@zenfs/core 0.0.7 → 0.0.9

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenfs/core",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "description": "A filesystem in your browser",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist",
@@ -44,19 +44,15 @@
44
44
  },
45
45
  "devDependencies": {
46
46
  "@jest/globals": "^29.5.0",
47
- "@types/archiver": "~2.1.2",
48
47
  "@types/jest": "^29.5.1",
49
48
  "@types/node": "^14.18.62",
50
49
  "@typescript-eslint/eslint-plugin": "^5.55.0",
51
50
  "@typescript-eslint/parser": "^5.55.0",
52
- "archiver": "~2.1.1",
53
51
  "buffer": "~5.1.0",
54
52
  "cross-env": "^7.0.3",
55
53
  "esbuild": "^0.17.18",
56
- "esbuild-plugin-polyfill-node": "^0.3.0",
57
54
  "eslint": "^8.36.0",
58
55
  "jest": "^29.5.0",
59
- "path": "^0.12.7",
60
56
  "prettier": "^2.8.7",
61
57
  "ts-jest": "^29.1.0",
62
58
  "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`.