@kayahr/wastelib
    Preparing search index...

    Class BinaryReader

    Reader for binary data. Supports reading single bits, bytes, characters and strings and more.

    Index

    Constructors

    • Creates a new binary reader for the given data.

      Parameters

      • data: ArrayLike<number>

        The data array to read from.

      • offset: number = 0

        Optional start offset. Defaults to 0.

      • size: number = data.length

        Optional maximum number of bytes to read from data array. Defaults to size of data array.

      Returns BinaryReader

    Methods

    • Returns the current bit index.

      Returns number

      The current bit index.

    • Returns the current byte index.

      Returns number

      The current byte index.

    • Checks if there is more data to read. If this method returns false then there is no more data and the next read operation results in an errors.

      Returns boolean

      True if there is still data to read, false if not.

    • Reads a single bit and returns it.

      Returns number

      The read bit.

    • Reads a single character and returns it.

      Returns string

      The read character.

    • Reads a string with the given length and returns it.

      Parameters

      • len: number

      Returns string

      The read string.

    • Reads an unsigned 16 bit value and returns it.

      Returns number

      The read value.

    • Reads an unsigned 32 bit value and returns it.

      Returns number

      The read value.

    • Reads an unsigned 8 bit value (byte) and returns it.

      Returns number

      The read value.

    • Reads the specified number of unsigned 8 bit values and returns it.

      Parameters

      • len: number

        The number of bytes to read.

      Returns number[]

      The read bytes.

    • Synchronizes the reader so it points to a full byte if it currently doesn't.

      Returns void