@zenfs/core 1.0.9 → 1.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/backends/backend.d.ts +4 -8
- package/dist/backends/backend.js +7 -11
- package/dist/backends/fetch.d.ts +2 -4
- package/dist/backends/fetch.js +1 -3
- package/dist/backends/memory.d.ts +1 -1
- package/dist/backends/overlay.d.ts +9 -5
- package/dist/backends/overlay.js +128 -55
- package/dist/backends/port/fs.d.ts +12 -17
- package/dist/backends/port/fs.js +5 -8
- package/dist/backends/port/rpc.d.ts +1 -1
- package/dist/backends/store/fs.d.ts +8 -10
- package/dist/backends/store/fs.js +30 -49
- package/dist/backends/store/simple.d.ts +1 -1
- package/dist/backends/store/simple.js +1 -1
- package/dist/backends/store/store.d.ts +7 -13
- package/dist/config.d.ts +5 -5
- package/dist/config.js +26 -26
- package/dist/emulation/async.d.ts +21 -176
- package/dist/emulation/async.js +17 -111
- package/dist/emulation/dir.d.ts +0 -1
- package/dist/emulation/path.d.ts +0 -4
- package/dist/emulation/path.js +4 -8
- package/dist/emulation/promises.d.ts +31 -121
- package/dist/emulation/promises.js +30 -97
- package/dist/emulation/shared.d.ts +7 -3
- package/dist/emulation/shared.js +8 -5
- package/dist/emulation/streams.d.ts +0 -3
- package/dist/emulation/sync.d.ts +25 -178
- package/dist/emulation/sync.js +36 -129
- package/dist/emulation/watchers.d.ts +0 -4
- package/dist/error.d.ts +11 -11
- package/dist/error.js +8 -10
- package/dist/file.d.ts +50 -171
- package/dist/file.js +33 -115
- package/dist/filesystem.d.ts +10 -62
- package/dist/filesystem.js +5 -6
- package/dist/mixins/async.d.ts +4 -6
- package/dist/mixins/async.js +3 -1
- package/dist/mixins/mutexed.d.ts +4 -4
- package/dist/mixins/mutexed.js +7 -5
- package/dist/mixins/readonly.js +14 -15
- package/dist/mixins/shared.d.ts +5 -5
- package/dist/mixins/sync.d.ts +2 -2
- package/dist/stats.d.ts +21 -37
- package/dist/stats.js +9 -21
- package/dist/utils.d.ts +1 -3
- package/package.json +4 -4
- package/src/backends/backend.ts +7 -11
- package/src/backends/fetch.ts +2 -4
- package/src/backends/memory.ts +1 -1
- package/src/backends/overlay.ts +49 -40
- package/src/backends/port/fs.ts +11 -14
- package/src/backends/port/rpc.ts +1 -0
- package/src/backends/store/fs.ts +30 -46
- package/src/backends/store/simple.ts +1 -1
- package/src/backends/store/store.ts +7 -13
- package/src/config.ts +26 -26
- package/src/emulation/async.ts +28 -178
- package/src/emulation/path.ts +4 -11
- package/src/emulation/promises.ts +34 -116
- package/src/emulation/shared.ts +8 -6
- package/src/emulation/sync.ts +41 -185
- package/src/error.ts +7 -11
- package/src/file.ts +47 -180
- package/src/filesystem.ts +14 -65
- package/src/mixins/async.ts +4 -6
- package/src/mixins/mutexed.ts +4 -4
- package/src/mixins/readonly.ts +15 -15
- package/src/mixins/shared.ts +5 -5
- package/src/mixins/sync.ts +3 -3
- package/src/stats.ts +21 -38
package/src/file.ts
CHANGED
|
@@ -6,10 +6,10 @@ import { size_max } from './inode.js';
|
|
|
6
6
|
import { Stats, type FileType } from './stats.js';
|
|
7
7
|
import './polyfills.js';
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
10
|
Typescript does not include a type declaration for resizable array buffers.
|
|
11
11
|
It has been standardized into ECMAScript though
|
|
12
|
-
Remove this if TS adds them to lib declarations
|
|
12
|
+
@todo Remove this if TS adds them to lib declarations
|
|
13
13
|
*/
|
|
14
14
|
declare global {
|
|
15
15
|
interface ArrayBuffer {
|
|
@@ -152,9 +152,6 @@ export abstract class File {
|
|
|
152
152
|
* The file system that created the file
|
|
153
153
|
*/
|
|
154
154
|
public fs: FileSystem,
|
|
155
|
-
/**
|
|
156
|
-
* The path to the file
|
|
157
|
-
*/
|
|
158
155
|
public readonly path: string
|
|
159
156
|
) {}
|
|
160
157
|
|
|
@@ -163,24 +160,10 @@ export abstract class File {
|
|
|
163
160
|
*/
|
|
164
161
|
public abstract position: number;
|
|
165
162
|
|
|
166
|
-
/**
|
|
167
|
-
* Asynchronous `stat`.
|
|
168
|
-
*/
|
|
169
163
|
public abstract stat(): Promise<Stats>;
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Synchronous `stat`.
|
|
173
|
-
*/
|
|
174
164
|
public abstract statSync(): Stats;
|
|
175
165
|
|
|
176
|
-
/**
|
|
177
|
-
* Asynchronous close.
|
|
178
|
-
*/
|
|
179
166
|
public abstract close(): Promise<void>;
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* Synchronous close.
|
|
183
|
-
*/
|
|
184
167
|
public abstract closeSync(): void;
|
|
185
168
|
|
|
186
169
|
public [Symbol.asyncDispose](): Promise<void> {
|
|
@@ -191,65 +174,40 @@ export abstract class File {
|
|
|
191
174
|
return this.closeSync();
|
|
192
175
|
}
|
|
193
176
|
|
|
194
|
-
/**
|
|
195
|
-
* Asynchronous truncate.
|
|
196
|
-
*/
|
|
197
177
|
public abstract truncate(len: number): Promise<void>;
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Synchronous truncate.
|
|
201
|
-
*/
|
|
202
178
|
public abstract truncateSync(len: number): void;
|
|
203
179
|
|
|
204
|
-
/**
|
|
205
|
-
* Asynchronous sync.
|
|
206
|
-
*/
|
|
207
180
|
public abstract sync(): Promise<void>;
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* Synchronous sync.
|
|
211
|
-
*/
|
|
212
181
|
public abstract syncSync(): void;
|
|
213
182
|
|
|
214
183
|
/**
|
|
215
184
|
* Write buffer to the file.
|
|
216
|
-
*
|
|
217
|
-
* without waiting for the callback.
|
|
218
|
-
* @param buffer Uint8Array containing the data to write to
|
|
219
|
-
* the file.
|
|
185
|
+
* @param buffer Uint8Array containing the data to write to the file.
|
|
220
186
|
* @param offset Offset in the buffer to start reading data from.
|
|
221
187
|
* @param length The amount of bytes to write to the file.
|
|
222
|
-
* @param position Offset from the beginning of the file where this
|
|
223
|
-
*
|
|
224
|
-
* the current position.
|
|
188
|
+
* @param position Offset from the beginning of the file where this data should be written.
|
|
189
|
+
* If position is null, the data will be written at the current position.
|
|
225
190
|
* @returns Promise resolving to the new length of the buffer
|
|
226
191
|
*/
|
|
227
192
|
public abstract write(buffer: Uint8Array, offset?: number, length?: number, position?: number): Promise<number>;
|
|
228
193
|
|
|
229
194
|
/**
|
|
230
195
|
* Write buffer to the file.
|
|
231
|
-
*
|
|
232
|
-
* without waiting for it to return.
|
|
233
|
-
* @param buffer Uint8Array containing the data to write to
|
|
234
|
-
* the file.
|
|
196
|
+
* @param buffer Uint8Array containing the data to write to the file.
|
|
235
197
|
* @param offset Offset in the buffer to start reading data from.
|
|
236
198
|
* @param length The amount of bytes to write to the file.
|
|
237
|
-
* @param position Offset from the beginning of the file where this
|
|
238
|
-
*
|
|
239
|
-
* the current position.
|
|
199
|
+
* @param position Offset from the beginning of the file where this data should be written.
|
|
200
|
+
* If position is null, the data will be written at the current position.
|
|
240
201
|
*/
|
|
241
202
|
public abstract writeSync(buffer: Uint8Array, offset?: number, length?: number, position?: number): number;
|
|
242
203
|
|
|
243
204
|
/**
|
|
244
205
|
* Read data from the file.
|
|
245
|
-
* @param buffer The buffer that the data will be
|
|
246
|
-
*
|
|
247
|
-
* @param offset The offset within the buffer where writing will
|
|
248
|
-
* start.
|
|
206
|
+
* @param buffer The buffer that the data will be written to.
|
|
207
|
+
* @param offset The offset within the buffer where writing will start.
|
|
249
208
|
* @param length An integer specifying the number of bytes to read.
|
|
250
|
-
* @param position An integer specifying where to begin reading from
|
|
251
|
-
*
|
|
252
|
-
* position.
|
|
209
|
+
* @param position An integer specifying where to begin reading from in the file.
|
|
210
|
+
* If position is null, data will be read from the current file position.
|
|
253
211
|
* @returns Promise resolving to the new length of the buffer
|
|
254
212
|
*/
|
|
255
213
|
public abstract read<TBuffer extends NodeJS.ArrayBufferView>(buffer: TBuffer, offset?: number, length?: number, position?: number): Promise<FileReadResult<TBuffer>>;
|
|
@@ -259,15 +217,12 @@ export abstract class File {
|
|
|
259
217
|
* @param buffer The buffer that the data will be written to.
|
|
260
218
|
* @param offset The offset within the buffer where writing will start.
|
|
261
219
|
* @param length An integer specifying the number of bytes to read.
|
|
262
|
-
* @param position An integer specifying where to begin reading from
|
|
263
|
-
*
|
|
264
|
-
* position.
|
|
220
|
+
* @param position An integer specifying where to begin reading from in the file.
|
|
221
|
+
* If position is null, data will be read from the current file position.
|
|
265
222
|
*/
|
|
266
223
|
public abstract readSync(buffer: ArrayBufferView, offset?: number, length?: number, position?: number): number;
|
|
267
224
|
|
|
268
225
|
/**
|
|
269
|
-
* Asynchronous `datasync`.
|
|
270
|
-
*
|
|
271
226
|
* Default implementation maps to `sync`.
|
|
272
227
|
*/
|
|
273
228
|
public datasync(): Promise<void> {
|
|
@@ -275,32 +230,16 @@ export abstract class File {
|
|
|
275
230
|
}
|
|
276
231
|
|
|
277
232
|
/**
|
|
278
|
-
* Synchronous `datasync`.
|
|
279
|
-
*
|
|
280
233
|
* Default implementation maps to `syncSync`.
|
|
281
234
|
*/
|
|
282
235
|
public datasyncSync(): void {
|
|
283
236
|
return this.syncSync();
|
|
284
237
|
}
|
|
285
238
|
|
|
286
|
-
/**
|
|
287
|
-
* Asynchronous `chown`.
|
|
288
|
-
*/
|
|
289
239
|
public abstract chown(uid: number, gid: number): Promise<void>;
|
|
290
|
-
|
|
291
|
-
/**
|
|
292
|
-
* Synchronous `chown`.
|
|
293
|
-
*/
|
|
294
240
|
public abstract chownSync(uid: number, gid: number): void;
|
|
295
241
|
|
|
296
|
-
/**
|
|
297
|
-
* Asynchronous `fchmod`.
|
|
298
|
-
*/
|
|
299
242
|
public abstract chmod(mode: number): Promise<void>;
|
|
300
|
-
|
|
301
|
-
/**
|
|
302
|
-
* Synchronous `fchmod`.
|
|
303
|
-
*/
|
|
304
243
|
public abstract chmodSync(mode: number): void;
|
|
305
244
|
|
|
306
245
|
/**
|
|
@@ -327,9 +266,8 @@ export abstract class File {
|
|
|
327
266
|
}
|
|
328
267
|
|
|
329
268
|
/**
|
|
330
|
-
* An implementation of
|
|
331
|
-
*
|
|
332
|
-
*
|
|
269
|
+
* An implementation of `File` that operates completely in-memory.
|
|
270
|
+
* `PreloadFile`s are backed by a `Uint8Array`.
|
|
333
271
|
*/
|
|
334
272
|
export class PreloadFile<FS extends FileSystem> extends File {
|
|
335
273
|
/**
|
|
@@ -348,16 +286,8 @@ export class PreloadFile<FS extends FileSystem> extends File {
|
|
|
348
286
|
protected closed: boolean = false;
|
|
349
287
|
|
|
350
288
|
/**
|
|
351
|
-
* Creates a file with
|
|
352
|
-
* that, if contents is specified, it will be mutated by the file
|
|
353
|
-
* @param _mode The mode that the file was opened using.
|
|
354
|
-
* Dictates permissions and where the file pointer starts.
|
|
355
|
-
* @param stats The stats object for the given file.
|
|
356
|
-
* PreloadFile will mutate this object. Note that this object must contain
|
|
357
|
-
* the appropriate mode that the file was opened as.
|
|
358
|
-
* @param buffer A buffer containing the entire
|
|
359
|
-
* contents of the file. PreloadFile will mutate this buffer. If not
|
|
360
|
-
* specified, we assume it is a new file.
|
|
289
|
+
* Creates a file with `path` and, optionally, the given contents.
|
|
290
|
+
* Note that, if contents is specified, it will be mutated by the file.
|
|
361
291
|
*/
|
|
362
292
|
public constructor(
|
|
363
293
|
/**
|
|
@@ -368,6 +298,9 @@ export class PreloadFile<FS extends FileSystem> extends File {
|
|
|
368
298
|
path: string,
|
|
369
299
|
public readonly flag: string,
|
|
370
300
|
public readonly stats: Stats,
|
|
301
|
+
/**
|
|
302
|
+
* A buffer containing the entire contents of the file.
|
|
303
|
+
*/
|
|
371
304
|
protected _buffer: Uint8Array = new Uint8Array(new ArrayBuffer(0, fs.metadata().noResizableBuffers ? {} : { maxByteLength: size_max }))
|
|
372
305
|
) {
|
|
373
306
|
super(fs, path);
|
|
@@ -399,10 +332,10 @@ export class PreloadFile<FS extends FileSystem> extends File {
|
|
|
399
332
|
* Get the current file position.
|
|
400
333
|
*
|
|
401
334
|
* We emulate the following bug mentioned in the Node documentation:
|
|
402
|
-
*
|
|
403
|
-
*
|
|
404
|
-
*
|
|
405
|
-
* @
|
|
335
|
+
*
|
|
336
|
+
* On Linux, positional writes don't work when the file is opened in append mode.
|
|
337
|
+
* The kernel ignores the position argument and always appends the data to the end of the file.
|
|
338
|
+
* @returns The current file position.
|
|
406
339
|
*/
|
|
407
340
|
public get position(): number {
|
|
408
341
|
if (isAppendable(this.flag)) {
|
|
@@ -411,12 +344,8 @@ export class PreloadFile<FS extends FileSystem> extends File {
|
|
|
411
344
|
return this._position;
|
|
412
345
|
}
|
|
413
346
|
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
* @param newPos new position
|
|
417
|
-
*/
|
|
418
|
-
public set position(newPos: number) {
|
|
419
|
-
this._position = newPos;
|
|
347
|
+
public set position(value: number) {
|
|
348
|
+
this._position = value;
|
|
420
349
|
}
|
|
421
350
|
|
|
422
351
|
public async sync(): Promise<void> {
|
|
@@ -458,8 +387,7 @@ export class PreloadFile<FS extends FileSystem> extends File {
|
|
|
458
387
|
}
|
|
459
388
|
|
|
460
389
|
/**
|
|
461
|
-
* Cleans up
|
|
462
|
-
* This will *not* sync the file data to the FS
|
|
390
|
+
* Cleans up. This will *not* sync the file data to the FS
|
|
463
391
|
*/
|
|
464
392
|
protected dispose(force?: boolean): void {
|
|
465
393
|
if (this.closed) {
|
|
@@ -477,9 +405,6 @@ export class PreloadFile<FS extends FileSystem> extends File {
|
|
|
477
405
|
this.closed = true;
|
|
478
406
|
}
|
|
479
407
|
|
|
480
|
-
/**
|
|
481
|
-
* Asynchronous `stat`.
|
|
482
|
-
*/
|
|
483
408
|
public stat(): Promise<Stats> {
|
|
484
409
|
if (this.closed) {
|
|
485
410
|
throw ErrnoError.With('EBADF', this.path, 'File.stat');
|
|
@@ -487,9 +412,6 @@ export class PreloadFile<FS extends FileSystem> extends File {
|
|
|
487
412
|
return Promise.resolve(new Stats(this.stats));
|
|
488
413
|
}
|
|
489
414
|
|
|
490
|
-
/**
|
|
491
|
-
* Synchronous `stat`.
|
|
492
|
-
*/
|
|
493
415
|
public statSync(): Stats {
|
|
494
416
|
if (this.closed) {
|
|
495
417
|
throw ErrnoError.With('EBADF', this.path, 'File.stat');
|
|
@@ -517,19 +439,11 @@ export class PreloadFile<FS extends FileSystem> extends File {
|
|
|
517
439
|
this._buffer = this._buffer.slice(0, length);
|
|
518
440
|
}
|
|
519
441
|
|
|
520
|
-
/**
|
|
521
|
-
* Asynchronous truncate.
|
|
522
|
-
* @param length
|
|
523
|
-
*/
|
|
524
442
|
public async truncate(length: number): Promise<void> {
|
|
525
443
|
this._truncate(length);
|
|
526
444
|
await this.sync();
|
|
527
445
|
}
|
|
528
446
|
|
|
529
|
-
/**
|
|
530
|
-
* Synchronous truncate.
|
|
531
|
-
* @param length
|
|
532
|
-
*/
|
|
533
447
|
public truncateSync(length: number): void {
|
|
534
448
|
this._truncate(length);
|
|
535
449
|
this.syncSync();
|
|
@@ -567,15 +481,11 @@ export class PreloadFile<FS extends FileSystem> extends File {
|
|
|
567
481
|
|
|
568
482
|
/**
|
|
569
483
|
* Write buffer to the file.
|
|
570
|
-
*
|
|
571
|
-
* without waiting for the callback.
|
|
572
|
-
* @param buffer Uint8Array containing the data to write to
|
|
573
|
-
* the file.
|
|
484
|
+
* @param buffer Uint8Array containing the data to write to the file.
|
|
574
485
|
* @param offset Offset in the buffer to start reading data from.
|
|
575
486
|
* @param length The amount of bytes to write to the file.
|
|
576
|
-
* @param position Offset from the beginning of the file where this
|
|
577
|
-
*
|
|
578
|
-
* the current position.
|
|
487
|
+
* @param position Offset from the beginning of the file where this data should be written.
|
|
488
|
+
* If position is null, the data will be written at the current position.
|
|
579
489
|
*/
|
|
580
490
|
public async write(buffer: Uint8Array, offset?: number, length?: number, position?: number): Promise<number> {
|
|
581
491
|
const bytesWritten = this._write(buffer, offset, length, position);
|
|
@@ -585,15 +495,11 @@ export class PreloadFile<FS extends FileSystem> extends File {
|
|
|
585
495
|
|
|
586
496
|
/**
|
|
587
497
|
* Write buffer to the file.
|
|
588
|
-
*
|
|
589
|
-
* without waiting for the callback.
|
|
590
|
-
* @param buffer Uint8Array containing the data to write to
|
|
591
|
-
* the file.
|
|
498
|
+
* @param buffer Uint8Array containing the data to write to the file.
|
|
592
499
|
* @param offset Offset in the buffer to start reading data from.
|
|
593
500
|
* @param length The amount of bytes to write to the file.
|
|
594
|
-
* @param position Offset from the beginning of the file where this
|
|
595
|
-
*
|
|
596
|
-
* the current position.
|
|
501
|
+
* @param position Offset from the beginning of the file where this data should be written.
|
|
502
|
+
* If position is null, the data will be written at the current position.
|
|
597
503
|
* @returns bytes written
|
|
598
504
|
*/
|
|
599
505
|
public writeSync(buffer: Uint8Array, offset: number = 0, length: number = this.stats.size, position: number = this.position): number {
|
|
@@ -628,14 +534,11 @@ export class PreloadFile<FS extends FileSystem> extends File {
|
|
|
628
534
|
|
|
629
535
|
/**
|
|
630
536
|
* Read data from the file.
|
|
631
|
-
* @param buffer The buffer that the data will be
|
|
632
|
-
*
|
|
633
|
-
* @param offset The offset within the buffer where writing will
|
|
634
|
-
* start.
|
|
537
|
+
* @param buffer The buffer that the data will be written to.
|
|
538
|
+
* @param offset The offset within the buffer where writing will start.
|
|
635
539
|
* @param length An integer specifying the number of bytes to read.
|
|
636
|
-
* @param position An integer specifying where to begin reading from
|
|
637
|
-
*
|
|
638
|
-
* position.
|
|
540
|
+
* @param position An integer specifying where to begin reading from in the file.
|
|
541
|
+
* If position is null, data will be read from the current file position.
|
|
639
542
|
*/
|
|
640
543
|
public async read<TBuffer extends ArrayBufferView>(buffer: TBuffer, offset?: number, length?: number, position?: number): Promise<{ bytesRead: number; buffer: TBuffer }> {
|
|
641
544
|
const bytesRead = this._read(buffer, offset, length, position);
|
|
@@ -645,13 +548,11 @@ export class PreloadFile<FS extends FileSystem> extends File {
|
|
|
645
548
|
|
|
646
549
|
/**
|
|
647
550
|
* Read data from the file.
|
|
648
|
-
* @param buffer The buffer that the data will be
|
|
649
|
-
* written to.
|
|
551
|
+
* @param buffer The buffer that the data will be written to.
|
|
650
552
|
* @param offset The offset within the buffer where writing will start.
|
|
651
553
|
* @param length An integer specifying the number of bytes to read.
|
|
652
|
-
* @param position An integer specifying where to begin reading from
|
|
653
|
-
*
|
|
654
|
-
* position.
|
|
554
|
+
* @param position An integer specifying where to begin reading from in the file.
|
|
555
|
+
* If position is null, data will be read from the current file position.
|
|
655
556
|
* @returns number of bytes written
|
|
656
557
|
*/
|
|
657
558
|
public readSync(buffer: ArrayBufferView, offset?: number, length?: number, position?: number): number {
|
|
@@ -660,10 +561,6 @@ export class PreloadFile<FS extends FileSystem> extends File {
|
|
|
660
561
|
return bytesRead;
|
|
661
562
|
}
|
|
662
563
|
|
|
663
|
-
/**
|
|
664
|
-
* Asynchronous `fchmod`.
|
|
665
|
-
* @param mode the mode
|
|
666
|
-
*/
|
|
667
564
|
public async chmod(mode: number): Promise<void> {
|
|
668
565
|
if (this.closed) {
|
|
669
566
|
throw ErrnoError.With('EBADF', this.path, 'File.chmod');
|
|
@@ -673,10 +570,6 @@ export class PreloadFile<FS extends FileSystem> extends File {
|
|
|
673
570
|
await this.sync();
|
|
674
571
|
}
|
|
675
572
|
|
|
676
|
-
/**
|
|
677
|
-
* Synchronous `fchmod`.
|
|
678
|
-
* @param mode
|
|
679
|
-
*/
|
|
680
573
|
public chmodSync(mode: number): void {
|
|
681
574
|
if (this.closed) {
|
|
682
575
|
throw ErrnoError.With('EBADF', this.path, 'File.chmod');
|
|
@@ -686,11 +579,6 @@ export class PreloadFile<FS extends FileSystem> extends File {
|
|
|
686
579
|
this.syncSync();
|
|
687
580
|
}
|
|
688
581
|
|
|
689
|
-
/**
|
|
690
|
-
* Asynchronous `fchown`.
|
|
691
|
-
* @param uid
|
|
692
|
-
* @param gid
|
|
693
|
-
*/
|
|
694
582
|
public async chown(uid: number, gid: number): Promise<void> {
|
|
695
583
|
if (this.closed) {
|
|
696
584
|
throw ErrnoError.With('EBADF', this.path, 'File.chown');
|
|
@@ -700,11 +588,6 @@ export class PreloadFile<FS extends FileSystem> extends File {
|
|
|
700
588
|
await this.sync();
|
|
701
589
|
}
|
|
702
590
|
|
|
703
|
-
/**
|
|
704
|
-
* Synchronous `fchown`.
|
|
705
|
-
* @param uid
|
|
706
|
-
* @param gid
|
|
707
|
-
*/
|
|
708
591
|
public chownSync(uid: number, gid: number): void {
|
|
709
592
|
if (this.closed) {
|
|
710
593
|
throw ErrnoError.With('EBADF', this.path, 'File.chown');
|
|
@@ -762,34 +645,18 @@ export class PreloadFile<FS extends FileSystem> extends File {
|
|
|
762
645
|
}
|
|
763
646
|
|
|
764
647
|
/**
|
|
765
|
-
* For the
|
|
648
|
+
* For the file systems which do not sync to anything.
|
|
766
649
|
*/
|
|
767
650
|
export class NoSyncFile<T extends FileSystem> extends PreloadFile<T> {
|
|
768
|
-
public constructor(fs: T, path: string, flag: string, stats: Stats, contents?: Uint8Array) {
|
|
769
|
-
super(fs, path, flag, stats, contents);
|
|
770
|
-
}
|
|
771
|
-
/**
|
|
772
|
-
* Asynchronous sync. Doesn't do anything, simply calls the cb.
|
|
773
|
-
*/
|
|
774
651
|
public sync(): Promise<void> {
|
|
775
652
|
return Promise.resolve();
|
|
776
653
|
}
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
public syncSync(): void {
|
|
781
|
-
// NOP.
|
|
782
|
-
}
|
|
783
|
-
/**
|
|
784
|
-
* Asynchronous close. Doesn't do anything, simply calls the cb.
|
|
785
|
-
*/
|
|
654
|
+
|
|
655
|
+
public syncSync(): void {}
|
|
656
|
+
|
|
786
657
|
public close(): Promise<void> {
|
|
787
658
|
return Promise.resolve();
|
|
788
659
|
}
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
*/
|
|
792
|
-
public closeSync(): void {
|
|
793
|
-
// NOP.
|
|
794
|
-
}
|
|
660
|
+
|
|
661
|
+
public closeSync(): void {}
|
|
795
662
|
}
|
package/src/filesystem.ts
CHANGED
|
@@ -14,7 +14,7 @@ export interface FileSystemMetadata {
|
|
|
14
14
|
name: string;
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
17
|
+
* Whether the FS is readonly or not
|
|
18
18
|
*/
|
|
19
19
|
readonly: boolean;
|
|
20
20
|
|
|
@@ -65,11 +65,10 @@ export interface FileSystemMetadata {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
/**
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
* This class includes default implementations for `exists` and `existsSync`
|
|
71
|
-
*
|
|
68
|
+
* Provides a consistent and easy to use internal API.
|
|
69
|
+
* Default implementations for `exists` and `existsSync` are included.
|
|
72
70
|
* If you are extending this class, note that every path is an absolute path and all arguments are present.
|
|
71
|
+
* @internal
|
|
73
72
|
*/
|
|
74
73
|
export abstract class FileSystem {
|
|
75
74
|
/**
|
|
@@ -99,88 +98,52 @@ export abstract class FileSystem {
|
|
|
99
98
|
|
|
100
99
|
public async ready(): Promise<void> {}
|
|
101
100
|
|
|
102
|
-
/**
|
|
103
|
-
* Asynchronous rename.
|
|
104
|
-
*/
|
|
105
101
|
public abstract rename(oldPath: string, newPath: string): Promise<void>;
|
|
106
|
-
/**
|
|
107
|
-
* Synchronous rename.
|
|
108
|
-
*/
|
|
109
102
|
public abstract renameSync(oldPath: string, newPath: string): void;
|
|
110
103
|
|
|
111
|
-
/**
|
|
112
|
-
* Asynchronous `stat`.
|
|
113
|
-
*/
|
|
114
104
|
public abstract stat(path: string): Promise<Stats>;
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Synchronous `stat`.
|
|
118
|
-
*/
|
|
119
105
|
public abstract statSync(path: string): Stats;
|
|
120
106
|
|
|
121
107
|
/**
|
|
122
|
-
* Opens the file at `path` with
|
|
108
|
+
* Opens the file at `path` with `flag`. The file must exist.
|
|
123
109
|
* @param path The path to open.
|
|
124
110
|
* @param flag The flag to use when opening the file.
|
|
125
111
|
*/
|
|
126
112
|
public abstract openFile(path: string, flag: string): Promise<File>;
|
|
127
113
|
|
|
128
114
|
/**
|
|
129
|
-
* Opens the file at `path` with
|
|
115
|
+
* Opens the file at `path` with `flag`. The file must exist.
|
|
130
116
|
* @param path The path to open.
|
|
131
117
|
* @param flag The flag to use when opening the file.
|
|
132
|
-
* @return A File object corresponding to the opened file.
|
|
133
118
|
*/
|
|
134
119
|
public abstract openFileSync(path: string, flag: string): File;
|
|
135
120
|
|
|
136
121
|
/**
|
|
137
|
-
* Create the file at `path` with
|
|
122
|
+
* Create the file at `path` with `mode`. Then, open it with `flag`.
|
|
138
123
|
*/
|
|
139
124
|
public abstract createFile(path: string, flag: string, mode: number): Promise<File>;
|
|
140
125
|
|
|
141
126
|
/**
|
|
142
|
-
* Create the file at `path` with
|
|
127
|
+
* Create the file at `path` with `mode`. Then, open it with `flag`.
|
|
143
128
|
*/
|
|
144
129
|
public abstract createFileSync(path: string, flag: string, mode: number): File;
|
|
145
130
|
|
|
146
|
-
/**
|
|
147
|
-
* Asynchronous `unlink`.
|
|
148
|
-
*/
|
|
149
131
|
public abstract unlink(path: string): Promise<void>;
|
|
150
|
-
/**
|
|
151
|
-
* Synchronous `unlink`.
|
|
152
|
-
*/
|
|
153
132
|
public abstract unlinkSync(path: string): void;
|
|
133
|
+
|
|
154
134
|
// Directory operations
|
|
155
|
-
|
|
156
|
-
* Asynchronous `rmdir`.
|
|
157
|
-
*/
|
|
135
|
+
|
|
158
136
|
public abstract rmdir(path: string): Promise<void>;
|
|
159
|
-
/**
|
|
160
|
-
* Synchronous `rmdir`.
|
|
161
|
-
*/
|
|
162
137
|
public abstract rmdirSync(path: string): void;
|
|
163
|
-
|
|
164
|
-
* Asynchronous `mkdir`.
|
|
165
|
-
* @param mode Mode to make the directory using.
|
|
166
|
-
*/
|
|
138
|
+
|
|
167
139
|
public abstract mkdir(path: string, mode: number): Promise<void>;
|
|
168
|
-
/**
|
|
169
|
-
* Synchronous `mkdir`.
|
|
170
|
-
* @param mode Mode to make the directory using.
|
|
171
|
-
*/
|
|
172
140
|
public abstract mkdirSync(path: string, mode: number): void;
|
|
173
|
-
|
|
174
|
-
* Asynchronous `readdir`. Reads the contents of a directory.
|
|
175
|
-
*/
|
|
141
|
+
|
|
176
142
|
public abstract readdir(path: string): Promise<string[]>;
|
|
177
|
-
/**
|
|
178
|
-
* Synchronous `readdir`. Reads the contents of a directory.
|
|
179
|
-
*/
|
|
180
143
|
public abstract readdirSync(path: string): string[];
|
|
181
144
|
|
|
182
145
|
/**
|
|
183
|
-
* Test whether or not
|
|
146
|
+
* Test whether or not `path` exists.
|
|
184
147
|
*/
|
|
185
148
|
public async exists(path: string): Promise<boolean> {
|
|
186
149
|
try {
|
|
@@ -192,7 +155,7 @@ export abstract class FileSystem {
|
|
|
192
155
|
}
|
|
193
156
|
|
|
194
157
|
/**
|
|
195
|
-
* Test whether or not
|
|
158
|
+
* Test whether or not `path` exists.
|
|
196
159
|
*/
|
|
197
160
|
public existsSync(path: string): boolean {
|
|
198
161
|
try {
|
|
@@ -203,23 +166,9 @@ export abstract class FileSystem {
|
|
|
203
166
|
}
|
|
204
167
|
}
|
|
205
168
|
|
|
206
|
-
/**
|
|
207
|
-
* Asynchronous `link`.
|
|
208
|
-
*/
|
|
209
169
|
public abstract link(target: string, link: string): Promise<void>;
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* Synchronous `link`.
|
|
213
|
-
*/
|
|
214
170
|
public abstract linkSync(target: string, link: string): void;
|
|
215
171
|
|
|
216
|
-
/**
|
|
217
|
-
* Synchronize the data and stats for path asynchronously
|
|
218
|
-
*/
|
|
219
172
|
public abstract sync(path: string, data: Uint8Array, stats: Readonly<Stats>): Promise<void>;
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* Synchronize the data and stats for path synchronously
|
|
223
|
-
*/
|
|
224
173
|
public abstract syncSync(path: string, data: Uint8Array, stats: Readonly<Stats>): void;
|
|
225
174
|
}
|
package/src/mixins/async.ts
CHANGED
|
@@ -3,14 +3,12 @@ import { Errno, ErrnoError } from '../error.js';
|
|
|
3
3
|
import { parseFlag, PreloadFile, type File } from '../file.js';
|
|
4
4
|
import type { FileSystem } from '../filesystem.js';
|
|
5
5
|
import type { Stats } from '../stats.js';
|
|
6
|
-
import type {
|
|
6
|
+
import type { AsyncFSMethods, Mixin } from './shared.js';
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
* @internal
|
|
10
|
-
*/
|
|
8
|
+
/** @internal */
|
|
11
9
|
export type AsyncOperation = {
|
|
12
|
-
[K in keyof
|
|
13
|
-
}[keyof
|
|
10
|
+
[K in keyof AsyncFSMethods]: [K, ...Parameters<FileSystem[K]>];
|
|
11
|
+
}[keyof AsyncFSMethods];
|
|
14
12
|
|
|
15
13
|
/**
|
|
16
14
|
* Async() implements synchronous methods on an asynchronous file system
|
package/src/mixins/mutexed.ts
CHANGED
|
@@ -227,15 +227,15 @@ export class _MutexedFS<T extends FileSystem> implements FileSystem {
|
|
|
227
227
|
* This serializes access to an underlying async filesystem.
|
|
228
228
|
* For example, on an OverlayFS instance with an async lower
|
|
229
229
|
* directory operations like rename and rmdir may involve multiple
|
|
230
|
-
* requests involving both the upper and lower
|
|
230
|
+
* requests involving both the upper and lower file systems -- they
|
|
231
231
|
* are not executed in a single atomic step. OverlayFS uses this
|
|
232
232
|
* to avoid having to reason about the correctness of
|
|
233
233
|
* multiple requests interleaving.
|
|
234
234
|
*
|
|
235
|
-
*
|
|
235
|
+
* @privateRemarks
|
|
236
236
|
* Instead of extending the passed class, `MutexedFS` stores it internally.
|
|
237
|
-
* This is to avoid a deadlock caused when a
|
|
238
|
-
* The problem is discussed
|
|
237
|
+
* This is to avoid a deadlock caused when a method calls another one
|
|
238
|
+
* The problem is discussed extensively in [#78](https://github.com/zen-fs/core/issues/78)
|
|
239
239
|
* Instead of extending `FileSystem`,
|
|
240
240
|
* `MutexedFS` implements it in order to make sure all of the methods are passed through
|
|
241
241
|
*
|