How to use the tar-stream.extract function in tar-stream

To help you get started, we’ve selected a few tar-stream 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 Derpthemeus / ChampionMasteryLookup / ts / staticDataUpdater.ts View on Github external
https.get(url, (response: http.IncomingMessage) => {
			if (response.statusCode === 200) {
				/** A promise for each file that needs to be saved. Each promise will be resolved when the file has been saved, or rejected if an error occurs */
				const promises: Promise[] = [];

				const tarStream = tar.extract();
				tarStream.on("error", (err: Error) => {
					reject(new VError(err, "Error reading tarball stream"));
				});

				const championJsonRegex = XRegExp(`^(.\\/)?${XRegExp.escape(ddragonVersion)}\\/data\\/en_US\\/champion\\.json$`);
				const profileIconRegex = XRegExp(`^(.\\/)?${XRegExp.escape(ddragonVersion)}\\/img\\/profileicon\\/.+[^\\/]$`);
				const championIconRegex = XRegExp(`^(.\\/)?${XRegExp.escape(ddragonVersion)}\\/img\\/champion\\/.+[^\\/]$`);

				let entriesChecked: number = 0;
				tarStream.on("entry", (header: { name: string }, entryStream: stream.Readable, next: Function) => {
					if (++entriesChecked % 1000 === 0) {
						console.log(`Checked ${entriesChecked} entries in the tarball...`);
					}
					if (profileIconRegex.test(header.name)) {
						const promise: Promise = saveEntry(entryStream, profileIconsPath, header.name);
						// This is needed to suppress an UnhandledPromiseRejectionWarning (the rejection will actually be handled later by Promise.all())
github heroku / cli / commands / update.js View on Github external
return new Promise(resolve => {
      this.fs.removeSync(dir)
      let extract = tar.extract()
      extract.on('entry', (header, stream, next) => {
        let p = path.join(dir, header.name)
        let opts = {mode: header.mode}
        switch (header.type) {
          case 'directory':
            this.fs.mkdirpSync(p, opts)
            next()
            break
          case 'file':
            stream.pipe(this.fs.createWriteStream(p, opts))
            break
          case 'symlink':
            // ignore symlinks since they will not work on windows
            next()
            break
          default: throw new Error(header.type)
github tessel / t2-cli / lib / update-fetch.js View on Github external
// System Objects
var path = require('path');
var fs = require('fs');

// Third Party Dependencies
var gunzip = require('zlib').createGunzip();
var extract = require('tar-stream').extract();
var Progress = require('t2-progress');
var request = require('request');
var streamToBuffer = require('stream-to-buffer');
var urljoin = require('url-join');
var semver = require('semver');

// Internal
var log = require('./log');
var remote = require('./remote');

const BUILD_SERVER_ROOT = `https://${remote.BUILDS_HOSTNAME}/t2`;
const FIRMWARE_PATH = urljoin(BUILD_SERVER_ROOT, 'firmware');
const BUILDS_JSON_FILE = urljoin(FIRMWARE_PATH, 'builds.json');
const OPENWRT_BINARY_FILE = 'openwrt.bin';
const FIRMWARE_BINARY_FILE = 'firmware.bin';
github digidem / osm-p2p-syncfile / test / create.js View on Github external
setupAndClose(function (err) {
        t.error(err)
        t.ok(fs.existsSync(filepath))
        t.equal(fs.readdirSync(dir).length, 1)
        t.notEqual(fs.readdirSync(dir).indexOf('sync.tar'), -1)

        var seen = []
        var ex = tar.extract()
        fs.createReadStream(filepath).pipe(ex)
        ex.on('entry', function (header, stream, next) {
          seen.push(header.name)
          stream.resume()
          stream.on('end', next)
        })
        ex.on('finish', function () {
          t.deepEquals(seen.sort(), ['___index.json', 'osm-p2p-db.tar'])
          t.end()
        })
      })
    })
github faastjs / faast.js / examples / map-buckets-module.ts View on Github external
export async function extractTarStream(
    content: Readable,
    processEntry: (header: tar.Headers, buf: Buffer) => void
) {
    const tarExtract: tar.Extract = tar.extract();
    tarExtract.on("entry", async (header, tarstream, next) => {
        const buf = await streamToBuffer(tarstream);
        processEntry(header, buf);
        next();
    });
    content.pipe(tarExtract);
    await new Promise(resolve => tarExtract.on("finish", resolve));
}
github mafintosh / docker-registry-server / registry.js View on Github external
resolve(function(err, resolved) {
    if (destroyed) return
    if (err) return result.destroy(err)

    var extract = tar.extract()
    var found = false

    result.on('close', function() {
      extract.destroy()
    })

    var entry = function(entry, stream, next) {
      if (entry.name.replace(/^\//, '') !== name) {
        stream.resume()
        return next()
      }

      found = true
      pump(stream, result, function() {
        extract.destroy()
      })
github Soluto / dynamico / server / express-middleware / lib / controller.ts View on Github external
export const save = (driver: Driver) => async (req: Request, res: Response) => {
  const name = sanitizeFilename(req.params.name);
  if (!valid(req.params.componentVersion)) {
    throw new InvalidVersionError({ componentVersion: req.params.componentVersion });
  }
  let componentVersion = clean(req.params.componentVersion) as string;
  const files: File[] = [];

  await promisePipe(
    intoStream(req.file.buffer),
    zlib.createGunzip(),
    tar.extract().on('entry', (header, stream: Stream, next) => {
      files.push({ name: sanitizeFilename(header.name), stream: new ReadableStreamClone(stream) });
      next();
    })
  );

  const issues = await driver.saveComponent(
    {
      name,
      version: componentVersion,
      dependencies: JSON.parse(req.body.peerDependencies)
    },
    files
  );

  res.json(issues);
};
github hyperledger / fabric-sdk-node / fabric-client / lib / Package.js View on Github external
static async _findFileNames(chaincodeDeploymentSpec) {
		const codePackage = chaincodeDeploymentSpec.getCodePackage().toBuffer();
		const gunzip = zlib.createGunzip();
		const extract = tar.extract();
		return new Promise((resolve) => {
			const fileNames = [];
			extract.on('entry', (header, stream, next) => {
				logger.debug('Package._findFileNames - found entry %s', header.name);
				if (header.type === 'file') {
					fileNames.push(header.name);
				}
				stream.on('end', () => {
					next();
				});
				stream.resume();
			});
			extract.on('finish', () => {
				resolve(fileNames.sort());
			});
			gunzip.pipe(extract);
github mafintosh / tar-fs / index.js View on Github external
exports.extract = function (cwd, opts) {
  if (!cwd) cwd = '.'
  if (!opts) opts = {}

  var xfs = opts.fs || fs
  var ignore = opts.ignore || opts.filter || noop
  var map = opts.map || noop
  var mapStream = opts.mapStream || echo
  var own = opts.chown !== false && !win32 && processGetuid() === 0
  var extract = opts.extract || tar.extract()
  var stack = []
  var now = new Date()
  var umask = typeof opts.umask === 'number' ? ~opts.umask : ~processUmask()
  var dmode = typeof opts.dmode === 'number' ? opts.dmode : 0
  var fmode = typeof opts.fmode === 'number' ? opts.fmode : 0
  var strict = opts.strict !== false

  if (opts.strip) map = strip(map, opts.strip)

  if (opts.readable) {
    dmode |= parseInt(555, 8)
    fmode |= parseInt(444, 8)
  }
  if (opts.writable) {
    dmode |= parseInt(333, 8)
    fmode |= parseInt(222, 8)
github replicatedhq / kots / kotsadm / api / src / util / tar.ts View on Github external
export function extractConfigSpecFromTarball(tarball: Buffer): Promise {
  const uncompressed = zlib.unzipSync(tarball);
  const extract = tar.extract();

  let configSpec = null;

  return new Promise((resolve, reject) => {
    extract.on("error", reject);

    extract.on("entry", (header, stream, next) => {
      stream.pipe(concat(data => {
        if (!isYaml(data.toString())) {
          next();
          return;
        }

        const doc = yaml.safeLoad(data.toString());
        if (doc.apiVersion === "kots.io/v1beta1" && doc.kind === "Config") {
          configSpec = data.toString();

tar-stream

tar-stream is a streaming tar parser and generator and nothing else. It operates purely using streams which means you can easily extract/parse tarballs without ever hitting the file system.

MIT
Latest version published 4 months ago

Package Health Score

83 / 100
Full package analysis

Similar packages