---
schema_version: "1"
id: 25a136615b5f8f3e6a63f1721b9e47b0bae0c9a18a4b485b565e378e7388563e
title: Archive and Extract Example
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/compression-module/latest/compression-module-archive-extract-example.md
canonical_url: https://docs.mulesoft.com/compression-module/latest/compression-module-archive-extract-example
source_site: docs.mulesoft.com
content_type: documentation
content_hash: a42aaed86e6eb1cd5b12df6e83d64ec0291aabe1435f36afc82eb507bf1f1d24
description: MuleSoft Documentation Site
release: "2.2"
latest: true
---
---
product: Compression Module
version: 2.2
is-latest-version: true
---

# Archive and Extract Example

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

The following Compression module example shows how to archive and extract files from a folder. The
File Connector **List** operation lists all the files from a folder named `input`. The **Compress**
operation then creates a compressed archive by generating an object with the key set to the file
name and the value set to the value of the listed files. Subsequently, the **Extract** operation
decompresses the archived file. Then, the **For Each** scope iterates over each extracted key/value
pair and writes the file to a new output folder with the key as the new file name and the value as
the corresponding extracted file content.

1.  In Studio, drag a **Scheduler** trigger to the flow.

2.  Set **Frequency** to `15` and **Time unit** to `SECONDS`.

3.  Drag the **List** operation alongside the **Scheduler** trigger.

4.  Add the connector configuration.

5.  Set **Directory path** to `input`.

6.  Drag a **Set payload** component alongside the **List** operation.

7.  Set **Value** to the following DataWeave expression:

```dataweave
output application/java
---
(0 to sizeOf(payload) - 1) as Array
reduce (index, acc={}) -&gt;
acc ++ { (payload[index].attributes.fileName): payload[index].payload}
```

8.  Drag the **Archive** operation alongside the **Set payload** component.

9.  Drag the **Extract** operation alongside the **Archive** operation.

10. Drag the **For Each** scope.

11. Set **Collection** to `payload`.

12. Drag the **Write** operation into the **For Each** scope.

13. Set **Path** to `#[output application/json--- "output/" ++ (payload pluck $$)[0]]`.

14. Set **Content** to `[CDATA[#[output application/java --- ( payload pluck $ )[0]]]`.

15. Drag a **Logger** component right to the **For Each** scope.

16. Set **Message** to `output application/json --- payload`.

17. Save and run your Mule app.

![Compression Module Archive Extract Flow in Studio Canvas](/mulesoft/current/en-us/compression-module/latest/_images/compression-module-example-1.png)

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

```xml
  <flow name="archive-extract-test" >
	<scheduler doc:name="Scheduler">
		<scheduling-strategy >
			<fixed-frequency frequency="15" timeUnit="SECONDS"/>
		</scheduling-strategy>
	</scheduler>
	<file:list doc:name="List" config-ref="File_Config" directoryPath="input"/>
	<set-payload value='#[output application/java
---
(0 to sizeOf(payload) - 1) as Array
reduce (index, acc={}) -&gt;
acc ++ { (payload[index].attributes.fileName): payload[index].payload}]' doc:name="Set Payload" />

	<compression:archive doc:name="Archive" >
		<compression:archiver>
			<compression:zip-archiver />
		</compression:archiver>
	</compression:archive>

	<compression:extract doc:name="Extract"  >
		<compression:extractor >
			<compression:zip-extractor />
		</compression:extractor>
	</compression:extract>

	<foreach doc:name="For Each" collection="#[dw::Core::entriesOf(payload)]">
        <file:write doc:name="Write" config-ref="File_Config" path='#[output application/json&#10;---&#10;"output/" ++ payload.key]'>
            <file:content><![CDATA[#[output application/java --- payload.value]]]></file:content>
        </file:write>
    </foreach>

	<logger level="INFO" doc:name="Logger" message="#[output application/json --- payload]"/>
  </flow>
</mule>
```

## See Also

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

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