11cb0ef41Sopenharmony_ciconst { Minipass } = require('minipass') 21cb0ef41Sopenharmony_ciconst _data = Symbol('_data') 31cb0ef41Sopenharmony_ciconst _length = Symbol('_length') 41cb0ef41Sopenharmony_ciclass Collect extends Minipass { 51cb0ef41Sopenharmony_ci constructor (options) { 61cb0ef41Sopenharmony_ci super(options) 71cb0ef41Sopenharmony_ci this[_data] = [] 81cb0ef41Sopenharmony_ci this[_length] = 0 91cb0ef41Sopenharmony_ci } 101cb0ef41Sopenharmony_ci write (chunk, encoding, cb) { 111cb0ef41Sopenharmony_ci if (typeof encoding === 'function') 121cb0ef41Sopenharmony_ci cb = encoding, encoding = 'utf8' 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ci if (!encoding) 151cb0ef41Sopenharmony_ci encoding = 'utf8' 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ci const c = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk, encoding) 181cb0ef41Sopenharmony_ci this[_data].push(c) 191cb0ef41Sopenharmony_ci this[_length] += c.length 201cb0ef41Sopenharmony_ci if (cb) 211cb0ef41Sopenharmony_ci cb() 221cb0ef41Sopenharmony_ci return true 231cb0ef41Sopenharmony_ci } 241cb0ef41Sopenharmony_ci end (chunk, encoding, cb) { 251cb0ef41Sopenharmony_ci if (typeof chunk === 'function') 261cb0ef41Sopenharmony_ci cb = chunk, chunk = null 271cb0ef41Sopenharmony_ci if (typeof encoding === 'function') 281cb0ef41Sopenharmony_ci cb = encoding, encoding = 'utf8' 291cb0ef41Sopenharmony_ci if (chunk) 301cb0ef41Sopenharmony_ci this.write(chunk, encoding) 311cb0ef41Sopenharmony_ci const result = Buffer.concat(this[_data], this[_length]) 321cb0ef41Sopenharmony_ci super.write(result) 331cb0ef41Sopenharmony_ci return super.end(cb) 341cb0ef41Sopenharmony_ci } 351cb0ef41Sopenharmony_ci} 361cb0ef41Sopenharmony_cimodule.exports = Collect 371cb0ef41Sopenharmony_ci 381cb0ef41Sopenharmony_ci// it would be possible to DRY this a bit by doing something like 391cb0ef41Sopenharmony_ci// this.collector = new Collect() and listening on its data event, 401cb0ef41Sopenharmony_ci// but it's not much code, and we may as well save the extra obj 411cb0ef41Sopenharmony_ciclass CollectPassThrough extends Minipass { 421cb0ef41Sopenharmony_ci constructor (options) { 431cb0ef41Sopenharmony_ci super(options) 441cb0ef41Sopenharmony_ci this[_data] = [] 451cb0ef41Sopenharmony_ci this[_length] = 0 461cb0ef41Sopenharmony_ci } 471cb0ef41Sopenharmony_ci write (chunk, encoding, cb) { 481cb0ef41Sopenharmony_ci if (typeof encoding === 'function') 491cb0ef41Sopenharmony_ci cb = encoding, encoding = 'utf8' 501cb0ef41Sopenharmony_ci 511cb0ef41Sopenharmony_ci if (!encoding) 521cb0ef41Sopenharmony_ci encoding = 'utf8' 531cb0ef41Sopenharmony_ci 541cb0ef41Sopenharmony_ci const c = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk, encoding) 551cb0ef41Sopenharmony_ci this[_data].push(c) 561cb0ef41Sopenharmony_ci this[_length] += c.length 571cb0ef41Sopenharmony_ci return super.write(chunk, encoding, cb) 581cb0ef41Sopenharmony_ci } 591cb0ef41Sopenharmony_ci end (chunk, encoding, cb) { 601cb0ef41Sopenharmony_ci if (typeof chunk === 'function') 611cb0ef41Sopenharmony_ci cb = chunk, chunk = null 621cb0ef41Sopenharmony_ci if (typeof encoding === 'function') 631cb0ef41Sopenharmony_ci cb = encoding, encoding = 'utf8' 641cb0ef41Sopenharmony_ci if (chunk) 651cb0ef41Sopenharmony_ci this.write(chunk, encoding) 661cb0ef41Sopenharmony_ci const result = Buffer.concat(this[_data], this[_length]) 671cb0ef41Sopenharmony_ci this.emit('collect', result) 681cb0ef41Sopenharmony_ci return super.end(cb) 691cb0ef41Sopenharmony_ci } 701cb0ef41Sopenharmony_ci} 711cb0ef41Sopenharmony_cimodule.exports.PassThrough = CollectPassThrough 72