UNPKG

@itwin/core-bentley

Version:

Bentley JavaScript core components

92 lines 5.56 kB
/** @packageDocumentation * @module Utils */ import { Id64String } from "./Id"; /** Allows the contents of an [ArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/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. * @public */ export declare class ByteStream { private readonly _view; private readonly _byteOffset; private _curPos; /** Construct a new ByteStream with the read position set to the beginning. * @param buffer The underlying buffer from which data is to be extracted. * @param subView 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, this constructor is private, and [[fromUint8Array]] or [[fromArrayBuffer]] should be used to create a ByteStream. */ private constructor(); /** Construct a new ByteStream for the range of bytes represented by `bytes`, which may be a subset of the range of bytes * represented by the underlying ArrayBuffer. The read position will be set to the beginning of the range of bytes. * @param bytes The Uint8Array from which data is to be extracted. */ static fromUint8Array(bytes: Uint8Array): ByteStream; /** Construct a new ByteStream with the read position set to the beginning. * @param buffer The underlying buffer from which data is to be extracted. * @param subView If defined, specifies the subset of the underlying buffer's data to use. */ static fromArrayBuffer(buffer: ArrayBuffer | SharedArrayBuffer, subView?: { byteOffset: number; byteLength: number; }): ByteStream; /** The number of bytes in this stream */ get length(): number; /** The number of bytes remaining to be read, from [[curPos]] to the end of the stream. */ get remainingLength(): number; /** Returns true if the current read position has been advanced past the end of the stream. This generally indicates that an attempt was made to read more data than is available. * @see [[isAtTheEnd]] */ get isPastTheEnd(): 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. * @see [[isPastTheEnd]]. */ get isAtTheEnd(): boolean; /** The current read position as an index into the stream of bytes. */ get curPos(): number; set curPos(pos: number); /** Adds the specified number of bytes to the current read position */ advance(numBytes: number): boolean; /** Subtracts the specified number of bytes from the current read position */ rewind(numBytes: number): boolean; /** Resets the current read position to the beginning of the stream */ reset(): void; /** Read a unsigned 8-bit integer from the current read position and advance by 1 byte. */ readUint8(): number; /** Read an unsigned 16-bit integer from the current read position and advance by 2 bytes. */ readUint16(): number; /** Read an unsigned 32-bit integer from the current read position and advance by 4 bytes. */ readUint32(): number; /** Read a signed 32-bit integer from the current read position and advance by 4 bytes. */ readInt32(): number; /** Read a 32-bit floating point number from the current read position and advance by 4 bytes. */ readFloat32(): number; /** Read a 64-bit floating point number from the current read position and advance by 8 bytes. */ readFloat64(): number; /** Read an unsigned 64-bit integer from the current read position, advance by 8 bytes, and return the 64-bit value as an Id64String. */ readId64(): Id64String; /** Read an unsigned 24-bit integer from the current read position and advance by 3 bytes. */ readUint24(): number; /** Read the specified number of bytes beginning at the current read position into a Uint8Array and advance by the specified number of byte. * @param numBytes The number of bytes to read. */ nextBytes(numBytes: number): Uint8Array; /** Read the specified number of bytes at the specified offset without changing the read position. */ readBytes(readPos: number, numBytes: number): Uint8Array; /** Read the specified number of unsigned 32-bit integers from the current read position and advance the read position. */ nextUint32s(numUint32s: number): Uint32Array; /** Returns the underlying array buffer */ get arrayBuffer(): ArrayBuffer | SharedArrayBuffer; private read; } //# sourceMappingURL=ByteStream.d.ts.map