Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'seek-bzip' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
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()));
};