Skip to content
This repository was archived by the owner on Nov 25, 2025. It is now read-only.

Commit c9d685b

Browse files
authored
Specify that text in streams is transmitted in UTF-8. (#66)
* Specify that text in streams is transmitted in UTF-8. The wasi-io stream types are byte streams capable of transmitting any data encoding, including any text encoding. However, sometimes an implementation knows the a particular data source or destination uses text data of a particular encoding, for example in an implementation of the stdio streams on Windows. In these cases, it's useful to have the implementation transcode the data, so that guest code doesn't need to be aware of where the data is coming from or going to, and have extra code for performing transcoding itself. Specify UTF-8 as the encoding to use, when transmitting data from sources or to destinations where the implementation knows the data is in a text format. * Update imports.md.
1 parent 7ef89bc commit c9d685b

File tree

3 files changed

+52
-5
lines changed

3 files changed

+52
-5
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ jobs:
1010
name: Check ABI files are up-to-date
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v3
14-
- uses: WebAssembly/wit-abi-up-to-date@v16
13+
- uses: actions/checkout@v4
14+
- uses: WebAssembly/wit-abi-up-to-date@v17

imports.md

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,21 @@
1212
<hr />
1313
<h3>Types</h3>
1414
<h4><a name="error"><code>resource error</code></a></h4>
15-
<hr />
15+
<p>A resource which represents some error information.</p>
16+
<p>The only method provided by this resource is <code>to-debug-string</code>,
17+
which provides some human-readable information about the error.</p>
18+
<p>In the <code>wasi:io</code> package, this resource is returned through the
19+
<code>wasi:io/streams/stream-error</code> type.</p>
20+
<p>To provide more specific error information, other interfaces may
21+
provide functions to further &quot;downcast&quot; this error into more specific
22+
error information. For example, <a href="#error"><code>error</code></a>s returned in streams derived
23+
from filesystem types to be described using the filesystem's own
24+
error-code type, using the function
25+
<code>wasi:filesystem/types/filesystem-error-code</code>, which takes a parameter
26+
<code>borrow&lt;error&gt;</code> and returns
27+
<code>option&lt;wasi:filesystem/types/error-code&gt;</code>.</p>
28+
<h2>The set of functions which can &quot;downcast&quot; an <a href="#error"><code>error</code></a> into a more
29+
concrete type is open.</h2>
1630
<h3>Functions</h3>
1731
<h4><a name="method_error.to_debug_string"><code>[method]error.to-debug-string: func</code></a></h4>
1832
<p>Returns a string that is suitable to assist humans in debugging
@@ -35,7 +49,7 @@ at once.</p>
3549
<hr />
3650
<h3>Types</h3>
3751
<h4><a name="pollable"><code>resource pollable</code></a></h4>
38-
<hr />
52+
<h2><a href="#pollable"><code>pollable</code></a> represents a single I/O event which may be ready, or not.</h2>
3953
<h3>Functions</h3>
4054
<h4><a name="method_pollable.ready"><code>[method]pollable.ready: func</code></a></h4>
4155
<p>Return the readiness of a pollable. This function never blocks.</p>
@@ -109,11 +123,28 @@ future operations.
109123
</li>
110124
</ul>
111125
<h4><a name="input_stream"><code>resource input-stream</code></a></h4>
126+
<p>An input bytestream.</p>
127+
<p><a href="#input_stream"><code>input-stream</code></a>s are <em>non-blocking</em> to the extent practical on underlying
128+
platforms. I/O operations always return promptly; if fewer bytes are
129+
promptly available than requested, they return the number of bytes promptly
130+
available, which could even be zero. To wait for data to be available,
131+
use the <code>subscribe</code> function to obtain a <a href="#pollable"><code>pollable</code></a> which can be polled
132+
for using <code>wasi:io/poll</code>.</p>
112133
<h4><a name="output_stream"><code>resource output-stream</code></a></h4>
113-
<hr />
134+
<p>An output bytestream.</p>
135+
<h2><a href="#output_stream"><code>output-stream</code></a>s are <em>non-blocking</em> to the extent practical on
136+
underlying platforms. Except where specified otherwise, I/O operations also
137+
always return promptly, after the number of bytes that can be written
138+
promptly, which could even be zero. To wait for the stream to be ready to
139+
accept data, the <code>subscribe</code> function to obtain a <a href="#pollable"><code>pollable</code></a> which can be
140+
polled for using <code>wasi:io/poll</code>.</h2>
114141
<h3>Functions</h3>
115142
<h4><a name="method_input_stream.read"><code>[method]input-stream.read: func</code></a></h4>
116143
<p>Perform a non-blocking read from the stream.</p>
144+
<p>When the source of a <code>read</code> is binary data, the bytes from the source
145+
are returned verbatim. When the source of a <code>read</code> is known to the
146+
implementation to be text, bytes containing the UTF-8 encoding of the
147+
text are returned.</p>
117148
<p>This function returns a list of bytes containing the read data,
118149
when successful. The returned list will contain up to <code>len</code> bytes;
119150
it may return fewer than requested, but not more. The list is
@@ -209,6 +240,11 @@ error.</p>
209240
</ul>
210241
<h4><a name="method_output_stream.write"><code>[method]output-stream.write: func</code></a></h4>
211242
<p>Perform a write. This function never blocks.</p>
243+
<p>When the destination of a <code>write</code> is binary data, the bytes from
244+
<code>contents</code> are written verbatim. When the destination of a <code>write</code> is
245+
known to the implementation to be text, the bytes of <code>contents</code> are
246+
transcoded from UTF-8 into the encoding of the destination and then
247+
written.</p>
212248
<p>Precondition: check-write gave permit of Ok(n) and contents has a
213249
length of less than or equal to n. Otherwise, this function will trap.</p>
214250
<p>returns Err(closed) without writing if the stream has closed since

wit/streams.wit

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ interface streams {
3232
resource input-stream {
3333
/// Perform a non-blocking read from the stream.
3434
///
35+
/// When the source of a `read` is binary data, the bytes from the source
36+
/// are returned verbatim. When the source of a `read` is known to the
37+
/// implementation to be text, bytes containing the UTF-8 encoding of the
38+
/// text are returned.
39+
///
3540
/// This function returns a list of bytes containing the read data,
3641
/// when successful. The returned list will contain up to `len` bytes;
3742
/// it may return fewer than requested, but not more. The list is
@@ -111,6 +116,12 @@ interface streams {
111116

112117
/// Perform a write. This function never blocks.
113118
///
119+
/// When the destination of a `write` is binary data, the bytes from
120+
/// `contents` are written verbatim. When the destination of a `write` is
121+
/// known to the implementation to be text, the bytes of `contents` are
122+
/// transcoded from UTF-8 into the encoding of the destination and then
123+
/// written.
124+
///
114125
/// Precondition: check-write gave permit of Ok(n) and contents has a
115126
/// length of less than or equal to n. Otherwise, this function will trap.
116127
///

0 commit comments

Comments
 (0)