Under heavy development. This site describes the intended 1.0 language. Current features and performance vary. Development status
Sn50SnThe SnAPI programming language
Development · Evolving reference

File

Owns one safe unbuffered native file with explicit close authority. TryOpen may allocate native path storage and perform filesystem I/O. Byte I/O permits short transfers; use std.io full-transfer/buffered helpers when needed. Flush is immediate because this owner has no user-space output cache; Synchronize makes durability explicit. Every operation except IsClosed may block. Noncopy movement transfers authority and leaves the source closed. Mutable receiver loans serialize position/I/O/close; external synchronization is required between threads. Destruction closes once without flush/sync and cannot report close failure; explicit Close provides recoverable diagnostics.

Sn is under heavy development. This reference includes the intended 1.0 design; features may be incomplete in the current compiler. Read the status →

Module std.fs

import std.fs;

Public declaration contracts and authored examples. A page can document several related symbols. Implementation bodies are excluded.

File

pub final class File

Owns one safe unbuffered native file with explicit close authority. TryOpen may allocate native path storage and perform filesystem I/O. Byte I/O permits short transfers; use std.io full-transfer/buffered helpers when needed. Flush is immediate because this owner has no user-space output cache; Synchronize makes durability explicit. Every operation except IsClosed may block. Noncopy movement transfers authority and leaves the source closed. Mutable receiver loans serialize position/I/O/close; external synchronization is required between threads. Destruction closes once without flush/sync and cannot report close failure; explicit Close provides recoverable diagnostics.

Example

module example.file_ownership;
from std.fs import File, Path;
fn Main() -> i32 {
    var PathOwner = {
        // Scoped writable carriers end immediately after explicit payload transfer.
        var PathOwnerCreation = Path.TryCreate("/dev/null");
        switch PathOwnerCreation {
            case .Ok { Value = Value: mut Path& } => break move(Value);
            case .Err => return 1;
        }
    };
    var Opened = {
        var OpenedCreation = File.TryOpen(PathOwner.View, .ReadWrite);
        switch OpenedCreation {
            case .Ok { Value = Value: mut File& } => break move(Value);
            case .Err => return 2;
        }
    };
    var Moved = move(Opened);
    if !Opened.IsClosed || Moved.IsClosed { return 3; }
    let Bytes: byte[2] = [0_byte, 0xFF_byte];
    switch Moved.Write(Bytes) { case .Ok { Value = Count } => { if Count != 2 { return 4; } } case .Err => return 5; }
    var Output: byte[1] = [0_byte];
    switch Moved.Read(Output) { case .Ok { Value = Count } => { if Count != 0 { return 6; } } case .Err => return 7; }
    if Moved.Flush() is .Err { Error = _ } { return 8; }
    if Moved.Seek(0, .Start) is .Err { Error = _ } { return 9; }
    if Moved.ReadMetadata() is .Err { Error = _ } { return 10; }
    if Moved.Close() is .Err { Error = _ } { return 11; }
    if !Moved.IsClosed { return 12; }
    if Moved.Close() is .Err { Error = _ } { return 13; }
    switch Moved.Synchronize() {
        case .Err { Error = PatternPayload5016 } => {
            switch PatternPayload5016 {
                case .Failure { Reason = PatternPayload5017 } if (PatternPayload5017 is .Closed) => {}
                default => return 14;
            }
        }
        default => return 14;
    }
    return 0;
}

File.init

pub init()

Creates a closed allocation-free owner.

File.init

pub init(Source: readonly Self&) = delete;

Rejects duplicated close authority. Source: Existing file owner.

File.init

pub init(Source: mut Self&&)

Transfers authority without I/O. Source: File left closed.

File.operator

pub fn operator =(Source: readonly Self&) -> void = delete;

Rejects copying close authority. Source: Existing file owner. Return: No runtime result; this assignment is deleted and cannot be invoked.

File.operator

pub fn operator =(Source: mut Self&&) -> void = delete;

Requires explicit Close before replacing ownership. Source: Existing file owner. Return: No runtime result; this assignment is deleted and cannot be invoked.

File.IsClosed

pub IsClosed: bool;

Observes closed/moved state without I/O.

File.TryOpen

pub static fn TryOpen(mut Path: PathView, Mode: FileOpenMode, Links: LinkPolicy) -> Result<Self, IoError>

Opens an absolute native path with explicit access/creation semantics. Path: Borrowed native units, copied only during the open operation. Mode: Access/creation policy; default opens existing input. Links: Final-component policy; NoFollow rejects data open of a symbolic link. Return: Sole file owner or portable path/storage/native failure. Warning: May allocate and block. Relative paths are rejected; no implicit cwd.

File.TryOpen

pub static fn TryOpen(mut Path: PathView) -> Result<Self, IoError>

Supplies the omitted arguments to TryOpen. Note: Defaults: Mode = .Read, Links = .Follow. Path: Same input, ownership and lifetime contract as the full operation. Return: The full synchronous operation's owned success value or typed failure.

File.TryOpen

pub static fn TryOpen(mut Path: PathView, Mode: FileOpenMode) -> Result<Self, IoError>

Supplies the omitted arguments to TryOpen. Note: Defaults: Links = .Follow. Path: Same input, ownership and lifetime contract as the full operation. Mode: Same input, ownership and lifetime contract as the full operation. Return: The full synchronous operation's owned success value or typed failure.

File.ReadMetadataAt

pub static fn ReadMetadataAt(mut Path: PathView, Links: LinkPolicy) -> Result<FileMetadata, IoError>

Reads detached metadata for one path-selected held object. Path: Borrowed absolute native path, retained through return. Links: Follow observes target; NoFollow observes final symbolic link. Return: Detached snapshot or portable path/storage/native/cleanup failure. Warning: May allocate/block. Intermediate links resolve normally. No data open, effective-access guarantee or atomic metadata snapshot is implied.

File.ReadMetadataAt

pub static fn ReadMetadataAt(mut Path: PathView) -> Result<FileMetadata, IoError>

Supplies the omitted arguments to ReadMetadataAt. Note: Defaults: Links = .Follow. Path: Same input, ownership and lifetime contract as the full operation. Return: The full synchronous operation's value or typed failure.

File.ReadMetadataAtAsync

pub static async fn ReadMetadataAtAsync(mut Path: PathView, Links: LinkPolicy, mut Token: CancellationToken) -> Task<Result<FileMetadata, IoError>>

Executes complete metadata-only path selection on a bounded worker. Path: Native view; retain borrowed backing through completion. Links: Copied final-component selection policy. Token: Cancellation observation preventing unstarted work. Return: Task with detached snapshot or exact admission/native/cleanup error. Warning: No native operation runs on the initiating thread. Completed native results win over late cancellation; temporary authority closes before return.

Example

module example.link_policy_async;
from std.process import ProgramInputs;
from std.fs import Path;
from std.fs import File, Directory, PathView;
from std.io import IoError;
from std.prelude import Result;
from std.task import Task, CancellationToken;
// Caller owns fixture paths: a two-byte regular file selected through FileLink,
// and a directory selected through DirectoryLink. Each is a final symbolic link.
// Observations retain no path/handle loan after return; no mutation is intended.
async fn InspectLinksAsync(FileLink: PathView, DirectoryLink: PathView) -> Task<Result<void, IoError>> {
    let Link = switch await File.ReadMetadataAtAsync(FileLink, .NoFollow) { case .Ok { Value = Value } => Value; case .Err { Error = Error } => return .Err { Error = Error }; };
    let Target = switch await File.ReadMetadataAtAsync(FileLink, .Follow) { case .Ok { Value = Value } => Value; case .Err { Error = Error } => return .Err { Error = Error }; };
    if Link.Kind != .SymbolicLink || Target.Kind != .Regular { return .Err { Error = .Failure { Reason = .NativeFailure, Transferred = 0 } }; }
    // Keep an unexpected success writable until its explicit close.
    var FileOpenAttempt = await File.TryOpenAsync(FileLink, .CreateOrTruncate, CancellationToken(), .NoFollow);
    switch FileOpenAttempt {
        case .Err { Error = PatternPayload5023 } => {
            switch PatternPayload5023 {
                case .Failure { Reason = PatternPayload5024 } if (PatternPayload5024 is .LinkResolutionFailure) => {}
                default => { let Error = PatternPayload5023; return .Err { Error = Error }; }
            }
        }
        case .Ok { Value = Value: mut File& } => { var Unexpected = move(Value); switch await Unexpected.CloseAsync() { case .Ok => {} case .Err { Error = Error } => return .Err { Error = Error }; } return .Err { Error = .Failure { Reason = .NativeFailure, Transferred = 0 } }; }
    }
    let Preserved = switch await File.ReadMetadataAtAsync(FileLink) { case .Ok { Value = Value } => Value; case .Err { Error = Error } => return .Err { Error = Error }; };
    let Length = switch Preserved.ByteLength { case .Some { Value = Value } => Value; case .None => return .Err { Error = .Failure { Reason = .NativeFailure, Transferred = 0 } }; };
    if Length != 2 { return .Err { Error = .Failure { Reason = .NativeFailure, Transferred = 0 } }; }
    var OpenedDirectory = {
        // Scoped writable carriers end immediately after explicit payload transfer.
        var OpenedDirectoryCreation = await Directory.TryOpenAsync(DirectoryLink, CancellationToken(), .Follow);
        switch OpenedDirectoryCreation {
            case .Ok { Value = Value: mut Directory& } => break move(Value);
            case .Err { Error = Error } => return .Err { Error = Error };
        }
    };
    switch await OpenedDirectory.CloseAsync() { case .Ok => {} case .Err { Error = Error } => return .Err { Error = Error }; }
    // Linux O_DIRECTORY|O_NOFOLLOW may report ENOTDIR instead of ELOOP.
    var DirectoryOpenAttempt = await Directory.TryOpenAsync(DirectoryLink, CancellationToken(), .NoFollow);
    switch DirectoryOpenAttempt {
        case .Err { Error = PatternPayload5025 } => {
            switch PatternPayload5025 {
                case .Failure { Reason = PatternPayload5026 } if (PatternPayload5026 is .LinkResolutionFailure) => {}
                case .Failure { Reason = PatternPayload5027 } if (PatternPayload5027 is .NotFound) => {}
                default => { let Error = PatternPayload5025; return .Err { Error = Error }; }
            }
        }
        case .Ok { Value = Value: mut Directory& } => { var Unexpected = move(Value); switch await Unexpected.CloseAsync() { case .Ok => {} case .Err { Error = Error } => return .Err { Error = Error }; } return .Err { Error = .Failure { Reason = .NativeFailure, Transferred = 0 } }; }
    }
    return .Ok;
}

// Supply absolute paths to exclusively owned, disposable fixtures as arguments.
async fn Main(Inputs: ProgramInputs) -> Task<i32> {
    if Inputs.Arguments().Length != 3 { return 20; }
    let FilePathText = switch Inputs.Arguments()[1].TryViewUtf8() { case .Some { Value = Text } => break Text; case .None => return 21; };
    var FilePath = {
        var Creation = Path.TryCreate(FilePathText);
        switch Creation { case .Ok { Value = Created: mut Path& } => break move(Created); case .Err => return 22; }
    };
    let DirectoryPathText = switch Inputs.Arguments()[2].TryViewUtf8() { case .Some { Value = Text } => break Text; case .None => return 21; };
    var DirectoryPath = {
        var Creation = Path.TryCreate(DirectoryPathText);
        switch Creation { case .Ok { Value = Created: mut Path& } => break move(Created); case .Err => return 22; }
    };
    switch await InspectLinksAsync(FilePath.View, DirectoryPath.View) { case .Ok => return 0; case .Err => return 23; }
}

File.ReadMetadataAtAsync

pub static fn ReadMetadataAtAsync(mut Path: PathView) -> Task<Result<FileMetadata, IoError>>

Supplies the omitted arguments to ReadMetadataAtAsync. Note: Defaults: Links = .Follow, Token = CancellationToken(). Path: Same input, ownership and lifetime contract as the full operation. Return: Exact full-operation result; no additional async frame is created.

File.ReadMetadataAtAsync

pub static fn ReadMetadataAtAsync(mut Path: PathView, Links: LinkPolicy) -> Task<Result<FileMetadata, IoError>>

Supplies the omitted arguments to ReadMetadataAtAsync. Note: Defaults: Token = CancellationToken(). Path: Same input, ownership and lifetime contract as the full operation. Links: Same input, ownership and lifetime contract as the full operation. Return: Exact full-operation result; no additional async frame is created.

File.Read

pub fn Read(Output: mut byte[]) -> Result<usize, IoError>

Performs one potentially short byte read. Output: Borrowed writable destination live through return. Return: Count, zero at EOF, or portable error. Warning: May block.

File.Write

pub fn Write(Input: readonly byte[]) -> Result<usize, IoError>

Performs one potentially short byte write. Input: Borrowed readable bytes live through return. Return: Accepted count or portable error. Warning: May block; no implicit flush/sync.

File.Flush

pub fn Flush() -> Result<void, IoError>

Completes user-space propagation for an unbuffered file. Return: Immediate success, or Closed; this performs no durability request.

File.Synchronize

pub fn Synchronize() -> Result<void, IoError>

Requests native durable-storage synchronization explicitly. Return: Success or portable storage/closed failure. Warning: May block on storage.

File.Seek

pub fn Seek(Offset: i64, Origin: SeekOrigin) -> Result<u64, IoError>

Changes the shared file position using a checked signed byte offset. Offset: Signed bytes relative to Origin. Origin: Position basis. Return: Absolute byte position or portable failure. Warning: May block.

File.Seek

pub fn Seek(Offset: i64) -> Result<u64, IoError>

Supplies the omitted arguments to Seek. Note: Defaults: Origin = .Start. Offset: Same input, ownership and lifetime contract as the full operation. Return: The full synchronous operation's value or typed failure.

File.ReadMetadata

pub fn ReadMetadata() -> Result<FileMetadata, IoError>

Reads a portable metadata snapshot without retaining another file lease. Return: Owned snapshot or portable failure; concurrent changes can make it stale. Warning: May block.

File.ChangePosixMode

pub fn ChangePosixMode(Mode: PosixFileMode) -> Result<void, IoError>

Caller retains its opened owner and handles the returned Result before deciding cleanup. This function changes its caller-provided object; it does not acquire a machine-local pathname or hide access checks.

Changes POSIX permission/special bits on the opened object. Mode: Owned semantic mode snapshot, not an ACL or effective access grant. Return: Success or exact portable native failure. Warning: May block; native ACL mask may change.

Example

module example.file_metadata_changes;
from std.process import ProgramInputs;
from std.fs import Path;
from std.fs import File, FileMetadata, PosixAccess, PosixFileMode, PosixOwnershipChange, FileTimestampChange;
from std.io import IoError;
from std.prelude import Result;
from std.time import Timestamp;
// Caller supplies its own opened file, desired numeric owner and wall time.
// Every operation may block. A later failure leaves earlier changes committed.
fn ConfigureOwnedFile(Opened: mut File&, UserId: u64, Modified: Timestamp) -> Result<FileMetadata, IoError> {
    let Ownership = PosixOwnershipChange { UserId = .Some { Value = UserId }, GroupId = none, };
    switch Opened.ChangePosixOwnership(Ownership) { case .Ok => {} case .Err { Error = Error } => return .Err { Error = Error }; }
    let Mode = PosixFileMode {
        Owner = PosixAccess { CanRead = true, CanWrite = true, CanExecute = false, },
        Group = PosixAccess { CanRead = true, CanWrite = false, CanExecute = false, },
        Other = PosixAccess { CanRead = false, CanWrite = false, CanExecute = false, },
        SetUserId = false, SetGroupId = false, Sticky = false,
    };
    switch Opened.ChangePosixMode(Mode) { case .Ok => {} case .Err { Error = Error } => return .Err { Error = Error }; }
    let Unchanged = FileTimestampChange { Accessed = .Keep, Modified = .Keep, };
    switch Opened.ChangeTimes(Unchanged) { case .Ok => {} case .Err { Error = Error } => return .Err { Error = Error }; }
    let Times = FileTimestampChange { Accessed = .Now, Modified = .Exact { Value = Modified }, };
    switch Opened.ChangeTimes(Times) { case .Ok => {} case .Err { Error = Error } => return .Err { Error = Error }; }
    return Opened.ReadMetadata();
}

// Supply absolute paths to exclusively owned, disposable fixtures as arguments.
fn Main(Inputs: ProgramInputs) -> i32 {
    if Inputs.Arguments().Length != 2 { return 20; }
    let OwnedPathText = switch Inputs.Arguments()[1].TryViewUtf8() { case .Some { Value = Text } => break Text; case .None => return 21; };
    var OwnedPath = {
        var Creation = Path.TryCreate(OwnedPathText);
        switch Creation { case .Ok { Value = Created: mut Path& } => break move(Created); case .Err => return 22; }
    };
    var Opened = {
        var Creation = File.TryOpen(OwnedPath.View, .ReadWrite);
        switch Creation { case .Ok { Value = Created: mut File& } => break move(Created); case .Err => return 23; }
    };
    let Snapshot = switch Opened.ReadMetadata() { case .Ok { Value = Value } => break Value; case .Err => return 24; };
    let Posix = switch Snapshot.Posix { case .Some { Value = Value } => break Value; case .None => return 25; };
    let Modified = switch Snapshot.Modified { case .Some { Value = Value } => break Value; case .None => return 26; };
    let Outcome = ConfigureOwnedFile(Opened, Posix.UserId, Modified);
    // End every operation's receiver loan before closing the sole native owner.
    let Closed = Opened.Close();
    if Outcome is .Err { Error = _ } { return 27; }
    if Closed is .Err { Error = _ } { return 28; }
    return 0;
}

File.ChangePosixOwnership

pub fn ChangePosixOwnership(Change: PosixOwnershipChange) -> Result<void, IoError>

Applies an explicit partial POSIX ownership change to the opened object. Change: Numeric identities to replace, with none preserving an identity. Return: Success or portable validation/access/native failure. Warning: May block; native ownership changes can clear special mode bits.

File.ChangeTimes

pub fn ChangeTimes(Change: FileTimestampChange) -> Result<void, IoError>

Applies paired access/modification time policies to the opened object. Change: Owned Keep/Now/Exact request, checked completely before mutation. Return: Success or portable validation/access/native failure. Warning: May block; native timestamp precision can be coarser than nanoseconds.

File.Close

pub fn Close() -> Result<void, IoError>

Consumes close authority even if native close reports failure. Return: Success for an already closed owner, otherwise native close outcome. Warning: May block; this owner is closed after every result.

File.ReadPosixAcl

pub fn ReadPosixAcl(Scope: PosixAclScope) -> Result<Vector<PosixAclEntry>?, IoError>

Copies a semantic ACL; None means no stored extended ACL, not missing mode permissions. Access policy can interact with native mode bits; default policy applies to future directory children, not existing children or current caller access. Scope: Access by default; Default selects directory inheritance policy. Return: Owned success or portable input/storage/native failure; capability denial/absence remains AccessDenied/UnsupportedOperation, not None. Warning: May allocate and block. Serialize receiver use. No ACL/mode/owner transaction or atomic joint snapshot is promised.

Example

module example.posix_acl;
from std.process import ProgramInputs;
from std.fs import Path;
from std.collections import Vector;
from std.fs import File, PosixAclEntry, PosixAclScope, PosixAccess;
from std.io import IoError;
from std.prelude import Result;
// Caller owns an exclusively used file/directory and accepts policy replacement.
// Scope selects object access or directory default inheritance. Every completed
// mutation remains committed if a later operation fails; caller owns cleanup.
fn ExerciseOwnedAcl(Opened: mut File&, UserId: u64, Scope: PosixAclScope) -> Result<void, IoError> {
    let Owner = PosixAccess { CanRead = true, CanWrite = true, CanExecute = true, };
    let Read = PosixAccess { CanRead = true, CanWrite = false, CanExecute = false, };
    let NoAccess = PosixAccess { CanRead = false, CanWrite = false, CanExecute = false, };
    let Policy: PosixAclEntry[5] = [
        .Owner { Access = Owner }, .User { Id = UserId, Access = Read },
        .OwningGroup { Access = Read }, .Mask { Access = Read }, .Other { Access = NoAccess }
    ];
    switch Opened.ChangePosixAcl(Policy, Scope) { case .Ok => {} case .Err { Error = Error } => return .Err { Error = Error }; }
    var Snapshot = {
        var SnapshotResult = Opened.ReadPosixAcl(Scope);
        switch SnapshotResult {
            case .Ok { Value = SnapshotPayload: mut Vector<PosixAclEntry>?& } => break move(SnapshotPayload);
            case .Err { Error = Error } => return .Err { Error = Error };
        }
    };
    var Entries = {
        // Scoped writable carriers end immediately after explicit payload transfer.
        var EntriesCarrier = move(Snapshot);
        switch EntriesCarrier {
            case .Some { Value = Value: mut Vector<PosixAclEntry>& } => break move(Value);
            case .None => return .Err { Error = .Failure { Reason = .NativeFailure, Transferred = 0 } };
        }
    };
    if Entries.Length != 5 { return .Err { Error = .Failure { Reason = .NativeFailure, Transferred = 0 } }; }
    switch Entries[1] {
        case .User { Id = Id, Access = Access } => { if Id != UserId || !Access.CanRead || Access.CanWrite || Access.CanExecute { return .Err { Error = .Failure { Reason = .NativeFailure, Transferred = 0 } }; } }
        default => return .Err { Error = .Failure { Reason = .NativeFailure, Transferred = 0 } };
    }
    switch Entries[3] {
        case .Mask { Access = Access } => { if !Access.CanRead || Access.CanWrite || Access.CanExecute { return .Err { Error = .Failure { Reason = .NativeFailure, Transferred = 0 } }; } }
        default => return .Err { Error = .Failure { Reason = .NativeFailure, Transferred = 0 } };
    }
    // Named entries without a mask are rejected before native mutation.
    let Invalid: PosixAclEntry[4] = [.Owner { Access = Owner }, .User { Id = UserId, Access = Read }, .OwningGroup { Access = Read }, .Other { Access = NoAccess }];
    switch Opened.ChangePosixAcl(Invalid, Scope) {
        case .Err { Error = PatternPayload5028 } => {
            switch PatternPayload5028 {
                case .Failure { Reason = PatternPayload5029 } if (PatternPayload5029 is .InvalidInput) => {}
                default => { let Error = PatternPayload5028; return .Err { Error = Error }; }
            }
        }
        case .Ok => return .Err { Error = .Failure { Reason = .NativeFailure, Transferred = 0 } };
    }
    var Preserved = {
        var PreservedResult = Opened.ReadPosixAcl(Scope);
        switch PreservedResult {
            case .Ok { Value = PreservedPayload: mut Vector<PosixAclEntry>?& } => break move(PreservedPayload);
            case .Err { Error = Error } => return .Err { Error = Error };
        }
    };
    switch move(Preserved) { case .Some { Value = Value } => { if Value.Length != Entries.Length { return .Err { Error = .Failure { Reason = .NativeFailure, Transferred = 0 } }; } } case .None => return .Err { Error = .Failure { Reason = .NativeFailure, Transferred = 0 } }; }
    switch Opened.RemovePosixAcl(Scope) { case .Ok => {} case .Err { Error = Error } => return .Err { Error = Error }; }
    var Absent = {
        var AbsentResult = Opened.ReadPosixAcl(Scope);
        switch AbsentResult {
            case .Ok { Value = AbsentPayload: mut Vector<PosixAclEntry>?& } => break move(AbsentPayload);
            case .Err { Error = Error } => return .Err { Error = Error };
        }
    };
    if Absent is .Some { Value = _ } { return .Err { Error = .Failure { Reason = .NativeFailure, Transferred = 0 } }; }
    return .Ok;
}

// Supply absolute paths to exclusively owned, disposable fixtures as arguments.
fn Main(Inputs: ProgramInputs) -> i32 {
    if Inputs.Arguments().Length != 2 { return 20; }
    let OwnedPathText = switch Inputs.Arguments()[1].TryViewUtf8() { case .Some { Value = Text } => break Text; case .None => return 21; };
    var OwnedPath = {
        var Creation = Path.TryCreate(OwnedPathText);
        switch Creation { case .Ok { Value = Created: mut Path& } => break move(Created); case .Err => return 22; }
    };
    var Opened = {
        var Creation = File.TryOpen(OwnedPath.View, .ReadWrite);
        switch Creation { case .Ok { Value = Created: mut File& } => break move(Created); case .Err => return 23; }
    };
    let Snapshot = switch Opened.ReadMetadata() { case .Ok { Value = Value } => break Value; case .Err => return 24; };
    let Posix = switch Snapshot.Posix { case .Some { Value = Value } => break Value; case .None => return 25; };
    let Outcome = ExerciseOwnedAcl(Opened, Posix.UserId, .Access);
    // End every operation's receiver loan before closing the sole native owner.
    let Closed = Opened.Close();
    if Outcome is .Err { Error = _ } { return 27; }
    if Closed is .Err { Error = _ } { return 28; }
    return 0;
}

File.ReadPosixAcl

pub fn ReadPosixAcl() -> Result<Vector<PosixAclEntry>?, IoError>

Supplies the omitted arguments to ReadPosixAcl. Note: Defaults: Scope = .Access. Return: The full synchronous operation's value or typed failure.

File.ReadPosixAclAsync

pub async fn ReadPosixAclAsync(Scope: PosixAclScope, mut Token: CancellationToken) -> Task<Result<Vector<PosixAclEntry>?, IoError>>

Executes ReadPosixAcl entirely on the bounded blocking worker. Scope: Copied access/default domain. Token: Cancellation observation preventing unstarted work. Return: Task yielding owned success or exact admission/native error. Warning: Retains receiver/backing loans through completion. Started native results win; cancellation cannot roll back completed policy changes.

Example

module example.posix_acl_async;
from std.process import ProgramInputs;
from std.fs import Path;
from std.collections import Vector;
from std.fs import File, PosixAclEntry, PosixAclScope, PosixAccess;
from std.io import IoError;
from std.prelude import Result;
from std.task import Task;
// Caller owns an exclusively used file/directory and accepts policy replacement.
// Scope selects object access or directory default inheritance. Every completed
// mutation remains committed if a later operation fails; caller owns cleanup.
async fn ExerciseOwnedAclAsync(Opened: mut File&, UserId: u64, Scope: PosixAclScope) -> Task<Result<void, IoError>> {
    let Owner = PosixAccess { CanRead = true, CanWrite = true, CanExecute = true, };
    let Read = PosixAccess { CanRead = true, CanWrite = false, CanExecute = false, };
    let NoAccess = PosixAccess { CanRead = false, CanWrite = false, CanExecute = false, };
    let Policy: PosixAclEntry[5] = [
        .Owner { Access = Owner }, .User { Id = UserId, Access = Read },
        .OwningGroup { Access = Read }, .Mask { Access = Read }, .Other { Access = NoAccess }
    ];
    switch await Opened.ChangePosixAclAsync(Policy, Scope) { case .Ok => {} case .Err { Error = Error } => return .Err { Error = Error }; }
    var Snapshot = {
        var SnapshotResult = await Opened.ReadPosixAclAsync(Scope);
        switch SnapshotResult {
            case .Ok { Value = SnapshotPayload: mut Vector<PosixAclEntry>?& } => break move(SnapshotPayload);
            case .Err { Error = Error } => return .Err { Error = Error };
        }
    };
    var Entries = {
        // Scoped writable carriers end immediately after explicit payload transfer.
        var EntriesCarrier = move(Snapshot);
        switch EntriesCarrier {
            case .Some { Value = Value: mut Vector<PosixAclEntry>& } => break move(Value);
            case .None => return .Err { Error = .Failure { Reason = .NativeFailure, Transferred = 0 } };
        }
    };
    if Entries.Length != 5 { return .Err { Error = .Failure { Reason = .NativeFailure, Transferred = 0 } }; }
    switch Entries[1] {
        case .User { Id = Id, Access = Access } => { if Id != UserId || !Access.CanRead || Access.CanWrite || Access.CanExecute { return .Err { Error = .Failure { Reason = .NativeFailure, Transferred = 0 } }; } }
        default => return .Err { Error = .Failure { Reason = .NativeFailure, Transferred = 0 } };
    }
    switch Entries[3] {
        case .Mask { Access = Access } => { if !Access.CanRead || Access.CanWrite || Access.CanExecute { return .Err { Error = .Failure { Reason = .NativeFailure, Transferred = 0 } }; } }
        default => return .Err { Error = .Failure { Reason = .NativeFailure, Transferred = 0 } };
    }
    // Named entries without a mask are rejected before native mutation.
    let Invalid: PosixAclEntry[4] = [.Owner { Access = Owner }, .User { Id = UserId, Access = Read }, .OwningGroup { Access = Read }, .Other { Access = NoAccess }];
    switch await Opened.ChangePosixAclAsync(Invalid, Scope) {
        case .Err { Error = PatternPayload5030 } => {
            switch PatternPayload5030 {
                case .Failure { Reason = PatternPayload5031 } if (PatternPayload5031 is .InvalidInput) => {}
                default => { let Error = PatternPayload5030; return .Err { Error = Error }; }
            }
        }
        case .Ok => return .Err { Error = .Failure { Reason = .NativeFailure, Transferred = 0 } };
    }
    var Preserved = {
        var PreservedResult = await Opened.ReadPosixAclAsync(Scope);
        switch PreservedResult {
            case .Ok { Value = PreservedPayload: mut Vector<PosixAclEntry>?& } => break move(PreservedPayload);
            case .Err { Error = Error } => return .Err { Error = Error };
        }
    };
    switch move(Preserved) { case .Some { Value = Value } => { if Value.Length != Entries.Length { return .Err { Error = .Failure { Reason = .NativeFailure, Transferred = 0 } }; } } case .None => return .Err { Error = .Failure { Reason = .NativeFailure, Transferred = 0 } }; }
    switch await Opened.RemovePosixAclAsync(Scope) { case .Ok => {} case .Err { Error = Error } => return .Err { Error = Error }; }
    var Absent = {
        var AbsentResult = await Opened.ReadPosixAclAsync(Scope);
        switch AbsentResult {
            case .Ok { Value = AbsentPayload: mut Vector<PosixAclEntry>?& } => break move(AbsentPayload);
            case .Err { Error = Error } => return .Err { Error = Error };
        }
    };
    if Absent is .Some { Value = _ } { return .Err { Error = .Failure { Reason = .NativeFailure, Transferred = 0 } }; }
    return .Ok;
}

// Supply absolute paths to exclusively owned, disposable fixtures as arguments.
async fn Main(Inputs: ProgramInputs) -> Task<i32> {
    if Inputs.Arguments().Length != 2 { return 20; }
    let OwnedPathText = switch Inputs.Arguments()[1].TryViewUtf8() { case .Some { Value = Text } => break Text; case .None => return 21; };
    var OwnedPath = {
        var Creation = Path.TryCreate(OwnedPathText);
        switch Creation { case .Ok { Value = Created: mut Path& } => break move(Created); case .Err => return 22; }
    };
    var Opened = {
        var Creation = File.TryOpen(OwnedPath.View, .ReadWrite);
        switch Creation { case .Ok { Value = Created: mut File& } => break move(Created); case .Err => return 23; }
    };
    let Snapshot = switch Opened.ReadMetadata() { case .Ok { Value = Value } => break Value; case .Err => return 24; };
    let Posix = switch Snapshot.Posix { case .Some { Value = Value } => break Value; case .None => return 25; };
    let Outcome = await ExerciseOwnedAclAsync(Opened, Posix.UserId, .Access);
    // End every operation's receiver loan before closing the sole native owner.
    let Closed = Opened.Close();
    if Outcome is .Err { Error = _ } { return 27; }
    if Closed is .Err { Error = _ } { return 28; }
    return 0;
}

File.ReadPosixAclAsync

pub fn ReadPosixAclAsync() -> Task<Result<Vector<PosixAclEntry>?, IoError>>

Supplies the omitted arguments to ReadPosixAclAsync. Note: Defaults: Scope = .Access, Token = CancellationToken(). Return: Exact full-operation result; no additional async frame is created.

File.ReadPosixAclAsync

pub fn ReadPosixAclAsync(mut Scope: PosixAclScope) -> Task<Result<Vector<PosixAclEntry>?, IoError>>

Supplies the omitted arguments to ReadPosixAclAsync. Note: Defaults: Token = CancellationToken(). Scope: Same input, ownership and lifetime contract as the full operation. Return: Exact full-operation result; no additional async frame is created.

File.ChangePosixAcl

pub fn ChangePosixAcl(Entries: readonly PosixAclEntry[], Scope: PosixAclScope) -> Result<void, IoError>

Validates and replaces one canonical semantic ACL before native mutation. Entries require Owner, OwningGroup and Other exactly once, ascending unique named IDs and a Mask for named entries; validation precedes mutation. Access policy can interact with native mode bits; default policy applies to future directory children, not existing children or current caller access. Entries: Borrowed canonical semantic policy; provider-representable IDs. Scope: Access by default; Default selects directory inheritance policy. Return: Owned success or portable input/storage/native failure; capability denial/absence remains AccessDenied/UnsupportedOperation, not None. Warning: May allocate and block. Serialize receiver use. No ACL/mode/owner transaction or atomic joint snapshot is promised.

File.ChangePosixAcl

pub fn ChangePosixAcl(Entries: readonly PosixAclEntry[]) -> Result<void, IoError>

Supplies the omitted arguments to ChangePosixAcl. Note: Defaults: Scope = .Access. Entries: Same input, ownership and lifetime contract as the full operation. Return: The full synchronous operation's success or typed failure.

File.ChangePosixAclAsync

pub async fn ChangePosixAclAsync(Entries: readonly PosixAclEntry[], Scope: PosixAclScope, mut Token: CancellationToken) -> Task<Result<void, IoError>>

Executes ChangePosixAcl entirely on the bounded blocking worker. Entries: Borrowed entries retained until task completion. Scope: Copied access/default domain. Token: Cancellation observation preventing unstarted work. Return: Task yielding owned success or exact admission/native error. Warning: Retains receiver/backing loans through completion. Started native results win; cancellation cannot roll back completed policy changes.

File.ChangePosixAclAsync

pub fn ChangePosixAclAsync(Entries: readonly PosixAclEntry[]) -> Task<Result<void, IoError>>

Supplies the omitted arguments to ChangePosixAclAsync. Note: Defaults: Scope = .Access, Token = CancellationToken(). Entries: Same input, ownership and lifetime contract as the full operation. Return: Exact full-operation result; no additional async frame is created.

File.ChangePosixAclAsync

pub fn ChangePosixAclAsync(Entries: readonly PosixAclEntry[], mut Scope: PosixAclScope) -> Task<Result<void, IoError>>

Supplies the omitted arguments to ChangePosixAclAsync. Note: Defaults: Token = CancellationToken(). Entries: Same input, ownership and lifetime contract as the full operation. Scope: Same input, ownership and lifetime contract as the full operation. Return: Exact full-operation result; no additional async frame is created.

File.RemovePosixAcl

pub fn RemovePosixAcl(Scope: PosixAclScope) -> Result<void, IoError>

Removes one stored ACL, reporting observed absence as NotFound. Presence observation and native removal are separate operations; external policy mutation can race them. No atomic read-and-remove is promised. Access policy can interact with native mode bits; default policy applies to future directory children, not existing children or current caller access. Scope: Access by default; Default selects directory inheritance policy. Return: Owned success or portable input/storage/native failure; capability denial/absence remains AccessDenied/UnsupportedOperation, not None. Warning: May allocate and block. Serialize receiver use. No ACL/mode/owner transaction or atomic joint snapshot is promised.

File.RemovePosixAcl

pub fn RemovePosixAcl() -> Result<void, IoError>

Supplies the omitted arguments to RemovePosixAcl. Note: Defaults: Scope = .Access. Return: The full synchronous operation's success or typed failure.

File.RemovePosixAclAsync

pub async fn RemovePosixAclAsync(Scope: PosixAclScope, mut Token: CancellationToken) -> Task<Result<void, IoError>>

Executes RemovePosixAcl entirely on the bounded blocking worker. Scope: Copied access/default domain. Token: Cancellation observation preventing unstarted work. Return: Task yielding owned success or exact admission/native error. Warning: Retains receiver/backing loans through completion. Started native results win; cancellation cannot roll back completed policy changes.

File.RemovePosixAclAsync

pub fn RemovePosixAclAsync() -> Task<Result<void, IoError>>

Supplies the omitted arguments to RemovePosixAclAsync. Note: Defaults: Scope = .Access, Token = CancellationToken(). Return: Exact full-operation result; no additional async frame is created.

File.RemovePosixAclAsync

pub fn RemovePosixAclAsync(mut Scope: PosixAclScope) -> Task<Result<void, IoError>>

Supplies the omitted arguments to RemovePosixAclAsync. Note: Defaults: Token = CancellationToken(). Scope: Same input, ownership and lifetime contract as the full operation. Return: Exact full-operation result; no additional async frame is created.

File.ReadExtendedAttribute

pub fn ReadExtendedAttribute(Name: readonly byte[]) -> Result<Vector<byte>?, IoError>

Reads an owned value; None means absent and Some(empty) means present empty. Native names are nonempty bytes without NUL; no Unicode conversion occurs. Name: Exact borrowed bytes; retained only through this call. Return: Owned success or explicit Closed/InvalidInput/AccessDenied/UnsupportedOperation and storage/native failures. Repeated query/copy races report ResourceChanged. Warning: May allocate and block. Serialize access to the receiver.

File.ReadExtendedAttributeAsync

pub async fn ReadExtendedAttributeAsync(Name: readonly byte[], mut Token: CancellationToken) -> Task<Result<Vector<byte>?, IoError>>

Executes ReadExtendedAttribute entirely inside the bounded blocking callback. Name: Exact borrowed bytes; backing must remain live until completion. Token: Cancellation observation preventing unstarted work. Return: Task with owned success or exact admission/native error. Warning: Retains the mutable receiver and slice loans through completion. Native results win after execution; cancellation does not undo mutation.

Example

module example.file_attributes_async;
from std.process import ProgramInputs;
from std.fs import Path;
from std.collections import Vector;
from std.fs import File;
from std.io import IoError;
from std.prelude import Result;
from std.task import Task;
async fn ReplaceOwnedAttributeAsync(Opened: mut File&) -> Task<Result<void, IoError>> {
    let Name: byte[13] = [0x75_byte, 0x73_byte, 0x65_byte, 0x72_byte, 0x2E_byte, 0x73_byte, 0x6E_byte, 0x2D_byte, 0x70_byte, 0x6C_byte, 0x61_byte, 0x6E_byte, 0x38_byte];
    let Bytes: byte[2] = [0_byte, 0xFF_byte];
    let Empty: byte[0] = [];
    // The caller reserves this name for this workflow and retains the file loan.
    switch await Opened.RemoveExtendedAttributeAsync(Name) {
        case .Ok => {}
        case .Err { Error = PatternPayload5036 } => {
            switch PatternPayload5036 {
                case .Failure { Reason = PatternPayload5037 } if (PatternPayload5037 is .NotFound) => {}
                default => { let Error = PatternPayload5036; return .Err { Error = Error }; }
            }
        }
    }
    let Missing = {
        var MissingResult = await Opened.ReadExtendedAttributeAsync(Name);
        switch MissingResult {
            case .Ok { Value = MissingPayload: mut Vector<byte>?& } => break move(MissingPayload);
            case .Err { Error = Error } => return .Err { Error = Error };
        }
    };
    if Missing is .Some { Value = _ } { return .Err { Error = .Failure { Reason = .NativeFailure, Transferred = 0 } }; }
    switch await Opened.WriteExtendedAttributeAsync(Name, Bytes, .CreateNew) { case .Ok => {} case .Err { Error = Error } => return .Err { Error = Error }; }
    var Read = {
        var ReadResult = await Opened.ReadExtendedAttributeAsync(Name);
        switch ReadResult {
            case .Ok { Value = ReadPayload: mut Vector<byte>?& } => break move(ReadPayload);
            case .Err { Error = Error } => return .Err { Error = Error };
        }
    };
    var Owned = {
        // Scoped writable carriers end immediately after explicit payload transfer.
        var OwnedCarrier = move(Read);
        switch OwnedCarrier {
            case .Some { Value = Value: mut Vector<byte>& } => break move(Value);
            case .None => return .Err { Error = .Failure { Reason = .NativeFailure, Transferred = 0 } };
        }
    };
    if Owned.Length != 2 || Owned[0] != 0_byte || Owned[1] != 0xFF_byte { return .Err { Error = .Failure { Reason = .NativeFailure, Transferred = 0 } }; }
    switch await Opened.WriteExtendedAttributeAsync(Name, Bytes, .CreateNew) {
        case .Err { Error = PatternPayload5038 } => {
            switch PatternPayload5038 {
                case .Failure { Reason = PatternPayload5039 } if (PatternPayload5039 is .AlreadyExists) => {}
                default => { let Error = PatternPayload5038; return .Err { Error = Error }; }
            }
        }
        case .Ok => return .Err { Error = .Failure { Reason = .NativeFailure, Transferred = 0 } };
    }
    switch await Opened.WriteExtendedAttributeAsync(Name, Empty, .ReplaceExisting) { case .Ok => {} case .Err { Error = Error } => return .Err { Error = Error }; }
    var Present = {
        var PresentResult = await Opened.ReadExtendedAttributeAsync(Name);
        switch PresentResult {
            case .Ok { Value = PresentPayload: mut Vector<byte>?& } => break move(PresentPayload);
            case .Err { Error = Error } => return .Err { Error = Error };
        }
    };
    switch move(Present) {
        case .Some { Value = Value } => { if Value.Length != 0 { return .Err { Error = .Failure { Reason = .NativeFailure, Transferred = 0 } }; } }
        case .None => return .Err { Error = .Failure { Reason = .NativeFailure, Transferred = 0 } };
    }
    // Upsert remains an explicit choice, even when the name already exists.
    switch await Opened.WriteExtendedAttributeAsync(Name, Bytes, .Upsert) { case .Ok => {} case .Err { Error = Error } => return .Err { Error = Error }; }
    var Names = {
        var NamesCreation = await Opened.DiscoverExtendedAttributeNamesAsync();
        switch NamesCreation {
            case .Ok { Value = Value: mut Vector<Vector<byte>>& } => break move(Value);
            case .Err { Error = Error } => return .Err { Error = Error };
        }
    };
    var Found = false;
    for Candidate in Names.AsSlice() {
        if Candidate.Length == Name.Length {
            var Equal = true;
            var Index: usize = 0;
            while Index < Name.Length { if Candidate[Index] != Name[Index] { Equal = false; } Index += 1; }
            if Equal { Found = true; }
        }
    }
    if !Found { return .Err { Error = .Failure { Reason = .NativeFailure, Transferred = 0 } }; }
    return await Opened.RemoveExtendedAttributeAsync(Name);
}

// Supply absolute paths to exclusively owned, disposable fixtures as arguments.
async fn Main(Inputs: ProgramInputs) -> Task<i32> {
    if Inputs.Arguments().Length != 2 { return 20; }
    let OwnedPathText = switch Inputs.Arguments()[1].TryViewUtf8() { case .Some { Value = Text } => break Text; case .None => return 21; };
    var OwnedPath = {
        var Creation = Path.TryCreate(OwnedPathText);
        switch Creation { case .Ok { Value = Created: mut Path& } => break move(Created); case .Err => return 22; }
    };
    var Opened = {
        var Creation = File.TryOpen(OwnedPath.View, .ReadWrite);
        switch Creation { case .Ok { Value = Created: mut File& } => break move(Created); case .Err => return 23; }
    };
    let Outcome = await ReplaceOwnedAttributeAsync(Opened);
    // End every operation's receiver loan before closing the sole native owner.
    let Closed = Opened.Close();
    if Outcome is .Err { Error = _ } { return 27; }
    if Closed is .Err { Error = _ } { return 28; }
    return 0;
}

File.ReadExtendedAttributeAsync

pub fn ReadExtendedAttributeAsync(Name: readonly byte[]) -> Task<Result<Vector<byte>?, IoError>>

Supplies the omitted arguments to ReadExtendedAttributeAsync. Note: Defaults: Token = CancellationToken(). Name: Same input, ownership and lifetime contract as the full operation. Return: Exact full-operation result; no additional async frame is created.

File.WriteExtendedAttribute

pub fn WriteExtendedAttribute(Name: readonly byte[], Value: readonly byte[], Mode: ExtendedAttributeWriteMode) -> Result<void, IoError>

Writes exact bytes under explicit create/replace/upsert semantics. Native names are nonempty bytes without NUL; no Unicode conversion occurs. Name: Exact borrowed bytes; retained only through this call. Value: Exact borrowed bytes; retained only through this call. Mode: Upsert by default; CreateNew rejects existing and ReplaceExisting rejects absent. Return: Owned success or explicit Closed/InvalidInput/AccessDenied/UnsupportedOperation and storage/native failures. Repeated query/copy races report ResourceChanged. Warning: May allocate and block. Serialize access to the receiver.

File.WriteExtendedAttribute

pub fn WriteExtendedAttribute(Name: readonly byte[], Value: readonly byte[]) -> Result<void, IoError>

Supplies the omitted arguments to WriteExtendedAttribute. Note: Defaults: Mode = .Upsert. Name: Same input, ownership and lifetime contract as the full operation. Value: Same input, ownership and lifetime contract as the full operation. Return: The full synchronous operation's success or typed failure.

File.WriteExtendedAttributeAsync

pub async fn WriteExtendedAttributeAsync(Name: readonly byte[], Value: readonly byte[], Mode: ExtendedAttributeWriteMode, mut Token: CancellationToken) -> Task<Result<void, IoError>>

Executes WriteExtendedAttribute entirely inside the bounded blocking callback. Name: Exact borrowed bytes; backing must remain live until completion. Value: Exact borrowed bytes; backing must remain live until completion. Mode: Copied explicit mutation policy. Token: Cancellation observation preventing unstarted work. Return: Task with owned success or exact admission/native error. Warning: Retains the mutable receiver and slice loans through completion. Native results win after execution; cancellation does not undo mutation.

File.WriteExtendedAttributeAsync

pub fn WriteExtendedAttributeAsync(Name: readonly byte[], Value: readonly byte[]) -> Task<Result<void, IoError>>

Supplies the omitted arguments to WriteExtendedAttributeAsync. Note: Defaults: Mode = .Upsert, Token = CancellationToken(). Name: Same input, ownership and lifetime contract as the full operation. Value: Same input, ownership and lifetime contract as the full operation. Return: Exact full-operation result; no additional async frame is created.

File.WriteExtendedAttributeAsync

pub fn WriteExtendedAttributeAsync(Name: readonly byte[], Value: readonly byte[], mut Mode: ExtendedAttributeWriteMode) -> Task<Result<void, IoError>>

Supplies the omitted arguments to WriteExtendedAttributeAsync. Note: Defaults: Token = CancellationToken(). Name: Same input, ownership and lifetime contract as the full operation. Value: Same input, ownership and lifetime contract as the full operation. Mode: Same input, ownership and lifetime contract as the full operation. Return: Exact full-operation result; no additional async frame is created.

File.RemoveExtendedAttribute

pub fn RemoveExtendedAttribute(Name: readonly byte[]) -> Result<void, IoError>

Removes one attribute; an absent name reports NotFound. Native names are nonempty bytes without NUL; no Unicode conversion occurs. Name: Exact borrowed bytes; retained only through this call. Return: Owned success or explicit Closed/InvalidInput/AccessDenied/UnsupportedOperation and storage/native failures. Repeated query/copy races report ResourceChanged. Warning: May allocate and block. Serialize access to the receiver.

File.RemoveExtendedAttributeAsync

pub async fn RemoveExtendedAttributeAsync(Name: readonly byte[], mut Token: CancellationToken) -> Task<Result<void, IoError>>

Executes RemoveExtendedAttribute entirely inside the bounded blocking callback. Name: Exact borrowed bytes; backing must remain live until completion. Token: Cancellation observation preventing unstarted work. Return: Task with owned success or exact admission/native error. Warning: Retains the mutable receiver and slice loans through completion. Native results win after execution; cancellation does not undo mutation.

File.RemoveExtendedAttributeAsync

pub fn RemoveExtendedAttributeAsync(Name: readonly byte[]) -> Task<Result<void, IoError>>

Supplies the omitted arguments to RemoveExtendedAttributeAsync. Note: Defaults: Token = CancellationToken(). Name: Same input, ownership and lifetime contract as the full operation. Return: Exact full-operation result; no additional async frame is created.

File.DiscoverExtendedAttributeNames

pub fn DiscoverExtendedAttributeNames() -> Result<Vector<Vector<byte>>, IoError>

Copies owned exact native names without ordering or atomic-snapshot guarantees. Native names are nonempty bytes without NUL; no Unicode conversion occurs. Return: Owned success or explicit Closed/InvalidInput/AccessDenied/UnsupportedOperation and storage/native failures. Repeated query/copy races report ResourceChanged. Warning: May allocate and block. Serialize access to the receiver.

File.DiscoverExtendedAttributeNamesAsync

pub async fn DiscoverExtendedAttributeNamesAsync(mut Token: CancellationToken) -> Task<Result<Vector<Vector<byte>>, IoError>>

Executes DiscoverExtendedAttributeNames entirely inside the bounded blocking callback. Token: Cancellation observation preventing unstarted work. Return: Task with owned success or exact admission/native error. Warning: Retains the mutable receiver and slice loans through completion. Native results win after execution; cancellation does not undo mutation.

File.DiscoverExtendedAttributeNamesAsync

pub fn DiscoverExtendedAttributeNamesAsync() -> Task<Result<Vector<Vector<byte>>, IoError>>

Supplies the omitted arguments to DiscoverExtendedAttributeNamesAsync. Note: Defaults: Token = CancellationToken(). Return: Exact full-operation result; no additional async frame is created.

File.TryOpenAsync

pub static async fn TryOpenAsync(mut Path: PathView, Mode: FileOpenMode, mut Token: CancellationToken, Links: LinkPolicy) -> Task<Result<Self, IoError>>

Executes Open on the bounded blocking executor. Path: Borrowed absolute native units retained through completion. Mode: Access/creation policy. Links: Final-component policy; defaults to Follow. See FileLinkPolicyAsyncWorkflow. Token: Cancellation observation; cannot interrupt committed native I/O. Return: Task yielding exact native result or portable dispatch/cancellation error. Warning: Retain receiver and borrowed backing until completion. No I/O runs on the initiating caller thread; native calls may occupy a worker until return.

Example

module example.async_file_ownership;
from std.fs import File, Path;
from std.task import Task, CancellationSource;
async fn Main() -> Task<i32> {
    var PathOwner = {
        // Scoped writable carriers end immediately after explicit payload transfer.
        var PathOwnerCreation = Path.TryCreate("/dev/null");
        switch PathOwnerCreation {
            case .Ok { Value = Value: mut Path& } => break move(Value);
            case .Err => return 1;
        }
    };
    var Opened = {
        var OpenedCreation = await File.TryOpenAsync(PathOwner.View, .ReadWrite);
        switch OpenedCreation {
            case .Ok { Value = Value: mut File& } => break move(Value);
            case .Err => return 2;
        }
    };
    var Moved = move(Opened);
    if !Opened.IsClosed || Moved.IsClosed { return 3; }
    let Bytes: byte[2] = [0_byte, 0xFF_byte];
    switch await Moved.WriteAsync(Bytes) { case .Ok { Value = Count } => { if Count != 2 { return 4; } } case .Err => return 5; }
    var Output: byte[1] = [0_byte];
    switch await Moved.ReadAsync(Output) { case .Ok { Value = Count } => { if Count != 0 { return 6; } } case .Err => return 7; }
    if await Moved.FlushAsync() is .Err { Error = _ } { return 8; }
    if await Moved.SeekAsync(0, .Start) is .Err { Error = _ } { return 9; }
    if await Moved.ReadMetadataAsync() is .Err { Error = _ } { return 10; }
    if await Moved.CloseAsync() is .Err { Error = _ } { return 11; }
    if !Moved.IsClosed { return 12; }
    if await Moved.CloseAsync() is .Err { Error = _ } { return 13; }
    switch await Moved.SynchronizeAsync() {
        case .Err { Error = PatternPayload5040 } => {
            switch PatternPayload5040 {
                case .Failure { Reason = PatternPayload5041 } if (PatternPayload5041 is .Closed) => {}
                default => return 14;
            }
        }
        default => return 14;
    }
    var Cancel = {
        var CancelCreation = CancellationSource.TryCreate();
        switch CancelCreation {
            case .Ok { Value = Value: mut CancellationSource& } => break move(Value);
            case .Err => return 15;
        }
    };
    if !Cancel.RequestCancellation() { return 16; }
    var PendingClose = {
        var PendingCloseCreation = File.TryOpen(PathOwner.View, .ReadWrite);
        switch PendingCloseCreation {
            case .Ok { Value = Value: mut File& } => break move(Value);
            case .Err => return 17;
        }
    };
    switch await PendingClose.CloseAsync(Cancel.Token) {
        case .Err { Error = PatternPayload5042 } => {
            switch PatternPayload5042 {
                case .Failure { Reason = PatternPayload5043 } if (PatternPayload5043 is .Cancelled) => {}
                default => return 18;
            }
        }
        default => return 18;
    }
    if PendingClose.IsClosed { return 19; }
    switch await PendingClose.WriteAsync(Bytes, Cancel.Token) {
        case .Err { Error = PatternPayload5044 } => {
            switch PatternPayload5044 {
                case .Failure { Reason = PatternPayload5045, Transferred = Count } if (PatternPayload5045 is .Cancelled) => { if Count != 0 { return 20; } }
                default => return 21;
            }
        }
        default => return 21;
    }
    if await PendingClose.CloseAsync() is .Err { Error = _ } { return 22; }
    switch await File.TryOpenAsync(PathOwner.View, .Read, Cancel.Token) {
        case .Err { Error = PatternPayload5046 } => {
            switch PatternPayload5046 {
                case .Failure { Reason = PatternPayload5047 } if (PatternPayload5047 is .Cancelled) => {}
                default => return 23;
            }
        }
        default => return 23;
    }
    return 0;
}

File.TryOpenAsync

pub static fn TryOpenAsync(mut Path: PathView) -> Task<Result<Self, IoError>>

Supplies the omitted arguments to TryOpenAsync. Note: Defaults: Mode = .Read, Token = CancellationToken(), Links = .Follow. Path: Same input, ownership and lifetime contract as the full operation. Return: Exact full-operation result; no additional async frame is created.

File.TryOpenAsync

pub static fn TryOpenAsync(mut Path: PathView, Mode: FileOpenMode) -> Task<Result<Self, IoError>>

Supplies the omitted arguments to TryOpenAsync. Note: Defaults: Token = CancellationToken(), Links = .Follow. Path: Same input, ownership and lifetime contract as the full operation. Mode: Same input, ownership and lifetime contract as the full operation. Return: Exact full-operation result; no additional async frame is created.

File.TryOpenAsync

pub static fn TryOpenAsync(mut Path: PathView, Mode: FileOpenMode, mut Token: CancellationToken) -> Task<Result<Self, IoError>>

Supplies the omitted arguments to TryOpenAsync. Note: Defaults: Links = .Follow. Path: Same input, ownership and lifetime contract as the full operation. Mode: Same input, ownership and lifetime contract as the full operation. Token: Same input, ownership and lifetime contract as the full operation. Return: Exact full-operation result; no additional async frame is created.

File.ReadAsync

pub async fn ReadAsync(Output: mut byte[], mut Token: CancellationToken) -> Task<Result<usize, IoError>>

Executes Read on the bounded blocking executor. Output: Borrowed writable byte range retained through completion. Token: Cancellation observation; cannot interrupt committed native I/O. Return: Task yielding exact native result or portable dispatch/cancellation error. Warning: Retain receiver and borrowed backing until completion. No I/O runs on the initiating caller thread; native calls may occupy a worker until return.

File.ReadAsync

pub fn ReadAsync(Output: mut byte[]) -> Task<Result<usize, IoError>>

Supplies the omitted arguments to ReadAsync. Note: Defaults: Token = CancellationToken(). Output: Same input, ownership and lifetime contract as the full operation. Return: Exact full-operation result; no additional async frame is created.

File.WriteAsync

pub async fn WriteAsync(Input: readonly byte[], mut Token: CancellationToken) -> Task<Result<usize, IoError>>

Executes Write on the bounded blocking executor. Input: Borrowed readable byte range retained through completion. Token: Cancellation observation; cannot interrupt committed native I/O. Return: Task yielding exact native result or portable dispatch/cancellation error. Warning: Retain receiver and borrowed backing until completion. No I/O runs on the initiating caller thread; native calls may occupy a worker until return.

File.WriteAsync

pub fn WriteAsync(Input: readonly byte[]) -> Task<Result<usize, IoError>>

Supplies the omitted arguments to WriteAsync. Note: Defaults: Token = CancellationToken(). Input: Same input, ownership and lifetime contract as the full operation. Return: Exact full-operation result; no additional async frame is created.

File.SynchronizeAsync

pub async fn SynchronizeAsync(mut Token: CancellationToken) -> Task<Result<void, IoError>>

Executes Synchronize on the bounded blocking executor. Token: Cancellation observation; cannot interrupt committed native I/O. Return: Task yielding exact native result or portable dispatch/cancellation error. Warning: Retain receiver and borrowed backing until completion. No I/O runs on the initiating caller thread; native calls may occupy a worker until return.

File.SynchronizeAsync

pub fn SynchronizeAsync() -> Task<Result<void, IoError>>

Supplies the omitted arguments to SynchronizeAsync. Note: Defaults: Token = CancellationToken(). Return: Exact full-operation result; no additional async frame is created.

File.SeekAsync

pub async fn SeekAsync(Offset: i64, Origin: SeekOrigin, mut Token: CancellationToken) -> Task<Result<u64, IoError>>

Executes Seek on the bounded blocking executor. Offset: Signed byte displacement. Origin: Position basis. Token: Cancellation observation; cannot interrupt committed native I/O. Return: Task yielding exact native result or portable dispatch/cancellation error. Warning: Retain receiver and borrowed backing until completion. No I/O runs on the initiating caller thread; native calls may occupy a worker until return.

File.SeekAsync

pub fn SeekAsync(Offset: i64) -> Task<Result<u64, IoError>>

Supplies the omitted arguments to SeekAsync. Note: Defaults: Origin = .Start, Token = CancellationToken(). Offset: Same input, ownership and lifetime contract as the full operation. Return: Exact full-operation result; no additional async frame is created.

File.SeekAsync

pub fn SeekAsync(Offset: i64, mut Origin: SeekOrigin) -> Task<Result<u64, IoError>>

Supplies the omitted arguments to SeekAsync. Note: Defaults: Token = CancellationToken(). Offset: Same input, ownership and lifetime contract as the full operation. Origin: Same input, ownership and lifetime contract as the full operation. Return: Exact full-operation result; no additional async frame is created.

File.ReadMetadataAsync

pub async fn ReadMetadataAsync(mut Token: CancellationToken) -> Task<Result<FileMetadata, IoError>>

This Linux workflow awaits every native operation and observes detached metadata after explicit asynchronous close. Borrowed path/receiver state remains live through each await; this is authored, not execution evidence.

Executes ReadMetadata on the bounded blocking executor. Token: Cancellation observation; cannot interrupt committed native I/O. Return: Task yielding exact native result or portable dispatch/cancellation error. Warning: Retain receiver and borrowed backing until completion. No I/O runs on the initiating caller thread; native calls may occupy a worker until return.

Example

module example.async_file_metadata;
from std.task import Task;
from std.fs import File, Path, PosixAccess, PosixFileMode, PosixFileMetadata;
async fn Main() -> Task<i32> {
    var PathOwner = {
        // Scoped writable carriers end immediately after explicit payload transfer.
        var PathOwnerCreation = Path.TryCreate("/dev/null");
        switch PathOwnerCreation {
            case .Ok { Value = Value: mut Path& } => break move(Value);
            case .Err => return 1;
        }
    };
    var Opened = {
        var OpenedCreation = await File.TryOpenAsync(PathOwner.View);
        switch OpenedCreation {
            case .Ok { Value = Value: mut File& } => break move(Value);
            case .Err => return 2;
        }
    };
    let Snapshot = switch await Opened.ReadMetadataAsync() { case .Ok { Value = Value } => break Value; case .Err => return 3; };
    if await Opened.CloseAsync() is .Err { Error = _ } { return 4; }
    // No lease remains: all observed values are independent of the closed file.
    if Snapshot.Kind != .CharacterDevice { return 5; }
    if Snapshot.ByteLength is .Some { Value = _ } { return 6; }
    if Snapshot.AllocatedByteLength is .Some { Value = _ } { return 7; }
    let Links = switch Snapshot.HardLinkCount { case .Some { Value = Value } => break Value; case .None => return 8; };
    if Links == 0 { return 9; }
    let Modified = switch Snapshot.Modified { case .Some { Value = Value } => break Value; case .None => return 10; };
    let Accessed = switch Snapshot.Accessed { case .Some { Value = Value } => break Value; case .None => return 11; };
    let Changed = switch Snapshot.Changed { case .Some { Value = Value } => break Value; case .None => return 12; };
    // Birth time may be missing; neither Changed nor epoch zero substitutes for it.
    switch Snapshot.Created { case .Some { Value = Created } => { let BirthTicks = Created.UnixTime.Count; } case .None => {} }
    let Posix = switch Snapshot.Posix { case .Some { Value = Value } => break Value; case .None => return 13; };
    // Reconstruct detached mode/identity values without changing native permissions.
    let Owner = PosixAccess { CanRead = Posix.Mode.Owner.CanRead, CanWrite = Posix.Mode.Owner.CanWrite, CanExecute = Posix.Mode.Owner.CanExecute, };
    let Mode = PosixFileMode { Owner = Owner, Group = Posix.Mode.Group, Other = Posix.Mode.Other, SetUserId = Posix.Mode.SetUserId, SetGroupId = Posix.Mode.SetGroupId, Sticky = Posix.Mode.Sticky, };
    let Identity = PosixFileMetadata { Device = Posix.Device, Inode = Posix.Inode, UserId = Posix.UserId, GroupId = Posix.GroupId, Mode = Mode, };
    if Identity.Device != Posix.Device || Identity.Inode != Posix.Inode || Identity.UserId != Posix.UserId || Identity.GroupId != Posix.GroupId { return 14; }
    if Identity.Mode.Group.CanRead != Posix.Mode.Group.CanRead || Identity.Mode.Group.CanWrite != Posix.Mode.Group.CanWrite || Identity.Mode.Group.CanExecute != Posix.Mode.Group.CanExecute { return 15; }
    if Identity.Mode.Other.CanRead != Posix.Mode.Other.CanRead || Identity.Mode.Other.CanWrite != Posix.Mode.Other.CanWrite || Identity.Mode.Other.CanExecute != Posix.Mode.Other.CanExecute { return 16; }
    if Identity.Mode.Owner.CanRead != Owner.CanRead || Identity.Mode.Owner.CanWrite != Owner.CanWrite || Identity.Mode.Owner.CanExecute != Owner.CanExecute { return 17; }
    if Identity.Mode.SetUserId != Posix.Mode.SetUserId || Identity.Mode.SetGroupId != Posix.Mode.SetGroupId || Identity.Mode.Sticky != Posix.Mode.Sticky { return 18; }
    let ContentTicks = Modified.UnixTime.Count;
    let AccessTicks = Accessed.UnixTime.Count;
    let StatusTicks = Changed.UnixTime.Count;
    return 0;
}

File.ReadMetadataAsync

pub fn ReadMetadataAsync() -> Task<Result<FileMetadata, IoError>>

Supplies the omitted arguments to ReadMetadataAsync. Note: Defaults: Token = CancellationToken(). Return: Exact full-operation result; no additional async frame is created.

File.ChangePosixModeAsync

pub async fn ChangePosixModeAsync(Mode: PosixFileMode, mut Token: CancellationToken) -> Task<Result<void, IoError>>

Executes ChangePosixMode inside the bounded blocking callback. Mode: Owned mutation request; validated before native mutation. Token: Cancellation observation preventing unstarted work. Return: Task with exact admission/native result; no late cancellation rollback. Warning: Receiver remains live/serialized through completion; native call may block a worker.

Example

module example.async_file_metadata_changes;
from std.process import ProgramInputs;
from std.fs import Path;
from std.task import Task, CancellationToken;
from std.fs import File, FileMetadata, PosixAccess, PosixFileMode, PosixOwnershipChange, FileTimestampChange;
from std.io import IoError;
from std.prelude import Result;
from std.time import Timestamp;
// Caller supplies its own opened file, desired numeric owner and wall time.
// Await each worker operation before starting the next; cancellation cannot
// roll back earlier committed changes. Opened remains borrowed throughout.
async fn ConfigureOwnedFileAsync(Opened: mut File&, UserId: u64, Modified: Timestamp, mut Token: CancellationToken) -> Task<Result<FileMetadata, IoError>> {
    let Ownership = PosixOwnershipChange { UserId = .Some { Value = UserId }, GroupId = none, };
    switch await Opened.ChangePosixOwnershipAsync(Ownership, Token) { case .Ok => {} case .Err { Error = Error } => return .Err { Error = Error }; }
    let Mode = PosixFileMode {
        Owner = PosixAccess { CanRead = true, CanWrite = true, CanExecute = false, },
        Group = PosixAccess { CanRead = true, CanWrite = false, CanExecute = false, },
        Other = PosixAccess { CanRead = false, CanWrite = false, CanExecute = false, },
        SetUserId = false, SetGroupId = false, Sticky = false,
    };
    switch await Opened.ChangePosixModeAsync(Mode, Token) { case .Ok => {} case .Err { Error = Error } => return .Err { Error = Error }; }
    let Unchanged = FileTimestampChange { Accessed = .Keep, Modified = .Keep, };
    switch await Opened.ChangeTimesAsync(Unchanged, Token) { case .Ok => {} case .Err { Error = Error } => return .Err { Error = Error }; }
    let Times = FileTimestampChange { Accessed = .Now, Modified = .Exact { Value = Modified }, };
    switch await Opened.ChangeTimesAsync(Times, Token) { case .Ok => {} case .Err { Error = Error } => return .Err { Error = Error }; }
    return await Opened.ReadMetadataAsync(Token);
}

// Supply absolute paths to exclusively owned, disposable fixtures as arguments.
async fn Main(Inputs: ProgramInputs) -> Task<i32> {
    if Inputs.Arguments().Length != 2 { return 20; }
    let OwnedPathText = switch Inputs.Arguments()[1].TryViewUtf8() { case .Some { Value = Text } => break Text; case .None => return 21; };
    var OwnedPath = {
        var Creation = Path.TryCreate(OwnedPathText);
        switch Creation { case .Ok { Value = Created: mut Path& } => break move(Created); case .Err => return 22; }
    };
    var Opened = {
        var Creation = File.TryOpen(OwnedPath.View, .ReadWrite);
        switch Creation { case .Ok { Value = Created: mut File& } => break move(Created); case .Err => return 23; }
    };
    let Snapshot = switch Opened.ReadMetadata() { case .Ok { Value = Value } => break Value; case .Err => return 24; };
    let Posix = switch Snapshot.Posix { case .Some { Value = Value } => break Value; case .None => return 25; };
    let Modified = switch Snapshot.Modified { case .Some { Value = Value } => break Value; case .None => return 26; };
    let Outcome = await ConfigureOwnedFileAsync(Opened, Posix.UserId, Modified, CancellationToken());
    // End every operation's receiver loan before closing the sole native owner.
    let Closed = Opened.Close();
    if Outcome is .Err { Error = _ } { return 27; }
    if Closed is .Err { Error = _ } { return 28; }
    return 0;
}

File.ChangePosixModeAsync

pub fn ChangePosixModeAsync(mut Mode: PosixFileMode) -> Task<Result<void, IoError>>

Supplies the omitted arguments to ChangePosixModeAsync. Note: Defaults: Token = CancellationToken(). Mode: Same input, ownership and lifetime contract as the full operation. Return: Exact full-operation result; no additional async frame is created.

File.ChangePosixOwnershipAsync

pub async fn ChangePosixOwnershipAsync(Change: PosixOwnershipChange, mut Token: CancellationToken) -> Task<Result<void, IoError>>

Executes ChangePosixOwnership inside the bounded blocking callback. Change: Owned mutation request; validated before native mutation. Token: Cancellation observation preventing unstarted work. Return: Task with exact admission/native result; no late cancellation rollback. Warning: Receiver remains live/serialized through completion; native call may block a worker.

File.ChangePosixOwnershipAsync

pub fn ChangePosixOwnershipAsync(mut Change: PosixOwnershipChange) -> Task<Result<void, IoError>>

Supplies the omitted arguments to ChangePosixOwnershipAsync. Note: Defaults: Token = CancellationToken(). Change: Same input, ownership and lifetime contract as the full operation. Return: Exact full-operation result; no additional async frame is created.

File.ChangeTimesAsync

pub async fn ChangeTimesAsync(Change: FileTimestampChange, mut Token: CancellationToken) -> Task<Result<void, IoError>>

Executes ChangeTimes inside the bounded blocking callback. Change: Owned mutation request; validated before native mutation. Token: Cancellation observation preventing unstarted work. Return: Task with exact admission/native result; no late cancellation rollback. Warning: Receiver remains live/serialized through completion; native call may block a worker.

File.ChangeTimesAsync

pub fn ChangeTimesAsync(mut Change: FileTimestampChange) -> Task<Result<void, IoError>>

Supplies the omitted arguments to ChangeTimesAsync. Note: Defaults: Token = CancellationToken(). Change: Same input, ownership and lifetime contract as the full operation. Return: Exact full-operation result; no additional async frame is created.

File.CloseAsync

pub async fn CloseAsync(mut Token: CancellationToken) -> Task<Result<void, IoError>>

Executes Close on the bounded blocking executor. Token: Cancellation observation; cannot interrupt committed native I/O. Return: Task yielding exact native result or portable dispatch/cancellation error. Warning: Retain receiver and borrowed backing until completion. No I/O runs on the initiating caller thread; native calls may occupy a worker until return.

File.CloseAsync

pub fn CloseAsync() -> Task<Result<void, IoError>>

Supplies the omitted arguments to CloseAsync. Note: Defaults: Token = CancellationToken(). Return: Exact full-operation result; no additional async frame is created.

File.FlushAsync

pub async fn FlushAsync(mut Token: CancellationToken) -> Task<Result<void, IoError>>

Completes unbuffered propagation without scheduling native I/O. Token: Cancellation checked before immediate successful completion. Return: Task yielding Ok or Closed/Cancelled; never requests durability.

File.FlushAsync

pub fn FlushAsync() -> Task<Result<void, IoError>>

Supplies the omitted arguments to FlushAsync. Note: Defaults: Token = CancellationToken(). Return: Exact full-operation result; no additional async frame is created.

File.ReadBytes

pub static fn ReadBytes(mut Path: PathView) -> Result<Vector<byte>, StreamReadError>

Opens an absolute path and collects all bytes using shared stream algorithms. Path: Borrowed native path, used only through this call. Return: Owned bytes or failure retaining consumed bytes and secondary cleanup reason. Warning: May allocate/block until EOF. Closes on every result; no fixed size limit.

Example

module example.whole_file;
from std.collections import Vector;
from std.fs import File, Path;
fn Main() -> i32 {
    // This selected Linux example uses a discard device, never a fixed user file.
    var PathOwner = {
        // Scoped writable carriers end immediately after explicit payload transfer.
        var PathOwnerCreation = Path.TryCreate("/dev/null");
        switch PathOwnerCreation {
            case .Ok { Value = Value: mut Path& } => break move(Value);
            case .Err => return 1;
        }
    };
    var Bytes = {
        var BytesCreation = File.ReadBytes(PathOwner.View);
        switch BytesCreation {
            case .Ok { Value = Value: mut Vector<byte>& } => break move(Value);
            case .Err => return 2;
        }
    };
    if Bytes.Length != 0 { return 3; }
    var Text = switch File.ReadText(PathOwner.View) { case .Ok { Value = Value } => break Value; case .Err => return 4; };
    if Text.ByteLength != 0 { return 5; }
    let Input: byte[2] = [0_byte, 0xFF_byte];
    if File.WriteBytes(PathOwner.View, Input) is .Err { Error = _ } { return 6; }
    if File.WriteText(PathOwner.View, "λ\0a") is .Err { Error = _ } { return 7; }
    var Relative = {
        var RelativeCreation = Path.TryCreate("relative-file");
        switch RelativeCreation {
            case .Ok { Value = Value: mut Path& } => break move(Value);
            case .Err => return 8;
        }
    };
    switch File.ReadBytes(Relative.View) {
        case .Err { Error = Error } => {
            if Error.Bytes.Length != 0 || Error.CleanupError is .Some { Value = _ } { return 9; }
            switch Error.Reason {
                case .Failure { Reason = PatternPayload5048 } if (PatternPayload5048 is .InvalidInput) => {}
                default => return 10;
            }
        }
        case .Ok => return 11;
    }
    switch File.WriteBytes(Relative.View, Input) {
        case .Err { Error = Error } => {
            if Error.CleanupError is .Some { Value = _ } { return 12; }
            switch Error.Reason {
                case .Failure { Reason = PatternPayload5049 } if (PatternPayload5049 is .InvalidInput) => {}
                default => return 13;
            }
        }
        case .Ok => return 14;
    }
    return 0;
}

File.ReadText

pub static fn ReadText(mut Path: PathView) -> Result<String, StreamReadError>

Reads/closes a whole file before shared strict UTF-8 decoding. Path: Borrowed absolute native path. Return: Owned text or failure retaining collected bytes; no replacement decoding. Warning: May allocate/block; byte/text collection copies into owned text.

File.WriteBytes

pub static fn WriteBytes(mut Path: PathView, Input: readonly byte[]) -> Result<void, FileWriteError>

Creates/truncates a file, submits all input bytes and closes explicitly. Path: Borrowed absolute native path. Input: Borrowed readable bytes. Return: Full transfer/close success or primary and optional secondary close failures. Warning: May allocate/block, truncates existing content, and does not promise atomic replacement or durable storage. Failed writes can leave a written prefix.

File.WriteText

pub static fn WriteText(mut Path: PathView, Text: str) -> Result<void, FileWriteError>

Writes exact UTF-8 bytes through whole-file byte composition. Path: Borrowed absolute native path. Text: Borrowed valid UTF-8. Return: Full transfer/close success or precise portable failures. Warning: Creates/truncates; may allocate/block. No newline/locale conversion.

File.ReadBytesAsync

pub static async fn ReadBytesAsync(mut Path: PathView, mut Token: CancellationToken) -> Task<Result<Vector<byte>, StreamReadError>>

Runs whole-file ReadBytes composition on one bounded blocking worker. Path: Borrowed absolute native path retained through completion. Token: Cancellation prevents unstarted compositions; cannot refund committed I/O. Return: Task yielding exact owned result or transfer/cleanup/admission failure. Warning: May occupy a worker until EOF/close; never closes on caller continuation.

Example

module example.async_whole_file;
from std.collections import Vector;
from std.fs import File, Path;
from std.task import Task, CancellationSource;
async fn Main() -> Task<i32> {
    // This selected Linux example uses a discard device, never a fixed user file.
    var PathOwner = {
        // Scoped writable carriers end immediately after explicit payload transfer.
        var PathOwnerCreation = Path.TryCreate("/dev/null");
        switch PathOwnerCreation {
            case .Ok { Value = Value: mut Path& } => break move(Value);
            case .Err => return 1;
        }
    };
    var Bytes = {
        var BytesCreation = await File.ReadBytesAsync(PathOwner.View);
        switch BytesCreation {
            case .Ok { Value = Value: mut Vector<byte>& } => break move(Value);
            case .Err => return 2;
        }
    };
    if Bytes.Length != 0 { return 3; }
    var Text = switch await File.ReadTextAsync(PathOwner.View) { case .Ok { Value = Value } => break Value; case .Err => return 4; };
    if Text.ByteLength != 0 { return 5; }
    let Input: byte[2] = [0_byte, 0xFF_byte];
    if await File.WriteBytesAsync(PathOwner.View, Input) is .Err { Error = _ } { return 6; }
    if await File.WriteTextAsync(PathOwner.View, "λ\0a") is .Err { Error = _ } { return 7; }
    var Relative = {
        var RelativeCreation = Path.TryCreate("relative-file");
        switch RelativeCreation {
            case .Ok { Value = Value: mut Path& } => break move(Value);
            case .Err => return 8;
        }
    };
    switch await File.ReadBytesAsync(Relative.View) {
        case .Err { Error = Error } => {
            if Error.Bytes.Length != 0 || Error.CleanupError is .Some { Value = _ } { return 9; }
            switch Error.Reason {
                case .Failure { Reason = PatternPayload5050 } if (PatternPayload5050 is .InvalidInput) => {}
                default => return 10;
            }
        }
        case .Ok => return 11;
    }
    switch await File.WriteBytesAsync(Relative.View, Input) {
        case .Err { Error = Error } => {
            if Error.CleanupError is .Some { Value = _ } { return 12; }
            switch Error.Reason {
                case .Failure { Reason = PatternPayload5051 } if (PatternPayload5051 is .InvalidInput) => {}
                default => return 13;
            }
        }
        case .Ok => return 14;
    }
    var Cancel = {
        var CancelCreation = CancellationSource.TryCreate();
        switch CancelCreation {
            case .Ok { Value = Value: mut CancellationSource& } => break move(Value);
            case .Err => return 15;
        }
    };
    if !Cancel.RequestCancellation() { return 16; }
    switch await File.ReadBytesAsync(PathOwner.View, Cancel.Token) {
        case .Err { Error = Error } => {
            if Error.Bytes.Length != 0 || Error.CleanupError is .Some { Value = _ } { return 17; }
            switch Error.Reason {
                case .Failure { Reason = PatternPayload5052, Transferred = Count } if (PatternPayload5052 is .Cancelled) => { if Count != 0 { return 18; } }
                default => return 19;
            }
        }
        case .Ok => return 20;
    }
    switch await File.WriteBytesAsync(PathOwner.View, Input, Cancel.Token) {
        case .Err { Error = Error } => { switch Error.Reason {
            case .Failure { Reason = PatternPayload5053, Transferred = Count } if (PatternPayload5053 is .Cancelled) => { if Count != 0 { return 21; } }
            default => return 22;
        } }
        case .Ok => return 23;
    }
    return 0;
}

File.ReadBytesAsync

pub static fn ReadBytesAsync(mut Path: PathView) -> Task<Result<Vector<byte>, StreamReadError>>

Supplies the omitted arguments to ReadBytesAsync. Note: Defaults: Token = CancellationToken(). Path: Same input, ownership and lifetime contract as the full operation. Return: Exact full-operation result; no additional async frame is created.

File.ReadTextAsync

pub static async fn ReadTextAsync(mut Path: PathView, mut Token: CancellationToken) -> Task<Result<String, StreamReadError>>

Runs whole-file ReadText composition on one bounded blocking worker. Path: Borrowed absolute native path retained through completion. Token: Cancellation prevents unstarted compositions; cannot refund committed I/O. Return: Task yielding exact owned result or transfer/cleanup/admission failure. Warning: May occupy a worker until EOF/close; never closes on caller continuation.

File.ReadTextAsync

pub static fn ReadTextAsync(mut Path: PathView) -> Task<Result<String, StreamReadError>>

Supplies the omitted arguments to ReadTextAsync. Note: Defaults: Token = CancellationToken(). Path: Same input, ownership and lifetime contract as the full operation. Return: Exact full-operation result; no additional async frame is created.

File.WriteBytesAsync

pub static async fn WriteBytesAsync(mut Path: PathView, Input: readonly byte[], mut Token: CancellationToken) -> Task<Result<void, FileWriteError>>

Runs whole-file WriteBytes composition on one bounded blocking worker. Path: Borrowed absolute native path retained through completion. Input: Borrowed readable bytes retained through completion. Token: Cancellation prevents unstarted compositions; cannot refund committed I/O. Return: Task yielding exact owned result or transfer/cleanup/admission failure. Warning: May occupy a worker until EOF/close; never closes on caller continuation.

File.WriteBytesAsync

pub static fn WriteBytesAsync(mut Path: PathView, Input: readonly byte[]) -> Task<Result<void, FileWriteError>>

Supplies the omitted arguments to WriteBytesAsync. Note: Defaults: Token = CancellationToken(). Path: Same input, ownership and lifetime contract as the full operation. Input: Same input, ownership and lifetime contract as the full operation. Return: Exact full-operation result; no additional async frame is created.

File.WriteTextAsync

pub static async fn WriteTextAsync(mut Path: PathView, Text: str, mut Token: CancellationToken) -> Task<Result<void, FileWriteError>>

Writes exact UTF-8 through the shared whole-file worker composition. Path: Borrowed absolute native path. Text: Borrowed valid UTF-8. Token: Cancellation observation retained through completion. Return: Task yielding full transfer/close or precise portable failures. Warning: Creates/truncates; native work executes on a bounded blocking worker.

File.WriteTextAsync

pub static fn WriteTextAsync(mut Path: PathView, Text: str) -> Task<Result<void, FileWriteError>>

Supplies the omitted arguments to WriteTextAsync. Note: Defaults: Token = CancellationToken(). Path: Same input, ownership and lifetime contract as the full operation. Text: Same input, ownership and lifetime contract as the full operation. Return: Exact full-operation result; no additional async frame is created.

Documentation snapshot: October 24, 2026 About versions ↗
Searching Development · language & standard library