Gzip Compress & Gzip Uncompress Transformer in Mule






Gzip Compress & Gzip Uncompress Transformer in Mule


How to compress & uncompress a file in mule ?

We can do it by Gzip Compress & Gzip Uncompress Transformers in Mulesoft.

Gzip Compress Transformer : It compress byte array or file.We can reduce file size by this transformer.

Gzip Uncompress Transformer : It is used to uncompress byte array or a file and restored it back in original size.

The Compression module supports and provides access to the most-used file archiver and compression formats through a Mule app.


A file archiver is a computer program that combines a number of files together into one archive file for easier transportation or storage, and most archivers employ data compression in their archive formats to reduce the size of the final archive. However, not all compression algorithms can archive multiple files. Some are limited to single-file data compression.

This module compresses and decompresses files for each of the available formats without losing any of the features that the format associated algorithm provides.
To achieve this capability, the module provides two pairs of operations, one for compressing and decompressing a single file, another for archiving and extracting a bundle of files. Each of these operations can be configured with the compression or archiving strategies of your choice.

flow of Compress & Gzip Uncompress Transformer :





In above flow, a file is compressed by Gzip Compress transformer and stored in output folder of src/main/resources. In second flow, file connector picks that compressed file and uncompress that by Gzip Uncompress transformer.We can compare file size of both the files in file's properties.

All files are in src/main/resources :



XML project code :



<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd">
    <file:connector name="File" outputPattern="output.json" writeToDirectory="src/main/resources/output" autoDelete="false" streaming="false" validateConnections="true" doc:name="File"/>
    <file:connector name="File2" outputPattern="original_input.json" autoDelete="false" streaming="false" validateConnections="true" doc:name="File" writeToDirectory="src/main/resources/uncompressed"/>
    <file:connector name="File1" outputPattern="input.json" writeToDirectory="src/main/resources/input" autoDelete="false" streaming="false" validateConnections="true" doc:name="File"/>
    <flow name="test_objecttostringFlow">
        <file:inbound-endpoint path="src/main/resources/input" connector-ref="File1" responseTimeout="10000" doc:name="File"/>
        <gzip-compress-transformer doc:name="Gzip Compress"/>
        <file:outbound-endpoint path="src/main/resources/output" outputPattern="output.json" connector-ref="File" responseTimeout="10000" doc:name="File"/>
    </flow>
    <flow name="test_gzipcompressFlow">
        <file:inbound-endpoint path="src/main/resources/output" connector-ref="File" responseTimeout="10000" doc:name="File"/>
        <gzip-uncompress-transformer doc:name="Gzip Uncompress"/>
        <file:outbound-endpoint path="src/main/resources/uncompressed" outputPattern="original_input.json" connector-ref="File2" responseTimeout="10000" doc:name="File"/>
    </flow>
</mule>

© 2020 goformule.com

Share on :

Mule 4:

XML to JSON in mule 4 Web service consumer VM Validation in Mule 4 Until Successful
Sub flow Set Variable & Remove Variable Set Transaction ID Scatter Gather Round Robin
Consume Restful Service CRUD in Mule 4 Parse Template Object to JSON Load Static Resource
JSON to XML Invoke Idempotent Filter ForEach Flat file to JSON
Fixwidth to JSON First Successful File Execute Error Handling
Email Dynamic Evaluate Custom Business Event CSV to JSON Copybook to JSON
Choice Router Async RabbitMQ


Mule 3:


Database Connector Async CXF Attachement XSLT
Mongo DB Cache scope Custom Business Event Gzip Compress Expression
SMTP For Each Expression Javascript Filter Reference
Salesforce Message Enricher Groovy Parse Template Idempotent
VM Poll Invoke Ruby Message
Webservice consumer Python Transformer reference Message Property Not
Collection Aggregator First Sucessful Catch Exception Strategy Reference Exception Strategy Or
Choice Message Chunk Aggregator Choice Exception Strategy Global Exception Strategy Schema Validation
Custom Aggregator Scatter Gather Custom Exception Strategy Batch Processing MEL
M Unit RAML Map Operator API Mocking Dataweave