"use strict";var S=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var C=Object.prototype.hasOwnProperty;var q=(e,r)=>{for(var t in r)S(e,t,{get:r[t],enumerable:!0})},z=(e,r,t,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let d of k(r))!C.call(e,d)&&d!==t&&S(e,d,{get:()=>r[d],enumerable:!(s=_(r,d))||s.enumerable});return e};var Z=e=>z(S({},"__esModule",{value:!0}),e);var Q={};q(Q,{boundaryMatchRegex:()=>g,boundaryRegex:()=>M,default:()=>L,encodeMultipartMessage:()=>v,parseMessage:()=>B,parseMultipartMessage:()=>L});module.exports=Z(Q);var M=/^[0-9a-zA-Z'()+_,\-./:=? ]{0,69}[0-9a-zA-Z'()+_,\-./:=?]$/,g=/;\s*boundary=(?:"([0-9a-zA-Z'()+_,\-./:=? ]{0,69}[0-9a-zA-Z'()+_,\-./:=?])"|([0-9a-zA-Z'+_\-.]{0,69}[0-9a-zA-Z'+_\-.]))/;var W=e=>new ReadableStream({pull(t){if(ArrayBuffer.isView(e))t.enqueue(e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength));else if(e instanceof ArrayBuffer)t.enqueue(e);else throw new TypeError("Expected ArrayBuffer or an ArrayBuffer view.");t.close()}}),f=W;var O=/;\s*boundary=(?:"([^"]+)"|([^;",]+))/,P="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+_-.",U=()=>{let e=new Uint8Array(24);return globalThis.crypto.getRandomValues(e),Array.from(e).map(r=>P[r%P.length]).join("")},T={preventClose:!0};async function*$(e,r,t){let s=new TextEncoder,d=s.encode(`\r --${e}`);if(Array.isArray(r)&&r.length<1){await t.abort(Error("At least one part is required"));return}let l=0;for await(let a of r){l++;let y,o;if(!a.body&&a.parts)if(o=a.headers.get("content-type"),!o)y=U(),o=`multipart/mixed; boundary="${y}"`;else if(!o.startsWith("multipart/")||!O.test(o)){await t.abort(Error("Invalid multipart content type: "+o));return}else{let c=o.match(g);(!c||!(y=c[1]||c[2]))&&(y=U(),o=o.replace(O,`; boundary="${y}"`))}await f(d).pipeTo(t,T),yield;{let c=[""];if(o){let u=!1;a.headers.forEach((p,i)=>{i!=="content-type"?c.push(`${i}: ${p}`):(u=!0,c.push(`${i}: ${o}`))}),u||c.push(`content-type: ${o}`)}else a.headers.forEach((u,p)=>{c.push(`${p}: ${u}`)});a.parts||!a.body?c.push(""):c.push("","");let m=s.encode(c.join(`\r `));c.length=0,await f(m).pipeTo(t,T),yield}if(a.body){if(a.body instanceof ArrayBuffer||ArrayBuffer.isView(a.body))await f(a.body).pipeTo(t,T);else if(a.body instanceof Blob)await a.body.stream().pipeTo(t,T);else if(a.body instanceof ReadableStream)await a.body.pipeTo(t,T);else{await t.abort(Error("Invalid body type"));return}yield}else if(a.parts){if(!y){await t.abort(Error("Runtime exception: undefined part boundary"));return}yield*$(y,a.parts,t),yield}}if(!l){await t.abort(Error("At least one part is required"));return}let n=s.encode(`\r --${e}--`);await f(n).pipeTo(t,T)}var H=(e,r)=>{let t=new TransformStream,s=$(e,r,t.writable),d=!1,l=t.readable.getReader();return new ReadableStream({start(a){(async()=>{for(;;)try{let y=await l.read();if(y.done){let o=new Uint8Array([13,10]);a.enqueue(o.buffer.slice(o.byteOffset,o.byteOffset+o.byteLength)),a.close();return}a.enqueue(y.value)}catch(y){a.error(y);return}})().catch(()=>{})},async pull(){if(d)return;(await s.next()).done&&(d=!0,await t.writable.close())}})},v=H;var V=(e,r)=>{e:for(let t=0;t<=e.length-r.length;t++){for(let s=0;s{let r=0,t=[];for(;(r=b(e,w))!==-1&&r!==0;){let d=e.indexOf(58);if(d===-1)throw new Error("Invalid header");let l=j.decode(e.subarray(0,d));for(;F.includes(e[r+2]);){let a=b(e.subarray(r+2),w);if(a<1)break;r+=2+a}let n=j.decode(e.subarray(d+1,r)).replace(/\r\n/g,"");t.push([l,n]),e=e.subarray(r+w.length)}let s=new Headers(t);return s.has("content-transfer-encoding")||s.set("content-transfer-encoding","7bit"),s.has("content-type")||s.set("content-type","text/plain; charset=us-ascii"),{headers:s,body:r===-1?null:e.subarray(r+w.length)}},B=J;var K=(e,...r)=>{let t=r.reduce((l,n)=>l+n.byteLength,e.length),s=new(Object(r[0])).constructor(t);s.set(e);let d=e.length;return r.forEach(l=>{s.set(l,d),d+=l.byteLength}),s},D=K;async function*G(e,r){var c;if(!M.test(r))throw new Error("Invalid boundary delimiter");let t=new TextEncoder,s=[9,32],d=new Uint8Array([13,10]),l=t.encode(`\r --${r}`),n=new Uint8Array,a=0,y=!1,o=e.getReader();try{for(;a!==3;){let{done:m,value:u}=await o.read();if(m){if(n.length===0||y)throw new Error("Invalid message");y=!0}else n=D(n,ArrayBuffer.isView(u)?new Uint8Array(u.buffer,u.byteOffset,u.byteLength):new Uint8Array(u));for(;n.length>0;){let p=NaN;if(a===0&&(p=b(n,l.slice(2))-2,p===-3)||(p!==-2&&(p=b(n,l)),p===-1))break;let i=p+l.length,h=m?0:b(n.subarray(i,i+32),d);if(h===-1&&n.length-i<32)break;if(h===-1||!Array.from(n.subarray(i+Math.min(2,h),i+h)).every(R=>s.includes(R)))throw new Error(`Invalid boundary at index ${p}`);if(m||h>=2){if([1,2].includes(a)&&n[i+0]===n[i+1]&&n[i+0]===45)a=3;else if(!s.includes(n[i+0])||!s.includes(n[i+1]))throw new Error(`Invalid boundary at index ${p} (${r}): ${(c=n[i+1])==null?void 0:c.toString(16)}`)}switch(a){case 0:a=1;break;case 1:a=2;case 2:case 3:if(n.subarray(p,i).length>0){let R=n.subarray(0,p),x=B(R),A=x.headers.get("content-type"),E;if(x.body&&(A!=null&&A.startsWith("multipart/"))){let I=A.match(g);if(I){let N=I[1]||I[2];E=G(f(x.body),N)}else E=null}yield{headers:x.headers,body:x.body,...E!==void 0&&{parts:E}}}break}if(a===3){n=n.subarray(n.length);break}n=n.subarray(h+i+2)}}}finally{o.releaseLock()}}var L=G;0&&(module.exports={boundaryMatchRegex,boundaryRegex,encodeMultipartMessage,parseMessage,parseMultipartMessage});