Module fs/file
fs/file
Async file I/O operations with Exception-based error handling.
Wraps a file descriptor with typed async I/O operations.
Uses the Exception effect for error handling.
Example
{ File, read_string, write_file, OpenMode } :: import "std/fs/file";
main :: (fn(io : Io, exn : Exception) -> unit)({
// Write a file
io.await(write_file(Path.new(`test.txt`), `hello world`, io), { io, exn });
// Read it back
content := io.await(read_string(Path.new(`test.txt`), io), { io, exn });
println(content);
// Open with OpenMode
f := io.await(File.open(Path.new(`test.txt`), .Read, io), { io, exn });
});
Types
File
object
File
An open file handle with async read/write operations.
Provides methods for reading, writing, seeking, and querying file metadata. Files are automatically closed when disposed.
Fields
| Name | Type | Description |
|---|---|---|
_fd | i32 | |
_path | Path | |
_is_closed | bool |
Trait Implementations
impl(File, ...)
open_with : (File) fn(path : Path, mode : OpenMode, perm : FilePermission, io : Io) -> Impl(Future(File, IoExn))open_with_str : (File) fn(path : str, mode : OpenMode, perm : FilePermission, io : Io) -> Impl(Future(File, IoExn))Open a file from a str path with the given mode and custom permissions.
Parameters
| Name | Type | Notes | Description |
|---|---|---|---|
path | str | Get the path this file was opened with. | |
mode | OpenMode | ||
perm | FilePermission | ||
io | Io |
open_with_cstr : (File) fn(path : *(u8), mode : OpenMode, perm : FilePermission, io : Io) -> Impl(Future(File, IoExn))Open a file from a C string path with the given mode and custom permissions.
Parameters
| Name | Type | Notes | Description |
|---|---|---|---|
path | *(u8) | Get the path this file was opened with. | |
mode | OpenMode | ||
perm | FilePermission | ||
io | Io |
open : (File) fn(path : Path, mode : OpenMode, io : Io) -> Impl(Future(File, IoExn))open_str : (File) fn(path : str, mode : OpenMode, io : Io) -> Impl(Future(File, IoExn))open_cstr : (File) fn(path : *(u8), mode : OpenMode, io : Io) -> Impl(Future(File, IoExn))read : (File) fn(self : File, buf : *(u8), size : u32, io : Io) -> Impl(Future(i32, IoExn))write_string : (File) fn(self : File, data : String, io : Io) -> Impl(Future(i32, IoExn))write_bytes : (File) fn(self : File, data : ArrayList(u8), io : Io) -> Impl(Future(i32, IoExn))read_bytes : (File) fn(self : File, io : Io) -> Impl(Future(ArrayList(u8), IoExn))read_string : (File) fn(self : File, io : Io) -> Impl(Future(String, IoExn))flush : (File) fn(self : File, io : Io) -> Impl(Future(unit, IoExn))seek : (File) fn(self : File, offset : i64, from : SeekFrom, exn : Exception) -> i64position : (File) fn(self : File) -> i64Get the current file position (byte offset from the beginning).
Parameters
| Name | Type | Notes |
|---|---|---|
self | File |
Returns: i64
size : (File) fn(self : File) -> i64close : (File) fn(self : File, io : Io) -> Impl(Future(unit, IoExn))fd : (File) fn(self : File) -> i32path : (File) fn(self : File) -> Pathimpl(File, Dispose(...))
dispose : (fn(self : Self) -> unit)Returns: unit
OpenMode
enum
OpenMode
Variants
| Variant | Fields | Description |
|---|---|---|
Read | ||
Write | ||
Append | ||
ReadWrite | ||
CreateNew |
FilePermission
newtype
FilePermission
Fields
| Name | Type | Description |
|---|---|---|
mode | u32 |
Methods
default : (FilePermission) fn() -> FilePermissionReturns: FilePermission
executable : (FilePermission) fn() -> FilePermissionReturns: FilePermission
readonly : (FilePermission) fn() -> FilePermissionReturns: FilePermission
private : (FilePermission) fn() -> FilePermissionReturns: FilePermission
SeekFrom
enum
SeekFrom
Variants
| Variant | Fields | Description |
|---|---|---|
Start | ||
Current | ||
End |
Functions
read_string
function
read_string_str
function
read_string_cstr
function
read_file
function
read_file_str
function
read_file_cstr
function
write_file
function
write_file_str
function
write_file_cstr
function
write_bytes
function
append_file
function
append_file_str
function
exists
function
exists_str
function
exists_cstr
function
is_file
function
is_file_str
function
is_file_cstr
function
is_dir
function
is_dir_str
function
is_dir_cstr
function
canonical
function
canonical_str
function
canonical_cstr
function