Zip tools
Functions:¶
_create_zip(folder, output)
¶
Zip a folder into a zip-file or into a BytesIO.
| PARAMETER | DESCRIPTION |
|---|---|
|
Folder to be zipped.
TYPE:
|
|
Either a string with the path of the zip file, or a BytesIO object.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
T
|
Either the zip-file path string, or the modified BytesIO object. |
Source code in fractal_server/zip_tools.py
_folder_can_be_deleted(folder)
¶
Given the path of a folder as string, returns False if either:
- the related zip file {folder}.zip does already exists,
- the folder and the zip file have a different number of internal files,
- the zip file has a very small size.
Otherwise returns True.
Source code in fractal_server/zip_tools.py
_read_single_file_from_zip(*, file_path, archive_path)
¶
Reads and returns the contents of a single file from a ZIP archive using
unzip -p.
| PARAMETER | DESCRIPTION |
|---|---|
|
relative to the archive
TYPE:
|
|
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The file content |
| RAISES | DESCRIPTION |
|---|---|
FileNotFoundError
|
if the file is not inside the archive |
Source code in fractal_server/zip_tools.py
_zip_folder_to_byte_stream_iterator(folder)
¶
Returns byte stream with the zipped log folder of a job.
| PARAMETER | DESCRIPTION |
|---|---|
|
the folder to zip
TYPE:
|
Source code in fractal_server/zip_tools.py
_zip_folder_to_file_and_remove(folder)
¶
Creates a ZIP archive of the specified folder and removes the original folder (if it can be deleted).
This function performs the following steps:
1. Creates a ZIP archive of the folder and names it with a temporary
suffix _tmp.zip.
2. Renames the ZIP removing the suffix (this would possibly overwrite a
file with the same name already present).
3. Checks if the folder can be safely deleted using the
_folder_can_be_deleted function. If so, deletes the original folder.