I'm was trying to make this example work:
var firstBuffer = Buffer.from('hello world');
var secondBuffer = Buffer.from(firstBuffer.buffer, 0, firstBuffer.length);
console.log (firstBuffer) // <Buffer 68 65 6c 6c 6f 20 77 6f 72 6c 64>
console.log (secondBuffer) // <Buffer da 07 00 00 da 07 00 00 db 07 00>
assert(firstBuffer.buffer === secondBuffer.buffer, ".buffer property is the same");
assert (firstBuffer[0] == secondBuffer[0]) // fails
it didn't worked and I didn't know why until I found that offset property of the firstBuffer wasn't 0 as I would assume. I modify it to use correct offset and problem was solved, but I spend more than hour because there wasn't any info in official docs.
It would be good to mention in documentation that result of Buffer.from(string) can have offset different than 0
I'm was trying to make this example work:
it didn't worked and I didn't know why until I found that
offsetproperty of thefirstBufferwasn't0as I would assume. I modify it to use correct offset and problem was solved, but I spend more than hour because there wasn't any info in official docs.It would be good to mention in documentation that result of
Buffer.from(string)can haveoffsetdifferent than0