You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|`wipe`| boolean = false | Delete the database and start with an empty filesystem |
65
+
|`url`| string = undefined | Let `readFile` requests fall back to an HTTP request to this base URL |
66
+
|`urlauto`| boolean = false | Fall back to HTTP for every read of a missing file, even if unbacked |
67
+
|`fileDbName`| string | Customize the database name |
68
+
|`fileStoreName`| string | Customize the store name |
69
+
|`lockDbName`| string | Customize the database name for the lock mutex |
70
+
|`lockStoreName`| string | Customize the store name for the lock mutex |
71
+
|`defer`| boolean = false | If true, avoids mutex contention during initialization |
72
+
|`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. |
72
73
73
74
#### Advanced usage
74
75
@@ -191,6 +192,66 @@ Returns the size of a file or directory in bytes.
191
192
192
193
All the same functions as above, but instead of passing a callback they return a promise.
193
194
195
+
## Providing a custom `backend` (advanced usage)
196
+
197
+
There are only two reasons I can think of that you would want to do this:
198
+
199
+
1. The `fs` module is normally a singleton. LightningFS allows you to safely(ish) hotswap between various data sources by calling `init` multiple times with different options. (It keeps track of file system operations in flight and waits until there's an idle moment to do the switch.)
200
+
201
+
2. LightningFS normalizes all the lovely variations of node's `fs` arguments:
And it normalizes filepaths. And will convert plain `StatLike` objects into `Stat` objects with methods like `isFile`, `isDirectory`, etc.
211
+
212
+
If that fits your needs, then you can provide a `backend` option and LightningFS will use that. Implement as few/many methods as you need for your application to work.
213
+
214
+
**Note:** If you use a custom backend, you are responsible for managing multi-threaded access - there are no magic mutexes included by default.
215
+
216
+
```tsx
217
+
218
+
typeEncodingOpts= {
219
+
encoding?:'utf8';
220
+
}
221
+
222
+
typeStatLike= {
223
+
type:'file'|'dir'|'symlink';
224
+
mode:number;
225
+
size:number;
226
+
ino:number|string|BigInt;
227
+
mtimeMs:number;
228
+
ctimeMs?:number;
229
+
}
230
+
231
+
interfaceIBackend {
232
+
// highly recommended - usually necessary for apps to work
0 commit comments