Reads all kind of data values from the specified source.

Constructors

Methods

  • Returns number

    the number of bits that have been read so far.

  • Returns number

    the number of bytes that have been read so far.

  • Returns the default encoding of the reader.

    Returns string

    the default encoding used when no encoding is specified as parameter to the various string read methods.

  • Returns the default endianness of the reader.

    Returns Endianness

    the default endianness used when no endianness is specified as parameter to the various read methods.

  • Executes the given operation as a look-ahead operation. So any reading from the reader is a look-ahead and the stream position will be reset when operation is finished. Look-ahead operations can be nested.

    Note that while reading data in a look-ahead operation buffers read from the stream pile up in memory because it is not possible to seek in a stream. So the only way to rewind to the previous position in the stream is to remember all the buffers read since then. So keep look-ahead operations short so in the best case the operation takes place in the same or the next buffer.

    Type Parameters

    • T

    Parameters

    • operation: (commit: (values?: number, bitsPerValue?: number) => void) => Promise<T>

      The look-ahead operation to perform.

    Returns Promise<T>

  • Reads a signed 64 bit value.

    Parameters

    • endianness: Endianness = ...

      Optional endianness. Defaults to endianness the reader was configured with.

    Returns Promise<null | bigint>

  • Reads an array of signed 64 bit values.

    Parameters

    • buffer: BigInt64Array

      The buffer to write the read bytes to.

    • Optionaloptions: ReadMultiByteArrayOptions

      Optional read array option.

    Returns Promise<number>

    the number of read 16 bit values. 0 when end of stream is reached or 0 bytes were requested to read.

  • Reads a unsigned 64 bit value.

    Parameters

    • endianness: Endianness = ...

      Optional endianness. Defaults to endianness the reader was configured with.

    Returns Promise<null | bigint>

  • Reads an array of unsigned 64 bit values.

    Parameters

    • buffer: BigUint64Array

      The buffer to write the read bytes to.

    • options: ReadMultiByteArrayOptions = {}

      Optional read array option.

    Returns Promise<number>

    the number of read 16 bit values. 0 when end of stream is reached or 0 bytes were requested to read.

  • Reads and returns a single bit from the stream.

    Returns Promise<null | number>

    the read bit. Null if end of stream has been reached.

  • Reads the given number of bits and returns them as a number array.

    TODO This can be optimized by reading the bits directly from the buffer instead of asynchronously reading bit by bit.

    Parameters

    • numBits: number

      The number of bits to read.

    Returns Promise<number[]>

    The read bits. Empty array when end of stream has been reached without reading any bit.

  • Reads a signed 16 bit value.

    Parameters

    • endianness: Endianness = ...

      Optional endianness. Defaults to endianness the reader was configured with.

    Returns Promise<null | number>

  • Reads an array of signed 16 bit values.

    Parameters

    • buffer: Int16Array

      The buffer to write the read bytes to.

    • Optionaloptions: ReadMultiByteArrayOptions

      Optional read array option.

    Returns Promise<number>

    the number of read 16 bit values. 0 when end of stream is reached or 0 bytes were requested to read.

  • Reads a signed 32 bit value.

    Parameters

    • endianness: Endianness = ...

      Optional endianness. Defaults to endianness the reader was configured with.

    Returns Promise<null | number>

  • Reads an array of signed 32 bit values.

    Parameters

    • buffer: Int32Array

      The buffer to write the read bytes to.

    • Optionaloptions: ReadMultiByteArrayOptions

      Optional read array option.

    Returns Promise<number>

    the number of read 16 bit values. 0 when end of stream is reached or 0 bytes were requested to read.

  • Reads and returns an signed 8 bit value.

    Returns Promise<null | number>

    the read value. Null if end of stream has been reached.

  • Reads an array of signed 8 bit values.

    Parameters

    • buffer: Int8Array

      The buffer to write the read bytes to.

    • offset: number = 0

      Offset within the buffer to start writing to. Defaults to 0.

    • size: number = ...

      Number of bytes to read. Defaults to buffer size minus offset.

    Returns Promise<number>

    the number of read bytes. 0 when end of stream is reached or 0 bytes were requested to read.

  • Reads a line from the stream. EOL marker can be defined in the options and by default stops at CRLF or LF without including the EOL marker in the returned string.

    Parameters

    Returns Promise<null | string>

    the read line. Null when end of stream is reached.

  • Reads a null-terminated string from the stream.

    Parameters

    Returns Promise<null | string>

    the read line. Null when end of stream is reached.

  • Reads a string from the stream.

    Parameters

    • size: number

      The maximum number of bytes to read. Only in ASCII encoding this is the same as the length of the string. In other encodings the returned string may be shorter.

    • encoding: string = ...

      The encoding. Defaults to encoding the reader was configured with.

    Returns Promise<string>

    the read string. May be smaller than requested size. Empty when end of stream is reached.

  • Reads an unsigned 16 bit value.

    Parameters

    • endianness: Endianness = ...

      Optional endianness. Defaults to endianness the reader was configured with.

    Returns Promise<null | number>

  • Reads an array of unsigned 16 bit values.

    Parameters

    • buffer: Uint16Array

      The buffer to write the read bytes to.

    • options: ReadMultiByteArrayOptions = {}

      Optional read array option.

    Returns Promise<number>

    the number of read 16 bit values. 0 when end of stream is reached or 0 bytes were requested to read.

  • Reads an unsigned 32 bit value.

    Parameters

    • endianness: Endianness = ...

      Optional endianness. Defaults to endianness the reader was configured with.

    Returns Promise<null | number>

  • Reads an array of unsigned 32 bit values.

    Parameters

    • buffer: Uint32Array

      The buffer to write the read bytes to.

    • options: ReadMultiByteArrayOptions = {}

      Optional read array option.

    Returns Promise<number>

    the number of read 16 bit values. 0 when end of stream is reached or 0 bytes were requested to read.

  • Reads and returns an unsigned 8 bit value.

    Returns Promise<null | number>

    the read value. Null if end of stream has been reached.

  • Reads an array of unsigned 8 bit values.

    Parameters

    • buffer: Uint8Array | Uint8ClampedArray

      The buffer to write the read bytes to.

    • offset: number = 0

      Offset within the buffer to start writing to. Defaults to 0.

    • size: number = ...

      Number of bytes to read. Defaults to buffer size minus offset.

    Returns Promise<number>

    the number of read bytes. 0 when end of stream is reached or 0 bytes were requested to read.

  • Skips the given number of bits. This is not the same as simply reading the given number of bits and ignoring the read data. Instead it is optimized to first skip as many bits as needed to get to a byte boundary then skipping full bytes inside current buffer, optionally fetching new buffers and finally skipping the remaining number of bits.

    Parameters

    • bits: number

      The number of bits to skip.

    Returns Promise<number>

    The actual number of skipped bits. Will be lower than given number if end of stream has been reached.

  • Skips the given number of bytes. This is not the same as simply reading the given number of bytes and ignoring the read data. Instead it is optimized to first skip as many bits as needed to get to a byte boundary then skipping full bytes inside the current buffer, optionally fetching new buffers and finally skipping the remaining bits.

    Actually this is the same as calling skipBits with the number of bytes converted to the number of bits.

    Parameters

    • bytes: number

      The number of bytes to skip.

    Returns Promise<number>

    The actual number of fully skipped bytes (not counting partially skipped bytes). Will be lower than given number if end of stream has been reached.