[PROCESS] () { if (this[PROCESSING]) return this[PROCESSING] = true for (let w = this[QUEUE].head; w !== null && this[JOBS] < this.jobs; w = w.next) { this[PROCESSJOB](w.value) if (w.value.ignore) { const p = w.next this[QUEUE].removeNode(w) w.next = p } } this[PROCESSING] = false if (this[ENDED] && !this[QUEUE].length && this[JOBS] === 0) { if (this.zip) this.zip.end(EOF) else { super.write(EOF) super.end() } } }
constructor (opt) { super(opt) opt = opt || Object.create(null) this.opt = opt this.cwd = opt.cwd || process.cwd() this.maxReadSize = opt.maxReadSize this.preservePaths = !!opt.preservePaths this.strict = !!opt.strict this.noPax = !!opt.noPax this.prefix = (opt.prefix || '').replace(/(\\|\/)+$/, '') this.linkCache = opt.linkCache || new Map() this.statCache = opt.statCache || new Map() this.readdirCache = opt.readdirCache || new Map() this[WRITEENTRYCLASS] = WriteEntry if (typeof opt.onwarn === 'function') this.on('warn', opt.onwarn) this.zip = null if (opt.gzip) { if (typeof opt.gzip !== 'object') opt.gzip = {} this.zip = new zlib.Gzip(opt.gzip) this.zip.on('data', chunk => super.write(chunk)) this.zip.on('end', _ => super.end()) this.zip.on('drain', _ => this[ONDRAIN]()) this.on('resume', _ => this.zip.resume()) } else this.on('drain', this[ONDRAIN]) this.portable = !!opt.portable this.noDirRecurse = !!opt.noDirRecurse this.follow = !!opt.follow this.noMtime = !!opt.noMtime this.mtime = opt.mtime || null this.filter = typeof opt.filter === 'function' ? opt.filter : _ => true this[QUEUE] = new Yallist this[JOBS] = 0 this.jobs = +opt.jobs || 4 this[PROCESSING] = false this[ENDED] = false }
this.on('resume', _ => this.zip.resume())
pause () { if (this.zip) this.zip.pause() return super.pause() }
source.on('data', chunk => { if (!zip.write(chunk)) source.pause() })