Skip to content

Commit 5b69f1c

Browse files
authored
Merge pull request #91 from isomorphic-git/low-level-backends
add to change low level backend
2 parents 76ce24c + d50fd84 commit 5b69f1c

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
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

azure-pipelines.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ jobs:
22
- job: Linux
33

44
pool:
5-
vmImage: 'Ubuntu 16.04'
5+
vmImage: 'Ubuntu 18.04'
66

77
steps:
88
- task: NodeTool@0
99
inputs:
10-
versionSpec: '10.x'
10+
versionSpec: '12.x'
1111
displayName: 'Install Node.js'
1212

1313
- script: npm ci

src/DefaultBackend.js

+4-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 };
@@ -118,6 +119,8 @@ module.exports = class DefaultBackend {
118119
}
119120
if (encoding === "utf8") {
120121
data = decode(data);
122+
} else {
123+
data.toString = () => decode(data);
121124
}
122125
}
123126
if (!stat) throw new ENOENT(filepath)

0 commit comments

Comments
 (0)