API reference
- class flametree.Directory(location='.', name=None, file_manager=None)
Directories contains a list of
_filesand subdirectories_dirs.You can also access all files in the directory’s subtree with
._all_files
- class flametree.File(location='.', name=None, file_manager=None)
- delete()
Delete this file
- move(target, replace=True)
Move this file to the specified target (a directory or a file)
- print_content()
Print the file’s content.
- read(mode='r', **kw)
Return the file’s content as a string (mode ‘r’) or bytes (‘rb’).
- write(content, mode='a')
Write data in the file.
- class flametree.DiskFileManager(target, replace=False)
Reader and Writer for disk files.
- Parameters:
target (str) – A directory on the disk. If it doesn’t exist, it will be created.
replace (bool) – If the target directory exists, should it be completely replaced or simply appended to?
- static close()
This method does nothing for DiskFileManagers.
- create(target, replace=False)
Create a new, empty file or directory on disk.
- static delete(target)
Delete the file on disk.
- static join_paths(*paths)
Join paths in a system/independent way – actually os.path.join.
- static list_directory_content(directory, element_type='file')
Return the list of all file or dir objects in the directory.
- classmethod list_dirs(directory)
Return the list of all directory objects in the directory.
- classmethod list_files(directory)
Return the list of all file objects in the directory.
- open(fileobject, mode='a')
Open a file on disk at the location given by the file object.
- static read(fileobject, mode='r')
Return the entire content of a file. The mode can be ‘r’ or ‘rb’.
- static write(fileobject, content, mode='a')
Write the content (str, bytes) to the given file object.
- class flametree.ZipFileManager(path=None, source=None, replace=False)
Reader and Writer of ZIP files.
- Parameters:
path (str) – Path to a zip archive to be read or written to.
source (str or bytes or file-like object) – Either a string/bytes representing zipped data, or a file-like object connected to zipped data.
replace (bool) – In case the provided path is pointing to an already-existing file, should it be erased or appended to?
- flametree.file_tree(target, replace=False)
Open a connection to a file tree which can be either a disk folder, a zip archive, or an in-memory zip archive.
- Parameters:
target (str or flametree directory) – Either the path to a target folder, or a zip file, or ‘@memory’ to write a zip file in memory (at which case a string of the zip file is returned). If the target is already a flametree directory, it is returned as-is.
replace (bool) – If True, will remove the target if it already exists. If False, new files will be written inside the target and some files may be overwritten.