Create a DataView from a Uint8Array. This is a convenience
function that avoids having to create a DataView manually, which
requires passing the byteOffset and byteLength parameters every time.
Not passing the byteOffset and byteLength parameters can result in
unexpected behavior when the Uint8Array is a view of a larger
ArrayBuffer, e.g., when using Uint8Array.subarray.
This function also supports Node.js Buffers.
Example
constbytes = newUint8Array([1, 2, 3]);
// This is equivalent to: // const dataView = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength); constdataView = createDataView(bytes);
Create a DataView from a Uint8Array. This is a convenience function that avoids having to create a DataView manually, which requires passing the
byteOffset
andbyteLength
parameters every time.Not passing the
byteOffset
andbyteLength
parameters can result in unexpected behavior when the Uint8Array is a view of a larger ArrayBuffer, e.g., when using Uint8Array.subarray.This function also supports Node.js Buffers.
Example
Returns
The DataView.