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.

Implements

Constructors

Properties

closed: DeferredPromise<void>
direction: Direction

Outbound streams are opened by the local node, inbound streams are opened by the remote

endErr: undefined | Error
id: string

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

log: Logger

The stream logger

metadata: Record<string, unknown>

User defined stream metadata

onAbort?: ((err) => void)

Type declaration

    • (err): void
    • Parameters

      Returns void

onCloseRead?: (() => void)

Type declaration

    • (): void
    • Returns void

onCloseWrite?: (() => void)

Type declaration

    • (): void
    • Returns void

onEnd?: ((err?) => void)

Type declaration

    • (err?): void
    • Parameters

      Returns void

onReset?: (() => void)

Type declaration

    • (): void
    • Returns void

protocol?: string

The protocol negotiated for this stream

readStatus: ReadStatus

The current status of the readable end of the stream

sendCloseWriteTimeout: number
sendingData?: DeferredPromise<void>
sinkController: AbortController
sinkEnd: DeferredPromise<void>
source: AsyncGenerator<Uint8ArrayList, void, unknown>
status: StreamStatus

The current status of the stream

streamSource: Pushable<Uint8ArrayList, void, unknown>
timeline: StreamTimeline

Lifecycle times for the stream

writeStatus: WriteStatus

The current status of the writable end of the stream

Methods

  • 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.

    Parameters

    Returns Promise<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.

    Parameters

    Returns Promise<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.

    Parameters

    Returns Promise<void>

  • Returns the amount of unread data - can be used to prevent large amounts of data building up when the stream consumer is too slow.

    Returns number