A Stream is a data channel between two peers that can be written to and read from at both ends.

It may be encrypted and multiplexed depending on the configuration of the nodes.

Hierarchy

Properties

abort: ((err: Error) => void)

Type declaration

    • (err: Error): void
    • Closes the stream for reading and writing. This should be called when a local error has occurred.

      Note, if called without an error any buffered data in the source can still be consumed and the stream will end normally.

      This will cause a RESET message to be sent to the remote, unless the sink has already ended.

      The sink will return and the source will throw if an error is passed or return normally if not.

      Parameters

      Returns void

close: (() => void)

Type declaration

    • (): void
    • Closes the stream for reading and writing.

      Any buffered data in the source can still be consumed and the stream will end normally.

      This will cause a CLOSE message to be sent to the remote, unless the sink has already ended.

      The sink and the source will return normally.

      Returns void

closeRead: (() => void)

Type declaration

    • (): void
    • Closes the stream for reading. If iterating over the source of this stream in a for await of loop, it will return (exit the loop) after any buffered data has been consumed.

      This function is called automatically by the muxer when it receives a CLOSE message from the remote.

      The source will return normally, the sink will continue to consume.

      Returns void

closeWrite: (() => void)

Type declaration

    • (): void
    • Closes the stream for writing. If iterating over the source of this stream in a for await of loop, it will return (exit the loop) after any buffered data has been consumed.

      The source will return normally, the sink will continue to consume.

      Returns void

id: string

Unique identifier for a stream. Identifiers are not unique across muxers.

metadata: Record<string, any>

User defined stream metadata

reset: (() => void)

Type declaration

    • (): void
    • Closes the stream immediately for reading and writing. This should be called when a remote error has occurred.

      This function is called automatically by the muxer when it receives a RESET message from the remote.

      The sink will return and the source will throw.

      Returns void

Stats about this stream