
louise
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
Dernier runRéussi#1199 · main · 10 min 33 s
1Étoiles
0Forks
0Issues
| 1 | /// Files, read and written whole (ADR 0049), through the `fs` capability |
| 2 | /// effect (ADR 0084). |
| 3 | /// |
| 4 | /// The runtime's real root reports `Error` with the OS's message — the real |
| 5 | /// operations do not panic for an I/O failure. Native reads, writes and |
| 6 | /// metadata calls run on the runtime's I/O blocking pool while their actor is |
| 7 | /// parked. A lexical handler can replace all five operations in a test. |
| 8 | /// |
| 9 | /// There is no sandbox: which paths are safe to touch is the program's |
| 10 | /// decision (beware `..` in paths built from requests). |
| 11 | |
| 12 | import std/bytes |
| 13 | |
| 14 | /// Filesystem authority. `file.read_bytes path`, for example, has effect |
| 15 | /// `/ <fs>`; a lexical `handle` may answer these operations without disk I/O. |
| 16 | pub effect fs |
| 17 | { |
| 18 | /// The file's contents as bytes, or why it could not be read. |
| 19 | fn read_bytes :: path: String -> Result<Bytes, String> |
| 20 | /// The bytes `content` written to `path` (created or truncated), or why it |
| 21 | /// could not be written. No directories are created. |
| 22 | fn write_bytes :: path: String content: Bytes -> Result<(), String> |
| 23 | /// Whether a file (not a directory) exists at `path`. |
| 24 | fn exists :: path: String -> Bool |
| 25 | /// The file's size in bytes, or why it could not be read. |
| 26 | fn size :: path: String -> Result<Int, String> |
| 27 | /// The names of the directory's entries (not full paths; never `.` or |
| 28 | /// `..`), or why they could not be listed (a missing or non-directory |
| 29 | /// `path`). The order is the OS's and unspecified. |
| 30 | fn list_dir :: path: String -> Result<List<String>, String> |
| 31 | } |
| 32 | |
| 33 | /// The file's contents, or why it could not be read. |
| 34 | pub fn read :: path: String -> Result<String, String> / <fs> |
| 35 | { |
| 36 | match read_bytes path { Ok(b) -> bytes.to_string b, Error(e) -> Error(e) } |
| 37 | } |
| 38 | |
| 39 | /// `content` written to `path` (created or truncated), or why it could not |
| 40 | /// be written. No directories are created. |
| 41 | pub fn write :: path: String content: String -> Result<(), String> / <fs> |
| 42 | { |
| 43 | write_bytes path (bytes.from_string content) |
| 44 | } |