2 lines
7.9 KiB
JavaScript
2 lines
7.9 KiB
JavaScript
|
var U=Uint8Array,b=Uint16Array,rr=Uint32Array,er=new U([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,0,0,0]),fr=new U([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,0,0]),hr=new U([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Ar=function(r,a){for(var v=new b(31),n=0;n<31;++n)v[n]=a+=1<<r[n-1];for(var f=new rr(v[30]),n=1;n<30;++n)for(var i=v[n];i<v[n+1];++i)f[i]=i-v[n]<<5|n;return[v,f]},Cr=Ar(er,2),Er=Cr[0],ur=Cr[1];Er[28]=258,ur[258]=28;var Or=Ar(fr,0),br=Or[0],sr=Or[1],cr=new b(32768);for(var c=0;c<32768;++c){var $=(c&43690)>>>1|(c&21845)<<1;$=($&52428)>>>2|($&13107)<<2,$=($&61680)>>>4|($&3855)<<4,cr[c]=(($&65280)>>>8|($&255)<<8)>>>1}var Y=function(r,a,v){for(var n=r.length,f=0,i=new b(a);f<n;++f)++i[r[f]-1];var h=new b(a);for(f=0;f<a;++f)h[f]=h[f-1]+i[f-1]<<1;var u;if(v){u=new b(1<<a);var l=15-a;for(f=0;f<n;++f)if(r[f])for(var w=f<<4|r[f],e=a-r[f],g=h[r[f]-1]++<<e,M=g|(1<<e)-1;g<=M;++g)u[cr[g]>>>l]=w}else for(u=new b(n),f=0;f<n;++f)u[f]=cr[h[r[f]-1]++]>>>15-r[f];return u},_=new U(288);for(var c=0;c<144;++c)_[c]=8;for(var c=144;c<256;++c)_[c]=9;for(var c=256;c<280;++c)_[c]=7;for(var c=280;c<288;++c)_[c]=8;var ar=new U(32);for(var c=0;c<32;++c)ar[c]=5;var qr=Y(_,9,0),Br=Y(_,9,1),Tr=Y(ar,5,0),yr=Y(ar,5,1),lr=function(r){for(var a=r[0],v=1;v<r.length;++v)r[v]>a&&(a=r[v]);return a},Q=function(r,a,v){var n=a/8>>0;return(r[n]|r[n+1]<<8)>>>(a&7)&v},or=function(r,a){var v=a/8>>0;return(r[v]|r[v+1]<<8|r[v+2]<<16)>>>(a&7)},gr=function(r){return(r/8>>0)+(r&7&&1)},Sr=function(r,a,v){(a==null||a<0)&&(a=0),(v==null||v>r.length)&&(v=r.length);var n=new(r instanceof b?b:r instanceof rr?rr:U)(v-a);return n.set(r.subarray(a,v)),n},Dr=function(r,a,v){var n=r.length,f=!a||v,i=!v||v.i;v||(v={}),a||(a=new U(n*3));var h=function(vr){var m=a.length;if(vr>m){var L=new U(Math.max(m*2,vr));L.set(a),a=L}},u=v.f||0,l=v.p||0,w=v.b||0,e=v.l,g=v.d,M=v.m,t=v.n,C=n*8;do{if(!e){v.f=u=Q(r,l,1);var z=Q(r,l+1,3);if(l+=3,z)if(z==1)e=Br,g=yr,M=9,t=5;else if(z==2){var R=Q(r,l,31)+257,K=Q(r,l+10,15)+4,B=R+Q(r,l+5,31)+1;l+=14;for(var A=new U(B),x=new U(19),o=0;o<K;++o)x[hr[o]]=Q(r,l+o*3,7);l+=K*3;var N=lr(x),T=(1<<N)-1;if(!i&&l+B*(N+7)>C)break;for(var j=Y(x,N,1),o=0;o<B;){var E=j[Q(r,l,T)];l+=E&15;var F=E>>>4;if(F<16)A[o++]=F;else{var G=0,O=0;for(F==16?(O=3+Q(r,l,3),l+=2,G=A[o-1]):F==17?(O=3+Q(r,l,7),l+=3):F==18&&(O=11+Q(r,l,127),l+=7);O--;)A[o++]=G}}var y=A.subarray(0,R),s=A.subarray(R);M=lr(y),t=lr(s),e=Y(y,M,1),g=Y(s,t,1)}else throw"invalid block type";else{var F=gr(l)+4,J=r[F-4]|r[F-3]<<8,q=F+J;if(q>n){if(i)throw"unexpected EOF";break}f&&h(w+J),a.set(r.subarray(F,q),w),v.b=w+=J,v.p=l=q*8;continue}if(l>C)throw"unexpected EOF"}f&&h(w+131072);for(var k=(1<<M)-1,H=(1<<t)-1,V=M+t+18;i||l+V<C;){var G=e[or(r,l)&k],W=G>>>4;if(l+=G&15,l>C)throw"unexpected EOF";if(!G)throw"invalid length/literal";if(W<256)a[w++]=W;else if(W==256){e=null;break}else{var I=W-254;if(W>264){var o=W-257,P=er[o];I=Q(r,l,(1<<P)-1)+Er[o],l+=P}var X=g[or(r,l)&H],D=X>>>4;if(!X)throw"invalid distance";l+=X&15;var s=br[D];if(D>3){var P=fr[D];s+=or(r,l)&(1<<P)-1,l+=P}if(l>C)throw"unexpected EOF";f&&h(w+131072);for(var S=w+I;w<S;w+=4)a[w]=a[w-s],a[w+1]=a[w+1-s],a[w+2]=a[w+2-s],a[w+3]=a[w+3-s];w=S}}v.l=e,v.p=l,v.b=w,e&&(u=1,v.m=M,v.d=g,v.n=t)}while(!u);return w==a.length?a:Sr(a,0,w)},Z=function(r,a,v){v<<=a&7;var n=a/8>>0;r[n]|=v,r[n+1]|=v>>>8},p=function(r,a,v){v<<=a&7;var n=a/8>>0;r[n]|=v,r[n+1]|=v>>>8,r[n+2]|=v>>>16},wr=function(r,a){for(var v=[],n=0;n<r.length;++n)r[n]&&v.push({s:n,f:r[n]});var f=v.length,i=v.slice();if(!f)return[new U(0),0];if(f==1){var h=new U(v[0].s+1);return h[v[0].s]=1,[h,1]}v.sort(function(B,A){return B.f-A.f}),v.push({s:-1,f:25001});var u=v[0],l=v[1],w=0,e=1,g=2;for(v[0]={s:-1,f:u.f+l.f,l:u,r:l};e!=f-1;)u=v[v[w].f<v[g].f?w++:g++],l=v[w!=e&&v[w].f<v[g].f?w++:g++],v[e++]={s:-1,f:u.f+l.f,l:u,r:l};for(var M=i[0].s,n=1;n<f;++n)i[n].s>M&&(M=i[n].s);var t=new b(M+1),C=tr(v[e-1],t,0);if(C>a){var n=0,z=0,F=C-a,J=1<<F;for(i.sort(function(A,x){return t[x.s]-t[A.s]||A.f-x.f});n<f;++n){var q=i[n].s;if(t[q]>a)z+=J-(1<<C-t[q]),t[q]=a;else break}for
|