GitHub

file_system

API reference for file_system.

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

AttributeTypeDescription
DEFAULT_WATCH_INTERVALDuration
layerLayer[FileSystem]

The host's file system, with the WatchBackend provided where the layer is built (if any).

DEFAULT_CHUNK_SIZELiteral[65536]

Bytes per chunk FileSystem.stream reads by default.

Types

TypeDefinitionDescription
FileTypetype FileType = Literal['File', 'Directory', 'SymbolicLink', 'BlockDevice', 'CharacterDevice', 'FIFO', 'Socket', 'Unknown']
OpenFlagtype OpenFlag = Literal['r', 'r+', 'w', 'wx', 'w+', 'wx+', 'a', 'ax', 'a+', 'ax+']

Node's open flags: r read, w truncate or create, a append or create, x fail if the file exists, + read and write.

SeekModetype SeekMode = Literal['start', 'current']
WatchEventtype 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.

ParameterTypeDescription
file_systemNoopFileSystem | 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)