Skip to content

Buffer.from offsets #54162

Open
Open
@friesendrywall

Description

Version

v20.15.0

Platform

Microsoft Windows NT 10.0.19045.0 x64

Subsystem

No response

What steps will reproduce the bug?

Use following example, the complete buffer is copied, byteOffset and length are ignored as near as I can prove.

const buff = Buffer.alloc(32);
for (let i = 0; i < 32; i++) {
    buff[i] = i;
}
const buff2 = Buffer.from(buff, 5, 5);
console.log(buff2);

How often does it reproduce? Is there a required condition?

Always.

What is the expected behavior? Why is that the expected behavior?

Expect a partial buffer copy like
<Buffer 05 06 07 08 09>

What do you see instead?

<Buffer 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f>

Additional information

If this is supposed to work, it should be fixed, but if not, improve the docs.

Metadata

Assignees

No one assigned

    Labels

    bufferIssues and PRs related to the buffer subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions