/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/multistream@4.1.0/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
/*! multistream. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
const stream=require("readable-stream"),once=require("once");function toStreams2Obj(t){return toStreams2(t,{objectMode:!0,highWaterMark:16})}function toStreams2Buf(t){return toStreams2(t)}function toStreams2(t,e){if(!t||"function"==typeof t||t._readableState)return t;const r=new stream.Readable(e).wrap(t);return t.destroy&&(r.destroy=t.destroy.bind(t)),r}class MultiStream extends stream.Readable{constructor(t,e){super({...e,autoDestroy:!0}),this._drained=!1,this._forwarding=!1,this._current=null,this._toStreams2=e&&e.objectMode?toStreams2Obj:toStreams2Buf,"function"==typeof t?this._queue=t:(this._queue=t.map(this._toStreams2),this._queue.forEach((t=>{"function"!=typeof t&&this._attachErrorListener(t)}))),this._next()}_read(){this._drained=!0,this._forward()}_forward(){if(this._forwarding||!this._drained||!this._current)return;let t;for(this._forwarding=!0;this._drained&&null!==(t=this._current.read());)this._drained=this.push(t);this._forwarding=!1}_destroy(t,e){let r=[];if(this._current&&r.push(this._current),"function"!=typeof this._queue&&(r=r.concat(this._queue)),0===r.length)e(t);else{let s=r.length,o=t;r.forEach((r=>{destroy(r,t,(t=>{o=o||t,0==--s&&e(o)}))}))}}_next(){if(this._current=null,"function"==typeof this._queue)this._queue(((t,e)=>{if(t)return this.destroy(t);e=this._toStreams2(e),this._attachErrorListener(e),this._gotNextStream(e)}));else{let t=this._queue.shift();"function"==typeof t&&(t=this._toStreams2(t()),this._attachErrorListener(t)),this._gotNextStream(t)}}_gotNextStream(t){if(!t)return void this.push(null);this._current=t,this._forward();const e=()=>{this._forward()},r=()=>{if(!t._readableState.ended&&!t.destroyed){const t=new Error("ERR_STREAM_PREMATURE_CLOSE");t.code="ERR_STREAM_PREMATURE_CLOSE",this.destroy(t)}},s=()=>{this._current=null,t.removeListener("readable",e),t.removeListener("end",s),t.removeListener("close",r),t.destroy(),this._next()};t.on("readable",e),t.once("end",s),t.once("close",r)}_attachErrorListener(t){if(!t)return;const e=r=>{t.removeListener("error",e),this.destroy(r)};t.once("error",e)}}function destroy(t,e,r){if(!t.destroy||t.destroyed)r(e);else{const s=once((t=>r(t||e)));t.on("error",s).on("close",(()=>s())).destroy(e,s)}}MultiStream.obj=t=>new MultiStream(t,{objectMode:!0,highWaterMark:16}),module.exports=MultiStream;
//# sourceMappingURL=/sm/36ad94c4c9b4272cbc48b3d3129ed8d0188fef1ec661f9a3354f44438e614b93.map