Read the file line by line (strips \r\n). limit caps how many lines are returned — a count, like range(0, N); 0 reads to EOF. A negative literal limit is a compile error (E3150).
The functions below are fallible: they return (T, Error), and the tables above show only the success type T. Always use destructuring (mut v, err = ... or mut v, _ = ...) — single-variable assignment is a compile-time error (E3089). See Return Value Handling.
Function
Full signature returns
read_file
(string, Error)
read_bytes
([u8], Error)
read_lines
([string], Error)
file_size
(i64, Error)
write_file
(bool, Error)
append_file
(bool, Error)
delete_file
(bool, Error)
rename_file
(bool, Error)
copy_file
(bool, Error)
move_file
(bool, Error)
list_dir
([string], Error)
make_dir
(bool, Error)
make_dir_all
(bool, Error)
remove_dir
(bool, Error)
remove_dir_all
(bool, Error)
walk
([string], Error)
glob
([string], Error)
write_bytes
(bool, Error)
append_bytes
(bool, Error)
temp_file
(string, Error)
temp_dir
(string, Error)
import @io
domain() {
// Always use destructuring; single-variable assignment is a compile error
io provides the OpenFlag enum for the mutually-exclusive open modes.
Reachable as io.O_RDONLY or OpenFlag.O_RDONLY (both denote the same value).
Underlying values: O_RDONLY 0, O_WRONLY 1, O_RDWR 2. OpenFlag is
reserved as a type name only while @io is imported.
All relative paths passed to @io functions (and any other stdlib function that accepts a file path, including csv.read_file, csv.write_file, and sqlite.open) are resolved relative to the current working directory of the process, the directory from which the program was launched. They are not resolved relative to the source file that contains the call.
project/
import @io
// Given project layout:
// main.gray
// src/cli.gray
// data/config.json
// Running from project/: gray main.gray
// All of these resolve from project/, regardless of which .gray file calls them:
domain() {
mut a, _ = io.read_file("data/config.json") // project/data/config.json
mut b, _ = io.read_file("./data/config.json") // same thing