LocalStorage#
LocalStorage #
Bases: StorageBase
LocalStorage is a concrete implementation of the StorageBase
class that
stores files locally on disk. This class manages file uploads, tracks file
hashes, and allows retrieval of stored files from a specified directory.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
The name of the storage type, set to "local_storage". |
files |
list[QuivrFile]
|
A list of files stored in this local storage. |
hashes |
Set[str]
|
A set of SHA-1 hashes of the uploaded files. |
copy_flag |
bool
|
If |
dir_path |
Path
|
The directory path where files are stored. |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dir_path |
Path | None
|
Optional directory path for storing files.
Defaults to the environment variable |
None
|
copy_flag |
bool
|
Whether to copy the file or create a symlink.
Defaults to |
True
|
get_files
async
#
get_files()
Retrieves the list of files stored in the local storage.
Returns:
Type | Description |
---|---|
list[QuivrFile]
|
list[QuivrFile]: A list of stored file objects. |
load
classmethod
#
load(config)
Loads the local storage from a configuration object. This method initializes the storage directory and populates it with deserialized files from the configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
LocalStorageConfig
|
Configuration object containing the storage path and serialized file data. |
required |
Returns:
Name | Type | Description |
---|---|---|
LocalStorage |
Self
|
An instance of |
remove_file
async
#
remove_file(file_id)
Removes a file from the local storage. This method is currently not implemented.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_id |
UUID
|
The unique identifier of the file to remove. |
required |
Raises:
Type | Description |
---|---|
NotImplementedError
|
Always raises this error as the method is not yet implemented. |
upload_file
async
#
upload_file(file, exists_ok=False)
Uploads a file to the local storage. Copies or creates a symlink based
on the copy_flag
attribute. Checks for duplicate file uploads using
the file's SHA-1 hash.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file |
QuivrFile
|
The file object to upload. |
required |
exists_ok |
bool
|
If |
False
|
Raises:
Type | Description |
---|---|
FileExistsError
|
If a file with the same SHA-1 hash already exists
and |
TransparentStorage #
options: heading_level: 2