data File
Namespace of file operations.
Example:
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 FileThread safety. the functions are independent; concurrent writers of one file must coordinate themselves.
Since. 1.0.0-beta
Methods
readText | (path: str) -> str | IoError ioWhole file as UTF-8 text. |
writeText | (path: str, text: str) -> () | IoError ioCreates or truncates the file and writes text. |
exists | (path: str) -> bool ioWhether something exists at path (a file, a directory or a link whose target exists). |
readBytes | (path: str) -> bytes | IoError ioWhole file as bytes. |
writeBytes | (path: str, content: bytes) -> () | IoError ioCreates or truncates the file and writes content. |
writeBytesSync | (path: str, content: bytes) -> () | IoError ioLike writeBytes, and fsyncs the file before returning (durable). |
appendText | (path: str, text: str) -> () | IoError ioAppends text, creating the file if needed. |
appendBytes | (path: str, content: bytes) -> () | IoError ioAppends content, creating the file if needed. |
remove | (path: str) -> () | IoError ioDeletes a file or a symbolic link (not a directory |
copy | (from: str, to: str, overwrite: bool) -> () | IoError ioCopies a file; an existing destination is replaced only with overwrite |
rename | (from: str, to: str) -> () | IoError ioRenames or moves (atomic within one file system; an existing destination file is replaced). |
metadata | (path: str) -> Metadata | IoError ioKind, size and modification time; does not follow a final symbolic link. |
stat | (path: str) -> Metadata | IoError ioLike metadata, following symbolic links. |
chmod | (path: str, mode: u32) -> () | IoError ioReplaces the permission bits (File.chmod(path, 0o600)). |
isFile | (path: str) -> bool ioWhether path is a regular file (following links); false for a missing path. |
isDir | (path: str) -> bool ioWhether path is a directory (following links); false for a missing path. |
Defined in: std/io/io.oxl:69