@zenfs/core 0.9.6 → 0.9.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.
Files changed (56) hide show
  1. package/dist/ApiError.d.ts +4 -3
  2. package/dist/ApiError.js +1 -1
  3. package/dist/backends/AsyncStore.d.ts +3 -2
  4. package/dist/backends/AsyncStore.js +12 -5
  5. package/dist/backends/InMemory.d.ts +1 -1
  6. package/dist/backends/Index.d.ts +7 -10
  7. package/dist/backends/Index.js +7 -5
  8. package/dist/backends/Overlay.js +1 -1
  9. package/dist/backends/SyncStore.d.ts +6 -6
  10. package/dist/backends/SyncStore.js +4 -4
  11. package/dist/backends/backend.d.ts +5 -4
  12. package/dist/backends/backend.js +2 -2
  13. package/dist/browser.min.js +4 -4
  14. package/dist/browser.min.js.map +3 -3
  15. package/dist/config.d.ts +1 -1
  16. package/dist/config.js +2 -2
  17. package/dist/emulation/async.d.ts +76 -77
  18. package/dist/emulation/async.js +42 -42
  19. package/dist/emulation/dir.js +6 -5
  20. package/dist/emulation/promises.d.ts +106 -102
  21. package/dist/emulation/promises.js +61 -65
  22. package/dist/emulation/shared.d.ts +1 -7
  23. package/dist/emulation/shared.js +1 -1
  24. package/dist/emulation/streams.js +3 -2
  25. package/dist/emulation/sync.d.ts +71 -64
  26. package/dist/emulation/sync.js +39 -40
  27. package/dist/file.d.ts +4 -4
  28. package/dist/file.js +7 -5
  29. package/dist/filesystem.d.ts +1 -1
  30. package/dist/filesystem.js +3 -0
  31. package/dist/mutex.js +2 -2
  32. package/dist/stats.d.ts +7 -7
  33. package/dist/stats.js +50 -10
  34. package/dist/utils.d.ts +5 -5
  35. package/dist/utils.js +4 -3
  36. package/package.json +3 -3
  37. package/readme.md +2 -2
  38. package/src/ApiError.ts +3 -1
  39. package/src/backends/AsyncStore.ts +14 -8
  40. package/src/backends/Index.ts +14 -10
  41. package/src/backends/Overlay.ts +3 -3
  42. package/src/backends/SyncStore.ts +8 -8
  43. package/src/backends/backend.ts +7 -5
  44. package/src/config.ts +5 -5
  45. package/src/emulation/async.ts +188 -196
  46. package/src/emulation/dir.ts +6 -6
  47. package/src/emulation/promises.ts +181 -173
  48. package/src/emulation/shared.ts +2 -9
  49. package/src/emulation/streams.ts +9 -8
  50. package/src/emulation/sync.ts +159 -159
  51. package/src/file.ts +11 -9
  52. package/src/filesystem.ts +11 -7
  53. package/src/mutex.ts +3 -3
  54. package/src/stats.ts +32 -23
  55. package/src/utils.ts +10 -9
  56. package/tsconfig.json +2 -1
@@ -37,7 +37,7 @@ export function stat(path, options, callback = nop) {
37
37
  callback = typeof options == 'function' ? options : callback;
38
38
  promises
39
39
  .stat(path, typeof options != 'function' ? options : {})
40
- .then((stats) => callback(null, stats))
40
+ .then(stats => callback(undefined, stats))
41
41
  .catch(callback);
42
42
  }
43
43
  stat;
@@ -45,7 +45,7 @@ export function lstat(path, options, callback = nop) {
45
45
  callback = typeof options == 'function' ? options : callback;
46
46
  promises
47
47
  .lstat(path, typeof options != 'function' ? options : {})
48
- .then(stats => callback(null, stats))
48
+ .then(stats => callback(undefined, stats))
49
49
  .catch(callback);
50
50
  }
51
51
  lstat;
@@ -75,7 +75,7 @@ export function open(path, flag, cbMode, cb = nop) {
75
75
  cb = typeof cbMode === 'function' ? cbMode : cb;
76
76
  promises
77
77
  .open(path, flag, mode)
78
- .then(handle => cb(null, handle.fd))
78
+ .then(handle => cb(undefined, handle.fd))
79
79
  .catch(cb);
80
80
  }
81
81
  open;
@@ -83,7 +83,7 @@ export function readFile(filename, options, cb = nop) {
83
83
  cb = typeof options === 'function' ? options : cb;
84
84
  promises
85
85
  .readFile(filename, typeof options === 'function' ? null : options)
86
- .then(data => cb(null, data))
86
+ .then(data => cb(undefined, data))
87
87
  .catch(cb);
88
88
  }
89
89
  readFile;
@@ -91,7 +91,7 @@ export function writeFile(filename, data, cbEncOpts, cb = nop) {
91
91
  cb = typeof cbEncOpts === 'function' ? cbEncOpts : cb;
92
92
  promises
93
93
  .writeFile(filename, data, typeof cbEncOpts != 'function' ? cbEncOpts : null)
94
- .then(() => cb(null))
94
+ .then(() => cb(undefined))
95
95
  .catch(cb);
96
96
  }
97
97
  writeFile;
@@ -107,7 +107,7 @@ export function fstat(fd, options, cb = nop) {
107
107
  cb = typeof options == 'function' ? options : cb;
108
108
  fd2file(fd)
109
109
  .stat()
110
- .then(stats => cb(null, typeof options == 'object' && options?.bigint ? new BigIntStats(stats) : stats))
110
+ .then(stats => cb(undefined, typeof options == 'object' && options?.bigint ? new BigIntStats(stats) : stats))
111
111
  .catch(cb);
112
112
  }
113
113
  fstat;
@@ -160,7 +160,7 @@ export function fdatasync(fd, cb = nop) {
160
160
  }
161
161
  fdatasync;
162
162
  export function write(fd, data, cbPosOff, cbLenEnc, cbPos, cb = nop) {
163
- let buffer, offset, length, position = null, encoding;
163
+ let buffer, offset, length, position, encoding;
164
164
  const handle = new promises.FileHandle(fd);
165
165
  if (typeof data === 'string') {
166
166
  // Signature 1: (fd, string, [position?, [encoding?]], cb?)
@@ -188,19 +188,19 @@ export function write(fd, data, cbPosOff, cbLenEnc, cbPos, cb = nop) {
188
188
  const _cb = cb;
189
189
  handle
190
190
  .write(buffer, offset, length, position)
191
- .then(({ bytesWritten }) => _cb(null, bytesWritten, buffer.toString(encoding)))
191
+ .then(({ bytesWritten }) => _cb(undefined, bytesWritten, buffer.toString(encoding)))
192
192
  .catch(_cb);
193
193
  }
194
194
  else {
195
195
  // Signature 2: (fd, buffer, offset, length, position?, cb?)
196
- buffer = Buffer.from(data);
196
+ buffer = Buffer.from(data.buffer);
197
197
  offset = cbPosOff;
198
198
  length = cbLenEnc;
199
199
  position = typeof cbPos === 'number' ? cbPos : null;
200
200
  const _cb = (typeof cbPos === 'function' ? cbPos : cb);
201
201
  handle
202
202
  .write(buffer, offset, length, position)
203
- .then(({ bytesWritten }) => _cb(null, bytesWritten, buffer))
203
+ .then(({ bytesWritten }) => _cb(undefined, bytesWritten, buffer))
204
204
  .catch(_cb);
205
205
  }
206
206
  }
@@ -220,7 +220,7 @@ write;
220
220
  export function read(fd, buffer, offset, length, position, cb = nop) {
221
221
  new promises.FileHandle(fd)
222
222
  .read(buffer, offset, length, position)
223
- .then(({ bytesRead, buffer }) => cb(null, bytesRead, buffer))
223
+ .then(({ bytesRead, buffer }) => cb(undefined, bytesRead, buffer))
224
224
  .catch(cb);
225
225
  }
226
226
  read;
@@ -297,7 +297,7 @@ export function readdir(path, _options, cb = nop) {
297
297
  promises
298
298
  .readdir(path, options)
299
299
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
300
- .then(entries => cb(null, entries))
300
+ .then(entries => cb(undefined, entries))
301
301
  .catch(cb);
302
302
  }
303
303
  readdir;
@@ -327,7 +327,7 @@ export function readlink(path, options, callback = nop) {
327
327
  callback = typeof options == 'function' ? options : callback;
328
328
  promises
329
329
  .readlink(path)
330
- .then(result => callback(null, result))
330
+ .then(result => callback(undefined, result))
331
331
  .catch(callback);
332
332
  }
333
333
  readlink;
@@ -417,7 +417,7 @@ export function realpath(path, arg2, cb = nop) {
417
417
  cb = typeof arg2 === 'function' ? arg2 : cb;
418
418
  promises
419
419
  .realpath(path, typeof arg2 === 'function' ? null : arg2)
420
- .then(result => cb(null, result))
420
+ .then(result => cb(undefined, result))
421
421
  .catch(cb);
422
422
  }
423
423
  realpath;
@@ -430,19 +430,19 @@ export function access(path, cbMode, cb = nop) {
430
430
  .catch(cb);
431
431
  }
432
432
  access;
433
- export function watchFile(filename, optsListener, listener = nop) {
434
- throw ApiError.With('ENOSYS', filename, 'watchFile');
433
+ export function watchFile(path, optsListener, listener = nop) {
434
+ throw ApiError.With('ENOSYS', path.toString(), 'watchFile');
435
435
  }
436
436
  watchFile;
437
437
  /**
438
438
  * @todo Implement
439
439
  */
440
- export function unwatchFile(filename, listener = nop) {
441
- throw ApiError.With('ENOSYS', filename, 'unwatchFile');
440
+ export function unwatchFile(path, listener = nop) {
441
+ throw ApiError.With('ENOSYS', path.toString(), 'unwatchFile');
442
442
  }
443
443
  unwatchFile;
444
- export function watch(filename, options, listener = nop) {
445
- throw ApiError.With('ENOSYS', filename, 'watch');
444
+ export function watch(path, options, listener = nop) {
445
+ throw ApiError.With('ENOSYS', path.toString(), 'watch');
446
446
  }
447
447
  watch;
448
448
  /**
@@ -480,7 +480,7 @@ export function createReadStream(path, _options) {
480
480
  .catch(callback);
481
481
  },
482
482
  });
483
- stream.path = path;
483
+ stream.path = path.toString();
484
484
  return stream;
485
485
  }
486
486
  createReadStream;
@@ -499,8 +499,8 @@ export function createWriteStream(path, _options) {
499
499
  async write(chunk, encoding, callback) {
500
500
  try {
501
501
  handle || (handle = await promises.open(path, 'w', options?.mode || 0o666));
502
- await handle.write(chunk, null, encoding);
503
- callback(null);
502
+ await handle.write(chunk, 0, encoding);
503
+ callback(undefined);
504
504
  }
505
505
  catch (error) {
506
506
  await handle?.close();
@@ -521,15 +521,15 @@ export function createWriteStream(path, _options) {
521
521
  .catch(callback);
522
522
  },
523
523
  });
524
- stream.path = path;
524
+ stream.path = path.toString();
525
525
  return stream;
526
526
  }
527
527
  createWriteStream;
528
528
  export function rm(path, options, callback = nop) {
529
529
  callback = typeof options === 'function' ? options : callback;
530
530
  promises
531
- .rm(path, typeof options === 'function' ? null : options)
532
- .then(() => callback(null))
531
+ .rm(path, typeof options === 'function' ? undefined : options)
532
+ .then(() => callback(undefined))
533
533
  .catch(callback);
534
534
  }
535
535
  rm;
@@ -537,60 +537,60 @@ export function mkdtemp(prefix, options, callback = nop) {
537
537
  callback = typeof options === 'function' ? options : callback;
538
538
  promises
539
539
  .mkdtemp(prefix, typeof options != 'function' ? options : null)
540
- .then(result => callback(null, result))
540
+ .then(result => callback(undefined, result))
541
541
  .catch(callback);
542
542
  }
543
543
  mkdtemp;
544
- export function copyFile(src, dest, flags, callback) {
544
+ export function copyFile(src, dest, flags, callback = nop) {
545
545
  callback = typeof flags === 'function' ? flags : callback;
546
546
  promises
547
- .copyFile(src, dest, typeof flags === 'function' ? null : flags)
548
- .then(() => callback(null))
547
+ .copyFile(src, dest, typeof flags === 'function' ? undefined : flags)
548
+ .then(() => callback(undefined))
549
549
  .catch(callback);
550
550
  }
551
551
  copyFile;
552
552
  export function readv(fd, buffers, position, cb = nop) {
553
553
  cb = typeof position === 'function' ? position : cb;
554
554
  new promises.FileHandle(fd)
555
- .readv(buffers, typeof position === 'function' ? null : position)
556
- .then(({ buffers, bytesRead }) => cb(null, bytesRead, buffers))
555
+ .readv(buffers, typeof position === 'function' ? undefined : position)
556
+ .then(({ buffers, bytesRead }) => cb(undefined, bytesRead, buffers))
557
557
  .catch(cb);
558
558
  }
559
559
  readv;
560
560
  export function writev(fd, buffers, position, cb = nop) {
561
561
  cb = typeof position === 'function' ? position : cb;
562
562
  new promises.FileHandle(fd)
563
- .writev(buffers, typeof position === 'function' ? null : position)
564
- .then(({ buffers, bytesWritten }) => cb(null, bytesWritten, buffers))
563
+ .writev(buffers, typeof position === 'function' ? undefined : position)
564
+ .then(({ buffers, bytesWritten }) => cb(undefined, bytesWritten, buffers))
565
565
  .catch(cb);
566
566
  }
567
567
  writev;
568
568
  export function opendir(path, options, cb = nop) {
569
569
  cb = typeof options === 'function' ? options : cb;
570
570
  promises
571
- .opendir(path, typeof options === 'function' ? null : options)
572
- .then(result => cb(null, result))
571
+ .opendir(path, typeof options === 'function' ? undefined : options)
572
+ .then(result => cb(undefined, result))
573
573
  .catch(cb);
574
574
  }
575
575
  opendir;
576
- export function cp(source, destination, opts, callback) {
576
+ export function cp(source, destination, opts, callback = nop) {
577
577
  callback = typeof opts === 'function' ? opts : callback;
578
578
  promises
579
- .cp(source, destination, typeof opts === 'function' ? null : opts)
580
- .then(() => callback(null))
579
+ .cp(source, destination, typeof opts === 'function' ? undefined : opts)
580
+ .then(() => callback(undefined))
581
581
  .catch(callback);
582
582
  }
583
583
  cp;
584
584
  export function statfs(path, options, callback = nop) {
585
585
  callback = typeof options === 'function' ? options : callback;
586
586
  promises
587
- .statfs(path, typeof options === 'function' ? null : options)
588
- .then(result => callback(null, result))
587
+ .statfs(path, typeof options === 'function' ? undefined : options)
588
+ .then(result => callback(undefined, result))
589
589
  .catch(callback);
590
590
  }
591
591
  statfs;
592
592
  export async function openAsBlob(path, options) {
593
- const handle = await promises.open(path, 'r');
593
+ const handle = await promises.open(path.toString(), 'r');
594
594
  const buffer = await handle.readFile();
595
595
  await handle.close();
596
596
  return new Blob([buffer], options);
@@ -44,6 +44,7 @@ export class Dir {
44
44
  constructor(path) {
45
45
  this.path = path;
46
46
  this.closed = false;
47
+ this._entries = [];
47
48
  }
48
49
  close(cb) {
49
50
  this.closed = true;
@@ -63,16 +64,16 @@ export class Dir {
63
64
  if (!this._entries) {
64
65
  this._entries = await readdir(this.path, { withFileTypes: true });
65
66
  }
66
- if (this._entries.length == 0) {
67
+ if (!this._entries.length) {
67
68
  return null;
68
69
  }
69
- return this._entries.shift();
70
+ return this._entries.shift() || null;
70
71
  }
71
72
  read(cb) {
72
73
  if (!cb) {
73
74
  return this._read();
74
75
  }
75
- this._read().then(value => cb(null, value));
76
+ this._read().then(value => cb(undefined, value));
76
77
  }
77
78
  /**
78
79
  * Synchronously read the next directory entry via `readdir(3)` as a `Dirent`.
@@ -83,10 +84,10 @@ export class Dir {
83
84
  if (!this._entries) {
84
85
  this._entries = readdirSync(this.path, { withFileTypes: true });
85
86
  }
86
- if (this._entries.length == 0) {
87
+ if (!this._entries.length) {
87
88
  return null;
88
89
  }
89
- return this._entries.shift();
90
+ return this._entries.shift() || null;
90
91
  }
91
92
  /**
92
93
  * Asynchronously iterates over the directory via `readdir(3)` until all entries have been read.