I have a look at the Node.js Buffer documentation and I don't understand the difference between Buffer.slice and Buffer.subarray.
Both point to "the same memory as the original".
But no one seems not to be the alias of the other (it seems to be said when it is the case).
And test says that behavior is the same :
> buf=Buffer.from([0,1,2,3,4,5,6])
<Buffer 00 01 02 03 04 05 06>
> bufSlice=buf.slice(1,5)
<Buffer 01 02 03 04>
> bufSub=buf.subarray(1,5)
<Buffer 01 02 03 04>
> bufSlice
<Buffer 01 02 03 04>
> bufSub
<Buffer 01 02 03 04>
> buf[3]=0xff
255
> buf
<Buffer 00 01 02 ff 04 05 06>
> bufSub
<Buffer 01 02 ff 04>
> bufSlice
<Buffer 01 02 ff 04>
(even if example of slice in Node.js documentation is not very clear).
So what's the difference ?
Uint8Array.prototype.slice()andTypedArray.prototype.subarray()subArraymethod is referencing to the same chunk in memory.