How to use the tar.t 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 yorkie / tensorflow-nodejs / scripts / download-libtensorflow.js View on Github external
https.get(DOWNLOAD_URL, (res) => {
  if (res.statusCode !== 200) {
    throw new Error(DOWNLOAD_URL + ' ' + res.statusMessage);
  } else {
    console.log(DOWNLOAD_URL + ' is finished downloaded.');
  }
  res.pipe(tar.t()).on('entry', (entry) => {
    if (entry.type !== 'File')
      return;
    let headerPath = path.join(__dirname, '../tensorflow/', entry.path);
    entry.pipe(fs.createWriteStream(headerPath));
  }).on('end', () => {
    console.log('download done');
    // const libPath = path.join(__dirname, '../tensorflow/lib/libtensorflow.so');
    // fs.rename(libPath, '/usr/local/lib/libtensorflow.so', (err) => {
    //   if (err)
    //     throw err;
    //   console.log('../tensorflow/lib/libtensorflow.so -> /usr/local/lib/libtensorflow.so');
    // });
  });
});
github cloudinary / cloudinary_js / pkg / verify-pkgs.js View on Github external
function getPackedFiles(pkg) {
  createPackageFile(pkg);
  const tarFile = `${pkgPath}/${pkg.name}/${pkg.name}-${version}.tgz`;
  const files = new Set();

  // Loop over tar file entries
  tar.t({
    sync: true,
    file: tarFile,
    onentry: entry => files.add(getTarEntryPath(entry))
  });

  deletePackageFile(pkg);

  return [...files];
}
github google / nodejs-container-image-builder / test / packer.ts View on Github external
it('packs a directory honoring an ignore file', (done) => {
    const nodeTar = require('tar');

    const fixtureDir = path.join(__dirname, '..', '..', 'fixtures', 'project');

    const tar = pack({'/apples': fixtureDir}, {ignoreFiles: ['.ignore']});

    let paths: string[] = [];

    const extract = tar.pipe(nodeTar.t());
    extract.on('entry', (e: Readable&{path: string}) => {
      paths.push(e.path);
      e.resume();
    });

    extract.on('end', () => {
      paths = paths.sort();
      assert.deepStrictEqual(
          [
            'apples/.ignore', 'apples/index.js', 'apples/lib/',
            'apples/lib/a-file.js', 'apples/test/', 'apples/test/test.js'
          ],
          paths, 'ignored files in globs in ignore files');

      console.log(paths);
      done();
github npm / pacote / test / pack-dir.js View on Github external
test('packs a directory into a valid tarball', t => {
  const manifest = {
    name: 'foo',
    version: '1.2.3'
  }
  const fixture = new Tacks(Dir({
    'package.json': File(manifest),
    'index.js': File('true === false\n')
  }))
  fixture.create(CACHE)
  let entries = {}
  const target = through()
  const extractor = tar.t()
  extractor.on('entry', (entry) => {
    let data = ''
    entry.on('end', () => {
      entries[entry.path] = data
    })
    entry.on('data', d => { data += d })
  })
  const pack = packDir(manifest, CACHE, CACHE, target)
  return BB.join(pipe(target, extractor), pack, () => {
    t.deepEqual(entries, {
      'package/package.json': JSON.stringify(manifest),
      'package/index.js': 'true === false\n'
    })
  })
})
github graalvm / graaljs / deps / npm / lib / pack.js View on Github external
function getContents (pkg, target, filename, silent) {
  const bundledWanted = new Set(
    pkg.bundleDependencies ||
    pkg.bundledDependencies ||
    []
  )
  const files = []
  const bundled = new Set()
  let totalEntries = 0
  let totalEntrySize = 0
  return tar.t({
    file: target,
    onentry (entry) {
      totalEntries++
      totalEntrySize += entry.size
      const p = entry.path
      if (p.startsWith('package/node_modules/')) {
        const name = p.match(/^package\/node_modules\/((?:@[^/]+\/)?[^/]+)/)[1]
        if (bundledWanted.has(name)) {
          bundled.add(name)
        }
      } else {
        files.push({
          path: entry.path.replace(/^package\//, ''),
          size: entry.size,
          mode: entry.mode
        })
github entropic-dev / entropic / tools / vcpm-sync / main.js View on Github external
);
  form.append(
    'optionalDependencies',
    JSON.stringify(packumentVersion.optionalDependencies || {})
  );
  form.append(
    'peerDependencies',
    JSON.stringify(packumentVersion.peerDependencies || {})
  );
  form.append(
    'bundledDependencies',
    JSON.stringify(packumentVersion.bundledDependencies || {})
  );

  const tarball = pacote.tarball.stream(`${pkg}@${version}`);
  const untar = tar.t();

  tarball.pipe(untar);
  untar.on('entry', entry => {
    const buf = [];
    entry.on('data', chunk => buf.push(chunk));
    entry.on('end', () => {
      form.append('entry[]', Buffer.concat(buf), {
        filename: enc(entry.path)
      });
    });
  });

  await new Promise((resolve, reject) => {
    tarball.on('error', reject);
    untar.on('end', resolve).on('error', reject);
  });
github saltyshiomix / create-nextron-app / index.js View on Github external
async function downloadAndExtract(name, example, spinner) {
  const masterUrl = 'https://codeload.github.com/saltyshiomix/nextron/tar.gz/master';
  const got = require('got');
  const { t, x } = require('tar');

  let ext = 'js';
  await got
    .stream(masterUrl)
    .pipe(t({ cwd: name, strip: 3, filter: (path) => {
      if (path.endsWith(`${example}/tsconfig.json`)) {
        ext = 'ts';
      }
      return false;
    }}))
    .on('finish', async () => {
      Promise.all([
        new Promise(resolve => {
          got
            .stream(masterUrl)
            .pipe(x({ cwd: name, strip: 3 }, ['nextron-master/examples/_template/gitignore.txt']))
            .on('finish', () => {
              fs.renameSync(path.join(name, 'gitignore.txt'), path.join(name, '.gitignore'));
              resolve();
            });
        }),