import{n as e}from"./chunk-DHbaKqs-.mjs";import{a as t,i as n,n as r,t as i}from"./from-Ba69_5cR.mjs";function a(e){let t=e.match(/\bfilename=("(.*?)"|([^()<>@,;:\\"/[\]?={}\s\t]+))($|;\s)/i);if(!t)return;let n=t[2]||t[3]||``,r=n.slice(n.lastIndexOf(`\\`)+1);return r=r.replace(/%22/g,`"`),r=r.replace(/&#(\d{4});/g,(e,t)=>String.fromCharCode(t)),r}async function o(e,n){if(!/multipart/i.test(n))throw TypeError(`Failed to fetch`);let i=n.match(/boundary=(?:"([^"]+)"|([^;]+))/i);if(!i)throw TypeError(`no or bad content-type header, no multipart boundary`);let o=new b(i[1]||i[2]),s,c,l,u,d,f,p=[],m=new r,h=e=>{l+=y.decode(e,{stream:!0})},g=e=>{p.push(e)},_=()=>{let e=new t(p,f,{type:d});m.append(u,e)},v=()=>{m.append(u,l)},y=new TextDecoder(`utf-8`);y.decode(),o.onPartBegin=function(){o.onPartData=h,o.onPartEnd=v,s=``,c=``,l=``,u=``,d=``,f=null,p.length=0},o.onHeaderField=function(e){s+=y.decode(e,{stream:!0})},o.onHeaderValue=function(e){c+=y.decode(e,{stream:!0})},o.onHeaderEnd=function(){if(c+=y.decode(),s=s.toLowerCase(),s===`content-disposition`){let e=c.match(/\bname=("([^"]*)"|([^()<>@,;:\\"/[\]?={}\s\t]+))/i);e&&(u=e[2]||e[3]||``),f=a(c),f&&(o.onPartData=g,o.onPartEnd=_)}else s===`content-type`&&(d=c);c=``,s=``};for await(let t of e)o.write(t);return o.end(),m}var s,c,l,u,d,f,p,m,h,g,_,v,y,b;e((()=>{i(),n(),s=0,c={START_BOUNDARY:s++,HEADER_FIELD_START:s++,HEADER_FIELD:s++,HEADER_VALUE_START:s++,HEADER_VALUE:s++,HEADER_VALUE_ALMOST_DONE:s++,HEADERS_ALMOST_DONE:s++,PART_DATA_START:s++,PART_DATA:s++,END:s++},l=1,u={PART_BOUNDARY:l,LAST_BOUNDARY:l*=2},d=10,f=13,p=32,m=45,h=58,g=97,_=122,v=e=>e|32,y=()=>{},b=class{constructor(e){this.index=0,this.flags=0,this.onHeaderEnd=y,this.onHeaderField=y,this.onHeadersEnd=y,this.onHeaderValue=y,this.onPartBegin=y,this.onPartData=y,this.onPartEnd=y,this.boundaryChars={},e=`\r
--`+e;let t=new Uint8Array(e.length);for(let n=0;n<e.length;n++)t[n]=e.charCodeAt(n),this.boundaryChars[t[n]]=!0;this.boundary=t,this.lookbehind=new Uint8Array(this.boundary.length+8),this.state=c.START_BOUNDARY}write(e){let t=0,n=e.length,r=this.index,{lookbehind:i,boundary:a,boundaryChars:o,index:s,state:l,flags:y}=this,b=this.boundary.length,x=b-1,S=e.length,C,w,T=e=>{this[e+`Mark`]=t},E=e=>{delete this[e+`Mark`]},D=(e,t,n,r)=>{(t===void 0||t!==n)&&this[e](r&&r.subarray(t,n))},O=(n,r)=>{let i=n+`Mark`;i in this&&(r?(D(n,this[i],t,e),delete this[i]):(D(n,this[i],e.length,e),this[i]=0))};for(t=0;t<n;t++)switch(C=e[t],l){case c.START_BOUNDARY:if(s===a.length-2){if(C===m)y|=u.LAST_BOUNDARY;else if(C!==f)return;s++;break}else if(s-1==a.length-2){if(y&u.LAST_BOUNDARY&&C===m)l=c.END,y=0;else if(!(y&u.LAST_BOUNDARY)&&C===d)s=0,D(`onPartBegin`),l=c.HEADER_FIELD_START;else return;break}C!==a[s+2]&&(s=-2),C===a[s+2]&&s++;break;case c.HEADER_FIELD_START:l=c.HEADER_FIELD,T(`onHeaderField`),s=0;case c.HEADER_FIELD:if(C===f){E(`onHeaderField`),l=c.HEADERS_ALMOST_DONE;break}if(s++,C===m)break;if(C===h){if(s===1)return;O(`onHeaderField`,!0),l=c.HEADER_VALUE_START;break}if(w=v(C),w<g||w>_)return;break;case c.HEADER_VALUE_START:if(C===p)break;T(`onHeaderValue`),l=c.HEADER_VALUE;case c.HEADER_VALUE:C===f&&(O(`onHeaderValue`,!0),D(`onHeaderEnd`),l=c.HEADER_VALUE_ALMOST_DONE);break;case c.HEADER_VALUE_ALMOST_DONE:if(C!==d)return;l=c.HEADER_FIELD_START;break;case c.HEADERS_ALMOST_DONE:if(C!==d)return;D(`onHeadersEnd`),l=c.PART_DATA_START;break;case c.PART_DATA_START:l=c.PART_DATA,T(`onPartData`);case c.PART_DATA:if(r=s,s===0){for(t+=x;t<S&&!(e[t]in o);)t+=b;t-=x,C=e[t]}if(s<a.length)a[s]===C?(s===0&&O(`onPartData`,!0),s++):s=0;else if(s===a.length)s++,C===f?y|=u.PART_BOUNDARY:C===m?y|=u.LAST_BOUNDARY:s=0;else if(s-1===a.length)if(y&u.PART_BOUNDARY){if(s=0,C===d){y&=~u.PART_BOUNDARY,D(`onPartEnd`),D(`onPartBegin`),l=c.HEADER_FIELD_START;break}}else y&u.LAST_BOUNDARY&&C===m?(D(`onPartEnd`),l=c.END,y=0):s=0;if(s>0)i[s-1]=C;else if(r>0){let e=new Uint8Array(i.buffer,i.byteOffset,i.byteLength);D(`onPartData`,0,r,e),r=0,T(`onPartData`),t--}break;case c.END:break;default:throw Error(`Unexpected state entered: ${l}`)}O(`onHeaderField`),O(`onHeaderValue`),O(`onPartData`),this.index=s,this.state=l,this.flags=y}end(){if(this.state===c.HEADER_FIELD_START&&this.index===0||this.state===c.PART_DATA&&this.index===this.boundary.length)this.onPartEnd();else if(this.state!==c.END)throw Error(`MultipartParser.end(): stream ended unexpectedly`)}}}))();export{o as toFormData};