gossamer/readable_stream
Types
A pull-based stream of bytes or objects, used as a source for data.
See ReadableStream on MDN.
pub type ReadableStream(a)
pub type StreamPipeOption {
PreventAbort
PreventCancel
PreventClose
Signal(abort_signal.AbortSignal)
}
Constructors
-
PreventAbort -
PreventCancel -
PreventClose -
Signal(abort_signal.AbortSignal)
pub type UnderlyingSource(a) {
Start(fn(default_controller.DefaultController(a)) -> Nil)
Pull(
fn(default_controller.DefaultController(a)) -> promise.Promise(
Nil,
),
)
Cancel(fn(dynamic.Dynamic) -> promise.Promise(Nil))
}
Constructors
-
Start(fn(default_controller.DefaultController(a)) -> Nil) -
Pull( fn(default_controller.DefaultController(a)) -> promise.Promise( Nil, ), ) -
Cancel(fn(dynamic.Dynamic) -> promise.Promise(Nil))
Values
pub fn async_iterator(
of stream: ReadableStream(a),
) -> async_iterator.AsyncIterator(a, Nil, Nil)
Returns an AsyncIterator that reads from the stream. The iterator
locks the stream until reading completes.
pub fn cancel(
stream: ReadableStream(a),
reason reason: r,
) -> promise.Promise(Result(Nil, js_error.JsError))
Signals consumer disinterest in the stream. Returns an error if the underlying source’s cancel callback throws or returns a rejecting promise.
pub fn from_async_iterator(
iterator: async_iterator.AsyncIterator(a, r, n),
) -> ReadableStream(a)
Creates a ReadableStream from an AsyncIterator.
Note: Panics on Bun — ReadableStream.from is not implemented.
See https://github.com/oven-sh/bun/issues/3700
pub fn from_iterator(
iterator: iterator.Iterator(a, r, n),
) -> ReadableStream(a)
Creates a ReadableStream from an Iterator.
Note: Panics on Bun — ReadableStream.from is not implemented.
See https://github.com/oven-sh/bun/issues/3700
pub fn from_pull(
pull: fn(default_controller.DefaultController(a)) -> promise.Promise(
Nil,
),
) -> ReadableStream(a)
Creates a ReadableStream from only a Pull callback — use when chunks
are produced on demand.
pub fn from_start(
start: fn(default_controller.DefaultController(a)) -> Nil,
) -> Result(ReadableStream(a), js_error.JsError)
Creates a ReadableStream from only a Start callback — use when all
chunks can be enqueued up front. Returns an error if start throws
synchronously.
pub fn get_byob_reader(
stream: ReadableStream(a),
) -> Result(byob_reader.ByobReader(a), js_error.JsError)
Acquires a ByobReader for bring-your-own-buffer reads. Returns an
error if the stream is already locked or is not a byte stream.
pub fn get_reader(
stream: ReadableStream(a),
) -> Result(reader.Reader(a), js_error.JsError)
Acquires a Reader that locks the stream. Returns an error if the
stream is already locked.
pub fn is_locked(stream: ReadableStream(a)) -> Bool
Checks whether the stream is locked to a reader.
pub fn new(
source: List(UnderlyingSource(a)),
) -> Result(ReadableStream(a), js_error.JsError)
Creates a ReadableStream driven by the given underlying-source
callbacks (Start, Pull, Cancel). Returns an error if the Start
callback throws synchronously.
pub fn pipe_through(
stream: ReadableStream(a),
transform: #(
ReadableStream(b),
writable_stream.WritableStream(a),
),
with options: List(StreamPipeOption),
) -> Result(ReadableStream(b), js_error.JsError)
Pipes the stream through a transform (a writable+readable pair), returning the readable side. Returns an error if this stream or the writable side is already locked.
pub fn pipe_to(
stream: ReadableStream(a),
destination: writable_stream.WritableStream(a),
with options: List(StreamPipeOption),
) -> promise.Promise(Result(Nil, js_error.JsError))
Pipes the stream to a WritableStream. Returns an error if piping
fails (stream errored, destination errored, or either side already
locked).
pub fn tee(
stream: ReadableStream(a),
) -> Result(
#(ReadableStream(a), ReadableStream(a)),
js_error.JsError,
)
Splits the stream into two independent streams reading the same data. Returns an error if the stream is already locked.