UNPKG

wretch

Version:

A tiny wrapper built around fetch with an intuitive syntax.

3 lines (2 loc) 463 B
const e=()=>{const e={ref:null},r=r=>(t,n)=>{let s=0,o=0;return r(t,n).then((r=>{try{const t=r.headers.get("content-length");o=t?+t:null;const n=new TransformStream({transform(r,t){s+=r.length,o<s&&(o=s),e.ref&&e.ref(s,o),t.enqueue(r)}});return new Response(r.body.pipeThrough(n),r)}catch(e){return r}}))};return{beforeRequest:e=>e._middlewares.push(r),resolver:{progress(r){return e.ref=r,this}}}};export{e as default}; //# sourceMappingURL=progress.min.mjs.map