ByteStream Class

Beta  

Allows the contents of an ArrayBuffer to be consumed sequentially using methods to extract data of a particular type from the bytes beginning at the current read position. Methods and properties beginning with 'next' consume data at the current read position and advance it by the size of the data read. The read position can also be directly adjusted by the caller.

Methods

Name Description
constructor(buffer: ArrayBuffer | SharedArrayBuffer, subView?: { byteLength: number, byteOffset: number }): ByteStream Construct a new ByteStream with the read position set to the beginning.  
advance(numBytes: number): boolean Add the specified number of bytes to the current read position  
nextBytes(numBytes: number): Uint8Array Read the next numBytes bytes into a Uint8Array and advance by numBytes.  
nextUint32s(numUint32s: number): Uint32Array    
readBytes(readPos: number, numBytes: number): Uint8Array Read the specified number of bytes at the specified offset without changing the read position.  
reset(): void Resets the current read position to the beginning of the stream  
rewind(numBytes: number): boolean Subtracts the specified number of bytes from the current read position  

Properties

Name Type Description
arrayBuffer Accessor ReadOnly ArrayBuffer | SharedArrayBuffer Returns the underlying array buffer  
curPos Accessor number The current read position as an index into the stream of bytes  
isPastTheEnd Accessor ReadOnly boolean Returns true if the current read position has been advanced past the end of the stream  
length Accessor ReadOnly number The number of bytes in this stream  
nextFloat32 Accessor ReadOnly number Read a 32-bit floating point number at the current read position and advance by 4 bytes.  
nextFloat64 Accessor ReadOnly number Read a 64-bit floating point number at the current read position and advance by 8 bytes.  
nextId64 Accessor ReadOnly Id64String Read a uint64 at the current read position, advance by 8 bytes, and return the uint64 value as an Id64String.  
nextInt32 Accessor ReadOnly number Read an int32 at the current read position and advance by 4 bytes.  
nextUint16 Accessor ReadOnly number Read a uint16 at the current read position and advance by 2 bytes.  
nextUint32 Accessor ReadOnly number Read a uint32 at the current read position and advance by 4 bytes.  
nextUint8 Accessor ReadOnly number Read a uint8 at the current read position and advance by 1 byte.  

Defined in

Last Updated: 13 June, 2024