Util.extractZip = function()

in pipeline/local_modules/pipeline_utils/pipeline_utils.js [171:206]


Util.extractZip = function (sourceZip, destDirectory) {
  return new Promise(function (resolve, reject) {
    console.log("Extracting zip: '" + sourceZip + "' to '" + destDirectory + "'");

    yauzl.open(sourceZip, {
      lazyEntries: true
    }, function (err, zipfile) {
      if (err) throw err;
      zipfile.readEntry();
      zipfile.on("error", reject);
      zipfile.on("end", resolve);
      zipfile.on("entry", function (entry) {
        if (/\/$/.test(entry.fileName)) {
          // directory file names end with '/'
          mkdirp(destDirectory + '/' + entry.fileName, function (err) {
            if (err) throw err;
            zipfile.readEntry();
          });
        } else {
          // file entry
          zipfile.openReadStream(entry, function (err, readStream) {
            if (err) throw err;
            // ensure parent directory exists
            mkdirp(destDirectory + '/' + path.dirname(entry.fileName), function (err) {
              if (err) throw err;
              readStream.pipe(fs.createWriteStream(destDirectory + '/' + entry.fileName));
              readStream.on("end", function () {
                zipfile.readEntry();
              });
            });
          });
        }
      });
    });
  });
}