core/postinstall.js
function extractDownload(filePath, requestOptions, retry) {
  const deferred = kew.defer();
  // extract to a unique directory in case multiple processes are
  // installing and extracting at once
  const extractedPath = filePath + '-extract-' + Date.now();
  let options = { cwd: extractedPath };

  fs.mkdirsSync(extractedPath, '0777');
  // Make double sure we have 0777 permissions; some operating systems
  // default umask does not allow write by default.
  fs.chmodSync(extractedPath, '0777');

  if (filePath.substr(-4) === '.zip') {
    log.info('Extracting zip contents');

    try {
      let zip = new AdmZip(filePath);
      zip.extractAllTo(extractedPath, true);
      deferred.resolve(extractedPath);
    } catch (err) {
      log.error('Error extracting zip');
      deferred.reject(err);
    }

  } else {
    log.info('Extracting tar contents (via spawned process)');
    cp.execFile('tar', ['jxf', filePath], options, function (err) {
      if (err) {
        if (!retry) {
          log.info('Error during extracting. Trying to download again.');
          fs.unlinkSync(filePath);
          return requestBinary(requestOptions, filePath).then(function (downloadedFile) {
            return extractDownload(downloadedFile, requestOptions, true);
          });
        } else {
          deferred.reject(err);
          log.error('Error extracting archive');
        }
      } else {
        deferred.resolve(extractedPath);
      }
    });
  }
  return deferred.promise;
}
function extractDownload(filePath, requestOptions, retry) {
  const deferred = kew.defer();
  // extract to a unique directory in case multiple processes are
  // installing and extracting at once
  const extractedPath = filePath + '-extract-' + Date.now();
  let options = { cwd: extractedPath };

  fs.mkdirsSync(extractedPath, '0777');
  // Make double sure we have 0777 permissions; some operating systems
  // default umask does not allow write by default.
  fs.chmodSync(extractedPath, '0777');

  if (filePath.substr(-4) === '.zip') {
    log.info('Extracting zip contents');

    try {
      let zip = new AdmZip(filePath);
      zip.extractAllTo(extractedPath, true);
      deferred.resolve(extractedPath);
    } catch (err) {
      log.error('Error extracting zip');
      deferred.reject(err);
    }

  } else {
    log.info('Extracting tar contents (via spawned process)');
    cp.execFile('tar', ['jxf', filePath], options, function (err) {
      if (err) {
        if (!retry) {
          log.info('Error during extracting. Trying to download again.');
          fs.unlinkSync(filePath);
          return requestBinary(requestOptions, filePath).then(function (downloadedFile) {
            return extractDownload(downloadedFile, requestOptions, true);
          });
        } else {
          deferred.reject(err);
          log.error('Error extracting archive');
        }
      } else {
        deferred.resolve(extractedPath);
      }
    });
  }
  return deferred.promise;
}
function extractDownload ( filePath , requestOptions , retry ) { const deferred = kew . defer ( ) ; // extract to a unique directory in case multiple processes are // installing and extracting at once const extractedPath = filePath + '-extract-' + Date . now ( ) ; let options = { cwd : extractedPath } ; fs . mkdirsSync ( extractedPath , '0777' ) ; // Make double sure we have 0777 permissions; some operating systems // default umask does not allow write by default. fs . chmodSync ( extractedPath , '0777' ) ; if ( filePath . substr ( - 4 ) === '.zip' ) { log . info ( 'Extracting zip contents' ) ; try { let zip = new AdmZip ( filePath ) ; zip . extractAllTo ( extractedPath , true ) ; deferred . resolve ( extractedPath ) ; } catch ( err ) { log . error ( 'Error extracting zip' ) ; deferred . reject ( err ) ; } } else { log . info ( 'Extracting tar contents (via spawned process)' ) ; cp . execFile ( 'tar' , [ 'jxf' , filePath ] , options , function ( err ) { if ( err ) { if ( ! retry ) { log . info ( 'Error during extracting. Trying to download again.' ) ; fs . unlinkSync ( filePath ) ; return requestBinary ( requestOptions , filePath ) . then ( function ( downloadedFile ) { return extractDownload ( downloadedFile , requestOptions , true ) ; } ) ; } else { deferred . reject ( err ) ; log . error ( 'Error extracting archive' ) ; } } else { deferred . resolve ( extractedPath ) ; } } ) ; } return deferred . promise ; }
Extracts the given Archive
@param {string} filePath - path of the ZIP archive to extract
@param {object} requestOptions - request options for retry attempt
@param {boolean} retry - set to true if it's already an retry attempt
@returns {*} - path of the extracted archive content
@function
Extracts the given Archive