core/postinstall.js
function requestBinary(requestOptions, filePath) {
  const deferred = kew.defer();
  const writePath = filePath + '-download-' + Date.now();

  log.info('Receiving...');
  let bar = null;
  requestProgress(request(requestOptions, (error, response, body) => {
    log.info('');
    if (!error && response.statusCode === 200) {
      fs.writeFileSync(writePath, body);
      log.info('Received ' + Math.floor(body.length / 1024) + 'K total.');
      fs.renameSync(writePath, filePath);
      deferred.resolve({
        requestOptions: requestOptions,
        downloadedFile: filePath
      });

    } else if (response) {
      log.error('Error requesting archive.\n' +
        'Status: ' + response.statusCode + '\n' +
        'Request options: ' + JSON.stringify(requestOptions, null, 2) + '\n' +
        'Response headers: ' + JSON.stringify(response.headers, null, 2) + '\n' +
        'Make sure your network and proxy settings are correct.\n\n');
      exit(1);
    } else if (error && error.stack && error.stack.indexOf('SELF_SIGNED_CERT_IN_CHAIN') != -1) {
      log.error('Error making request.');
      exit(1);
    } else if (error) {
      log.error('Error making request.\n' + error.stack + '\n\n' +
        'Please report this full log at https://github.com/hypery2k/galenframework-cli/issues');
      exit(1);
    } else {
      log.error('Something unexpected happened, please report this full ' +
        'log at https://github.com/hypery2k/galenframework-cli/issues');
      exit(1);
    }
  })).on('progress', (state) => {
    if (!bar) {
      bar = new Progress('  [:bar] :percent :etas', { total: state.total, width: 40 });
    }
    bar.curr = state.received;
    bar.tick(0);
  });

  return deferred.promise;
}
function requestBinary(requestOptions, filePath) {
  const deferred = kew.defer();
  const writePath = filePath + '-download-' + Date.now();

  log.info('Receiving...');
  let bar = null;
  requestProgress(request(requestOptions, (error, response, body) => {
    log.info('');
    if (!error && response.statusCode === 200) {
      fs.writeFileSync(writePath, body);
      log.info('Received ' + Math.floor(body.length / 1024) + 'K total.');
      fs.renameSync(writePath, filePath);
      deferred.resolve({
        requestOptions: requestOptions,
        downloadedFile: filePath
      });

    } else if (response) {
      log.error('Error requesting archive.\n' +
        'Status: ' + response.statusCode + '\n' +
        'Request options: ' + JSON.stringify(requestOptions, null, 2) + '\n' +
        'Response headers: ' + JSON.stringify(response.headers, null, 2) + '\n' +
        'Make sure your network and proxy settings are correct.\n\n');
      exit(1);
    } else if (error && error.stack && error.stack.indexOf('SELF_SIGNED_CERT_IN_CHAIN') != -1) {
      log.error('Error making request.');
      exit(1);
    } else if (error) {
      log.error('Error making request.\n' + error.stack + '\n\n' +
        'Please report this full log at https://github.com/hypery2k/galenframework-cli/issues');
      exit(1);
    } else {
      log.error('Something unexpected happened, please report this full ' +
        'log at https://github.com/hypery2k/galenframework-cli/issues');
      exit(1);
    }
  })).on('progress', (state) => {
    if (!bar) {
      bar = new Progress('  [:bar] :percent :etas', { total: state.total, width: 40 });
    }
    bar.curr = state.received;
    bar.tick(0);
  });

  return deferred.promise;
}
function requestBinary ( requestOptions , filePath ) { const deferred = kew . defer ( ) ; const writePath = filePath + '-download-' + Date . now ( ) ; log . info ( 'Receiving...' ) ; let bar = null ; requestProgress ( request ( requestOptions , ( error , response , body ) => { log . info ( '' ) ; if ( ! error && response . statusCode === 200 ) { fs . writeFileSync ( writePath , body ) ; log . info ( 'Received ' + Math . floor ( body . length / 1024 ) + 'K total.' ) ; fs . renameSync ( writePath , filePath ) ; deferred . resolve ( { requestOptions : requestOptions , downloadedFile : filePath } ) ; } else if ( response ) { log . error ( 'Error requesting archive.\n' + 'Status: ' + response . statusCode + '\n' + 'Request options: ' + JSON . stringify ( requestOptions , null , 2 ) + '\n' + 'Response headers: ' + JSON . stringify ( response . headers , null , 2 ) + '\n' + 'Make sure your network and proxy settings are correct.\n\n' ) ; exit ( 1 ) ; } else if ( error && error . stack && error . stack . indexOf ( 'SELF_SIGNED_CERT_IN_CHAIN' ) != - 1 ) { log . error ( 'Error making request.' ) ; exit ( 1 ) ; } else if ( error ) { log . error ( 'Error making request.\n' + error . stack + '\n\n' + 'Please report this full log at https://github.com/hypery2k/galenframework-cli/issues' ) ; exit ( 1 ) ; } else { log . error ( 'Something unexpected happened, please report this full ' + 'log at https://github.com/hypery2k/galenframework-cli/issues' ) ; exit ( 1 ) ; } } ) ) . on ( 'progress' , ( state ) => { if ( ! bar ) { bar = new Progress ( '  [:bar] :percent :etas' , { total : state . total , width : 40 } ) ; } bar . curr = state . received ; bar . tick ( 0 ) ; } ) ; return deferred . promise ; }
Downloads binary file
@param {object} requestOptions - to use for HTTP call
@param {string} filePath - download URL
@returns {*}
@function
Downloads binary file