@zenfs/core 1.2.5 → 1.2.7
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/config.d.ts +9 -0
- package/dist/config.js +1 -0
- package/dist/emulation/config.d.ts +5 -1
- package/dist/emulation/config.js +5 -1
- package/dist/file.js +25 -13
- package/package.json +1 -1
- package/src/config.ts +11 -0
- package/src/emulation/config.ts +6 -1
- package/src/file.ts +17 -13
package/dist/config.d.ts
CHANGED
|
@@ -61,6 +61,15 @@ export interface Configuration<T extends ConfigMounts> extends SharedConfig {
|
|
|
61
61
|
* @default false
|
|
62
62
|
*/
|
|
63
63
|
disableUpdateOnRead: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* If true, files will only sync to the file system when closed.
|
|
66
|
+
*
|
|
67
|
+
* This can increase performance.
|
|
68
|
+
* @experimental
|
|
69
|
+
* @overrides `disableUpdateOnRead`
|
|
70
|
+
* @default false
|
|
71
|
+
*/
|
|
72
|
+
onlySyncOnClose: boolean;
|
|
64
73
|
}
|
|
65
74
|
/**
|
|
66
75
|
* Configures ZenFS with single mount point /
|
package/dist/config.js
CHANGED
|
@@ -71,6 +71,7 @@ export async function configure(configuration) {
|
|
|
71
71
|
cache.setEnabled(configuration.cacheStats ?? false);
|
|
72
72
|
config.checkAccess = !configuration.disableAccessChecks;
|
|
73
73
|
config.updateOnRead = !configuration.disableUpdateOnRead;
|
|
74
|
+
config.syncImmediately = !configuration.onlySyncOnClose;
|
|
74
75
|
if (configuration.addDevices) {
|
|
75
76
|
const devfs = new DeviceFS();
|
|
76
77
|
devfs.createDevice('/null', nullDevice);
|
|
@@ -4,9 +4,13 @@ export declare const config: {
|
|
|
4
4
|
*/
|
|
5
5
|
checkAccess: boolean;
|
|
6
6
|
/**
|
|
7
|
-
* Whether to
|
|
7
|
+
* Whether to mark a file as dirty after updating its `atime` when read from
|
|
8
8
|
*/
|
|
9
9
|
updateOnRead: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Whether to immediately sync when files are changed
|
|
12
|
+
*/
|
|
13
|
+
syncImmediately: boolean;
|
|
10
14
|
/**
|
|
11
15
|
* If a file's buffer is not large enough to store content when writing and the buffer can't be resized, reuse the buffer passed to write()
|
|
12
16
|
*/
|
package/dist/emulation/config.js
CHANGED
|
@@ -4,9 +4,13 @@ export const config = {
|
|
|
4
4
|
*/
|
|
5
5
|
checkAccess: true,
|
|
6
6
|
/**
|
|
7
|
-
* Whether to
|
|
7
|
+
* Whether to mark a file as dirty after updating its `atime` when read from
|
|
8
8
|
*/
|
|
9
9
|
updateOnRead: true,
|
|
10
|
+
/**
|
|
11
|
+
* Whether to immediately sync when files are changed
|
|
12
|
+
*/
|
|
13
|
+
syncImmediately: true,
|
|
10
14
|
/**
|
|
11
15
|
* If a file's buffer is not large enough to store content when writing and the buffer can't be resized, reuse the buffer passed to write()
|
|
12
16
|
*/
|
package/dist/file.js
CHANGED
|
@@ -289,11 +289,13 @@ export class PreloadFile extends File {
|
|
|
289
289
|
}
|
|
290
290
|
async truncate(length) {
|
|
291
291
|
this._truncate(length);
|
|
292
|
-
|
|
292
|
+
if (config.syncImmediately)
|
|
293
|
+
await this.sync();
|
|
293
294
|
}
|
|
294
295
|
truncateSync(length) {
|
|
295
296
|
this._truncate(length);
|
|
296
|
-
|
|
297
|
+
if (config.syncImmediately)
|
|
298
|
+
this.syncSync();
|
|
297
299
|
}
|
|
298
300
|
_write(buffer, offset = 0, length = this.stats.size, position = this.position) {
|
|
299
301
|
if (this.closed) {
|
|
@@ -337,7 +339,8 @@ export class PreloadFile extends File {
|
|
|
337
339
|
*/
|
|
338
340
|
async write(buffer, offset, length, position) {
|
|
339
341
|
const bytesWritten = this._write(buffer, offset, length, position);
|
|
340
|
-
|
|
342
|
+
if (config.syncImmediately)
|
|
343
|
+
await this.sync();
|
|
341
344
|
return bytesWritten;
|
|
342
345
|
}
|
|
343
346
|
/**
|
|
@@ -351,7 +354,8 @@ export class PreloadFile extends File {
|
|
|
351
354
|
*/
|
|
352
355
|
writeSync(buffer, offset = 0, length = this.stats.size, position = this.position) {
|
|
353
356
|
const bytesWritten = this._write(buffer, offset, length, position);
|
|
354
|
-
|
|
357
|
+
if (config.syncImmediately)
|
|
358
|
+
this.syncSync();
|
|
355
359
|
return bytesWritten;
|
|
356
360
|
}
|
|
357
361
|
_read(buffer, offset = 0, length = this.stats.size, position) {
|
|
@@ -363,8 +367,8 @@ export class PreloadFile extends File {
|
|
|
363
367
|
}
|
|
364
368
|
if (config.updateOnRead) {
|
|
365
369
|
this.dirty = true;
|
|
366
|
-
this.stats.atimeMs = Date.now();
|
|
367
370
|
}
|
|
371
|
+
this.stats.atimeMs = Date.now();
|
|
368
372
|
position ?? (position = this.position);
|
|
369
373
|
let end = position + length;
|
|
370
374
|
if (end > this.stats.size) {
|
|
@@ -389,7 +393,8 @@ export class PreloadFile extends File {
|
|
|
389
393
|
*/
|
|
390
394
|
async read(buffer, offset, length, position) {
|
|
391
395
|
const bytesRead = this._read(buffer, offset, length, position);
|
|
392
|
-
|
|
396
|
+
if (config.syncImmediately)
|
|
397
|
+
await this.sync();
|
|
393
398
|
return { bytesRead, buffer };
|
|
394
399
|
}
|
|
395
400
|
/**
|
|
@@ -403,7 +408,8 @@ export class PreloadFile extends File {
|
|
|
403
408
|
*/
|
|
404
409
|
readSync(buffer, offset, length, position) {
|
|
405
410
|
const bytesRead = this._read(buffer, offset, length, position);
|
|
406
|
-
|
|
411
|
+
if (config.syncImmediately)
|
|
412
|
+
this.syncSync();
|
|
407
413
|
return bytesRead;
|
|
408
414
|
}
|
|
409
415
|
async chmod(mode) {
|
|
@@ -412,7 +418,8 @@ export class PreloadFile extends File {
|
|
|
412
418
|
}
|
|
413
419
|
this.dirty = true;
|
|
414
420
|
this.stats.chmod(mode);
|
|
415
|
-
|
|
421
|
+
if (config.syncImmediately)
|
|
422
|
+
await this.sync();
|
|
416
423
|
}
|
|
417
424
|
chmodSync(mode) {
|
|
418
425
|
if (this.closed) {
|
|
@@ -420,7 +427,8 @@ export class PreloadFile extends File {
|
|
|
420
427
|
}
|
|
421
428
|
this.dirty = true;
|
|
422
429
|
this.stats.chmod(mode);
|
|
423
|
-
|
|
430
|
+
if (config.syncImmediately)
|
|
431
|
+
this.syncSync();
|
|
424
432
|
}
|
|
425
433
|
async chown(uid, gid) {
|
|
426
434
|
if (this.closed) {
|
|
@@ -428,7 +436,8 @@ export class PreloadFile extends File {
|
|
|
428
436
|
}
|
|
429
437
|
this.dirty = true;
|
|
430
438
|
this.stats.chown(uid, gid);
|
|
431
|
-
|
|
439
|
+
if (config.syncImmediately)
|
|
440
|
+
await this.sync();
|
|
432
441
|
}
|
|
433
442
|
chownSync(uid, gid) {
|
|
434
443
|
if (this.closed) {
|
|
@@ -436,7 +445,8 @@ export class PreloadFile extends File {
|
|
|
436
445
|
}
|
|
437
446
|
this.dirty = true;
|
|
438
447
|
this.stats.chown(uid, gid);
|
|
439
|
-
|
|
448
|
+
if (config.syncImmediately)
|
|
449
|
+
this.syncSync();
|
|
440
450
|
}
|
|
441
451
|
async utimes(atime, mtime) {
|
|
442
452
|
if (this.closed) {
|
|
@@ -445,7 +455,8 @@ export class PreloadFile extends File {
|
|
|
445
455
|
this.dirty = true;
|
|
446
456
|
this.stats.atime = atime;
|
|
447
457
|
this.stats.mtime = mtime;
|
|
448
|
-
|
|
458
|
+
if (config.syncImmediately)
|
|
459
|
+
await this.sync();
|
|
449
460
|
}
|
|
450
461
|
utimesSync(atime, mtime) {
|
|
451
462
|
if (this.closed) {
|
|
@@ -454,7 +465,8 @@ export class PreloadFile extends File {
|
|
|
454
465
|
this.dirty = true;
|
|
455
466
|
this.stats.atime = atime;
|
|
456
467
|
this.stats.mtime = mtime;
|
|
457
|
-
|
|
468
|
+
if (config.syncImmediately)
|
|
469
|
+
this.syncSync();
|
|
458
470
|
}
|
|
459
471
|
async _setType(type) {
|
|
460
472
|
if (this.closed) {
|
package/package.json
CHANGED
package/src/config.ts
CHANGED
|
@@ -126,6 +126,16 @@ export interface Configuration<T extends ConfigMounts> extends SharedConfig {
|
|
|
126
126
|
* @default false
|
|
127
127
|
*/
|
|
128
128
|
disableUpdateOnRead: boolean;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* If true, files will only sync to the file system when closed.
|
|
132
|
+
*
|
|
133
|
+
* This can increase performance.
|
|
134
|
+
* @experimental
|
|
135
|
+
* @overrides `disableUpdateOnRead`
|
|
136
|
+
* @default false
|
|
137
|
+
*/
|
|
138
|
+
onlySyncOnClose: boolean;
|
|
129
139
|
}
|
|
130
140
|
|
|
131
141
|
/**
|
|
@@ -154,6 +164,7 @@ export async function configure<T extends ConfigMounts>(configuration: Partial<C
|
|
|
154
164
|
cache.setEnabled(configuration.cacheStats ?? false);
|
|
155
165
|
config.checkAccess = !configuration.disableAccessChecks;
|
|
156
166
|
config.updateOnRead = !configuration.disableUpdateOnRead;
|
|
167
|
+
config.syncImmediately = !configuration.onlySyncOnClose;
|
|
157
168
|
|
|
158
169
|
if (configuration.addDevices) {
|
|
159
170
|
const devfs = new DeviceFS();
|
package/src/emulation/config.ts
CHANGED
|
@@ -5,10 +5,15 @@ export const config = {
|
|
|
5
5
|
checkAccess: true,
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* Whether to
|
|
8
|
+
* Whether to mark a file as dirty after updating its `atime` when read from
|
|
9
9
|
*/
|
|
10
10
|
updateOnRead: true,
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Whether to immediately sync when files are changed
|
|
14
|
+
*/
|
|
15
|
+
syncImmediately: true,
|
|
16
|
+
|
|
12
17
|
/**
|
|
13
18
|
* If a file's buffer is not large enough to store content when writing and the buffer can't be resized, reuse the buffer passed to write()
|
|
14
19
|
*/
|
package/src/file.ts
CHANGED
|
@@ -441,12 +441,12 @@ export class PreloadFile<FS extends FileSystem> extends File {
|
|
|
441
441
|
|
|
442
442
|
public async truncate(length: number): Promise<void> {
|
|
443
443
|
this._truncate(length);
|
|
444
|
-
await this.sync();
|
|
444
|
+
if (config.syncImmediately) await this.sync();
|
|
445
445
|
}
|
|
446
446
|
|
|
447
447
|
public truncateSync(length: number): void {
|
|
448
448
|
this._truncate(length);
|
|
449
|
-
this.syncSync();
|
|
449
|
+
if (config.syncImmediately) this.syncSync();
|
|
450
450
|
}
|
|
451
451
|
|
|
452
452
|
protected _write(buffer: Uint8Array, offset: number = 0, length: number = this.stats.size, position: number = this.position): number {
|
|
@@ -494,7 +494,7 @@ export class PreloadFile<FS extends FileSystem> extends File {
|
|
|
494
494
|
*/
|
|
495
495
|
public async write(buffer: Uint8Array, offset?: number, length?: number, position?: number): Promise<number> {
|
|
496
496
|
const bytesWritten = this._write(buffer, offset, length, position);
|
|
497
|
-
await this.sync();
|
|
497
|
+
if (config.syncImmediately) await this.sync();
|
|
498
498
|
return bytesWritten;
|
|
499
499
|
}
|
|
500
500
|
|
|
@@ -509,7 +509,7 @@ export class PreloadFile<FS extends FileSystem> extends File {
|
|
|
509
509
|
*/
|
|
510
510
|
public writeSync(buffer: Uint8Array, offset: number = 0, length: number = this.stats.size, position: number = this.position): number {
|
|
511
511
|
const bytesWritten = this._write(buffer, offset, length, position);
|
|
512
|
-
this.syncSync();
|
|
512
|
+
if (config.syncImmediately) this.syncSync();
|
|
513
513
|
return bytesWritten;
|
|
514
514
|
}
|
|
515
515
|
|
|
@@ -517,13 +517,17 @@ export class PreloadFile<FS extends FileSystem> extends File {
|
|
|
517
517
|
if (this.closed) {
|
|
518
518
|
throw ErrnoError.With('EBADF', this.path, 'File.read');
|
|
519
519
|
}
|
|
520
|
+
|
|
520
521
|
if (!isReadable(this.flag)) {
|
|
521
522
|
throw new ErrnoError(Errno.EPERM, 'File not opened with a readable mode.');
|
|
522
523
|
}
|
|
524
|
+
|
|
523
525
|
if (config.updateOnRead) {
|
|
524
526
|
this.dirty = true;
|
|
525
|
-
this.stats.atimeMs = Date.now();
|
|
526
527
|
}
|
|
528
|
+
|
|
529
|
+
this.stats.atimeMs = Date.now();
|
|
530
|
+
|
|
527
531
|
position ??= this.position;
|
|
528
532
|
let end = position + length;
|
|
529
533
|
if (end > this.stats.size) {
|
|
@@ -549,7 +553,7 @@ export class PreloadFile<FS extends FileSystem> extends File {
|
|
|
549
553
|
*/
|
|
550
554
|
public async read<TBuffer extends ArrayBufferView>(buffer: TBuffer, offset?: number, length?: number, position?: number): Promise<{ bytesRead: number; buffer: TBuffer }> {
|
|
551
555
|
const bytesRead = this._read(buffer, offset, length, position);
|
|
552
|
-
await this.sync();
|
|
556
|
+
if (config.syncImmediately) await this.sync();
|
|
553
557
|
return { bytesRead, buffer };
|
|
554
558
|
}
|
|
555
559
|
|
|
@@ -564,7 +568,7 @@ export class PreloadFile<FS extends FileSystem> extends File {
|
|
|
564
568
|
*/
|
|
565
569
|
public readSync(buffer: ArrayBufferView, offset?: number, length?: number, position?: number): number {
|
|
566
570
|
const bytesRead = this._read(buffer, offset, length, position);
|
|
567
|
-
this.syncSync();
|
|
571
|
+
if (config.syncImmediately) this.syncSync();
|
|
568
572
|
return bytesRead;
|
|
569
573
|
}
|
|
570
574
|
|
|
@@ -574,7 +578,7 @@ export class PreloadFile<FS extends FileSystem> extends File {
|
|
|
574
578
|
}
|
|
575
579
|
this.dirty = true;
|
|
576
580
|
this.stats.chmod(mode);
|
|
577
|
-
await this.sync();
|
|
581
|
+
if (config.syncImmediately) await this.sync();
|
|
578
582
|
}
|
|
579
583
|
|
|
580
584
|
public chmodSync(mode: number): void {
|
|
@@ -583,7 +587,7 @@ export class PreloadFile<FS extends FileSystem> extends File {
|
|
|
583
587
|
}
|
|
584
588
|
this.dirty = true;
|
|
585
589
|
this.stats.chmod(mode);
|
|
586
|
-
this.syncSync();
|
|
590
|
+
if (config.syncImmediately) this.syncSync();
|
|
587
591
|
}
|
|
588
592
|
|
|
589
593
|
public async chown(uid: number, gid: number): Promise<void> {
|
|
@@ -592,7 +596,7 @@ export class PreloadFile<FS extends FileSystem> extends File {
|
|
|
592
596
|
}
|
|
593
597
|
this.dirty = true;
|
|
594
598
|
this.stats.chown(uid, gid);
|
|
595
|
-
await this.sync();
|
|
599
|
+
if (config.syncImmediately) await this.sync();
|
|
596
600
|
}
|
|
597
601
|
|
|
598
602
|
public chownSync(uid: number, gid: number): void {
|
|
@@ -601,7 +605,7 @@ export class PreloadFile<FS extends FileSystem> extends File {
|
|
|
601
605
|
}
|
|
602
606
|
this.dirty = true;
|
|
603
607
|
this.stats.chown(uid, gid);
|
|
604
|
-
this.syncSync();
|
|
608
|
+
if (config.syncImmediately) this.syncSync();
|
|
605
609
|
}
|
|
606
610
|
|
|
607
611
|
public async utimes(atime: Date, mtime: Date): Promise<void> {
|
|
@@ -611,7 +615,7 @@ export class PreloadFile<FS extends FileSystem> extends File {
|
|
|
611
615
|
this.dirty = true;
|
|
612
616
|
this.stats.atime = atime;
|
|
613
617
|
this.stats.mtime = mtime;
|
|
614
|
-
await this.sync();
|
|
618
|
+
if (config.syncImmediately) await this.sync();
|
|
615
619
|
}
|
|
616
620
|
|
|
617
621
|
public utimesSync(atime: Date, mtime: Date): void {
|
|
@@ -621,7 +625,7 @@ export class PreloadFile<FS extends FileSystem> extends File {
|
|
|
621
625
|
this.dirty = true;
|
|
622
626
|
this.stats.atime = atime;
|
|
623
627
|
this.stats.mtime = mtime;
|
|
624
|
-
this.syncSync();
|
|
628
|
+
if (config.syncImmediately) this.syncSync();
|
|
625
629
|
}
|
|
626
630
|
|
|
627
631
|
public async _setType(type: FileType): Promise<void> {
|