Switched to zlib.js, all tests passing
This commit is contained in:
parent
c9cb4b4bdb
commit
16c64d1ca2
|
@ -0,0 +1,31 @@
|
||||||
|
/** @license zlib.js 2012 - imaya [ https://github.com/imaya/zlib.js ] The MIT License */(function() {'use strict';function m(a){throw a;}var q=void 0,u,aa=this;function v(a,b){var c=a.split("."),d=aa;!(c[0]in d)&&d.execScript&&d.execScript("var "+c[0]);for(var f;c.length&&(f=c.shift());)!c.length&&b!==q?d[f]=b:d=d[f]?d[f]:d[f]={}};var w="undefined"!==typeof Uint8Array&&"undefined"!==typeof Uint16Array&&"undefined"!==typeof Uint32Array&&"undefined"!==typeof DataView;new (w?Uint8Array:Array)(256);var x;for(x=0;256>x;++x)for(var y=x,ba=7,y=y>>>1;y;y>>>=1)--ba;var z=[0,1996959894,3993919788,2567524794,124634137,1886057615,3915621685,2657392035,249268274,2044508324,3772115230,2547177864,162941995,2125561021,3887607047,2428444049,498536548,1789927666,4089016648,2227061214,450548861,1843258603,4107580753,2211677639,325883990,1684777152,4251122042,2321926636,335633487,1661365465,4195302755,2366115317,997073096,1281953886,3579855332,2724688242,1006888145,1258607687,3524101629,2768942443,901097722,1119000684,3686517206,2898065728,853044451,1172266101,3705015759,
|
||||||
|
2882616665,651767980,1373503546,3369554304,3218104598,565507253,1454621731,3485111705,3099436303,671266974,1594198024,3322730930,2970347812,795835527,1483230225,3244367275,3060149565,1994146192,31158534,2563907772,4023717930,1907459465,112637215,2680153253,3904427059,2013776290,251722036,2517215374,3775830040,2137656763,141376813,2439277719,3865271297,1802195444,476864866,2238001368,4066508878,1812370925,453092731,2181625025,4111451223,1706088902,314042704,2344532202,4240017532,1658658271,366619977,
|
||||||
|
2362670323,4224994405,1303535960,984961486,2747007092,3569037538,1256170817,1037604311,2765210733,3554079995,1131014506,879679996,2909243462,3663771856,1141124467,855842277,2852801631,3708648649,1342533948,654459306,3188396048,3373015174,1466479909,544179635,3110523913,3462522015,1591671054,702138776,2966460450,3352799412,1504918807,783551873,3082640443,3233442989,3988292384,2596254646,62317068,1957810842,3939845945,2647816111,81470997,1943803523,3814918930,2489596804,225274430,2053790376,3826175755,
|
||||||
|
2466906013,167816743,2097651377,4027552580,2265490386,503444072,1762050814,4150417245,2154129355,426522225,1852507879,4275313526,2312317920,282753626,1742555852,4189708143,2394877945,397917763,1622183637,3604390888,2714866558,953729732,1340076626,3518719985,2797360999,1068828381,1219638859,3624741850,2936675148,906185462,1090812512,3747672003,2825379669,829329135,1181335161,3412177804,3160834842,628085408,1382605366,3423369109,3138078467,570562233,1426400815,3317316542,2998733608,733239954,1555261956,
|
||||||
|
3268935591,3050360625,752459403,1541320221,2607071920,3965973030,1969922972,40735498,2617837225,3943577151,1913087877,83908371,2512341634,3803740692,2075208622,213261112,2463272603,3855990285,2094854071,198958881,2262029012,4057260610,1759359992,534414190,2176718541,4139329115,1873836001,414664567,2282248934,4279200368,1711684554,285281116,2405801727,4167216745,1634467795,376229701,2685067896,3608007406,1308918612,956543938,2808555105,3495958263,1231636301,1047427035,2932959818,3654703836,1088359270,
|
||||||
|
936918E3,2847714899,3736837829,1202900863,817233897,3183342108,3401237130,1404277552,615818150,3134207493,3453421203,1423857449,601450431,3009837614,3294710456,1567103746,711928724,3020668471,3272380065,1510334235,755167117],B=w?new Uint32Array(z):z;function C(a){var b=a.length,c=0,d=Number.POSITIVE_INFINITY,f,h,k,e,g,l,p,s,r,A;for(s=0;s<b;++s)a[s]>c&&(c=a[s]),a[s]<d&&(d=a[s]);f=1<<c;h=new (w?Uint32Array:Array)(f);k=1;e=0;for(g=2;k<=c;){for(s=0;s<b;++s)if(a[s]===k){l=0;p=e;for(r=0;r<k;++r)l=l<<1|p&1,p>>=1;A=k<<16|s;for(r=l;r<f;r+=g)h[r]=A;++e}++k;e<<=1;g<<=1}return[h,c,d]};var D=[],E;for(E=0;288>E;E++)switch(!0){case 143>=E:D.push([E+48,8]);break;case 255>=E:D.push([E-144+400,9]);break;case 279>=E:D.push([E-256+0,7]);break;case 287>=E:D.push([E-280+192,8]);break;default:m("invalid literal: "+E)}
|
||||||
|
var ca=function(){function a(a){switch(!0){case 3===a:return[257,a-3,0];case 4===a:return[258,a-4,0];case 5===a:return[259,a-5,0];case 6===a:return[260,a-6,0];case 7===a:return[261,a-7,0];case 8===a:return[262,a-8,0];case 9===a:return[263,a-9,0];case 10===a:return[264,a-10,0];case 12>=a:return[265,a-11,1];case 14>=a:return[266,a-13,1];case 16>=a:return[267,a-15,1];case 18>=a:return[268,a-17,1];case 22>=a:return[269,a-19,2];case 26>=a:return[270,a-23,2];case 30>=a:return[271,a-27,2];case 34>=a:return[272,
|
||||||
|
a-31,2];case 42>=a:return[273,a-35,3];case 50>=a:return[274,a-43,3];case 58>=a:return[275,a-51,3];case 66>=a:return[276,a-59,3];case 82>=a:return[277,a-67,4];case 98>=a:return[278,a-83,4];case 114>=a:return[279,a-99,4];case 130>=a:return[280,a-115,4];case 162>=a:return[281,a-131,5];case 194>=a:return[282,a-163,5];case 226>=a:return[283,a-195,5];case 257>=a:return[284,a-227,5];case 258===a:return[285,a-258,0];default:m("invalid length: "+a)}}var b=[],c,d;for(c=3;258>=c;c++)d=a(c),b[c]=d[2]<<24|d[1]<<
|
||||||
|
16|d[0];return b}();w&&new Uint32Array(ca);function F(a,b){this.l=[];this.m=32768;this.d=this.f=this.c=this.t=0;this.input=w?new Uint8Array(a):a;this.u=!1;this.n=G;this.L=!1;if(b||!(b={}))b.index&&(this.c=b.index),b.bufferSize&&(this.m=b.bufferSize),b.bufferType&&(this.n=b.bufferType),b.resize&&(this.L=b.resize);switch(this.n){case H:this.a=32768;this.b=new (w?Uint8Array:Array)(32768+this.m+258);break;case G:this.a=0;this.b=new (w?Uint8Array:Array)(this.m);this.e=this.X;this.B=this.S;this.q=this.W;break;default:m(Error("invalid inflate mode"))}}
|
||||||
|
var H=0,G=1;
|
||||||
|
F.prototype.r=function(){for(;!this.u;){var a=I(this,3);a&1&&(this.u=!0);a>>>=1;switch(a){case 0:var b=this.input,c=this.c,d=this.b,f=this.a,h=b.length,k=q,e=q,g=d.length,l=q;this.d=this.f=0;c+1>=h&&m(Error("invalid uncompressed block header: LEN"));k=b[c++]|b[c++]<<8;c+1>=h&&m(Error("invalid uncompressed block header: NLEN"));e=b[c++]|b[c++]<<8;k===~e&&m(Error("invalid uncompressed block header: length verify"));c+k>b.length&&m(Error("input buffer is broken"));switch(this.n){case H:for(;f+k>d.length;){l=
|
||||||
|
g-f;k-=l;if(w)d.set(b.subarray(c,c+l),f),f+=l,c+=l;else for(;l--;)d[f++]=b[c++];this.a=f;d=this.e();f=this.a}break;case G:for(;f+k>d.length;)d=this.e({H:2});break;default:m(Error("invalid inflate mode"))}if(w)d.set(b.subarray(c,c+k),f),f+=k,c+=k;else for(;k--;)d[f++]=b[c++];this.c=c;this.a=f;this.b=d;break;case 1:this.q(da,ea);break;case 2:fa(this);break;default:m(Error("unknown BTYPE: "+a))}}return this.B()};
|
||||||
|
var J=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],K=w?new Uint16Array(J):J,L=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,258,258],M=w?new Uint16Array(L):L,ga=[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],O=w?new Uint8Array(ga):ga,ha=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577],ia=w?new Uint16Array(ha):ha,ja=[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],P=w?new Uint8Array(ja):ja,Q=new (w?Uint8Array:Array)(288),R,la;R=0;for(la=Q.length;R<la;++R)Q[R]=143>=R?8:255>=R?9:279>=R?7:8;var da=C(Q),S=new (w?Uint8Array:Array)(30),T,ma;T=0;for(ma=S.length;T<ma;++T)S[T]=5;var ea=C(S);function I(a,b){for(var c=a.f,d=a.d,f=a.input,h=a.c,k=f.length,e;d<b;)h>=k&&m(Error("input buffer is broken")),c|=f[h++]<<d,d+=8;e=c&(1<<b)-1;a.f=c>>>b;a.d=d-b;a.c=h;return e}
|
||||||
|
function U(a,b){for(var c=a.f,d=a.d,f=a.input,h=a.c,k=f.length,e=b[0],g=b[1],l,p;d<g&&!(h>=k);)c|=f[h++]<<d,d+=8;l=e[c&(1<<g)-1];p=l>>>16;a.f=c>>p;a.d=d-p;a.c=h;return l&65535}
|
||||||
|
function fa(a){function b(a,b,c){var d,e=this.K,f,g;for(g=0;g<a;)switch(d=U(this,b),d){case 16:for(f=3+I(this,2);f--;)c[g++]=e;break;case 17:for(f=3+I(this,3);f--;)c[g++]=0;e=0;break;case 18:for(f=11+I(this,7);f--;)c[g++]=0;e=0;break;default:e=c[g++]=d}this.K=e;return c}var c=I(a,5)+257,d=I(a,5)+1,f=I(a,4)+4,h=new (w?Uint8Array:Array)(K.length),k,e,g,l;for(l=0;l<f;++l)h[K[l]]=I(a,3);if(!w){l=f;for(f=h.length;l<f;++l)h[K[l]]=0}k=C(h);e=new (w?Uint8Array:Array)(c);g=new (w?Uint8Array:Array)(d);a.K=
|
||||||
|
0;a.q(C(b.call(a,c,k,e)),C(b.call(a,d,k,g)))}u=F.prototype;u.q=function(a,b){var c=this.b,d=this.a;this.C=a;for(var f=c.length-258,h,k,e,g;256!==(h=U(this,a));)if(256>h)d>=f&&(this.a=d,c=this.e(),d=this.a),c[d++]=h;else{k=h-257;g=M[k];0<O[k]&&(g+=I(this,O[k]));h=U(this,b);e=ia[h];0<P[h]&&(e+=I(this,P[h]));d>=f&&(this.a=d,c=this.e(),d=this.a);for(;g--;)c[d]=c[d++-e]}for(;8<=this.d;)this.d-=8,this.c--;this.a=d};
|
||||||
|
u.W=function(a,b){var c=this.b,d=this.a;this.C=a;for(var f=c.length,h,k,e,g;256!==(h=U(this,a));)if(256>h)d>=f&&(c=this.e(),f=c.length),c[d++]=h;else{k=h-257;g=M[k];0<O[k]&&(g+=I(this,O[k]));h=U(this,b);e=ia[h];0<P[h]&&(e+=I(this,P[h]));d+g>f&&(c=this.e(),f=c.length);for(;g--;)c[d]=c[d++-e]}for(;8<=this.d;)this.d-=8,this.c--;this.a=d};
|
||||||
|
u.e=function(){var a=new (w?Uint8Array:Array)(this.a-32768),b=this.a-32768,c,d,f=this.b;if(w)a.set(f.subarray(32768,a.length));else{c=0;for(d=a.length;c<d;++c)a[c]=f[c+32768]}this.l.push(a);this.t+=a.length;if(w)f.set(f.subarray(b,b+32768));else for(c=0;32768>c;++c)f[c]=f[b+c];this.a=32768;return f};
|
||||||
|
u.X=function(a){var b,c=this.input.length/this.c+1|0,d,f,h,k=this.input,e=this.b;a&&("number"===typeof a.H&&(c=a.H),"number"===typeof a.Q&&(c+=a.Q));2>c?(d=(k.length-this.c)/this.C[2],h=258*(d/2)|0,f=h<e.length?e.length+h:e.length<<1):f=e.length*c;w?(b=new Uint8Array(f),b.set(e)):b=e;return this.b=b};
|
||||||
|
u.B=function(){var a=0,b=this.b,c=this.l,d,f=new (w?Uint8Array:Array)(this.t+(this.a-32768)),h,k,e,g;if(0===c.length)return w?this.b.subarray(32768,this.a):this.b.slice(32768,this.a);h=0;for(k=c.length;h<k;++h){d=c[h];e=0;for(g=d.length;e<g;++e)f[a++]=d[e]}h=32768;for(k=this.a;h<k;++h)f[a++]=b[h];this.l=[];return this.buffer=f};
|
||||||
|
u.S=function(){var a,b=this.a;w?this.L?(a=new Uint8Array(b),a.set(this.b.subarray(0,b))):a=this.b.subarray(0,b):(this.b.length>b&&(this.b.length=b),a=this.b);return this.buffer=a};function V(a){a=a||{};this.files=[];this.v=a.comment}V.prototype.M=function(a){this.j=a};V.prototype.s=function(a){var b=a[2]&65535|2;return b*(b^1)>>8&255};V.prototype.k=function(a,b){a[0]=(B[(a[0]^b)&255]^a[0]>>>8)>>>0;a[1]=(6681*(20173*(a[1]+(a[0]&255))>>>0)>>>0)+1>>>0;a[2]=(B[(a[2]^a[1]>>>24)&255]^a[2]>>>8)>>>0};V.prototype.U=function(a){var b=[305419896,591751049,878082192],c,d;w&&(b=new Uint32Array(b));c=0;for(d=a.length;c<d;++c)this.k(b,a[c]&255);return b};function W(a,b){b=b||{};this.input=w&&a instanceof Array?new Uint8Array(a):a;this.c=0;this.ca=b.verify||!1;this.j=b.password}var na={P:0,N:8},X=[80,75,1,2],Y=[80,75,3,4],Z=[80,75,5,6];function oa(a,b){this.input=a;this.offset=b}
|
||||||
|
oa.prototype.parse=function(){var a=this.input,b=this.offset;(a[b++]!==X[0]||a[b++]!==X[1]||a[b++]!==X[2]||a[b++]!==X[3])&&m(Error("invalid file header signature"));this.version=a[b++];this.ja=a[b++];this.$=a[b++]|a[b++]<<8;this.I=a[b++]|a[b++]<<8;this.A=a[b++]|a[b++]<<8;this.time=a[b++]|a[b++]<<8;this.V=a[b++]|a[b++]<<8;this.p=(a[b++]|a[b++]<<8|a[b++]<<16|a[b++]<<24)>>>0;this.z=(a[b++]|a[b++]<<8|a[b++]<<16|a[b++]<<24)>>>0;this.J=(a[b++]|a[b++]<<8|a[b++]<<16|a[b++]<<24)>>>0;this.h=a[b++]|a[b++]<<
|
||||||
|
8;this.g=a[b++]|a[b++]<<8;this.F=a[b++]|a[b++]<<8;this.fa=a[b++]|a[b++]<<8;this.ha=a[b++]|a[b++]<<8;this.ga=a[b++]|a[b++]<<8|a[b++]<<16|a[b++]<<24;this.aa=(a[b++]|a[b++]<<8|a[b++]<<16|a[b++]<<24)>>>0;this.filename=String.fromCharCode.apply(null,w?a.subarray(b,b+=this.h):a.slice(b,b+=this.h));this.Y=w?a.subarray(b,b+=this.g):a.slice(b,b+=this.g);this.v=w?a.subarray(b,b+this.F):a.slice(b,b+this.F);this.length=b-this.offset};function pa(a,b){this.input=a;this.offset=b}var qa={O:1,da:8,ea:2048};
|
||||||
|
pa.prototype.parse=function(){var a=this.input,b=this.offset;(a[b++]!==Y[0]||a[b++]!==Y[1]||a[b++]!==Y[2]||a[b++]!==Y[3])&&m(Error("invalid local file header signature"));this.$=a[b++]|a[b++]<<8;this.I=a[b++]|a[b++]<<8;this.A=a[b++]|a[b++]<<8;this.time=a[b++]|a[b++]<<8;this.V=a[b++]|a[b++]<<8;this.p=(a[b++]|a[b++]<<8|a[b++]<<16|a[b++]<<24)>>>0;this.z=(a[b++]|a[b++]<<8|a[b++]<<16|a[b++]<<24)>>>0;this.J=(a[b++]|a[b++]<<8|a[b++]<<16|a[b++]<<24)>>>0;this.h=a[b++]|a[b++]<<8;this.g=a[b++]|a[b++]<<8;this.filename=
|
||||||
|
String.fromCharCode.apply(null,w?a.subarray(b,b+=this.h):a.slice(b,b+=this.h));this.Y=w?a.subarray(b,b+=this.g):a.slice(b,b+=this.g);this.length=b-this.offset};
|
||||||
|
function $(a){var b=[],c={},d,f,h,k;if(!a.i){if(a.o===q){var e=a.input,g;if(!a.D)a:{var l=a.input,p;for(p=l.length-12;0<p;--p)if(l[p]===Z[0]&&l[p+1]===Z[1]&&l[p+2]===Z[2]&&l[p+3]===Z[3]){a.D=p;break a}m(Error("End of Central Directory Record not found"))}g=a.D;(e[g++]!==Z[0]||e[g++]!==Z[1]||e[g++]!==Z[2]||e[g++]!==Z[3])&&m(Error("invalid signature"));a.ia=e[g++]|e[g++]<<8;a.ka=e[g++]|e[g++]<<8;a.la=e[g++]|e[g++]<<8;a.ba=e[g++]|e[g++]<<8;a.R=(e[g++]|e[g++]<<8|e[g++]<<16|e[g++]<<24)>>>0;a.o=(e[g++]|
|
||||||
|
e[g++]<<8|e[g++]<<16|e[g++]<<24)>>>0;a.w=e[g++]|e[g++]<<8;a.v=w?e.subarray(g,g+a.w):e.slice(g,g+a.w)}d=a.o;h=0;for(k=a.ba;h<k;++h)f=new oa(a.input,d),f.parse(),d+=f.length,b[h]=f,c[f.filename]=h;a.R<d-a.o&&m(Error("invalid file header size"));a.i=b;a.G=c}}u=W.prototype;u.Z=function(){var a=[],b,c,d;this.i||$(this);d=this.i;b=0;for(c=d.length;b<c;++b)a[b]=d[b].filename;return a};
|
||||||
|
u.r=function(a,b){var c;this.G||$(this);c=this.G[a];c===q&&m(Error(a+" not found"));var d;d=b||{};var f=this.input,h=this.i,k,e,g,l,p,s,r,A;h||$(this);h[c]===q&&m(Error("wrong index"));e=h[c].aa;k=new pa(this.input,e);k.parse();e+=k.length;g=k.z;if(0!==(k.I&qa.O)){!d.password&&!this.j&&m(Error("please set password"));s=this.T(d.password||this.j);r=e;for(A=e+12;r<A;++r)ra(this,s,f[r]);e+=12;g-=12;r=e;for(A=e+g;r<A;++r)f[r]=ra(this,s,f[r])}switch(k.A){case na.P:l=w?this.input.subarray(e,e+g):this.input.slice(e,
|
||||||
|
e+g);break;case na.N:l=(new F(this.input,{index:e,bufferSize:k.J})).r();break;default:m(Error("unknown compression type"))}if(this.ca){var t=q,n,N="number"===typeof t?t:t=0,ka=l.length;n=-1;for(N=ka&7;N--;++t)n=n>>>8^B[(n^l[t])&255];for(N=ka>>3;N--;t+=8)n=n>>>8^B[(n^l[t])&255],n=n>>>8^B[(n^l[t+1])&255],n=n>>>8^B[(n^l[t+2])&255],n=n>>>8^B[(n^l[t+3])&255],n=n>>>8^B[(n^l[t+4])&255],n=n>>>8^B[(n^l[t+5])&255],n=n>>>8^B[(n^l[t+6])&255],n=n>>>8^B[(n^l[t+7])&255];p=(n^4294967295)>>>0;k.p!==p&&m(Error("wrong crc: file=0x"+
|
||||||
|
k.p.toString(16)+", data=0x"+p.toString(16)))}return l};u.M=function(a){this.j=a};function ra(a,b,c){c^=a.s(b);a.k(b,c);return c}u.k=V.prototype.k;u.T=V.prototype.U;u.s=V.prototype.s;v("Zlib.Unzip",W);v("Zlib.Unzip.prototype.decompress",W.prototype.r);v("Zlib.Unzip.prototype.getFilenames",W.prototype.Z);v("Zlib.Unzip.prototype.setPassword",W.prototype.M);}).call(this);
|
|
@ -0,0 +1,37 @@
|
||||||
|
/** @license zlib.js 2012 - imaya [ https://github.com/imaya/zlib.js ] The MIT License */(function() {'use strict';var n=void 0,y=!0,aa=this;function G(e,b){var a=e.split("."),d=aa;!(a[0]in d)&&d.execScript&&d.execScript("var "+a[0]);for(var c;a.length&&(c=a.shift());)!a.length&&b!==n?d[c]=b:d=d[c]?d[c]:d[c]={}};var H="undefined"!==typeof Uint8Array&&"undefined"!==typeof Uint16Array&&"undefined"!==typeof Uint32Array&&"undefined"!==typeof DataView;function ba(e,b){this.index="number"===typeof b?b:0;this.f=0;this.buffer=e instanceof(H?Uint8Array:Array)?e:new (H?Uint8Array:Array)(32768);if(2*this.buffer.length<=this.index)throw Error("invalid index");this.buffer.length<=this.index&&ca(this)}function ca(e){var b=e.buffer,a,d=b.length,c=new (H?Uint8Array:Array)(d<<1);if(H)c.set(b);else for(a=0;a<d;++a)c[a]=b[a];return e.buffer=c}
|
||||||
|
ba.prototype.b=function(e,b,a){var d=this.buffer,c=this.index,f=this.f,l=d[c],p;a&&1<b&&(e=8<b?(L[e&255]<<24|L[e>>>8&255]<<16|L[e>>>16&255]<<8|L[e>>>24&255])>>32-b:L[e]>>8-b);if(8>b+f)l=l<<b|e,f+=b;else for(p=0;p<b;++p)l=l<<1|e>>b-p-1&1,8===++f&&(f=0,d[c++]=L[l],l=0,c===d.length&&(d=ca(this)));d[c]=l;this.buffer=d;this.f=f;this.index=c};ba.prototype.finish=function(){var e=this.buffer,b=this.index,a;0<this.f&&(e[b]<<=8-this.f,e[b]=L[e[b]],b++);H?a=e.subarray(0,b):(e.length=b,a=e);return a};
|
||||||
|
var da=new (H?Uint8Array:Array)(256),ha;for(ha=0;256>ha;++ha){for(var U=ha,ja=U,ka=7,U=U>>>1;U;U>>>=1)ja<<=1,ja|=U&1,--ka;da[ha]=(ja<<ka&255)>>>0}var L=da;function la(e){var b=n,a,d="number"===typeof b?b:b=0,c=e.length;a=-1;for(d=c&7;d--;++b)a=a>>>8^V[(a^e[b])&255];for(d=c>>3;d--;b+=8)a=a>>>8^V[(a^e[b])&255],a=a>>>8^V[(a^e[b+1])&255],a=a>>>8^V[(a^e[b+2])&255],a=a>>>8^V[(a^e[b+3])&255],a=a>>>8^V[(a^e[b+4])&255],a=a>>>8^V[(a^e[b+5])&255],a=a>>>8^V[(a^e[b+6])&255],a=a>>>8^V[(a^e[b+7])&255];return(a^4294967295)>>>0}
|
||||||
|
var ma=[0,1996959894,3993919788,2567524794,124634137,1886057615,3915621685,2657392035,249268274,2044508324,3772115230,2547177864,162941995,2125561021,3887607047,2428444049,498536548,1789927666,4089016648,2227061214,450548861,1843258603,4107580753,2211677639,325883990,1684777152,4251122042,2321926636,335633487,1661365465,4195302755,2366115317,997073096,1281953886,3579855332,2724688242,1006888145,1258607687,3524101629,2768942443,901097722,1119000684,3686517206,2898065728,853044451,1172266101,3705015759,
|
||||||
|
2882616665,651767980,1373503546,3369554304,3218104598,565507253,1454621731,3485111705,3099436303,671266974,1594198024,3322730930,2970347812,795835527,1483230225,3244367275,3060149565,1994146192,31158534,2563907772,4023717930,1907459465,112637215,2680153253,3904427059,2013776290,251722036,2517215374,3775830040,2137656763,141376813,2439277719,3865271297,1802195444,476864866,2238001368,4066508878,1812370925,453092731,2181625025,4111451223,1706088902,314042704,2344532202,4240017532,1658658271,366619977,
|
||||||
|
2362670323,4224994405,1303535960,984961486,2747007092,3569037538,1256170817,1037604311,2765210733,3554079995,1131014506,879679996,2909243462,3663771856,1141124467,855842277,2852801631,3708648649,1342533948,654459306,3188396048,3373015174,1466479909,544179635,3110523913,3462522015,1591671054,702138776,2966460450,3352799412,1504918807,783551873,3082640443,3233442989,3988292384,2596254646,62317068,1957810842,3939845945,2647816111,81470997,1943803523,3814918930,2489596804,225274430,2053790376,3826175755,
|
||||||
|
2466906013,167816743,2097651377,4027552580,2265490386,503444072,1762050814,4150417245,2154129355,426522225,1852507879,4275313526,2312317920,282753626,1742555852,4189708143,2394877945,397917763,1622183637,3604390888,2714866558,953729732,1340076626,3518719985,2797360999,1068828381,1219638859,3624741850,2936675148,906185462,1090812512,3747672003,2825379669,829329135,1181335161,3412177804,3160834842,628085408,1382605366,3423369109,3138078467,570562233,1426400815,3317316542,2998733608,733239954,1555261956,
|
||||||
|
3268935591,3050360625,752459403,1541320221,2607071920,3965973030,1969922972,40735498,2617837225,3943577151,1913087877,83908371,2512341634,3803740692,2075208622,213261112,2463272603,3855990285,2094854071,198958881,2262029012,4057260610,1759359992,534414190,2176718541,4139329115,1873836001,414664567,2282248934,4279200368,1711684554,285281116,2405801727,4167216745,1634467795,376229701,2685067896,3608007406,1308918612,956543938,2808555105,3495958263,1231636301,1047427035,2932959818,3654703836,1088359270,
|
||||||
|
936918E3,2847714899,3736837829,1202900863,817233897,3183342108,3401237130,1404277552,615818150,3134207493,3453421203,1423857449,601450431,3009837614,3294710456,1567103746,711928724,3020668471,3272380065,1510334235,755167117],V=H?new Uint32Array(ma):ma;function na(e){this.buffer=new (H?Uint16Array:Array)(2*e);this.length=0}na.prototype.getParent=function(e){return 2*((e-2)/4|0)};na.prototype.push=function(e,b){var a,d,c=this.buffer,f;a=this.length;c[this.length++]=b;for(c[this.length++]=e;0<a;)if(d=this.getParent(a),c[a]>c[d])f=c[a],c[a]=c[d],c[d]=f,f=c[a+1],c[a+1]=c[d+1],c[d+1]=f,a=d;else break;return this.length};
|
||||||
|
na.prototype.pop=function(){var e,b,a=this.buffer,d,c,f;b=a[0];e=a[1];this.length-=2;a[0]=a[this.length];a[1]=a[this.length+1];for(f=0;;){c=2*f+2;if(c>=this.length)break;c+2<this.length&&a[c+2]>a[c]&&(c+=2);if(a[c]>a[f])d=a[f],a[f]=a[c],a[c]=d,d=a[f+1],a[f+1]=a[c+1],a[c+1]=d;else break;f=c}return{index:e,value:b,length:this.length}};function pa(e,b){this.k=qa;this.l=0;this.input=H&&e instanceof Array?new Uint8Array(e):e;this.e=0;b&&(b.lazy&&(this.l=b.lazy),"number"===typeof b.compressionType&&(this.k=b.compressionType),b.outputBuffer&&(this.c=H&&b.outputBuffer instanceof Array?new Uint8Array(b.outputBuffer):b.outputBuffer),"number"===typeof b.outputIndex&&(this.e=b.outputIndex));this.c||(this.c=new (H?Uint8Array:Array)(32768))}var qa=2,sa=[],Y;
|
||||||
|
for(Y=0;288>Y;Y++)switch(y){case 143>=Y:sa.push([Y+48,8]);break;case 255>=Y:sa.push([Y-144+400,9]);break;case 279>=Y:sa.push([Y-256+0,7]);break;case 287>=Y:sa.push([Y-280+192,8]);break;default:throw"invalid literal: "+Y;}
|
||||||
|
pa.prototype.g=function(){var e,b,a,d,c=this.input;switch(this.k){case 0:a=0;for(d=c.length;a<d;){b=H?c.subarray(a,a+65535):c.slice(a,a+65535);a+=b.length;var f=b,l=a===d,p=n,k=n,q=n,w=n,u=n,m=this.c,h=this.e;if(H){for(m=new Uint8Array(this.c.buffer);m.length<=h+f.length+5;)m=new Uint8Array(m.length<<1);m.set(this.c)}p=l?1:0;m[h++]=p|0;k=f.length;q=~k+65536&65535;m[h++]=k&255;m[h++]=k>>>8&255;m[h++]=q&255;m[h++]=q>>>8&255;if(H)m.set(f,h),h+=f.length,m=m.subarray(0,h);else{w=0;for(u=f.length;w<u;++w)m[h++]=
|
||||||
|
f[w];m.length=h}this.e=h;this.c=m}break;case 1:var s=new ba(H?new Uint8Array(this.c.buffer):this.c,this.e);s.b(1,1,y);s.b(1,2,y);var t=ta(this,c),r,Q,z;r=0;for(Q=t.length;r<Q;r++)if(z=t[r],ba.prototype.b.apply(s,sa[z]),256<z)s.b(t[++r],t[++r],y),s.b(t[++r],5),s.b(t[++r],t[++r],y);else if(256===z)break;this.c=s.finish();this.e=this.c.length;break;case qa:var A=new ba(H?new Uint8Array(this.c.buffer):this.c,this.e),F,I,N,B,C,g=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],J,ea,O,W,X,oa=Array(19),
|
||||||
|
ya,Z,ia,D,za;F=qa;A.b(1,1,y);A.b(F,2,y);I=ta(this,c);J=ua(this.p,15);ea=va(J);O=ua(this.o,7);W=va(O);for(N=286;257<N&&0===J[N-1];N--);for(B=30;1<B&&0===O[B-1];B--);var Aa=N,Ba=B,P=new (H?Uint32Array:Array)(Aa+Ba),v,R,x,fa,M=new (H?Uint32Array:Array)(316),K,E,S=new (H?Uint8Array:Array)(19);for(v=R=0;v<Aa;v++)P[R++]=J[v];for(v=0;v<Ba;v++)P[R++]=O[v];if(!H){v=0;for(fa=S.length;v<fa;++v)S[v]=0}v=K=0;for(fa=P.length;v<fa;v+=R){for(R=1;v+R<fa&&P[v+R]===P[v];++R);x=R;if(0===P[v])if(3>x)for(;0<x--;)M[K++]=
|
||||||
|
0,S[0]++;else for(;0<x;)E=138>x?x:138,E>x-3&&E<x&&(E=x-3),10>=E?(M[K++]=17,M[K++]=E-3,S[17]++):(M[K++]=18,M[K++]=E-11,S[18]++),x-=E;else if(M[K++]=P[v],S[P[v]]++,x--,3>x)for(;0<x--;)M[K++]=P[v],S[P[v]]++;else for(;0<x;)E=6>x?x:6,E>x-3&&E<x&&(E=x-3),M[K++]=16,M[K++]=E-3,S[16]++,x-=E}e=H?M.subarray(0,K):M.slice(0,K);X=ua(S,7);for(D=0;19>D;D++)oa[D]=X[g[D]];for(C=19;4<C&&0===oa[C-1];C--);ya=va(X);A.b(N-257,5,y);A.b(B-1,5,y);A.b(C-4,4,y);for(D=0;D<C;D++)A.b(oa[D],3,y);D=0;for(za=e.length;D<za;D++)if(Z=
|
||||||
|
e[D],A.b(ya[Z],X[Z],y),16<=Z){D++;switch(Z){case 16:ia=2;break;case 17:ia=3;break;case 18:ia=7;break;default:throw"invalid code: "+Z;}A.b(e[D],ia,y)}var Ca=[ea,J],Da=[W,O],T,Ea,ga,ra,Fa,Ga,Ha,Ia;Fa=Ca[0];Ga=Ca[1];Ha=Da[0];Ia=Da[1];T=0;for(Ea=I.length;T<Ea;++T)if(ga=I[T],A.b(Fa[ga],Ga[ga],y),256<ga)A.b(I[++T],I[++T],y),ra=I[++T],A.b(Ha[ra],Ia[ra],y),A.b(I[++T],I[++T],y);else if(256===ga)break;this.c=A.finish();this.e=this.c.length;break;default:throw"invalid compression type";}return this.c};
|
||||||
|
function wa(e,b){this.length=e;this.n=b}
|
||||||
|
var xa=function(){function e(a){switch(y){case 3===a:return[257,a-3,0];case 4===a:return[258,a-4,0];case 5===a:return[259,a-5,0];case 6===a:return[260,a-6,0];case 7===a:return[261,a-7,0];case 8===a:return[262,a-8,0];case 9===a:return[263,a-9,0];case 10===a:return[264,a-10,0];case 12>=a:return[265,a-11,1];case 14>=a:return[266,a-13,1];case 16>=a:return[267,a-15,1];case 18>=a:return[268,a-17,1];case 22>=a:return[269,a-19,2];case 26>=a:return[270,a-23,2];case 30>=a:return[271,a-27,2];case 34>=a:return[272,
|
||||||
|
a-31,2];case 42>=a:return[273,a-35,3];case 50>=a:return[274,a-43,3];case 58>=a:return[275,a-51,3];case 66>=a:return[276,a-59,3];case 82>=a:return[277,a-67,4];case 98>=a:return[278,a-83,4];case 114>=a:return[279,a-99,4];case 130>=a:return[280,a-115,4];case 162>=a:return[281,a-131,5];case 194>=a:return[282,a-163,5];case 226>=a:return[283,a-195,5];case 257>=a:return[284,a-227,5];case 258===a:return[285,a-258,0];default:throw"invalid length: "+a;}}var b=[],a,d;for(a=3;258>=a;a++)d=e(a),b[a]=d[2]<<24|
|
||||||
|
d[1]<<16|d[0];return b}(),Ja=H?new Uint32Array(xa):xa;
|
||||||
|
function ta(e,b){function a(a,c){var b=a.n,d=[],e=0,f;f=Ja[a.length];d[e++]=f&65535;d[e++]=f>>16&255;d[e++]=f>>24;var g;switch(y){case 1===b:g=[0,b-1,0];break;case 2===b:g=[1,b-2,0];break;case 3===b:g=[2,b-3,0];break;case 4===b:g=[3,b-4,0];break;case 6>=b:g=[4,b-5,1];break;case 8>=b:g=[5,b-7,1];break;case 12>=b:g=[6,b-9,2];break;case 16>=b:g=[7,b-13,2];break;case 24>=b:g=[8,b-17,3];break;case 32>=b:g=[9,b-25,3];break;case 48>=b:g=[10,b-33,4];break;case 64>=b:g=[11,b-49,4];break;case 96>=b:g=[12,b-
|
||||||
|
65,5];break;case 128>=b:g=[13,b-97,5];break;case 192>=b:g=[14,b-129,6];break;case 256>=b:g=[15,b-193,6];break;case 384>=b:g=[16,b-257,7];break;case 512>=b:g=[17,b-385,7];break;case 768>=b:g=[18,b-513,8];break;case 1024>=b:g=[19,b-769,8];break;case 1536>=b:g=[20,b-1025,9];break;case 2048>=b:g=[21,b-1537,9];break;case 3072>=b:g=[22,b-2049,10];break;case 4096>=b:g=[23,b-3073,10];break;case 6144>=b:g=[24,b-4097,11];break;case 8192>=b:g=[25,b-6145,11];break;case 12288>=b:g=[26,b-8193,12];break;case 16384>=
|
||||||
|
b:g=[27,b-12289,12];break;case 24576>=b:g=[28,b-16385,13];break;case 32768>=b:g=[29,b-24577,13];break;default:throw"invalid distance";}f=g;d[e++]=f[0];d[e++]=f[1];d[e++]=f[2];var k,l;k=0;for(l=d.length;k<l;++k)m[h++]=d[k];t[d[0]]++;r[d[3]]++;s=a.length+c-1;u=null}var d,c,f,l,p,k={},q,w,u,m=H?new Uint16Array(2*b.length):[],h=0,s=0,t=new (H?Uint32Array:Array)(286),r=new (H?Uint32Array:Array)(30),Q=e.l,z;if(!H){for(f=0;285>=f;)t[f++]=0;for(f=0;29>=f;)r[f++]=0}t[256]=1;d=0;for(c=b.length;d<c;++d){f=p=
|
||||||
|
0;for(l=3;f<l&&d+f!==c;++f)p=p<<8|b[d+f];k[p]===n&&(k[p]=[]);q=k[p];if(!(0<s--)){for(;0<q.length&&32768<d-q[0];)q.shift();if(d+3>=c){u&&a(u,-1);f=0;for(l=c-d;f<l;++f)z=b[d+f],m[h++]=z,++t[z];break}0<q.length?(w=Ka(b,d,q),u?u.length<w.length?(z=b[d-1],m[h++]=z,++t[z],a(w,0)):a(u,-1):w.length<Q?u=w:a(w,0)):u?a(u,-1):(z=b[d],m[h++]=z,++t[z])}q.push(d)}m[h++]=256;t[256]++;e.p=t;e.o=r;return H?m.subarray(0,h):m}
|
||||||
|
function Ka(e,b,a){var d,c,f=0,l,p,k,q,w=e.length;p=0;q=a.length;a:for(;p<q;p++){d=a[q-p-1];l=3;if(3<f){for(k=f;3<k;k--)if(e[d+k-1]!==e[b+k-1])continue a;l=f}for(;258>l&&b+l<w&&e[d+l]===e[b+l];)++l;l>f&&(c=d,f=l);if(258===l)break}return new wa(f,b-c)}
|
||||||
|
function ua(e,b){var a=e.length,d=new na(572),c=new (H?Uint8Array:Array)(a),f,l,p,k,q;if(!H)for(k=0;k<a;k++)c[k]=0;for(k=0;k<a;++k)0<e[k]&&d.push(k,e[k]);f=Array(d.length/2);l=new (H?Uint32Array:Array)(d.length/2);if(1===f.length)return c[d.pop().index]=1,c;k=0;for(q=d.length/2;k<q;++k)f[k]=d.pop(),l[k]=f[k].value;p=La(l,l.length,b);k=0;for(q=f.length;k<q;++k)c[f[k].index]=p[k];return c}
|
||||||
|
function La(e,b,a){function d(a){var c=k[a][q[a]];c===b?(d(a+1),d(a+1)):--l[c];++q[a]}var c=new (H?Uint16Array:Array)(a),f=new (H?Uint8Array:Array)(a),l=new (H?Uint8Array:Array)(b),p=Array(a),k=Array(a),q=Array(a),w=(1<<a)-b,u=1<<a-1,m,h,s,t,r;c[a-1]=b;for(h=0;h<a;++h)w<u?f[h]=0:(f[h]=1,w-=u),w<<=1,c[a-2-h]=(c[a-1-h]/2|0)+b;c[0]=f[0];p[0]=Array(c[0]);k[0]=Array(c[0]);for(h=1;h<a;++h)c[h]>2*c[h-1]+f[h]&&(c[h]=2*c[h-1]+f[h]),p[h]=Array(c[h]),k[h]=Array(c[h]);for(m=0;m<b;++m)l[m]=a;for(s=0;s<c[a-1];++s)p[a-
|
||||||
|
1][s]=e[s],k[a-1][s]=s;for(m=0;m<a;++m)q[m]=0;1===f[a-1]&&(--l[0],++q[a-1]);for(h=a-2;0<=h;--h){t=m=0;r=q[h+1];for(s=0;s<c[h];s++)t=p[h+1][r]+p[h+1][r+1],t>e[m]?(p[h][s]=t,k[h][s]=b,r+=2):(p[h][s]=e[m],k[h][s]=m,++m);q[h]=0;1===f[h]&&d(h)}return l}
|
||||||
|
function va(e){var b=new (H?Uint16Array:Array)(e.length),a=[],d=[],c=0,f,l,p,k;f=0;for(l=e.length;f<l;f++)a[e[f]]=(a[e[f]]|0)+1;f=1;for(l=16;f<=l;f++)d[f]=c,c+=a[f]|0,c<<=1;f=0;for(l=e.length;f<l;f++){c=d[e[f]];d[e[f]]+=1;p=b[f]=0;for(k=e[f];p<k;p++)b[f]=b[f]<<1|c&1,c>>>=1}return b};function $(e){e=e||{};this.files=[];this.d=e.comment}var Ma=[80,75,1,2],Na=[80,75,3,4],Oa=[80,75,5,6];$.prototype.m=function(e,b){b=b||{};var a,d=e.length,c=0;H&&e instanceof Array&&(e=new Uint8Array(e));"number"!==typeof b.compressionMethod&&(b.compressionMethod=8);if(b.compress)switch(b.compressionMethod){case 0:break;case 8:c=la(e);e=(new pa(e,b.deflateOption)).g();a=y;break;default:throw Error("unknown compression method:"+b.compressionMethod);}this.files.push({buffer:e,a:b,j:a,r:!1,size:d,h:c})};
|
||||||
|
$.prototype.q=function(e){this.i=e};
|
||||||
|
$.prototype.g=function(){var e=this.files,b,a,d,c,f,l=0,p=0,k,q,w,u,m,h,s,t,r,Q,z,A,F,I,N,B,C,g,J;B=0;for(C=e.length;B<C;++B){b=e[B];t=b.a.filename?b.a.filename.length:0;r=b.a.comment?b.a.comment.length:0;if(!b.j)switch(b.h=la(b.buffer),b.a.compressionMethod){case 0:break;case 8:b.buffer=(new pa(b.buffer,b.a.deflateOption)).g();b.j=y;break;default:throw Error("unknown compression method:"+b.a.compressionMethod);}if(b.a.password!==n||this.i!==n){var ea=b.a.password||this.i,O=[305419896,591751049,878082192],
|
||||||
|
W=n,X=n;H&&(O=new Uint32Array(O));W=0;for(X=ea.length;W<X;++W)Pa(O,ea[W]&255);N=O;F=b.buffer;H?(I=new Uint8Array(F.length+12),I.set(F,12),F=I):F.unshift(0,0,0,0,0,0,0,0,0,0,0,0);for(g=0;12>g;++g)F[g]=Qa(N,11===B?b.h&255:256*Math.random()|0);for(J=F.length;g<J;++g)F[g]=Qa(N,F[g]);b.buffer=F}l+=30+t+b.buffer.length;p+=46+t+r}a=new (H?Uint8Array:Array)(l+p+(46+(this.d?this.d.length:0)));d=0;c=l;f=c+p;B=0;for(C=e.length;B<C;++B){b=e[B];t=b.a.filename?b.a.filename.length:0;r=b.a.comment?b.a.comment.length:
|
||||||
|
0;k=d;a[d++]=Na[0];a[d++]=Na[1];a[d++]=Na[2];a[d++]=Na[3];a[c++]=Ma[0];a[c++]=Ma[1];a[c++]=Ma[2];a[c++]=Ma[3];a[c++]=20;a[c++]=b.a.os||0;a[d++]=a[c++]=20;q=a[d++]=a[c++]=0;if(b.a.password||this.i)q|=1;a[d++]=a[c++]=q&255;a[d++]=a[c++]=q>>8&255;w=b.a.compressionMethod;a[d++]=a[c++]=w&255;a[d++]=a[c++]=w>>8&255;u=b.a.date||new Date;a[d++]=a[c++]=(u.getMinutes()&7)<<5|u.getSeconds()/2|0;a[d++]=a[c++]=u.getHours()<<3|u.getMinutes()>>3;a[d++]=a[c++]=(u.getMonth()+1&7)<<5|u.getDate();a[d++]=a[c++]=(u.getFullYear()-
|
||||||
|
1980&127)<<1|u.getMonth()+1>>3;m=b.h;a[d++]=a[c++]=m&255;a[d++]=a[c++]=m>>8&255;a[d++]=a[c++]=m>>16&255;a[d++]=a[c++]=m>>24&255;h=b.buffer.length;a[d++]=a[c++]=h&255;a[d++]=a[c++]=h>>8&255;a[d++]=a[c++]=h>>16&255;a[d++]=a[c++]=h>>24&255;s=b.size;a[d++]=a[c++]=s&255;a[d++]=a[c++]=s>>8&255;a[d++]=a[c++]=s>>16&255;a[d++]=a[c++]=s>>24&255;a[d++]=a[c++]=t&255;a[d++]=a[c++]=t>>8&255;a[d++]=a[c++]=0;a[d++]=a[c++]=0;a[c++]=r&255;a[c++]=r>>8&255;a[c++]=0;a[c++]=0;a[c++]=0;a[c++]=0;a[c++]=0;a[c++]=0;a[c++]=
|
||||||
|
0;a[c++]=0;a[c++]=k&255;a[c++]=k>>8&255;a[c++]=k>>16&255;a[c++]=k>>24&255;if(Q=b.a.filename)if(H)a.set(Q,d),a.set(Q,c),d+=t,c+=t;else for(g=0;g<t;++g)a[d++]=a[c++]=Q[g];if(z=b.a.extraField)if(H)a.set(z,d),a.set(z,c),d+=0,c+=0;else for(g=0;g<r;++g)a[d++]=a[c++]=z[g];if(A=b.a.comment)if(H)a.set(A,c),c+=r;else for(g=0;g<r;++g)a[c++]=A[g];if(H)a.set(b.buffer,d),d+=b.buffer.length;else{g=0;for(J=b.buffer.length;g<J;++g)a[d++]=b.buffer[g]}}a[f++]=Oa[0];a[f++]=Oa[1];a[f++]=Oa[2];a[f++]=Oa[3];a[f++]=0;a[f++]=
|
||||||
|
0;a[f++]=0;a[f++]=0;a[f++]=C&255;a[f++]=C>>8&255;a[f++]=C&255;a[f++]=C>>8&255;a[f++]=p&255;a[f++]=p>>8&255;a[f++]=p>>16&255;a[f++]=p>>24&255;a[f++]=l&255;a[f++]=l>>8&255;a[f++]=l>>16&255;a[f++]=l>>24&255;r=this.d?this.d.length:0;a[f++]=r&255;a[f++]=r>>8&255;if(this.d)if(H)a.set(this.d,f);else{g=0;for(J=r;g<J;++g)a[f++]=this.d[g]}return a};function Qa(e,b){var a,d=e[2]&65535|2;a=d*(d^1)>>8&255;Pa(e,b);return a^b}
|
||||||
|
function Pa(e,b){e[0]=(V[(e[0]^b)&255]^e[0]>>>8)>>>0;e[1]=(6681*(20173*(e[1]+(e[0]&255))>>>0)>>>0)+1>>>0;e[2]=(V[(e[2]^e[1]>>>24)&255]^e[2]>>>8)>>>0};function Ra(e,b){var a,d,c,f;if(Object.keys)a=Object.keys(b);else for(d in a=[],c=0,b)a[c++]=d;c=0;for(f=a.length;c<f;++c)d=a[c],G(e+"."+d,b[d])};G("Zlib.Zip",$);G("Zlib.Zip.prototype.addFile",$.prototype.m);G("Zlib.Zip.prototype.compress",$.prototype.g);G("Zlib.Zip.prototype.setPassword",$.prototype.q);Ra("Zlib.Zip.CompressionMethod",{STORE:0,DEFLATE:8});Ra("Zlib.Zip.OperatingSystem",{MSDOS:0,UNIX:3,MACINTOSH:7});}).call(this);
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -1,581 +0,0 @@
|
||||||
/*
|
|
||||||
Based on https://github.com/gildas-lormeau/zip.js/blob/master/WebContent/zip.js
|
|
||||||
|
|
||||||
Copyright (c) 2013 Gildas Lormeau. All rights reserved.
|
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
|
||||||
modification, are permitted provided that the following conditions are met:
|
|
||||||
|
|
||||||
1. Redistributions of source code must retain the above copyright notice,
|
|
||||||
this list of conditions and the following disclaimer.
|
|
||||||
|
|
||||||
2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
notice, this list of conditions and the following disclaimer in
|
|
||||||
the documentation and/or other materials provided with the distribution.
|
|
||||||
|
|
||||||
3. The names of the authors may not be used to endorse or promote products
|
|
||||||
derived from this software without specific prior written permission.
|
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
||||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
||||||
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
||||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
||||||
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
||||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
||||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
||||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
define(function(require) {
|
|
||||||
|
|
||||||
var ERR_BAD_FORMAT = "File format is not recognized.";
|
|
||||||
var ERR_ENCRYPTED = "File contains encrypted entry.";
|
|
||||||
var ERR_ZIP64 = "File is using Zip64 (4gb+ file size).";
|
|
||||||
var ERR_READ = "Error while reading zip file.";
|
|
||||||
var ERR_WRITE = "Error while writing zip file.";
|
|
||||||
var ERR_WRITE_DATA = "Error while writing file data.";
|
|
||||||
var ERR_READ_DATA = "Error while reading file data.";
|
|
||||||
var ERR_DUPLICATED_NAME = "File already exists.";
|
|
||||||
var CHUNK_SIZE = 512 * 1024;
|
|
||||||
|
|
||||||
var Inflater = require("zip.js/inflate");
|
|
||||||
var Deflater = require("zip.js/deflate");
|
|
||||||
|
|
||||||
var TEXT_PLAIN = "text/plain";
|
|
||||||
var MESSAGE_EVENT = "message";
|
|
||||||
|
|
||||||
function Crc32() {
|
|
||||||
var crc = -1, that = this;
|
|
||||||
that.append = function(data) {
|
|
||||||
var offset, table = that.table;
|
|
||||||
for (offset = 0; offset < data.length; offset++)
|
|
||||||
crc = (crc >>> 8) ^ table[(crc ^ data[offset]) & 0xFF];
|
|
||||||
};
|
|
||||||
that.get = function() {
|
|
||||||
return ~crc;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
Crc32.prototype.table = (function() {
|
|
||||||
var i, j, t, table = [];
|
|
||||||
for (i = 0; i < 256; i++) {
|
|
||||||
t = i;
|
|
||||||
for (j = 0; j < 8; j++)
|
|
||||||
if (t & 1)
|
|
||||||
t = (t >>> 1) ^ 0xEDB88320;
|
|
||||||
else
|
|
||||||
t = t >>> 1;
|
|
||||||
table[i] = t;
|
|
||||||
}
|
|
||||||
return table;
|
|
||||||
})();
|
|
||||||
|
|
||||||
function getDataHelper(byteLength, bytes) {
|
|
||||||
var dataBuffer, dataArray;
|
|
||||||
dataBuffer = new ArrayBuffer(byteLength);
|
|
||||||
dataArray = new Uint8Array(dataBuffer);
|
|
||||||
if (bytes)
|
|
||||||
dataArray.set(bytes, 0);
|
|
||||||
return {
|
|
||||||
buffer : dataBuffer,
|
|
||||||
array : dataArray,
|
|
||||||
view : new DataView(dataBuffer)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Readers
|
|
||||||
|
|
||||||
// Filer fs-based File Reader, given a path and a fs instance
|
|
||||||
function FileReader(path, fs) {
|
|
||||||
var that = this;
|
|
||||||
|
|
||||||
function init(callback, onerror) {
|
|
||||||
fs.stat(path, function(err, stats) {
|
|
||||||
if(err) return onerror(err);
|
|
||||||
|
|
||||||
that.size = stats.size;
|
|
||||||
callback();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function getData(callback, onerror) {
|
|
||||||
if(that.data) {
|
|
||||||
callback();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
fs.readFile(path, function(err, data) {
|
|
||||||
if(err) return onerror(err);
|
|
||||||
that.data = data;
|
|
||||||
callback();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function readUint8Array(index, length, callback, onerror) {
|
|
||||||
getData(function() {
|
|
||||||
callback(that.data.subarray(index, index + length));
|
|
||||||
}, onerror);
|
|
||||||
}
|
|
||||||
|
|
||||||
that.size = 0;
|
|
||||||
that.init = init;
|
|
||||||
that.readUint8Array = readUint8Array;
|
|
||||||
}
|
|
||||||
FileReader.prototype.checkCrc32 = false;
|
|
||||||
|
|
||||||
// Filer fs-based File Writer
|
|
||||||
function FileWriter(path, fs) {
|
|
||||||
var that = this;
|
|
||||||
|
|
||||||
function init(callback, onerror) {
|
|
||||||
// XXX: delete path if it exists?
|
|
||||||
fs.Shell().rm(path, function(err) {
|
|
||||||
callback();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function getData(callback, onerror) {
|
|
||||||
fs.readFile(path, function(err, data) {
|
|
||||||
if(err) return onerror(err);
|
|
||||||
callback(data);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function writeUint8Array(array, callback, onerror) {
|
|
||||||
fs.appendFile(path, array, function(err) {
|
|
||||||
if(err) return onerror(err);
|
|
||||||
callback();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
that.init = init;
|
|
||||||
that.writeUint8Array = writeUint8Array;
|
|
||||||
that.getData = getData;
|
|
||||||
}
|
|
||||||
|
|
||||||
// inflate/deflate core functions
|
|
||||||
function launchProcess(process, reader, writer, offset, size, onappend, onprogress, onend, onreaderror, onwriteerror) {
|
|
||||||
var chunkIndex = 0, index, outputSize = 0;
|
|
||||||
|
|
||||||
function step() {
|
|
||||||
var outputData;
|
|
||||||
index = chunkIndex * CHUNK_SIZE;
|
|
||||||
if (index < size)
|
|
||||||
reader.readUint8Array(offset + index, Math.min(CHUNK_SIZE, size - index), function(inputData) {
|
|
||||||
var outputData = process.append(inputData, function() {
|
|
||||||
if (onprogress)
|
|
||||||
onprogress(offset + index, size);
|
|
||||||
});
|
|
||||||
outputSize += outputData.length;
|
|
||||||
onappend(true, inputData);
|
|
||||||
writer.writeUint8Array(outputData, function() {
|
|
||||||
onappend(false, outputData);
|
|
||||||
chunkIndex++;
|
|
||||||
setTimeout(step, 1);
|
|
||||||
}, onwriteerror);
|
|
||||||
if (onprogress)
|
|
||||||
onprogress(index, size);
|
|
||||||
}, onreaderror);
|
|
||||||
else {
|
|
||||||
outputData = process.flush();
|
|
||||||
if (outputData) {
|
|
||||||
outputSize += outputData.length;
|
|
||||||
writer.writeUint8Array(outputData, function() {
|
|
||||||
onappend(false, outputData);
|
|
||||||
onend(outputSize);
|
|
||||||
}, onwriteerror);
|
|
||||||
} else
|
|
||||||
onend(outputSize);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
step();
|
|
||||||
}
|
|
||||||
|
|
||||||
function inflate(reader, writer, offset, size, computeCrc32, onend, onprogress, onreaderror, onwriteerror) {
|
|
||||||
var crc32 = new Crc32();
|
|
||||||
|
|
||||||
function oninflateappend(sending, array) {
|
|
||||||
if (computeCrc32 && !sending)
|
|
||||||
crc32.append(array);
|
|
||||||
}
|
|
||||||
|
|
||||||
function oninflateend(outputSize) {
|
|
||||||
onend(outputSize, crc32.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
launchProcess(new Inflater(), reader, writer, offset, size, oninflateappend, onprogress, oninflateend, onreaderror, onwriteerror);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
function deflate(reader, writer, level, onend, onprogress, onreaderror, onwriteerror) {
|
|
||||||
var crc32 = new Crc32();
|
|
||||||
|
|
||||||
function ondeflateappend(sending, array) {
|
|
||||||
if (sending)
|
|
||||||
crc32.append(array);
|
|
||||||
}
|
|
||||||
|
|
||||||
function ondeflateend(outputSize) {
|
|
||||||
onend(outputSize, crc32.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
launchProcess(new Deflater(), reader, writer, 0, reader.size, ondeflateappend, onprogress, ondeflateend, onreaderror, onwriteerror);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
function copy(reader, writer, offset, size, computeCrc32, onend, onprogress, onreaderror, onwriteerror) {
|
|
||||||
var chunkIndex = 0, crc32 = new Crc32();
|
|
||||||
|
|
||||||
function step() {
|
|
||||||
var index = chunkIndex * CHUNK_SIZE;
|
|
||||||
if (index < size)
|
|
||||||
reader.readUint8Array(offset + index, Math.min(CHUNK_SIZE, size - index), function(array) {
|
|
||||||
if (computeCrc32)
|
|
||||||
crc32.append(array);
|
|
||||||
if (onprogress)
|
|
||||||
onprogress(index, size, array);
|
|
||||||
writer.writeUint8Array(array, function() {
|
|
||||||
chunkIndex++;
|
|
||||||
step();
|
|
||||||
}, onwriteerror);
|
|
||||||
}, onreaderror);
|
|
||||||
else
|
|
||||||
onend(size, crc32.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
step();
|
|
||||||
}
|
|
||||||
|
|
||||||
// ZipReader
|
|
||||||
|
|
||||||
function decodeASCII(str) {
|
|
||||||
var i, out = "", charCode, extendedASCII = [ '\u00C7', '\u00FC', '\u00E9', '\u00E2', '\u00E4', '\u00E0', '\u00E5', '\u00E7', '\u00EA', '\u00EB',
|
|
||||||
'\u00E8', '\u00EF', '\u00EE', '\u00EC', '\u00C4', '\u00C5', '\u00C9', '\u00E6', '\u00C6', '\u00F4', '\u00F6', '\u00F2', '\u00FB', '\u00F9',
|
|
||||||
'\u00FF', '\u00D6', '\u00DC', '\u00F8', '\u00A3', '\u00D8', '\u00D7', '\u0192', '\u00E1', '\u00ED', '\u00F3', '\u00FA', '\u00F1', '\u00D1',
|
|
||||||
'\u00AA', '\u00BA', '\u00BF', '\u00AE', '\u00AC', '\u00BD', '\u00BC', '\u00A1', '\u00AB', '\u00BB', '_', '_', '_', '\u00A6', '\u00A6',
|
|
||||||
'\u00C1', '\u00C2', '\u00C0', '\u00A9', '\u00A6', '\u00A6', '+', '+', '\u00A2', '\u00A5', '+', '+', '-', '-', '+', '-', '+', '\u00E3',
|
|
||||||
'\u00C3', '+', '+', '-', '-', '\u00A6', '-', '+', '\u00A4', '\u00F0', '\u00D0', '\u00CA', '\u00CB', '\u00C8', 'i', '\u00CD', '\u00CE',
|
|
||||||
'\u00CF', '+', '+', '_', '_', '\u00A6', '\u00CC', '_', '\u00D3', '\u00DF', '\u00D4', '\u00D2', '\u00F5', '\u00D5', '\u00B5', '\u00FE',
|
|
||||||
'\u00DE', '\u00DA', '\u00DB', '\u00D9', '\u00FD', '\u00DD', '\u00AF', '\u00B4', '\u00AD', '\u00B1', '_', '\u00BE', '\u00B6', '\u00A7',
|
|
||||||
'\u00F7', '\u00B8', '\u00B0', '\u00A8', '\u00B7', '\u00B9', '\u00B3', '\u00B2', '_', ' ' ];
|
|
||||||
for (i = 0; i < str.length; i++) {
|
|
||||||
charCode = str.charCodeAt(i) & 0xFF;
|
|
||||||
if (charCode > 127)
|
|
||||||
out += extendedASCII[charCode - 128];
|
|
||||||
else
|
|
||||||
out += String.fromCharCode(charCode);
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
function decodeUTF8(string) {
|
|
||||||
return decodeURIComponent(escape(string));
|
|
||||||
}
|
|
||||||
|
|
||||||
function getString(bytes) {
|
|
||||||
var i, str = "";
|
|
||||||
for (i = 0; i < bytes.length; i++)
|
|
||||||
str += String.fromCharCode(bytes[i]);
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getDate(timeRaw) {
|
|
||||||
var date = (timeRaw & 0xffff0000) >> 16, time = timeRaw & 0x0000ffff;
|
|
||||||
try {
|
|
||||||
return new Date(1980 + ((date & 0xFE00) >> 9), ((date & 0x01E0) >> 5) - 1, date & 0x001F, (time & 0xF800) >> 11, (time & 0x07E0) >> 5,
|
|
||||||
(time & 0x001F) * 2, 0);
|
|
||||||
} catch (e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function readCommonHeader(entry, data, index, centralDirectory, onerror) {
|
|
||||||
entry.version = data.view.getUint16(index, true);
|
|
||||||
entry.bitFlag = data.view.getUint16(index + 2, true);
|
|
||||||
entry.compressionMethod = data.view.getUint16(index + 4, true);
|
|
||||||
entry.lastModDateRaw = data.view.getUint32(index + 6, true);
|
|
||||||
entry.lastModDate = getDate(entry.lastModDateRaw);
|
|
||||||
if ((entry.bitFlag & 0x01) === 0x01) {
|
|
||||||
onerror(ERR_ENCRYPTED);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (centralDirectory || (entry.bitFlag & 0x0008) != 0x0008) {
|
|
||||||
entry.crc32 = data.view.getUint32(index + 10, true);
|
|
||||||
entry.compressedSize = data.view.getUint32(index + 14, true);
|
|
||||||
entry.uncompressedSize = data.view.getUint32(index + 18, true);
|
|
||||||
}
|
|
||||||
if (entry.compressedSize === 0xFFFFFFFF || entry.uncompressedSize === 0xFFFFFFFF) {
|
|
||||||
onerror(ERR_ZIP64);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
entry.filenameLength = data.view.getUint16(index + 22, true);
|
|
||||||
entry.extraFieldLength = data.view.getUint16(index + 24, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
function createZipReader(reader, onerror) {
|
|
||||||
function Entry() {
|
|
||||||
}
|
|
||||||
|
|
||||||
Entry.prototype.getData = function(writer, onend, onprogress, checkCrc32) {
|
|
||||||
var that = this;
|
|
||||||
|
|
||||||
function terminate(callback, param) {
|
|
||||||
if (callback)
|
|
||||||
callback(param);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCrc32(crc32) {
|
|
||||||
var dataCrc32 = getDataHelper(4);
|
|
||||||
dataCrc32.view.setUint32(0, crc32);
|
|
||||||
return that.crc32 == dataCrc32.view.getUint32(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getWriterData(uncompressedSize, crc32) {
|
|
||||||
if (checkCrc32 && !testCrc32(crc32))
|
|
||||||
onreaderror();
|
|
||||||
else
|
|
||||||
writer.getData(function(data) {
|
|
||||||
terminate(onend, data);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function onreaderror() {
|
|
||||||
terminate(onerror, ERR_READ_DATA);
|
|
||||||
}
|
|
||||||
|
|
||||||
function onwriteerror() {
|
|
||||||
terminate(onerror, ERR_WRITE_DATA);
|
|
||||||
}
|
|
||||||
|
|
||||||
reader.readUint8Array(that.offset, 30, function(bytes) {
|
|
||||||
var data = getDataHelper(bytes.length, bytes), dataOffset;
|
|
||||||
if (data.view.getUint32(0) != 0x504b0304) {
|
|
||||||
onerror(ERR_BAD_FORMAT);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
readCommonHeader(that, data, 4, false, onerror);
|
|
||||||
dataOffset = that.offset + 30 + that.filenameLength + that.extraFieldLength;
|
|
||||||
writer.init(function() {
|
|
||||||
if (that.compressionMethod === 0)
|
|
||||||
copy(reader, writer, dataOffset, that.compressedSize, checkCrc32, getWriterData, onprogress, onreaderror, onwriteerror);
|
|
||||||
else
|
|
||||||
inflate(reader, writer, dataOffset, that.compressedSize, checkCrc32, getWriterData, onprogress, onreaderror, onwriteerror);
|
|
||||||
}, onwriteerror);
|
|
||||||
}, onreaderror);
|
|
||||||
};
|
|
||||||
|
|
||||||
function seekEOCDR(offset, entriesCallback) {
|
|
||||||
reader.readUint8Array(reader.size - offset, offset, function(bytes) {
|
|
||||||
var dataView = getDataHelper(bytes.length, bytes).view;
|
|
||||||
if (dataView.getUint32(0) != 0x504b0506) {
|
|
||||||
seekEOCDR(offset + 1, entriesCallback);
|
|
||||||
} else {
|
|
||||||
entriesCallback(dataView);
|
|
||||||
}
|
|
||||||
}, function() {
|
|
||||||
onerror(ERR_READ);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
getEntries : function(callback) {
|
|
||||||
if (reader.size < 22) {
|
|
||||||
onerror(ERR_BAD_FORMAT);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// look for End of central directory record
|
|
||||||
seekEOCDR(22, function(dataView) {
|
|
||||||
var datalength, fileslength;
|
|
||||||
datalength = dataView.getUint32(16, true);
|
|
||||||
fileslength = dataView.getUint16(8, true);
|
|
||||||
reader.readUint8Array(datalength, reader.size - datalength, function(bytes) {
|
|
||||||
var i, index = 0, entries = [], entry, filename, comment, data = getDataHelper(bytes.length, bytes);
|
|
||||||
for (i = 0; i < fileslength; i++) {
|
|
||||||
entry = new Entry();
|
|
||||||
if (data.view.getUint32(index) != 0x504b0102) {
|
|
||||||
onerror(ERR_BAD_FORMAT);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
readCommonHeader(entry, data, index + 6, true, onerror);
|
|
||||||
entry.commentLength = data.view.getUint16(index + 32, true);
|
|
||||||
entry.directory = ((data.view.getUint8(index + 38) & 0x10) == 0x10);
|
|
||||||
entry.offset = data.view.getUint32(index + 42, true);
|
|
||||||
filename = getString(data.array.subarray(index + 46, index + 46 + entry.filenameLength));
|
|
||||||
entry.filename = ((entry.bitFlag & 0x0800) === 0x0800) ? decodeUTF8(filename) : decodeASCII(filename);
|
|
||||||
if (!entry.directory && entry.filename.charAt(entry.filename.length - 1) == "/")
|
|
||||||
entry.directory = true;
|
|
||||||
comment = getString(data.array.subarray(index + 46 + entry.filenameLength + entry.extraFieldLength, index + 46
|
|
||||||
+ entry.filenameLength + entry.extraFieldLength + entry.commentLength));
|
|
||||||
entry.comment = ((entry.bitFlag & 0x0800) === 0x0800) ? decodeUTF8(comment) : decodeASCII(comment);
|
|
||||||
entries.push(entry);
|
|
||||||
index += 46 + entry.filenameLength + entry.extraFieldLength + entry.commentLength;
|
|
||||||
}
|
|
||||||
callback(entries);
|
|
||||||
}, function() {
|
|
||||||
onerror(ERR_READ);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
|
||||||
close : function(callback) {
|
|
||||||
if (callback)
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// ZipWriter
|
|
||||||
|
|
||||||
function encodeUTF8(string) {
|
|
||||||
return unescape(encodeURIComponent(string));
|
|
||||||
}
|
|
||||||
|
|
||||||
function getBytes(str) {
|
|
||||||
var i, array = [];
|
|
||||||
for (i = 0; i < str.length; i++)
|
|
||||||
array.push(str.charCodeAt(i));
|
|
||||||
return array;
|
|
||||||
}
|
|
||||||
|
|
||||||
function createZipWriter(writer, onerror, dontDeflate) {
|
|
||||||
var files = {}, filenames = [], datalength = 0;
|
|
||||||
|
|
||||||
function terminate(callback, message) {
|
|
||||||
if (callback)
|
|
||||||
callback(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
function onwriteerror() {
|
|
||||||
terminate(onerror, ERR_WRITE);
|
|
||||||
}
|
|
||||||
|
|
||||||
function onreaderror() {
|
|
||||||
terminate(onerror, ERR_READ_DATA);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
add : function(name, reader, onend, onprogress, options) {
|
|
||||||
var header, filename, date;
|
|
||||||
|
|
||||||
function writeHeader(callback) {
|
|
||||||
var data;
|
|
||||||
date = options.lastModDate || new Date();
|
|
||||||
header = getDataHelper(26);
|
|
||||||
files[name] = {
|
|
||||||
headerArray : header.array,
|
|
||||||
directory : options.directory,
|
|
||||||
filename : filename,
|
|
||||||
offset : datalength,
|
|
||||||
comment : getBytes(encodeUTF8(options.comment || ""))
|
|
||||||
};
|
|
||||||
header.view.setUint32(0, 0x14000808);
|
|
||||||
if (options.version)
|
|
||||||
header.view.setUint8(0, options.version);
|
|
||||||
if (!dontDeflate && options.level !== 0 && !options.directory)
|
|
||||||
header.view.setUint16(4, 0x0800);
|
|
||||||
header.view.setUint16(6, (((date.getHours() << 6) | date.getMinutes()) << 5) | date.getSeconds() / 2, true);
|
|
||||||
header.view.setUint16(8, ((((date.getFullYear() - 1980) << 4) | (date.getMonth() + 1)) << 5) | date.getDate(), true);
|
|
||||||
header.view.setUint16(22, filename.length, true);
|
|
||||||
data = getDataHelper(30 + filename.length);
|
|
||||||
data.view.setUint32(0, 0x504b0304);
|
|
||||||
data.array.set(header.array, 4);
|
|
||||||
data.array.set(filename, 30);
|
|
||||||
datalength += data.array.length;
|
|
||||||
writer.writeUint8Array(data.array, callback, onwriteerror);
|
|
||||||
}
|
|
||||||
|
|
||||||
function writeFooter(compressedLength, crc32) {
|
|
||||||
var footer = getDataHelper(16);
|
|
||||||
datalength += compressedLength || 0;
|
|
||||||
footer.view.setUint32(0, 0x504b0708);
|
|
||||||
if (typeof crc32 != "undefined") {
|
|
||||||
header.view.setUint32(10, crc32, true);
|
|
||||||
footer.view.setUint32(4, crc32, true);
|
|
||||||
}
|
|
||||||
if (reader) {
|
|
||||||
footer.view.setUint32(8, compressedLength, true);
|
|
||||||
header.view.setUint32(14, compressedLength, true);
|
|
||||||
footer.view.setUint32(12, reader.size, true);
|
|
||||||
header.view.setUint32(18, reader.size, true);
|
|
||||||
}
|
|
||||||
writer.writeUint8Array(footer.array, function() {
|
|
||||||
datalength += 16;
|
|
||||||
terminate(onend);
|
|
||||||
}, onwriteerror);
|
|
||||||
}
|
|
||||||
|
|
||||||
function writeFile() {
|
|
||||||
options = options || {};
|
|
||||||
name = name.trim();
|
|
||||||
if (options.directory && name.charAt(name.length - 1) != "/")
|
|
||||||
name += "/";
|
|
||||||
if (files.hasOwnProperty(name)) {
|
|
||||||
onerror(ERR_DUPLICATED_NAME);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
filename = getBytes(encodeUTF8(name));
|
|
||||||
filenames.push(name);
|
|
||||||
writeHeader(function() {
|
|
||||||
if (reader)
|
|
||||||
if (dontDeflate || options.level === 0)
|
|
||||||
copy(reader, writer, 0, reader.size, true, writeFooter, onprogress, onreaderror, onwriteerror);
|
|
||||||
else
|
|
||||||
writeFooter();
|
|
||||||
}, onwriteerror);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (reader)
|
|
||||||
reader.init(writeFile, onreaderror);
|
|
||||||
else
|
|
||||||
writeFile();
|
|
||||||
},
|
|
||||||
close : function(callback) {
|
|
||||||
var data, length = 0, index = 0, indexFilename, file;
|
|
||||||
for (indexFilename = 0; indexFilename < filenames.length; indexFilename++) {
|
|
||||||
file = files[filenames[indexFilename]];
|
|
||||||
length += 46 + file.filename.length + file.comment.length;
|
|
||||||
}
|
|
||||||
data = getDataHelper(length + 22);
|
|
||||||
for (indexFilename = 0; indexFilename < filenames.length; indexFilename++) {
|
|
||||||
file = files[filenames[indexFilename]];
|
|
||||||
data.view.setUint32(index, 0x504b0102);
|
|
||||||
data.view.setUint16(index + 4, 0x1400);
|
|
||||||
data.array.set(file.headerArray, index + 6);
|
|
||||||
data.view.setUint16(index + 32, file.comment.length, true);
|
|
||||||
if (file.directory)
|
|
||||||
data.view.setUint8(index + 38, 0x10);
|
|
||||||
data.view.setUint32(index + 42, file.offset, true);
|
|
||||||
data.array.set(file.filename, index + 46);
|
|
||||||
data.array.set(file.comment, index + 46 + file.filename.length);
|
|
||||||
index += 46 + file.filename.length + file.comment.length;
|
|
||||||
}
|
|
||||||
data.view.setUint32(index, 0x504b0506);
|
|
||||||
data.view.setUint16(index + 8, filenames.length, true);
|
|
||||||
data.view.setUint16(index + 10, filenames.length, true);
|
|
||||||
data.view.setUint32(index + 12, length, true);
|
|
||||||
data.view.setUint32(index + 16, datalength, true);
|
|
||||||
writer.writeUint8Array(data.array, function() {
|
|
||||||
terminate(function() {
|
|
||||||
writer.getData(callback);
|
|
||||||
});
|
|
||||||
}, onwriteerror);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
FileReader : FileReader,
|
|
||||||
FileWriter : FileWriter,
|
|
||||||
createReader : function(reader, callback, onerror) {
|
|
||||||
reader.init(function() {
|
|
||||||
callback(createZipReader(reader, onerror));
|
|
||||||
}, onerror);
|
|
||||||
},
|
|
||||||
createWriter : function(writer, callback, onerror, dontDeflate) {
|
|
||||||
writer.init(function() {
|
|
||||||
callback(createZipWriter(writer, onerror, dontDeflate));
|
|
||||||
}, onerror);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
});
|
|
|
@ -6,6 +6,9 @@ define(function(require) {
|
||||||
var Environment = require('src/shell/environment');
|
var Environment = require('src/shell/environment');
|
||||||
var async = require('async');
|
var async = require('async');
|
||||||
|
|
||||||
|
require('zip');
|
||||||
|
require('unzip');
|
||||||
|
|
||||||
function Shell(fs, options) {
|
function Shell(fs, options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
|
|
||||||
|
@ -478,6 +481,7 @@ define(function(require) {
|
||||||
|
|
||||||
Shell.prototype.unzip = function(path, options, callback) {
|
Shell.prototype.unzip = function(path, options, callback) {
|
||||||
var fs = this.fs;
|
var fs = this.fs;
|
||||||
|
var sh = this;
|
||||||
if(typeof options === 'function') {
|
if(typeof options === 'function') {
|
||||||
callback = options;
|
callback = options;
|
||||||
options = {};
|
options = {};
|
||||||
|
@ -493,26 +497,31 @@ define(function(require) {
|
||||||
path = Path.resolve(this.cwd, path);
|
path = Path.resolve(this.cwd, path);
|
||||||
var destination = Path.resolve(options.destination || this.cwd);
|
var destination = Path.resolve(options.destination || this.cwd);
|
||||||
|
|
||||||
var Zip = require('zip.js/zip');
|
fs.readFile(path, function(err, data) {
|
||||||
Zip.createReader(new Zip.FileReader(path, fs), function(reader) {
|
if(err) return callback(err);
|
||||||
reader.getEntries(function(entries) {
|
|
||||||
|
|
||||||
function inflate(entry, callback) {
|
var unzip = new Zlib.Unzip(data);
|
||||||
var path = Path.join(destination, entry.filename);
|
// Separate filenames within the zip archive with what will go in fs
|
||||||
if(entry.directory) {
|
var filenames = unzip.getFilenames().map(function(filename) {
|
||||||
this.mkdirp(path, callback);
|
return {
|
||||||
} else {
|
zipFilename: filename,
|
||||||
console.log('inflate', path);
|
fsFilename: Path.join(destination, filename)
|
||||||
entry.getData(new Zip.FileWriter(path, fs), function() { callback(); });
|
};
|
||||||
}
|
});
|
||||||
|
|
||||||
|
function decompress(path, callback) {
|
||||||
|
var data = unzip.decompress(path.zipFilename);
|
||||||
|
|
||||||
|
// Make sure the dir(s) we need exist before writing file
|
||||||
|
var dir = Path.dirname(path.fsFilename);
|
||||||
|
sh.mkdirp(dir, function(err) {
|
||||||
|
console.log('inflate', path.zipFilename, path.fsFilename);
|
||||||
|
fs.writeFile(path.fsFilename, data, callback);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async.eachSeries(entries, inflate, function(error) {
|
async.eachSeries(filenames, decompress, callback);
|
||||||
if(error) return callback(error);
|
|
||||||
reader.close(callback);
|
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}, callback);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Shell.prototype.zip = function(zipfile, paths, options, callback) {
|
Shell.prototype.zip = function(zipfile, paths, options, callback) {
|
||||||
|
@ -537,29 +546,28 @@ console.log('inflate', path);
|
||||||
}
|
}
|
||||||
zipfile = Path.resolve(this.cwd, zipfile);
|
zipfile = Path.resolve(this.cwd, zipfile);
|
||||||
|
|
||||||
var Zip = require('zip.js/zip');
|
function encode(s) {
|
||||||
function zipPath(path, callback) {
|
return new TextEncoder('utf8').encode(s);
|
||||||
Zip.createWriter(new Zip.FileWriter(zipfile, fs), function(writer) {
|
|
||||||
var realpath = Path.resolve(this.cwd, path);
|
|
||||||
fs.stat(realpath, function(err, stats) {
|
|
||||||
if(err) {
|
|
||||||
callback(err);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tack on zip entry options we care about.
|
function add(path, callback) {
|
||||||
var options = { lastModDate: new Date(stats.mtime) };
|
fs.readFile(path, function(err, data) {
|
||||||
if(stats.isDirectory()) {
|
if(err) return callback(err);
|
||||||
options.directory = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
writer.add(path, new Zip.FileReader(realpath, fs),
|
// Make path relative within the zip
|
||||||
function() { writer.close(function() { callback(); }); }, null, options);
|
var relpath = path.replace(/^\//, '');
|
||||||
|
zip.addFile(data, { filename: encode(relpath) });
|
||||||
|
callback();
|
||||||
});
|
});
|
||||||
}, function(err) { callback(err); });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async.eachSeries(paths, zipPath, callback);
|
var zip = new Zlib.Zip();
|
||||||
|
async.eachSeries(paths, add, function(err) {
|
||||||
|
if(err) return callback(err);
|
||||||
|
|
||||||
|
var compressed = zip.compress();
|
||||||
|
fs.writeFile(zipfile, compressed, callback);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return Shell;
|
return Shell;
|
||||||
|
|
|
@ -51,27 +51,32 @@ define(["Filer", "util"], function(Filer, util) {
|
||||||
|
|
||||||
it('should be able to zip and unzip a file', function(done) {
|
it('should be able to zip and unzip a file', function(done) {
|
||||||
var fs = util.fs();
|
var fs = util.fs();
|
||||||
var file = 'test-file.txt';
|
var file = '/test-file.txt';
|
||||||
var zipfile = file + '.zip';
|
var zipfile = file + '.zip';
|
||||||
var shell = fs.Shell();
|
var shell = fs.Shell();
|
||||||
var Path = Filer.Path;
|
var Path = Filer.Path;
|
||||||
var contents = "This is a test file used in some of the tests.\n";
|
var contents = "This is a test file used in some of the tests.\n";
|
||||||
|
|
||||||
shell.tempDir(function(err, tmp) {
|
fs.writeFile(file, contents, function(err) {
|
||||||
if(err) throw err;
|
if(err) throw err;
|
||||||
|
|
||||||
var filepath = Path.join(tmp, file);
|
shell.zip(zipfile, file, function(err) {
|
||||||
var zipfilepath = Path.join('/', zipfile);
|
|
||||||
|
|
||||||
fs.writeFile(filepath, contents, function(err) {
|
|
||||||
if(err) throw err;
|
if(err) throw err;
|
||||||
|
|
||||||
shell.zip(zipfilepath, filepath, function(err) {
|
fs.stat(zipfile, function(err, stats) {
|
||||||
|
if(err) throw err;
|
||||||
|
expect(stats.isFile()).to.be.true;
|
||||||
|
|
||||||
|
shell.rm(file, function(err) {
|
||||||
if(err) throw err;
|
if(err) throw err;
|
||||||
|
|
||||||
shell.unzip(zipfilepath, function(err) {
|
shell.unzip(zipfile, function(err) {
|
||||||
if(err) throw err;
|
if(err) throw err;
|
||||||
|
|
||||||
|
fs.stat(file, function(err, stats) {
|
||||||
|
if(err) throw err;
|
||||||
|
expect(stats.isFile()).to.be.true;
|
||||||
|
|
||||||
fs.readFile(Path.join('/', file), 'utf8', function(err, data) {
|
fs.readFile(Path.join('/', file), 'utf8', function(err, data) {
|
||||||
if(err) throw err;
|
if(err) throw err;
|
||||||
expect(data).to.equal(contents);
|
expect(data).to.equal(contents);
|
||||||
|
@ -82,6 +87,8 @@ define(["Filer", "util"], function(Filer, util) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue