@zenfs/core 0.9.6 → 0.10.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 (82) hide show
  1. package/dist/backends/AsyncStore.d.ts +3 -2
  2. package/dist/backends/AsyncStore.js +40 -33
  3. package/dist/backends/Fetch.d.ts +84 -0
  4. package/dist/backends/Fetch.js +171 -0
  5. package/dist/backends/InMemory.d.ts +1 -1
  6. package/dist/backends/Index.d.ts +7 -10
  7. package/dist/backends/Index.js +26 -24
  8. package/dist/backends/Locked.d.ts +11 -11
  9. package/dist/backends/Locked.js +50 -49
  10. package/dist/backends/Overlay.js +22 -22
  11. package/dist/backends/SyncStore.d.ts +6 -6
  12. package/dist/backends/SyncStore.js +30 -30
  13. package/dist/backends/backend.d.ts +5 -4
  14. package/dist/backends/backend.js +6 -6
  15. package/dist/backends/port/fs.d.ts +124 -0
  16. package/dist/backends/port/fs.js +241 -0
  17. package/dist/backends/port/rpc.d.ts +60 -0
  18. package/dist/backends/port/rpc.js +71 -0
  19. package/dist/backends/port/store.d.ts +30 -0
  20. package/dist/backends/port/store.js +142 -0
  21. package/dist/browser.min.js +4 -4
  22. package/dist/browser.min.js.map +4 -4
  23. package/dist/config.d.ts +9 -11
  24. package/dist/config.js +13 -13
  25. package/dist/emulation/async.d.ts +76 -77
  26. package/dist/emulation/async.js +45 -45
  27. package/dist/emulation/dir.js +8 -7
  28. package/dist/emulation/index.d.ts +1 -1
  29. package/dist/emulation/index.js +1 -1
  30. package/dist/emulation/path.d.ts +3 -2
  31. package/dist/emulation/path.js +19 -45
  32. package/dist/emulation/promises.d.ts +112 -113
  33. package/dist/emulation/promises.js +167 -173
  34. package/dist/emulation/shared.d.ts +6 -17
  35. package/dist/emulation/shared.js +9 -9
  36. package/dist/emulation/streams.js +3 -2
  37. package/dist/emulation/sync.d.ts +71 -64
  38. package/dist/emulation/sync.js +62 -63
  39. package/dist/{ApiError.d.ts → error.d.ts} +15 -15
  40. package/dist/error.js +292 -0
  41. package/dist/file.d.ts +6 -4
  42. package/dist/file.js +17 -9
  43. package/dist/filesystem.d.ts +1 -1
  44. package/dist/filesystem.js +18 -15
  45. package/dist/index.d.ts +4 -1
  46. package/dist/index.js +4 -1
  47. package/dist/mutex.js +4 -3
  48. package/dist/stats.d.ts +7 -7
  49. package/dist/stats.js +50 -10
  50. package/dist/utils.d.ts +10 -9
  51. package/dist/utils.js +15 -15
  52. package/package.json +5 -5
  53. package/readme.md +19 -11
  54. package/src/backends/AsyncStore.ts +42 -36
  55. package/src/backends/Fetch.ts +230 -0
  56. package/src/backends/Index.ts +33 -29
  57. package/src/backends/Locked.ts +50 -49
  58. package/src/backends/Overlay.ts +24 -24
  59. package/src/backends/SyncStore.ts +34 -34
  60. package/src/backends/backend.ts +13 -11
  61. package/src/backends/port/fs.ts +308 -0
  62. package/src/backends/port/readme.md +59 -0
  63. package/src/backends/port/rpc.ts +144 -0
  64. package/src/backends/port/store.ts +187 -0
  65. package/src/config.ts +25 -29
  66. package/src/emulation/async.ts +191 -199
  67. package/src/emulation/dir.ts +8 -8
  68. package/src/emulation/index.ts +1 -1
  69. package/src/emulation/path.ts +25 -49
  70. package/src/emulation/promises.ts +286 -287
  71. package/src/emulation/shared.ts +14 -23
  72. package/src/emulation/streams.ts +9 -8
  73. package/src/emulation/sync.ts +182 -182
  74. package/src/{ApiError.ts → error.ts} +91 -89
  75. package/src/file.ts +23 -13
  76. package/src/filesystem.ts +26 -22
  77. package/src/index.ts +4 -1
  78. package/src/mutex.ts +6 -4
  79. package/src/stats.ts +32 -23
  80. package/src/utils.ts +23 -24
  81. package/tsconfig.json +4 -3
  82. package/dist/ApiError.js +0 -292
@@ -1,12 +1,12 @@
1
1
  import { Buffer } from 'buffer';
2
- import { ApiError, ErrorCode } from '../ApiError.js';
2
+ import { ErrnoError, Errno } from '../error.js';
3
3
  import { ActionType, isAppendable, isReadable, isWriteable, parseFlag, pathExistsAction, pathNotExistsAction } from '../file.js';
4
4
  import { BigIntStats, FileType } from '../stats.js';
5
5
  import { normalizeMode, normalizeOptions, normalizePath, normalizeTime } from '../utils.js';
6
- import { COPYFILE_EXCL, S_IFBLK, S_IFCHR, S_IFDIR, S_IFIFO, S_IFLNK, S_IFMT, S_IFREG, S_IFSOCK } from './constants.js';
6
+ import { COPYFILE_EXCL, F_OK, S_IFBLK, S_IFCHR, S_IFDIR, S_IFIFO, S_IFLNK, S_IFMT, S_IFREG, S_IFSOCK } from './constants.js';
7
7
  import { Dir, Dirent } from './dir.js';
8
8
  import { dirname, join, parse } from './path.js';
9
- import { cred, fd2file, fdMap, fixError, getFdForFile, mounts, resolveMount } from './shared.js';
9
+ import { cred, fd2file, fdMap, fixError, file2fd, mounts, resolveMount } from './shared.js';
10
10
  function doOp(...[name, resolveSymlinks, path, ...args]) {
11
11
  path = normalizePath(path);
12
12
  const { fs, path: resolvedPath } = resolveMount(resolveSymlinks && existsSync(path) ? realpathSync(path) : path);
@@ -52,7 +52,7 @@ export function existsSync(path) {
52
52
  return fs.existsSync(resolvedPath, cred);
53
53
  }
54
54
  catch (e) {
55
- if (e.errno == ErrorCode.ENOENT) {
55
+ if (e.errno == Errno.ENOENT) {
56
56
  return false;
57
57
  }
58
58
  throw e;
@@ -60,12 +60,12 @@ export function existsSync(path) {
60
60
  }
61
61
  existsSync;
62
62
  export function statSync(path, options) {
63
- const stats = doOp('statSync', true, path, cred);
63
+ const stats = doOp('statSync', true, path.toString(), cred);
64
64
  return options?.bigint ? new BigIntStats(stats) : stats;
65
65
  }
66
66
  statSync;
67
67
  export function lstatSync(path, options) {
68
- const stats = doOp('statSync', false, path, cred);
68
+ const stats = doOp('statSync', false, path.toString(), cred);
69
69
  return options?.bigint ? new BigIntStats(stats) : stats;
70
70
  }
71
71
  lstatSync;
@@ -89,10 +89,10 @@ truncateSync;
89
89
  * @param path
90
90
  */
91
91
  export function unlinkSync(path) {
92
- return doOp('unlinkSync', false, path, cred);
92
+ return doOp('unlinkSync', false, path.toString(), cred);
93
93
  }
94
94
  unlinkSync;
95
- function _openSync(_path, _flag, _mode, resolveSymlinks) {
95
+ function _openSync(_path, _flag, _mode, resolveSymlinks = true) {
96
96
  const path = normalizePath(_path), mode = normalizeMode(_mode, 0o644), flag = parseFlag(_flag);
97
97
  // Check if the path exists, and is a file.
98
98
  let stats;
@@ -106,22 +106,22 @@ function _openSync(_path, _flag, _mode, resolveSymlinks) {
106
106
  // Ensure parent exists.
107
107
  const parentStats = doOp('statSync', resolveSymlinks, dirname(path), cred);
108
108
  if (!parentStats.isDirectory()) {
109
- throw ApiError.With('ENOTDIR', dirname(path), '_open');
109
+ throw ErrnoError.With('ENOTDIR', dirname(path), '_open');
110
110
  }
111
111
  return doOp('createFileSync', resolveSymlinks, path, flag, mode, cred);
112
112
  case ActionType.THROW:
113
- throw ApiError.With('ENOENT', path, '_open');
113
+ throw ErrnoError.With('ENOENT', path, '_open');
114
114
  default:
115
- throw new ApiError(ErrorCode.EINVAL, 'Invalid FileFlag object.');
115
+ throw new ErrnoError(Errno.EINVAL, 'Invalid FileFlag object.');
116
116
  }
117
117
  }
118
118
  if (!stats.hasAccess(mode, cred)) {
119
- throw ApiError.With('EACCES', path, '_open');
119
+ throw ErrnoError.With('EACCES', path, '_open');
120
120
  }
121
121
  // File exists.
122
122
  switch (pathExistsAction(flag)) {
123
123
  case ActionType.THROW:
124
- throw ApiError.With('EEXIST', path, '_open');
124
+ throw ErrnoError.With('EEXIST', path, '_open');
125
125
  case ActionType.TRUNCATE:
126
126
  // Delete file.
127
127
  doOp('unlinkSync', resolveSymlinks, path, cred);
@@ -135,7 +135,7 @@ function _openSync(_path, _flag, _mode, resolveSymlinks) {
135
135
  case ActionType.NOP:
136
136
  return doOp('openFileSync', resolveSymlinks, path, flag, cred);
137
137
  default:
138
- throw new ApiError(ErrorCode.EINVAL, 'Invalid FileFlag object.');
138
+ throw new ErrnoError(Errno.EINVAL, 'Invalid FileFlag object.');
139
139
  }
140
140
  }
141
141
  /**
@@ -146,8 +146,8 @@ function _openSync(_path, _flag, _mode, resolveSymlinks) {
146
146
  * @param mode Mode to use to open the file. Can be ignored if the
147
147
  * filesystem doesn't support permissions.
148
148
  */
149
- export function openSync(path, flag, mode) {
150
- return getFdForFile(_openSync(path, flag, mode, true));
149
+ export function openSync(path, flag, mode = F_OK) {
150
+ return file2fd(_openSync(path, flag, mode, true));
151
151
  }
152
152
  openSync;
153
153
  /**
@@ -155,7 +155,7 @@ openSync;
155
155
  * @internal
156
156
  */
157
157
  export function lopenSync(path, flag, mode) {
158
- return getFdForFile(_openSync(path, flag, mode, false));
158
+ return file2fd(_openSync(path, flag, mode, false));
159
159
  }
160
160
  /**
161
161
  * Synchronously reads the entire contents of a file.
@@ -175,13 +175,13 @@ function _readFileSync(fname, flag, resolveSymlinks) {
175
175
  file.closeSync();
176
176
  }
177
177
  }
178
- export function readFileSync(filename, arg2 = {}) {
179
- const options = normalizeOptions(arg2, null, 'r', 0o644);
178
+ export function readFileSync(path, _options = {}) {
179
+ const options = normalizeOptions(_options, null, 'r', 0o644);
180
180
  const flag = parseFlag(options.flag);
181
181
  if (!isReadable(flag)) {
182
- throw new ApiError(ErrorCode.EINVAL, 'Flag passed to readFile must allow for reading.');
182
+ throw new ErrnoError(Errno.EINVAL, 'Flag passed to readFile must allow for reading.');
183
183
  }
184
- const data = Buffer.from(_readFileSync(filename, options.flag, true));
184
+ const data = Buffer.from(_readFileSync(typeof path == 'number' ? fd2file(path).path : path.toString(), options.flag, true));
185
185
  return options.encoding ? data.toString(options.encoding) : data;
186
186
  }
187
187
  readFileSync;
@@ -194,26 +194,26 @@ readFileSync;
194
194
  function _writeFileSync(fname, data, flag, mode, resolveSymlinks) {
195
195
  const file = _openSync(fname, flag, mode, resolveSymlinks);
196
196
  try {
197
- file.writeSync(data, 0, data.length, 0);
197
+ file.writeSync(data, 0, data.byteLength, 0);
198
198
  }
199
199
  finally {
200
200
  file.closeSync();
201
201
  }
202
202
  }
203
- export function writeFileSync(filename, data, _options) {
203
+ export function writeFileSync(path, data, _options = {}) {
204
204
  const options = normalizeOptions(_options, 'utf8', 'w+', 0o644);
205
205
  const flag = parseFlag(options.flag);
206
206
  if (!isWriteable(flag)) {
207
- throw new ApiError(ErrorCode.EINVAL, 'Flag passed to writeFile must allow for writing.');
207
+ throw new ErrnoError(Errno.EINVAL, 'Flag passed to writeFile must allow for writing.');
208
208
  }
209
209
  if (typeof data != 'string' && !options.encoding) {
210
- throw new ApiError(ErrorCode.EINVAL, 'Encoding not specified');
210
+ throw new ErrnoError(Errno.EINVAL, 'Encoding not specified');
211
211
  }
212
- const encodedData = typeof data == 'string' ? Buffer.from(data, options.encoding) : data;
213
- if (encodedData === undefined) {
214
- throw new ApiError(ErrorCode.EINVAL, 'Data not specified');
212
+ const encodedData = typeof data == 'string' ? Buffer.from(data, options.encoding) : new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
213
+ if (!encodedData) {
214
+ throw new ErrnoError(Errno.EINVAL, 'Data not specified');
215
215
  }
216
- _writeFileSync(filename, encodedData, options.flag, options.mode, true);
216
+ _writeFileSync(typeof path == 'number' ? fd2file(path).path : path.toString(), encodedData, options.flag, options.mode, true);
217
217
  }
218
218
  writeFileSync;
219
219
  /**
@@ -223,7 +223,7 @@ writeFileSync;
223
223
  function _appendFileSync(fname, data, flag, mode, resolveSymlinks) {
224
224
  const file = _openSync(fname, flag, mode, resolveSymlinks);
225
225
  try {
226
- file.writeSync(data, 0, data.length, null);
226
+ file.writeSync(data, 0, data.byteLength, null);
227
227
  }
228
228
  finally {
229
229
  file.closeSync();
@@ -240,17 +240,17 @@ function _appendFileSync(fname, data, flag, mode, resolveSymlinks) {
240
240
  * @option options mode Defaults to `0644`.
241
241
  * @option options flag Defaults to `'a'`.
242
242
  */
243
- export function appendFileSync(filename, data, _options) {
243
+ export function appendFileSync(filename, data, _options = {}) {
244
244
  const options = normalizeOptions(_options, 'utf8', 'a', 0o644);
245
245
  const flag = parseFlag(options.flag);
246
246
  if (!isAppendable(flag)) {
247
- throw new ApiError(ErrorCode.EINVAL, 'Flag passed to appendFile must allow for appending.');
247
+ throw new ErrnoError(Errno.EINVAL, 'Flag passed to appendFile must allow for appending.');
248
248
  }
249
249
  if (typeof data != 'string' && !options.encoding) {
250
- throw new ApiError(ErrorCode.EINVAL, 'Encoding not specified');
250
+ throw new ErrnoError(Errno.EINVAL, 'Encoding not specified');
251
251
  }
252
- const encodedData = typeof data == 'string' ? Buffer.from(data, options.encoding) : data;
253
- _appendFileSync(filename, encodedData, options.flag, options.mode, true);
252
+ const encodedData = typeof data == 'string' ? Buffer.from(data, options.encoding) : new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
253
+ _appendFileSync(typeof filename == 'number' ? fd2file(filename).path : filename.toString(), encodedData, options.flag, options.mode, true);
254
254
  }
255
255
  appendFileSync;
256
256
  export function fstatSync(fd, options) {
@@ -273,8 +273,9 @@ closeSync;
273
273
  * @param len
274
274
  */
275
275
  export function ftruncateSync(fd, len = 0) {
276
+ len || (len = 0);
276
277
  if (len < 0) {
277
- throw new ApiError(ErrorCode.EINVAL);
278
+ throw new ErrnoError(Errno.EINVAL);
278
279
  }
279
280
  fd2file(fd).truncateSync(len);
280
281
  }
@@ -296,26 +297,24 @@ export function fdatasyncSync(fd) {
296
297
  }
297
298
  fdatasyncSync;
298
299
  export function writeSync(fd, data, posOrOff, lenOrEnc, pos) {
299
- let buffer, offset = 0, length, position;
300
+ let buffer, offset, length, position;
300
301
  if (typeof data === 'string') {
301
302
  // Signature 1: (fd, string, [position?, [encoding?]])
302
303
  position = typeof posOrOff === 'number' ? posOrOff : null;
303
304
  const encoding = (typeof lenOrEnc === 'string' ? lenOrEnc : 'utf8');
304
305
  offset = 0;
305
306
  buffer = Buffer.from(data, encoding);
306
- length = buffer.length;
307
+ length = buffer.byteLength;
307
308
  }
308
309
  else {
309
310
  // Signature 2: (fd, buffer, offset, length, position?)
310
- buffer = data;
311
+ buffer = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
311
312
  offset = posOrOff;
312
313
  length = lenOrEnc;
313
314
  position = typeof pos === 'number' ? pos : null;
314
315
  }
315
316
  const file = fd2file(fd);
316
- if (position === undefined || position === null) {
317
- position = file.position;
318
- }
317
+ position ?? (position = file.position);
319
318
  return file.writeSync(buffer, offset, length, position);
320
319
  }
321
320
  writeSync;
@@ -351,7 +350,7 @@ fchownSync;
351
350
  export function fchmodSync(fd, mode) {
352
351
  const numMode = normalizeMode(mode, -1);
353
352
  if (numMode < 0) {
354
- throw new ApiError(ErrorCode.EINVAL, `Invalid mode.`);
353
+ throw new ErrnoError(Errno.EINVAL, `Invalid mode.`);
355
354
  }
356
355
  fd2file(fd).chmodSync(numMode);
357
356
  }
@@ -372,13 +371,13 @@ futimesSync;
372
371
  * @param path
373
372
  */
374
373
  export function rmdirSync(path) {
375
- return doOp('rmdirSync', true, path, cred);
374
+ return doOp('rmdirSync', true, path.toString(), cred);
376
375
  }
377
376
  rmdirSync;
378
377
  export function mkdirSync(path, options) {
379
378
  const mode = typeof options == 'number' || typeof options == 'string' ? options : options?.mode;
380
379
  const recursive = typeof options == 'object' && options?.recursive;
381
- doOp('mkdirSync', true, path, normalizeMode(mode, 0o777), cred);
380
+ doOp('mkdirSync', true, path.toString(), normalizeMode(mode, 0o777), cred);
382
381
  }
383
382
  mkdirSync;
384
383
  export function readdirSync(path, options) {
@@ -397,9 +396,9 @@ export function readdirSync(path, options) {
397
396
  }
398
397
  return entries.map((entry) => {
399
398
  if (typeof options == 'object' && options?.withFileTypes) {
400
- return new Dirent(entry, statSync(join(path, entry)));
399
+ return new Dirent(entry, statSync(join(path.toString(), entry)));
401
400
  }
402
- if (options == 'buffer' || (typeof options == 'object' && options.encoding == 'buffer')) {
401
+ if (options == 'buffer' || (typeof options == 'object' && options?.encoding == 'buffer')) {
403
402
  return Buffer.from(entry);
404
403
  }
405
404
  return entry;
@@ -414,7 +413,7 @@ readdirSync;
414
413
  */
415
414
  export function linkSync(existing, newpath) {
416
415
  newpath = normalizePath(newpath);
417
- return doOp('linkSync', false, existing, newpath, cred);
416
+ return doOp('linkSync', false, existing.toString(), newpath.toString(), cred);
418
417
  }
419
418
  linkSync;
420
419
  /**
@@ -425,19 +424,19 @@ linkSync;
425
424
  */
426
425
  export function symlinkSync(target, path, type = 'file') {
427
426
  if (!['file', 'dir', 'junction'].includes(type)) {
428
- throw new ApiError(ErrorCode.EINVAL, 'Invalid type: ' + type);
427
+ throw new ErrnoError(Errno.EINVAL, 'Invalid type: ' + type);
429
428
  }
430
429
  if (existsSync(path)) {
431
- throw ApiError.With('EEXIST', path, 'symlink');
430
+ throw ErrnoError.With('EEXIST', path.toString(), 'symlink');
432
431
  }
433
- writeFileSync(path, target);
432
+ writeFileSync(path, target.toString());
434
433
  const file = _openSync(path, 'r+', 0o644, false);
435
434
  file._setTypeSync(FileType.SYMLINK);
436
435
  }
437
436
  symlinkSync;
438
437
  export function readlinkSync(path, options) {
439
- const value = Buffer.from(_readFileSync(path, 'r', false));
440
- const encoding = typeof options == 'object' ? options.encoding : options;
438
+ const value = Buffer.from(_readFileSync(path.toString(), 'r', false));
439
+ const encoding = typeof options == 'object' ? options?.encoding : options;
441
440
  if (encoding == 'buffer') {
442
441
  return value;
443
442
  }
@@ -540,7 +539,7 @@ realpathSync;
540
539
  export function accessSync(path, mode = 0o600) {
541
540
  const stats = statSync(path);
542
541
  if (!stats.hasAccess(mode, cred)) {
543
- throw new ApiError(ErrorCode.EACCES);
542
+ throw new ErrnoError(Errno.EACCES);
544
543
  }
545
544
  }
546
545
  accessSync;
@@ -569,12 +568,12 @@ export function rmSync(path, options) {
569
568
  case S_IFIFO:
570
569
  case S_IFSOCK:
571
570
  default:
572
- throw new ApiError(ErrorCode.EPERM, 'File type not supported', path, 'rm');
571
+ throw new ErrnoError(Errno.EPERM, 'File type not supported', path, 'rm');
573
572
  }
574
573
  }
575
574
  rmSync;
576
575
  export function mkdtempSync(prefix, options) {
577
- const encoding = typeof options === 'object' ? options.encoding : options || 'utf8';
576
+ const encoding = typeof options === 'object' ? options?.encoding : options || 'utf8';
578
577
  const fsName = `${prefix}${Date.now()}-${Math.random().toString(36).slice(2)}`;
579
578
  const resolvedPath = '/tmp/' + fsName;
580
579
  mkdirSync(resolvedPath);
@@ -592,7 +591,7 @@ export function copyFileSync(src, dest, flags) {
592
591
  src = normalizePath(src);
593
592
  dest = normalizePath(dest);
594
593
  if (flags && flags & COPYFILE_EXCL && existsSync(dest)) {
595
- throw new ApiError(ErrorCode.EEXIST, 'Destination file already exists.', dest, 'copyFile');
594
+ throw new ErrnoError(Errno.EEXIST, 'Destination file already exists.', dest, 'copyFile');
596
595
  }
597
596
  writeFileSync(dest, readFileSync(src));
598
597
  }
@@ -608,7 +607,7 @@ export function readvSync(fd, buffers, position) {
608
607
  const file = fd2file(fd);
609
608
  let bytesRead = 0;
610
609
  for (const buffer of buffers) {
611
- bytesRead += file.readSync(buffer, 0, buffer.length, position + bytesRead);
610
+ bytesRead += file.readSync(buffer, 0, buffer.byteLength, position + bytesRead);
612
611
  }
613
612
  return bytesRead;
614
613
  }
@@ -624,7 +623,7 @@ export function writevSync(fd, buffers, position) {
624
623
  const file = fd2file(fd);
625
624
  let bytesWritten = 0;
626
625
  for (const buffer of buffers) {
627
- bytesWritten += file.writeSync(buffer, 0, buffer.length, position + bytesWritten);
626
+ bytesWritten += file.writeSync(new Uint8Array(buffer.buffer), 0, buffer.byteLength, position + bytesWritten);
628
627
  }
629
628
  return bytesWritten;
630
629
  }
@@ -657,12 +656,12 @@ export function cpSync(source, destination, opts) {
657
656
  destination = normalizePath(destination);
658
657
  const srcStats = lstatSync(source); // Use lstat to follow symlinks if not dereferencing
659
658
  if (opts?.errorOnExist && existsSync(destination)) {
660
- throw new ApiError(ErrorCode.EEXIST, 'Destination file or directory already exists.', destination, 'cp');
659
+ throw new ErrnoError(Errno.EEXIST, 'Destination file or directory already exists.', destination, 'cp');
661
660
  }
662
661
  switch (srcStats.mode & S_IFMT) {
663
662
  case S_IFDIR:
664
663
  if (!opts?.recursive) {
665
- throw new ApiError(ErrorCode.EISDIR, source + ' is a directory (not copied)', source, 'cp');
664
+ throw new ErrnoError(Errno.EISDIR, source + ' is a directory (not copied)', source, 'cp');
666
665
  }
667
666
  mkdirSync(destination, { recursive: true }); // Ensure the destination directory exists
668
667
  for (const dirent of readdirSync(source, { withFileTypes: true })) {
@@ -681,7 +680,7 @@ export function cpSync(source, destination, opts) {
681
680
  case S_IFIFO:
682
681
  case S_IFSOCK:
683
682
  default:
684
- throw new ApiError(ErrorCode.EPERM, 'File type not supported', source, 'rm');
683
+ throw new ErrnoError(Errno.EPERM, 'File type not supported', source, 'rm');
685
684
  }
686
685
  // Optionally preserve timestamps
687
686
  if (opts?.preserveTimestamps) {
@@ -690,5 +689,5 @@ export function cpSync(source, destination, opts) {
690
689
  }
691
690
  cpSync;
692
691
  export function statfsSync(path, options) {
693
- throw ApiError.With('ENOSYS', path, 'statfs');
692
+ throw ErrnoError.With('ENOSYS', path.toString(), 'statfs');
694
693
  }
@@ -1,10 +1,10 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
2
  /**
3
- * Standard libc error codes. More will be added to this enum and ErrorStrings as they are
3
+ * Standard libc error codes. More will be added to this enum and error strings as they are
4
4
  * needed.
5
5
  * @url https://en.wikipedia.org/wiki/Errno.h
6
6
  */
7
- export declare enum ErrorCode {
7
+ export declare enum Errno {
8
8
  /** Operation not permitted */
9
9
  EPERM = 1,
10
10
  /** No such file or directory */
@@ -159,13 +159,13 @@ export declare enum ErrorCode {
159
159
  * @internal
160
160
  */
161
161
  export declare const errorMessages: {
162
- [K in ErrorCode]: string;
162
+ [K in Errno]: string;
163
163
  };
164
- interface ApiErrorJSON {
165
- errno: ErrorCode;
164
+ export interface ErrnoErrorJSON {
165
+ errno: Errno;
166
166
  message: string;
167
167
  path?: string;
168
- code: keyof typeof ErrorCode;
168
+ code: keyof typeof Errno;
169
169
  stack: string;
170
170
  syscall: string;
171
171
  }
@@ -173,13 +173,14 @@ interface ApiErrorJSON {
173
173
  * Represents a ZenFS error. Passed back to applications after a failed
174
174
  * call to the ZenFS API.
175
175
  */
176
- export declare class ApiError extends Error implements NodeJS.ErrnoException {
177
- errno: ErrorCode;
178
- path?: string;
176
+ export declare class ErrnoError extends Error implements NodeJS.ErrnoException {
177
+ errno: Errno;
178
+ path?: string | undefined;
179
179
  syscall: string;
180
- static fromJSON(json: ApiErrorJSON): ApiError;
181
- static With(code: keyof typeof ErrorCode, path: string, syscall?: string): ApiError;
182
- code: keyof typeof ErrorCode;
180
+ static fromJSON(json: ErrnoErrorJSON): ErrnoError;
181
+ static With(code: keyof typeof Errno, path?: string, syscall?: string): ErrnoError;
182
+ code: keyof typeof Errno;
183
+ stack: string;
183
184
  /**
184
185
  * Represents a ZenFS error. Passed back to applications after a failed
185
186
  * call to the ZenFS API.
@@ -190,15 +191,14 @@ export declare class ApiError extends Error implements NodeJS.ErrnoException {
190
191
  * @param type The type of the error.
191
192
  * @param message A descriptive error message.
192
193
  */
193
- constructor(errno: ErrorCode, message?: string, path?: string, syscall?: string);
194
+ constructor(errno: Errno, message?: string, path?: string | undefined, syscall?: string);
194
195
  /**
195
196
  * @return A friendly error message.
196
197
  */
197
198
  toString(): string;
198
- toJSON(): ApiErrorJSON;
199
+ toJSON(): ErrnoErrorJSON;
199
200
  /**
200
201
  * The size of the API error in buffer-form in bytes.
201
202
  */
202
203
  bufferSize(): number;
203
204
  }
204
- export {};