@zenfs/core 0.4.0 → 0.4.1
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/browser.min.js +4 -4
- package/dist/browser.min.js.map +4 -4
- package/dist/config.d.ts +23 -0
- package/dist/config.js +36 -0
- package/dist/index.d.ts +3 -28
- package/dist/index.js +3 -39
- package/license.md +3 -80
- package/package.json +71 -67
- package/readme.md +9 -5
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Backend, BackendConfig } from './backends/backend.js';
|
|
2
|
+
import { FileSystem } from './filesystem.js';
|
|
3
|
+
/**
|
|
4
|
+
* Initializes ZenFS with the given file systems.
|
|
5
|
+
*/
|
|
6
|
+
export declare function initialize(mounts: {
|
|
7
|
+
[point: string]: FileSystem;
|
|
8
|
+
}, uid?: number, gid?: number): void;
|
|
9
|
+
/**
|
|
10
|
+
* Defines a mapping of mount points to their configurations
|
|
11
|
+
*/
|
|
12
|
+
export interface ConfigMapping {
|
|
13
|
+
[mountPoint: string]: FileSystem | BackendConfig | Backend;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* A configuration for ZenFS
|
|
17
|
+
*/
|
|
18
|
+
export type Configuration = FileSystem | BackendConfig | ConfigMapping;
|
|
19
|
+
/**
|
|
20
|
+
* Creates filesystems with the given configuration, and initializes ZenFS with it.
|
|
21
|
+
* See the Configuration type for more info on the configuration object.
|
|
22
|
+
*/
|
|
23
|
+
export declare function configure(config: Configuration): Promise<void>;
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { isBackend, resolveBackendConfig } from './backends/backend.js';
|
|
2
|
+
import { Cred } from './cred.js';
|
|
3
|
+
import * as fs from './emulation/index.js';
|
|
4
|
+
import { setCred } from './emulation/shared.js';
|
|
5
|
+
import { FileSystem } from './filesystem.js';
|
|
6
|
+
/**
|
|
7
|
+
* Initializes ZenFS with the given file systems.
|
|
8
|
+
*/
|
|
9
|
+
export function initialize(mounts, uid = 0, gid = 0) {
|
|
10
|
+
setCred(new Cred(uid, gid, uid, gid, uid, gid));
|
|
11
|
+
fs.initialize(mounts);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Creates filesystems with the given configuration, and initializes ZenFS with it.
|
|
15
|
+
* See the Configuration type for more info on the configuration object.
|
|
16
|
+
*/
|
|
17
|
+
export async function configure(config) {
|
|
18
|
+
if ('backend' in config || config instanceof FileSystem) {
|
|
19
|
+
// single FS
|
|
20
|
+
config = { '/': config };
|
|
21
|
+
}
|
|
22
|
+
for (let [point, value] of Object.entries(config)) {
|
|
23
|
+
if (typeof value == 'number') {
|
|
24
|
+
//should never happen
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
if (value instanceof FileSystem) {
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
if (isBackend(value)) {
|
|
31
|
+
value = { backend: value };
|
|
32
|
+
}
|
|
33
|
+
config[point] = await resolveBackendConfig(value);
|
|
34
|
+
}
|
|
35
|
+
initialize(config);
|
|
36
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,31 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* ZenFS's main module. This is exposed in the browser via the ZenFS global.
|
|
3
|
-
*/
|
|
4
|
-
import * as fs from './emulation/index.js';
|
|
5
|
-
import { FileSystem } from './filesystem.js';
|
|
6
|
-
import { type Backend, type BackendConfig } from './backends/backend.js';
|
|
7
|
-
/**
|
|
8
|
-
* Initializes ZenFS with the given file systems.
|
|
9
|
-
*/
|
|
10
|
-
export declare function initialize(mounts: {
|
|
11
|
-
[point: string]: FileSystem;
|
|
12
|
-
}, uid?: number, gid?: number): void;
|
|
13
|
-
/**
|
|
14
|
-
* Defines a mapping of mount points to their configurations
|
|
15
|
-
*/
|
|
16
|
-
export interface ConfigMapping {
|
|
17
|
-
[mountPoint: string]: FileSystem | BackendConfig | Backend;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* A configuration for ZenFS
|
|
21
|
-
*/
|
|
22
|
-
export type Configuration = FileSystem | BackendConfig | ConfigMapping;
|
|
23
|
-
/**
|
|
24
|
-
* Creates filesystems with the given configuration, and initializes ZenFS with it.
|
|
25
|
-
* See the Configuration type for more info on the configuration object.
|
|
26
|
-
*/
|
|
27
|
-
export declare function configure(config: Configuration): Promise<void>;
|
|
28
|
-
export type { Backend, BackendConfig } from './backends/backend.js';
|
|
1
|
+
export * from './backends/backend.js';
|
|
29
2
|
export * from './backends/AsyncMirror.js';
|
|
30
3
|
export * from './backends/AsyncStore.js';
|
|
31
4
|
export * from './backends/InMemory.js';
|
|
@@ -33,6 +6,7 @@ export * from './backends/Locked.js';
|
|
|
33
6
|
export * from './backends/Overlay.js';
|
|
34
7
|
export * from './backends/SyncStore.js';
|
|
35
8
|
export * from './ApiError.js';
|
|
9
|
+
export * from './config.js';
|
|
36
10
|
export * from './cred.js';
|
|
37
11
|
export * from './file.js';
|
|
38
12
|
export * from './filesystem.js';
|
|
@@ -41,5 +15,6 @@ export * from './inode.js';
|
|
|
41
15
|
export * from './mutex.js';
|
|
42
16
|
export * from './stats.js';
|
|
43
17
|
export * from './utils.js';
|
|
18
|
+
import * as fs from './emulation/index.js';
|
|
44
19
|
export { fs };
|
|
45
20
|
export default fs;
|
package/dist/index.js
CHANGED
|
@@ -1,42 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* ZenFS's main module. This is exposed in the browser via the ZenFS global.
|
|
3
|
-
*/
|
|
4
|
-
import * as fs from './emulation/index.js';
|
|
5
|
-
import { FileSystem } from './filesystem.js';
|
|
6
|
-
import { Cred } from './cred.js';
|
|
7
|
-
import { isBackend, resolveBackendConfig } from './backends/backend.js';
|
|
8
|
-
import { setCred } from './emulation/shared.js';
|
|
9
|
-
/**
|
|
10
|
-
* Initializes ZenFS with the given file systems.
|
|
11
|
-
*/
|
|
12
|
-
export function initialize(mounts, uid = 0, gid = 0) {
|
|
13
|
-
setCred(new Cred(uid, gid, uid, gid, uid, gid));
|
|
14
|
-
fs.initialize(mounts);
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Creates filesystems with the given configuration, and initializes ZenFS with it.
|
|
18
|
-
* See the Configuration type for more info on the configuration object.
|
|
19
|
-
*/
|
|
20
|
-
export async function configure(config) {
|
|
21
|
-
if ('backend' in config || config instanceof FileSystem) {
|
|
22
|
-
// single FS
|
|
23
|
-
config = { '/': config };
|
|
24
|
-
}
|
|
25
|
-
for (let [point, value] of Object.entries(config)) {
|
|
26
|
-
if (typeof value == 'number') {
|
|
27
|
-
//should never happen
|
|
28
|
-
continue;
|
|
29
|
-
}
|
|
30
|
-
if (value instanceof FileSystem) {
|
|
31
|
-
continue;
|
|
32
|
-
}
|
|
33
|
-
if (isBackend(value)) {
|
|
34
|
-
value = { backend: value };
|
|
35
|
-
}
|
|
36
|
-
config[point] = await resolveBackendConfig(value);
|
|
37
|
-
}
|
|
38
|
-
initialize(config);
|
|
39
|
-
}
|
|
1
|
+
export * from './backends/backend.js';
|
|
40
2
|
export * from './backends/AsyncMirror.js';
|
|
41
3
|
export * from './backends/AsyncStore.js';
|
|
42
4
|
export * from './backends/InMemory.js';
|
|
@@ -44,6 +6,7 @@ export * from './backends/Locked.js';
|
|
|
44
6
|
export * from './backends/Overlay.js';
|
|
45
7
|
export * from './backends/SyncStore.js';
|
|
46
8
|
export * from './ApiError.js';
|
|
9
|
+
export * from './config.js';
|
|
47
10
|
export * from './cred.js';
|
|
48
11
|
export * from './file.js';
|
|
49
12
|
export * from './filesystem.js';
|
|
@@ -52,5 +15,6 @@ export * from './inode.js';
|
|
|
52
15
|
export * from './mutex.js';
|
|
53
16
|
export * from './stats.js';
|
|
54
17
|
export * from './utils.js';
|
|
18
|
+
import * as fs from './emulation/index.js';
|
|
55
19
|
export { fs };
|
|
56
20
|
export default fs;
|
package/license.md
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
ZenFS
|
|
1
|
+
Copyright (c) 2023-2024 James P. and other ZenFS contributors.
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Copyright (c) 2013-2023 John Vilk and other ZenFS contributors.
|
|
3
|
+
Copyright (c) 2013-2023 John Vilk and other BrowserFS contributors.
|
|
6
4
|
|
|
7
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
8
6
|
this software and associated documentation files (the "Software"), to deal in
|
|
@@ -22,11 +20,9 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
22
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
21
|
SOFTWARE.
|
|
24
22
|
|
|
25
|
-
====
|
|
26
|
-
|
|
27
23
|
This license applies to all parts of ZenFS, except for the following items:
|
|
28
24
|
|
|
29
|
-
- The test fixtures located in `test/fixtures/
|
|
25
|
+
- The test fixtures located in `test/fixtures/node`. Their license follows:
|
|
30
26
|
"""
|
|
31
27
|
Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
|
32
28
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
@@ -47,76 +43,3 @@ This license applies to all parts of ZenFS, except for the following items:
|
|
|
47
43
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
48
44
|
IN THE SOFTWARE.
|
|
49
45
|
"""
|
|
50
|
-
|
|
51
|
-
- The Emscripten file system in src/generic/emscripten_fs.ts is a modified
|
|
52
|
-
version of Emscripten's NODEFS. Emscripten's license follows:
|
|
53
|
-
"""
|
|
54
|
-
Emscripten is available under 2 licenses, the MIT license and the
|
|
55
|
-
University of Illinois/NCSA Open Source License.
|
|
56
|
-
|
|
57
|
-
Both are permissive open source licenses, with little if any
|
|
58
|
-
practical difference between them.
|
|
59
|
-
|
|
60
|
-
The reason for offering both is that (1) the MIT license is
|
|
61
|
-
well-known, while (2) the University of Illinois/NCSA Open Source
|
|
62
|
-
License allows Emscripten's code to be integrated upstream into
|
|
63
|
-
LLVM, which uses that license, should the opportunity arise.
|
|
64
|
-
|
|
65
|
-
The full text of both licenses follows.
|
|
66
|
-
|
|
67
|
-
==============================================================================
|
|
68
|
-
|
|
69
|
-
Copyright (c) 2010-2011 Emscripten authors, see AUTHORS file.
|
|
70
|
-
|
|
71
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
72
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
73
|
-
in the Software without restriction, including without limitation the rights
|
|
74
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
75
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
76
|
-
furnished to do so, subject to the following conditions:
|
|
77
|
-
|
|
78
|
-
The above copyright notice and this permission notice shall be included in
|
|
79
|
-
all copies or substantial portions of the Software.
|
|
80
|
-
|
|
81
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
82
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
83
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
84
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
85
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
86
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
87
|
-
THE SOFTWARE.
|
|
88
|
-
|
|
89
|
-
==============================================================================
|
|
90
|
-
|
|
91
|
-
Copyright (c) 2010-2011 Emscripten authors, see AUTHORS file.
|
|
92
|
-
All rights reserved.
|
|
93
|
-
|
|
94
|
-
Permission is hereby granted, free of charge, to any person obtaining a
|
|
95
|
-
copy of this software and associated documentation files (the
|
|
96
|
-
"Software"), to deal with the Software without restriction, including
|
|
97
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
|
98
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
|
99
|
-
permit persons to whom the Software is furnished to do so, subject to
|
|
100
|
-
the following conditions:
|
|
101
|
-
|
|
102
|
-
Redistributions of source code must retain the above copyright
|
|
103
|
-
notice, this list of conditions and the following disclaimers.
|
|
104
|
-
|
|
105
|
-
Redistributions in binary form must reproduce the above
|
|
106
|
-
copyright notice, this list of conditions and the following disclaimers
|
|
107
|
-
in the documentation and/or other materials provided with the
|
|
108
|
-
distribution.
|
|
109
|
-
|
|
110
|
-
Neither the names of Mozilla,
|
|
111
|
-
nor the names of its contributors may be used to endorse
|
|
112
|
-
or promote products derived from this Software without specific prior
|
|
113
|
-
written permission.
|
|
114
|
-
|
|
115
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
116
|
-
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
117
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
118
|
-
IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR
|
|
119
|
-
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
120
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
121
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
|
|
122
|
-
"""
|
package/package.json
CHANGED
|
@@ -1,69 +1,73 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
2
|
+
"name": "@zenfs/core",
|
|
3
|
+
"version": "0.4.1",
|
|
4
|
+
"description": "A filesystem in your browser",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"filesystem",
|
|
9
|
+
"node",
|
|
10
|
+
"storage"
|
|
11
|
+
],
|
|
12
|
+
"bin": {
|
|
13
|
+
"make-index": "scripts/make-index.js"
|
|
14
|
+
},
|
|
15
|
+
"type": "module",
|
|
16
|
+
"homepage": "https://github.com/zen-fs/core",
|
|
17
|
+
"author": "James P. <jp@drvortex.dev> (https://drvortex.dev)",
|
|
18
|
+
"contributors": [
|
|
19
|
+
"John Vilk <jvilk@cs.umass.edu>"
|
|
20
|
+
],
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/zen-fs/core.git"
|
|
25
|
+
},
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/zen-fs/core/issues"
|
|
28
|
+
},
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">= 18"
|
|
31
|
+
},
|
|
32
|
+
"exports": {
|
|
33
|
+
".": "./dist/index.js",
|
|
34
|
+
"./*": "./dist/*"
|
|
35
|
+
},
|
|
36
|
+
"typesVersions": {
|
|
37
|
+
"*": {
|
|
38
|
+
"*": [
|
|
39
|
+
"./dist/*"
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"format": "prettier --write src test",
|
|
45
|
+
"format:check": "prettier --check src test",
|
|
46
|
+
"lint": "eslint src test && tsc -p tsconfig.json --noEmit",
|
|
47
|
+
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules npx jest",
|
|
48
|
+
"build": "node scripts/build.js",
|
|
49
|
+
"build:docs": "typedoc --out docs --name ZenFS src/index.ts",
|
|
50
|
+
"dev": "node scripts/build.js --watch",
|
|
51
|
+
"prepublishOnly": "npm run build"
|
|
52
|
+
},
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"@types/node": "^14.0.0",
|
|
55
|
+
"@types/readable-stream": "^4.0.10",
|
|
56
|
+
"minimatch": "^9.0.3",
|
|
57
|
+
"readable-stream": "^4.5.2"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@jest/globals": "^29.5.0",
|
|
61
|
+
"@types/jest": "^29.5.1",
|
|
62
|
+
"@typescript-eslint/eslint-plugin": "^5.55.0",
|
|
63
|
+
"@typescript-eslint/parser": "^5.55.0",
|
|
64
|
+
"cross-env": "^7.0.3",
|
|
65
|
+
"esbuild": "^0.17.18",
|
|
66
|
+
"eslint": "^8.36.0",
|
|
67
|
+
"jest": "^29.5.0",
|
|
68
|
+
"prettier": "^2.8.7",
|
|
69
|
+
"ts-jest": "^29.1.0",
|
|
70
|
+
"typedoc": "^0.25.1",
|
|
71
|
+
"typescript": "^4.9.5"
|
|
72
|
+
}
|
|
69
73
|
}
|
package/readme.md
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
# ZenFS
|
|
2
2
|
|
|
3
|
-
ZenFS is
|
|
3
|
+
ZenFS is a file system that emulates the [Node JS file system API](http://nodejs.org/api/fs.html).
|
|
4
|
+
|
|
5
|
+
It works using a system of backends, which are used by ZenFS to store and retrieve data. ZenFS can also integrate nicely with other tools.
|
|
6
|
+
|
|
7
|
+
ZenFS is a fork of [BrowserFS](https://github.com/jvilk/BrowserFS).
|
|
4
8
|
|
|
5
9
|
## Backends
|
|
6
10
|
|
|
@@ -33,7 +37,7 @@ npm install @zenfs/core
|
|
|
33
37
|
```js
|
|
34
38
|
import fs from '@zenfs/core';
|
|
35
39
|
|
|
36
|
-
fs.writeFileSync('/test.txt', 'Cool, I can do this in
|
|
40
|
+
fs.writeFileSync('/test.txt', 'Cool, I can do this in any JS environment (including browsers)!');
|
|
37
41
|
|
|
38
42
|
const contents = fs.readFileSync('/test.txt', 'utf-8');
|
|
39
43
|
console.log(contents);
|
|
@@ -66,9 +70,9 @@ await configure({
|
|
|
66
70
|
> [!TIP]
|
|
67
71
|
> When configuring a mount point, you can pass in
|
|
68
72
|
>
|
|
69
|
-
> 1. A
|
|
70
|
-
> 2.
|
|
71
|
-
> 3.
|
|
73
|
+
> 1. A `Backend` object, if the backend has no required options
|
|
74
|
+
> 2. An object that has the options accepted by the backend and a `backend` property which is a `Backend` object
|
|
75
|
+
> 3. A `FileSystem` instance (_not recommended_)
|
|
72
76
|
|
|
73
77
|
Here is an example that mounts the `Storage` backend from `@zenfs/dom` on `/`:
|
|
74
78
|
|