Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v12 - avoid needless data copying in fs.promises.writeFileHandle when called with Uint8Array #35343

Closed
joelrbrandt opened this issue Sep 25, 2020 · 0 comments
Labels
fs Issues and PRs related to the fs subsystem / file system.

Comments

@joelrbrandt
Copy link
Contributor

Is your feature request related to a problem? Please describe.
In node v12, fs.promises.writeFileHandle performs needless data copying when writing a Uint8Array. See:
https://github.com/nodejs/node/blob/v12.x/lib/internal/fs/promises.js#L151

If data is a Uint8Array, the local variable buffer will actually be a Uint8Array object. Calling .slice on a Uint8Array creates a shallow copy of the values. This is documented both on MDN and in the node documentation.

Describe the solution you'd like
Don't use .slice on Uint8Arrays

Describe alternatives you've considered
Manually making a Buffer out of my Uint8Array before calling fs write functions.

Thanks for all your hard work in making Node awesome!

@watilde watilde added the fs Issues and PRs related to the fs subsystem / file system. label Sep 26, 2020
targos added a commit to targos/node that referenced this issue Sep 27, 2020
Before this change, only the first part of typed arrays which have more
than 1 byte per element (e.g. Uint16Array) would be written.
This also removes the use of the `slice` method to avoid unnecessary
copying the data.

Fixes: nodejs#35343
MylesBorins pushed a commit that referenced this issue Sep 29, 2020
Before this change, only the first part of typed arrays which have more
than 1 byte per element (e.g. Uint16Array) would be written.
This also removes the use of the `slice` method to avoid unnecessary
copying the data.

Fixes: #35343

PR-URL: #35376
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Zeyu Yang <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
joesepi pushed a commit to joesepi/node that referenced this issue Jan 8, 2021
Before this change, only the first part of typed arrays which have more
than 1 byte per element (e.g. Uint16Array) would be written.
This also removes the use of the `slice` method to avoid unnecessary
copying the data.

Fixes: nodejs#35343

PR-URL: nodejs#35376
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Zeyu Yang <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fs Issues and PRs related to the fs subsystem / file system.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants