lib/impl/importForms/unzipFile.js
function unzipToWorkingDir(params, callback) {
  var unzipError;

  var queue = async.queue(unzipWorker, params.queueConcurrency || 5);

  //Pushing a single file unzip to the queue.
  function getQueueEntry(zipfile) {
    return function queueEntry(entry) {
      queue.push({
        zipfile: zipfile,
        workingDir: params.workingDir,
        entry: entry
      }, function(err) {
        if (err) {
          logger.debug("Error unzipping file params.zipFilePath", err);
          //If one of the files has failed to unzip correctly. No point in continuing to unzip. Close the zip file.
          zipfile.close();
        }
      });
    };
  }

  unzip.open(params.zipFilePath, {lazyEntries: true}, function(err, zipfile) {
    if (err) {
      return callback(err);
    }

    zipfile.on("entry", getQueueEntry(zipfile));
    zipfile.readEntry();

    zipfile.on('error', function(err) {
      logger.error("Error unzipping Zip File " + params.zipFilePath, err);
      unzipError = err;
    });

    zipfile.on('close', function() {
      //When the queue is empty and the zip file has finisihed scanning files, then the unzip is finished
      logger.debug("Zip File " + params.zipFilePath + " Unzipped");
      callback(unzipError);
    });
  });
}
function unzipToWorkingDir(params, callback) {
  var unzipError;

  var queue = async.queue(unzipWorker, params.queueConcurrency || 5);

  //Pushing a single file unzip to the queue.
  function getQueueEntry(zipfile) {
    return function queueEntry(entry) {
      queue.push({
        zipfile: zipfile,
        workingDir: params.workingDir,
        entry: entry
      }, function(err) {
        if (err) {
          logger.debug("Error unzipping file params.zipFilePath", err);
          //If one of the files has failed to unzip correctly. No point in continuing to unzip. Close the zip file.
          zipfile.close();
        }
      });
    };
  }

  unzip.open(params.zipFilePath, {lazyEntries: true}, function(err, zipfile) {
    if (err) {
      return callback(err);
    }

    zipfile.on("entry", getQueueEntry(zipfile));
    zipfile.readEntry();

    zipfile.on('error', function(err) {
      logger.error("Error unzipping Zip File " + params.zipFilePath, err);
      unzipError = err;
    });

    zipfile.on('close', function() {
      //When the queue is empty and the zip file has finisihed scanning files, then the unzip is finished
      logger.debug("Zip File " + params.zipFilePath + " Unzipped");
      callback(unzipError);
    });
  });
}
function unzipToWorkingDir ( params , callback ) { var unzipError ; var queue = async . queue ( unzipWorker , params . queueConcurrency || 5 ) ; //Pushing a single file unzip to the queue. function getQueueEntry ( zipfile ) { return function queueEntry ( entry ) { queue . push ( { zipfile : zipfile , workingDir : params . workingDir , entry : entry } , function ( err ) { if ( err ) { logger . debug ( "Error unzipping file params.zipFilePath" , err ) ; //If one of the files has failed to unzip correctly. No point in continuing to unzip. Close the zip file. zipfile . close ( ) ; } } ) ; } ; } unzip . open ( params . zipFilePath , { lazyEntries : true } , function ( err , zipfile ) { if ( err ) { return callback ( err ) ; } zipfile . on ( "entry" , getQueueEntry ( zipfile ) ) ; zipfile . readEntry ( ) ; zipfile . on ( 'error' , function ( err ) { logger . error ( "Error unzipping Zip File " + params . zipFilePath , err ) ; unzipError = err ; } ) ; zipfile . on ( 'close' , function ( ) { //When the queue is empty and the zip file has finisihed scanning files, then the unzip is finished logger . debug ( "Zip File " + params . zipFilePath + " Unzipped" ) ; callback ( unzipError ) ; } ) ; } ) ; }
unzipToWorkingDir - Unzipping a file to a working directory.

Using a queue to control the number of files decompressing at a time.

@param  {object} params
@param  {string} params.zipFilePath Path to the ZIP file to unzip.
@param  {number} params.queueConcurrency Concurrency Of the async queue
@param  {string} params.workingDir Unzip Working Directory
@param  {function} callback
unzipToWorkingDir - Unzipping a file to a working directory .