UNPKG

fast-extract

Version:

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

41 lines (40 loc) 1.18 kB
import throttle from 'lodash.throttle'; import { Transform } from 'stream'; 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){ 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 };