std::io
std/src/io.mo
pub def IO.println (s : String) : IO UnitWrite s and a newline to stdout (buffered; see IO.flush_stdout).
pub def IO.write_file (path : Path) (content : String) : IO (Result StreamError Unit)Create or truncate path and write content to it. A missing parent
directory is not_found; it is not created.
pub def IO.write_file_bytes (path : Path) (bytes : List U8) : IO (Result StreamError Unit)Write raw bytes to path, truncating it. The byte counterpart of
IO.write_file; no decoding is involved.
pub def IO.read_file (path : Path) : IO (Result StreamError String)The whole file at path as text; a missing file is not_found.
The chunks are gathered into ONE buffer and decoded once: decoding each 64 KiB chunk on its own would split a multi-byte character that straddles a chunk boundary, which the interpreter's lossy UTF-8 decode turns into U+FFFD.
pub def IO.read_file_bytes (path : Path) : IO (Result StreamError (List U8))The whole file at path as raw bytes; a missing file is not_found.
Unlike IO.read_file, this never decodes, so NUL bytes and arbitrary
binary content survive. One chunk is returned directly; several are
copied into one buffer first.
pub def IO.read_tail (path : Path) (n : I64) : IO (Result StreamError String)The last n bytes of the file at path, read from size - n so the
rest is never read: for following a log that may be large. A missing
file is not_found, and a pipe (which cannot seek) is an error. The
text never starts inside a UTF-8 character, and NUL bytes read as
spaces.
pub def IO.tail_text (from : I64) (bytes : List U8) : StringA tail cut mid-file loses at most three continuation bytes (0b10xxxxxx) at its front; NUL becomes a space, since a String ends at one.
pub def IO.file_exists_native (path : String) : IO BoolDoes path exist, following symlinks?
pub def IO.is_dir_native (path : String) : IO BoolIs path a directory, following symlinks?
pub def IO.file_size_raw (path : String) : IO I64A file's size in bytes, or -1 when it cannot be stated -- the
convention IO.file_size above decodes into Option.none.
pub def IO.list_dir_native (path : String) : IO (List String)pub def IO.get_env (s : String) : IO (Option String)pub def IO.write_to (s : FdStream) (text : String) : IO Unitpub def IO.read_line : IO (Result StreamError (Option String))pub def IO.read_stdin_exact (n : I64) : IO Stringpub def IO.write_stdout (s : String) : IO Unitpub def IO.flush_stdout : IO Unitpub def IO.write_stderr (s : String) : IO Unitpub def IO.current_time : IO I64pub def IO.current_time_nano : IO I64pub def IO.epoch_time_nano : IO I64Nanoseconds since the Unix epoch from the wall clock, on every backend
(compiled IO.current_time_nano is monotonic). For timestamps, not
intervals: a clock step can move it backwards.
pub def IO.file_exists (path : Path) : IO Boolpub def IO.is_dir (path : Path) : IO Boolpub def IO.file_size (path : Path) : IO (Option I64)The size of the file at path in bytes (following symlinks), or
none when it does not exist or cannot be read.
pub def IO.list_dir (path : Path) : IO (List Path)The entries of the directory path, one level, sorted, each joined
onto path (Path.file_name gives the bare name back).
pub def IO.tcp_connect_timeout (host : String) (port : U16) (timeout_ms : I64) : IO (Result StreamError FdStream)Connect with a deadline, including the per-address connect attempts.
Name resolution (getaddrinfo) still has no timeout.
pub def IO.tcp_connect (host : String) (port : U16) : IO (Result StreamError FdStream)Blocking connect: the zero-deadline spelling of IO.tcp_connect_timeout.
pub def IO.tcp_listen (port : U16) : IO (Result StreamError FdStream)pub def IO.tcp_listen_on (host : String) (port : U16) : IO (Result StreamError FdStream)Listen on a specific host address or name ("127.0.0.1", "localhost",
"" for the wildcard) instead of always 0.0.0.0.
pub def IO.tcp_accept (listener : FdStream) : IO (Result StreamError FdStream)pub def IO.tcp_local_port (listener : FdStream) : IO U16