---
schema_version: "1"
id: 142b3a328d92c5cded96f99e174f780aeefa8a3bd4e3839feec23ee79ccd3edd
title: Compress and Decompress Example
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/compression-module/latest/compression-module-compress-decompress-example.md
canonical_url: https://docs.mulesoft.com/compression-module/latest/compression-module-compress-decompress-example
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 2a412598f6f1f299635535633e6c0f10b776503e4fa49d7513788230df6ca1d7
description: MuleSoft Documentation Site
release: "2.2"
latest: true
---
---
product: Compression Module
version: 2.2
is-latest-version: true
---

# Compress and Decompress Example

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

The following Compression module examples show how to compress a file using the **Compress**
operation and decompress a payload from a remote service using the **Decompress** operation.

## Compress a File

In the following example, you configure the File Connector **Read** operation to read a file. Then,
the **Compress** operation compresses the file and saves it in GZip format. Subsequently, the File
Connector **Write** operation writes the content into the given path on demand.

1.  In Studio, drag the File Connector **Read** operation to your flow.

2.  Set **Path** to `file.txt`.

3.  Drag the **Compress** operation alongside the **Read** operation.

4.  Set **Compressor** to **Gzip compressor**

5.  Drag the **Write** operation alongside the **Compress** operation.

6.  Set **Path** to `file-txt.gz`.

In the **Configuration XML** editor, the configuration looks like this:

```xml
<file:read path="file.txt"/>
<compression:compress>
   <compression:compressor>
       <compression:gzip-compressor/>
   </compression:compressor>
</compression:compress>
<file:write path="file-txt.gz"/>
```

## Decompress a Payload from a Remote Service

In the following example, you configure the Web Service Consumer Connector **Consume** operation to
consume an operation that returns a Zip file from a server. Then, the **Decompress** operation
decompresses the Zip file.

1.  In Studio, drag the Web Service Consumer Connector **Consume** operation to your flow.

2.  Set **Connector configuration** to your operation configuration, for example `ZipServiceConfig`.

3.  Set **Operation** to the name of the web service operation to invoke, for example `returnsZip`.

4.  Drag the **Decompress** operation alongside the **Consume** operation.

5.  Set **Content** to `payload.body.zipContent`.

6.  Set **Compressor** to **Zip compressor**.

In the **Configuration XML** editor, the configuration looks like this:

```xml
<compression:decompress doc:name="Decompress" >
 <compression:compressed ><![CDATA[#[payload.body.zipContent]]]></compression:compressed>
    <compression:decompressor >
   <compression:gzip-decompressor />
</compression:decompressor>
</compression:decompress>
```

## See Also

- [Compression Module Reference](https://docs.mulesoft.com/compression-module/latest/compression-documentation)

- [Salesforce Help](https://help.salesforce.com)
