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

TestData:

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

Compress and Decompress File In Mule 4

 

Drag and drop compress operation mule palette select the Compressor as Zip Compressor, please visit how to add module 

Compress and Decompress File In Mule 4

 

Configure the File Write operation to write the compressed file

Compress and Decompress File In Mule 4

 

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

  
Thank you for taking out time to read the above post. Hope you found it useful. In case of any questions, feel free to comment below. Also, if you are keen on knowing about a specific topic, happy to explore your recommendations as well.
 
For any latest updates or posts on our website, you can follow us on LinkedIn. Look forward to connecting with you there.


Share this:
Subscribe
Notify of
guest
2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Uday sankar
Uday sankar
3 years ago

Could you please give a demo on Archive multiple csv files into zip folder and extract same no.of csv files. after archiving same file content needs to be present if we extract manually and see files.

Thanks in advance.