fast-extract
Version:
Extract contents from various archive types (tar, tar.bz2, tar.gz, tar.xz, tgz, zip)
33 lines (32 loc) • 1.01 kB
JavaScript
import { Transform } from 'stream';
import throttle from 'lodash.throttle';
let EntryProgressTransform = class EntryProgressTransform extends Transform {
_transform(entry, encoding, callback) {
this.progress(entry);
this.push(entry, encoding);
callback();
}
_flush(callback) {
this.progress(null);
callback();
}
constructor(options){
super({
objectMode: true
});
let done = false;
this.progress = function progress(entry) {
if (done) return; // throttle can call after done
// biome-ignore lint/suspicious/noAssignInExpressions: <explanation>
if (!entry) return done = true;
options.progress({
progress: 'extract',
...entry
});
};
if (options.time) this.progress = throttle(this.progress, options.time, {
leading: true
});
}
};
export { EntryProgressTransform as default };