How to use the tar-stream.pack 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 thlorenz / spinup / lib / inject-dockerfile.js View on Github external
pack.finalize();
    });

  tarballStream.on('error', console.error).pipe(extract);
  return pack;
};

function inspect(obj, depth) {
  console.error(require('util').inspect(obj, false, depth || 5, true));
}

// Test
if (!module.parent && typeof window === 'undefined') {
  var dir = path.join(__dirname, '..', 'tmp');  
  var resdir = path.join(__dirname, '..', 'result');  
  var pack = tar.pack();
  var extract = tar.extract();

  var gunzip = require('zlib').createGunzip();

  var ins = fs.createReadStream(dir + '/in.tar.gz', 'utf8').pipe(gunzip);

  go(ins, true)
    .on('error', console.error)
    .pipe(fs.createWriteStream(resdir + '/out.tar', 'utf8'));
}
github spark3dp / print-manager / spark-print-mgr / printableTranslation / translators / Autodesk-Ember.js View on Github external
EmberTranslator.prototype.startTranslation = function (inputPath, outputPath) {
    // create the tar -> gzip -> file stream
    this.fstream = fs.createWriteStream( outputPath );
    this.gzip = zlib.createGzip();
    this.pack = tar.pack();

    this.gzip.pipe( this.fstream );
    this.pack.pipe( this.gzip );
    
    // write the settings
    this.writeSettings();

    return DLPTranslator.prototype.startTranslation.apply( this, [inputPath, outputPath] );
};
github digidem / osm-p2p-syncfile / index.js View on Github external
mfeed.ready(function () {
    // re-pack syncfile multifeed dir into tarball
    var tarPath = path.join(self._syncdir, 'osm-p2p-db.tar')
    var tarSize = 0
    var tcount = through(function (chunk, _, next) { tarSize += chunk.length; next(null, chunk) })

    // 1. create new tar.pack() stream, to be piped to fs.createWriteStream inside self._syncdir
    var pack = tar.pack()

    // 2. recursively walk files in self._syncdir (skip new tar file)
    var rd = readdirp({root: path.join(self._syncdir, 'multifeed')})

    // 3. write all to the tar file
    var twrite = through.obj(function (file, _, next) {
      if (file.path === 'osm-p2p-db.tar') return next()
      debug('file', file.fullPath, file.stat.size)
      var entry = pack.entry({ name: file.path, size: file.stat.size }, function (err) {
        debug('wrote', file.path)
        if (err) return next(err)
        else next()
      })
      pump(fs.createReadStream(file.fullPath), entry)
    })
github teambit / bit / src / api / consumer / lib / doctor.ts View on Github external
async function _generateExamineResultsTarFile(
  examineResults: ExamineResult[],
  envMeta: DoctorMetaData
): Promise {
  const pack = tar.pack(); // pack is a streams2 stream
  const debugLog = await _getDebugLogAsStream();
  const consumerInfo = await _getConsumerInfo();
  let bitmap;
  if (consumerInfo && consumerInfo.path) {
    bitmap = _getBitMap(consumerInfo.path);
  }
  pack.entry({ name: 'env-meta.json' }, JSON.stringify(envMeta, null, 2));
  pack.entry({ name: 'doc-results.json' }, JSON.stringify(examineResults, null, 2));
  if (debugLog) {
    pack.entry({ name: 'debug.log' }, debugLog);
  }
  if (bitmap) {
    pack.entry({ name: '.bitmap' }, bitmap);
  }
  if (consumerInfo && consumerInfo.consumerConfig) {
    pack.entry({ name: 'config.json' }, JSON.stringify(consumerInfo.consumerConfig.toPlainObject(), null, 4));
github sysgears / larix / packages / larix / src / __tests__ / MockRegistry.ts View on Github external
return new Promise(resolve => {
      const { name, version } = pkgJson;
      const pack = tar.pack();
      for (const filePath of Object.keys(files)) {
        pack.entry({ name: filePath }, files[filePath]);
      }
      pack.finalize();
      const writer = new streams.WritableStream();
      const z = zlib.createGzip();
      pack
        .pipe(z)
        .pipe(writer)
        .on('finish', () => {
          const tarballName =
            name.indexOf('/') < 0 ? name : name.substring(name.indexOf('/') + 1) + '-' + version + '.tgz';
          const metadataUrl = `/${name}`;
          let metadata = { versions: {} };
          if (this._resources[metadataUrl]) {
            metadata = JSON.parse(this._resources[metadataUrl].toString());
github npm / pacote / test / finalize-manifest.js View on Github external
function makeTarball (files) {
  let tarData = ''
  const pack = tar.pack()
  Object.keys(files).forEach(function (filename) {
    pack.entry({
      name: 'package/' + filename
    }, JSON.stringify(files[filename]))
  })
  pack.finalize()
  return BB.fromNode(cb => {
    pack.on('error', cb)
    pack.on('end', function () { cb(null, tarData) })
    pack.on('data', function (d) { tarData += d })
  })
}
github cardstack / cardstack / packages / hub / docker-host / build-image.js View on Github external
function buildContext(packages, appName) {
  let archive = tar.pack();
  archive.entry({ name: 'Dockerfile' }, dockerfile(packages, appName));

  async function archivePackages() {
    for (let package of packages) {
      await archivePackage(archive, package);
    }
    archive.finalize();
  }
  archivePackages();

  return archive;
}
github mozilla / thimble.mozilla.org / default / index.js View on Github external
function getDefaultProject(title, dataType) {
  var result = dataType === TAR_STREAM ? Tar.pack() : [];

  _defaultProjects[title].forEach(function(file) {
    switch(dataType) {
    case TAR_STREAM:
      result.entry({ name: file.path }, file.buffer);
      break;
    case FILE_STREAM:
      result.push({
        path: file.path,
        stream: MemoryStream.createReadStream(file.buffer),
        size: file.buffer.length
      });
      break;
    case BUFFER:
    default:
      result.push(file);
github grunjol / nobin-debian-installer / index.js View on Github external
function Deb () {
  this.data = tar.pack()
  this.control = tar.pack()
  this.pkgSize = 0
  this.controlFile = {}
  this.filesMd5 = []
  this.dirs = {}
}
github simon-engledew / dockerweb / server / src / dockerfile.js View on Github external
import tar from 'tar-stream';

var pack = tar.pack();

pack.entry({ name: 'Dockerfile' }, `
FROM gliderlabs/alpine:3.3

CMD ["/bin/sh"]
`);

pack.finalize();

export default pack;

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 6 months ago

Package Health Score

79 / 100
Full package analysis

Similar packages