Skip to content

Buffer.from(<ArrayBufferView>) #43862

Closed
Closed
@LiviaMedeiros

Description

@LiviaMedeiros

What is the problem this feature will solve?

Buffer.from() has many different forms, including Buffer.from(arrayBuffer[, byteOffset[, length]]) and Buffer.from(buffer).

However, Buffer.from(abv) does not exist. Depending on exact input, trying to call it with such objects results in false positives, data truncation, data corruption (e.g. double -> unsigned char), thrown TypeErrors and empty buffers.

Creating Buffer from ArrayBufferView's data in userland is extremely error-prone because Buffer.from(arrayBuffer) doesn't copy the data.

What is the feature you are proposing to solve the problem?

Adjust Buffer.from(buffer) to accept not only Buffer and Uint8Array but any ArrayBufferView or at least any TypedArray.

What alternatives have you considered?

Deprecation and removal of Buffer from core into userspace module, with prior porting all core APIs to native Uint8Array/TypedArray/ArrayBufferViews.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bufferIssues and PRs related to the buffer subsystem.feature requestIssues that request new features to be added to Node.js.never-staleMark issue so that it is never considered stale

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions