@zenfs/core 1.0.5 → 1.0.7
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/backends/file_index.d.ts +1 -1
- package/dist/backends/file_index.js +1 -1
- package/dist/utils.js +4 -4
- package/package.json +4 -7
- package/readme.md +6 -4
- package/src/backends/file_index.ts +1 -1
- package/src/utils.ts +6 -4
- package/dist/browser.min.js +0 -22
- package/dist/browser.min.js.map +0 -7
- package/scripts/build.js +0 -83
package/dist/utils.js
CHANGED
|
@@ -87,6 +87,7 @@ export function levenshtein(a, b) {
|
|
|
87
87
|
* @hidden
|
|
88
88
|
*/
|
|
89
89
|
export const setImmediate = typeof globalThis.setImmediate == 'function' ? globalThis.setImmediate : (cb) => setTimeout(cb, 0);
|
|
90
|
+
const encoder = new TextEncoder();
|
|
90
91
|
/**
|
|
91
92
|
* Encodes a string into a buffer
|
|
92
93
|
* @internal
|
|
@@ -95,8 +96,9 @@ export function encode(input) {
|
|
|
95
96
|
if (typeof input != 'string') {
|
|
96
97
|
throw new ErrnoError(Errno.EINVAL, 'Can not encode a non-string');
|
|
97
98
|
}
|
|
98
|
-
return
|
|
99
|
+
return encoder.encode(input);
|
|
99
100
|
}
|
|
101
|
+
const decoder = new TextDecoder();
|
|
100
102
|
/**
|
|
101
103
|
* Decodes a string from a buffer
|
|
102
104
|
* @internal
|
|
@@ -105,9 +107,7 @@ export function decode(input) {
|
|
|
105
107
|
if (!(input instanceof Uint8Array)) {
|
|
106
108
|
throw new ErrnoError(Errno.EINVAL, 'Can not decode a non-Uint8Array');
|
|
107
109
|
}
|
|
108
|
-
return
|
|
109
|
-
.map(char => String.fromCharCode(char))
|
|
110
|
-
.join('');
|
|
110
|
+
return decoder.decode(input);
|
|
111
111
|
}
|
|
112
112
|
/**
|
|
113
113
|
* Decodes a directory listing
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zenfs/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "A filesystem, anywhere",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -10,8 +10,7 @@
|
|
|
10
10
|
"storage"
|
|
11
11
|
],
|
|
12
12
|
"bin": {
|
|
13
|
-
"make-index": "scripts/make-index.js"
|
|
14
|
-
"build": "scripts/build.js"
|
|
13
|
+
"make-index": "scripts/make-index.js"
|
|
15
14
|
},
|
|
16
15
|
"files": [
|
|
17
16
|
"dist",
|
|
@@ -47,9 +46,9 @@
|
|
|
47
46
|
"scripts": {
|
|
48
47
|
"format": "prettier --write .",
|
|
49
48
|
"format:check": "prettier --check .",
|
|
50
|
-
"lint": "
|
|
49
|
+
"lint": "eslint src tests",
|
|
51
50
|
"test": "tsx --test --experimental-test-coverage",
|
|
52
|
-
"build": "
|
|
51
|
+
"build": "tsc -p tsconfig.json",
|
|
53
52
|
"build:docs": "typedoc",
|
|
54
53
|
"dev": "npm run build -- --watch",
|
|
55
54
|
"prepublishOnly": "npm run build"
|
|
@@ -70,9 +69,7 @@
|
|
|
70
69
|
},
|
|
71
70
|
"devDependencies": {
|
|
72
71
|
"@eslint/js": "^9.8.0",
|
|
73
|
-
"@fal-works/esbuild-plugin-global-externals": "^2.1.2",
|
|
74
72
|
"@types/eslint__js": "^8.42.3",
|
|
75
|
-
"esbuild": "^0.21.0",
|
|
76
73
|
"eslint": "^9.8.0",
|
|
77
74
|
"globals": "^15.9.0",
|
|
78
75
|
"lint-staged": "^15.2.7",
|
package/readme.md
CHANGED
|
@@ -4,8 +4,6 @@ ZenFS is a file system that emulates the [NodeJS filesystem API](http://nodejs.o
|
|
|
4
4
|
|
|
5
5
|
It works using a system of backends, which are used by ZenFS to store and retrieve data. ZenFS can also integrate with other tools.
|
|
6
6
|
|
|
7
|
-
ZenFS is a fork of [BrowserFS](https://github.com/jvilk/BrowserFS). If you are using ZenFS in a research paper, you may want to [cite BrowserFS](https://github.com/jvilk/BrowserFS#citing).
|
|
8
|
-
|
|
9
7
|
## Backends
|
|
10
8
|
|
|
11
9
|
ZenFS is modular and extensible. The core includes some built-in backends:
|
|
@@ -32,7 +30,7 @@ npm install @zenfs/core
|
|
|
32
30
|
> [!NOTE]
|
|
33
31
|
> The examples are written in ESM.
|
|
34
32
|
> If you are using CJS, you can `require` the package.
|
|
35
|
-
> If using a browser environment
|
|
33
|
+
> If using a browser environment, you can use a `<script>` with `type=module` (you may need to use import maps)
|
|
36
34
|
|
|
37
35
|
```js
|
|
38
36
|
import fs from '@zenfs/core'; // You can also use the named export, `fs`
|
|
@@ -105,7 +103,7 @@ await configureSingle({ backend: IndexedDB });
|
|
|
105
103
|
|
|
106
104
|
const exists = await exists('/myfile.txt');
|
|
107
105
|
if (!exists) {
|
|
108
|
-
await writeFile('/myfile.txt', 'Lots of
|
|
106
|
+
await writeFile('/myfile.txt', 'Lots of persistent data');
|
|
109
107
|
}
|
|
110
108
|
```
|
|
111
109
|
|
|
@@ -162,3 +160,7 @@ ZenFS exports a drop-in for Node's `fs` module (up to the version of `@types/nod
|
|
|
162
160
|
### Testing
|
|
163
161
|
|
|
164
162
|
Run unit tests with `npm test`.
|
|
163
|
+
|
|
164
|
+
### BrowserFS Fork
|
|
165
|
+
|
|
166
|
+
ZenFS is a fork of [BrowserFS](https://github.com/jvilk/BrowserFS). If you are using ZenFS in a research paper, you may want to [cite BrowserFS](https://github.com/jvilk/BrowserFS#citing).
|
package/src/utils.ts
CHANGED
|
@@ -117,6 +117,8 @@ export function levenshtein(a: string, b: string): number {
|
|
|
117
117
|
*/
|
|
118
118
|
export const setImmediate = typeof globalThis.setImmediate == 'function' ? globalThis.setImmediate : (cb: () => unknown) => setTimeout(cb, 0);
|
|
119
119
|
|
|
120
|
+
const encoder = new TextEncoder();
|
|
121
|
+
|
|
120
122
|
/**
|
|
121
123
|
* Encodes a string into a buffer
|
|
122
124
|
* @internal
|
|
@@ -125,9 +127,11 @@ export function encode(input: string): Uint8Array {
|
|
|
125
127
|
if (typeof input != 'string') {
|
|
126
128
|
throw new ErrnoError(Errno.EINVAL, 'Can not encode a non-string');
|
|
127
129
|
}
|
|
128
|
-
return
|
|
130
|
+
return encoder.encode(input);
|
|
129
131
|
}
|
|
130
132
|
|
|
133
|
+
const decoder = new TextDecoder();
|
|
134
|
+
|
|
131
135
|
/**
|
|
132
136
|
* Decodes a string from a buffer
|
|
133
137
|
* @internal
|
|
@@ -137,9 +141,7 @@ export function decode(input?: Uint8Array): string {
|
|
|
137
141
|
throw new ErrnoError(Errno.EINVAL, 'Can not decode a non-Uint8Array');
|
|
138
142
|
}
|
|
139
143
|
|
|
140
|
-
return
|
|
141
|
-
.map(char => String.fromCharCode(char))
|
|
142
|
-
.join('');
|
|
144
|
+
return decoder.decode(input);
|
|
143
145
|
}
|
|
144
146
|
|
|
145
147
|
/**
|