FileStorage
Stores <key>.json files in a directory (the default storage).
Class in sponsorkit.storage.
from sponsorkit import FileStorageAlso importable from sponsorkit.storage.
class FileStorage:
...Stores <key>.json files in a directory (the default storage).
The directory is created (mode 0700) on the first write; files are written 0600 via a temporary <file>.<random>.tmp that is renamed over the target file.
Constructor#
FileStorage(directory: str | os.PathLike[str]) -> None| Parameter | Type | Default | Description |
|---|---|---|---|
directory | str | os.PathLike[str] | required |
Attributes#
directory#
directory: str | os.PathLike[str]The directory that holds the <key>.json files.
Methods#
path()#
def path(self, key: str) -> PathThe file that holds key.
read()#
def read(self, key: str) -> str | NoneRead the file, or None if it does not exist.
write()#
def write(self, key: str, data: str) -> NoneWrite atomically: temp file (0600), fsync, rename.
delete()#
def delete(self, key: str) -> NoneDelete the file if it exists.