├── .gitignore ├── .npmignore ├── dist ├── zip-loader.js ├── zip-loader.min.js ├── zip-loader.module.js └── zip-loader.module.min.js ├── examples ├── 496_RPG_icons.html ├── 496_RPG_icons.zip ├── basic.html ├── basic.zip ├── basic │ └── data.json ├── direct-unzip.html ├── index.html ├── logo.svg ├── mixed.html └── mixed.zip ├── package.json ├── readme.md ├── rollup.config.mjs └── src ├── DataReader.js ├── ZipLoader.js ├── parseZip.js └── types.ts /.gitignore: -------------------------------------------------------------------------------- 1 | *.DS_Store 2 | Thumbs.db 3 | 4 | logs 5 | *.log 6 | npm-debug.log* 7 | 8 | *.map 9 | 10 | node_modules 11 | package-lock.json 12 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | examples/* 2 | -------------------------------------------------------------------------------- /dist/zip-loader.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * zip-loader 3 | * https://github.com/yomotsu/ZipLoader 4 | * (c) 2017 @yomotsu 5 | * Released under the MIT License. 6 | * ZipLoader uses pako, released under the MIT license. 7 | */ 8 | (function (global, factory) { 9 | typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : 10 | typeof define === 'function' && define.amd ? define(factory) : 11 | (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.ZipLoader = factory()); 12 | })(this, (function () { 'use strict'; 13 | 14 | var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; 15 | 16 | var pako_inflate_min = {exports: {}}; 17 | 18 | /*! pako 2.1.0 https://github.com/nodeca/pako @license (MIT AND Zlib) */ 19 | 20 | (function (module, exports) { 21 | !function(e,t){t(exports);}(commonjsGlobal,(function(e){var t=(e,t,i,n)=>{let a=65535&e|0,r=e>>>16&65535|0,o=0;for(;0!==i;){o=i>2e3?2e3:i,i-=o;do{a=a+t[n++]|0,r=r+a|0;}while(--o);a%=65521,r%=65521;}return a|r<<16|0};const i=new Uint32Array((()=>{let e,t=[];for(var i=0;i<256;i++){e=i;for(var n=0;n<8;n++)e=1&e?3988292384^e>>>1:e>>>1;t[i]=e;}return t})());var n=(e,t,n,a)=>{const r=i,o=a+n;e^=-1;for(let i=a;i>>8^r[255&(e^t[i])];return -1^e};const a=16209;var r=function(e,t){let i,n,r,o,s,l,d,f,c,h,u,w,b,m,k,_,g,p,v,x,y,E,R,A;const Z=e.state;i=e.next_in,R=e.input,n=i+(e.avail_in-5),r=e.next_out,A=e.output,o=r-(t-e.avail_out),s=r+(e.avail_out-257),l=Z.dmax,d=Z.wsize,f=Z.whave,c=Z.wnext,h=Z.window,u=Z.hold,w=Z.bits,b=Z.lencode,m=Z.distcode,k=(1<>>24,u>>>=p,w-=p,p=g>>>16&255,0===p)A[r++]=65535&g;else {if(!(16&p)){if(0==(64&p)){g=b[(65535&g)+(u&(1<>>=p,w-=p),w<15&&(u+=R[i++]<>>24,u>>>=p,w-=p,p=g>>>16&255,!(16&p)){if(0==(64&p)){g=m[(65535&g)+(u&(1<l){e.msg="invalid distance too far back",Z.mode=a;break e}if(u>>>=p,w-=p,p=r-o,x>p){if(p=x-p,p>f&&Z.sane){e.msg="invalid distance too far back",Z.mode=a;break e}if(y=0,E=h,0===c){if(y+=d-p,p2;)A[r++]=E[y++],A[r++]=E[y++],A[r++]=E[y++],v-=3;v&&(A[r++]=E[y++],v>1&&(A[r++]=E[y++]));}else {y=r-x;do{A[r++]=A[y++],A[r++]=A[y++],A[r++]=A[y++],v-=3;}while(v>2);v&&(A[r++]=A[y++],v>1&&(A[r++]=A[y++]));}break}}break}}while(i>3,i-=v,w-=v<<3,u&=(1<{const u=h.bits;let w,b,m,k,_,g,p=0,v=0,x=0,y=0,E=0,R=0,A=0,Z=0,S=0,T=0,O=null;const U=new Uint16Array(16),D=new Uint16Array(16);let I,B,N,C=null;for(p=0;p<=o;p++)U[p]=0;for(v=0;v=1&&0===U[y];y--);if(E>y&&(E=y),0===y)return a[r++]=20971520,a[r++]=20971520,h.bits=1,0;for(x=1;x0&&(0===e||1!==y))return -1;for(D[1]=0,p=1;p852||2===e&&S>592)return 1;for(;;){I=p-A,c[v]+1=g?(B=C[c[v]-g],N=O[c[v]-g]):(B=96,N=0),w=1<>A)+b]=I<<24|B<<16|N|0;}while(0!==b);for(w=1<>=1;if(0!==w?(T&=w-1,T+=w):T=0,v++,0==--U[p]){if(p===y)break;p=t[i+c[v]];}if(p>E&&(T&k)!==m){for(0===A&&(A=E),_+=x,R=p-A,Z=1<852||2===e&&S>592)return 1;m=T&k,a[m]=E<<24|R<<16|_-r|0;}}return 0!==T&&(a[_+T]=p-A<<24|64<<16|0),h.bits=E,0},h={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8};const{Z_FINISH:u,Z_BLOCK:w,Z_TREES:b,Z_OK:m,Z_STREAM_END:k,Z_NEED_DICT:_,Z_STREAM_ERROR:g,Z_DATA_ERROR:p,Z_MEM_ERROR:v,Z_BUF_ERROR:x,Z_DEFLATED:y}=h,E=16180,R=16190,A=16191,Z=16192,S=16194,T=16199,O=16200,U=16206,D=16209,I=e=>(e>>>24&255)+(e>>>8&65280)+((65280&e)<<8)+((255&e)<<24);function B(){this.strm=null,this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0;}const N=e=>{if(!e)return 1;const t=e.state;return !t||t.strm!==e||t.mode16211?1:0},C=e=>{if(N(e))return g;const t=e.state;return e.total_in=e.total_out=t.total=0,e.msg="",t.wrap&&(e.adler=1&t.wrap),t.mode=E,t.last=0,t.havedict=0,t.flags=-1,t.dmax=32768,t.head=null,t.hold=0,t.bits=0,t.lencode=t.lendyn=new Int32Array(852),t.distcode=t.distdyn=new Int32Array(592),t.sane=1,t.back=-1,m},z=e=>{if(N(e))return g;const t=e.state;return t.wsize=0,t.whave=0,t.wnext=0,C(e)},F=(e,t)=>{let i;if(N(e))return g;const n=e.state;return t<0?(i=0,t=-t):(i=5+(t>>4),t<48&&(t&=15)),t&&(t<8||t>15)?g:(null!==n.window&&n.wbits!==t&&(n.window=null),n.wrap=i,n.wbits=t,z(e))},L=(e,t)=>{if(!e)return g;const i=new B;e.state=i,i.strm=e,i.window=null,i.mode=E;const n=F(e,t);return n!==m&&(e.state=null),n};let M,H,j=!0;const K=e=>{if(j){M=new Int32Array(512),H=new Int32Array(32);let t=0;for(;t<144;)e.lens[t++]=8;for(;t<256;)e.lens[t++]=9;for(;t<280;)e.lens[t++]=7;for(;t<288;)e.lens[t++]=8;for(c(1,e.lens,0,288,M,0,e.work,{bits:9}),t=0;t<32;)e.lens[t++]=5;c(2,e.lens,0,32,H,0,e.work,{bits:5}),j=!1;}e.lencode=M,e.lenbits=9,e.distcode=H,e.distbits=5;},P=(e,t,i,n)=>{let a;const r=e.state;return null===r.window&&(r.wsize=1<=r.wsize?(r.window.set(t.subarray(i-r.wsize,i),0),r.wnext=0,r.whave=r.wsize):(a=r.wsize-r.wnext,a>n&&(a=n),r.window.set(t.subarray(i-n,i-n+a),r.wnext),(n-=a)?(r.window.set(t.subarray(i-n,i),0),r.wnext=n,r.whave=r.wsize):(r.wnext+=a,r.wnext===r.wsize&&(r.wnext=0),r.whaveL(e,15),inflateInit2:L,inflate:(e,i)=>{let a,o,s,l,d,f,h,B,C,z,F,L,M,H,j,Y,G,X,W,q,J,Q,V=0;const $=new Uint8Array(4);let ee,te;const ie=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(N(e)||!e.output||!e.input&&0!==e.avail_in)return g;a=e.state,a.mode===A&&(a.mode=Z),d=e.next_out,s=e.output,h=e.avail_out,l=e.next_in,o=e.input,f=e.avail_in,B=a.hold,C=a.bits,z=f,F=h,Q=m;e:for(;;)switch(a.mode){case E:if(0===a.wrap){a.mode=Z;break}for(;C<16;){if(0===f)break e;f--,B+=o[l++]<>>8&255,a.check=n(a.check,$,2,0),B=0,C=0,a.mode=16181;break}if(a.head&&(a.head.done=!1),!(1&a.wrap)||(((255&B)<<8)+(B>>8))%31){e.msg="incorrect header check",a.mode=D;break}if((15&B)!==y){e.msg="unknown compression method",a.mode=D;break}if(B>>>=4,C-=4,J=8+(15&B),0===a.wbits&&(a.wbits=J),J>15||J>a.wbits){e.msg="invalid window size",a.mode=D;break}a.dmax=1<>8&1),512&a.flags&&4&a.wrap&&($[0]=255&B,$[1]=B>>>8&255,a.check=n(a.check,$,2,0)),B=0,C=0,a.mode=16182;case 16182:for(;C<32;){if(0===f)break e;f--,B+=o[l++]<>>8&255,$[2]=B>>>16&255,$[3]=B>>>24&255,a.check=n(a.check,$,4,0)),B=0,C=0,a.mode=16183;case 16183:for(;C<16;){if(0===f)break e;f--,B+=o[l++]<>8),512&a.flags&&4&a.wrap&&($[0]=255&B,$[1]=B>>>8&255,a.check=n(a.check,$,2,0)),B=0,C=0,a.mode=16184;case 16184:if(1024&a.flags){for(;C<16;){if(0===f)break e;f--,B+=o[l++]<>>8&255,a.check=n(a.check,$,2,0)),B=0,C=0;}else a.head&&(a.head.extra=null);a.mode=16185;case 16185:if(1024&a.flags&&(L=a.length,L>f&&(L=f),L&&(a.head&&(J=a.head.extra_len-a.length,a.head.extra||(a.head.extra=new Uint8Array(a.head.extra_len)),a.head.extra.set(o.subarray(l,l+L),J)),512&a.flags&&4&a.wrap&&(a.check=n(a.check,o,L,l)),f-=L,l+=L,a.length-=L),a.length))break e;a.length=0,a.mode=16186;case 16186:if(2048&a.flags){if(0===f)break e;L=0;do{J=o[l+L++],a.head&&J&&a.length<65536&&(a.head.name+=String.fromCharCode(J));}while(J&&L>9&1,a.head.done=!0),e.adler=a.check=0,a.mode=A;break;case 16189:for(;C<32;){if(0===f)break e;f--,B+=o[l++]<>>=7&C,C-=7&C,a.mode=U;break}for(;C<3;){if(0===f)break e;f--,B+=o[l++]<>>=1,C-=1,3&B){case 0:a.mode=16193;break;case 1:if(K(a),a.mode=T,i===b){B>>>=2,C-=2;break e}break;case 2:a.mode=16196;break;case 3:e.msg="invalid block type",a.mode=D;}B>>>=2,C-=2;break;case 16193:for(B>>>=7&C,C-=7&C;C<32;){if(0===f)break e;f--,B+=o[l++]<>>16^65535)){e.msg="invalid stored block lengths",a.mode=D;break}if(a.length=65535&B,B=0,C=0,a.mode=S,i===b)break e;case S:a.mode=16195;case 16195:if(L=a.length,L){if(L>f&&(L=f),L>h&&(L=h),0===L)break e;s.set(o.subarray(l,l+L),d),f-=L,l+=L,h-=L,d+=L,a.length-=L;break}a.mode=A;break;case 16196:for(;C<14;){if(0===f)break e;f--,B+=o[l++]<>>=5,C-=5,a.ndist=1+(31&B),B>>>=5,C-=5,a.ncode=4+(15&B),B>>>=4,C-=4,a.nlen>286||a.ndist>30){e.msg="too many length or distance symbols",a.mode=D;break}a.have=0,a.mode=16197;case 16197:for(;a.have>>=3,C-=3;}for(;a.have<19;)a.lens[ie[a.have++]]=0;if(a.lencode=a.lendyn,a.lenbits=7,ee={bits:a.lenbits},Q=c(0,a.lens,0,19,a.lencode,0,a.work,ee),a.lenbits=ee.bits,Q){e.msg="invalid code lengths set",a.mode=D;break}a.have=0,a.mode=16198;case 16198:for(;a.have>>24,Y=V>>>16&255,G=65535&V,!(j<=C);){if(0===f)break e;f--,B+=o[l++]<>>=j,C-=j,a.lens[a.have++]=G;else {if(16===G){for(te=j+2;C>>=j,C-=j,0===a.have){e.msg="invalid bit length repeat",a.mode=D;break}J=a.lens[a.have-1],L=3+(3&B),B>>>=2,C-=2;}else if(17===G){for(te=j+3;C>>=j,C-=j,J=0,L=3+(7&B),B>>>=3,C-=3;}else {for(te=j+7;C>>=j,C-=j,J=0,L=11+(127&B),B>>>=7,C-=7;}if(a.have+L>a.nlen+a.ndist){e.msg="invalid bit length repeat",a.mode=D;break}for(;L--;)a.lens[a.have++]=J;}}if(a.mode===D)break;if(0===a.lens[256]){e.msg="invalid code -- missing end-of-block",a.mode=D;break}if(a.lenbits=9,ee={bits:a.lenbits},Q=c(1,a.lens,0,a.nlen,a.lencode,0,a.work,ee),a.lenbits=ee.bits,Q){e.msg="invalid literal/lengths set",a.mode=D;break}if(a.distbits=6,a.distcode=a.distdyn,ee={bits:a.distbits},Q=c(2,a.lens,a.nlen,a.ndist,a.distcode,0,a.work,ee),a.distbits=ee.bits,Q){e.msg="invalid distances set",a.mode=D;break}if(a.mode=T,i===b)break e;case T:a.mode=O;case O:if(f>=6&&h>=258){e.next_out=d,e.avail_out=h,e.next_in=l,e.avail_in=f,a.hold=B,a.bits=C,r(e,F),d=e.next_out,s=e.output,h=e.avail_out,l=e.next_in,o=e.input,f=e.avail_in,B=a.hold,C=a.bits,a.mode===A&&(a.back=-1);break}for(a.back=0;V=a.lencode[B&(1<>>24,Y=V>>>16&255,G=65535&V,!(j<=C);){if(0===f)break e;f--,B+=o[l++]<>X)],j=V>>>24,Y=V>>>16&255,G=65535&V,!(X+j<=C);){if(0===f)break e;f--,B+=o[l++]<>>=X,C-=X,a.back+=X;}if(B>>>=j,C-=j,a.back+=j,a.length=G,0===Y){a.mode=16205;break}if(32&Y){a.back=-1,a.mode=A;break}if(64&Y){e.msg="invalid literal/length code",a.mode=D;break}a.extra=15&Y,a.mode=16201;case 16201:if(a.extra){for(te=a.extra;C>>=a.extra,C-=a.extra,a.back+=a.extra;}a.was=a.length,a.mode=16202;case 16202:for(;V=a.distcode[B&(1<>>24,Y=V>>>16&255,G=65535&V,!(j<=C);){if(0===f)break e;f--,B+=o[l++]<>X)],j=V>>>24,Y=V>>>16&255,G=65535&V,!(X+j<=C);){if(0===f)break e;f--,B+=o[l++]<>>=X,C-=X,a.back+=X;}if(B>>>=j,C-=j,a.back+=j,64&Y){e.msg="invalid distance code",a.mode=D;break}a.offset=G,a.extra=15&Y,a.mode=16203;case 16203:if(a.extra){for(te=a.extra;C>>=a.extra,C-=a.extra,a.back+=a.extra;}if(a.offset>a.dmax){e.msg="invalid distance too far back",a.mode=D;break}a.mode=16204;case 16204:if(0===h)break e;if(L=F-h,a.offset>L){if(L=a.offset-L,L>a.whave&&a.sane){e.msg="invalid distance too far back",a.mode=D;break}L>a.wnext?(L-=a.wnext,M=a.wsize-L):M=a.wnext-L,L>a.length&&(L=a.length),H=a.window;}else H=s,M=d-a.offset,L=a.length;L>h&&(L=h),h-=L,a.length-=L;do{s[d++]=H[M++];}while(--L);0===a.length&&(a.mode=O);break;case 16205:if(0===h)break e;s[d++]=a.length,h--,a.mode=O;break;case U:if(a.wrap){for(;C<32;){if(0===f)break e;f--,B|=o[l++]<{if(N(e))return g;let t=e.state;return t.window&&(t.window=null),e.state=null,m},inflateGetHeader:(e,t)=>{if(N(e))return g;const i=e.state;return 0==(2&i.wrap)?g:(i.head=t,t.done=!1,m)},inflateSetDictionary:(e,i)=>{const n=i.length;let a,r,o;return N(e)?g:(a=e.state,0!==a.wrap&&a.mode!==R?g:a.mode===R&&(r=1,r=t(r,i,n,0),r!==a.check)?p:(o=P(e,i,n,n),o?(a.mode=16210,v):(a.havedict=1,m)))},inflateInfo:"pako inflate (from Nodeca project)"};const G=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var X=function(e){const t=Array.prototype.slice.call(arguments,1);for(;t.length;){const i=t.shift();if(i){if("object"!=typeof i)throw new TypeError(i+"must be non-object");for(const t in i)G(i,t)&&(e[t]=i[t]);}}return e},W=e=>{let t=0;for(let i=0,n=e.length;i=252?6:e>=248?5:e>=240?4:e>=224?3:e>=192?2:1;J[254]=J[254]=1;var Q=e=>{if("function"==typeof TextEncoder&&TextEncoder.prototype.encode)return (new TextEncoder).encode(e);let t,i,n,a,r,o=e.length,s=0;for(a=0;a>>6,t[r++]=128|63&i):i<65536?(t[r++]=224|i>>>12,t[r++]=128|i>>>6&63,t[r++]=128|63&i):(t[r++]=240|i>>>18,t[r++]=128|i>>>12&63,t[r++]=128|i>>>6&63,t[r++]=128|63&i);return t},V=(e,t)=>{const i=t||e.length;if("function"==typeof TextDecoder&&TextDecoder.prototype.decode)return (new TextDecoder).decode(e.subarray(0,t));let n,a;const r=new Array(2*i);for(a=0,n=0;n4)r[a++]=65533,n+=o-1;else {for(t&=2===o?31:3===o?15:7;o>1&&n1?r[a++]=65533:t<65536?r[a++]=t:(t-=65536,r[a++]=55296|t>>10&1023,r[a++]=56320|1023&t);}}return ((e,t)=>{if(t<65534&&e.subarray&&q)return String.fromCharCode.apply(null,e.length===t?e:e.subarray(0,t));let i="";for(let n=0;n{(t=t||e.length)>e.length&&(t=e.length);let i=t-1;for(;i>=0&&128==(192&e[i]);)i--;return i<0||0===i?t:i+J[e[i]]>t?i:t},ee={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"};var te=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0;};var ie=function(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1;};const ne=Object.prototype.toString,{Z_NO_FLUSH:ae,Z_FINISH:re,Z_OK:oe,Z_STREAM_END:se,Z_NEED_DICT:le,Z_STREAM_ERROR:de,Z_DATA_ERROR:fe,Z_MEM_ERROR:ce}=h;function he(e){this.options=X({chunkSize:65536,windowBits:15,to:""},e||{});const t=this.options;t.raw&&t.windowBits>=0&&t.windowBits<16&&(t.windowBits=-t.windowBits,0===t.windowBits&&(t.windowBits=-15)),!(t.windowBits>=0&&t.windowBits<16)||e&&e.windowBits||(t.windowBits+=32),t.windowBits>15&&t.windowBits<48&&0==(15&t.windowBits)&&(t.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new te,this.strm.avail_out=0;let i=Y.inflateInit2(this.strm,t.windowBits);if(i!==oe)throw new Error(ee[i]);if(this.header=new ie,Y.inflateGetHeader(this.strm,this.header),t.dictionary&&("string"==typeof t.dictionary?t.dictionary=Q(t.dictionary):"[object ArrayBuffer]"===ne.call(t.dictionary)&&(t.dictionary=new Uint8Array(t.dictionary)),t.raw&&(i=Y.inflateSetDictionary(this.strm,t.dictionary),i!==oe)))throw new Error(ee[i])}function ue(e,t){const i=new he(t);if(i.push(e),i.err)throw i.msg||ee[i.err];return i.result}he.prototype.push=function(e,t){const i=this.strm,n=this.options.chunkSize,a=this.options.dictionary;let r,o,s;if(this.ended)return !1;for(o=t===~~t?t:!0===t?re:ae,"[object ArrayBuffer]"===ne.call(e)?i.input=new Uint8Array(e):i.input=e,i.next_in=0,i.avail_in=i.input.length;;){for(0===i.avail_out&&(i.output=new Uint8Array(n),i.next_out=0,i.avail_out=n),r=Y.inflate(i,o),r===le&&a&&(r=Y.inflateSetDictionary(i,a),r===oe?r=Y.inflate(i,o):r===fe&&(r=le));i.avail_in>0&&r===se&&i.state.wrap>0&&0!==e[i.next_in];)Y.inflateReset(i),r=Y.inflate(i,o);switch(r){case de:case fe:case le:case ce:return this.onEnd(r),this.ended=!0,!1}if(s=i.avail_out,i.next_out&&(0===i.avail_out||r===se))if("string"===this.options.to){let e=$(i.output,i.next_out),t=i.next_out-e,a=V(i.output,e);i.next_out=t,i.avail_out=n-t,t&&i.output.set(i.output.subarray(e,e+t),0),this.onData(a);}else this.onData(i.output.length===i.next_out?i.output:i.output.subarray(0,i.next_out));if(r!==oe||0!==s){if(r===se)return r=Y.inflateEnd(this.strm),this.onEnd(r),this.ended=!0,!0;if(0===i.avail_in)break}}return !0},he.prototype.onData=function(e){this.chunks.push(e);},he.prototype.onEnd=function(e){e===oe&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=W(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg;};var we=he,be=ue,me=function(e,t){return (t=t||{}).raw=!0,ue(e,t)},ke=ue,_e=h,ge={Inflate:we,inflate:be,inflateRaw:me,ungzip:ke,constants:_e};e.Inflate=we,e.constants=_e,e.default=ge,e.inflate=be,e.inflateRaw=me,e.ungzip=ke,Object.defineProperty(e,"__esModule",{value:!0});})); 22 | } (pako_inflate_min, pako_inflate_min.exports)); 23 | 24 | var pako_inflate_minExports = pako_inflate_min.exports; 25 | 26 | const LITTLE_ENDIAN = true; 27 | 28 | class DataReader { 29 | 30 | /** @param {ArrayBuffer} buffer */ 31 | constructor( buffer ) { 32 | 33 | this.dataView = new DataView( buffer ); 34 | this.position = 0; 35 | 36 | } 37 | 38 | /** @param {number} length */ 39 | skip( length ) { 40 | 41 | this.position += length; 42 | 43 | } 44 | 45 | /** @param {number} length */ 46 | readBytes( length ) { 47 | 48 | const type = length === 4 ? 'getUint32' : 49 | length === 2 ? 'getUint16' : 50 | 'getUint8'; 51 | const start = this.position; 52 | this.position += length; 53 | return this.dataView[ type ]( start, LITTLE_ENDIAN ); 54 | 55 | } 56 | 57 | } 58 | 59 | const LOCAL_FILE_HEADER = 0x04034b50; 60 | const CENTRAL_DIRECTORY = 0x02014b50; 61 | // const END_OF_CENTRAL_DIRECTORY = 0x06054b50; 62 | 63 | const parseZip = ( buffer ) => { 64 | 65 | const reader = new DataReader( buffer ); 66 | const files = {}; 67 | 68 | while ( true ) { 69 | 70 | const signature = reader.readBytes( 4 ); 71 | 72 | if ( signature === LOCAL_FILE_HEADER ) { 73 | 74 | const file = parseLocalFile( reader ); 75 | files[ file.name ] = { buffer: file.buffer }; 76 | continue; 77 | 78 | } 79 | 80 | if ( signature === CENTRAL_DIRECTORY ) { 81 | 82 | parseCentralDirectory( reader ); 83 | continue; 84 | 85 | } 86 | 87 | break; 88 | 89 | } 90 | 91 | return files; 92 | 93 | }; 94 | 95 | // # Local file header 96 | // 97 | // | Offset | Length | Contents | 98 | // | ------ | -------- | ---------------------------------------- | 99 | // | 0 | 4 bytes | Local file header signature (0x04034b50) | 100 | // | 4 | 2 bytes | Version needed to extract | 101 | // | 6 | 2 bytes | General purpose bit flag | 102 | // | 8 | 2 bytes | Compression method | 103 | // | 10 | 2 bytes | Last mod file time | 104 | // | 12 | 2 bytes | Last mod file date | 105 | // | 14 | 4 bytes | CRC-32 | 106 | // | 18 | 4 bytes | Compressed size (n) | 107 | // | 22 | 4 bytes | Uncompressed size | 108 | // | 26 | 2 bytes | Filename length (f) | 109 | // | 28 | 2 bytes | Extra field length (e) | 110 | // | | (f)bytes | Filename | 111 | // | | (e)bytes | Extra field | 112 | // | | (n)bytes | Compressed data | 113 | const parseLocalFile = ( reader ) => { 114 | 115 | let i = 0; 116 | let data; 117 | reader.skip( 4 ); 118 | // const version = reader.readBytes( 2 ); 119 | // const bitFlag = reader.readBytes( 2 ); 120 | const compression = reader.readBytes( 2 ); 121 | reader.skip( 8 ); 122 | // const lastModTime = reader.readBytes( 2 ); 123 | // const lastModDate = reader.readBytes( 2 ); 124 | // const crc32 = reader.readBytes( 4 ); 125 | const compressedSize = reader.readBytes( 4 ); 126 | reader.skip( 4 ); 127 | // const uncompressedSize = reader.readBytes( 4 ); 128 | const filenameLength = reader.readBytes( 2 ); 129 | const extraFieldLength = reader.readBytes( 2 ); 130 | const filename = []; 131 | // const extraField = []; 132 | const compressedData = new Uint8Array( compressedSize ); 133 | 134 | for ( i = 0; i < filenameLength; i ++ ) { 135 | 136 | filename.push( String.fromCharCode( reader.readBytes( 1 ) ) ); 137 | 138 | } 139 | 140 | reader.skip( extraFieldLength ); 141 | // for ( i = 0; i < extraFieldLength; i ++ ) { 142 | 143 | // extraField.push( reader.readBytes( 1 ) ); 144 | 145 | // } 146 | 147 | for ( i = 0; i < compressedSize; i ++ ) { 148 | 149 | compressedData[ i ] = reader.readBytes( 1 ); 150 | 151 | } 152 | 153 | switch ( compression ) { 154 | 155 | case 0: 156 | data = compressedData; 157 | break; 158 | case 8: 159 | data = new Uint8Array( pako_inflate_minExports.inflate( compressedData, { raw: true } ) ); 160 | break; 161 | default: 162 | console.log( `${ filename.join( '' ) }: unsupported compression type` ); 163 | data = compressedData; 164 | 165 | } 166 | 167 | return { 168 | name: filename.join( '' ), 169 | buffer: data 170 | }; 171 | 172 | }; 173 | 174 | // # Central directory 175 | // 176 | // | Offset | Length | Contents | 177 | // | ------ | -------- | ------------------------------------------ | 178 | // | 0 | 4 bytes | Central file header signature (0x02014b50) | 179 | // | 4 | 2 bytes | Version made by | 180 | // | 6 | 2 bytes | Version needed to extract | 181 | // | 8 | 2 bytes | General purpose bit flag | 182 | // | 10 | 2 bytes | Compression method | 183 | // | 12 | 2 bytes | Last mod file time | 184 | // | 14 | 2 bytes | Last mod file date | 185 | // | 16 | 4 bytes | CRC-32 | 186 | // | 20 | 4 bytes | Compressed size | 187 | // | 24 | 4 bytes | Uncompressed size | 188 | // | 28 | 2 bytes | Filename length (f) | 189 | // | 30 | 2 bytes | Extra field length (e) | 190 | // | 32 | 2 bytes | File comment length (c) | 191 | // | 34 | 2 bytes | Disk number start | 192 | // | 36 | 2 bytes | Internal file attributes | 193 | // | 38 | 4 bytes | External file attributes | 194 | // | 42 | 4 bytes | Relative offset of local header | 195 | // | 46 | (f)bytes | Filename | 196 | // | | (e)bytes | Extra field | 197 | // | | (c)bytes | File comment | 198 | const parseCentralDirectory = ( reader ) => { 199 | 200 | // let i = 0; 201 | reader.skip( 24 ); 202 | // const versionMadeby = reader.readBytes( 2 ); 203 | // const versionNeedToExtract = reader.readBytes( 2 ); 204 | // const bitFlag = reader.readBytes( 2 ); 205 | // const compression = reader.readBytes( 2 ); 206 | // const lastModTime = reader.readBytes( 2 ); 207 | // const lastModDate = reader.readBytes( 2 ); 208 | // const crc32 = reader.readBytes( 4 ); 209 | // const compressedSize = reader.readBytes( 4 ); 210 | // const uncompressedSize = reader.readBytes( 4 ); 211 | const filenameLength = reader.readBytes( 2 ); 212 | const extraFieldLength = reader.readBytes( 2 ); 213 | const fileCommentLength = reader.readBytes( 2 ); 214 | reader.skip( 12 ); 215 | // const diskNumberStart = reader.readBytes( 2 ); 216 | // const internalFileAttrs = reader.readBytes( 2 ); 217 | // const externalFileAttrs = reader.readBytes( 4 ); 218 | // const relativeOffset = reader.readBytes( 4 ); 219 | // const filename = []; 220 | // const extraField = []; 221 | // const fileComment = []; 222 | 223 | reader.skip( filenameLength ); 224 | // for ( i = 0; i < filenameLength; i ++ ) { 225 | 226 | // filename.push( String.fromCharCode( reader.readBytes( 1 ) ) ); 227 | 228 | // } 229 | 230 | reader.skip( extraFieldLength ); 231 | // for ( i = 0; i < extraFieldLength; i ++ ) { 232 | 233 | // extraField.push( reader.readBytes( 1 ) ); 234 | 235 | // } 236 | 237 | reader.skip( fileCommentLength ); 238 | // for ( i = 0; i < fileCommentLength; i ++ ) { 239 | 240 | // fileComment.push( reader.readBytes( 1 ) ); 241 | 242 | // } 243 | 244 | }; 245 | 246 | /** 247 | * @class ZipLoader 248 | * @classdesc A class for loading and extracting files from a ZIP archive. 249 | */ 250 | const ZipLoader = class ZipLoader { 251 | 252 | /** 253 | * @function 254 | * @description Loads a zip archive from a File or Blob object and returns a Promise that resolves with a new ZipLoader instance 255 | * @param {Blob|File} blobOrFile - The Blob or File object to load 256 | * @returns {Promise} 257 | */ 258 | static unzip( blobOrFile ) { 259 | 260 | return new Promise( ( resolve ) => { 261 | 262 | const instance = new ZipLoader(); 263 | const fileReader = new FileReader(); 264 | 265 | fileReader.onload = ( event ) => { 266 | 267 | const arrayBuffer = event.target.result; 268 | instance.files = parseZip( arrayBuffer ); 269 | resolve( instance ); 270 | 271 | }; 272 | 273 | if ( blobOrFile instanceof Blob ) { 274 | 275 | fileReader.readAsArrayBuffer( blobOrFile ); 276 | 277 | } 278 | 279 | } ); 280 | 281 | } 282 | 283 | /** 284 | * @constructor 285 | * @param {string} url 286 | * @param {RequestInit} fetchOptions 287 | */ 288 | constructor( url, fetchOptions = {} ) { 289 | 290 | /** @private */ 291 | this._listeners = {}; 292 | 293 | /** @type {String|undefined} */ 294 | this.url = url; 295 | 296 | /** @type {RequestInit} */ 297 | this.fetchOptions = fetchOptions; 298 | 299 | /** @type {import('./types.ts').Files | null} */ 300 | this.files = null; 301 | 302 | } 303 | 304 | /** 305 | * Loads the ZIP archive specified by the url property. 306 | * Returns a Promise that resolves when the ZIP archive has been loaded and extracted. 307 | * 308 | * @async 309 | * @returns {Promise} A Promise that resolves when the ZIP archive has been loaded and extracted. 310 | */ 311 | async load() { 312 | 313 | this.clear(); 314 | 315 | const startTime = Date.now(); 316 | const res = await fetch( this.url, this.fetchOptions ).then( ( res ) => { 317 | 318 | const that = this; 319 | const total = parseInt( res.headers.get( 'content-length' ), 10 ); 320 | let loaded = 0; 321 | 322 | return new Response( new ReadableStream( { 323 | start( controller ) { 324 | const reader = res.body.getReader(); 325 | 326 | const pump = async () => { 327 | const { done, value } = await reader.read(); 328 | if ( done ) { 329 | 330 | controller.close(); 331 | return; 332 | 333 | } 334 | loaded += value.byteLength; 335 | controller.enqueue( value ); 336 | that.dispatch( { 337 | type: 'progress', 338 | loaded, 339 | total, 340 | elapsedTime: Date.now() - startTime, 341 | } ); 342 | pump(); 343 | }; 344 | pump(); 345 | } 346 | } ) ); 347 | 348 | } ).catch( ( error ) => { 349 | 350 | this.dispatch( { 351 | type: 'error', 352 | error 353 | } ); 354 | 355 | } ); 356 | 357 | const arrayBuffer = await res.arrayBuffer(); 358 | this.files = parseZip( arrayBuffer ); 359 | this.dispatch( { 360 | type: 'load', 361 | elapsedTime: Date.now() - startTime, 362 | } ); 363 | 364 | return this.files; 365 | 366 | } 367 | 368 | /** 369 | * Extracts a file from the loaded ZIP archive and returns it as a Blob URL. 370 | * 371 | * @param {string} filename - The name of the file to extract. 372 | * @param {string} type - The MIME type of the file. 373 | * @returns {string} The Blob URL of the extracted file. 374 | */ 375 | extractAsBlobUrl( filename, type ) { 376 | 377 | if ( this.files[ filename ].url ) { 378 | 379 | return this.files[ filename ].url; 380 | 381 | } 382 | 383 | const blob = new Blob( [ this.files[ filename ].buffer ], { type: type } ); 384 | this.files[ filename ].url = URL.createObjectURL( blob ); 385 | return this.files[ filename ].url; 386 | 387 | } 388 | 389 | /** 390 | * @param {string} filename 391 | * @returns {string|undefined} 392 | */ 393 | extractAsText( filename ) { 394 | 395 | const buffer = this.files[ filename ].buffer; 396 | 397 | if ( typeof TextDecoder !== 'undefined' ) { 398 | 399 | return new TextDecoder().decode( buffer ); 400 | 401 | } 402 | 403 | let str = ''; 404 | 405 | for ( let i = 0, l = buffer.length; i < l; i ++ ) { 406 | 407 | str += String.fromCharCode( buffer[ i ] ); 408 | 409 | } 410 | 411 | return decodeURIComponent( escape( str ) ); 412 | 413 | } 414 | 415 | /** 416 | * @param {string} filename 417 | * @returns {*} 418 | */ 419 | extractAsJSON( filename ) { 420 | 421 | return JSON.parse( this.extractAsText( filename ) ); 422 | 423 | } 424 | 425 | /** 426 | * Adds the specified event listener. 427 | * @param {string} type event name 428 | * @param {import('./types.ts').Listener} listener handler function 429 | */ 430 | on( type, listener ) { 431 | 432 | if ( ! this._listeners[ type ] ) { 433 | 434 | this._listeners[ type ] = []; 435 | 436 | } 437 | 438 | if ( this._listeners[ type ].indexOf( listener ) === - 1 ) { 439 | 440 | this._listeners[ type ].push( listener ); 441 | 442 | } 443 | 444 | } 445 | 446 | /** 447 | * Removes the specified event listener 448 | * @param {string} type event name 449 | * @param {import('./types.ts').Listener} listener handler function 450 | */ 451 | off( type, listener ) { 452 | 453 | const listenerArray = this._listeners[ type ]; 454 | 455 | if ( !! listenerArray ) { 456 | 457 | const index = listenerArray.indexOf( listener ); 458 | 459 | if ( index !== - 1 ) { 460 | 461 | listenerArray.splice( index, 1 ); 462 | 463 | } 464 | 465 | } 466 | 467 | } 468 | 469 | dispatch( event ) { 470 | 471 | const listenerArray = this._listeners[ event.type ]; 472 | 473 | if ( !! listenerArray ) { 474 | 475 | event.target = this; 476 | const length = listenerArray.length; 477 | 478 | for ( let i = 0; i < length; i ++ ) { 479 | 480 | listenerArray[ i ].call( this, event ); 481 | 482 | } 483 | 484 | } 485 | 486 | } 487 | 488 | /** @param {string=} filename */ 489 | clear( filename ) { 490 | 491 | if ( !! filename ) { 492 | 493 | URL.revokeObjectURL( this.files[ filename ].url ); 494 | delete this.files[ filename ]; 495 | return; 496 | 497 | } 498 | 499 | for ( let key in this.files ) { 500 | 501 | URL.revokeObjectURL( this.files[ key ].url ); 502 | 503 | } 504 | 505 | this.files = null; 506 | 507 | } 508 | 509 | }; 510 | 511 | return ZipLoader; 512 | 513 | })); 514 | -------------------------------------------------------------------------------- /dist/zip-loader.min.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * zip-loader 3 | * https://github.com/yomotsu/ZipLoader 4 | * (c) 2017 @yomotsu 5 | * Released under the MIT License. 6 | * ZipLoader uses pako, released under the MIT license. 7 | */ 8 | (function(global,factory){typeof exports==="object"&&typeof module!=="undefined"?module.exports=factory():typeof define==="function"&&define.amd?define(factory):(global=typeof globalThis!=="undefined"?globalThis:global||self,global.ZipLoader=factory())})(this,(function(){"use strict";var commonjsGlobal=typeof globalThis!=="undefined"?globalThis:typeof window!=="undefined"?window:typeof global!=="undefined"?global:typeof self!=="undefined"?self:{};var pako_inflate_min={exports:{}}; 9 | /*! pako 2.1.0 https://github.com/nodeca/pako @license (MIT AND Zlib) */(function(module,exports){!function(e,t){t(exports)}(commonjsGlobal,(function(e){var t=(e,t,i,n)=>{let a=65535&e|0,r=e>>>16&65535|0,o=0;for(;0!==i;){o=i>2e3?2e3:i,i-=o;do{a=a+t[n++]|0,r=r+a|0}while(--o);a%=65521,r%=65521}return a|r<<16|0};const i=new Uint32Array((()=>{let e,t=[];for(var i=0;i<256;i++){e=i;for(var n=0;n<8;n++)e=1&e?3988292384^e>>>1:e>>>1;t[i]=e}return t})());var n=(e,t,n,a)=>{const r=i,o=a+n;e^=-1;for(let i=a;i>>8^r[255&(e^t[i])];return-1^e};const a=16209;var r=function(e,t){let i,n,r,o,s,l,d,f,c,h,u,w,b,m,k,_,g,p,v,x,y,E,R,A;const Z=e.state;i=e.next_in,R=e.input,n=i+(e.avail_in-5),r=e.next_out,A=e.output,o=r-(t-e.avail_out),s=r+(e.avail_out-257),l=Z.dmax,d=Z.wsize,f=Z.whave,c=Z.wnext,h=Z.window,u=Z.hold,w=Z.bits,b=Z.lencode,m=Z.distcode,k=(1<>>24,u>>>=p,w-=p,p=g>>>16&255,0===p)A[r++]=65535&g;else{if(!(16&p)){if(0==(64&p)){g=b[(65535&g)+(u&(1<>>=p,w-=p),w<15&&(u+=R[i++]<>>24,u>>>=p,w-=p,p=g>>>16&255,!(16&p)){if(0==(64&p)){g=m[(65535&g)+(u&(1<l){e.msg="invalid distance too far back",Z.mode=a;break e}if(u>>>=p,w-=p,p=r-o,x>p){if(p=x-p,p>f&&Z.sane){e.msg="invalid distance too far back",Z.mode=a;break e}if(y=0,E=h,0===c){if(y+=d-p,p2;)A[r++]=E[y++],A[r++]=E[y++],A[r++]=E[y++],v-=3;v&&(A[r++]=E[y++],v>1&&(A[r++]=E[y++]))}else{y=r-x;do{A[r++]=A[y++],A[r++]=A[y++],A[r++]=A[y++],v-=3}while(v>2);v&&(A[r++]=A[y++],v>1&&(A[r++]=A[y++]))}break}}break}}while(i>3,i-=v,w-=v<<3,u&=(1<{const u=h.bits;let w,b,m,k,_,g,p=0,v=0,x=0,y=0,E=0,R=0,A=0,Z=0,S=0,T=0,O=null;const U=new Uint16Array(16),D=new Uint16Array(16);let I,B,N,C=null;for(p=0;p<=o;p++)U[p]=0;for(v=0;v=1&&0===U[y];y--);if(E>y&&(E=y),0===y)return a[r++]=20971520,a[r++]=20971520,h.bits=1,0;for(x=1;x0&&(0===e||1!==y))return-1;for(D[1]=0,p=1;p852||2===e&&S>592)return 1;for(;;){I=p-A,c[v]+1=g?(B=C[c[v]-g],N=O[c[v]-g]):(B=96,N=0),w=1<>A)+b]=I<<24|B<<16|N|0}while(0!==b);for(w=1<>=1;if(0!==w?(T&=w-1,T+=w):T=0,v++,0==--U[p]){if(p===y)break;p=t[i+c[v]]}if(p>E&&(T&k)!==m){for(0===A&&(A=E),_+=x,R=p-A,Z=1<852||2===e&&S>592)return 1;m=T&k,a[m]=E<<24|R<<16|_-r|0}}return 0!==T&&(a[_+T]=p-A<<24|64<<16|0),h.bits=E,0},h={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8};const{Z_FINISH:u,Z_BLOCK:w,Z_TREES:b,Z_OK:m,Z_STREAM_END:k,Z_NEED_DICT:_,Z_STREAM_ERROR:g,Z_DATA_ERROR:p,Z_MEM_ERROR:v,Z_BUF_ERROR:x,Z_DEFLATED:y}=h,E=16180,R=16190,A=16191,Z=16192,S=16194,T=16199,O=16200,U=16206,D=16209,I=e=>(e>>>24&255)+(e>>>8&65280)+((65280&e)<<8)+((255&e)<<24);function B(){this.strm=null,this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}const N=e=>{if(!e)return 1;const t=e.state;return!t||t.strm!==e||t.mode16211?1:0},C=e=>{if(N(e))return g;const t=e.state;return e.total_in=e.total_out=t.total=0,e.msg="",t.wrap&&(e.adler=1&t.wrap),t.mode=E,t.last=0,t.havedict=0,t.flags=-1,t.dmax=32768,t.head=null,t.hold=0,t.bits=0,t.lencode=t.lendyn=new Int32Array(852),t.distcode=t.distdyn=new Int32Array(592),t.sane=1,t.back=-1,m},z=e=>{if(N(e))return g;const t=e.state;return t.wsize=0,t.whave=0,t.wnext=0,C(e)},F=(e,t)=>{let i;if(N(e))return g;const n=e.state;return t<0?(i=0,t=-t):(i=5+(t>>4),t<48&&(t&=15)),t&&(t<8||t>15)?g:(null!==n.window&&n.wbits!==t&&(n.window=null),n.wrap=i,n.wbits=t,z(e))},L=(e,t)=>{if(!e)return g;const i=new B;e.state=i,i.strm=e,i.window=null,i.mode=E;const n=F(e,t);return n!==m&&(e.state=null),n};let M,H,j=!0;const K=e=>{if(j){M=new Int32Array(512),H=new Int32Array(32);let t=0;for(;t<144;)e.lens[t++]=8;for(;t<256;)e.lens[t++]=9;for(;t<280;)e.lens[t++]=7;for(;t<288;)e.lens[t++]=8;for(c(1,e.lens,0,288,M,0,e.work,{bits:9}),t=0;t<32;)e.lens[t++]=5;c(2,e.lens,0,32,H,0,e.work,{bits:5}),j=!1}e.lencode=M,e.lenbits=9,e.distcode=H,e.distbits=5},P=(e,t,i,n)=>{let a;const r=e.state;return null===r.window&&(r.wsize=1<=r.wsize?(r.window.set(t.subarray(i-r.wsize,i),0),r.wnext=0,r.whave=r.wsize):(a=r.wsize-r.wnext,a>n&&(a=n),r.window.set(t.subarray(i-n,i-n+a),r.wnext),(n-=a)?(r.window.set(t.subarray(i-n,i),0),r.wnext=n,r.whave=r.wsize):(r.wnext+=a,r.wnext===r.wsize&&(r.wnext=0),r.whaveL(e,15),inflateInit2:L,inflate:(e,i)=>{let a,o,s,l,d,f,h,B,C,z,F,L,M,H,j,Y,G,X,W,q,J,Q,V=0;const $=new Uint8Array(4);let ee,te;const ie=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(N(e)||!e.output||!e.input&&0!==e.avail_in)return g;a=e.state,a.mode===A&&(a.mode=Z),d=e.next_out,s=e.output,h=e.avail_out,l=e.next_in,o=e.input,f=e.avail_in,B=a.hold,C=a.bits,z=f,F=h,Q=m;e:for(;;)switch(a.mode){case E:if(0===a.wrap){a.mode=Z;break}for(;C<16;){if(0===f)break e;f--,B+=o[l++]<>>8&255,a.check=n(a.check,$,2,0),B=0,C=0,a.mode=16181;break}if(a.head&&(a.head.done=!1),!(1&a.wrap)||(((255&B)<<8)+(B>>8))%31){e.msg="incorrect header check",a.mode=D;break}if((15&B)!==y){e.msg="unknown compression method",a.mode=D;break}if(B>>>=4,C-=4,J=8+(15&B),0===a.wbits&&(a.wbits=J),J>15||J>a.wbits){e.msg="invalid window size",a.mode=D;break}a.dmax=1<>8&1),512&a.flags&&4&a.wrap&&($[0]=255&B,$[1]=B>>>8&255,a.check=n(a.check,$,2,0)),B=0,C=0,a.mode=16182;case 16182:for(;C<32;){if(0===f)break e;f--,B+=o[l++]<>>8&255,$[2]=B>>>16&255,$[3]=B>>>24&255,a.check=n(a.check,$,4,0)),B=0,C=0,a.mode=16183;case 16183:for(;C<16;){if(0===f)break e;f--,B+=o[l++]<>8),512&a.flags&&4&a.wrap&&($[0]=255&B,$[1]=B>>>8&255,a.check=n(a.check,$,2,0)),B=0,C=0,a.mode=16184;case 16184:if(1024&a.flags){for(;C<16;){if(0===f)break e;f--,B+=o[l++]<>>8&255,a.check=n(a.check,$,2,0)),B=0,C=0}else a.head&&(a.head.extra=null);a.mode=16185;case 16185:if(1024&a.flags&&(L=a.length,L>f&&(L=f),L&&(a.head&&(J=a.head.extra_len-a.length,a.head.extra||(a.head.extra=new Uint8Array(a.head.extra_len)),a.head.extra.set(o.subarray(l,l+L),J)),512&a.flags&&4&a.wrap&&(a.check=n(a.check,o,L,l)),f-=L,l+=L,a.length-=L),a.length))break e;a.length=0,a.mode=16186;case 16186:if(2048&a.flags){if(0===f)break e;L=0;do{J=o[l+L++],a.head&&J&&a.length<65536&&(a.head.name+=String.fromCharCode(J))}while(J&&L>9&1,a.head.done=!0),e.adler=a.check=0,a.mode=A;break;case 16189:for(;C<32;){if(0===f)break e;f--,B+=o[l++]<>>=7&C,C-=7&C,a.mode=U;break}for(;C<3;){if(0===f)break e;f--,B+=o[l++]<>>=1,C-=1,3&B){case 0:a.mode=16193;break;case 1:if(K(a),a.mode=T,i===b){B>>>=2,C-=2;break e}break;case 2:a.mode=16196;break;case 3:e.msg="invalid block type",a.mode=D}B>>>=2,C-=2;break;case 16193:for(B>>>=7&C,C-=7&C;C<32;){if(0===f)break e;f--,B+=o[l++]<>>16^65535)){e.msg="invalid stored block lengths",a.mode=D;break}if(a.length=65535&B,B=0,C=0,a.mode=S,i===b)break e;case S:a.mode=16195;case 16195:if(L=a.length,L){if(L>f&&(L=f),L>h&&(L=h),0===L)break e;s.set(o.subarray(l,l+L),d),f-=L,l+=L,h-=L,d+=L,a.length-=L;break}a.mode=A;break;case 16196:for(;C<14;){if(0===f)break e;f--,B+=o[l++]<>>=5,C-=5,a.ndist=1+(31&B),B>>>=5,C-=5,a.ncode=4+(15&B),B>>>=4,C-=4,a.nlen>286||a.ndist>30){e.msg="too many length or distance symbols",a.mode=D;break}a.have=0,a.mode=16197;case 16197:for(;a.have>>=3,C-=3}for(;a.have<19;)a.lens[ie[a.have++]]=0;if(a.lencode=a.lendyn,a.lenbits=7,ee={bits:a.lenbits},Q=c(0,a.lens,0,19,a.lencode,0,a.work,ee),a.lenbits=ee.bits,Q){e.msg="invalid code lengths set",a.mode=D;break}a.have=0,a.mode=16198;case 16198:for(;a.have>>24,Y=V>>>16&255,G=65535&V,!(j<=C);){if(0===f)break e;f--,B+=o[l++]<>>=j,C-=j,a.lens[a.have++]=G;else{if(16===G){for(te=j+2;C>>=j,C-=j,0===a.have){e.msg="invalid bit length repeat",a.mode=D;break}J=a.lens[a.have-1],L=3+(3&B),B>>>=2,C-=2}else if(17===G){for(te=j+3;C>>=j,C-=j,J=0,L=3+(7&B),B>>>=3,C-=3}else{for(te=j+7;C>>=j,C-=j,J=0,L=11+(127&B),B>>>=7,C-=7}if(a.have+L>a.nlen+a.ndist){e.msg="invalid bit length repeat",a.mode=D;break}for(;L--;)a.lens[a.have++]=J}}if(a.mode===D)break;if(0===a.lens[256]){e.msg="invalid code -- missing end-of-block",a.mode=D;break}if(a.lenbits=9,ee={bits:a.lenbits},Q=c(1,a.lens,0,a.nlen,a.lencode,0,a.work,ee),a.lenbits=ee.bits,Q){e.msg="invalid literal/lengths set",a.mode=D;break}if(a.distbits=6,a.distcode=a.distdyn,ee={bits:a.distbits},Q=c(2,a.lens,a.nlen,a.ndist,a.distcode,0,a.work,ee),a.distbits=ee.bits,Q){e.msg="invalid distances set",a.mode=D;break}if(a.mode=T,i===b)break e;case T:a.mode=O;case O:if(f>=6&&h>=258){e.next_out=d,e.avail_out=h,e.next_in=l,e.avail_in=f,a.hold=B,a.bits=C,r(e,F),d=e.next_out,s=e.output,h=e.avail_out,l=e.next_in,o=e.input,f=e.avail_in,B=a.hold,C=a.bits,a.mode===A&&(a.back=-1);break}for(a.back=0;V=a.lencode[B&(1<>>24,Y=V>>>16&255,G=65535&V,!(j<=C);){if(0===f)break e;f--,B+=o[l++]<>X)],j=V>>>24,Y=V>>>16&255,G=65535&V,!(X+j<=C);){if(0===f)break e;f--,B+=o[l++]<>>=X,C-=X,a.back+=X}if(B>>>=j,C-=j,a.back+=j,a.length=G,0===Y){a.mode=16205;break}if(32&Y){a.back=-1,a.mode=A;break}if(64&Y){e.msg="invalid literal/length code",a.mode=D;break}a.extra=15&Y,a.mode=16201;case 16201:if(a.extra){for(te=a.extra;C>>=a.extra,C-=a.extra,a.back+=a.extra}a.was=a.length,a.mode=16202;case 16202:for(;V=a.distcode[B&(1<>>24,Y=V>>>16&255,G=65535&V,!(j<=C);){if(0===f)break e;f--,B+=o[l++]<>X)],j=V>>>24,Y=V>>>16&255,G=65535&V,!(X+j<=C);){if(0===f)break e;f--,B+=o[l++]<>>=X,C-=X,a.back+=X}if(B>>>=j,C-=j,a.back+=j,64&Y){e.msg="invalid distance code",a.mode=D;break}a.offset=G,a.extra=15&Y,a.mode=16203;case 16203:if(a.extra){for(te=a.extra;C>>=a.extra,C-=a.extra,a.back+=a.extra}if(a.offset>a.dmax){e.msg="invalid distance too far back",a.mode=D;break}a.mode=16204;case 16204:if(0===h)break e;if(L=F-h,a.offset>L){if(L=a.offset-L,L>a.whave&&a.sane){e.msg="invalid distance too far back",a.mode=D;break}L>a.wnext?(L-=a.wnext,M=a.wsize-L):M=a.wnext-L,L>a.length&&(L=a.length),H=a.window}else H=s,M=d-a.offset,L=a.length;L>h&&(L=h),h-=L,a.length-=L;do{s[d++]=H[M++]}while(--L);0===a.length&&(a.mode=O);break;case 16205:if(0===h)break e;s[d++]=a.length,h--,a.mode=O;break;case U:if(a.wrap){for(;C<32;){if(0===f)break e;f--,B|=o[l++]<{if(N(e))return g;let t=e.state;return t.window&&(t.window=null),e.state=null,m},inflateGetHeader:(e,t)=>{if(N(e))return g;const i=e.state;return 0==(2&i.wrap)?g:(i.head=t,t.done=!1,m)},inflateSetDictionary:(e,i)=>{const n=i.length;let a,r,o;return N(e)?g:(a=e.state,0!==a.wrap&&a.mode!==R?g:a.mode===R&&(r=1,r=t(r,i,n,0),r!==a.check)?p:(o=P(e,i,n,n),o?(a.mode=16210,v):(a.havedict=1,m)))},inflateInfo:"pako inflate (from Nodeca project)"};const G=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var X=function(e){const t=Array.prototype.slice.call(arguments,1);for(;t.length;){const i=t.shift();if(i){if("object"!=typeof i)throw new TypeError(i+"must be non-object");for(const t in i)G(i,t)&&(e[t]=i[t])}}return e},W=e=>{let t=0;for(let i=0,n=e.length;i=252?6:e>=248?5:e>=240?4:e>=224?3:e>=192?2:1;J[254]=J[254]=1;var Q=e=>{if("function"==typeof TextEncoder&&TextEncoder.prototype.encode)return(new TextEncoder).encode(e);let t,i,n,a,r,o=e.length,s=0;for(a=0;a>>6,t[r++]=128|63&i):i<65536?(t[r++]=224|i>>>12,t[r++]=128|i>>>6&63,t[r++]=128|63&i):(t[r++]=240|i>>>18,t[r++]=128|i>>>12&63,t[r++]=128|i>>>6&63,t[r++]=128|63&i);return t},V=(e,t)=>{const i=t||e.length;if("function"==typeof TextDecoder&&TextDecoder.prototype.decode)return(new TextDecoder).decode(e.subarray(0,t));let n,a;const r=new Array(2*i);for(a=0,n=0;n4)r[a++]=65533,n+=o-1;else{for(t&=2===o?31:3===o?15:7;o>1&&n1?r[a++]=65533:t<65536?r[a++]=t:(t-=65536,r[a++]=55296|t>>10&1023,r[a++]=56320|1023&t)}}return((e,t)=>{if(t<65534&&e.subarray&&q)return String.fromCharCode.apply(null,e.length===t?e:e.subarray(0,t));let i="";for(let n=0;n{(t=t||e.length)>e.length&&(t=e.length);let i=t-1;for(;i>=0&&128==(192&e[i]);)i--;return i<0||0===i?t:i+J[e[i]]>t?i:t},ee={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"};var te=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0};var ie=function(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1};const ne=Object.prototype.toString,{Z_NO_FLUSH:ae,Z_FINISH:re,Z_OK:oe,Z_STREAM_END:se,Z_NEED_DICT:le,Z_STREAM_ERROR:de,Z_DATA_ERROR:fe,Z_MEM_ERROR:ce}=h;function he(e){this.options=X({chunkSize:65536,windowBits:15,to:""},e||{});const t=this.options;t.raw&&t.windowBits>=0&&t.windowBits<16&&(t.windowBits=-t.windowBits,0===t.windowBits&&(t.windowBits=-15)),!(t.windowBits>=0&&t.windowBits<16)||e&&e.windowBits||(t.windowBits+=32),t.windowBits>15&&t.windowBits<48&&0==(15&t.windowBits)&&(t.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new te,this.strm.avail_out=0;let i=Y.inflateInit2(this.strm,t.windowBits);if(i!==oe)throw new Error(ee[i]);if(this.header=new ie,Y.inflateGetHeader(this.strm,this.header),t.dictionary&&("string"==typeof t.dictionary?t.dictionary=Q(t.dictionary):"[object ArrayBuffer]"===ne.call(t.dictionary)&&(t.dictionary=new Uint8Array(t.dictionary)),t.raw&&(i=Y.inflateSetDictionary(this.strm,t.dictionary),i!==oe)))throw new Error(ee[i])}function ue(e,t){const i=new he(t);if(i.push(e),i.err)throw i.msg||ee[i.err];return i.result}he.prototype.push=function(e,t){const i=this.strm,n=this.options.chunkSize,a=this.options.dictionary;let r,o,s;if(this.ended)return!1;for(o=t===~~t?t:!0===t?re:ae,"[object ArrayBuffer]"===ne.call(e)?i.input=new Uint8Array(e):i.input=e,i.next_in=0,i.avail_in=i.input.length;;){for(0===i.avail_out&&(i.output=new Uint8Array(n),i.next_out=0,i.avail_out=n),r=Y.inflate(i,o),r===le&&a&&(r=Y.inflateSetDictionary(i,a),r===oe?r=Y.inflate(i,o):r===fe&&(r=le));i.avail_in>0&&r===se&&i.state.wrap>0&&0!==e[i.next_in];)Y.inflateReset(i),r=Y.inflate(i,o);switch(r){case de:case fe:case le:case ce:return this.onEnd(r),this.ended=!0,!1}if(s=i.avail_out,i.next_out&&(0===i.avail_out||r===se))if("string"===this.options.to){let e=$(i.output,i.next_out),t=i.next_out-e,a=V(i.output,e);i.next_out=t,i.avail_out=n-t,t&&i.output.set(i.output.subarray(e,e+t),0),this.onData(a)}else this.onData(i.output.length===i.next_out?i.output:i.output.subarray(0,i.next_out));if(r!==oe||0!==s){if(r===se)return r=Y.inflateEnd(this.strm),this.onEnd(r),this.ended=!0,!0;if(0===i.avail_in)break}}return!0},he.prototype.onData=function(e){this.chunks.push(e)},he.prototype.onEnd=function(e){e===oe&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=W(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};var we=he,be=ue,me=function(e,t){return(t=t||{}).raw=!0,ue(e,t)},ke=ue,_e=h,ge={Inflate:we,inflate:be,inflateRaw:me,ungzip:ke,constants:_e};e.Inflate=we,e.constants=_e,e.default=ge,e.inflate=be,e.inflateRaw=me,e.ungzip=ke,Object.defineProperty(e,"__esModule",{value:!0})}))})(pako_inflate_min,pako_inflate_min.exports);var pako_inflate_minExports=pako_inflate_min.exports;const LITTLE_ENDIAN=true;class DataReader{constructor(buffer){this.dataView=new DataView(buffer);this.position=0}skip(length){this.position+=length}readBytes(length){const type=length===4?"getUint32":length===2?"getUint16":"getUint8";const start=this.position;this.position+=length;return this.dataView[type](start,LITTLE_ENDIAN)}}const LOCAL_FILE_HEADER=67324752;const CENTRAL_DIRECTORY=33639248;const parseZip=buffer=>{const reader=new DataReader(buffer);const files={};while(true){const signature=reader.readBytes(4);if(signature===LOCAL_FILE_HEADER){const file=parseLocalFile(reader);files[file.name]={buffer:file.buffer};continue}if(signature===CENTRAL_DIRECTORY){parseCentralDirectory(reader);continue}break}return files};const parseLocalFile=reader=>{let i=0;let data;reader.skip(4);const compression=reader.readBytes(2);reader.skip(8);const compressedSize=reader.readBytes(4);reader.skip(4);const filenameLength=reader.readBytes(2);const extraFieldLength=reader.readBytes(2);const filename=[];const compressedData=new Uint8Array(compressedSize);for(i=0;i{reader.skip(24);const filenameLength=reader.readBytes(2);const extraFieldLength=reader.readBytes(2);const fileCommentLength=reader.readBytes(2);reader.skip(12);reader.skip(filenameLength);reader.skip(extraFieldLength);reader.skip(fileCommentLength)};const ZipLoader=class ZipLoader{static unzip(blobOrFile){return new Promise((resolve=>{const instance=new ZipLoader;const fileReader=new FileReader;fileReader.onload=event=>{const arrayBuffer=event.target.result;instance.files=parseZip(arrayBuffer);resolve(instance)};if(blobOrFile instanceof Blob){fileReader.readAsArrayBuffer(blobOrFile)}}))}constructor(url,fetchOptions={}){this._listeners={};this.url=url;this.fetchOptions=fetchOptions;this.files=null}async load(){this.clear();const startTime=Date.now();const res=await fetch(this.url,this.fetchOptions).then((res=>{const that=this;const total=parseInt(res.headers.get("content-length"),10);let loaded=0;return new Response(new ReadableStream({start(controller){const reader=res.body.getReader();const pump=async()=>{const{done:done,value:value}=await reader.read();if(done){controller.close();return}loaded+=value.byteLength;controller.enqueue(value);that.dispatch({type:"progress",loaded:loaded,total:total,elapsedTime:Date.now()-startTime});pump()};pump()}}))})).catch((error=>{this.dispatch({type:"error",error:error})}));const arrayBuffer=await res.arrayBuffer();this.files=parseZip(arrayBuffer);this.dispatch({type:"load",elapsedTime:Date.now()-startTime});return this.files}extractAsBlobUrl(filename,type){if(this.files[filename].url){return this.files[filename].url}const blob=new Blob([this.files[filename].buffer],{type:type});this.files[filename].url=URL.createObjectURL(blob);return this.files[filename].url}extractAsText(filename){const buffer=this.files[filename].buffer;if(typeof TextDecoder!=="undefined"){return(new TextDecoder).decode(buffer)}let str="";for(let i=0,l=buffer.length;i{let a=65535&e|0,r=e>>>16&65535|0,o=0;for(;0!==i;){o=i>2e3?2e3:i,i-=o;do{a=a+t[n++]|0,r=r+a|0;}while(--o);a%=65521,r%=65521;}return a|r<<16|0};const i=new Uint32Array((()=>{let e,t=[];for(var i=0;i<256;i++){e=i;for(var n=0;n<8;n++)e=1&e?3988292384^e>>>1:e>>>1;t[i]=e;}return t})());var n=(e,t,n,a)=>{const r=i,o=a+n;e^=-1;for(let i=a;i>>8^r[255&(e^t[i])];return -1^e};const a=16209;var r=function(e,t){let i,n,r,o,s,l,d,f,c,h,u,w,b,m,k,_,g,p,v,x,y,E,R,A;const Z=e.state;i=e.next_in,R=e.input,n=i+(e.avail_in-5),r=e.next_out,A=e.output,o=r-(t-e.avail_out),s=r+(e.avail_out-257),l=Z.dmax,d=Z.wsize,f=Z.whave,c=Z.wnext,h=Z.window,u=Z.hold,w=Z.bits,b=Z.lencode,m=Z.distcode,k=(1<>>24,u>>>=p,w-=p,p=g>>>16&255,0===p)A[r++]=65535&g;else {if(!(16&p)){if(0==(64&p)){g=b[(65535&g)+(u&(1<>>=p,w-=p),w<15&&(u+=R[i++]<>>24,u>>>=p,w-=p,p=g>>>16&255,!(16&p)){if(0==(64&p)){g=m[(65535&g)+(u&(1<l){e.msg="invalid distance too far back",Z.mode=a;break e}if(u>>>=p,w-=p,p=r-o,x>p){if(p=x-p,p>f&&Z.sane){e.msg="invalid distance too far back",Z.mode=a;break e}if(y=0,E=h,0===c){if(y+=d-p,p2;)A[r++]=E[y++],A[r++]=E[y++],A[r++]=E[y++],v-=3;v&&(A[r++]=E[y++],v>1&&(A[r++]=E[y++]));}else {y=r-x;do{A[r++]=A[y++],A[r++]=A[y++],A[r++]=A[y++],v-=3;}while(v>2);v&&(A[r++]=A[y++],v>1&&(A[r++]=A[y++]));}break}}break}}while(i>3,i-=v,w-=v<<3,u&=(1<{const u=h.bits;let w,b,m,k,_,g,p=0,v=0,x=0,y=0,E=0,R=0,A=0,Z=0,S=0,T=0,O=null;const U=new Uint16Array(16),D=new Uint16Array(16);let I,B,N,C=null;for(p=0;p<=o;p++)U[p]=0;for(v=0;v=1&&0===U[y];y--);if(E>y&&(E=y),0===y)return a[r++]=20971520,a[r++]=20971520,h.bits=1,0;for(x=1;x0&&(0===e||1!==y))return -1;for(D[1]=0,p=1;p852||2===e&&S>592)return 1;for(;;){I=p-A,c[v]+1=g?(B=C[c[v]-g],N=O[c[v]-g]):(B=96,N=0),w=1<>A)+b]=I<<24|B<<16|N|0;}while(0!==b);for(w=1<>=1;if(0!==w?(T&=w-1,T+=w):T=0,v++,0==--U[p]){if(p===y)break;p=t[i+c[v]];}if(p>E&&(T&k)!==m){for(0===A&&(A=E),_+=x,R=p-A,Z=1<852||2===e&&S>592)return 1;m=T&k,a[m]=E<<24|R<<16|_-r|0;}}return 0!==T&&(a[_+T]=p-A<<24|64<<16|0),h.bits=E,0},h={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8};const{Z_FINISH:u,Z_BLOCK:w,Z_TREES:b,Z_OK:m,Z_STREAM_END:k,Z_NEED_DICT:_,Z_STREAM_ERROR:g,Z_DATA_ERROR:p,Z_MEM_ERROR:v,Z_BUF_ERROR:x,Z_DEFLATED:y}=h,E=16180,R=16190,A=16191,Z=16192,S=16194,T=16199,O=16200,U=16206,D=16209,I=e=>(e>>>24&255)+(e>>>8&65280)+((65280&e)<<8)+((255&e)<<24);function B(){this.strm=null,this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0;}const N=e=>{if(!e)return 1;const t=e.state;return !t||t.strm!==e||t.mode16211?1:0},C=e=>{if(N(e))return g;const t=e.state;return e.total_in=e.total_out=t.total=0,e.msg="",t.wrap&&(e.adler=1&t.wrap),t.mode=E,t.last=0,t.havedict=0,t.flags=-1,t.dmax=32768,t.head=null,t.hold=0,t.bits=0,t.lencode=t.lendyn=new Int32Array(852),t.distcode=t.distdyn=new Int32Array(592),t.sane=1,t.back=-1,m},z=e=>{if(N(e))return g;const t=e.state;return t.wsize=0,t.whave=0,t.wnext=0,C(e)},F=(e,t)=>{let i;if(N(e))return g;const n=e.state;return t<0?(i=0,t=-t):(i=5+(t>>4),t<48&&(t&=15)),t&&(t<8||t>15)?g:(null!==n.window&&n.wbits!==t&&(n.window=null),n.wrap=i,n.wbits=t,z(e))},L=(e,t)=>{if(!e)return g;const i=new B;e.state=i,i.strm=e,i.window=null,i.mode=E;const n=F(e,t);return n!==m&&(e.state=null),n};let M,H,j=!0;const K=e=>{if(j){M=new Int32Array(512),H=new Int32Array(32);let t=0;for(;t<144;)e.lens[t++]=8;for(;t<256;)e.lens[t++]=9;for(;t<280;)e.lens[t++]=7;for(;t<288;)e.lens[t++]=8;for(c(1,e.lens,0,288,M,0,e.work,{bits:9}),t=0;t<32;)e.lens[t++]=5;c(2,e.lens,0,32,H,0,e.work,{bits:5}),j=!1;}e.lencode=M,e.lenbits=9,e.distcode=H,e.distbits=5;},P=(e,t,i,n)=>{let a;const r=e.state;return null===r.window&&(r.wsize=1<=r.wsize?(r.window.set(t.subarray(i-r.wsize,i),0),r.wnext=0,r.whave=r.wsize):(a=r.wsize-r.wnext,a>n&&(a=n),r.window.set(t.subarray(i-n,i-n+a),r.wnext),(n-=a)?(r.window.set(t.subarray(i-n,i),0),r.wnext=n,r.whave=r.wsize):(r.wnext+=a,r.wnext===r.wsize&&(r.wnext=0),r.whaveL(e,15),inflateInit2:L,inflate:(e,i)=>{let a,o,s,l,d,f,h,B,C,z,F,L,M,H,j,Y,G,X,W,q,J,Q,V=0;const $=new Uint8Array(4);let ee,te;const ie=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(N(e)||!e.output||!e.input&&0!==e.avail_in)return g;a=e.state,a.mode===A&&(a.mode=Z),d=e.next_out,s=e.output,h=e.avail_out,l=e.next_in,o=e.input,f=e.avail_in,B=a.hold,C=a.bits,z=f,F=h,Q=m;e:for(;;)switch(a.mode){case E:if(0===a.wrap){a.mode=Z;break}for(;C<16;){if(0===f)break e;f--,B+=o[l++]<>>8&255,a.check=n(a.check,$,2,0),B=0,C=0,a.mode=16181;break}if(a.head&&(a.head.done=!1),!(1&a.wrap)||(((255&B)<<8)+(B>>8))%31){e.msg="incorrect header check",a.mode=D;break}if((15&B)!==y){e.msg="unknown compression method",a.mode=D;break}if(B>>>=4,C-=4,J=8+(15&B),0===a.wbits&&(a.wbits=J),J>15||J>a.wbits){e.msg="invalid window size",a.mode=D;break}a.dmax=1<>8&1),512&a.flags&&4&a.wrap&&($[0]=255&B,$[1]=B>>>8&255,a.check=n(a.check,$,2,0)),B=0,C=0,a.mode=16182;case 16182:for(;C<32;){if(0===f)break e;f--,B+=o[l++]<>>8&255,$[2]=B>>>16&255,$[3]=B>>>24&255,a.check=n(a.check,$,4,0)),B=0,C=0,a.mode=16183;case 16183:for(;C<16;){if(0===f)break e;f--,B+=o[l++]<>8),512&a.flags&&4&a.wrap&&($[0]=255&B,$[1]=B>>>8&255,a.check=n(a.check,$,2,0)),B=0,C=0,a.mode=16184;case 16184:if(1024&a.flags){for(;C<16;){if(0===f)break e;f--,B+=o[l++]<>>8&255,a.check=n(a.check,$,2,0)),B=0,C=0;}else a.head&&(a.head.extra=null);a.mode=16185;case 16185:if(1024&a.flags&&(L=a.length,L>f&&(L=f),L&&(a.head&&(J=a.head.extra_len-a.length,a.head.extra||(a.head.extra=new Uint8Array(a.head.extra_len)),a.head.extra.set(o.subarray(l,l+L),J)),512&a.flags&&4&a.wrap&&(a.check=n(a.check,o,L,l)),f-=L,l+=L,a.length-=L),a.length))break e;a.length=0,a.mode=16186;case 16186:if(2048&a.flags){if(0===f)break e;L=0;do{J=o[l+L++],a.head&&J&&a.length<65536&&(a.head.name+=String.fromCharCode(J));}while(J&&L>9&1,a.head.done=!0),e.adler=a.check=0,a.mode=A;break;case 16189:for(;C<32;){if(0===f)break e;f--,B+=o[l++]<>>=7&C,C-=7&C,a.mode=U;break}for(;C<3;){if(0===f)break e;f--,B+=o[l++]<>>=1,C-=1,3&B){case 0:a.mode=16193;break;case 1:if(K(a),a.mode=T,i===b){B>>>=2,C-=2;break e}break;case 2:a.mode=16196;break;case 3:e.msg="invalid block type",a.mode=D;}B>>>=2,C-=2;break;case 16193:for(B>>>=7&C,C-=7&C;C<32;){if(0===f)break e;f--,B+=o[l++]<>>16^65535)){e.msg="invalid stored block lengths",a.mode=D;break}if(a.length=65535&B,B=0,C=0,a.mode=S,i===b)break e;case S:a.mode=16195;case 16195:if(L=a.length,L){if(L>f&&(L=f),L>h&&(L=h),0===L)break e;s.set(o.subarray(l,l+L),d),f-=L,l+=L,h-=L,d+=L,a.length-=L;break}a.mode=A;break;case 16196:for(;C<14;){if(0===f)break e;f--,B+=o[l++]<>>=5,C-=5,a.ndist=1+(31&B),B>>>=5,C-=5,a.ncode=4+(15&B),B>>>=4,C-=4,a.nlen>286||a.ndist>30){e.msg="too many length or distance symbols",a.mode=D;break}a.have=0,a.mode=16197;case 16197:for(;a.have>>=3,C-=3;}for(;a.have<19;)a.lens[ie[a.have++]]=0;if(a.lencode=a.lendyn,a.lenbits=7,ee={bits:a.lenbits},Q=c(0,a.lens,0,19,a.lencode,0,a.work,ee),a.lenbits=ee.bits,Q){e.msg="invalid code lengths set",a.mode=D;break}a.have=0,a.mode=16198;case 16198:for(;a.have>>24,Y=V>>>16&255,G=65535&V,!(j<=C);){if(0===f)break e;f--,B+=o[l++]<>>=j,C-=j,a.lens[a.have++]=G;else {if(16===G){for(te=j+2;C>>=j,C-=j,0===a.have){e.msg="invalid bit length repeat",a.mode=D;break}J=a.lens[a.have-1],L=3+(3&B),B>>>=2,C-=2;}else if(17===G){for(te=j+3;C>>=j,C-=j,J=0,L=3+(7&B),B>>>=3,C-=3;}else {for(te=j+7;C>>=j,C-=j,J=0,L=11+(127&B),B>>>=7,C-=7;}if(a.have+L>a.nlen+a.ndist){e.msg="invalid bit length repeat",a.mode=D;break}for(;L--;)a.lens[a.have++]=J;}}if(a.mode===D)break;if(0===a.lens[256]){e.msg="invalid code -- missing end-of-block",a.mode=D;break}if(a.lenbits=9,ee={bits:a.lenbits},Q=c(1,a.lens,0,a.nlen,a.lencode,0,a.work,ee),a.lenbits=ee.bits,Q){e.msg="invalid literal/lengths set",a.mode=D;break}if(a.distbits=6,a.distcode=a.distdyn,ee={bits:a.distbits},Q=c(2,a.lens,a.nlen,a.ndist,a.distcode,0,a.work,ee),a.distbits=ee.bits,Q){e.msg="invalid distances set",a.mode=D;break}if(a.mode=T,i===b)break e;case T:a.mode=O;case O:if(f>=6&&h>=258){e.next_out=d,e.avail_out=h,e.next_in=l,e.avail_in=f,a.hold=B,a.bits=C,r(e,F),d=e.next_out,s=e.output,h=e.avail_out,l=e.next_in,o=e.input,f=e.avail_in,B=a.hold,C=a.bits,a.mode===A&&(a.back=-1);break}for(a.back=0;V=a.lencode[B&(1<>>24,Y=V>>>16&255,G=65535&V,!(j<=C);){if(0===f)break e;f--,B+=o[l++]<>X)],j=V>>>24,Y=V>>>16&255,G=65535&V,!(X+j<=C);){if(0===f)break e;f--,B+=o[l++]<>>=X,C-=X,a.back+=X;}if(B>>>=j,C-=j,a.back+=j,a.length=G,0===Y){a.mode=16205;break}if(32&Y){a.back=-1,a.mode=A;break}if(64&Y){e.msg="invalid literal/length code",a.mode=D;break}a.extra=15&Y,a.mode=16201;case 16201:if(a.extra){for(te=a.extra;C>>=a.extra,C-=a.extra,a.back+=a.extra;}a.was=a.length,a.mode=16202;case 16202:for(;V=a.distcode[B&(1<>>24,Y=V>>>16&255,G=65535&V,!(j<=C);){if(0===f)break e;f--,B+=o[l++]<>X)],j=V>>>24,Y=V>>>16&255,G=65535&V,!(X+j<=C);){if(0===f)break e;f--,B+=o[l++]<>>=X,C-=X,a.back+=X;}if(B>>>=j,C-=j,a.back+=j,64&Y){e.msg="invalid distance code",a.mode=D;break}a.offset=G,a.extra=15&Y,a.mode=16203;case 16203:if(a.extra){for(te=a.extra;C>>=a.extra,C-=a.extra,a.back+=a.extra;}if(a.offset>a.dmax){e.msg="invalid distance too far back",a.mode=D;break}a.mode=16204;case 16204:if(0===h)break e;if(L=F-h,a.offset>L){if(L=a.offset-L,L>a.whave&&a.sane){e.msg="invalid distance too far back",a.mode=D;break}L>a.wnext?(L-=a.wnext,M=a.wsize-L):M=a.wnext-L,L>a.length&&(L=a.length),H=a.window;}else H=s,M=d-a.offset,L=a.length;L>h&&(L=h),h-=L,a.length-=L;do{s[d++]=H[M++];}while(--L);0===a.length&&(a.mode=O);break;case 16205:if(0===h)break e;s[d++]=a.length,h--,a.mode=O;break;case U:if(a.wrap){for(;C<32;){if(0===f)break e;f--,B|=o[l++]<{if(N(e))return g;let t=e.state;return t.window&&(t.window=null),e.state=null,m},inflateGetHeader:(e,t)=>{if(N(e))return g;const i=e.state;return 0==(2&i.wrap)?g:(i.head=t,t.done=!1,m)},inflateSetDictionary:(e,i)=>{const n=i.length;let a,r,o;return N(e)?g:(a=e.state,0!==a.wrap&&a.mode!==R?g:a.mode===R&&(r=1,r=t(r,i,n,0),r!==a.check)?p:(o=P(e,i,n,n),o?(a.mode=16210,v):(a.havedict=1,m)))},inflateInfo:"pako inflate (from Nodeca project)"};const G=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var X=function(e){const t=Array.prototype.slice.call(arguments,1);for(;t.length;){const i=t.shift();if(i){if("object"!=typeof i)throw new TypeError(i+"must be non-object");for(const t in i)G(i,t)&&(e[t]=i[t]);}}return e},W=e=>{let t=0;for(let i=0,n=e.length;i=252?6:e>=248?5:e>=240?4:e>=224?3:e>=192?2:1;J[254]=J[254]=1;var Q=e=>{if("function"==typeof TextEncoder&&TextEncoder.prototype.encode)return (new TextEncoder).encode(e);let t,i,n,a,r,o=e.length,s=0;for(a=0;a>>6,t[r++]=128|63&i):i<65536?(t[r++]=224|i>>>12,t[r++]=128|i>>>6&63,t[r++]=128|63&i):(t[r++]=240|i>>>18,t[r++]=128|i>>>12&63,t[r++]=128|i>>>6&63,t[r++]=128|63&i);return t},V=(e,t)=>{const i=t||e.length;if("function"==typeof TextDecoder&&TextDecoder.prototype.decode)return (new TextDecoder).decode(e.subarray(0,t));let n,a;const r=new Array(2*i);for(a=0,n=0;n4)r[a++]=65533,n+=o-1;else {for(t&=2===o?31:3===o?15:7;o>1&&n1?r[a++]=65533:t<65536?r[a++]=t:(t-=65536,r[a++]=55296|t>>10&1023,r[a++]=56320|1023&t);}}return ((e,t)=>{if(t<65534&&e.subarray&&q)return String.fromCharCode.apply(null,e.length===t?e:e.subarray(0,t));let i="";for(let n=0;n{(t=t||e.length)>e.length&&(t=e.length);let i=t-1;for(;i>=0&&128==(192&e[i]);)i--;return i<0||0===i?t:i+J[e[i]]>t?i:t},ee={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"};var te=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0;};var ie=function(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1;};const ne=Object.prototype.toString,{Z_NO_FLUSH:ae,Z_FINISH:re,Z_OK:oe,Z_STREAM_END:se,Z_NEED_DICT:le,Z_STREAM_ERROR:de,Z_DATA_ERROR:fe,Z_MEM_ERROR:ce}=h;function he(e){this.options=X({chunkSize:65536,windowBits:15,to:""},e||{});const t=this.options;t.raw&&t.windowBits>=0&&t.windowBits<16&&(t.windowBits=-t.windowBits,0===t.windowBits&&(t.windowBits=-15)),!(t.windowBits>=0&&t.windowBits<16)||e&&e.windowBits||(t.windowBits+=32),t.windowBits>15&&t.windowBits<48&&0==(15&t.windowBits)&&(t.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new te,this.strm.avail_out=0;let i=Y.inflateInit2(this.strm,t.windowBits);if(i!==oe)throw new Error(ee[i]);if(this.header=new ie,Y.inflateGetHeader(this.strm,this.header),t.dictionary&&("string"==typeof t.dictionary?t.dictionary=Q(t.dictionary):"[object ArrayBuffer]"===ne.call(t.dictionary)&&(t.dictionary=new Uint8Array(t.dictionary)),t.raw&&(i=Y.inflateSetDictionary(this.strm,t.dictionary),i!==oe)))throw new Error(ee[i])}function ue(e,t){const i=new he(t);if(i.push(e),i.err)throw i.msg||ee[i.err];return i.result}he.prototype.push=function(e,t){const i=this.strm,n=this.options.chunkSize,a=this.options.dictionary;let r,o,s;if(this.ended)return !1;for(o=t===~~t?t:!0===t?re:ae,"[object ArrayBuffer]"===ne.call(e)?i.input=new Uint8Array(e):i.input=e,i.next_in=0,i.avail_in=i.input.length;;){for(0===i.avail_out&&(i.output=new Uint8Array(n),i.next_out=0,i.avail_out=n),r=Y.inflate(i,o),r===le&&a&&(r=Y.inflateSetDictionary(i,a),r===oe?r=Y.inflate(i,o):r===fe&&(r=le));i.avail_in>0&&r===se&&i.state.wrap>0&&0!==e[i.next_in];)Y.inflateReset(i),r=Y.inflate(i,o);switch(r){case de:case fe:case le:case ce:return this.onEnd(r),this.ended=!0,!1}if(s=i.avail_out,i.next_out&&(0===i.avail_out||r===se))if("string"===this.options.to){let e=$(i.output,i.next_out),t=i.next_out-e,a=V(i.output,e);i.next_out=t,i.avail_out=n-t,t&&i.output.set(i.output.subarray(e,e+t),0),this.onData(a);}else this.onData(i.output.length===i.next_out?i.output:i.output.subarray(0,i.next_out));if(r!==oe||0!==s){if(r===se)return r=Y.inflateEnd(this.strm),this.onEnd(r),this.ended=!0,!0;if(0===i.avail_in)break}}return !0},he.prototype.onData=function(e){this.chunks.push(e);},he.prototype.onEnd=function(e){e===oe&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=W(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg;};var we=he,be=ue,me=function(e,t){return (t=t||{}).raw=!0,ue(e,t)},ke=ue,_e=h,ge={Inflate:we,inflate:be,inflateRaw:me,ungzip:ke,constants:_e};e.Inflate=we,e.constants=_e,e.default=ge,e.inflate=be,e.inflateRaw=me,e.ungzip=ke,Object.defineProperty(e,"__esModule",{value:!0});})); 16 | } (pako_inflate_min, pako_inflate_min.exports)); 17 | 18 | var pako_inflate_minExports = pako_inflate_min.exports; 19 | 20 | const LITTLE_ENDIAN = true; 21 | 22 | class DataReader { 23 | 24 | /** @param {ArrayBuffer} buffer */ 25 | constructor( buffer ) { 26 | 27 | this.dataView = new DataView( buffer ); 28 | this.position = 0; 29 | 30 | } 31 | 32 | /** @param {number} length */ 33 | skip( length ) { 34 | 35 | this.position += length; 36 | 37 | } 38 | 39 | /** @param {number} length */ 40 | readBytes( length ) { 41 | 42 | const type = length === 4 ? 'getUint32' : 43 | length === 2 ? 'getUint16' : 44 | 'getUint8'; 45 | const start = this.position; 46 | this.position += length; 47 | return this.dataView[ type ]( start, LITTLE_ENDIAN ); 48 | 49 | } 50 | 51 | } 52 | 53 | const LOCAL_FILE_HEADER = 0x04034b50; 54 | const CENTRAL_DIRECTORY = 0x02014b50; 55 | // const END_OF_CENTRAL_DIRECTORY = 0x06054b50; 56 | 57 | const parseZip = ( buffer ) => { 58 | 59 | const reader = new DataReader( buffer ); 60 | const files = {}; 61 | 62 | while ( true ) { 63 | 64 | const signature = reader.readBytes( 4 ); 65 | 66 | if ( signature === LOCAL_FILE_HEADER ) { 67 | 68 | const file = parseLocalFile( reader ); 69 | files[ file.name ] = { buffer: file.buffer }; 70 | continue; 71 | 72 | } 73 | 74 | if ( signature === CENTRAL_DIRECTORY ) { 75 | 76 | parseCentralDirectory( reader ); 77 | continue; 78 | 79 | } 80 | 81 | break; 82 | 83 | } 84 | 85 | return files; 86 | 87 | }; 88 | 89 | // # Local file header 90 | // 91 | // | Offset | Length | Contents | 92 | // | ------ | -------- | ---------------------------------------- | 93 | // | 0 | 4 bytes | Local file header signature (0x04034b50) | 94 | // | 4 | 2 bytes | Version needed to extract | 95 | // | 6 | 2 bytes | General purpose bit flag | 96 | // | 8 | 2 bytes | Compression method | 97 | // | 10 | 2 bytes | Last mod file time | 98 | // | 12 | 2 bytes | Last mod file date | 99 | // | 14 | 4 bytes | CRC-32 | 100 | // | 18 | 4 bytes | Compressed size (n) | 101 | // | 22 | 4 bytes | Uncompressed size | 102 | // | 26 | 2 bytes | Filename length (f) | 103 | // | 28 | 2 bytes | Extra field length (e) | 104 | // | | (f)bytes | Filename | 105 | // | | (e)bytes | Extra field | 106 | // | | (n)bytes | Compressed data | 107 | const parseLocalFile = ( reader ) => { 108 | 109 | let i = 0; 110 | let data; 111 | reader.skip( 4 ); 112 | // const version = reader.readBytes( 2 ); 113 | // const bitFlag = reader.readBytes( 2 ); 114 | const compression = reader.readBytes( 2 ); 115 | reader.skip( 8 ); 116 | // const lastModTime = reader.readBytes( 2 ); 117 | // const lastModDate = reader.readBytes( 2 ); 118 | // const crc32 = reader.readBytes( 4 ); 119 | const compressedSize = reader.readBytes( 4 ); 120 | reader.skip( 4 ); 121 | // const uncompressedSize = reader.readBytes( 4 ); 122 | const filenameLength = reader.readBytes( 2 ); 123 | const extraFieldLength = reader.readBytes( 2 ); 124 | const filename = []; 125 | // const extraField = []; 126 | const compressedData = new Uint8Array( compressedSize ); 127 | 128 | for ( i = 0; i < filenameLength; i ++ ) { 129 | 130 | filename.push( String.fromCharCode( reader.readBytes( 1 ) ) ); 131 | 132 | } 133 | 134 | reader.skip( extraFieldLength ); 135 | // for ( i = 0; i < extraFieldLength; i ++ ) { 136 | 137 | // extraField.push( reader.readBytes( 1 ) ); 138 | 139 | // } 140 | 141 | for ( i = 0; i < compressedSize; i ++ ) { 142 | 143 | compressedData[ i ] = reader.readBytes( 1 ); 144 | 145 | } 146 | 147 | switch ( compression ) { 148 | 149 | case 0: 150 | data = compressedData; 151 | break; 152 | case 8: 153 | data = new Uint8Array( pako_inflate_minExports.inflate( compressedData, { raw: true } ) ); 154 | break; 155 | default: 156 | console.log( `${ filename.join( '' ) }: unsupported compression type` ); 157 | data = compressedData; 158 | 159 | } 160 | 161 | return { 162 | name: filename.join( '' ), 163 | buffer: data 164 | }; 165 | 166 | }; 167 | 168 | // # Central directory 169 | // 170 | // | Offset | Length | Contents | 171 | // | ------ | -------- | ------------------------------------------ | 172 | // | 0 | 4 bytes | Central file header signature (0x02014b50) | 173 | // | 4 | 2 bytes | Version made by | 174 | // | 6 | 2 bytes | Version needed to extract | 175 | // | 8 | 2 bytes | General purpose bit flag | 176 | // | 10 | 2 bytes | Compression method | 177 | // | 12 | 2 bytes | Last mod file time | 178 | // | 14 | 2 bytes | Last mod file date | 179 | // | 16 | 4 bytes | CRC-32 | 180 | // | 20 | 4 bytes | Compressed size | 181 | // | 24 | 4 bytes | Uncompressed size | 182 | // | 28 | 2 bytes | Filename length (f) | 183 | // | 30 | 2 bytes | Extra field length (e) | 184 | // | 32 | 2 bytes | File comment length (c) | 185 | // | 34 | 2 bytes | Disk number start | 186 | // | 36 | 2 bytes | Internal file attributes | 187 | // | 38 | 4 bytes | External file attributes | 188 | // | 42 | 4 bytes | Relative offset of local header | 189 | // | 46 | (f)bytes | Filename | 190 | // | | (e)bytes | Extra field | 191 | // | | (c)bytes | File comment | 192 | const parseCentralDirectory = ( reader ) => { 193 | 194 | // let i = 0; 195 | reader.skip( 24 ); 196 | // const versionMadeby = reader.readBytes( 2 ); 197 | // const versionNeedToExtract = reader.readBytes( 2 ); 198 | // const bitFlag = reader.readBytes( 2 ); 199 | // const compression = reader.readBytes( 2 ); 200 | // const lastModTime = reader.readBytes( 2 ); 201 | // const lastModDate = reader.readBytes( 2 ); 202 | // const crc32 = reader.readBytes( 4 ); 203 | // const compressedSize = reader.readBytes( 4 ); 204 | // const uncompressedSize = reader.readBytes( 4 ); 205 | const filenameLength = reader.readBytes( 2 ); 206 | const extraFieldLength = reader.readBytes( 2 ); 207 | const fileCommentLength = reader.readBytes( 2 ); 208 | reader.skip( 12 ); 209 | // const diskNumberStart = reader.readBytes( 2 ); 210 | // const internalFileAttrs = reader.readBytes( 2 ); 211 | // const externalFileAttrs = reader.readBytes( 4 ); 212 | // const relativeOffset = reader.readBytes( 4 ); 213 | // const filename = []; 214 | // const extraField = []; 215 | // const fileComment = []; 216 | 217 | reader.skip( filenameLength ); 218 | // for ( i = 0; i < filenameLength; i ++ ) { 219 | 220 | // filename.push( String.fromCharCode( reader.readBytes( 1 ) ) ); 221 | 222 | // } 223 | 224 | reader.skip( extraFieldLength ); 225 | // for ( i = 0; i < extraFieldLength; i ++ ) { 226 | 227 | // extraField.push( reader.readBytes( 1 ) ); 228 | 229 | // } 230 | 231 | reader.skip( fileCommentLength ); 232 | // for ( i = 0; i < fileCommentLength; i ++ ) { 233 | 234 | // fileComment.push( reader.readBytes( 1 ) ); 235 | 236 | // } 237 | 238 | }; 239 | 240 | /** 241 | * @class ZipLoader 242 | * @classdesc A class for loading and extracting files from a ZIP archive. 243 | */ 244 | const ZipLoader = class ZipLoader { 245 | 246 | /** 247 | * @function 248 | * @description Loads a zip archive from a File or Blob object and returns a Promise that resolves with a new ZipLoader instance 249 | * @param {Blob|File} blobOrFile - The Blob or File object to load 250 | * @returns {Promise} 251 | */ 252 | static unzip( blobOrFile ) { 253 | 254 | return new Promise( ( resolve ) => { 255 | 256 | const instance = new ZipLoader(); 257 | const fileReader = new FileReader(); 258 | 259 | fileReader.onload = ( event ) => { 260 | 261 | const arrayBuffer = event.target.result; 262 | instance.files = parseZip( arrayBuffer ); 263 | resolve( instance ); 264 | 265 | }; 266 | 267 | if ( blobOrFile instanceof Blob ) { 268 | 269 | fileReader.readAsArrayBuffer( blobOrFile ); 270 | 271 | } 272 | 273 | } ); 274 | 275 | } 276 | 277 | /** 278 | * @constructor 279 | * @param {string} url 280 | * @param {RequestInit} fetchOptions 281 | */ 282 | constructor( url, fetchOptions = {} ) { 283 | 284 | /** @private */ 285 | this._listeners = {}; 286 | 287 | /** @type {String|undefined} */ 288 | this.url = url; 289 | 290 | /** @type {RequestInit} */ 291 | this.fetchOptions = fetchOptions; 292 | 293 | /** @type {import('./types.ts').Files | null} */ 294 | this.files = null; 295 | 296 | } 297 | 298 | /** 299 | * Loads the ZIP archive specified by the url property. 300 | * Returns a Promise that resolves when the ZIP archive has been loaded and extracted. 301 | * 302 | * @async 303 | * @returns {Promise} A Promise that resolves when the ZIP archive has been loaded and extracted. 304 | */ 305 | async load() { 306 | 307 | this.clear(); 308 | 309 | const startTime = Date.now(); 310 | const res = await fetch( this.url, this.fetchOptions ).then( ( res ) => { 311 | 312 | const that = this; 313 | const total = parseInt( res.headers.get( 'content-length' ), 10 ); 314 | let loaded = 0; 315 | 316 | return new Response( new ReadableStream( { 317 | start( controller ) { 318 | const reader = res.body.getReader(); 319 | 320 | const pump = async () => { 321 | const { done, value } = await reader.read(); 322 | if ( done ) { 323 | 324 | controller.close(); 325 | return; 326 | 327 | } 328 | loaded += value.byteLength; 329 | controller.enqueue( value ); 330 | that.dispatch( { 331 | type: 'progress', 332 | loaded, 333 | total, 334 | elapsedTime: Date.now() - startTime, 335 | } ); 336 | pump(); 337 | }; 338 | pump(); 339 | } 340 | } ) ); 341 | 342 | } ).catch( ( error ) => { 343 | 344 | this.dispatch( { 345 | type: 'error', 346 | error 347 | } ); 348 | 349 | } ); 350 | 351 | const arrayBuffer = await res.arrayBuffer(); 352 | this.files = parseZip( arrayBuffer ); 353 | this.dispatch( { 354 | type: 'load', 355 | elapsedTime: Date.now() - startTime, 356 | } ); 357 | 358 | return this.files; 359 | 360 | } 361 | 362 | /** 363 | * Extracts a file from the loaded ZIP archive and returns it as a Blob URL. 364 | * 365 | * @param {string} filename - The name of the file to extract. 366 | * @param {string} type - The MIME type of the file. 367 | * @returns {string} The Blob URL of the extracted file. 368 | */ 369 | extractAsBlobUrl( filename, type ) { 370 | 371 | if ( this.files[ filename ].url ) { 372 | 373 | return this.files[ filename ].url; 374 | 375 | } 376 | 377 | const blob = new Blob( [ this.files[ filename ].buffer ], { type: type } ); 378 | this.files[ filename ].url = URL.createObjectURL( blob ); 379 | return this.files[ filename ].url; 380 | 381 | } 382 | 383 | /** 384 | * @param {string} filename 385 | * @returns {string|undefined} 386 | */ 387 | extractAsText( filename ) { 388 | 389 | const buffer = this.files[ filename ].buffer; 390 | 391 | if ( typeof TextDecoder !== 'undefined' ) { 392 | 393 | return new TextDecoder().decode( buffer ); 394 | 395 | } 396 | 397 | let str = ''; 398 | 399 | for ( let i = 0, l = buffer.length; i < l; i ++ ) { 400 | 401 | str += String.fromCharCode( buffer[ i ] ); 402 | 403 | } 404 | 405 | return decodeURIComponent( escape( str ) ); 406 | 407 | } 408 | 409 | /** 410 | * @param {string} filename 411 | * @returns {*} 412 | */ 413 | extractAsJSON( filename ) { 414 | 415 | return JSON.parse( this.extractAsText( filename ) ); 416 | 417 | } 418 | 419 | /** 420 | * Adds the specified event listener. 421 | * @param {string} type event name 422 | * @param {import('./types.ts').Listener} listener handler function 423 | */ 424 | on( type, listener ) { 425 | 426 | if ( ! this._listeners[ type ] ) { 427 | 428 | this._listeners[ type ] = []; 429 | 430 | } 431 | 432 | if ( this._listeners[ type ].indexOf( listener ) === - 1 ) { 433 | 434 | this._listeners[ type ].push( listener ); 435 | 436 | } 437 | 438 | } 439 | 440 | /** 441 | * Removes the specified event listener 442 | * @param {string} type event name 443 | * @param {import('./types.ts').Listener} listener handler function 444 | */ 445 | off( type, listener ) { 446 | 447 | const listenerArray = this._listeners[ type ]; 448 | 449 | if ( !! listenerArray ) { 450 | 451 | const index = listenerArray.indexOf( listener ); 452 | 453 | if ( index !== - 1 ) { 454 | 455 | listenerArray.splice( index, 1 ); 456 | 457 | } 458 | 459 | } 460 | 461 | } 462 | 463 | dispatch( event ) { 464 | 465 | const listenerArray = this._listeners[ event.type ]; 466 | 467 | if ( !! listenerArray ) { 468 | 469 | event.target = this; 470 | const length = listenerArray.length; 471 | 472 | for ( let i = 0; i < length; i ++ ) { 473 | 474 | listenerArray[ i ].call( this, event ); 475 | 476 | } 477 | 478 | } 479 | 480 | } 481 | 482 | /** @param {string=} filename */ 483 | clear( filename ) { 484 | 485 | if ( !! filename ) { 486 | 487 | URL.revokeObjectURL( this.files[ filename ].url ); 488 | delete this.files[ filename ]; 489 | return; 490 | 491 | } 492 | 493 | for ( let key in this.files ) { 494 | 495 | URL.revokeObjectURL( this.files[ key ].url ); 496 | 497 | } 498 | 499 | this.files = null; 500 | 501 | } 502 | 503 | }; 504 | 505 | export { ZipLoader as default }; 506 | -------------------------------------------------------------------------------- /dist/zip-loader.module.min.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * zip-loader 3 | * https://github.com/yomotsu/ZipLoader 4 | * (c) 2017 @yomotsu 5 | * Released under the MIT License. 6 | * ZipLoader uses pako, released under the MIT license. 7 | */ 8 | var commonjsGlobal=typeof globalThis!=="undefined"?globalThis:typeof window!=="undefined"?window:typeof global!=="undefined"?global:typeof self!=="undefined"?self:{};var pako_inflate_min={exports:{}}; 9 | /*! pako 2.1.0 https://github.com/nodeca/pako @license (MIT AND Zlib) */(function(module,exports){!function(e,t){t(exports)}(commonjsGlobal,(function(e){var t=(e,t,i,n)=>{let a=65535&e|0,r=e>>>16&65535|0,o=0;for(;0!==i;){o=i>2e3?2e3:i,i-=o;do{a=a+t[n++]|0,r=r+a|0}while(--o);a%=65521,r%=65521}return a|r<<16|0};const i=new Uint32Array((()=>{let e,t=[];for(var i=0;i<256;i++){e=i;for(var n=0;n<8;n++)e=1&e?3988292384^e>>>1:e>>>1;t[i]=e}return t})());var n=(e,t,n,a)=>{const r=i,o=a+n;e^=-1;for(let i=a;i>>8^r[255&(e^t[i])];return-1^e};const a=16209;var r=function(e,t){let i,n,r,o,s,l,d,f,c,h,u,w,b,m,k,_,g,p,v,x,y,E,R,A;const Z=e.state;i=e.next_in,R=e.input,n=i+(e.avail_in-5),r=e.next_out,A=e.output,o=r-(t-e.avail_out),s=r+(e.avail_out-257),l=Z.dmax,d=Z.wsize,f=Z.whave,c=Z.wnext,h=Z.window,u=Z.hold,w=Z.bits,b=Z.lencode,m=Z.distcode,k=(1<>>24,u>>>=p,w-=p,p=g>>>16&255,0===p)A[r++]=65535&g;else{if(!(16&p)){if(0==(64&p)){g=b[(65535&g)+(u&(1<>>=p,w-=p),w<15&&(u+=R[i++]<>>24,u>>>=p,w-=p,p=g>>>16&255,!(16&p)){if(0==(64&p)){g=m[(65535&g)+(u&(1<l){e.msg="invalid distance too far back",Z.mode=a;break e}if(u>>>=p,w-=p,p=r-o,x>p){if(p=x-p,p>f&&Z.sane){e.msg="invalid distance too far back",Z.mode=a;break e}if(y=0,E=h,0===c){if(y+=d-p,p2;)A[r++]=E[y++],A[r++]=E[y++],A[r++]=E[y++],v-=3;v&&(A[r++]=E[y++],v>1&&(A[r++]=E[y++]))}else{y=r-x;do{A[r++]=A[y++],A[r++]=A[y++],A[r++]=A[y++],v-=3}while(v>2);v&&(A[r++]=A[y++],v>1&&(A[r++]=A[y++]))}break}}break}}while(i>3,i-=v,w-=v<<3,u&=(1<{const u=h.bits;let w,b,m,k,_,g,p=0,v=0,x=0,y=0,E=0,R=0,A=0,Z=0,S=0,T=0,O=null;const U=new Uint16Array(16),D=new Uint16Array(16);let I,B,N,C=null;for(p=0;p<=o;p++)U[p]=0;for(v=0;v=1&&0===U[y];y--);if(E>y&&(E=y),0===y)return a[r++]=20971520,a[r++]=20971520,h.bits=1,0;for(x=1;x0&&(0===e||1!==y))return-1;for(D[1]=0,p=1;p852||2===e&&S>592)return 1;for(;;){I=p-A,c[v]+1=g?(B=C[c[v]-g],N=O[c[v]-g]):(B=96,N=0),w=1<>A)+b]=I<<24|B<<16|N|0}while(0!==b);for(w=1<>=1;if(0!==w?(T&=w-1,T+=w):T=0,v++,0==--U[p]){if(p===y)break;p=t[i+c[v]]}if(p>E&&(T&k)!==m){for(0===A&&(A=E),_+=x,R=p-A,Z=1<852||2===e&&S>592)return 1;m=T&k,a[m]=E<<24|R<<16|_-r|0}}return 0!==T&&(a[_+T]=p-A<<24|64<<16|0),h.bits=E,0},h={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8};const{Z_FINISH:u,Z_BLOCK:w,Z_TREES:b,Z_OK:m,Z_STREAM_END:k,Z_NEED_DICT:_,Z_STREAM_ERROR:g,Z_DATA_ERROR:p,Z_MEM_ERROR:v,Z_BUF_ERROR:x,Z_DEFLATED:y}=h,E=16180,R=16190,A=16191,Z=16192,S=16194,T=16199,O=16200,U=16206,D=16209,I=e=>(e>>>24&255)+(e>>>8&65280)+((65280&e)<<8)+((255&e)<<24);function B(){this.strm=null,this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}const N=e=>{if(!e)return 1;const t=e.state;return!t||t.strm!==e||t.mode16211?1:0},C=e=>{if(N(e))return g;const t=e.state;return e.total_in=e.total_out=t.total=0,e.msg="",t.wrap&&(e.adler=1&t.wrap),t.mode=E,t.last=0,t.havedict=0,t.flags=-1,t.dmax=32768,t.head=null,t.hold=0,t.bits=0,t.lencode=t.lendyn=new Int32Array(852),t.distcode=t.distdyn=new Int32Array(592),t.sane=1,t.back=-1,m},z=e=>{if(N(e))return g;const t=e.state;return t.wsize=0,t.whave=0,t.wnext=0,C(e)},F=(e,t)=>{let i;if(N(e))return g;const n=e.state;return t<0?(i=0,t=-t):(i=5+(t>>4),t<48&&(t&=15)),t&&(t<8||t>15)?g:(null!==n.window&&n.wbits!==t&&(n.window=null),n.wrap=i,n.wbits=t,z(e))},L=(e,t)=>{if(!e)return g;const i=new B;e.state=i,i.strm=e,i.window=null,i.mode=E;const n=F(e,t);return n!==m&&(e.state=null),n};let M,H,j=!0;const K=e=>{if(j){M=new Int32Array(512),H=new Int32Array(32);let t=0;for(;t<144;)e.lens[t++]=8;for(;t<256;)e.lens[t++]=9;for(;t<280;)e.lens[t++]=7;for(;t<288;)e.lens[t++]=8;for(c(1,e.lens,0,288,M,0,e.work,{bits:9}),t=0;t<32;)e.lens[t++]=5;c(2,e.lens,0,32,H,0,e.work,{bits:5}),j=!1}e.lencode=M,e.lenbits=9,e.distcode=H,e.distbits=5},P=(e,t,i,n)=>{let a;const r=e.state;return null===r.window&&(r.wsize=1<=r.wsize?(r.window.set(t.subarray(i-r.wsize,i),0),r.wnext=0,r.whave=r.wsize):(a=r.wsize-r.wnext,a>n&&(a=n),r.window.set(t.subarray(i-n,i-n+a),r.wnext),(n-=a)?(r.window.set(t.subarray(i-n,i),0),r.wnext=n,r.whave=r.wsize):(r.wnext+=a,r.wnext===r.wsize&&(r.wnext=0),r.whaveL(e,15),inflateInit2:L,inflate:(e,i)=>{let a,o,s,l,d,f,h,B,C,z,F,L,M,H,j,Y,G,X,W,q,J,Q,V=0;const $=new Uint8Array(4);let ee,te;const ie=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(N(e)||!e.output||!e.input&&0!==e.avail_in)return g;a=e.state,a.mode===A&&(a.mode=Z),d=e.next_out,s=e.output,h=e.avail_out,l=e.next_in,o=e.input,f=e.avail_in,B=a.hold,C=a.bits,z=f,F=h,Q=m;e:for(;;)switch(a.mode){case E:if(0===a.wrap){a.mode=Z;break}for(;C<16;){if(0===f)break e;f--,B+=o[l++]<>>8&255,a.check=n(a.check,$,2,0),B=0,C=0,a.mode=16181;break}if(a.head&&(a.head.done=!1),!(1&a.wrap)||(((255&B)<<8)+(B>>8))%31){e.msg="incorrect header check",a.mode=D;break}if((15&B)!==y){e.msg="unknown compression method",a.mode=D;break}if(B>>>=4,C-=4,J=8+(15&B),0===a.wbits&&(a.wbits=J),J>15||J>a.wbits){e.msg="invalid window size",a.mode=D;break}a.dmax=1<>8&1),512&a.flags&&4&a.wrap&&($[0]=255&B,$[1]=B>>>8&255,a.check=n(a.check,$,2,0)),B=0,C=0,a.mode=16182;case 16182:for(;C<32;){if(0===f)break e;f--,B+=o[l++]<>>8&255,$[2]=B>>>16&255,$[3]=B>>>24&255,a.check=n(a.check,$,4,0)),B=0,C=0,a.mode=16183;case 16183:for(;C<16;){if(0===f)break e;f--,B+=o[l++]<>8),512&a.flags&&4&a.wrap&&($[0]=255&B,$[1]=B>>>8&255,a.check=n(a.check,$,2,0)),B=0,C=0,a.mode=16184;case 16184:if(1024&a.flags){for(;C<16;){if(0===f)break e;f--,B+=o[l++]<>>8&255,a.check=n(a.check,$,2,0)),B=0,C=0}else a.head&&(a.head.extra=null);a.mode=16185;case 16185:if(1024&a.flags&&(L=a.length,L>f&&(L=f),L&&(a.head&&(J=a.head.extra_len-a.length,a.head.extra||(a.head.extra=new Uint8Array(a.head.extra_len)),a.head.extra.set(o.subarray(l,l+L),J)),512&a.flags&&4&a.wrap&&(a.check=n(a.check,o,L,l)),f-=L,l+=L,a.length-=L),a.length))break e;a.length=0,a.mode=16186;case 16186:if(2048&a.flags){if(0===f)break e;L=0;do{J=o[l+L++],a.head&&J&&a.length<65536&&(a.head.name+=String.fromCharCode(J))}while(J&&L>9&1,a.head.done=!0),e.adler=a.check=0,a.mode=A;break;case 16189:for(;C<32;){if(0===f)break e;f--,B+=o[l++]<>>=7&C,C-=7&C,a.mode=U;break}for(;C<3;){if(0===f)break e;f--,B+=o[l++]<>>=1,C-=1,3&B){case 0:a.mode=16193;break;case 1:if(K(a),a.mode=T,i===b){B>>>=2,C-=2;break e}break;case 2:a.mode=16196;break;case 3:e.msg="invalid block type",a.mode=D}B>>>=2,C-=2;break;case 16193:for(B>>>=7&C,C-=7&C;C<32;){if(0===f)break e;f--,B+=o[l++]<>>16^65535)){e.msg="invalid stored block lengths",a.mode=D;break}if(a.length=65535&B,B=0,C=0,a.mode=S,i===b)break e;case S:a.mode=16195;case 16195:if(L=a.length,L){if(L>f&&(L=f),L>h&&(L=h),0===L)break e;s.set(o.subarray(l,l+L),d),f-=L,l+=L,h-=L,d+=L,a.length-=L;break}a.mode=A;break;case 16196:for(;C<14;){if(0===f)break e;f--,B+=o[l++]<>>=5,C-=5,a.ndist=1+(31&B),B>>>=5,C-=5,a.ncode=4+(15&B),B>>>=4,C-=4,a.nlen>286||a.ndist>30){e.msg="too many length or distance symbols",a.mode=D;break}a.have=0,a.mode=16197;case 16197:for(;a.have>>=3,C-=3}for(;a.have<19;)a.lens[ie[a.have++]]=0;if(a.lencode=a.lendyn,a.lenbits=7,ee={bits:a.lenbits},Q=c(0,a.lens,0,19,a.lencode,0,a.work,ee),a.lenbits=ee.bits,Q){e.msg="invalid code lengths set",a.mode=D;break}a.have=0,a.mode=16198;case 16198:for(;a.have>>24,Y=V>>>16&255,G=65535&V,!(j<=C);){if(0===f)break e;f--,B+=o[l++]<>>=j,C-=j,a.lens[a.have++]=G;else{if(16===G){for(te=j+2;C>>=j,C-=j,0===a.have){e.msg="invalid bit length repeat",a.mode=D;break}J=a.lens[a.have-1],L=3+(3&B),B>>>=2,C-=2}else if(17===G){for(te=j+3;C>>=j,C-=j,J=0,L=3+(7&B),B>>>=3,C-=3}else{for(te=j+7;C>>=j,C-=j,J=0,L=11+(127&B),B>>>=7,C-=7}if(a.have+L>a.nlen+a.ndist){e.msg="invalid bit length repeat",a.mode=D;break}for(;L--;)a.lens[a.have++]=J}}if(a.mode===D)break;if(0===a.lens[256]){e.msg="invalid code -- missing end-of-block",a.mode=D;break}if(a.lenbits=9,ee={bits:a.lenbits},Q=c(1,a.lens,0,a.nlen,a.lencode,0,a.work,ee),a.lenbits=ee.bits,Q){e.msg="invalid literal/lengths set",a.mode=D;break}if(a.distbits=6,a.distcode=a.distdyn,ee={bits:a.distbits},Q=c(2,a.lens,a.nlen,a.ndist,a.distcode,0,a.work,ee),a.distbits=ee.bits,Q){e.msg="invalid distances set",a.mode=D;break}if(a.mode=T,i===b)break e;case T:a.mode=O;case O:if(f>=6&&h>=258){e.next_out=d,e.avail_out=h,e.next_in=l,e.avail_in=f,a.hold=B,a.bits=C,r(e,F),d=e.next_out,s=e.output,h=e.avail_out,l=e.next_in,o=e.input,f=e.avail_in,B=a.hold,C=a.bits,a.mode===A&&(a.back=-1);break}for(a.back=0;V=a.lencode[B&(1<>>24,Y=V>>>16&255,G=65535&V,!(j<=C);){if(0===f)break e;f--,B+=o[l++]<>X)],j=V>>>24,Y=V>>>16&255,G=65535&V,!(X+j<=C);){if(0===f)break e;f--,B+=o[l++]<>>=X,C-=X,a.back+=X}if(B>>>=j,C-=j,a.back+=j,a.length=G,0===Y){a.mode=16205;break}if(32&Y){a.back=-1,a.mode=A;break}if(64&Y){e.msg="invalid literal/length code",a.mode=D;break}a.extra=15&Y,a.mode=16201;case 16201:if(a.extra){for(te=a.extra;C>>=a.extra,C-=a.extra,a.back+=a.extra}a.was=a.length,a.mode=16202;case 16202:for(;V=a.distcode[B&(1<>>24,Y=V>>>16&255,G=65535&V,!(j<=C);){if(0===f)break e;f--,B+=o[l++]<>X)],j=V>>>24,Y=V>>>16&255,G=65535&V,!(X+j<=C);){if(0===f)break e;f--,B+=o[l++]<>>=X,C-=X,a.back+=X}if(B>>>=j,C-=j,a.back+=j,64&Y){e.msg="invalid distance code",a.mode=D;break}a.offset=G,a.extra=15&Y,a.mode=16203;case 16203:if(a.extra){for(te=a.extra;C>>=a.extra,C-=a.extra,a.back+=a.extra}if(a.offset>a.dmax){e.msg="invalid distance too far back",a.mode=D;break}a.mode=16204;case 16204:if(0===h)break e;if(L=F-h,a.offset>L){if(L=a.offset-L,L>a.whave&&a.sane){e.msg="invalid distance too far back",a.mode=D;break}L>a.wnext?(L-=a.wnext,M=a.wsize-L):M=a.wnext-L,L>a.length&&(L=a.length),H=a.window}else H=s,M=d-a.offset,L=a.length;L>h&&(L=h),h-=L,a.length-=L;do{s[d++]=H[M++]}while(--L);0===a.length&&(a.mode=O);break;case 16205:if(0===h)break e;s[d++]=a.length,h--,a.mode=O;break;case U:if(a.wrap){for(;C<32;){if(0===f)break e;f--,B|=o[l++]<{if(N(e))return g;let t=e.state;return t.window&&(t.window=null),e.state=null,m},inflateGetHeader:(e,t)=>{if(N(e))return g;const i=e.state;return 0==(2&i.wrap)?g:(i.head=t,t.done=!1,m)},inflateSetDictionary:(e,i)=>{const n=i.length;let a,r,o;return N(e)?g:(a=e.state,0!==a.wrap&&a.mode!==R?g:a.mode===R&&(r=1,r=t(r,i,n,0),r!==a.check)?p:(o=P(e,i,n,n),o?(a.mode=16210,v):(a.havedict=1,m)))},inflateInfo:"pako inflate (from Nodeca project)"};const G=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var X=function(e){const t=Array.prototype.slice.call(arguments,1);for(;t.length;){const i=t.shift();if(i){if("object"!=typeof i)throw new TypeError(i+"must be non-object");for(const t in i)G(i,t)&&(e[t]=i[t])}}return e},W=e=>{let t=0;for(let i=0,n=e.length;i=252?6:e>=248?5:e>=240?4:e>=224?3:e>=192?2:1;J[254]=J[254]=1;var Q=e=>{if("function"==typeof TextEncoder&&TextEncoder.prototype.encode)return(new TextEncoder).encode(e);let t,i,n,a,r,o=e.length,s=0;for(a=0;a>>6,t[r++]=128|63&i):i<65536?(t[r++]=224|i>>>12,t[r++]=128|i>>>6&63,t[r++]=128|63&i):(t[r++]=240|i>>>18,t[r++]=128|i>>>12&63,t[r++]=128|i>>>6&63,t[r++]=128|63&i);return t},V=(e,t)=>{const i=t||e.length;if("function"==typeof TextDecoder&&TextDecoder.prototype.decode)return(new TextDecoder).decode(e.subarray(0,t));let n,a;const r=new Array(2*i);for(a=0,n=0;n4)r[a++]=65533,n+=o-1;else{for(t&=2===o?31:3===o?15:7;o>1&&n1?r[a++]=65533:t<65536?r[a++]=t:(t-=65536,r[a++]=55296|t>>10&1023,r[a++]=56320|1023&t)}}return((e,t)=>{if(t<65534&&e.subarray&&q)return String.fromCharCode.apply(null,e.length===t?e:e.subarray(0,t));let i="";for(let n=0;n{(t=t||e.length)>e.length&&(t=e.length);let i=t-1;for(;i>=0&&128==(192&e[i]);)i--;return i<0||0===i?t:i+J[e[i]]>t?i:t},ee={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"};var te=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0};var ie=function(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1};const ne=Object.prototype.toString,{Z_NO_FLUSH:ae,Z_FINISH:re,Z_OK:oe,Z_STREAM_END:se,Z_NEED_DICT:le,Z_STREAM_ERROR:de,Z_DATA_ERROR:fe,Z_MEM_ERROR:ce}=h;function he(e){this.options=X({chunkSize:65536,windowBits:15,to:""},e||{});const t=this.options;t.raw&&t.windowBits>=0&&t.windowBits<16&&(t.windowBits=-t.windowBits,0===t.windowBits&&(t.windowBits=-15)),!(t.windowBits>=0&&t.windowBits<16)||e&&e.windowBits||(t.windowBits+=32),t.windowBits>15&&t.windowBits<48&&0==(15&t.windowBits)&&(t.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new te,this.strm.avail_out=0;let i=Y.inflateInit2(this.strm,t.windowBits);if(i!==oe)throw new Error(ee[i]);if(this.header=new ie,Y.inflateGetHeader(this.strm,this.header),t.dictionary&&("string"==typeof t.dictionary?t.dictionary=Q(t.dictionary):"[object ArrayBuffer]"===ne.call(t.dictionary)&&(t.dictionary=new Uint8Array(t.dictionary)),t.raw&&(i=Y.inflateSetDictionary(this.strm,t.dictionary),i!==oe)))throw new Error(ee[i])}function ue(e,t){const i=new he(t);if(i.push(e),i.err)throw i.msg||ee[i.err];return i.result}he.prototype.push=function(e,t){const i=this.strm,n=this.options.chunkSize,a=this.options.dictionary;let r,o,s;if(this.ended)return!1;for(o=t===~~t?t:!0===t?re:ae,"[object ArrayBuffer]"===ne.call(e)?i.input=new Uint8Array(e):i.input=e,i.next_in=0,i.avail_in=i.input.length;;){for(0===i.avail_out&&(i.output=new Uint8Array(n),i.next_out=0,i.avail_out=n),r=Y.inflate(i,o),r===le&&a&&(r=Y.inflateSetDictionary(i,a),r===oe?r=Y.inflate(i,o):r===fe&&(r=le));i.avail_in>0&&r===se&&i.state.wrap>0&&0!==e[i.next_in];)Y.inflateReset(i),r=Y.inflate(i,o);switch(r){case de:case fe:case le:case ce:return this.onEnd(r),this.ended=!0,!1}if(s=i.avail_out,i.next_out&&(0===i.avail_out||r===se))if("string"===this.options.to){let e=$(i.output,i.next_out),t=i.next_out-e,a=V(i.output,e);i.next_out=t,i.avail_out=n-t,t&&i.output.set(i.output.subarray(e,e+t),0),this.onData(a)}else this.onData(i.output.length===i.next_out?i.output:i.output.subarray(0,i.next_out));if(r!==oe||0!==s){if(r===se)return r=Y.inflateEnd(this.strm),this.onEnd(r),this.ended=!0,!0;if(0===i.avail_in)break}}return!0},he.prototype.onData=function(e){this.chunks.push(e)},he.prototype.onEnd=function(e){e===oe&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=W(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};var we=he,be=ue,me=function(e,t){return(t=t||{}).raw=!0,ue(e,t)},ke=ue,_e=h,ge={Inflate:we,inflate:be,inflateRaw:me,ungzip:ke,constants:_e};e.Inflate=we,e.constants=_e,e.default=ge,e.inflate=be,e.inflateRaw=me,e.ungzip=ke,Object.defineProperty(e,"__esModule",{value:!0})}))})(pako_inflate_min,pako_inflate_min.exports);var pako_inflate_minExports=pako_inflate_min.exports;const LITTLE_ENDIAN=true;class DataReader{constructor(buffer){this.dataView=new DataView(buffer);this.position=0}skip(length){this.position+=length}readBytes(length){const type=length===4?"getUint32":length===2?"getUint16":"getUint8";const start=this.position;this.position+=length;return this.dataView[type](start,LITTLE_ENDIAN)}}const LOCAL_FILE_HEADER=67324752;const CENTRAL_DIRECTORY=33639248;const parseZip=buffer=>{const reader=new DataReader(buffer);const files={};while(true){const signature=reader.readBytes(4);if(signature===LOCAL_FILE_HEADER){const file=parseLocalFile(reader);files[file.name]={buffer:file.buffer};continue}if(signature===CENTRAL_DIRECTORY){parseCentralDirectory(reader);continue}break}return files};const parseLocalFile=reader=>{let i=0;let data;reader.skip(4);const compression=reader.readBytes(2);reader.skip(8);const compressedSize=reader.readBytes(4);reader.skip(4);const filenameLength=reader.readBytes(2);const extraFieldLength=reader.readBytes(2);const filename=[];const compressedData=new Uint8Array(compressedSize);for(i=0;i{reader.skip(24);const filenameLength=reader.readBytes(2);const extraFieldLength=reader.readBytes(2);const fileCommentLength=reader.readBytes(2);reader.skip(12);reader.skip(filenameLength);reader.skip(extraFieldLength);reader.skip(fileCommentLength)};const ZipLoader=class ZipLoader{static unzip(blobOrFile){return new Promise((resolve=>{const instance=new ZipLoader;const fileReader=new FileReader;fileReader.onload=event=>{const arrayBuffer=event.target.result;instance.files=parseZip(arrayBuffer);resolve(instance)};if(blobOrFile instanceof Blob){fileReader.readAsArrayBuffer(blobOrFile)}}))}constructor(url,fetchOptions={}){this._listeners={};this.url=url;this.fetchOptions=fetchOptions;this.files=null}async load(){this.clear();const startTime=Date.now();const res=await fetch(this.url,this.fetchOptions).then((res=>{const that=this;const total=parseInt(res.headers.get("content-length"),10);let loaded=0;return new Response(new ReadableStream({start(controller){const reader=res.body.getReader();const pump=async()=>{const{done:done,value:value}=await reader.read();if(done){controller.close();return}loaded+=value.byteLength;controller.enqueue(value);that.dispatch({type:"progress",loaded:loaded,total:total,elapsedTime:Date.now()-startTime});pump()};pump()}}))})).catch((error=>{this.dispatch({type:"error",error:error})}));const arrayBuffer=await res.arrayBuffer();this.files=parseZip(arrayBuffer);this.dispatch({type:"load",elapsedTime:Date.now()-startTime});return this.files}extractAsBlobUrl(filename,type){if(this.files[filename].url){return this.files[filename].url}const blob=new Blob([this.files[filename].buffer],{type:type});this.files[filename].url=URL.createObjectURL(blob);return this.files[filename].url}extractAsText(filename){const buffer=this.files[filename].buffer;if(typeof TextDecoder!=="undefined"){return(new TextDecoder).decode(buffer)}let str="";for(let i=0,l=buffer.length;i 2 | 3 | 4 | 5 | =^.^= 6 | 12 | 13 | 14 |

index

15 |

Load 495 PNGs in one http request

16 |

Zip archive can contain multiple files. That mean you don't need to concern about number of http connections.

17 | 18 | 19 | 20 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /examples/496_RPG_icons.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yomotsu/ZipLoader/3075ed397fef2ba23e2415a7b65def9d1b6753f3/examples/496_RPG_icons.zip -------------------------------------------------------------------------------- /examples/basic.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | =^.^= 6 | 7 | 8 |

index

9 |

Check to see your console!

10 |

"basic.zip" which was loaded in this demo contains a JSON file, and it will be extracted into your console.

11 | 12 |

You can compare with original JSON file, that can be seen here

13 | 14 | 15 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /examples/basic.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yomotsu/ZipLoader/3075ed397fef2ba23e2415a7b65def9d1b6753f3/examples/basic.zip -------------------------------------------------------------------------------- /examples/basic/data.json: -------------------------------------------------------------------------------- 1 | { 2 | "someText": "hello!", 3 | "someNumber": 1, 4 | "yesOrNo": true 5 | } 6 | -------------------------------------------------------------------------------- /examples/direct-unzip.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | =^.^= 6 | 7 | 8 |

index

9 |

Select a zip file to extract

10 | 11 | select a zip file
12 |
13 | 14 | 15 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /examples/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | ZipLoader.js 6 | 8 | 9 | 10 | 11 |

GitHub repo

12 | 13 |

zip-loader.js

14 | 15 |

demos

16 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /examples/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /examples/mixed.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | =^.^= 6 | 35 | 36 | 37 |

index

38 |

Multiple file types in 1 zip file

39 | 40 | 41 |
42 |
JPEG image
43 |
44 |
45 | 46 |
47 |
SVG image
48 |
49 |
50 | 51 |
52 |
Video
53 |
54 |
55 | 56 |
57 |
Audio
58 |
59 |
60 | 61 |
62 |
Text
63 |

 64 | 
65 | 66 |
67 |
JSON
68 |

 69 | 
70 | 71 | 72 | 73 | 74 | 178 | 179 | 180 | 181 | -------------------------------------------------------------------------------- /examples/mixed.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yomotsu/ZipLoader/3075ed397fef2ba23e2415a7b65def9d1b6753f3/examples/mixed.zip -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "zip-loader", 3 | "version": "1.3.0", 4 | "author": "Yomotsu", 5 | "license": "MIT", 6 | "repository": "yomotsu/ZipLoader", 7 | "main": "dist/zip-loader.js", 8 | "jsnext:main": "dist/zip-loader.module.js", 9 | "module": "dist/zip-loader.module.js", 10 | "types": "dist/ZipLoader.d.ts", 11 | "dependencies": { 12 | "pako": "^2.1.0" 13 | }, 14 | "devDependencies": { 15 | "@rollup/plugin-commonjs": "^25.0.7", 16 | "@rollup/plugin-node-resolve": "^15.2.3", 17 | "rollup": "^4.14.2", 18 | "terser": "^5.30.3", 19 | "typescript": "^5.4.5" 20 | }, 21 | "scripts": { 22 | "dev": "rollup --config --watch", 23 | "build": "rollup --config && terser 'dist/zip-loader.js' -o 'dist/zip-loader.min.js' --comments '/^!/' && terser 'dist/zip-loader.module.js' -o 'dist/zip-loader.module.min.js' --comments '/^!/'", 24 | "types": "tsc -p src/ZipLoader.js --declaration --allowJs --emitDeclarationOnly --outDir dist" 25 | }, 26 | "browserslist": [ 27 | "> 1%", 28 | "last 3 versions", 29 | "not dead" 30 | ] 31 | } 32 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # ZipLoader 2 | 3 | ZipLoader is a light weight zip file loader and unzipper for Web browsers. 4 | (only 25KB (gzipped 9KB) ) 5 | 6 | Plus, It makes easy to make loading progress bar. 7 | 8 | [![Latest NPM release](https://img.shields.io/npm/v/zip-loader.svg)](https://www.npmjs.com/package/zip-loader) 9 | ![MIT License](https://img.shields.io/npm/l/zip-loader.svg) 10 | [![dependencies Status](https://david-dm.org/yomotsu/ZipLoader/status.svg)](https://david-dm.org/yomotsu/ZipLoader) 11 | [![devDependencies Status](https://david-dm.org/yomotsu/ZipLoader/dev-status.svg)](https://david-dm.org/yomotsu/ZipLoader?type=dev) 12 | 13 | [Demos can be seen here](https://yomotsu.github.io/ZipLoader/examples/). 14 | 15 | ## Usage 16 | 17 | Both standalone version and [NPM module](https://www.npmjs.com/package/zip-loader) version are available. 18 | 19 | ### Standalone 20 | 21 | Copy zip-loader.js from `/dist/zip-loader.js` and place it in your project. 22 | ```html 23 | 24 | ``` 25 | 26 | ### NPM 27 | ``` 28 | $ npm install --save zip-loader 29 | ``` 30 | 31 | then 32 | ```javascript 33 | import ZipLoader from 'zip-loader'; 34 | ``` 35 | 36 | ## To load and unzip 37 | 38 | Make a loader instance with a target zip url. Then, `load()` it. 39 | 40 | ```javascript 41 | const fetchOptions = { /* same as the second argument of `fetch()` */} 42 | const loader = new ZipLoader( './foldername.zip', fetchOptions ); 43 | loader.load(); 44 | ``` 45 | 46 | You can track the loading progress through the `'progress'` event. 47 | Once complete, the zip file is automatically unzipped, and the `'load'` event is triggered. 48 | As a result, the instance will include a `files` property, which contains the filename and binary buffer 49 | 50 | ```javascript 51 | const loader = new ZipLoader( './foldername.zip' ); 52 | 53 | loader.on( 'progress', ( event ) => { 54 | 55 | console.log( 'loading', event.loaded, event.total ); 56 | 57 | } ); 58 | 59 | loader.on( 'load', ( event ) => { 60 | 61 | console.log( 'loaded!' ); 62 | console.log( loader.files ); 63 | 64 | const json = loader.extractAsJSON( 'foldername/data.json' ); 65 | console.log( json ); 66 | 67 | } ); 68 | 69 | loader.on( 'error', ( event ) => { 70 | 71 | console.log( 'error', event.error ); 72 | 73 | } ); 74 | 75 | loader.load(); 76 | ``` 77 | 78 | It also returns a `Promise`. 79 | 80 | ```javascript 81 | const loader = new ZipLoader( './foldername.zip' ); 82 | 83 | await loader.load(); 84 | 85 | console.log( 'loaded!' ); 86 | console.log( loader.files ); 87 | 88 | const json = loader.extractAsJSON( 'foldername/data.json' ); 89 | console.log( json ); 90 | ``` 91 | 92 | ## unzip Blob/File directly 93 | 94 | ```javascript 95 | const zipLoaderInstance = await ZipLoader.unzip( blobOrFile ); 96 | console.log( zipLoaderInstance.files ); 97 | ``` 98 | 99 | ## Pick up unzipped files 100 | 101 | There are 3 (+1) ways to pick up unzipped files. 102 | 103 | - as a text. 104 | - as a JSON. 105 | - as an URL (for ``, `