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.

  • 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.

Path for given file_hash contained in PathAndHash object.

Return type:



IOError – If the file with corresponding file_hash is not in storage.


Add new file into the storage.


file_obj (file) – Opened file-like object.


Path where the file-like object is stored contained with hash in PathAndHash object.

Return type:


  • AssertionError – If the file_obj is not file-like object.
  • IOError – If the file couldn’t be added to storage.

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.

Remove file/archive by it’s file_hash.

Parameters:file_hash (str) – Hash, which is used to find the file in storage.
Raises:IOError – If the file for given file_hash was not found in storage.

Delete file/directory identified by path argument.


path have to be in path.

Parameters:path (str) – Path of the file / directory you want to remove.
Raises:IOError – If the file / directory doesn’t exists, or is not in path.