Files and directories as a service (Effect's FileSystem).
Programs read the FileSystem service and get the host's with
file_system.layer (or a test double)::
from pyfect import file_system
from pyfect.file_system import FileSystem
@fx.fn
def program():
fs = yield from FileSystem()
yield from fs.write_file_string("notes.txt", "hello")
return (yield from fs.read_file_string("notes.txt"))
fx.run_blocking(program().pipe(fx.provide(file_system.layer)))Every operation fails with a PlatformError whose reason is a
NotFound, PermissionDenied, AlreadyExists, BadResource ...
(fx.platform_error). open and the *_scoped temporaries live
until their scope closes; stream and sink read and write files as
byte streams. watch uses a provided WatchBackend, else the operating
system's change notification with the watch extra (WatchfilesBackend),
else polls (LiveFileSystem(watch_interval=...)). NoopFileSystem / layer_noop are an
empty file system to subclass in tests.
Values#
| Attribute | Type | Description |
|---|---|---|
DEFAULT_WATCH_INTERVAL | Duration | |
layer | Layer[FileSystem] | The host's file system, with the |
DEFAULT_CHUNK_SIZE | Literal[65536] | Bytes per chunk |
Types#
| Type | Definition | Description |
|---|---|---|
FileType | type FileType = Literal['File', 'Directory', 'SymbolicLink', 'BlockDevice', 'CharacterDevice', 'FIFO', 'Socket', 'Unknown'] | |
OpenFlag | type OpenFlag = Literal['r', 'r+', 'w', 'wx', 'w+', 'wx+', 'a', 'ax', 'a+', 'ax+'] | Node's open flags: |
SeekMode | type SeekMode = Literal['start', 'current'] | |
WatchEvent | type WatchEvent = Create | Update | Remove |
Classes#
Functions#
layer_noop#
layer_noop(file_system=None) -> Layer[FileSystem]A layer providing file_system (a NoopFileSystem subclass
instance), or an empty NoopFileSystem.
| Parameter | Type | Description |
|---|---|---|
file_system | NoopFileSystem | None = None |
Returns Layer[FileSystem]
def layer_noop(file_system: NoopFileSystem | None = None) -> Layer[FileSystem]:
"""A layer providing ``file_system`` (a ``NoopFileSystem`` subclass
instance), or an empty ``NoopFileSystem``."""
return layer_succeed(FileSystem, NoopFileSystem() if file_system is None else file_system)