API.md 2.5 KB

Storage class

This class is backend storage of PotatoEgg. None of the methods which do something on the file check that file exists and they return an Exception if it doesn't. It is your responsibility to check existance of a file or directory with Storage.exists.

Storage(base, db_path, properties)

  • base: A string representing the "root" of Storage and must be an existing directory. If it is a relative path, it will be converted to an absolute one.
  • db_path: A string which is path to an LMDB database. If it doesn't exist there, one will be created. It might be inside the root. In that case it is your responsibility to take care of this and prevent unwanted access.
  • properties: An iterator containing strings which are valid properies a file can have.

Storage.ls(path = "", reverse=False)

  • Returns a list of files in the given path which defaults to root which is sorted(ascending order unless reverse is True) and contains regular files and directories only(should we include other types like character and block devices or sockets or Doors if on Solaris?)

Storage.add(path, file, properties = {})

Writes the given file on storage in the given path.

Deletes the file in path along with all its properties if the file already exists

  • path must be an instance of string.
  • file must be either an instance of bytes(NOT string) or an object which has a read(number_of_bytes) method. In the second case, data is read using the said method in 64KiB chunks and transferred to storage.
  • properties defaults to an empty dictionary. It must be a dictionary-like object which its keys are valid properties a file might have. The file will be initialized with these after creation.

Storage.hashsum(path)

Returns a string containing hexadecimal digest of SHA1 hashsum of file.

Storage.delete(path)

Removes the given file in storage will all its properties.

Storage.exists(path)

Returns True if file exists and False otherwise.

Storage.size(path)

Returns an integer indicating size of file in bytes.

Storage.move(path, new)

Moves the file to its new location. Can be used for renaming also.

Storage.get_property(path, property_)

Returns property value of the given file which can be any Python object and returns None if such a property does not exist.

Storage.set_property(path, property_, value)

Sets the Python object value as value of the valid property property_. If the given property already exists with some value, that will be replaced.