Module
pooka/file
src/pooka/file.pookaFiles are the workshop notebooks that stay after the process goes home.
Return filesystem failures as FileError with the relevant path and message. Text reads validate UTF-8; byte APIs retain the original bytes. Directory deletion is nonrecursive, while recursive creation tolerates existing directories.
import pooka/file
let result = file.read("notes.txt")
API reference
class FileError(path: String, message: String)
A file failure carrying the details needed by its caller. Keep this value in Result until a boundary can explain it.
path: String
Stringmessage: String
String
fn(String, String) -> pooka/file.FileErrorread(path: String) -> Result(String, FileError)
fn(String) -> Result(String, pooka/file.FileError)Read text and validate that its bytes are UTF-8.
import pooka/file
let result = file.read("notes.txt")
read_bytes(path: String) -> Result(BitArray, FileError)
fn(String) -> Result(BitArray, pooka/file.FileError)Read the original bytes without UTF-8 decoding.
import pooka/file
let result = file.read_bytes("notes.bin")
write(path: String, text: String) -> Result(Nil, FileError)
fn(String, String) -> Result(Nil, pooka/file.FileError)Replace a file with the supplied UTF-8 text.
import pooka/file
let result = file.write("notes.txt", "oak")
write_bytes(path: String, data: BitArray) -> Result(Nil, FileError)
fn(String, BitArray) -> Result(Nil, pooka/file.FileError)Replace a file with whole-byte data; non-byte-aligned input is rejected.
import pooka/file
let result = file.write_bytes("notes.bin", <<1, 2, 3>>)
append(path: String, text: String) -> Result(Nil, FileError)
fn(String, String) -> Result(Nil, pooka/file.FileError)Append UTF-8 text to a file.
import pooka/file
let result = file.append("notes.txt", "pine")
exists(path: String) -> Result(Bool, FileError)
fn(String) -> Result(Bool, pooka/file.FileError)Test existence. A missing path returns Ok(False); other filesystem errors retain their detail.
import pooka/file
let result = file.exists("notes.txt")
is_file(path: String) -> Result(Bool, FileError)
fn(String) -> Result(Bool, pooka/file.FileError)Check whether a path names a regular file.
import pooka/file
let result = file.is_file("notes.txt")
is_directory(path: String) -> Result(Bool, FileError)
fn(String) -> Result(Bool, pooka/file.FileError)Check whether a path names a directory.
import pooka/file
let result = file.is_directory("notes")
delete(path: String) -> Result(Nil, FileError)
fn(String) -> Result(Nil, pooka/file.FileError)Delete a file, retaining its path in any FileError.
import pooka/file
let result = file.delete("temporary.txt")
copy(source: String, destination: String) -> Result(Nil, FileError)
fn(String, String) -> Result(Nil, pooka/file.FileError)Copy a file to a destination. Failures identify the source path.
import pooka/file
let result = file.copy("notes.txt", "notes-copy.txt")
rename(source: String, destination: String) -> Result(Nil, FileError)
fn(String, String) -> Result(Nil, pooka/file.FileError)Rename a path. Failures identify the source path.
import pooka/file
let result = file.rename("old-notes.txt", "notes.txt")
list_directory(path: String) -> Result(List(String), FileError)
fn(String) -> Result(List(String), pooka/file.FileError)List names in a directory without promising their order.
import pooka/file
let result = file.list_directory("notes")
create_directory(path: String) -> Result(Nil, FileError)
fn(String) -> Result(Nil, pooka/file.FileError)Create one directory; its parent must already exist.
import pooka/file
let result = file.create_directory("notes")
create_directories(path: String) -> Result(Nil, FileError)
fn(String) -> Result(Nil, pooka/file.FileError)Create missing parent directories; existing directories are accepted.
import pooka/file
let result = file.create_directories("notes/winter")
remove_directory(path: String) -> Result(Nil, FileError)
fn(String) -> Result(Nil, pooka/file.FileError)Remove an empty directory. This does not recursively delete its contents.
import pooka/file
let result = file.remove_directory("empty-notes")