@componentor/fs 3.0.27 → 3.0.28

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
@@ -159,6 +159,7 @@ interface FSReadStream {
159
159
  pause(): this;
160
160
  resume(): this;
161
161
  read(size?: number): Uint8Array | null;
162
+ setEncoding(encoding: string): this;
162
163
  destroy(err?: Error): this;
163
164
  }
164
165
  interface ReadStreamOptions {
@@ -187,6 +188,8 @@ interface FSWriteStream {
187
188
  writable: boolean;
188
189
  bytesWritten: number;
189
190
  path: string;
191
+ cork(): void;
192
+ uncork(): void;
190
193
  write(chunk: string | Uint8Array, encodingOrCb?: string | Function, cb?: Function): boolean;
191
194
  end(chunk?: string | Uint8Array | Function, encodingOrCb?: string | Function, cb?: Function): this;
192
195
  on(event: string, fn: Function): this;
@@ -435,6 +438,7 @@ declare class VFSFileSystem {
435
438
  fstatSync(fd: number): Stats;
436
439
  ftruncateSync(fd: number, len?: number): void;
437
440
  fdatasyncSync(fd: number): void;
441
+ fsyncSync(fd: number): void;
438
442
  readvSync(fd: number, buffers: Uint8Array[], position?: number | null): number;
439
443
  writevSync(fd: number, buffers: Uint8Array[], position?: number | null): number;
440
444
  readv(fd: number, buffers: Uint8Array[], position: number | null | undefined, callback: (err: Error | null, bytesRead?: number, buffers?: Uint8Array[]) => void): void;
@@ -509,6 +513,8 @@ declare class VFSFileSystem {
509
513
  mkdtemp(prefix: string, callback: (err: Error | null, folder?: string) => void): void;
510
514
  cp(src: string, dest: string, callback: (err: Error | null) => void): void;
511
515
  cp(src: string, dest: string, options: CpOptions, callback: (err: Error | null) => void): void;
516
+ fdatasync(fd: number, callback: (err: Error | null) => void): void;
517
+ fsync(fd: number, callback: (err: Error | null) => void): void;
512
518
  exists(filePath: string, callback: (exists: boolean) => void): void;
513
519
  }
514
520
  declare class VFSPromises {
@@ -557,6 +563,8 @@ declare class VFSPromises {
557
563
  openAsBlob(filePath: string, options?: OpenAsBlobOptions): Promise<Blob>;
558
564
  statfs(path: string): Promise<StatFs>;
559
565
  watch(filePath: string, options?: WatchOptions): AsyncIterable<WatchEventType>;
566
+ fsync(_fd: number): Promise<void>;
567
+ fdatasync(_fd: number): Promise<void>;
560
568
  flush(): Promise<void>;
561
569
  purge(): Promise<void>;
562
570
  }
@@ -587,6 +595,7 @@ declare class NodeReadable extends SimpleEventEmitter {
587
595
  private _ended;
588
596
  private _reading;
589
597
  private _readBuffer;
598
+ private _encoding;
590
599
  /** Whether the stream is still readable (not ended or destroyed). */
591
600
  readable: boolean;
592
601
  /** The file path this stream reads from (set externally). */
@@ -602,6 +611,11 @@ declare class NodeReadable extends SimpleEventEmitter {
602
611
  on(event: string, fn: Listener): this;
603
612
  pause(): this;
604
613
  resume(): this;
614
+ /**
615
+ * Set the character encoding for data read from this stream.
616
+ * When set, 'data' events emit strings instead of Uint8Array.
617
+ */
618
+ setEncoding(encoding: string): this;
605
619
  /**
606
620
  * Non-flowing read — returns the last buffered chunk or null.
607
621
  * Node.js has a complex buffer system; we keep it simple here.
@@ -624,7 +638,18 @@ declare class NodeWritable extends SimpleEventEmitter {
624
638
  private _destroyed;
625
639
  private _finished;
626
640
  private _writing;
641
+ private _corked;
627
642
  constructor(path: string, _writeFn: (chunk: Uint8Array) => Promise<void>, _closeFn: () => Promise<void>);
643
+ /**
644
+ * Buffer all writes until `uncork()` is called.
645
+ * In this minimal implementation we only track the flag for compatibility.
646
+ */
647
+ cork(): void;
648
+ /**
649
+ * Flush buffered writes (clears the cork flag).
650
+ * In this minimal implementation we only track the flag for compatibility.
651
+ */
652
+ uncork(): void;
628
653
  write(chunk: string | Uint8Array, encodingOrCb?: string | ((...args: unknown[]) => void), cb?: (...args: unknown[]) => void): boolean;
629
654
  end(chunk?: string | Uint8Array | ((...args: unknown[]) => void), encodingOrCb?: string | ((...args: unknown[]) => void), cb?: (...args: unknown[]) => void): this;
630
655
  destroy(err?: Error): this;
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) {
@@ -2002,7 +2030,11 @@ function emptyStats() {
2002
2030
  atime: zero,
2003
2031
  mtime: zero,
2004
2032
  ctime: zero,
2005
- birthtime: zero
2033
+ birthtime: zero,
2034
+ atimeNs: 0,
2035
+ mtimeNs: 0,
2036
+ ctimeNs: 0,
2037
+ birthtimeNs: 0
2006
2038
  };
2007
2039
  }
2008
2040
  async function* watchAsync(ns, _asyncRequest, filePath, options) {
@@ -2957,6 +2989,9 @@ var VFSFileSystem = class {
2957
2989
  fdatasyncSync(fd) {
2958
2990
  fdatasyncSync(this._sync, fd);
2959
2991
  }
2992
+ fsyncSync(fd) {
2993
+ fdatasyncSync(this._sync, fd);
2994
+ }
2960
2995
  // ---- Vector I/O methods ----
2961
2996
  readvSync(fd, buffers, position) {
2962
2997
  let totalRead = 0;
@@ -3232,168 +3267,168 @@ var VFSFileSystem = class {
3232
3267
  const cb = typeof optionsOrCallback === "function" ? optionsOrCallback : callback;
3233
3268
  const opts = typeof optionsOrCallback === "function" ? void 0 : optionsOrCallback;
3234
3269
  this.promises.readFile(filePath, opts).then(
3235
- (result) => cb(null, result),
3236
- (err) => cb(err)
3270
+ (result) => setTimeout(() => cb(null, result), 0),
3271
+ (err) => setTimeout(() => cb(err), 0)
3237
3272
  );
3238
3273
  }
3239
3274
  writeFile(filePath, data, optionsOrCallback, callback) {
3240
3275
  const cb = typeof optionsOrCallback === "function" ? optionsOrCallback : callback;
3241
3276
  const opts = typeof optionsOrCallback === "function" ? void 0 : optionsOrCallback;
3242
3277
  this.promises.writeFile(filePath, data, opts).then(
3243
- () => cb(null),
3244
- (err) => cb(err)
3278
+ () => setTimeout(() => cb(null), 0),
3279
+ (err) => setTimeout(() => cb(err), 0)
3245
3280
  );
3246
3281
  }
3247
3282
  appendFile(filePath, data, optionsOrCallback, callback) {
3248
3283
  const cb = typeof optionsOrCallback === "function" ? optionsOrCallback : callback;
3249
3284
  const opts = typeof optionsOrCallback === "function" ? void 0 : optionsOrCallback;
3250
3285
  this.promises.appendFile(filePath, data, opts).then(
3251
- () => cb(null),
3252
- (err) => cb(err)
3286
+ () => setTimeout(() => cb(null), 0),
3287
+ (err) => setTimeout(() => cb(err), 0)
3253
3288
  );
3254
3289
  }
3255
3290
  mkdir(filePath, optionsOrCallback, callback) {
3256
3291
  const cb = typeof optionsOrCallback === "function" ? optionsOrCallback : callback;
3257
3292
  const opts = typeof optionsOrCallback === "function" ? void 0 : optionsOrCallback;
3258
3293
  this.promises.mkdir(filePath, opts).then(
3259
- (result) => cb(null, result),
3260
- (err) => cb(err)
3294
+ (result) => setTimeout(() => cb(null, result), 0),
3295
+ (err) => setTimeout(() => cb(err), 0)
3261
3296
  );
3262
3297
  }
3263
3298
  rmdir(filePath, optionsOrCallback, callback) {
3264
3299
  const cb = typeof optionsOrCallback === "function" ? optionsOrCallback : callback;
3265
3300
  const opts = typeof optionsOrCallback === "function" ? void 0 : optionsOrCallback;
3266
3301
  this.promises.rmdir(filePath, opts).then(
3267
- () => cb(null),
3268
- (err) => cb(err)
3302
+ () => setTimeout(() => cb(null), 0),
3303
+ (err) => setTimeout(() => cb(err), 0)
3269
3304
  );
3270
3305
  }
3271
3306
  rm(filePath, optionsOrCallback, callback) {
3272
3307
  const cb = typeof optionsOrCallback === "function" ? optionsOrCallback : callback;
3273
3308
  const opts = typeof optionsOrCallback === "function" ? void 0 : optionsOrCallback;
3274
3309
  this.promises.rm(filePath, opts).then(
3275
- () => cb(null),
3276
- (err) => cb(err)
3310
+ () => setTimeout(() => cb(null), 0),
3311
+ (err) => setTimeout(() => cb(err), 0)
3277
3312
  );
3278
3313
  }
3279
3314
  unlink(filePath, callback) {
3280
3315
  this.promises.unlink(filePath).then(
3281
- () => callback(null),
3282
- (err) => callback(err)
3316
+ () => setTimeout(() => callback(null), 0),
3317
+ (err) => setTimeout(() => callback(err), 0)
3283
3318
  );
3284
3319
  }
3285
3320
  readdir(filePath, optionsOrCallback, callback) {
3286
3321
  const cb = typeof optionsOrCallback === "function" ? optionsOrCallback : callback;
3287
3322
  const opts = typeof optionsOrCallback === "function" ? void 0 : optionsOrCallback;
3288
3323
  this.promises.readdir(filePath, opts).then(
3289
- (result) => cb(null, result),
3290
- (err) => cb(err)
3324
+ (result) => setTimeout(() => cb(null, result), 0),
3325
+ (err) => setTimeout(() => cb(err), 0)
3291
3326
  );
3292
3327
  }
3293
3328
  stat(filePath, optionsOrCallback, callback) {
3294
3329
  const cb = typeof optionsOrCallback === "function" ? optionsOrCallback : callback;
3295
3330
  const opts = typeof optionsOrCallback === "function" ? void 0 : optionsOrCallback;
3296
3331
  this.promises.stat(filePath, opts).then(
3297
- (result) => cb(null, result),
3298
- (err) => cb(err)
3332
+ (result) => setTimeout(() => cb(null, result), 0),
3333
+ (err) => setTimeout(() => cb(err), 0)
3299
3334
  );
3300
3335
  }
3301
3336
  lstat(filePath, optionsOrCallback, callback) {
3302
3337
  const cb = typeof optionsOrCallback === "function" ? optionsOrCallback : callback;
3303
3338
  const opts = typeof optionsOrCallback === "function" ? void 0 : optionsOrCallback;
3304
3339
  this.promises.lstat(filePath, opts).then(
3305
- (result) => cb(null, result),
3306
- (err) => cb(err)
3340
+ (result) => setTimeout(() => cb(null, result), 0),
3341
+ (err) => setTimeout(() => cb(err), 0)
3307
3342
  );
3308
3343
  }
3309
3344
  access(filePath, modeOrCallback, callback) {
3310
3345
  const cb = typeof modeOrCallback === "function" ? modeOrCallback : callback;
3311
3346
  const mode = typeof modeOrCallback === "function" ? void 0 : modeOrCallback;
3312
3347
  this.promises.access(filePath, mode).then(
3313
- () => cb(null),
3314
- (err) => cb(err)
3348
+ () => setTimeout(() => cb(null), 0),
3349
+ (err) => setTimeout(() => cb(err), 0)
3315
3350
  );
3316
3351
  }
3317
3352
  rename(oldPath, newPath, callback) {
3318
3353
  this.promises.rename(oldPath, newPath).then(
3319
- () => callback(null),
3320
- (err) => callback(err)
3354
+ () => setTimeout(() => callback(null), 0),
3355
+ (err) => setTimeout(() => callback(err), 0)
3321
3356
  );
3322
3357
  }
3323
3358
  copyFile(src, dest, modeOrCallback, callback) {
3324
3359
  const cb = typeof modeOrCallback === "function" ? modeOrCallback : callback;
3325
3360
  const mode = typeof modeOrCallback === "function" ? void 0 : modeOrCallback;
3326
3361
  this.promises.copyFile(src, dest, mode).then(
3327
- () => cb(null),
3328
- (err) => cb(err)
3362
+ () => setTimeout(() => cb(null), 0),
3363
+ (err) => setTimeout(() => cb(err), 0)
3329
3364
  );
3330
3365
  }
3331
3366
  truncate(filePath, lenOrCallback, callback) {
3332
3367
  const cb = typeof lenOrCallback === "function" ? lenOrCallback : callback;
3333
3368
  const len = typeof lenOrCallback === "function" ? void 0 : lenOrCallback;
3334
3369
  this.promises.truncate(filePath, len).then(
3335
- () => cb(null),
3336
- (err) => cb(err)
3370
+ () => setTimeout(() => cb(null), 0),
3371
+ (err) => setTimeout(() => cb(err), 0)
3337
3372
  );
3338
3373
  }
3339
3374
  realpath(filePath, callback) {
3340
3375
  this.promises.realpath(filePath).then(
3341
- (result) => callback(null, result),
3342
- (err) => callback(err)
3376
+ (result) => setTimeout(() => callback(null, result), 0),
3377
+ (err) => setTimeout(() => callback(err), 0)
3343
3378
  );
3344
3379
  }
3345
3380
  chmod(filePath, mode, callback) {
3346
3381
  this.promises.chmod(filePath, mode).then(
3347
- () => callback(null),
3348
- (err) => callback(err)
3382
+ () => setTimeout(() => callback(null), 0),
3383
+ (err) => setTimeout(() => callback(err), 0)
3349
3384
  );
3350
3385
  }
3351
3386
  chown(filePath, uid, gid, callback) {
3352
3387
  this.promises.chown(filePath, uid, gid).then(
3353
- () => callback(null),
3354
- (err) => callback(err)
3388
+ () => setTimeout(() => callback(null), 0),
3389
+ (err) => setTimeout(() => callback(err), 0)
3355
3390
  );
3356
3391
  }
3357
3392
  utimes(filePath, atime, mtime, callback) {
3358
3393
  this.promises.utimes(filePath, atime, mtime).then(
3359
- () => callback(null),
3360
- (err) => callback(err)
3394
+ () => setTimeout(() => callback(null), 0),
3395
+ (err) => setTimeout(() => callback(err), 0)
3361
3396
  );
3362
3397
  }
3363
3398
  symlink(target, linkPath, typeOrCallback, callback) {
3364
3399
  const cb = typeof typeOrCallback === "function" ? typeOrCallback : callback;
3365
3400
  const type = typeof typeOrCallback === "function" ? void 0 : typeOrCallback;
3366
3401
  this.promises.symlink(target, linkPath, type).then(
3367
- () => cb(null),
3368
- (err) => cb(err)
3402
+ () => setTimeout(() => cb(null), 0),
3403
+ (err) => setTimeout(() => cb(err), 0)
3369
3404
  );
3370
3405
  }
3371
3406
  readlink(filePath, optionsOrCallback, callback) {
3372
3407
  const cb = typeof optionsOrCallback === "function" ? optionsOrCallback : callback;
3373
3408
  const opts = typeof optionsOrCallback === "function" ? void 0 : optionsOrCallback;
3374
3409
  this.promises.readlink(filePath, opts).then(
3375
- (result) => cb(null, result),
3376
- (err) => cb(err)
3410
+ (result) => setTimeout(() => cb(null, result), 0),
3411
+ (err) => setTimeout(() => cb(err), 0)
3377
3412
  );
3378
3413
  }
3379
3414
  link(existingPath, newPath, callback) {
3380
3415
  this.promises.link(existingPath, newPath).then(
3381
- () => callback(null),
3382
- (err) => callback(err)
3416
+ () => setTimeout(() => callback(null), 0),
3417
+ (err) => setTimeout(() => callback(err), 0)
3383
3418
  );
3384
3419
  }
3385
3420
  open(filePath, flags, modeOrCallback, callback) {
3386
3421
  const cb = typeof modeOrCallback === "function" ? modeOrCallback : callback;
3387
3422
  const mode = typeof modeOrCallback === "function" ? void 0 : modeOrCallback;
3388
3423
  this.promises.open(filePath, flags, mode).then(
3389
- (handle) => cb(null, handle.fd),
3390
- (err) => cb(err)
3424
+ (handle) => setTimeout(() => cb(null, handle.fd), 0),
3425
+ (err) => setTimeout(() => cb(err), 0)
3391
3426
  );
3392
3427
  }
3393
3428
  mkdtemp(prefix, callback) {
3394
3429
  this.promises.mkdtemp(prefix).then(
3395
- (result) => callback(null, result),
3396
- (err) => callback(err)
3430
+ (result) => setTimeout(() => callback(null, result), 0),
3431
+ (err) => setTimeout(() => callback(err), 0)
3397
3432
  );
3398
3433
  }
3399
3434
  cp(src, dest, optionsOrCallback, callback) {
@@ -3401,17 +3436,33 @@ var VFSFileSystem = class {
3401
3436
  const opts = typeof optionsOrCallback === "function" ? void 0 : optionsOrCallback;
3402
3437
  if (cb) {
3403
3438
  this._cpAsync(src, dest, opts).then(
3404
- () => cb(null),
3405
- (err) => cb(err)
3439
+ () => setTimeout(() => cb(null), 0),
3440
+ (err) => setTimeout(() => cb(err), 0)
3406
3441
  );
3407
3442
  return;
3408
3443
  }
3409
3444
  return this._cpAsync(src, dest, opts);
3410
3445
  }
3446
+ fdatasync(fd, callback) {
3447
+ try {
3448
+ this.fdatasyncSync(fd);
3449
+ callback(null);
3450
+ } catch (err) {
3451
+ callback(err);
3452
+ }
3453
+ }
3454
+ fsync(fd, callback) {
3455
+ try {
3456
+ this.fsyncSync(fd);
3457
+ callback(null);
3458
+ } catch (err) {
3459
+ callback(err);
3460
+ }
3461
+ }
3411
3462
  exists(filePath, callback) {
3412
3463
  this.promises.exists(filePath).then(
3413
- (result) => callback(result),
3414
- () => callback(false)
3464
+ (result) => setTimeout(() => callback(result), 0),
3465
+ () => setTimeout(() => callback(false), 0)
3415
3466
  );
3416
3467
  }
3417
3468
  };
@@ -3597,6 +3648,12 @@ var VFSPromises = class {
3597
3648
  async *watch(filePath, options) {
3598
3649
  yield* watchAsync(this._ns, this._async, filePath, options);
3599
3650
  }
3651
+ async fsync(_fd) {
3652
+ await this._async(OP.FSYNC, "");
3653
+ }
3654
+ async fdatasync(_fd) {
3655
+ await this._async(OP.FSYNC, "");
3656
+ }
3600
3657
  async flush() {
3601
3658
  await this._async(OP.FSYNC, "");
3602
3659
  }