@zenfs/core 1.8.0 → 1.8.2

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/utils.js CHANGED
@@ -160,3 +160,36 @@ export function canary(path, syscall) {
160
160
  export function _throw(e) {
161
161
  throw e;
162
162
  }
163
+ /**
164
+ * Grows a buffer if it isn't large enough
165
+ * @returns The original buffer if resized successfully, or a newly created buffer
166
+ * @internal Not for external use!
167
+ */
168
+ export function growBuffer(buffer, newByteLength) {
169
+ if (buffer.byteLength >= newByteLength)
170
+ return buffer;
171
+ if (ArrayBuffer.isView(buffer)) {
172
+ const newBuffer = growBuffer(buffer.buffer, newByteLength);
173
+ return new buffer.constructor(newBuffer, buffer.byteOffset, newByteLength);
174
+ }
175
+ const isShared = buffer instanceof SharedArrayBuffer;
176
+ // Note: If true, the buffer must be resizable/growable because of the first check.
177
+ if (buffer.maxByteLength > newByteLength) {
178
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
179
+ isShared ? buffer.grow(newByteLength) : buffer.resize(newByteLength);
180
+ return buffer;
181
+ }
182
+ if (isShared) {
183
+ const newBuffer = new SharedArrayBuffer(newByteLength);
184
+ new Uint8Array(newBuffer).set(new Uint8Array(buffer));
185
+ return newBuffer;
186
+ }
187
+ try {
188
+ return buffer.transfer(newByteLength);
189
+ }
190
+ catch {
191
+ const newBuffer = new ArrayBuffer(newByteLength);
192
+ new Uint8Array(newBuffer).set(new Uint8Array(buffer));
193
+ return newBuffer;
194
+ }
195
+ }
package/dist/vfs/async.js CHANGED
@@ -431,7 +431,7 @@ export function createReadStream(path, options) {
431
431
  try {
432
432
  handle || (handle = await promises.open.call(context, path, 'r', options === null || options === void 0 ? void 0 : options.mode));
433
433
  const result = await handle.read(new Uint8Array(size), 0, size, handle.file.position);
434
- stream.push(!result.bytesRead ? null : result.buffer.slice(0, result.bytesRead));
434
+ stream.push(!result.bytesRead ? null : result.buffer.subarray(0, result.bytesRead));
435
435
  handle.file.position += result.bytesRead;
436
436
  if (!result.bytesRead) {
437
437
  await handle.close();
@@ -197,7 +197,7 @@ export class FileHandle {
197
197
  controller.close();
198
198
  return;
199
199
  }
200
- controller.enqueue(result.buffer.slice(0, result.bytesRead));
200
+ controller.enqueue(result.buffer.subarray(0, result.bytesRead));
201
201
  position += result.bytesRead;
202
202
  if (++i >= maxChunks) {
203
203
  throw new ErrnoError(Errno.EFBIG, 'Too many iterations on readable stream', this.file.path, 'FileHandle.readableWebStream');
@@ -333,7 +333,7 @@ export class FileHandle {
333
333
  read: async (size) => {
334
334
  try {
335
335
  const result = await this.read(new Uint8Array(size), 0, size, this.file.position);
336
- stream.push(!result.bytesRead ? null : result.buffer.slice(0, result.bytesRead)); // Push data or null for EOF
336
+ stream.push(!result.bytesRead ? null : result.buffer.subarray(0, result.bytesRead)); // Push data or null for EOF
337
337
  this.file.position += result.bytesRead;
338
338
  }
339
339
  catch (error) {
package/eslint.shared.js CHANGED
@@ -45,6 +45,7 @@ export default [
45
45
  '@typescript-eslint/no-unsafe-call': 'off',
46
46
  '@typescript-eslint/restrict-plus-operands': 'off',
47
47
  '@typescript-eslint/no-base-to-string': 'off',
48
+ '@typescript-eslint/no-unused-expressions': 'warn',
48
49
  },
49
50
  },
50
51
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenfs/core",
3
- "version": "1.8.0",
3
+ "version": "1.8.2",
4
4
  "description": "A filesystem, anywhere",
5
5
  "funding": {
6
6
  "type": "individual",
@@ -1,10 +1,9 @@
1
1
  import assert from 'node:assert';
2
2
  import { suite, test } from 'node:test';
3
3
  import { fs } from '../common.js';
4
-
4
+ const fn = 'write.txt';
5
5
  suite('write', () => {
6
6
  test('write file with specified content', async () => {
7
- const fn = 'write.txt';
8
7
  const expected = 'ümlaut.';
9
8
 
10
9
  const handle = await fs.promises.open(fn, 'w', 0o644);
@@ -20,10 +19,9 @@ suite('write', () => {
20
19
  });
21
20
 
22
21
  test('write a buffer to a file', async () => {
23
- const filename = 'write.txt';
24
22
  const expected = Buffer.from('hello');
25
23
 
26
- const handle = await fs.promises.open(filename, 'w', 0o644);
24
+ const handle = await fs.promises.open(fn, 'w', 0o644);
27
25
 
28
26
  const written = await handle.write(expected, 0, expected.length, null);
29
27
 
@@ -31,15 +29,12 @@ suite('write', () => {
31
29
 
32
30
  await handle.close();
33
31
 
34
- assert((await fs.promises.readFile(filename)).equals(expected));
32
+ assert((await fs.promises.readFile(fn)).equals(expected));
35
33
 
36
- await fs.promises.unlink(filename);
34
+ await fs.promises.unlink(fn);
37
35
  });
38
- });
39
36
 
40
- suite('writeSync', () => {
41
- test('write file with specified content', () => {
42
- const fn = 'write.txt';
37
+ test('writeSync file with specified content', () => {
43
38
  const fd = fs.openSync(fn, 'w');
44
39
 
45
40
  let written = fs.writeSync(fd, '');
@@ -53,6 +48,6 @@ suite('writeSync', () => {
53
48
 
54
49
  fs.closeSync(fd);
55
50
 
56
- assert(fs.readFileSync(fn, 'utf8') === 'foobár');
51
+ assert.strictEqual(fs.readFileSync(fn, 'utf8'), 'foobár');
57
52
  });
58
53
  });