Skip to content

napi is missing method to create buffer from ArrayBuffer #54440

Description

@ronag

What is the problem this feature will solve?

Not possible to create Buffer from ArrayBuffer with napi

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

Add signature similar to what we have for typed arrays:

napi_status napi_create_typedarray(napi_env env,
                                   napi_typedarray_type type,
                                   size_t length,
                                   napi_value arraybuffer,
                                   size_t byte_offset,
                                   napi_value* result) 
napi_status napi_create_buffer(napi_env env,
                               size_t length,
                               napi_value arraybuffer,
                               size_t byte_offset,
                               napi_value* result) 

What alternatives have you considered?

No response

Activity

  1. added
    bufferIssues and PRs related to the buffer subsystem.
    node-apiIssues and PRs related to Node-API.
    on Aug 18, 2024
  2. moved this from Awaiting Triage to Triaged in Node.js feature requestson Aug 18, 2024
  3. shubhamsugara22 commented on Aug 20, 2024

    @shubhamsugara22

    Would like to work on it , and discuss more on it
    I think his feature would bring the API in line with the existing napi_create_typedarray function
    @ronag @redyetidev

  4. shubhamsugara22 commented on Aug 21, 2024

    @shubhamsugara22

    We already have a functionin in src/node_api.cc , should we update this function or create new one with different name
    @ronag @redyetidev
    like to discuss on these 2 also , like reference and structure if already done for any other module
    // Get the underlying ArrayBuffer data
    // Create a Buffer from the ArrayBuffer

    napi_status NAPI_CDECL napi_create_buffer(napi_env env,
                                              size_t length,
                                              void** data,
                                              napi_value* result) {
      NAPI_PREAMBLE(env);
    
  5. ronag commented on Aug 21, 2024

    @ronag
    MemberAuthor

    napi_create_buffer_from_array_buffer or something?

  6. shubhamsugara22 commented on Aug 21, 2024

    @shubhamsugara22

    Though the same name regarding the other 2 points have any idea ?

  7. moved this from In Progress to Has PR in Node-API Team Projecton Aug 30, 2024
  8. gabrielschulhof commented on Sep 13, 2024

    @gabrielschulhof
    Contributor

    Please use

    napi_status node_api_create*

    That is, the prefix should not be napi_ for new APIs, but node_api_.

  9. moved this from Triaged to In Progress in Node.js feature requestson Sep 13, 2024
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.node-apiIssues and PRs related to Node-API.

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions