nodejs / node

Node.js JavaScript runtime ✨🐢🚀✨
https://nodejs.org
Other
107.78k stars 29.68k forks source link

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

Closed sky-train closed 6 years ago

sky-train commented 6 years ago

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

// display //ArrayBuffer { byteLength: 8192 }

addaleax commented 6 years ago

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 commented 6 years ago

Thanks!

ChALkeR commented 6 years ago

Closing as answered.