std::io

std/src/io.mo

defIO.println#
pub def IO.println (s : String) : IO Unit

Write s and a newline to stdout (buffered; see IO.flush_stdout).

defIO.write_file#
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.

defIO.write_file_bytes#
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.

defIO.read_file#
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.

defIO.read_file_bytes#
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.

defIO.read_tail#
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.

defIO.tail_text#
pub def IO.tail_text (from : I64) (bytes : List U8) : String

A tail cut mid-file loses at most three continuation bytes (0b10xxxxxx) at its front; NUL becomes a space, since a String ends at one.

defIO.file_exists_native#
pub def IO.file_exists_native (path : String) : IO Bool

Does path exist, following symlinks?

defIO.is_dir_native#
pub def IO.is_dir_native (path : String) : IO Bool

Is path a directory, following symlinks?

defIO.file_size_raw#
pub def IO.file_size_raw (path : String) : IO I64

A file's size in bytes, or -1 when it cannot be stated -- the convention IO.file_size above decodes into Option.none.

defIO.list_dir_native#
pub def IO.list_dir_native (path : String) : IO (List String)
defIO.get_env#
pub def IO.get_env (s : String) : IO (Option String)
defIO.write_to#
pub def IO.write_to (s : FdStream) (text : String) : IO Unit
defIO.read_line#
pub def IO.read_line : IO (Result StreamError (Option String))
defIO.read_stdin_exact#
pub def IO.read_stdin_exact (n : I64) : IO String
defIO.write_stdout#
pub def IO.write_stdout (s : String) : IO Unit
defIO.flush_stdout#
pub def IO.flush_stdout : IO Unit
defIO.write_stderr#
pub def IO.write_stderr (s : String) : IO Unit
defIO.current_time#
pub def IO.current_time : IO I64
defIO.current_time_nano#
pub def IO.current_time_nano : IO I64
defIO.epoch_time_nano#
pub def IO.epoch_time_nano : IO I64

Nanoseconds 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.

defIO.file_exists#
pub def IO.file_exists (path : Path) : IO Bool
defIO.is_dir#
pub def IO.is_dir (path : Path) : IO Bool
defIO.file_size#
pub 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.

defIO.list_dir#
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).

defIO.tcp_connect_timeout#
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.

defIO.tcp_connect#
pub def IO.tcp_connect (host : String) (port : U16) : IO (Result StreamError FdStream)

Blocking connect: the zero-deadline spelling of IO.tcp_connect_timeout.

defIO.tcp_listen#
pub def IO.tcp_listen (port : U16) : IO (Result StreamError FdStream)
defIO.tcp_listen_on#
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.

defIO.tcp_accept#
pub def IO.tcp_accept (listener : FdStream) : IO (Result StreamError FdStream)
defIO.tcp_local_port#
pub def IO.tcp_local_port (listener : FdStream) : IO U16