How to use the tar.Extract function in tar

To help you get started, we’ve selected a few tar examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jasonsanjose / brackets-sass / node / 2.0.2 / node_modules / node-sass / node_modules / pangyp / lib / install.js View on Github external
cb(err)
        }
        return
      }

      if (created) {
        log.verbose('created nodedir', created)
      }

      // now download the node tarball
      var tarPath = gyp.opts['tarball']
      var tarballUrl = tarPath ? tarPath : distUrl + '/v' + version + '/' + runtime + '-v' + version + '.tar.gz'
        , badDownload = false
        , extractCount = 0
        , gunzip = zlib.createGunzip()
        , extracter = tar.Extract({ path: devDir, strip: 1, filter: isValid })

      var contentShasums = {}
      var expectShasums = {}

      // checks if a file to be extracted from the tarball is valid.
      // only .h header files and the gyp files get extracted
      function isValid () {
        var name = this.path.substring(devDir.length + 1)
        var isValid = valid(name)
        if (name === '' && this.type === 'Directory') {
          // the first directory entry is ok
          return true
        }
        if (isValid) {
          log.verbose('extracted file from tarball', name)
          extractCount++
github vgno / roc-deprecated / src / cli / helpers / github.js View on Github external
temp.mkdir('roc', function(err, dirPath) {
            if (err) {
                reject(err);
            }

            /* eslint-disable new-cap */
            const writeTar = tar.Extract({strip: 1, path: dirPath});
            /* eslint-enable */

            writeTar.on('finish', () => resolve(dirPath));

            request
                .get(`http://github.com/${packageName}/tarball/${version}`)
                .on('error', reject)
                .pipe(zlib.createGunzip())
                .on('error', reject)
                .pipe(writeTar)
                .on('error', reject);
        });
    });
github bigcompany / big / resources / replicator / index.js View on Github external
function extract (options, callback) {

  var fstream = require('fstream'),
  fstreamNpm = require('fstream-npm'),
  zlib = require('zlib'),
  tar = require('tar');

  //
  // Choose the directory where the snapshot will be extracted
  //
  var extractor = new tar.Extract({
    path: options.targetDir
  });

  //
  // Read in the contents of the snapshot as a stream,
  // and pipe that to Gunzip which will extract the contents of the tar
  //
  fs.createReadStream(options.path).pipe(zlib.Gunzip()).pipe(extractor).on('end', function () {
    callback(null, {
      source: options.path,
      target: options.targetDir
    });
  });

};
github marklagendijk / WinLess / WinLess / node_modules / npm / lib / utils / tar.js View on Github external
.pipe(zlib.Unzip())
        .on("error", function (er) {
          if (er) log.error("tar.unpack", "unzip error "+tarball)
          cb(er)
        })
        .pipe(tar.Extract(extractOpts))
        .on("entry", extractEntry)
        .on("error", function (er) {
          if (er) log.error("tar.unpack", "untar error "+tarball)
          cb(er)
        })
        .on("close", cb)
    } else if (c.toString().match(/^package\//)) {
      // naked tar
      fst
        .pipe(tar.Extract(extractOpts))
        .on("entry", extractEntry)
        .on("error", function (er) {
          if (er) log.error("tar.unpack", "untar error "+tarball)
          cb(er)
        })
        .on("close", cb)
    } else {
      // naked js file
      var jsOpts = { path: path.resolve(target, "index.js") }

      if (process.platform !== "win32" &&
          typeof uid === "number" &&
          typeof gid === "number") {
        jsOpts.uid = uid
        jsOpts.gid = gid
      }
github CodeJockey / node-ninja / lib / install.js View on Github external
} else {
          cb(err)
        }
        return
      }

      if (created) {
        log.verbose('created nodedir', created)
      }

      // now download the node tarball
      var tarPath = gyp.opts.tarball
      var badDownload = false
        , extractCount = 0
        , gunzip = zlib.createGunzip()
        , extracter = tar.Extract({ path: devDir, strip: 1, filter: isValid })

      var contentShasums = {}
      var expectShasums = {}

      // checks if a file to be extracted from the tarball is valid.
      // only .h header files and the gyp files get extracted
      function isValid () {
        var name = this.path.substring(devDir.length + 1)
        var isValid = valid(name)
        if (name === '' && this.type === 'Directory') {
          // the first directory entry is ok
          return true
        }
        if (isValid) {
          log.verbose('extracted file from tarball', name)
          extractCount++
github phonegap / phonegap-app-desktop / src / js / download-node.js View on Github external
var downloadTarballAndExtract = function(url, location, callback) {
  var tempPath = temp.mkdirSync('apm-node-');
  var stream = tar.Extract({
    path: tempPath
  });
  stream.on('end', function() {
    callback.call(this, tempPath);
  });
  stream.on('error', callback);
  var requestStream = request.get(url);
  requestStream.on('response', function(response) {
    if (response.statusCode == 404) {
      console.error('download not found:', url);
      process.exit(1);
    }
    requestStream.pipe(zlib.createGunzip()).pipe(stream);
  });
};
github L-A / Little-Jekyll / install.js View on Github external
function extract(platform, arch, cb) {
  var localFile = localFilePath(platform, arch);
  var jekyllPath = Path.join(__dirname, 'jekyll');
  rmdirSync(jekyllPath);

  var extractor = require('tar').Extract({
    path: jekyllPath,
    strip: 1
  });
  extractor.on('error', function(err) {
    console.log('Error: ' + err);
  });
  extractor.on('end', function() {
    console.log("Traveling Jekyll for " + platform + " " + arch + " installed")
    if(cb) { cb() };
  });
  fs.createReadStream(localFile)
  .on('error', function(err) {
    console.log('Error: ' + err);
  })
  .pipe(zlib.createGunzip())
  .pipe(extractor);
github elastic / kibana / src / cli / plugin / pluginDownloader.js View on Github external
function downloadSingle(source, dest, timeout) {
    var gunzip = zlib.createGunzip();
    var tarExtract = new tar.Extract({ path: dest, strip: 1 });

    return wrappedRequest(source, timeout)
    .then(function (req) {
      var reporter = progressReporter(logger, req);

      req
      .on('response', reporter.handleResponse)
      .on('data', reporter.handleData)
      .on('error', _.partial(reporter.handleError, 'ENOTFOUND'))
      .pipe(gunzip)
      .on('error', _.partial(reporter.handleError, 'EEXTRACT'))
      .pipe(tarExtract)
      .on('error', _.partial(reporter.handleError, 'EEXTRACT'))
      .on('end', reporter.handleEnd);

      return reporter.promise;
github elastic / kibana / src / server / bin / plugin / pluginDownloader.js View on Github external
function downloadSingle(source, dest, timeout) {
    var gunzip = zlib.createGunzip();
    var tarExtract = tar.Extract({ path: dest, strip: 1 });

    var requestOptions = { url: source };
    if (timeout !== 0) {
      requestOptions.timeout = timeout;
    }

    return wrappedRequest(requestOptions)
    .then(function (req) {
      //debugger;
      var reporter = progressReporter(logger, req);

      req
      .on('response', reporter.handleResponse)
      .on('data', reporter.handleData)
      .on('error', _.partial(reporter.handleError, 'ENOTFOUND'))
      .pipe(gunzip)
github Robinlim / npm_cache_share / src / js / common / compressUtils.js View on Github external
function tarExtractStream(dir, callback) {
    //错误处理
    function onError(err) {
        throw err;
    }
    //处理结束
    function onEnd() {
        callback && callback();
    }

    var extractor = tar.Extract({
            path: dir
        })
        .on('error', onError)
        .on('end', onEnd);

    return extractor;
}
function zipExtractStream(dir, callback) {