@componentor/fs 3.0.27 → 3.0.29

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.js CHANGED
@@ -71,6 +71,7 @@ var NodeReadable = class extends SimpleEventEmitter {
71
71
  _ended = false;
72
72
  _reading = false;
73
73
  _readBuffer = null;
74
+ _encoding = null;
74
75
  /** Whether the stream is still readable (not ended or destroyed). */
75
76
  readable = true;
76
77
  /** The file path this stream reads from (set externally). */
@@ -97,6 +98,14 @@ var NodeReadable = class extends SimpleEventEmitter {
97
98
  this._drain();
98
99
  return this;
99
100
  }
101
+ /**
102
+ * Set the character encoding for data read from this stream.
103
+ * When set, 'data' events emit strings instead of Uint8Array.
104
+ */
105
+ setEncoding(encoding) {
106
+ this._encoding = encoding;
107
+ return this;
108
+ }
100
109
  /**
101
110
  * Non-flowing read — returns the last buffered chunk or null.
102
111
  * Node.js has a complex buffer system; we keep it simple here.
@@ -174,7 +183,11 @@ var NodeReadable = class extends SimpleEventEmitter {
174
183
  }
175
184
  this.bytesRead += result.value.byteLength;
176
185
  this._readBuffer = result.value;
177
- this.emit("data", result.value);
186
+ if (this._encoding) {
187
+ this.emit("data", new TextDecoder(this._encoding).decode(result.value));
188
+ } else {
189
+ this.emit("data", result.value);
190
+ }
178
191
  }
179
192
  } catch (err) {
180
193
  if (!this._destroyed) {
@@ -201,7 +214,22 @@ var NodeWritable = class extends SimpleEventEmitter {
201
214
  _destroyed = false;
202
215
  _finished = false;
203
216
  _writing = false;
217
+ _corked = false;
204
218
  // -- public API -----------------------------------------------------------
219
+ /**
220
+ * Buffer all writes until `uncork()` is called.
221
+ * In this minimal implementation we only track the flag for compatibility.
222
+ */
223
+ cork() {
224
+ this._corked = true;
225
+ }
226
+ /**
227
+ * Flush buffered writes (clears the cork flag).
228
+ * In this minimal implementation we only track the flag for compatibility.
229
+ */
230
+ uncork() {
231
+ this._corked = false;
232
+ }
205
233
  write(chunk, encodingOrCb, cb) {
206
234
  const callback = typeof encodingOrCb === "function" ? encodingOrCb : cb;
207
235
  if (this._destroyed || this._finished) {
@@ -1148,6 +1176,21 @@ async function readFile(asyncRequest, filePath, options) {
1148
1176
  }
1149
1177
  }
1150
1178
 
1179
+ // src/methods/chmod.ts
1180
+ function chmodSync(syncRequest, filePath, mode) {
1181
+ const modeBuf = new Uint8Array(4);
1182
+ new DataView(modeBuf.buffer).setUint32(0, mode, true);
1183
+ const buf = encodeRequest(OP.CHMOD, filePath, 0, modeBuf);
1184
+ const { status } = syncRequest(buf);
1185
+ if (status !== 0) throw statusToError(status, "chmod", filePath);
1186
+ }
1187
+ async function chmod(asyncRequest, filePath, mode) {
1188
+ const modeBuf = new Uint8Array(4);
1189
+ new DataView(modeBuf.buffer).setUint32(0, mode, true);
1190
+ const { status } = await asyncRequest(OP.CHMOD, filePath, 0, modeBuf);
1191
+ if (status !== 0) throw statusToError(status, "chmod", filePath);
1192
+ }
1193
+
1151
1194
  // src/methods/writeFile.ts
1152
1195
  var encoder3 = new TextEncoder();
1153
1196
  function writeFileSync(syncRequest, filePath, data, options) {
@@ -1163,9 +1206,12 @@ function writeFileSync(syncRequest, filePath, data, options) {
1163
1206
  const buf = encodeRequest(OP.WRITE, filePath, flags, encoded);
1164
1207
  const { status } = syncRequest(buf);
1165
1208
  if (status !== 0) throw statusToError(status, "write", filePath);
1209
+ if (opts?.mode !== void 0) {
1210
+ chmodSync(syncRequest, filePath, opts.mode);
1211
+ }
1166
1212
  return;
1167
1213
  }
1168
- const fd = openSync(syncRequest, filePath, flag);
1214
+ const fd = openSync(syncRequest, filePath, flag, opts?.mode);
1169
1215
  try {
1170
1216
  writeSyncFd(syncRequest, fd, encoded, 0, encoded.byteLength, 0);
1171
1217
  } finally {
@@ -1185,9 +1231,12 @@ async function writeFile(asyncRequest, filePath, data, options) {
1185
1231
  const { status } = await asyncRequest(OP.WRITE, filePath, flags, encoded);
1186
1232
  if (signal?.aborted) throw new DOMException("The operation was aborted", "AbortError");
1187
1233
  if (status !== 0) throw statusToError(status, "write", filePath);
1234
+ if (opts?.mode !== void 0) {
1235
+ await chmod(asyncRequest, filePath, opts.mode);
1236
+ }
1188
1237
  return;
1189
1238
  }
1190
- const handle = await open(asyncRequest, filePath, flag);
1239
+ const handle = await open(asyncRequest, filePath, flag, opts?.mode);
1191
1240
  try {
1192
1241
  await handle.writeFile(encoded);
1193
1242
  if (signal?.aborted) throw new DOMException("The operation was aborted", "AbortError");
@@ -1343,6 +1392,10 @@ async function unlink(asyncRequest, filePath) {
1343
1392
  }
1344
1393
 
1345
1394
  // src/methods/readdir.ts
1395
+ var textEncoder = new TextEncoder();
1396
+ function namesToBuffers(names) {
1397
+ return names.map((n) => textEncoder.encode(n));
1398
+ }
1346
1399
  function readdirBaseSync(syncRequest, filePath, withFileTypes) {
1347
1400
  const flags = withFileTypes ? 1 : 0;
1348
1401
  const buf = encodeRequest(OP.READDIR, filePath, flags);
@@ -1428,28 +1481,46 @@ async function readdirRecursiveAsync(asyncRequest, basePath, prefix, withFileTyp
1428
1481
  return results;
1429
1482
  }
1430
1483
  function readdirSync(syncRequest, filePath, options) {
1431
- const opts = typeof options === "string" ? { } : options;
1484
+ const opts = typeof options === "string" ? { encoding: options } : options;
1485
+ const asBuffer = opts?.encoding === "buffer";
1432
1486
  if (opts?.recursive) {
1433
- return readdirRecursiveSync(
1487
+ const result2 = readdirRecursiveSync(
1434
1488
  syncRequest,
1435
1489
  filePath,
1436
1490
  "",
1437
1491
  !!opts?.withFileTypes
1438
1492
  );
1493
+ if (asBuffer && !opts?.withFileTypes) {
1494
+ return namesToBuffers(result2);
1495
+ }
1496
+ return result2;
1497
+ }
1498
+ const result = readdirBaseSync(syncRequest, filePath, !!opts?.withFileTypes);
1499
+ if (asBuffer && !opts?.withFileTypes) {
1500
+ return namesToBuffers(result);
1439
1501
  }
1440
- return readdirBaseSync(syncRequest, filePath, !!opts?.withFileTypes);
1502
+ return result;
1441
1503
  }
1442
1504
  async function readdir(asyncRequest, filePath, options) {
1443
- const opts = typeof options === "string" ? { } : options;
1505
+ const opts = typeof options === "string" ? { encoding: options } : options;
1506
+ const asBuffer = opts?.encoding === "buffer";
1444
1507
  if (opts?.recursive) {
1445
- return readdirRecursiveAsync(
1508
+ const result2 = await readdirRecursiveAsync(
1446
1509
  asyncRequest,
1447
1510
  filePath,
1448
1511
  "",
1449
1512
  !!opts?.withFileTypes
1450
1513
  );
1514
+ if (asBuffer && !opts?.withFileTypes) {
1515
+ return namesToBuffers(result2);
1516
+ }
1517
+ return result2;
1518
+ }
1519
+ const result = await readdirBaseAsync(asyncRequest, filePath, !!opts?.withFileTypes);
1520
+ if (asBuffer && !opts?.withFileTypes) {
1521
+ return namesToBuffers(result);
1451
1522
  }
1452
- return readdirBaseAsync(asyncRequest, filePath, !!opts?.withFileTypes);
1523
+ return result;
1453
1524
  }
1454
1525
 
1455
1526
  // src/methods/stat.ts
@@ -1548,21 +1619,6 @@ async function realpath(asyncRequest, filePath) {
1548
1619
  return decoder5.decode(data);
1549
1620
  }
1550
1621
 
1551
- // src/methods/chmod.ts
1552
- function chmodSync(syncRequest, filePath, mode) {
1553
- const modeBuf = new Uint8Array(4);
1554
- new DataView(modeBuf.buffer).setUint32(0, mode, true);
1555
- const buf = encodeRequest(OP.CHMOD, filePath, 0, modeBuf);
1556
- const { status } = syncRequest(buf);
1557
- if (status !== 0) throw statusToError(status, "chmod", filePath);
1558
- }
1559
- async function chmod(asyncRequest, filePath, mode) {
1560
- const modeBuf = new Uint8Array(4);
1561
- new DataView(modeBuf.buffer).setUint32(0, mode, true);
1562
- const { status } = await asyncRequest(OP.CHMOD, filePath, 0, modeBuf);
1563
- if (status !== 0) throw statusToError(status, "chmod", filePath);
1564
- }
1565
-
1566
1622
  // src/methods/chown.ts
1567
1623
  function chownSync(syncRequest, filePath, uid, gid) {
1568
1624
  const ownerBuf = new Uint8Array(8);
@@ -2002,7 +2058,11 @@ function emptyStats() {
2002
2058
  atime: zero,
2003
2059
  mtime: zero,
2004
2060
  ctime: zero,
2005
- birthtime: zero
2061
+ birthtime: zero,
2062
+ atimeNs: 0,
2063
+ mtimeNs: 0,
2064
+ ctimeNs: 0,
2065
+ birthtimeNs: 0
2006
2066
  };
2007
2067
  }
2008
2068
  async function* watchAsync(ns, _asyncRequest, filePath, options) {
@@ -2294,6 +2354,12 @@ var VFSFileSystem = class {
2294
2354
  this.rejectReady = reject;
2295
2355
  });
2296
2356
  this.promises = new VFSPromises(this._async, ns);
2357
+ const boundRealpath = this.realpath.bind(this);
2358
+ boundRealpath.native = boundRealpath;
2359
+ this.realpath = boundRealpath;
2360
+ const boundRealpathSync = this.realpathSync.bind(this);
2361
+ boundRealpathSync.native = boundRealpathSync;
2362
+ this.realpathSync = boundRealpathSync;
2297
2363
  instanceRegistry.set(ns, this);
2298
2364
  this.bootstrap();
2299
2365
  }
@@ -2767,6 +2833,25 @@ var VFSFileSystem = class {
2767
2833
  globSync(pattern, options) {
2768
2834
  return globSync(this._sync, pattern, options);
2769
2835
  }
2836
+ opendirSync(filePath) {
2837
+ const dirPath = toPathString(filePath);
2838
+ const entries = this.readdirSync(dirPath, { withFileTypes: true });
2839
+ let index = 0;
2840
+ return {
2841
+ path: dirPath,
2842
+ async read() {
2843
+ if (index >= entries.length) return null;
2844
+ return entries[index++];
2845
+ },
2846
+ async close() {
2847
+ },
2848
+ async *[Symbol.asyncIterator]() {
2849
+ for (const entry of entries) {
2850
+ yield entry;
2851
+ }
2852
+ }
2853
+ };
2854
+ }
2770
2855
  statSync(filePath, options) {
2771
2856
  return statSync(this._sync, toPathString(filePath), options);
2772
2857
  }
@@ -2919,6 +3004,9 @@ var VFSFileSystem = class {
2919
3004
  utimesSync(filePath, atime, mtime) {
2920
3005
  utimesSync(this._sync, toPathString(filePath), atime, mtime);
2921
3006
  }
3007
+ /** utimes on an open file descriptor. No-op in this VFS (cannot resolve fd to path). */
3008
+ futimesSync(_fd, _atime, _mtime) {
3009
+ }
2922
3010
  /** Like utimesSync but operates on the symlink itself. In this VFS, delegates to utimesSync. */
2923
3011
  lutimesSync(filePath, atime, mtime) {
2924
3012
  utimesSync(this._sync, filePath, atime, mtime);
@@ -2957,6 +3045,9 @@ var VFSFileSystem = class {
2957
3045
  fdatasyncSync(fd) {
2958
3046
  fdatasyncSync(this._sync, fd);
2959
3047
  }
3048
+ fsyncSync(fd) {
3049
+ fdatasyncSync(this._sync, fd);
3050
+ }
2960
3051
  // ---- Vector I/O methods ----
2961
3052
  readvSync(fd, buffers, position) {
2962
3053
  let totalRead = 0;
@@ -3232,168 +3323,168 @@ var VFSFileSystem = class {
3232
3323
  const cb = typeof optionsOrCallback === "function" ? optionsOrCallback : callback;
3233
3324
  const opts = typeof optionsOrCallback === "function" ? void 0 : optionsOrCallback;
3234
3325
  this.promises.readFile(filePath, opts).then(
3235
- (result) => cb(null, result),
3236
- (err) => cb(err)
3326
+ (result) => setTimeout(() => cb(null, result), 0),
3327
+ (err) => setTimeout(() => cb(err), 0)
3237
3328
  );
3238
3329
  }
3239
3330
  writeFile(filePath, data, optionsOrCallback, callback) {
3240
3331
  const cb = typeof optionsOrCallback === "function" ? optionsOrCallback : callback;
3241
3332
  const opts = typeof optionsOrCallback === "function" ? void 0 : optionsOrCallback;
3242
3333
  this.promises.writeFile(filePath, data, opts).then(
3243
- () => cb(null),
3244
- (err) => cb(err)
3334
+ () => setTimeout(() => cb(null), 0),
3335
+ (err) => setTimeout(() => cb(err), 0)
3245
3336
  );
3246
3337
  }
3247
3338
  appendFile(filePath, data, optionsOrCallback, callback) {
3248
3339
  const cb = typeof optionsOrCallback === "function" ? optionsOrCallback : callback;
3249
3340
  const opts = typeof optionsOrCallback === "function" ? void 0 : optionsOrCallback;
3250
3341
  this.promises.appendFile(filePath, data, opts).then(
3251
- () => cb(null),
3252
- (err) => cb(err)
3342
+ () => setTimeout(() => cb(null), 0),
3343
+ (err) => setTimeout(() => cb(err), 0)
3253
3344
  );
3254
3345
  }
3255
3346
  mkdir(filePath, optionsOrCallback, callback) {
3256
3347
  const cb = typeof optionsOrCallback === "function" ? optionsOrCallback : callback;
3257
3348
  const opts = typeof optionsOrCallback === "function" ? void 0 : optionsOrCallback;
3258
3349
  this.promises.mkdir(filePath, opts).then(
3259
- (result) => cb(null, result),
3260
- (err) => cb(err)
3350
+ (result) => setTimeout(() => cb(null, result), 0),
3351
+ (err) => setTimeout(() => cb(err), 0)
3261
3352
  );
3262
3353
  }
3263
3354
  rmdir(filePath, optionsOrCallback, callback) {
3264
3355
  const cb = typeof optionsOrCallback === "function" ? optionsOrCallback : callback;
3265
3356
  const opts = typeof optionsOrCallback === "function" ? void 0 : optionsOrCallback;
3266
3357
  this.promises.rmdir(filePath, opts).then(
3267
- () => cb(null),
3268
- (err) => cb(err)
3358
+ () => setTimeout(() => cb(null), 0),
3359
+ (err) => setTimeout(() => cb(err), 0)
3269
3360
  );
3270
3361
  }
3271
3362
  rm(filePath, optionsOrCallback, callback) {
3272
3363
  const cb = typeof optionsOrCallback === "function" ? optionsOrCallback : callback;
3273
3364
  const opts = typeof optionsOrCallback === "function" ? void 0 : optionsOrCallback;
3274
3365
  this.promises.rm(filePath, opts).then(
3275
- () => cb(null),
3276
- (err) => cb(err)
3366
+ () => setTimeout(() => cb(null), 0),
3367
+ (err) => setTimeout(() => cb(err), 0)
3277
3368
  );
3278
3369
  }
3279
3370
  unlink(filePath, callback) {
3280
3371
  this.promises.unlink(filePath).then(
3281
- () => callback(null),
3282
- (err) => callback(err)
3372
+ () => setTimeout(() => callback(null), 0),
3373
+ (err) => setTimeout(() => callback(err), 0)
3283
3374
  );
3284
3375
  }
3285
3376
  readdir(filePath, optionsOrCallback, callback) {
3286
3377
  const cb = typeof optionsOrCallback === "function" ? optionsOrCallback : callback;
3287
3378
  const opts = typeof optionsOrCallback === "function" ? void 0 : optionsOrCallback;
3288
3379
  this.promises.readdir(filePath, opts).then(
3289
- (result) => cb(null, result),
3290
- (err) => cb(err)
3380
+ (result) => setTimeout(() => cb(null, result), 0),
3381
+ (err) => setTimeout(() => cb(err), 0)
3291
3382
  );
3292
3383
  }
3293
3384
  stat(filePath, optionsOrCallback, callback) {
3294
3385
  const cb = typeof optionsOrCallback === "function" ? optionsOrCallback : callback;
3295
3386
  const opts = typeof optionsOrCallback === "function" ? void 0 : optionsOrCallback;
3296
3387
  this.promises.stat(filePath, opts).then(
3297
- (result) => cb(null, result),
3298
- (err) => cb(err)
3388
+ (result) => setTimeout(() => cb(null, result), 0),
3389
+ (err) => setTimeout(() => cb(err), 0)
3299
3390
  );
3300
3391
  }
3301
3392
  lstat(filePath, optionsOrCallback, callback) {
3302
3393
  const cb = typeof optionsOrCallback === "function" ? optionsOrCallback : callback;
3303
3394
  const opts = typeof optionsOrCallback === "function" ? void 0 : optionsOrCallback;
3304
3395
  this.promises.lstat(filePath, opts).then(
3305
- (result) => cb(null, result),
3306
- (err) => cb(err)
3396
+ (result) => setTimeout(() => cb(null, result), 0),
3397
+ (err) => setTimeout(() => cb(err), 0)
3307
3398
  );
3308
3399
  }
3309
3400
  access(filePath, modeOrCallback, callback) {
3310
3401
  const cb = typeof modeOrCallback === "function" ? modeOrCallback : callback;
3311
3402
  const mode = typeof modeOrCallback === "function" ? void 0 : modeOrCallback;
3312
3403
  this.promises.access(filePath, mode).then(
3313
- () => cb(null),
3314
- (err) => cb(err)
3404
+ () => setTimeout(() => cb(null), 0),
3405
+ (err) => setTimeout(() => cb(err), 0)
3315
3406
  );
3316
3407
  }
3317
3408
  rename(oldPath, newPath, callback) {
3318
3409
  this.promises.rename(oldPath, newPath).then(
3319
- () => callback(null),
3320
- (err) => callback(err)
3410
+ () => setTimeout(() => callback(null), 0),
3411
+ (err) => setTimeout(() => callback(err), 0)
3321
3412
  );
3322
3413
  }
3323
3414
  copyFile(src, dest, modeOrCallback, callback) {
3324
3415
  const cb = typeof modeOrCallback === "function" ? modeOrCallback : callback;
3325
3416
  const mode = typeof modeOrCallback === "function" ? void 0 : modeOrCallback;
3326
3417
  this.promises.copyFile(src, dest, mode).then(
3327
- () => cb(null),
3328
- (err) => cb(err)
3418
+ () => setTimeout(() => cb(null), 0),
3419
+ (err) => setTimeout(() => cb(err), 0)
3329
3420
  );
3330
3421
  }
3331
3422
  truncate(filePath, lenOrCallback, callback) {
3332
3423
  const cb = typeof lenOrCallback === "function" ? lenOrCallback : callback;
3333
3424
  const len = typeof lenOrCallback === "function" ? void 0 : lenOrCallback;
3334
3425
  this.promises.truncate(filePath, len).then(
3335
- () => cb(null),
3336
- (err) => cb(err)
3426
+ () => setTimeout(() => cb(null), 0),
3427
+ (err) => setTimeout(() => cb(err), 0)
3337
3428
  );
3338
3429
  }
3339
3430
  realpath(filePath, callback) {
3340
3431
  this.promises.realpath(filePath).then(
3341
- (result) => callback(null, result),
3342
- (err) => callback(err)
3432
+ (result) => setTimeout(() => callback(null, result), 0),
3433
+ (err) => setTimeout(() => callback(err), 0)
3343
3434
  );
3344
3435
  }
3345
3436
  chmod(filePath, mode, callback) {
3346
3437
  this.promises.chmod(filePath, mode).then(
3347
- () => callback(null),
3348
- (err) => callback(err)
3438
+ () => setTimeout(() => callback(null), 0),
3439
+ (err) => setTimeout(() => callback(err), 0)
3349
3440
  );
3350
3441
  }
3351
3442
  chown(filePath, uid, gid, callback) {
3352
3443
  this.promises.chown(filePath, uid, gid).then(
3353
- () => callback(null),
3354
- (err) => callback(err)
3444
+ () => setTimeout(() => callback(null), 0),
3445
+ (err) => setTimeout(() => callback(err), 0)
3355
3446
  );
3356
3447
  }
3357
3448
  utimes(filePath, atime, mtime, callback) {
3358
3449
  this.promises.utimes(filePath, atime, mtime).then(
3359
- () => callback(null),
3360
- (err) => callback(err)
3450
+ () => setTimeout(() => callback(null), 0),
3451
+ (err) => setTimeout(() => callback(err), 0)
3361
3452
  );
3362
3453
  }
3363
3454
  symlink(target, linkPath, typeOrCallback, callback) {
3364
3455
  const cb = typeof typeOrCallback === "function" ? typeOrCallback : callback;
3365
3456
  const type = typeof typeOrCallback === "function" ? void 0 : typeOrCallback;
3366
3457
  this.promises.symlink(target, linkPath, type).then(
3367
- () => cb(null),
3368
- (err) => cb(err)
3458
+ () => setTimeout(() => cb(null), 0),
3459
+ (err) => setTimeout(() => cb(err), 0)
3369
3460
  );
3370
3461
  }
3371
3462
  readlink(filePath, optionsOrCallback, callback) {
3372
3463
  const cb = typeof optionsOrCallback === "function" ? optionsOrCallback : callback;
3373
3464
  const opts = typeof optionsOrCallback === "function" ? void 0 : optionsOrCallback;
3374
3465
  this.promises.readlink(filePath, opts).then(
3375
- (result) => cb(null, result),
3376
- (err) => cb(err)
3466
+ (result) => setTimeout(() => cb(null, result), 0),
3467
+ (err) => setTimeout(() => cb(err), 0)
3377
3468
  );
3378
3469
  }
3379
3470
  link(existingPath, newPath, callback) {
3380
3471
  this.promises.link(existingPath, newPath).then(
3381
- () => callback(null),
3382
- (err) => callback(err)
3472
+ () => setTimeout(() => callback(null), 0),
3473
+ (err) => setTimeout(() => callback(err), 0)
3383
3474
  );
3384
3475
  }
3385
3476
  open(filePath, flags, modeOrCallback, callback) {
3386
3477
  const cb = typeof modeOrCallback === "function" ? modeOrCallback : callback;
3387
3478
  const mode = typeof modeOrCallback === "function" ? void 0 : modeOrCallback;
3388
3479
  this.promises.open(filePath, flags, mode).then(
3389
- (handle) => cb(null, handle.fd),
3390
- (err) => cb(err)
3480
+ (handle) => setTimeout(() => cb(null, handle.fd), 0),
3481
+ (err) => setTimeout(() => cb(err), 0)
3391
3482
  );
3392
3483
  }
3393
3484
  mkdtemp(prefix, callback) {
3394
3485
  this.promises.mkdtemp(prefix).then(
3395
- (result) => callback(null, result),
3396
- (err) => callback(err)
3486
+ (result) => setTimeout(() => callback(null, result), 0),
3487
+ (err) => setTimeout(() => callback(err), 0)
3397
3488
  );
3398
3489
  }
3399
3490
  cp(src, dest, optionsOrCallback, callback) {
@@ -3401,19 +3492,113 @@ var VFSFileSystem = class {
3401
3492
  const opts = typeof optionsOrCallback === "function" ? void 0 : optionsOrCallback;
3402
3493
  if (cb) {
3403
3494
  this._cpAsync(src, dest, opts).then(
3404
- () => cb(null),
3405
- (err) => cb(err)
3495
+ () => setTimeout(() => cb(null), 0),
3496
+ (err) => setTimeout(() => cb(err), 0)
3406
3497
  );
3407
3498
  return;
3408
3499
  }
3409
3500
  return this._cpAsync(src, dest, opts);
3410
3501
  }
3502
+ fdatasync(fd, callback) {
3503
+ try {
3504
+ this.fdatasyncSync(fd);
3505
+ callback(null);
3506
+ } catch (err) {
3507
+ callback(err);
3508
+ }
3509
+ }
3510
+ fsync(fd, callback) {
3511
+ try {
3512
+ this.fsyncSync(fd);
3513
+ callback(null);
3514
+ } catch (err) {
3515
+ callback(err);
3516
+ }
3517
+ }
3518
+ fstat(fd, optionsOrCallback, callback) {
3519
+ const cb = typeof optionsOrCallback === "function" ? optionsOrCallback : callback;
3520
+ try {
3521
+ const result = this.fstatSync(fd);
3522
+ setTimeout(() => cb(null, result), 0);
3523
+ } catch (err) {
3524
+ setTimeout(() => cb(err), 0);
3525
+ }
3526
+ }
3527
+ ftruncate(fd, lenOrCallback, callback) {
3528
+ const cb = typeof lenOrCallback === "function" ? lenOrCallback : callback;
3529
+ const len = typeof lenOrCallback === "function" ? 0 : lenOrCallback;
3530
+ try {
3531
+ this.ftruncateSync(fd, len);
3532
+ setTimeout(() => cb(null), 0);
3533
+ } catch (err) {
3534
+ setTimeout(() => cb(err), 0);
3535
+ }
3536
+ }
3537
+ read(fd, buffer, offset, length, position, callback) {
3538
+ try {
3539
+ const bytesRead = this.readSync(fd, buffer, offset, length, position);
3540
+ setTimeout(() => callback(null, bytesRead, buffer), 0);
3541
+ } catch (err) {
3542
+ setTimeout(() => callback(err), 0);
3543
+ }
3544
+ }
3545
+ write(fd, bufferOrString, offsetOrPosition, lengthOrEncoding, position, callback) {
3546
+ const cb = [offsetOrPosition, lengthOrEncoding, position, callback].find((a) => typeof a === "function");
3547
+ try {
3548
+ let bytesWritten;
3549
+ if (typeof bufferOrString === "string") {
3550
+ const pos = typeof offsetOrPosition === "function" ? void 0 : offsetOrPosition;
3551
+ const enc = typeof lengthOrEncoding === "function" ? void 0 : lengthOrEncoding;
3552
+ bytesWritten = this.writeSync(fd, bufferOrString, pos, enc);
3553
+ } else {
3554
+ const off = typeof offsetOrPosition === "function" ? void 0 : offsetOrPosition;
3555
+ const len = typeof lengthOrEncoding === "function" ? void 0 : lengthOrEncoding;
3556
+ const pos = typeof position === "function" ? void 0 : position;
3557
+ bytesWritten = this.writeSync(fd, bufferOrString, off, len, pos);
3558
+ }
3559
+ setTimeout(() => cb(null, bytesWritten, bufferOrString), 0);
3560
+ } catch (err) {
3561
+ setTimeout(() => cb(err), 0);
3562
+ }
3563
+ }
3564
+ close(fd, callback) {
3565
+ try {
3566
+ this.closeSync(fd);
3567
+ if (callback) setTimeout(() => callback(null), 0);
3568
+ } catch (err) {
3569
+ if (callback) setTimeout(() => callback(err), 0);
3570
+ else throw err;
3571
+ }
3572
+ }
3411
3573
  exists(filePath, callback) {
3412
3574
  this.promises.exists(filePath).then(
3413
- (result) => callback(result),
3414
- () => callback(false)
3575
+ (result) => setTimeout(() => callback(result), 0),
3576
+ () => setTimeout(() => callback(false), 0)
3577
+ );
3578
+ }
3579
+ opendir(filePath, callback) {
3580
+ this.promises.opendir(filePath).then(
3581
+ (dir) => setTimeout(() => callback(null, dir), 0),
3582
+ (err) => setTimeout(() => callback(err), 0)
3415
3583
  );
3416
3584
  }
3585
+ glob(pattern, optionsOrCallback, callback) {
3586
+ const cb = typeof optionsOrCallback === "function" ? optionsOrCallback : callback;
3587
+ const opts = typeof optionsOrCallback === "function" ? void 0 : optionsOrCallback;
3588
+ this.promises.glob(pattern, opts).then(
3589
+ (result) => setTimeout(() => cb(null, result), 0),
3590
+ (err) => setTimeout(() => cb(err), 0)
3591
+ );
3592
+ }
3593
+ futimes(fd, atime, mtime, callback) {
3594
+ setTimeout(() => callback(null), 0);
3595
+ }
3596
+ fchmod(fd, mode, callback) {
3597
+ setTimeout(() => callback(null), 0);
3598
+ }
3599
+ fchown(fd, uid, gid, callback) {
3600
+ setTimeout(() => callback(null), 0);
3601
+ }
3417
3602
  };
3418
3603
  var VFSPromises = class {
3419
3604
  _async;
@@ -3422,6 +3607,10 @@ var VFSPromises = class {
3422
3607
  this._async = asyncRequest;
3423
3608
  this._ns = ns;
3424
3609
  }
3610
+ /** Node.js compat: fs.promises.constants (same as fs.constants) */
3611
+ get constants() {
3612
+ return constants;
3613
+ }
3425
3614
  readFile(filePath, options) {
3426
3615
  return readFile(this._async, toPathString(filePath), options);
3427
3616
  }
@@ -3551,6 +3740,9 @@ var VFSPromises = class {
3551
3740
  utimes(filePath, atime, mtime) {
3552
3741
  return utimes(this._async, toPathString(filePath), atime, mtime);
3553
3742
  }
3743
+ /** utimes on an open file descriptor. No-op in this VFS (cannot resolve fd to path). */
3744
+ async futimes(_fd, _atime, _mtime) {
3745
+ }
3554
3746
  /** Like utimes but operates on the symlink itself. In this VFS, delegates to utimes. */
3555
3747
  lutimes(filePath, atime, mtime) {
3556
3748
  return utimes(this._async, filePath, atime, mtime);
@@ -3597,6 +3789,12 @@ var VFSPromises = class {
3597
3789
  async *watch(filePath, options) {
3598
3790
  yield* watchAsync(this._ns, this._async, filePath, options);
3599
3791
  }
3792
+ async fsync(_fd) {
3793
+ await this._async(OP.FSYNC, "");
3794
+ }
3795
+ async fdatasync(_fd) {
3796
+ await this._async(OP.FSYNC, "");
3797
+ }
3600
3798
  async flush() {
3601
3799
  await this._async(OP.FSYNC, "");
3602
3800
  }
@@ -5275,6 +5473,6 @@ function init() {
5275
5473
  return getDefaultFS().init();
5276
5474
  }
5277
5475
 
5278
- export { FSError, NodeReadable, NodeWritable, SimpleEventEmitter, VFSFileSystem, constants, createError, createFS, getDefaultFS, init, loadFromOPFS, path_exports as path, repairVFS, statusToError, unpackToOPFS };
5476
+ export { FSError, NodeReadable, NodeWritable, NodeReadable as ReadStream, SimpleEventEmitter, VFSFileSystem, NodeWritable as WriteStream, constants, createError, createFS, getDefaultFS, init, loadFromOPFS, path_exports as path, repairVFS, statusToError, unpackToOPFS };
5279
5477
  //# sourceMappingURL=index.js.map
5280
5478
  //# sourceMappingURL=index.js.map