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

Buffer.from what does it do? #13563

Closed
ubershmekel opened this issue Jun 8, 2017 · 3 comments
Closed

Buffer.from what does it do? #13563

ubershmekel opened this issue Jun 8, 2017 · 3 comments
Labels
buffer Issues and PRs related to the buffer subsystem. question Issues that look for answers.

Comments

@ubershmekel
Copy link

ubershmekel commented Jun 8, 2017

  • Version: v7.9.0
  • Platform: Darwin yuvmac.dd-wrt 16.6.0 Darwin Kernel Version 16.6.0: Fri Apr 14 16:21:16 PDT 2017; root:xnu-3789.60.24~6/RELEASE_X86_64 x86_64
  • Subsystem: Buffer
> Buffer.from(Buffer.from('1234567890'), 1, 3);
<Buffer 31 32 33 34 35 36 37 38 39 30>
> Buffer.from(Buffer.from('1234567890').buffer, 0, 3);
<Buffer 78 dc bf>
> Buffer.from('1234567890').buffer
ArrayBuffer { byteLength: 8192 }

These are questions, but I believe they correspond to either bugs in the docs or implementation.

See also #7134 where .slice is the recommended solution, but the underlying problem isn't resolved.

@vkurchatkin
Copy link
Contributor

There is no bug. Truncation only works if first argument is ArrayBuffer, not Buffer.

What does .buffer mean? It seems to allow the truncation to occur but has the wrong bytes in it.

See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/buffer

@vsemozhetbyt vsemozhetbyt added buffer Issues and PRs related to the buffer subsystem. question Issues that look for answers. labels Jun 8, 2017
@ubershmekel
Copy link
Author

@vkurchatkin it's returning the wrong bytes when I use the .buffer in the second invocation.

@vsemozhetbyt
Copy link
Contributor

@ubershmekel I think it is possibly connected with Buffer.poolSize and internal preallocation:
https://nodejs.org/api/buffer.html#buffer_class_property_buffer_poolsize

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
buffer Issues and PRs related to the buffer subsystem. question Issues that look for answers.
Projects
None yet
Development

No branches or pull requests

3 participants