You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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!
The text was updated successfully, but these errors were encountered:
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
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 <ruben@bridgewater.de>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
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 <ruben@bridgewater.de>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
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 variablebuffer
will actually be aUint8Array
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 Uint8ArraysDescribe 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!
The text was updated successfully, but these errors were encountered: