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.
| Parameter | Type | Description |
|---|---|---|
offset | int | |
whence | SeekMode = '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).
| Parameter | Type | Description |
|---|---|---|
buffer | bytearray | memoryview | |
position | int | 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.
| Parameter | Type | Description |
|---|---|---|
size | int | |
position | int | 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]| Parameter | Type | Description |
|---|---|---|
length | int = 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).
| Parameter | Type | Description |
|---|---|---|
data | bytes |
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.
| Parameter | Type | Description |
|---|---|---|
data | bytes |
Returns Effect[None, PlatformError]
@abstractmethod
def write_all(self, data: bytes) -> Effect[None, PlatformError]:
"""Write all of ``data``."""