Skip to content

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

Closed as not planned
Closed as not planned
@issuefiler

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.

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.stale

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions