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 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. While this is still a
fully-supported data structure, in most cases using a TypedArray
will suffice.