An abstraction for reading streaming data.

When retrieved from an underlying source, data will be buffered in an internal queue.

Data can be consumed by either attaching a "data" listener, piping, or teeing the stream.

Details

Events:

  • start

  • error

  • data

  • pipe

  • tee

  • close

See also

readable_controller

Other streams: TransformStream, WriteableStream

Super class

streams::EventEmitter -> ReadableStream

Active bindings

current_state

1

is_locked

1

is_ready

A boolean value of whether the stream is ready to accept chunks. This does not, however, mean that the stream is able to accept chunks (e.g. if it has a full buffer).

controller

A list that is passed to start, pull, and abort methods. Contains references to the following:

  • emit

  • desired_size

  • start_value

  • enqueue

  • close

desired_size

1

Methods

Inherited methods


Method new()

Create a new ReadableStream

Usage

ReadableStream$new(
  start = NULL,
  pull = NULL,
  flush = NULL,
  abort = NULL,
  queue_strategy = NULL
)

Arguments

start

a function that is called once the stream enters the "started" state. Must be of signature: function(controller)

pull

a function that is called whenever the stream wants more data in its buffer. Must be of signature: function(controller)

flush

a function that is called prior to the stream ending. Must be of signature: function(controller)

abort

a function that is called to immediately abort the stream, dropping all unconsumed chunks in the process. Must be of signature: function(controller)

queue_strategy

a QueueStrategy object, describing how chunks will be buffered by the stream


Method pipe()

Pipe the ReadableStream to a WriteableStream. Pulled data from the ReadableStream is written to the WriteableStream, respecting backpressure signals from the WriteableStream.

When piped, the ReadableStream is in a locked state, and cannot be manually controlled.

Specifics:

  • Upon calling pipe(), the ReadableStream emits a "pipe" event.

  • Data events will cause the ReadableStream to write to the WriteableStream

  • The ReadableStream listens to the WriteableStream's drain and backpressure events, pausing and resuming flow when appropriate

  • When a "close" event is emitted from the ReadableStream, the WriteableStream is sent a close request

  • When an "error" event is emitted from the ReadableStream, it is propogated to the WriteableStream.

Usage

ReadableStream$pipe(destination)

Arguments

destination

ReadableStream

Returns

destination


Method tee()

Tee the ReadableStream, creating two ReadableStreams in the process. Data from this ReadableStream will flow into the two destination streams, and will respect backpressure signals from both destination streams.

Specifics:

  • Upon calling tee(), the ReadableStream will emit a "tee" event.

  • The resulting teed streams act as push streams, wherein the data from the teeing stream is pushed when appropriate

  • Data is only pushed when both streams are able to accept new chunks, otherwise the chunks will be buffered inside the teeing stream

  • The queue strategy of the teeing stream is respected

  • The teed streams utilise the default queue strategy, accepting one chunk at a time

Usage

ReadableStream$tee()

Returns

list of teed streams


Method abort()

1

Usage

ReadableStream$abort(reason = NULL)

Arguments

reason

data

Returns

NULL


Method close()

1

Usage

ReadableStream$close()

Returns

NULL


Method lock_stream()

1

Usage

ReadableStream$lock_stream(destination)

Arguments

destination

1

Returns

NULL


Method set_upstream()

1

Usage

ReadableStream$set_upstream(destination)

Arguments

destination

1

Returns

NULL


Method print()

1

Usage

ReadableStream$print()

Returns

NULL


Method format()

1

Usage

ReadableStream$format(...)

Arguments

...

1

Returns

NULL


Method clone()

The objects of this class are cloneable with this method.

Usage

ReadableStream$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.