Created
May 28, 2013 14:02
-
-
Save zefanja/5662970 to your computer and use it in GitHub Desktop.
browser implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script type="text/javascript" src="lib/inflate_stream.min.js"></script> | |
</head> | |
<body> | |
<h2>Sword Browser Version</h2> | |
<input type="file" id="files" name="files[]"/> | |
<script type="text/javascript" src="sword.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** @license zlib.js 2012 - imaya [ https://github.com/imaya/zlib.js ] The MIT License */ | |
(function() {'use strict';var i=void 0,m=!0,aa=this;function q(a,c){var b=a.split("."),d=aa;!(b[0]in d)&&d.execScript&&d.execScript("var "+b[0]);for(var e;b.length&&(e=b.shift());)!b.length&&c!==i?d[e]=c:d=d[e]?d[e]:d[e]={}};var r="undefined"!==typeof Uint8Array&&"undefined"!==typeof Uint16Array&&"undefined"!==typeof Uint32Array;new (r?Uint8Array:Array)(256);var s;for(s=0;256>s;++s)for(var t=s,ba=7,t=t>>>1;t;t>>>=1)--ba;var ca=[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];r&&new Uint32Array(ca);function u(a){var c=a.length,b=0,d=Number.POSITIVE_INFINITY,e,f,g,h,j,l,k,n,p;for(n=0;n<c;++n)a[n]>b&&(b=a[n]),a[n]<d&&(d=a[n]);e=1<<b;f=new (r?Uint32Array:Array)(e);g=1;h=0;for(j=2;g<=b;){for(n=0;n<c;++n)if(a[n]===g){l=0;k=h;for(p=0;p<g;++p)l=l<<1|k&1,k>>=1;for(p=l;p<e;p+=j)f[p]=g<<16|n;++h}++g;h<<=1;j<<=1}return[f,b,d]};var v=[],w;for(w=0;288>w;w++)switch(m){case 143>=w:v.push([w+48,8]);break;case 255>=w:v.push([w-144+400,9]);break;case 279>=w:v.push([w-256+0,7]);break;case 287>=w:v.push([w-280+192,8]);break;default:throw"invalid literal: "+w;} | |
function da(){var a=x;switch(m){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 y=[],x,z; | |
for(x=3;258>=x;x++)z=da(),y[x]=z[2]<<24|z[1]<<16|z[0];r&&new Uint32Array(y);var ea=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];r&&new Uint16Array(ea);var fa=[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];r&&new Uint16Array(fa);var 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];r&&new Uint8Array(ga);var 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];r&&new Uint16Array(ha); | |
var ia=[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];r&&new Uint8Array(ia);var A=new (r?Uint8Array:Array)(288),B,C;B=0;for(C=A.length;B<C;++B)A[B]=143>=B?8:255>=B?9:279>=B?7:8;u(A);var D=new (r?Uint8Array:Array)(30),E,F;E=0;for(F=D.length;E<F;++E)D[E]=5;u(D);function G(a,c,b){this.t=[];this.q=b?b:32768;this.u=0;this.a=c===i?0:c;this.d=this.e=0;this.input=r?new Uint8Array(a):a;this.c=new (r?Uint8Array:Array)(this.q);this.b=0;this.s=this.l=!1;this.f=0;this.status=H}var H=0; | |
G.prototype.i=function(a,c){var b=!1;a!==i&&(this.input=a);c!==i&&(this.a=c);for(;!b;)switch(this.status){case H:case 1:var d;var e=i;this.status=1;I(this);if(0>(e=J(this,3)))K(this),d=-1;else{e&1&&(this.l=m);e>>>=1;switch(e){case 0:this.g=0;break;case 1:this.g=1;break;case 2:this.g=2;break;default:throw Error("unknown BTYPE: "+e);}this.status=2;d=i}0>d&&(b=m);break;case 2:case 3:switch(this.g){case 0:0>ja(this)&&(b=m);break;case 1:this.status=3;this.k=ka;this.n=la;this.status=4;break;case 2:0>ma(this)&& | |
(b=m)}break;case 4:case 5:switch(this.g){case 0:var f;a:{var g=this.input,h=this.a,j=this.c,l=this.b,k=this.m;for(this.status=5;k--;){l===j.length&&(j=L(this));if(g[h]===i){this.a=h;this.b=l;this.m=k+1;f=-1;break a}j[l++]=g[h++]}0>k&&(this.status=6);this.a=h;this.b=l;f=0}0>f&&(b=m);break;case 1:case 2:0>na(this)&&(b=m)}break;case 6:this.l?b=m:this.status=H}var n,p=this.b;this.s?r?(n=new Uint8Array(p),n.set(this.c.subarray(this.f,p))):n=this.c.slice(this.f,p):n=r?this.c.subarray(this.f,p):this.c.slice(this.f, | |
p);this.buffer=n;this.f=p;return this.buffer}; | |
var M=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],N=r?new Uint16Array(M):M,O=[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],oa=r?new Uint16Array(O):O,P=[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],Q=r?new Uint8Array(P):P,R=[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],pa=r?new Uint16Array(R):R,S=[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],T=r?new Uint8Array(S):S,U=new (r?Uint8Array:Array)(288),V,W;V=0;for(W=U.length;V<W;++V)U[V]=143>=V?8:255>=V?9:279>=V?7:8;var ka=u(U),X=new (r?Uint8Array:Array)(30),Y,qa;Y=0;for(qa=X.length;Y<qa;++Y)X[Y]=5;var la=u(X);function J(a,c){for(var b=a.e,d=a.d,e=a.input,f=a.a,g;d<c;){g=e[f++];if(g===i)return-1;b|=g<<d;d+=8}g=b&(1<<c)-1;a.e=b>>>c;a.d=d-c;a.a=f;return g} | |
function Z(a,c){for(var b=a.e,d=a.d,e=a.input,f=a.a,g=c[0],h=c[1],j,l,k;d<h;){j=e[f++];if(j===i)return-1;b|=j<<d;d+=8}l=g[b&(1<<h)-1];k=l>>>16;a.e=b>>k;a.d=d-k;a.a=f;return l&65535}function ja(a){var c,b,d,e=a.input,f=a.a;a.status=3;c=e[f++];if(c===i)return-1;b=c;c=e[f++];if(c===i)return-1;b|=c<<8;c=e[f++];if(c===i)return-1;d=c;c=e[f++];if(c===i)return-1;if(b===~(d|c<<8))throw Error("invalid uncompressed block header: length verify");a.e=0;a.d=0;a.a=f;a.m=b;a.status=4} | |
function I(a){a.r=a.a;a.p=a.d;a.o=a.e}function K(a){a.a=a.r;a.d=a.p;a.e=a.o} | |
function ma(a){var c,b,d,e=new (r?Uint8Array:Array)(N.length),f,g,h,j=0;a.status=3;I(a);c=J(a,5)+257;b=J(a,5)+1;d=J(a,4)+4;if(0>c||0>b||0>d)return K(a),-1;try{for(var l=function(a,b,c){for(var d,e,f,g=0,h,g=0;g<a;){d=Z(this,b);if(0>d)throw Error("not enough input");switch(d){case 16:if(0>(h=J(this,2)))throw Error("not enough input");for(f=3+h;f--;)c[g++]=e;break;case 17:if(0>(h=J(this,3)))throw Error("not enough input");for(f=3+h;f--;)c[g++]=0;e=0;break;case 18:if(0>(h=J(this,7)))throw Error("not enough input"); | |
for(f=11+h;f--;)c[g++]=0;e=0;break;default:e=c[g++]=d}}return c},k,j=0;j<d;++j){if(0>(k=J(a,3)))throw Error("not enough input");e[N[j]]=k}f=u(e);g=new (r?Uint8Array:Array)(c);h=new (r?Uint8Array:Array)(b);a.k=u(l.call(a,c,f,g));a.n=u(l.call(a,b,f,h))}catch(n){return K(a),-1}a.status=4;return 0} | |
function na(a){var c=a.c,b=a.b,d,e,f,g,h=a.k,j=a.n,l=c.length,k;for(a.status=5;;){I(a);d=Z(a,h);if(0>d)return a.b=b,K(a),-1;if(256===d)break;if(256>d)b===l&&(c=L(a),l=c.length),c[b++]=d;else{e=d-257;g=oa[e];if(0<Q[e]){k=J(a,Q[e]);if(0>k)return a.b=b,K(a),-1;g+=k}d=Z(a,j);if(0>d)return a.b=b,K(a),-1;f=pa[d];if(0<T[d]){k=J(a,T[d]);if(0>k)return a.b=b,K(a),-1;f+=k}b+g>=l&&(c=L(a),l=c.length);for(;g--;)c[b]=c[b++-f];if(a.a===a.input.length)return a.b=b,-1}}for(;8<=a.d;)a.d-=8,a.a--;a.b=b;a.status=6} | |
function L(a){var c,b=a.input.length/a.a+1|0,d,e,f,g=a.input,h=a.c;2>b?(d=(g.length-a.a)/a.k[2],f=258*(d/2)|0,e=f<h.length?h.length+f:h.length<<1):e=h.length*b;r?(c=new Uint8Array(e),c.set(h)):c=h;a.c=c;return a.c}G.prototype.j=function(){return r?this.c.subarray(0,this.b):this.c.slice(0,this.b)};function $(a){this.input=a===i?new (r?Uint8Array:Array):a;this.a=0;this.h=new G(this.input,this.a);this.c=this.h.c} | |
$.prototype.i=function(a){var c;if(a!==i)if(r){var b=new Uint8Array(this.input.length+a.length);b.set(this.input,0);b.set(a,this.input.length);this.input=b}else this.input=this.input.concat(a);var d;if(d=this.method===i){var e;var f=this.a,g=this.input,h=g[f++],j=g[f++];if(h===i||j===i)e=-1;else{switch(h&15){case ra:this.method=ra;break;default:throw Error("unsupported compression method");}if(0!==((h<<8)+j)%31)throw Error("invalid fcheck flag:"+((h<<8)+j)%31);if(j&32)throw Error("fdict flag is not supported"); | |
this.a=f;e=i}d=0>e}if(d)return new (r?Uint8Array:Array);c=this.h.i(this.input,this.a);this.a=this.h.a;return c};$.prototype.j=function(){return this.h.j()};q("Zlib.InflateStream",$);q("Zlib.InflateStream.prototype.decompress",$.prototype.i);q("Zlib.InflateStream.prototype.getBytes",$.prototype.j);var ra=8;}).call(this); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var inflator = new Zlib.InflateStream(); | |
function handleFileSelect(evt) { | |
var files = evt.target.files; // FileList object | |
// files is a FileList of File objects. List some properties. | |
var blob = null; | |
for (var i = 0, f; f = files[i]; i++) { | |
console.log(escape(f.name), f.type, f.size); | |
blob = f.slice(0, 3980); | |
console.log(blob); | |
} | |
var reader = new FileReader(); | |
// If we use onloadend, we need to check the readyState. | |
reader.onloadend = function(evt) { | |
if (evt.target.readyState == FileReader.DONE) { // DONE == 2 | |
console.log("RESULT:", new Uint8Array(evt.target.result)); | |
var inflated = inflator.decompress(new Uint8Array(evt.target.result)); | |
console.log(inflated); | |
var resultBlob = new Blob([inflated]); | |
console.log("rBlob", resultBlob); | |
var f = new FileReader(); | |
f.readAsText(resultBlob); | |
f.onload = function(e) { | |
console.log(e.target.result); | |
}; | |
} | |
}; | |
reader.readAsArrayBuffer(blob); | |
//reader.readAsBinaryString(blob); | |
} | |
document.getElementById("files").addEventListener('change', handleFileSelect, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment