Skip to content

Conversation

@clemyan
Copy link
Member

@clemyan clemyan commented Oct 21, 2025

What's the problem this PR addresses?

Fixes #6890
Fixes #6145

Node's implementation of FileHandle#read allows reading into TypedArrays and DataViews (collectively known as ArrayBufferViews, and checks for them using ArrayBuffer.isView().

On the other hand, our implementation checks using Buffer.isBuffer() and thus only allows Buffer. If an ArrayBufferView is given, it treats them as an options bag and pass its .buffer (which is an ArrayBuffer) as the sink to the backing fs. If the backing fs is Node's native fs then it would throw.

How did you fix it?

Allow ArrayBufferViews by checking with ArrayBuffer.isView() as in Node's implementation.

Because the underlying FakeFS interface only allows Buffer (and changing that would be a breaking change), a Buffer backed by the ArrayBufferView is used. (Q: Should we make that change next major?)

Also un-vendored the TypeScript types if the exact same type is available from @types/node along the way. AFAICT those were vendored because those types wasn't available at first? \cc @merceyz

This fix should be orthogonal to #6919

Checklist

  • I have set the packages that need to be released for my changes to be effective.
  • I will check that all automated PR checks pass before the PR gets reviewed.

@clemyan clemyan force-pushed the clemyan/fix-filehandle-read branch from ef1b818 to 86374f8 Compare October 23, 2025 14:49
@clemyan
Copy link
Member Author

clemyan commented Oct 23, 2025

Also discovered that the read implementation was based on essentially Node 17.3.0 but the minimum Node version Yarn supports now is 18.12.0. Updated the implementation to match the latter. Namely:

  • length defaults to buffer.byteLength - offset now
  • handle.read(buffer, options) signature

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug?]: Incorrect FS return type under PnP [Bug?]: FileHandle.read is not supporting TypedArray and DataView properly in pnp mode

2 participants