Local Filesystem

class keg_storage.backends.filesystem.LocalFSStorage(root: Union[str, pathlib.Path], linked_endpoint: Optional[str] = None, secret_key: Optional[bytes] = None, name: str = None)[source]
copy(path: str, new_path: str)[source]

Copy the remote file specified by path to new_path.

Create a signed JWT authorizing the user to perform the specified operations

delete(path: str)[source]

Delete the remote file specified by path.

Verify a JWT and extract the path and allowed operations

download(path: str, file_obj: IO, *, progress_callback: Optional[Callable[[int], None]] = None)

Copies a remote file at path to a file-like object file_obj.

If desired, a progress callback can be supplied. The function should accept an int parameter, which will be the number of bytes downloaded so far.

get(path: str, dest: str) → None

Copies a remote file at path to the dest path given on the local filesystem.

Create a URL pointing to the given linked_endpoint containing a JWT authorizing the user user to perform the given operations.

This is currently only implemented for flask based apps but you may override this method in your own subclass to support other frameworks.

To use this method you must provide secret_key and linked_endpoint to the constructor.

Note: content_type parameter is ignored for this backend.

list(path: str) → List[keg_storage.backends.base.ListEntry][source]

Returns a list of ListEntry`s representing files available under the directory or prefix given in `path.

open(path: str, mode: Union[keg_storage.backends.base.FileMode, str])[source]

Returns a instance of RemoteFile for the given path that can be used for reading and/or writing depending on the mode given.

put(path: str, dest: str) → None

Copies a local file at path to a remote file at dest.

upload(file_obj: IO, path: str, *, progress_callback: Optional[Callable[[int], None]] = None)

Copies the contents of a file-like object file_obj to a remote file at path

If desired, a progress callback can be supplied. The function should accept an int parameter, which will be the number of bytes uploaded so far.

class keg_storage.backends.filesystem.LocalFSFile(path: pathlib.Path, mode: keg_storage.backends.base.FileMode)[source]
close()[source]

Cleanup and deallocate any held resources. This method may be called multiple times on a single instance. If the file was already closed, this method should do nothing.

read(size: int) → bytes[source]

Read and return up to size bytes from the remote file. If the end of the file is reached this should return an empty bytes string.

write(data: bytes) → None[source]

Write the data buffer to the remote file.