How to use the tar.list 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 lerna / lerna / utils / get-packed / lib / get-packed.js View on Github external
function getPacked(pkg, tarFilePath) {
  const bundledWanted = new Set(pkg.bundleDependencies || pkg.bundledDependencies || []);
  const bundled = new Set();
  const files = [];

  let totalEntries = 0;
  let totalEntrySize = 0;

  return tar
    .list({
      file: tarFilePath,
      onentry(entry) {
        totalEntries += 1;
        totalEntrySize += entry.size;

        const p = entry.path;

        /* istanbul ignore if */
        if (p.startsWith("package/node_modules/")) {
          const name = p.match(/^package\/node_modules\/((?:@[^/]+\/)?[^/]+)/)[1];

          if (bundledWanted.has(name)) {
            bundled.add(name);
          }
        } else {
github elastic / kibana / x-pack / legacy / plugins / epm / server / registry / extract.ts View on Github external
export async function untarBuffer(
  buffer: Buffer,
  filter = (entry: ArchiveEntry): boolean => true,
  onEntry = (entry: ArchiveEntry): void => {}
): Promise {
  const deflatedStream = bufferToStream(buffer);
  // use tar.list vs .extract to avoid writing to disk
  const inflateStream = tar.list().on('entry', (entry: tar.FileStat) => {
    const path = entry.header.path || '';
    if (!filter({ path })) return;
    streamToBuffer(entry).then(entryBuffer => onEntry({ buffer: entryBuffer, path }));
  });

  return new Promise((resolve, reject) => {
    inflateStream.on('end', resolve).on('error', reject);
    deflatedStream.pipe(inflateStream);
  });
}
github orangewise / s3-zip / test / test-s3-same-file-alt-names.js View on Github external
archive.on('close', function () {
    fs.createReadStream(outputPath)
      .pipe(tar.list())
      .on('entry', function (entry) {
        filesRead.push(entry.path)
      })
      .on('end', function () {
        child.same(filesRead, outputFiles)
        child.end()
      })
  })
})
github orangewise / s3-zip / test / test-s3-zip-alt-names.js View on Github external
archive.on('close', function () {
    fs.createReadStream(outputPath)
      .pipe(tar.list())
      .on('entry', function (entry) {
        child.same(entry.path, file1Alt)
        child.same(entry.mode, parseInt('0600', 8))
      })
      .on('end', function () {
        child.end()
      })
  })
})
github vtex / toolbelt / src / modules / setup / utils.ts View on Github external
return new Promise(async (resolve, reject) => {
    try {
      const res = await axios.get(url, { responseType: 'stream', headers: { Authorization: getToken() } })
      let fileCount = 0
      const fileEmitter = tar.list()
      fileEmitter.on('entry', () => (fileCount += 1))
      await util.promisify(pipeline)([res.data, fileEmitter])
      resolve(fileCount === 0)
    } catch (err) {
      reject(err)
    }
  })
}
github angular / webdriver-manager / lib / provider / utils / file_utils.ts View on Github external
export async function tarFileList(tarball: string): Promise {
  const fileList: string[] = [];
  await tar
      .list({
        file: tarball,
        onentry: entry => {
          fileList.push(entry['path'].toString());
        }
      });    
  return fileList;
}
github buildo / smooth-release / src / npm / publish.js View on Github external
const readTar = (file) => {
  const actual = [];
  const onentry = entry => actual.push(entry.path);
  return tar.list({ file, onentry }).then(() => actual);
};