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