Sidebar

I have a gzip archive. How do I extract it?

0 votes
29 views
asked Jun 22 by jon-t-7005 (4,990 points)

1 Answer

0 votes

This function can be used to extract a gzipped file.  Create a new Published Function and paste this in.  The syntax to use it is this:  gunzipFile(fileToUnzip, outputFileName);

For example:

gunzipFile('C:\\temp\\archive.gz', 'C:\\temp\\output.txt');

 

function gunzipFile(zipFilePath, outputFile) {
   var zipFile = null;
   zipFile = new java.io.FileInputStream(zipFilePath);
   var gzipInputStream = new java.util.zip.GZIPInputStream(zipFile);
   var bytes = new Packages.java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, 1024);
   
   var outputStream = new java.io.FileOutputStream(outputFile);
   try {
      var length;
      while ((length = gzipInputStream.read(bytes)) >= 0) {
         outputStream.write(bytes, 0, length);
      }
   }  catch (err) {
      qie.error('Failed to unzip file \'' + zipFilePath + '\': ' + err);
   } finally {
      outputStream.close();
      gzipInputStream.close();
      zipFile.close();
   }
}

answered Jun 22 by jon-t-7005 (4,990 points)
...