UNPKG

@vulppi/toolbelt

Version:

A collection of tools and utilities.

2 lines (1 loc) 970 B
"use strict";(()=>{var f=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,n)=>(typeof require<"u"?require:t)[n]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var a=f("pako");function g(e){return(0,a.deflate)(JSON.stringify(e))}function h(e){return JSON.parse((0,a.inflate)(e,{to:"string"}).toString())}async function*p(e){if(!e.body)return;let t=parseInt(e.headers.get("content-length")||"0",10),n=new TextDecoder,i=0,c=e.body;async function*y(r){let o=r.getReader();try{for(;;){let{done:s,value:d}=await o.read();if(s)break;d&&(yield d)}}finally{o.releaseLock()}}let l=c[Symbol.asyncIterator]?c[Symbol.asyncIterator]():y(c);try{for await(let r of l){let o=n.decode(r,{stream:!0});i+=r.byteLength;let s=t?i/t:-1;yield{chunk:o,progress:s}}}catch(r){throw console.error("Error reading stream:",r),r}finally{let r=n.decode();r&&(yield{chunk:r,progress:1})}}})();