@componentor/fs 3.0.31 → 3.0.33

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/index.d.mts CHANGED
@@ -450,7 +450,7 @@ declare class VFSFileSystem {
450
450
  length?: number;
451
451
  position?: number | null;
452
452
  }, lengthOrEncoding?: number | string, position?: number | null): number;
453
- fstatSync(fd: number): Stats;
453
+ fstatSync(fd: number, options?: StatOptions): Stats | BigIntStats;
454
454
  ftruncateSync(fd: number, len?: number): void;
455
455
  fdatasyncSync(fd: number): void;
456
456
  fsyncSync(fd: number): void;
@@ -487,6 +487,12 @@ declare class VFSFileSystem {
487
487
  * Returns a Promise that resolves when the new mode is ready. */
488
488
  setMode(newMode: FSMode): Promise<void>;
489
489
  private _validateCb;
490
+ /** Adapt a promise to optional Node.js callback style.
491
+ * If cb is a function: calls cb(err, result) via setTimeout. Returns void.
492
+ * If cb is missing: returns the promise (allows .then() or await). */
493
+ private _cb;
494
+ /** Like _cb but for void-returning promises (no result value). */
495
+ private _cbVoid;
490
496
  readFile(filePath: string, callback: (err: Error | null, data?: Uint8Array | string) => void): void;
491
497
  readFile(filePath: string, options: ReadOptions | Encoding | null, callback: (err: Error | null, data?: Uint8Array | string) => void): void;
492
498
  writeFile(filePath: string, data: string | Uint8Array, callback: (err: Error | null) => void): void;
@@ -499,7 +505,7 @@ declare class VFSFileSystem {
499
505
  rmdir(filePath: string, options: RmdirOptions, callback: (err: Error | null) => void): void;
500
506
  rm(filePath: string, callback: (err: Error | null) => void): void;
501
507
  rm(filePath: string, options: RmOptions, callback: (err: Error | null) => void): void;
502
- unlink(filePath: string, callback: (err: Error | null) => void): void;
508
+ unlink(filePath: string, callback?: (err: Error | null) => void): any;
503
509
  readdir(filePath: string, callback: (err: Error | null, files?: string[] | Dirent[]) => void): void;
504
510
  readdir(filePath: string, options: ReaddirOptions | Encoding | null, callback: (err: Error | null, files?: string[] | Dirent[]) => void): void;
505
511
  stat(filePath: string, callback: (err: Error | null, stats?: Stats | BigIntStats) => void): void;
@@ -508,47 +514,53 @@ declare class VFSFileSystem {
508
514
  lstat(filePath: string, options: StatOptions, callback: (err: Error | null, stats?: Stats | BigIntStats) => void): void;
509
515
  access(filePath: string, callback: (err: Error | null) => void): void;
510
516
  access(filePath: string, mode: number, callback: (err: Error | null) => void): void;
511
- rename(oldPath: string, newPath: string, callback: (err: Error | null) => void): void;
517
+ rename(oldPath: string, newPath: string, callback?: (err: Error | null) => void): any;
512
518
  copyFile(src: string, dest: string, callback: (err: Error | null) => void): void;
513
519
  copyFile(src: string, dest: string, mode: number, callback: (err: Error | null) => void): void;
514
520
  truncate(filePath: string, callback: (err: Error | null) => void): void;
515
521
  truncate(filePath: string, len: number, callback: (err: Error | null) => void): void;
516
- realpath(filePath: string, callback: (err: Error | null, resolvedPath?: string) => void): void;
517
- chmod(filePath: string, mode: number, callback: (err: Error | null) => void): void;
518
- chown(filePath: string, uid: number, gid: number, callback: (err: Error | null) => void): void;
519
- utimes(filePath: string, atime: Date | number, mtime: Date | number, callback: (err: Error | null) => void): void;
522
+ realpath(filePath: string, callback?: (err: Error | null, resolvedPath?: string) => void): any;
523
+ chmod(filePath: string, mode: number, callback?: (err: Error | null) => void): any;
524
+ chown(filePath: string, uid: number, gid: number, callback?: (err: Error | null) => void): any;
525
+ utimes(filePath: string, atime: Date | number, mtime: Date | number, callback?: (err: Error | null) => void): any;
520
526
  symlink(target: string, linkPath: string, callback: (err: Error | null) => void): void;
521
527
  symlink(target: string, linkPath: string, type: string | null, callback: (err: Error | null) => void): void;
522
528
  readlink(filePath: string, callback: (err: Error | null, linkString?: string | Uint8Array) => void): void;
523
529
  readlink(filePath: string, options: {
524
530
  encoding?: string | null;
525
531
  } | string | null, callback: (err: Error | null, linkString?: string | Uint8Array) => void): void;
526
- link(existingPath: string, newPath: string, callback: (err: Error | null) => void): void;
532
+ link(existingPath: string, newPath: string, callback?: (err: Error | null) => void): any;
527
533
  open(filePath: string, flags: string | number, callback: (err: Error | null, fd?: number) => void): void;
528
534
  open(filePath: string, flags: string | number, mode: number, callback: (err: Error | null, fd?: number) => void): void;
529
- mkdtemp(prefix: string, callback: (err: Error | null, folder?: string) => void): void;
535
+ mkdtemp(prefix: string, callback?: (err: Error | null, folder?: string) => void): any;
530
536
  cp(src: string, dest: string, callback: (err: Error | null) => void): void;
531
537
  cp(src: string, dest: string, options: CpOptions, callback: (err: Error | null) => void): void;
532
- fdatasync(fd: number, callback: (err: Error | null) => void): void;
533
- fsync(fd: number, callback: (err: Error | null) => void): void;
534
- fstat(fd: number, callback: (err: Error | null, stats?: Stats) => void): void;
535
- fstat(fd: number, options: any, callback: (err: Error | null, stats?: Stats) => void): void;
538
+ fdatasync(fd: number, callback?: (err: Error | null) => void): void;
539
+ fsync(fd: number, callback?: (err: Error | null) => void): void;
540
+ fstat(fd: number, callback: (err: Error | null, stats?: Stats | BigIntStats) => void): void;
541
+ fstat(fd: number, options: any, callback: (err: Error | null, stats?: Stats | BigIntStats) => void): void;
536
542
  ftruncate(fd: number, callback: (err: Error | null) => void): void;
537
543
  ftruncate(fd: number, len: number, callback: (err: Error | null) => void): void;
538
544
  read(fd: number, buffer: Uint8Array, offset: number, length: number, position: number | null, callback: (err: Error | null, bytesRead?: number, buffer?: Uint8Array) => void): void;
545
+ read(fd: number, options: {
546
+ buffer: Uint8Array;
547
+ offset?: number;
548
+ length?: number;
549
+ position?: number | null;
550
+ }, callback: (err: Error | null, bytesRead?: number, buffer?: Uint8Array) => void): void;
539
551
  write(fd: number, buffer: Uint8Array, offset: number, length: number, position: number | null, callback: (err: Error | null, bytesWritten?: number, buffer?: Uint8Array) => void): void;
540
552
  write(fd: number, data: string, position: number | null | undefined, encoding: string | undefined, callback: (err: Error | null, bytesWritten?: number, data?: string) => void): void;
541
553
  close(fd: number, callback?: (err: Error | null) => void): void;
542
- exists(filePath: string, callback: (exists: boolean) => void): void;
543
- opendir(filePath: string, callback: (err: Error | null, dir?: Dir) => void): void;
554
+ exists(filePath: string, callback?: (exists: boolean) => void): any;
555
+ opendir(filePath: string, callback?: (err: Error | null, dir?: Dir) => void): any;
544
556
  glob(pattern: string, callback: (err: Error | null, matches?: string[]) => void): void;
545
557
  glob(pattern: string, options: GlobOptions, callback: (err: Error | null, matches?: string[]) => void): void;
546
- futimes(fd: number, atime: Date | number, mtime: Date | number, callback: (err: Error | null) => void): void;
547
- fchmod(fd: number, mode: number, callback: (err: Error | null) => void): void;
548
- fchown(fd: number, uid: number, gid: number, callback: (err: Error | null) => void): void;
549
- lchmod(filePath: string, mode: number, callback: (err: Error | null) => void): void;
550
- lchown(filePath: string, uid: number, gid: number, callback: (err: Error | null) => void): void;
551
- lutimes(filePath: string, atime: Date | number, mtime: Date | number, callback: (err: Error | null) => void): void;
558
+ futimes(fd: number, atime: Date | number, mtime: Date | number, callback?: (err: Error | null) => void): void;
559
+ fchmod(fd: number, mode: number, callback?: (err: Error | null) => void): void;
560
+ fchown(fd: number, uid: number, gid: number, callback?: (err: Error | null) => void): void;
561
+ lchmod(filePath: string, mode: number, callback?: (err: Error | null) => void): any;
562
+ lchown(filePath: string, uid: number, gid: number, callback?: (err: Error | null) => void): any;
563
+ lutimes(filePath: string, atime: Date | number, mtime: Date | number, callback?: (err: Error | null) => void): any;
552
564
  }
553
565
  declare class VFSPromises {
554
566
  private _async;
@@ -642,6 +654,8 @@ declare class VFSPromises {
642
654
  openAsBlob(filePath: string, options?: OpenAsBlobOptions): Promise<Blob>;
643
655
  statfs(path: string): Promise<StatFs>;
644
656
  watch(filePath: string, options?: WatchOptions): AsyncIterable<WatchEventType>;
657
+ fstat(fd: number, options?: StatOptions): Promise<Stats | BigIntStats>;
658
+ ftruncate(fd: number, len?: number): Promise<void>;
645
659
  fsync(_fd: number): Promise<void>;
646
660
  fdatasync(_fd: number): Promise<void>;
647
661
  flush(): Promise<void>;
@@ -666,6 +680,10 @@ declare class SimpleEventEmitter {
666
680
  removeAllListeners(event?: string): this;
667
681
  emit(event: string, ...args: unknown[]): boolean;
668
682
  listenerCount(event: string): number;
683
+ rawListeners(event: string): Function[];
684
+ prependListener(event: string, fn: Listener): this;
685
+ prependOnceListener(event: string, fn: Listener): this;
686
+ eventNames(): string[];
669
687
  }
670
688
  declare class NodeReadable extends SimpleEventEmitter {
671
689
  private _readFn;
package/dist/index.js CHANGED
@@ -59,6 +59,25 @@ var SimpleEventEmitter = class {
59
59
  listenerCount(event) {
60
60
  return this._listeners.get(event)?.length ?? 0;
61
61
  }
62
+ rawListeners(event) {
63
+ return [...this._listeners.get(event) ?? []];
64
+ }
65
+ prependListener(event, fn) {
66
+ const arr = this._listeners.get(event) ?? [];
67
+ arr.unshift(fn);
68
+ this._listeners.set(event, arr);
69
+ return this;
70
+ }
71
+ prependOnceListener(event, fn) {
72
+ const wrapper = (...args) => {
73
+ this.off(event, wrapper);
74
+ fn(...args);
75
+ };
76
+ return this.prependListener(event, wrapper);
77
+ }
78
+ eventNames() {
79
+ return [...this._listeners.keys()].filter((k) => (this._listeners.get(k)?.length ?? 0) > 0);
80
+ }
62
81
  };
63
82
  var NodeReadable = class extends SimpleEventEmitter {
64
83
  constructor(_readFn, destroyFn) {
@@ -852,13 +871,13 @@ function writeSyncFd(syncRequest, fd, bufferOrString, offsetOrPositionOrOptions,
852
871
  if (status !== 0) throw statusToError(status, "write", String(fd));
853
872
  return data ? new DataView(data.buffer, data.byteOffset, data.byteLength).getUint32(0, true) : 0;
854
873
  }
855
- function fstatSync(syncRequest, fd) {
874
+ function fstatSync(syncRequest, fd, options) {
856
875
  const fdBuf = new Uint8Array(4);
857
876
  new DataView(fdBuf.buffer).setUint32(0, fd, true);
858
877
  const buf = encodeRequest(OP.FSTAT, "", 0, fdBuf);
859
878
  const { status, data } = syncRequest(buf);
860
879
  if (status !== 0) throw statusToError(status, "fstat", String(fd));
861
- return decodeStats(data);
880
+ return options?.bigint ? decodeStatsBigInt(data) : decodeStats(data);
862
881
  }
863
882
  function ftruncateSync(syncRequest, fd, len = 0) {
864
883
  const fdBuf = new Uint8Array(12);
@@ -3036,8 +3055,8 @@ var VFSFileSystem = class {
3036
3055
  writeSync(fd, bufferOrString, offsetOrPositionOrOptions, lengthOrEncoding, position) {
3037
3056
  return writeSyncFd(this._sync, fd, bufferOrString, offsetOrPositionOrOptions, lengthOrEncoding, position);
3038
3057
  }
3039
- fstatSync(fd) {
3040
- return fstatSync(this._sync, fd);
3058
+ fstatSync(fd, options) {
3059
+ return fstatSync(this._sync, fd, options);
3041
3060
  }
3042
3061
  ftruncateSync(fd, len) {
3043
3062
  ftruncateSync(this._sync, fd, len);
@@ -3080,11 +3099,13 @@ var VFSFileSystem = class {
3080
3099
  pos = positionOrCallback;
3081
3100
  cb = callback;
3082
3101
  }
3102
+ this._validateCb(cb);
3083
3103
  try {
3084
3104
  const bytesRead = this.readvSync(fd, buffers, pos);
3085
- setTimeout(() => cb(null, bytesRead, buffers), 0);
3105
+ if (cb) setTimeout(() => cb(null, bytesRead, buffers), 0);
3086
3106
  } catch (err) {
3087
- setTimeout(() => cb(err), 0);
3107
+ if (cb) setTimeout(() => cb(err), 0);
3108
+ else throw err;
3088
3109
  }
3089
3110
  }
3090
3111
  writev(fd, buffers, positionOrCallback, callback) {
@@ -3097,11 +3118,13 @@ var VFSFileSystem = class {
3097
3118
  pos = positionOrCallback;
3098
3119
  cb = callback;
3099
3120
  }
3121
+ this._validateCb(cb);
3100
3122
  try {
3101
3123
  const bytesWritten = this.writevSync(fd, buffers, pos);
3102
- setTimeout(() => cb(null, bytesWritten, buffers), 0);
3124
+ if (cb) setTimeout(() => cb(null, bytesWritten, buffers), 0);
3103
3125
  } catch (err) {
3104
- setTimeout(() => cb(err), 0);
3126
+ if (cb) setTimeout(() => cb(err), 0);
3127
+ else throw err;
3105
3128
  }
3106
3129
  }
3107
3130
  // ---- statfs methods ----
@@ -3124,6 +3147,7 @@ var VFSFileSystem = class {
3124
3147
  statfs(path, callback) {
3125
3148
  const result = this.statfsSync(path);
3126
3149
  if (callback) {
3150
+ this._validateCb(callback);
3127
3151
  setTimeout(() => callback(null, result), 0);
3128
3152
  return;
3129
3153
  }
@@ -3337,205 +3361,161 @@ var VFSFileSystem = class {
3337
3361
  // Node.js-style callback overloads for all async operations.
3338
3362
  // These delegate to this.promises.* and adapt the result to (err, result) callbacks.
3339
3363
  _validateCb(cb) {
3340
- if (typeof cb !== "function") {
3364
+ if (cb !== void 0 && cb !== null && typeof cb !== "function") {
3341
3365
  throw new TypeError('The "cb" argument must be of type function. Received ' + typeof cb);
3342
3366
  }
3343
3367
  }
3368
+ /** Adapt a promise to optional Node.js callback style.
3369
+ * If cb is a function: calls cb(err, result) via setTimeout. Returns void.
3370
+ * If cb is missing: returns the promise (allows .then() or await). */
3371
+ _cb(promise, cb, mapResult) {
3372
+ if (typeof cb === "function") {
3373
+ promise.then(
3374
+ (val) => setTimeout(() => cb(null, ...mapResult ? mapResult(val) : [val]), 0),
3375
+ (err) => setTimeout(() => cb(err), 0)
3376
+ );
3377
+ return;
3378
+ }
3379
+ return promise;
3380
+ }
3381
+ /** Like _cb but for void-returning promises (no result value). */
3382
+ _cbVoid(promise, cb) {
3383
+ if (typeof cb === "function") {
3384
+ promise.then(
3385
+ () => setTimeout(() => cb(null), 0),
3386
+ (err) => setTimeout(() => cb(err), 0)
3387
+ );
3388
+ return;
3389
+ }
3390
+ return promise;
3391
+ }
3344
3392
  readFile(filePath, optionsOrCallback, callback) {
3345
3393
  const cb = typeof optionsOrCallback === "function" ? optionsOrCallback : callback;
3346
3394
  this._validateCb(cb);
3347
3395
  const opts = typeof optionsOrCallback === "function" ? void 0 : optionsOrCallback;
3348
- this.promises.readFile(filePath, opts).then(
3349
- (result) => setTimeout(() => cb(null, result), 0),
3350
- (err) => setTimeout(() => cb(err), 0)
3351
- );
3396
+ return this._cb(this.promises.readFile(filePath, opts), cb);
3352
3397
  }
3353
3398
  writeFile(filePath, data, optionsOrCallback, callback) {
3354
3399
  const cb = typeof optionsOrCallback === "function" ? optionsOrCallback : callback;
3355
3400
  this._validateCb(cb);
3356
3401
  const opts = typeof optionsOrCallback === "function" ? void 0 : optionsOrCallback;
3357
- this.promises.writeFile(filePath, data, opts).then(
3358
- () => setTimeout(() => cb(null), 0),
3359
- (err) => setTimeout(() => cb(err), 0)
3360
- );
3402
+ return this._cbVoid(this.promises.writeFile(filePath, data, opts), cb);
3361
3403
  }
3362
3404
  appendFile(filePath, data, optionsOrCallback, callback) {
3363
3405
  const cb = typeof optionsOrCallback === "function" ? optionsOrCallback : callback;
3364
3406
  this._validateCb(cb);
3365
3407
  const opts = typeof optionsOrCallback === "function" ? void 0 : optionsOrCallback;
3366
- this.promises.appendFile(filePath, data, opts).then(
3367
- () => setTimeout(() => cb(null), 0),
3368
- (err) => setTimeout(() => cb(err), 0)
3369
- );
3408
+ return this._cbVoid(this.promises.appendFile(filePath, data, opts), cb);
3370
3409
  }
3371
3410
  mkdir(filePath, optionsOrCallback, callback) {
3372
3411
  const cb = typeof optionsOrCallback === "function" ? optionsOrCallback : callback;
3373
3412
  this._validateCb(cb);
3374
3413
  const opts = typeof optionsOrCallback === "function" ? void 0 : optionsOrCallback;
3375
- this.promises.mkdir(filePath, opts).then(
3376
- (result) => setTimeout(() => cb(null, result), 0),
3377
- (err) => setTimeout(() => cb(err), 0)
3378
- );
3414
+ return this._cb(this.promises.mkdir(filePath, opts), cb);
3379
3415
  }
3380
3416
  rmdir(filePath, optionsOrCallback, callback) {
3381
3417
  const cb = typeof optionsOrCallback === "function" ? optionsOrCallback : callback;
3382
3418
  this._validateCb(cb);
3383
3419
  const opts = typeof optionsOrCallback === "function" ? void 0 : optionsOrCallback;
3384
- this.promises.rmdir(filePath, opts).then(
3385
- () => setTimeout(() => cb(null), 0),
3386
- (err) => setTimeout(() => cb(err), 0)
3387
- );
3420
+ return this._cbVoid(this.promises.rmdir(filePath, opts), cb);
3388
3421
  }
3389
3422
  rm(filePath, optionsOrCallback, callback) {
3390
3423
  const cb = typeof optionsOrCallback === "function" ? optionsOrCallback : callback;
3391
3424
  this._validateCb(cb);
3392
3425
  const opts = typeof optionsOrCallback === "function" ? void 0 : optionsOrCallback;
3393
- this.promises.rm(filePath, opts).then(
3394
- () => setTimeout(() => cb(null), 0),
3395
- (err) => setTimeout(() => cb(err), 0)
3396
- );
3426
+ return this._cbVoid(this.promises.rm(filePath, opts), cb);
3397
3427
  }
3398
3428
  unlink(filePath, callback) {
3399
3429
  this._validateCb(callback);
3400
- this.promises.unlink(filePath).then(
3401
- () => setTimeout(() => callback(null), 0),
3402
- (err) => setTimeout(() => callback(err), 0)
3403
- );
3430
+ return this._cbVoid(this.promises.unlink(filePath), callback);
3404
3431
  }
3405
3432
  readdir(filePath, optionsOrCallback, callback) {
3406
3433
  const cb = typeof optionsOrCallback === "function" ? optionsOrCallback : callback;
3407
3434
  this._validateCb(cb);
3408
3435
  const opts = typeof optionsOrCallback === "function" ? void 0 : optionsOrCallback;
3409
- this.promises.readdir(filePath, opts).then(
3410
- (result) => setTimeout(() => cb(null, result), 0),
3411
- (err) => setTimeout(() => cb(err), 0)
3412
- );
3436
+ return this._cb(this.promises.readdir(filePath, opts), cb);
3413
3437
  }
3414
3438
  stat(filePath, optionsOrCallback, callback) {
3415
3439
  const cb = typeof optionsOrCallback === "function" ? optionsOrCallback : callback;
3416
3440
  this._validateCb(cb);
3417
3441
  const opts = typeof optionsOrCallback === "function" ? void 0 : optionsOrCallback;
3418
- this.promises.stat(filePath, opts).then(
3419
- (result) => setTimeout(() => cb(null, result), 0),
3420
- (err) => setTimeout(() => cb(err), 0)
3421
- );
3442
+ return this._cb(this.promises.stat(filePath, opts), cb);
3422
3443
  }
3423
3444
  lstat(filePath, optionsOrCallback, callback) {
3424
3445
  const cb = typeof optionsOrCallback === "function" ? optionsOrCallback : callback;
3425
3446
  this._validateCb(cb);
3426
3447
  const opts = typeof optionsOrCallback === "function" ? void 0 : optionsOrCallback;
3427
- this.promises.lstat(filePath, opts).then(
3428
- (result) => setTimeout(() => cb(null, result), 0),
3429
- (err) => setTimeout(() => cb(err), 0)
3430
- );
3448
+ return this._cb(this.promises.lstat(filePath, opts), cb);
3431
3449
  }
3432
3450
  access(filePath, modeOrCallback, callback) {
3433
3451
  const cb = typeof modeOrCallback === "function" ? modeOrCallback : callback;
3434
3452
  this._validateCb(cb);
3435
3453
  const mode = typeof modeOrCallback === "function" ? void 0 : modeOrCallback;
3436
- this.promises.access(filePath, mode).then(
3437
- () => setTimeout(() => cb(null), 0),
3438
- (err) => setTimeout(() => cb(err), 0)
3439
- );
3454
+ return this._cbVoid(this.promises.access(filePath, mode), cb);
3440
3455
  }
3441
3456
  rename(oldPath, newPath, callback) {
3442
3457
  this._validateCb(callback);
3443
- this.promises.rename(oldPath, newPath).then(
3444
- () => setTimeout(() => callback(null), 0),
3445
- (err) => setTimeout(() => callback(err), 0)
3446
- );
3458
+ return this._cbVoid(this.promises.rename(oldPath, newPath), callback);
3447
3459
  }
3448
3460
  copyFile(src, dest, modeOrCallback, callback) {
3449
3461
  const cb = typeof modeOrCallback === "function" ? modeOrCallback : callback;
3450
3462
  this._validateCb(cb);
3451
3463
  const mode = typeof modeOrCallback === "function" ? void 0 : modeOrCallback;
3452
- this.promises.copyFile(src, dest, mode).then(
3453
- () => setTimeout(() => cb(null), 0),
3454
- (err) => setTimeout(() => cb(err), 0)
3455
- );
3464
+ return this._cbVoid(this.promises.copyFile(src, dest, mode), cb);
3456
3465
  }
3457
3466
  truncate(filePath, lenOrCallback, callback) {
3458
3467
  const cb = typeof lenOrCallback === "function" ? lenOrCallback : callback;
3459
3468
  this._validateCb(cb);
3460
3469
  const len = typeof lenOrCallback === "function" ? void 0 : lenOrCallback;
3461
- this.promises.truncate(filePath, len).then(
3462
- () => setTimeout(() => cb(null), 0),
3463
- (err) => setTimeout(() => cb(err), 0)
3464
- );
3470
+ return this._cbVoid(this.promises.truncate(filePath, len), cb);
3465
3471
  }
3466
3472
  realpath(filePath, callback) {
3467
3473
  this._validateCb(callback);
3468
- this.promises.realpath(filePath).then(
3469
- (result) => setTimeout(() => callback(null, result), 0),
3470
- (err) => setTimeout(() => callback(err), 0)
3471
- );
3474
+ return this._cb(this.promises.realpath(filePath), callback);
3472
3475
  }
3473
3476
  chmod(filePath, mode, callback) {
3474
3477
  this._validateCb(callback);
3475
- this.promises.chmod(filePath, mode).then(
3476
- () => setTimeout(() => callback(null), 0),
3477
- (err) => setTimeout(() => callback(err), 0)
3478
- );
3478
+ return this._cbVoid(this.promises.chmod(filePath, mode), callback);
3479
3479
  }
3480
3480
  chown(filePath, uid, gid, callback) {
3481
3481
  this._validateCb(callback);
3482
- this.promises.chown(filePath, uid, gid).then(
3483
- () => setTimeout(() => callback(null), 0),
3484
- (err) => setTimeout(() => callback(err), 0)
3485
- );
3482
+ return this._cbVoid(this.promises.chown(filePath, uid, gid), callback);
3486
3483
  }
3487
3484
  utimes(filePath, atime, mtime, callback) {
3488
3485
  this._validateCb(callback);
3489
- this.promises.utimes(filePath, atime, mtime).then(
3490
- () => setTimeout(() => callback(null), 0),
3491
- (err) => setTimeout(() => callback(err), 0)
3492
- );
3486
+ return this._cbVoid(this.promises.utimes(filePath, atime, mtime), callback);
3493
3487
  }
3494
3488
  symlink(target, linkPath, typeOrCallback, callback) {
3495
3489
  const cb = typeof typeOrCallback === "function" ? typeOrCallback : callback;
3496
3490
  this._validateCb(cb);
3497
3491
  const type = typeof typeOrCallback === "function" ? void 0 : typeOrCallback;
3498
- this.promises.symlink(target, linkPath, type).then(
3499
- () => setTimeout(() => cb(null), 0),
3500
- (err) => setTimeout(() => cb(err), 0)
3501
- );
3492
+ return this._cbVoid(this.promises.symlink(target, linkPath, type), cb);
3502
3493
  }
3503
3494
  readlink(filePath, optionsOrCallback, callback) {
3504
3495
  const cb = typeof optionsOrCallback === "function" ? optionsOrCallback : callback;
3505
3496
  this._validateCb(cb);
3506
3497
  const opts = typeof optionsOrCallback === "function" ? void 0 : optionsOrCallback;
3507
- this.promises.readlink(filePath, opts).then(
3508
- (result) => setTimeout(() => cb(null, result), 0),
3509
- (err) => setTimeout(() => cb(err), 0)
3510
- );
3498
+ return this._cb(this.promises.readlink(filePath, opts), cb);
3511
3499
  }
3512
3500
  link(existingPath, newPath, callback) {
3513
3501
  this._validateCb(callback);
3514
- this.promises.link(existingPath, newPath).then(
3515
- () => setTimeout(() => callback(null), 0),
3516
- (err) => setTimeout(() => callback(err), 0)
3517
- );
3502
+ return this._cbVoid(this.promises.link(existingPath, newPath), callback);
3518
3503
  }
3519
3504
  open(filePath, flags, modeOrCallback, callback) {
3520
3505
  const cb = typeof modeOrCallback === "function" ? modeOrCallback : callback;
3521
3506
  this._validateCb(cb);
3522
3507
  const mode = typeof modeOrCallback === "function" ? void 0 : modeOrCallback;
3523
- this.promises.open(filePath, flags, mode).then(
3524
- (handle) => setTimeout(() => cb(null, handle.fd), 0),
3525
- (err) => setTimeout(() => cb(err), 0)
3526
- );
3508
+ return this._cb(this.promises.open(filePath, flags, mode), cb, (handle) => [handle.fd]);
3527
3509
  }
3528
3510
  mkdtemp(prefix, callback) {
3529
3511
  this._validateCb(callback);
3530
- this.promises.mkdtemp(prefix).then(
3531
- (result) => setTimeout(() => callback(null, result), 0),
3532
- (err) => setTimeout(() => callback(err), 0)
3533
- );
3512
+ return this._cb(this.promises.mkdtemp(prefix), callback);
3534
3513
  }
3535
3514
  cp(src, dest, optionsOrCallback, callback) {
3536
3515
  const cb = typeof optionsOrCallback === "function" ? optionsOrCallback : callback;
3537
3516
  const opts = typeof optionsOrCallback === "function" ? void 0 : optionsOrCallback;
3538
3517
  if (cb) {
3518
+ this._validateCb(cb);
3539
3519
  this._cpAsync(src, dest, opts).then(
3540
3520
  () => setTimeout(() => cb(null), 0),
3541
3521
  (err) => setTimeout(() => cb(err), 0)
@@ -3548,28 +3528,32 @@ var VFSFileSystem = class {
3548
3528
  this._validateCb(callback);
3549
3529
  try {
3550
3530
  this.fdatasyncSync(fd);
3551
- setTimeout(() => callback(null), 0);
3531
+ if (callback) setTimeout(() => callback(null), 0);
3552
3532
  } catch (err) {
3553
- setTimeout(() => callback(err), 0);
3533
+ if (callback) setTimeout(() => callback(err), 0);
3534
+ else throw err;
3554
3535
  }
3555
3536
  }
3556
3537
  fsync(fd, callback) {
3557
3538
  this._validateCb(callback);
3558
3539
  try {
3559
3540
  this.fsyncSync(fd);
3560
- setTimeout(() => callback(null), 0);
3541
+ if (callback) setTimeout(() => callback(null), 0);
3561
3542
  } catch (err) {
3562
- setTimeout(() => callback(err), 0);
3543
+ if (callback) setTimeout(() => callback(err), 0);
3544
+ else throw err;
3563
3545
  }
3564
3546
  }
3565
3547
  fstat(fd, optionsOrCallback, callback) {
3566
3548
  const cb = typeof optionsOrCallback === "function" ? optionsOrCallback : callback;
3567
3549
  this._validateCb(cb);
3550
+ const opts = typeof optionsOrCallback === "function" ? void 0 : optionsOrCallback;
3568
3551
  try {
3569
- const result = this.fstatSync(fd);
3570
- setTimeout(() => cb(null, result), 0);
3552
+ const result = this.fstatSync(fd, opts);
3553
+ if (cb) setTimeout(() => cb(null, result), 0);
3571
3554
  } catch (err) {
3572
- setTimeout(() => cb(err), 0);
3555
+ if (cb) setTimeout(() => cb(err), 0);
3556
+ else throw err;
3573
3557
  }
3574
3558
  }
3575
3559
  ftruncate(fd, lenOrCallback, callback) {
@@ -3578,18 +3562,38 @@ var VFSFileSystem = class {
3578
3562
  const len = typeof lenOrCallback === "function" ? 0 : lenOrCallback;
3579
3563
  try {
3580
3564
  this.ftruncateSync(fd, len);
3581
- setTimeout(() => cb(null), 0);
3565
+ if (cb) setTimeout(() => cb(null), 0);
3582
3566
  } catch (err) {
3583
- setTimeout(() => cb(err), 0);
3567
+ if (cb) setTimeout(() => cb(err), 0);
3568
+ else throw err;
3584
3569
  }
3585
3570
  }
3586
3571
  read(fd, buffer, offset, length, position, callback) {
3587
- this._validateCb(callback);
3572
+ let cb;
3573
+ let buf;
3574
+ let off;
3575
+ let len;
3576
+ let pos;
3577
+ if (typeof buffer === "object" && !(buffer instanceof Uint8Array) && buffer !== null && "buffer" in buffer) {
3578
+ cb = offset;
3579
+ buf = buffer.buffer;
3580
+ off = buffer.offset ?? 0;
3581
+ len = buffer.length ?? buf.byteLength;
3582
+ pos = buffer.position ?? null;
3583
+ } else {
3584
+ cb = callback;
3585
+ buf = buffer;
3586
+ off = offset;
3587
+ len = length;
3588
+ pos = position;
3589
+ }
3590
+ this._validateCb(cb);
3588
3591
  try {
3589
- const bytesRead = this.readSync(fd, buffer, offset, length, position);
3590
- setTimeout(() => callback(null, bytesRead, buffer), 0);
3592
+ const bytesRead = this.readSync(fd, buf, off, len, pos);
3593
+ if (cb) setTimeout(() => cb(null, bytesRead, buf), 0);
3591
3594
  } catch (err) {
3592
- setTimeout(() => callback(err), 0);
3595
+ if (cb) setTimeout(() => cb(err), 0);
3596
+ else throw err;
3593
3597
  }
3594
3598
  }
3595
3599
  write(fd, bufferOrString, offsetOrPosition, lengthOrEncoding, position, callback) {
@@ -3607,9 +3611,10 @@ var VFSFileSystem = class {
3607
3611
  const pos = typeof position === "function" ? void 0 : position;
3608
3612
  bytesWritten = this.writeSync(fd, bufferOrString, off, len, pos);
3609
3613
  }
3610
- setTimeout(() => cb(null, bytesWritten, bufferOrString), 0);
3614
+ if (cb) setTimeout(() => cb(null, bytesWritten, bufferOrString), 0);
3611
3615
  } catch (err) {
3612
- setTimeout(() => cb(err), 0);
3616
+ if (cb) setTimeout(() => cb(err), 0);
3617
+ else throw err;
3613
3618
  }
3614
3619
  }
3615
3620
  close(fd, callback) {
@@ -3622,59 +3627,49 @@ var VFSFileSystem = class {
3622
3627
  }
3623
3628
  }
3624
3629
  exists(filePath, callback) {
3625
- this.promises.exists(filePath).then(
3626
- (result) => setTimeout(() => callback(result), 0),
3627
- () => setTimeout(() => callback(false), 0)
3628
- );
3630
+ const p = this.promises.exists(filePath);
3631
+ if (typeof callback === "function") {
3632
+ p.then(
3633
+ (result) => setTimeout(() => callback(result), 0),
3634
+ () => setTimeout(() => callback(false), 0)
3635
+ );
3636
+ return;
3637
+ }
3638
+ return p;
3629
3639
  }
3630
3640
  opendir(filePath, callback) {
3631
3641
  this._validateCb(callback);
3632
- this.promises.opendir(filePath).then(
3633
- (dir) => setTimeout(() => callback(null, dir), 0),
3634
- (err) => setTimeout(() => callback(err), 0)
3635
- );
3642
+ return this._cb(this.promises.opendir(filePath), callback);
3636
3643
  }
3637
3644
  glob(pattern, optionsOrCallback, callback) {
3638
3645
  const cb = typeof optionsOrCallback === "function" ? optionsOrCallback : callback;
3639
3646
  this._validateCb(cb);
3640
3647
  const opts = typeof optionsOrCallback === "function" ? void 0 : optionsOrCallback;
3641
- this.promises.glob(pattern, opts).then(
3642
- (result) => setTimeout(() => cb(null, result), 0),
3643
- (err) => setTimeout(() => cb(err), 0)
3644
- );
3648
+ return this._cb(this.promises.glob(pattern, opts), cb);
3645
3649
  }
3646
3650
  futimes(fd, atime, mtime, callback) {
3647
3651
  this._validateCb(callback);
3648
- setTimeout(() => callback(null), 0);
3652
+ if (callback) setTimeout(() => callback(null), 0);
3649
3653
  }
3650
3654
  fchmod(fd, mode, callback) {
3651
3655
  this._validateCb(callback);
3652
- setTimeout(() => callback(null), 0);
3656
+ if (callback) setTimeout(() => callback(null), 0);
3653
3657
  }
3654
3658
  fchown(fd, uid, gid, callback) {
3655
3659
  this._validateCb(callback);
3656
- setTimeout(() => callback(null), 0);
3660
+ if (callback) setTimeout(() => callback(null), 0);
3657
3661
  }
3658
3662
  lchmod(filePath, mode, callback) {
3659
3663
  this._validateCb(callback);
3660
- this.promises.lchmod(filePath, mode).then(
3661
- () => setTimeout(() => callback(null), 0),
3662
- (err) => setTimeout(() => callback(err), 0)
3663
- );
3664
+ return this._cbVoid(this.promises.lchmod(filePath, mode), callback);
3664
3665
  }
3665
3666
  lchown(filePath, uid, gid, callback) {
3666
3667
  this._validateCb(callback);
3667
- this.promises.lchown(filePath, uid, gid).then(
3668
- () => setTimeout(() => callback(null), 0),
3669
- (err) => setTimeout(() => callback(err), 0)
3670
- );
3668
+ return this._cbVoid(this.promises.lchown(filePath, uid, gid), callback);
3671
3669
  }
3672
3670
  lutimes(filePath, atime, mtime, callback) {
3673
3671
  this._validateCb(callback);
3674
- this.promises.lutimes(filePath, atime, mtime).then(
3675
- () => setTimeout(() => callback(null), 0),
3676
- (err) => setTimeout(() => callback(err), 0)
3677
- );
3672
+ return this._cbVoid(this.promises.lutimes(filePath, atime, mtime), callback);
3678
3673
  }
3679
3674
  };
3680
3675
  var VFSPromises = class {
@@ -3866,6 +3861,15 @@ var VFSPromises = class {
3866
3861
  async *watch(filePath, options) {
3867
3862
  yield* watchAsync(this._ns, this._async, filePath, options);
3868
3863
  }
3864
+ async fstat(fd, options) {
3865
+ const { status, data } = await this._async(OP.FSTAT, "", 0, null, void 0, { fd });
3866
+ if (status !== 0) throw statusToError(status, "fstat", String(fd));
3867
+ return options?.bigint ? decodeStatsBigInt(data) : decodeStats(data);
3868
+ }
3869
+ async ftruncate(fd, len = 0) {
3870
+ const { status } = await this._async(OP.FTRUNCATE, "", 0, null, void 0, { fd, length: len });
3871
+ if (status !== 0) throw statusToError(status, "ftruncate", String(fd));
3872
+ }
3869
3873
  async fsync(_fd) {
3870
3874
  await this._async(OP.FSYNC, "");
3871
3875
  }