Skip to content
napi-bindings

Search

Search pages, projects and the Node-API reference

Browse Node-APIshow

napi_create_typedarray

functionv1js_native_api.h

This API creates a JavaScript TypedArray object over an existing ArrayBuffer or SharedArrayBuffer.

napi_status napi_create_typedarray(napi_env env,
                                   napi_typedarray_type type,
                                   size_t length,
                                   napi_value arraybuffer,
                                   size_t byte_offset,
                                   napi_value* result)
  • [in] env: The environment that the API is invoked under.
  • [in] type: Scalar datatype of the elements within the TypedArray.
  • [in] length: Number of elements in the TypedArray.
  • [in] arraybuffer: ArrayBuffer or SharedArrayBuffer underlying the typed array.
  • [in] byte_offset: The byte offset within the ArrayBuffer or SharedArrayBuffer from which to start projecting the TypedArray.
  • [out] result: A napi_value representing a JavaScript TypedArray.

Returns napi_ok if the API succeeded.

This API creates a JavaScript TypedArray object over an existing ArrayBuffer or SharedArrayBuffer. TypedArray objects provide an array-like view over an underlying data buffer where each element has the same underlying binary scalar datatype.

It is required that (length * size_of_element) + byte_offset is less than or equal to the size in bytes of the ArrayBuffer or SharedArrayBuffer passed in. If not, a RangeError exception is raised.

For element sizes greater than 1, byte_offset is required to be a multiple of the element size. If not, a RangeError exception is raised.

JavaScript TypedArray objects are described in Section TypedArray objects of the ECMAScript Language Specification.

View in the official Node.js documentation