@componentor/fs 3.0.28 → 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 +78 -3
- package/dist/index.js +165 -24
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -311,6 +311,18 @@ type AsyncRequestFn = (op: number, path: string, flags?: number, data?: Uint8Arr
|
|
|
311
311
|
data: Uint8Array | null;
|
|
312
312
|
}>;
|
|
313
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
|
+
|
|
314
326
|
declare class VFSFileSystem {
|
|
315
327
|
private sab;
|
|
316
328
|
private ctrl;
|
|
@@ -388,8 +400,9 @@ declare class VFSFileSystem {
|
|
|
388
400
|
rmdirSync(filePath: PathLike, options?: RmdirOptions): void;
|
|
389
401
|
rmSync(filePath: PathLike, options?: RmOptions): void;
|
|
390
402
|
unlinkSync(filePath: PathLike): void;
|
|
391
|
-
readdirSync(filePath: PathLike, options?: ReaddirOptions | Encoding | null): string[] | Dirent[];
|
|
403
|
+
readdirSync(filePath: PathLike, options?: ReaddirOptions | Encoding | null): string[] | Uint8Array[] | Dirent[];
|
|
392
404
|
globSync(pattern: string, options?: GlobOptions): string[];
|
|
405
|
+
opendirSync(filePath: PathLike): Dir;
|
|
393
406
|
statSync(filePath: PathLike, options?: StatOptions): Stats | BigIntStats;
|
|
394
407
|
lstatSync(filePath: PathLike, options?: StatOptions): Stats | BigIntStats;
|
|
395
408
|
renameSync(oldPath: PathLike, newPath: PathLike): void;
|
|
@@ -410,6 +423,8 @@ declare class VFSFileSystem {
|
|
|
410
423
|
/** chown on an open file descriptor. No-op in this VFS (permissions are cosmetic). */
|
|
411
424
|
fchownSync(_fd: number, _uid: number, _gid: number): void;
|
|
412
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;
|
|
413
428
|
/** Like utimesSync but operates on the symlink itself. In this VFS, delegates to utimesSync. */
|
|
414
429
|
lutimesSync(filePath: string, atime: Date | number, mtime: Date | number): void;
|
|
415
430
|
symlinkSync(target: PathLike, linkPath: PathLike, type?: string | null): void;
|
|
@@ -515,12 +530,70 @@ declare class VFSFileSystem {
|
|
|
515
530
|
cp(src: string, dest: string, options: CpOptions, callback: (err: Error | null) => void): void;
|
|
516
531
|
fdatasync(fd: number, callback: (err: Error | null) => void): void;
|
|
517
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;
|
|
518
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;
|
|
519
548
|
}
|
|
520
549
|
declare class VFSPromises {
|
|
521
550
|
private _async;
|
|
522
551
|
private _ns;
|
|
523
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
|
+
};
|
|
524
597
|
readFile(filePath: PathLike, options?: ReadOptions | Encoding | null): Promise<string | Uint8Array<ArrayBufferLike>>;
|
|
525
598
|
writeFile(filePath: PathLike, data: string | Uint8Array, options?: WriteOptions | Encoding): Promise<void>;
|
|
526
599
|
appendFile(filePath: PathLike, data: string | Uint8Array, options?: WriteOptions | Encoding): Promise<void>;
|
|
@@ -528,7 +601,7 @@ declare class VFSPromises {
|
|
|
528
601
|
rmdir(filePath: PathLike, options?: RmdirOptions): Promise<void>;
|
|
529
602
|
rm(filePath: PathLike, options?: RmOptions): Promise<void>;
|
|
530
603
|
unlink(filePath: PathLike): Promise<void>;
|
|
531
|
-
readdir(filePath: PathLike, options?: ReaddirOptions | Encoding | null): Promise<string[] | Dirent[]>;
|
|
604
|
+
readdir(filePath: PathLike, options?: ReaddirOptions | Encoding | null): Promise<Uint8Array<ArrayBufferLike>[] | string[] | Dirent[]>;
|
|
532
605
|
glob(pattern: string, options?: GlobOptions): Promise<string[]>;
|
|
533
606
|
stat(filePath: PathLike, options?: StatOptions): Promise<BigIntStats | Stats>;
|
|
534
607
|
lstat(filePath: PathLike, options?: StatOptions): Promise<BigIntStats | Stats>;
|
|
@@ -550,6 +623,8 @@ declare class VFSPromises {
|
|
|
550
623
|
/** chown on an open file descriptor. No-op in this VFS (permissions are cosmetic). */
|
|
551
624
|
fchown(_fd: number, _uid: number, _gid: number): Promise<void>;
|
|
552
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>;
|
|
553
628
|
/** Like utimes but operates on the symlink itself. In this VFS, delegates to utimes. */
|
|
554
629
|
lutimes(filePath: string, atime: Date | number, mtime: Date | number): Promise<void>;
|
|
555
630
|
symlink(target: PathLike, linkPath: PathLike, type?: string | null): Promise<void>;
|
|
@@ -856,4 +931,4 @@ declare function getDefaultFS(): VFSFileSystem;
|
|
|
856
931
|
/** Async init helper — avoids blocking main thread */
|
|
857
932
|
declare function init(): Promise<void>;
|
|
858
933
|
|
|
859
|
-
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 };
|
package/dist/index.js
CHANGED
|
@@ -1176,6 +1176,21 @@ async function readFile(asyncRequest, filePath, options) {
|
|
|
1176
1176
|
}
|
|
1177
1177
|
}
|
|
1178
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
|
+
|
|
1179
1194
|
// src/methods/writeFile.ts
|
|
1180
1195
|
var encoder3 = new TextEncoder();
|
|
1181
1196
|
function writeFileSync(syncRequest, filePath, data, options) {
|
|
@@ -1191,9 +1206,12 @@ function writeFileSync(syncRequest, filePath, data, options) {
|
|
|
1191
1206
|
const buf = encodeRequest(OP.WRITE, filePath, flags, encoded);
|
|
1192
1207
|
const { status } = syncRequest(buf);
|
|
1193
1208
|
if (status !== 0) throw statusToError(status, "write", filePath);
|
|
1209
|
+
if (opts?.mode !== void 0) {
|
|
1210
|
+
chmodSync(syncRequest, filePath, opts.mode);
|
|
1211
|
+
}
|
|
1194
1212
|
return;
|
|
1195
1213
|
}
|
|
1196
|
-
const fd = openSync(syncRequest, filePath, flag);
|
|
1214
|
+
const fd = openSync(syncRequest, filePath, flag, opts?.mode);
|
|
1197
1215
|
try {
|
|
1198
1216
|
writeSyncFd(syncRequest, fd, encoded, 0, encoded.byteLength, 0);
|
|
1199
1217
|
} finally {
|
|
@@ -1213,9 +1231,12 @@ async function writeFile(asyncRequest, filePath, data, options) {
|
|
|
1213
1231
|
const { status } = await asyncRequest(OP.WRITE, filePath, flags, encoded);
|
|
1214
1232
|
if (signal?.aborted) throw new DOMException("The operation was aborted", "AbortError");
|
|
1215
1233
|
if (status !== 0) throw statusToError(status, "write", filePath);
|
|
1234
|
+
if (opts?.mode !== void 0) {
|
|
1235
|
+
await chmod(asyncRequest, filePath, opts.mode);
|
|
1236
|
+
}
|
|
1216
1237
|
return;
|
|
1217
1238
|
}
|
|
1218
|
-
const handle = await open(asyncRequest, filePath, flag);
|
|
1239
|
+
const handle = await open(asyncRequest, filePath, flag, opts?.mode);
|
|
1219
1240
|
try {
|
|
1220
1241
|
await handle.writeFile(encoded);
|
|
1221
1242
|
if (signal?.aborted) throw new DOMException("The operation was aborted", "AbortError");
|
|
@@ -1371,6 +1392,10 @@ async function unlink(asyncRequest, filePath) {
|
|
|
1371
1392
|
}
|
|
1372
1393
|
|
|
1373
1394
|
// src/methods/readdir.ts
|
|
1395
|
+
var textEncoder = new TextEncoder();
|
|
1396
|
+
function namesToBuffers(names) {
|
|
1397
|
+
return names.map((n) => textEncoder.encode(n));
|
|
1398
|
+
}
|
|
1374
1399
|
function readdirBaseSync(syncRequest, filePath, withFileTypes) {
|
|
1375
1400
|
const flags = withFileTypes ? 1 : 0;
|
|
1376
1401
|
const buf = encodeRequest(OP.READDIR, filePath, flags);
|
|
@@ -1456,28 +1481,46 @@ async function readdirRecursiveAsync(asyncRequest, basePath, prefix, withFileTyp
|
|
|
1456
1481
|
return results;
|
|
1457
1482
|
}
|
|
1458
1483
|
function readdirSync(syncRequest, filePath, options) {
|
|
1459
|
-
const opts = typeof options === "string" ? { } : options;
|
|
1484
|
+
const opts = typeof options === "string" ? { encoding: options } : options;
|
|
1485
|
+
const asBuffer = opts?.encoding === "buffer";
|
|
1460
1486
|
if (opts?.recursive) {
|
|
1461
|
-
|
|
1487
|
+
const result2 = readdirRecursiveSync(
|
|
1462
1488
|
syncRequest,
|
|
1463
1489
|
filePath,
|
|
1464
1490
|
"",
|
|
1465
1491
|
!!opts?.withFileTypes
|
|
1466
1492
|
);
|
|
1493
|
+
if (asBuffer && !opts?.withFileTypes) {
|
|
1494
|
+
return namesToBuffers(result2);
|
|
1495
|
+
}
|
|
1496
|
+
return result2;
|
|
1467
1497
|
}
|
|
1468
|
-
|
|
1498
|
+
const result = readdirBaseSync(syncRequest, filePath, !!opts?.withFileTypes);
|
|
1499
|
+
if (asBuffer && !opts?.withFileTypes) {
|
|
1500
|
+
return namesToBuffers(result);
|
|
1501
|
+
}
|
|
1502
|
+
return result;
|
|
1469
1503
|
}
|
|
1470
1504
|
async function readdir(asyncRequest, filePath, options) {
|
|
1471
|
-
const opts = typeof options === "string" ? { } : options;
|
|
1505
|
+
const opts = typeof options === "string" ? { encoding: options } : options;
|
|
1506
|
+
const asBuffer = opts?.encoding === "buffer";
|
|
1472
1507
|
if (opts?.recursive) {
|
|
1473
|
-
|
|
1508
|
+
const result2 = await readdirRecursiveAsync(
|
|
1474
1509
|
asyncRequest,
|
|
1475
1510
|
filePath,
|
|
1476
1511
|
"",
|
|
1477
1512
|
!!opts?.withFileTypes
|
|
1478
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);
|
|
1479
1522
|
}
|
|
1480
|
-
return
|
|
1523
|
+
return result;
|
|
1481
1524
|
}
|
|
1482
1525
|
|
|
1483
1526
|
// src/methods/stat.ts
|
|
@@ -1576,21 +1619,6 @@ async function realpath(asyncRequest, filePath) {
|
|
|
1576
1619
|
return decoder5.decode(data);
|
|
1577
1620
|
}
|
|
1578
1621
|
|
|
1579
|
-
// src/methods/chmod.ts
|
|
1580
|
-
function chmodSync(syncRequest, filePath, mode) {
|
|
1581
|
-
const modeBuf = new Uint8Array(4);
|
|
1582
|
-
new DataView(modeBuf.buffer).setUint32(0, mode, true);
|
|
1583
|
-
const buf = encodeRequest(OP.CHMOD, filePath, 0, modeBuf);
|
|
1584
|
-
const { status } = syncRequest(buf);
|
|
1585
|
-
if (status !== 0) throw statusToError(status, "chmod", filePath);
|
|
1586
|
-
}
|
|
1587
|
-
async function chmod(asyncRequest, filePath, mode) {
|
|
1588
|
-
const modeBuf = new Uint8Array(4);
|
|
1589
|
-
new DataView(modeBuf.buffer).setUint32(0, mode, true);
|
|
1590
|
-
const { status } = await asyncRequest(OP.CHMOD, filePath, 0, modeBuf);
|
|
1591
|
-
if (status !== 0) throw statusToError(status, "chmod", filePath);
|
|
1592
|
-
}
|
|
1593
|
-
|
|
1594
1622
|
// src/methods/chown.ts
|
|
1595
1623
|
function chownSync(syncRequest, filePath, uid, gid) {
|
|
1596
1624
|
const ownerBuf = new Uint8Array(8);
|
|
@@ -2326,6 +2354,12 @@ var VFSFileSystem = class {
|
|
|
2326
2354
|
this.rejectReady = reject;
|
|
2327
2355
|
});
|
|
2328
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;
|
|
2329
2363
|
instanceRegistry.set(ns, this);
|
|
2330
2364
|
this.bootstrap();
|
|
2331
2365
|
}
|
|
@@ -2799,6 +2833,25 @@ var VFSFileSystem = class {
|
|
|
2799
2833
|
globSync(pattern, options) {
|
|
2800
2834
|
return globSync(this._sync, pattern, options);
|
|
2801
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
|
+
}
|
|
2802
2855
|
statSync(filePath, options) {
|
|
2803
2856
|
return statSync(this._sync, toPathString(filePath), options);
|
|
2804
2857
|
}
|
|
@@ -2951,6 +3004,9 @@ var VFSFileSystem = class {
|
|
|
2951
3004
|
utimesSync(filePath, atime, mtime) {
|
|
2952
3005
|
utimesSync(this._sync, toPathString(filePath), atime, mtime);
|
|
2953
3006
|
}
|
|
3007
|
+
/** utimes on an open file descriptor. No-op in this VFS (cannot resolve fd to path). */
|
|
3008
|
+
futimesSync(_fd, _atime, _mtime) {
|
|
3009
|
+
}
|
|
2954
3010
|
/** Like utimesSync but operates on the symlink itself. In this VFS, delegates to utimesSync. */
|
|
2955
3011
|
lutimesSync(filePath, atime, mtime) {
|
|
2956
3012
|
utimesSync(this._sync, filePath, atime, mtime);
|
|
@@ -3459,12 +3515,90 @@ var VFSFileSystem = class {
|
|
|
3459
3515
|
callback(err);
|
|
3460
3516
|
}
|
|
3461
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
|
+
}
|
|
3462
3573
|
exists(filePath, callback) {
|
|
3463
3574
|
this.promises.exists(filePath).then(
|
|
3464
3575
|
(result) => setTimeout(() => callback(result), 0),
|
|
3465
3576
|
() => setTimeout(() => callback(false), 0)
|
|
3466
3577
|
);
|
|
3467
3578
|
}
|
|
3579
|
+
opendir(filePath, callback) {
|
|
3580
|
+
this.promises.opendir(filePath).then(
|
|
3581
|
+
(dir) => setTimeout(() => callback(null, dir), 0),
|
|
3582
|
+
(err) => setTimeout(() => callback(err), 0)
|
|
3583
|
+
);
|
|
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
|
+
}
|
|
3468
3602
|
};
|
|
3469
3603
|
var VFSPromises = class {
|
|
3470
3604
|
_async;
|
|
@@ -3473,6 +3607,10 @@ var VFSPromises = class {
|
|
|
3473
3607
|
this._async = asyncRequest;
|
|
3474
3608
|
this._ns = ns;
|
|
3475
3609
|
}
|
|
3610
|
+
/** Node.js compat: fs.promises.constants (same as fs.constants) */
|
|
3611
|
+
get constants() {
|
|
3612
|
+
return constants;
|
|
3613
|
+
}
|
|
3476
3614
|
readFile(filePath, options) {
|
|
3477
3615
|
return readFile(this._async, toPathString(filePath), options);
|
|
3478
3616
|
}
|
|
@@ -3602,6 +3740,9 @@ var VFSPromises = class {
|
|
|
3602
3740
|
utimes(filePath, atime, mtime) {
|
|
3603
3741
|
return utimes(this._async, toPathString(filePath), atime, mtime);
|
|
3604
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
|
+
}
|
|
3605
3746
|
/** Like utimes but operates on the symlink itself. In this VFS, delegates to utimes. */
|
|
3606
3747
|
lutimes(filePath, atime, mtime) {
|
|
3607
3748
|
return utimes(this._async, filePath, atime, mtime);
|
|
@@ -5332,6 +5473,6 @@ function init() {
|
|
|
5332
5473
|
return getDefaultFS().init();
|
|
5333
5474
|
}
|
|
5334
5475
|
|
|
5335
|
-
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 };
|
|
5336
5477
|
//# sourceMappingURL=index.js.map
|
|
5337
5478
|
//# sourceMappingURL=index.js.map
|