@zenfs/core 1.11.4 → 2.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.
Files changed (135) hide show
  1. package/dist/backends/backend.d.ts +19 -15
  2. package/dist/backends/backend.js +36 -19
  3. package/dist/backends/cow.d.ts +20 -30
  4. package/dist/backends/cow.js +83 -192
  5. package/dist/backends/fetch.d.ts +1 -0
  6. package/dist/backends/fetch.js +30 -30
  7. package/dist/backends/index.d.ts +1 -1
  8. package/dist/backends/index.js +1 -1
  9. package/dist/backends/memory.d.ts +5 -7
  10. package/dist/backends/memory.js +2 -3
  11. package/dist/backends/passthrough.d.ts +19 -23
  12. package/dist/backends/passthrough.js +98 -288
  13. package/dist/backends/port.d.ts +220 -0
  14. package/dist/backends/port.js +328 -0
  15. package/dist/backends/single_buffer.d.ts +59 -47
  16. package/dist/backends/single_buffer.js +468 -219
  17. package/dist/backends/store/fs.d.ts +25 -35
  18. package/dist/backends/store/fs.js +276 -315
  19. package/dist/backends/store/store.d.ts +10 -15
  20. package/dist/backends/store/store.js +11 -10
  21. package/dist/config.d.ts +3 -12
  22. package/dist/config.js +17 -19
  23. package/dist/context.d.ts +8 -21
  24. package/dist/context.js +33 -10
  25. package/dist/index.d.ts +2 -1
  26. package/dist/index.js +2 -1
  27. package/dist/internal/contexts.d.ts +63 -0
  28. package/dist/internal/contexts.js +15 -0
  29. package/dist/internal/credentials.d.ts +2 -11
  30. package/dist/internal/credentials.js +0 -19
  31. package/dist/internal/devices.d.ts +18 -80
  32. package/dist/internal/devices.js +103 -316
  33. package/dist/internal/error.d.ts +9 -204
  34. package/dist/internal/error.js +19 -288
  35. package/dist/internal/file_index.d.ts +1 -1
  36. package/dist/internal/file_index.js +11 -11
  37. package/dist/internal/filesystem.d.ts +51 -94
  38. package/dist/internal/filesystem.js +21 -20
  39. package/dist/internal/index.d.ts +1 -2
  40. package/dist/internal/index.js +1 -2
  41. package/dist/internal/index_fs.d.ts +12 -30
  42. package/dist/internal/index_fs.js +37 -69
  43. package/dist/internal/inode.d.ts +140 -24
  44. package/dist/internal/inode.js +515 -66
  45. package/dist/mixins/async.js +52 -112
  46. package/dist/mixins/mutexed.d.ts +19 -18
  47. package/dist/mixins/mutexed.js +62 -64
  48. package/dist/mixins/readonly.d.ts +7 -6
  49. package/dist/mixins/readonly.js +24 -18
  50. package/dist/mixins/sync.js +8 -8
  51. package/dist/{vfs/path.d.ts → path.d.ts} +3 -4
  52. package/dist/{vfs/path.js → path.js} +6 -9
  53. package/dist/polyfills.js +1 -1
  54. package/dist/readline.d.ts +134 -0
  55. package/dist/readline.js +623 -0
  56. package/dist/utils.d.ts +9 -37
  57. package/dist/utils.js +17 -85
  58. package/dist/vfs/acl.d.ts +42 -0
  59. package/dist/vfs/acl.js +268 -0
  60. package/dist/vfs/async.d.ts +9 -23
  61. package/dist/vfs/async.js +25 -27
  62. package/dist/vfs/config.d.ts +6 -18
  63. package/dist/vfs/config.js +8 -18
  64. package/dist/vfs/dir.d.ts +3 -3
  65. package/dist/vfs/dir.js +12 -12
  66. package/dist/vfs/file.d.ts +106 -0
  67. package/dist/vfs/file.js +244 -0
  68. package/dist/vfs/flags.d.ts +19 -0
  69. package/dist/vfs/flags.js +62 -0
  70. package/dist/vfs/index.d.ts +4 -10
  71. package/dist/vfs/index.js +4 -13
  72. package/dist/vfs/ioctl.d.ts +88 -0
  73. package/dist/vfs/ioctl.js +409 -0
  74. package/dist/vfs/promises.d.ts +81 -19
  75. package/dist/vfs/promises.js +404 -288
  76. package/dist/vfs/shared.d.ts +7 -37
  77. package/dist/vfs/shared.js +29 -85
  78. package/dist/{stats.d.ts → vfs/stats.d.ts} +14 -28
  79. package/dist/{stats.js → vfs/stats.js} +11 -66
  80. package/dist/vfs/streams.d.ts +1 -0
  81. package/dist/vfs/streams.js +32 -27
  82. package/dist/vfs/sync.d.ts +3 -3
  83. package/dist/vfs/sync.js +263 -260
  84. package/dist/vfs/watchers.d.ts +2 -2
  85. package/dist/vfs/watchers.js +12 -12
  86. package/dist/vfs/xattr.d.ts +116 -0
  87. package/dist/vfs/xattr.js +201 -0
  88. package/package.json +5 -3
  89. package/readme.md +1 -1
  90. package/scripts/test.js +2 -2
  91. package/tests/assignment.ts +1 -1
  92. package/tests/backend/config.worker.js +4 -1
  93. package/tests/backend/fetch.test.ts +3 -0
  94. package/tests/backend/port.test.ts +19 -33
  95. package/tests/backend/remote.worker.js +4 -1
  96. package/tests/backend/single-buffer.test.ts +53 -0
  97. package/tests/backend/single-buffer.worker.js +30 -0
  98. package/tests/common/context.test.ts +3 -3
  99. package/tests/common/handle.test.ts +17 -12
  100. package/tests/common/mutex.test.ts +9 -9
  101. package/tests/common/path.test.ts +1 -1
  102. package/tests/common/readline.test.ts +104 -0
  103. package/tests/common.ts +4 -19
  104. package/tests/fetch/fetch.ts +2 -2
  105. package/tests/fs/append.test.ts +4 -4
  106. package/tests/fs/directory.test.ts +25 -25
  107. package/tests/fs/errors.test.ts +15 -19
  108. package/tests/fs/links.test.ts +4 -3
  109. package/tests/fs/open.test.ts +4 -21
  110. package/tests/fs/permissions.test.ts +14 -18
  111. package/tests/fs/read.test.ts +10 -9
  112. package/tests/fs/readFile.test.ts +10 -26
  113. package/tests/fs/rename.test.ts +4 -9
  114. package/tests/fs/stat.test.ts +8 -8
  115. package/tests/fs/streams.test.ts +2 -11
  116. package/tests/fs/times.test.ts +7 -7
  117. package/tests/fs/truncate.test.ts +8 -36
  118. package/tests/fs/watch.test.ts +10 -10
  119. package/tests/fs/write.test.ts +77 -13
  120. package/tests/fs/xattr.test.ts +85 -0
  121. package/tests/logs.js +22 -0
  122. package/tests/setup/context.ts +1 -1
  123. package/tests/setup/index.ts +3 -3
  124. package/tests/setup/port.ts +7 -1
  125. package/dist/backends/port/fs.d.ts +0 -84
  126. package/dist/backends/port/fs.js +0 -151
  127. package/dist/backends/port/rpc.d.ts +0 -77
  128. package/dist/backends/port/rpc.js +0 -100
  129. package/dist/backends/store/simple.d.ts +0 -20
  130. package/dist/backends/store/simple.js +0 -13
  131. package/dist/internal/file.d.ts +0 -359
  132. package/dist/internal/file.js +0 -751
  133. package/dist/internal/log.d.ts +0 -133
  134. package/dist/internal/log.js +0 -218
  135. package/tests/fs/writeFile.test.ts +0 -70
@@ -1,359 +0,0 @@
1
- import { Stats, type StatsLike } from '../stats.js';
2
- import type { FileSystem, StreamOptions } from './filesystem.js';
3
- import '../polyfills.js';
4
- /**
5
- * @internal @hidden
6
- */
7
- export declare function parseFlag(flag: string | number): string;
8
- /**
9
- * @internal @hidden
10
- */
11
- export declare function flagToString(flag: number): string;
12
- /**
13
- * @internal @hidden
14
- */
15
- export declare function flagToNumber(flag: string): number;
16
- /**
17
- * Parses a flag as a mode (W_OK, R_OK, and/or X_OK)
18
- * @param flag the flag to parse
19
- * @internal @hidden
20
- */
21
- export declare function flagToMode(flag: string): number;
22
- /** @hidden */
23
- export declare function isReadable(flag: string): boolean;
24
- /** @hidden */
25
- export declare function isWriteable(flag: string): boolean;
26
- /** @hidden */
27
- export declare function isTruncating(flag: string): boolean;
28
- /** @hidden */
29
- export declare function isAppendable(flag: string): boolean;
30
- /** @hidden */
31
- export declare function isSynchronous(flag: string): boolean;
32
- /** @hidden */
33
- export declare function isExclusive(flag: string): boolean;
34
- /** @hidden */
35
- export interface FileReadResult<T extends ArrayBufferView> {
36
- bytesRead: number;
37
- buffer: T;
38
- }
39
- /**
40
- * @category Internals
41
- */
42
- export declare abstract class File<FS extends FileSystem = FileSystem> {
43
- /**
44
- * @internal
45
- * The file system that created the file
46
- */
47
- fs: FS;
48
- readonly path: string;
49
- constructor(
50
- /**
51
- * @internal
52
- * The file system that created the file
53
- */
54
- fs: FS, path: string);
55
- /**
56
- * Get the current file position.
57
- */
58
- abstract position: number;
59
- abstract stat(): Promise<Stats>;
60
- abstract statSync(): Stats;
61
- abstract close(): Promise<void>;
62
- abstract closeSync(): void;
63
- [Symbol.asyncDispose](): Promise<void>;
64
- [Symbol.dispose](): void;
65
- abstract truncate(len: number): Promise<void>;
66
- abstract truncateSync(len: number): void;
67
- abstract sync(): Promise<void>;
68
- abstract syncSync(): void;
69
- /**
70
- * Write buffer to the file.
71
- * @param buffer Uint8Array containing the data to write to the file.
72
- * @param offset Offset in the buffer to start reading data from.
73
- * @param length The amount of bytes to write to the file.
74
- * @param position Offset from the beginning of the file where this data should be written.
75
- * If position is null, the data will be written at the current position.
76
- * @returns Promise resolving to the new length of the buffer
77
- */
78
- abstract write(buffer: Uint8Array, offset?: number, length?: number, position?: number): Promise<number>;
79
- /**
80
- * Write buffer to the file.
81
- * @param buffer Uint8Array containing the data to write to the file.
82
- * @param offset Offset in the buffer to start reading data from.
83
- * @param length The amount of bytes to write to the file.
84
- * @param position Offset from the beginning of the file where this data should be written.
85
- * If position is null, the data will be written at the current position.
86
- */
87
- abstract writeSync(buffer: Uint8Array, offset?: number, length?: number, position?: number): number;
88
- /**
89
- * Read data from the file.
90
- * @param buffer The buffer that the data will be written to.
91
- * @param offset The offset within the buffer where writing will start.
92
- * @param length An integer specifying the number of bytes to read.
93
- * @param position An integer specifying where to begin reading from in the file.
94
- * If position is null, data will be read from the current file position.
95
- * @returns Promise resolving to the new length of the buffer
96
- */
97
- abstract read<TBuffer extends ArrayBufferView>(buffer: TBuffer, offset?: number, length?: number, position?: number): Promise<FileReadResult<TBuffer>>;
98
- /**
99
- * Read data from the file.
100
- * @param buffer The buffer that the data will be written to.
101
- * @param offset The offset within the buffer where writing will start.
102
- * @param length An integer specifying the number of bytes to read.
103
- * @param position An integer specifying where to begin reading from in the file.
104
- * If position is null, data will be read from the current file position.
105
- */
106
- abstract readSync(buffer: ArrayBufferView, offset?: number, length?: number, position?: number): number;
107
- /**
108
- * Default implementation maps to `sync`.
109
- */
110
- datasync(): Promise<void>;
111
- /**
112
- * Default implementation maps to `syncSync`.
113
- */
114
- datasyncSync(): void;
115
- abstract chown(uid: number, gid: number): Promise<void>;
116
- abstract chownSync(uid: number, gid: number): void;
117
- abstract chmod(mode: number): Promise<void>;
118
- abstract chmodSync(mode: number): void;
119
- /**
120
- * Change the file timestamps of the file.
121
- */
122
- abstract utimes(atime: number, mtime: number): Promise<void>;
123
- /**
124
- * Change the file timestamps of the file.
125
- */
126
- abstract utimesSync(atime: number, mtime: number): void;
127
- /**
128
- * Create a stream for reading the file.
129
- */
130
- streamRead(options: StreamOptions): ReadableStream;
131
- /**
132
- * Create a stream for writing the file.
133
- */
134
- streamWrite(options: StreamOptions): WritableStream;
135
- }
136
- /**
137
- * An implementation of `File` that operates completely in-memory.
138
- * `PreloadFile`s are backed by a `Uint8Array`.
139
- * @category Internals
140
- */
141
- export declare class PreloadFile<FS extends FileSystem> extends File<FS> {
142
- readonly flag: string;
143
- readonly stats: Stats;
144
- /**
145
- * A buffer containing the entire contents of the file.
146
- */
147
- protected _buffer: Uint8Array;
148
- /**
149
- * Current position
150
- */
151
- protected _position: number;
152
- /**
153
- * Whether the file has changes which have not been written to the FS
154
- */
155
- protected dirty: boolean;
156
- /**
157
- * Whether the file is open or closed
158
- */
159
- protected closed: boolean;
160
- /**
161
- * Creates a file with `path` and, optionally, the given contents.
162
- * Note that, if contents is specified, it will be mutated by the file.
163
- */
164
- constructor(fs: FS, path: string, flag: string, stats: Stats,
165
- /**
166
- * A buffer containing the entire contents of the file.
167
- */
168
- _buffer?: Uint8Array);
169
- /**
170
- * Get the underlying buffer for this file. Mutating not recommended and will mess up dirty tracking.
171
- */
172
- get buffer(): Uint8Array;
173
- /**
174
- * Get the current file position.
175
- *
176
- * We emulate the following bug mentioned in the Node documentation:
177
- *
178
- * On Linux, positional writes don't work when the file is opened in append mode.
179
- * The kernel ignores the position argument and always appends the data to the end of the file.
180
- * @returns The current file position.
181
- */
182
- get position(): number;
183
- set position(value: number);
184
- sync(): Promise<void>;
185
- syncSync(): void;
186
- close(): Promise<void>;
187
- closeSync(): void;
188
- /**
189
- * Cleans up. This will *not* sync the file data to the FS
190
- */
191
- protected dispose(force?: boolean): void;
192
- stat(): Promise<Stats>;
193
- statSync(): Stats;
194
- protected _truncate(length: number): void;
195
- truncate(length: number): Promise<void>;
196
- truncateSync(length: number): void;
197
- protected _write(buffer: Uint8Array, offset?: number, length?: number, position?: number): number;
198
- /**
199
- * Write buffer to the file.
200
- * @param buffer Uint8Array containing the data to write to the file.
201
- * @param offset Offset in the buffer to start reading data from.
202
- * @param length The amount of bytes to write to the file.
203
- * @param position Offset from the beginning of the file where this data should be written.
204
- * If position is null, the data will be written at the current position.
205
- */
206
- write(buffer: Uint8Array, offset?: number, length?: number, position?: number): Promise<number>;
207
- /**
208
- * Write buffer to the file.
209
- * @param buffer Uint8Array containing the data to write to the file.
210
- * @param offset Offset in the buffer to start reading data from.
211
- * @param length The amount of bytes to write to the file.
212
- * @param position Offset from the beginning of the file where this data should be written.
213
- * If position is null, the data will be written at the current position.
214
- * @returns bytes written
215
- */
216
- writeSync(buffer: Uint8Array, offset?: number, length?: number, position?: number): number;
217
- protected _read(buffer: ArrayBufferView, offset?: number, length?: number, position?: number): number;
218
- /**
219
- * Read data from the file.
220
- * @param buffer The buffer that the data will be written to.
221
- * @param offset The offset within the buffer where writing will start.
222
- * @param length An integer specifying the number of bytes to read.
223
- * @param position An integer specifying where to begin reading from in the file.
224
- * If position is null, data will be read from the current file position.
225
- */
226
- read<TBuffer extends ArrayBufferView>(buffer: TBuffer, offset?: number, length?: number, position?: number): Promise<{
227
- bytesRead: number;
228
- buffer: TBuffer;
229
- }>;
230
- /**
231
- * Read data from the file.
232
- * @param buffer The buffer that the data will be written to.
233
- * @param offset The offset within the buffer where writing will start.
234
- * @param length An integer specifying the number of bytes to read.
235
- * @param position An integer specifying where to begin reading from in the file.
236
- * If position is null, data will be read from the current file position.
237
- * @returns number of bytes written
238
- */
239
- readSync(buffer: ArrayBufferView, offset?: number, length?: number, position?: number): number;
240
- chmod(mode: number): Promise<void>;
241
- chmodSync(mode: number): void;
242
- chown(uid: number, gid: number): Promise<void>;
243
- chownSync(uid: number, gid: number): void;
244
- utimes(atime: number, mtime: number): Promise<void>;
245
- utimesSync(atime: number, mtime: number): void;
246
- }
247
- /**
248
- * For the file systems which do not sync to anything.
249
- * @category Internals
250
- * @deprecated
251
- */
252
- export declare class NoSyncFile<T extends FileSystem> extends PreloadFile<T> {
253
- constructor(...args: ConstructorParameters<typeof PreloadFile<T>>);
254
- sync(): Promise<void>;
255
- syncSync(): void;
256
- close(): Promise<void>;
257
- closeSync(): void;
258
- }
259
- /**
260
- * An implementation of `File` that uses the FS
261
- * @category Internals
262
- */
263
- export declare class LazyFile<FS extends FileSystem> extends File<FS> {
264
- readonly flag: string;
265
- readonly stats: StatsLike<number>;
266
- protected _buffer?: Uint8Array;
267
- /**
268
- * Current position
269
- */
270
- protected _position: number;
271
- /**
272
- * Get the current file position.
273
- *
274
- * We emulate the following bug mentioned in the Node documentation:
275
- *
276
- * On Linux, positional writes don't work when the file is opened in append mode.
277
- * The kernel ignores the position argument and always appends the data to the end of the file.
278
- * @returns The current file position.
279
- */
280
- get position(): number;
281
- set position(value: number);
282
- /**
283
- * Whether the file has changes which have not been written to the FS
284
- */
285
- protected dirty: boolean;
286
- /**
287
- * Whether the file is open or closed
288
- */
289
- protected closed: boolean;
290
- /**
291
- * Creates a file with `path` and, optionally, the given contents.
292
- * Note that, if contents is specified, it will be mutated by the file.
293
- */
294
- constructor(fs: FS, path: string, flag: string, stats: StatsLike<number>);
295
- sync(): Promise<void>;
296
- syncSync(): void;
297
- close(): Promise<void>;
298
- closeSync(): void;
299
- /**
300
- * Cleans up. This will *not* sync the file data to the FS
301
- */
302
- protected dispose(force?: boolean): void;
303
- stat(): Promise<Stats>;
304
- statSync(): Stats;
305
- truncate(length: number): Promise<void>;
306
- truncateSync(length: number): void;
307
- protected prepareWrite(buffer: Uint8Array, offset: number, length: number, position: number): Uint8Array;
308
- /**
309
- * Write buffer to the file.
310
- * @param buffer Uint8Array containing the data to write to the file.
311
- * @param offset Offset in the buffer to start reading data from.
312
- * @param length The amount of bytes to write to the file.
313
- * @param position Offset from the beginning of the file where this data should be written.
314
- * If position is null, the data will be written at the current position.
315
- */
316
- write(buffer: Uint8Array, offset?: number, length?: number, position?: number): Promise<number>;
317
- /**
318
- * Write buffer to the file.
319
- * @param buffer Uint8Array containing the data to write to the file.
320
- * @param offset Offset in the buffer to start reading data from.
321
- * @param length The amount of bytes to write to the file.
322
- * @param position Offset from the beginning of the file where this data should be written.
323
- * If position is null, the data will be written at the current position.
324
- * @returns bytes written
325
- */
326
- writeSync(buffer: Uint8Array, offset?: number, length?: number, position?: number): number;
327
- /**
328
- * Computes position information for reading
329
- */
330
- protected prepareRead(length: number, position: number): number;
331
- /**
332
- * Read data from the file.
333
- * @param buffer The buffer that the data will be written to.
334
- * @param offset The offset within the buffer where writing will start.
335
- * @param length An integer specifying the number of bytes to read.
336
- * @param position An integer specifying where to begin reading from in the file.
337
- * If position is unset, data will be read from the current file position.
338
- */
339
- read<TBuffer extends ArrayBufferView>(buffer: TBuffer, offset?: number, length?: number, position?: number): Promise<{
340
- bytesRead: number;
341
- buffer: TBuffer;
342
- }>;
343
- /**
344
- * Read data from the file.
345
- * @param buffer The buffer that the data will be written to.
346
- * @param offset The offset within the buffer where writing will start.
347
- * @param length An integer specifying the number of bytes to read.
348
- * @param position An integer specifying where to begin reading from in the file.
349
- * If position is null, data will be read from the current file position.
350
- * @returns number of bytes written
351
- */
352
- readSync(buffer: ArrayBufferView, offset?: number, length?: number, position?: number): number;
353
- chmod(mode: number): Promise<void>;
354
- chmodSync(mode: number): void;
355
- chown(uid: number, gid: number): Promise<void>;
356
- chownSync(uid: number, gid: number): void;
357
- utimes(atime: number, mtime: number): Promise<void>;
358
- utimesSync(atime: number, mtime: number): void;
359
- }