File¶
Import: import system.io;
Read the usage guide for examples and common tasks. This reference lists the public declarations for this part of the library. See Reading API signatures for parameter and result notation.
File¶
File - a small cross-runtime filesystem API.
read¶
Reads the whole file at path as UTF-8 text.
public static async fun read(
borrow path: string,
token: Option<CancellationToken> = Option.None
): Result<string, IoError>
write¶
Overwrites path with content; resolves with Ok(bytes_written) or Err on failure.
public static async fun write(
borrow path: string,
borrow content: string,
token: Option<CancellationToken> = Option.None
): Result<long, IoError>
append¶
Appends content to the end of path; resolves with Ok(bytes_written) or Err.
public static async fun append(
borrow path: string,
borrow content: string,
token: Option<CancellationToken> = Option.None
): Result<long, IoError>
read_bytes¶
Reads the whole file at path as raw bytes.
public static async fun read_bytes(
borrow path: string,
token: Option<CancellationToken> = Option.None
): Result<byte[], IoError>
write_bytes¶
Writes raw bytes to path, replacing any existing contents.
public static async fun write_bytes(
borrow path: string,
borrow data: byte[],
token: Option<CancellationToken> = Option.None
): Result<long, IoError>
delete¶
Deletes path; resolves Ok(Unit()) on success.
public static async fun delete(
borrow path: string,
token: Option<CancellationToken> = Option.None
): Result<Unit, IoError>
copy¶
Copies a file from from to to, overwriting to when it already exists.
public static async fun copy(
borrow from: string,
borrow to: string,
token: Option<CancellationToken> = Option.None
): Result<Unit, IoError>
rename¶
Renames or moves from to to (same-volume when the OS requires it).
public static async fun rename(
borrow from: string,
borrow to: string,
token: Option<CancellationToken> = Option.None
): Result<Unit, IoError>
remove_dir¶
Removes an empty directory at path.
public static async fun remove_dir(
borrow path: string,
token: Option<CancellationToken> = Option.None
): Result<Unit, IoError>
remove_dir_all¶
Recursively deletes path (file or directory tree).
public static async fun remove_dir_all(
borrow path: string,
token: Option<CancellationToken> = Option.None
): Result<Unit, IoError>
create_dir¶
Creates a single directory at path; resolves Ok(Unit()) on success.
public static async fun create_dir(
borrow path: string,
token: Option<CancellationToken> = Option.None
): Result<Unit, IoError>
create_dir_all¶
Creates path and any missing parents; resolves Ok(Unit()) on success.
public static async fun create_dir_all(
borrow path: string,
token: Option<CancellationToken> = Option.None
): Result<Unit, IoError>
list¶
Lists the entries of directory path, or Err(IoError) when the path is missing or not a directory (an existing empty directory yields Ok([])).
public static async fun list(
borrow path: string,
token: Option<CancellationToken> = Option.None
): Result<string[], IoError>
list_paths¶
Like list, but each name is joined onto path. Fails with the same IoError cases.
public static async fun list_paths(
borrow path: string,
token: Option<CancellationToken> = Option.None
): Result<string[], IoError>
read_lines¶
Reads the whole file and splits on \n, dropping a trailing empty part from a final newline.
public static async fun read_lines(
borrow path: string,
token: Option<CancellationToken> = Option.None
): Result<string[], IoError>
write_lines¶
Writes lines joined by newlines, including a trailing newline when lines is non-empty.
public static async fun write_lines(
borrow path: string,
borrow lines: string[],
token: Option<CancellationToken> = Option.None
): Result<long, IoError>
exists¶
Cheap synchronous predicates (no async overhead).
size¶
Size of path in bytes, or None if it does not exist.
is_dir¶
Returns whether the path refers to a directory.
is_file¶
Returns whether path exists and is a regular file. Returns false when the path is missing or cannot be inspected; call stat to see why.
stat¶
One stat of path. Follows symlinks. Missing paths are Err.