@zenfs/core 0.0.12 → 0.2.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.
Files changed (54) hide show
  1. package/dist/ApiError.d.ts +52 -15
  2. package/dist/ApiError.js +77 -50
  3. package/dist/FileIndex.d.ts +32 -35
  4. package/dist/FileIndex.js +93 -109
  5. package/dist/backends/AsyncMirror.d.ts +42 -43
  6. package/dist/backends/AsyncMirror.js +154 -147
  7. package/dist/backends/AsyncStore.d.ts +29 -28
  8. package/dist/backends/AsyncStore.js +375 -482
  9. package/dist/backends/FolderAdapter.js +8 -19
  10. package/dist/backends/InMemory.d.ts +16 -13
  11. package/dist/backends/InMemory.js +29 -14
  12. package/dist/backends/Locked.d.ts +8 -28
  13. package/dist/backends/Locked.js +74 -224
  14. package/dist/backends/OverlayFS.d.ts +26 -34
  15. package/dist/backends/OverlayFS.js +303 -511
  16. package/dist/backends/SyncStore.d.ts +54 -72
  17. package/dist/backends/SyncStore.js +159 -161
  18. package/dist/backends/backend.d.ts +45 -29
  19. package/dist/backends/backend.js +83 -13
  20. package/dist/backends/index.d.ts +6 -7
  21. package/dist/backends/index.js +5 -6
  22. package/dist/browser.min.js +21 -6
  23. package/dist/browser.min.js.map +4 -4
  24. package/dist/emulation/callbacks.d.ts +119 -113
  25. package/dist/emulation/callbacks.js +129 -92
  26. package/dist/emulation/constants.js +1 -1
  27. package/dist/emulation/dir.d.ts +55 -0
  28. package/dist/emulation/dir.js +104 -0
  29. package/dist/emulation/fs.d.ts +1 -2
  30. package/dist/emulation/fs.js +0 -1
  31. package/dist/emulation/index.d.ts +3 -0
  32. package/dist/emulation/index.js +3 -0
  33. package/dist/emulation/promises.d.ts +265 -145
  34. package/dist/emulation/promises.js +526 -383
  35. package/dist/emulation/shared.d.ts +20 -6
  36. package/dist/emulation/shared.js +22 -23
  37. package/dist/emulation/streams.d.ts +102 -0
  38. package/dist/emulation/streams.js +55 -0
  39. package/dist/emulation/sync.d.ts +98 -69
  40. package/dist/emulation/sync.js +280 -133
  41. package/dist/file.d.ts +175 -173
  42. package/dist/file.js +257 -273
  43. package/dist/filesystem.d.ts +71 -244
  44. package/dist/filesystem.js +67 -472
  45. package/dist/index.d.ts +7 -44
  46. package/dist/index.js +22 -75
  47. package/dist/inode.d.ts +37 -28
  48. package/dist/inode.js +123 -65
  49. package/dist/stats.d.ts +91 -36
  50. package/dist/stats.js +138 -110
  51. package/dist/utils.d.ts +26 -13
  52. package/dist/utils.js +79 -107
  53. package/package.json +7 -4
  54. package/readme.md +2 -40
@@ -1,5 +1,6 @@
1
1
  import { ApiError, ErrorCode } from '../ApiError.js';
2
- import { nop, normalizeMode } from './shared.js';
2
+ import { BigIntStats } from '../stats.js';
3
+ import { fd2file, nop, normalizeMode } from './shared.js';
3
4
  import * as promises from './promises.js';
4
5
  import { R_OK } from './constants.js';
5
6
  import { decode, encode } from '../utils.js';
@@ -16,13 +17,10 @@ export function rename(oldPath, newPath, cb = nop) {
16
17
  .then(() => cb())
17
18
  .catch(cb);
18
19
  }
20
+ rename;
19
21
  /**
20
22
  * Test whether or not the given path exists by checking with the file system.
21
23
  * Then call the callback argument with either true or false.
22
- * @example Sample invocation
23
- * fs.exists('/etc/passwd', function (exists) {
24
- * util.debug(exists ? "it's there" : "no passwd!");
25
- * });
26
24
  * @param path
27
25
  * @param callback
28
26
  */
@@ -32,30 +30,23 @@ export function exists(path, cb = nop) {
32
30
  .then(cb)
33
31
  .catch(() => cb(false));
34
32
  }
35
- /**
36
- * Asynchronous `stat`.
37
- * @param path
38
- * @param callback
39
- */
40
- export function stat(path, cb = nop) {
33
+ exists;
34
+ export function stat(path, options, callback = nop) {
35
+ callback = typeof options == 'function' ? options : callback;
41
36
  promises
42
- .stat(path)
43
- .then(stats => cb(null, stats))
44
- .catch(cb);
37
+ .stat(path, typeof options != 'function' ? options : {})
38
+ .then(stats => callback(null, stats))
39
+ .catch(callback);
45
40
  }
46
- /**
47
- * Asynchronous `lstat`.
48
- * `lstat()` is identical to `stat()`, except that if path is a symbolic link,
49
- * then the link itself is stat-ed, not the file that it refers to.
50
- * @param path
51
- * @param callback
52
- */
53
- export function lstat(path, cb = nop) {
41
+ stat;
42
+ export function lstat(path, options, callback = nop) {
43
+ callback = typeof options == 'function' ? options : callback;
54
44
  promises
55
- .lstat(path)
56
- .then(stats => cb(null, stats))
57
- .catch(cb);
45
+ .lstat(path, typeof options != 'function' ? options : {})
46
+ .then(stats => callback(null, stats))
47
+ .catch(callback);
58
48
  }
49
+ lstat;
59
50
  export function truncate(path, arg2 = 0, cb = nop) {
60
51
  cb = typeof arg2 === 'function' ? arg2 : cb;
61
52
  const len = typeof arg2 === 'number' ? arg2 : 0;
@@ -64,6 +55,7 @@ export function truncate(path, arg2 = 0, cb = nop) {
64
55
  .then(() => cb())
65
56
  .catch(cb);
66
57
  }
58
+ truncate;
67
59
  /**
68
60
  * Asynchronous `unlink`.
69
61
  * @param path
@@ -75,79 +67,96 @@ export function unlink(path, cb = nop) {
75
67
  .then(() => cb())
76
68
  .catch(cb);
77
69
  }
70
+ unlink;
78
71
  export function open(path, flag, arg2, cb = nop) {
79
72
  const mode = normalizeMode(arg2, 0o644);
80
73
  cb = typeof arg2 === 'function' ? arg2 : cb;
81
74
  promises
82
75
  .open(path, flag, mode)
83
- .then(fd => cb(null, fd))
76
+ .then(handle => cb(null, handle.fd))
84
77
  .catch(cb);
85
78
  }
86
- export function readFile(filename, arg2 = {}, cb = nop) {
87
- cb = typeof arg2 === 'function' ? arg2 : cb;
88
- promises.readFile(filename, typeof arg2 === 'function' ? null : arg2);
79
+ open;
80
+ export function readFile(filename, options, cb = nop) {
81
+ cb = typeof options === 'function' ? options : cb;
82
+ promises
83
+ .readFile(filename, typeof options === 'function' ? null : options)
84
+ .then(data => cb(null, data))
85
+ .catch(cb);
89
86
  }
90
- export function writeFile(filename, data, arg3 = {}, cb = nop) {
87
+ readFile;
88
+ export function writeFile(filename, data, arg3, cb = nop) {
91
89
  cb = typeof arg3 === 'function' ? arg3 : cb;
92
- promises.writeFile(filename, data, typeof arg3 === 'function' ? undefined : arg3);
90
+ promises
91
+ .writeFile(filename, data, typeof arg3 != 'function' ? arg3 : null)
92
+ .then(() => cb(null))
93
+ .catch(cb);
93
94
  }
95
+ writeFile;
94
96
  export function appendFile(filename, data, arg3, cb = nop) {
95
97
  cb = typeof arg3 === 'function' ? arg3 : cb;
96
98
  promises.appendFile(filename, data, typeof arg3 === 'function' ? null : arg3);
97
99
  }
98
- /**
99
- * Asynchronous `fstat`.
100
- * `fstat()` is identical to `stat()`, except that the file to be stat-ed is
101
- * specified by the file descriptor `fd`.
102
- * @param fd
103
- * @param callback
104
- */
105
- export function fstat(fd, cb = nop) {
106
- promises
107
- .fstat(fd)
108
- .then(stats => cb(null, stats))
100
+ appendFile;
101
+ export function fstat(fd, options, cb = nop) {
102
+ cb = typeof options == 'function' ? options : cb;
103
+ fd2file(fd)
104
+ .stat()
105
+ .then(stats => cb(null, (typeof options == 'object' && options?.bigint ? BigIntStats.clone(stats) : stats)))
109
106
  .catch(cb);
110
107
  }
108
+ fstat;
111
109
  /**
112
110
  * Asynchronous close.
113
111
  * @param fd
114
112
  * @param callback
115
113
  */
116
114
  export function close(fd, cb = nop) {
117
- promises
118
- .close(fd)
115
+ new promises.FileHandle(fd)
116
+ .close()
119
117
  .then(() => cb())
120
118
  .catch(cb);
121
119
  }
122
- export function ftruncate(fd, arg2, cb = nop) {
123
- const length = typeof arg2 === 'number' ? arg2 : 0;
124
- cb = typeof arg2 === 'function' ? arg2 : cb;
125
- promises.ftruncate(fd, length);
120
+ close;
121
+ export function ftruncate(fd, lenOrCB, cb = nop) {
122
+ const length = typeof lenOrCB === 'number' ? lenOrCB : 0;
123
+ cb = typeof lenOrCB === 'function' ? lenOrCB : cb;
124
+ const file = fd2file(fd);
125
+ if (length < 0) {
126
+ throw new ApiError(ErrorCode.EINVAL);
127
+ }
128
+ file.truncate(length)
129
+ .then(() => cb())
130
+ .catch(cb);
126
131
  }
132
+ ftruncate;
127
133
  /**
128
134
  * Asynchronous fsync.
129
135
  * @param fd
130
136
  * @param callback
131
137
  */
132
138
  export function fsync(fd, cb = nop) {
133
- promises
134
- .fsync(fd)
139
+ fd2file(fd)
140
+ .sync()
135
141
  .then(() => cb())
136
142
  .catch(cb);
137
143
  }
144
+ fsync;
138
145
  /**
139
146
  * Asynchronous fdatasync.
140
147
  * @param fd
141
148
  * @param callback
142
149
  */
143
150
  export function fdatasync(fd, cb = nop) {
144
- promises
145
- .fdatasync(fd)
151
+ fd2file(fd)
152
+ .datasync()
146
153
  .then(() => cb())
147
154
  .catch(cb);
148
155
  }
156
+ fdatasync;
149
157
  export function write(fd, arg2, arg3, arg4, arg5, cb = nop) {
150
158
  let buffer, offset, length, position = null, encoding;
159
+ const handle = new promises.FileHandle(fd);
151
160
  if (typeof arg2 === 'string') {
152
161
  // Signature 1: (fd, string, [position?, [encoding?]], cb?)
153
162
  encoding = 'utf8';
@@ -172,9 +181,9 @@ export function write(fd, arg2, arg3, arg4, arg5, cb = nop) {
172
181
  offset = 0;
173
182
  length = buffer.length;
174
183
  const _cb = cb;
175
- promises
176
- .write(fd, buffer, offset, length, position)
177
- .then(bytesWritten => _cb(null, bytesWritten, decode(buffer)))
184
+ handle
185
+ .write(buffer, offset, length, position)
186
+ .then(({ bytesWritten }) => _cb(null, bytesWritten, decode(buffer)))
178
187
  .catch(_cb);
179
188
  }
180
189
  else {
@@ -184,12 +193,13 @@ export function write(fd, arg2, arg3, arg4, arg5, cb = nop) {
184
193
  length = arg4;
185
194
  position = typeof arg5 === 'number' ? arg5 : null;
186
195
  const _cb = (typeof arg5 === 'function' ? arg5 : cb);
187
- promises
188
- .write(fd, buffer, offset, length, position)
189
- .then(bytesWritten => _cb(null, bytesWritten, buffer))
196
+ handle
197
+ .write(buffer, offset, length, position)
198
+ .then(({ bytesWritten }) => _cb(null, bytesWritten, buffer))
190
199
  .catch(_cb);
191
200
  }
192
201
  }
202
+ write;
193
203
  /**
194
204
  * Read data from the file specified by `fd`.
195
205
  * @param buffer The buffer that the data will be
@@ -203,11 +213,12 @@ export function write(fd, arg2, arg3, arg4, arg5, cb = nop) {
203
213
  * @param callback The number is the number of bytes read
204
214
  */
205
215
  export function read(fd, buffer, offset, length, position, cb = nop) {
206
- promises
207
- .read(fd, buffer, offset, length, position)
216
+ new promises.FileHandle(fd)
217
+ .read(buffer, offset, length, position)
208
218
  .then(({ bytesRead, buffer }) => cb(null, bytesRead, buffer))
209
219
  .catch(cb);
210
220
  }
221
+ read;
211
222
  /**
212
223
  * Asynchronous `fchown`.
213
224
  * @param fd
@@ -216,11 +227,12 @@ export function read(fd, buffer, offset, length, position, cb = nop) {
216
227
  * @param callback
217
228
  */
218
229
  export function fchown(fd, uid, gid, cb = nop) {
219
- promises
220
- .fchown(fd, uid, gid)
230
+ new promises.FileHandle(fd)
231
+ .chown(uid, gid)
221
232
  .then(() => cb())
222
233
  .catch(cb);
223
234
  }
235
+ fchown;
224
236
  /**
225
237
  * Asynchronous `fchmod`.
226
238
  * @param fd
@@ -228,11 +240,12 @@ export function fchown(fd, uid, gid, cb = nop) {
228
240
  * @param callback
229
241
  */
230
242
  export function fchmod(fd, mode, cb) {
231
- promises
232
- .fchmod(fd, mode)
243
+ new promises.FileHandle(fd)
244
+ .chmod(mode)
233
245
  .then(() => cb())
234
246
  .catch(cb);
235
247
  }
248
+ fchmod;
236
249
  /**
237
250
  * Change the file timestamps of a file referenced by the supplied file
238
251
  * descriptor.
@@ -242,11 +255,12 @@ export function fchmod(fd, mode, cb) {
242
255
  * @param callback
243
256
  */
244
257
  export function futimes(fd, atime, mtime, cb = nop) {
245
- promises
246
- .futimes(fd, atime, mtime)
258
+ new promises.FileHandle(fd)
259
+ .utimes(atime, mtime)
247
260
  .then(() => cb())
248
261
  .catch(cb);
249
262
  }
263
+ futimes;
250
264
  /**
251
265
  * Asynchronous `rmdir`.
252
266
  * @param path
@@ -258,6 +272,7 @@ export function rmdir(path, cb = nop) {
258
272
  .then(() => cb())
259
273
  .catch(cb);
260
274
  }
275
+ rmdir;
261
276
  /**
262
277
  * Asynchronous `mkdir`.
263
278
  * @param path
@@ -270,50 +285,47 @@ export function mkdir(path, mode, cb = nop) {
270
285
  .then(() => cb())
271
286
  .catch(cb);
272
287
  }
273
- /**
274
- * Asynchronous `readdir`. Reads the contents of a directory.
275
- * The callback gets two arguments `(err, files)` where `files` is an array of
276
- * the names of the files in the directory excluding `'.'` and `'..'`.
277
- * @param path
278
- * @param callback
279
- */
280
- export function readdir(path, cb = nop) {
288
+ mkdir;
289
+ export function readdir(path, _options, cb = nop) {
290
+ cb = typeof _options == 'function' ? _options : cb;
291
+ const options = typeof _options != 'function' ? _options : {};
281
292
  promises
282
- .readdir(path)
293
+ .readdir(path, options)
294
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
283
295
  .then(entries => cb(null, entries))
284
296
  .catch(cb);
285
297
  }
298
+ readdir;
286
299
  /**
287
300
  * Asynchronous `link`.
288
- * @param srcpath
289
- * @param dstpath
301
+ * @param existing
302
+ * @param newpath
290
303
  * @param callback
291
304
  */
292
- export function link(srcpath, dstpath, cb = nop) {
305
+ export function link(existing, newpath, cb = nop) {
293
306
  promises
294
- .link(srcpath, dstpath)
307
+ .link(existing, newpath)
295
308
  .then(() => cb())
296
309
  .catch(cb);
297
310
  }
298
- export function symlink(srcpath, dstpath, arg3, cb = nop) {
299
- const type = typeof arg3 === 'string' ? arg3 : 'file';
300
- cb = typeof arg3 === 'function' ? arg3 : cb;
311
+ link;
312
+ export function symlink(target, path, typeOrCB, cb = nop) {
313
+ const type = typeof typeOrCB === 'string' ? typeOrCB : 'file';
314
+ cb = typeof typeOrCB === 'function' ? typeOrCB : cb;
301
315
  promises
302
- .symlink(srcpath, dstpath, typeof arg3 === 'function' ? null : arg3)
316
+ .symlink(target, path, type)
303
317
  .then(() => cb())
304
318
  .catch(cb);
305
319
  }
306
- /**
307
- * Asynchronous readlink.
308
- * @param path
309
- * @param callback
310
- */
311
- export function readlink(path, cb = nop) {
320
+ symlink;
321
+ export function readlink(path, options, callback = nop) {
322
+ callback = typeof options == 'function' ? options : callback;
312
323
  promises
313
324
  .readlink(path)
314
- .then(result => cb(null, result))
315
- .catch(cb);
325
+ .then(result => callback(null, result))
326
+ .catch(callback);
316
327
  }
328
+ readlink;
317
329
  /**
318
330
  * Asynchronous `chown`.
319
331
  * @param path
@@ -327,6 +339,7 @@ export function chown(path, uid, gid, cb = nop) {
327
339
  .then(() => cb())
328
340
  .catch(cb);
329
341
  }
342
+ chown;
330
343
  /**
331
344
  * Asynchronous `lchown`.
332
345
  * @param path
@@ -340,6 +353,7 @@ export function lchown(path, uid, gid, cb = nop) {
340
353
  .then(() => cb())
341
354
  .catch(cb);
342
355
  }
356
+ lchown;
343
357
  /**
344
358
  * Asynchronous `chmod`.
345
359
  * @param path
@@ -352,6 +366,7 @@ export function chmod(path, mode, cb = nop) {
352
366
  .then(() => cb())
353
367
  .catch(cb);
354
368
  }
369
+ chmod;
355
370
  /**
356
371
  * Asynchronous `lchmod`.
357
372
  * @param path
@@ -364,6 +379,7 @@ export function lchmod(path, mode, cb = nop) {
364
379
  .then(() => cb())
365
380
  .catch(cb);
366
381
  }
382
+ lchmod;
367
383
  /**
368
384
  * Change file timestamps of the file referenced by the supplied path.
369
385
  * @param path
@@ -377,6 +393,7 @@ export function utimes(path, atime, mtime, cb = nop) {
377
393
  .then(() => cb())
378
394
  .catch(cb);
379
395
  }
396
+ utimes;
380
397
  /**
381
398
  * Change file timestamps of the file referenced by the supplied path.
382
399
  * @param path
@@ -390,14 +407,15 @@ export function lutimes(path, atime, mtime, cb = nop) {
390
407
  .then(() => cb())
391
408
  .catch(cb);
392
409
  }
410
+ lutimes;
393
411
  export function realpath(path, arg2, cb = nop) {
394
- const cache = typeof arg2 === 'object' ? arg2 : {};
395
412
  cb = typeof arg2 === 'function' ? arg2 : cb;
396
413
  promises
397
414
  .realpath(path, typeof arg2 === 'function' ? null : arg2)
398
415
  .then(result => cb(null, result))
399
416
  .catch(cb);
400
417
  }
418
+ realpath;
401
419
  export function access(path, arg2, cb = nop) {
402
420
  const mode = typeof arg2 === 'number' ? arg2 : R_OK;
403
421
  cb = typeof arg2 === 'function' ? arg2 : cb;
@@ -406,6 +424,7 @@ export function access(path, arg2, cb = nop) {
406
424
  .then(() => cb())
407
425
  .catch(cb);
408
426
  }
427
+ access;
409
428
  export function watchFile(filename, arg2, listener = nop) {
410
429
  throw new ApiError(ErrorCode.ENOTSUP);
411
430
  }
@@ -421,3 +440,21 @@ export function createReadStream(path, options) {
421
440
  export function createWriteStream(path, options) {
422
441
  throw new ApiError(ErrorCode.ENOTSUP);
423
442
  }
443
+ export function rm(path) {
444
+ new ApiError(ErrorCode.ENOTSUP);
445
+ }
446
+ export function mkdtemp(path) {
447
+ new ApiError(ErrorCode.ENOTSUP);
448
+ }
449
+ export function copyFile(src, dest, flags, callback) {
450
+ new ApiError(ErrorCode.ENOTSUP);
451
+ }
452
+ export function readv(path) {
453
+ new ApiError(ErrorCode.ENOTSUP);
454
+ }
455
+ export function writev(fd, buffers, position, cb) {
456
+ throw new ApiError(ErrorCode.ENOTSUP);
457
+ }
458
+ export function opendir(path) {
459
+ throw new ApiError(ErrorCode.ENOTSUP);
460
+ }
@@ -68,7 +68,7 @@ export const O_DIRECT = 0o40000;
68
68
  export const O_NONBLOCK = 0o4000;
69
69
  // File Type Constants
70
70
  /** Constant for fs.Stats mode property for determining a file's type. Bit mask used to extract the file type code. */
71
- export const S_IFMT = 0o170000;
71
+ export const S_IFMT = 0xf000;
72
72
  /** Constant for fs.Stats mode property for determining a file's type. File type constant for a regular file. */
73
73
  export const S_IFREG = 0o100000;
74
74
  /** Constant for fs.Stats mode property for determining a file's type. File type constant for a directory. */
@@ -0,0 +1,55 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ import type { Dirent as _Dirent, Dir as _Dir } from 'fs';
3
+ import { NoArgCallback, TwoArgCallback } from '../filesystem.js';
4
+ import { Stats } from '../stats.js';
5
+ export declare class Dirent implements _Dirent {
6
+ name: string;
7
+ protected stats: Stats;
8
+ constructor(name: string, stats: Stats);
9
+ isFile(): boolean;
10
+ isDirectory(): boolean;
11
+ isBlockDevice(): boolean;
12
+ isCharacterDevice(): boolean;
13
+ isSymbolicLink(): boolean;
14
+ isFIFO(): boolean;
15
+ isSocket(): boolean;
16
+ }
17
+ /**
18
+ * A class representing a directory stream.
19
+ */
20
+ export declare class Dir implements _Dir {
21
+ readonly path: string;
22
+ protected closed: boolean;
23
+ protected checkClosed(): void;
24
+ protected _entries: Dirent[];
25
+ constructor(path: string);
26
+ /**
27
+ * Asynchronously close the directory's underlying resource handle.
28
+ * Subsequent reads will result in errors.
29
+ */
30
+ close(): Promise<void>;
31
+ close(cb: NoArgCallback): void;
32
+ /**
33
+ * Synchronously close the directory's underlying resource handle.
34
+ * Subsequent reads will result in errors.
35
+ */
36
+ closeSync(): void;
37
+ protected _read(): Promise<Dirent | null>;
38
+ /**
39
+ * Asynchronously read the next directory entry via `readdir(3)` as an `Dirent`.
40
+ * After the read is completed, a value is returned that will be resolved with an `Dirent`, or `null` if there are no more directory entries to read.
41
+ * Directory entries returned by this function are in no particular order as provided by the operating system's underlying directory mechanisms.
42
+ */
43
+ read(): Promise<Dirent | null>;
44
+ read(cb: TwoArgCallback<Dirent | null>): void;
45
+ /**
46
+ * Synchronously read the next directory entry via `readdir(3)` as a `Dirent`.
47
+ * If there are no more directory entries to read, null will be returned.
48
+ * Directory entries returned by this function are in no particular order as provided by the operating system's underlying directory mechanisms.
49
+ */
50
+ readSync(): Dirent | null;
51
+ /**
52
+ * Asynchronously iterates over the directory via `readdir(3)` until all entries have been read.
53
+ */
54
+ [Symbol.asyncIterator](): AsyncIterableIterator<Dirent>;
55
+ }
@@ -0,0 +1,104 @@
1
+ import { readdir } from './promises.js';
2
+ import { ApiError, ErrorCode } from '../ApiError.js';
3
+ import { readdirSync } from './sync.js';
4
+ export class Dirent {
5
+ constructor(name, stats) {
6
+ this.name = name;
7
+ this.stats = stats;
8
+ }
9
+ isFile() {
10
+ return this.stats.isFile();
11
+ }
12
+ isDirectory() {
13
+ return this.stats.isDirectory();
14
+ }
15
+ isBlockDevice() {
16
+ return this.stats.isBlockDevice();
17
+ }
18
+ isCharacterDevice() {
19
+ return this.stats.isCharacterDevice();
20
+ }
21
+ isSymbolicLink() {
22
+ return this.stats.isSymbolicLink();
23
+ }
24
+ isFIFO() {
25
+ return this.stats.isFIFO();
26
+ }
27
+ isSocket() {
28
+ return this.stats.isSocket();
29
+ }
30
+ }
31
+ /**
32
+ * A class representing a directory stream.
33
+ */
34
+ export class Dir {
35
+ checkClosed() {
36
+ if (this.closed) {
37
+ throw new ApiError(ErrorCode.EBADF, 'Can not use closed Dir');
38
+ }
39
+ }
40
+ constructor(path) {
41
+ this.path = path;
42
+ this.closed = false;
43
+ }
44
+ close(cb) {
45
+ this.closed = true;
46
+ if (!cb) {
47
+ return Promise.resolve();
48
+ }
49
+ cb();
50
+ }
51
+ /**
52
+ * Synchronously close the directory's underlying resource handle.
53
+ * Subsequent reads will result in errors.
54
+ */
55
+ closeSync() {
56
+ this.closed = true;
57
+ }
58
+ async _read() {
59
+ if (!this._entries) {
60
+ this._entries = await readdir(this.path, { withFileTypes: true });
61
+ }
62
+ if (this._entries.length == 0) {
63
+ return null;
64
+ }
65
+ return this._entries.shift();
66
+ }
67
+ read(cb) {
68
+ if (!cb) {
69
+ return this._read();
70
+ }
71
+ this._read().then(value => cb(null, value));
72
+ }
73
+ /**
74
+ * Synchronously read the next directory entry via `readdir(3)` as a `Dirent`.
75
+ * If there are no more directory entries to read, null will be returned.
76
+ * Directory entries returned by this function are in no particular order as provided by the operating system's underlying directory mechanisms.
77
+ */
78
+ readSync() {
79
+ if (!this._entries) {
80
+ this._entries = readdirSync(this.path, { withFileTypes: true });
81
+ }
82
+ if (this._entries.length == 0) {
83
+ return null;
84
+ }
85
+ return this._entries.shift();
86
+ }
87
+ /**
88
+ * Asynchronously iterates over the directory via `readdir(3)` until all entries have been read.
89
+ */
90
+ [Symbol.asyncIterator]() {
91
+ const _this = this;
92
+ return {
93
+ [Symbol.asyncIterator]: this[Symbol.asyncIterator],
94
+ async next() {
95
+ const value = await _this._read();
96
+ if (value != null) {
97
+ return { done: false, value };
98
+ }
99
+ await _this.close();
100
+ return { done: true, value: undefined };
101
+ },
102
+ };
103
+ }
104
+ }
@@ -1,7 +1,6 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
2
  import * as fs_mock from './index.js';
3
3
  import type * as fs_node from 'node:fs';
4
- type ZenFSModule = typeof fs_node & typeof fs_mock;
5
- declare const fs: ZenFSModule;
4
+ declare const fs: typeof fs_node & typeof fs_mock;
6
5
  export * from './index.js';
7
6
  export default fs;
@@ -1,5 +1,4 @@
1
1
  import * as fs_mock from './index.js';
2
- // @ts-expect-error 2322
3
2
  const fs = fs_mock;
4
3
  export * from './index.js';
5
4
  export default fs;
@@ -2,4 +2,7 @@ export * from './callbacks.js';
2
2
  export * from './sync.js';
3
3
  export * as promises from './promises.js';
4
4
  export * as constants from './constants.js';
5
+ export * from './streams.js';
6
+ export * from './dir.js';
5
7
  export { initialize, getMount, getMounts, mount, umount, _toUnixTimestamp } from './shared.js';
8
+ export { Stats, BigIntStats } from '../stats.js';
@@ -2,4 +2,7 @@ export * from './callbacks.js';
2
2
  export * from './sync.js';
3
3
  export * as promises from './promises.js';
4
4
  export * as constants from './constants.js';
5
+ export * from './streams.js';
6
+ export * from './dir.js';
5
7
  export { initialize, getMount, getMounts, mount, umount, _toUnixTimestamp } from './shared.js';
8
+ export { Stats, BigIntStats } from '../stats.js';