FilesystemBackend
File-system result backend.
Attributes
| Attribute | Type | Description |
|---|---|---|
| url | str = None | URL to the directory we should use |
| path | bytes | The directory path encoded as a bytes object used for file operations. |
| sep | bytes | directory separator (to join the directory with the key) |
| open | Callable = open | open function to use when opening files |
| unlink | Callable = os.unlink | unlink 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
| Name | Type | Description |
|---|---|---|
| url | str = None | The URL pointing to the directory to be used for storage. |
| open | Callable = open | The function used to open files within the filesystem. |
| unlink | Callable = os.unlink | The function used to delete files from the filesystem. |
| sep | str = os.sep | The directory separator used to join paths and keys. |
| encoding | str = default_encoding | The 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
| Name | Type | Description |
|---|---|---|
| key | bytes | The unique identifier for the file to be read |
Returns
| Type | Description |
|---|---|
bytes | The 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
| Name | Type | Description |
|---|---|---|
| key | bytes | The unique identifier used as the filename |
| value | any | The data to be stored, which will be converted to bytes if necessary |
Returns
| Type | Description |
|---|---|
null | null |
mget()
@classmethod
def mget(
keys: list
) - > generator
Yields the content of multiple files corresponding to the provided list of keys.
Parameters
| Name | Type | Description |
|---|---|---|
| keys | list | An iterable of unique identifiers to retrieve |
Returns
| Type | Description |
|---|---|
generator | A 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
| Name | Type | Description |
|---|---|---|
| key | bytes | The unique identifier of the file to be deleted |
Returns
| Type | Description |
|---|---|
null | null |
cleanup()
@classmethod
def cleanup() - > null
Delete expired meta-data.
Returns
| Type | Description |
|---|---|
null | null |