nvflare.app_common.storages.filesystem_storage module¶
- class FilesystemStorage(root_dir='/', uri_root='/')[source]¶
Bases:
StorageSpec
Init FileSystemStorage.
Uses local filesystem to persist objects, with absolute paths as object URIs.
- Parameters:
root_dir – the absolute path on the filesystem to store things
uri_root – serving as the root of the storage. All URIs are rooted at this uri_root.
- create_object(uri: str, data, meta: dict, overwrite_existing: bool = False)[source]¶
Creates an object.
- Parameters:
uri – URI of the object
data – content of the object
meta – meta of the object
overwrite_existing – whether to overwrite the object if already exists
- Raises:
TypeError – if invalid argument types
StorageException –
if error creating the object - if object already exists and overwrite_existing is False - if object will be at a non-empty directory
IOError – if error writing the object
- delete_object(uri: str)[source]¶
Deletes the specified object.
- Parameters:
uri – URI of the object
- Raises:
TypeError – if invalid argument types
StorageException – if object does not exist
- get_data(uri: str, component_name: str = 'data') bytes [source]¶
Gets data of the specified object.
- Parameters:
uri – URI of the object
component_name – storage component name
- Returns:
data of the object.
- Raises:
TypeError – if invalid argument types
StorageException – if object does not exist
- get_data_for_download(uri: str, component_name: str = 'data', download_file: str = None)[source]¶
Gets data of the specified object.
- Parameters:
uri – URI of the object
component_name – storage component name
download_file – component file_name for download
- Raises StorageException when:
invalid args
- get_detail(uri: str) Tuple[dict, bytes] [source]¶
Gets both data and meta of the specified object.
- Parameters:
uri – URI of the object
- Returns:
meta and data of the object.
- Raises:
TypeError – if invalid argument types
StorageException – if object does not exist
- get_meta(uri: str) dict [source]¶
Gets meta of the specified object.
- Parameters:
uri – URI of the object
- Returns:
meta of the object.
- Raises:
TypeError – if invalid argument types
StorageException – if object does not exist
- is_valid_component()¶
- list_objects(path: str) List[str] [source]¶
List all objects in the specified path.
- Parameters:
path – the path uri to the objects
- Returns:
list of URIs of objects
- Raises:
TypeError – if invalid argument types
StorageException – if path does not exist or is not a valid directory.
- update_meta(uri: str, meta: dict, replace: bool)[source]¶
Updates the meta of the specified object.
- Parameters:
uri – URI of the object
meta – value of new meta
replace – whether to replace the current meta completely or partial update
- Raises:
TypeError – if invalid argument types
StorageException – if object does not exist
IOError – if error writing the object