a byte buffer implementing fuman readable/writable streams

Implements

Constructors

Accessors

Methods

  • Explicitly dispose of the buffer that was returned by the last call to writeSync.

    If less than bytes bytes were written to the buffer, the number of bytes that were written must be passed as the written argument.

    Parameters

    • Optionalwritten: number

    Returns void

  • Read data from the underlying source into the provided Uint8Array, up to the length of the array, and return the number of bytes read.

    If there are no bytes available currently, the implementation is supposed to wait until at least one byte is available, and only then resolve the promise. Resolving the promise with a zero-length Uint8Array is marking the end of the source.

    Parameters

    • into: Uint8Array

    Returns Promise<number>

    Uint8Array containing the bytes that were read.

  • Read the specified number of bytes from the source and return them as a Uint8Array.

    The returned Uint8Array:

    • may be a view into a larger buffer
    • is only valid until the next call to readSync
    • may be smaller than the requested number of bytes if the end of the source is reached.

    these constraints allow for more efficient zero-copy implementations in many cases

    Parameters

    • bytes: number

      The number of bytes to read

    Returns Uint8Array

    Uint8Array containing the bytes that were read.

  • get the "result" of the buffer, i.e. everything that has been written so far, but not yet read

    Note: this method returns a view into the underlying buffer, and does advance the read cursor

    Returns Uint8Array

  • Write bytes to the underlying stream, resolving once the write is complete

    Parameters

    • bytes: Uint8Array

    Returns Promise<void>

  • Write the specified number of bytes to the underlying source.

    The implementation is supposed to make sure there are at least bytes bytes available in the underlying source and return a Uint8Array that can be written to. The returned Uint8Array must be valid at least until the next call to writeSync or disposeWriteSync.

    If the caller writes less than bytes bytes to the returned Uint8Array, disposeWriteSync must be called with the number of bytes that were actually written.

    Parameters

    • size: number

    Returns Uint8Array

    Uint8Array of length bytes that can be written to