GitHub

API reference for File.

An open file, closed when the scope FileSystem.open ran in closes. Reads and writes move a cursor the handle keeps, unless given a position.

Functions

stat

stat() -> Effect[FileInfo, PlatformError]

Returns Effect[FileInfo, PlatformError]

@abstractmethod
def stat(self) -> Effect[FileInfo, PlatformError]: ...

seek

seek(offset, whence='start') -> Effect[int, PlatformError]

Move the cursor to offset from the start or the current position; succeeds with the new position. Fails with a BadArgument before the start of the file.

ParameterTypeDescription
offsetint
whenceSeekMode = 'start'

Returns Effect[int, PlatformError]

@abstractmethod
def seek(self, offset: int, whence: SeekMode = "start") -> Effect[int, PlatformError]:
    """Move the cursor to ``offset`` from the start or the current
    position; succeeds with the new position. Fails with a
    ``BadArgument`` before the start of the file."""

sync

sync() -> Effect[None, PlatformError]

Flush the file's data to the device (fsync).

Returns Effect[None, PlatformError]

@abstractmethod
def sync(self) -> Effect[None, PlatformError]:
    """Flush the file's data to the device (``fsync``)."""

read

read(buffer, *, position=None) -> Effect[int, PlatformError]

Read into buffer; succeeds with the bytes read (0 at the end).

ParameterTypeDescription
bufferbytearray | memoryview
positionint | None = None

Returns Effect[int, PlatformError]

@abstractmethod
def read(
    self, buffer: bytearray | memoryview, *, position: int | None = None
) -> Effect[int, PlatformError]:
    """Read into ``buffer``; succeeds with the bytes read (0 at the
    end)."""

read_alloc

read_alloc(size, *, position=None) -> Effect[bytes | None, PlatformError]

Read up to size bytes; None at the end of the file.

ParameterTypeDescription
sizeint
positionint | None = None

Returns Effect[bytes | None, PlatformError]

@abstractmethod
def read_alloc(
    self, size: int, *, position: int | None = None
) -> Effect[bytes | None, PlatformError]:
    """Read up to ``size`` bytes; ``None`` at the end of the file."""

truncate

truncate(length=0) -> Effect[None, PlatformError]
ParameterTypeDescription
lengthint = 0

Returns Effect[None, PlatformError]

@abstractmethod
def truncate(self, length: int = 0) -> Effect[None, PlatformError]: ...

write

write(data) -> Effect[int, PlatformError]

Write once; succeeds with the bytes written, maybe fewer than len(data).

ParameterTypeDescription
databytes

Returns Effect[int, PlatformError]

@abstractmethod
def write(self, data: bytes) -> Effect[int, PlatformError]:
    """Write once; succeeds with the bytes written, maybe fewer than
    ``len(data)``."""

write_all

write_all(data) -> Effect[None, PlatformError]

Write all of data.

ParameterTypeDescription
databytes

Returns Effect[None, PlatformError]

@abstractmethod
def write_all(self, data: bytes) -> Effect[None, PlatformError]:
    """Write all of ``data``."""