Skip to main content

FilesystemBackend

File-system result backend.

Attributes

AttributeTypeDescription
urlstr = NoneURL to the directory we should use
pathbytesThe directory path encoded as a bytes object used for file operations.
sepbytesdirectory separator (to join the directory with the key)
openCallable = openopen function to use when opening files
unlinkCallable = os.unlinkunlink function to use when deleting files

Constructor

Signature

def FilesystemBackend(
url: str = None,
open: Callable = open,
unlink: Callable = os.unlink,
sep: str = os.sep,
encoding: str = default_encoding
) - > null

Parameters

NameTypeDescription
urlstr = NoneThe URL pointing to the directory to be used for storage.
openCallable = openThe function used to open files within the filesystem.
unlinkCallable = os.unlinkThe function used to delete files from the filesystem.
sepstr = os.sepThe directory separator used to join paths and keys.
encodingstr = default_encodingThe character encoding used for filesystem paths and separators.

Methods


get()

@classmethod
def get(
key: bytes
) - > bytes

Retrieves the binary content of the file associated with the specified key.

Parameters

NameTypeDescription
keybytesThe unique identifier for the file to be read

Returns

TypeDescription
bytesThe raw bytes of the file content, or None if the file does not exist

set()

@classmethod
def set(
key: bytes,
value: any
) - > null

Writes the provided value to a file named after the specified key, ensuring the value is in byte format.

Parameters

NameTypeDescription
keybytesThe unique identifier used as the filename
valueanyThe data to be stored, which will be converted to bytes if necessary

Returns

TypeDescription
nullnull

mget()

@classmethod
def mget(
keys: list
) - > generator

Yields the content of multiple files corresponding to the provided list of keys.

Parameters

NameTypeDescription
keyslistAn iterable of unique identifiers to retrieve

Returns

TypeDescription
generatorA generator yielding the byte content for each requested key

delete()

@classmethod
def delete(
key: bytes
) - > null

Removes the file associated with the specified key from the filesystem.

Parameters

NameTypeDescription
keybytesThe unique identifier of the file to be deleted

Returns

TypeDescription
nullnull

cleanup()

@classmethod
def cleanup() - > null

Delete expired meta-data.

Returns

TypeDescription
nullnull