@zenfs/core 1.2.5 → 1.2.6

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 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
@@ -70,7 +70,8 @@ export async function configure(configuration) {
70
70
  Object.assign(credentials, { uid, gid, suid: uid, sgid: gid, euid: uid, egid: gid });
71
71
  cache.setEnabled(configuration.cacheStats ?? false);
72
72
  config.checkAccess = !configuration.disableAccessChecks;
73
- config.updateOnRead = !configuration.disableUpdateOnRead;
73
+ config.syncOnRead = !configuration.onlySyncOnClose || !configuration.disableUpdateOnRead;
74
+ config.syncOnWrite = !configuration.onlySyncOnClose;
74
75
  if (configuration.addDevices) {
75
76
  const devfs = new DeviceFS();
76
77
  devfs.createDevice('/null', nullDevice);
@@ -6,7 +6,11 @@ export declare const config: {
6
6
  /**
7
7
  * Whether to sync atime updates immediately when reading from a file
8
8
  */
9
- updateOnRead: boolean;
9
+ syncOnRead: boolean;
10
+ /**
11
+ * Whether to immediately sync when files are written to
12
+ */
13
+ syncOnWrite: 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
  */
@@ -6,7 +6,11 @@ export const config = {
6
6
  /**
7
7
  * Whether to sync atime updates immediately when reading from a file
8
8
  */
9
- updateOnRead: true,
9
+ syncOnRead: true,
10
+ /**
11
+ * Whether to immediately sync when files are written to
12
+ */
13
+ syncOnWrite: 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
- await this.sync();
292
+ if (config.syncOnWrite)
293
+ await this.sync();
293
294
  }
294
295
  truncateSync(length) {
295
296
  this._truncate(length);
296
- this.syncSync();
297
+ if (config.syncOnWrite)
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
- await this.sync();
342
+ if (config.syncOnWrite)
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
- this.syncSync();
357
+ if (config.syncOnWrite)
358
+ this.syncSync();
355
359
  return bytesWritten;
356
360
  }
357
361
  _read(buffer, offset = 0, length = this.stats.size, position) {
@@ -361,10 +365,8 @@ export class PreloadFile extends File {
361
365
  if (!isReadable(this.flag)) {
362
366
  throw new ErrnoError(Errno.EPERM, 'File not opened with a readable mode.');
363
367
  }
364
- if (config.updateOnRead) {
365
- this.dirty = true;
366
- this.stats.atimeMs = Date.now();
367
- }
368
+ this.dirty = true;
369
+ this.stats.atimeMs = Date.now();
368
370
  position ?? (position = this.position);
369
371
  let end = position + length;
370
372
  if (end > this.stats.size) {
@@ -389,7 +391,8 @@ export class PreloadFile extends File {
389
391
  */
390
392
  async read(buffer, offset, length, position) {
391
393
  const bytesRead = this._read(buffer, offset, length, position);
392
- await this.sync();
394
+ if (config.syncOnRead)
395
+ await this.sync();
393
396
  return { bytesRead, buffer };
394
397
  }
395
398
  /**
@@ -403,7 +406,8 @@ export class PreloadFile extends File {
403
406
  */
404
407
  readSync(buffer, offset, length, position) {
405
408
  const bytesRead = this._read(buffer, offset, length, position);
406
- this.syncSync();
409
+ if (config.syncOnRead)
410
+ this.syncSync();
407
411
  return bytesRead;
408
412
  }
409
413
  async chmod(mode) {
@@ -412,7 +416,8 @@ export class PreloadFile extends File {
412
416
  }
413
417
  this.dirty = true;
414
418
  this.stats.chmod(mode);
415
- await this.sync();
419
+ if (config.syncOnWrite)
420
+ await this.sync();
416
421
  }
417
422
  chmodSync(mode) {
418
423
  if (this.closed) {
@@ -420,7 +425,8 @@ export class PreloadFile extends File {
420
425
  }
421
426
  this.dirty = true;
422
427
  this.stats.chmod(mode);
423
- this.syncSync();
428
+ if (config.syncOnWrite)
429
+ this.syncSync();
424
430
  }
425
431
  async chown(uid, gid) {
426
432
  if (this.closed) {
@@ -428,7 +434,8 @@ export class PreloadFile extends File {
428
434
  }
429
435
  this.dirty = true;
430
436
  this.stats.chown(uid, gid);
431
- await this.sync();
437
+ if (config.syncOnWrite)
438
+ await this.sync();
432
439
  }
433
440
  chownSync(uid, gid) {
434
441
  if (this.closed) {
@@ -436,7 +443,8 @@ export class PreloadFile extends File {
436
443
  }
437
444
  this.dirty = true;
438
445
  this.stats.chown(uid, gid);
439
- this.syncSync();
446
+ if (config.syncOnWrite)
447
+ this.syncSync();
440
448
  }
441
449
  async utimes(atime, mtime) {
442
450
  if (this.closed) {
@@ -445,7 +453,8 @@ export class PreloadFile extends File {
445
453
  this.dirty = true;
446
454
  this.stats.atime = atime;
447
455
  this.stats.mtime = mtime;
448
- await this.sync();
456
+ if (config.syncOnWrite)
457
+ await this.sync();
449
458
  }
450
459
  utimesSync(atime, mtime) {
451
460
  if (this.closed) {
@@ -454,7 +463,8 @@ export class PreloadFile extends File {
454
463
  this.dirty = true;
455
464
  this.stats.atime = atime;
456
465
  this.stats.mtime = mtime;
457
- this.syncSync();
466
+ if (config.syncOnWrite)
467
+ this.syncSync();
458
468
  }
459
469
  async _setType(type) {
460
470
  if (this.closed) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenfs/core",
3
- "version": "1.2.5",
3
+ "version": "1.2.6",
4
4
  "description": "A filesystem, anywhere",
5
5
  "funding": {
6
6
  "type": "individual",
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
  /**
@@ -153,7 +163,8 @@ export async function configure<T extends ConfigMounts>(configuration: Partial<C
153
163
 
154
164
  cache.setEnabled(configuration.cacheStats ?? false);
155
165
  config.checkAccess = !configuration.disableAccessChecks;
156
- config.updateOnRead = !configuration.disableUpdateOnRead;
166
+ config.syncOnRead = !configuration.onlySyncOnClose || !configuration.disableUpdateOnRead;
167
+ config.syncOnWrite = !configuration.onlySyncOnClose;
157
168
 
158
169
  if (configuration.addDevices) {
159
170
  const devfs = new DeviceFS();
@@ -7,7 +7,12 @@ export const config = {
7
7
  /**
8
8
  * Whether to sync atime updates immediately when reading from a file
9
9
  */
10
- updateOnRead: true,
10
+ syncOnRead: true,
11
+
12
+ /**
13
+ * Whether to immediately sync when files are written to
14
+ */
15
+ syncOnWrite: true,
11
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()
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.syncOnWrite) 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.syncOnWrite) 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.syncOnWrite) 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.syncOnWrite) this.syncSync();
513
513
  return bytesWritten;
514
514
  }
515
515
 
@@ -520,10 +520,8 @@ export class PreloadFile<FS extends FileSystem> extends File {
520
520
  if (!isReadable(this.flag)) {
521
521
  throw new ErrnoError(Errno.EPERM, 'File not opened with a readable mode.');
522
522
  }
523
- if (config.updateOnRead) {
524
- this.dirty = true;
525
- this.stats.atimeMs = Date.now();
526
- }
523
+ this.dirty = true;
524
+ this.stats.atimeMs = Date.now();
527
525
  position ??= this.position;
528
526
  let end = position + length;
529
527
  if (end > this.stats.size) {
@@ -549,7 +547,7 @@ export class PreloadFile<FS extends FileSystem> extends File {
549
547
  */
550
548
  public async read<TBuffer extends ArrayBufferView>(buffer: TBuffer, offset?: number, length?: number, position?: number): Promise<{ bytesRead: number; buffer: TBuffer }> {
551
549
  const bytesRead = this._read(buffer, offset, length, position);
552
- await this.sync();
550
+ if (config.syncOnRead) await this.sync();
553
551
  return { bytesRead, buffer };
554
552
  }
555
553
 
@@ -564,7 +562,7 @@ export class PreloadFile<FS extends FileSystem> extends File {
564
562
  */
565
563
  public readSync(buffer: ArrayBufferView, offset?: number, length?: number, position?: number): number {
566
564
  const bytesRead = this._read(buffer, offset, length, position);
567
- this.syncSync();
565
+ if (config.syncOnRead) this.syncSync();
568
566
  return bytesRead;
569
567
  }
570
568
 
@@ -574,7 +572,7 @@ export class PreloadFile<FS extends FileSystem> extends File {
574
572
  }
575
573
  this.dirty = true;
576
574
  this.stats.chmod(mode);
577
- await this.sync();
575
+ if (config.syncOnWrite) await this.sync();
578
576
  }
579
577
 
580
578
  public chmodSync(mode: number): void {
@@ -583,7 +581,7 @@ export class PreloadFile<FS extends FileSystem> extends File {
583
581
  }
584
582
  this.dirty = true;
585
583
  this.stats.chmod(mode);
586
- this.syncSync();
584
+ if (config.syncOnWrite) this.syncSync();
587
585
  }
588
586
 
589
587
  public async chown(uid: number, gid: number): Promise<void> {
@@ -592,7 +590,7 @@ export class PreloadFile<FS extends FileSystem> extends File {
592
590
  }
593
591
  this.dirty = true;
594
592
  this.stats.chown(uid, gid);
595
- await this.sync();
593
+ if (config.syncOnWrite) await this.sync();
596
594
  }
597
595
 
598
596
  public chownSync(uid: number, gid: number): void {
@@ -601,7 +599,7 @@ export class PreloadFile<FS extends FileSystem> extends File {
601
599
  }
602
600
  this.dirty = true;
603
601
  this.stats.chown(uid, gid);
604
- this.syncSync();
602
+ if (config.syncOnWrite) this.syncSync();
605
603
  }
606
604
 
607
605
  public async utimes(atime: Date, mtime: Date): Promise<void> {
@@ -611,7 +609,7 @@ export class PreloadFile<FS extends FileSystem> extends File {
611
609
  this.dirty = true;
612
610
  this.stats.atime = atime;
613
611
  this.stats.mtime = mtime;
614
- await this.sync();
612
+ if (config.syncOnWrite) await this.sync();
615
613
  }
616
614
 
617
615
  public utimesSync(atime: Date, mtime: Date): void {
@@ -621,7 +619,7 @@ export class PreloadFile<FS extends FileSystem> extends File {
621
619
  this.dirty = true;
622
620
  this.stats.atime = atime;
623
621
  this.stats.mtime = mtime;
624
- this.syncSync();
622
+ if (config.syncOnWrite) this.syncSync();
625
623
  }
626
624
 
627
625
  public async _setType(type: FileType): Promise<void> {