ByteStream Class

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 'read' and taking no arguments 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. Deprecated  
advance(numBytes: number): boolean Adds the specified number of bytes to the current read position  
nextBytes(numBytes: number): Uint8Array Read the specified number of bytes beginning at the current read position into a Uint8Array and advance by the specified number of byte.  
nextUint32s(numUint32s: number): Uint32Array Read the specified number of unsigned 32-bit integers from the current read position and advance the read position.  
readBytes(readPos: number, numBytes: number): Uint8Array Read the specified number of bytes at the specified offset without changing the read position.  
readFloat32(): number Read a 32-bit floating point number from the current read position and advance by 4 bytes.  
readFloat64(): number Read a 64-bit floating point number from the current read position and advance by 8 bytes.  
readId64(): string Read an unsigned 64-bit integer from the current read position, advance by 8 bytes, and return the 64-bit value as an Id64String.  
readInt32(): number Read a signed 32-bit integer from the current read position and advance by 4 bytes.  
readUint16(): number Read an unsigned 16-bit integer from the current read position and advance by 2 bytes.  
readUint24(): number Read an unsigned 24-bit integer from the current read position and advance by 3 bytes.  
readUint32(): number Read an unsigned 32-bit integer from the current read position and advance by 4 bytes.  
readUint8(): number Read a unsigned 8-bit integer from the current read position and advance by 1 byte.  
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  
fromArrayBuffer(buffer: ArrayBuffer | SharedArrayBuffer, subView?: { byteLength: number, byteOffset: number }): ByteStream Static Construct a new ByteStream with the read position set to the beginning.  
fromUint8Array(bytes: Uint8Array): ByteStream Static Construct a new ByteStream for the range of bytes represented by bytes, which may be a subset of the range of bytes  

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.  
isAtTheEnd Accessor ReadOnly boolean Returns true if the current read position has advanced precisely to the end of the stream, indicating all of the data has been consumed.  
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    
nextFloat64 Accessor ReadOnly number    
nextId64 Accessor ReadOnly string    
nextInt32 Accessor ReadOnly number    
nextUint16 Accessor ReadOnly number    
nextUint24 Accessor ReadOnly number    
nextUint32 Accessor ReadOnly number    
nextUint8 Accessor ReadOnly number    
remainingLength Accessor ReadOnly number The number of bytes remaining to be read, from curPos to the end of the stream.  

Defined in

Last Updated: 17 December, 2024