Options
All
  • Public
  • Public/Protected
  • All
Menu

Class IOBuffer

Class for writing and reading binary data

Hierarchy

  • IOBuffer

Index

Constructors

constructor

  • If it's a number, it will initialize the buffer with the number as the buffer's length. If it's undefined, it will initialize the buffer with a default length of 8 Kb. If its an ArrayBuffer, a TypedArray, it will create a view over the underlying ArrayBuffer.

    Parameters

    Returns IOBuffer

Properties

Private _data

_data: DataView

Private _lastWrittenByte

_lastWrittenByte: number

Private _mark

_mark: number = 0

Private _marks

_marks: number[] = []

buffer

buffer: ArrayBuffer

byteLength

byteLength: number

byteOffset

byteOffset: number

length

length: number

littleEndian

littleEndian: boolean = true

offset

offset: number = 0

Methods

Private _updateLastWrittenByte

  • _updateLastWrittenByte(): void

available

  • available(byteLength: number): boolean
  • Checks if the memory allocated to the buffer is sufficient to store more bytes after the offset

    Parameters

    • byteLength: number

    Returns boolean

    Returns true if there is sufficient space and false otherwise

ensureAvailable

  • ensureAvailable(byteLength: number): this
  • Make sure the buffer has sufficient memory to write a given byteLength at the current pointer offset If the buffer's memory is insufficient, this method will create a new buffer (a copy) with a length that is twice (byteLength + current offset)

    Parameters

    • byteLength: number

    Returns this

isBigEndian

  • isBigEndian(): boolean
  • Check if big-endian mode is used for reading and writing multi-byte values

    Returns boolean

    Returns true if big-endian mode is used, false otherwise

isLittleEndian

  • isLittleEndian(): boolean
  • Check if little-endian mode is used for reading and writing multi-byte values

    Returns boolean

    Returns true if little-endian mode is used, false otherwise

mark

  • mark(): this

popMark

  • popMark(): this
  • Pop the last pointer offset from the mark stack, and set the current pointer offset to the popped value

    see

    {@link IOBuffer#pushMark}

    Returns this

pushMark

  • pushMark(): this
  • Push the current pointer offset to the mark stack

    see

    {@link IOBuffer#popMark}

    Returns this

readBoolean

  • readBoolean(): boolean
  • Read a byte and return false if the byte's value is 0, or true otherwise Moves pointer forward

    Returns boolean

readByte

  • readByte(): number

readBytes

  • readBytes(n: number): Uint8Array

readChar

  • readChar(): string

readChars

  • readChars(n?: number): string
  • Read n 1-byte ascii characters and move pointer forward

    Parameters

    • Default value n: number = 1

    Returns string

readFloat32

  • readFloat32(): number

readFloat64

  • readFloat64(): number

readInt16

  • readInt16(): number

readInt32

  • readInt32(): number

readInt8

  • readInt8(): number

readUint16

  • readUint16(): number

readUint32

  • readUint32(): number

readUint8

  • readUint8(): number

reset

  • reset(): this
  • Move the pointer back to the last pointer offset set by mark

    see

    {@link IOBuffer#mark}

    Returns this

rewind

  • rewind(): this

seek

  • seek(offset: number): this

setBigEndian

  • setBigEndian(): this

setLittleEndian

  • setLittleEndian(): this

skip

  • skip(n: number): this

toArray

  • toArray(): Uint8Array
  • Export a Uint8Array view of the internal buffer. The view starts at the byte offset and its length is calculated to stop at the last written byte or the original length.

    Returns Uint8Array

writeBoolean

  • writeBoolean(value?: boolean): this
  • Write 0xff if the passed value is truthy, 0x00 otherwise

    Parameters

    • Default value value: boolean = false

    Returns this

writeByte

  • writeByte(value: number): this

writeBytes

  • writeBytes(bytes: number[] | Uint8Array): this

writeChar

  • writeChar(str: string): this
  • Write the charCode of the passed string's first character to the current pointer offset

    Parameters

    • str: string

      The character to set

    Returns this

writeChars

  • writeChars(str: string): this
  • Write the charCodes of the passed string's characters to the current pointer offset

    Parameters

    • str: string

    Returns this

writeFloat32

  • writeFloat32(value: number): this
  • Write a 32-bit floating number at the current pointer offset

    Parameters

    • value: number

      The value to set

    Returns this

writeFloat64

  • writeFloat64(value: number): this
  • Write a 64-bit floating number at the current pointer offset

    Parameters

    • value: number

    Returns this

writeInt16

  • writeInt16(value: number): this

writeInt32

  • writeInt32(value: number): this
  • Write a 32-bit signed integer at the current pointer offset

    Parameters

    • value: number

    Returns this

writeInt8

  • writeInt8(value: number): this

writeUint16

  • writeUint16(value: number): this

writeUint32

  • writeUint32(value: number): this
  • Write a 32-bit unsigned integer at the current pointer offset

    Parameters

    • value: number

      The value to set

    Returns this

writeUint8

  • writeUint8(value: number): this

Generated using TypeDoc