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

buf.slice() return buffer object with not correct ArrayBuffer length #22299

Closed
sky-train opened this issue Aug 13, 2018 · 3 comments
Closed

buf.slice() return buffer object with not correct ArrayBuffer length #22299

sky-train opened this issue Aug 13, 2018 · 3 comments
Labels
buffer Issues and PRs related to the buffer subsystem. question Issues that look for answers.

Comments

@sky-train
Copy link

const buf = Buffer.from([1,2,3]);
console.log( buf.slice(1,2).buffer );

// display
//ArrayBuffer { byteLength: 8192 }

@addaleax addaleax added the buffer Issues and PRs related to the buffer subsystem. label Aug 13, 2018
@addaleax
Copy link
Member

Unlike Uint8Array, Buffer uses a slice method that does not copy data but rather returns a view of the original buffer: https://nodejs.org/api/buffer.html#buffer_buf_slice_start_end

So this result seems expected to me.

@sky-train
Copy link
Author

Thanks!

@ChALkeR ChALkeR added the question Issues that look for answers. label Aug 14, 2018
@ChALkeR
Copy link
Member

ChALkeR commented Aug 14, 2018

Closing as answered.

@ChALkeR ChALkeR closed this as completed Aug 14, 2018
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