From 1c65f71df8e4fd6eda6970035cd276cba03c5bcb Mon Sep 17 00:00:00 2001 From: Pat Hickey Date: Wed, 7 Jun 2023 15:34:48 -0700 Subject: [PATCH] make {read,write,append}-via-stream fallible stream creation is an appropriate place to return an error-code indicating the file cannot be read, written, or appended to. --- example-world.md | 15 +++++++++------ wit/types.wit | 18 ++++++++++++------ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/example-world.md b/example-world.md index 8cd6102..3e44c98 100644 --- a/example-world.md +++ b/example-world.md @@ -833,7 +833,8 @@ not reuse it thereafter.

Functions

read-via-stream: func

-

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.

Note: This allows using read-stream, which is similar to read in POSIX.

@@ -844,10 +845,11 @@ file and they do not interfere with each other.

Return values

write-via-stream: func

-

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.

Params
@@ -857,10 +859,11 @@ POSIX.

Return values

append-via-stream: func

-

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.

Params
@@ -869,7 +872,7 @@ POSIX.

Return values

advise: func

Provide file advisory information on a descriptor.

diff --git a/wit/types.wit b/wit/types.wit index 627b638..0f7d96e 100644 --- a/wit/types.wit +++ b/wit/types.wit @@ -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. @@ -322,9 +324,11 @@ interface types { this: descriptor, /// The offset within the file at which to start reading. offset: filesize, - ) -> input-stream + ) -> result - /// 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. @@ -332,15 +336,17 @@ interface types { this: descriptor, /// The offset within the file at which to start writing. offset: filesize, - ) -> output-stream + ) -> result - /// 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 /// Provide file advisory information on a descriptor. ///