How to create Zip file with multiple files in Mirth?
var zipFile = “c:\\test.zip”;
var sourceFiles= new Array(${arrayOfFileNames});
try {
var buffer = java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, 5000);
var fileOutput = new java.io.FileOutputStream(zipFile);
var zos = new java.util.zip.ZipOutputStream(fileOutput);
for (i = 0; i < sourceFiles.length; i++) {
var srcFile = new java.io.File(sourceFiles[i]);
var fis = new java.io.FileInputStream(srcFile);
zos.putNextEntry(new java.util.zip.ZipEntry(sourceFiles.getName()));
var length;
while ((length = fis.read(buffer)) > 0) {
zos.write(buffer, 0, length);
}
zos.closeEntry();
fis.close();
}
zos.close();
} catch (ioe) {
logger.debug(“Error creating zip file: ” + ioe);
}
Paste the above provided code in the destination Javascript Writer. It does not require any external Java libraries to achieve this task as well.
Happy Integrating……