-
Notifications
You must be signed in to change notification settings - Fork 28.2k
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
Allow ArrayBuffer as argument to writeFile and friends #42228
Comments
Looking at the I also wonder if writing arrayBuffers directly to a file is considered to be an undefined behaviour, since they are byte arrays and their representation is dependent on the width of the view we are casting it to. (https://stackoverflow.com/questions/42416783/where-to-use-arraybuffer-vs-typed-array-in-javascript) |
The implementation literally just casts any
The answer you link would suggest
Which makes sense, like you actually write a chunk of bytes to a file, not a sequence of |
Okay that makes sense, thanks for the explanation! |
@nodejs/fs |
There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment. For more information on how the project manages feature requests, please consult the feature request management document. |
keepalive |
Here's a draft PR to consider. It required some work in a few different places to apply the change to most of the write functions:
I didn't touch any |
Extended most file writing functions to accept ArrayBuffers rather than only strings, buffers, or data views. Does not include functions that accept arrays of dataviews, such as writev. Fixes: nodejs#42228
There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment. For more information on how the project manages feature requests, please consult the feature request management document. |
There has been no activity on this feature request and it is being closed. If you feel closing this issue is not the right thing to do, please leave a comment. For more information on how the project manages feature requests, please consult the feature request management document. |
Given the security risk unchecked readfile with callback is, this seems like a really bad idea |
What is the problem this feature will solve?
Currently one can write a large number of types to a file. However one cannot currently write an
ArrayBuffer
to a file without wrapping it in a typed array.It would be convenient to be able to write an
ArrayBuffer
directly to a file if one is received from some library without having to wrap directly. (The fact this isn't possible is something I forget pretty much everytime I go to write anArrayBuffer
).What is the feature you are proposing to solve the problem?
I propose allowing
fs.promises.writeFile("./some-file", someArrayBuffer)
to work whensomeArrayBuffer
is anArrayBuffer
. Typed arrays and such are already supported, so this shouldn't be particularly complicated to implement.What alternatives have you considered?
No response
The text was updated successfully, but these errors were encountered: