constructor Method

Deprecated  in 3.x. Use fromUint8Array or fromArrayBuffer.

Construct a new ByteStream with the read position set to the beginning.

ByteStream(buffer: ArrayBuffer | SharedArrayBuffer, subView?: { byteLength: number, byteOffset: number }): ByteStream

Parameter Type Description
buffer ArrayBuffer | SharedArrayBuffer The underlying buffer from which data is to be extracted.
subView { byteLength: number, byteOffset: number } If defined, specifies the subset of the underlying buffer's data to use.
This constructor is subject to two common mistakes:

1. Given bytes: Uint8Array, new ByteStream(bytes) will compile but at run-time will produce an error asserting that
the DataView constructor requires an ArrayBuffer. The correct usage is new ByteStream(bytes.buffer).
2. Given bytes: Uint8Array, new ByteStream(bytes.buffer) creates a stream for the entire range of bytes represented by the underlying
ArrayBuffer. If bytes represents only a sub-range of the underlying buffer's data, the results will be unexpected unless the optional subView
argument is supplied, with correct offset and length.

For both of the above reasons, prefer to use fromUint8Array.

Returns - ByteStream

Defined in

Last Updated: 21 November, 2024