@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.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;
@@ -308,6 +311,18 @@ type AsyncRequestFn = (op: number, path: string, flags?: number, data?: Uint8Arr
308
311
  data: Uint8Array | null;
309
312
  }>;
310
313
 
314
+ /**
315
+ * VFSFileSystem — main thread API.
316
+ *
317
+ * Provides Node.js-compatible sync and async filesystem methods.
318
+ * Sync methods use SAB + Atomics to block until the server responds.
319
+ * Async methods use postMessage to the async relay worker.
320
+ *
321
+ * On import, workers are spawned immediately. Every method blocks
322
+ * (or waits) until the worker is ready. This is by design — the library
323
+ * primarily runs inside workers where blocking is fine.
324
+ */
325
+
311
326
  declare class VFSFileSystem {
312
327
  private sab;
313
328
  private ctrl;
@@ -385,8 +400,9 @@ declare class VFSFileSystem {
385
400
  rmdirSync(filePath: PathLike, options?: RmdirOptions): void;
386
401
  rmSync(filePath: PathLike, options?: RmOptions): void;
387
402
  unlinkSync(filePath: PathLike): void;
388
- readdirSync(filePath: PathLike, options?: ReaddirOptions | Encoding | null): string[] | Dirent[];
403
+ readdirSync(filePath: PathLike, options?: ReaddirOptions | Encoding | null): string[] | Uint8Array[] | Dirent[];
389
404
  globSync(pattern: string, options?: GlobOptions): string[];
405
+ opendirSync(filePath: PathLike): Dir;
390
406
  statSync(filePath: PathLike, options?: StatOptions): Stats | BigIntStats;
391
407
  lstatSync(filePath: PathLike, options?: StatOptions): Stats | BigIntStats;
392
408
  renameSync(oldPath: PathLike, newPath: PathLike): void;
@@ -407,6 +423,8 @@ declare class VFSFileSystem {
407
423
  /** chown on an open file descriptor. No-op in this VFS (permissions are cosmetic). */
408
424
  fchownSync(_fd: number, _uid: number, _gid: number): void;
409
425
  utimesSync(filePath: PathLike, atime: Date | number, mtime: Date | number): void;
426
+ /** utimes on an open file descriptor. No-op in this VFS (cannot resolve fd to path). */
427
+ futimesSync(_fd: number, _atime: Date | number, _mtime: Date | number): void;
410
428
  /** Like utimesSync but operates on the symlink itself. In this VFS, delegates to utimesSync. */
411
429
  lutimesSync(filePath: string, atime: Date | number, mtime: Date | number): void;
412
430
  symlinkSync(target: PathLike, linkPath: PathLike, type?: string | null): void;
@@ -435,6 +453,7 @@ declare class VFSFileSystem {
435
453
  fstatSync(fd: number): Stats;
436
454
  ftruncateSync(fd: number, len?: number): void;
437
455
  fdatasyncSync(fd: number): void;
456
+ fsyncSync(fd: number): void;
438
457
  readvSync(fd: number, buffers: Uint8Array[], position?: number | null): number;
439
458
  writevSync(fd: number, buffers: Uint8Array[], position?: number | null): number;
440
459
  readv(fd: number, buffers: Uint8Array[], position: number | null | undefined, callback: (err: Error | null, bytesRead?: number, buffers?: Uint8Array[]) => void): void;
@@ -509,12 +528,72 @@ declare class VFSFileSystem {
509
528
  mkdtemp(prefix: string, callback: (err: Error | null, folder?: string) => void): void;
510
529
  cp(src: string, dest: string, callback: (err: Error | null) => void): void;
511
530
  cp(src: string, dest: string, options: CpOptions, callback: (err: Error | null) => void): void;
531
+ fdatasync(fd: number, callback: (err: Error | null) => void): void;
532
+ fsync(fd: number, callback: (err: Error | null) => void): void;
533
+ fstat(fd: number, callback: (err: Error | null, stats?: Stats) => void): void;
534
+ fstat(fd: number, options: any, callback: (err: Error | null, stats?: Stats) => void): void;
535
+ ftruncate(fd: number, callback: (err: Error | null) => void): void;
536
+ ftruncate(fd: number, len: number, callback: (err: Error | null) => void): void;
537
+ read(fd: number, buffer: Uint8Array, offset: number, length: number, position: number | null, callback: (err: Error | null, bytesRead?: number, buffer?: Uint8Array) => void): void;
538
+ write(fd: number, buffer: Uint8Array, offset: number, length: number, position: number | null, callback: (err: Error | null, bytesWritten?: number, buffer?: Uint8Array) => void): void;
539
+ write(fd: number, data: string, position: number | null | undefined, encoding: string | undefined, callback: (err: Error | null, bytesWritten?: number, data?: string) => void): void;
540
+ close(fd: number, callback?: (err: Error | null) => void): void;
512
541
  exists(filePath: string, callback: (exists: boolean) => void): void;
542
+ opendir(filePath: string, callback: (err: Error | null, dir?: Dir) => void): void;
543
+ glob(pattern: string, callback: (err: Error | null, matches?: string[]) => void): void;
544
+ glob(pattern: string, options: GlobOptions, callback: (err: Error | null, matches?: string[]) => void): void;
545
+ futimes(fd: number, atime: Date | number, mtime: Date | number, callback: (err: Error | null) => void): void;
546
+ fchmod(fd: number, mode: number, callback: (err: Error | null) => void): void;
547
+ fchown(fd: number, uid: number, gid: number, callback: (err: Error | null) => void): void;
513
548
  }
514
549
  declare class VFSPromises {
515
550
  private _async;
516
551
  private _ns;
517
552
  constructor(asyncRequest: AsyncRequestFn, ns: string);
553
+ /** Node.js compat: fs.promises.constants (same as fs.constants) */
554
+ get constants(): {
555
+ readonly F_OK: 0;
556
+ readonly R_OK: 4;
557
+ readonly W_OK: 2;
558
+ readonly X_OK: 1;
559
+ readonly COPYFILE_EXCL: 1;
560
+ readonly COPYFILE_FICLONE: 2;
561
+ readonly COPYFILE_FICLONE_FORCE: 4;
562
+ readonly O_RDONLY: 0;
563
+ readonly O_WRONLY: 1;
564
+ readonly O_RDWR: 2;
565
+ readonly O_CREAT: 64;
566
+ readonly O_EXCL: 128;
567
+ readonly O_TRUNC: 512;
568
+ readonly O_APPEND: 1024;
569
+ readonly O_NOCTTY: 256;
570
+ readonly O_NONBLOCK: 2048;
571
+ readonly O_SYNC: 4096;
572
+ readonly O_DSYNC: 4096;
573
+ readonly O_DIRECTORY: 65536;
574
+ readonly O_NOFOLLOW: 131072;
575
+ readonly O_NOATIME: 262144;
576
+ readonly S_IFMT: 61440;
577
+ readonly S_IFREG: 32768;
578
+ readonly S_IFDIR: 16384;
579
+ readonly S_IFCHR: 8192;
580
+ readonly S_IFBLK: 24576;
581
+ readonly S_IFIFO: 4096;
582
+ readonly S_IFLNK: 40960;
583
+ readonly S_IFSOCK: 49152;
584
+ readonly S_IRWXU: 448;
585
+ readonly S_IRUSR: 256;
586
+ readonly S_IWUSR: 128;
587
+ readonly S_IXUSR: 64;
588
+ readonly S_IRWXG: 56;
589
+ readonly S_IRGRP: 32;
590
+ readonly S_IWGRP: 16;
591
+ readonly S_IXGRP: 8;
592
+ readonly S_IRWXO: 7;
593
+ readonly S_IROTH: 4;
594
+ readonly S_IWOTH: 2;
595
+ readonly S_IXOTH: 1;
596
+ };
518
597
  readFile(filePath: PathLike, options?: ReadOptions | Encoding | null): Promise<string | Uint8Array<ArrayBufferLike>>;
519
598
  writeFile(filePath: PathLike, data: string | Uint8Array, options?: WriteOptions | Encoding): Promise<void>;
520
599
  appendFile(filePath: PathLike, data: string | Uint8Array, options?: WriteOptions | Encoding): Promise<void>;
@@ -522,7 +601,7 @@ declare class VFSPromises {
522
601
  rmdir(filePath: PathLike, options?: RmdirOptions): Promise<void>;
523
602
  rm(filePath: PathLike, options?: RmOptions): Promise<void>;
524
603
  unlink(filePath: PathLike): Promise<void>;
525
- readdir(filePath: PathLike, options?: ReaddirOptions | Encoding | null): Promise<string[] | Dirent[]>;
604
+ readdir(filePath: PathLike, options?: ReaddirOptions | Encoding | null): Promise<Uint8Array<ArrayBufferLike>[] | string[] | Dirent[]>;
526
605
  glob(pattern: string, options?: GlobOptions): Promise<string[]>;
527
606
  stat(filePath: PathLike, options?: StatOptions): Promise<BigIntStats | Stats>;
528
607
  lstat(filePath: PathLike, options?: StatOptions): Promise<BigIntStats | Stats>;
@@ -544,6 +623,8 @@ declare class VFSPromises {
544
623
  /** chown on an open file descriptor. No-op in this VFS (permissions are cosmetic). */
545
624
  fchown(_fd: number, _uid: number, _gid: number): Promise<void>;
546
625
  utimes(filePath: PathLike, atime: Date | number, mtime: Date | number): Promise<void>;
626
+ /** utimes on an open file descriptor. No-op in this VFS (cannot resolve fd to path). */
627
+ futimes(_fd: number, _atime: Date | number, _mtime: Date | number): Promise<void>;
547
628
  /** Like utimes but operates on the symlink itself. In this VFS, delegates to utimes. */
548
629
  lutimes(filePath: string, atime: Date | number, mtime: Date | number): Promise<void>;
549
630
  symlink(target: PathLike, linkPath: PathLike, type?: string | null): Promise<void>;
@@ -557,6 +638,8 @@ declare class VFSPromises {
557
638
  openAsBlob(filePath: string, options?: OpenAsBlobOptions): Promise<Blob>;
558
639
  statfs(path: string): Promise<StatFs>;
559
640
  watch(filePath: string, options?: WatchOptions): AsyncIterable<WatchEventType>;
641
+ fsync(_fd: number): Promise<void>;
642
+ fdatasync(_fd: number): Promise<void>;
560
643
  flush(): Promise<void>;
561
644
  purge(): Promise<void>;
562
645
  }
@@ -587,6 +670,7 @@ declare class NodeReadable extends SimpleEventEmitter {
587
670
  private _ended;
588
671
  private _reading;
589
672
  private _readBuffer;
673
+ private _encoding;
590
674
  /** Whether the stream is still readable (not ended or destroyed). */
591
675
  readable: boolean;
592
676
  /** The file path this stream reads from (set externally). */
@@ -602,6 +686,11 @@ declare class NodeReadable extends SimpleEventEmitter {
602
686
  on(event: string, fn: Listener): this;
603
687
  pause(): this;
604
688
  resume(): this;
689
+ /**
690
+ * Set the character encoding for data read from this stream.
691
+ * When set, 'data' events emit strings instead of Uint8Array.
692
+ */
693
+ setEncoding(encoding: string): this;
605
694
  /**
606
695
  * Non-flowing read — returns the last buffered chunk or null.
607
696
  * Node.js has a complex buffer system; we keep it simple here.
@@ -624,7 +713,18 @@ declare class NodeWritable extends SimpleEventEmitter {
624
713
  private _destroyed;
625
714
  private _finished;
626
715
  private _writing;
716
+ private _corked;
627
717
  constructor(path: string, _writeFn: (chunk: Uint8Array) => Promise<void>, _closeFn: () => Promise<void>);
718
+ /**
719
+ * Buffer all writes until `uncork()` is called.
720
+ * In this minimal implementation we only track the flag for compatibility.
721
+ */
722
+ cork(): void;
723
+ /**
724
+ * Flush buffered writes (clears the cork flag).
725
+ * In this minimal implementation we only track the flag for compatibility.
726
+ */
727
+ uncork(): void;
628
728
  write(chunk: string | Uint8Array, encodingOrCb?: string | ((...args: unknown[]) => void), cb?: (...args: unknown[]) => void): boolean;
629
729
  end(chunk?: string | Uint8Array | ((...args: unknown[]) => void), encodingOrCb?: string | ((...args: unknown[]) => void), cb?: (...args: unknown[]) => void): this;
630
730
  destroy(err?: Error): this;
@@ -831,4 +931,4 @@ declare function getDefaultFS(): VFSFileSystem;
831
931
  /** Async init helper — avoids blocking main thread */
832
932
  declare function init(): Promise<void>;
833
933
 
834
- export { type BigIntStats, type CpOptions, type Dir, type Dirent, type Encoding, FSError, type FSMode, type FSReadStream, type FSWatcher, type FSWriteStream, type FileHandle, type LoadResult, type MkdirOptions, NodeReadable, NodeWritable, type OpenAsBlobOptions, type PathLike, type ReadOptions, type ReadStreamOptions, type ReaddirOptions, type RepairResult, type RmOptions, type RmdirOptions, SimpleEventEmitter, type StatFs, type StatOptions, type Stats, type UnpackResult, type VFSConfig, VFSFileSystem, type VFSLimits, type WatchEventType, type WatchFileListener, type WatchListener, type WatchOptions, type WriteOptions, type WriteStreamOptions, constants, createError, createFS, getDefaultFS, init, loadFromOPFS, path, repairVFS, statusToError, unpackToOPFS };
934
+ export { type BigIntStats, type CpOptions, type Dir, type Dirent, type Encoding, FSError, type FSMode, type FSReadStream, type FSWatcher, type FSWriteStream, type FileHandle, type LoadResult, type MkdirOptions, NodeReadable, NodeWritable, type OpenAsBlobOptions, type PathLike, type ReadOptions, NodeReadable as ReadStream, type ReadStreamOptions, type ReaddirOptions, type RepairResult, type RmOptions, type RmdirOptions, SimpleEventEmitter, type StatFs, type StatOptions, type Stats, type UnpackResult, type VFSConfig, VFSFileSystem, type VFSLimits, type WatchEventType, type WatchFileListener, type WatchListener, type WatchOptions, type WriteOptions, NodeWritable as WriteStream, type WriteStreamOptions, constants, createError, createFS, getDefaultFS, init, loadFromOPFS, path, repairVFS, statusToError, unpackToOPFS };