install.js
function install(runtime, abi, platform, arch, cb) {
  const essential = runtime + '-v' + abi + '-' + platform + '-' + arch;
  const pkgVersion = pkg.version;
  const currentPlatform = pkg.name + '-v' + pkgVersion + '-' + essential;

  console.log('Downloading prebuild for platform:', currentPlatform);
  let downloadUrl = 'https://github.com/WilixLead/iohook/releases/download/v' + pkgVersion + '/' + currentPlatform + '.tar.gz';

  let reqOpts = {url: downloadUrl};
  let tempFile = path.join(os.tmpdir(), 'prebuild.tar.gz');
  let req = get(reqOpts, function(err, res) {
    if (err) {
      return onerror(err);
    }
    if (res.statusCode !== 200) {
      if (res.statusCode === 404) {
        console.error('Prebuild for current platform (' + currentPlatform + ') not found!');
        console.error('Try to compile for your platform:');
        console.error('# cd node_modules/iohook;');
        console.error('# npm run compile');
        console.error('');
        return onerror('Prebuild for current platform (' + currentPlatform + ') not found!');
      }
      return onerror('Bad response from prebuild server. Code: ' + res.statusCode);
    }
    pump(res, fs.createWriteStream(tempFile), function(err) {
      if (err) {
        throw err;
      }
      let options = {
        readable: true,
        writable: true,
        hardlinkAsFilesFallback: true
      };
      let binaryName;
      let updateName = function(entry) {
        if (/\.node$/i.test(entry.name)) binaryName = entry.name
      };
      let targetFile = path.join(__dirname, 'builds', essential);
      let extract = tfs.extract(targetFile, options)
        .on('entry', updateName);
      pump(fs.createReadStream(tempFile), zlib.createGunzip(), extract, function(err) {
        if (err) {
          return onerror(err);
        }
        cb()
      })
    })
  });

  req.setTimeout(30 * 1000, function() {
    req.abort()
  })
}
function install(runtime, abi, platform, arch, cb) {
  const essential = runtime + '-v' + abi + '-' + platform + '-' + arch;
  const pkgVersion = pkg.version;
  const currentPlatform = pkg.name + '-v' + pkgVersion + '-' + essential;

  console.log('Downloading prebuild for platform:', currentPlatform);
  let downloadUrl = 'https://github.com/WilixLead/iohook/releases/download/v' + pkgVersion + '/' + currentPlatform + '.tar.gz';

  let reqOpts = {url: downloadUrl};
  let tempFile = path.join(os.tmpdir(), 'prebuild.tar.gz');
  let req = get(reqOpts, function(err, res) {
    if (err) {
      return onerror(err);
    }
    if (res.statusCode !== 200) {
      if (res.statusCode === 404) {
        console.error('Prebuild for current platform (' + currentPlatform + ') not found!');
        console.error('Try to compile for your platform:');
        console.error('# cd node_modules/iohook;');
        console.error('# npm run compile');
        console.error('');
        return onerror('Prebuild for current platform (' + currentPlatform + ') not found!');
      }
      return onerror('Bad response from prebuild server. Code: ' + res.statusCode);
    }
    pump(res, fs.createWriteStream(tempFile), function(err) {
      if (err) {
        throw err;
      }
      let options = {
        readable: true,
        writable: true,
        hardlinkAsFilesFallback: true
      };
      let binaryName;
      let updateName = function(entry) {
        if (/\.node$/i.test(entry.name)) binaryName = entry.name
      };
      let targetFile = path.join(__dirname, 'builds', essential);
      let extract = tfs.extract(targetFile, options)
        .on('entry', updateName);
      pump(fs.createReadStream(tempFile), zlib.createGunzip(), extract, function(err) {
        if (err) {
          return onerror(err);
        }
        cb()
      })
    })
  });

  req.setTimeout(30 * 1000, function() {
    req.abort()
  })
}
function install ( runtime , abi , platform , arch , cb ) { const essential = runtime + '-v' + abi + '-' + platform + '-' + arch ; const pkgVersion = pkg . version ; const currentPlatform = pkg . name + '-v' + pkgVersion + '-' + essential ; console . log ( 'Downloading prebuild for platform:' , currentPlatform ) ; let downloadUrl = 'https://github.com/WilixLead/iohook/releases/download/v' + pkgVersion + '/' + currentPlatform + '.tar.gz' ; let reqOpts = { url : downloadUrl } ; let tempFile = path . join ( os . tmpdir ( ) , 'prebuild.tar.gz' ) ; let req = get ( reqOpts , function ( err , res ) { if ( err ) { return onerror ( err ) ; } if ( res . statusCode !== 200 ) { if ( res . statusCode === 404 ) { console . error ( 'Prebuild for current platform (' + currentPlatform + ') not found!' ) ; console . error ( 'Try to compile for your platform:' ) ; console . error ( '# cd node_modules/iohook;' ) ; console . error ( '# npm run compile' ) ; console . error ( '' ) ; return onerror ( 'Prebuild for current platform (' + currentPlatform + ') not found!' ) ; } return onerror ( 'Bad response from prebuild server. Code: ' + res . statusCode ) ; } pump ( res , fs . createWriteStream ( tempFile ) , function ( err ) { if ( err ) { throw err ; } let options = { readable : true , writable : true , hardlinkAsFilesFallback : true } ; let binaryName ; let updateName = function ( entry ) { if ( / \.node$ / i . test ( entry . name ) ) binaryName = entry . name } ; let targetFile = path . join ( __dirname , 'builds' , essential ) ; let extract = tfs . extract ( targetFile , options ) . on ( 'entry' , updateName ) ; pump ( fs . createReadStream ( tempFile ) , zlib . createGunzip ( ) , extract , function ( err ) { if ( err ) { return onerror ( err ) ; } cb ( ) } ) } ) } ) ; req . setTimeout ( 30 * 1000 , function ( ) { req . abort ( ) } ) }
Download and Install prebuild
@param runtime
@param abi
@param platform
@param arch
@param cb Callback
Download and Install prebuild