-
Notifications
You must be signed in to change notification settings - Fork 55
/
jszip-deflate.js
1 lines (1 loc) · 11.4 KB
/
jszip-deflate.js
1
if(!JSZip){throw"JSZip not defined"}(function(){var ak=32768;var aT=0;var e=1;var bo=2;var bf=6;var N=true;var a5=32768;var bd=64;var bt=1024*8;var aX=2*ak;var X=3;var bs=258;var B=16;var U=8192;var g=13;if(U>a5){alert("error: zip_INBUFSIZ is too small")}if((ak<<1)>(1<<B)){alert("error: zip_WSIZE is too large")}if(g>B-1){alert("error: zip_HASH_BITS is too large")}if(g<8||bs!=258){alert("error: Code too clever")}var a1=U;var au=1<<g;var a6=au-1;var aS=ak-1;var S=0;var V=4096;var bq=bs+X+1;var z=ak-bq;var p=1;var by=15;var aL=7;var aA=29;var K=256;var P=256;var al=K+1+aA;var bn=30;var s=19;var bg=16;var aR=17;var bu=18;var bm=2*al+1;var aD=parseInt((g+X-1)/X);var aq;var bx,i;var L;var aZ=null;var a4,a3;var d;var bl;var c;var an;var y;var aj;var ap;var a7;var ai;var q;var Z;var aa;var aF;var bh;var O;var r;var x;var Y;var I;var aC;var k;var n;var F;var aU;var D;var l;var at;var af;var E;var j;var C;var bb;var f;var m;var aI;var bk;var W;var bp;var br;var az;var M;var a;var aw;var aW;var G;var w;var ad;var aQ;var be;var b;var bA=function(){this.fc=0;this.dl=0};var o=function(){this.dyn_tree=null;this.static_tree=null;this.extra_bits=null;this.extra_base=0;this.elems=0;this.max_length=0;this.max_code=0};var R=function(bF,bE,bH,bG){this.good_length=bF;this.max_lazy=bE;this.nice_length=bH;this.max_chain=bG};var bi=function(){this.next=null;this.len=0;this.ptr=new Array(bt);this.off=0};var aE=new Array(0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0);var u=new Array(0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13);var J=new Array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7);var aG=new Array(16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15);var aP=new Array(new R(0,0,0,0),new R(4,4,8,4),new R(4,5,16,8),new R(4,6,32,32),new R(4,4,16,16),new R(8,16,32,32),new R(8,16,128,128),new R(8,32,128,256),new R(32,128,258,1024),new R(32,258,258,4096));var ab=function(bF){var bE;if(!bF){bF=bf}else{if(bF<1){bF=1}else{if(bF>9){bF=9}}}k=bF;L=false;x=false;if(aZ!=null){return}aq=bx=i=null;aZ=new Array(bt);bl=new Array(aX);c=new Array(a1);an=new Array(a5+bd);y=new Array(1<<B);aU=new Array(bm);for(bE=0;bE<bm;bE++){aU[bE]=new bA()}D=new Array(2*bn+1);for(bE=0;bE<2*bn+1;bE++){D[bE]=new bA()}l=new Array(al+2);for(bE=0;bE<al+2;bE++){l[bE]=new bA()}at=new Array(bn);for(bE=0;bE<bn;bE++){at[bE]=new bA()}af=new Array(2*s+1);for(bE=0;bE<2*s+1;bE++){af[bE]=new bA()}E=new o();j=new o();C=new o();bb=new Array(by+1);f=new Array(2*al+1);bk=new Array(2*al+1);W=new Array(bs-X+1);bp=new Array(512);br=new Array(aA);az=new Array(bn);M=new Array(parseInt(U/8))};var ay=function(){aq=bx=i=null;aZ=null;bl=null;c=null;an=null;y=null;aU=null;D=null;l=null;at=null;af=null;E=null;j=null;C=null;bb=null;f=null;bk=null;W=null;bp=null;br=null;az=null;M=null};var av=function(bE){bE.next=aq;aq=bE};var T=function(){var bE;if(aq!=null){bE=aq;aq=aq.next}else{bE=new bi()}bE.next=null;bE.len=bE.off=0;return bE};var ah=function(bE){return y[ak+bE]};var ag=function(bE,bF){return y[ak+bE]=bF};var Q=function(bE){aZ[a3+a4++]=bE;if(a3+a4==bt){h()}};var aN=function(bE){bE&=65535;if(a3+a4<bt-2){aZ[a3+a4++]=(bE&255);aZ[a3+a4++]=(bE>>>8)}else{Q(bE&255);Q(bE>>>8)}};var aB=function(){ai=((ai<<aD)^(bl[O+X-1]&255))&a6;q=ah(ai);y[O&aS]=q;ag(ai,O)};var bc=function(bF,bE){bv(bE[bF].fc,bE[bF].dl)};var aK=function(bE){return(bE<256?bp[bE]:bp[256+(bE>>7)])&255};var ae=function(bF,bG,bE){return bF[bG].fc<bF[bE].fc||(bF[bG].fc==bF[bE].fc&&bk[bG]<=bk[bE])};var ba=function(bH,bF,bG){var bE;for(bE=0;bE<bG&&b<be.length;bE++){bH[bF+bE]=be.charCodeAt(b++)&255}return bE};var bz=function(){var bE;for(bE=0;bE<au;bE++){y[ak+bE]=0}aC=aP[k].max_lazy;n=aP[k].good_length;if(!N){F=aP[k].nice_length}I=aP[k].max_chain;O=0;a7=0;Y=ba(bl,0,2*ak);if(Y<=0){x=true;Y=0;return}x=false;while(Y<bq&&!x){ac()}ai=0;for(bE=0;bE<X-1;bE++){ai=((ai<<aD)^(bl[bE]&255))&a6}};var a9=function(bJ){var bL=I;var bG=O;var bH;var bK;var bF=bh;var bI=(O>z?O-z:S);var bE=O+bs;var bN=bl[bG+bF-1];var bM=bl[bG+bF];if(bh>=n){bL>>=2}do{bH=bJ;if(bl[bH+bF]!=bM||bl[bH+bF-1]!=bN||bl[bH]!=bl[bG]||bl[++bH]!=bl[bG+1]){continue}bG+=2;bH++;do{}while(bl[++bG]==bl[++bH]&&bl[++bG]==bl[++bH]&&bl[++bG]==bl[++bH]&&bl[++bG]==bl[++bH]&&bl[++bG]==bl[++bH]&&bl[++bG]==bl[++bH]&&bl[++bG]==bl[++bH]&&bl[++bG]==bl[++bH]&&bG<bE);bK=bs-(bE-bG);bG=bE-bs;if(bK>bF){r=bJ;bF=bK;if(N){if(bK>=bs){break}}else{if(bK>=F){break}}bN=bl[bG+bF-1];bM=bl[bG+bF]}}while((bJ=y[bJ&aS])>bI&&--bL!=0);return bF};var ac=function(){var bG,bE;var bF=aX-Y-O;if(bF==-1){bF--}else{if(O>=ak+z){for(bG=0;bG<ak;bG++){bl[bG]=bl[bG+ak]}r-=ak;O-=ak;a7-=ak;for(bG=0;bG<au;bG++){bE=ah(bG);ag(bG,bE>=ak?bE-ak:S)}for(bG=0;bG<ak;bG++){bE=y[bG];y[bG]=(bE>=ak?bE-ak:S)}bF+=ak}}if(!x){bG=ba(bl,O+Y,bF);if(bG<=0){x=true}else{Y+=bG}}};var bw=function(){while(Y!=0&&bx==null){var bE;aB();if(q!=S&&O-q<=z){aF=a9(q);if(aF>Y){aF=Y}}if(aF>=X){bE=bj(O-r,aF-X);Y-=aF;if(aF<=aC){aF--;do{O++;aB()}while(--aF!=0);O++}else{O+=aF;aF=0;ai=bl[O]&255;ai=((ai<<aD)^(bl[O+1]&255))&a6}}else{bE=bj(0,bl[O]&255);Y--;O++}if(bE){t(0);a7=O}while(Y<bq&&!x){ac()}}};var aV=function(){while(Y!=0&&bx==null){aB();bh=aF;Z=r;aF=X-1;if(q!=S&&bh<aC&&O-q<=z){aF=a9(q);if(aF>Y){aF=Y}if(aF==X&&O-r>V){aF--}}if(bh>=X&&aF<=bh){var bE;bE=bj(O-1-Z,bh-X);Y-=bh-1;bh-=2;do{O++;aB()}while(--bh!=0);aa=0;aF=X-1;O++;if(bE){t(0);a7=O}}else{if(aa!=0){if(bj(0,bl[O-1]&255)){t(0);a7=O}O++;Y--}else{aa=1;O++;Y--}}while(Y<bq&&!x){ac()}}};var aJ=function(){if(x){return}aj=0;ap=0;aY();bz();bx=null;a4=0;a3=0;if(k<=3){bh=X-1;aF=0}else{aF=X-1;aa=0}d=false};var v=function(bH,bF,bE){var bG;if(!L){aJ();L=true;if(Y==0){d=true;return 0}}if((bG=bB(bH,bF,bE))==bE){return bE}if(d){return bG}if(k<=3){bw()}else{aV()}if(Y==0){if(aa!=0){bj(0,bl[O-1]&255)}t(1);d=true}return bG+bB(bH,bG+bF,bE-bG)};var bB=function(bK,bI,bF){var bJ,bG,bE;bJ=0;while(bx!=null&&bJ<bF){bG=bF-bJ;if(bG>bx.len){bG=bx.len}for(bE=0;bE<bG;bE++){bK[bI+bJ+bE]=bx.ptr[bx.off+bE]}bx.off+=bG;bx.len-=bG;bJ+=bG;if(bx.len==0){var bH;bH=bx;bx=bx.next;av(bH)}}if(bJ==bF){return bJ}if(a3<a4){bG=bF-bJ;if(bG>a4-a3){bG=a4-a3}for(bE=0;bE<bG;bE++){bK[bI+bJ+bE]=aZ[a3+bE]}a3+=bG;bJ+=bG;if(a4==a3){a4=a3=0}}return bJ};var aY=function(){var bI;var bG;var bF;var bE;var bH;if(at[0].dl!=0){return}E.dyn_tree=aU;E.static_tree=l;E.extra_bits=aE;E.extra_base=K+1;E.elems=al;E.max_length=by;E.max_code=0;j.dyn_tree=D;j.static_tree=at;j.extra_bits=u;j.extra_base=0;j.elems=bn;j.max_length=by;j.max_code=0;C.dyn_tree=af;C.static_tree=null;C.extra_bits=J;C.extra_base=0;C.elems=s;C.max_length=aL;C.max_code=0;bF=0;for(bE=0;bE<aA-1;bE++){br[bE]=bF;for(bI=0;bI<(1<<aE[bE]);bI++){W[bF++]=bE}}W[bF-1]=bE;bH=0;for(bE=0;bE<16;bE++){az[bE]=bH;for(bI=0;bI<(1<<u[bE]);bI++){bp[bH++]=bE}}bH>>=7;for(;bE<bn;bE++){az[bE]=bH<<7;for(bI=0;bI<(1<<(u[bE]-7));bI++){bp[256+bH++]=bE}}for(bG=0;bG<=by;bG++){bb[bG]=0}bI=0;while(bI<=143){l[bI++].dl=8;bb[8]++}while(bI<=255){l[bI++].dl=9;bb[9]++}while(bI<=279){l[bI++].dl=7;bb[7]++}while(bI<=287){l[bI++].dl=8;bb[8]++}a2(l,al+1);for(bI=0;bI<bn;bI++){at[bI].dl=5;at[bI].fc=ao(bI,5)}ar()};var ar=function(){var bE;for(bE=0;bE<al;bE++){aU[bE].fc=0}for(bE=0;bE<bn;bE++){D[bE].fc=0}for(bE=0;bE<s;bE++){af[bE].fc=0}aU[P].fc=1;ad=aQ=0;a=aw=aW=0;G=0;w=1};var H=function(bE,bG){var bF=f[bG];var bH=bG<<1;while(bH<=m){if(bH<m&&ae(bE,f[bH+1],f[bH])){bH++}if(ae(bE,bF,f[bH])){break}f[bG]=f[bH];bG=bH;bH<<=1}f[bG]=bF};var am=function(bM){var bR=bM.dyn_tree;var bH=bM.extra_bits;var bE=bM.extra_base;var bN=bM.max_code;var bP=bM.max_length;var bQ=bM.static_tree;var bK;var bF,bG;var bO;var bJ;var bL;var bI=0;for(bO=0;bO<=by;bO++){bb[bO]=0}bR[f[aI]].dl=0;for(bK=aI+1;bK<bm;bK++){bF=f[bK];bO=bR[bR[bF].dl].dl+1;if(bO>bP){bO=bP;bI++}bR[bF].dl=bO;if(bF>bN){continue}bb[bO]++;bJ=0;if(bF>=bE){bJ=bH[bF-bE]}bL=bR[bF].fc;ad+=bL*(bO+bJ);if(bQ!=null){aQ+=bL*(bQ[bF].dl+bJ)}}if(bI==0){return}do{bO=bP-1;while(bb[bO]==0){bO--}bb[bO]--;bb[bO+1]+=2;bb[bP]--;bI-=2}while(bI>0);for(bO=bP;bO!=0;bO--){bF=bb[bO];while(bF!=0){bG=f[--bK];if(bG>bN){continue}if(bR[bG].dl!=bO){ad+=(bO-bR[bG].dl)*bR[bG].fc;bR[bG].fc=bO}bF--}}};var a2=function(bF,bK){var bH=new Array(by+1);var bG=0;var bI;var bJ;for(bI=1;bI<=by;bI++){bG=((bG+bb[bI-1])<<1);bH[bI]=bG}for(bJ=0;bJ<=bK;bJ++){var bE=bF[bJ].dl;if(bE==0){continue}bF[bJ].fc=ao(bH[bE]++,bE)}};var a8=function(bJ){var bM=bJ.dyn_tree;var bL=bJ.static_tree;var bE=bJ.elems;var bF,bH;var bK=-1;var bG=bE;m=0;aI=bm;for(bF=0;bF<bE;bF++){if(bM[bF].fc!=0){f[++m]=bK=bF;bk[bF]=0}else{bM[bF].dl=0}}while(m<2){var bI=f[++m]=(bK<2?++bK:0);bM[bI].fc=1;bk[bI]=0;ad--;if(bL!=null){aQ-=bL[bI].dl}}bJ.max_code=bK;for(bF=m>>1;bF>=1;bF--){H(bM,bF)}do{bF=f[p];f[p]=f[m--];H(bM,p);bH=f[p];f[--aI]=bF;f[--aI]=bH;bM[bG].fc=bM[bF].fc+bM[bH].fc;if(bk[bF]>bk[bH]+1){bk[bG]=bk[bF]}else{bk[bG]=bk[bH]+1}bM[bF].dl=bM[bH].dl=bG;f[p]=bG++;H(bM,p)}while(m>=2);f[--aI]=f[p];am(bJ);a2(bM,bK)};var ax=function(bM,bL){var bF;var bJ=-1;var bE;var bH=bM[0].dl;var bI=0;var bG=7;var bK=4;if(bH==0){bG=138;bK=3}bM[bL+1].dl=65535;for(bF=0;bF<=bL;bF++){bE=bH;bH=bM[bF+1].dl;if(++bI<bG&&bE==bH){continue}else{if(bI<bK){af[bE].fc+=bI}else{if(bE!=0){if(bE!=bJ){af[bE].fc++}af[bg].fc++}else{if(bI<=10){af[aR].fc++}else{af[bu].fc++}}}}bI=0;bJ=bE;if(bH==0){bG=138;bK=3}else{if(bE==bH){bG=6;bK=3}else{bG=7;bK=4}}}};var aH=function(bM,bL){var bF;var bJ=-1;var bE;var bH=bM[0].dl;var bI=0;var bG=7;var bK=4;if(bH==0){bG=138;bK=3}for(bF=0;bF<=bL;bF++){bE=bH;bH=bM[bF+1].dl;if(++bI<bG&&bE==bH){continue}else{if(bI<bK){do{bc(bE,af)}while(--bI!=0)}else{if(bE!=0){if(bE!=bJ){bc(bE,af);bI--}bc(bg,af);bv(bI-3,2)}else{if(bI<=10){bc(aR,af);bv(bI-3,3)}else{bc(bu,af);bv(bI-11,7)}}}}bI=0;bJ=bE;if(bH==0){bG=138;bK=3}else{if(bE==bH){bG=6;bK=3}else{bG=7;bK=4}}}};var A=function(){var bE;ax(aU,E.max_code);ax(D,j.max_code);a8(C);for(bE=s-1;bE>=3;bE--){if(af[aG[bE]].dl!=0){break}}ad+=3*(bE+1)+5+5+4;return bE};var bD=function(bF,bE,bG){var bH;bv(bF-257,5);bv(bE-1,5);bv(bG-4,4);for(bH=0;bH<bG;bH++){bv(af[aG[bH]].dl,3)}aH(aU,bF-1);aH(D,bE-1)};var t=function(bE){var bG,bF;var bI;var bJ;bJ=O-a7;M[aW]=G;a8(E);a8(j);bI=A();bG=(ad+3+7)>>3;bF=(aQ+3+7)>>3;if(bF<=bG){bG=bF}if(bJ+4<=bG&&a7>=0){var bH;bv((aT<<1)+bE,3);bC();aN(bJ);aN(~bJ);for(bH=0;bH<bJ;bH++){Q(bl[a7+bH])}}else{if(bF==bG){bv((e<<1)+bE,3);aM(l,at)}else{bv((bo<<1)+bE,3);bD(E.max_code+1,j.max_code+1,bI+1);aM(aU,D)}}ar();if(bE!=0){bC()}};var bj=function(bI,bG){an[a++]=bG;if(bI==0){aU[bG].fc++}else{bI--;aU[W[bG]+K+1].fc++;D[aK(bI)].fc++;c[aw++]=bI;G|=w}w<<=1;if((a&7)==0){M[aW++]=G;G=0;w=1}if(k>2&&(a&4095)==0){var bE=a*8;var bH=O-a7;var bF;for(bF=0;bF<bn;bF++){bE+=D[bF].fc*(5+u[bF])}bE>>=3;if(aw<parseInt(a/2)&&bE<parseInt(bH/2)){return true}}return(a==U-1||aw==a1)};var aM=function(bK,bI){var bM;var bF;var bG=0;var bN=0;var bJ=0;var bL=0;var bE;var bH;if(a!=0){do{if((bG&7)==0){bL=M[bJ++]}bF=an[bG++]&255;if((bL&1)==0){bc(bF,bK)}else{bE=W[bF];bc(bE+K+1,bK);bH=aE[bE];if(bH!=0){bF-=br[bE];bv(bF,bH)}bM=c[bN++];bE=aK(bM);bc(bE,bI);bH=u[bE];if(bH!=0){bM-=az[bE];bv(bM,bH)}}bL>>=1}while(bG<a)}bc(P,bK)};var a0=16;var bv=function(bF,bE){if(ap>a0-bE){aj|=(bF<<ap);aN(aj);aj=(bF>>(a0-ap));ap+=bE-a0}else{aj|=bF<<ap;ap+=bE}};var ao=function(bG,bE){var bF=0;do{bF|=bG&1;bG>>=1;bF<<=1}while(--bE>0);return bF>>1};var bC=function(){if(ap>8){aN(aj)}else{if(ap>0){Q(aj)}}aj=0;ap=0};var h=function(){if(a4!=0){var bF,bE;bF=T();if(bx==null){bx=i=bF}else{i=i.next=bF}bF.len=a4-a3;for(bE=0;bE<bF.len;bE++){bF.ptr[bE]=aZ[a3+bE]}a4=a3=0}};var aO=function(bI,bK){var bG,bF;be=bI;b=0;if(typeof bK=="undefined"){bK=bf}ab(bK);var bJ=new Array(1024);var bH=[];while((bG=v(bJ,0,bJ.length))>0){var bE=new Array(bG);for(bF=0;bF<bG;bF++){bE[bF]=String.fromCharCode(bJ[bF])}bH[bH.length]=bE.join("")}be=null;return bH.join("")};JSZip.compressions.DEFLATE={magic:"\x08\x00",compress:function(bE){return aO(bE)}}})();