@zenfs/core 1.0.10 → 1.1.0
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/backends/backend.d.ts +4 -8
- package/dist/backends/backend.js +7 -11
- package/dist/backends/fetch.d.ts +2 -4
- package/dist/backends/fetch.js +1 -3
- package/dist/backends/file_index.js +3 -3
- package/dist/backends/memory.d.ts +1 -1
- package/dist/backends/overlay.d.ts +7 -3
- package/dist/backends/overlay.js +13 -9
- package/dist/backends/port/fs.d.ts +12 -17
- package/dist/backends/port/fs.js +5 -8
- package/dist/backends/port/rpc.d.ts +1 -1
- package/dist/backends/store/fs.d.ts +13 -15
- package/dist/backends/store/fs.js +35 -54
- package/dist/backends/store/simple.d.ts +1 -1
- package/dist/backends/store/simple.js +1 -1
- package/dist/backends/store/store.d.ts +7 -13
- package/dist/config.d.ts +13 -5
- package/dist/config.js +36 -26
- package/dist/devices.d.ts +158 -0
- package/dist/devices.js +423 -0
- package/dist/emulation/async.d.ts +21 -176
- package/dist/emulation/async.js +17 -111
- package/dist/emulation/constants.d.ts +5 -0
- package/dist/emulation/constants.js +5 -0
- package/dist/emulation/dir.d.ts +0 -1
- package/dist/emulation/path.d.ts +0 -4
- package/dist/emulation/path.js +4 -8
- package/dist/emulation/promises.d.ts +31 -121
- package/dist/emulation/promises.js +30 -97
- package/dist/emulation/shared.d.ts +7 -3
- package/dist/emulation/shared.js +11 -7
- package/dist/emulation/streams.d.ts +0 -3
- package/dist/emulation/sync.d.ts +25 -178
- package/dist/emulation/sync.js +36 -129
- package/dist/emulation/watchers.d.ts +0 -4
- package/dist/error.d.ts +11 -11
- package/dist/error.js +8 -10
- package/dist/file.d.ts +50 -171
- package/dist/file.js +34 -117
- package/dist/filesystem.d.ts +10 -62
- package/dist/filesystem.js +5 -6
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/inode.d.ts +0 -5
- package/dist/inode.js +0 -5
- package/dist/mixins/async.d.ts +4 -6
- package/dist/mixins/async.js +3 -1
- package/dist/mixins/mutexed.d.ts +4 -4
- package/dist/mixins/mutexed.js +7 -5
- package/dist/mixins/readonly.js +14 -15
- package/dist/mixins/shared.d.ts +5 -5
- package/dist/mixins/sync.d.ts +2 -2
- package/dist/stats.d.ts +21 -37
- package/dist/stats.js +10 -23
- package/dist/utils.d.ts +15 -7
- package/dist/utils.js +28 -6
- package/package.json +4 -4
- package/readme.md +58 -2
- package/src/backends/backend.ts +7 -11
- package/src/backends/fetch.ts +2 -4
- package/src/backends/file_index.ts +3 -3
- package/src/backends/memory.ts +1 -1
- package/src/backends/overlay.ts +11 -9
- package/src/backends/port/fs.ts +11 -14
- package/src/backends/port/rpc.ts +1 -0
- package/src/backends/store/fs.ts +40 -55
- package/src/backends/store/simple.ts +1 -1
- package/src/backends/store/store.ts +7 -13
- package/src/config.ts +48 -26
- package/src/devices.ts +469 -0
- package/src/emulation/async.ts +28 -178
- package/src/emulation/constants.ts +6 -0
- package/src/emulation/path.ts +4 -11
- package/src/emulation/promises.ts +34 -116
- package/src/emulation/shared.ts +11 -8
- package/src/emulation/sync.ts +41 -185
- package/src/error.ts +7 -11
- package/src/file.ts +48 -182
- package/src/filesystem.ts +14 -65
- package/src/index.ts +2 -0
- package/src/inode.ts +0 -6
- package/src/mixins/async.ts +4 -6
- package/src/mixins/mutexed.ts +4 -4
- package/src/mixins/readonly.ts +15 -15
- package/src/mixins/shared.ts +5 -5
- package/src/mixins/sync.ts +3 -3
- package/src/stats.ts +22 -40
- package/src/utils.ts +33 -6
|
@@ -77,14 +77,14 @@ export class FileHandle implements promises.FileHandle {
|
|
|
77
77
|
|
|
78
78
|
/**
|
|
79
79
|
* Asynchronous ftruncate(2) - Truncate a file to a specified length.
|
|
80
|
-
* @param
|
|
80
|
+
* @param length If not specified, defaults to `0`.
|
|
81
81
|
*/
|
|
82
|
-
public async truncate(
|
|
83
|
-
|
|
84
|
-
if (
|
|
82
|
+
public async truncate(length?: number | null): Promise<void> {
|
|
83
|
+
length ||= 0;
|
|
84
|
+
if (length < 0) {
|
|
85
85
|
throw new ErrnoError(Errno.EINVAL);
|
|
86
86
|
}
|
|
87
|
-
await this.file.truncate(
|
|
87
|
+
await this.file.truncate(length);
|
|
88
88
|
emitChange('change', this.file.path);
|
|
89
89
|
}
|
|
90
90
|
|
|
@@ -103,10 +103,9 @@ export class FileHandle implements promises.FileHandle {
|
|
|
103
103
|
* The `FileHandle` must have been opened for appending.
|
|
104
104
|
* @param data The data to write. If something other than a `Buffer` or `Uint8Array` is provided, the value is coerced to a string.
|
|
105
105
|
* @param _options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
* If `flag` is not supplied, the default of `'a'` is used.
|
|
106
|
+
* - `encoding` defaults to `'utf8'`.
|
|
107
|
+
* - `mode` defaults to `0o666`.
|
|
108
|
+
* - `flag` defaults to `'a'`.
|
|
110
109
|
*/
|
|
111
110
|
public async appendFile(data: string | Uint8Array, _options: (fs.ObjectEncodingOptions & FlagAndOpenMode) | BufferEncoding = {}): Promise<void> {
|
|
112
111
|
const options = normalizeOptions(_options, 'utf8', 'a', 0o644);
|
|
@@ -161,10 +160,11 @@ export class FileHandle implements promises.FileHandle {
|
|
|
161
160
|
/**
|
|
162
161
|
* Returns a `ReadableStream` that may be used to read the files data.
|
|
163
162
|
*
|
|
164
|
-
* An error will be thrown if this method is called more than once or is called after the `FileHandle` is closed
|
|
165
|
-
* or closing.
|
|
163
|
+
* An error will be thrown if this method is called more than once or is called after the `FileHandle` is closed or closing.
|
|
166
164
|
*
|
|
167
|
-
* While the `ReadableStream` will read the file to completion,
|
|
165
|
+
* While the `ReadableStream` will read the file to completion,
|
|
166
|
+
* it will not close the `FileHandle` automatically.
|
|
167
|
+
* User code must still call the `fileHandle.close()` method.
|
|
168
168
|
*
|
|
169
169
|
* @since v17.0.0
|
|
170
170
|
* @experimental
|
|
@@ -272,10 +272,9 @@ export class FileHandle implements promises.FileHandle {
|
|
|
272
272
|
* It is unsafe to call `writeFile()` multiple times on the same file without waiting for the `Promise` to be resolved (or rejected).
|
|
273
273
|
* @param data The data to write. If something other than a `Buffer` or `Uint8Array` is provided, the value is coerced to a string.
|
|
274
274
|
* @param _options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
|
|
275
|
-
*
|
|
276
|
-
*
|
|
277
|
-
*
|
|
278
|
-
* If `flag` is not supplied, the default of `'w'` is used.
|
|
275
|
+
* - `encoding` defaults to `'utf8'`.
|
|
276
|
+
* - `mode` defaults to `0o666`.
|
|
277
|
+
* - `flag` defaults to `'w'`.
|
|
279
278
|
*/
|
|
280
279
|
public async writeFile(data: string | Uint8Array, _options: fs.WriteFileOptions = {}): Promise<void> {
|
|
281
280
|
const options = normalizeOptions(_options, 'utf8', 'w', 0o644);
|
|
@@ -332,10 +331,8 @@ export class FileHandle implements promises.FileHandle {
|
|
|
332
331
|
}
|
|
333
332
|
|
|
334
333
|
/**
|
|
335
|
-
* Creates a
|
|
336
|
-
*
|
|
334
|
+
* Creates a stream for reading from the file.
|
|
337
335
|
* @param options Options for the readable stream
|
|
338
|
-
* @returns A `ReadStream` object.
|
|
339
336
|
*/
|
|
340
337
|
public createReadStream(options?: CreateReadStreamOptions): ReadStream {
|
|
341
338
|
const stream = new ReadStream({
|
|
@@ -359,10 +356,8 @@ export class FileHandle implements promises.FileHandle {
|
|
|
359
356
|
}
|
|
360
357
|
|
|
361
358
|
/**
|
|
362
|
-
* Creates a
|
|
363
|
-
*
|
|
359
|
+
* Creates a stream for writing to the file.
|
|
364
360
|
* @param options Options for the writeable stream.
|
|
365
|
-
* @returns A `WriteStream` object
|
|
366
361
|
*/
|
|
367
362
|
public createWriteStream(options?: CreateWriteStreamOptions): WriteStream {
|
|
368
363
|
const streamOptions = {
|
|
@@ -385,11 +380,6 @@ export class FileHandle implements promises.FileHandle {
|
|
|
385
380
|
}
|
|
386
381
|
}
|
|
387
382
|
|
|
388
|
-
/**
|
|
389
|
-
* Renames a file
|
|
390
|
-
* @param oldPath
|
|
391
|
-
* @param newPath
|
|
392
|
-
*/
|
|
393
383
|
export async function rename(oldPath: fs.PathLike, newPath: fs.PathLike): Promise<void> {
|
|
394
384
|
oldPath = normalizePath(oldPath);
|
|
395
385
|
newPath = normalizePath(newPath);
|
|
@@ -414,8 +404,7 @@ export async function rename(oldPath: fs.PathLike, newPath: fs.PathLike): Promis
|
|
|
414
404
|
rename satisfies typeof promises.rename;
|
|
415
405
|
|
|
416
406
|
/**
|
|
417
|
-
* Test whether or not
|
|
418
|
-
* @param path
|
|
407
|
+
* Test whether or not `path` exists by checking with the file system.
|
|
419
408
|
*/
|
|
420
409
|
export async function exists(path: fs.PathLike): Promise<boolean> {
|
|
421
410
|
try {
|
|
@@ -430,11 +419,6 @@ export async function exists(path: fs.PathLike): Promise<boolean> {
|
|
|
430
419
|
}
|
|
431
420
|
}
|
|
432
421
|
|
|
433
|
-
/**
|
|
434
|
-
* `stat`.
|
|
435
|
-
* @param path
|
|
436
|
-
* @returns Stats
|
|
437
|
-
*/
|
|
438
422
|
export async function stat(path: fs.PathLike, options: fs.BigIntOptions): Promise<BigIntStats>;
|
|
439
423
|
export async function stat(path: fs.PathLike, options?: { bigint?: false }): Promise<Stats>;
|
|
440
424
|
export async function stat(path: fs.PathLike, options?: fs.StatOptions): Promise<Stats | BigIntStats>;
|
|
@@ -457,8 +441,6 @@ stat satisfies typeof promises.stat;
|
|
|
457
441
|
* `lstat`.
|
|
458
442
|
* `lstat()` is identical to `stat()`, except that if path is a symbolic link,
|
|
459
443
|
* then the link itself is stat-ed, not the file that it refers to.
|
|
460
|
-
* @param path
|
|
461
|
-
* @return
|
|
462
444
|
*/
|
|
463
445
|
export async function lstat(path: fs.PathLike, options?: { bigint?: boolean }): Promise<Stats>;
|
|
464
446
|
export async function lstat(path: fs.PathLike, options: { bigint: true }): Promise<BigIntStats>;
|
|
@@ -476,21 +458,12 @@ lstat satisfies typeof promises.lstat;
|
|
|
476
458
|
|
|
477
459
|
// FILE-ONLY METHODS
|
|
478
460
|
|
|
479
|
-
/**
|
|
480
|
-
* `truncate`.
|
|
481
|
-
* @param path
|
|
482
|
-
* @param len
|
|
483
|
-
*/
|
|
484
461
|
export async function truncate(path: fs.PathLike, len: number = 0): Promise<void> {
|
|
485
462
|
await using handle = await open(path, 'r+');
|
|
486
463
|
await handle.truncate(len);
|
|
487
464
|
}
|
|
488
465
|
truncate satisfies typeof promises.truncate;
|
|
489
466
|
|
|
490
|
-
/**
|
|
491
|
-
* `unlink`.
|
|
492
|
-
* @param path
|
|
493
|
-
*/
|
|
494
467
|
export async function unlink(path: fs.PathLike): Promise<void> {
|
|
495
468
|
path = normalizePath(path);
|
|
496
469
|
const { fs, path: resolved } = resolveMount(path);
|
|
@@ -562,7 +535,7 @@ async function _open(path: fs.PathLike, _flag: fs.OpenMode, _mode: fs.Mode = 0o6
|
|
|
562
535
|
/**
|
|
563
536
|
* Asynchronous file open.
|
|
564
537
|
* @see http://www.manpagez.com/man/2/open/
|
|
565
|
-
* @param
|
|
538
|
+
* @param flag Handles the complexity of the various file modes. See its API for more details.
|
|
566
539
|
* @param mode Mode to use to open the file. Can be ignored if the filesystem doesn't support permissions.
|
|
567
540
|
*/
|
|
568
541
|
export async function open(path: fs.PathLike, flag: fs.OpenMode = 'r', mode: fs.Mode = 0o644): Promise<FileHandle> {
|
|
@@ -572,11 +545,9 @@ open satisfies typeof promises.open;
|
|
|
572
545
|
|
|
573
546
|
/**
|
|
574
547
|
* Asynchronously reads the entire contents of a file.
|
|
575
|
-
* @
|
|
576
|
-
* @
|
|
577
|
-
*
|
|
578
|
-
* options.flag Defaults to `'r'`.
|
|
579
|
-
* @returns file data
|
|
548
|
+
* @option encoding The string encoding for the file contents. Defaults to `null`.
|
|
549
|
+
* @option flag Defaults to `'r'`.
|
|
550
|
+
* @returns the file data
|
|
580
551
|
*/
|
|
581
552
|
export async function readFile(path: fs.PathLike | promises.FileHandle, options?: { encoding?: null; flag?: fs.OpenMode } | null): Promise<Buffer>;
|
|
582
553
|
export async function readFile(path: fs.PathLike | promises.FileHandle, options: { encoding: BufferEncoding; flag?: fs.OpenMode } | BufferEncoding): Promise<string>;
|
|
@@ -598,12 +569,9 @@ readFile satisfies typeof promises.readFile;
|
|
|
598
569
|
* Asynchronously writes data to a file, replacing the file if it already exists.
|
|
599
570
|
*
|
|
600
571
|
* The encoding option is ignored if data is a buffer.
|
|
601
|
-
* @
|
|
602
|
-
* @
|
|
603
|
-
* @
|
|
604
|
-
* @option options encoding Defaults to `'utf8'`.
|
|
605
|
-
* @option options mode Defaults to `0644`.
|
|
606
|
-
* @option options flag Defaults to `'w'`.
|
|
572
|
+
* @option encoding Defaults to `'utf8'`.
|
|
573
|
+
* @option mode Defaults to `0644`.
|
|
574
|
+
* @option flag Defaults to `'w'`.
|
|
607
575
|
*/
|
|
608
576
|
export async function writeFile(
|
|
609
577
|
path: fs.PathLike | promises.FileHandle,
|
|
@@ -622,14 +590,10 @@ export async function writeFile(
|
|
|
622
590
|
writeFile satisfies typeof promises.writeFile;
|
|
623
591
|
|
|
624
592
|
/**
|
|
625
|
-
* Asynchronously append data to a file, creating the file if it not yet
|
|
626
|
-
*
|
|
627
|
-
* @
|
|
628
|
-
* @
|
|
629
|
-
* @param options
|
|
630
|
-
* @option options encoding Defaults to `'utf8'`.
|
|
631
|
-
* @option options mode Defaults to `0644`.
|
|
632
|
-
* @option options flag Defaults to `'a'`.
|
|
593
|
+
* Asynchronously append data to a file, creating the file if it not yet exists.
|
|
594
|
+
* @option encoding Defaults to `'utf8'`.
|
|
595
|
+
* @option mode Defaults to `0644`.
|
|
596
|
+
* @option flag Defaults to `'a'`.
|
|
633
597
|
*/
|
|
634
598
|
export async function appendFile(
|
|
635
599
|
path: fs.PathLike | promises.FileHandle,
|
|
@@ -653,10 +617,6 @@ appendFile satisfies typeof promises.appendFile;
|
|
|
653
617
|
|
|
654
618
|
// DIRECTORY-ONLY METHODS
|
|
655
619
|
|
|
656
|
-
/**
|
|
657
|
-
* `rmdir`.
|
|
658
|
-
* @param path
|
|
659
|
-
*/
|
|
660
620
|
export async function rmdir(path: fs.PathLike): Promise<void> {
|
|
661
621
|
path = normalizePath(path);
|
|
662
622
|
path = (await exists(path)) ? await realpath(path) : path;
|
|
@@ -723,7 +683,7 @@ mkdir satisfies typeof promises.mkdir;
|
|
|
723
683
|
/**
|
|
724
684
|
* Asynchronous readdir(3) - read a directory.
|
|
725
685
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
726
|
-
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'
|
|
686
|
+
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'`.
|
|
727
687
|
*/
|
|
728
688
|
export async function readdir(path: fs.PathLike, options?: (fs.ObjectEncodingOptions & { withFileTypes?: false; recursive?: boolean }) | BufferEncoding | null): Promise<string[]>;
|
|
729
689
|
export async function readdir(path: fs.PathLike, options: fs.BufferEncodingOption & { withFileTypes?: false; recursive?: boolean }): Promise<Buffer[]>;
|
|
@@ -768,11 +728,6 @@ readdir satisfies typeof promises.readdir;
|
|
|
768
728
|
|
|
769
729
|
// SYMLINK METHODS
|
|
770
730
|
|
|
771
|
-
/**
|
|
772
|
-
* `link`.
|
|
773
|
-
* @param targetPath
|
|
774
|
-
* @param linkPath
|
|
775
|
-
*/
|
|
776
731
|
export async function link(targetPath: fs.PathLike, linkPath: fs.PathLike): Promise<void> {
|
|
777
732
|
targetPath = normalizePath(targetPath);
|
|
778
733
|
if (!(await stat(dirname(targetPath))).hasAccess(constants.R_OK)) {
|
|
@@ -820,10 +775,6 @@ export async function symlink(target: fs.PathLike, path: fs.PathLike, type: fs.s
|
|
|
820
775
|
}
|
|
821
776
|
symlink satisfies typeof promises.symlink;
|
|
822
777
|
|
|
823
|
-
/**
|
|
824
|
-
* readlink.
|
|
825
|
-
* @param path
|
|
826
|
-
*/
|
|
827
778
|
export async function readlink(path: fs.PathLike, options: fs.BufferEncodingOption): Promise<Buffer>;
|
|
828
779
|
export async function readlink(path: fs.PathLike, options?: fs.EncodingOption | null): Promise<string>;
|
|
829
780
|
export async function readlink(path: fs.PathLike, options?: fs.BufferEncodingOption | fs.EncodingOption | string | null): Promise<string | Buffer>;
|
|
@@ -837,46 +788,24 @@ readlink satisfies typeof promises.readlink;
|
|
|
837
788
|
|
|
838
789
|
// PROPERTY OPERATIONS
|
|
839
790
|
|
|
840
|
-
/**
|
|
841
|
-
* `chown`.
|
|
842
|
-
* @param path
|
|
843
|
-
* @param uid
|
|
844
|
-
* @param gid
|
|
845
|
-
*/
|
|
846
791
|
export async function chown(path: fs.PathLike, uid: number, gid: number): Promise<void> {
|
|
847
792
|
await using handle = await open(path, 'r+');
|
|
848
793
|
await handle.chown(uid, gid);
|
|
849
794
|
}
|
|
850
795
|
chown satisfies typeof promises.chown;
|
|
851
796
|
|
|
852
|
-
/**
|
|
853
|
-
* `lchown`.
|
|
854
|
-
* @param path
|
|
855
|
-
* @param uid
|
|
856
|
-
* @param gid
|
|
857
|
-
*/
|
|
858
797
|
export async function lchown(path: fs.PathLike, uid: number, gid: number): Promise<void> {
|
|
859
798
|
await using handle: FileHandle = await _open(path, 'r+', 0o644, false);
|
|
860
799
|
await handle.chown(uid, gid);
|
|
861
800
|
}
|
|
862
801
|
lchown satisfies typeof promises.lchown;
|
|
863
802
|
|
|
864
|
-
/**
|
|
865
|
-
* `chmod`.
|
|
866
|
-
* @param path
|
|
867
|
-
* @param mode
|
|
868
|
-
*/
|
|
869
803
|
export async function chmod(path: fs.PathLike, mode: fs.Mode): Promise<void> {
|
|
870
804
|
await using handle = await open(path, 'r+');
|
|
871
805
|
await handle.chmod(mode);
|
|
872
806
|
}
|
|
873
807
|
chmod satisfies typeof promises.chmod;
|
|
874
808
|
|
|
875
|
-
/**
|
|
876
|
-
* `lchmod`.
|
|
877
|
-
* @param path
|
|
878
|
-
* @param mode
|
|
879
|
-
*/
|
|
880
809
|
export async function lchmod(path: fs.PathLike, mode: fs.Mode): Promise<void> {
|
|
881
810
|
await using handle: FileHandle = await _open(path, 'r+', 0o644, false);
|
|
882
811
|
await handle.chmod(mode);
|
|
@@ -885,9 +814,6 @@ lchmod satisfies typeof promises.lchmod;
|
|
|
885
814
|
|
|
886
815
|
/**
|
|
887
816
|
* Change file timestamps of the file referenced by the supplied path.
|
|
888
|
-
* @param path
|
|
889
|
-
* @param atime
|
|
890
|
-
* @param mtime
|
|
891
817
|
*/
|
|
892
818
|
export async function utimes(path: fs.PathLike, atime: string | number | Date, mtime: string | number | Date): Promise<void> {
|
|
893
819
|
await using handle = await open(path, 'r+');
|
|
@@ -897,9 +823,6 @@ utimes satisfies typeof promises.utimes;
|
|
|
897
823
|
|
|
898
824
|
/**
|
|
899
825
|
* Change file timestamps of the file referenced by the supplied path.
|
|
900
|
-
* @param path
|
|
901
|
-
* @param atime
|
|
902
|
-
* @param mtime
|
|
903
826
|
*/
|
|
904
827
|
export async function lutimes(path: fs.PathLike, atime: fs.TimeLike, mtime: fs.TimeLike): Promise<void> {
|
|
905
828
|
await using handle: FileHandle = await _open(path, 'r+', 0o644, false);
|
|
@@ -910,7 +833,7 @@ lutimes satisfies typeof promises.lutimes;
|
|
|
910
833
|
/**
|
|
911
834
|
* Asynchronous realpath(3) - return the canonicalized absolute pathname.
|
|
912
835
|
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
913
|
-
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result.
|
|
836
|
+
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. Defaults to `'utf8'`.
|
|
914
837
|
*/
|
|
915
838
|
export async function realpath(path: fs.PathLike, options: fs.BufferEncodingOption): Promise<Buffer>;
|
|
916
839
|
export async function realpath(path: fs.PathLike, options?: fs.EncodingOption | BufferEncoding): Promise<string>;
|
|
@@ -961,11 +884,6 @@ export function watch<T extends string | Buffer>(filename: fs.PathLike, options:
|
|
|
961
884
|
}
|
|
962
885
|
watch satisfies typeof promises.watch;
|
|
963
886
|
|
|
964
|
-
/**
|
|
965
|
-
* `access`.
|
|
966
|
-
* @param path
|
|
967
|
-
* @param mode
|
|
968
|
-
*/
|
|
969
887
|
export async function access(path: fs.PathLike, mode: number = constants.F_OK): Promise<void> {
|
|
970
888
|
const stats = await stat(path);
|
|
971
889
|
if (!stats.hasAccess(mode)) {
|
|
@@ -1066,7 +984,7 @@ opendir satisfies typeof promises.opendir;
|
|
|
1066
984
|
* @param opts Options for the copy operation. Currently supports these options from Node.js 'fs.await cp':
|
|
1067
985
|
* * `dereference`: Dereference symbolic links.
|
|
1068
986
|
* * `errorOnExist`: Throw an error if the destination file or directory already exists.
|
|
1069
|
-
* * `filter`: A function that takes a source and destination path and returns a boolean, indicating whether to copy
|
|
987
|
+
* * `filter`: A function that takes a source and destination path and returns a boolean, indicating whether to copy `source` element.
|
|
1070
988
|
* * `force`: Overwrite the destination if it exists, and overwrite existing readonly destination files.
|
|
1071
989
|
* * `preserveTimestamps`: Preserve file timestamps.
|
|
1072
990
|
* * `recursive`: If `true`, copies directories recursively.
|
|
@@ -1114,8 +1032,8 @@ export async function cp(source: fs.PathLike, destination: fs.PathLike, opts?: f
|
|
|
1114
1032
|
cp satisfies typeof promises.cp;
|
|
1115
1033
|
|
|
1116
1034
|
/**
|
|
1117
|
-
* @since v18.15.0
|
|
1118
|
-
* @
|
|
1035
|
+
* @since Node v18.15.0
|
|
1036
|
+
* @returns Fulfills with an {fs.StatFs} for the file system.
|
|
1119
1037
|
*/
|
|
1120
1038
|
export async function statfs(path: fs.PathLike, opts?: fs.StatFsOptions & { bigint?: false }): Promise<fs.StatsFs>;
|
|
1121
1039
|
export async function statfs(path: fs.PathLike, opts: fs.StatFsOptions & { bigint: true }): Promise<fs.BigIntStatsFs>;
|
package/src/emulation/shared.ts
CHANGED
|
@@ -5,9 +5,9 @@ import { InMemory } from '../backends/memory.js';
|
|
|
5
5
|
import { Errno, ErrnoError } from '../error.js';
|
|
6
6
|
import type { File } from '../file.js';
|
|
7
7
|
import type { FileSystem } from '../filesystem.js';
|
|
8
|
-
import { size_max } from '../inode.js';
|
|
9
8
|
import { normalizePath } from '../utils.js';
|
|
10
9
|
import { resolve, type AbsolutePath } from './path.js';
|
|
10
|
+
import { size_max } from './constants.js';
|
|
11
11
|
|
|
12
12
|
// descriptors
|
|
13
13
|
export const fdMap: Map<number, File> = new Map();
|
|
@@ -24,7 +24,6 @@ export function fd2file(fd: number): File {
|
|
|
24
24
|
return fdMap.get(fd)!;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
// mounting
|
|
28
27
|
export type MountObject = Record<AbsolutePath, FileSystem>;
|
|
29
28
|
|
|
30
29
|
/**
|
|
@@ -33,13 +32,11 @@ export type MountObject = Record<AbsolutePath, FileSystem>;
|
|
|
33
32
|
*/
|
|
34
33
|
export const mounts: Map<string, FileSystem> = new Map();
|
|
35
34
|
|
|
36
|
-
|
|
37
|
-
Set a default root.
|
|
38
|
-
*/
|
|
35
|
+
// Set a default root.
|
|
39
36
|
mount('/', InMemory.create({ name: 'root' }));
|
|
40
37
|
|
|
41
38
|
/**
|
|
42
|
-
* Mounts the file system at
|
|
39
|
+
* Mounts the file system at `mountPoint`.
|
|
43
40
|
*/
|
|
44
41
|
export function mount(mountPoint: string, fs: FileSystem): void {
|
|
45
42
|
if (mountPoint[0] !== '/') {
|
|
@@ -53,7 +50,7 @@ export function mount(mountPoint: string, fs: FileSystem): void {
|
|
|
53
50
|
}
|
|
54
51
|
|
|
55
52
|
/**
|
|
56
|
-
* Unmounts the file system at
|
|
53
|
+
* Unmounts the file system at `mountPoint`.
|
|
57
54
|
*/
|
|
58
55
|
export function umount(mountPoint: string): void {
|
|
59
56
|
if (mountPoint[0] !== '/') {
|
|
@@ -71,7 +68,8 @@ export function umount(mountPoint: string): void {
|
|
|
71
68
|
*/
|
|
72
69
|
export function resolveMount(path: string): { fs: FileSystem; path: string; mountPoint: string } {
|
|
73
70
|
path = normalizePath(path);
|
|
74
|
-
|
|
71
|
+
// Maybe do something for devices here
|
|
72
|
+
const sortedMounts = [...mounts].sort((a, b) => (a[0].length > b[0].length ? -1 : 1)); // descending order of the string length
|
|
75
73
|
for (const [mountPoint, fs] of sortedMounts) {
|
|
76
74
|
// We know path is normalized, so it would be a substring of the mount point.
|
|
77
75
|
if (mountPoint.length <= path.length && path.startsWith(mountPoint)) {
|
|
@@ -88,6 +86,7 @@ export function resolveMount(path: string): { fs: FileSystem; path: string; moun
|
|
|
88
86
|
|
|
89
87
|
/**
|
|
90
88
|
* Reverse maps the paths in text from the mounted FileSystem to the global path
|
|
89
|
+
* @hidden
|
|
91
90
|
*/
|
|
92
91
|
export function fixPaths(text: string, paths: Record<string, string>): string {
|
|
93
92
|
for (const [from, to] of Object.entries(paths)) {
|
|
@@ -96,6 +95,10 @@ export function fixPaths(text: string, paths: Record<string, string>): string {
|
|
|
96
95
|
return text;
|
|
97
96
|
}
|
|
98
97
|
|
|
98
|
+
/**
|
|
99
|
+
* Fix paths in error stacks
|
|
100
|
+
* @hidden
|
|
101
|
+
*/
|
|
99
102
|
export function fixError<E extends Error>(e: E, paths: Record<string, string>): E {
|
|
100
103
|
if (typeof e.stack == 'string') {
|
|
101
104
|
e.stack = fixPaths(e.stack, paths);
|