@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/dist/ApiError.d.ts +2 -2
- package/dist/ApiError.js +11 -7
- package/dist/FileIndex.js +2 -2
- package/dist/backends/AsyncMirror.js +2 -2
- package/dist/backends/AsyncStore.d.ts +4 -5
- package/dist/backends/AsyncStore.js +21 -21
- package/dist/backends/FolderAdapter.js +6 -6
- package/dist/backends/InMemory.d.ts +2 -3
- package/dist/backends/OverlayFS.js +7 -7
- package/dist/backends/SyncStore.d.ts +12 -13
- package/dist/backends/SyncStore.js +21 -21
- package/dist/browser.min.js +6 -11
- package/dist/browser.min.js.map +4 -4
- package/dist/emulation/callbacks.d.ts +6 -6
- package/dist/emulation/callbacks.js +3 -2
- package/dist/emulation/path.d.ts +16 -0
- package/dist/emulation/path.js +451 -0
- package/dist/emulation/promises.d.ts +6 -6
- package/dist/emulation/promises.js +2 -1
- package/dist/emulation/shared.js +4 -4
- package/dist/emulation/sync.d.ts +6 -6
- package/dist/emulation/sync.js +2 -1
- package/dist/file.d.ts +23 -24
- package/dist/file.js +18 -20
- package/dist/filesystem.d.ts +3 -3
- package/dist/filesystem.js +10 -10
- package/dist/inode.d.ts +2 -3
- package/dist/inode.js +17 -17
- package/dist/stats.d.ts +3 -4
- package/dist/stats.js +13 -13
- package/dist/utils.d.ts +10 -5
- package/dist/utils.js +3 -9
- package/package.json +1 -5
- package/{README.md → readme.md} +24 -20
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zenfs/core",
|
|
3
|
-
"version": "0.0.
|
|
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",
|
package/{README.md → readme.md}
RENAMED
|
@@ -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
|
|
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
|
|
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 `
|
|
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';
|
|
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: '
|
|
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
|
|
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 {
|
|
165
|
-
import '@zenfs/fs-
|
|
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 {
|
|
242
|
-
const BFS = new
|
|
243
|
-
FS.createFolder(FS.root, 'data', true, true); // Create the folder
|
|
244
|
-
FS.mount(BFS, { root: '/' }, '/data'); // Mount BFS's root folder into
|
|
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`.
|