@zenfs/core 0.2.2 → 0.3.0

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/file.d.ts CHANGED
@@ -1,5 +1,5 @@
1
+ import type { FileSystem } from './filesystem.js';
1
2
  import { Stats, type FileType } from './stats.js';
2
- import { FileSystem, type SyncFileSystem } from './filesystem.js';
3
3
  declare global {
4
4
  interface ArrayBuffer {
5
5
  readonly resizable: boolean;
@@ -419,7 +419,7 @@ export declare abstract class PreloadFile<T extends FileSystem> extends File {
419
419
  /**
420
420
  * For synchronous file systems
421
421
  */
422
- export declare class SyncFile<FS extends SyncFileSystem> extends PreloadFile<FS> {
422
+ export declare class SyncFile<FS extends FileSystem> extends PreloadFile<FS> {
423
423
  constructor(_fs: FS, _path: string, _flag: FileFlag, _stat: Stats, contents?: Uint8Array);
424
424
  sync(): Promise<void>;
425
425
  syncSync(): void;
package/dist/file.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ApiError, ErrorCode } from './ApiError.js';
2
- import { Stats } from './stats.js';
3
- import { O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, O_EXCL, O_TRUNC, O_APPEND, O_SYNC, S_IFMT } from './emulation/constants.js';
2
+ import { O_APPEND, O_CREAT, O_EXCL, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY, S_IFMT } from './emulation/constants.js';
4
3
  import { size_max } from './inode.js';
4
+ import { Stats } from './stats.js';
5
5
  export var ActionType;
6
6
  (function (ActionType) {
7
7
  // Indicates that the code should not do anything.
@@ -46,7 +46,6 @@ export interface FileSystemMetadata {
46
46
  * - All arguments are present. Any optional arguments at the Node API level have been passed in with their default values.
47
47
  */
48
48
  export declare abstract class FileSystem {
49
- static get Name(): string;
50
49
  get metadata(): FileSystemMetadata;
51
50
  constructor(options?: object);
52
51
  abstract ready(): Promise<this>;
@@ -156,10 +155,15 @@ export declare abstract class FileSystem {
156
155
  }
157
156
  /**
158
157
  * Implements the asynchronous API in terms of the synchronous API.
158
+ *
159
+ * @example ```ts
160
+ * class SyncFS extends Sync(FileSystem) {}
161
+ * ```
159
162
  */
160
- export declare abstract class SyncFileSystem extends FileSystem {
161
- get metadata(): FileSystemMetadata;
162
- ready(): Promise<this>;
163
+ export declare function Sync<T extends abstract new (...args: any[]) => FileSystem>(FS: T): (abstract new (...args: any[]) => {
164
+ readonly metadata: FileSystemMetadata;
165
+ ready(): Promise<any>;
166
+ exists(path: string, cred: Cred): Promise<boolean>;
163
167
  rename(oldPath: string, newPath: string, cred: Cred): Promise<void>;
164
168
  stat(path: string, cred: Cred): Promise<Stats>;
165
169
  createFile(path: string, flag: FileFlag, mode: number, cred: Cred): Promise<File>;
@@ -170,21 +174,61 @@ export declare abstract class SyncFileSystem extends FileSystem {
170
174
  readdir(path: string, cred: Cred): Promise<string[]>;
171
175
  link(srcpath: string, dstpath: string, cred: Cred): Promise<void>;
172
176
  sync(path: string, data: Uint8Array, stats: Readonly<Stats>): Promise<void>;
173
- }
174
- export declare abstract class ReadonlySyncFileSystem extends SyncFileSystem {
177
+ /**
178
+ * Synchronous rename.
179
+ */
175
180
  renameSync(oldPath: string, newPath: string, cred: Cred): void;
181
+ /**
182
+ * Synchronous `stat`.
183
+ */
184
+ statSync(path: string, cred: Cred): Stats;
185
+ /**
186
+ * Opens the file at path p with the given flag. The file must exist.
187
+ * @param p The path to open.
188
+ * @param flag The flag to use when opening the file.
189
+ * @return A File object corresponding to the opened file.
190
+ */
191
+ openFileSync(path: string, flag: FileFlag, cred: Cred): File;
192
+ /**
193
+ * Create the file at path p with the given mode. Then, open it with the given
194
+ * flag.
195
+ */
176
196
  createFileSync(path: string, flag: FileFlag, mode: number, cred: Cred): File;
197
+ /**
198
+ * Synchronous `unlink`.
199
+ */
177
200
  unlinkSync(path: string, cred: Cred): void;
201
+ /**
202
+ * Synchronous `rmdir`.
203
+ */
178
204
  rmdirSync(path: string, cred: Cred): void;
205
+ /**
206
+ * Synchronous `mkdir`.
207
+ * @param mode Mode to make the directory using. Can be ignored if
208
+ * the filesystem doesn't support permissions.
209
+ */
179
210
  mkdirSync(path: string, mode: number, cred: Cred): void;
211
+ /**
212
+ * Synchronous `readdir`. Reads the contents of a directory.
213
+ */
214
+ readdirSync(path: string, cred: Cred): string[];
215
+ /**
216
+ * Test whether or not the given path exists by checking with the file system.
217
+ */
218
+ existsSync(path: string, cred: Cred): boolean;
219
+ /**
220
+ * Synchronous `link`.
221
+ */
180
222
  linkSync(srcpath: string, dstpath: string, cred: Cred): void;
223
+ /**
224
+ * Synchronize the data and stats for path synchronously
225
+ */
181
226
  syncSync(path: string, data: Uint8Array, stats: Readonly<Stats>): void;
182
- }
183
- export declare abstract class AsyncFileSystem extends FileSystem {
227
+ }) & T;
228
+ export declare function Async<T extends abstract new (...args: any[]) => FileSystem>(FS: T): (abstract new (...args: any[]) => {
184
229
  renameSync(oldPath: string, newPath: string, cred: Cred): void;
185
230
  statSync(path: string, cred: Cred): Stats;
186
231
  createFileSync(path: string, flag: FileFlag, mode: number, cred: Cred): File;
187
- openSync(path: string, flags: FileFlag, mode: number, cred: Cred): File;
188
232
  openFileSync(path: string, flag: FileFlag, cred: Cred): File;
189
233
  unlinkSync(path: string, cred: Cred): void;
190
234
  rmdirSync(path: string, cred: Cred): void;
@@ -192,13 +236,121 @@ export declare abstract class AsyncFileSystem extends FileSystem {
192
236
  readdirSync(path: string, cred: Cred): string[];
193
237
  linkSync(srcpath: string, dstpath: string, cred: Cred): void;
194
238
  syncSync(path: string, data: Uint8Array, stats: Readonly<Stats>): void;
195
- }
196
- export declare abstract class ReadonlyAsyncFileSystem extends AsyncFileSystem {
239
+ readonly metadata: FileSystemMetadata;
240
+ ready(): Promise<any>;
241
+ /**
242
+ * Asynchronous rename. No arguments other than a possible exception
243
+ * are given to the completion callback.
244
+ */
245
+ rename(oldPath: string, newPath: string, cred: Cred): Promise<void>;
246
+ /**
247
+ * Asynchronous `stat`.
248
+ */
249
+ stat(path: string, cred: Cred): Promise<Stats>;
250
+ /**
251
+ * Opens the file at path p with the given flag. The file must exist.
252
+ * @param p The path to open.
253
+ * @param flag The flag to use when opening the file.
254
+ */
255
+ openFile(path: string, flag: FileFlag, cred: Cred): Promise<File>;
256
+ /**
257
+ * Create the file at path p with the given mode. Then, open it with the given
258
+ * flag.
259
+ */
260
+ createFile(path: string, flag: FileFlag, mode: number, cred: Cred): Promise<File>;
261
+ /**
262
+ * Asynchronous `unlink`.
263
+ */
264
+ unlink(path: string, cred: Cred): Promise<void>;
265
+ /**
266
+ * Asynchronous `rmdir`.
267
+ */
268
+ rmdir(path: string, cred: Cred): Promise<void>;
269
+ /**
270
+ * Asynchronous `mkdir`.
271
+ * @param mode Mode to make the directory using. Can be ignored if
272
+ * the filesystem doesn't support permissions.
273
+ */
274
+ mkdir(path: string, mode: number, cred: Cred): Promise<void>;
275
+ /**
276
+ * Asynchronous `readdir`. Reads the contents of a directory.
277
+ *
278
+ * The callback gets two arguments `(err, files)` where `files` is an array of
279
+ * the names of the files in the directory excluding `'.'` and `'..'`.
280
+ */
281
+ readdir(path: string, cred: Cred): Promise<string[]>;
282
+ /**
283
+ * Test whether or not the given path exists by checking with the file system.
284
+ */
285
+ exists(path: string, cred: Cred): Promise<boolean>;
286
+ /**
287
+ * Test whether or not the given path exists by checking with the file system.
288
+ */
289
+ existsSync(path: string, cred: Cred): boolean;
290
+ /**
291
+ * Asynchronous `link`.
292
+ */
293
+ link(srcpath: string, dstpath: string, cred: Cred): Promise<void>;
294
+ /**
295
+ * Synchronize the data and stats for path asynchronously
296
+ */
297
+ sync(path: string, data: Uint8Array, stats: Readonly<Stats>): Promise<void>;
298
+ }) & T;
299
+ export declare function Readonly<T extends abstract new (...args: any[]) => FileSystem>(FS: T): (abstract new (...args: any[]) => {
197
300
  rename(oldPath: string, newPath: string, cred: Cred): Promise<void>;
301
+ renameSync(oldPath: string, newPath: string, cred: Cred): void;
198
302
  createFile(path: string, flag: FileFlag, mode: number, cred: Cred): Promise<File>;
303
+ createFileSync(path: string, flag: FileFlag, mode: number, cred: Cred): File;
199
304
  unlink(path: string, cred: Cred): Promise<void>;
305
+ unlinkSync(path: string, cred: Cred): void;
200
306
  rmdir(path: string, cred: Cred): Promise<void>;
307
+ rmdirSync(path: string, cred: Cred): void;
201
308
  mkdir(path: string, mode: number, cred: Cred): Promise<void>;
309
+ mkdirSync(path: string, mode: number, cred: Cred): void;
202
310
  link(srcpath: string, dstpath: string, cred: Cred): Promise<void>;
311
+ linkSync(srcpath: string, dstpath: string, cred: Cred): void;
203
312
  sync(path: string, data: Uint8Array, stats: Readonly<Stats>): Promise<void>;
204
- }
313
+ syncSync(path: string, data: Uint8Array, stats: Readonly<Stats>): void;
314
+ readonly metadata: FileSystemMetadata;
315
+ ready(): Promise<any>;
316
+ /**
317
+ * Asynchronous `stat`.
318
+ */
319
+ stat(path: string, cred: Cred): Promise<Stats>;
320
+ /**
321
+ * Synchronous `stat`.
322
+ */
323
+ statSync(path: string, cred: Cred): Stats;
324
+ /**
325
+ * Opens the file at path p with the given flag. The file must exist.
326
+ * @param p The path to open.
327
+ * @param flag The flag to use when opening the file.
328
+ */
329
+ openFile(path: string, flag: FileFlag, cred: Cred): Promise<File>;
330
+ /**
331
+ * Opens the file at path p with the given flag. The file must exist.
332
+ * @param p The path to open.
333
+ * @param flag The flag to use when opening the file.
334
+ * @return A File object corresponding to the opened file.
335
+ */
336
+ openFileSync(path: string, flag: FileFlag, cred: Cred): File;
337
+ /**
338
+ * Asynchronous `readdir`. Reads the contents of a directory.
339
+ *
340
+ * The callback gets two arguments `(err, files)` where `files` is an array of
341
+ * the names of the files in the directory excluding `'.'` and `'..'`.
342
+ */
343
+ readdir(path: string, cred: Cred): Promise<string[]>;
344
+ /**
345
+ * Synchronous `readdir`. Reads the contents of a directory.
346
+ */
347
+ readdirSync(path: string, cred: Cred): string[];
348
+ /**
349
+ * Test whether or not the given path exists by checking with the file system.
350
+ */
351
+ exists(path: string, cred: Cred): Promise<boolean>;
352
+ /**
353
+ * Test whether or not the given path exists by checking with the file system.
354
+ */
355
+ existsSync(path: string, cred: Cred): boolean;
356
+ }) & T;
@@ -1,5 +1,3 @@
1
- /* eslint-disable @typescript-eslint/no-unused-vars */
2
- // disable no-unused-vars since BaseFileSystem uses them a lot
3
1
  import { ApiError, ErrorCode } from './ApiError.js';
4
2
  /**
5
3
  * Structure for a filesystem. All ZenFS FileSystems must implement this.
@@ -12,9 +10,6 @@ import { ApiError, ErrorCode } from './ApiError.js';
12
10
  * - All arguments are present. Any optional arguments at the Node API level have been passed in with their default values.
13
11
  */
14
12
  export class FileSystem {
15
- static get Name() {
16
- return this.name;
17
- }
18
13
  get metadata() {
19
14
  return {
20
15
  name: this.constructor.name,
@@ -25,6 +20,7 @@ export class FileSystem {
25
20
  freeSpace: 0,
26
21
  };
27
22
  }
23
+ /* eslint-disable-next-line @typescript-eslint/no-unused-vars */
28
24
  constructor(options) {
29
25
  // unused
30
26
  }
@@ -55,123 +51,140 @@ export class FileSystem {
55
51
  }
56
52
  /**
57
53
  * Implements the asynchronous API in terms of the synchronous API.
54
+ *
55
+ * @example ```ts
56
+ * class SyncFS extends Sync(FileSystem) {}
57
+ * ```
58
58
  */
59
- export class SyncFileSystem extends FileSystem {
60
- get metadata() {
61
- return { ...super.metadata, synchronous: true };
62
- }
63
- async ready() {
64
- return this;
65
- }
66
- async rename(oldPath, newPath, cred) {
67
- return this.renameSync(oldPath, newPath, cred);
68
- }
69
- async stat(path, cred) {
70
- return this.statSync(path, cred);
71
- }
72
- async createFile(path, flag, mode, cred) {
73
- return this.createFileSync(path, flag, mode, cred);
74
- }
75
- async openFile(path, flag, cred) {
76
- return this.openFileSync(path, flag, cred);
77
- }
78
- async unlink(path, cred) {
79
- return this.unlinkSync(path, cred);
80
- }
81
- async rmdir(path, cred) {
82
- return this.rmdirSync(path, cred);
83
- }
84
- async mkdir(path, mode, cred) {
85
- return this.mkdirSync(path, mode, cred);
86
- }
87
- async readdir(path, cred) {
88
- return this.readdirSync(path, cred);
89
- }
90
- async link(srcpath, dstpath, cred) {
91
- return this.linkSync(srcpath, dstpath, cred);
92
- }
93
- async sync(path, data, stats) {
94
- return this.syncSync(path, data, stats);
95
- }
96
- }
97
- export class ReadonlySyncFileSystem extends SyncFileSystem {
98
- renameSync(oldPath, newPath, cred) {
99
- throw new ApiError(ErrorCode.EROFS);
100
- }
101
- createFileSync(path, flag, mode, cred) {
102
- throw new ApiError(ErrorCode.EROFS);
103
- }
104
- unlinkSync(path, cred) {
105
- throw new ApiError(ErrorCode.EROFS);
106
- }
107
- rmdirSync(path, cred) {
108
- throw new ApiError(ErrorCode.EROFS);
109
- }
110
- mkdirSync(path, mode, cred) {
111
- throw new ApiError(ErrorCode.EROFS);
112
- }
113
- linkSync(srcpath, dstpath, cred) {
114
- throw new ApiError(ErrorCode.EROFS);
115
- }
116
- syncSync(path, data, stats) {
117
- throw new ApiError(ErrorCode.EROFS);
59
+ export function Sync(FS) {
60
+ /**
61
+ * Implements the asynchronous API in terms of the synchronous API.
62
+ */
63
+ class SyncFileSystem extends FS {
64
+ get metadata() {
65
+ return { ...super.metadata, synchronous: true };
66
+ }
67
+ async ready() {
68
+ return this;
69
+ }
70
+ async exists(path, cred) {
71
+ return this.existsSync(path, cred);
72
+ }
73
+ async rename(oldPath, newPath, cred) {
74
+ return this.renameSync(oldPath, newPath, cred);
75
+ }
76
+ async stat(path, cred) {
77
+ return this.statSync(path, cred);
78
+ }
79
+ async createFile(path, flag, mode, cred) {
80
+ return this.createFileSync(path, flag, mode, cred);
81
+ }
82
+ async openFile(path, flag, cred) {
83
+ return this.openFileSync(path, flag, cred);
84
+ }
85
+ async unlink(path, cred) {
86
+ return this.unlinkSync(path, cred);
87
+ }
88
+ async rmdir(path, cred) {
89
+ return this.rmdirSync(path, cred);
90
+ }
91
+ async mkdir(path, mode, cred) {
92
+ return this.mkdirSync(path, mode, cred);
93
+ }
94
+ async readdir(path, cred) {
95
+ return this.readdirSync(path, cred);
96
+ }
97
+ async link(srcpath, dstpath, cred) {
98
+ return this.linkSync(srcpath, dstpath, cred);
99
+ }
100
+ async sync(path, data, stats) {
101
+ return this.syncSync(path, data, stats);
102
+ }
118
103
  }
104
+ return SyncFileSystem;
119
105
  }
120
- export class AsyncFileSystem extends FileSystem {
121
- renameSync(oldPath, newPath, cred) {
122
- throw new ApiError(ErrorCode.ENOTSUP);
123
- }
124
- statSync(path, cred) {
125
- throw new ApiError(ErrorCode.ENOTSUP);
126
- }
127
- createFileSync(path, flag, mode, cred) {
128
- throw new ApiError(ErrorCode.ENOTSUP);
129
- }
130
- openSync(path, flags, mode, cred) {
131
- throw new ApiError(ErrorCode.ENOTSUP);
132
- }
133
- openFileSync(path, flag, cred) {
134
- throw new ApiError(ErrorCode.ENOTSUP);
135
- }
136
- unlinkSync(path, cred) {
137
- throw new ApiError(ErrorCode.ENOTSUP);
138
- }
139
- rmdirSync(path, cred) {
140
- throw new ApiError(ErrorCode.ENOTSUP);
141
- }
142
- mkdirSync(path, mode, cred) {
143
- throw new ApiError(ErrorCode.ENOTSUP);
144
- }
145
- readdirSync(path, cred) {
146
- throw new ApiError(ErrorCode.ENOTSUP);
147
- }
148
- linkSync(srcpath, dstpath, cred) {
149
- throw new ApiError(ErrorCode.ENOTSUP);
150
- }
151
- syncSync(path, data, stats) {
152
- throw new ApiError(ErrorCode.ENOTSUP);
106
+ export function Async(FS) {
107
+ class AsyncFileSystem extends FS {
108
+ /* eslint-disable @typescript-eslint/no-unused-vars */
109
+ renameSync(oldPath, newPath, cred) {
110
+ throw new ApiError(ErrorCode.ENOTSUP);
111
+ }
112
+ statSync(path, cred) {
113
+ throw new ApiError(ErrorCode.ENOTSUP);
114
+ }
115
+ createFileSync(path, flag, mode, cred) {
116
+ throw new ApiError(ErrorCode.ENOTSUP);
117
+ }
118
+ openFileSync(path, flag, cred) {
119
+ throw new ApiError(ErrorCode.ENOTSUP);
120
+ }
121
+ unlinkSync(path, cred) {
122
+ throw new ApiError(ErrorCode.ENOTSUP);
123
+ }
124
+ rmdirSync(path, cred) {
125
+ throw new ApiError(ErrorCode.ENOTSUP);
126
+ }
127
+ mkdirSync(path, mode, cred) {
128
+ throw new ApiError(ErrorCode.ENOTSUP);
129
+ }
130
+ readdirSync(path, cred) {
131
+ throw new ApiError(ErrorCode.ENOTSUP);
132
+ }
133
+ linkSync(srcpath, dstpath, cred) {
134
+ throw new ApiError(ErrorCode.ENOTSUP);
135
+ }
136
+ syncSync(path, data, stats) {
137
+ throw new ApiError(ErrorCode.ENOTSUP);
138
+ }
153
139
  }
140
+ /* eslint-enable @typescript-eslint/no-unused-vars */
141
+ return AsyncFileSystem;
154
142
  }
155
- export class ReadonlyAsyncFileSystem extends AsyncFileSystem {
156
- async rename(oldPath, newPath, cred) {
157
- throw new ApiError(ErrorCode.EROFS);
158
- }
159
- async createFile(path, flag, mode, cred) {
160
- throw new ApiError(ErrorCode.EROFS);
161
- }
162
- async unlink(path, cred) {
163
- throw new ApiError(ErrorCode.EROFS);
164
- }
165
- async rmdir(path, cred) {
166
- throw new ApiError(ErrorCode.EROFS);
167
- }
168
- async mkdir(path, mode, cred) {
169
- throw new ApiError(ErrorCode.EROFS);
170
- }
171
- async link(srcpath, dstpath, cred) {
172
- throw new ApiError(ErrorCode.EROFS);
173
- }
174
- async sync(path, data, stats) {
175
- throw new ApiError(ErrorCode.EROFS);
143
+ export function Readonly(FS) {
144
+ class ReadonlyFileSystem extends FS {
145
+ /* eslint-disable @typescript-eslint/no-unused-vars */
146
+ async rename(oldPath, newPath, cred) {
147
+ throw new ApiError(ErrorCode.EROFS);
148
+ }
149
+ renameSync(oldPath, newPath, cred) {
150
+ throw new ApiError(ErrorCode.EROFS);
151
+ }
152
+ async createFile(path, flag, mode, cred) {
153
+ throw new ApiError(ErrorCode.EROFS);
154
+ }
155
+ createFileSync(path, flag, mode, cred) {
156
+ throw new ApiError(ErrorCode.EROFS);
157
+ }
158
+ async unlink(path, cred) {
159
+ throw new ApiError(ErrorCode.EROFS);
160
+ }
161
+ unlinkSync(path, cred) {
162
+ throw new ApiError(ErrorCode.EROFS);
163
+ }
164
+ async rmdir(path, cred) {
165
+ throw new ApiError(ErrorCode.EROFS);
166
+ }
167
+ rmdirSync(path, cred) {
168
+ throw new ApiError(ErrorCode.EROFS);
169
+ }
170
+ async mkdir(path, mode, cred) {
171
+ throw new ApiError(ErrorCode.EROFS);
172
+ }
173
+ mkdirSync(path, mode, cred) {
174
+ throw new ApiError(ErrorCode.EROFS);
175
+ }
176
+ async link(srcpath, dstpath, cred) {
177
+ throw new ApiError(ErrorCode.EROFS);
178
+ }
179
+ linkSync(srcpath, dstpath, cred) {
180
+ throw new ApiError(ErrorCode.EROFS);
181
+ }
182
+ async sync(path, data, stats) {
183
+ throw new ApiError(ErrorCode.EROFS);
184
+ }
185
+ syncSync(path, data, stats) {
186
+ throw new ApiError(ErrorCode.EROFS);
187
+ }
176
188
  }
189
+ return ReadonlyFileSystem;
177
190
  }
package/dist/utils.d.ts CHANGED
@@ -1,14 +1,9 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
- /// <reference types="node" resolution-mode="require"/>
3
2
  import { FileSystem } from './filesystem.js';
4
3
  import { Cred } from './cred.js';
5
- import type { TextDecoder as _TextDecoder, TextEncoder as _TextEncoder } from 'node:util';
6
4
  declare global {
7
- function setImmediate(callback: () => unknown): void;
8
5
  function atob(data: string): string;
9
6
  function btoa(data: string): string;
10
- const TextDecoder: typeof _TextDecoder;
11
- const TextEncoder: typeof _TextEncoder;
12
7
  }
13
8
  /**
14
9
  * Synchronous recursive makedir.
@@ -30,7 +25,7 @@ export declare function toPromise(fn: (...fnArgs: unknown[]) => unknown): (...ar
30
25
  /**
31
26
  * @internal
32
27
  */
33
- export declare const setImmediate: typeof globalThis.setImmediate | ((cb: any) => NodeJS.Timeout);
28
+ export declare const setImmediate: (callback: () => unknown) => void;
34
29
  /**
35
30
  * Encodes a string into a buffer
36
31
  * @internal
package/dist/utils.js CHANGED
@@ -123,7 +123,7 @@ export const setImmediate = typeof globalThis.setImmediate == 'function' ? globa
123
123
  export function encode(input, encoding = 'utf8') {
124
124
  switch (encoding) {
125
125
  case 'ascii':
126
- return new TextEncoder().encode(input).map(v => v & 0x7f);
126
+ return new globalThis.TextEncoder().encode(input).map(v => v & 0x7f);
127
127
  case 'latin1':
128
128
  case 'binary':
129
129
  case 'utf8':
@@ -131,11 +131,11 @@ export function encode(input, encoding = 'utf8') {
131
131
  case 'base64':
132
132
  case 'base64url':
133
133
  case 'hex':
134
- return new TextEncoder().encode(input);
134
+ return new globalThis.TextEncoder().encode(input);
135
135
  case 'utf16le':
136
136
  case 'ucs2':
137
137
  case 'ucs-2':
138
- return new TextEncoder().encode(input).slice(0, -1);
138
+ return new globalThis.TextEncoder().encode(input).slice(0, -1);
139
139
  default:
140
140
  throw new ApiError(ErrorCode.EINVAL, 'Invalid encoding: ' + encoding);
141
141
  }
@@ -149,10 +149,10 @@ export function decode(input, encoding = 'utf8') {
149
149
  case 'ascii':
150
150
  case 'utf8':
151
151
  case 'utf-8':
152
- return new TextDecoder().decode(input);
152
+ return new globalThis.TextDecoder().decode(input);
153
153
  case 'latin1':
154
154
  case 'binary':
155
- return new TextDecoder('latin1').decode(input);
155
+ return new globalThis.TextDecoder('latin1').decode(input);
156
156
  case 'utf16le':
157
157
  case 'ucs2':
158
158
  case 'ucs-2':
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenfs/core",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "description": "A filesystem in your browser",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist",