UNPKG

@prostory/mountain

Version:

Yet another HTTP/2 server and client.

3 lines (2 loc) 750 B
import o from"path";import{appendFileSync as e}from"fs";import{constants as n}from"http2";import t from"busboy";import{ContentType as r}from"../../constants.js";const i=(i,m,p={})=>new Promise(((s,T)=>{var c;const d=null!==(c=m[n.HTTP2_HEADER_CONTENT_TYPE])&&void 0!==c?c:"",a={};d.includes(r.MULTIPART_FORM_DATA)||T(new Error(`Unexpected Content-Type - "${d}". Expected "${r.MULTIPART_FORM_DATA}"`));try{i.pipe(new t({headers:m}).on("file",((n,t,r,i,m)=>{var s;const T=o.resolve(null!==(s=p.directory)&&void 0!==s?s:"",r);t.on("data",(o=>{e(T,o)})).on("end",(()=>{a[n]={mime:m,path:T,filename:r,encoding:i}}))})).on("field",((o,e)=>{a[o]=e})).on("finish",(()=>{s(a)})))}catch(o){T(o)}}));export{i as formData}; //# sourceMappingURL=form_data.js.map