Skip to content

Commit

Permalink
make {read,write,append}-via-stream fallible
Browse files Browse the repository at this point in the history
stream creation is an appropriate place to return an error-code indicating the
file cannot be read, written, or appended to.
  • Loading branch information
Pat Hickey committed Jun 10, 2023
1 parent 5fcec57 commit 1c65f71
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
15 changes: 9 additions & 6 deletions example-world.md
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,8 @@ not reuse it thereafter.
<hr />
<h3>Functions</h3>
<h4><a name="read_via_stream"><code>read-via-stream: func</code></a></h4>
<p>Return a stream for reading from a file.</p>
<p>Return a stream for reading from a file, if available.</p>
<p>May fail with an error-code describing why the file cannot be read.</p>
<p>Multiple read, write, and append streams may be active on the same open
file and they do not interfere with each other.</p>
<p>Note: This allows using <code>read-stream</code>, which is similar to <a href="#read"><code>read</code></a> in POSIX.</p>
Expand All @@ -844,10 +845,11 @@ file and they do not interfere with each other.</p>
</ul>
<h5>Return values</h5>
<ul>
<li><a name="read_via_stream.0"></a> <a href="#input_stream"><a href="#input_stream"><code>input-stream</code></a></a></li>
<li><a name="read_via_stream.0"></a> result&lt;<a href="#input_stream"><a href="#input_stream"><code>input-stream</code></a></a>, <a href="#error_code"><a href="#error_code"><code>error-code</code></a></a>&gt;</li>
</ul>
<h4><a name="write_via_stream"><code>write-via-stream: func</code></a></h4>
<p>Return a stream for writing to a file.</p>
<p>Return a stream for writing to a file, if available.</p>
<p>May fail with an error-code describing why the file cannot be written.</p>
<p>Note: This allows using <code>write-stream</code>, which is similar to <a href="#write"><code>write</code></a> in
POSIX.</p>
<h5>Params</h5>
Expand All @@ -857,10 +859,11 @@ POSIX.</p>
</ul>
<h5>Return values</h5>
<ul>
<li><a name="write_via_stream.0"></a> <a href="#output_stream"><a href="#output_stream"><code>output-stream</code></a></a></li>
<li><a name="write_via_stream.0"></a> result&lt;<a href="#output_stream"><a href="#output_stream"><code>output-stream</code></a></a>, <a href="#error_code"><a href="#error_code"><code>error-code</code></a></a>&gt;</li>
</ul>
<h4><a name="append_via_stream"><code>append-via-stream: func</code></a></h4>
<p>Return a stream for appending to a file.</p>
<p>Return a stream for appending to a file, if available.</p>
<p>May fail with an error-code describing why the file cannot be appended.</p>
<p>Note: This allows using <code>write-stream</code>, which is similar to <a href="#write"><code>write</code></a> with
<code>O_APPEND</code> in in POSIX.</p>
<h5>Params</h5>
Expand All @@ -869,7 +872,7 @@ POSIX.</p>
</ul>
<h5>Return values</h5>
<ul>
<li><a name="append_via_stream.0"></a> <a href="#output_stream"><a href="#output_stream"><code>output-stream</code></a></a></li>
<li><a name="append_via_stream.0"></a> result&lt;<a href="#output_stream"><a href="#output_stream"><code>output-stream</code></a></a>, <a href="#error_code"><a href="#error_code"><code>error-code</code></a></a>&gt;</li>
</ul>
<h4><a name="advise"><code>advise: func</code></a></h4>
<p>Provide file advisory information on a descriptor.</p>
Expand Down
18 changes: 12 additions & 6 deletions wit/types.wit
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,9 @@ interface types {
/// This [represents a resource](https://github.com/WebAssembly/WASI/blob/main/docs/WitInWasi.md#Resources).
type descriptor = u32

/// Return a stream for reading from a file.
/// Return a stream for reading from a file, if available.
///
/// May fail with an error-code describing why the file cannot be read.
///
/// Multiple read, write, and append streams may be active on the same open
/// file and they do not interfere with each other.
Expand All @@ -322,25 +324,29 @@ interface types {
this: descriptor,
/// The offset within the file at which to start reading.
offset: filesize,
) -> input-stream
) -> result<input-stream, error-code>

/// Return a stream for writing to a file.
/// Return a stream for writing to a file, if available.
///
/// May fail with an error-code describing why the file cannot be written.
///
/// Note: This allows using `write-stream`, which is similar to `write` in
/// POSIX.
write-via-stream: func(
this: descriptor,
/// The offset within the file at which to start writing.
offset: filesize,
) -> output-stream
) -> result<output-stream, error-code>

/// Return a stream for appending to a file.
/// Return a stream for appending to a file, if available.
///
/// May fail with an error-code describing why the file cannot be appended.
///
/// Note: This allows using `write-stream`, which is similar to `write` with
/// `O_APPEND` in in POSIX.
append-via-stream: func(
this: descriptor,
) -> output-stream
) -> result<output-stream, error-code>

/// Provide file advisory information on a descriptor.
///
Expand Down

0 comments on commit 1c65f71

Please sign in to comment.