Getting started Community Training Tutorials Documentation APIs, AI & Tools
output application/java
---
(0 to sizeOf(payload) - 1) as Array
reduce (index, acc={}) ->
acc ++ { (payload[index].attributes.fileName): payload[index].payload}
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 Archive 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.
In Studio, drag a Scheduler trigger to the flow.
Set Frequency to 15 and Time unit to SECONDS.
Drag the List operation alongside the Scheduler trigger.
Add the connector configuration.
Set Directory path to input.
Drag a Set payload component alongside the List operation.
Set Value to the following DataWeave expression:
output application/java
---
(0 to sizeOf(payload) - 1) as Array
reduce (index, acc={}) ->
acc ++ { (payload[index].attributes.fileName): payload[index].payload}
Drag the Archive operation alongside the Set payload component.
Set Entries to payload.
Drag the Extract operation alongside the Archive operation.
Drag the For Each scope.
Set Collection to #[dw::Core::entriesOf(payload)].
Drag the Write operation into the For Each scope.
Set Path to #[output application/json --- "output/" ++ payload.key].
Set Content to #[output application/java --- payload.value].
Drag a Logger component right to the For Each scope.
Set Message to output application/json --- payload.
Save and run your Mule app.

In the Configuration XML editor, the configuration looks like this:
<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={}) ->
acc ++ { (payload[index].attributes.fileName): payload[index].payload}]' doc:name="Set Payload" />
<compression:archive doc:name="Archive" >
<compression:entries>#[payload]</compression:entries>
<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 --- "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>
The payload of the Extract operation is an object with key/value pairs that map archived file names to extracted file contents. For example, if the input folder contains invoice.txt and report.csv, the extracted payload has the following structure:
{
"invoice.txt": "Invoice content",
"report.csv": "Report content"
}
The For Each scope converts each object entry to a key/value pair. The Write operation uses payload.key for the output file name and payload.value for its content.