Back to Wasi

Imports

proposals/io/imports.md

0.2.1123.2 KB
Original Source
<h1><a id="imports"></a>World imports</h1> <ul> <li>Imports: <ul> <li>interface <a href="#wasi_io_error_0_2_11"><code>wasi:io/[email protected]</code></a></li> <li>interface <a href="#wasi_io_poll_0_2_11"><code>wasi:io/[email protected]</code></a></li> <li>interface <a href="#wasi_io_streams_0_2_11"><code>wasi:io/[email protected]</code></a></li> </ul> </li> </ul> <h2><a id="wasi_io_error_0_2_11"></a>Import interface wasi:io/[email protected]</h2> <hr /> <h3>Types</h3> <h4><a id="error"></a><code>resource error</code></h4> <p>A resource which represents some error information.</p> <p>The only method provided by this resource is <code>to-debug-string</code>, which provides some human-readable information about the error.</p> <p>In the <code>wasi:io</code> package, this resource is returned through the <code>wasi:io/streams.stream-error</code> type.</p> <p>To provide more specific error information, other interfaces may offer functions to &quot;downcast&quot; this error into more specific types. For example, errors returned from streams derived from filesystem types can be described using the filesystem's own error-code type. This is done using the function <code>wasi:filesystem/types.filesystem-error-code</code>, which takes a <code>borrow&lt;error&gt;</code> parameter and returns an <code>option&lt;wasi:filesystem/types.error-code&gt;</code>.</p> <h2>The set of functions which can &quot;downcast&quot; an <a href="#error"><code>error</code></a> into a more concrete type is open.</h2> <h3>Functions</h3> <h4><a id="method_error_to_debug_string"></a><code>[method]error.to-debug-string: func</code></h4> <p>Returns a string that is suitable to assist humans in debugging this error.</p> <p>WARNING: The returned string should not be consumed mechanically! It may change across platforms, hosts, or other implementation details. Parsing this string is a major platform-compatibility hazard.</p> <h5>Params</h5> <ul> <li><a id="method_error_to_debug_string.self"></a><code>self</code>: borrow&lt;<a href="#error"><a href="#error"><code>error</code></a></a>&gt;</li> </ul> <h5>Return values</h5> <ul> <li><a id="method_error_to_debug_string.0"></a> <code>string</code></li> </ul> <h2><a id="wasi_io_poll_0_2_11"></a>Import interface wasi:io/[email protected]</h2> <p>A poll API intended to let users wait for I/O events on multiple handles at once.</p> <hr /> <h3>Types</h3> <h4><a id="pollable"></a><code>resource pollable</code></h4> <h2><a href="#pollable"><code>pollable</code></a> represents a single I/O event which may be ready, or not.</h2> <h3>Functions</h3> <h4><a id="method_pollable_ready"></a><code>[method]pollable.ready: func</code></h4> <p>Return the readiness of a pollable. This function never blocks.</p> <p>Returns <code>true</code> when the pollable is ready, and <code>false</code> otherwise.</p> <h5>Params</h5> <ul> <li><a id="method_pollable_ready.self"></a><code>self</code>: borrow&lt;<a href="#pollable"><a href="#pollable"><code>pollable</code></a></a>&gt;</li> </ul> <h5>Return values</h5> <ul> <li><a id="method_pollable_ready.0"></a> <code>bool</code></li> </ul> <h4><a id="method_pollable_block"></a><code>[method]pollable.block: func</code></h4> <p><code>block</code> returns immediately if the pollable is ready, and otherwise blocks until ready.</p> <p>This function is equivalent to calling <code>poll.poll</code> on a list containing only this pollable.</p> <h5>Params</h5> <ul> <li><a id="method_pollable_block.self"></a><code>self</code>: borrow&lt;<a href="#pollable"><a href="#pollable"><code>pollable</code></a></a>&gt;</li> </ul> <h4><a id="poll"></a><code>poll: func</code></h4> <p>Poll for completion on a set of pollables.</p> <p>This function takes a list of pollables, which identify I/O sources of interest, and waits until one or more of the events is ready for I/O.</p> <p>The result <code>list&lt;u32&gt;</code> contains one or more indices of handles in the argument list that is ready for I/O.</p> <p>This function traps if either:</p> <ul> <li>the list is empty, or:</li> <li>the list contains more elements than can be indexed with a <code>u32</code> value.</li> </ul> <p>A timeout can be implemented by adding a pollable from the wasi-clocks API to the list.</p> <p>This function does not return a <code>result</code>; polling in itself does not do any I/O so it doesn't fail. If any of the I/O sources identified by the pollables has an error, it is indicated by marking the source as being ready for I/O.</p> <h5>Params</h5> <ul> <li><a id="poll.in"></a><code>in</code>: list&lt;borrow&lt;<a href="#pollable"><a href="#pollable"><code>pollable</code></a></a>&gt;&gt;</li> </ul> <h5>Return values</h5> <ul> <li><a id="poll.0"></a> list&lt;<code>u32</code>&gt;</li> </ul> <h2><a id="wasi_io_streams_0_2_11"></a>Import interface wasi:io/[email protected]</h2> <p>WASI I/O is an I/O abstraction API which is currently focused on providing stream types.</p> <p>In the future, the component model is expected to add built-in stream types; when it does, they are expected to subsume this API.</p> <hr /> <h3>Types</h3> <h4><a id="error"></a><code>type error</code></h4> <p><a href="#error"><a href="#error"><code>error</code></a></a></p> <p> <h4><a id="pollable"></a><code>type pollable</code></h4> <p><a href="#pollable"><a href="#pollable"><code>pollable</code></a></a></p> <p> <h4><a id="stream_error"></a><code>variant stream-error</code></h4> <p>An error for input-stream and output-stream operations.</p> <h5>Variant Cases</h5> <ul> <li> <p><a id="stream_error.last_operation_failed"></a><code>last-operation-failed</code>: own&lt;<a href="#error"><a href="#error"><code>error</code></a></a>&gt;</p> <p>The last operation (a write or flush) failed before completion. <p>More information is available in the <a href="#error"><code>error</code></a> payload.</p> <p>After this, the stream will be closed. All future operations return <a href="#stream_error.closed"><code>stream-error::closed</code></a>.</p> </li> <li> <p><a id="stream_error.closed"></a><code>closed</code></p> <p>The stream is closed: no more input will be accepted by the stream. A closed output-stream will return this error on all future operations. </li> </ul> <h4><a id="input_stream"></a><code>resource input-stream</code></h4> <p>An input bytestream.</p> <p><a href="#input_stream"><code>input-stream</code></a>s are <em>non-blocking</em> to the extent practical on underlying platforms. I/O operations always return promptly; if fewer bytes are promptly available than requested, they return the number of bytes promptly available, which could even be zero. To wait for data to be available, use the <code>subscribe</code> function to obtain a <a href="#pollable"><code>pollable</code></a> which can be polled for using <code>wasi:io/poll</code>.</p> <h4><a id="output_stream"></a><code>resource output-stream</code></h4> <p>An output bytestream.</p> <p><a href="#output_stream"><code>output-stream</code></a>s are <em>non-blocking</em> to the extent practical on underlying platforms. Except where specified otherwise, I/O operations also always return promptly, after the number of bytes that can be written promptly, which could even be zero. To wait for the stream to be ready to accept data, the <code>subscribe</code> function to obtain a <a href="#pollable"><code>pollable</code></a> which can be polled for using <code>wasi:io/poll</code>.</p> <h2>Dropping an <a href="#output_stream"><code>output-stream</code></a> while there's still an active write in progress may result in the data being lost. Before dropping the stream, be sure to fully flush your writes.</h2> <h3>Functions</h3> <h4><a id="method_input_stream_read"></a><code>[method]input-stream.read: func</code></h4> <p>Perform a non-blocking read from the stream.</p> <p>When the source of a <code>read</code> is binary data, the bytes from the source are returned verbatim. When the source of a <code>read</code> is known to the implementation to be text, bytes containing the UTF-8 encoding of the text are returned.</p> <p>This function returns a list of bytes containing the read data, when successful. The returned list will contain up to <code>len</code> bytes; it may return fewer than requested, but not more. The list is empty when no bytes are available for reading at this time. The pollable given by <code>subscribe</code> will be ready when more bytes are available.</p> <p>This function fails with a <a href="#stream_error"><code>stream-error</code></a> when the operation encounters an error, giving <code>last-operation-failed</code>, or when the stream is closed, giving <code>closed</code>.</p> <p>When the caller gives a <code>len</code> of 0, it represents a request to read 0 bytes. If the stream is still open, this call should succeed and return an empty list, or otherwise fail with <code>closed</code>.</p> <p>The <code>len</code> parameter is a <code>u64</code>, which could represent a list of u8 which is not possible to allocate in wasm32, or not desirable to allocate as as a return value by the callee. The callee may return a list of bytes less than <code>len</code> in size while more bytes are available for reading.</p> <h5>Params</h5> <ul> <li><a id="method_input_stream_read.self"></a><code>self</code>: borrow&lt;<a href="#input_stream"><a href="#input_stream"><code>input-stream</code></a></a>&gt;</li> <li><a id="method_input_stream_read.len"></a><code>len</code>: <code>u64</code></li> </ul> <h5>Return values</h5> <ul> <li><a id="method_input_stream_read.0"></a> result&lt;list&lt;<code>u8</code>&gt;, <a href="#stream_error"><a href="#stream_error"><code>stream-error</code></a></a>&gt;</li> </ul> <h4><a id="method_input_stream_blocking_read"></a><code>[method]input-stream.blocking-read: func</code></h4> <p>Read bytes from a stream, after blocking until at least one byte can be read. Except for blocking, behavior is identical to <code>read</code>.</p> <h5>Params</h5> <ul> <li><a id="method_input_stream_blocking_read.self"></a><code>self</code>: borrow&lt;<a href="#input_stream"><a href="#input_stream"><code>input-stream</code></a></a>&gt;</li> <li><a id="method_input_stream_blocking_read.len"></a><code>len</code>: <code>u64</code></li> </ul> <h5>Return values</h5> <ul> <li><a id="method_input_stream_blocking_read.0"></a> result&lt;list&lt;<code>u8</code>&gt;, <a href="#stream_error"><a href="#stream_error"><code>stream-error</code></a></a>&gt;</li> </ul> <h4><a id="method_input_stream_skip"></a><code>[method]input-stream.skip: func</code></h4> <p>Skip bytes from a stream. Returns number of bytes skipped.</p> <p>Behaves identical to <code>read</code>, except instead of returning a list of bytes, returns the number of bytes consumed from the stream.</p> <h5>Params</h5> <ul> <li><a id="method_input_stream_skip.self"></a><code>self</code>: borrow&lt;<a href="#input_stream"><a href="#input_stream"><code>input-stream</code></a></a>&gt;</li> <li><a id="method_input_stream_skip.len"></a><code>len</code>: <code>u64</code></li> </ul> <h5>Return values</h5> <ul> <li><a id="method_input_stream_skip.0"></a> result&lt;<code>u64</code>, <a href="#stream_error"><a href="#stream_error"><code>stream-error</code></a></a>&gt;</li> </ul> <h4><a id="method_input_stream_blocking_skip"></a><code>[method]input-stream.blocking-skip: func</code></h4> <p>Skip bytes from a stream, after blocking until at least one byte can be skipped. Except for blocking behavior, identical to <code>skip</code>.</p> <h5>Params</h5> <ul> <li><a id="method_input_stream_blocking_skip.self"></a><code>self</code>: borrow&lt;<a href="#input_stream"><a href="#input_stream"><code>input-stream</code></a></a>&gt;</li> <li><a id="method_input_stream_blocking_skip.len"></a><code>len</code>: <code>u64</code></li> </ul> <h5>Return values</h5> <ul> <li><a id="method_input_stream_blocking_skip.0"></a> result&lt;<code>u64</code>, <a href="#stream_error"><a href="#stream_error"><code>stream-error</code></a></a>&gt;</li> </ul> <h4><a id="method_input_stream_subscribe"></a><code>[method]input-stream.subscribe: func</code></h4> <p>Create a <a href="#pollable"><code>pollable</code></a> which will resolve once either the specified stream has bytes available to read or the other end of the stream has been closed. The created <a href="#pollable"><code>pollable</code></a> is a child resource of the <a href="#input_stream"><code>input-stream</code></a>. Implementations may trap if the <a href="#input_stream"><code>input-stream</code></a> is dropped before all derived <a href="#pollable"><code>pollable</code></a>s created with this function are dropped.</p> <h5>Params</h5> <ul> <li><a id="method_input_stream_subscribe.self"></a><code>self</code>: borrow&lt;<a href="#input_stream"><a href="#input_stream"><code>input-stream</code></a></a>&gt;</li> </ul> <h5>Return values</h5> <ul> <li><a id="method_input_stream_subscribe.0"></a> own&lt;<a href="#pollable"><a href="#pollable"><code>pollable</code></a></a>&gt;</li> </ul> <h4><a id="method_output_stream_check_write"></a><code>[method]output-stream.check-write: func</code></h4> <p>Check readiness for writing. This function never blocks.</p> <p>Returns the number of bytes permitted for the next call to <code>write</code>, or an error. Calling <code>write</code> with more bytes than this function has permitted will trap.</p> <p>When this function returns 0 bytes, the <code>subscribe</code> pollable will become ready when this function will report at least 1 byte, or an error.</p> <h5>Params</h5> <ul> <li><a id="method_output_stream_check_write.self"></a><code>self</code>: borrow&lt;<a href="#output_stream"><a href="#output_stream"><code>output-stream</code></a></a>&gt;</li> </ul> <h5>Return values</h5> <ul> <li><a id="method_output_stream_check_write.0"></a> result&lt;<code>u64</code>, <a href="#stream_error"><a href="#stream_error"><code>stream-error</code></a></a>&gt;</li> </ul> <h4><a id="method_output_stream_write"></a><code>[method]output-stream.write: func</code></h4> <p>Perform a write. This function never blocks.</p> <p>When the destination of a <code>write</code> is binary data, the bytes from <code>contents</code> are written verbatim. When the destination of a <code>write</code> is known to the implementation to be text, the bytes of <code>contents</code> are transcoded from UTF-8 into the encoding of the destination and then written.</p> <p>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.</p> <p>returns Err(closed) without writing if the stream has closed since the last call to check-write provided a permit.</p> <h5>Params</h5> <ul> <li><a id="method_output_stream_write.self"></a><code>self</code>: borrow&lt;<a href="#output_stream"><a href="#output_stream"><code>output-stream</code></a></a>&gt;</li> <li><a id="method_output_stream_write.contents"></a><code>contents</code>: list&lt;<code>u8</code>&gt;</li> </ul> <h5>Return values</h5> <ul> <li><a id="method_output_stream_write.0"></a> result&lt;_, <a href="#stream_error"><a href="#stream_error"><code>stream-error</code></a></a>&gt;</li> </ul> <h4><a id="method_output_stream_blocking_write_and_flush"></a><code>[method]output-stream.blocking-write-and-flush: func</code></h4> <p>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.</p> <p>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.</p> <h5>Params</h5> <ul> <li><a id="method_output_stream_blocking_write_and_flush.self"></a><code>self</code>: borrow&lt;<a href="#output_stream"><a href="#output_stream"><code>output-stream</code></a></a>&gt;</li> <li><a id="method_output_stream_blocking_write_and_flush.contents"></a><code>contents</code>: list&lt;<code>u8</code>&gt;</li> </ul> <h5>Return values</h5> <ul> <li><a id="method_output_stream_blocking_write_and_flush.0"></a> result&lt;_, <a href="#stream_error"><a href="#stream_error"><code>stream-error</code></a></a>&gt;</li> </ul> <h4><a id="method_output_stream_flush"></a><code>[method]output-stream.flush: func</code></h4> <p>Request to flush buffered output. This function never blocks.</p> <p>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 <code>write</code> prior to this call.</p> <p>Upon calling this function, the <a href="#output_stream"><code>output-stream</code></a> will not accept any writes (<code>check-write</code> will return <code>ok(0)</code>) until the flush has completed. The <code>subscribe</code> pollable will become ready when the flush has completed and the stream can accept more writes.</p> <h5>Params</h5> <ul> <li><a id="method_output_stream_flush.self"></a><code>self</code>: borrow&lt;<a href="#output_stream"><a href="#output_stream"><code>output-stream</code></a></a>&gt;</li> </ul> <h5>Return values</h5> <ul> <li><a id="method_output_stream_flush.0"></a> result&lt;_, <a href="#stream_error"><a href="#stream_error"><code>stream-error</code></a></a>&gt;</li> </ul> <h4><a id="method_output_stream_blocking_flush"></a><code>[method]output-stream.blocking-flush: func</code></h4> <p>Request to flush buffered output, and block until flush completes and stream is ready for writing again.</p> <h5>Params</h5> <ul> <li><a id="method_output_stream_blocking_flush.self"></a><code>self</code>: borrow&lt;<a href="#output_stream"><a href="#output_stream"><code>output-stream</code></a></a>&gt;</li> </ul> <h5>Return values</h5> <ul> <li><a id="method_output_stream_blocking_flush.0"></a> result&lt;_, <a href="#stream_error"><a href="#stream_error"><code>stream-error</code></a></a>&gt;</li> </ul> <h4><a id="method_output_stream_subscribe"></a><code>[method]output-stream.subscribe: func</code></h4> <p>Create a <a href="#pollable"><code>pollable</code></a> which will resolve once the output-stream is ready for more writing, or an error has occurred. When this pollable is ready, <code>check-write</code> will return <code>ok(n)</code> with n&gt;0, or an error.</p> <p>If the stream is closed, this pollable is always ready immediately.</p> <p>The created <a href="#pollable"><code>pollable</code></a> is a child resource of the <a href="#output_stream"><code>output-stream</code></a>. Implementations may trap if the <a href="#output_stream"><code>output-stream</code></a> is dropped before all derived <a href="#pollable"><code>pollable</code></a>s created with this function are dropped.</p> <h5>Params</h5> <ul> <li><a id="method_output_stream_subscribe.self"></a><code>self</code>: borrow&lt;<a href="#output_stream"><a href="#output_stream"><code>output-stream</code></a></a>&gt;</li> </ul> <h5>Return values</h5> <ul> <li><a id="method_output_stream_subscribe.0"></a> own&lt;<a href="#pollable"><a href="#pollable"><code>pollable</code></a></a>&gt;</li> </ul> <h4><a id="method_output_stream_write_zeroes"></a><code>[method]output-stream.write-zeroes: func</code></h4> <p>Write zeroes to a stream.</p> <p>This should be used precisely like <code>write</code> 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.</p> <h5>Params</h5> <ul> <li><a id="method_output_stream_write_zeroes.self"></a><code>self</code>: borrow&lt;<a href="#output_stream"><a href="#output_stream"><code>output-stream</code></a></a>&gt;</li> <li><a id="method_output_stream_write_zeroes.len"></a><code>len</code>: <code>u64</code></li> </ul> <h5>Return values</h5> <ul> <li><a id="method_output_stream_write_zeroes.0"></a> result&lt;_, <a href="#stream_error"><a href="#stream_error"><code>stream-error</code></a></a>&gt;</li> </ul> <h4><a id="method_output_stream_blocking_write_zeroes_and_flush"></a><code>[method]output-stream.blocking-write-zeroes-and-flush: func</code></h4> <p>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.</p> <p>Functionality is equivelant to <code>blocking-write-and-flush</code> with contents given as a list of len containing only zeroes.</p> <h5>Params</h5> <ul> <li><a id="method_output_stream_blocking_write_zeroes_and_flush.self"></a><code>self</code>: borrow&lt;<a href="#output_stream"><a href="#output_stream"><code>output-stream</code></a></a>&gt;</li> <li><a id="method_output_stream_blocking_write_zeroes_and_flush.len"></a><code>len</code>: <code>u64</code></li> </ul> <h5>Return values</h5> <ul> <li><a id="method_output_stream_blocking_write_zeroes_and_flush.0"></a> result&lt;_, <a href="#stream_error"><a href="#stream_error"><code>stream-error</code></a></a>&gt;</li> </ul> <h4><a id="method_output_stream_splice"></a><code>[method]output-stream.splice: func</code></h4> <p>Read from one stream and write to another.</p> <p>The behavior of splice is equivalent to:</p> <ol> <li>calling <code>check-write</code> on the <a href="#output_stream"><code>output-stream</code></a></li> <li>calling <code>read</code> on the <a href="#input_stream"><code>input-stream</code></a> with the smaller of the <code>check-write</code> permitted length and the <code>len</code> provided to <code>splice</code></li> <li>calling <code>write</code> on the <a href="#output_stream"><code>output-stream</code></a> with that read data.</li> </ol> <p>Any error reported by the call to <code>check-write</code>, <code>read</code>, or <code>write</code> ends the splice and reports that error.</p> <p>This function returns the number of bytes transferred; it may be less than <code>len</code>.</p> <h5>Params</h5> <ul> <li><a id="method_output_stream_splice.self"></a><code>self</code>: borrow&lt;<a href="#output_stream"><a href="#output_stream"><code>output-stream</code></a></a>&gt;</li> <li><a id="method_output_stream_splice.src"></a><code>src</code>: borrow&lt;<a href="#input_stream"><a href="#input_stream"><code>input-stream</code></a></a>&gt;</li> <li><a id="method_output_stream_splice.len"></a><code>len</code>: <code>u64</code></li> </ul> <h5>Return values</h5> <ul> <li><a id="method_output_stream_splice.0"></a> result&lt;<code>u64</code>, <a href="#stream_error"><a href="#stream_error"><code>stream-error</code></a></a>&gt;</li> </ul> <h4><a id="method_output_stream_blocking_splice"></a><code>[method]output-stream.blocking-splice: func</code></h4> <p>Read from one stream and write to another, with blocking.</p> <p>This is similar to <code>splice</code>, except that it blocks until the <a href="#output_stream"><code>output-stream</code></a> is ready for writing, and the <a href="#input_stream"><code>input-stream</code></a> is ready for reading, before performing the <code>splice</code>.</p> <h5>Params</h5> <ul> <li><a id="method_output_stream_blocking_splice.self"></a><code>self</code>: borrow&lt;<a href="#output_stream"><a href="#output_stream"><code>output-stream</code></a></a>&gt;</li> <li><a id="method_output_stream_blocking_splice.src"></a><code>src</code>: borrow&lt;<a href="#input_stream"><a href="#input_stream"><code>input-stream</code></a></a>&gt;</li> <li><a id="method_output_stream_blocking_splice.len"></a><code>len</code>: <code>u64</code></li> </ul> <h5>Return values</h5> <ul> <li><a id="method_output_stream_blocking_splice.0"></a> result&lt;<code>u64</code>, <a href="#stream_error"><a href="#stream_error"><code>stream-error</code></a></a>&gt;</li> </ul>