镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
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

  1. added
    bufferIssues and PRs related to the buffer subsystem.
    on May 9, 2023
  2. sankalp1999 commented on May 10, 2023

    @sankalp1999
    Contributor

    I think I can help with this. I can modify the code to accomodate for dataView.

  3. sankalp1999 commented on May 10, 2023

    @sankalp1999
    Contributor

    Relevant comments on why DataView was not added earlier.

    #46500 (comment)

    #46500 (comment)

    To be frank at first glance, it looked manageable to me but it seems it's pretty complex.

    Comments suggest that a separate method should be created for this. Would need maintainers' advice.

  4. sankalp1999 commented on May 12, 2023

    @sankalp1999
    Contributor

    Relevant comments on why DataView was not added earlier.

    #46500 (comment)

    #46500 (comment)

    To be frank at first glance, it looked manageable to me but it seems it's pretty complex.

    Comments suggest that a separate method should be created for this. Would need maintainers' advice.

    @jasnell what do you think

  5. github-actions commented on Nov 9, 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.

  6. added
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on Nov 9, 2023
  7. github-actions commented on Dec 9, 2023

    @github-actions
    Contributor

    There has been no activity on this feature request and it is being closed. If you feel closing this issue is not the right thing to do, please leave a comment.

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

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