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] env: The environment that the API is invoked under.

  • [in] valuenapi_value 代表被查询的 node::Buffer

    ¥[in] value: napi_value representing the node::Buffer being queried.

  • [out] datanode::Buffer 的底层数据缓冲区。如果长度是 0,这可能是 NULL 或任何其他指针值。

    ¥[out] data: The underlying data buffer of the node::Buffer. If length is 0, this may be NULL or any other pointer value.

  • [out] length:底层数据缓冲区的字节长度。

    ¥[out] length: Length in bytes of the underlying data buffer.

如果 API 成功,则返回 napi_ok

¥Returns napi_ok if the API succeeded.

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

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

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

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