@zenfs/core 1.8.1 → 1.8.3

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/devices.d.ts CHANGED
@@ -69,7 +69,7 @@ export interface DeviceDriver<TData = any> {
69
69
  * @deprecated
70
70
  * @todo [BREAKING] Remove
71
71
  */
72
- read(file: DeviceFile<TData>, buffer: ArrayBufferView, offset?: number, length?: number, position?: number): number;
72
+ read?(file: DeviceFile<TData>, buffer: ArrayBufferView, offset?: number, length?: number, position?: number): number;
73
73
  /**
74
74
  * Synchronously read from a device.
75
75
  * @privateRemarks
@@ -85,7 +85,7 @@ export interface DeviceDriver<TData = any> {
85
85
  * @deprecated
86
86
  * @todo [BREAKING] Remove
87
87
  */
88
- write(file: DeviceFile<TData>, buffer: Uint8Array, offset: number, length: number, position?: number): number;
88
+ write?(file: DeviceFile<TData>, buffer: Uint8Array, offset: number, length: number, position?: number): number;
89
89
  /**
90
90
  * Synchronously write to a device
91
91
  * @group File operations
package/dist/devices.js CHANGED
@@ -427,24 +427,9 @@ export class DeviceFS extends StoreFS {
427
427
  device.driver.writeD(device, data, offset);
428
428
  }
429
429
  }
430
- function defaultWrite(file, buffer, offset, length, position) {
431
- return file.writeSync(buffer, offset, length, position);
432
- }
433
- function defaultWriteD(device, data, offset) {
430
+ function defaultWrite(device, data, offset) {
434
431
  return;
435
432
  }
436
- function defaultRead(file, buffer, offset, length, position) {
437
- return file.readSync(buffer, offset, length, position);
438
- }
439
- // 512 bytes.
440
- const blockSize = 0x200;
441
- function alloc(bytesNeeded, existing) {
442
- const blocksNeeded = bytesNeeded / blockSize;
443
- const currentBocks = existing ? existing.byteLength / blockSize : 0;
444
- if (blocksNeeded <= currentBocks && existing)
445
- return existing;
446
- return new Uint8Array(Math.ceil(blocksNeeded));
447
- }
448
433
  const emptyBuffer = new Uint8Array();
449
434
  /**
450
435
  * Simulates the `/dev/null` device.
@@ -464,8 +449,7 @@ export const nullDevice = {
464
449
  readD() {
465
450
  return emptyBuffer;
466
451
  },
467
- write: defaultWrite,
468
- writeD: defaultWriteD,
452
+ writeD: defaultWrite,
469
453
  };
470
454
  /**
471
455
  * Simulates the `/dev/zero` device
@@ -483,12 +467,10 @@ export const zeroDevice = {
483
467
  init() {
484
468
  return { major: 1, minor: 5 };
485
469
  },
486
- read: defaultRead,
487
470
  readD(device, buffer, offset, end) {
488
471
  buffer.fill(0, offset, end);
489
472
  },
490
- write: defaultWrite,
491
- writeD: defaultWriteD,
473
+ writeD: defaultWrite,
492
474
  };
493
475
  /**
494
476
  * Simulates the `/dev/full` device.
@@ -502,7 +484,6 @@ export const fullDevice = {
502
484
  init() {
503
485
  return { major: 1, minor: 7 };
504
486
  },
505
- read: defaultRead,
506
487
  readD(device, buffer, offset, end) {
507
488
  buffer.fill(0, offset, end);
508
489
  },
@@ -525,14 +506,12 @@ export const randomDevice = {
525
506
  init() {
526
507
  return { major: 1, minor: 8 };
527
508
  },
528
- read: defaultRead,
529
509
  readD(device, buffer) {
530
510
  for (let i = 0; i < buffer.length; i++) {
531
511
  buffer[i] = Math.floor(Math.random() * 256);
532
512
  }
533
513
  },
534
- write: defaultWrite,
535
- writeD: defaultWriteD,
514
+ writeD: defaultWrite,
536
515
  };
537
516
  /**
538
517
  * Simulates the `/dev/console` device.
@@ -544,11 +523,9 @@ const consoleDevice = {
544
523
  init(ino, { output = text => console.log(text) } = {}) {
545
524
  return { major: 5, minor: 1, data: { output } };
546
525
  },
547
- read: defaultRead,
548
526
  readD() {
549
527
  return emptyBuffer;
550
528
  },
551
- write: defaultWrite,
552
529
  writeD(device, buffer, offset) {
553
530
  const text = decodeUTF8(buffer);
554
531
  device.data.output(text, offset);
package/dist/file.js CHANGED
@@ -626,7 +626,7 @@ export class LazyFile extends File {
626
626
  end = position + Math.max(this.stats.size - position, 0);
627
627
  }
628
628
  this._position = end;
629
- return end - position;
629
+ return end;
630
630
  }
631
631
  /**
632
632
  * Read data from the file.
@@ -637,12 +637,12 @@ export class LazyFile extends File {
637
637
  * If position is unset, data will be read from the current file position.
638
638
  */
639
639
  async read(buffer, offset = 0, length = buffer.byteLength - offset, position = this.position) {
640
- const bytesRead = this.prepareRead(length, position);
640
+ const end = this.prepareRead(length, position);
641
641
  const uint8 = new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
642
- await this.fs.read(this.path, uint8.subarray(offset, offset + length), position, bytesRead);
642
+ await this.fs.read(this.path, uint8.subarray(offset, offset + length), position, end);
643
643
  if (config.syncImmediately)
644
644
  await this.sync();
645
- return { bytesRead, buffer };
645
+ return { bytesRead: end - position, buffer };
646
646
  }
647
647
  /**
648
648
  * Read data from the file.
@@ -654,12 +654,12 @@ export class LazyFile extends File {
654
654
  * @returns number of bytes written
655
655
  */
656
656
  readSync(buffer, offset = 0, length = buffer.byteLength - offset, position = this.position) {
657
- const bytesRead = this.prepareRead(length, position);
657
+ const end = this.prepareRead(length, position);
658
658
  const uint8 = new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
659
- this.fs.readSync(this.path, uint8.subarray(offset, offset + length), position, bytesRead);
659
+ this.fs.readSync(this.path, uint8.subarray(offset, offset + length), position, end);
660
660
  if (config.syncImmediately)
661
661
  this.syncSync();
662
- return bytesRead;
662
+ return end - position;
663
663
  }
664
664
  async chmod(mode) {
665
665
  if (this.closed)
@@ -149,8 +149,8 @@ export declare abstract class FileSystem {
149
149
  existsSync(path: string): boolean;
150
150
  abstract link(target: string, link: string): Promise<void>;
151
151
  abstract linkSync(target: string, link: string): void;
152
- abstract sync(path: string, data?: Uint8Array, stats?: Partial<Readonly<StatsLike>>): Promise<void>;
153
- abstract syncSync(path: string, data?: Uint8Array, stats?: Partial<Readonly<StatsLike>>): void;
152
+ abstract sync(path: string, data?: Uint8Array, stats?: Readonly<Partial<StatsLike>>): Promise<void>;
153
+ abstract syncSync(path: string, data?: Uint8Array, stats?: Readonly<Partial<StatsLike>>): void;
154
154
  /**
155
155
  * Reads into a buffer
156
156
  * @param buffer The buffer to read into. You must set the `byteOffset` and `byteLength` appropriately!
package/dist/utils.d.ts CHANGED
@@ -73,7 +73,7 @@ export declare function normalizeOptions(options: fs.WriteFileOptions | (fs.Enco
73
73
  export type Concrete<T extends ClassLike> = Pick<T, keyof T> & (new (...args: any[]) => InstanceType<T>);
74
74
  /**
75
75
  * Generate a random ino
76
- * @internal
76
+ * @internal @deprecated @hidden
77
77
  */
78
78
  export declare function randomBigInt(): bigint;
79
79
  /**
package/dist/utils.js CHANGED
@@ -135,7 +135,7 @@ export function normalizeOptions(options, encoding = 'utf8', flag, mode = 0) {
135
135
  }
136
136
  /**
137
137
  * Generate a random ino
138
- * @internal
138
+ * @internal @deprecated @hidden
139
139
  */
140
140
  export function randomBigInt() {
141
141
  return BigInt('0x' + randomHex(8));
@@ -179,10 +179,17 @@ export function growBuffer(buffer, newByteLength) {
179
179
  isShared ? buffer.grow(newByteLength) : buffer.resize(newByteLength);
180
180
  return buffer;
181
181
  }
182
- if (!isShared) {
182
+ if (isShared) {
183
+ const newBuffer = new SharedArrayBuffer(newByteLength);
184
+ new Uint8Array(newBuffer).set(new Uint8Array(buffer));
185
+ return newBuffer;
186
+ }
187
+ try {
183
188
  return buffer.transfer(newByteLength);
184
189
  }
185
- const newBuffer = new SharedArrayBuffer(newByteLength);
186
- new Uint8Array(newBuffer).set(new Uint8Array(buffer));
187
- return newBuffer;
190
+ catch {
191
+ const newBuffer = new ArrayBuffer(newByteLength);
192
+ new Uint8Array(newBuffer).set(new Uint8Array(buffer));
193
+ return newBuffer;
194
+ }
188
195
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenfs/core",
3
- "version": "1.8.1",
3
+ "version": "1.8.3",
4
4
  "description": "A filesystem, anywhere",
5
5
  "funding": {
6
6
  "type": "individual",