镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Buffer.from(<ArrayBufferView>) #43862

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.

Activity

  1. added
    feature requestIssues requesting new Node.js features.
    bufferIssues and PRs related to the buffer subsystem.
    on Jul 16, 2022
  2. moved this to Pending Triage in Node.js feature requestson Oct 22, 2022
  3. github-actions commented on Jan 13, 2023

    @github-actions
    Contributor

    There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment.

    For more information on how the project manages feature requests, please consult the feature request management document.

  4. added
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on Jan 13, 2023
  5. jasnell commented on Jan 13, 2023

    @jasnell
    Member

    This should be kept open. It's still needed

  6. added
    never-staleIssues and PRs exempt from automated stale handling.
    and removed
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on Jan 13, 2023
  7. addaleax commented on Jan 13, 2023

    @addaleax
    Member

    @jasnell Is this actionable, though? Buffer.from(abv) has well-defined semantics right now (even if those include data truncation – it matches Uint8Array.from() in that regard, afaict).

  8. jasnell commented on Feb 4, 2023

    @jasnell
    Member

    It doesn't need to be Buffer.from(abv) exactly. It can easily be another variation, Buffer.fromTypedArray or such (I'm horrible with naming so other suggestions are welcome)

  9. addaleax commented on Feb 4, 2023

    @addaleax
    Member

    Yeah, we could do that. It’s probably worth thinking about the name – it should reflect that it creates the buffer from the underlying memory of a TypedArray rather than its contents – and it’s probably still worth thinking about whether this really makes sense to address in Node.js itself (the fact that writing new Uint8Array(typedArray.buffer, typedArray.byteOffset, typedArray.byteLength) is verbose and repetitive isn’t really a Node.js-specific thing).

  10. LiviaMedeiros commented on Feb 5, 2023

    @LiviaMedeiros
    MemberAuthor

    Agreed with idea of separate method; its existence by itself would also imply that Buffer.from(abv) does something different.

  11. added a commit that references this issue on Feb 25, 2023
  12. moved this from Pending Triage to Done in Node.js feature requestson Mar 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bufferIssues and PRs related to the buffer subsystem.feature requestIssues requesting new Node.js features.never-staleIssues and PRs exempt from automated stale handling.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions