Compress¶
flowtask.interfaces.compress
¶
CompressSupport
¶
Bases: ABC
CompressSupport.
Overview
This component handles compressing and uncompressing files and folders into various formats. Supported formats: - ZIP (.zip and .jar) - TAR (.tar) - GZ (.gz) - BZIP2 (.bz2) - XZ (.xz) - 7z (.7z) - RAR (.rar)
Methods:
| Name | Description |
|---|---|
- compress |
Compress files/folders into various formats. |
- uncompress |
Uncompress files/folders from various formats. |
- zip_file |
Compress a single file into a zip file. |
- unzip_file |
Uncompress a single file from a zip archive. |
- zip_folder |
Compress a folder into a zip file. |
- unzip_folder |
Uncompress files from a zip archive to a folder. |
Parameters: - source: Path to the file or folder to be compressed or uncompressed. - destination: Path where the compressed/uncompressed file should be saved. - remove_source: Boolean to remove the source file/folder after operation.
compress
async
¶
Compress the given source into the destination file in the specified format.
compress_7z
async
¶
Compress files/folders into a 7z archive.
compress_gzip
async
¶
Compress a file or folder into a gzip file. If the extension indicates a tarball format (e.g., .tar.gz, .tar.bz2, .tar.xz), compress as a tarball; otherwise, compress as a simple .gz file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Union[str, PosixPath]
|
The file or folder to compress. |
required |
destination
|
Union[str, PosixPath]
|
The destination path for the compressed file. |
required |
extension
|
str
|
The desired extension (e.g., .gz, .tar.gz, .tar.bz2, .tar.xz). |
'.gz'
|
remove_source
|
bool
|
Whether to remove the source file/folder after compression. |
False
|
Returns:
| Type | Description |
|---|---|
str
|
The path of the compressed file. |
compress_rar
async
¶
Compress files/folders into a rar archive.
compress_tar
async
¶
Compress files/folders into a tar archive.
compress_zip
async
¶
compress_zip(source, destination, compress_type=ZIP_DEFLATED, compress_level=9, remove_source=False)
Compress files/folders into a zip archive.
uncompress
async
¶
Uncompress the given source file into the destination folder.
uncompress_7z
async
¶
Uncompress files from a 7z archive.
uncompress_gzip
async
¶
Uncompress a Gzip file or tarball and return the list of uncompressed files.
uncompress_rar
async
¶
Uncompress files from a rar archive.
uncompress_tar
async
¶
Uncompress files from a tar archive.
uncompress_zip
async
¶
Uncompress files from a zip archive.
unzip_folder
async
¶
Uncompress files from a zip archive into a folder.
zip_file
async
¶
Compress a single file into a zip file.
zip_folder
async
¶
Compress a folder into a zip file.