async function e(e,t){let n=e.headers["content-type"];if(!n||!~n.indexOf("multipart/"))return e;let r=n.indexOf("boundary="),i="-";if(~r){let e=r+9,t=n.indexOf(";",e);i=n.slice(e,t>-1?t:void 0).trim().replace(/"/g,"")}return async function*(e,t,n){let r,i,f,a=!n||!n.multiple,l=Buffer.byteLength(t),o=Buffer.alloc(0),s=[];e:for await(let n of e){r=o.byteLength,o=Buffer.concat([o,n]);let e=n.indexOf(t);for(~e?r+=e:r=o.indexOf(t),s=[];~r;){let e=o.subarray(0,r),n=o.subarray(r+l);if(i){let t=e.indexOf("\r\n\r\n")+4,r=e.lastIndexOf("\r\n",t),i=!1,l=e.subarray(t,r>-1?void 0:r),o=String(e.subarray(0,t)).trim().split("\r\n"),d={},y=o.length;for(;f=o[--y];f=f.split(": "),d[f.shift().toLowerCase()]=f.join(": "));if(f=d["content-type"],f&&~f.indexOf("application/json"))try{l=JSON.parse(String(l)),i=!0}catch(e){}if(f={headers:d,body:l,json:i},a?yield f:s.push(f),45===n[0]&&45===n[1])break e}else t="\r\n"+t,i=l+=2;o=n,r=o.indexOf(t)}s.length&&(yield s)}s.length&&(yield s)}(e,`--${i}`,t)}export{e as meros};