Interface WriteableStream<T>

A interface that emulates the API shape of a node.js writeable stream for use in desktop and web environments.

interface WriteableStream<T> {
    destroy(): void;
    end(result?): void;
    error(error): void;
    on(event, callback): void;
    on(event, callback): void;
    on(event, callback): void;
    pause(): void;
    removeListener(event, callback): void;
    resume(): void;
    write(data): void | Promise<void>;
}

Type Parameters

  • T

Hierarchy (view full)

Methods

  • Signals the end of the stream to the consumer. If the result is not an error, will trigger the on('data') event listener if the stream is flowing and buffer the data otherwise until the stream is flowing.

    In case of an error, the on('error') event will be used if the stream is flowing.

    Parameters

    • Optional result: Error | T

    Returns void

  • Signals an error to the consumer of the stream via the on('error') handler if the stream is flowing.

    Parameters

    • error: Error

    Returns void

  • The 'data' event is emitted whenever the stream is relinquishing ownership of a chunk of data to a consumer.

    Parameters

    • event: "data"
    • callback: ((data) => void)
        • (data): void
        • Parameters

          • data: T

          Returns void

    Returns void

  • Emitted when any error occurs.

    Parameters

    • event: "error"
    • callback: ((err) => void)
        • (err): void
        • Parameters

          • err: Error

          Returns void

    Returns void

  • The 'end' event is emitted when there is no more data to be consumed from the stream. The 'end' event will not be emitted unless the data is completely consumed.

    Parameters

    • event: "end"
    • callback: (() => void)
        • (): void
        • Returns void

    Returns void

  • Writing data to the stream will trigger the on('data') event listener if the stream is flowing and buffer the data otherwise until the stream is flowing.

    If a highWaterMark is configured and writing to the stream reaches this mark, a promise will be returned that should be awaited on before writing more data. Otherwise there is a risk of buffering a large number of data chunks without consumer.

    Parameters

    • data: T

    Returns void | Promise<void>