UNPKG

fast-extract

Version:

Extract contents from various archive types (tar, tar.bz2, tar.gz, tar.xz, tgz, zip)

45 lines (44 loc) 1.35 kB
import throttle from 'lodash.throttle'; import { Transform } from '../../compat/stream.js'; let EntryProgressTransform = class EntryProgressTransform extends Transform { _transform(entry, encoding, callback) { if (this.progress) this.progress(entry); this.push(entry, encoding); callback(); } _flush(callback) { if (this.progress) { this.progress(null); if (this.progress.cancel) this.progress.cancel(); this.progress = null; } callback(); } constructor(options){ options = options ? { ...options, objectMode: true } : { objectMode: true }; super(options); const internalOptions = options; let done = false; this.progress = function progress(entry) { if (done) return; // throttle can call after done if (!entry) { done = true; return done; } internalOptions.progress({ progress: 'extract', ...entry }); }; const time = internalOptions.time; if (time !== undefined) this.progress = throttle(this.progress, time, { leading: true }); } }; export { EntryProgressTransform as default };