Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface ReadStream<T>

Represents a stream of items that can be read from.

Any class that implements this interface can be used by a Pipe to pipe data from it to a WriteStream.

Streaming mode

The stream is either in flowing or fetch mode.
    Initially the stream is in flowing mode.
  • When the stream is in flowing mode, elements are delivered to the handler.
  • When the stream is in fetch mode, only the number of requested elements will be delivered to the handler.
The mode can be changed with the {@link ReadStream#pause}, {@link ReadStream#resume} and {@link ReadStream#fetch} methods:
  • Calling {@link ReadStream#resume} sets the flowing mode
  • Calling {@link ReadStream#pause} sets the fetch mode and resets the demand to 0
  • Calling {@link ReadStream#fetch} requests a specific amount of elements and adds it to the actual demand

Type parameters

  • T

Hierarchy

Implemented by

Index

Methods

endHandler

  • endHandler(endHandler: ((res: void) => void) | Handler<void> | null | undefined): ReadStream<T>
  • Set an end handler. Once the stream has ended, and there is no more data to be read, this handler will be called.

    Parameters

    • endHandler: ((res: void) => void) | Handler<void> | null | undefined

    Returns ReadStream<T>

exceptionHandler

fetch

  • Fetch the specified amount of elements. If the ReadStream has been paused, reading will recommence with the specified amount of items, otherwise the specified amount will be added to the current stream demand.

    Parameters

    • amount: number

    Returns ReadStream<T>

handler

  • handler(handler: ((res: T) => void) | Handler<T> | null | undefined): ReadStream<T>
  • Set a data handler. As data is read, the handler will be called with the data.

    Parameters

    • handler: ((res: T) => void) | Handler<T> | null | undefined

    Returns ReadStream<T>

pause

  • Pause the ReadStream, it sets the buffer in fetch mode and clears the actual demand.

    While it's paused, no data will be sent to the data handler.

    Returns ReadStream<T>

pipe

  • Pause this stream and return a Pipe to transfer the elements of this stream to a destination WriteStream.

    The stream will be resumed when the pipe will be wired to a WriteStream.

    Returns Pipe<T>

pipeTo

  • Pipe this ReadStream to the WriteStream.

    Elements emitted by this stream will be written to the write stream until this stream ends or fails.

    Once this stream has ended or failed, the write stream will be ended and the handler will be called with the result.

    Parameters

    Returns PromiseLike<void>

  • Pipe this ReadStream to the WriteStream.

    Elements emitted by this stream will be written to the write stream until this stream ends or fails.

    Once this stream has ended or failed, the write stream will be ended and the handler will be called with the result.

    Parameters

    Returns void

resume

  • Resume reading, and sets the buffer in flowing mode.

    If the ReadStream has been paused, reading will recommence on it.

    Returns ReadStream<T>

Generated using TypeDoc