Unzip .zip files in mirth
Create a source as File Reader. put the zip file directory to read and make sure you enable read as binary radio button. as shown below
Now, the logic is that the .zip file will be read via mirth engine and the data inside the zip file will be consumed as base 64 based content and written in to the output folder.
Provide the below code in the transformer editor.
// path at which the ZIP files has to be unzipped
var destinationPath = “C:\\Projects\\NON-EAI-PROJECTS\\tmp”;
var buffer_value = 1024;
// Convert incoming data to a base64 encoded data
var strBase64Data = connectorMessage.getRawData();
var decodedBytes = FileUtil.decode(strBase64Data);
// process all zipped files
var is = new java.io.ByteArrayInputStream(decodedBytes);
var zis = new java.util.zip.ZipInputStream(is);
var entry;
while((entry = zis.getNextEntry()) != null) {
// save file
var count;
var buffer = java.lang.reflect.Array.newInstance(java.lang.Byte .TYPE, buffer_value);
var fileOut = new java.io.File(destinationPath + “\\” + entry.getName());
var fos = new java.io.FileOutputStream(fileOut);
// read byte content from zipped file
while ((count = zis.read(buffer, 0, buffer_value)) != -1) {
fos.write(buffer, 0, count);
}
fos.close();
}
zis.close();