@zenfs/core 0.3.4 → 0.4.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.
Files changed (44) hide show
  1. package/dist/FileIndex.d.ts +6 -0
  2. package/dist/FileIndex.js +3 -3
  3. package/dist/backends/AsyncMirror.d.ts +3 -5
  4. package/dist/backends/AsyncMirror.js +7 -6
  5. package/dist/backends/AsyncStore.d.ts +9 -4
  6. package/dist/backends/AsyncStore.js +7 -2
  7. package/dist/backends/Locked.d.ts +8 -8
  8. package/dist/backends/Locked.js +2 -1
  9. package/dist/backends/Overlay.d.ts +13 -1
  10. package/dist/backends/Overlay.js +16 -16
  11. package/dist/backends/SyncStore.d.ts +8 -5
  12. package/dist/backends/SyncStore.js +9 -5
  13. package/dist/backends/backend.js +8 -8
  14. package/dist/browser.min.js +4 -5
  15. package/dist/browser.min.js.map +4 -4
  16. package/dist/cred.d.ts +1 -1
  17. package/dist/cred.js +1 -1
  18. package/dist/emulation/callbacks.d.ts +1 -1
  19. package/dist/emulation/callbacks.js +1 -1
  20. package/dist/emulation/constants.d.ts +48 -42
  21. package/dist/emulation/constants.js +68 -59
  22. package/dist/emulation/dir.d.ts +2 -2
  23. package/dist/emulation/promises.d.ts +1 -1
  24. package/dist/emulation/promises.js +6 -6
  25. package/dist/emulation/sync.d.ts +1 -1
  26. package/dist/emulation/sync.js +7 -7
  27. package/dist/file.d.ts +26 -12
  28. package/dist/file.js +68 -29
  29. package/dist/filesystem.d.ts +3 -3
  30. package/dist/index.d.ts +6 -3
  31. package/dist/index.js +4 -5
  32. package/dist/inode.d.ts +21 -15
  33. package/dist/inode.js +52 -40
  34. package/dist/mutex.d.ts +1 -2
  35. package/dist/mutex.js +1 -1
  36. package/dist/stats.d.ts +70 -18
  37. package/dist/stats.js +12 -18
  38. package/dist/utils.d.ts +3 -8
  39. package/dist/utils.js +60 -39
  40. package/package.json +5 -1
  41. package/readme.md +14 -10
  42. package/scripts/make-index.js +100 -0
  43. package/dist/backends/index.d.ts +0 -10
  44. package/dist/backends/index.js +0 -12
package/dist/cred.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Credentials used for FS ops.
2
+ * Credentials used for various operations.
3
3
  * Similar to Linux's cred struct. See https://github.com/torvalds/linux/blob/master/include/linux/cred.h
4
4
  */
5
5
  export declare class Cred {
package/dist/cred.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Credentials used for FS ops.
2
+ * Credentials used for various operations.
3
3
  * Similar to Linux's cred struct. See https://github.com/torvalds/linux/blob/master/include/linux/cred.h
4
4
  */
5
5
  export class Cred {
@@ -2,7 +2,7 @@
2
2
  /// <reference types="node" resolution-mode="require"/>
3
3
  import type * as Node from 'fs';
4
4
  import { TwoArgCallback, NoArgCallback, ThreeArgCallback, FileContents } from '../filesystem.js';
5
- import { BigIntStats, Stats } from '../stats.js';
5
+ import { BigIntStats, type Stats } from '../stats.js';
6
6
  import { PathLike } from './shared.js';
7
7
  import { ReadStream, WriteStream } from './streams.js';
8
8
  import { Dirent } from './dir.js';
@@ -102,7 +102,7 @@ export function fstat(fd, options, cb = nop) {
102
102
  cb = typeof options == 'function' ? options : cb;
103
103
  fd2file(fd)
104
104
  .stat()
105
- .then(stats => cb(null, (typeof options == 'object' && options?.bigint ? BigIntStats.clone(stats) : stats)))
105
+ .then(stats => cb(null, (typeof options == 'object' && options?.bigint ? new BigIntStats(stats) : stats)))
106
106
  .catch(cb);
107
107
  }
108
108
  fstat;
@@ -1,10 +1,10 @@
1
- /** Constant for fs.access(). File is visible to the calling process. */
1
+ /** File is visible to the calling process. */
2
2
  export declare const F_OK = 0;
3
- /** Constant for fs.access(). File can be read by the calling process. */
3
+ /** File can be read by the calling process. */
4
4
  export declare const R_OK = 4;
5
- /** Constant for fs.access(). File can be written by the calling process. */
5
+ /** File can be written by the calling process. */
6
6
  export declare const W_OK = 2;
7
- /** Constant for fs.access(). File can be executed by the calling process. */
7
+ /** File can be executed by the calling process. */
8
8
  export declare const X_OK = 1;
9
9
  /** Constant for fs.copyFile. Flag indicating the destination file should not be overwritten if it already exists. */
10
10
  export declare const COPYFILE_EXCL = 1;
@@ -18,27 +18,27 @@ export declare const COPYFILE_FICLONE = 2;
18
18
  * If the underlying platform does not support copy-on-write, then the operation will fail with an error.
19
19
  */
20
20
  export declare const COPYFILE_FICLONE_FORCE = 4;
21
- /** Constant for fs.open(). Flag indicating to open a file for read-only access. */
21
+ /** Flag indicating to open a file for read-only access. */
22
22
  export declare const O_RDONLY = 0;
23
- /** Constant for fs.open(). Flag indicating to open a file for write-only access. */
23
+ /** Flag indicating to open a file for write-only access. */
24
24
  export declare const O_WRONLY = 1;
25
- /** Constant for fs.open(). Flag indicating to open a file for read-write access. */
25
+ /** Flag indicating to open a file for read-write access. */
26
26
  export declare const O_RDWR = 2;
27
- /** Constant for fs.open(). Flag indicating to create the file if it does not already exist. */
27
+ /** Flag indicating to create the file if it does not already exist. */
28
28
  export declare const O_CREAT = 64;
29
- /** Constant for fs.open(). Flag indicating that opening a file should fail if the O_CREAT flag is set and the file already exists. */
29
+ /** Flag indicating that opening a file should fail if the O_CREAT flag is set and the file already exists. */
30
30
  export declare const O_EXCL = 128;
31
31
  /**
32
- * Constant for fs.open(). Flag indicating that if path identifies a terminal device,
32
+ * Flag indicating that if path identifies a terminal device,
33
33
  * opening the path shall not cause that terminal to become the controlling terminal for the process
34
34
  * (if the process does not already have one).
35
35
  */
36
36
  export declare const O_NOCTTY = 256;
37
- /** Constant for fs.open(). Flag indicating that if the file exists and is a regular file, and the file is opened successfully for write access, its length shall be truncated to zero. */
37
+ /** Flag indicating that if the file exists and is a regular file, and the file is opened successfully for write access, its length shall be truncated to zero. */
38
38
  export declare const O_TRUNC = 512;
39
- /** Constant for fs.open(). Flag indicating that data will be appended to the end of the file. */
39
+ /** Flag indicating that data will be appended to the end of the file. */
40
40
  export declare const O_APPEND = 1024;
41
- /** Constant for fs.open(). Flag indicating that the open should fail if the path is not a directory. */
41
+ /** Flag indicating that the open should fail if the path is not a directory. */
42
42
  export declare const O_DIRECTORY = 65536;
43
43
  /**
44
44
  * constant for fs.open().
@@ -47,55 +47,61 @@ export declare const O_DIRECTORY = 65536;
47
47
  * This flag is available on Linux operating systems only.
48
48
  */
49
49
  export declare const O_NOATIME = 262144;
50
- /** Constant for fs.open(). Flag indicating that the open should fail if the path is a symbolic link. */
50
+ /** Flag indicating that the open should fail if the path is a symbolic link. */
51
51
  export declare const O_NOFOLLOW = 131072;
52
- /** Constant for fs.open(). Flag indicating that the file is opened for synchronous I/O. */
52
+ /** Flag indicating that the file is opened for synchronous I/O. */
53
53
  export declare const O_SYNC = 1052672;
54
- /** Constant for fs.open(). Flag indicating that the file is opened for synchronous I/O with write operations waiting for data integrity. */
54
+ /** Flag indicating that the file is opened for synchronous I/O with write operations waiting for data integrity. */
55
55
  export declare const O_DSYNC = 4096;
56
- /** Constant for fs.open(). Flag indicating to open the symbolic link itself rather than the resource it is pointing to. */
56
+ /** Flag indicating to open the symbolic link itself rather than the resource it is pointing to. */
57
57
  export declare const O_SYMLINK = 32768;
58
- /** Constant for fs.open(). When set, an attempt will be made to minimize caching effects of file I/O. */
58
+ /** When set, an attempt will be made to minimize caching effects of file I/O. */
59
59
  export declare const O_DIRECT = 16384;
60
- /** Constant for fs.open(). Flag indicating to open the file in nonblocking mode when possible. */
60
+ /** Flag indicating to open the file in nonblocking mode when possible. */
61
61
  export declare const O_NONBLOCK = 2048;
62
- /** Constant for fs.Stats mode property for determining a file's type. Bit mask used to extract the file type code. */
62
+ /** Bit mask used to extract the file type from mode. */
63
63
  export declare const S_IFMT = 61440;
64
- /** Constant for fs.Stats mode property for determining a file's type. File type constant for a regular file. */
64
+ /** File type constant for a socket. */
65
+ export declare const S_IFSOCK = 49152;
66
+ /** File type constant for a symbolic link. */
67
+ export declare const S_IFLNK = 40960;
68
+ /** File type constant for a regular file. */
65
69
  export declare const S_IFREG = 32768;
66
- /** Constant for fs.Stats mode property for determining a file's type. File type constant for a directory. */
70
+ /** File type constant for a block-oriented device file. */
71
+ export declare const S_IFBLK = 24576;
72
+ /** File type constant for a directory. */
67
73
  export declare const S_IFDIR = 16384;
68
- /** Constant for fs.Stats mode property for determining a file's type. File type constant for a character-oriented device file. */
74
+ /** File type constant for a character-oriented device file. */
69
75
  export declare const S_IFCHR = 8192;
70
- /** Constant for fs.Stats mode property for determining a file's type. File type constant for a block-oriented device file. */
71
- export declare const S_IFBLK = 24576;
72
- /** Constant for fs.Stats mode property for determining a file's type. File type constant for a FIFO/pipe. */
76
+ /** File type constant for a FIFO/pipe. */
73
77
  export declare const S_IFIFO = 4096;
74
- /** Constant for fs.Stats mode property for determining a file's type. File type constant for a symbolic link. */
75
- export declare const S_IFLNK = 40960;
76
- /** Constant for fs.Stats mode property for determining a file's type. File type constant for a socket. */
77
- export declare const S_IFSOCK = 49152;
78
- /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable, writable and executable by owner. */
78
+ /** Set user id */
79
+ export declare const S_ISUID = 2048;
80
+ /** Set group id */
81
+ export declare const S_ISGID = 1024;
82
+ /** Sticky bit */
83
+ export declare const S_ISVTX = 512;
84
+ /** File mode indicating readable, writable and executable by owner. */
79
85
  export declare const S_IRWXU = 448;
80
- /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable by owner. */
86
+ /** File mode indicating readable by owner. */
81
87
  export declare const S_IRUSR = 256;
82
- /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating writable by owner. */
88
+ /** File mode indicating writable by owner. */
83
89
  export declare const S_IWUSR = 128;
84
- /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating executable by owner. */
90
+ /** File mode indicating executable by owner. */
85
91
  export declare const S_IXUSR = 64;
86
- /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable, writable and executable by group. */
92
+ /** File mode indicating readable, writable and executable by group. */
87
93
  export declare const S_IRWXG = 56;
88
- /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable by group. */
94
+ /** File mode indicating readable by group. */
89
95
  export declare const S_IRGRP = 32;
90
- /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating writable by group. */
96
+ /** File mode indicating writable by group. */
91
97
  export declare const S_IWGRP = 16;
92
- /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating executable by group. */
98
+ /** File mode indicating executable by group. */
93
99
  export declare const S_IXGRP = 8;
94
- /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable, writable and executable by others. */
100
+ /** File mode indicating readable, writable and executable by others. */
95
101
  export declare const S_IRWXO = 7;
96
- /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable by others. */
102
+ /** File mode indicating readable by others. */
97
103
  export declare const S_IROTH = 4;
98
- /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating writable by others. */
104
+ /** File mode indicating writable by others. */
99
105
  export declare const S_IWOTH = 2;
100
- /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating executable by others. */
106
+ /** File mode indicating executable by others. */
101
107
  export declare const S_IXOTH = 1;
@@ -1,15 +1,18 @@
1
1
  /*
2
2
  FS Constants
3
3
  See https://nodejs.org/api/fs.html#file-access-constants
4
+
5
+ Note: Many of these are pulled from
6
+ https://github.com/torvalds/linux/blob/master/include/uapi/linux/stat.h
4
7
  */
5
8
  // File Access Constants
6
- /** Constant for fs.access(). File is visible to the calling process. */
9
+ /** File is visible to the calling process. */
7
10
  export const F_OK = 0;
8
- /** Constant for fs.access(). File can be read by the calling process. */
11
+ /** File can be read by the calling process. */
9
12
  export const R_OK = 4;
10
- /** Constant for fs.access(). File can be written by the calling process. */
13
+ /** File can be written by the calling process. */
11
14
  export const W_OK = 2;
12
- /** Constant for fs.access(). File can be executed by the calling process. */
15
+ /** File can be executed by the calling process. */
13
16
  export const X_OK = 1;
14
17
  // File Copy Constants
15
18
  /** Constant for fs.copyFile. Flag indicating the destination file should not be overwritten if it already exists. */
@@ -25,86 +28,92 @@ export const COPYFILE_FICLONE = 2;
25
28
  */
26
29
  export const COPYFILE_FICLONE_FORCE = 4;
27
30
  // File Open Constants
28
- /** Constant for fs.open(). Flag indicating to open a file for read-only access. */
31
+ /** Flag indicating to open a file for read-only access. */
29
32
  export const O_RDONLY = 0;
30
- /** Constant for fs.open(). Flag indicating to open a file for write-only access. */
33
+ /** Flag indicating to open a file for write-only access. */
31
34
  export const O_WRONLY = 1;
32
- /** Constant for fs.open(). Flag indicating to open a file for read-write access. */
35
+ /** Flag indicating to open a file for read-write access. */
33
36
  export const O_RDWR = 2;
34
- /** Constant for fs.open(). Flag indicating to create the file if it does not already exist. */
35
- export const O_CREAT = 0o100; // Node internal is
36
- /** Constant for fs.open(). Flag indicating that opening a file should fail if the O_CREAT flag is set and the file already exists. */
37
- export const O_EXCL = 0o200;
37
+ /** Flag indicating to create the file if it does not already exist. */
38
+ export const O_CREAT = 0x40; // bit 6
39
+ /** Flag indicating that opening a file should fail if the O_CREAT flag is set and the file already exists. */
40
+ export const O_EXCL = 0x80; // bit 7
38
41
  /**
39
- * Constant for fs.open(). Flag indicating that if path identifies a terminal device,
42
+ * Flag indicating that if path identifies a terminal device,
40
43
  * opening the path shall not cause that terminal to become the controlling terminal for the process
41
44
  * (if the process does not already have one).
42
45
  */
43
- export const O_NOCTTY = 0o400;
44
- /** Constant for fs.open(). Flag indicating that if the file exists and is a regular file, and the file is opened successfully for write access, its length shall be truncated to zero. */
45
- export const O_TRUNC = 0o1000;
46
- /** Constant for fs.open(). Flag indicating that data will be appended to the end of the file. */
47
- export const O_APPEND = 0o2000;
48
- /** Constant for fs.open(). Flag indicating that the open should fail if the path is not a directory. */
49
- export const O_DIRECTORY = 0o200000;
46
+ export const O_NOCTTY = 0x100; // bit 8
47
+ /** Flag indicating that if the file exists and is a regular file, and the file is opened successfully for write access, its length shall be truncated to zero. */
48
+ export const O_TRUNC = 0x200; // bit 9
49
+ /** Flag indicating that data will be appended to the end of the file. */
50
+ export const O_APPEND = 0x400; // bit 10
51
+ /** Flag indicating that the open should fail if the path is not a directory. */
52
+ export const O_DIRECTORY = 0x10000; // bit 16
50
53
  /**
51
54
  * constant for fs.open().
52
55
  * Flag indicating reading accesses to the file system will no longer result in
53
56
  * an update to the atime information associated with the file.
54
57
  * This flag is available on Linux operating systems only.
55
58
  */
56
- export const O_NOATIME = 0o1000000;
57
- /** Constant for fs.open(). Flag indicating that the open should fail if the path is a symbolic link. */
58
- export const O_NOFOLLOW = 0o400000;
59
- /** Constant for fs.open(). Flag indicating that the file is opened for synchronous I/O. */
60
- export const O_SYNC = 0o4010000;
61
- /** Constant for fs.open(). Flag indicating that the file is opened for synchronous I/O with write operations waiting for data integrity. */
62
- export const O_DSYNC = 0o10000;
63
- /** Constant for fs.open(). Flag indicating to open the symbolic link itself rather than the resource it is pointing to. */
64
- export const O_SYMLINK = 0o100000;
65
- /** Constant for fs.open(). When set, an attempt will be made to minimize caching effects of file I/O. */
66
- export const O_DIRECT = 0o40000;
67
- /** Constant for fs.open(). Flag indicating to open the file in nonblocking mode when possible. */
68
- export const O_NONBLOCK = 0o4000;
59
+ export const O_NOATIME = 0x40000; // bit 18
60
+ /** Flag indicating that the open should fail if the path is a symbolic link. */
61
+ export const O_NOFOLLOW = 0x20000; // bit 17
62
+ /** Flag indicating that the file is opened for synchronous I/O. */
63
+ export const O_SYNC = 0x101000; // bit 20 and bit 12
64
+ /** Flag indicating that the file is opened for synchronous I/O with write operations waiting for data integrity. */
65
+ export const O_DSYNC = 0x1000; // bit 12
66
+ /** Flag indicating to open the symbolic link itself rather than the resource it is pointing to. */
67
+ export const O_SYMLINK = 0x8000; // bit 15
68
+ /** When set, an attempt will be made to minimize caching effects of file I/O. */
69
+ export const O_DIRECT = 0x4000; // bit 14
70
+ /** Flag indicating to open the file in nonblocking mode when possible. */
71
+ export const O_NONBLOCK = 0x800; // bit 11
69
72
  // File Type Constants
70
- /** Constant for fs.Stats mode property for determining a file's type. Bit mask used to extract the file type code. */
73
+ /** Bit mask used to extract the file type from mode. */
71
74
  export const S_IFMT = 0xf000;
72
- /** Constant for fs.Stats mode property for determining a file's type. File type constant for a regular file. */
73
- export const S_IFREG = 0o100000;
74
- /** Constant for fs.Stats mode property for determining a file's type. File type constant for a directory. */
75
- export const S_IFDIR = 0o40000;
76
- /** Constant for fs.Stats mode property for determining a file's type. File type constant for a character-oriented device file. */
77
- export const S_IFCHR = 0o20000;
78
- /** Constant for fs.Stats mode property for determining a file's type. File type constant for a block-oriented device file. */
79
- export const S_IFBLK = 0o60000;
80
- /** Constant for fs.Stats mode property for determining a file's type. File type constant for a FIFO/pipe. */
81
- export const S_IFIFO = 0o10000;
82
- /** Constant for fs.Stats mode property for determining a file's type. File type constant for a symbolic link. */
83
- export const S_IFLNK = 0o120000;
84
- /** Constant for fs.Stats mode property for determining a file's type. File type constant for a socket. */
85
- export const S_IFSOCK = 0o140000;
75
+ /** File type constant for a socket. */
76
+ export const S_IFSOCK = 0xc000;
77
+ /** File type constant for a symbolic link. */
78
+ export const S_IFLNK = 0xa000;
79
+ /** File type constant for a regular file. */
80
+ export const S_IFREG = 0x8000;
81
+ /** File type constant for a block-oriented device file. */
82
+ export const S_IFBLK = 0x6000;
83
+ /** File type constant for a directory. */
84
+ export const S_IFDIR = 0x4000;
85
+ /** File type constant for a character-oriented device file. */
86
+ export const S_IFCHR = 0x2000;
87
+ /** File type constant for a FIFO/pipe. */
88
+ export const S_IFIFO = 0x1000;
89
+ /** Set user id */
90
+ export const S_ISUID = 0o4000;
91
+ /** Set group id */
92
+ export const S_ISGID = 0o2000;
93
+ /** Sticky bit */
94
+ export const S_ISVTX = 0o1000;
86
95
  // File Mode Constants
87
- /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable, writable and executable by owner. */
96
+ /** File mode indicating readable, writable and executable by owner. */
88
97
  export const S_IRWXU = 0o700;
89
- /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable by owner. */
98
+ /** File mode indicating readable by owner. */
90
99
  export const S_IRUSR = 0o400;
91
- /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating writable by owner. */
100
+ /** File mode indicating writable by owner. */
92
101
  export const S_IWUSR = 0o200;
93
- /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating executable by owner. */
102
+ /** File mode indicating executable by owner. */
94
103
  export const S_IXUSR = 0o100;
95
- /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable, writable and executable by group. */
104
+ /** File mode indicating readable, writable and executable by group. */
96
105
  export const S_IRWXG = 0o70;
97
- /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable by group. */
106
+ /** File mode indicating readable by group. */
98
107
  export const S_IRGRP = 0o40;
99
- /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating writable by group. */
108
+ /** File mode indicating writable by group. */
100
109
  export const S_IWGRP = 0o20;
101
- /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating executable by group. */
110
+ /** File mode indicating executable by group. */
102
111
  export const S_IXGRP = 0o10;
103
- /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable, writable and executable by others. */
112
+ /** File mode indicating readable, writable and executable by others. */
104
113
  export const S_IRWXO = 7;
105
- /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable by others. */
114
+ /** File mode indicating readable by others. */
106
115
  export const S_IROTH = 4;
107
- /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating writable by others. */
116
+ /** File mode indicating writable by others. */
108
117
  export const S_IWOTH = 2;
109
- /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating executable by others. */
118
+ /** File mode indicating executable by others. */
110
119
  export const S_IXOTH = 1;
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
2
  import type { Dirent as _Dirent, Dir as _Dir } from 'fs';
3
- import { NoArgCallback, TwoArgCallback } from '../filesystem.js';
4
- import { Stats } from '../stats.js';
3
+ import type { NoArgCallback, TwoArgCallback } from '../filesystem.js';
4
+ import type { Stats } from '../stats.js';
5
5
  export declare class Dirent implements _Dirent {
6
6
  name: string;
7
7
  protected stats: Stats;
@@ -5,7 +5,7 @@ import type * as Node from 'node:fs';
5
5
  export * as constants from './constants.js';
6
6
  import type { PathLike, BufferToUint8Array } from './shared.js';
7
7
  import { FileContents } from '../filesystem.js';
8
- import { BigIntStats, Stats } from '../stats.js';
8
+ import { BigIntStats, type Stats } from '../stats.js';
9
9
  import { Dirent } from './dir.js';
10
10
  export declare class FileHandle implements BufferToUint8Array<Node.promises.FileHandle> {
11
11
  /**
@@ -211,12 +211,12 @@ export async function exists(_path) {
211
211
  }
212
212
  export async function stat(path, options) {
213
213
  const stats = await doOp('stat', true, path, cred);
214
- return options?.bigint ? BigIntStats.clone(stats) : stats;
214
+ return options?.bigint ? new BigIntStats(stats) : stats;
215
215
  }
216
216
  stat;
217
217
  export async function lstat(path, options) {
218
218
  const stats = await doOp('stat', false, path, cred);
219
- return options?.bigint ? BigIntStats.clone(stats) : stats;
219
+ return options?.bigint ? new BigIntStats(stats) : stats;
220
220
  }
221
221
  lstat;
222
222
  // FILE-ONLY METHODS
@@ -248,7 +248,7 @@ unlink;
248
248
  * @internal
249
249
  */
250
250
  async function _open(_path, _flag, _mode = 0o644, resolveSymlinks) {
251
- const path = normalizePath(_path), mode = normalizeMode(_mode, 0o644), flag = FileFlag.FromString(_flag);
251
+ const path = normalizePath(_path), mode = normalizeMode(_mode, 0o644), flag = FileFlag.Get(_flag);
252
252
  try {
253
253
  switch (flag.pathExistsAction()) {
254
254
  case ActionType.THROW:
@@ -327,7 +327,7 @@ async function _readFile(fname, flag, resolveSymlinks) {
327
327
  }
328
328
  export async function readFile(filename, _options) {
329
329
  const options = normalizeOptions(_options, null, 'r', null);
330
- const flag = FileFlag.FromString(options.flag);
330
+ const flag = FileFlag.Get(options.flag);
331
331
  if (!flag.isReadable()) {
332
332
  throw new ApiError(ErrorCode.EINVAL, 'Flag passed must allow for reading.');
333
333
  }
@@ -363,7 +363,7 @@ async function _writeFile(fname, data, flag, mode, resolveSymlinks) {
363
363
  */
364
364
  export async function writeFile(filename, data, _options) {
365
365
  const options = normalizeOptions(_options, 'utf8', 'w', 0o644);
366
- const flag = FileFlag.FromString(options.flag);
366
+ const flag = FileFlag.Get(options.flag);
367
367
  if (!flag.isWriteable()) {
368
368
  throw new ApiError(ErrorCode.EINVAL, 'Flag passed must allow for writing.');
369
369
  }
@@ -399,7 +399,7 @@ async function _appendFile(fname, data, flag, mode, resolveSymlinks) {
399
399
  */
400
400
  export async function appendFile(filename, data, _options) {
401
401
  const options = normalizeOptions(_options, 'utf8', 'a', 0o644);
402
- const flag = FileFlag.FromString(options.flag);
402
+ const flag = FileFlag.Get(options.flag);
403
403
  if (!flag.isAppendable()) {
404
404
  throw new ApiError(ErrorCode.EINVAL, 'Flag passed to appendFile must allow for appending.');
405
405
  }
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
2
  /// <reference types="node" resolution-mode="require"/>
3
3
  import { FileContents } from '../filesystem.js';
4
- import { BigIntStats, Stats } from '../stats.js';
4
+ import { BigIntStats, type Stats } from '../stats.js';
5
5
  import type { symlink, ReadSyncOptions, BaseEncodingOptions, BufferEncodingOption } from 'fs';
6
6
  import type * as Node from 'fs';
7
7
  import { PathLike } from './shared.js';
@@ -60,12 +60,12 @@ export function existsSync(path) {
60
60
  existsSync;
61
61
  export function statSync(path, options) {
62
62
  const stats = doOp('statSync', true, path, cred);
63
- return options?.bigint ? BigIntStats.clone(stats) : stats;
63
+ return options?.bigint ? new BigIntStats(stats) : stats;
64
64
  }
65
65
  statSync;
66
66
  export function lstatSync(path, options) {
67
67
  const stats = doOp('statSync', false, path, cred);
68
- return options?.bigint ? BigIntStats.clone(stats) : stats;
68
+ return options?.bigint ? new BigIntStats(stats) : stats;
69
69
  }
70
70
  lstatSync;
71
71
  /**
@@ -92,7 +92,7 @@ export function unlinkSync(path) {
92
92
  }
93
93
  unlinkSync;
94
94
  function _openSync(_path, _flag, _mode, resolveSymlinks) {
95
- const path = normalizePath(_path), mode = normalizeMode(_mode, 0o644), flag = FileFlag.FromString(_flag);
95
+ const path = normalizePath(_path), mode = normalizeMode(_mode, 0o644), flag = FileFlag.Get(_flag);
96
96
  // Check if the path exists, and is a file.
97
97
  let stats;
98
98
  try {
@@ -176,7 +176,7 @@ function _readFileSync(fname, flag, resolveSymlinks) {
176
176
  }
177
177
  export function readFileSync(filename, arg2 = {}) {
178
178
  const options = normalizeOptions(arg2, null, 'r', 0o644);
179
- const flag = FileFlag.FromString(options.flag);
179
+ const flag = FileFlag.Get(options.flag);
180
180
  if (!flag.isReadable()) {
181
181
  throw new ApiError(ErrorCode.EINVAL, 'Flag passed to readFile must allow for reading.');
182
182
  }
@@ -201,7 +201,7 @@ function _writeFileSync(fname, data, flag, mode, resolveSymlinks) {
201
201
  }
202
202
  export function writeFileSync(filename, data, _options) {
203
203
  const options = normalizeOptions(_options, 'utf8', 'w', 0o644);
204
- const flag = FileFlag.FromString(options.flag);
204
+ const flag = FileFlag.Get(options.flag);
205
205
  if (!flag.isWriteable()) {
206
206
  throw new ApiError(ErrorCode.EINVAL, 'Flag passed to writeFile must allow for writing.');
207
207
  }
@@ -230,7 +230,7 @@ function _appendFileSync(fname, data, flag, mode, resolveSymlinks) {
230
230
  }
231
231
  export function appendFileSync(filename, data, arg3) {
232
232
  const options = normalizeOptions(arg3, 'utf8', 'a', 0o644);
233
- const flag = FileFlag.FromString(options.flag);
233
+ const flag = FileFlag.Get(options.flag);
234
234
  if (!flag.isAppendable()) {
235
235
  throw new ApiError(ErrorCode.EINVAL, 'Flag passed to appendFile must allow for appending.');
236
236
  }
@@ -243,7 +243,7 @@ export function appendFileSync(filename, data, arg3) {
243
243
  appendFileSync;
244
244
  export function fstatSync(fd, options) {
245
245
  const stats = fd2file(fd).statSync();
246
- return options?.bigint ? BigIntStats.clone(stats) : stats;
246
+ return options?.bigint ? new BigIntStats(stats) : stats;
247
247
  }
248
248
  fstatSync;
249
249
  /**
package/dist/file.d.ts CHANGED
@@ -17,6 +17,9 @@ declare global {
17
17
  }): ArrayBuffer;
18
18
  }
19
19
  }
20
+ /**
21
+ * @hidden
22
+ */
20
23
  export declare enum ActionType {
21
24
  NOP = 0,
22
25
  THROW = 1,
@@ -42,28 +45,39 @@ export declare enum ActionType {
42
45
  * Exclusive mode ensures that the file path is newly created.
43
46
  */
44
47
  export declare class FileFlag {
45
- private static flagCache;
46
- private static validFlagStrs;
48
+ /**
49
+ * Contains cached FileMode instances.
50
+ */
51
+ protected static cache: Map<string | number, FileFlag>;
52
+ /**
53
+ * Array of valid mode strings.
54
+ */
55
+ protected static validStrings: string[];
47
56
  /**
48
57
  * Get an object representing the given file flag.
49
58
  * @param flag The string or number representing the flag
50
59
  * @return The FileFlag object representing the flag
51
60
  * @throw when the flag string is invalid
52
61
  */
53
- static FromString(flag: string | number): FileFlag;
54
- private flagStr;
62
+ static Get(flag: string | number): FileFlag;
63
+ protected _flag: string;
55
64
  /**
56
- * This should never be called directly.
57
65
  * @param flag The string or number representing the flag
58
66
  * @throw when the flag is invalid
59
67
  */
60
- constructor(flag: string | number);
68
+ protected constructor(flag: string | number);
61
69
  /**
62
70
  * @param flag The number representing the flag
63
- * @return The string representing the flag
64
- * @throw when the flag number is invalid
71
+ * @returns The string representing the flag
72
+ * @throws when the flag number is invalid
73
+ */
74
+ static StringOf(flag: number): string;
75
+ /**
76
+ * @param flag The string representing the flag
77
+ * @returns The number representing the flag
78
+ * @throws when the flag string is invalid
65
79
  */
66
- static NumberToString(flag: number): string;
80
+ static NumberOf(flag: string): number;
67
81
  /**
68
82
  * Get the underlying flag string for this flag.
69
83
  */
@@ -258,11 +272,11 @@ export declare abstract class File {
258
272
  * extend this class and implement those two methods.
259
273
  * @todo 'close' lever that disables functionality once closed.
260
274
  */
261
- export declare abstract class PreloadFile<T extends FileSystem> extends File {
275
+ export declare abstract class PreloadFile<FS extends FileSystem> extends File {
262
276
  /**
263
277
  * The file system that created the file.
264
278
  */
265
- protected fs: T;
279
+ protected fs: FS;
266
280
  /**
267
281
  * Path to the file
268
282
  */
@@ -288,7 +302,7 @@ export declare abstract class PreloadFile<T extends FileSystem> extends File {
288
302
  /**
289
303
  * The file system that created the file.
290
304
  */
291
- fs: T,
305
+ fs: FS,
292
306
  /**
293
307
  * Path to the file
294
308
  */