Skip to content

Commit e530b68

Browse files
committed
feat: add to change low level backend
1 parent 76ce24c commit e530b68

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

README.md

+13
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,10 @@ Options object:
6969
| `lockDbName` | string | Customize the database name for the lock mutex |
7070
| `lockStoreName` | string | Customize the store name for the lock mutex |
7171
| `defer` | boolean = false | If true, avoids mutex contention during initialization |
72+
| `db` | IDB | Replacement for DB object that hold Filesystem data. It's low level replacement for `backend` option. |
7273
| `backend` | IBackend | If present, none of the other arguments (except `defer`) have any effect, and instead of using the normal LightningFS stuff, LightningFS acts as a wrapper around the provided custom backend. |
7374

75+
7476
#### Advanced usage
7577

7678
You can procrastinate initializing the FS object until later.
@@ -258,6 +260,17 @@ interface IBackend {
258260
deactivate?(): Awaited<void>; // called after fs has been idle for a while
259261
destroy?(): Awaited<void>; // called before hotswapping backends
260262
}
263+
264+
interface IDB {
265+
saveSuperblock(superblock): void;
266+
loadSuperblock(): Awaited<Buffer>;
267+
readFile(inode): Awaited<Buffer>;
268+
writeFile(inode, data): Awaited<void>;
269+
unlink(inode): Awaited<void>;
270+
wipe(): void;
271+
close(): void;
272+
}
273+
261274
```
262275

263276
## License

src/DefaultBackend.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ module.exports = class DefaultBackend {
2121
url,
2222
urlauto,
2323
fileDbName = name,
24+
db = null,
2425
fileStoreName = name + "_files",
2526
lockDbName = name + "_lock",
2627
lockStoreName = name + "_lock",
2728
} = {}) {
2829
this._name = name
29-
this._idb = new IdbBackend(fileDbName, fileStoreName);
30+
this._idb = db || new IdbBackend(fileDbName, fileStoreName);
3031
this._mutex = navigator.locks ? new Mutex2(name) : new Mutex(lockDbName, lockStoreName);
3132
this._cache = new CacheFS(name);
3233
this._opts = { wipe, url };

0 commit comments

Comments
 (0)