@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.
- package/dist/FileIndex.d.ts +6 -0
- package/dist/FileIndex.js +3 -3
- package/dist/backends/AsyncMirror.d.ts +3 -5
- package/dist/backends/AsyncMirror.js +7 -6
- package/dist/backends/AsyncStore.d.ts +9 -4
- package/dist/backends/AsyncStore.js +7 -2
- package/dist/backends/Locked.d.ts +8 -8
- package/dist/backends/Locked.js +2 -1
- package/dist/backends/Overlay.d.ts +13 -1
- package/dist/backends/Overlay.js +16 -16
- package/dist/backends/SyncStore.d.ts +8 -5
- package/dist/backends/SyncStore.js +9 -5
- package/dist/backends/backend.js +8 -8
- package/dist/browser.min.js +4 -5
- package/dist/browser.min.js.map +4 -4
- package/dist/cred.d.ts +1 -1
- package/dist/cred.js +1 -1
- package/dist/emulation/callbacks.d.ts +1 -1
- package/dist/emulation/callbacks.js +1 -1
- package/dist/emulation/constants.d.ts +48 -42
- package/dist/emulation/constants.js +68 -59
- package/dist/emulation/dir.d.ts +2 -2
- package/dist/emulation/promises.d.ts +1 -1
- package/dist/emulation/promises.js +6 -6
- package/dist/emulation/sync.d.ts +1 -1
- package/dist/emulation/sync.js +7 -7
- package/dist/file.d.ts +26 -12
- package/dist/file.js +68 -29
- package/dist/filesystem.d.ts +3 -3
- package/dist/index.d.ts +6 -3
- package/dist/index.js +4 -5
- package/dist/inode.d.ts +21 -15
- package/dist/inode.js +52 -40
- package/dist/mutex.d.ts +1 -2
- package/dist/mutex.js +1 -1
- package/dist/stats.d.ts +70 -18
- package/dist/stats.js +12 -18
- package/dist/utils.d.ts +3 -8
- package/dist/utils.js +60 -39
- package/package.json +5 -1
- package/readme.md +14 -10
- package/scripts/make-index.js +100 -0
- package/dist/backends/index.d.ts +0 -10
- package/dist/backends/index.js +0 -12
package/dist/cred.d.ts
CHANGED
package/dist/cred.js
CHANGED
|
@@ -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
|
|
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
|
-
/**
|
|
1
|
+
/** File is visible to the calling process. */
|
|
2
2
|
export declare const F_OK = 0;
|
|
3
|
-
/**
|
|
3
|
+
/** File can be read by the calling process. */
|
|
4
4
|
export declare const R_OK = 4;
|
|
5
|
-
/**
|
|
5
|
+
/** File can be written by the calling process. */
|
|
6
6
|
export declare const W_OK = 2;
|
|
7
|
-
/**
|
|
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
|
-
/**
|
|
21
|
+
/** Flag indicating to open a file for read-only access. */
|
|
22
22
|
export declare const O_RDONLY = 0;
|
|
23
|
-
/**
|
|
23
|
+
/** Flag indicating to open a file for write-only access. */
|
|
24
24
|
export declare const O_WRONLY = 1;
|
|
25
|
-
/**
|
|
25
|
+
/** Flag indicating to open a file for read-write access. */
|
|
26
26
|
export declare const O_RDWR = 2;
|
|
27
|
-
/**
|
|
27
|
+
/** Flag indicating to create the file if it does not already exist. */
|
|
28
28
|
export declare const O_CREAT = 64;
|
|
29
|
-
/**
|
|
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
|
-
*
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
39
|
+
/** Flag indicating that data will be appended to the end of the file. */
|
|
40
40
|
export declare const O_APPEND = 1024;
|
|
41
|
-
/**
|
|
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
|
-
/**
|
|
50
|
+
/** Flag indicating that the open should fail if the path is a symbolic link. */
|
|
51
51
|
export declare const O_NOFOLLOW = 131072;
|
|
52
|
-
/**
|
|
52
|
+
/** Flag indicating that the file is opened for synchronous I/O. */
|
|
53
53
|
export declare const O_SYNC = 1052672;
|
|
54
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
60
|
+
/** Flag indicating to open the file in nonblocking mode when possible. */
|
|
61
61
|
export declare const O_NONBLOCK = 2048;
|
|
62
|
-
/**
|
|
62
|
+
/** Bit mask used to extract the file type from mode. */
|
|
63
63
|
export declare const S_IFMT = 61440;
|
|
64
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
74
|
+
/** File type constant for a character-oriented device file. */
|
|
69
75
|
export declare const S_IFCHR = 8192;
|
|
70
|
-
/**
|
|
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
|
-
/**
|
|
75
|
-
export declare const
|
|
76
|
-
/**
|
|
77
|
-
export declare const
|
|
78
|
-
/**
|
|
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
|
-
/**
|
|
86
|
+
/** File mode indicating readable by owner. */
|
|
81
87
|
export declare const S_IRUSR = 256;
|
|
82
|
-
/**
|
|
88
|
+
/** File mode indicating writable by owner. */
|
|
83
89
|
export declare const S_IWUSR = 128;
|
|
84
|
-
/**
|
|
90
|
+
/** File mode indicating executable by owner. */
|
|
85
91
|
export declare const S_IXUSR = 64;
|
|
86
|
-
/**
|
|
92
|
+
/** File mode indicating readable, writable and executable by group. */
|
|
87
93
|
export declare const S_IRWXG = 56;
|
|
88
|
-
/**
|
|
94
|
+
/** File mode indicating readable by group. */
|
|
89
95
|
export declare const S_IRGRP = 32;
|
|
90
|
-
/**
|
|
96
|
+
/** File mode indicating writable by group. */
|
|
91
97
|
export declare const S_IWGRP = 16;
|
|
92
|
-
/**
|
|
98
|
+
/** File mode indicating executable by group. */
|
|
93
99
|
export declare const S_IXGRP = 8;
|
|
94
|
-
/**
|
|
100
|
+
/** File mode indicating readable, writable and executable by others. */
|
|
95
101
|
export declare const S_IRWXO = 7;
|
|
96
|
-
/**
|
|
102
|
+
/** File mode indicating readable by others. */
|
|
97
103
|
export declare const S_IROTH = 4;
|
|
98
|
-
/**
|
|
104
|
+
/** File mode indicating writable by others. */
|
|
99
105
|
export declare const S_IWOTH = 2;
|
|
100
|
-
/**
|
|
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
|
-
/**
|
|
9
|
+
/** File is visible to the calling process. */
|
|
7
10
|
export const F_OK = 0;
|
|
8
|
-
/**
|
|
11
|
+
/** File can be read by the calling process. */
|
|
9
12
|
export const R_OK = 4;
|
|
10
|
-
/**
|
|
13
|
+
/** File can be written by the calling process. */
|
|
11
14
|
export const W_OK = 2;
|
|
12
|
-
/**
|
|
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
|
-
/**
|
|
31
|
+
/** Flag indicating to open a file for read-only access. */
|
|
29
32
|
export const O_RDONLY = 0;
|
|
30
|
-
/**
|
|
33
|
+
/** Flag indicating to open a file for write-only access. */
|
|
31
34
|
export const O_WRONLY = 1;
|
|
32
|
-
/**
|
|
35
|
+
/** Flag indicating to open a file for read-write access. */
|
|
33
36
|
export const O_RDWR = 2;
|
|
34
|
-
/**
|
|
35
|
-
export const O_CREAT =
|
|
36
|
-
/**
|
|
37
|
-
export const O_EXCL =
|
|
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
|
-
*
|
|
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 =
|
|
44
|
-
/**
|
|
45
|
-
export const O_TRUNC =
|
|
46
|
-
/**
|
|
47
|
-
export const O_APPEND =
|
|
48
|
-
/**
|
|
49
|
-
export const O_DIRECTORY =
|
|
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 =
|
|
57
|
-
/**
|
|
58
|
-
export const O_NOFOLLOW =
|
|
59
|
-
/**
|
|
60
|
-
export const O_SYNC =
|
|
61
|
-
/**
|
|
62
|
-
export const O_DSYNC =
|
|
63
|
-
/**
|
|
64
|
-
export const O_SYMLINK =
|
|
65
|
-
/**
|
|
66
|
-
export const O_DIRECT =
|
|
67
|
-
/**
|
|
68
|
-
export const O_NONBLOCK =
|
|
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
|
-
/**
|
|
73
|
+
/** Bit mask used to extract the file type from mode. */
|
|
71
74
|
export const S_IFMT = 0xf000;
|
|
72
|
-
/**
|
|
73
|
-
export const
|
|
74
|
-
/**
|
|
75
|
-
export const
|
|
76
|
-
/**
|
|
77
|
-
export const
|
|
78
|
-
/**
|
|
79
|
-
export const S_IFBLK =
|
|
80
|
-
/**
|
|
81
|
-
export const
|
|
82
|
-
/**
|
|
83
|
-
export const
|
|
84
|
-
/**
|
|
85
|
-
export const
|
|
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
|
-
/**
|
|
96
|
+
/** File mode indicating readable, writable and executable by owner. */
|
|
88
97
|
export const S_IRWXU = 0o700;
|
|
89
|
-
/**
|
|
98
|
+
/** File mode indicating readable by owner. */
|
|
90
99
|
export const S_IRUSR = 0o400;
|
|
91
|
-
/**
|
|
100
|
+
/** File mode indicating writable by owner. */
|
|
92
101
|
export const S_IWUSR = 0o200;
|
|
93
|
-
/**
|
|
102
|
+
/** File mode indicating executable by owner. */
|
|
94
103
|
export const S_IXUSR = 0o100;
|
|
95
|
-
/**
|
|
104
|
+
/** File mode indicating readable, writable and executable by group. */
|
|
96
105
|
export const S_IRWXG = 0o70;
|
|
97
|
-
/**
|
|
106
|
+
/** File mode indicating readable by group. */
|
|
98
107
|
export const S_IRGRP = 0o40;
|
|
99
|
-
/**
|
|
108
|
+
/** File mode indicating writable by group. */
|
|
100
109
|
export const S_IWGRP = 0o20;
|
|
101
|
-
/**
|
|
110
|
+
/** File mode indicating executable by group. */
|
|
102
111
|
export const S_IXGRP = 0o10;
|
|
103
|
-
/**
|
|
112
|
+
/** File mode indicating readable, writable and executable by others. */
|
|
104
113
|
export const S_IRWXO = 7;
|
|
105
|
-
/**
|
|
114
|
+
/** File mode indicating readable by others. */
|
|
106
115
|
export const S_IROTH = 4;
|
|
107
|
-
/**
|
|
116
|
+
/** File mode indicating writable by others. */
|
|
108
117
|
export const S_IWOTH = 2;
|
|
109
|
-
/**
|
|
118
|
+
/** File mode indicating executable by others. */
|
|
110
119
|
export const S_IXOTH = 1;
|
package/dist/emulation/dir.d.ts
CHANGED
|
@@ -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
|
|
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
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
}
|
package/dist/emulation/sync.d.ts
CHANGED
|
@@ -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';
|
package/dist/emulation/sync.js
CHANGED
|
@@ -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
|
|
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
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
|
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
|
-
|
|
46
|
-
|
|
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
|
|
54
|
-
|
|
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
|
-
* @
|
|
64
|
-
* @
|
|
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
|
|
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<
|
|
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:
|
|
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:
|
|
305
|
+
fs: FS,
|
|
292
306
|
/**
|
|
293
307
|
* Path to the file
|
|
294
308
|
*/
|