a BinaryStream can be use to perform sequential read or write inside a buffer. The BinaryStream maintains a cursor up to date as the caller operates on the stream using the various read/write methods. It uses the Little Endian It uses the Little Endian convention.

data can either be:

  • a Buffer , in this case the BinaryStream operates on this Buffer
  • null , in this case a BinaryStream with 1024 bytes is created
  • any data , in this case the object is converted into a binary buffer.

example:

var stream = new BinaryStream(32)

Constructors

  • Parameters

    • data: undefined | number | Buffer

    Returns BinaryStream

Properties

buffer: Buffer
length: number

the current position inside the buffer

maxByteStringLength: number
maxStringLength: number

Methods

  • Parameters

    • length: number

    Returns Uint8Array

  • read a single signed byte (8 bits) from the stream.

    Returns number

    the value read

  • read a byte stream to the stream. The method reads the length of the byte array from the stream as a 32 bits integer before reading the byte stream.

    Returns null | Buffer

  • read a single 64-bit floating point number from the stream.

    Returns number

  • read a single 32-bit floating point number from the stream.

    Returns number

  • read a single signed 16-bit integer from the stream.

    Returns number

  • Returns number

  • read a single signed 32-bit integer from the stream.

    Returns number

  • Returns null | string

  • read a single unsigned 16-bit integer from the stream.

    Returns number

  • read a single unsigned 32-bit integer from the stream.

    Returns number

  • read a single unsigned byte (8 bits) from the stream.

    Returns number

  • set the cursor to the begining of the stream

    Returns void

  • Parameters

    • arrayBuf: ArrayBuffer

      a buffer or byte array write

    • Optionaloffset: number

      the offset position (default =0)

    • Optionallength: number

      the number of byte to write

    Returns void

  • write a byte stream to the stream. The method writes the length of the byte array into the stream as a 32 bits integer before the byte stream.

    Parameters

    • buf: Buffer

      the buffer to write.

    Returns void

  • write a single 64 bit floating number to the stream.

    Parameters

    • value: number

      the value to write

    Returns void

  • write a single 32 bit floating number to the stream.

    Parameters

    • value: number

      the value to write

    Returns void

  • write a single 16 bit signed integer to the stream.

    Parameters

    • value: number

      the value to write

    Returns void

  • write a single signed byte (8 bits) to the stream. value must be in the range of [-127,128]

    Parameters

    • value: number

      the value to write

    Returns void

  • write a single 32 bit signed integer to the stream.

    Parameters

    • value: number

      the value to write

    Returns void

  • Parameters

    • value: null | string

    Returns void

  • write a single 16 bit unsigned integer to the stream.

    Parameters

    • value: number

      the value to write

    Returns void

  • write a single 32 bit unsigned integer to the stream.

    Parameters

    • value: number

      the value to write

    Returns void

  • write a single unsigned byte (8 bits) to the stream.

    Parameters

    • value: number

      the value to write

    Returns void