Skip to content

Buffer.copyBytesFrom should accept a DataView as well. #47924

Description

@issuefiler

The issue

The Buffer.copyBytesFrom method was added by the issue #43862. What it does is create a Buffer by copying the data to which the view of an ArrayBuffer or SharedArrayBuffer is referring (“viewing”). The current problem is that it only accepts a TypedArray for its view parameter, when DataViews, too, are views.

> Buffer.copyBytesFrom(new DataView(new SharedArrayBuffer(1024)))
Uncaught:
TypeError [ERR_INVALID_ARG_TYPE]: The "view" argument must be an instance of TypedArray. Received an instance of DataView
    at __node_internal_captureLargerStackTrace (node:internal/errors:490:5)
    at new NodeError (node:internal/errors:399:5)
    at Function.copyBytesFrom (node:buffer:347:11) {
  code: 'ERR_INVALID_ARG_TYPE'
}

My suggestion

I suggest:

  • enabling Buffer.copyBytesFrom to accept a DataView as well for the view parameter.
  • modifying the documentation accordingly.

Activity

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.staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions