msb-file 0.0.3 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- "use strict";var Q=Object.create;var K=Object.defineProperty;var X=Object.getOwnPropertyDescriptor;var Z=Object.getOwnPropertyNames;var _=Object.getPrototypeOf,x=Object.prototype.hasOwnProperty;var ee=(r,e,n,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of Z(e))!x.call(r,t)&&t!==n&&K(r,t,{get:()=>e[t],enumerable:!(a=X(e,t))||a.enumerable});return r};var L=(r,e,n)=>(n=r!=null?Q(_(r)):{},ee(e||!r||!r.__esModule?K(n,"default",{value:r,enumerable:!0}):n,r));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const O=require("localforage"),re=require("js-md5");function U(r,e,n,a,t,u,i){try{var l=r[u](i),o=l.value}catch(h){return void n(h)}l.done?e(o):Promise.resolve(o).then(a,t)}function g(r){return function(){var e=this,n=arguments;return new Promise(function(a,t){var u=r.apply(e,n);function i(o){U(u,a,t,i,l,"next",o)}function l(o){U(u,a,t,i,l,"throw",o)}i(void 0)})}}function ne(r,e){if(!(r instanceof e))throw new TypeError("Cannot call a class as a function")}function W(r,e){for(var n=0;n<e.length;n++){var a=e[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(r,q(a.key),a)}}function te(r,e,n){return e&&W(r.prototype,e),n&&W(r,n),Object.defineProperty(r,"prototype",{writable:!1}),r}function m(r,e,n){return(e=q(e))in r?Object.defineProperty(r,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):r[e]=n,r}function c(){var r,e,n=typeof Symbol=="function"?Symbol:{},a=n.iterator||"@@iterator",t=n.toStringTag||"@@toStringTag";function u(p,y,P,j){var f=y&&y.prototype instanceof l?y:l,G=Object.create(f.prototype);return C(G,"_invoke",(function(F,Y,J){var E,d,w,B=0,T=J||[],z=!1,R={p:0,n:0,v:r,a:A,f:A.bind(r,4),d:function(S,k){return E=S,d=0,w=r,R.n=k,i}};function A(S,k){for(d=S,w=k,e=0;!z&&B&&!N&&e<T.length;e++){var N,b=T[e],$=R.p,I=b[2];S>3?(N=I===k)&&(w=b[(d=b[4])?5:(d=3,3)],b[4]=b[5]=r):b[0]<=$&&((N=S<2&&$<b[1])?(d=0,R.v=k,R.n=b[1]):$<I&&(N=S<3||b[0]>k||k>I)&&(b[4]=S,b[5]=k,R.n=I,d=0))}if(N||S>1)return i;throw z=!0,k}return function(S,k,N){if(B>1)throw TypeError("Generator is already running");for(z&&k===1&&A(k,N),d=k,w=N;(e=d<2?r:w)||!z;){E||(d?d<3?(d>1&&(R.n=-1),A(d,w)):R.n=w:R.v=w);try{if(B=2,E){if(d||(S="next"),e=E[S]){if(!(e=e.call(E,w)))throw TypeError("iterator result is not an object");if(!e.done)return e;w=e.value,d<2&&(d=0)}else d===1&&(e=E.return)&&e.call(E),d<2&&(w=TypeError("The iterator does not provide a '"+S+"' method"),d=1);E=r}else if((e=(z=R.n<0)?w:F.call(Y,R))!==i)break}catch(b){E=r,d=1,w=b}finally{B=1}}return{value:e,done:z}}})(p,P,j),!0),G}var i={};function l(){}function o(){}function h(){}e=Object.getPrototypeOf;var v=[][a]?e(e([][a]())):(C(e={},a,function(){return this}),e),s=h.prototype=l.prototype=Object.create(v);function D(p){return Object.setPrototypeOf?Object.setPrototypeOf(p,h):(p.__proto__=h,C(p,t,"GeneratorFunction")),p.prototype=Object.create(s),p}return o.prototype=h,C(s,"constructor",h),C(h,"constructor",o),o.displayName="GeneratorFunction",C(h,t,"GeneratorFunction"),C(s),C(s,t,"Generator"),C(s,a,function(){return this}),C(s,"toString",function(){return"[object Generator]"}),(c=function(){return{w:u,m:D}})()}function C(r,e,n,a){var t=Object.defineProperty;try{t({},"",{})}catch{t=0}C=function(u,i,l,o){function h(v,s){C(u,v,function(D){return this._invoke(v,s,D)})}i?t?t(u,i,{value:l,enumerable:!o,configurable:!o,writable:!o}):u[i]=l:(h("next",0),h("throw",1),h("return",2))},C(r,e,n,a)}function ae(r){if(r!=null){var e=r[typeof Symbol=="function"&&Symbol.iterator||"@@iterator"],n=0;if(e)return e.call(r);if(typeof r.next=="function")return r;if(!isNaN(r.length))return{next:function(){return r&&n>=r.length&&(r=void 0),{value:r&&r[n++],done:!r}}}}throw new TypeError(typeof r+" is not iterable")}function ie(r,e){if(typeof r!="object"||!r)return r;var n=r[Symbol.toPrimitive];if(n!==void 0){var a=n.call(r,e);if(typeof a!="object")return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(r)}function q(r){var e=ie(r,"string");return typeof e=="symbol"?e:e+""}var H=(function(r){return r.PENDING="pending",r.PAUSE="pause",r.DOWNLOADING="downloading",r.FINISHED="finished",r.ERROR="error",r})(H||{}),V=(function(r){return r.READY="ready",r.STATUS_UPDATE="status_update",r.PROGRESS_UPDATE="progress_update",r})(V||{}),M=(function(){function r(e){var n=this,a=e.url,t=e.fileName,u=e.chunkSize,i=u===void 0?10*1024*1024:u,l=e.onReady,o=e.onProgress,h=e.onStatusChange;ne(this,r),m(this,"url",void 0),m(this,"fileName",void 0),m(this,"isReady",!1),m(this,"abortController",void 0),m(this,"currentChunk",0),m(this,"chunkSize",void 0),m(this,"totalChunk",0),m(this,"totalSize",0),m(this,"status","pending"),m(this,"onReady",void 0),m(this,"onStatusChange",void 0),m(this,"onProgress",void 0),m(this,"getURLMd5",(function(){var v;return function(){return v||(v=re.md5(n.url))}})()),this.url=a,this.fileName=t,this.chunkSize=i,this.abortController=new AbortController,this.onReady=l,this.onProgress=o,this.onStatusChange=h,this.openDB()}return te(r,[{key:"changeStatus",value:function(n){var a,t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:null;this.status=n,(a=this.onStatusChange)===null||a===void 0||a.call(this,n,t)}},{key:"openDB",value:(function(){var e=g(c().m(function a(){var t,u;return c().w(function(i){for(;;)switch(i.p=i.n){case 0:return i.p=0,this.changeStatus("pending"),i.n=1,O.ready();case 1:return i.n=2,this.init();case 2:(t=this.onReady)===null||t===void 0||t.call(this),this.isReady=!0,i.n=4;break;case 3:i.p=3,u=i.v,this.changeStatus("error",u);case 4:return i.a(2)}},a,this,[[0,3]])}));function n(){return e.apply(this,arguments)}return n})()},{key:"getChunkKeys",value:(function(){var e=g(c().m(function a(){var t,u;return c().w(function(i){for(;;)switch(i.n){case 0:return t=this.getURLMd5(),i.n=1,O.keys();case 1:return u=i.v,i.a(2,u.filter(function(l){return l.startsWith("".concat(t,"_"))}))}},a,this)}));function n(){return e.apply(this,arguments)}return n})()},{key:"getCompletedCount",value:(function(){var e=g(c().m(function a(){var t;return c().w(function(u){for(;;)switch(u.n){case 0:return u.n=1,this.getChunkKeys();case 1:return t=u.v,u.a(2,t.length)}},a,this)}));function n(){return e.apply(this,arguments)}return n})()},{key:"getResumePosition",value:(function(){var e=g(c().m(function a(){var t,u,i,l;return c().w(function(o){for(;;)switch(o.n){case 0:return o.n=1,this.getChunkKeys();case 1:for(t=o.v,u=t.map(function(h){return parseInt(h.split("_")[1],10)}).filter(function(h){return!isNaN(h)}),i=0,l=new Set(u);l.has(i);)i++;return o.a(2,i)}},a,this)}));function n(){return e.apply(this,arguments)}return n})()},{key:"init",value:(function(){var e=g(c().m(function a(){var t;return c().w(function(u){for(;;)switch(u.n){case 0:return u.n=1,this.getFileSize();case 1:return t=u.v,this.totalSize=t,this.totalChunk=Math.ceil(this.totalSize/this.chunkSize),u.n=2,this.getResumePosition();case 2:this.currentChunk=u.v,this.updateProgress();case 3:return u.a(2)}},a,this)}));function n(){return e.apply(this,arguments)}return n})()},{key:"getFileSize",value:(function(){var e=g(c().m(function a(){var t,u,i,l,o,h,v;return c().w(function(s){for(;;)switch(s.p=s.n){case 0:return s.p=0,s.n=1,fetch(this.url,{method:"HEAD"});case 1:if(t=s.v,u=t.headers,i=u.get("content-length"),!i){s.n=2;break}return s.a(2,Number(i));case 2:s.n=4;break;case 3:s.p=3,s.v;case 4:return s.n=5,fetch(this.url,{method:"GET",headers:{Range:"bytes=0-0"}});case 5:if(l=s.v,o=l.headers,h=o.get("content-range"),!h){s.n=6;break}if(v=h.match(/\/(\d+)$/),!v){s.n=6;break}return s.a(2,Number(v[1]));case 6:throw new Error("无法获取文件大小");case 7:return s.a(2)}},a,this,[[0,3]])}));function n(){return e.apply(this,arguments)}return n})()},{key:"getCurrentChunkName",value:function(n){var a=this.getURLMd5();return"".concat(a,"_").concat(n)}},{key:"getChunkData",value:(function(){var e=g(c().m(function a(t,u){var i,l;return c().w(function(o){for(;;)switch(o.n){case 0:return o.n=1,fetch(this.url,{headers:{Range:"bytes=".concat(t,"-").concat(u)},signal:(i=this.abortController)===null||i===void 0?void 0:i.signal});case 1:return l=o.v,o.a(2,l.arrayBuffer())}},a,this)}));function n(a,t){return e.apply(this,arguments)}return n})()},{key:"abort",value:function(){var n;(n=this.abortController)===null||n===void 0||n.abort(),this.abortController=new AbortController}},{key:"updateProgress",value:(function(){var e=g(c().m(function a(){var t,u,i;return c().w(function(l){for(;;)switch(l.n){case 0:return l.n=1,this.getCompletedCount();case 1:u=l.v,i=(u/this.totalChunk*100).toFixed(2),(t=this.onProgress)===null||t===void 0||t.call(this,i);case 2:return l.a(2)}},a,this)}));function n(){return e.apply(this,arguments)}return n})()},{key:"resetState",value:function(){this.currentChunk=0,this.updateProgress(),this.changeStatus("pending")}},{key:"start",value:function(){this.isReady&&(this.changeStatus("downloading"),this.download())}},{key:"pause",value:function(){this.changeStatus("pause"),this.abort()}},{key:"resume",value:(function(){var e=g(c().m(function a(){return c().w(function(t){for(;;)switch(t.n){case 0:return t.n=1,this.getResumePosition();case 1:this.currentChunk=t.v,this.changeStatus("downloading"),this.download();case 2:return t.a(2)}},a,this)}));function n(){return e.apply(this,arguments)}return n})()},{key:"cancel",value:(function(){var e=g(c().m(function a(){return c().w(function(t){for(;;)switch(t.n){case 0:return this.abort(),t.n=1,this.remove();case 1:this.resetState();case 2:return t.a(2)}},a,this)}));function n(){return e.apply(this,arguments)}return n})()},{key:"uploadSingeChunk",value:(function(){var e=g(c().m(function a(t){var u,i,l,o;return c().w(function(h){for(;;)switch(h.n){case 0:return u=this.getCurrentChunkName(t),h.n=1,O.getItem(u);case 1:if(!h.v){h.n=2;break}return this.updateProgress(),h.a(2);case 2:return i=t*this.chunkSize,l=Math.min(i+this.chunkSize-1,this.totalSize-1),h.n=3,this.getChunkData(i,l);case 3:return o=h.v,h.n=4,O.setItem(u,new Blob([o]));case 4:this.updateProgress();case 5:return h.a(2)}},a,this)}));function n(a){return e.apply(this,arguments)}return n})()},{key:"download",value:(function(){var e=g(c().m(function a(){var t=this,u,i,l,o,h,v;return c().w(function(s){for(;;)switch(s.p=s.n){case 0:s.p=0,u=4,i=[],l=(function(){var D=g(c().m(function p(y){return c().w(function(P){for(;;)switch(P.n){case 0:return P.n=1,t.uploadSingeChunk(y);case 1:return P.a(2)}},p)}));return function(y){return D.apply(this,arguments)}})(),o=c().m(function D(){var p;return c().w(function(y){for(;;)switch(y.n){case 0:if(!(i.length>=u)){y.n=1;break}return y.n=1,Promise.race(i);case 1:p=l(t.currentChunk++).finally(function(){var P=i.indexOf(p);P>-1&&i.splice(P,1)}),i.push(p);case 2:return y.a(2)}},D)});case 1:if(!(this.currentChunk<this.totalChunk)){s.n=3;break}return s.d(ae(o()),2);case 2:s.n=1;break;case 3:return s.n=4,Promise.all(i);case 4:this.changeStatus("finished"),this.mergeAndDownload(),s.n=7;break;case 5:if(s.p=5,v=s.v,h=v,!(h&&h.name==="AbortError")){s.n=6;break}return s.a(2);case 6:this.changeStatus("error",v);case 7:return s.a(2)}},a,this,[[0,5]])}));function n(){return e.apply(this,arguments)}return n})()},{key:"remove",value:(function(){var e=g(c().m(function a(){var t;return c().w(function(u){for(;;)switch(u.n){case 0:return u.n=1,this.getChunkKeys();case 1:return t=u.v,u.n=2,Promise.all(t.map(function(i){return O.removeItem(i)}));case 2:return u.a(2)}},a,this)}));function n(){return e.apply(this,arguments)}return n})()},{key:"mergeAndDownload",value:(function(){var e=g(c().m(function a(){var t=this,u,i,l,o,h,v,s,D,p,y,P,j;return c().w(function(f){for(;;)switch(f.p=f.n){case 0:return f.n=1,this.getCompletedCount();case 1:if(u=f.v,!(u<this.totalChunk)){f.n=2;break}return this.changeStatus("error",new Error("下载不完整,请取消再重新下载")),f.a(2);case 2:return f.n=3,import("streamsaver");case 3:i=f.v,l=i.createWriteStream(this.fileName,{size:this.totalSize}),o=l.getWriter(),h=this.getURLMd5(),f.p=4,v=0;case 5:if(!(v<this.totalChunk)){f.n=13;break}return f.n=6,O.getItem("".concat(h,"_").concat(v));case 6:if(s=f.v,s){f.n=7;break}throw new Error("Chunk ".concat(v," missed!"));case 7:D=s.stream().getReader();case 8:return f.n=9,D.read();case 9:if(p=f.v,y=p.done,P=p.value,!y){f.n=10;break}return f.a(3,12);case 10:return f.n=11,o.write(P);case 11:f.n=8;break;case 12:v++,f.n=5;break;case 13:return f.n=14,o.close();case 14:setTimeout(g(c().m(function G(){return c().w(function(F){for(;;)switch(F.n){case 0:return F.n=1,t.remove();case 1:t.resetState();case 2:return F.a(2)}},G)})),2e3),f.n=16;break;case 15:f.p=15,j=f.v,this.changeStatus("error",j),o.abort&&o.abort(j);case 16:return f.a(2)}},a,this,[[4,15]])}));function n(){return e.apply(this,arguments)}return n})()},{key:"destroy",value:function(){this.abort()}}],[{key:"setMitmPath",value:function(n){import("streamsaver").then(function(a){a.mitm=n})}}])})();m(M,"EVENTS",V);m(M,"STATUS",H);exports.Download=M;
1
+ "use strict";var Q=Object.create;var K=Object.defineProperty;var X=Object.getOwnPropertyDescriptor;var Z=Object.getOwnPropertyNames;var _=Object.getPrototypeOf,x=Object.prototype.hasOwnProperty;var ee=(r,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of Z(e))!x.call(r,t)&&t!==n&&K(r,t,{get:()=>e[t],enumerable:!(i=X(e,t))||i.enumerable});return r};var L=(r,e,n)=>(n=r!=null?Q(_(r)):{},ee(e||!r||!r.__esModule?K(n,"default",{value:r,enumerable:!0}):n,r));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const O=require("localforage"),re=require("js-md5");function U(r,e,n,i,t,u,a){try{var l=r[u](a),o=l.value}catch(h){return void n(h)}l.done?e(o):Promise.resolve(o).then(i,t)}function p(r){return function(){var e=this,n=arguments;return new Promise(function(i,t){var u=r.apply(e,n);function a(o){U(u,i,t,a,l,"next",o)}function l(o){U(u,i,t,a,l,"throw",o)}a(void 0)})}}function te(r,e){if(!(r instanceof e))throw new TypeError("Cannot call a class as a function")}function W(r,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(r,q(i.key),i)}}function ne(r,e,n){return e&&W(r.prototype,e),n&&W(r,n),Object.defineProperty(r,"prototype",{writable:!1}),r}function g(r,e,n){return(e=q(e))in r?Object.defineProperty(r,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):r[e]=n,r}function c(){var r,e,n=typeof Symbol=="function"?Symbol:{},i=n.iterator||"@@iterator",t=n.toStringTag||"@@toStringTag";function u(m,y,P,j){var f=y&&y.prototype instanceof l?y:l,G=Object.create(f.prototype);return C(G,"_invoke",(function(F,Y,J){var E,d,w,B=0,T=J||[],z=!1,R={p:0,n:0,v:r,a:A,f:A.bind(r,4),d:function(S,k){return E=S,d=0,w=r,R.n=k,a}};function A(S,k){for(d=S,w=k,e=0;!z&&B&&!N&&e<T.length;e++){var N,b=T[e],M=R.p,I=b[2];S>3?(N=I===k)&&(w=b[(d=b[4])?5:(d=3,3)],b[4]=b[5]=r):b[0]<=M&&((N=S<2&&M<b[1])?(d=0,R.v=k,R.n=b[1]):M<I&&(N=S<3||b[0]>k||k>I)&&(b[4]=S,b[5]=k,R.n=I,d=0))}if(N||S>1)return a;throw z=!0,k}return function(S,k,N){if(B>1)throw TypeError("Generator is already running");for(z&&k===1&&A(k,N),d=k,w=N;(e=d<2?r:w)||!z;){E||(d?d<3?(d>1&&(R.n=-1),A(d,w)):R.n=w:R.v=w);try{if(B=2,E){if(d||(S="next"),e=E[S]){if(!(e=e.call(E,w)))throw TypeError("iterator result is not an object");if(!e.done)return e;w=e.value,d<2&&(d=0)}else d===1&&(e=E.return)&&e.call(E),d<2&&(w=TypeError("The iterator does not provide a '"+S+"' method"),d=1);E=r}else if((e=(z=R.n<0)?w:F.call(Y,R))!==a)break}catch(b){E=r,d=1,w=b}finally{B=1}}return{value:e,done:z}}})(m,P,j),!0),G}var a={};function l(){}function o(){}function h(){}e=Object.getPrototypeOf;var v=[][i]?e(e([][i]())):(C(e={},i,function(){return this}),e),s=h.prototype=l.prototype=Object.create(v);function D(m){return Object.setPrototypeOf?Object.setPrototypeOf(m,h):(m.__proto__=h,C(m,t,"GeneratorFunction")),m.prototype=Object.create(s),m}return o.prototype=h,C(s,"constructor",h),C(h,"constructor",o),o.displayName="GeneratorFunction",C(h,t,"GeneratorFunction"),C(s),C(s,t,"Generator"),C(s,i,function(){return this}),C(s,"toString",function(){return"[object Generator]"}),(c=function(){return{w:u,m:D}})()}function C(r,e,n,i){var t=Object.defineProperty;try{t({},"",{})}catch{t=0}C=function(u,a,l,o){function h(v,s){C(u,v,function(D){return this._invoke(v,s,D)})}a?t?t(u,a,{value:l,enumerable:!o,configurable:!o,writable:!o}):u[a]=l:(h("next",0),h("throw",1),h("return",2))},C(r,e,n,i)}function ae(r){if(r!=null){var e=r[typeof Symbol=="function"&&Symbol.iterator||"@@iterator"],n=0;if(e)return e.call(r);if(typeof r.next=="function")return r;if(!isNaN(r.length))return{next:function(){return r&&n>=r.length&&(r=void 0),{value:r&&r[n++],done:!r}}}}throw new TypeError(typeof r+" is not iterable")}function ie(r,e){if(typeof r!="object"||!r)return r;var n=r[Symbol.toPrimitive];if(n!==void 0){var i=n.call(r,e);if(typeof i!="object")return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(r)}function q(r){var e=ie(r,"string");return typeof e=="symbol"?e:e+""}var H=(function(r){return r.PENDING="pending",r.PAUSE="pause",r.DOWNLOADING="downloading",r.FINISHED="finished",r.ERROR="error",r})(H||{}),V=(function(r){return r.READY="ready",r.STATUS_UPDATE="status_update",r.PROGRESS_UPDATE="progress_update",r})(V||{}),$=(function(){function r(e){var n=this,i=e.url,t=e.fileName,u=e.chunkSize,a=u===void 0?10*1024*1024:u,l=e.mitmPath,o=e.onReady,h=e.onProgress,v=e.onStatusChange;te(this,r),g(this,"url",void 0),g(this,"fileName",void 0),g(this,"isReady",!1),g(this,"mitmPath",void 0),g(this,"abortController",void 0),g(this,"currentChunk",0),g(this,"chunkSize",void 0),g(this,"totalChunk",0),g(this,"totalSize",0),g(this,"status","pending"),g(this,"onReady",void 0),g(this,"onStatusChange",void 0),g(this,"onProgress",void 0),g(this,"getURLMd5",(function(){var s;return function(){return s||(s=re.md5(n.url))}})()),this.url=i,this.fileName=t,this.chunkSize=a,this.mitmPath=l,this.abortController=new AbortController,this.onReady=o,this.onProgress=h,this.onStatusChange=v,this.openDB()}return ne(r,[{key:"changeStatus",value:function(n){var i,t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:null;this.status=n,(i=this.onStatusChange)===null||i===void 0||i.call(this,n,t)}},{key:"openDB",value:(function(){var e=p(c().m(function i(){var t,u;return c().w(function(a){for(;;)switch(a.p=a.n){case 0:return a.p=0,this.changeStatus("pending"),a.n=1,O.ready();case 1:return a.n=2,this.init();case 2:(t=this.onReady)===null||t===void 0||t.call(this),this.isReady=!0,a.n=4;break;case 3:a.p=3,u=a.v,this.changeStatus("error",u);case 4:return a.a(2)}},i,this,[[0,3]])}));function n(){return e.apply(this,arguments)}return n})()},{key:"getChunkKeys",value:(function(){var e=p(c().m(function i(){var t,u;return c().w(function(a){for(;;)switch(a.n){case 0:return t=this.getURLMd5(),a.n=1,O.keys();case 1:return u=a.v,a.a(2,u.filter(function(l){return l.startsWith("".concat(t,"_"))}))}},i,this)}));function n(){return e.apply(this,arguments)}return n})()},{key:"getCompletedCount",value:(function(){var e=p(c().m(function i(){var t;return c().w(function(u){for(;;)switch(u.n){case 0:return u.n=1,this.getChunkKeys();case 1:return t=u.v,u.a(2,t.length)}},i,this)}));function n(){return e.apply(this,arguments)}return n})()},{key:"getResumePosition",value:(function(){var e=p(c().m(function i(){var t,u,a,l;return c().w(function(o){for(;;)switch(o.n){case 0:return o.n=1,this.getChunkKeys();case 1:for(t=o.v,u=t.map(function(h){return parseInt(h.split("_")[1],10)}).filter(function(h){return!isNaN(h)}),a=0,l=new Set(u);l.has(a);)a++;return o.a(2,a)}},i,this)}));function n(){return e.apply(this,arguments)}return n})()},{key:"init",value:(function(){var e=p(c().m(function i(){var t;return c().w(function(u){for(;;)switch(u.n){case 0:return u.n=1,this.getFileSize();case 1:return t=u.v,this.totalSize=t,this.totalChunk=Math.ceil(this.totalSize/this.chunkSize),u.n=2,this.getResumePosition();case 2:this.currentChunk=u.v,this.updateProgress();case 3:return u.a(2)}},i,this)}));function n(){return e.apply(this,arguments)}return n})()},{key:"getFileSize",value:(function(){var e=p(c().m(function i(){var t,u,a,l,o,h,v;return c().w(function(s){for(;;)switch(s.p=s.n){case 0:return s.p=0,s.n=1,fetch(this.url,{method:"HEAD"});case 1:if(t=s.v,u=t.headers,a=u.get("content-length"),!a){s.n=2;break}return s.a(2,Number(a));case 2:s.n=4;break;case 3:s.p=3,s.v;case 4:return s.n=5,fetch(this.url,{method:"GET",headers:{Range:"bytes=0-0"}});case 5:if(l=s.v,o=l.headers,h=o.get("content-range"),!h){s.n=6;break}if(v=h.match(/\/(\d+)$/),!v){s.n=6;break}return s.a(2,Number(v[1]));case 6:throw new Error("无法获取文件大小");case 7:return s.a(2)}},i,this,[[0,3]])}));function n(){return e.apply(this,arguments)}return n})()},{key:"getCurrentChunkName",value:function(n){var i=this.getURLMd5();return"".concat(i,"_").concat(n)}},{key:"getChunkData",value:(function(){var e=p(c().m(function i(t,u){var a,l;return c().w(function(o){for(;;)switch(o.n){case 0:return o.n=1,fetch(this.url,{headers:{Range:"bytes=".concat(t,"-").concat(u)},signal:(a=this.abortController)===null||a===void 0?void 0:a.signal});case 1:return l=o.v,o.a(2,l.arrayBuffer())}},i,this)}));function n(i,t){return e.apply(this,arguments)}return n})()},{key:"abort",value:function(){var n;(n=this.abortController)===null||n===void 0||n.abort(),this.abortController=new AbortController}},{key:"updateProgress",value:(function(){var e=p(c().m(function i(){var t,u,a;return c().w(function(l){for(;;)switch(l.n){case 0:return l.n=1,this.getCompletedCount();case 1:u=l.v,a=(u/this.totalChunk*100).toFixed(2),(t=this.onProgress)===null||t===void 0||t.call(this,a);case 2:return l.a(2)}},i,this)}));function n(){return e.apply(this,arguments)}return n})()},{key:"resetState",value:function(){this.currentChunk=0,this.updateProgress(),this.changeStatus("pending")}},{key:"start",value:function(){this.isReady&&(this.changeStatus("downloading"),this.download())}},{key:"pause",value:function(){this.changeStatus("pause"),this.abort()}},{key:"resume",value:(function(){var e=p(c().m(function i(){return c().w(function(t){for(;;)switch(t.n){case 0:return t.n=1,this.getResumePosition();case 1:this.currentChunk=t.v,this.changeStatus("downloading"),this.download();case 2:return t.a(2)}},i,this)}));function n(){return e.apply(this,arguments)}return n})()},{key:"cancel",value:(function(){var e=p(c().m(function i(){return c().w(function(t){for(;;)switch(t.n){case 0:return this.abort(),t.n=1,this.remove();case 1:this.resetState();case 2:return t.a(2)}},i,this)}));function n(){return e.apply(this,arguments)}return n})()},{key:"uploadSingeChunk",value:(function(){var e=p(c().m(function i(t){var u,a,l,o;return c().w(function(h){for(;;)switch(h.n){case 0:return u=this.getCurrentChunkName(t),h.n=1,O.getItem(u);case 1:if(!h.v){h.n=2;break}return this.updateProgress(),h.a(2);case 2:return a=t*this.chunkSize,l=Math.min(a+this.chunkSize-1,this.totalSize-1),h.n=3,this.getChunkData(a,l);case 3:return o=h.v,h.n=4,O.setItem(u,new Blob([o]));case 4:this.updateProgress();case 5:return h.a(2)}},i,this)}));function n(i){return e.apply(this,arguments)}return n})()},{key:"download",value:(function(){var e=p(c().m(function i(){var t=this,u,a,l,o,h,v;return c().w(function(s){for(;;)switch(s.p=s.n){case 0:s.p=0,u=4,a=[],l=(function(){var D=p(c().m(function m(y){return c().w(function(P){for(;;)switch(P.n){case 0:return P.n=1,t.uploadSingeChunk(y);case 1:return P.a(2)}},m)}));return function(y){return D.apply(this,arguments)}})(),o=c().m(function D(){var m;return c().w(function(y){for(;;)switch(y.n){case 0:if(!(a.length>=u)){y.n=1;break}return y.n=1,Promise.race(a);case 1:m=l(t.currentChunk++).finally(function(){var P=a.indexOf(m);P>-1&&a.splice(P,1)}),a.push(m);case 2:return y.a(2)}},D)});case 1:if(!(this.currentChunk<this.totalChunk)){s.n=3;break}return s.d(ae(o()),2);case 2:s.n=1;break;case 3:return s.n=4,Promise.all(a);case 4:this.changeStatus("finished"),this.mergeAndDownload(),s.n=7;break;case 5:if(s.p=5,v=s.v,h=v,!(h&&h.name==="AbortError")){s.n=6;break}return s.a(2);case 6:this.changeStatus("error",v);case 7:return s.a(2)}},i,this,[[0,5]])}));function n(){return e.apply(this,arguments)}return n})()},{key:"remove",value:(function(){var e=p(c().m(function i(){var t;return c().w(function(u){for(;;)switch(u.n){case 0:return u.n=1,this.getChunkKeys();case 1:return t=u.v,u.n=2,Promise.all(t.map(function(a){return O.removeItem(a)}));case 2:return u.a(2)}},i,this)}));function n(){return e.apply(this,arguments)}return n})()},{key:"mergeAndDownload",value:(function(){var e=p(c().m(function i(){var t=this,u,a,l,o,h,v,s,D,m,y,P,j;return c().w(function(f){for(;;)switch(f.p=f.n){case 0:return f.n=1,this.getCompletedCount();case 1:if(u=f.v,!(u<this.totalChunk)){f.n=2;break}return this.changeStatus("error",new Error("下载不完整,请取消再重新下载")),f.a(2);case 2:return f.n=3,import("streamsaver");case 3:a=f.v,this.mitmPath&&(a.default.mitm=this.mitmPath),l=a.default.createWriteStream(this.fileName,{size:this.totalSize}),o=l.getWriter(),h=this.getURLMd5(),f.p=4,v=0;case 5:if(!(v<this.totalChunk)){f.n=13;break}return f.n=6,O.getItem("".concat(h,"_").concat(v));case 6:if(s=f.v,s){f.n=7;break}throw new Error("Chunk ".concat(v," missed!"));case 7:D=s.stream().getReader();case 8:return f.n=9,D.read();case 9:if(m=f.v,y=m.done,P=m.value,!y){f.n=10;break}return f.a(3,12);case 10:return f.n=11,o.write(P);case 11:f.n=8;break;case 12:v++,f.n=5;break;case 13:return f.n=14,o.close();case 14:setTimeout(p(c().m(function G(){return c().w(function(F){for(;;)switch(F.n){case 0:return F.n=1,t.remove();case 1:t.resetState();case 2:return F.a(2)}},G)})),2e3),f.n=16;break;case 15:f.p=15,j=f.v,this.changeStatus("error",j),o.abort&&o.abort(j);case 16:return f.a(2)}},i,this,[[4,15]])}));function n(){return e.apply(this,arguments)}return n})()},{key:"destroy",value:function(){this.abort()}}],[{key:"setMitmPath",value:(function(){var e=p(c().m(function i(t){var u;return c().w(function(a){for(;;)switch(a.n){case 0:return a.n=1,import("streamsaver");case 1:u=a.v,u.default.mitm=t;case 2:return a.a(2)}},i)}));function n(i){return e.apply(this,arguments)}return n})()}])})();g($,"EVENTS",V);g($,"STATUS",H);exports.Download=$;
package/lib/msb-file.d.ts CHANGED
@@ -4,6 +4,7 @@ export declare class Download {
4
4
  url: string;
5
5
  fileName: string;
6
6
  isReady: boolean;
7
+ mitmPath?: string;
7
8
  abortController?: AbortController;
8
9
  currentChunk: number;
9
10
  chunkSize: number;
@@ -13,8 +14,8 @@ export declare class Download {
13
14
  onReady: DownloadOptions['onReady'];
14
15
  onStatusChange: DownloadOptions['onStatusChange'];
15
16
  onProgress: DownloadOptions['onProgress'];
16
- constructor({ url, fileName, chunkSize, onReady, onProgress, onStatusChange, }: DownloadOptions);
17
- static setMitmPath(path: string): void;
17
+ constructor({ url, fileName, chunkSize, mitmPath, onReady, onProgress, onStatusChange, }: DownloadOptions);
18
+ static setMitmPath(path: string): Promise<void>;
18
19
  changeStatus(value: STATUS, error?: any): void;
19
20
  openDB(): Promise<void>;
20
21
  getChunkKeys(): Promise<string[]>;
@@ -39,9 +40,10 @@ export declare class Download {
39
40
  destroy(): void;
40
41
  }
41
42
 
42
- declare type DownloadOptions = {
43
+ export declare type DownloadOptions = {
43
44
  url: string;
44
45
  fileName: string;
46
+ mitmPath?: string;
45
47
  onReady?: () => void;
46
48
  onStatusChange?: (status: STATUS, error: any) => void;
47
49
  onProgress?: (value: string) => void;
@@ -1,88 +1,88 @@
1
1
  import O from "localforage";
2
2
  import { md5 as q } from "js-md5";
3
- function K(r, e, n, i, t, u, a) {
3
+ function T(n, e, a, i, t, u, r) {
4
4
  try {
5
- var l = r[u](a), o = l.value;
5
+ var l = n[u](r), o = l.value;
6
6
  } catch (h) {
7
- return void n(h);
7
+ return void a(h);
8
8
  }
9
9
  l.done ? e(o) : Promise.resolve(o).then(i, t);
10
10
  }
11
- function g(r) {
11
+ function p(n) {
12
12
  return function() {
13
- var e = this, n = arguments;
13
+ var e = this, a = arguments;
14
14
  return new Promise(function(i, t) {
15
- var u = r.apply(e, n);
16
- function a(o) {
17
- K(u, i, t, a, l, "next", o);
15
+ var u = n.apply(e, a);
16
+ function r(o) {
17
+ T(u, i, t, r, l, "next", o);
18
18
  }
19
19
  function l(o) {
20
- K(u, i, t, a, l, "throw", o);
20
+ T(u, i, t, r, l, "throw", o);
21
21
  }
22
- a(void 0);
22
+ r(void 0);
23
23
  });
24
24
  };
25
25
  }
26
- function J(r, e) {
27
- if (!(r instanceof e)) throw new TypeError("Cannot call a class as a function");
26
+ function J(n, e) {
27
+ if (!(n instanceof e)) throw new TypeError("Cannot call a class as a function");
28
28
  }
29
- function M(r, e) {
30
- for (var n = 0; n < e.length; n++) {
31
- var i = e[n];
32
- i.enumerable = i.enumerable || !1, i.configurable = !0, "value" in i && (i.writable = !0), Object.defineProperty(r, L(i.key), i);
29
+ function K(n, e) {
30
+ for (var a = 0; a < e.length; a++) {
31
+ var i = e[a];
32
+ i.enumerable = i.enumerable || !1, i.configurable = !0, "value" in i && (i.writable = !0), Object.defineProperty(n, L(i.key), i);
33
33
  }
34
34
  }
35
- function Q(r, e, n) {
36
- return e && M(r.prototype, e), n && M(r, n), Object.defineProperty(r, "prototype", {
35
+ function Q(n, e, a) {
36
+ return e && K(n.prototype, e), a && K(n, a), Object.defineProperty(n, "prototype", {
37
37
  writable: !1
38
- }), r;
38
+ }), n;
39
39
  }
40
- function m(r, e, n) {
41
- return (e = L(e)) in r ? Object.defineProperty(r, e, {
42
- value: n,
40
+ function g(n, e, a) {
41
+ return (e = L(e)) in n ? Object.defineProperty(n, e, {
42
+ value: a,
43
43
  enumerable: !0,
44
44
  configurable: !0,
45
45
  writable: !0
46
- }) : r[e] = n, r;
46
+ }) : n[e] = a, n;
47
47
  }
48
48
  function c() {
49
- var r, e, n = typeof Symbol == "function" ? Symbol : {}, i = n.iterator || "@@iterator", t = n.toStringTag || "@@toStringTag";
50
- function u(p, y, P, F) {
49
+ var n, e, a = typeof Symbol == "function" ? Symbol : {}, i = a.iterator || "@@iterator", t = a.toStringTag || "@@toStringTag";
50
+ function u(d, y, P, F) {
51
51
  var f = y && y.prototype instanceof l ? y : l, j = Object.create(f.prototype);
52
52
  return C(j, "_invoke", (function(G, V, Y) {
53
- var E, d, w, B = 0, T = Y || [], z = !1, R = {
53
+ var E, m, w, B = 0, M = Y || [], z = !1, R = {
54
54
  p: 0,
55
55
  n: 0,
56
- v: r,
56
+ v: n,
57
57
  a: A,
58
- f: A.bind(r, 4),
58
+ f: A.bind(n, 4),
59
59
  d: function(S, k) {
60
- return E = S, d = 0, w = r, R.n = k, a;
60
+ return E = S, m = 0, w = n, R.n = k, r;
61
61
  }
62
62
  };
63
63
  function A(S, k) {
64
- for (d = S, w = k, e = 0; !z && B && !N && e < T.length; e++) {
65
- var N, b = T[e], $ = R.p, I = b[2];
66
- S > 3 ? (N = I === k) && (w = b[(d = b[4]) ? 5 : (d = 3, 3)], b[4] = b[5] = r) : b[0] <= $ && ((N = S < 2 && $ < b[1]) ? (d = 0, R.v = k, R.n = b[1]) : $ < I && (N = S < 3 || b[0] > k || k > I) && (b[4] = S, b[5] = k, R.n = I, d = 0));
64
+ for (m = S, w = k, e = 0; !z && B && !N && e < M.length; e++) {
65
+ var N, b = M[e], $ = R.p, I = b[2];
66
+ S > 3 ? (N = I === k) && (w = b[(m = b[4]) ? 5 : (m = 3, 3)], b[4] = b[5] = n) : b[0] <= $ && ((N = S < 2 && $ < b[1]) ? (m = 0, R.v = k, R.n = b[1]) : $ < I && (N = S < 3 || b[0] > k || k > I) && (b[4] = S, b[5] = k, R.n = I, m = 0));
67
67
  }
68
- if (N || S > 1) return a;
68
+ if (N || S > 1) return r;
69
69
  throw z = !0, k;
70
70
  }
71
71
  return function(S, k, N) {
72
72
  if (B > 1) throw TypeError("Generator is already running");
73
- for (z && k === 1 && A(k, N), d = k, w = N; (e = d < 2 ? r : w) || !z; ) {
74
- E || (d ? d < 3 ? (d > 1 && (R.n = -1), A(d, w)) : R.n = w : R.v = w);
73
+ for (z && k === 1 && A(k, N), m = k, w = N; (e = m < 2 ? n : w) || !z; ) {
74
+ E || (m ? m < 3 ? (m > 1 && (R.n = -1), A(m, w)) : R.n = w : R.v = w);
75
75
  try {
76
76
  if (B = 2, E) {
77
- if (d || (S = "next"), e = E[S]) {
77
+ if (m || (S = "next"), e = E[S]) {
78
78
  if (!(e = e.call(E, w))) throw TypeError("iterator result is not an object");
79
79
  if (!e.done) return e;
80
- w = e.value, d < 2 && (d = 0);
81
- } else d === 1 && (e = E.return) && e.call(E), d < 2 && (w = TypeError("The iterator does not provide a '" + S + "' method"), d = 1);
82
- E = r;
83
- } else if ((e = (z = R.n < 0) ? w : G.call(V, R)) !== a) break;
80
+ w = e.value, m < 2 && (m = 0);
81
+ } else m === 1 && (e = E.return) && e.call(E), m < 2 && (w = TypeError("The iterator does not provide a '" + S + "' method"), m = 1);
82
+ E = n;
83
+ } else if ((e = (z = R.n < 0) ? w : G.call(V, R)) !== r) break;
84
84
  } catch (b) {
85
- E = r, d = 1, w = b;
85
+ E = n, m = 1, w = b;
86
86
  } finally {
87
87
  B = 1;
88
88
  }
@@ -92,9 +92,9 @@ function c() {
92
92
  done: z
93
93
  };
94
94
  };
95
- })(p, P, F), !0), j;
95
+ })(d, P, F), !0), j;
96
96
  }
97
- var a = {};
97
+ var r = {};
98
98
  function l() {
99
99
  }
100
100
  function o() {
@@ -105,8 +105,8 @@ function c() {
105
105
  var v = [][i] ? e(e([][i]())) : (C(e = {}, i, function() {
106
106
  return this;
107
107
  }), e), s = h.prototype = l.prototype = Object.create(v);
108
- function D(p) {
109
- return Object.setPrototypeOf ? Object.setPrototypeOf(p, h) : (p.__proto__ = h, C(p, t, "GeneratorFunction")), p.prototype = Object.create(s), p;
108
+ function D(d) {
109
+ return Object.setPrototypeOf ? Object.setPrototypeOf(d, h) : (d.__proto__ = h, C(d, t, "GeneratorFunction")), d.prototype = Object.create(s), d;
110
110
  }
111
111
  return o.prototype = h, C(s, "constructor", h), C(h, "constructor", o), o.displayName = "GeneratorFunction", C(h, t, "GeneratorFunction"), C(s), C(s, t, "Generator"), C(s, i, function() {
112
112
  return this;
@@ -119,136 +119,136 @@ function c() {
119
119
  };
120
120
  })();
121
121
  }
122
- function C(r, e, n, i) {
122
+ function C(n, e, a, i) {
123
123
  var t = Object.defineProperty;
124
124
  try {
125
125
  t({}, "", {});
126
126
  } catch {
127
127
  t = 0;
128
128
  }
129
- C = function(u, a, l, o) {
129
+ C = function(u, r, l, o) {
130
130
  function h(v, s) {
131
131
  C(u, v, function(D) {
132
132
  return this._invoke(v, s, D);
133
133
  });
134
134
  }
135
- a ? t ? t(u, a, {
135
+ r ? t ? t(u, r, {
136
136
  value: l,
137
137
  enumerable: !o,
138
138
  configurable: !o,
139
139
  writable: !o
140
- }) : u[a] = l : (h("next", 0), h("throw", 1), h("return", 2));
141
- }, C(r, e, n, i);
140
+ }) : u[r] = l : (h("next", 0), h("throw", 1), h("return", 2));
141
+ }, C(n, e, a, i);
142
142
  }
143
- function X(r) {
144
- if (r != null) {
145
- var e = r[typeof Symbol == "function" && Symbol.iterator || "@@iterator"], n = 0;
146
- if (e) return e.call(r);
147
- if (typeof r.next == "function") return r;
148
- if (!isNaN(r.length)) return {
143
+ function X(n) {
144
+ if (n != null) {
145
+ var e = n[typeof Symbol == "function" && Symbol.iterator || "@@iterator"], a = 0;
146
+ if (e) return e.call(n);
147
+ if (typeof n.next == "function") return n;
148
+ if (!isNaN(n.length)) return {
149
149
  next: function() {
150
- return r && n >= r.length && (r = void 0), {
151
- value: r && r[n++],
152
- done: !r
150
+ return n && a >= n.length && (n = void 0), {
151
+ value: n && n[a++],
152
+ done: !n
153
153
  };
154
154
  }
155
155
  };
156
156
  }
157
- throw new TypeError(typeof r + " is not iterable");
157
+ throw new TypeError(typeof n + " is not iterable");
158
158
  }
159
- function Z(r, e) {
160
- if (typeof r != "object" || !r) return r;
161
- var n = r[Symbol.toPrimitive];
162
- if (n !== void 0) {
163
- var i = n.call(r, e);
159
+ function Z(n, e) {
160
+ if (typeof n != "object" || !n) return n;
161
+ var a = n[Symbol.toPrimitive];
162
+ if (a !== void 0) {
163
+ var i = a.call(n, e);
164
164
  if (typeof i != "object") return i;
165
165
  throw new TypeError("@@toPrimitive must return a primitive value.");
166
166
  }
167
- return (e === "string" ? String : Number)(r);
167
+ return (e === "string" ? String : Number)(n);
168
168
  }
169
- function L(r) {
170
- var e = Z(r, "string");
169
+ function L(n) {
170
+ var e = Z(n, "string");
171
171
  return typeof e == "symbol" ? e : e + "";
172
172
  }
173
- var U = /* @__PURE__ */ (function(r) {
174
- return r.PENDING = "pending", r.PAUSE = "pause", r.DOWNLOADING = "downloading", r.FINISHED = "finished", r.ERROR = "error", r;
175
- })(U || {}), W = /* @__PURE__ */ (function(r) {
176
- return r.READY = "ready", r.STATUS_UPDATE = "status_update", r.PROGRESS_UPDATE = "progress_update", r;
173
+ var U = /* @__PURE__ */ (function(n) {
174
+ return n.PENDING = "pending", n.PAUSE = "pause", n.DOWNLOADING = "downloading", n.FINISHED = "finished", n.ERROR = "error", n;
175
+ })(U || {}), W = /* @__PURE__ */ (function(n) {
176
+ return n.READY = "ready", n.STATUS_UPDATE = "status_update", n.PROGRESS_UPDATE = "progress_update", n;
177
177
  })(W || {}), H = /* @__PURE__ */ (function() {
178
- function r(e) {
179
- var n = this, i = e.url, t = e.fileName, u = e.chunkSize, a = u === void 0 ? 10 * 1024 * 1024 : u, l = e.onReady, o = e.onProgress, h = e.onStatusChange;
180
- J(this, r), m(this, "url", void 0), m(this, "fileName", void 0), m(this, "isReady", !1), m(this, "abortController", void 0), m(this, "currentChunk", 0), m(this, "chunkSize", void 0), m(this, "totalChunk", 0), m(this, "totalSize", 0), m(
178
+ function n(e) {
179
+ var a = this, i = e.url, t = e.fileName, u = e.chunkSize, r = u === void 0 ? 10 * 1024 * 1024 : u, l = e.mitmPath, o = e.onReady, h = e.onProgress, v = e.onStatusChange;
180
+ J(this, n), g(this, "url", void 0), g(this, "fileName", void 0), g(this, "isReady", !1), g(this, "mitmPath", void 0), g(this, "abortController", void 0), g(this, "currentChunk", 0), g(this, "chunkSize", void 0), g(this, "totalChunk", 0), g(this, "totalSize", 0), g(
181
181
  this,
182
182
  "status",
183
183
  "pending"
184
184
  /* PENDING */
185
- ), m(this, "onReady", void 0), m(this, "onStatusChange", void 0), m(this, "onProgress", void 0), m(this, "getURLMd5", /* @__PURE__ */ (function() {
186
- var v;
185
+ ), g(this, "onReady", void 0), g(this, "onStatusChange", void 0), g(this, "onProgress", void 0), g(this, "getURLMd5", /* @__PURE__ */ (function() {
186
+ var s;
187
187
  return function() {
188
- return v || (v = q(n.url));
188
+ return s || (s = q(a.url));
189
189
  };
190
- })()), this.url = i, this.fileName = t, this.chunkSize = a, this.abortController = new AbortController(), this.onReady = l, this.onProgress = o, this.onStatusChange = h, this.openDB();
190
+ })()), this.url = i, this.fileName = t, this.chunkSize = r, this.mitmPath = l, this.abortController = new AbortController(), this.onReady = o, this.onProgress = h, this.onStatusChange = v, this.openDB();
191
191
  }
192
- return Q(r, [{
192
+ return Q(n, [{
193
193
  key: "changeStatus",
194
- value: function(n) {
194
+ value: function(a) {
195
195
  var i, t = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : null;
196
- this.status = n, (i = this.onStatusChange) === null || i === void 0 || i.call(this, n, t);
196
+ this.status = a, (i = this.onStatusChange) === null || i === void 0 || i.call(this, a, t);
197
197
  }
198
198
  }, {
199
199
  key: "openDB",
200
200
  value: (function() {
201
- var e = g(/* @__PURE__ */ c().m(function i() {
201
+ var e = p(/* @__PURE__ */ c().m(function i() {
202
202
  var t, u;
203
- return c().w(function(a) {
204
- for (; ; ) switch (a.p = a.n) {
203
+ return c().w(function(r) {
204
+ for (; ; ) switch (r.p = r.n) {
205
205
  case 0:
206
- return a.p = 0, this.changeStatus(
206
+ return r.p = 0, this.changeStatus(
207
207
  "pending"
208
208
  /* PENDING */
209
- ), a.n = 1, O.ready();
209
+ ), r.n = 1, O.ready();
210
210
  case 1:
211
- return a.n = 2, this.init();
211
+ return r.n = 2, this.init();
212
212
  case 2:
213
- (t = this.onReady) === null || t === void 0 || t.call(this), this.isReady = !0, a.n = 4;
213
+ (t = this.onReady) === null || t === void 0 || t.call(this), this.isReady = !0, r.n = 4;
214
214
  break;
215
215
  case 3:
216
- a.p = 3, u = a.v, this.changeStatus("error", u);
216
+ r.p = 3, u = r.v, this.changeStatus("error", u);
217
217
  case 4:
218
- return a.a(2);
218
+ return r.a(2);
219
219
  }
220
220
  }, i, this, [[0, 3]]);
221
221
  }));
222
- function n() {
222
+ function a() {
223
223
  return e.apply(this, arguments);
224
224
  }
225
- return n;
225
+ return a;
226
226
  })()
227
227
  }, {
228
228
  key: "getChunkKeys",
229
229
  value: (function() {
230
- var e = g(/* @__PURE__ */ c().m(function i() {
230
+ var e = p(/* @__PURE__ */ c().m(function i() {
231
231
  var t, u;
232
- return c().w(function(a) {
233
- for (; ; ) switch (a.n) {
232
+ return c().w(function(r) {
233
+ for (; ; ) switch (r.n) {
234
234
  case 0:
235
- return t = this.getURLMd5(), a.n = 1, O.keys();
235
+ return t = this.getURLMd5(), r.n = 1, O.keys();
236
236
  case 1:
237
- return u = a.v, a.a(2, u.filter(function(l) {
237
+ return u = r.v, r.a(2, u.filter(function(l) {
238
238
  return l.startsWith("".concat(t, "_"));
239
239
  }));
240
240
  }
241
241
  }, i, this);
242
242
  }));
243
- function n() {
243
+ function a() {
244
244
  return e.apply(this, arguments);
245
245
  }
246
- return n;
246
+ return a;
247
247
  })()
248
248
  }, {
249
249
  key: "getCompletedCount",
250
250
  value: (function() {
251
- var e = g(/* @__PURE__ */ c().m(function i() {
251
+ var e = p(/* @__PURE__ */ c().m(function i() {
252
252
  var t;
253
253
  return c().w(function(u) {
254
254
  for (; ; ) switch (u.n) {
@@ -259,16 +259,16 @@ var U = /* @__PURE__ */ (function(r) {
259
259
  }
260
260
  }, i, this);
261
261
  }));
262
- function n() {
262
+ function a() {
263
263
  return e.apply(this, arguments);
264
264
  }
265
- return n;
265
+ return a;
266
266
  })()
267
267
  }, {
268
268
  key: "getResumePosition",
269
269
  value: (function() {
270
- var e = g(/* @__PURE__ */ c().m(function i() {
271
- var t, u, a, l;
270
+ var e = p(/* @__PURE__ */ c().m(function i() {
271
+ var t, u, r, l;
272
272
  return c().w(function(o) {
273
273
  for (; ; ) switch (o.n) {
274
274
  case 0:
@@ -278,21 +278,21 @@ var U = /* @__PURE__ */ (function(r) {
278
278
  return parseInt(h.split("_")[1], 10);
279
279
  }).filter(function(h) {
280
280
  return !isNaN(h);
281
- }), a = 0, l = new Set(u); l.has(a); )
282
- a++;
283
- return o.a(2, a);
281
+ }), r = 0, l = new Set(u); l.has(r); )
282
+ r++;
283
+ return o.a(2, r);
284
284
  }
285
285
  }, i, this);
286
286
  }));
287
- function n() {
287
+ function a() {
288
288
  return e.apply(this, arguments);
289
289
  }
290
- return n;
290
+ return a;
291
291
  })()
292
292
  }, {
293
293
  key: "init",
294
294
  value: (function() {
295
- var e = g(/* @__PURE__ */ c().m(function i() {
295
+ var e = p(/* @__PURE__ */ c().m(function i() {
296
296
  var t;
297
297
  return c().w(function(u) {
298
298
  for (; ; ) switch (u.n) {
@@ -307,16 +307,16 @@ var U = /* @__PURE__ */ (function(r) {
307
307
  }
308
308
  }, i, this);
309
309
  }));
310
- function n() {
310
+ function a() {
311
311
  return e.apply(this, arguments);
312
312
  }
313
- return n;
313
+ return a;
314
314
  })()
315
315
  }, {
316
316
  key: "getFileSize",
317
317
  value: (function() {
318
- var e = g(/* @__PURE__ */ c().m(function i() {
319
- var t, u, a, l, o, h, v;
318
+ var e = p(/* @__PURE__ */ c().m(function i() {
319
+ var t, u, r, l, o, h, v;
320
320
  return c().w(function(s) {
321
321
  for (; ; ) switch (s.p = s.n) {
322
322
  case 0:
@@ -324,11 +324,11 @@ var U = /* @__PURE__ */ (function(r) {
324
324
  method: "HEAD"
325
325
  });
326
326
  case 1:
327
- if (t = s.v, u = t.headers, a = u.get("content-length"), !a) {
327
+ if (t = s.v, u = t.headers, r = u.get("content-length"), !r) {
328
328
  s.n = 2;
329
329
  break;
330
330
  }
331
- return s.a(2, Number(a));
331
+ return s.a(2, Number(r));
332
332
  case 2:
333
333
  s.n = 4;
334
334
  break;
@@ -358,22 +358,22 @@ var U = /* @__PURE__ */ (function(r) {
358
358
  }
359
359
  }, i, this, [[0, 3]]);
360
360
  }));
361
- function n() {
361
+ function a() {
362
362
  return e.apply(this, arguments);
363
363
  }
364
- return n;
364
+ return a;
365
365
  })()
366
366
  }, {
367
367
  key: "getCurrentChunkName",
368
- value: function(n) {
368
+ value: function(a) {
369
369
  var i = this.getURLMd5();
370
- return "".concat(i, "_").concat(n);
370
+ return "".concat(i, "_").concat(a);
371
371
  }
372
372
  }, {
373
373
  key: "getChunkData",
374
374
  value: (function() {
375
- var e = g(/* @__PURE__ */ c().m(function i(t, u) {
376
- var a, l;
375
+ var e = p(/* @__PURE__ */ c().m(function i(t, u) {
376
+ var r, l;
377
377
  return c().w(function(o) {
378
378
  for (; ; ) switch (o.n) {
379
379
  case 0:
@@ -381,44 +381,44 @@ var U = /* @__PURE__ */ (function(r) {
381
381
  headers: {
382
382
  Range: "bytes=".concat(t, "-").concat(u)
383
383
  },
384
- signal: (a = this.abortController) === null || a === void 0 ? void 0 : a.signal
384
+ signal: (r = this.abortController) === null || r === void 0 ? void 0 : r.signal
385
385
  });
386
386
  case 1:
387
387
  return l = o.v, o.a(2, l.arrayBuffer());
388
388
  }
389
389
  }, i, this);
390
390
  }));
391
- function n(i, t) {
391
+ function a(i, t) {
392
392
  return e.apply(this, arguments);
393
393
  }
394
- return n;
394
+ return a;
395
395
  })()
396
396
  }, {
397
397
  key: "abort",
398
398
  value: function() {
399
- var n;
400
- (n = this.abortController) === null || n === void 0 || n.abort(), this.abortController = new AbortController();
399
+ var a;
400
+ (a = this.abortController) === null || a === void 0 || a.abort(), this.abortController = new AbortController();
401
401
  }
402
402
  }, {
403
403
  key: "updateProgress",
404
404
  value: (function() {
405
- var e = g(/* @__PURE__ */ c().m(function i() {
406
- var t, u, a;
405
+ var e = p(/* @__PURE__ */ c().m(function i() {
406
+ var t, u, r;
407
407
  return c().w(function(l) {
408
408
  for (; ; ) switch (l.n) {
409
409
  case 0:
410
410
  return l.n = 1, this.getCompletedCount();
411
411
  case 1:
412
- u = l.v, a = (u / this.totalChunk * 100).toFixed(2), (t = this.onProgress) === null || t === void 0 || t.call(this, a);
412
+ u = l.v, r = (u / this.totalChunk * 100).toFixed(2), (t = this.onProgress) === null || t === void 0 || t.call(this, r);
413
413
  case 2:
414
414
  return l.a(2);
415
415
  }
416
416
  }, i, this);
417
417
  }));
418
- function n() {
418
+ function a() {
419
419
  return e.apply(this, arguments);
420
420
  }
421
- return n;
421
+ return a;
422
422
  })()
423
423
  }, {
424
424
  key: "resetState",
@@ -447,7 +447,7 @@ var U = /* @__PURE__ */ (function(r) {
447
447
  }, {
448
448
  key: "resume",
449
449
  value: (function() {
450
- var e = g(/* @__PURE__ */ c().m(function i() {
450
+ var e = p(/* @__PURE__ */ c().m(function i() {
451
451
  return c().w(function(t) {
452
452
  for (; ; ) switch (t.n) {
453
453
  case 0:
@@ -462,15 +462,15 @@ var U = /* @__PURE__ */ (function(r) {
462
462
  }
463
463
  }, i, this);
464
464
  }));
465
- function n() {
465
+ function a() {
466
466
  return e.apply(this, arguments);
467
467
  }
468
- return n;
468
+ return a;
469
469
  })()
470
470
  }, {
471
471
  key: "cancel",
472
472
  value: (function() {
473
- var e = g(/* @__PURE__ */ c().m(function i() {
473
+ var e = p(/* @__PURE__ */ c().m(function i() {
474
474
  return c().w(function(t) {
475
475
  for (; ; ) switch (t.n) {
476
476
  case 0:
@@ -482,16 +482,16 @@ var U = /* @__PURE__ */ (function(r) {
482
482
  }
483
483
  }, i, this);
484
484
  }));
485
- function n() {
485
+ function a() {
486
486
  return e.apply(this, arguments);
487
487
  }
488
- return n;
488
+ return a;
489
489
  })()
490
490
  }, {
491
491
  key: "uploadSingeChunk",
492
492
  value: (function() {
493
- var e = g(/* @__PURE__ */ c().m(function i(t) {
494
- var u, a, l, o;
493
+ var e = p(/* @__PURE__ */ c().m(function i(t) {
494
+ var u, r, l, o;
495
495
  return c().w(function(h) {
496
496
  for (; ; ) switch (h.n) {
497
497
  case 0:
@@ -503,7 +503,7 @@ var U = /* @__PURE__ */ (function(r) {
503
503
  }
504
504
  return this.updateProgress(), h.a(2);
505
505
  case 2:
506
- return a = t * this.chunkSize, l = Math.min(a + this.chunkSize - 1, this.totalSize - 1), h.n = 3, this.getChunkData(a, l);
506
+ return r = t * this.chunkSize, l = Math.min(r + this.chunkSize - 1, this.totalSize - 1), h.n = 3, this.getChunkData(r, l);
507
507
  case 3:
508
508
  return o = h.v, h.n = 4, O.setItem(u, new Blob([o]));
509
509
  case 4:
@@ -513,21 +513,21 @@ var U = /* @__PURE__ */ (function(r) {
513
513
  }
514
514
  }, i, this);
515
515
  }));
516
- function n(i) {
516
+ function a(i) {
517
517
  return e.apply(this, arguments);
518
518
  }
519
- return n;
519
+ return a;
520
520
  })()
521
521
  }, {
522
522
  key: "download",
523
523
  value: (function() {
524
- var e = g(/* @__PURE__ */ c().m(function i() {
525
- var t = this, u, a, l, o, h, v;
524
+ var e = p(/* @__PURE__ */ c().m(function i() {
525
+ var t = this, u, r, l, o, h, v;
526
526
  return c().w(function(s) {
527
527
  for (; ; ) switch (s.p = s.n) {
528
528
  case 0:
529
- s.p = 0, u = 4, a = [], l = /* @__PURE__ */ (function() {
530
- var D = g(/* @__PURE__ */ c().m(function p(y) {
529
+ s.p = 0, u = 4, r = [], l = /* @__PURE__ */ (function() {
530
+ var D = p(/* @__PURE__ */ c().m(function d(y) {
531
531
  return c().w(function(P) {
532
532
  for (; ; ) switch (P.n) {
533
533
  case 0:
@@ -535,26 +535,26 @@ var U = /* @__PURE__ */ (function(r) {
535
535
  case 1:
536
536
  return P.a(2);
537
537
  }
538
- }, p);
538
+ }, d);
539
539
  }));
540
540
  return function(y) {
541
541
  return D.apply(this, arguments);
542
542
  };
543
543
  })(), o = /* @__PURE__ */ c().m(function D() {
544
- var p;
544
+ var d;
545
545
  return c().w(function(y) {
546
546
  for (; ; ) switch (y.n) {
547
547
  case 0:
548
- if (!(a.length >= u)) {
548
+ if (!(r.length >= u)) {
549
549
  y.n = 1;
550
550
  break;
551
551
  }
552
- return y.n = 1, Promise.race(a);
552
+ return y.n = 1, Promise.race(r);
553
553
  case 1:
554
- p = l(t.currentChunk++).finally(function() {
555
- var P = a.indexOf(p);
556
- P > -1 && a.splice(P, 1);
557
- }), a.push(p);
554
+ d = l(t.currentChunk++).finally(function() {
555
+ var P = r.indexOf(d);
556
+ P > -1 && r.splice(P, 1);
557
+ }), r.push(d);
558
558
  case 2:
559
559
  return y.a(2);
560
560
  }
@@ -570,7 +570,7 @@ var U = /* @__PURE__ */ (function(r) {
570
570
  s.n = 1;
571
571
  break;
572
572
  case 3:
573
- return s.n = 4, Promise.all(a);
573
+ return s.n = 4, Promise.all(r);
574
574
  case 4:
575
575
  this.changeStatus(
576
576
  "finished"
@@ -590,39 +590,39 @@ var U = /* @__PURE__ */ (function(r) {
590
590
  }
591
591
  }, i, this, [[0, 5]]);
592
592
  }));
593
- function n() {
593
+ function a() {
594
594
  return e.apply(this, arguments);
595
595
  }
596
- return n;
596
+ return a;
597
597
  })()
598
598
  }, {
599
599
  key: "remove",
600
600
  value: (function() {
601
- var e = g(/* @__PURE__ */ c().m(function i() {
601
+ var e = p(/* @__PURE__ */ c().m(function i() {
602
602
  var t;
603
603
  return c().w(function(u) {
604
604
  for (; ; ) switch (u.n) {
605
605
  case 0:
606
606
  return u.n = 1, this.getChunkKeys();
607
607
  case 1:
608
- return t = u.v, u.n = 2, Promise.all(t.map(function(a) {
609
- return O.removeItem(a);
608
+ return t = u.v, u.n = 2, Promise.all(t.map(function(r) {
609
+ return O.removeItem(r);
610
610
  }));
611
611
  case 2:
612
612
  return u.a(2);
613
613
  }
614
614
  }, i, this);
615
615
  }));
616
- function n() {
616
+ function a() {
617
617
  return e.apply(this, arguments);
618
618
  }
619
- return n;
619
+ return a;
620
620
  })()
621
621
  }, {
622
622
  key: "mergeAndDownload",
623
623
  value: (function() {
624
- var e = g(/* @__PURE__ */ c().m(function i() {
625
- var t = this, u, a, l, o, h, v, s, D, p, y, P, F;
624
+ var e = p(/* @__PURE__ */ c().m(function i() {
625
+ var t = this, u, r, l, o, h, v, s, D, d, y, P, F;
626
626
  return c().w(function(f) {
627
627
  for (; ; ) switch (f.p = f.n) {
628
628
  case 0:
@@ -636,7 +636,7 @@ var U = /* @__PURE__ */ (function(r) {
636
636
  case 2:
637
637
  return f.n = 3, import("streamsaver");
638
638
  case 3:
639
- a = f.v, l = a.createWriteStream(this.fileName, {
639
+ r = f.v, this.mitmPath && (r.default.mitm = this.mitmPath), l = r.default.createWriteStream(this.fileName, {
640
640
  size: this.totalSize
641
641
  }), o = l.getWriter(), h = this.getURLMd5(), f.p = 4, v = 0;
642
642
  case 5:
@@ -656,7 +656,7 @@ var U = /* @__PURE__ */ (function(r) {
656
656
  case 8:
657
657
  return f.n = 9, D.read();
658
658
  case 9:
659
- if (p = f.v, y = p.done, P = p.value, !y) {
659
+ if (d = f.v, y = d.done, P = d.value, !y) {
660
660
  f.n = 10;
661
661
  break;
662
662
  }
@@ -672,7 +672,7 @@ var U = /* @__PURE__ */ (function(r) {
672
672
  case 13:
673
673
  return f.n = 14, o.close();
674
674
  case 14:
675
- setTimeout(/* @__PURE__ */ g(/* @__PURE__ */ c().m(function j() {
675
+ setTimeout(/* @__PURE__ */ p(/* @__PURE__ */ c().m(function j() {
676
676
  return c().w(function(G) {
677
677
  for (; ; ) switch (G.n) {
678
678
  case 0:
@@ -692,10 +692,10 @@ var U = /* @__PURE__ */ (function(r) {
692
692
  }
693
693
  }, i, this, [[4, 15]]);
694
694
  }));
695
- function n() {
695
+ function a() {
696
696
  return e.apply(this, arguments);
697
697
  }
698
- return n;
698
+ return a;
699
699
  })()
700
700
  }, {
701
701
  key: "destroy",
@@ -704,15 +704,29 @@ var U = /* @__PURE__ */ (function(r) {
704
704
  }
705
705
  }], [{
706
706
  key: "setMitmPath",
707
- value: function(n) {
708
- import("streamsaver").then(function(i) {
709
- i.mitm = n;
710
- });
711
- }
707
+ value: (function() {
708
+ var e = p(/* @__PURE__ */ c().m(function i(t) {
709
+ var u;
710
+ return c().w(function(r) {
711
+ for (; ; ) switch (r.n) {
712
+ case 0:
713
+ return r.n = 1, import("streamsaver");
714
+ case 1:
715
+ u = r.v, u.default.mitm = t;
716
+ case 2:
717
+ return r.a(2);
718
+ }
719
+ }, i);
720
+ }));
721
+ function a(i) {
722
+ return e.apply(this, arguments);
723
+ }
724
+ return a;
725
+ })()
712
726
  }]);
713
727
  })();
714
- m(H, "EVENTS", W);
715
- m(H, "STATUS", U);
728
+ g(H, "EVENTS", W);
729
+ g(H, "STATUS", U);
716
730
  export {
717
731
  H as Download
718
732
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "msb-file",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "main": "lib/msb-file.cjs.js",
5
5
  "module": "lib/msb-file.es.js",
6
6
  "types": "lib/msb-file.d.ts",