FileStorage

Stores <key>.json files in a directory (the default storage).

On this page

Class in sponsorkit.storage.

from sponsorkit import FileStorage

Also 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
ParameterTypeDefaultDescription
directorystr | 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) -> Path

The file that holds key.

read()#

def read(self, key: str) -> str | None

Read the file, or None if it does not exist.

write()#

def write(self, key: str, data: str) -> None

Write atomically: temp file (0600), fsync, rename.

delete()#

def delete(self, key: str) -> None

Delete the file if it exists.