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] env
: The environment that the API is invoked under. -
[in] size
:输入缓冲区的大小(以字节为单位)(应与新缓冲区的大小相同)。¥
[in] size
: Size in bytes of the input buffer (should be the same as the size of the new buffer). -
[in] data
:指向要从中复制的基础缓冲区的原始指针。¥
[in] data
: Raw pointer to the underlying buffer to copy from. -
[out] result_data
:指向新Buffer
的基础数据缓冲区的指针。result_data
可以选择性地通过传递NULL
来忽略。¥
[out] result_data
: Pointer to the newBuffer
's underlying data buffer.result_data
can optionally be ignored by passingNULL
. -
[out] result
:一个napi_value
代表一个node::Buffer
。¥
[out] result
: Anapi_value
representing anode::Buffer
.
如果 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.