OxL Reference

data File

Namespace of file operations.

Example:

oxl✓ checked in CI
use std.io { File }

fn main() io {
  let path = "/tmp/oxl_doc_file_example.txt"
  File.writeText(path, "hello")!
  File.appendText(path, " world")!
  print(File.readText(path)!)
  File.remove(path)!
}
Output
hello world
pub(api) data File

Thread safety. the functions are independent; concurrent writers of one file must coordinate themselves.

Since. 1.0.0-beta

Methods

readText(path: str) -> str | IoError io
Whole file as UTF-8 text.
writeText(path: str, text: str) -> () | IoError io
Creates or truncates the file and writes text.
exists(path: str) -> bool io
Whether something exists at path (a file, a directory or a link whose target exists).
readBytes(path: str) -> bytes | IoError io
Whole file as bytes.
writeBytes(path: str, content: bytes) -> () | IoError io
Creates or truncates the file and writes content.
writeBytesSync(path: str, content: bytes) -> () | IoError io
Like writeBytes, and fsyncs the file before returning (durable).
appendText(path: str, text: str) -> () | IoError io
Appends text, creating the file if needed.
appendBytes(path: str, content: bytes) -> () | IoError io
Appends content, creating the file if needed.
remove(path: str) -> () | IoError io
Deletes a file or a symbolic link (not a directory
copy(from: str, to: str, overwrite: bool) -> () | IoError io
Copies a file; an existing destination is replaced only with overwrite
rename(from: str, to: str) -> () | IoError io
Renames or moves (atomic within one file system; an existing destination file is replaced).
metadata(path: str) -> Metadata | IoError io
Kind, size and modification time; does not follow a final symbolic link.
stat(path: str) -> Metadata | IoError io
Like metadata, following symbolic links.
chmod(path: str, mode: u32) -> () | IoError io
Replaces the permission bits (File.chmod(path, 0o600)).
isFile(path: str) -> bool io
Whether path is a regular file (following links); false for a missing path.
isDir(path: str) -> bool io
Whether path is a directory (following links); false for a missing path.

Defined in: std/io/io.oxl:69

See also