Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return stream.fromAsync(async () => func(await stream.readToEnd(data)));
};
}
let compress_fns;
let decompress_fns;
if (nodeZlib) { // Use Node native zlib for DEFLATE compression/decompression
compress_fns = {
zip: node_zlib(nodeZlib.createDeflateRaw, { level: config.deflate_level }),
zlib: node_zlib(nodeZlib.createDeflate, { level: config.deflate_level })
};
decompress_fns = {
zip: node_zlib(nodeZlib.createInflateRaw),
zlib: node_zlib(nodeZlib.createInflate),
bzip2: bzip2(Bunzip.decode)
};
} else { // Use JS fallbacks
compress_fns = {
zip: pako_zlib(pako.Deflate, { raw: true, level: config.deflate_level }),
zlib: pako_zlib(pako.Deflate, { level: config.deflate_level })
};
decompress_fns = {
zip: pako_zlib(pako.Inflate, { raw: true }),
zlib: pako_zlib(pako.Inflate),
bzip2: bzip2(Bunzip.decode)
};
}
module.exports = () => input => {
if (!Buffer.isBuffer(input) && !isStream(input)) {
return Promise.reject(new TypeError(`Expected a Buffer or Stream, got ${typeof input}`));
}
if (Buffer.isBuffer(input) && (!fileType(input) || fileType(input).ext !== 'bz2')) {
return Promise.resolve([]);
}
if (Buffer.isBuffer(input)) {
return decompressTar()(seekBzip.decode(input));
}
return decompressTar()(input.pipe(unbzip2Stream()));
};