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.
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, _ = ...) See Return Value Handling.
stat returns a FileInfo: size i64 (bytes), mode i64 (permission bits, also on Windows), mod_time i64 (seconds since the Unix epoch), and is_dir, is_file, is_symlink (all bool). stat does not follow a final symlink, so is_symlink is accurate. A missing path returns an Error. FileInfo is reserved as a type name only while @io is imported.
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 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