Struct wasm_streams::readable::ReadableStream [−][src]
pub struct ReadableStream { /* fields omitted */ }
Expand description
ReadableStream
s can be created from a raw JavaScript stream with
from_raw
, or from a Rust Stream
with from_stream
.
They can be converted into a raw JavaScript stream with
into_raw
, or into a Rust Stream
with into_stream
.
If the browser supports readable byte streams,
then they can be created from a Rust AsyncRead
with
from_async_read
, or converted into one with
into_async_read
.
Implementations
Creates a new ReadableStream
from a JavaScript stream.
pub fn from_stream<St>(stream: St) -> Self where
St: Stream<Item = Result<JsValue, JsValue>> + 'static,
pub fn from_stream<St>(stream: St) -> Self where
St: Stream<Item = Result<JsValue, JsValue>> + 'static,
pub fn from_async_read<R>(async_read: R, default_buffer_len: usize) -> Self where
R: AsyncRead + 'static,
pub fn from_async_read<R>(async_read: R, default_buffer_len: usize) -> Self where
R: AsyncRead + 'static,
Creates a new ReadableStream
from an AsyncRead
.
This creates a readable byte stream whose autoAllocateChunkSize
is default_buffer_len
.
Therefore, if a default reader is used to consume the stream, the given async_read
will be polled with a buffer of this size. If a BYOB reader is used,
then it will be polled with a buffer of the same size as the BYOB read request instead.
Panics if readable byte streams are not supported by the browser.
Acquires a reference to the underlying JavaScript stream.
Consumes this ReadableStream
, returning the underlying JavaScript stream.
Returns true
if the stream is locked to a reader.
Cancels the stream, signaling a loss of interest in the stream by a consumer.
If the stream is currently locked to a reader, then this returns an error.
Cancels the stream, signaling a loss of interest in the stream by a consumer.
The supplied reason
will be given to the underlying source, which may or may not use it.
If the stream is currently locked to a reader, then this returns an error.
Creates a default reader and locks the stream to the new reader.
While the stream is locked, no other reader can be acquired until this one is released.
Panics if the stream is already locked to a reader. For a non-panicking variant,
use try_get_reader
.
Try to create a default reader and lock the stream to the new reader.
While the stream is locked, no other reader can be acquired until this one is released.
If the stream is already locked to a reader, then this returns an error.
Creates a BYOB reader and locks the stream to the new reader.
While the stream is locked, no other reader can be acquired until this one is released.
Panics if the stream is already locked to a reader, or if this stream is not a readable
byte stream. For a non-panicking variant, use try_get_reader
.
Try to create a BYOB reader and lock the stream to the new reader.
While the stream is locked, no other reader can be acquired until this one is released.
If the stream is already locked to a reader, then this returns an error.
pub async fn pipe_to_with_options<'a>(
&'a mut self,
dest: &'a mut WritableStream,
options: &PipeOptions
) -> Result<(), JsValue>
pub async fn pipe_to_with_options<'a>(
&'a mut self,
dest: &'a mut WritableStream,
options: &PipeOptions
) -> Result<(), JsValue>
Pipes this readable stream to a given writable stream.
Piping a stream will lock it for the duration of the pipe, preventing any other consumer from acquiring a reader.
Errors and closures of the source and destination streams propagate as follows:
- An error in the source readable stream will abort
the destination writable stream, unless
options.prevent_abort
istrue
. - An error in the destination writable stream will cancel
the source readable stream, unless
options.prevent_cancel
istrue
. - When the source readable stream closes, the destination writable stream will be closed,
unless
options.prevent_close
istrue
. - If the destination writable stream starts out closed or closing, the source readable stream
will be canceled,
unless unless
options.prevent_cancel
istrue
.
This returns ()
if the pipe completes successfully, or Err(error)
if any error
was encountered during the process.
Tees this readable stream,
returning the two resulting branches as new ReadableStream
instances.
Teeing a stream will lock it, preventing any other consumer from acquiring a reader. To cancel the stream, cancel both of the resulting branches; a composite cancellation reason will then be propagated to the stream’s underlying source.
Note that the chunks seen in each branch will be the same object. If the chunks are not immutable, this could allow interference between the two branches.
Panics if the stream is already locked to a reader. For a non-panicking variant,
use try_tee
.
Tries to tee this readable stream,
returning the two resulting branches as new ReadableStream
instances.
Teeing a stream will lock it, preventing any other consumer from acquiring a reader. To cancel the stream, cancel both of the resulting branches; a composite cancellation reason will then be propagated to the stream’s underlying source.
Note that the chunks seen in each branch will be the same object. If the chunks are not immutable, this could allow interference between the two branches.
If the stream is already locked to a reader, then this returns an error
along with the original ReadableStream
.
Try to convert this ReadableStream
into a Stream
.
Items and errors are represented by their raw JsValue
.
Use map
, map_ok
and/or
map_err
on the returned stream to convert them to a more
appropriate type.
If the stream is already locked to a reader, then this returns an error
along with the original ReadableStream
.
Converts this ReadableStream
into an AsyncRead
.
Panics if the stream is already locked to a reader, or if this stream is not a readable
byte stream. For a non-panicking variant, use try_into_async_read
.
Try to convert this ReadableStream
into an AsyncRead
.
If the stream is already locked to a reader, or if this stream is not a readable byte
stream, then this returns an error along with the original ReadableStream
.
Trait Implementations
Equivalent to from_stream
.