async-downloader
Version:
A lightweight, threaded resource download helper leveraging web workers
1 lines • 1.8 kB
JavaScript
(()=>{"use strict";var e={717:function(e,t){var n=this&&this.__awaiter||function(e,t,n,o){return new(n||(n=Promise))((function(r,s){function a(e){try{u(o.next(e))}catch(e){s(e)}}function i(e){try{u(o.throw(e))}catch(e){s(e)}}function u(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,i)}u((o=o.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.default=(e,t)=>n(void 0,void 0,void 0,(function*(){return yield new Promise(((n,o)=>{let r=(new Date).getTime();const s=new XMLHttpRequest;s.open("GET",e,!0),s.responseType="blob",s.addEventListener("progress",(({lengthComputable:e,loaded:n,total:o})=>{(new Date).getTime()<r+100||!e||(t(Math.floor(n/o*100)),r=(new Date).getTime())})),s.onload=()=>4!==s.readyState||200!==s.status?o(new Error("Download failed")):n(s.response),s.send()}))}))},827:function(e,t,n){var o=this&&this.__awaiter||function(e,t,n,o){return new(n||(n=Promise))((function(r,s){function a(e){try{u(o.next(e))}catch(e){s(e)}}function i(e){try{u(o.throw(e))}catch(e){s(e)}}function u(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,i)}u((o=o.apply(e,t||[])).next())}))},r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const s=r(n(717)),a=self;a.addEventListener("message",(({data:e})=>o(void 0,void 0,void 0,(function*(){try{const t=yield s.default(e,(e=>{a.postMessage({type:"progress",progress:e})}));a.postMessage({type:"result",result:t})}catch(e){if(!(e instanceof Error))return;a.postMessage({type:"error",message:e.message})}}))))}},t={};!function n(o){var r=t[o];if(void 0!==r)return r.exports;var s=t[o]={exports:{}};return e[o].call(s.exports,s,s.exports,n),s.exports}(827)})();