@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.
@@ -17,7 +17,7 @@ export declare const version = 1;
17
17
  */
18
18
  export declare class Index extends Map<string, Stats> {
19
19
  /**
20
- * Convience method
20
+ * Convenience method
21
21
  */
22
22
  files(): Map<string, Stats>;
23
23
  /**
@@ -14,7 +14,7 @@ export const version = 1;
14
14
  */
15
15
  export class Index extends Map {
16
16
  /**
17
- * Convience method
17
+ * Convenience method
18
18
  */
19
19
  files() {
20
20
  const files = new Map();
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 new Uint8Array(Array.from(input).map(char => char.charCodeAt(0)));
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 Array.from(input)
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.5",
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": "tsc -p tsconfig.json --noEmit && eslint src tests",
49
+ "lint": "eslint src tests",
51
50
  "test": "tsx --test --experimental-test-coverage",
52
- "build": "node scripts/build.js --globalName=ZenFS --entry src/index.ts",
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 without support for `type=module` in `script` tags, you can add a `script` tag to your HTML pointing to the `browser.min.js` and use ZenFS with the global `ZenFS` object.
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 persistant data');
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).
@@ -27,7 +27,7 @@ export const version = 1;
27
27
  */
28
28
  export class Index extends Map<string, Stats> {
29
29
  /**
30
- * Convience method
30
+ * Convenience method
31
31
  */
32
32
  public files(): Map<string, Stats> {
33
33
  const files = new Map<string, Stats>();
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 new Uint8Array(Array.from(input).map(char => char.charCodeAt(0)));
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 Array.from(input)
141
- .map(char => String.fromCharCode(char))
142
- .join('');
144
+ return decoder.decode(input);
143
145
  }
144
146
 
145
147
  /**