@zenfs/core 2.4.1 → 2.4.2

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 (99) hide show
  1. package/COPYING.md +18 -0
  2. package/{readme.md → README.md} +16 -74
  3. package/dist/backends/fetch.js +1 -1
  4. package/dist/backends/memory.js +1 -1
  5. package/dist/backends/passthrough.d.ts +1 -2
  6. package/dist/backends/single_buffer.js +1 -1
  7. package/dist/backends/store/fs.js +4 -4
  8. package/dist/config.js +15 -15
  9. package/dist/context.js +3 -2
  10. package/dist/index.d.ts +9 -3
  11. package/dist/index.js +9 -4
  12. package/dist/internal/contexts.d.ts +5 -4
  13. package/dist/internal/devices.js +1 -1
  14. package/dist/internal/error.d.ts +11 -2
  15. package/dist/internal/error.js +38 -2
  16. package/dist/internal/file_index.js +1 -1
  17. package/dist/internal/index.d.ts +1 -0
  18. package/dist/internal/index.js +2 -1
  19. package/dist/internal/index_fs.js +1 -1
  20. package/dist/internal/inode.d.ts +51 -2
  21. package/dist/internal/inode.js +18 -2
  22. package/dist/mixins/shared.js +1 -1
  23. package/dist/node/async.d.ts +278 -0
  24. package/dist/node/async.js +518 -0
  25. package/dist/node/compat.d.ts +4 -0
  26. package/dist/node/compat.js +6 -0
  27. package/dist/node/dir.d.ts +78 -0
  28. package/dist/node/dir.js +150 -0
  29. package/dist/node/index.d.ts +8 -0
  30. package/dist/node/index.js +8 -0
  31. package/dist/{vfs → node}/promises.d.ts +10 -66
  32. package/dist/{vfs → node}/promises.js +141 -478
  33. package/dist/{vfs → node}/stats.d.ts +0 -4
  34. package/dist/{vfs → node}/stats.js +1 -16
  35. package/dist/{vfs → node}/streams.js +2 -2
  36. package/dist/node/sync.d.ts +252 -0
  37. package/dist/node/sync.js +682 -0
  38. package/dist/node/types.d.ts +21 -0
  39. package/dist/utils.d.ts +1 -7
  40. package/dist/utils.js +0 -6
  41. package/dist/vfs/acl.js +1 -1
  42. package/dist/vfs/async.d.ts +22 -278
  43. package/dist/vfs/async.js +212 -501
  44. package/dist/vfs/dir.d.ts +5 -82
  45. package/dist/vfs/dir.js +5 -233
  46. package/dist/vfs/file.d.ts +52 -13
  47. package/dist/vfs/file.js +167 -25
  48. package/dist/vfs/flags.js +1 -1
  49. package/dist/vfs/index.d.ts +2 -5
  50. package/dist/vfs/index.js +2 -5
  51. package/dist/vfs/shared.d.ts +25 -1
  52. package/dist/vfs/shared.js +6 -4
  53. package/dist/vfs/sync.d.ts +17 -245
  54. package/dist/vfs/sync.js +129 -773
  55. package/dist/vfs/watchers.d.ts +1 -1
  56. package/dist/vfs/watchers.js +2 -2
  57. package/dist/vfs/xattr.js +1 -1
  58. package/eslint.shared.js +1 -0
  59. package/package.json +7 -5
  60. package/scripts/make-index.js +5 -29
  61. package/scripts/test.js +59 -51
  62. package/tests/backend/fetch.test.ts +2 -2
  63. package/tests/backend/port.test.ts +2 -3
  64. package/tests/backend/single-buffer.test.ts +1 -1
  65. package/tests/common/casefold.test.ts +1 -1
  66. package/tests/common/context.test.ts +11 -4
  67. package/tests/common/devices.test.ts +3 -3
  68. package/tests/common/handle.test.ts +4 -3
  69. package/tests/common/inode.test.ts +2 -2
  70. package/tests/common/mounts.test.ts +1 -3
  71. package/tests/common/mutex.test.ts +1 -3
  72. package/tests/common/path.test.ts +2 -2
  73. package/tests/common/readline.test.ts +1 -1
  74. package/tests/common.ts +5 -4
  75. package/tests/fetch/fetch.ts +1 -1
  76. package/tests/fs/dir.test.ts +3 -43
  77. package/tests/fs/directory.test.ts +4 -4
  78. package/tests/fs/errors.test.ts +2 -2
  79. package/tests/fs/links.test.ts +1 -1
  80. package/tests/fs/permissions.test.ts +3 -3
  81. package/tests/fs/read.test.ts +1 -1
  82. package/tests/fs/scaling.test.ts +1 -1
  83. package/tests/fs/stat.test.ts +1 -2
  84. package/tests/fs/times.test.ts +1 -1
  85. package/tests/fs/watch.test.ts +3 -2
  86. package/tests/setup/context.ts +1 -2
  87. package/tests/setup/cow.ts +1 -1
  88. package/tests/setup/index.ts +2 -2
  89. package/tests/setup/port.ts +1 -1
  90. package/tests/setup/single-buffer.ts +1 -1
  91. package/tests/setup.ts +4 -3
  92. package/dist/vfs/types.d.ts +0 -24
  93. package/tests/assignment.ts +0 -21
  94. /package/dist/{vfs/constants.d.ts → constants.d.ts} +0 -0
  95. /package/dist/{vfs/constants.js → constants.js} +0 -0
  96. /package/dist/{readline.d.ts → node/readline.d.ts} +0 -0
  97. /package/dist/{readline.js → node/readline.js} +0 -0
  98. /package/dist/{vfs → node}/streams.d.ts +0 -0
  99. /package/dist/{vfs → node}/types.js +0 -0
@@ -1,251 +1,23 @@
1
- import type * as fs from 'node:fs';
1
+ import type { PathLike } from 'node:fs';
2
2
  import type { V_Context } from '../context.js';
3
- import type { FileContents, ReaddirOptions } from './types.js';
4
- import { Buffer } from 'buffer';
5
- import { Dir, Dirent } from './dir.js';
6
- import { BigIntStats, Stats } from './stats.js';
7
- export declare function renameSync(this: V_Context, oldPath: fs.PathLike, newPath: fs.PathLike): void;
3
+ import type { MkdirOptions, OpenOptions, ReaddirOptions, ResolvedPath } from './shared.js';
4
+ import { type ExceptionExtra } from 'kerium';
5
+ import { Dirent } from './dir.js';
6
+ import { Handle } from './file.js';
8
7
  /**
9
- * Test whether or not `path` exists by checking with the file system.
8
+ * Resolves the mount and real path for a path.
9
+ * Additionally, any stats fetched will be returned for de-duplication
10
+ * @category VFS
11
+ * @internal @hidden
10
12
  */
11
- export declare function existsSync(this: V_Context, path: fs.PathLike): boolean;
12
- export declare function statSync(this: V_Context, path: fs.PathLike, options?: {
13
- bigint?: boolean;
14
- }): Stats;
15
- export declare function statSync(this: V_Context, path: fs.PathLike, options: {
16
- bigint: true;
17
- }): BigIntStats;
13
+ export declare function resolve($: V_Context, path: string, preserveSymlinks?: boolean, extra?: ExceptionExtra): ResolvedPath;
18
14
  /**
19
- * Synchronous `lstat`.
20
- * `lstat()` is identical to `stat()`, except that if path is a symbolic link,
21
- * then the link itself is stat-ed, not the file that it refers to.
22
- */
23
- export declare function lstatSync(this: V_Context, path: fs.PathLike, options?: {
24
- bigint?: boolean;
25
- }): Stats;
26
- export declare function lstatSync(this: V_Context, path: fs.PathLike, options: {
27
- bigint: true;
28
- }): BigIntStats;
29
- export declare function truncateSync(this: V_Context, path: fs.PathLike, len?: number | null): void;
30
- export declare function unlinkSync(this: V_Context, path: fs.PathLike): void;
31
- /**
32
- * Synchronous file open.
33
- * @see https://nodejs.org/api/fs.html#fsopensyncpath-flags-mode
34
- * @param flag {@link https://nodejs.org/api/fs.html#file-system-flags}
35
- */
36
- export declare function openSync(this: V_Context, path: fs.PathLike, flag: fs.OpenMode, mode?: fs.Mode | null): number;
37
- /**
38
- * Opens a file or symlink
15
+ * @category VFS
39
16
  * @internal
40
17
  */
41
- export declare function lopenSync(this: V_Context, path: fs.PathLike, flag: string, mode?: fs.Mode | null): number;
42
- /**
43
- * Synchronously reads the entire contents of a file.
44
- * @option encoding The string encoding for the file contents. Defaults to `null`.
45
- * @option flag Defaults to `'r'`.
46
- * @returns file contents
47
- */
48
- export declare function readFileSync(this: V_Context, path: fs.PathOrFileDescriptor, options?: {
49
- flag?: string;
50
- } | null): NonSharedBuffer;
51
- export declare function readFileSync(this: V_Context, path: fs.PathOrFileDescriptor, options?: (fs.EncodingOption & {
52
- flag?: string;
53
- }) | BufferEncoding | null): string;
54
- /**
55
- * Synchronously writes data to a file, replacing the file if it already exists.
56
- *
57
- * The encoding option is ignored if data is a buffer.
58
- * @option encoding Defaults to `'utf8'`.
59
- * @option mode Defaults to `0644`.
60
- * @option flag Defaults to `'w'`.
61
- */
62
- export declare function writeFileSync(this: V_Context, path: fs.PathOrFileDescriptor, data: FileContents, options?: fs.WriteFileOptions): void;
63
- export declare function writeFileSync(this: V_Context, path: fs.PathOrFileDescriptor, data: FileContents, encoding?: BufferEncoding): void;
64
- /**
65
- * Asynchronously append data to a file, creating the file if it not yet exists.
66
- * @option encoding Defaults to `'utf8'`.
67
- * @option mode Defaults to `0644`.
68
- * @option flag Defaults to `'a+'`.
69
- */
70
- export declare function appendFileSync(this: V_Context, filename: fs.PathOrFileDescriptor, data: FileContents, _options?: fs.WriteFileOptions): void;
71
- /**
72
- * Synchronous `fstat`.
73
- * `fstat()` is identical to `stat()`, except that the file to be stat-ed is
74
- * specified by the file descriptor `fd`.
75
- */
76
- export declare function fstatSync(this: V_Context, fd: number, options?: {
77
- bigint?: boolean;
78
- }): Stats;
79
- export declare function fstatSync(this: V_Context, fd: number, options: {
80
- bigint: true;
81
- }): BigIntStats;
82
- export declare function closeSync(this: V_Context, fd: number): void;
83
- export declare function ftruncateSync(this: V_Context, fd: number, len?: number | null): void;
84
- export declare function fsyncSync(this: V_Context, fd: number): void;
85
- export declare function fdatasyncSync(this: V_Context, fd: number): void;
86
- /**
87
- * Write buffer to the file specified by `fd`.
88
- * @param data Uint8Array containing the data to write to the file.
89
- * @param offset Offset in the buffer to start reading data from.
90
- * @param length The amount of bytes to write to the file.
91
- * @param position Offset from the beginning of the file where this data should be written.
92
- * If position is null, the data will be written at the current position.
93
- */
94
- export declare function writeSync(this: V_Context, fd: number, data: ArrayBufferView, offset?: number | null, length?: number | null, position?: number | null): number;
95
- export declare function writeSync(this: V_Context, fd: number, data: string, position?: number | null, encoding?: BufferEncoding | null): number;
96
- export declare function readSync(this: V_Context, fd: number, buffer: ArrayBufferView, options?: fs.ReadSyncOptions): number;
97
- export declare function readSync(this: V_Context, fd: number, buffer: ArrayBufferView, offset: number, length: number, position?: fs.ReadPosition | null): number;
98
- export declare function fchownSync(this: V_Context, fd: number, uid: number, gid: number): void;
99
- export declare function fchmodSync(this: V_Context, fd: number, mode: number | string): void;
100
- /**
101
- * Change the file timestamps of a file referenced by the supplied file descriptor.
102
- */
103
- export declare function futimesSync(this: V_Context, fd: number, atime: string | number | Date, mtime: string | number | Date): void;
104
- export declare function rmdirSync(this: V_Context, path: fs.PathLike): void;
105
- /**
106
- * Synchronous `mkdir`. Mode defaults to `o777`.
107
- */
108
- export declare function mkdirSync(this: V_Context, path: fs.PathLike, options: fs.MakeDirectoryOptions & {
109
- recursive: true;
110
- }): string | undefined;
111
- export declare function mkdirSync(this: V_Context, path: fs.PathLike, options?: fs.Mode | (fs.MakeDirectoryOptions & {
112
- recursive?: false;
113
- }) | null): void;
114
- export declare function mkdirSync(this: V_Context, path: fs.PathLike, options?: fs.Mode | fs.MakeDirectoryOptions | null): string | undefined;
115
- export declare function readdirSync(this: V_Context, path: fs.PathLike, options?: {
116
- encoding: BufferEncoding | null;
117
- withFileTypes?: false;
118
- recursive?: boolean;
119
- } | BufferEncoding | null): string[];
120
- export declare function readdirSync(this: V_Context, path: fs.PathLike, options: {
121
- encoding: 'buffer';
122
- withFileTypes?: false;
123
- recursive?: boolean;
124
- } | 'buffer'): Buffer[];
125
- export declare function readdirSync(this: V_Context, path: fs.PathLike, options?: (fs.ObjectEncodingOptions & {
126
- withFileTypes?: false;
127
- recursive?: boolean;
128
- }) | BufferEncoding | null): string[] | Buffer[];
129
- export declare function readdirSync(this: V_Context, path: fs.PathLike, options: fs.ObjectEncodingOptions & {
130
- withFileTypes: true;
131
- recursive?: boolean;
132
- }): Dirent[];
133
- export declare function readdirSync(this: V_Context, path: fs.PathLike, options: {
134
- encoding: 'buffer';
135
- withFileTypes: true;
136
- recursive?: boolean;
137
- }): Dirent<Buffer>[];
138
- export declare function readdirSync(this: V_Context, path: fs.PathLike, options?: ReaddirOptions): string[] | Dirent<any>[] | Buffer[];
139
- export declare function linkSync(this: V_Context, targetPath: fs.PathLike, linkPath: fs.PathLike): void;
140
- /**
141
- * Synchronous `symlink`.
142
- * @param target target path
143
- * @param path link path
144
- * @param type can be either `'dir'` or `'file'` (default is `'file'`)
145
- */
146
- export declare function symlinkSync(this: V_Context, target: fs.PathLike, path: fs.PathLike, type?: fs.symlink.Type | null): void;
147
- export declare function readlinkSync(this: V_Context, path: fs.PathLike, options?: fs.BufferEncodingOption): Buffer;
148
- export declare function readlinkSync(this: V_Context, path: fs.PathLike, options: fs.EncodingOption | BufferEncoding): string;
149
- export declare function readlinkSync(this: V_Context, path: fs.PathLike, options?: fs.EncodingOption | BufferEncoding | fs.BufferEncodingOption): Buffer | string;
150
- export declare function chownSync(this: V_Context, path: fs.PathLike, uid: number, gid: number): void;
151
- export declare function lchownSync(this: V_Context, path: fs.PathLike, uid: number, gid: number): void;
152
- export declare function chmodSync(this: V_Context, path: fs.PathLike, mode: fs.Mode): void;
153
- export declare function lchmodSync(this: V_Context, path: fs.PathLike, mode: number | string): void;
154
- /**
155
- * Change file timestamps of the file referenced by the supplied path.
156
- */
157
- export declare function utimesSync(this: V_Context, path: fs.PathLike, atime: string | number | Date, mtime: string | number | Date): void;
158
- /**
159
- * Change file timestamps of the file referenced by the supplied path.
160
- */
161
- export declare function lutimesSync(this: V_Context, path: fs.PathLike, atime: string | number | Date, mtime: string | number | Date): void;
162
- export declare function realpathSync(this: V_Context, path: fs.PathLike, options: fs.BufferEncodingOption): Buffer;
163
- export declare function realpathSync(this: V_Context, path: fs.PathLike, options?: fs.EncodingOption): string;
164
- export declare function accessSync(this: V_Context, path: fs.PathLike, mode?: number): void;
165
- /**
166
- * Synchronous `rm`. Removes files or directories (recursively).
167
- * @param path The path to the file or directory to remove.
168
- */
169
- export declare function rmSync(this: V_Context, path: fs.PathLike, options?: fs.RmOptions): void;
170
- /**
171
- * Synchronous `mkdtemp`. Creates a unique temporary directory.
172
- * @param prefix The directory prefix.
173
- * @param options The encoding (or an object including `encoding`).
174
- * @returns The path to the created temporary directory, encoded as a string or buffer.
175
- */
176
- export declare function mkdtempSync(this: V_Context, prefix: fs.PathLike, options: fs.BufferEncodingOption): Buffer;
177
- export declare function mkdtempSync(this: V_Context, prefix: fs.PathLike, options?: fs.EncodingOption): string;
178
- /**
179
- * Returns a disposable object whose `path` property holds the created directory path.
180
- * When the object is disposed, the directory and its contents will be removed if it still exists.
181
- * If the directory cannot be deleted, disposal will throw an error.
182
- * The object has a `remove()` method which will perform the same task.
183
- * @todo Add `satisfies` and maybe change return type once @types/node adds this.
184
- */
185
- export declare function mkdtempDisposableSync(this: V_Context, prefix: fs.PathLike, options?: fs.EncodingOption | fs.BufferEncodingOption): {
186
- path: string;
187
- remove(): void;
188
- [Symbol.dispose](): void;
189
- };
190
- /**
191
- * Synchronous `copyFile`. Copies a file.
192
- * @param flags Optional flags for the copy operation. Currently supports these flags:
193
- * - `fs.constants.COPYFILE_EXCL`: If the destination file already exists, the operation fails.
194
- */
195
- export declare function copyFileSync(this: V_Context, source: fs.PathLike, destination: fs.PathLike, flags?: number): void;
196
- /**
197
- * Synchronous `readv`. Reads from a file descriptor into multiple buffers.
198
- * @param fd The file descriptor.
199
- * @param buffers An array of Uint8Array buffers.
200
- * @param position The position in the file where to begin reading.
201
- * @returns The number of bytes read.
202
- */
203
- export declare function readvSync(this: V_Context, fd: number, buffers: readonly NodeJS.ArrayBufferView[], position?: number): number;
204
- /**
205
- * Synchronous `writev`. Writes from multiple buffers into a file descriptor.
206
- * @param fd The file descriptor.
207
- * @param buffers An array of Uint8Array buffers.
208
- * @param position The position in the file where to begin writing.
209
- * @returns The number of bytes written.
210
- */
211
- export declare function writevSync(this: V_Context, fd: number, buffers: readonly ArrayBufferView[], position?: number): number;
212
- /**
213
- * Synchronous `opendir`. Opens a directory.
214
- * @param path The path to the directory.
215
- * @param options Options for opening the directory.
216
- * @returns A `Dir` object representing the opened directory.
217
- * @todo Handle options
218
- */
219
- export declare function opendirSync(this: V_Context, path: fs.PathLike, options?: fs.OpenDirOptions): Dir;
220
- /**
221
- * Synchronous `cp`. Recursively copies a file or directory.
222
- * @param source The source file or directory.
223
- * @param destination The destination file or directory.
224
- * @param opts Options for the copy operation. Currently supports these options from Node.js 'fs.cpSync':
225
- * - `dereference`: Dereference symbolic links. *(unconfirmed)*
226
- * - `errorOnExist`: Throw an error if the destination file or directory already exists.
227
- * - `filter`: A function that takes a source and destination path and returns a boolean, indicating whether to copy `source` element.
228
- * - `force`: Overwrite the destination if it exists, and overwrite existing readonly destination files. *(unconfirmed)*
229
- * - `preserveTimestamps`: Preserve file timestamps.
230
- * - `recursive`: If `true`, copies directories recursively.
231
- */
232
- export declare function cpSync(this: V_Context, source: fs.PathLike, destination: fs.PathLike, opts?: fs.CopySyncOptions): void;
233
- /**
234
- * Synchronous statfs(2). Returns information about the mounted file system which contains path.
235
- * In case of an error, the err.code will be one of Common System Errors.
236
- * @param path A path to an existing file or directory on the file system to be queried.
237
- */
238
- export declare function statfsSync(this: V_Context, path: fs.PathLike, options?: fs.StatFsOptions & {
239
- bigint?: false;
240
- }): fs.StatsFs;
241
- export declare function statfsSync(this: V_Context, path: fs.PathLike, options: fs.StatFsOptions & {
242
- bigint: true;
243
- }): fs.BigIntStatsFs;
244
- export declare function statfsSync(this: V_Context, path: fs.PathLike, options?: fs.StatFsOptions): fs.StatsFs | fs.BigIntStatsFs;
245
- /**
246
- * Retrieves the files matching the specified pattern.
247
- */
248
- export declare function globSync(pattern: string | readonly string[]): string[];
249
- export declare function globSync(pattern: string | readonly string[], options: fs.GlobOptionsWithFileTypes): Dirent[];
250
- export declare function globSync(pattern: string | readonly string[], options: fs.GlobOptionsWithoutFileTypes): string[];
251
- export declare function globSync(pattern: string | readonly string[], options: fs.GlobOptions): Dirent[] | string[];
18
+ export declare function open(this: V_Context, path: PathLike, opt: OpenOptions): Handle;
19
+ export declare function readlink(this: V_Context, path: PathLike): string;
20
+ export declare function mkdir(this: V_Context, path: PathLike, options?: MkdirOptions): string | void;
21
+ export declare function readdir(this: V_Context, path: PathLike, options?: ReaddirOptions): Dirent[];
22
+ export declare function rename(this: V_Context, oldPath: PathLike, newPath: PathLike): void;
23
+ export declare function link(this: V_Context, target: PathLike, link: PathLike): void;