iobuffer
    Preparing search index...

    Class IOBuffer

    Index

    Constructors

    • Create a new IOBuffer.

      Parameters

      • data: InputData = defaultByteLength

        The data to construct the IOBuffer with. If data is a number, it will be the new buffer's length
        If data is undefined, the buffer will be initialized with a default length of 8Kb
        If data is an ArrayBuffer, SharedArrayBuffer, an ArrayBufferView (Typed Array), an IOBuffer instance, or a Node.js Buffer, a view will be created over the underlying ArrayBuffer.

      • options: IOBufferOptions = {}

        An object for the options.

      Returns IOBuffer

      A new IOBuffer instance.

    Properties

    buffer: ArrayBufferLike

    Reference to the internal ArrayBuffer object.

    byteLength: number

    Byte length of the internal ArrayBuffer.

    byteOffset: number

    Byte offset of the internal ArrayBuffer.

    length: number

    Byte length of the internal ArrayBuffer.

    offset: number

    The current offset of the buffer's pointer.

    Methods

    • Checks if the memory allocated to the buffer is sufficient to store more bytes after the offset.

      Parameters

      • byteLength: number = 1

        The needed memory in bytes.

      Returns boolean

      true if there is sufficient space and false otherwise.

    • Move the pointer n bytes backward.

      Parameters

      • n: number = 1

        Number of bytes to move back.

      Returns this

      This.

    • Read the next n bytes, return a string decoded with encoding and move pointer forward by n bytes. If no encoding is passed, the function is equivalent to

      Parameters

      • n: number = 1

        Number of bytes to read.

      • encoding: string = 'utf8'

        The encoding to use. Default is 'utf8'.

      Returns string

      The decoded string.

    • 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 = 1

        The needed memory in bytes.

      Returns this

      This.

    • Get the total number of bytes written so far, regardless of the current offset.

      Returns number

      • Total number of bytes.
    • Check if big-endian mode is used for reading and writing multi-byte values.

      Returns boolean

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

    • Check if little-endian mode is used for reading and writing multi-byte values.

      Returns boolean

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

    • Pop the last pointer offset from the mark stack, and set the current pointer offset to the popped value.

      Returns this

      This.

    • Creates an array of corresponding to the type type and size size. For example type uint8 will create a Uint8Array.

      Type Parameters

      • T extends
            | "uint8"
            | "int8"
            | "int16"
            | "uint16"
            | "int32"
            | "uint32"
            | "uint64"
            | "int64"
            | "float32"
            | "float64"

      Parameters

      • size: number

        size of the resulting array

      • type: T

        number type of elements to read

      Returns InstanceType<
          {
              float32: Float32ArrayConstructor;
              float64: Float64ArrayConstructor;
              int16: Int16ArrayConstructor;
              int32: Int32ArrayConstructor;
              int64: BigInt64ArrayConstructor;
              int8: Int8ArrayConstructor;
              uint16: Uint16ArrayConstructor;
              uint32: Uint32ArrayConstructor;
              uint64: BigUint64ArrayConstructor;
              uint8: Uint8ArrayConstructor;
          }[T],
      >

      The read array.

    • Read a 64-bit signed integer number and move pointer forward by 8 bytes.

      Returns bigint

      The read value.

    • Read a 64-bit unsigned integer number and move pointer forward by 8 bytes.

      Returns bigint

      The read value.

    • Read a byte and return false if the byte's value is 0, or true otherwise. Moves pointer forward by one byte.

      Returns boolean

      The read boolean.

    • Read n bytes and move pointer forward by n bytes.

      Parameters

      • n: number = 1

        Number of bytes to read.

      Returns Uint8Array

      The read bytes.

    • Read a 1-byte ASCII character and move pointer forward by 1 byte.

      Returns string

      The read character.

    • Read n 1-byte ASCII characters and move pointer forward by n bytes.

      Parameters

      • n: number = 1

        Number of characters to read.

      Returns string

      The read characters.

    • Read a 32-bit floating number and move pointer forward by 4 bytes.

      Returns number

      The read value.

    • Read a 64-bit floating number and move pointer forward by 8 bytes.

      Returns number

      The read value.

    • Read a 16-bit signed integer and move pointer forward by 2 bytes.

      Returns number

      The read value.

    • Read a 32-bit signed integer and move pointer forward by 4 bytes.

      Returns number

      The read value.

    • Read a signed 8-bit integer and move pointer forward by 1 byte.

      Returns number

      The read byte.

    • Read a 16-bit unsigned integer and move pointer forward by 2 bytes.

      Returns number

      The read value.

    • Read a 32-bit unsigned integer and move pointer forward by 4 bytes.

      Returns number

      The read value.

    • Read an unsigned 8-bit integer and move pointer forward by 1 byte.

      Returns number

      The read byte.

    • Read the next n bytes, return a UTF-8 decoded string and move pointer forward by n bytes.

      Parameters

      • n: number = 1

        Number of bytes to read.

      Returns string

      The decoded string.

    • Move the pointer offset back to 0.

      Returns this

      This.

    • Move the pointer to the given offset.

      Parameters

      • offset: number

        The offset to move to.

      Returns this

      This.

    • Switches to big-endian mode for reading and writing multi-byte values.

      Returns this

      This.

    • Set little-endian mode for reading and writing multi-byte values.

      Returns this

      This.

    • Move the pointer n bytes forward.

      Parameters

      • n: number = 1

        Number of bytes to skip.

      Returns this

      This.

    • 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

      A new Uint8Array view.

    • Write value as a 64-bit signed bigint and move pointer forward by 8 bytes.

      Parameters

      • value: bigint

        The value to write.

      Returns this

      This.

    • Write value as a 64-bit unsigned bigint and move pointer forward by 8 bytes.

      Parameters

      • value: bigint

        The value to write.

      Returns this

      This.

    • Write 0xff if the passed value is truthy, 0x00 otherwise and move pointer forward by 1 byte.

      Parameters

      • value: unknown

        The value to write.

      Returns this

      This.

    • Write all elements of bytes as uint8 values and move pointer forward by bytes.length bytes.

      Parameters

      • bytes: ArrayLike<number>

        The array of bytes to write.

      Returns this

      This.

    • Write the charCode of str's first character as an 8-bit unsigned integer and move pointer forward by 1 byte.

      Parameters

      • str: string

        The character to write.

      Returns this

      This.

    • Write the charCodes of all str's characters as 8-bit unsigned integers and move pointer forward by str.length bytes.

      Parameters

      • str: string

        The characters to write.

      Returns this

      This.

    • Write value as a 32-bit floating number and move pointer forward by 4 bytes.

      Parameters

      • value: number

        The value to write.

      Returns this

      This.

    • Write value as a 64-bit floating number and move pointer forward by 8 bytes.

      Parameters

      • value: number

        The value to write.

      Returns this

      This.

    • Write value as a 16-bit signed integer and move pointer forward by 2 bytes.

      Parameters

      • value: number

        The value to write.

      Returns this

      This.

    • Write value as a 32-bit signed integer and move pointer forward by 4 bytes.

      Parameters

      • value: number

        The value to write.

      Returns this

      This.

    • Write value as an 8-bit signed integer and move pointer forward by 1 byte.

      Parameters

      • value: number

        The value to write.

      Returns this

      This.

    • Write value as a 16-bit unsigned integer and move pointer forward by 2 bytes.

      Parameters

      • value: number

        The value to write.

      Returns this

      This.

    • Write value as a 32-bit unsigned integer and move pointer forward by 4 bytes.

      Parameters

      • value: number

        The value to write.

      Returns this

      This.

    • Write value as an 8-bit unsigned integer and move pointer forward by 1 byte.

      Parameters

      • value: number

        The value to write.

      Returns this

      This.

    • UTF-8 encode and write str to the current pointer offset and move pointer forward according to the encoded length.

      Parameters

      • str: string

        The string to write.

      Returns this

      This.