-
-
Notifications
You must be signed in to change notification settings - Fork 32.7k
Closed
Labels
bufferIssues and PRs related to the buffer subsystem.Issues and PRs related to the buffer subsystem.docIssues and PRs related to the documentations.Issues and PRs related to the documentations.
Description
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
- Version: 9.8.0
- Platform: 4.13.0-36-generic Working with nvm, nvmw and similar installation managers #40-Ubuntu SMP x86_64
- Subsystem: buffer
Metadata
Metadata
Assignees
Labels
bufferIssues and PRs related to the buffer subsystem.Issues and PRs related to the buffer subsystem.docIssues and PRs related to the documentations.Issues and PRs related to the documentations.