Compress and Decompress File In Mule 4
In this tutorial we will demonstrate how can we compress and decompress the file in mule 4, In Mule 4 compresses and decompresses files for each of the available formats.
Below operations are supported for compress Module
- Archive: Compresses all the given entries into a new file in the configured format
- Compress: Compresses a given content using the configured format, ZIP or GZIP.
- Decompress: Decompresses a single entry of compressed content which is assumed to be in an specific format (ZIP or GZIP).
- Extract: Decompresses a given content that represent an archive in a compression format.
ZIP Compressor vs GZIP Compressor:
- ZIP is more popular on Windows operating systems.
- Gzip is the standard file compression for Unix and Linux systems.
- Gzip is faster than ZIP while compressing and decompressing.
- ZIP is an archiving and compression tool, all in one, while Gzip needs the help of Tar command to archive files.
- Gzip can save more disk space than ZIP compression applications.
- Both Gzip and ZIP use the DEFLATE compression algorithm
We will create a sample project in anypoint studio to compress the file and write to folder as soon as the file is compressed it will be read from a folder and uncompressed the same file back to original size into another folder
Create a sample pdf file to read
Drag and drop the http listener and configure the same to trigger the flow
Configure the File Read operation to read the PDF file
Drag and drop compress operation mule palette select the Compressor as Zip Compressor, please visit how to add module
Configure the File Write operation to write the compressed file
Now configure the on New or Updated File operation and configure the Directory and File pattern to read the compressed file
Configure the Decompress operation
Configure the File Write operation to write the uncompressed file
Deploy the project and trigger the request from soap ui
See the below result File is compressed successfully with 157 KB
File uncompressed to its original size.
Sample project: compress-decompressfile sample application