/*
 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.
 */
'use strict';(function(n){function A(){this.crc=-1}function I(){}function U(c,b,a){if(0>b||0>a||b+a>c.size)throw new RangeError("offset:"+b+", length:"+a+", size:"+c.size);if(c.slice)return c.slice(b,b+a);if(c.webkitSlice)return c.webkitSlice(b,b+a);if(c.mozSlice)return c.mozSlice(b,b+a);if(c.msSlice)return c.msSlice(b,b+a)}function y(c,b){var a,f;a=new ArrayBuffer(c);f=new Uint8Array(a);b&&f.set(b,0);return{buffer:a,array:f,view:new DataView(a)}}function C(){}function D(c){var b=this,a;b.size=0;
b.init=function(f,h){var d=new Blob([c],{type:"text/plain"});a=new z(d);a.init(function(){b.size=a.size;f()},h)};b.readUint8Array=function(c,b,d,g){a.readUint8Array(c,b,d,g)}}function E(c){var b=this,a;b.size=0;b.init=function(f){for(var h=c.length;"="==c.charAt(h-1);)h--;a=c.indexOf(",")+1;b.size=Math.floor(.75*(h-a));f()};b.readUint8Array=function(b,h,d){var g=y(h),k=4*Math.floor(b/3),p=n.atob(c.substring(k+a,4*Math.ceil((b+h)/3)+a));for(b=k=b-3*Math.floor(k/4);b<k+h;b++)g.array[b-k]=p.charCodeAt(b);
d(g.array)}}function z(c){var b=this;b.size=0;b.init=function(a){b.size=c.size;a()};b.readUint8Array=function(a,b,h,d){var g=new FileReader;g.onload=function(a){h(new Uint8Array(a.target.result))};g.onerror=d;try{g.readAsArrayBuffer(U(c,a,b))}catch(k){d(k)}}}function w(){}function F(c){var b;this.init=function(a){b=new Blob([],{type:"text/plain"});a()};this.writeUint8Array=function(a,c){b=new Blob([b,J?a:a.buffer],{type:"text/plain"});c()};this.getData=function(a,f){var h=new FileReader;h.onload=
function(c){a(c.target.result)};h.onerror=f;h.readAsText(b,c)}}function G(c){var b="",a="";this.init=function(a){b+="data:"+(c||"")+";base64,";a()};this.writeUint8Array=function(c,h){var d,g=a.length,k=a;a="";for(d=0;d<3*Math.floor((g+c.length)/3)-g;d++)k+=String.fromCharCode(c[d]);for(;d<c.length;d++)a+=String.fromCharCode(c[d]);2<k.length?b+=n.btoa(k):a=k;h()};this.getData=function(c){c(b+n.btoa(a))}}function H(c){var b;this.init=function(a){b=new Blob([],{type:c});a()};this.writeUint8Array=function(a,
f){b=new Blob([b,J?a:a.buffer],{type:c});f()};this.getData=function(c){c(b)}}function K(c,b,a,f,h,d,g,k,p,x){function q(){c.removeEventListener("message",t,!1);k(e,M)}function t(a){a=a.data;var b=a.data,k=a.error;if(k)k.toString=function(){return"Error: "+this.message},p(k);else if(a.sn===l)switch("number"===typeof a.codecTime&&(c.codecTime+=a.codecTime),"number"===typeof a.crcTime&&(c.crcTime+=a.crcTime),a.type){case "append":b?(e+=b.length,f.writeUint8Array(b,function(){m()},x)):m();break;case "flush":M=
a.crc;b?(e+=b.length,f.writeUint8Array(b,function(){q()},x)):q();break;case "progress":g&&g(r+a.loaded,d);break;case "importScripts":case "newTask":case "echo":break;default:console.warn("zip.js:launchWorkerProcess: unknown message: ",a)}}function m(){r=524288*u;r<d?a.readUint8Array(h+r,Math.min(524288,d-r),function(a){g&&g(r,d);var e=0===r?b:{sn:l};e.type="append";e.data=a;try{c.postMessage(e,[a.buffer])}catch(k){c.postMessage(e)}u++},p):c.postMessage({sn:l,type:"flush"})}var u=0,r,e,l=b.sn,M;e=
0;c.addEventListener("message",t,!1);m()}function L(c,b,a,f,h,d,g,k,p,x){function q(){var d;m=524288*t;if(m<h)b.readUint8Array(f+m,Math.min(524288,h-m),function(b){var k;try{k=c.append(b,function(a){g&&g(m+a,h)})}catch(d){p(d);return}k?(u+=k.length,a.writeUint8Array(k,function(){t++;setTimeout(q,1)},x),e&&l.append(k)):(t++,setTimeout(q,1));r&&l.append(b);g&&g(m,h)},p);else{try{d=c.flush()}catch(n){p(n);return}d?(e&&l.append(d),u+=d.length,a.writeUint8Array(d,function(){k(u,l.get())},x)):k(u,l.get())}}
var t=0,m,u=0,r="input"===d,e="output"===d,l=new A;q()}function N(c,b,a,f,h,d,g,k,p,x,q){n.zip.useWebWorkers&&g?K(c,{sn:b,codecClass:"NOOP",crcType:"input"},a,f,h,d,p,k,x,q):L(new I,a,f,h,d,"input",p,k,x,q)}function O(c){var b,a="",f,h="\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\u00c8i\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_ ".split("");
for(b=0;b<c.length;b++)f=c.charCodeAt(b)&255,a=127<f?a+h[f-128]:a+String.fromCharCode(f);return a}function P(c){var b,a="";for(b=0;b<c.length;b++)a+=String.fromCharCode(c[b]);return a}function Q(c,b,a,f,h){c.version=b.view.getUint16(a,!0);c.bitFlag=b.view.getUint16(a+2,!0);c.compressionMethod=b.view.getUint16(a+4,!0);c.lastModDateRaw=b.view.getUint32(a+6,!0);var d;a:{var g=c.lastModDateRaw,k=(g&4294901760)>>16,g=g&65535;try{d=new Date(1980+((k&65024)>>9),((k&480)>>5)-1,k&31,(g&63488)>>11,(g&2016)>>
5,2*(g&31),0);break a}catch(p){}d=void 0}c.lastModDate=d;if(1===(c.bitFlag&1))h("File contains encrypted entry.");else{if(f||8!=(c.bitFlag&8))c.crc32=b.view.getUint32(a+10,!0),c.compressedSize=b.view.getUint32(a+14,!0),c.uncompressedSize=b.view.getUint32(a+18,!0);4294967295===c.compressedSize||4294967295===c.uncompressedSize?h("File is using Zip64 (4gb+ file size)."):(c.filenameLength=b.view.getUint16(a+22,!0),c.extraFieldLength=b.view.getUint16(a+24,!0))}}function V(c,b,a){function f(){}function h(b){function d(g,
h){c.readUint8Array(c.size-g,g,function(a){for(var c=a.length-22;0<=c;c--)if(80===a[c]&&75===a[c+1]&&5===a[c+2]&&6===a[c+3]){b(new DataView(a.buffer,c,22));return}h()},function(){a("Error while reading zip file.")})}22>c.size?a("File format is not recognized."):d(22,function(){d(Math.min(65558,c.size),function(){a("File format is not recognized.")})})}var d=0;f.prototype.getData=function(b,g,h,f){function t(a){var c=y(4);c.view.setUint32(0,a);return e.crc32==c.view.getUint32(0)}function m(c,e){f&&
!t(e)?a("CRC failed."):b.getData(function(a){g(a)})}function u(c){a(c||"Error while reading file data.")}function r(c){a(c||"Error while writing file data.")}var e=this;c.readUint8Array(e.offset,30,function(g){g=y(g.length,g);var t;1347093252!=g.view.getUint32(0)?a("File format is not recognized."):(Q(e,g,4,!1,a),t=e.offset+30+e.filenameLength+e.extraFieldLength,b.init(function(){if(0===e.compressionMethod)N(e._worker,d++,c,b,t,e.compressedSize,f,m,h,u,r);else{var a=d++,g=e.compressedSize,l=f?"output":
"none";n.zip.useWebWorkers?K(e._worker,{sn:a,codecClass:"Inflater",crcType:l},c,b,t,g,h,m,u,r):L(new n.zip.Inflater,c,b,t,g,l,h,m,u,r)}},r))},u)};var g={getEntries:function(b){var g=this._worker;h(function(d){var h,t;h=d.getUint32(16,!0);t=d.getUint16(8,!0);0>h||h>=c.size?a("File format is not recognized."):c.readUint8Array(h,c.size-h,function(c){var d=0,h=[],e,l,n=y(c.length,c);for(c=0;c<t;c++){e=new f;e._worker=g;if(1347092738!=n.view.getUint32(d)){a("File format is not recognized.");return}Q(e,
n,d+6,!0,a);e.commentLength=n.view.getUint16(d+32,!0);e.directory=16==(n.view.getUint8(d+38)&16);e.offset=n.view.getUint32(d+42,!0);l=P(n.array.subarray(d+46,d+46+e.filenameLength));e.filename=2048===(e.bitFlag&2048)?decodeURIComponent(escape(l)):O(l);e.directory||"/"!=e.filename.charAt(e.filename.length-1)||(e.directory=!0);l=P(n.array.subarray(d+46+e.filenameLength+e.extraFieldLength,d+46+e.filenameLength+e.extraFieldLength+e.commentLength));e.comment=2048===(e.bitFlag&2048)?decodeURIComponent(escape(l)):
O(l);h.push(e);d+=46+e.filenameLength+e.extraFieldLength+e.commentLength}b(h)},function(){a("Error while reading zip file.")})})},close:function(a){this._worker&&(this._worker.terminate(),this._worker=null);a&&a()},_worker:null};n.zip.useWebWorkers?R("inflater",function(a){g._worker=a;b(g)},function(c){a(c)}):b(g)}function S(c){var b,a=[];for(b=0;b<c.length;b++)a.push(c.charCodeAt(b));return a}function W(c,b,a,f){function h(c){a(c||"Error while writing zip file.")}function d(c){a(c||"Error while reading file data.")}
var g={},k=[],p=0,x=0,q={add:function(b,m,u,r,e){function l(a){var d;B=e.lastModDate||new Date;v=y(26);g[b]={headerArray:v.array,directory:e.directory,filename:w,offset:p,comment:S(unescape(encodeURIComponent(e.comment||"")))};v.view.setUint32(0,335546376);e.version&&v.view.setUint8(0,e.version);f||0===e.level||e.directory||v.view.setUint16(4,2048);v.view.setUint16(6,(B.getHours()<<6|B.getMinutes())<<5|B.getSeconds()/2,!0);v.view.setUint16(8,(B.getFullYear()-1980<<4|B.getMonth()+1)<<5|B.getDate(),
!0);v.view.setUint16(22,w.length,!0);d=y(30+w.length);d.view.setUint32(0,1347093252);d.array.set(v.array,4);d.array.set(w,30);p+=d.array.length;c.writeUint8Array(d.array,a,h)}function q(a,b){var d=y(16);p+=a||0;d.view.setUint32(0,1347094280);"undefined"!=typeof b&&(v.view.setUint32(10,b,!0),d.view.setUint32(4,b,!0));m&&(d.view.setUint32(8,a,!0),v.view.setUint32(14,a,!0),d.view.setUint32(12,m.size,!0),v.view.setUint32(18,m.size,!0));c.writeUint8Array(d.array,function(){p+=16;u()},h)}function z(){e=
e||{};b=b.trim();e.directory&&"/"!=b.charAt(b.length-1)&&(b+="/");g.hasOwnProperty(b)?a("File already exists."):(w=S(unescape(encodeURIComponent(b))),k.push(b),l(function(){if(m)if(f||0===e.level)N(A,x++,m,c,0,m.size,!0,q,r,d,h);else{var a=x++;n.zip.useWebWorkers?K(A,{sn:a,options:{level:e.level},codecClass:"Deflater",crcType:"input"},m,c,0,m.size,r,q,d,h):L(new n.zip.Deflater,m,c,0,m.size,"input",r,q,d,h)}else q()},h))}var v,w,B,A=this._worker;m?m.init(z,d):z()},close:function(a){this._worker&&(this._worker.terminate(),
this._worker=null);var b,d=0,f=0,e,l;for(e=0;e<k.length;e++)l=g[k[e]],d+=46+l.filename.length+l.comment.length;b=y(d+22);for(e=0;e<k.length;e++)l=g[k[e]],b.view.setUint32(f,1347092738),b.view.setUint16(f+4,5120),b.array.set(l.headerArray,f+6),b.view.setUint16(f+32,l.comment.length,!0),l.directory&&b.view.setUint8(f+38,16),b.view.setUint32(f+42,l.offset,!0),b.array.set(l.filename,f+46),b.array.set(l.comment,f+46+l.filename.length),f+=46+l.filename.length+l.comment.length;b.view.setUint32(f,1347093766);
b.view.setUint16(f+8,k.length,!0);b.view.setUint16(f+10,k.length,!0);b.view.setUint32(f+12,d,!0);b.view.setUint32(f+16,p,!0);c.writeUint8Array(b.array,function(){c.getData(a)},h)},_worker:null};n.zip.useWebWorkers?R("deflater",function(a){q._worker=a;b(q)},function(b){a(b)}):b(q)}function X(c){var b=document.createElement("a");return c.map(function(a){b.href=a;return b.href})}function R(c,b,a){function f(c){c=c.data;c.error?(g.terminate(),a(c.error)):"importScripts"===c.type&&(g.removeEventListener("message",
f),g.removeEventListener("error",h),b(g))}function h(b){g.terminate();a(b)}if(null!==n.zip.workerScripts&&null!==n.zip.workerScriptsPath)a(Error("Either zip.workerScripts or zip.workerScriptsPath may be set, not both."));else{var d;if(n.zip.workerScripts){d=n.zip.workerScripts[c];if(!Array.isArray(d)){a(Error("zip.workerScripts."+c+" is not an array!"));return}d=X(d)}else d=Y[c].slice(0),d[0]=(n.zip.workerScriptsPath||"")+d[0];var g=new Worker(d[0]);g.codecTime=g.crcTime=0;g.postMessage({type:"importScripts",
scripts:d.slice(1)});g.addEventListener("message",f);g.addEventListener("error",h)}}function T(c){console.error(c)}var J;try{J=0===(new Blob([new DataView(new ArrayBuffer(0))])).size}catch(c){}A.prototype.append=function(c){for(var b=this.crc|0,a=this.table,f=0,h=c.length|0;f<h;f++)b=b>>>8^a[(b^c[f])&255];this.crc=b};A.prototype.get=function(){return~this.crc};A.prototype.table=function(){var c,b,a,f=[];for(c=0;256>c;c++){a=c;for(b=0;8>b;b++)a=a&1?a>>>1^3988292384:a>>>1;f[c]=a}return f}();I.prototype.append=
function(c,b){return c};I.prototype.flush=function(){};D.prototype=new C;D.prototype.constructor=D;E.prototype=new C;E.prototype.constructor=E;z.prototype=new C;z.prototype.constructor=z;w.prototype.getData=function(c){c(this.data)};F.prototype=new w;F.prototype.constructor=F;G.prototype=new w;G.prototype.constructor=G;H.prototype=new w;H.prototype.constructor=H;var Y={deflater:["z-worker.js","deflate.js"],inflater:["z-worker.js","inflate.js"]};n.zip={Reader:C,Writer:w,BlobReader:z,Data64URIReader:E,
TextReader:D,BlobWriter:H,Data64URIWriter:G,TextWriter:F,createReader:function(c,b,a){a=a||T;c.init(function(){V(c,b,a)},a)},createWriter:function(c,b,a,f){a=a||T;f=!!f;c.init(function(){W(c,b,a,f)},a)},useWebWorkers:!0,workerScriptsPath:null,workerScripts:null}})(this);
