
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#1197 · main · 10 min 35 s
1Étoiles
0Forks
0Issues
| 1 | /// Files, read and written whole (ADR 0049). |
| 2 | /// |
| 3 | /// Every operation is `/ <io>` and reports `Error` with the OS's message — |
| 4 | /// nothing here panics. Reading and writing run on the runtime's `io` |
| 5 | /// blocking pool, so a slow disk never stalls the scheduler. |
| 6 | /// |
| 7 | /// There is no sandbox: which paths are safe to touch is the program's |
| 8 | /// decision (beware `..` in paths built from requests). |
| 9 | |
| 10 | import std/bytes |
| 11 | |
| 12 | /// The file's contents, or why it could not be read. |
| 13 | pub fn read :: path: String -> Result<String, String> / <io> |
| 14 | { |
| 15 | match read_bytes path { Ok(b) -> bytes.to_string b, Error(e) -> Error(e) } |
| 16 | } |
| 17 | |
| 18 | /// The file's contents as bytes, or why it could not be read. |
| 19 | @extern c "tl_file_read" (blocking io) |
| 20 | pub fn read_bytes :: path: String -> Result<Bytes, String> / <io> |
| 21 | |
| 22 | /// `content` written to `path` (created or truncated), or why it could |
| 23 | /// not be written. No directories are created. |
| 24 | pub fn write :: path: String content: String -> Result<(), String> / <io> |
| 25 | { |
| 26 | write_bytes path (bytes.from_string content) |
| 27 | } |
| 28 | |
| 29 | /// The bytes `content` written to `path` (created or truncated), or why |
| 30 | /// it could not be written. |
| 31 | @extern c "tl_file_write" (blocking io) |
| 32 | pub fn write_bytes :: path: String content: Bytes -> Result<(), String> / <io> |
| 33 | |
| 34 | /// Whether a file (not a directory) exists at `path`. |
| 35 | @extern c "tl_file_exists" (blocking io) |
| 36 | pub fn exists :: path: String -> Bool / <io> |
| 37 | |
| 38 | /// The file's size in bytes, or why it could not be read. |
| 39 | @extern c "tl_file_size" (blocking io) |
| 40 | pub fn size :: path: String -> Result<Int, String> / <io> |
| 41 | |
| 42 | /// The names of the directory's entries (not full paths; never `.` or |
| 43 | /// `..`), or why they could not be listed (a missing or non-directory |
| 44 | /// `path`). The order is the OS's and unspecified. |
| 45 | @extern c "tl_file_list_dir" (blocking io) |
| 46 | pub fn list_dir :: path: String -> Result<List<String>, String> / <io> |