-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
Buffer created using new Buffer(buffer) has a different ArrayBuffer from the original one #4341
Comments
This is expected behaviour.
> var arr = new Uint8Array(6); var buf = new Buffer(arr.buffer); buf
<Buffer 00 00 00 00 00 00>
> arr[0] = 2; buf
<Buffer 02 00 00 00 00 00> Edit: example fixed, there was a mistake in the initial version.
See https://nodejs.org/api/buffer.html#buffer_new_buffer_buffer and https://nodejs.org/api/buffer.html#buffer_class_slowbuffer. |
Btw, is |
@ChALkeR ... not actually seeing that behavior at all:
See: https://nodejs.org/dist/latest-v5.x/docs/api/buffer.html#buffer_buffer Edit... hmm ok, nevermind... went back and re-read the example above... it's a bit inconsistent..
|
@jasnell Sorry, there was a copy-paste error in my example (when I tried to fit it into two repl lines). Fixed. |
cc @trevnorris |
So the confusion seems to be that How this works isn't likely to change. Do we need better explanation in our documentation? |
@trevnorris That and the missing documentation for |
I believe this is addressed with the recent commits. Closing |
I came across this issue myself after investigating a memory corruption issue in https://github.com/mozilla/pdf.js/. Here's behavior that I consider very surprising: > var x = new Buffer([1]);
undefined
> new Buffer(x).length
1
> new Buffer(x.buffer).length
8192 @jasnell can you elaborate about which commits address this and/or how it's been addressed. Thank you. |
@jbergknoff That is expected. |
@trevnorris thank you for the clarification. With respect, it's only expected if one is intimately familiar with the implementation details of Node's |
Hope the title describes the issue correctly:)
Codes:
node_buffer.buffer is different from another_node_buffer.buffer !
The text was updated successfully, but these errors were encountered: