ReadableStream.Rd
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.
Events:
start
error
data
pipe
tee
close
readable_controller
Other streams:
TransformStream
,
WriteableStream
streams::EventEmitter
-> ReadableStream
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
Inherited methods
streams::EventEmitter$emit()
streams::EventEmitter$event_names()
streams::EventEmitter$get_max_listeners()
streams::EventEmitter$listener_count()
streams::EventEmitter$off()
streams::EventEmitter$on()
streams::EventEmitter$once()
streams::EventEmitter$prepend_listener()
streams::EventEmitter$prepend_once_listener()
streams::EventEmitter$raw_listeners()
streams::EventEmitter$remove_all_listeners()
streams::EventEmitter$set_max_listeners()
new()
Create a new ReadableStream
ReadableStream$new(
start = NULL,
pull = NULL,
flush = NULL,
abort = NULL,
queue_strategy = NULL
)
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
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.
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