/// Files, read and written whole (ADR 0049), through the `fs` capability /// effect (ADR 0084). /// /// The runtime's real root reports `Error` with the OS's message — the real /// operations do not panic for an I/O failure. Native reads, writes and /// metadata calls run on the runtime's I/O blocking pool while their actor is /// parked. A lexical handler can replace all five operations in a test. /// /// There is no sandbox: which paths are safe to touch is the program's /// decision (beware `..` in paths built from requests). import std/bytes /// Filesystem authority. `file.read_bytes path`, for example, has effect /// `/ `; a lexical `handle` may answer these operations without disk I/O. pub effect fs { /// The file's contents as bytes, or why it could not be read. fn read_bytes :: path: String -> Result /// The bytes `content` written to `path` (created or truncated), or why it /// could not be written. No directories are created. fn write_bytes :: path: String content: Bytes -> Result<(), String> /// Whether a file (not a directory) exists at `path`. fn exists :: path: String -> Bool /// The file's size in bytes, or why it could not be read. fn size :: path: String -> Result /// The names of the directory's entries (not full paths; never `.` or /// `..`), or why they could not be listed (a missing or non-directory /// `path`). The order is the OS's and unspecified. fn list_dir :: path: String -> Result, String> } /// The file's contents, or why it could not be read. pub fn read :: path: String -> Result / { match read_bytes path { Ok(b) -> bytes.to_string b, Error(e) -> Error(e) } } /// `content` written to `path` (created or truncated), or why it could not /// be written. No directories are created. pub fn write :: path: String content: String -> Result<(), String> / { write_bytes path (bytes.from_string content) }