Contact Us 1-800-596-4880

Compress and Decompress Example

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:

<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:

<wsc:consume config="ZipServiceConfig" operation="returnsZip"/>
<compression:decompress>
   <compression:content>
      #[payload.body.zipContent]
   </compression:content>
   <compression:decompressor>
       <compression:zip-decompressor/>
   </compression:decompressor>
</compression:decompress>
View on GitHub