Options
All
  • Public
  • Public/Protected
  • All
Menu

Class BufferInputStream

Sequential reading of values from a given Buffer. Loosely inspired by Java's ByteArrayInputStream.

Hierarchy

  • BufferInputStream

Implements

  • any

Index

Constructors

constructor

  • Construct an input stream from a Buffer

    Parameters

    • buffer: Buffer

      The source Buffer.

    Returns BufferInputStream

Properties

buffer

buffer: Buffer

The buffer to read from

count

count: number

The number of bytes in the buffer

pos

pos: number

The current reading position

Methods

hasRemaining

  • hasRemaining(): boolean
  • Indicates if there are remaining bytes to be found

    Returns boolean

    true if there are remaining bytes

peek

  • peek(): number
  • Returns the next byte in the input stream, without extracting it.

    Returns number

    The byte that was read, or -1 if the stream is exhausted.

read

  • read(): number
  • Read one byte.

    Returns number

    The byte that was read, or -1 if the stream is exhausted.

readInt32

  • readInt32(): number
  • Read a signed, big-endian 32-bit integer.

    Returns number

    the number that has been read.

readInt64

  • readInt64(): Long
  • Read a signed, big-endian 64-bit long.

    Returns Long

    the number that has been read.

readInt8

  • readInt8(): number
  • Read a signed 8-bit integer.

    Returns number

    the number that has been read.

readMany

  • readMany(length: number): Buffer
  • Read a specified amount of bytes.

    If the length is greater than the remaining number of bytes, this function will read up to the last available byte in the buffer.

    throws

    will throw an OutOfBounds error if length is a negative number.

    Parameters

    • length: number

      the number of bytes you wish to read.

    Returns Buffer

    the bytes that have been read

readUInt64

  • readUInt64(): Long
  • Read an unsigned, big-endian 64-bit long.

    Returns Long

    the number that has been read.

readUntil

  • readUntil(delim: number): Buffer
  • Read until a specified byte (delimiter) is found.

    The buffer position is updated to point to just after the delimiter.

    If the delimiter can't be found, then return all bytes until the end of the buffer.

    Parameters

    • delim: number

      the delimiter byte

    Returns Buffer

    a buffer containing the bytes up to but not including the delimiter byte.