Zip Module
Properties Configuration Settings
The Zip transformer implements a PKZip-compatible Zip compressor and decompressor.
Remarks
The Zip module is used for compressing and decompressing messages. The module uses the Deflate algorithm specified in RFC 1951 for compression, and produces and reads output compatible with PKZip, WinZip, etc.
Zip Compressor Module
The Zip Compress operation creates an archive based on the specified files. The Zip Compressor relies on a Map of filenames to file content as input, e.g. Map<Filename,InputStream>. The elements will be compressed into a Binary zip archive in the output payload.
Compression strength is regulated by the CompressionLevel property. You may also control encryption behavior by setting the Password and EncryptionAlgorithm properties on this module.
Archive Example
In the body of your flow, configure the File List connector to list the contents of the target directory.
Behind the File List connector, transform the output of File List so it can be correctly interpreted by the Zip Compressor. The easiest way to do this is with the Set Payload connector. Paste in the following DataWeave code to properly format the File List output so it can be used by the Compressor.
output application/java --- (0 to sizeOf(payload) - 1) as Array reduce (index, acc={}) -> acc ++ { (payload[index].attributes.fileName): payload[index].payload}Finally, add the Zip Compressor. That is all that is required to begin compressing data. Behind the Zip Compressor you can write the new archive to disk with a File Write connector or perform further processing.
Zip Decompressor Module
The Zip Decompress operation extracts the inner files of the input archive. The Zip Decompressor relies on a Binary archive in the incoming message payload as input. The elements in the archive will be decompressed into a Map of filenames to decompressed content as key:value pairs in the output payload, e.g. Map<Filename,OutputStream>. The Map elements can be accessed with a For Each scope.
The Password property must be set in order to extract files which have been encrypted. You may also use the ExcludedFiles property to regulate which files are to be extracted from the archive.
Extract Example
First, create an event source such as a Scheduler endpoint to start the flow. Then in the body of your flow, drag an instance of the File Read connector into the project and configure it to read in a particular archive file.
Add an instance of the Zip Decompressor behind the File Read connector. There is no need to transform the output data of the File Read connector before passing it to the Decompressor.
Behind the Decompressor add a For Each Scope and set the collection property to payload. This will configure the For Each Scope to iterate over the output of the Decompressor. Then inside the For Each Scope, the filename and decompressed file data are available as key:value pairs.
As an example, to write the file to disk you can use a File Write connector inside the For Each Scope and MuleSoft pluck function. Set the Path property of the File Write connector to:
output application/json --- "c:/temp/mule/output/" ++ (payload pluck $$)[0]
Set the Content property of the File Write connector to:
output application/java --- ( payload pluck $ )[0]
That is all that is required to configure the File Write connector to write the inner file to disk.
Compressor Property List
The following is the full list of the properties of the compressor module with short descriptions. Click on the links for further details.
CompressionLevel | The compression level to use. |
EncryptionAlgorithm | The algorithm used to encrypt a MuleSoft when written to the archive. |
FileModifiedTime | The modified time of the compressed files. |
LogFile | The file to write logging information to at runtime. |
LogMode | What information gets logged during component execution. |
LogType | How information gets logged during component execution. |
Other | Defines a set of configuration settings to be used by the transformer. |
Password | A password for the zip file. |
RuntimeLicense | Specifies the component runtime license key. |
TempPath | A temporary directory where uncompressed and compressed data can be stored. |
ZipComment | The comment for the entire zip file. |
Decompressor Property List
The following is the full list of the properties of the decompressor module with short descriptions. Click on the links for further details.
FileMask | Specifies which files the component should include when extracting. |
LogFile | The file to write logging information to at runtime. |
LogMode | What information gets logged during component execution. |
LogType | How information gets logged during component execution. |
Other | Defines a set of configuration settings to be used by the transformer. |
Password | A password for the zip file. |
RuntimeLicense | Specifies the component runtime license key. |
TempPath | A temporary directory where uncompressed and compressed data can be stored. |
Configuration Settings
The following is a list of configuration settings for the module with short descriptions. Click on the links for further details.
Append | Specifies whether to append files. |
ArchiveFile | The location of the archive file on disk. |
CompressionMethod | Used to set the method of compression. |
ExcludedFiles | A list of files to exclude. |
ExtractToPath | . |
IncludeFiles | Specifies local files to include in the archive. |
OverwriteFiles | Whether or not to overwrite files. |
PlainPassword | Allows you to specify a password stored in plaintext. |
PreserveModifiedTime | Whether or not to preserve the original modified time on extracted files. |