For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).
FileDescriptor
struct FileDescriptor
Owning file descriptor that is closed explicitly with close().
Movable but not copyable, so exactly one value owns the descriptor. -1
is the niche, so Optional[FileDescriptor] is the size of a descriptor.
Examples:
from std.io import FileDescriptor
def release(var fd: FileDescriptor) raises:
fd^.close()
Implemented traits
AnyType,
Movable,
UnsafeNicheable,
_FieldNicheable
Methods
__init__
def __init__(out self, *, unsafe_raw_fd: RawFileDescriptor)
Takes ownership of a raw file descriptor.
Args:
- unsafe_raw_fd (
RawFileDescriptor): The descriptor to own. Nothing else may close it, so never passstdin,stdout,stderror the descriptor behind aFileHandle.
def __init__(out self, *, copy_borrowed: BorrowedFileDescriptor)
Constructs a new owner by duplicating a borrowed descriptor.
The new FileDescriptor owns a fresh descriptor that refers to the
same open file description as copy_borrowed, so the two share the
file offset and status flags but are closed independently. The copy
is close-on-exec, so child processes don't inherit it.
Args:
- copy_borrowed (
BorrowedFileDescriptor): The descriptor to duplicate.
Raises:
If the duplication fails.
close
def close(deinit self)
Closes the owned file descriptor.
Raises:
If the close fails. A failed close can mean buffered writes never reached the file.