BalancedDiscStorage class¶
- class BalancedDiscStorage.balanced_disc_storage.BalancedDiscStorage(path, dir_limit=32000)¶
Bases: object
Store files, make sure, that there are never more files in one directory than _dir_limit.
- path = None¶
Path on which the storage operates.
- dir_limit = None¶
Maximal number of files in directory.
- read_bs = None¶
File read blocksize.
- hash_builder = None¶
Hashing function used for FN.
- file_path_from_hash(file_hash, path=None, hash_list=None)¶
For given file_hash, return path on filesystem.
Parameters: - file_hash (str) – Hash of the file, for which you wish to know the path.
- path (str, default None) – Recursion argument, don’t set this.
- hash_list (list, default None) – Recursion argument, don’t set this.
Returns: Path for given file_hash contained in PathAndHash object.
Return type: str
Raises: IOError – If the file with corresponding file_hash is not in storage.
- add_file(file_obj)¶
Add new file into the storage.
Parameters: file_obj (file) – Opened file-like object.
Returns: Path where the file-like object is stored contained with hash in PathAndHash object.
Return type: obj
Raises: - AssertionError – If the file_obj is not file-like object.
- IOError – If the file couldn’t be added to storage.
- delete_by_file(file_obj)¶
Remove file from the storage. File is identified by opened file_obj, from which the hashes / path are computed.
Parameters: file_obj (file) – Opened file-like object, which is used to compute hashes. Raises: IOError – If the file_obj is not in storage.