napi_create_buffer_copy
napi_status napi_create_buffer_copy(napi_env env,
size_t length,
const void* data,
void** result_data,
napi_value* result) [in] env:调用该 API 时所处的环境。[in] size:输入缓冲区的字节大小(应与新缓冲区的大小相同)。[in] data:指向要复制的底层缓冲区的原始指针。[out] result_data:指向新Buffer的底层数据缓冲区的指针。通过传入NULL,可以选择忽略result_data。[out] result:一个表示node::Buffer的napi_value。
如果 API 成功,则返回 napi_ok。
【Returns napi_ok if the API succeeded.】
这个 API 会分配一个 node::Buffer 对象,并用从传入缓冲区复制的数据初始化它。虽然这仍然是一个完全支持的数据结构,但在大多数情况下使用 TypedArray 就足够了。
【This API allocates a node::Buffer object and initializes it with data copied
from the passed-in buffer. While this is still a fully-supported data
structure, in most cases using a TypedArray will suffice.】