@zenfs/core 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,16 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ import type { ParsedPath } from 'node:path';
3
+ export declare const cwd = "/";
4
+ export declare const sep = "/";
5
+ export declare function normalizeString(path: string, allowAboveRoot: boolean): string;
6
+ export declare function formatExt(ext: string): string;
7
+ export declare function resolve(...args: string[]): string;
8
+ export declare function normalize(path: string): string;
9
+ export declare function isAbsolute(path: string): boolean;
10
+ export declare function join(...args: string[]): string;
11
+ export declare function relative(from: string, to: string): string;
12
+ export declare function dirname(path: string): string;
13
+ export declare function basename(path: string, suffix?: string): string;
14
+ export declare function extname(path: string): string;
15
+ export declare function format(pathObject: ParsedPath): string;
16
+ export declare function parse(path: string): ParsedPath;
@@ -0,0 +1,451 @@
1
+ /*
2
+ Copyright Joyent, Inc. and other Node contributors.
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a
5
+ copy of this software and associated documentation files (the
6
+ "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to permit
9
+ persons to whom the Software is furnished to do so, subject to the
10
+ following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included
13
+ in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
18
+ NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
19
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21
+ USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ */
23
+ export const cwd = '/';
24
+ export const sep = '/';
25
+ function validateString(str, name) {
26
+ if (typeof str != 'string') {
27
+ throw new TypeError(`"${name}" is not a string`);
28
+ }
29
+ }
30
+ function validateObject(str, name) {
31
+ if (typeof str != 'object') {
32
+ throw new TypeError(`"${name}" is not an object`);
33
+ }
34
+ }
35
+ // Resolves . and .. elements in a path with directory names
36
+ export function normalizeString(path, allowAboveRoot) {
37
+ let res = '';
38
+ let lastSegmentLength = 0;
39
+ let lastSlash = -1;
40
+ let dots = 0;
41
+ let char = '\x00';
42
+ for (let i = 0; i <= path.length; ++i) {
43
+ if (i < path.length) {
44
+ char = path[i];
45
+ }
46
+ else if (char == '/') {
47
+ break;
48
+ }
49
+ else {
50
+ char = '/';
51
+ }
52
+ if (char == '/') {
53
+ if (lastSlash === i - 1 || dots === 1) {
54
+ // NOOP
55
+ }
56
+ else if (dots === 2) {
57
+ if (res.length < 2 || lastSegmentLength !== 2 || res.at(-1) !== '.' || res.at(-2) !== '.') {
58
+ if (res.length > 2) {
59
+ const lastSlashIndex = res.lastIndexOf('/');
60
+ if (lastSlashIndex === -1) {
61
+ res = '';
62
+ lastSegmentLength = 0;
63
+ }
64
+ else {
65
+ res = res.slice(0, lastSlashIndex);
66
+ lastSegmentLength = res.length - 1 - res.lastIndexOf('/');
67
+ }
68
+ lastSlash = i;
69
+ dots = 0;
70
+ continue;
71
+ }
72
+ else if (res.length !== 0) {
73
+ res = '';
74
+ lastSegmentLength = 0;
75
+ lastSlash = i;
76
+ dots = 0;
77
+ continue;
78
+ }
79
+ }
80
+ if (allowAboveRoot) {
81
+ res += res.length > 0 ? '/..' : '..';
82
+ lastSegmentLength = 2;
83
+ }
84
+ }
85
+ else {
86
+ if (res.length > 0)
87
+ res += '/' + path.slice(lastSlash + 1, i);
88
+ else
89
+ res = path.slice(lastSlash + 1, i);
90
+ lastSegmentLength = i - lastSlash - 1;
91
+ }
92
+ lastSlash = i;
93
+ dots = 0;
94
+ }
95
+ else if (char === '.' && dots !== -1) {
96
+ ++dots;
97
+ }
98
+ else {
99
+ dots = -1;
100
+ }
101
+ }
102
+ return res;
103
+ }
104
+ export function formatExt(ext) {
105
+ return ext ? `${ext[0] === '.' ? '' : '.'}${ext}` : '';
106
+ }
107
+ export function resolve(...args) {
108
+ let resolvedPath = '';
109
+ let resolvedAbsolute = false;
110
+ for (let i = args.length - 1; i >= -1 && !resolvedAbsolute; i--) {
111
+ const path = i >= 0 ? args[i] : cwd;
112
+ validateString(path, `paths[${i}]`);
113
+ // Skip empty entries
114
+ if (path.length === 0) {
115
+ continue;
116
+ }
117
+ resolvedPath = `${path}/${resolvedPath}`;
118
+ resolvedAbsolute = path[0] === '/';
119
+ }
120
+ // At this point the path should be resolved to a full absolute path, but
121
+ // handle relative paths to be safe (might happen when process.cwd() fails)
122
+ // Normalize the path
123
+ resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
124
+ if (resolvedAbsolute) {
125
+ return `/${resolvedPath}`;
126
+ }
127
+ return resolvedPath.length > 0 ? resolvedPath : '.';
128
+ }
129
+ export function normalize(path) {
130
+ validateString(path, 'path');
131
+ if (path.length === 0)
132
+ return '.';
133
+ const isAbsolute = path[0] === '/';
134
+ const trailingSeparator = path.at(-1) === '/';
135
+ // Normalize the path
136
+ path = normalizeString(path, !isAbsolute);
137
+ if (path.length === 0) {
138
+ if (isAbsolute)
139
+ return '/';
140
+ return trailingSeparator ? './' : '.';
141
+ }
142
+ if (trailingSeparator)
143
+ path += '/';
144
+ return isAbsolute ? `/${path}` : path;
145
+ }
146
+ export function isAbsolute(path) {
147
+ validateString(path, 'path');
148
+ return path.length > 0 && path[0] === '/';
149
+ }
150
+ export function join(...args) {
151
+ if (args.length === 0)
152
+ return '.';
153
+ let joined;
154
+ for (let i = 0; i < args.length; ++i) {
155
+ const arg = args[i];
156
+ validateString(arg, 'path');
157
+ if (arg.length > 0) {
158
+ if (joined === undefined)
159
+ joined = arg;
160
+ else
161
+ joined += `/${arg}`;
162
+ }
163
+ }
164
+ if (joined === undefined)
165
+ return '.';
166
+ return normalize(joined);
167
+ }
168
+ export function relative(from, to) {
169
+ validateString(from, 'from');
170
+ validateString(to, 'to');
171
+ if (from === to)
172
+ return '';
173
+ // Trim leading forward slashes.
174
+ from = resolve(from);
175
+ to = resolve(to);
176
+ if (from === to)
177
+ return '';
178
+ const fromStart = 1;
179
+ const fromEnd = from.length;
180
+ const fromLen = fromEnd - fromStart;
181
+ const toStart = 1;
182
+ const toLen = to.length - toStart;
183
+ // Compare paths to find the longest common path from root
184
+ const length = fromLen < toLen ? fromLen : toLen;
185
+ let lastCommonSep = -1;
186
+ let i = 0;
187
+ for (; i < length; i++) {
188
+ const fromCode = from[fromStart + i];
189
+ if (fromCode !== to[toStart + i])
190
+ break;
191
+ else if (fromCode === '/')
192
+ lastCommonSep = i;
193
+ }
194
+ if (i === length) {
195
+ if (toLen > length) {
196
+ if (to[toStart + i] === '/') {
197
+ // We get here if `from` is the exact base path for `to`.
198
+ // For example: from='/foo/bar'; to='/foo/bar/baz'
199
+ return to.slice(toStart + i + 1);
200
+ }
201
+ if (i === 0) {
202
+ // We get here if `from` is the root
203
+ // For example: from='/'; to='/foo'
204
+ return to.slice(toStart + i);
205
+ }
206
+ }
207
+ else if (fromLen > length) {
208
+ if (from[fromStart + i] === '/') {
209
+ // We get here if `to` is the exact base path for `from`.
210
+ // For example: from='/foo/bar/baz'; to='/foo/bar'
211
+ lastCommonSep = i;
212
+ }
213
+ else if (i === 0) {
214
+ // We get here if `to` is the root.
215
+ // For example: from='/foo/bar'; to='/'
216
+ lastCommonSep = 0;
217
+ }
218
+ }
219
+ }
220
+ let out = '';
221
+ // Generate the relative path based on the path difference between `to`
222
+ // and `from`.
223
+ for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
224
+ if (i === fromEnd || from[i] === '/') {
225
+ out += out.length === 0 ? '..' : '/..';
226
+ }
227
+ }
228
+ // Lastly, append the rest of the destination (`to`) path that comes after
229
+ // the common path parts.
230
+ return `${out}${to.slice(toStart + lastCommonSep)}`;
231
+ }
232
+ export function dirname(path) {
233
+ validateString(path, 'path');
234
+ if (path.length === 0)
235
+ return '.';
236
+ const hasRoot = path[0] === '/';
237
+ let end = -1;
238
+ let matchedSlash = true;
239
+ for (let i = path.length - 1; i >= 1; --i) {
240
+ if (path[i] === '/') {
241
+ if (!matchedSlash) {
242
+ end = i;
243
+ break;
244
+ }
245
+ }
246
+ else {
247
+ // We saw the first non-path separator
248
+ matchedSlash = false;
249
+ }
250
+ }
251
+ if (end === -1)
252
+ return hasRoot ? '/' : '.';
253
+ if (hasRoot && end === 1)
254
+ return '//';
255
+ return path.slice(0, end);
256
+ }
257
+ export function basename(path, suffix) {
258
+ if (suffix !== undefined)
259
+ validateString(suffix, 'ext');
260
+ validateString(path, 'path');
261
+ let start = 0;
262
+ let end = -1;
263
+ let matchedSlash = true;
264
+ if (suffix !== undefined && suffix.length > 0 && suffix.length <= path.length) {
265
+ if (suffix === path)
266
+ return '';
267
+ let extIdx = suffix.length - 1;
268
+ let firstNonSlashEnd = -1;
269
+ for (let i = path.length - 1; i >= 0; --i) {
270
+ if (path[i] === '/') {
271
+ // If we reached a path separator that was not part of a set of path
272
+ // separators at the end of the string, stop now
273
+ if (!matchedSlash) {
274
+ start = i + 1;
275
+ break;
276
+ }
277
+ }
278
+ else {
279
+ if (firstNonSlashEnd === -1) {
280
+ // We saw the first non-path separator, remember this index in case
281
+ // we need it if the extension ends up not matching
282
+ matchedSlash = false;
283
+ firstNonSlashEnd = i + 1;
284
+ }
285
+ if (extIdx >= 0) {
286
+ // Try to match the explicit extension
287
+ if (path[i] === suffix[extIdx]) {
288
+ if (--extIdx === -1) {
289
+ // We matched the extension, so mark this as the end of our path
290
+ // component
291
+ end = i;
292
+ }
293
+ }
294
+ else {
295
+ // Extension does not match, so our result is the entire path
296
+ // component
297
+ extIdx = -1;
298
+ end = firstNonSlashEnd;
299
+ }
300
+ }
301
+ }
302
+ }
303
+ if (start === end)
304
+ end = firstNonSlashEnd;
305
+ else if (end === -1)
306
+ end = path.length;
307
+ return path.slice(start, end);
308
+ }
309
+ for (let i = path.length - 1; i >= 0; --i) {
310
+ if (path[i] === '/') {
311
+ // If we reached a path separator that was not part of a set of path
312
+ // separators at the end of the string, stop now
313
+ if (!matchedSlash) {
314
+ start = i + 1;
315
+ break;
316
+ }
317
+ }
318
+ else if (end === -1) {
319
+ // We saw the first non-path separator, mark this as the end of our
320
+ // path component
321
+ matchedSlash = false;
322
+ end = i + 1;
323
+ }
324
+ }
325
+ if (end === -1)
326
+ return '';
327
+ return path.slice(start, end);
328
+ }
329
+ export function extname(path) {
330
+ validateString(path, 'path');
331
+ let startDot = -1;
332
+ let startPart = 0;
333
+ let end = -1;
334
+ let matchedSlash = true;
335
+ // Track the state of characters (if any) we see before our first dot and
336
+ // after any path separator we find
337
+ let preDotState = 0;
338
+ for (let i = path.length - 1; i >= 0; --i) {
339
+ if (path[i] === '/') {
340
+ // If we reached a path separator that was not part of a set of path
341
+ // separators at the end of the string, stop now
342
+ if (!matchedSlash) {
343
+ startPart = i + 1;
344
+ break;
345
+ }
346
+ continue;
347
+ }
348
+ if (end === -1) {
349
+ // We saw the first non-path separator, mark this as the end of our
350
+ // extension
351
+ matchedSlash = false;
352
+ end = i + 1;
353
+ }
354
+ if (path[i] === '.') {
355
+ // If this is our first dot, mark it as the start of our extension
356
+ if (startDot === -1)
357
+ startDot = i;
358
+ else if (preDotState !== 1)
359
+ preDotState = 1;
360
+ }
361
+ else if (startDot !== -1) {
362
+ // We saw a non-dot and non-path separator before our dot, so we should
363
+ // have a good chance at having a non-empty extension
364
+ preDotState = -1;
365
+ }
366
+ }
367
+ if (startDot === -1 ||
368
+ end === -1 ||
369
+ // We saw a non-dot character immediately before the dot
370
+ preDotState === 0 ||
371
+ // The (right-most) trimmed path component is exactly '..'
372
+ (preDotState === 1 && startDot === end - 1 && startDot === startPart + 1)) {
373
+ return '';
374
+ }
375
+ return path.slice(startDot, end);
376
+ }
377
+ export function format(pathObject) {
378
+ validateObject(pathObject, 'pathObject');
379
+ const dir = pathObject.dir || pathObject.root;
380
+ const base = pathObject.base || `${pathObject.name || ''}${formatExt(pathObject.ext)}`;
381
+ if (!dir) {
382
+ return base;
383
+ }
384
+ return dir === pathObject.root ? `${dir}${base}` : `${dir}/${base}`;
385
+ }
386
+ export function parse(path) {
387
+ validateString(path, 'path');
388
+ const isAbsolute = path[0] === '/';
389
+ const ret = { root: isAbsolute ? '/' : '', dir: '', base: '', ext: '', name: '' };
390
+ if (path.length === 0)
391
+ return ret;
392
+ const start = isAbsolute ? 1 : 0;
393
+ let startDot = -1;
394
+ let startPart = 0;
395
+ let end = -1;
396
+ let matchedSlash = true;
397
+ let i = path.length - 1;
398
+ // Track the state of characters (if any) we see before our first dot and
399
+ // after any path separator we find
400
+ let preDotState = 0;
401
+ // Get non-dir info
402
+ for (; i >= start; --i) {
403
+ if (path[i] === '/') {
404
+ // If we reached a path separator that was not part of a set of path
405
+ // separators at the end of the string, stop now
406
+ if (!matchedSlash) {
407
+ startPart = i + 1;
408
+ break;
409
+ }
410
+ continue;
411
+ }
412
+ if (end === -1) {
413
+ // We saw the first non-path separator, mark this as the end of our
414
+ // extension
415
+ matchedSlash = false;
416
+ end = i + 1;
417
+ }
418
+ if (path[i] === '.') {
419
+ // If this is our first dot, mark it as the start of our extension
420
+ if (startDot === -1)
421
+ startDot = i;
422
+ else if (preDotState !== 1)
423
+ preDotState = 1;
424
+ }
425
+ else if (startDot !== -1) {
426
+ // We saw a non-dot and non-path separator before our dot, so we should
427
+ // have a good chance at having a non-empty extension
428
+ preDotState = -1;
429
+ }
430
+ }
431
+ if (end !== -1) {
432
+ const start = startPart === 0 && isAbsolute ? 1 : startPart;
433
+ if (startDot === -1 ||
434
+ // We saw a non-dot character immediately before the dot
435
+ preDotState === 0 ||
436
+ // The (right-most) trimmed path component is exactly '..'
437
+ (preDotState === 1 && startDot === end - 1 && startDot === startPart + 1)) {
438
+ ret.base = ret.name = path.slice(start, end);
439
+ }
440
+ else {
441
+ ret.name = path.slice(start, startDot);
442
+ ret.base = path.slice(start, end);
443
+ ret.ext = path.slice(startDot, end);
444
+ }
445
+ }
446
+ if (startPart > 0)
447
+ ret.dir = path.slice(0, startPart - 1);
448
+ else if (isAbsolute)
449
+ ret.dir = '/';
450
+ return ret;
451
+ }
@@ -1,5 +1,5 @@
1
1
  // Utilities and shared data
2
- import { posix as path } from 'path';
2
+ import { resolve } from './path.js';
3
3
  import { ApiError, ErrorCode } from '../ApiError.js';
4
4
  import { Cred } from '../cred.js';
5
5
  //import { BackendConstructor } from '../backends.js';
@@ -52,7 +52,7 @@ export function normalizePath(p) {
52
52
  throw new ApiError(ErrorCode.EINVAL, 'Path must not be empty.');
53
53
  }
54
54
  p = p.replaceAll(/\/+/g, '/');
55
- return path.resolve(p);
55
+ return resolve(p);
56
56
  }
57
57
  export function normalizeOptions(options, defEnc, defFlag, defMode) {
58
58
  // typeof null === 'object' so special-case handing is needed.
@@ -129,7 +129,7 @@ export function mount(mountPoint, fs) {
129
129
  if (mountPoint[0] !== '/') {
130
130
  mountPoint = '/' + mountPoint;
131
131
  }
132
- mountPoint = path.resolve(mountPoint);
132
+ mountPoint = resolve(mountPoint);
133
133
  if (mounts.has(mountPoint)) {
134
134
  throw new ApiError(ErrorCode.EINVAL, 'Mount point ' + mountPoint + ' is already in use.');
135
135
  }
@@ -142,7 +142,7 @@ export function umount(mountPoint) {
142
142
  if (mountPoint[0] !== '/') {
143
143
  mountPoint = `/${mountPoint}`;
144
144
  }
145
- mountPoint = path.resolve(mountPoint);
145
+ mountPoint = resolve(mountPoint);
146
146
  if (!mounts.has(mountPoint)) {
147
147
  throw new ApiError(ErrorCode.EINVAL, 'Mount point ' + mountPoint + ' is already unmounted.');
148
148
  }
@@ -12,7 +12,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
12
12
  var _a;
13
13
  import { ApiError, ErrorCode } from './ApiError.js';
14
14
  import { FileFlag, ActionType } from './file.js';
15
- import * as path from 'path';
15
+ import * as path from './emulation/path.js';
16
16
  import { Buffer } from 'buffer';
17
17
  /**
18
18
  * Structure for a filesystem. **All** ZenFS FileSystems must implement
package/dist/utils.js CHANGED
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { ErrorCode, ApiError } from './ApiError.js';
11
- import * as path from 'path';
11
+ import * as path from './emulation/path.js';
12
12
  import { Buffer } from 'buffer';
13
13
  /**
14
14
  * Synchronous recursive makedir.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenfs/core",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "description": "A filesystem in your browser",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist",
@@ -53,10 +53,8 @@
53
53
  "buffer": "~5.1.0",
54
54
  "cross-env": "^7.0.3",
55
55
  "esbuild": "^0.17.18",
56
- "esbuild-plugin-polyfill-node": "^0.3.0",
57
56
  "eslint": "^8.36.0",
58
57
  "jest": "^29.5.0",
59
- "path": "^0.12.7",
60
58
  "prettier": "^2.8.7",
61
59
  "ts-jest": "^29.1.0",
62
60
  "typedoc": "^0.25.1",
@@ -33,10 +33,10 @@ npm install @zenfs/core
33
33
 
34
34
  ## Usage
35
35
 
36
- > 🛈 The examples are written in ESM. If you are using CJS, you can `require` the package. If running in a borwser you can add a script tag to your HTML pointing to the `browser.min.js` and use ZenFS via the global `ZenFS` object.
36
+ > 🛈 The examples are written in ESM. If you are using CJS, you can `require` the package. If running in a browser you can add a script tag to your HTML pointing to the `browser.min.js` and use ZenFS via the global `ZenFS` object.
37
37
 
38
38
  ```js
39
- import { fs } from '@zenfs/core';
39
+ import fs from '@zenfs/core';
40
40
 
41
41
  fs.writeFileSync('/test.txt', 'Cool, I can do this in the browser!');
42
42
 
@@ -46,14 +46,15 @@ console.log(contents);
46
46
 
47
47
  #### Using different backends
48
48
 
49
- A `InMemory` backend is created by default. If you would like to use a different one, you must configure ZenFS. It is recommended to do so using the `configure` function. Here is an example using the `LocalStorage` backend from `@zenfs/fs-dom`:
49
+ A `InMemory` backend is created by default. If you would like to use a different one, you must configure ZenFS. It is recommended to do so using the `configure` function. Here is an example using the `Storage` backend from `@zenfs/fs-dom`:
50
50
 
51
51
  ```js
52
- import { configure, fs } from '@zenfs/core';
53
- import '@zenfs/fs-dom'; // size effects are needed
52
+ import { configure, fs, registerBackend } from '@zenfs/core';
53
+ import { StorageFileSystem } from '@zenfs/fs-dom';
54
+ registerBackend(StorageFileSystem);
54
55
 
55
56
  // you can also add a callback as the last parameter instead of using promises
56
- await configure({ fs: 'LocalStorage' });
57
+ await configure({ fs: 'Storage' });
57
58
 
58
59
  if (!fs.existsSync('/test.txt')) {
59
60
  fs.writeFileSync('/test.txt', 'This will persist across reloads!');
@@ -65,13 +66,14 @@ console.log(contents);
65
66
 
66
67
  #### Using multiple backends
67
68
 
68
- You can use multiple backends by passing an object to `configure` which maps paths to file systems. The following example mounts a zip file to `/zip`, in-memory storage to `/tmp`, and IndexedDB browser-local storage to `/home` (note that `/` has the default in-memory backend):
69
+ You can use multiple backends by passing an object to `configure` which maps paths to file systems. The following example mounts a zip file to `/zip`, in-memory storage to `/tmp`, and IndexedDB storage to `/home` (note that `/` has the default in-memory backend):
69
70
 
70
71
  ```js
71
- import { configure } from '@zenfs/core';
72
- import '@zenfs/fs-dom';
73
- import '@zenfs/fs-zip';
72
+ import { configure, registerBackend } from '@zenfs/core';
73
+ import { IndexedDBFileSystem } from '@zenfs/fs-dom';
74
+ import { ZipFS } from '@zenfs/fs-zip';
74
75
  import Buffer from 'buffer';
76
+ registerBackend(IndexedDBFileSystem, ZipFS);
75
77
 
76
78
  const zipData = await (await fetch('mydata.zip')).arrayBuffer();
77
79
 
@@ -92,8 +94,9 @@ await configure({
92
94
  The FS promises API is exposed as `promises`.
93
95
 
94
96
  ```js
95
- import { configure, promises } from '@zenfs/core';
96
- import '@zenfs/fs-dom';
97
+ import { configure, promises, registerBackend } from '@zenfs/core';
98
+ import { IndexedDBFileSystem } from '@zenfs/fs-dom';
99
+ registerBackend(IndexedDBFileSystem);
97
100
 
98
101
  await configure({ '/': 'IndexedDB' });
99
102
 
@@ -111,7 +114,8 @@ You may have noticed that attempting to use a synchronous method on an asynchron
111
114
 
112
115
  ```js
113
116
  import { configure, fs } from '@zenfs/core';
114
- import '@zenfs/fs-dom';
117
+ import { IndexedDBFileSystem } from '@zenfs/fs-dom';
118
+ registerBackend(IndexedDBFileSystem);
115
119
 
116
120
  await configure({
117
121
  '/': { fs: 'AsyncMirror', options: { sync: { fs: 'InMemory' }, async: { fs: 'IndexedDB' } } }
@@ -161,10 +165,10 @@ fs.umount('/tmp'); // unmount /tmp
161
165
  This could be used in the "multiple backends" example like so:
162
166
 
163
167
  ```js
164
- import { configure, fs, ZipFS } from '@zenfs/core';
165
- import '@zenfs/fs-dom';
166
- import '@zenfs/fs-zip';
168
+ import { IndexedDBFileSystem } from '@zenfs/fs-dom';
169
+ import { ZipFS } from '@zenfs/fs-zip';
167
170
  import Buffer from 'buffer';
171
+ registerBackend(IndexedDBFileSystem);
168
172
 
169
173
  await configure({
170
174
  '/tmp': 'InMemory',
@@ -238,10 +242,10 @@ export default {
238
242
  You can use any _synchronous_ ZenFS file systems with Emscripten.
239
243
 
240
244
  ```js
241
- import { EmscriptenFS } from '@zenfs/fs-emscripten';
242
- const BFS = new EmscriptenFS(); // Create a ZenFS Emscripten FS plugin.
243
- FS.createFolder(FS.root, 'data', true, true); // Create the folder that we'll turn into a mount point.
244
- FS.mount(BFS, { root: '/' }, '/data'); // Mount BFS's root folder into the '/data' folder.
245
+ import { EmscriptenFSPlugin } from '@zenfs/fs-emscripten';
246
+ const BFS = new EmscriptenFSPlugin(); // Create a ZenFS Emscripten FS plugin.
247
+ FS.createFolder(FS.root, 'data', true, true); // Create the folder to turn into a mount point.
248
+ FS.mount(BFS, { root: '/' }, '/data'); // Mount BFS's root folder into /data.
245
249
  ```
246
250
 
247
251
  If you want to use an asynchronous backend, you must wrap it in an `AsyncMirror`.