napi_get_buffer_info


napi_status napi_get_buffer_info(napi_env env,
                                 napi_value value,
                                 void** data,
                                 size_t* length) 
  • [in] env:调用该 API 时所处的环境。
  • [in] value:表示正在查询的 node::BufferUint8Arraynapi_value
  • [out] datanode::BufferUint8Array 的底层数据缓冲区。如果长度为 0,则此值可能为 NULL 或其他任意指针值。
  • [out] length:底层数据缓冲区的字节长度。

如果 API 成功,则返回 napi_ok

【Returns napi_ok if the API succeeded.】

该方法返回与 napi_get_typedarray_info 相同的 databyte_length。而 napi_get_typedarray_info 也接受 node::Buffer(一个 Uint8Array)作为值。

【This method returns the identical data and byte_length as napi_get_typedarray_info. And napi_get_typedarray_info accepts a node::Buffer (a Uint8Array) as the value too.】

此 API 用于检索 node::Buffer 的底层数据缓冲区及其长度。

【This API is used to retrieve the underlying data buffer of a node::Buffer and its length.】

警告:使用此 API 时请小心,因为如果底层数据缓冲区由虚拟机管理,其生命周期无法保证。

Warning: Use caution while using this API since the underlying data buffer's lifetime is not guaranteed if it's managed by the VM.】