napi_create_buffer


napi_status napi_create_buffer(napi_env env,
                               size_t size,
                               void** data,
                               napi_value* result) 
  • [in] env:调用 API 的环境。

    ¥[in] env: The environment that the API is invoked under.

  • [in] size:底层缓冲区的大小(以字节为单位)。

    ¥[in] size: Size in bytes of the underlying buffer.

  • [out] data:指向底层缓冲区的原始指针。data 可以选择性地通过传递 NULL 来忽略。

    ¥[out] data: Raw pointer to the underlying buffer. data can optionally be ignored by passing NULL.

  • [out] result:一个 napi_value 代表一个 node::Buffer

    ¥[out] result: A napi_value representing a node::Buffer.

如果 API 成功,则返回 napi_ok

¥Returns napi_ok if the API succeeded.

此 API 分配一个 node::Buffer 对象。虽然这仍然是一个完全受支持的数据结构,但在大多数情况下使用 TypedArray 就足够了。

¥This API allocates a node::Buffer object. While this is still a fully-supported data structure, in most cases using a TypedArray will suffice.