Constructors

  • Creates a new EncodeBuffer with a specified initial size/buffer

    Parameters

    • init: number | Uint8Array
    • Optionalcontext: $.Context

    Returns $.EncodeBuffer

Properties

array: Uint8Array
asyncCount: number
asyncPromise: Promise<void>
asyncResolve: ((value: void | Promise<void>) => void)
context: $.Context
finishedArrays: (Uint8Array | $.EncodeBuffer)[]
finishedSize: number
index: number
queuedArrays: Uint8Array[]
view: DataView

Methods

  • Pushes the data written in array to finishedArrays. Leaves the buffer in an invalid state -- array and index must be updated.

    Returns void

  • Copies all data from finishedArrays into fullArray

    Parameters

    • fullArray: Uint8Array
    • index: number

    Returns number

  • Sets array and updates view

    Parameters

    • array: Uint8Array

    Returns void

  • Creates a sub-buffer that can be written into later to insert data into the middle of the array. .close() must be called after the cursor is done being written into. The cursor should not be used after .close() is called. If the cursor will be written into asynchronously, the buffer must be held open with .waitFor().

    Parameters

    • length: number

    Returns $.EncodeBuffer & {
        close(): void;
    }

  • Finishes the current array, and returns a Uint8Array containing everything written. The EncodeBuffer is left in an undefined state, and should not be used afterwards. Throws if asynchronous writes are still pending.

    Returns Uint8Array

  • Finishes the current array, and returns a Uint8Array containing everything written. The EncodeBuffer is left in an undefined state, and should not be used afterwards.

    Returns Promise<Uint8Array>

  • Inserts a Uint8Array at the current position in the buffer. This does not consume any of the pre-allocated space.

    Parameters

    • buffer: Uint8Array

    Returns void

  • Finishes the current array and resumes writing on the previous array. Must be called after .pushAlloc().

    Returns void

  • Allocates more space in the EncodeBuffer. .popAlloc() must be called after this space is used.

    Parameters

    • size: number

    Returns void

  • Consumes length allocated bytes without writing anything, and returns the skipped subarray. Anything written into the returned array will not affect the buffer, except if it is later reincorporated e.g. via .insertArray(). Rather niche.

    Parameters

    • length: number

    Returns Uint8Array

  • Immediately invokes the callback, and holds the buffer open until the returned promise resolves.

    Parameters

    • fn: (() => Promise<void>)
        • (): Promise<void>
        • Returns Promise<void>

    Returns void

  • Invokes the callback once buffer's async tasks finish, and holds this buffer open until the callback returns.

    Parameters

    Returns void

  • Creates a sub-buffer that can be written into asynchronously. The buffer passed to the callback should not be used after the returned promise resolves.

    Parameters

    • length: number
    • fn: ((buffer: $.EncodeBuffer) => Promise<void>)
        • (buffer): Promise<void>
        • Parameters

          Returns Promise<void>

    Returns void