output-stream
An output bytestream.
resource output-stream;F check-write
check-write: func() -> result<u64, stream-error>;Check readiness for writing. This function never blocks.
Returns the number of bytes permitted for the next call to write,
or an error. Calling write with more bytes than this function has
permitted will trap.
When this function returns 0 bytes, the subscribe pollable will
become ready when this function will report at least 1 byte, or an
error.
F write
write: func(contents: list<u8>) -> result<_, stream-error>;Perform a write. This function never blocks.
When the destination of a write is binary data, the bytes from
contents are written verbatim. When the destination of a write is
known to the implementation to be text, the bytes of contents are
transcoded from UTF-8 into the encoding of the destination and then
written.
Precondition: check-write gave permit of Ok(n) and contents has a length of less than or equal to n. Otherwise, this function will trap.
returns Err(closed) without writing if the stream has closed since the last call to check-write provided a permit.
F blocking-write-and-flush
blocking-write-and-flush: func(contents: list<u8>) -> result<_, stream-error>;Perform a write of up to 4096 bytes, and then flush the stream. Block until all of these operations are complete, or an error occurs.
Returns success when all of the contents written are successfully flushed to output. If an error occurs at any point before all contents are successfully flushed, that error is returned as soon as possible. If writing and flushing the complete contents causes the stream to become closed, this call should return success, and subsequent calls to check-write or other interfaces should return stream-error::closed.
F flush
flush: func() -> result<_, stream-error>;Request to flush buffered output. This function never blocks.
This tells the output-stream that the caller intends any buffered
output to be flushed. the output which is expected to be flushed
is all that has been passed to write prior to this call.
Upon calling this function, the output-stream will not accept any
writes (check-write will return ok(0)) until the flush has
completed. The subscribe pollable will become ready when the
flush has completed and the stream can accept more writes.
F blocking-flush
blocking-flush: func() -> result<_, stream-error>;Request to flush buffered output, and block until flush completes and stream is ready for writing again.
F subscribe
subscribe: func() -> pollable;Create a pollable which will resolve once the output-stream
is ready for more writing, or an error has occurred. When this
pollable is ready, check-write will return ok(n) with n>0, or an
error.
If the stream is closed, this pollable is always ready immediately.
The created pollable is a child resource of the output-stream.
Implementations may trap if the output-stream is dropped before
all derived pollables created with this function are dropped.
F write-zeroes
write-zeroes: func(len: u64) -> result<_, stream-error>;Write zeroes to a stream.
This should be used precisely like write with the exact same
preconditions (must use check-write first), but instead of
passing a list of bytes, you simply pass the number of zero-bytes
that should be written.
F blocking-write-zeroes-and-flush
blocking-write-zeroes-and-flush: func(len: u64) -> result<_, stream-error>;Perform a write of up to 4096 zeroes, and then flush the stream. Block until all of these operations are complete, or an error occurs.
Functionality is equivelant to blocking-write-and-flush with
contents given as a list of len containing only zeroes.
F splice
splice: func(src: borrow<input-stream>, len: u64) -> result<u64, stream-error>;Read from one stream and write to another.
The behavior of splice is equivalent to:
- calling
check-writeon theoutput-stream - calling
readon theinput-streamwith the smaller of thecheck-writepermitted length and thelenprovided tosplice - calling
writeon theoutput-streamwith that read data.
Any error reported by the call to check-write, read, or
write ends the splice and reports that error.
This function returns the number of bytes transferred; it may be less
than len.
F blocking-splice
blocking-splice: func(src: borrow<input-stream>, len: u64) -> result<u64, stream-error>;Read from one stream and write to another, with blocking.
This is similar to splice, except that it blocks until the
output-stream is ready for writing, and the input-stream
is ready for reading, before performing the splice.