Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 {
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);
});
}
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()
})
})
})
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()
})
})
})
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)
}
})
}
export async function tarFileList(tarball: string): Promise {
const fileList: string[] = [];
await tar
.list({
file: tarball,
onentry: entry => {
fileList.push(entry['path'].toString());
}
});
return fileList;
}
const readTar = (file) => {
const actual = [];
const onentry = entry => actual.push(entry.path);
return tar.list({ file, onentry }).then(() => actual);
};