diff --git a/bower.json b/bower.json index 34f6536..e7e8ff3 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "filer", - "version": "0.0.9", + "version": "0.0.10", "main": "dist/filer.js", "devDependencies": { "mocha": "1.17.1", diff --git a/dist/filer.js b/dist/filer.js index 5363c6b..c89b3d6 100644 --- a/dist/filer.js +++ b/dist/filer.js @@ -966,602 +966,7 @@ }()); }).call(this,_dereq_("FWaASH")) -},{"FWaASH":7}],2:[function(_dereq_,module,exports){ -/*! - * Shim implementation of the TextEncoder, TextDecoder spec: - * http://encoding.spec.whatwg.org/#interface-textencoder - * - * http://code.google.com/p/stringencoding/source/browse/encoding.js - * 09b44d71759d on Sep 19, 2013 - * Used under Apache License 2.0 - http://code.google.com/p/stringencoding/ - * - * Filer: modified to remove non-utf8 aspects, converted to CommonJS - */ -(function(global) { - 'use strict'; - - // - // Utilities - // - - /** - * @param {number} a The number to test. - * @param {number} min The minimum value in the range, inclusive. - * @param {number} max The maximum value in the range, inclusive. - * @return {boolean} True if a >= min and a <= max. - */ - function inRange(a, min, max) { - return min <= a && a <= max; - } - - /** - * @param {number} n The numerator. - * @param {number} d The denominator. - * @return {number} The result of the integer division of n by d. - */ - function div(n, d) { - return Math.floor(n / d); - } - - - // - // Implementation of Encoding specification - // http://dvcs.w3.org/hg/encoding/raw-file/tip/Overview.html - // - - // - // 3. Terminology - // - - // - // 4. Encodings - // - - /** @const */ var EOF_byte = -1; - /** @const */ var EOF_code_point = -1; - - /** - * @constructor - * @param {Uint8Array} bytes Array of bytes that provide the stream. - */ - function ByteInputStream(bytes) { - /** @type {number} */ - var pos = 0; - - /** @return {number} Get the next byte from the stream. */ - this.get = function() { - return (pos >= bytes.length) ? EOF_byte : Number(bytes[pos]); - }; - - /** @param {number} n Number (positive or negative) by which to - * offset the byte pointer. */ - this.offset = function(n) { - pos += n; - if (pos < 0) { - throw new Error('Seeking past start of the buffer'); - } - if (pos > bytes.length) { - throw new Error('Seeking past EOF'); - } - }; - - /** - * @param {Array.} test Array of bytes to compare against. - * @return {boolean} True if the start of the stream matches the test - * bytes. - */ - this.match = function(test) { - if (test.length > pos + bytes.length) { - return false; - } - var i; - for (i = 0; i < test.length; i += 1) { - if (Number(bytes[pos + i]) !== test[i]) { - return false; - } - } - return true; - }; - } - - /** - * @constructor - * @param {Array.} bytes The array to write bytes into. - */ - function ByteOutputStream(bytes) { - /** @type {number} */ - var pos = 0; - - /** - * @param {...number} var_args The byte or bytes to emit into the stream. - * @return {number} The last byte emitted. - */ - this.emit = function(var_args) { - /** @type {number} */ - var last = EOF_byte; - var i; - for (i = 0; i < arguments.length; ++i) { - last = Number(arguments[i]); - bytes[pos++] = last; - } - return last; - }; - } - - /** - * @constructor - * @param {string} string The source of code units for the stream. - */ - function CodePointInputStream(string) { - /** - * @param {string} string Input string of UTF-16 code units. - * @return {Array.} Code points. - */ - function stringToCodePoints(string) { - /** @type {Array.} */ - var cps = []; - // Based on http://www.w3.org/TR/WebIDL/#idl-DOMString - var i = 0, n = string.length; - while (i < string.length) { - var c = string.charCodeAt(i); - if (!inRange(c, 0xD800, 0xDFFF)) { - cps.push(c); - } else if (inRange(c, 0xDC00, 0xDFFF)) { - cps.push(0xFFFD); - } else { // (inRange(cu, 0xD800, 0xDBFF)) - if (i === n - 1) { - cps.push(0xFFFD); - } else { - var d = string.charCodeAt(i + 1); - if (inRange(d, 0xDC00, 0xDFFF)) { - var a = c & 0x3FF; - var b = d & 0x3FF; - i += 1; - cps.push(0x10000 + (a << 10) + b); - } else { - cps.push(0xFFFD); - } - } - } - i += 1; - } - return cps; - } - - /** @type {number} */ - var pos = 0; - /** @type {Array.} */ - var cps = stringToCodePoints(string); - - /** @param {number} n The number of bytes (positive or negative) - * to advance the code point pointer by.*/ - this.offset = function(n) { - pos += n; - if (pos < 0) { - throw new Error('Seeking past start of the buffer'); - } - if (pos > cps.length) { - throw new Error('Seeking past EOF'); - } - }; - - - /** @return {number} Get the next code point from the stream. */ - this.get = function() { - if (pos >= cps.length) { - return EOF_code_point; - } - return cps[pos]; - }; - } - - /** - * @constructor - */ - function CodePointOutputStream() { - /** @type {string} */ - var string = ''; - - /** @return {string} The accumulated string. */ - this.string = function() { - return string; - }; - - /** @param {number} c The code point to encode into the stream. */ - this.emit = function(c) { - if (c <= 0xFFFF) { - string += String.fromCharCode(c); - } else { - c -= 0x10000; - string += String.fromCharCode(0xD800 + ((c >> 10) & 0x3ff)); - string += String.fromCharCode(0xDC00 + (c & 0x3ff)); - } - }; - } - - /** - * @constructor - * @param {string} message Description of the error. - */ - function EncodingError(message) { - this.name = 'EncodingError'; - this.message = message; - this.code = 0; - } - EncodingError.prototype = Error.prototype; - - /** - * @param {boolean} fatal If true, decoding errors raise an exception. - * @param {number=} opt_code_point Override the standard fallback code point. - * @return {number} The code point to insert on a decoding error. - */ - function decoderError(fatal, opt_code_point) { - if (fatal) { - throw new EncodingError('Decoder error'); - } - return opt_code_point || 0xFFFD; - } - - /** - * @param {number} code_point The code point that could not be encoded. - */ - function encoderError(code_point) { - throw new EncodingError('The code point ' + code_point + - ' could not be encoded.'); - } - - /** - * @param {string} label The encoding label. - * @return {?{name:string,labels:Array.}} - */ - function getEncoding(label) { - label = String(label).trim().toLowerCase(); - if (Object.prototype.hasOwnProperty.call(label_to_encoding, label)) { - return label_to_encoding[label]; - } - return null; - } - - /** @type {Array.<{encodings: Array.<{name:string,labels:Array.}>, - * heading: string}>} */ - var encodings = [ - { - "encodings": [ - { - "labels": [ - "unicode-1-1-utf-8", - "utf-8", - "utf8" - ], - "name": "utf-8" - } - ], - "heading": "The Encoding" - } - // XXXfiler - removed non-utf8 aspects - ]; - - var name_to_encoding = {}; - var label_to_encoding = {}; - encodings.forEach(function(category) { - category.encodings.forEach(function(encoding) { - name_to_encoding[encoding.name] = encoding; - encoding.labels.forEach(function(label) { - label_to_encoding[label] = encoding; - }); - }); - }); - - // - // 7. The encoding - // - - // 7.1 utf-8 - - /** - * @constructor - * @param {{fatal: boolean}} options - */ - function UTF8Decoder(options) { - var fatal = options.fatal; - var /** @type {number} */ utf8_code_point = 0, - /** @type {number} */ utf8_bytes_needed = 0, - /** @type {number} */ utf8_bytes_seen = 0, - /** @type {number} */ utf8_lower_boundary = 0; - - /** - * @param {ByteInputStream} byte_pointer The byte stream to decode. - * @return {?number} The next code point decoded, or null if not enough - * data exists in the input stream to decode a complete code point. - */ - this.decode = function(byte_pointer) { - var bite = byte_pointer.get(); - if (bite === EOF_byte) { - if (utf8_bytes_needed !== 0) { - return decoderError(fatal); - } - return EOF_code_point; - } - byte_pointer.offset(1); - - if (utf8_bytes_needed === 0) { - if (inRange(bite, 0x00, 0x7F)) { - return bite; - } - if (inRange(bite, 0xC2, 0xDF)) { - utf8_bytes_needed = 1; - utf8_lower_boundary = 0x80; - utf8_code_point = bite - 0xC0; - } else if (inRange(bite, 0xE0, 0xEF)) { - utf8_bytes_needed = 2; - utf8_lower_boundary = 0x800; - utf8_code_point = bite - 0xE0; - } else if (inRange(bite, 0xF0, 0xF4)) { - utf8_bytes_needed = 3; - utf8_lower_boundary = 0x10000; - utf8_code_point = bite - 0xF0; - } else { - return decoderError(fatal); - } - utf8_code_point = utf8_code_point * Math.pow(64, utf8_bytes_needed); - return null; - } - if (!inRange(bite, 0x80, 0xBF)) { - utf8_code_point = 0; - utf8_bytes_needed = 0; - utf8_bytes_seen = 0; - utf8_lower_boundary = 0; - byte_pointer.offset(-1); - return decoderError(fatal); - } - utf8_bytes_seen += 1; - utf8_code_point = utf8_code_point + (bite - 0x80) * - Math.pow(64, utf8_bytes_needed - utf8_bytes_seen); - if (utf8_bytes_seen !== utf8_bytes_needed) { - return null; - } - var code_point = utf8_code_point; - var lower_boundary = utf8_lower_boundary; - utf8_code_point = 0; - utf8_bytes_needed = 0; - utf8_bytes_seen = 0; - utf8_lower_boundary = 0; - if (inRange(code_point, lower_boundary, 0x10FFFF) && - !inRange(code_point, 0xD800, 0xDFFF)) { - return code_point; - } - return decoderError(fatal); - }; - } - - /** - * @constructor - * @param {{fatal: boolean}} options - */ - function UTF8Encoder(options) { - var fatal = options.fatal; - /** - * @param {ByteOutputStream} output_byte_stream Output byte stream. - * @param {CodePointInputStream} code_point_pointer Input stream. - * @return {number} The last byte emitted. - */ - this.encode = function(output_byte_stream, code_point_pointer) { - var code_point = code_point_pointer.get(); - if (code_point === EOF_code_point) { - return EOF_byte; - } - code_point_pointer.offset(1); - if (inRange(code_point, 0xD800, 0xDFFF)) { - return encoderError(code_point); - } - if (inRange(code_point, 0x0000, 0x007f)) { - return output_byte_stream.emit(code_point); - } - var count, offset; - if (inRange(code_point, 0x0080, 0x07FF)) { - count = 1; - offset = 0xC0; - } else if (inRange(code_point, 0x0800, 0xFFFF)) { - count = 2; - offset = 0xE0; - } else if (inRange(code_point, 0x10000, 0x10FFFF)) { - count = 3; - offset = 0xF0; - } - var result = output_byte_stream.emit( - div(code_point, Math.pow(64, count)) + offset); - while (count > 0) { - var temp = div(code_point, Math.pow(64, count - 1)); - result = output_byte_stream.emit(0x80 + (temp % 64)); - count -= 1; - } - return result; - }; - } - - name_to_encoding['utf-8'].getEncoder = function(options) { - return new UTF8Encoder(options); - }; - name_to_encoding['utf-8'].getDecoder = function(options) { - return new UTF8Decoder(options); - }; - - // - // Implementation of Text Encoding Web API - // - - /** @const */ var DEFAULT_ENCODING = 'utf-8'; - - /** - * @constructor - * @param {string=} opt_encoding The label of the encoding; - * defaults to 'utf-8'. - * @param {{fatal: boolean}=} options - */ - function TextEncoder(opt_encoding, options) { - if (!(this instanceof TextEncoder)) { - throw new TypeError('Constructor cannot be called as a function'); - } - opt_encoding = opt_encoding ? String(opt_encoding) : DEFAULT_ENCODING; - options = Object(options); - /** @private */ - this._encoding = getEncoding(opt_encoding); - if (this._encoding === null || (this._encoding.name !== 'utf-8' && - this._encoding.name !== 'utf-16le' && - this._encoding.name !== 'utf-16be')) - throw new TypeError('Unknown encoding: ' + opt_encoding); - /** @private @type {boolean} */ - this._streaming = false; - /** @private */ - this._encoder = null; - /** @private @type {{fatal: boolean}=} */ - this._options = { fatal: Boolean(options.fatal) }; - - if (Object.defineProperty) { - Object.defineProperty( - this, 'encoding', - { get: function() { return this._encoding.name; } }); - } else { - this.encoding = this._encoding.name; - } - - return this; - } - - TextEncoder.prototype = { - /** - * @param {string=} opt_string The string to encode. - * @param {{stream: boolean}=} options - */ - encode: function encode(opt_string, options) { - opt_string = opt_string ? String(opt_string) : ''; - options = Object(options); - // TODO: any options? - if (!this._streaming) { - this._encoder = this._encoding.getEncoder(this._options); - } - this._streaming = Boolean(options.stream); - - var bytes = []; - var output_stream = new ByteOutputStream(bytes); - var input_stream = new CodePointInputStream(opt_string); - while (input_stream.get() !== EOF_code_point) { - this._encoder.encode(output_stream, input_stream); - } - if (!this._streaming) { - var last_byte; - do { - last_byte = this._encoder.encode(output_stream, input_stream); - } while (last_byte !== EOF_byte); - this._encoder = null; - } - return new Uint8Array(bytes); - } - }; - - - /** - * @constructor - * @param {string=} opt_encoding The label of the encoding; - * defaults to 'utf-8'. - * @param {{fatal: boolean}=} options - */ - function TextDecoder(opt_encoding, options) { - if (!(this instanceof TextDecoder)) { - throw new TypeError('Constructor cannot be called as a function'); - } - opt_encoding = opt_encoding ? String(opt_encoding) : DEFAULT_ENCODING; - options = Object(options); - /** @private */ - this._encoding = getEncoding(opt_encoding); - if (this._encoding === null) - throw new TypeError('Unknown encoding: ' + opt_encoding); - - /** @private @type {boolean} */ - this._streaming = false; - /** @private */ - this._decoder = null; - /** @private @type {{fatal: boolean}=} */ - this._options = { fatal: Boolean(options.fatal) }; - - if (Object.defineProperty) { - Object.defineProperty( - this, 'encoding', - { get: function() { return this._encoding.name; } }); - } else { - this.encoding = this._encoding.name; - } - - return this; - } - - // TODO: Issue if input byte stream is offset by decoder - // TODO: BOM detection will not work if stream header spans multiple calls - // (last N bytes of previous stream may need to be retained?) - TextDecoder.prototype = { - /** - * @param {ArrayBufferView=} opt_view The buffer of bytes to decode. - * @param {{stream: boolean}=} options - */ - decode: function decode(opt_view, options) { - if (opt_view && !('buffer' in opt_view && 'byteOffset' in opt_view && - 'byteLength' in opt_view)) { - throw new TypeError('Expected ArrayBufferView'); - } else if (!opt_view) { - opt_view = new Uint8Array(0); - } - options = Object(options); - - if (!this._streaming) { - this._decoder = this._encoding.getDecoder(this._options); - this._BOMseen = false; - } - this._streaming = Boolean(options.stream); - - var bytes = new Uint8Array(opt_view.buffer, - opt_view.byteOffset, - opt_view.byteLength); - var input_stream = new ByteInputStream(bytes); - - var output_stream = new CodePointOutputStream(), code_point; - while (input_stream.get() !== EOF_byte) { - code_point = this._decoder.decode(input_stream); - if (code_point !== null && code_point !== EOF_code_point) { - output_stream.emit(code_point); - } - } - if (!this._streaming) { - do { - code_point = this._decoder.decode(input_stream); - if (code_point !== null && code_point !== EOF_code_point) { - output_stream.emit(code_point); - } - } while (code_point !== EOF_code_point && - input_stream.get() != EOF_byte); - this._decoder = null; - } - - var result = output_stream.string(); - if (!this._BOMseen && result.length) { - this._BOMseen = true; - if (['utf-8', 'utf-16le', 'utf-16be'].indexOf(this.encoding) !== -1 && - result.charCodeAt(0) === 0xFEFF) { - result = result.substring(1); - } - } - - return result; - } - }; - - // Prefer native impl if available - module.exports = { - TextEncoder: global['TextEncoder'] || TextEncoder, - TextDecoder: global['TextDecoder'] || TextDecoder - }; -}(this)); - -},{}],3:[function(_dereq_,module,exports){ +},{"FWaASH":6}],2:[function(_dereq_,module,exports){ // Based on https://github.com/diy/intercom.js/blob/master/lib/events.js // Copyright 2012 DIY Co Apache License, Version 2.0 // http://www.apache.org/licenses/LICENSE-2.0 @@ -1634,7 +1039,7 @@ EventEmitter.prototype.removeAllListeners = pub.removeAllListeners; module.exports = EventEmitter; -},{}],4:[function(_dereq_,module,exports){ +},{}],3:[function(_dereq_,module,exports){ // Based on https://github.com/diy/intercom.js/blob/master/lib/intercom.js // Copyright 2012 DIY Co Apache License, Version 2.0 // http://www.apache.org/licenses/LICENSE-2.0 @@ -1954,7 +1359,7 @@ Intercom.getInstance = (function() { module.exports = Intercom; -},{"../src/shared.js":23,"./eventemitter.js":3}],5:[function(_dereq_,module,exports){ +},{"../src/shared.js":56,"./eventemitter.js":2}],4:[function(_dereq_,module,exports){ // Cherry-picked bits of underscore.js, lodash.js /** @@ -2053,82 +1458,493 @@ function nodash(value) { module.exports = nodash; +},{}],5:[function(_dereq_,module,exports){ +(function (Buffer){ +// Browser Request +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +var XHR = XMLHttpRequest +if (!XHR) throw new Error('missing XMLHttpRequest') +request.log = { + 'trace': noop, 'debug': noop, 'info': noop, 'warn': noop, 'error': noop +} + +var DEFAULT_TIMEOUT = 3 * 60 * 1000 // 3 minutes + +// +// request +// + +function request(options, callback) { + // The entry-point to the API: prep the options object and pass the real work to run_xhr. + if(typeof callback !== 'function') + throw new Error('Bad callback given: ' + callback) + + if(!options) + throw new Error('No options given') + + var options_onResponse = options.onResponse; // Save this for later. + + if(typeof options === 'string') + options = {'uri':options}; + else + options = JSON.parse(JSON.stringify(options)); // Use a duplicate for mutating. + + options.onResponse = options_onResponse // And put it back. + + if (options.verbose) request.log = getLogger(); + + if(options.url) { + options.uri = options.url; + delete options.url; + } + + if(!options.uri && options.uri !== "") + throw new Error("options.uri is a required argument"); + + if(typeof options.uri != "string") + throw new Error("options.uri must be a string"); + + var unsupported_options = ['proxy', '_redirectsFollowed', 'maxRedirects', 'followRedirect'] + for (var i = 0; i < unsupported_options.length; i++) + if(options[ unsupported_options[i] ]) + throw new Error("options." + unsupported_options[i] + " is not supported") + + options.callback = callback + options.method = options.method || 'GET'; + options.headers = options.headers || {}; + options.body = options.body || null + options.timeout = options.timeout || request.DEFAULT_TIMEOUT + + if(options.headers.host) + throw new Error("Options.headers.host is not supported"); + + if(options.json) { + options.headers.accept = options.headers.accept || 'application/json' + if(options.method !== 'GET') + options.headers['content-type'] = 'application/json' + + if(typeof options.json !== 'boolean') + options.body = JSON.stringify(options.json) + else if(typeof options.body !== 'string') + options.body = JSON.stringify(options.body) + } + + //BEGIN QS Hack + var serialize = function(obj) { + var str = []; + for(var p in obj) + if (obj.hasOwnProperty(p)) { + str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p])); + } + return str.join("&"); + } + + if(options.qs){ + var qs = (typeof options.qs == 'string')? options.qs : serialize(options.qs); + if(options.uri.indexOf('?') !== -1){ //no get params + options.uri = options.uri+'&'+qs; + }else{ //existing get params + options.uri = options.uri+'?'+qs; + } + } + //END QS Hack + + //BEGIN FORM Hack + var multipart = function(obj) { + //todo: support file type (useful?) + var result = {}; + result.boundry = '-------------------------------'+Math.floor(Math.random()*1000000000); + var lines = []; + for(var p in obj){ + if (obj.hasOwnProperty(p)) { + lines.push( + '--'+result.boundry+"\n"+ + 'Content-Disposition: form-data; name="'+p+'"'+"\n"+ + "\n"+ + obj[p]+"\n" + ); + } + } + lines.push( '--'+result.boundry+'--' ); + result.body = lines.join(''); + result.length = result.body.length; + result.type = 'multipart/form-data; boundary='+result.boundry; + return result; + } + + if(options.form){ + if(typeof options.form == 'string') throw('form name unsupported'); + if(options.method === 'POST'){ + var encoding = (options.encoding || 'application/x-www-form-urlencoded').toLowerCase(); + options.headers['content-type'] = encoding; + switch(encoding){ + case 'application/x-www-form-urlencoded': + options.body = serialize(options.form).replace(/%20/g, "+"); + break; + case 'multipart/form-data': + var multi = multipart(options.form); + //options.headers['content-length'] = multi.length; + options.body = multi.body; + options.headers['content-type'] = multi.type; + break; + default : throw new Error('unsupported encoding:'+encoding); + } + } + } + //END FORM Hack + + // If onResponse is boolean true, call back immediately when the response is known, + // not when the full request is complete. + options.onResponse = options.onResponse || noop + if(options.onResponse === true) { + options.onResponse = callback + options.callback = noop + } + + // XXX Browsers do not like this. + //if(options.body) + // options.headers['content-length'] = options.body.length; + + // HTTP basic authentication + if(!options.headers.authorization && options.auth) + options.headers.authorization = 'Basic ' + b64_enc(options.auth.username + ':' + options.auth.password); + + return run_xhr(options) +} + +var req_seq = 0 +function run_xhr(options) { + var xhr = new XHR + , timed_out = false + , is_cors = is_crossDomain(options.uri) + , supports_cors = ('withCredentials' in xhr) + + req_seq += 1 + xhr.seq_id = req_seq + xhr.id = req_seq + ': ' + options.method + ' ' + options.uri + xhr._id = xhr.id // I know I will type "_id" from habit all the time. + + if(is_cors && !supports_cors) { + var cors_err = new Error('Browser does not support cross-origin request: ' + options.uri) + cors_err.cors = 'unsupported' + return options.callback(cors_err, xhr) + } + + xhr.timeoutTimer = setTimeout(too_late, options.timeout) + function too_late() { + timed_out = true + var er = new Error('ETIMEDOUT') + er.code = 'ETIMEDOUT' + er.duration = options.timeout + + request.log.error('Timeout', { 'id':xhr._id, 'milliseconds':options.timeout }) + return options.callback(er, xhr) + } + + // Some states can be skipped over, so remember what is still incomplete. + var did = {'response':false, 'loading':false, 'end':false} + + xhr.onreadystatechange = on_state_change + xhr.open(options.method, options.uri, true) // asynchronous + // Deal with requests for raw buffer response + if(options.encoding === null) { + xhr.responseType = 'arraybuffer'; + } + if(is_cors) + xhr.withCredentials = !! options.withCredentials + xhr.send(options.body) + return xhr + + function on_state_change(event) { + if(timed_out) + return request.log.debug('Ignoring timed out state change', {'state':xhr.readyState, 'id':xhr.id}) + + request.log.debug('State change', {'state':xhr.readyState, 'id':xhr.id, 'timed_out':timed_out}) + + if(xhr.readyState === XHR.OPENED) { + request.log.debug('Request started', {'id':xhr.id}) + for (var key in options.headers) + xhr.setRequestHeader(key, options.headers[key]) + } + + else if(xhr.readyState === XHR.HEADERS_RECEIVED) + on_response() + + else if(xhr.readyState === XHR.LOADING) { + on_response() + on_loading() + } + + else if(xhr.readyState === XHR.DONE) { + on_response() + on_loading() + on_end() + } + } + + function on_response() { + if(did.response) + return + + did.response = true + request.log.debug('Got response', {'id':xhr.id, 'status':xhr.status}) + clearTimeout(xhr.timeoutTimer) + xhr.statusCode = xhr.status // Node request compatibility + + // Detect failed CORS requests. + if(is_cors && xhr.statusCode == 0) { + var cors_err = new Error('CORS request rejected: ' + options.uri) + cors_err.cors = 'rejected' + + // Do not process this request further. + did.loading = true + did.end = true + + return options.callback(cors_err, xhr) + } + + options.onResponse(null, xhr) + } + + function on_loading() { + if(did.loading) + return + + did.loading = true + request.log.debug('Response body loading', {'id':xhr.id}) + // TODO: Maybe simulate "data" events by watching xhr.responseText + } + + function on_end() { + if(did.end) + return + + did.end = true + request.log.debug('Request done', {'id':xhr.id}) + + if(options.encoding === null) { + xhr.body = new Buffer(new Uint8Array(xhr.response)); + } else { + xhr.body = xhr.responseText + if(options.json) { + try { xhr.body = JSON.parse(xhr.responseText) } + catch (er) { return options.callback(er, xhr) } + } + } + + options.callback(null, xhr, xhr.body) + } + +} // request + +request.withCredentials = false; +request.DEFAULT_TIMEOUT = DEFAULT_TIMEOUT; + +// +// defaults +// + +request.defaults = function(options, requester) { + var def = function (method) { + var d = function (params, callback) { + if(typeof params === 'string') + params = {'uri': params}; + else { + params = JSON.parse(JSON.stringify(params)); + } + for (var i in options) { + if (params[i] === undefined) params[i] = options[i] + } + return method(params, callback) + } + return d + } + var de = def(request) + de.get = def(request.get) + de.post = def(request.post) + de.put = def(request.put) + de.head = def(request.head) + return de +} + +// +// HTTP method shortcuts +// + +var shortcuts = [ 'get', 'put', 'post', 'head' ]; +shortcuts.forEach(function(shortcut) { + var method = shortcut.toUpperCase(); + var func = shortcut.toLowerCase(); + + request[func] = function(opts) { + if(typeof opts === 'string') + opts = {'method':method, 'uri':opts}; + else { + opts = JSON.parse(JSON.stringify(opts)); + opts.method = method; + } + + var args = [opts].concat(Array.prototype.slice.apply(arguments, [1])); + return request.apply(this, args); + } +}) + +// +// CouchDB shortcut +// + +request.couch = function(options, callback) { + if(typeof options === 'string') + options = {'uri':options} + + // Just use the request API to do JSON. + options.json = true + if(options.body) + options.json = options.body + delete options.body + + callback = callback || noop + + var xhr = request(options, couch_handler) + return xhr + + function couch_handler(er, resp, body) { + if(er) + return callback(er, resp, body) + + if((resp.statusCode < 200 || resp.statusCode > 299) && body.error) { + // The body is a Couch JSON object indicating the error. + er = new Error('CouchDB error: ' + (body.error.reason || body.error.error)) + for (var key in body) + er[key] = body[key] + return callback(er, resp, body); + } + + return callback(er, resp, body); + } +} + +// +// Utility +// + +function noop() {} + +function getLogger() { + var logger = {} + , levels = ['trace', 'debug', 'info', 'warn', 'error'] + , level, i + + for(i = 0; i < levels.length; i++) { + level = levels[i] + + logger[level] = noop + if(typeof console !== 'undefined' && console && console[level]) + logger[level] = formatted(console, level) + } + + return logger +} + +function formatted(obj, method) { + return formatted_logger + + function formatted_logger(str, context) { + if(typeof context === 'object') + str += ' ' + JSON.stringify(context) + + return obj[method].call(obj, str) + } +} + +// Return whether a URL is a cross-domain request. +function is_crossDomain(url) { + var rurl = /^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?)?/ + + // jQuery #8138, IE may throw an exception when accessing + // a field from window.location if document.domain has been set + var ajaxLocation + try { ajaxLocation = location.href } + catch (e) { + // Use the href attribute of an A element since IE will modify it given document.location + ajaxLocation = document.createElement( "a" ); + ajaxLocation.href = ""; + ajaxLocation = ajaxLocation.href; + } + + var ajaxLocParts = rurl.exec(ajaxLocation.toLowerCase()) || [] + , parts = rurl.exec(url.toLowerCase() ) + + var result = !!( + parts && + ( parts[1] != ajaxLocParts[1] + || parts[2] != ajaxLocParts[2] + || (parts[3] || (parts[1] === "http:" ? 80 : 443)) != (ajaxLocParts[3] || (ajaxLocParts[1] === "http:" ? 80 : 443)) + ) + ) + + //console.debug('is_crossDomain('+url+') -> ' + result) + return result +} + +// MIT License from http://phpjs.org/functions/base64_encode:358 +function b64_enc (data) { + // Encodes string using MIME base64 algorithm + var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; + var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, ac = 0, enc="", tmp_arr = []; + + if (!data) { + return data; + } + + // assume utf8 data + // data = this.utf8_encode(data+''); + + do { // pack three octets into four hexets + o1 = data.charCodeAt(i++); + o2 = data.charCodeAt(i++); + o3 = data.charCodeAt(i++); + + bits = o1<<16 | o2<<8 | o3; + + h1 = bits>>18 & 0x3f; + h2 = bits>>12 & 0x3f; + h3 = bits>>6 & 0x3f; + h4 = bits & 0x3f; + + // use hexets to index into b64, and append result to encoded string + tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4); + } while (i < data.length); + + enc = tmp_arr.join(''); + + switch (data.length % 3) { + case 1: + enc = enc.slice(0, -2) + '=='; + break; + case 2: + enc = enc.slice(0, -1) + '='; + break; + } + + return enc; +} +module.exports = request; + +}).call(this,_dereq_("buffer").Buffer) },{}],6:[function(_dereq_,module,exports){ -var ZlibNamespace = {}; - -/** @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>>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-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;0ha;++ha){for(var U=ha,ja=U,ka=7,U=U>>>1;U;U>>>=1)ja<<=1,ja|=U&1,--ka;da[ha]=(ja<>>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;0c[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+2a[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>>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;wx)for(;0x?x:138,E>x-3&&E=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(;0x?x:6,E>x-3&&ED;D++)oa[D]=X[g[D]];for(C=19;4=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=f;)t[f++]=0;for(f=0;29>=f;)r[f++]=0}t[256]=1;d=0;for(c=b.length;d=c){u&&a(u,-1);f=0;for(l=c-d;fl&&b+lf&&(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;k2*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;me[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>>=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;Bg;++g)F[g]=Qa(N,11===B?b.h&255:256*Math.random()|0);for(J=F.length;g>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>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>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;cx;++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;sc&&(c=a[s]),a[s]>=1;A=k<<16|s;for(r=l;rE;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=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=k&&m(Error("input buffer is broken")),c|=f[h++]<>>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=k);)c|=f[h++]<>>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;gh)d>=f&&(this.a=d,c=this.e(),d=this.a),c[d++]=h;else{k=h-257;g=M[k];0=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];0f&&(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;cc;++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=hb&&(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>>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>>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>>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(ZlibNamespace); - -module.exports = ZlibNamespace.Zlib; - -},{}],7:[function(_dereq_,module,exports){ // shim for using process in browser var process = module.exports = {}; @@ -2193,7 +2009,8588 @@ process.chdir = function (dir) { throw new Error('process.chdir is not supported'); }; +},{}],7:[function(_dereq_,module,exports){ +'use strict'; +// private property +var _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; + + +// public method for encoding +exports.encode = function(input, utf8) { + var output = ""; + var chr1, chr2, chr3, enc1, enc2, enc3, enc4; + var i = 0; + + while (i < input.length) { + + chr1 = input.charCodeAt(i++); + chr2 = input.charCodeAt(i++); + chr3 = input.charCodeAt(i++); + + enc1 = chr1 >> 2; + enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); + enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); + enc4 = chr3 & 63; + + if (isNaN(chr2)) { + enc3 = enc4 = 64; + } + else if (isNaN(chr3)) { + enc4 = 64; + } + + output = output + _keyStr.charAt(enc1) + _keyStr.charAt(enc2) + _keyStr.charAt(enc3) + _keyStr.charAt(enc4); + + } + + return output; +}; + +// public method for decoding +exports.decode = function(input, utf8) { + var output = ""; + var chr1, chr2, chr3; + var enc1, enc2, enc3, enc4; + var i = 0; + + input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); + + while (i < input.length) { + + enc1 = _keyStr.indexOf(input.charAt(i++)); + enc2 = _keyStr.indexOf(input.charAt(i++)); + enc3 = _keyStr.indexOf(input.charAt(i++)); + enc4 = _keyStr.indexOf(input.charAt(i++)); + + chr1 = (enc1 << 2) | (enc2 >> 4); + chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); + chr3 = ((enc3 & 3) << 6) | enc4; + + output = output + String.fromCharCode(chr1); + + if (enc3 != 64) { + output = output + String.fromCharCode(chr2); + } + if (enc4 != 64) { + output = output + String.fromCharCode(chr3); + } + + } + + return output; + +}; + },{}],8:[function(_dereq_,module,exports){ +'use strict'; +function CompressedObject() { + this.compressedSize = 0; + this.uncompressedSize = 0; + this.crc32 = 0; + this.compressionMethod = null; + this.compressedContent = null; +} + +CompressedObject.prototype = { + /** + * Return the decompressed content in an unspecified format. + * The format will depend on the decompressor. + * @return {Object} the decompressed content. + */ + getContent: function() { + return null; // see implementation + }, + /** + * Return the compressed content in an unspecified format. + * The format will depend on the compressed conten source. + * @return {Object} the compressed content. + */ + getCompressedContent: function() { + return null; // see implementation + } +}; +module.exports = CompressedObject; + +},{}],9:[function(_dereq_,module,exports){ +'use strict'; +exports.STORE = { + magic: "\x00\x00", + compress: function(content) { + return content; // no compression + }, + uncompress: function(content) { + return content; // no compression + }, + compressInputType: null, + uncompressInputType: null +}; +exports.DEFLATE = _dereq_('./flate'); + +},{"./flate":12}],10:[function(_dereq_,module,exports){ +'use strict'; +var utils = _dereq_('./utils'); + +function DataReader(data) { + this.data = null; // type : see implementation + this.length = 0; + this.index = 0; +} +DataReader.prototype = { + /** + * Check that the offset will not go too far. + * @param {string} offset the additional offset to check. + * @throws {Error} an Error if the offset is out of bounds. + */ + checkOffset: function(offset) { + this.checkIndex(this.index + offset); + }, + /** + * Check that the specifed index will not be too far. + * @param {string} newIndex the index to check. + * @throws {Error} an Error if the index is out of bounds. + */ + checkIndex: function(newIndex) { + if (this.length < newIndex || newIndex < 0) { + throw new Error("End of data reached (data length = " + this.length + ", asked index = " + (newIndex) + "). Corrupted zip ?"); + } + }, + /** + * Change the index. + * @param {number} newIndex The new index. + * @throws {Error} if the new index is out of the data. + */ + setIndex: function(newIndex) { + this.checkIndex(newIndex); + this.index = newIndex; + }, + /** + * Skip the next n bytes. + * @param {number} n the number of bytes to skip. + * @throws {Error} if the new index is out of the data. + */ + skip: function(n) { + this.setIndex(this.index + n); + }, + /** + * Get the byte at the specified index. + * @param {number} i the index to use. + * @return {number} a byte. + */ + byteAt: function(i) { + // see implementations + }, + /** + * Get the next number with a given byte size. + * @param {number} size the number of bytes to read. + * @return {number} the corresponding number. + */ + readInt: function(size) { + var result = 0, + i; + this.checkOffset(size); + for (i = this.index + size - 1; i >= this.index; i--) { + result = (result << 8) + this.byteAt(i); + } + this.index += size; + return result; + }, + /** + * Get the next string with a given byte size. + * @param {number} size the number of bytes to read. + * @return {string} the corresponding string. + */ + readString: function(size) { + return utils.transformTo("string", this.readData(size)); + }, + /** + * Get raw data without conversion, bytes. + * @param {number} size the number of bytes to read. + * @return {Object} the raw data, implementation specific. + */ + readData: function(size) { + // see implementations + }, + /** + * Find the last occurence of a zip signature (4 bytes). + * @param {string} sig the signature to find. + * @return {number} the index of the last occurence, -1 if not found. + */ + lastIndexOfSignature: function(sig) { + // see implementations + }, + /** + * Get the next date. + * @return {Date} the date. + */ + readDate: function() { + var dostime = this.readInt(4); + return new Date( + ((dostime >> 25) & 0x7f) + 1980, // year + ((dostime >> 21) & 0x0f) - 1, // month + (dostime >> 16) & 0x1f, // day + (dostime >> 11) & 0x1f, // hour + (dostime >> 5) & 0x3f, // minute + (dostime & 0x1f) << 1); // second + } +}; +module.exports = DataReader; + +},{"./utils":22}],11:[function(_dereq_,module,exports){ +'use strict'; +exports.base64 = false; +exports.binary = false; +exports.dir = false; +exports.date = null; +exports.compression = null; + +},{}],12:[function(_dereq_,module,exports){ +'use strict'; +var USE_TYPEDARRAY = (typeof Uint8Array !== 'undefined') && (typeof Uint16Array !== 'undefined') && (typeof Uint32Array !== 'undefined'); + +var pako = _dereq_("pako"); +exports.uncompressInputType = USE_TYPEDARRAY ? "uint8array" : "array"; +exports.compressInputType = USE_TYPEDARRAY ? "uint8array" : "array"; + +exports.magic = "\x08\x00"; +exports.compress = function(input) { + return pako.deflateRaw(input); +}; +exports.uncompress = function(input) { + return pako.inflateRaw(input); +}; + +},{"pako":25}],13:[function(_dereq_,module,exports){ +'use strict'; +/** +Usage: + zip = new JSZip(); + zip.file("hello.txt", "Hello, World!").file("tempfile", "nothing"); + zip.folder("images").file("smile.gif", base64Data, {base64: true}); + zip.file("Xmas.txt", "Ho ho ho !", {date : new Date("December 25, 2007 00:00:01")}); + zip.remove("tempfile"); + + base64zip = zip.generate(); + +**/ + +/** + * Representation a of zip file in js + * @constructor + * @param {String=|ArrayBuffer=|Uint8Array=} data the data to load, if any (optional). + * @param {Object=} options the options for creating this objects (optional). + */ +function JSZip(data, options) { + // if this constructor is used without `new`, it adds `new` before itself: + if(!(this instanceof JSZip)) return new JSZip(data, options); + + // object containing the files : + // { + // "folder/" : {...}, + // "folder/data.txt" : {...} + // } + this.files = {}; + + // Where we are in the hierarchy + this.root = ""; + if (data) { + this.load(data, options); + } + this.clone = function() { + var newObj = new JSZip(); + for (var i in this) { + if (typeof this[i] !== "function") { + newObj[i] = this[i]; + } + } + return newObj; + }; +} +JSZip.prototype = _dereq_('./object'); +JSZip.prototype.load = _dereq_('./load'); +JSZip.support = _dereq_('./support'); +JSZip.defaults = _dereq_('./defaults'); +JSZip.utils = _dereq_('./utils'); +JSZip.base64 = _dereq_('./base64'); +JSZip.compressions = _dereq_('./compressions'); +module.exports = JSZip; + +},{"./base64":7,"./compressions":9,"./defaults":11,"./load":14,"./object":17,"./support":20,"./utils":22}],14:[function(_dereq_,module,exports){ +'use strict'; +var base64 = _dereq_('./base64'); +var ZipEntries = _dereq_('./zipEntries'); +module.exports = function(data, options) { + var files, zipEntries, i, input; + options = options || {}; + if (options.base64) { + data = base64.decode(data); + } + + zipEntries = new ZipEntries(data, options); + files = zipEntries.files; + for (i = 0; i < files.length; i++) { + input = files[i]; + this.file(input.fileName, input.decompressed, { + binary: true, + optimizedBinaryString: true, + date: input.date, + dir: input.dir + }); + } + + return this; +}; + +},{"./base64":7,"./zipEntries":23}],15:[function(_dereq_,module,exports){ +(function (Buffer){ +'use strict'; +module.exports = function(data, encoding){ + return new Buffer(data, encoding); +}; +module.exports.test = function(b){ + return Buffer.isBuffer(b); +}; +}).call(this,_dereq_("buffer").Buffer) +},{}],16:[function(_dereq_,module,exports){ +'use strict'; +var Uint8ArrayReader = _dereq_('./uint8ArrayReader'); + +function NodeBufferReader(data) { + this.data = data; + this.length = this.data.length; + this.index = 0; +} +NodeBufferReader.prototype = new Uint8ArrayReader(); + +/** + * @see DataReader.readData + */ +NodeBufferReader.prototype.readData = function(size) { + this.checkOffset(size); + var result = this.data.slice(this.index, this.index + size); + this.index += size; + return result; +}; +module.exports = NodeBufferReader; + +},{"./uint8ArrayReader":21}],17:[function(_dereq_,module,exports){ +'use strict'; +var support = _dereq_('./support'); +var utils = _dereq_('./utils'); +var signature = _dereq_('./signature'); +var defaults = _dereq_('./defaults'); +var base64 = _dereq_('./base64'); +var compressions = _dereq_('./compressions'); +var CompressedObject = _dereq_('./compressedObject'); +var nodeBuffer = _dereq_('./nodeBuffer'); +/** + * Returns the raw data of a ZipObject, decompress the content if necessary. + * @param {ZipObject} file the file to use. + * @return {String|ArrayBuffer|Uint8Array|Buffer} the data. + */ + +var textEncoder, textDecoder; +if ( + support.uint8array && + typeof TextEncoder === "function" && + typeof TextDecoder === "function" +) { + textEncoder = new TextEncoder("utf-8"); + textDecoder = new TextDecoder("utf-8"); +} + +var getRawData = function(file) { + if (file._data instanceof CompressedObject) { + file._data = file._data.getContent(); + file.options.binary = true; + file.options.base64 = false; + + if (utils.getTypeOf(file._data) === "uint8array") { + var copy = file._data; + // when reading an arraybuffer, the CompressedObject mechanism will keep it and subarray() a Uint8Array. + // if we request a file in the same format, we might get the same Uint8Array or its ArrayBuffer (the original zip file). + file._data = new Uint8Array(copy.length); + // with an empty Uint8Array, Opera fails with a "Offset larger than array size" + if (copy.length !== 0) { + file._data.set(copy, 0); + } + } + } + return file._data; +}; + +/** + * Returns the data of a ZipObject in a binary form. If the content is an unicode string, encode it. + * @param {ZipObject} file the file to use. + * @return {String|ArrayBuffer|Uint8Array|Buffer} the data. + */ +var getBinaryData = function(file) { + var result = getRawData(file), + type = utils.getTypeOf(result); + if (type === "string") { + if (!file.options.binary) { + // unicode text ! + // unicode string => binary string is a painful process, check if we can avoid it. + if (textEncoder) { + return textEncoder.encode(result); + } + if (support.nodebuffer) { + return nodeBuffer(result, "utf-8"); + } + } + return file.asBinary(); + } + return result; +}; + +/** + * Transform this._data into a string. + * @param {function} filter a function String -> String, applied if not null on the result. + * @return {String} the string representing this._data. + */ +var dataToString = function(asUTF8) { + var result = getRawData(this); + if (result === null || typeof result === "undefined") { + return ""; + } + // if the data is a base64 string, we decode it before checking the encoding ! + if (this.options.base64) { + result = base64.decode(result); + } + if (asUTF8 && this.options.binary) { + // JSZip.prototype.utf8decode supports arrays as input + // skip to array => string step, utf8decode will do it. + result = out.utf8decode(result); + } + else { + // no utf8 transformation, do the array => string step. + result = utils.transformTo("string", result); + } + + if (!asUTF8 && !this.options.binary) { + result = out.utf8encode(result); + } + return result; +}; +/** + * A simple object representing a file in the zip file. + * @constructor + * @param {string} name the name of the file + * @param {String|ArrayBuffer|Uint8Array|Buffer} data the data + * @param {Object} options the options of the file + */ +var ZipObject = function(name, data, options) { + this.name = name; + this._data = data; + this.options = options; +}; + +ZipObject.prototype = { + /** + * Return the content as UTF8 string. + * @return {string} the UTF8 string. + */ + asText: function() { + return dataToString.call(this, true); + }, + /** + * Returns the binary content. + * @return {string} the content as binary. + */ + asBinary: function() { + return dataToString.call(this, false); + }, + /** + * Returns the content as a nodejs Buffer. + * @return {Buffer} the content as a Buffer. + */ + asNodeBuffer: function() { + var result = getBinaryData(this); + return utils.transformTo("nodebuffer", result); + }, + /** + * Returns the content as an Uint8Array. + * @return {Uint8Array} the content as an Uint8Array. + */ + asUint8Array: function() { + var result = getBinaryData(this); + return utils.transformTo("uint8array", result); + }, + /** + * Returns the content as an ArrayBuffer. + * @return {ArrayBuffer} the content as an ArrayBufer. + */ + asArrayBuffer: function() { + return this.asUint8Array().buffer; + } +}; + +/** + * Transform an integer into a string in hexadecimal. + * @private + * @param {number} dec the number to convert. + * @param {number} bytes the number of bytes to generate. + * @returns {string} the result. + */ +var decToHex = function(dec, bytes) { + var hex = "", + i; + for (i = 0; i < bytes; i++) { + hex += String.fromCharCode(dec & 0xff); + dec = dec >>> 8; + } + return hex; +}; + +/** + * Merge the objects passed as parameters into a new one. + * @private + * @param {...Object} var_args All objects to merge. + * @return {Object} a new object with the data of the others. + */ +var extend = function() { + var result = {}, i, attr; + for (i = 0; i < arguments.length; i++) { // arguments is not enumerable in some browsers + for (attr in arguments[i]) { + if (arguments[i].hasOwnProperty(attr) && typeof result[attr] === "undefined") { + result[attr] = arguments[i][attr]; + } + } + } + return result; +}; + +/** + * Transforms the (incomplete) options from the user into the complete + * set of options to create a file. + * @private + * @param {Object} o the options from the user. + * @return {Object} the complete set of options. + */ +var prepareFileAttrs = function(o) { + o = o || {}; + if (o.base64 === true && (o.binary === null || o.binary === undefined)) { + o.binary = true; + } + o = extend(o, defaults); + o.date = o.date || new Date(); + if (o.compression !== null) o.compression = o.compression.toUpperCase(); + + return o; +}; + +/** + * Add a file in the current folder. + * @private + * @param {string} name the name of the file + * @param {String|ArrayBuffer|Uint8Array|Buffer} data the data of the file + * @param {Object} o the options of the file + * @return {Object} the new file. + */ +var fileAdd = function(name, data, o) { + // be sure sub folders exist + var dataType = utils.getTypeOf(data); + + o = prepareFileAttrs(o); + + if (o.dir || data === null || typeof data === "undefined") { + o.base64 = false; + o.binary = false; + data = null; + } + else if (dataType === "string") { + if (o.binary && !o.base64) { + // optimizedBinaryString == true means that the file has already been filtered with a 0xFF mask + if (o.optimizedBinaryString !== true) { + // this is a string, not in a base64 format. + // Be sure that this is a correct "binary string" + data = utils.string2binary(data); + } + } + } + else { // arraybuffer, uint8array, ... + o.base64 = false; + o.binary = true; + + if (!dataType && !(data instanceof CompressedObject)) { + throw new Error("The data of '" + name + "' is in an unsupported format !"); + } + + // special case : it's way easier to work with Uint8Array than with ArrayBuffer + if (dataType === "arraybuffer") { + data = utils.transformTo("uint8array", data); + } + } + + var object = new ZipObject(name, data, o); + this.files[name] = object; + return object; +}; + +/** + * Add a (sub) folder in the current folder. + * @private + * @param {string} name the folder's name + * @return {Object} the new folder. + */ +var folderAdd = function(name) { + // Check the name ends with a / + if (name.slice(-1) != "/") { + name += "/"; // IE doesn't like substr(-1) + } + + // Does this folder already exist? + if (!this.files[name]) { + fileAdd.call(this, name, null, { + dir: true + }); + } + return this.files[name]; +}; + +/** + * Generate a JSZip.CompressedObject for a given zipOject. + * @param {ZipObject} file the object to read. + * @param {JSZip.compression} compression the compression to use. + * @return {JSZip.CompressedObject} the compressed result. + */ +var generateCompressedObjectFrom = function(file, compression) { + var result = new CompressedObject(), + content; + + // the data has not been decompressed, we might reuse things ! + if (file._data instanceof CompressedObject) { + result.uncompressedSize = file._data.uncompressedSize; + result.crc32 = file._data.crc32; + + if (result.uncompressedSize === 0 || file.options.dir) { + compression = compressions['STORE']; + result.compressedContent = ""; + result.crc32 = 0; + } + else if (file._data.compressionMethod === compression.magic) { + result.compressedContent = file._data.getCompressedContent(); + } + else { + content = file._data.getContent(); + // need to decompress / recompress + result.compressedContent = compression.compress(utils.transformTo(compression.compressInputType, content)); + } + } + else { + // have uncompressed data + content = getBinaryData(file); + if (!content || content.length === 0 || file.options.dir) { + compression = compressions['STORE']; + content = ""; + } + result.uncompressedSize = content.length; + result.crc32 = this.crc32(content); + result.compressedContent = compression.compress(utils.transformTo(compression.compressInputType, content)); + } + + result.compressedSize = result.compressedContent.length; + result.compressionMethod = compression.magic; + + return result; +}; + +/** + * Generate the various parts used in the construction of the final zip file. + * @param {string} name the file name. + * @param {ZipObject} file the file content. + * @param {JSZip.CompressedObject} compressedObject the compressed object. + * @param {number} offset the current offset from the start of the zip file. + * @return {object} the zip parts. + */ +var generateZipParts = function(name, file, compressedObject, offset) { + var data = compressedObject.compressedContent, + utfEncodedFileName = this.utf8encode(file.name), + useUTF8 = utfEncodedFileName !== file.name, + o = file.options, + dosTime, + dosDate, + extraFields = "", + unicodePathExtraField = ""; + + // date + // @see http://www.delorie.com/djgpp/doc/rbinter/it/52/13.html + // @see http://www.delorie.com/djgpp/doc/rbinter/it/65/16.html + // @see http://www.delorie.com/djgpp/doc/rbinter/it/66/16.html + + dosTime = o.date.getHours(); + dosTime = dosTime << 6; + dosTime = dosTime | o.date.getMinutes(); + dosTime = dosTime << 5; + dosTime = dosTime | o.date.getSeconds() / 2; + + dosDate = o.date.getFullYear() - 1980; + dosDate = dosDate << 4; + dosDate = dosDate | (o.date.getMonth() + 1); + dosDate = dosDate << 5; + dosDate = dosDate | o.date.getDate(); + + if (useUTF8) { + // set the unicode path extra field. unzip needs at least one extra + // field to correctly handle unicode path, so using the path is as good + // as any other information. This could improve the situation with + // other archive managers too. + // This field is usually used without the utf8 flag, with a non + // unicode path in the header (winrar, winzip). This helps (a bit) + // with the messy Windows' default compressed folders feature but + // breaks on p7zip which doesn't seek the unicode path extra field. + // So for now, UTF-8 everywhere ! + unicodePathExtraField = + // Version + decToHex(1, 1) + + // NameCRC32 + decToHex(this.crc32(utfEncodedFileName), 4) + + // UnicodeName + utfEncodedFileName; + + extraFields += + // Info-ZIP Unicode Path Extra Field + "\x75\x70" + + // size + decToHex(unicodePathExtraField.length, 2) + + // content + unicodePathExtraField; + } + + var header = ""; + + // version needed to extract + header += "\x0A\x00"; + // general purpose bit flag + // set bit 11 if utf8 + header += useUTF8 ? "\x00\x08" : "\x00\x00"; + // compression method + header += compressedObject.compressionMethod; + // last mod file time + header += decToHex(dosTime, 2); + // last mod file date + header += decToHex(dosDate, 2); + // crc-32 + header += decToHex(compressedObject.crc32, 4); + // compressed size + header += decToHex(compressedObject.compressedSize, 4); + // uncompressed size + header += decToHex(compressedObject.uncompressedSize, 4); + // file name length + header += decToHex(utfEncodedFileName.length, 2); + // extra field length + header += decToHex(extraFields.length, 2); + + + var fileRecord = signature.LOCAL_FILE_HEADER + header + utfEncodedFileName + extraFields; + + var dirRecord = signature.CENTRAL_FILE_HEADER + + // version made by (00: DOS) + "\x14\x00" + + // file header (common to file and central directory) + header + + // file comment length + "\x00\x00" + + // disk number start + "\x00\x00" + + // internal file attributes TODO + "\x00\x00" + + // external file attributes + (file.options.dir === true ? "\x10\x00\x00\x00" : "\x00\x00\x00\x00") + + // relative offset of local header + decToHex(offset, 4) + + // file name + utfEncodedFileName + + // extra field + extraFields; + + + return { + fileRecord: fileRecord, + dirRecord: dirRecord, + compressedObject: compressedObject + }; +}; + +/** + * An object to write any content to a string. + * @constructor + */ +var StringWriter = function() { + this.data = []; +}; +StringWriter.prototype = { + /** + * Append any content to the current string. + * @param {Object} input the content to add. + */ + append: function(input) { + input = utils.transformTo("string", input); + this.data.push(input); + }, + /** + * Finalize the construction an return the result. + * @return {string} the generated string. + */ + finalize: function() { + return this.data.join(""); + } +}; +/** + * An object to write any content to an Uint8Array. + * @constructor + * @param {number} length The length of the array. + */ +var Uint8ArrayWriter = function(length) { + this.data = new Uint8Array(length); + this.index = 0; +}; +Uint8ArrayWriter.prototype = { + /** + * Append any content to the current array. + * @param {Object} input the content to add. + */ + append: function(input) { + if (input.length !== 0) { + // with an empty Uint8Array, Opera fails with a "Offset larger than array size" + input = utils.transformTo("uint8array", input); + this.data.set(input, this.index); + this.index += input.length; + } + }, + /** + * Finalize the construction an return the result. + * @return {Uint8Array} the generated array. + */ + finalize: function() { + return this.data; + } +}; + +// return the actual prototype of JSZip +var out = { + /** + * Read an existing zip and merge the data in the current JSZip object. + * The implementation is in jszip-load.js, don't forget to include it. + * @param {String|ArrayBuffer|Uint8Array|Buffer} stream The stream to load + * @param {Object} options Options for loading the stream. + * options.base64 : is the stream in base64 ? default : false + * @return {JSZip} the current JSZip object + */ + load: function(stream, options) { + throw new Error("Load method is not defined. Is the file jszip-load.js included ?"); + }, + + /** + * Filter nested files/folders with the specified function. + * @param {Function} search the predicate to use : + * function (relativePath, file) {...} + * It takes 2 arguments : the relative path and the file. + * @return {Array} An array of matching elements. + */ + filter: function(search) { + var result = [], + filename, relativePath, file, fileClone; + for (filename in this.files) { + if (!this.files.hasOwnProperty(filename)) { + continue; + } + file = this.files[filename]; + // return a new object, don't let the user mess with our internal objects :) + fileClone = new ZipObject(file.name, file._data, extend(file.options)); + relativePath = filename.slice(this.root.length, filename.length); + if (filename.slice(0, this.root.length) === this.root && // the file is in the current root + search(relativePath, fileClone)) { // and the file matches the function + result.push(fileClone); + } + } + return result; + }, + + /** + * Add a file to the zip file, or search a file. + * @param {string|RegExp} name The name of the file to add (if data is defined), + * the name of the file to find (if no data) or a regex to match files. + * @param {String|ArrayBuffer|Uint8Array|Buffer} data The file data, either raw or base64 encoded + * @param {Object} o File options + * @return {JSZip|Object|Array} this JSZip object (when adding a file), + * a file (when searching by string) or an array of files (when searching by regex). + */ + file: function(name, data, o) { + if (arguments.length === 1) { + if (utils.isRegExp(name)) { + var regexp = name; + return this.filter(function(relativePath, file) { + return !file.options.dir && regexp.test(relativePath); + }); + } + else { // text + return this.filter(function(relativePath, file) { + return !file.options.dir && relativePath === name; + })[0] || null; + } + } + else { // more than one argument : we have data ! + name = this.root + name; + fileAdd.call(this, name, data, o); + } + return this; + }, + + /** + * Add a directory to the zip file, or search. + * @param {String|RegExp} arg The name of the directory to add, or a regex to search folders. + * @return {JSZip} an object with the new directory as the root, or an array containing matching folders. + */ + folder: function(arg) { + if (!arg) { + return this; + } + + if (utils.isRegExp(arg)) { + return this.filter(function(relativePath, file) { + return file.options.dir && arg.test(relativePath); + }); + } + + // else, name is a new folder + var name = this.root + arg; + var newFolder = folderAdd.call(this, name); + + // Allow chaining by returning a new object with this folder as the root + var ret = this.clone(); + ret.root = newFolder.name; + return ret; + }, + + /** + * Delete a file, or a directory and all sub-files, from the zip + * @param {string} name the name of the file to delete + * @return {JSZip} this JSZip object + */ + remove: function(name) { + name = this.root + name; + var file = this.files[name]; + if (!file) { + // Look for any folders + if (name.slice(-1) != "/") { + name += "/"; + } + file = this.files[name]; + } + + if (file && !file.options.dir) { + // file + delete this.files[name]; + } else { + // maybe a folder, delete recursively + var kids = this.filter(function(relativePath, file) { + return file.name.slice(0, name.length) === name; + }); + for (var i = 0; i < kids.length; i++) { + delete this.files[kids[i].name]; + } + } + + return this; + }, + + /** + * Generate the complete zip file + * @param {Object} options the options to generate the zip file : + * - base64, (deprecated, use type instead) true to generate base64. + * - compression, "STORE" by default. + * - type, "base64" by default. Values are : string, base64, uint8array, arraybuffer, blob. + * @return {String|Uint8Array|ArrayBuffer|Buffer|Blob} the zip file + */ + generate: function(options) { + options = extend(options || {}, { + base64: true, + compression: "STORE", + type: "base64" + }); + + utils.checkSupport(options.type); + + var zipData = [], + localDirLength = 0, + centralDirLength = 0, + writer, i; + + + // first, generate all the zip parts. + for (var name in this.files) { + if (!this.files.hasOwnProperty(name)) { + continue; + } + var file = this.files[name]; + + var compressionName = file.options.compression || options.compression.toUpperCase(); + var compression = compressions[compressionName]; + if (!compression) { + throw new Error(compressionName + " is not a valid compression method !"); + } + + var compressedObject = generateCompressedObjectFrom.call(this, file, compression); + + var zipPart = generateZipParts.call(this, name, file, compressedObject, localDirLength); + localDirLength += zipPart.fileRecord.length + compressedObject.compressedSize; + centralDirLength += zipPart.dirRecord.length; + zipData.push(zipPart); + } + + var dirEnd = ""; + + // end of central dir signature + dirEnd = signature.CENTRAL_DIRECTORY_END + + // number of this disk + "\x00\x00" + + // number of the disk with the start of the central directory + "\x00\x00" + + // total number of entries in the central directory on this disk + decToHex(zipData.length, 2) + + // total number of entries in the central directory + decToHex(zipData.length, 2) + + // size of the central directory 4 bytes + decToHex(centralDirLength, 4) + + // offset of start of central directory with respect to the starting disk number + decToHex(localDirLength, 4) + + // .ZIP file comment length + "\x00\x00"; + + + // we have all the parts (and the total length) + // time to create a writer ! + var typeName = options.type.toLowerCase(); + if(typeName==="uint8array"||typeName==="arraybuffer"||typeName==="blob"||typeName==="nodebuffer") { + writer = new Uint8ArrayWriter(localDirLength + centralDirLength + dirEnd.length); + }else{ + writer = new StringWriter(localDirLength + centralDirLength + dirEnd.length); + } + + for (i = 0; i < zipData.length; i++) { + writer.append(zipData[i].fileRecord); + writer.append(zipData[i].compressedObject.compressedContent); + } + for (i = 0; i < zipData.length; i++) { + writer.append(zipData[i].dirRecord); + } + + writer.append(dirEnd); + + var zip = writer.finalize(); + + + + switch(options.type.toLowerCase()) { + // case "zip is an Uint8Array" + case "uint8array" : + case "arraybuffer" : + case "nodebuffer" : + return utils.transformTo(options.type.toLowerCase(), zip); + case "blob" : + return utils.arrayBuffer2Blob(utils.transformTo("arraybuffer", zip)); + // case "zip is a string" + case "base64" : + return (options.base64) ? base64.encode(zip) : zip; + default : // case "string" : + return zip; + } + + }, + + /** + * + * Javascript crc32 + * http://www.webtoolkit.info/ + * + */ + crc32: function crc32(input, crc) { + if (typeof input === "undefined" || !input.length) { + return 0; + } + + var isArray = utils.getTypeOf(input) !== "string"; + + var table = [ + 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, + 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3, + 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, + 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, + 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, + 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, + 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, + 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5, + 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, + 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, + 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, + 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59, + 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, + 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F, + 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, + 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D, + 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, + 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433, + 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, + 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01, + 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, + 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, + 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, + 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65, + 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, + 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, + 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, + 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9, + 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, + 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F, + 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, + 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD, + 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, + 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683, + 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, + 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, + 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, + 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7, + 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, + 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, + 0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, + 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B, + 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, + 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79, + 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, + 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, + 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, + 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D, + 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, + 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713, + 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, + 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, + 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, + 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777, + 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, + 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45, + 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, + 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB, + 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, + 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9, + 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, + 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF, + 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, + 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D]; + + if (typeof(crc) == "undefined") { + crc = 0; + } + var x = 0; + var y = 0; + var b = 0; + + crc = crc ^ (-1); + for (var i = 0, iTop = input.length; i < iTop; i++) { + b = isArray ? input[i] : input.charCodeAt(i); + y = (crc ^ b) & 0xFF; + x = table[y]; + crc = (crc >>> 8) ^ x; + } + + return crc ^ (-1); + }, + + // Inspired by http://my.opera.com/GreyWyvern/blog/show.dml/1725165 + + /** + * http://www.webtoolkit.info/javascript-utf8.html + */ + utf8encode: function(string) { + // TextEncoder + Uint8Array to binary string is faster than checking every bytes on long strings. + // http://jsperf.com/utf8encode-vs-textencoder + // On short strings (file names for example), the TextEncoder API is (currently) slower. + if (textEncoder) { + var u8 = textEncoder.encode(string); + return utils.transformTo("string", u8); + } + if (support.nodebuffer) { + return utils.transformTo("string", nodeBuffer(string, "utf-8")); + } + + // array.join may be slower than string concatenation but generates less objects (less time spent garbage collecting). + // See also http://jsperf.com/array-direct-assignment-vs-push/31 + var result = [], + resIndex = 0; + + for (var n = 0; n < string.length; n++) { + + var c = string.charCodeAt(n); + + if (c < 128) { + result[resIndex++] = String.fromCharCode(c); + } + else if ((c > 127) && (c < 2048)) { + result[resIndex++] = String.fromCharCode((c >> 6) | 192); + result[resIndex++] = String.fromCharCode((c & 63) | 128); + } + else { + result[resIndex++] = String.fromCharCode((c >> 12) | 224); + result[resIndex++] = String.fromCharCode(((c >> 6) & 63) | 128); + result[resIndex++] = String.fromCharCode((c & 63) | 128); + } + + } + + return result.join(""); + }, + + /** + * http://www.webtoolkit.info/javascript-utf8.html + */ + utf8decode: function(input) { + var result = [], + resIndex = 0; + var type = utils.getTypeOf(input); + var isArray = type !== "string"; + var i = 0; + var c = 0, + c1 = 0, + c2 = 0, + c3 = 0; + + // check if we can use the TextDecoder API + // see http://encoding.spec.whatwg.org/#api + if (textDecoder) { + return textDecoder.decode( + utils.transformTo("uint8array", input) + ); + } + if (support.nodebuffer) { + return utils.transformTo("nodebuffer", input).toString("utf-8"); + } + + while (i < input.length) { + + c = isArray ? input[i] : input.charCodeAt(i); + + if (c < 128) { + result[resIndex++] = String.fromCharCode(c); + i++; + } + else if ((c > 191) && (c < 224)) { + c2 = isArray ? input[i + 1] : input.charCodeAt(i + 1); + result[resIndex++] = String.fromCharCode(((c & 31) << 6) | (c2 & 63)); + i += 2; + } + else { + c2 = isArray ? input[i + 1] : input.charCodeAt(i + 1); + c3 = isArray ? input[i + 2] : input.charCodeAt(i + 2); + result[resIndex++] = String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); + i += 3; + } + + } + + return result.join(""); + } +}; +module.exports = out; + +},{"./base64":7,"./compressedObject":8,"./compressions":9,"./defaults":11,"./nodeBuffer":15,"./signature":18,"./support":20,"./utils":22}],18:[function(_dereq_,module,exports){ +'use strict'; +exports.LOCAL_FILE_HEADER = "PK\x03\x04"; +exports.CENTRAL_FILE_HEADER = "PK\x01\x02"; +exports.CENTRAL_DIRECTORY_END = "PK\x05\x06"; +exports.ZIP64_CENTRAL_DIRECTORY_LOCATOR = "PK\x06\x07"; +exports.ZIP64_CENTRAL_DIRECTORY_END = "PK\x06\x06"; +exports.DATA_DESCRIPTOR = "PK\x07\x08"; + +},{}],19:[function(_dereq_,module,exports){ +'use strict'; +var DataReader = _dereq_('./dataReader'); +var utils = _dereq_('./utils'); + +function StringReader(data, optimizedBinaryString) { + this.data = data; + if (!optimizedBinaryString) { + this.data = utils.string2binary(this.data); + } + this.length = this.data.length; + this.index = 0; +} +StringReader.prototype = new DataReader(); +/** + * @see DataReader.byteAt + */ +StringReader.prototype.byteAt = function(i) { + return this.data.charCodeAt(i); +}; +/** + * @see DataReader.lastIndexOfSignature + */ +StringReader.prototype.lastIndexOfSignature = function(sig) { + return this.data.lastIndexOf(sig); +}; +/** + * @see DataReader.readData + */ +StringReader.prototype.readData = function(size) { + this.checkOffset(size); + // this will work because the constructor applied the "& 0xff" mask. + var result = this.data.slice(this.index, this.index + size); + this.index += size; + return result; +}; +module.exports = StringReader; + +},{"./dataReader":10,"./utils":22}],20:[function(_dereq_,module,exports){ +(function (Buffer){ +'use strict'; +exports.base64 = true; +exports.array = true; +exports.string = true; +exports.arraybuffer = typeof ArrayBuffer !== "undefined" && typeof Uint8Array !== "undefined"; +// contains true if JSZip can read/generate nodejs Buffer, false otherwise. +// Browserify will provide a Buffer implementation for browsers, which is +// an augmented Uint8Array (i.e., can be used as either Buffer or U8). +exports.nodebuffer = typeof Buffer !== "undefined"; +// contains true if JSZip can read/generate Uint8Array, false otherwise. +exports.uint8array = typeof Uint8Array !== "undefined"; + +if (typeof ArrayBuffer === "undefined") { + exports.blob = false; +} +else { + var buffer = new ArrayBuffer(0); + try { + exports.blob = new Blob([buffer], { + type: "application/zip" + }).size === 0; + } + catch (e) { + try { + var Builder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder || window.MSBlobBuilder; + var builder = new Builder(); + builder.append(buffer); + exports.blob = builder.getBlob('application/zip').size === 0; + } + catch (e) { + exports.blob = false; + } + } +} + +}).call(this,_dereq_("buffer").Buffer) +},{}],21:[function(_dereq_,module,exports){ +'use strict'; +var DataReader = _dereq_('./dataReader'); + +function Uint8ArrayReader(data) { + if (data) { + this.data = data; + this.length = this.data.length; + this.index = 0; + } +} +Uint8ArrayReader.prototype = new DataReader(); +/** + * @see DataReader.byteAt + */ +Uint8ArrayReader.prototype.byteAt = function(i) { + return this.data[i]; +}; +/** + * @see DataReader.lastIndexOfSignature + */ +Uint8ArrayReader.prototype.lastIndexOfSignature = function(sig) { + var sig0 = sig.charCodeAt(0), + sig1 = sig.charCodeAt(1), + sig2 = sig.charCodeAt(2), + sig3 = sig.charCodeAt(3); + for (var i = this.length - 4; i >= 0; --i) { + if (this.data[i] === sig0 && this.data[i + 1] === sig1 && this.data[i + 2] === sig2 && this.data[i + 3] === sig3) { + return i; + } + } + + return -1; +}; +/** + * @see DataReader.readData + */ +Uint8ArrayReader.prototype.readData = function(size) { + this.checkOffset(size); + var result = this.data.subarray(this.index, this.index + size); + this.index += size; + return result; +}; +module.exports = Uint8ArrayReader; + +},{"./dataReader":10}],22:[function(_dereq_,module,exports){ +'use strict'; +var support = _dereq_('./support'); +var compressions = _dereq_('./compressions'); +var nodeBuffer = _dereq_('./nodeBuffer'); +/** + * Convert a string to a "binary string" : a string containing only char codes between 0 and 255. + * @param {string} str the string to transform. + * @return {String} the binary string. + */ +exports.string2binary = function(str) { + var result = ""; + for (var i = 0; i < str.length; i++) { + result += String.fromCharCode(str.charCodeAt(i) & 0xff); + } + return result; +}; +/** + * Create a Uint8Array from the string. + * @param {string} str the string to transform. + * @return {Uint8Array} the typed array. + * @throws {Error} an Error if the browser doesn't support the requested feature. + */ +exports.string2Uint8Array = function(str) { + return exports.transformTo("uint8array", str); +}; + +/** + * Create a string from the Uint8Array. + * @param {Uint8Array} array the array to transform. + * @return {string} the string. + * @throws {Error} an Error if the browser doesn't support the requested feature. + */ +exports.uint8Array2String = function(array) { + return exports.transformTo("string", array); +}; +/** + * Create a blob from the given string. + * @param {string} str the string to transform. + * @return {Blob} the string. + * @throws {Error} an Error if the browser doesn't support the requested feature. + */ +exports.string2Blob = function(str) { + var buffer = exports.transformTo("arraybuffer", str); + return exports.arrayBuffer2Blob(buffer); +}; +exports.arrayBuffer2Blob = function(buffer) { + exports.checkSupport("blob"); + + try { + // Blob constructor + return new Blob([buffer], { + type: "application/zip" + }); + } + catch (e) { + + try { + // deprecated, browser only, old way + var Builder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder || window.MSBlobBuilder; + var builder = new Builder(); + builder.append(buffer); + return builder.getBlob('application/zip'); + } + catch (e) { + + // well, fuck ?! + throw new Error("Bug : can't construct the Blob."); + } + } + + +}; +/** + * The identity function. + * @param {Object} input the input. + * @return {Object} the same input. + */ +function identity(input) { + return input; +} + +/** + * Fill in an array with a string. + * @param {String} str the string to use. + * @param {Array|ArrayBuffer|Uint8Array|Buffer} array the array to fill in (will be mutated). + * @return {Array|ArrayBuffer|Uint8Array|Buffer} the updated array. + */ +function stringToArrayLike(str, array) { + for (var i = 0; i < str.length; ++i) { + array[i] = str.charCodeAt(i) & 0xFF; + } + return array; +} + +/** + * Transform an array-like object to a string. + * @param {Array|ArrayBuffer|Uint8Array|Buffer} array the array to transform. + * @return {String} the result. + */ +function arrayLikeToString(array) { + // Performances notes : + // -------------------- + // String.fromCharCode.apply(null, array) is the fastest, see + // see http://jsperf.com/converting-a-uint8array-to-a-string/2 + // but the stack is limited (and we can get huge arrays !). + // + // result += String.fromCharCode(array[i]); generate too many strings ! + // + // This code is inspired by http://jsperf.com/arraybuffer-to-string-apply-performance/2 + var chunk = 65536; + var result = [], + len = array.length, + type = exports.getTypeOf(array), + k = 0, + canUseApply = true; + try { + switch(type) { + case "uint8array": + String.fromCharCode.apply(null, new Uint8Array(0)); + break; + case "nodebuffer": + String.fromCharCode.apply(null, nodeBuffer(0)); + break; + } + } catch(e) { + canUseApply = false; + } + + // no apply : slow and painful algorithm + // default browser on android 4.* + if (!canUseApply) { + var resultStr = ""; + for(var i = 0; i < array.length;i++) { + resultStr += String.fromCharCode(array[i]); + } + return resultStr; + } + while (k < len && chunk > 1) { + try { + if (type === "array" || type === "nodebuffer") { + result.push(String.fromCharCode.apply(null, array.slice(k, Math.min(k + chunk, len)))); + } + else { + result.push(String.fromCharCode.apply(null, array.subarray(k, Math.min(k + chunk, len)))); + } + k += chunk; + } + catch (e) { + chunk = Math.floor(chunk / 2); + } + } + return result.join(""); +} + +/** + * Copy the data from an array-like to an other array-like. + * @param {Array|ArrayBuffer|Uint8Array|Buffer} arrayFrom the origin array. + * @param {Array|ArrayBuffer|Uint8Array|Buffer} arrayTo the destination array which will be mutated. + * @return {Array|ArrayBuffer|Uint8Array|Buffer} the updated destination array. + */ +function arrayLikeToArrayLike(arrayFrom, arrayTo) { + for (var i = 0; i < arrayFrom.length; i++) { + arrayTo[i] = arrayFrom[i]; + } + return arrayTo; +} + +// a matrix containing functions to transform everything into everything. +var transform = {}; + +// string to ? +transform["string"] = { + "string": identity, + "array": function(input) { + return stringToArrayLike(input, new Array(input.length)); + }, + "arraybuffer": function(input) { + return transform["string"]["uint8array"](input).buffer; + }, + "uint8array": function(input) { + return stringToArrayLike(input, new Uint8Array(input.length)); + }, + "nodebuffer": function(input) { + return stringToArrayLike(input, nodeBuffer(input.length)); + } +}; + +// array to ? +transform["array"] = { + "string": arrayLikeToString, + "array": identity, + "arraybuffer": function(input) { + return (new Uint8Array(input)).buffer; + }, + "uint8array": function(input) { + return new Uint8Array(input); + }, + "nodebuffer": function(input) { + return nodeBuffer(input); + } +}; + +// arraybuffer to ? +transform["arraybuffer"] = { + "string": function(input) { + return arrayLikeToString(new Uint8Array(input)); + }, + "array": function(input) { + return arrayLikeToArrayLike(new Uint8Array(input), new Array(input.byteLength)); + }, + "arraybuffer": identity, + "uint8array": function(input) { + return new Uint8Array(input); + }, + "nodebuffer": function(input) { + return nodeBuffer(new Uint8Array(input)); + } +}; + +// uint8array to ? +transform["uint8array"] = { + "string": arrayLikeToString, + "array": function(input) { + return arrayLikeToArrayLike(input, new Array(input.length)); + }, + "arraybuffer": function(input) { + return input.buffer; + }, + "uint8array": identity, + "nodebuffer": function(input) { + return nodeBuffer(input); + } +}; + +// nodebuffer to ? +transform["nodebuffer"] = { + "string": arrayLikeToString, + "array": function(input) { + return arrayLikeToArrayLike(input, new Array(input.length)); + }, + "arraybuffer": function(input) { + return transform["nodebuffer"]["uint8array"](input).buffer; + }, + "uint8array": function(input) { + return arrayLikeToArrayLike(input, new Uint8Array(input.length)); + }, + "nodebuffer": identity +}; + +/** + * Transform an input into any type. + * The supported output type are : string, array, uint8array, arraybuffer, nodebuffer. + * If no output type is specified, the unmodified input will be returned. + * @param {String} outputType the output type. + * @param {String|Array|ArrayBuffer|Uint8Array|Buffer} input the input to convert. + * @throws {Error} an Error if the browser doesn't support the requested output type. + */ +exports.transformTo = function(outputType, input) { + if (!input) { + // undefined, null, etc + // an empty string won't harm. + input = ""; + } + if (!outputType) { + return input; + } + exports.checkSupport(outputType); + var inputType = exports.getTypeOf(input); + var result = transform[inputType][outputType](input); + return result; +}; + +/** + * Return the type of the input. + * The type will be in a format valid for JSZip.utils.transformTo : string, array, uint8array, arraybuffer. + * @param {Object} input the input to identify. + * @return {String} the (lowercase) type of the input. + */ +exports.getTypeOf = function(input) { + if (typeof input === "string") { + return "string"; + } + if (Object.prototype.toString.call(input) === "[object Array]") { + return "array"; + } + if (support.nodebuffer && nodeBuffer.test(input)) { + return "nodebuffer"; + } + if (support.uint8array && input instanceof Uint8Array) { + return "uint8array"; + } + if (support.arraybuffer && input instanceof ArrayBuffer) { + return "arraybuffer"; + } +}; + +/** + * Throw an exception if the type is not supported. + * @param {String} type the type to check. + * @throws {Error} an Error if the browser doesn't support the requested type. + */ +exports.checkSupport = function(type) { + var supported = support[type.toLowerCase()]; + if (!supported) { + throw new Error(type + " is not supported by this browser"); + } +}; +exports.MAX_VALUE_16BITS = 65535; +exports.MAX_VALUE_32BITS = -1; // well, "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" is parsed as -1 + +/** + * Prettify a string read as binary. + * @param {string} str the string to prettify. + * @return {string} a pretty string. + */ +exports.pretty = function(str) { + var res = '', + code, i; + for (i = 0; i < (str || "").length; i++) { + code = str.charCodeAt(i); + res += '\\x' + (code < 16 ? "0" : "") + code.toString(16).toUpperCase(); + } + return res; +}; + +/** + * Find a compression registered in JSZip. + * @param {string} compressionMethod the method magic to find. + * @return {Object|null} the JSZip compression object, null if none found. + */ +exports.findCompression = function(compressionMethod) { + for (var method in compressions) { + if (!compressions.hasOwnProperty(method)) { + continue; + } + if (compressions[method].magic === compressionMethod) { + return compressions[method]; + } + } + return null; +}; +/** +* Cross-window, cross-Node-context regular expression detection +* @param {Object} object Anything +* @return {Boolean} true if the object is a regular expression, +* false otherwise +*/ +exports.isRegExp = function (object) { + return Object.prototype.toString.call(object) === "[object RegExp]"; +}; + + +},{"./compressions":9,"./nodeBuffer":15,"./support":20}],23:[function(_dereq_,module,exports){ +'use strict'; +var StringReader = _dereq_('./stringReader'); +var NodeBufferReader = _dereq_('./nodeBufferReader'); +var Uint8ArrayReader = _dereq_('./uint8ArrayReader'); +var utils = _dereq_('./utils'); +var sig = _dereq_('./signature'); +var ZipEntry = _dereq_('./zipEntry'); +var support = _dereq_('./support'); +// class ZipEntries {{{ +/** + * All the entries in the zip file. + * @constructor + * @param {String|ArrayBuffer|Uint8Array} data the binary stream to load. + * @param {Object} loadOptions Options for loading the stream. + */ +function ZipEntries(data, loadOptions) { + this.files = []; + this.loadOptions = loadOptions; + if (data) { + this.load(data); + } +} +ZipEntries.prototype = { + /** + * Check that the reader is on the speficied signature. + * @param {string} expectedSignature the expected signature. + * @throws {Error} if it is an other signature. + */ + checkSignature: function(expectedSignature) { + var signature = this.reader.readString(4); + if (signature !== expectedSignature) { + throw new Error("Corrupted zip or bug : unexpected signature " + "(" + utils.pretty(signature) + ", expected " + utils.pretty(expectedSignature) + ")"); + } + }, + /** + * Read the end of the central directory. + */ + readBlockEndOfCentral: function() { + this.diskNumber = this.reader.readInt(2); + this.diskWithCentralDirStart = this.reader.readInt(2); + this.centralDirRecordsOnThisDisk = this.reader.readInt(2); + this.centralDirRecords = this.reader.readInt(2); + this.centralDirSize = this.reader.readInt(4); + this.centralDirOffset = this.reader.readInt(4); + + this.zipCommentLength = this.reader.readInt(2); + this.zipComment = this.reader.readString(this.zipCommentLength); + }, + /** + * Read the end of the Zip 64 central directory. + * Not merged with the method readEndOfCentral : + * The end of central can coexist with its Zip64 brother, + * I don't want to read the wrong number of bytes ! + */ + readBlockZip64EndOfCentral: function() { + this.zip64EndOfCentralSize = this.reader.readInt(8); + this.versionMadeBy = this.reader.readString(2); + this.versionNeeded = this.reader.readInt(2); + this.diskNumber = this.reader.readInt(4); + this.diskWithCentralDirStart = this.reader.readInt(4); + this.centralDirRecordsOnThisDisk = this.reader.readInt(8); + this.centralDirRecords = this.reader.readInt(8); + this.centralDirSize = this.reader.readInt(8); + this.centralDirOffset = this.reader.readInt(8); + + this.zip64ExtensibleData = {}; + var extraDataSize = this.zip64EndOfCentralSize - 44, + index = 0, + extraFieldId, + extraFieldLength, + extraFieldValue; + while (index < extraDataSize) { + extraFieldId = this.reader.readInt(2); + extraFieldLength = this.reader.readInt(4); + extraFieldValue = this.reader.readString(extraFieldLength); + this.zip64ExtensibleData[extraFieldId] = { + id: extraFieldId, + length: extraFieldLength, + value: extraFieldValue + }; + } + }, + /** + * Read the end of the Zip 64 central directory locator. + */ + readBlockZip64EndOfCentralLocator: function() { + this.diskWithZip64CentralDirStart = this.reader.readInt(4); + this.relativeOffsetEndOfZip64CentralDir = this.reader.readInt(8); + this.disksCount = this.reader.readInt(4); + if (this.disksCount > 1) { + throw new Error("Multi-volumes zip are not supported"); + } + }, + /** + * Read the local files, based on the offset read in the central part. + */ + readLocalFiles: function() { + var i, file; + for (i = 0; i < this.files.length; i++) { + file = this.files[i]; + this.reader.setIndex(file.localHeaderOffset); + this.checkSignature(sig.LOCAL_FILE_HEADER); + file.readLocalPart(this.reader); + file.handleUTF8(); + } + }, + /** + * Read the central directory. + */ + readCentralDir: function() { + var file; + + this.reader.setIndex(this.centralDirOffset); + while (this.reader.readString(4) === sig.CENTRAL_FILE_HEADER) { + file = new ZipEntry({ + zip64: this.zip64 + }, this.loadOptions); + file.readCentralPart(this.reader); + this.files.push(file); + } + }, + /** + * Read the end of central directory. + */ + readEndOfCentral: function() { + var offset = this.reader.lastIndexOfSignature(sig.CENTRAL_DIRECTORY_END); + if (offset === -1) { + throw new Error("Corrupted zip : can't find end of central directory"); + } + this.reader.setIndex(offset); + this.checkSignature(sig.CENTRAL_DIRECTORY_END); + this.readBlockEndOfCentral(); + + + /* extract from the zip spec : + 4) If one of the fields in the end of central directory + record is too small to hold required data, the field + should be set to -1 (0xFFFF or 0xFFFFFFFF) and the + ZIP64 format record should be created. + 5) The end of central directory record and the + Zip64 end of central directory locator record must + reside on the same disk when splitting or spanning + an archive. + */ + if (this.diskNumber === utils.MAX_VALUE_16BITS || this.diskWithCentralDirStart === utils.MAX_VALUE_16BITS || this.centralDirRecordsOnThisDisk === utils.MAX_VALUE_16BITS || this.centralDirRecords === utils.MAX_VALUE_16BITS || this.centralDirSize === utils.MAX_VALUE_32BITS || this.centralDirOffset === utils.MAX_VALUE_32BITS) { + this.zip64 = true; + + /* + Warning : the zip64 extension is supported, but ONLY if the 64bits integer read from + the zip file can fit into a 32bits integer. This cannot be solved : Javascript represents + all numbers as 64-bit double precision IEEE 754 floating point numbers. + So, we have 53bits for integers and bitwise operations treat everything as 32bits. + see https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Operators/Bitwise_Operators + and http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf section 8.5 + */ + + // should look for a zip64 EOCD locator + offset = this.reader.lastIndexOfSignature(sig.ZIP64_CENTRAL_DIRECTORY_LOCATOR); + if (offset === -1) { + throw new Error("Corrupted zip : can't find the ZIP64 end of central directory locator"); + } + this.reader.setIndex(offset); + this.checkSignature(sig.ZIP64_CENTRAL_DIRECTORY_LOCATOR); + this.readBlockZip64EndOfCentralLocator(); + + // now the zip64 EOCD record + this.reader.setIndex(this.relativeOffsetEndOfZip64CentralDir); + this.checkSignature(sig.ZIP64_CENTRAL_DIRECTORY_END); + this.readBlockZip64EndOfCentral(); + } + }, + prepareReader: function(data) { + var type = utils.getTypeOf(data); + if (type === "string" && !support.uint8array) { + this.reader = new StringReader(data, this.loadOptions.optimizedBinaryString); + } + else if (type === "nodebuffer") { + this.reader = new NodeBufferReader(data); + } + else { + this.reader = new Uint8ArrayReader(utils.transformTo("uint8array", data)); + } + }, + /** + * Read a zip file and create ZipEntries. + * @param {String|ArrayBuffer|Uint8Array|Buffer} data the binary string representing a zip file. + */ + load: function(data) { + this.prepareReader(data); + this.readEndOfCentral(); + this.readCentralDir(); + this.readLocalFiles(); + } +}; +// }}} end of ZipEntries +module.exports = ZipEntries; + +},{"./nodeBufferReader":16,"./signature":18,"./stringReader":19,"./support":20,"./uint8ArrayReader":21,"./utils":22,"./zipEntry":24}],24:[function(_dereq_,module,exports){ +'use strict'; +var StringReader = _dereq_('./stringReader'); +var utils = _dereq_('./utils'); +var CompressedObject = _dereq_('./compressedObject'); +var jszipProto = _dereq_('./object'); +// class ZipEntry {{{ +/** + * An entry in the zip file. + * @constructor + * @param {Object} options Options of the current file. + * @param {Object} loadOptions Options for loading the stream. + */ +function ZipEntry(options, loadOptions) { + this.options = options; + this.loadOptions = loadOptions; +} +ZipEntry.prototype = { + /** + * say if the file is encrypted. + * @return {boolean} true if the file is encrypted, false otherwise. + */ + isEncrypted: function() { + // bit 1 is set + return (this.bitFlag & 0x0001) === 0x0001; + }, + /** + * say if the file has utf-8 filename/comment. + * @return {boolean} true if the filename/comment is in utf-8, false otherwise. + */ + useUTF8: function() { + // bit 11 is set + return (this.bitFlag & 0x0800) === 0x0800; + }, + /** + * Prepare the function used to generate the compressed content from this ZipFile. + * @param {DataReader} reader the reader to use. + * @param {number} from the offset from where we should read the data. + * @param {number} length the length of the data to read. + * @return {Function} the callback to get the compressed content (the type depends of the DataReader class). + */ + prepareCompressedContent: function(reader, from, length) { + return function() { + var previousIndex = reader.index; + reader.setIndex(from); + var compressedFileData = reader.readData(length); + reader.setIndex(previousIndex); + + return compressedFileData; + }; + }, + /** + * Prepare the function used to generate the uncompressed content from this ZipFile. + * @param {DataReader} reader the reader to use. + * @param {number} from the offset from where we should read the data. + * @param {number} length the length of the data to read. + * @param {JSZip.compression} compression the compression used on this file. + * @param {number} uncompressedSize the uncompressed size to expect. + * @return {Function} the callback to get the uncompressed content (the type depends of the DataReader class). + */ + prepareContent: function(reader, from, length, compression, uncompressedSize) { + return function() { + + var compressedFileData = utils.transformTo(compression.uncompressInputType, this.getCompressedContent()); + var uncompressedFileData = compression.uncompress(compressedFileData); + + if (uncompressedFileData.length !== uncompressedSize) { + throw new Error("Bug : uncompressed data size mismatch"); + } + + return uncompressedFileData; + }; + }, + /** + * Read the local part of a zip file and add the info in this object. + * @param {DataReader} reader the reader to use. + */ + readLocalPart: function(reader) { + var compression, localExtraFieldsLength; + + // we already know everything from the central dir ! + // If the central dir data are false, we are doomed. + // On the bright side, the local part is scary : zip64, data descriptors, both, etc. + // The less data we get here, the more reliable this should be. + // Let's skip the whole header and dash to the data ! + reader.skip(22); + // in some zip created on windows, the filename stored in the central dir contains \ instead of /. + // Strangely, the filename here is OK. + // I would love to treat these zip files as corrupted (see http://www.info-zip.org/FAQ.html#backslashes + // or APPNOTE#4.4.17.1, "All slashes MUST be forward slashes '/'") but there are a lot of bad zip generators... + // Search "unzip mismatching "local" filename continuing with "central" filename version" on + // the internet. + // + // I think I see the logic here : the central directory is used to display + // content and the local directory is used to extract the files. Mixing / and \ + // may be used to display \ to windows users and use / when extracting the files. + // Unfortunately, this lead also to some issues : http://seclists.org/fulldisclosure/2009/Sep/394 + this.fileNameLength = reader.readInt(2); + localExtraFieldsLength = reader.readInt(2); // can't be sure this will be the same as the central dir + this.fileName = reader.readString(this.fileNameLength); + reader.skip(localExtraFieldsLength); + + if (this.compressedSize == -1 || this.uncompressedSize == -1) { + throw new Error("Bug or corrupted zip : didn't get enough informations from the central directory " + "(compressedSize == -1 || uncompressedSize == -1)"); + } + + compression = utils.findCompression(this.compressionMethod); + if (compression === null) { // no compression found + throw new Error("Corrupted zip : compression " + utils.pretty(this.compressionMethod) + " unknown (inner file : " + this.fileName + ")"); + } + this.decompressed = new CompressedObject(); + this.decompressed.compressedSize = this.compressedSize; + this.decompressed.uncompressedSize = this.uncompressedSize; + this.decompressed.crc32 = this.crc32; + this.decompressed.compressionMethod = this.compressionMethod; + this.decompressed.getCompressedContent = this.prepareCompressedContent(reader, reader.index, this.compressedSize, compression); + this.decompressed.getContent = this.prepareContent(reader, reader.index, this.compressedSize, compression, this.uncompressedSize); + + // we need to compute the crc32... + if (this.loadOptions.checkCRC32) { + this.decompressed = utils.transformTo("string", this.decompressed.getContent()); + if (jszipProto.crc32(this.decompressed) !== this.crc32) { + throw new Error("Corrupted zip : CRC32 mismatch"); + } + } + }, + + /** + * Read the central part of a zip file and add the info in this object. + * @param {DataReader} reader the reader to use. + */ + readCentralPart: function(reader) { + this.versionMadeBy = reader.readString(2); + this.versionNeeded = reader.readInt(2); + this.bitFlag = reader.readInt(2); + this.compressionMethod = reader.readString(2); + this.date = reader.readDate(); + this.crc32 = reader.readInt(4); + this.compressedSize = reader.readInt(4); + this.uncompressedSize = reader.readInt(4); + this.fileNameLength = reader.readInt(2); + this.extraFieldsLength = reader.readInt(2); + this.fileCommentLength = reader.readInt(2); + this.diskNumberStart = reader.readInt(2); + this.internalFileAttributes = reader.readInt(2); + this.externalFileAttributes = reader.readInt(4); + this.localHeaderOffset = reader.readInt(4); + + if (this.isEncrypted()) { + throw new Error("Encrypted zip are not supported"); + } + + this.fileName = reader.readString(this.fileNameLength); + this.readExtraFields(reader); + this.parseZIP64ExtraField(reader); + this.fileComment = reader.readString(this.fileCommentLength); + + // warning, this is true only for zip with madeBy == DOS (plateform dependent feature) + this.dir = this.externalFileAttributes & 0x00000010 ? true : false; + }, + /** + * Parse the ZIP64 extra field and merge the info in the current ZipEntry. + * @param {DataReader} reader the reader to use. + */ + parseZIP64ExtraField: function(reader) { + + if (!this.extraFields[0x0001]) { + return; + } + + // should be something, preparing the extra reader + var extraReader = new StringReader(this.extraFields[0x0001].value); + + // I really hope that these 64bits integer can fit in 32 bits integer, because js + // won't let us have more. + if (this.uncompressedSize === utils.MAX_VALUE_32BITS) { + this.uncompressedSize = extraReader.readInt(8); + } + if (this.compressedSize === utils.MAX_VALUE_32BITS) { + this.compressedSize = extraReader.readInt(8); + } + if (this.localHeaderOffset === utils.MAX_VALUE_32BITS) { + this.localHeaderOffset = extraReader.readInt(8); + } + if (this.diskNumberStart === utils.MAX_VALUE_32BITS) { + this.diskNumberStart = extraReader.readInt(4); + } + }, + /** + * Read the central part of a zip file and add the info in this object. + * @param {DataReader} reader the reader to use. + */ + readExtraFields: function(reader) { + var start = reader.index, + extraFieldId, + extraFieldLength, + extraFieldValue; + + this.extraFields = this.extraFields || {}; + + while (reader.index < start + this.extraFieldsLength) { + extraFieldId = reader.readInt(2); + extraFieldLength = reader.readInt(2); + extraFieldValue = reader.readString(extraFieldLength); + + this.extraFields[extraFieldId] = { + id: extraFieldId, + length: extraFieldLength, + value: extraFieldValue + }; + } + }, + /** + * Apply an UTF8 transformation if needed. + */ + handleUTF8: function() { + if (this.useUTF8()) { + this.fileName = jszipProto.utf8decode(this.fileName); + this.fileComment = jszipProto.utf8decode(this.fileComment); + } else { + var upath = this.findExtraFieldUnicodePath(); + if (upath !== null) { + this.fileName = upath; + } + } + }, + + /** + * Find the unicode path declared in the extra field, if any. + * @return {String} the unicode path, null otherwise. + */ + findExtraFieldUnicodePath: function() { + var upathField = this.extraFields[0x7075]; + if (upathField) { + var extraReader = new StringReader(upathField.value); + + // wrong version + if (extraReader.readInt(1) !== 1) { + return null; + } + + // the crc of the filename changed, this field is out of date. + if (jszipProto.crc32(this.fileName) !== extraReader.readInt(4)) { + return null; + } + + return jszipProto.utf8decode(extraReader.readString(upathField.length - 5)); + } + return null; + } +}; +module.exports = ZipEntry; + +},{"./compressedObject":8,"./object":17,"./stringReader":19,"./utils":22}],25:[function(_dereq_,module,exports){ +// Top level file is just a mixin of submodules & constants +'use strict'; + +var assign = _dereq_('./lib/utils/common').assign; + +var deflate = _dereq_('./lib/deflate'); +var inflate = _dereq_('./lib/inflate'); +var constants = _dereq_('./lib/zlib/constants'); + +var pako = {}; + +assign(pako, deflate, inflate, constants); + +module.exports = pako; +},{"./lib/deflate":26,"./lib/inflate":27,"./lib/utils/common":28,"./lib/zlib/constants":31}],26:[function(_dereq_,module,exports){ +'use strict'; + + +var zlib_deflate = _dereq_('./zlib/deflate.js'); +var utils = _dereq_('./utils/common'); +var strings = _dereq_('./utils/strings'); +var msg = _dereq_('./zlib/messages'); +var zstream = _dereq_('./zlib/zstream'); + + +/* Public constants ==========================================================*/ +/* ===========================================================================*/ + +var Z_NO_FLUSH = 0; +var Z_FINISH = 4; + +var Z_OK = 0; +var Z_STREAM_END = 1; + +var Z_DEFAULT_COMPRESSION = -1; + +var Z_DEFAULT_STRATEGY = 0; + +var Z_DEFLATED = 8; + +/* ===========================================================================*/ + + +/** + * class Deflate + * + * Generic JS-style wrapper for zlib calls. If you don't need + * streaming behaviour - use more simple functions: [[deflate]], + * [[deflateRaw]] and [[gzip]]. + **/ + +/* internal + * Deflate.chunks -> Array + * + * Chunks of output data, if [[Deflate#onData]] not overriden. + **/ + +/** + * Deflate.result -> Uint8Array|Array + * + * Compressed result, generated by default [[Deflate#onData]] + * and [[Deflate#onEnd]] handlers. Filled after you push last chunk + * (call [[Deflate#push]] with `Z_FINISH` / `true` param). + **/ + +/** + * Deflate.err -> Number + * + * Error code after deflate finished. 0 (Z_OK) on success. + * You will not need it in real life, because deflate errors + * are possible only on wrong options or bad `onData` / `onEnd` + * custom handlers. + **/ + +/** + * Deflate.msg -> String + * + * Error message, if [[Deflate.err]] != 0 + **/ + + +/** + * new Deflate(options) + * - options (Object): zlib deflate options. + * + * Creates new deflator instance with specified params. Throws exception + * on bad params. Supported options: + * + * - `level` + * - `windowBits` + * - `memLevel` + * - `strategy` + * + * [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced) + * for more information on these. + * + * Additional options, for internal needs: + * + * - `chunkSize` - size of generated data chunks (16K by default) + * - `raw` (Boolean) - do raw deflate + * - `gzip` (Boolean) - create gzip wrapper + * - `to` (String) - if equal to 'string', then result will be "binary string" + * (each char code [0..255]) + * - `header` (Object) - custom header for gzip + * - `text` (Boolean) - true if compressed data believed to be text + * - `time` (Number) - modification time, unix timestamp + * - `os` (Number) - operation system code + * - `extra` (Array) - array of bytes with extra data (max 65536) + * - `name` (String) - file name (binary string) + * - `comment` (String) - comment (binary string) + * - `hcrc` (Boolean) - true if header crc should be added + * + * ##### Example: + * + * ```javascript + * var pako = require('pako') + * , chunk1 = Uint8Array([1,2,3,4,5,6,7,8,9]) + * , chunk2 = Uint8Array([10,11,12,13,14,15,16,17,18,19]); + * + * var deflate = new pako.Deflate({ level: 3}); + * + * deflate.push(chunk1, false); + * deflate.push(chunk2, true); // true -> last chunk + * + * if (deflate.err) { throw new Error(deflate.err); } + * + * console.log(deflate.result); + * ``` + **/ +var Deflate = function(options) { + + this.options = utils.assign({ + level: Z_DEFAULT_COMPRESSION, + method: Z_DEFLATED, + chunkSize: 16384, + windowBits: 15, + memLevel: 8, + strategy: Z_DEFAULT_STRATEGY, + to: '' + }, options || {}); + + var opt = this.options; + + if (opt.raw && (opt.windowBits > 0)) { + opt.windowBits = -opt.windowBits; + } + + else if (opt.gzip && (opt.windowBits > 0) && (opt.windowBits < 16)) { + opt.windowBits += 16; + } + + this.err = 0; // error code, if happens (0 = Z_OK) + this.msg = ''; // error message + this.ended = false; // used to avoid multiple onEnd() calls + this.chunks = []; // chunks of compressed data + + this.strm = new zstream(); + this.strm.avail_out = 0; + + var status = zlib_deflate.deflateInit2( + this.strm, + opt.level, + opt.method, + opt.windowBits, + opt.memLevel, + opt.strategy + ); + + if (status !== Z_OK) { + throw new Error(msg[status]); + } + + if (opt.header) { + zlib_deflate.deflateSetHeader(this.strm, opt.header); + } +}; + +/** + * Deflate#push(data[, mode]) -> Boolean + * - data (Uint8Array|Array|String): input data. Strings will be converted to + * utf8 byte sequence. + * - mode (Number|Boolean): 0..6 for corresponding Z_NO_FLUSH..Z_TREE modes. + * See constants. Skipped or `false` means Z_NO_FLUSH, `true` meansh Z_FINISH. + * + * Sends input data to deflate pipe, generating [[Deflate#onData]] calls with + * new compressed chunks. Returns `true` on success. The last data block must have + * mode Z_FINISH (or `true`). That flush internal pending buffers and call + * [[Deflate#onEnd]]. + * + * On fail call [[Deflate#onEnd]] with error code and return false. + * + * We strongly recommend to use `Uint8Array` on input for best speed (output + * array format is detected automatically). Also, don't skip last param and always + * use the same type in your code (boolean or number). That will improve JS speed. + * + * For regular `Array`-s make sure all elements are [0..255]. + * + * ##### Example + * + * ```javascript + * push(chunk, false); // push one of data chunks + * ... + * push(chunk, true); // push last chunk + * ``` + **/ +Deflate.prototype.push = function(data, mode) { + var strm = this.strm; + var chunkSize = this.options.chunkSize; + var status, _mode; + + if (this.ended) { return false; } + + _mode = (mode === ~~mode) ? mode : ((mode === true) ? Z_FINISH : Z_NO_FLUSH); + + // Convert data if needed + if (typeof data === 'string') { + // If we need to compress text, change encoding to utf8. + strm.input = strings.string2buf(data); + } else { + strm.input = data; + } + + strm.next_in = 0; + strm.avail_in = strm.input.length; + + do { + if (strm.avail_out === 0) { + strm.output = new utils.Buf8(chunkSize); + strm.next_out = 0; + strm.avail_out = chunkSize; + } + status = zlib_deflate.deflate(strm, _mode); /* no bad return value */ + + if (status !== Z_STREAM_END && status !== Z_OK) { + this.onEnd(status); + this.ended = true; + return false; + } + if (strm.avail_out === 0 || (strm.avail_in === 0 && _mode === Z_FINISH)) { + if (this.options.to === 'string') { + this.onData(strings.buf2binstring(utils.shrinkBuf(strm.output, strm.next_out))); + } else { + this.onData(utils.shrinkBuf(strm.output, strm.next_out)); + } + } + } while ((strm.avail_in > 0 || strm.avail_out === 0) && status !== Z_STREAM_END); + + // Finalize on the last chunk. + if (_mode === Z_FINISH) { + status = zlib_deflate.deflateEnd(this.strm); + this.onEnd(status); + this.ended = true; + return status === Z_OK; + } + + return true; +}; + + +/** + * Deflate#onData(chunk) -> Void + * - chunk (Uint8Array|Array|String): ouput data. Type of array depends + * on js engine support. When string output requested, each chunk + * will be string. + * + * By default, stores data blocks in `chunks[]` property and glue + * those in `onEnd`. Override this handler, if you need another behaviour. + **/ +Deflate.prototype.onData = function(chunk) { + this.chunks.push(chunk); +}; + + +/** + * Deflate#onEnd(status) -> Void + * - status (Number): deflate status. 0 (Z_OK) on success, + * other if not. + * + * Called once after you tell deflate that input stream complete + * or error happenned. By default - join collected chunks, + * free memory and fill `results` / `err` properties. + **/ +Deflate.prototype.onEnd = function(status) { + // On success - join + if (status === Z_OK) { + if (this.options.to === 'string') { + this.result = this.chunks.join(''); + } else { + this.result = utils.flattenChunks(this.chunks); + } + } + this.chunks = []; + this.err = status; + this.msg = this.strm.msg; +}; + + +/** + * deflate(data[, options]) -> Uint8Array|Array|String + * - data (Uint8Array|Array|String): input data to compress. + * - options (Object): zlib deflate options. + * + * Compress `data` with deflate alrorythm and `options`. + * + * Supported options are: + * + * - level + * - windowBits + * - memLevel + * - strategy + * + * [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced) + * for more information on these. + * + * Sugar (options): + * + * - `raw` (Boolean) - say that we work with raw stream, if you don't wish to specify + * negative windowBits implicitly. + * - `to` (String) - if equal to 'string', then result will be "binary string" + * (each char code [0..255]) + * + * ##### Example: + * + * ```javascript + * var pako = require('pako') + * , data = Uint8Array([1,2,3,4,5,6,7,8,9]); + * + * console.log(pako.deflate(data)); + * ``` + **/ +function deflate(input, options) { + var deflator = new Deflate(options); + + deflator.push(input, true); + + // That will never happens, if you don't cheat with options :) + if (deflator.err) { throw deflator.msg; } + + return deflator.result; +} + + +/** + * deflateRaw(data[, options]) -> Uint8Array|Array|String + * - data (Uint8Array|Array|String): input data to compress. + * - options (Object): zlib deflate options. + * + * The same as [[deflate]], but creates raw data, without wrapper + * (header and adler32 crc). + **/ +function deflateRaw(input, options) { + options = options || {}; + options.raw = true; + return deflate(input, options); +} + + +/** + * gzip(data[, options]) -> Uint8Array|Array|String + * - data (Uint8Array|Array|String): input data to compress. + * - options (Object): zlib deflate options. + * + * The same as [[deflate]], but create gzip wrapper instead of + * deflate one. + **/ +function gzip(input, options) { + options = options || {}; + options.gzip = true; + return deflate(input, options); +} + + +exports.Deflate = Deflate; +exports.deflate = deflate; +exports.deflateRaw = deflateRaw; +exports.gzip = gzip; +},{"./utils/common":28,"./utils/strings":29,"./zlib/deflate.js":33,"./zlib/messages":38,"./zlib/zstream":40}],27:[function(_dereq_,module,exports){ +'use strict'; + + +var zlib_inflate = _dereq_('./zlib/inflate.js'); +var utils = _dereq_('./utils/common'); +var strings = _dereq_('./utils/strings'); +var c = _dereq_('./zlib/constants'); +var msg = _dereq_('./zlib/messages'); +var zstream = _dereq_('./zlib/zstream'); +var gzheader = _dereq_('./zlib/gzheader'); + + +/** + * class Inflate + * + * Generic JS-style wrapper for zlib calls. If you don't need + * streaming behaviour - use more simple functions: [[inflate]] + * and [[inflateRaw]]. + **/ + +/* internal + * inflate.chunks -> Array + * + * Chunks of output data, if [[Inflate#onData]] not overriden. + **/ + +/** + * Inflate.result -> Uint8Array|Array|String + * + * Uncompressed result, generated by default [[Inflate#onData]] + * and [[Inflate#onEnd]] handlers. Filled after you push last chunk + * (call [[Inflate#push]] with `Z_FINISH` / `true` param). + **/ + +/** + * Inflate.err -> Number + * + * Error code after inflate finished. 0 (Z_OK) on success. + * Should be checked if broken data possible. + **/ + +/** + * Inflate.msg -> String + * + * Error message, if [[Inflate.err]] != 0 + **/ + + +/** + * new Inflate(options) + * - options (Object): zlib inflate options. + * + * Creates new inflator instance with specified params. Throws exception + * on bad params. Supported options: + * + * - `windowBits` + * + * [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced) + * for more information on these. + * + * Additional options, for internal needs: + * + * - `chunkSize` - size of generated data chunks (16K by default) + * - `raw` (Boolean) - do raw inflate + * - `to` (String) - if equal to 'string', then result will be converted + * from utf8 to utf16 (javascript) string. When string output requested, + * chunk length can differ from `chunkSize`, depending on content. + * + * By default, when no options set, autodetect deflate/gzip data format via + * wrapper header. + * + * ##### Example: + * + * ```javascript + * var pako = require('pako') + * , chunk1 = Uint8Array([1,2,3,4,5,6,7,8,9]) + * , chunk2 = Uint8Array([10,11,12,13,14,15,16,17,18,19]); + * + * var inflate = new pako.Inflate({ level: 3}); + * + * inflate.push(chunk1, false); + * inflate.push(chunk2, true); // true -> last chunk + * + * if (inflate.err) { throw new Error(inflate.err); } + * + * console.log(inflate.result); + * ``` + **/ +var Inflate = function(options) { + + this.options = utils.assign({ + chunkSize: 16384, + windowBits: 0, + to: '' + }, options || {}); + + var opt = this.options; + + // Force window size for `raw` data, if not set directly, + // because we have no header for autodetect. + if (opt.raw && (opt.windowBits >= 0) && (opt.windowBits < 16)) { + opt.windowBits = -opt.windowBits; + if (opt.windowBits === 0) { opt.windowBits = -15; } + } + + // If `windowBits` not defined (and mode not raw) - set autodetect flag for gzip/deflate + if ((opt.windowBits >= 0) && (opt.windowBits < 16) && + !(options && options.windowBits)) { + opt.windowBits += 32; + } + + // Gzip header has no info about windows size, we can do autodetect only + // for deflate. So, if window size not set, force it to max when gzip possible + if ((opt.windowBits > 15) && (opt.windowBits < 48)) { + // bit 3 (16) -> gzipped data + // bit 4 (32) -> autodetect gzip/deflate + if ((opt.windowBits & 15) === 0) { + opt.windowBits |= 15; + } + } + + this.err = 0; // error code, if happens (0 = Z_OK) + this.msg = ''; // error message + this.ended = false; // used to avoid multiple onEnd() calls + this.chunks = []; // chunks of compressed data + + this.strm = new zstream(); + this.strm.avail_out = 0; + + var status = zlib_inflate.inflateInit2( + this.strm, + opt.windowBits + ); + + if (status !== c.Z_OK) { + throw new Error(msg[status]); + } + + this.header = new gzheader(); + + zlib_inflate.inflateGetHeader(this.strm, this.header); +}; + +/** + * Inflate#push(data[, mode]) -> Boolean + * - data (Uint8Array|Array|String): input data + * - mode (Number|Boolean): 0..6 for corresponding Z_NO_FLUSH..Z_TREE modes. + * See constants. Skipped or `false` means Z_NO_FLUSH, `true` meansh Z_FINISH. + * + * Sends input data to inflate pipe, generating [[Inflate#onData]] calls with + * new output chunks. Returns `true` on success. The last data block must have + * mode Z_FINISH (or `true`). That flush internal pending buffers and call + * [[Inflate#onEnd]]. + * + * On fail call [[Inflate#onEnd]] with error code and return false. + * + * We strongly recommend to use `Uint8Array` on input for best speed (output + * format is detected automatically). Also, don't skip last param and always + * use the same type in your code (boolean or number). That will improve JS speed. + * + * For regular `Array`-s make sure all elements are [0..255]. + * + * ##### Example + * + * ```javascript + * push(chunk, false); // push one of data chunks + * ... + * push(chunk, true); // push last chunk + * ``` + **/ +Inflate.prototype.push = function(data, mode) { + var strm = this.strm; + var chunkSize = this.options.chunkSize; + var status, _mode; + var next_out_utf8, tail, utf8str; + + if (this.ended) { return false; } + _mode = (mode === ~~mode) ? mode : ((mode === true) ? c.Z_FINISH : c.Z_NO_FLUSH); + + // Convert data if needed + if (typeof data === 'string') { + // Only binary strings can be decompressed on practice + strm.input = strings.binstring2buf(data); + } else { + strm.input = data; + } + + strm.next_in = 0; + strm.avail_in = strm.input.length; + + do { + if (strm.avail_out === 0) { + strm.output = new utils.Buf8(chunkSize); + strm.next_out = 0; + strm.avail_out = chunkSize; + } + + status = zlib_inflate.inflate(strm, c.Z_NO_FLUSH); /* no bad return value */ + + if (status !== c.Z_STREAM_END && status !== c.Z_OK) { + this.onEnd(status); + this.ended = true; + return false; + } + + if (strm.next_out) { + if (strm.avail_out === 0 || status === c.Z_STREAM_END || (strm.avail_in === 0 && _mode === c.Z_FINISH)) { + + if (this.options.to === 'string') { + + next_out_utf8 = strings.utf8border(strm.output, strm.next_out); + + tail = strm.next_out - next_out_utf8; + utf8str = strings.buf2string(strm.output, next_out_utf8); + + // move tail + strm.next_out = tail; + strm.avail_out = chunkSize - tail; + if (tail) { utils.arraySet(strm.output, strm.output, next_out_utf8, tail, 0); } + + this.onData(utf8str); + + } else { + this.onData(utils.shrinkBuf(strm.output, strm.next_out)); + } + } + } + } while ((strm.avail_in > 0 || strm.avail_out === 0) && status !== c.Z_STREAM_END); + + if (status === c.Z_STREAM_END) { + _mode = c.Z_FINISH; + } + // Finalize on the last chunk. + if (_mode === c.Z_FINISH) { + status = zlib_inflate.inflateEnd(this.strm); + this.onEnd(status); + this.ended = true; + return status === c.Z_OK; + } + + return true; +}; + + +/** + * Inflate#onData(chunk) -> Void + * - chunk (Uint8Array|Array|String): ouput data. Type of array depends + * on js engine support. When string output requested, each chunk + * will be string. + * + * By default, stores data blocks in `chunks[]` property and glue + * those in `onEnd`. Override this handler, if you need another behaviour. + **/ +Inflate.prototype.onData = function(chunk) { + this.chunks.push(chunk); +}; + + +/** + * Inflate#onEnd(status) -> Void + * - status (Number): inflate status. 0 (Z_OK) on success, + * other if not. + * + * Called once after you tell inflate that input stream complete + * or error happenned. By default - join collected chunks, + * free memory and fill `results` / `err` properties. + **/ +Inflate.prototype.onEnd = function(status) { + // On success - join + if (status === c.Z_OK) { + if (this.options.to === 'string') { + // Glue & convert here, until we teach pako to send + // utf8 alligned strings to onData + this.result = this.chunks.join(''); + } else { + this.result = utils.flattenChunks(this.chunks); + } + } + this.chunks = []; + this.err = status; + this.msg = this.strm.msg; +}; + + +/** + * inflate(data[, options]) -> Uint8Array|Array|String + * - data (Uint8Array|Array|String): input data to decompress. + * - options (Object): zlib inflate options. + * + * Decompress `data` with inflate/ungzip and `options`. Autodetect + * format via wrapper header by default. That's why we don't provide + * separate `ungzip` method. + * + * Supported options are: + * + * - windowBits + * + * [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced) + * for more information. + * + * Sugar (options): + * + * - `raw` (Boolean) - say that we work with raw stream, if you don't wish to specify + * negative windowBits implicitly. + * - `to` (String) - if equal to 'string', then result will be converted + * from utf8 to utf16 (javascript) string. When string output requested, + * chunk length can differ from `chunkSize`, depending on content. + * + * + * ##### Example: + * + * ```javascript + * var pako = require('pako') + * , input = pako.deflate([1,2,3,4,5,6,7,8,9]) + * , output; + * + * try { + * output = pako.inflate(input); + * } catch (err) + * console.log(err); + * } + * ``` + **/ +function inflate(input, options) { + var inflator = new Inflate(options); + + inflator.push(input, true); + + // That will never happens, if you don't cheat with options :) + if (inflator.err) { throw inflator.msg; } + + return inflator.result; +} + + +/** + * inflateRaw(data[, options]) -> Uint8Array|Array|String + * - data (Uint8Array|Array|String): input data to decompress. + * - options (Object): zlib inflate options. + * + * The same as [[inflate]], but creates raw data, without wrapper + * (header and adler32 crc). + **/ +function inflateRaw(input, options) { + options = options || {}; + options.raw = true; + return inflate(input, options); +} + + +/** + * ungzip(data[, options]) -> Uint8Array|Array|String + * - data (Uint8Array|Array|String): input data to decompress. + * - options (Object): zlib inflate options. + * + * Just shortcut to [[inflate]], because it autodetects format + * by header.content. Done for convenience. + **/ + + +exports.Inflate = Inflate; +exports.inflate = inflate; +exports.inflateRaw = inflateRaw; +exports.ungzip = inflate; + +},{"./utils/common":28,"./utils/strings":29,"./zlib/constants":31,"./zlib/gzheader":34,"./zlib/inflate.js":36,"./zlib/messages":38,"./zlib/zstream":40}],28:[function(_dereq_,module,exports){ +'use strict'; + + +var TYPED_OK = (typeof Uint8Array !== 'undefined') && + (typeof Uint16Array !== 'undefined') && + (typeof Int32Array !== 'undefined'); + + +exports.assign = function (obj /*from1, from2, from3, ...*/) { + var sources = Array.prototype.slice.call(arguments, 1); + while (sources.length) { + var source = sources.shift(); + if (!source) { continue; } + + if (typeof(source) !== 'object') { + throw new TypeError(source + 'must be non-object'); + } + + for (var p in source) { + if (source.hasOwnProperty(p)) { + obj[p] = source[p]; + } + } + } + + return obj; +}; + + +// reduce buffer size, avoiding mem copy +exports.shrinkBuf = function (buf, size) { + if (buf.length === size) { return buf; } + if (buf.subarray) { return buf.subarray(0, size); } + buf.length = size; + return buf; +}; + + +var fnTyped = { + arraySet: function (dest, src, src_offs, len, dest_offs) { + if (src.subarray && dest.subarray) { + dest.set(src.subarray(src_offs, src_offs+len), dest_offs); + return; + } + // Fallback to ordinary array + for(var i=0; i= 252 ? 6 : i >= 248 ? 5 : i >= 240 ? 4 : i >= 224 ? 3 : i >= 192 ? 2 : 1); +} +_utf8len[254]=_utf8len[254]=1; // Invalid sequence start + + +// convert string to array (typed, when possible) +exports.string2buf = function (str) { + var buf, c, c2, m_pos, i, str_len = str.length, buf_len = 0; + + // count binary size + for (m_pos = 0; m_pos < str_len; m_pos++) { + c = str.charCodeAt(m_pos); + if ((c & 0xfc00) === 0xd800 && (m_pos+1 < str_len)) { + c2 = str.charCodeAt(m_pos+1); + if ((c2 & 0xfc00) === 0xdc00) { + c = 0x10000 + ((c - 0xd800) << 10) + (c2 - 0xdc00); + m_pos++; + } + } + buf_len += c < 0x80 ? 1 : c < 0x800 ? 2 : c < 0x10000 ? 3 : 4; + } + + // allocate buffer + buf = new utils.Buf8(buf_len); + + // convert + for (i=0, m_pos = 0; i < buf_len; m_pos++) { + c = str.charCodeAt(m_pos); + if ((c & 0xfc00) === 0xd800 && (m_pos+1 < str_len)) { + c2 = str.charCodeAt(m_pos+1); + if ((c2 & 0xfc00) === 0xdc00) { + c = 0x10000 + ((c - 0xd800) << 10) + (c2 - 0xdc00); + m_pos++; + } + } + if (c < 0x80) { + /* one byte */ + buf[i++] = c; + } else if (c < 0x800) { + /* two bytes */ + buf[i++] = 0xC0 | (c >>> 6); + buf[i++] = 0x80 | (c & 0x3f); + } else if (c < 0x10000) { + /* three bytes */ + buf[i++] = 0xE0 | (c >>> 12); + buf[i++] = 0x80 | (c >>> 6 & 0x3f); + buf[i++] = 0x80 | (c & 0x3f); + } else { + /* four bytes */ + buf[i++] = 0xf0 | (c >>> 18); + buf[i++] = 0x80 | (c >>> 12 & 0x3f); + buf[i++] = 0x80 | (c >>> 6 & 0x3f); + buf[i++] = 0x80 | (c & 0x3f); + } + } + + return buf; +}; + +// Helper (used in 2 places) +function buf2binstring(buf, len) { + // use fallback for big arrays to avoid stack overflow + if (len < 65537) { + if ((buf.subarray && STR_APPLY_UIA_OK) || (!buf.subarray && STR_APPLY_OK)) { + return String.fromCharCode.apply(null, utils.shrinkBuf(buf, len)); + } + } + + var result = ''; + for(var i=0; i < len; i++) { + result += String.fromCharCode(buf[i]); + } + return result; +} + + +// Convert byte array to binary string +exports.buf2binstring = function(buf) { + return buf2binstring(buf, buf.length); +}; + + +// Convert binary string (typed, when possible) +exports.binstring2buf = function(str) { + var buf = new utils.Buf8(str.length); + for(var i=0, len=buf.length; i < len; i++) { + buf[i] = str.charCodeAt(i); + } + return buf; +}; + + +// convert array to string +exports.buf2string = function (buf, max) { + var i, out, c, c_len; + var len = max || buf.length; + + // Reserve max possible length (2 words per char) + // NB: by unknown reasons, Array is significantly faster for + // String.fromCharCode.apply than Uint16Array. + var utf16buf = new Array(len*2); + + for (out=0, i=0; i 4) { utf16buf[out++] = 0xfffd; i += c_len-1; continue; } + + // apply mask on first byte + c &= c_len === 2 ? 0x1f : c_len === 3 ? 0x0f : 0x07; + // join the rest + while (c_len > 1 && i < len) { + c = (c << 6) | (buf[i++] & 0x3f); + c_len--; + } + + // terminated by end of string? + if (c_len > 1) { utf16buf[out++] = 0xfffd; continue; } + + if (c < 0x10000) { + utf16buf[out++] = c; + } else { + c -= 0x10000; + utf16buf[out++] = 0xd800 | ((c >> 10) & 0x3ff); + utf16buf[out++] = 0xdc00 | (c & 0x3ff); + } + } + + return buf2binstring(utf16buf, out); +}; + + +// Calculate max possible position in utf8 buffer, +// that will not break sequence. If that's not possible +// - (very small limits) return max size as is. +// +// buf[] - utf8 bytes array +// max - length limit (mandatory); +exports.utf8border = function(buf, max) { + var pos; + + max = max || buf.length; + if (max > buf.length) { max = buf.length; } + + // go back from last position, until start of sequence found + pos = max-1; + while (pos >= 0 && (buf[pos] & 0xC0) === 0x80) { pos--; } + + // Fuckup - very small and broken sequence, + // return max, because we should return something anyway. + if (pos < 0) { return max; } + + // If we came to start of buffer - that means vuffer is too small, + // return max too. + if (pos === 0) { return max; } + + return (pos + _utf8len[buf[pos]] > max) ? pos : max; +}; + +},{"./common":28}],30:[function(_dereq_,module,exports){ +'use strict'; + +// Note: adler32 takes 12% for level 0 and 2% for level 6. +// It doesn't worth to make additional optimizationa as in original. +// Small size is preferable. + +function adler32(adler, buf, len, pos) { + var s1 = (adler & 0xffff) |0 + , s2 = ((adler >>> 16) & 0xffff) |0 + , n = 0; + + while (len !== 0) { + // Set limit ~ twice less than 5552, to keep + // s2 in 31-bits, because we force signed ints. + // in other case %= will fail. + n = len > 2000 ? 2000 : len; + len -= n; + + do { + s1 = (s1 + buf[pos++]) |0; + s2 = (s2 + s1) |0; + } while (--n); + + s1 %= 65521; + s2 %= 65521; + } + + return (s1 | (s2 << 16)) |0; +} + + +module.exports = adler32; +},{}],31:[function(_dereq_,module,exports){ +module.exports = { + + /* Allowed flush values; see deflate() and inflate() below for details */ + Z_NO_FLUSH: 0, + Z_PARTIAL_FLUSH: 1, + Z_SYNC_FLUSH: 2, + Z_FULL_FLUSH: 3, + Z_FINISH: 4, + Z_BLOCK: 5, + Z_TREES: 6, + + /* Return codes for the compression/decompression functions. Negative values + * are errors, positive values are used for special but normal events. + */ + Z_OK: 0, + Z_STREAM_END: 1, + Z_NEED_DICT: 2, + Z_ERRNO: -1, + Z_STREAM_ERROR: -2, + Z_DATA_ERROR: -3, + //Z_MEM_ERROR: -4, + Z_BUF_ERROR: -5, + //Z_VERSION_ERROR: -6, + + /* compression levels */ + Z_NO_COMPRESSION: 0, + Z_BEST_SPEED: 1, + Z_BEST_COMPRESSION: 9, + Z_DEFAULT_COMPRESSION: -1, + + + Z_FILTERED: 1, + Z_HUFFMAN_ONLY: 2, + Z_RLE: 3, + Z_FIXED: 4, + Z_DEFAULT_STRATEGY: 0, + + /* Possible values of the data_type field (though see inflate()) */ + Z_BINARY: 0, + Z_TEXT: 1, + //Z_ASCII: 1, // = Z_TEXT (deprecated) + Z_UNKNOWN: 2, + + /* The deflate compression method */ + Z_DEFLATED: 8 + //Z_NULL: null // Use -1 or null inline, depending on var type +}; +},{}],32:[function(_dereq_,module,exports){ +'use strict'; + +// Note: we can't get significant speed boost here. +// So write code to minimize size - no pregenerated tables +// and array tools dependencies. + + +// Use ordinary array, since untyped makes no boost here +function makeTable() { + var c, table = []; + + for(var n =0; n < 256; n++){ + c = n; + for(var k =0; k < 8; k++){ + c = ((c&1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1)); + } + table[n] = c; + } + + return table; +} + +// Create table on load. Just 255 signed longs. Not a problem. +var crcTable = makeTable(); + + +function crc32(crc, buf, len, pos) { + var t = crcTable + , end = pos + len; + + crc = crc ^ (-1); + + for (var i = pos; i < end; i++ ) { + crc = (crc >>> 8) ^ t[(crc ^ buf[i]) & 0xFF]; + } + + return (crc ^ (-1)); // >>> 0; +} + + +module.exports = crc32; +},{}],33:[function(_dereq_,module,exports){ +'use strict'; + +var utils = _dereq_('../utils/common'); +var trees = _dereq_('./trees'); +var adler32 = _dereq_('./adler32'); +var crc32 = _dereq_('./crc32'); +var msg = _dereq_('./messages'); + +/* Public constants ==========================================================*/ +/* ===========================================================================*/ + + +/* Allowed flush values; see deflate() and inflate() below for details */ +var Z_NO_FLUSH = 0; +var Z_PARTIAL_FLUSH = 1; +//var Z_SYNC_FLUSH = 2; +var Z_FULL_FLUSH = 3; +var Z_FINISH = 4; +var Z_BLOCK = 5; +//var Z_TREES = 6; + + +/* Return codes for the compression/decompression functions. Negative values + * are errors, positive values are used for special but normal events. + */ +var Z_OK = 0; +var Z_STREAM_END = 1; +//var Z_NEED_DICT = 2; +//var Z_ERRNO = -1; +var Z_STREAM_ERROR = -2; +var Z_DATA_ERROR = -3; +//var Z_MEM_ERROR = -4; +var Z_BUF_ERROR = -5; +//var Z_VERSION_ERROR = -6; + + +/* compression levels */ +//var Z_NO_COMPRESSION = 0; +//var Z_BEST_SPEED = 1; +//var Z_BEST_COMPRESSION = 9; +var Z_DEFAULT_COMPRESSION = -1; + + +var Z_FILTERED = 1; +var Z_HUFFMAN_ONLY = 2; +var Z_RLE = 3; +var Z_FIXED = 4; +var Z_DEFAULT_STRATEGY = 0; + +/* Possible values of the data_type field (though see inflate()) */ +//var Z_BINARY = 0; +//var Z_TEXT = 1; +//var Z_ASCII = 1; // = Z_TEXT +var Z_UNKNOWN = 2; + + +/* The deflate compression method */ +var Z_DEFLATED = 8; + +/*============================================================================*/ + + +var MAX_MEM_LEVEL = 9; +/* Maximum value for memLevel in deflateInit2 */ +var MAX_WBITS = 15; +/* 32K LZ77 window */ +var DEF_MEM_LEVEL = 8; + + +var LENGTH_CODES = 29; +/* number of length codes, not counting the special END_BLOCK code */ +var LITERALS = 256; +/* number of literal bytes 0..255 */ +var L_CODES = LITERALS + 1 + LENGTH_CODES; +/* number of Literal or Length codes, including the END_BLOCK code */ +var D_CODES = 30; +/* number of distance codes */ +var BL_CODES = 19; +/* number of codes used to transfer the bit lengths */ +var HEAP_SIZE = 2*L_CODES + 1; +/* maximum heap size */ +var MAX_BITS = 15; +/* All codes must not exceed MAX_BITS bits */ + +var MIN_MATCH = 3; +var MAX_MATCH = 258; +var MIN_LOOKAHEAD = (MAX_MATCH + MIN_MATCH + 1); + +var PRESET_DICT = 0x20; + +var INIT_STATE = 42; +var EXTRA_STATE = 69; +var NAME_STATE = 73; +var COMMENT_STATE = 91; +var HCRC_STATE = 103; +var BUSY_STATE = 113; +var FINISH_STATE = 666; + +var BS_NEED_MORE = 1; /* block not completed, need more input or more output */ +var BS_BLOCK_DONE = 2; /* block flush performed */ +var BS_FINISH_STARTED = 3; /* finish started, need only more output at next deflate */ +var BS_FINISH_DONE = 4; /* finish done, accept no more input or output */ + +var OS_CODE = 0x03; // Unix :) . Don't detect, use this default. + +function err(strm, errorCode) { + strm.msg = msg[errorCode]; + return errorCode; +} + +function rank(f) { + return ((f) << 1) - ((f) > 4 ? 9 : 0); +} + +function zero(buf) { var len = buf.length; while (--len >= 0) { buf[len] = 0; } } + + +/* ========================================================================= + * Flush as much pending output as possible. All deflate() output goes + * through this function so some applications may wish to modify it + * to avoid allocating a large strm->output buffer and copying into it. + * (See also read_buf()). + */ +function flush_pending(strm) { + var s = strm.state; + + //_tr_flush_bits(s); + var len = s.pending; + if (len > strm.avail_out) { + len = strm.avail_out; + } + if (len === 0) { return; } + + utils.arraySet(strm.output, s.pending_buf, s.pending_out, len, strm.next_out); + strm.next_out += len; + s.pending_out += len; + strm.total_out += len; + strm.avail_out -= len; + s.pending -= len; + if (s.pending === 0) { + s.pending_out = 0; + } +} + + +function flush_block_only (s, last) { + trees._tr_flush_block(s, (s.block_start >= 0 ? s.block_start : -1), s.strstart - s.block_start, last); + s.block_start = s.strstart; + flush_pending(s.strm); +} + + +function put_byte(s, b) { + s.pending_buf[s.pending++] = b; +} + + +/* ========================================================================= + * Put a short in the pending buffer. The 16-bit value is put in MSB order. + * IN assertion: the stream state is correct and there is enough room in + * pending_buf. + */ +function putShortMSB(s, b) { +// put_byte(s, (Byte)(b >> 8)); +// put_byte(s, (Byte)(b & 0xff)); + s.pending_buf[s.pending++] = (b >>> 8) & 0xff; + s.pending_buf[s.pending++] = b & 0xff; +} + + +/* =========================================================================== + * Read a new buffer from the current input stream, update the adler32 + * and total number of bytes read. All deflate() input goes through + * this function so some applications may wish to modify it to avoid + * allocating a large strm->input buffer and copying from it. + * (See also flush_pending()). + */ +function read_buf(strm, buf, start, size) { + var len = strm.avail_in; + + if (len > size) { len = size; } + if (len === 0) { return 0; } + + strm.avail_in -= len; + + utils.arraySet(buf, strm.input, strm.next_in, len, start); + if (strm.state.wrap === 1) { + strm.adler = adler32(strm.adler, buf, len, start); + } + + else if (strm.state.wrap === 2) { + strm.adler = crc32(strm.adler, buf, len, start); + } + + strm.next_in += len; + strm.total_in += len; + + return len; +} + + +/* =========================================================================== + * Set match_start to the longest match starting at the given string and + * return its length. Matches shorter or equal to prev_length are discarded, + * in which case the result is equal to prev_length and match_start is + * garbage. + * IN assertions: cur_match is the head of the hash chain for the current + * string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1 + * OUT assertion: the match length is not greater than s->lookahead. + */ +function longest_match(s, cur_match) { + var chain_length = s.max_chain_length; /* max hash chain length */ + var scan = s.strstart; /* current string */ + var match; /* matched string */ + var len; /* length of current match */ + var best_len = s.prev_length; /* best match length so far */ + var nice_match = s.nice_match; /* stop if match long enough */ + var limit = (s.strstart > (s.w_size - MIN_LOOKAHEAD)) ? + s.strstart - (s.w_size - MIN_LOOKAHEAD) : 0/*NIL*/; + + var _win = s.window; // shortcut + + var wmask = s.w_mask; + var prev = s.prev; + + /* Stop when cur_match becomes <= limit. To simplify the code, + * we prevent matches with the string of window index 0. + */ + + var strend = s.strstart + MAX_MATCH; + var scan_end1 = _win[scan + best_len - 1]; + var scan_end = _win[scan + best_len]; + + /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16. + * It is easy to get rid of this optimization if necessary. + */ + // Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever"); + + /* Do not waste too much time if we already have a good match: */ + if (s.prev_length >= s.good_match) { + chain_length >>= 2; + } + /* Do not look for matches beyond the end of the input. This is necessary + * to make deflate deterministic. + */ + if (nice_match > s.lookahead) { nice_match = s.lookahead; } + + // Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); + + do { + // Assert(cur_match < s->strstart, "no future"); + match = cur_match; + + /* Skip to next match if the match length cannot increase + * or if the match length is less than 2. Note that the checks below + * for insufficient lookahead only occur occasionally for performance + * reasons. Therefore uninitialized memory will be accessed, and + * conditional jumps will be made that depend on those values. + * However the length of the match is limited to the lookahead, so + * the output of deflate is not affected by the uninitialized values. + */ + + if (_win[match + best_len] !== scan_end || + _win[match + best_len - 1] !== scan_end1 || + _win[match] !== _win[scan] || + _win[++match] !== _win[scan + 1]) { + continue; + } + + /* The check at best_len-1 can be removed because it will be made + * again later. (This heuristic is not always a win.) + * It is not necessary to compare scan[2] and match[2] since they + * are always equal when the other bytes match, given that + * the hash keys are equal and that HASH_BITS >= 8. + */ + scan += 2; + match++; + // Assert(*scan == *match, "match[2]?"); + + /* We check for insufficient lookahead only every 8th comparison; + * the 256th check will be made at strstart+258. + */ + do { + /*jshint noempty:false*/ + } while (_win[++scan] === _win[++match] && _win[++scan] === _win[++match] && + _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && + _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && + _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && + scan < strend); + + // Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); + + len = MAX_MATCH - (strend - scan); + scan = strend - MAX_MATCH; + + if (len > best_len) { + s.match_start = cur_match; + best_len = len; + if (len >= nice_match) { + break; + } + scan_end1 = _win[scan + best_len - 1]; + scan_end = _win[scan + best_len]; + } + } while ((cur_match = prev[cur_match & wmask]) > limit && --chain_length !== 0); + + if (best_len <= s.lookahead) { + return best_len; + } + return s.lookahead; +} + + +/* =========================================================================== + * Fill the window when the lookahead becomes insufficient. + * Updates strstart and lookahead. + * + * IN assertion: lookahead < MIN_LOOKAHEAD + * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD + * At least one byte has been read, or avail_in == 0; reads are + * performed for at least two bytes (required for the zip translate_eol + * option -- not supported here). + */ +function fill_window(s) { + var _w_size = s.w_size; + var p, n, m, more, str; + + //Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead"); + + do { + more = s.window_size - s.lookahead - s.strstart; + + // JS ints have 32 bit, block below not needed + /* Deal with !@#$% 64K limit: */ + //if (sizeof(int) <= 2) { + // if (more == 0 && s->strstart == 0 && s->lookahead == 0) { + // more = wsize; + // + // } else if (more == (unsigned)(-1)) { + // /* Very unlikely, but possible on 16 bit machine if + // * strstart == 0 && lookahead == 1 (input done a byte at time) + // */ + // more--; + // } + //} + + + /* If the window is almost full and there is insufficient lookahead, + * move the upper half to the lower one to make room in the upper half. + */ + if (s.strstart >= _w_size + (_w_size - MIN_LOOKAHEAD)) { + + utils.arraySet(s.window, s.window, _w_size, _w_size, 0); + s.match_start -= _w_size; + s.strstart -= _w_size; + /* we now have strstart >= MAX_DIST */ + s.block_start -= _w_size; + + /* Slide the hash table (could be avoided with 32 bit values + at the expense of memory usage). We slide even when level == 0 + to keep the hash table consistent if we switch back to level > 0 + later. (Using level 0 permanently is not an optimal usage of + zlib, so we don't care about this pathological case.) + */ + + n = s.hash_size; + p = n; + do { + m = s.head[--p]; + s.head[p] = (m >= _w_size ? m - _w_size : 0); + } while (--n); + + n = _w_size; + p = n; + do { + m = s.prev[--p]; + s.prev[p] = (m >= _w_size ? m - _w_size : 0); + /* If n is not on any hash chain, prev[n] is garbage but + * its value will never be used. + */ + } while (--n); + + more += _w_size; + } + if (s.strm.avail_in === 0) { + break; + } + + /* If there was no sliding: + * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 && + * more == window_size - lookahead - strstart + * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1) + * => more >= window_size - 2*WSIZE + 2 + * In the BIG_MEM or MMAP case (not yet supported), + * window_size == input_size + MIN_LOOKAHEAD && + * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD. + * Otherwise, window_size == 2*WSIZE so more >= 2. + * If there was sliding, more >= WSIZE. So in all cases, more >= 2. + */ + //Assert(more >= 2, "more < 2"); + n = read_buf(s.strm, s.window, s.strstart + s.lookahead, more); + s.lookahead += n; + + /* Initialize the hash value now that we have some input: */ + if (s.lookahead + s.insert >= MIN_MATCH) { + str = s.strstart - s.insert; + s.ins_h = s.window[str]; + + /* UPDATE_HASH(s, s->ins_h, s->window[str + 1]); */ + s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[str + 1]) & s.hash_mask; +//#if MIN_MATCH != 3 +// Call update_hash() MIN_MATCH-3 more times +//#endif + while (s.insert) { + /* UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); */ + s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[str + MIN_MATCH-1]) & s.hash_mask; + + s.prev[str & s.w_mask] = s.head[s.ins_h]; + s.head[s.ins_h] = str; + str++; + s.insert--; + if (s.lookahead + s.insert < MIN_MATCH) { + break; + } + } + } + /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage, + * but this is not important since only literal bytes will be emitted. + */ + + } while (s.lookahead < MIN_LOOKAHEAD && s.strm.avail_in !== 0); + + /* If the WIN_INIT bytes after the end of the current data have never been + * written, then zero those bytes in order to avoid memory check reports of + * the use of uninitialized (or uninitialised as Julian writes) bytes by + * the longest match routines. Update the high water mark for the next + * time through here. WIN_INIT is set to MAX_MATCH since the longest match + * routines allow scanning to strstart + MAX_MATCH, ignoring lookahead. + */ +// if (s.high_water < s.window_size) { +// var curr = s.strstart + s.lookahead; +// var init = 0; +// +// if (s.high_water < curr) { +// /* Previous high water mark below current data -- zero WIN_INIT +// * bytes or up to end of window, whichever is less. +// */ +// init = s.window_size - curr; +// if (init > WIN_INIT) +// init = WIN_INIT; +// zmemzero(s->window + curr, (unsigned)init); +// s->high_water = curr + init; +// } +// else if (s->high_water < (ulg)curr + WIN_INIT) { +// /* High water mark at or above current data, but below current data +// * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up +// * to end of window, whichever is less. +// */ +// init = (ulg)curr + WIN_INIT - s->high_water; +// if (init > s->window_size - s->high_water) +// init = s->window_size - s->high_water; +// zmemzero(s->window + s->high_water, (unsigned)init); +// s->high_water += init; +// } +// } +// +// Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD, +// "not enough room for search"); +} + +/* =========================================================================== + * Copy without compression as much as possible from the input stream, return + * the current block state. + * This function does not insert new strings in the dictionary since + * uncompressible data is probably not useful. This function is used + * only for the level=0 compression option. + * NOTE: this function should be optimized to avoid extra copying from + * window to pending_buf. + */ +function deflate_stored(s, flush) { + /* Stored blocks are limited to 0xffff bytes, pending_buf is limited + * to pending_buf_size, and each stored block has a 5 byte header: + */ + var max_block_size = 0xffff; + + if (max_block_size > s.pending_buf_size - 5) { + max_block_size = s.pending_buf_size - 5; + } + + /* Copy as much as possible from input to output: */ + for (;;) { + /* Fill the window as much as possible: */ + if (s.lookahead <= 1) { + + //Assert(s->strstart < s->w_size+MAX_DIST(s) || + // s->block_start >= (long)s->w_size, "slide too late"); +// if (!(s.strstart < s.w_size + (s.w_size - MIN_LOOKAHEAD) || +// s.block_start >= s.w_size)) { +// throw new Error("slide too late"); +// } + + fill_window(s); + if (s.lookahead === 0 && flush === Z_NO_FLUSH) { + return BS_NEED_MORE; + } + + if (s.lookahead === 0) { + break; + } + /* flush the current block */ + } + //Assert(s->block_start >= 0L, "block gone"); +// if (s.block_start < 0) throw new Error("block gone"); + + s.strstart += s.lookahead; + s.lookahead = 0; + + /* Emit a stored block if pending_buf will be full: */ + var max_start = s.block_start + max_block_size; + + if (s.strstart === 0 || s.strstart >= max_start) { + /* strstart == 0 is possible when wraparound on 16-bit machine */ + s.lookahead = s.strstart - max_start; + s.strstart = max_start; + /*** FLUSH_BLOCK(s, 0); ***/ + flush_block_only(s, false); + if (s.strm.avail_out === 0) { + return BS_NEED_MORE; + } + /***/ + + + } + /* Flush if we may have to slide, otherwise block_start may become + * negative and the data will be gone: + */ + if (s.strstart - s.block_start >= (s.w_size - MIN_LOOKAHEAD)) { + /*** FLUSH_BLOCK(s, 0); ***/ + flush_block_only(s, false); + if (s.strm.avail_out === 0) { + return BS_NEED_MORE; + } + /***/ + } + } + + s.insert = 0; + + if (flush === Z_FINISH) { + /*** FLUSH_BLOCK(s, 1); ***/ + flush_block_only(s, true); + if (s.strm.avail_out === 0) { + return BS_FINISH_STARTED; + } + /***/ + return BS_FINISH_DONE; + } + + if (s.strstart > s.block_start) { + /*** FLUSH_BLOCK(s, 0); ***/ + flush_block_only(s, false); + if (s.strm.avail_out === 0) { + return BS_NEED_MORE; + } + /***/ + } + + return BS_NEED_MORE; +} + +/* =========================================================================== + * Compress as much as possible from the input stream, return the current + * block state. + * This function does not perform lazy evaluation of matches and inserts + * new strings in the dictionary only for unmatched strings or for short + * matches. It is used only for the fast compression options. + */ +function deflate_fast(s, flush) { + var hash_head; /* head of the hash chain */ + var bflush; /* set if current block must be flushed */ + + for (;;) { + /* Make sure that we always have enough lookahead, except + * at the end of the input file. We need MAX_MATCH bytes + * for the next match, plus MIN_MATCH bytes to insert the + * string following the next match. + */ + if (s.lookahead < MIN_LOOKAHEAD) { + fill_window(s); + if (s.lookahead < MIN_LOOKAHEAD && flush === Z_NO_FLUSH) { + return BS_NEED_MORE; + } + if (s.lookahead === 0) { + break; /* flush the current block */ + } + } + + /* Insert the string window[strstart .. strstart+2] in the + * dictionary, and set hash_head to the head of the hash chain: + */ + hash_head = 0/*NIL*/; + if (s.lookahead >= MIN_MATCH) { + /*** INSERT_STRING(s, s.strstart, hash_head); ***/ + s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask; + hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h]; + s.head[s.ins_h] = s.strstart; + /***/ + } + + /* Find the longest match, discarding those <= prev_length. + * At this point we have always match_length < MIN_MATCH + */ + if (hash_head !== 0/*NIL*/ && ((s.strstart - hash_head) <= (s.w_size - MIN_LOOKAHEAD))) { + /* To simplify the code, we prevent matches with the string + * of window index 0 (in particular we have to avoid a match + * of the string with itself at the start of the input file). + */ + s.match_length = longest_match(s, hash_head); + /* longest_match() sets match_start */ + } + if (s.match_length >= MIN_MATCH) { + // check_match(s, s.strstart, s.match_start, s.match_length); // for debug only + + /*** _tr_tally_dist(s, s.strstart - s.match_start, + s.match_length - MIN_MATCH, bflush); ***/ + bflush = trees._tr_tally(s, s.strstart - s.match_start, s.match_length - MIN_MATCH); + + s.lookahead -= s.match_length; + + /* Insert new strings in the hash table only if the match length + * is not too large. This saves time but degrades compression. + */ + if (s.match_length <= s.max_lazy_match/*max_insert_length*/ && s.lookahead >= MIN_MATCH) { + s.match_length--; /* string at strstart already in table */ + do { + s.strstart++; + /*** INSERT_STRING(s, s.strstart, hash_head); ***/ + s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask; + hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h]; + s.head[s.ins_h] = s.strstart; + /***/ + /* strstart never exceeds WSIZE-MAX_MATCH, so there are + * always MIN_MATCH bytes ahead. + */ + } while (--s.match_length !== 0); + s.strstart++; + } else + { + s.strstart += s.match_length; + s.match_length = 0; + s.ins_h = s.window[s.strstart]; + /* UPDATE_HASH(s, s.ins_h, s.window[s.strstart+1]); */ + s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + 1]) & s.hash_mask; + +//#if MIN_MATCH != 3 +// Call UPDATE_HASH() MIN_MATCH-3 more times +//#endif + /* If lookahead < MIN_MATCH, ins_h is garbage, but it does not + * matter since it will be recomputed at next deflate call. + */ + } + } else { + /* No match, output a literal byte */ + //Tracevv((stderr,"%c", s.window[s.strstart])); + /*** _tr_tally_lit(s, s.window[s.strstart], bflush); ***/ + bflush = trees._tr_tally(s, 0, s.window[s.strstart]); + + s.lookahead--; + s.strstart++; + } + if (bflush) { + /*** FLUSH_BLOCK(s, 0); ***/ + flush_block_only(s, false); + if (s.strm.avail_out === 0) { + return BS_NEED_MORE; + } + /***/ + } + } + s.insert = ((s.strstart < (MIN_MATCH-1)) ? s.strstart : MIN_MATCH-1); + if (flush === Z_FINISH) { + /*** FLUSH_BLOCK(s, 1); ***/ + flush_block_only(s, true); + if (s.strm.avail_out === 0) { + return BS_FINISH_STARTED; + } + /***/ + return BS_FINISH_DONE; + } + if (s.last_lit) { + /*** FLUSH_BLOCK(s, 0); ***/ + flush_block_only(s, false); + if (s.strm.avail_out === 0) { + return BS_NEED_MORE; + } + /***/ + } + return BS_BLOCK_DONE; +} + +/* =========================================================================== + * Same as above, but achieves better compression. We use a lazy + * evaluation for matches: a match is finally adopted only if there is + * no better match at the next window position. + */ +function deflate_slow(s, flush) { + var hash_head; /* head of hash chain */ + var bflush; /* set if current block must be flushed */ + + var max_insert; + + /* Process the input block. */ + for (;;) { + /* Make sure that we always have enough lookahead, except + * at the end of the input file. We need MAX_MATCH bytes + * for the next match, plus MIN_MATCH bytes to insert the + * string following the next match. + */ + if (s.lookahead < MIN_LOOKAHEAD) { + fill_window(s); + if (s.lookahead < MIN_LOOKAHEAD && flush === Z_NO_FLUSH) { + return BS_NEED_MORE; + } + if (s.lookahead === 0) { break; } /* flush the current block */ + } + + /* Insert the string window[strstart .. strstart+2] in the + * dictionary, and set hash_head to the head of the hash chain: + */ + hash_head = 0/*NIL*/; + if (s.lookahead >= MIN_MATCH) { + /*** INSERT_STRING(s, s.strstart, hash_head); ***/ + s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask; + hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h]; + s.head[s.ins_h] = s.strstart; + /***/ + } + + /* Find the longest match, discarding those <= prev_length. + */ + s.prev_length = s.match_length; + s.prev_match = s.match_start; + s.match_length = MIN_MATCH-1; + + if (hash_head !== 0/*NIL*/ && s.prev_length < s.max_lazy_match && + s.strstart - hash_head <= (s.w_size-MIN_LOOKAHEAD)/*MAX_DIST(s)*/) { + /* To simplify the code, we prevent matches with the string + * of window index 0 (in particular we have to avoid a match + * of the string with itself at the start of the input file). + */ + s.match_length = longest_match(s, hash_head); + /* longest_match() sets match_start */ + + if (s.match_length <= 5 && + (s.strategy === Z_FILTERED || (s.match_length === MIN_MATCH && s.strstart - s.match_start > 4096/*TOO_FAR*/))) { + + /* If prev_match is also MIN_MATCH, match_start is garbage + * but we will ignore the current match anyway. + */ + s.match_length = MIN_MATCH-1; + } + } + /* If there was a match at the previous step and the current + * match is not better, output the previous match: + */ + if (s.prev_length >= MIN_MATCH && s.match_length <= s.prev_length) { + max_insert = s.strstart + s.lookahead - MIN_MATCH; + /* Do not insert strings in hash table beyond this. */ + + //check_match(s, s.strstart-1, s.prev_match, s.prev_length); + + /***_tr_tally_dist(s, s.strstart - 1 - s.prev_match, + s.prev_length - MIN_MATCH, bflush);***/ + bflush = trees._tr_tally(s, s.strstart - 1- s.prev_match, s.prev_length - MIN_MATCH); + /* Insert in hash table all strings up to the end of the match. + * strstart-1 and strstart are already inserted. If there is not + * enough lookahead, the last two strings are not inserted in + * the hash table. + */ + s.lookahead -= s.prev_length-1; + s.prev_length -= 2; + do { + if (++s.strstart <= max_insert) { + /*** INSERT_STRING(s, s.strstart, hash_head); ***/ + s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask; + hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h]; + s.head[s.ins_h] = s.strstart; + /***/ + } + } while (--s.prev_length !== 0); + s.match_available = 0; + s.match_length = MIN_MATCH-1; + s.strstart++; + + if (bflush) { + /*** FLUSH_BLOCK(s, 0); ***/ + flush_block_only(s, false); + if (s.strm.avail_out === 0) { + return BS_NEED_MORE; + } + /***/ + } + + } else if (s.match_available) { + /* If there was no match at the previous position, output a + * single literal. If there was a match but the current match + * is longer, truncate the previous match to a single literal. + */ + //Tracevv((stderr,"%c", s->window[s->strstart-1])); + /*** _tr_tally_lit(s, s.window[s.strstart-1], bflush); ***/ + bflush = trees._tr_tally(s, 0, s.window[s.strstart-1]); + + if (bflush) { + /*** FLUSH_BLOCK_ONLY(s, 0) ***/ + flush_block_only(s, false); + /***/ + } + s.strstart++; + s.lookahead--; + if (s.strm.avail_out === 0) { + return BS_NEED_MORE; + } + } else { + /* There is no previous match to compare with, wait for + * the next step to decide. + */ + s.match_available = 1; + s.strstart++; + s.lookahead--; + } + } + //Assert (flush != Z_NO_FLUSH, "no flush?"); + if (s.match_available) { + //Tracevv((stderr,"%c", s->window[s->strstart-1])); + /*** _tr_tally_lit(s, s.window[s.strstart-1], bflush); ***/ + bflush = trees._tr_tally(s, 0, s.window[s.strstart-1]); + + s.match_available = 0; + } + s.insert = s.strstart < MIN_MATCH-1 ? s.strstart : MIN_MATCH-1; + if (flush === Z_FINISH) { + /*** FLUSH_BLOCK(s, 1); ***/ + flush_block_only(s, true); + if (s.strm.avail_out === 0) { + return BS_FINISH_STARTED; + } + /***/ + return BS_FINISH_DONE; + } + if (s.last_lit) { + /*** FLUSH_BLOCK(s, 0); ***/ + flush_block_only(s, false); + if (s.strm.avail_out === 0) { + return BS_NEED_MORE; + } + /***/ + } + + return BS_BLOCK_DONE; +} + + +/* =========================================================================== + * For Z_RLE, simply look for runs of bytes, generate matches only of distance + * one. Do not maintain a hash table. (It will be regenerated if this run of + * deflate switches away from Z_RLE.) + */ +function deflate_rle(s, flush) { + var bflush; /* set if current block must be flushed */ + var prev; /* byte at distance one to match */ + var scan, strend; /* scan goes up to strend for length of run */ + + var _win = s.window; + + for (;;) { + /* Make sure that we always have enough lookahead, except + * at the end of the input file. We need MAX_MATCH bytes + * for the longest run, plus one for the unrolled loop. + */ + if (s.lookahead <= MAX_MATCH) { + fill_window(s); + if (s.lookahead <= MAX_MATCH && flush === Z_NO_FLUSH) { + return BS_NEED_MORE; + } + if (s.lookahead === 0) { break; } /* flush the current block */ + } + + /* See how many times the previous byte repeats */ + s.match_length = 0; + if (s.lookahead >= MIN_MATCH && s.strstart > 0) { + scan = s.strstart - 1; + prev = _win[scan]; + if (prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan]) { + strend = s.strstart + MAX_MATCH; + do { + /*jshint noempty:false*/ + } while (prev === _win[++scan] && prev === _win[++scan] && + prev === _win[++scan] && prev === _win[++scan] && + prev === _win[++scan] && prev === _win[++scan] && + prev === _win[++scan] && prev === _win[++scan] && + scan < strend); + s.match_length = MAX_MATCH - (strend - scan); + if (s.match_length > s.lookahead) { + s.match_length = s.lookahead; + } + } + //Assert(scan <= s->window+(uInt)(s->window_size-1), "wild scan"); + } + + /* Emit match if have run of MIN_MATCH or longer, else emit literal */ + if (s.match_length >= MIN_MATCH) { + //check_match(s, s.strstart, s.strstart - 1, s.match_length); + + /*** _tr_tally_dist(s, 1, s.match_length - MIN_MATCH, bflush); ***/ + bflush = trees._tr_tally(s, 1, s.match_length - MIN_MATCH); + + s.lookahead -= s.match_length; + s.strstart += s.match_length; + s.match_length = 0; + } else { + /* No match, output a literal byte */ + //Tracevv((stderr,"%c", s->window[s->strstart])); + /*** _tr_tally_lit(s, s.window[s.strstart], bflush); ***/ + bflush = trees._tr_tally(s, 0, s.window[s.strstart]); + + s.lookahead--; + s.strstart++; + } + if (bflush) { + /*** FLUSH_BLOCK(s, 0); ***/ + flush_block_only(s, false); + if (s.strm.avail_out === 0) { + return BS_NEED_MORE; + } + /***/ + } + } + s.insert = 0; + if (flush === Z_FINISH) { + /*** FLUSH_BLOCK(s, 1); ***/ + flush_block_only(s, true); + if (s.strm.avail_out === 0) { + return BS_FINISH_STARTED; + } + /***/ + return BS_FINISH_DONE; + } + if (s.last_lit) { + /*** FLUSH_BLOCK(s, 0); ***/ + flush_block_only(s, false); + if (s.strm.avail_out === 0) { + return BS_NEED_MORE; + } + /***/ + } + return BS_BLOCK_DONE; +} + +/* =========================================================================== + * For Z_HUFFMAN_ONLY, do not look for matches. Do not maintain a hash table. + * (It will be regenerated if this run of deflate switches away from Huffman.) + */ +function deflate_huff(s, flush) { + var bflush; /* set if current block must be flushed */ + + for (;;) { + /* Make sure that we have a literal to write. */ + if (s.lookahead === 0) { + fill_window(s); + if (s.lookahead === 0) { + if (flush === Z_NO_FLUSH) { + return BS_NEED_MORE; + } + break; /* flush the current block */ + } + } + + /* Output a literal byte */ + s.match_length = 0; + //Tracevv((stderr,"%c", s->window[s->strstart])); + /*** _tr_tally_lit(s, s.window[s.strstart], bflush); ***/ + bflush = trees._tr_tally(s, 0, s.window[s.strstart]); + s.lookahead--; + s.strstart++; + if (bflush) { + /*** FLUSH_BLOCK(s, 0); ***/ + flush_block_only(s, false); + if (s.strm.avail_out === 0) { + return BS_NEED_MORE; + } + /***/ + } + } + s.insert = 0; + if (flush === Z_FINISH) { + /*** FLUSH_BLOCK(s, 1); ***/ + flush_block_only(s, true); + if (s.strm.avail_out === 0) { + return BS_FINISH_STARTED; + } + /***/ + return BS_FINISH_DONE; + } + if (s.last_lit) { + /*** FLUSH_BLOCK(s, 0); ***/ + flush_block_only(s, false); + if (s.strm.avail_out === 0) { + return BS_NEED_MORE; + } + /***/ + } + return BS_BLOCK_DONE; +} + +/* Values for max_lazy_match, good_match and max_chain_length, depending on + * the desired pack level (0..9). The values given below have been tuned to + * exclude worst case performance for pathological files. Better values may be + * found for specific files. + */ +var Config = function (good_length, max_lazy, nice_length, max_chain, func) { + this.good_length = good_length; + this.max_lazy = max_lazy; + this.nice_length = nice_length; + this.max_chain = max_chain; + this.func = func; +}; + +var configuration_table; + +configuration_table = [ + /* good lazy nice chain */ + new Config(0, 0, 0, 0, deflate_stored), /* 0 store only */ + new Config(4, 4, 8, 4, deflate_fast), /* 1 max speed, no lazy matches */ + new Config(4, 5, 16, 8, deflate_fast), /* 2 */ + new Config(4, 6, 32, 32, deflate_fast), /* 3 */ + + new Config(4, 4, 16, 16, deflate_slow), /* 4 lazy matches */ + new Config(8, 16, 32, 32, deflate_slow), /* 5 */ + new Config(8, 16, 128, 128, deflate_slow), /* 6 */ + new Config(8, 32, 128, 256, deflate_slow), /* 7 */ + new Config(32, 128, 258, 1024, deflate_slow), /* 8 */ + new Config(32, 258, 258, 4096, deflate_slow) /* 9 max compression */ +]; + + +/* =========================================================================== + * Initialize the "longest match" routines for a new zlib stream + */ +function lm_init(s) { + s.window_size = 2 * s.w_size; + + /*** CLEAR_HASH(s); ***/ + zero(s.head); // Fill with NIL (= 0); + + /* Set the default configuration parameters: + */ + s.max_lazy_match = configuration_table[s.level].max_lazy; + s.good_match = configuration_table[s.level].good_length; + s.nice_match = configuration_table[s.level].nice_length; + s.max_chain_length = configuration_table[s.level].max_chain; + + s.strstart = 0; + s.block_start = 0; + s.lookahead = 0; + s.insert = 0; + s.match_length = s.prev_length = MIN_MATCH - 1; + s.match_available = 0; + s.ins_h = 0; +} + + +function DeflateState() { + this.strm = null; /* pointer back to this zlib stream */ + this.status = 0; /* as the name implies */ + this.pending_buf = null; /* output still pending */ + this.pending_buf_size = 0; /* size of pending_buf */ + this.pending_out = 0; /* next pending byte to output to the stream */ + this.pending = 0; /* nb of bytes in the pending buffer */ + this.wrap = 0; /* bit 0 true for zlib, bit 1 true for gzip */ + this.gzhead = null; /* gzip header information to write */ + this.gzindex = 0; /* where in extra, name, or comment */ + this.method = Z_DEFLATED; /* can only be DEFLATED */ + this.last_flush = -1; /* value of flush param for previous deflate call */ + + this.w_size = 0; /* LZ77 window size (32K by default) */ + this.w_bits = 0; /* log2(w_size) (8..16) */ + this.w_mask = 0; /* w_size - 1 */ + + this.window = null; + /* Sliding window. Input bytes are read into the second half of the window, + * and move to the first half later to keep a dictionary of at least wSize + * bytes. With this organization, matches are limited to a distance of + * wSize-MAX_MATCH bytes, but this ensures that IO is always + * performed with a length multiple of the block size. + */ + + this.window_size = 0; + /* Actual size of window: 2*wSize, except when the user input buffer + * is directly used as sliding window. + */ + + this.prev = null; + /* Link to older string with same hash index. To limit the size of this + * array to 64K, this link is maintained only for the last 32K strings. + * An index in this array is thus a window index modulo 32K. + */ + + this.head = null; /* Heads of the hash chains or NIL. */ + + this.ins_h = 0; /* hash index of string to be inserted */ + this.hash_size = 0; /* number of elements in hash table */ + this.hash_bits = 0; /* log2(hash_size) */ + this.hash_mask = 0; /* hash_size-1 */ + + this.hash_shift = 0; + /* Number of bits by which ins_h must be shifted at each input + * step. It must be such that after MIN_MATCH steps, the oldest + * byte no longer takes part in the hash key, that is: + * hash_shift * MIN_MATCH >= hash_bits + */ + + this.block_start = 0; + /* Window position at the beginning of the current output block. Gets + * negative when the window is moved backwards. + */ + + this.match_length = 0; /* length of best match */ + this.prev_match = 0; /* previous match */ + this.match_available = 0; /* set if previous match exists */ + this.strstart = 0; /* start of string to insert */ + this.match_start = 0; /* start of matching string */ + this.lookahead = 0; /* number of valid bytes ahead in window */ + + this.prev_length = 0; + /* Length of the best match at previous step. Matches not greater than this + * are discarded. This is used in the lazy match evaluation. + */ + + this.max_chain_length = 0; + /* To speed up deflation, hash chains are never searched beyond this + * length. A higher limit improves compression ratio but degrades the + * speed. + */ + + this.max_lazy_match = 0; + /* Attempt to find a better match only when the current match is strictly + * smaller than this value. This mechanism is used only for compression + * levels >= 4. + */ + // That's alias to max_lazy_match, don't use directly + //this.max_insert_length = 0; + /* Insert new strings in the hash table only if the match length is not + * greater than this length. This saves time but degrades compression. + * max_insert_length is used only for compression levels <= 3. + */ + + this.level = 0; /* compression level (1..9) */ + this.strategy = 0; /* favor or force Huffman coding*/ + + this.good_match = 0; + /* Use a faster search when the previous match is longer than this */ + + this.nice_match = 0; /* Stop searching when current match exceeds this */ + + /* used by trees.c: */ + + /* Didn't use ct_data typedef below to suppress compiler warning */ + + // struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */ + // struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */ + // struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */ + + // Use flat array of DOUBLE size, with interleaved fata, + // because JS does not support effective + this.dyn_ltree = new utils.Buf16(HEAP_SIZE * 2); + this.dyn_dtree = new utils.Buf16((2*D_CODES+1) * 2); + this.bl_tree = new utils.Buf16((2*BL_CODES+1) * 2); + zero(this.dyn_ltree); + zero(this.dyn_dtree); + zero(this.bl_tree); + + this.l_desc = null; /* desc. for literal tree */ + this.d_desc = null; /* desc. for distance tree */ + this.bl_desc = null; /* desc. for bit length tree */ + + //ush bl_count[MAX_BITS+1]; + this.bl_count = new utils.Buf16(MAX_BITS+1); + /* number of codes at each bit length for an optimal tree */ + + //int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */ + this.heap = new utils.Buf16(2*L_CODES+1); /* heap used to build the Huffman trees */ + zero(this.heap); + + this.heap_len = 0; /* number of elements in the heap */ + this.heap_max = 0; /* element of largest frequency */ + /* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used. + * The same heap array is used to build all trees. + */ + + this.depth = new utils.Buf16(2*L_CODES+1); //uch depth[2*L_CODES+1]; + zero(this.depth); + /* Depth of each subtree used as tie breaker for trees of equal frequency + */ + + this.l_buf = 0; /* buffer index for literals or lengths */ + + this.lit_bufsize = 0; + /* Size of match buffer for literals/lengths. There are 4 reasons for + * limiting lit_bufsize to 64K: + * - frequencies can be kept in 16 bit counters + * - if compression is not successful for the first block, all input + * data is still in the window so we can still emit a stored block even + * when input comes from standard input. (This can also be done for + * all blocks if lit_bufsize is not greater than 32K.) + * - if compression is not successful for a file smaller than 64K, we can + * even emit a stored file instead of a stored block (saving 5 bytes). + * This is applicable only for zip (not gzip or zlib). + * - creating new Huffman trees less frequently may not provide fast + * adaptation to changes in the input data statistics. (Take for + * example a binary file with poorly compressible code followed by + * a highly compressible string table.) Smaller buffer sizes give + * fast adaptation but have of course the overhead of transmitting + * trees more frequently. + * - I can't count above 4 + */ + + this.last_lit = 0; /* running index in l_buf */ + + this.d_buf = 0; + /* Buffer index for distances. To simplify the code, d_buf and l_buf have + * the same number of elements. To use different lengths, an extra flag + * array would be necessary. + */ + + this.opt_len = 0; /* bit length of current block with optimal trees */ + this.static_len = 0; /* bit length of current block with static trees */ + this.matches = 0; /* number of string matches in current block */ + this.insert = 0; /* bytes at end of window left to insert */ + + + this.bi_buf = 0; + /* Output buffer. bits are inserted starting at the bottom (least + * significant bits). + */ + this.bi_valid = 0; + /* Number of valid bits in bi_buf. All bits above the last valid bit + * are always zero. + */ + + // Used for window memory init. We safely ignore it for JS. That makes + // sense only for pointers and memory check tools. + //this.high_water = 0; + /* High water mark offset in window for initialized bytes -- bytes above + * this are set to zero in order to avoid memory check warnings when + * longest match routines access bytes past the input. This is then + * updated to the new high water mark. + */ +} + + +function deflateResetKeep(strm) { + var s; + + if (!strm || !strm.state) { + return err(strm, Z_STREAM_ERROR); + } + + strm.total_in = strm.total_out = 0; + strm.data_type = Z_UNKNOWN; + + s = strm.state; + s.pending = 0; + s.pending_out = 0; + + if (s.wrap < 0) { + s.wrap = -s.wrap; + /* was made negative by deflate(..., Z_FINISH); */ + } + s.status = (s.wrap ? INIT_STATE : BUSY_STATE); + strm.adler = (s.wrap === 2) ? + 0 // crc32(0, Z_NULL, 0) + : + 1; // adler32(0, Z_NULL, 0) + s.last_flush = Z_NO_FLUSH; + trees._tr_init(s); + return Z_OK; +} + + +function deflateReset(strm) { + var ret = deflateResetKeep(strm); + if (ret === Z_OK) { + lm_init(strm.state); + } + return ret; +} + + +function deflateSetHeader(strm, head) { + if (!strm || !strm.state) { return Z_STREAM_ERROR; } + if (strm.state.wrap !== 2) { return Z_STREAM_ERROR; } + strm.state.gzhead = head; + return Z_OK; +} + + +function deflateInit2(strm, level, method, windowBits, memLevel, strategy) { + if (!strm) { // === Z_NULL + return Z_STREAM_ERROR; + } + var wrap = 1; + + if (level === Z_DEFAULT_COMPRESSION) { + level = 6; + } + + if (windowBits < 0) { /* suppress zlib wrapper */ + wrap = 0; + windowBits = -windowBits; + } + + else if (windowBits > 15) { + wrap = 2; /* write gzip wrapper instead */ + windowBits -= 16; + } + + + if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method !== Z_DEFLATED || + windowBits < 8 || windowBits > 15 || level < 0 || level > 9 || + strategy < 0 || strategy > Z_FIXED) { + return err(strm, Z_STREAM_ERROR); + } + + + if (windowBits === 8) { + windowBits = 9; + } + /* until 256-byte window bug fixed */ + + var s = new DeflateState(); + + strm.state = s; + s.strm = strm; + + s.wrap = wrap; + s.gzhead = null; + s.w_bits = windowBits; + s.w_size = 1 << s.w_bits; + s.w_mask = s.w_size - 1; + + s.hash_bits = memLevel + 7; + s.hash_size = 1 << s.hash_bits; + s.hash_mask = s.hash_size - 1; + s.hash_shift = ~~((s.hash_bits + MIN_MATCH - 1) / MIN_MATCH); + + s.window = new utils.Buf8(s.w_size * 2); + s.head = new utils.Buf16(s.hash_size); + s.prev = new utils.Buf16(s.w_size); + + // Don't need mem init magic for JS. + //s.high_water = 0; /* nothing written to s->window yet */ + + s.lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */ + + s.pending_buf_size = s.lit_bufsize * 4; + s.pending_buf = new utils.Buf8(s.pending_buf_size); + + s.d_buf = s.lit_bufsize >> 1; + s.l_buf = (1 + 2) * s.lit_bufsize; + + s.level = level; + s.strategy = strategy; + s.method = method; + + return deflateReset(strm); +} + +function deflateInit(strm, level) { + return deflateInit2(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY); +} + + +function deflate(strm, flush) { + var old_flush, s; + var beg, val; // for gzip header write only + + if (!strm || !strm.state || + flush > Z_BLOCK || flush < 0) { + return strm ? err(strm, Z_STREAM_ERROR) : Z_STREAM_ERROR; + } + + s = strm.state; + + if (!strm.output || + (!strm.input && strm.avail_in !== 0) || + (s.status === FINISH_STATE && flush !== Z_FINISH)) { + return err(strm, (strm.avail_out === 0) ? Z_BUF_ERROR : Z_STREAM_ERROR); + } + + s.strm = strm; /* just in case */ + old_flush = s.last_flush; + s.last_flush = flush; + + /* Write the header */ + if (s.status === INIT_STATE) { + + if (s.wrap === 2) { // GZIP header + strm.adler = 0; //crc32(0L, Z_NULL, 0); + put_byte(s, 31); + put_byte(s, 139); + put_byte(s, 8); + if (!s.gzhead) { // s->gzhead == Z_NULL + put_byte(s, 0); + put_byte(s, 0); + put_byte(s, 0); + put_byte(s, 0); + put_byte(s, 0); + put_byte(s, s.level === 9 ? 2 : + (s.strategy >= Z_HUFFMAN_ONLY || s.level < 2 ? + 4 : 0)); + put_byte(s, OS_CODE); + s.status = BUSY_STATE; + } + else { + put_byte(s, (s.gzhead.text ? 1 : 0) + + (s.gzhead.hcrc ? 2 : 0) + + (!s.gzhead.extra ? 0 : 4) + + (!s.gzhead.name ? 0 : 8) + + (!s.gzhead.comment ? 0 : 16) + ); + put_byte(s, s.gzhead.time & 0xff); + put_byte(s, (s.gzhead.time >> 8) & 0xff); + put_byte(s, (s.gzhead.time >> 16) & 0xff); + put_byte(s, (s.gzhead.time >> 24) & 0xff); + put_byte(s, s.level === 9 ? 2 : + (s.strategy >= Z_HUFFMAN_ONLY || s.level < 2 ? + 4 : 0)); + put_byte(s, s.gzhead.os & 0xff); + if (s.gzhead.extra && s.gzhead.extra.length) { + put_byte(s, s.gzhead.extra.length & 0xff); + put_byte(s, (s.gzhead.extra.length >> 8) & 0xff); + } + if (s.gzhead.hcrc) { + strm.adler = crc32(strm.adler, s.pending_buf, s.pending, 0); + } + s.gzindex = 0; + s.status = EXTRA_STATE; + } + } + else // DEFLATE header + { + var header = (Z_DEFLATED + ((s.w_bits - 8) << 4)) << 8; + var level_flags = -1; + + if (s.strategy >= Z_HUFFMAN_ONLY || s.level < 2) { + level_flags = 0; + } else if (s.level < 6) { + level_flags = 1; + } else if (s.level === 6) { + level_flags = 2; + } else { + level_flags = 3; + } + header |= (level_flags << 6); + if (s.strstart !== 0) { header |= PRESET_DICT; } + header += 31 - (header % 31); + + s.status = BUSY_STATE; + putShortMSB(s, header); + + /* Save the adler32 of the preset dictionary: */ + if (s.strstart !== 0) { + putShortMSB(s, strm.adler >>> 16); + putShortMSB(s, strm.adler & 0xffff); + } + strm.adler = 1; // adler32(0L, Z_NULL, 0); + } + } + +//#ifdef GZIP + if (s.status === EXTRA_STATE) { + if (s.gzhead.extra/* != Z_NULL*/) { + beg = s.pending; /* start of bytes to update crc */ + + while (s.gzindex < (s.gzhead.extra.length & 0xffff)) { + if (s.pending === s.pending_buf_size) { + if (s.gzhead.hcrc && s.pending > beg) { + strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg); + } + flush_pending(strm); + beg = s.pending; + if (s.pending === s.pending_buf_size) { + break; + } + } + put_byte(s, s.gzhead.extra[s.gzindex] & 0xff); + s.gzindex++; + } + if (s.gzhead.hcrc && s.pending > beg) { + strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg); + } + if (s.gzindex === s.gzhead.extra.length) { + s.gzindex = 0; + s.status = NAME_STATE; + } + } + else { + s.status = NAME_STATE; + } + } + if (s.status === NAME_STATE) { + if (s.gzhead.name/* != Z_NULL*/) { + beg = s.pending; /* start of bytes to update crc */ + //int val; + + do { + if (s.pending === s.pending_buf_size) { + if (s.gzhead.hcrc && s.pending > beg) { + strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg); + } + flush_pending(strm); + beg = s.pending; + if (s.pending === s.pending_buf_size) { + val = 1; + break; + } + } + // JS specific: little magic to add zero terminator to end of string + if (s.gzindex < s.gzhead.name.length) { + val = s.gzhead.name.charCodeAt(s.gzindex++) & 0xff; + } else { + val = 0; + } + put_byte(s, val); + } while (val !== 0); + + if (s.gzhead.hcrc && s.pending > beg){ + strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg); + } + if (val === 0) { + s.gzindex = 0; + s.status = COMMENT_STATE; + } + } + else { + s.status = COMMENT_STATE; + } + } + if (s.status === COMMENT_STATE) { + if (s.gzhead.comment/* != Z_NULL*/) { + beg = s.pending; /* start of bytes to update crc */ + //int val; + + do { + if (s.pending === s.pending_buf_size) { + if (s.gzhead.hcrc && s.pending > beg) { + strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg); + } + flush_pending(strm); + beg = s.pending; + if (s.pending === s.pending_buf_size) { + val = 1; + break; + } + } + // JS specific: little magic to add zero terminator to end of string + if (s.gzindex < s.gzhead.comment.length) { + val = s.gzhead.comment.charCodeAt(s.gzindex++) & 0xff; + } else { + val = 0; + } + put_byte(s, val); + } while (val !== 0); + + if (s.gzhead.hcrc && s.pending > beg) { + strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg); + } + if (val === 0) { + s.status = HCRC_STATE; + } + } + else { + s.status = HCRC_STATE; + } + } + if (s.status === HCRC_STATE) { + if (s.gzhead.hcrc) { + if (s.pending + 2 > s.pending_buf_size) { + flush_pending(strm); + } + if (s.pending + 2 <= s.pending_buf_size) { + put_byte(s, strm.adler & 0xff); + put_byte(s, (strm.adler >> 8) & 0xff); + strm.adler = 0; //crc32(0L, Z_NULL, 0); + s.status = BUSY_STATE; + } + } + else { + s.status = BUSY_STATE; + } + } +//#endif + + /* Flush as much pending output as possible */ + if (s.pending !== 0) { + flush_pending(strm); + if (strm.avail_out === 0) { + /* Since avail_out is 0, deflate will be called again with + * more output space, but possibly with both pending and + * avail_in equal to zero. There won't be anything to do, + * but this is not an error situation so make sure we + * return OK instead of BUF_ERROR at next call of deflate: + */ + s.last_flush = -1; + return Z_OK; + } + + /* Make sure there is something to do and avoid duplicate consecutive + * flushes. For repeated and useless calls with Z_FINISH, we keep + * returning Z_STREAM_END instead of Z_BUF_ERROR. + */ + } else if (strm.avail_in === 0 && rank(flush) <= rank(old_flush) && + flush !== Z_FINISH) { + return err(strm, Z_BUF_ERROR); + } + + /* User must not provide more input after the first FINISH: */ + if (s.status === FINISH_STATE && strm.avail_in !== 0) { + return err(strm, Z_BUF_ERROR); + } + + /* Start a new block or continue the current one. + */ + if (strm.avail_in !== 0 || s.lookahead !== 0 || + (flush !== Z_NO_FLUSH && s.status !== FINISH_STATE)) { + var bstate = (s.strategy === Z_HUFFMAN_ONLY) ? deflate_huff(s, flush) : + (s.strategy === Z_RLE ? deflate_rle(s, flush) : + configuration_table[s.level].func(s, flush)); + + if (bstate === BS_FINISH_STARTED || bstate === BS_FINISH_DONE) { + s.status = FINISH_STATE; + } + if (bstate === BS_NEED_MORE || bstate === BS_FINISH_STARTED) { + if (strm.avail_out === 0) { + s.last_flush = -1; + /* avoid BUF_ERROR next call, see above */ + } + return Z_OK; + /* If flush != Z_NO_FLUSH && avail_out == 0, the next call + * of deflate should use the same flush parameter to make sure + * that the flush is complete. So we don't have to output an + * empty block here, this will be done at next call. This also + * ensures that for a very small output buffer, we emit at most + * one empty block. + */ + } + if (bstate === BS_BLOCK_DONE) { + if (flush === Z_PARTIAL_FLUSH) { + trees._tr_align(s); + } + else if (flush !== Z_BLOCK) { /* FULL_FLUSH or SYNC_FLUSH */ + + trees._tr_stored_block(s, 0, 0, false); + /* For a full flush, this empty block will be recognized + * as a special marker by inflate_sync(). + */ + if (flush === Z_FULL_FLUSH) { + /*** CLEAR_HASH(s); ***/ /* forget history */ + zero(s.head); // Fill with NIL (= 0); + + if (s.lookahead === 0) { + s.strstart = 0; + s.block_start = 0; + s.insert = 0; + } + } + } + flush_pending(strm); + if (strm.avail_out === 0) { + s.last_flush = -1; /* avoid BUF_ERROR at next call, see above */ + return Z_OK; + } + } + } + //Assert(strm->avail_out > 0, "bug2"); + //if (strm.avail_out <= 0) { throw new Error("bug2");} + + if (flush !== Z_FINISH) { return Z_OK; } + if (s.wrap <= 0) { return Z_STREAM_END; } + + /* Write the trailer */ + if (s.wrap === 2) { + put_byte(s, strm.adler & 0xff); + put_byte(s, (strm.adler >> 8) & 0xff); + put_byte(s, (strm.adler >> 16) & 0xff); + put_byte(s, (strm.adler >> 24) & 0xff); + put_byte(s, strm.total_in & 0xff); + put_byte(s, (strm.total_in >> 8) & 0xff); + put_byte(s, (strm.total_in >> 16) & 0xff); + put_byte(s, (strm.total_in >> 24) & 0xff); + } + else + { + putShortMSB(s, strm.adler >>> 16); + putShortMSB(s, strm.adler & 0xffff); + } + + flush_pending(strm); + /* If avail_out is zero, the application will call deflate again + * to flush the rest. + */ + if (s.wrap > 0) { s.wrap = -s.wrap; } + /* write the trailer only once! */ + return s.pending !== 0 ? Z_OK : Z_STREAM_END; +} + +function deflateEnd(strm) { + var status; + + if (!strm/*== Z_NULL*/ || !strm.state/*== Z_NULL*/) { + return Z_STREAM_ERROR; + } + + status = strm.state.status; + if (status !== INIT_STATE && + status !== EXTRA_STATE && + status !== NAME_STATE && + status !== COMMENT_STATE && + status !== HCRC_STATE && + status !== BUSY_STATE && + status !== FINISH_STATE + ) { + return err(strm, Z_STREAM_ERROR); + } + + strm.state = null; + + return status === BUSY_STATE ? err(strm, Z_DATA_ERROR) : Z_OK; +} + +/* ========================================================================= + * Copy the source state to the destination state + */ +//function deflateCopy(dest, source) { +// +//} + +exports.deflateInit = deflateInit; +exports.deflateInit2 = deflateInit2; +exports.deflateReset = deflateReset; +exports.deflateResetKeep = deflateResetKeep; +exports.deflateSetHeader = deflateSetHeader; +exports.deflate = deflate; +exports.deflateEnd = deflateEnd; +exports.deflateInfo = 'pako deflate (from Nodeca project)'; + +/* Not implemented +exports.deflateBound = deflateBound; +exports.deflateCopy = deflateCopy; +exports.deflateSetDictionary = deflateSetDictionary; +exports.deflateParams = deflateParams; +exports.deflatePending = deflatePending; +exports.deflatePrime = deflatePrime; +exports.deflateTune = deflateTune; +*/ +},{"../utils/common":28,"./adler32":30,"./crc32":32,"./messages":38,"./trees":39}],34:[function(_dereq_,module,exports){ +'use strict'; + + +function GZheader() { + /* true if compressed data believed to be text */ + this.text = 0; + /* modification time */ + this.time = 0; + /* extra flags (not used when writing a gzip file) */ + this.xflags = 0; + /* operating system */ + this.os = 0; + /* pointer to extra field or Z_NULL if none */ + this.extra = null; + /* extra field length (valid if extra != Z_NULL) */ + this.extra_len = 0; // Actually, we don't need it in JS, + // but leave for few code modifications + + // + // Setup limits is not necessary because in js we should not preallocate memory + // for inflate use constant limit in 65536 bytes + // + + /* space at extra (only when reading header) */ + // this.extra_max = 0; + /* pointer to zero-terminated file name or Z_NULL */ + this.name = ''; + /* space at name (only when reading header) */ + // this.name_max = 0; + /* pointer to zero-terminated comment or Z_NULL */ + this.comment = ''; + /* space at comment (only when reading header) */ + // this.comm_max = 0; + /* true if there was or will be a header crc */ + this.hcrc = 0; + /* true when done reading gzip header (not used when writing a gzip file) */ + this.done = false; +} + +module.exports = GZheader; +},{}],35:[function(_dereq_,module,exports){ +'use strict'; + +// See state defs from inflate.js +var BAD = 30; /* got a data error -- remain here until reset */ +var TYPE = 12; /* i: waiting for type bits, including last-flag bit */ + +/* + Decode literal, length, and distance codes and write out the resulting + literal and match bytes until either not enough input or output is + available, an end-of-block is encountered, or a data error is encountered. + When large enough input and output buffers are supplied to inflate(), for + example, a 16K input buffer and a 64K output buffer, more than 95% of the + inflate execution time is spent in this routine. + + Entry assumptions: + + state.mode === LEN + strm.avail_in >= 6 + strm.avail_out >= 258 + start >= strm.avail_out + state.bits < 8 + + On return, state.mode is one of: + + LEN -- ran out of enough output space or enough available input + TYPE -- reached end of block code, inflate() to interpret next block + BAD -- error in block data + + Notes: + + - The maximum input bits used by a length/distance pair is 15 bits for the + length code, 5 bits for the length extra, 15 bits for the distance code, + and 13 bits for the distance extra. This totals 48 bits, or six bytes. + Therefore if strm.avail_in >= 6, then there is enough input to avoid + checking for available input while decoding. + + - The maximum bytes that a single length/distance pair can output is 258 + bytes, which is the maximum length that can be coded. inflate_fast() + requires strm.avail_out >= 258 for each loop to avoid checking for + output space. + */ +module.exports = function inflate_fast(strm, start) { + var state; + var _in; /* local strm.input */ + var last; /* have enough input while in < last */ + var _out; /* local strm.output */ + var beg; /* inflate()'s initial strm.output */ + var end; /* while out < end, enough space available */ +//#ifdef INFLATE_STRICT + var dmax; /* maximum distance from zlib header */ +//#endif + var wsize; /* window size or zero if not using window */ + var whave; /* valid bytes in the window */ + var wnext; /* window write index */ + var window; /* allocated sliding window, if wsize != 0 */ + var hold; /* local strm.hold */ + var bits; /* local strm.bits */ + var lcode; /* local strm.lencode */ + var dcode; /* local strm.distcode */ + var lmask; /* mask for first level of length codes */ + var dmask; /* mask for first level of distance codes */ + var here; /* retrieved table entry */ + var op; /* code bits, operation, extra bits, or */ + /* window position, window bytes to copy */ + var len; /* match length, unused bytes */ + var dist; /* match distance */ + var from; /* where to copy match from */ + var from_source; + + + var input, output; // JS specific, because we have no pointers + + /* copy state to local variables */ + state = strm.state; + //here = state.here; + _in = strm.next_in; + input = strm.input; + last = _in + (strm.avail_in - 5); + _out = strm.next_out; + output = strm.output; + beg = _out - (start - strm.avail_out); + end = _out + (strm.avail_out - 257); +//#ifdef INFLATE_STRICT + dmax = state.dmax; +//#endif + wsize = state.wsize; + whave = state.whave; + wnext = state.wnext; + window = state.window; + hold = state.hold; + bits = state.bits; + lcode = state.lencode; + dcode = state.distcode; + lmask = (1 << state.lenbits) - 1; + dmask = (1 << state.distbits) - 1; + + + /* decode literals and length/distances until end-of-block or not enough + input data or output space */ + + top: + do { + if (bits < 15) { + hold += input[_in++] << bits; + bits += 8; + hold += input[_in++] << bits; + bits += 8; + } + + here = lcode[hold & lmask]; + + dolen: + for (;;) { // Goto emulation + op = here >>> 24/*here.bits*/; + hold >>>= op; + bits -= op; + op = (here >>> 16) & 0xff/*here.op*/; + if (op === 0) { /* literal */ + //Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? + // "inflate: literal '%c'\n" : + // "inflate: literal 0x%02x\n", here.val)); + output[_out++] = here & 0xffff/*here.val*/; + } + else if (op & 16) { /* length base */ + len = here & 0xffff/*here.val*/; + op &= 15; /* number of extra bits */ + if (op) { + if (bits < op) { + hold += input[_in++] << bits; + bits += 8; + } + len += hold & ((1 << op) - 1); + hold >>>= op; + bits -= op; + } + //Tracevv((stderr, "inflate: length %u\n", len)); + if (bits < 15) { + hold += input[_in++] << bits; + bits += 8; + hold += input[_in++] << bits; + bits += 8; + } + here = dcode[hold & dmask]; + + dodist: + for (;;) { // goto emulation + op = here >>> 24/*here.bits*/; + hold >>>= op; + bits -= op; + op = (here >>> 16) & 0xff/*here.op*/; + + if (op & 16) { /* distance base */ + dist = here & 0xffff/*here.val*/; + op &= 15; /* number of extra bits */ + if (bits < op) { + hold += input[_in++] << bits; + bits += 8; + if (bits < op) { + hold += input[_in++] << bits; + bits += 8; + } + } + dist += hold & ((1 << op) - 1); +//#ifdef INFLATE_STRICT + if (dist > dmax) { + strm.msg = 'invalid distance too far back'; + state.mode = BAD; + break top; + } +//#endif + hold >>>= op; + bits -= op; + //Tracevv((stderr, "inflate: distance %u\n", dist)); + op = _out - beg; /* max distance in output */ + if (dist > op) { /* see if copy from window */ + op = dist - op; /* distance back in window */ + if (op > whave) { + if (state.sane) { + strm.msg = 'invalid distance too far back'; + state.mode = BAD; + break top; + } + +// (!) This block is disabled in zlib defailts, +// don't enable it for binary compatibility +//#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR +// if (len <= op - whave) { +// do { +// output[_out++] = 0; +// } while (--len); +// continue top; +// } +// len -= op - whave; +// do { +// output[_out++] = 0; +// } while (--op > whave); +// if (op === 0) { +// from = _out - dist; +// do { +// output[_out++] = output[from++]; +// } while (--len); +// continue top; +// } +//#endif + } + from = 0; // window index + from_source = window; + if (wnext === 0) { /* very common case */ + from += wsize - op; + if (op < len) { /* some from window */ + len -= op; + do { + output[_out++] = window[from++]; + } while (--op); + from = _out - dist; /* rest from output */ + from_source = output; + } + } + else if (wnext < op) { /* wrap around window */ + from += wsize + wnext - op; + op -= wnext; + if (op < len) { /* some from end of window */ + len -= op; + do { + output[_out++] = window[from++]; + } while (--op); + from = 0; + if (wnext < len) { /* some from start of window */ + op = wnext; + len -= op; + do { + output[_out++] = window[from++]; + } while (--op); + from = _out - dist; /* rest from output */ + from_source = output; + } + } + } + else { /* contiguous in window */ + from += wnext - op; + if (op < len) { /* some from window */ + len -= op; + do { + output[_out++] = window[from++]; + } while (--op); + from = _out - dist; /* rest from output */ + from_source = output; + } + } + while (len > 2) { + output[_out++] = from_source[from++]; + output[_out++] = from_source[from++]; + output[_out++] = from_source[from++]; + len -= 3; + } + if (len) { + output[_out++] = from_source[from++]; + if (len > 1) { + output[_out++] = from_source[from++]; + } + } + } + else { + from = _out - dist; /* copy direct from output */ + do { /* minimum length is three */ + output[_out++] = output[from++]; + output[_out++] = output[from++]; + output[_out++] = output[from++]; + len -= 3; + } while (len > 2); + if (len) { + output[_out++] = output[from++]; + if (len > 1) { + output[_out++] = output[from++]; + } + } + } + } + else if ((op & 64) === 0) { /* 2nd level distance code */ + here = dcode[(here & 0xffff)/*here.val*/ + (hold & ((1 << op) - 1))]; + continue dodist; + } + else { + strm.msg = 'invalid distance code'; + state.mode = BAD; + break top; + } + + break; // need to emulate goto via "continue" + } + } + else if ((op & 64) === 0) { /* 2nd level length code */ + here = lcode[(here & 0xffff)/*here.val*/ + (hold & ((1 << op) - 1))]; + continue dolen; + } + else if (op & 32) { /* end-of-block */ + //Tracevv((stderr, "inflate: end of block\n")); + state.mode = TYPE; + break top; + } + else { + strm.msg = 'invalid literal/length code'; + state.mode = BAD; + break top; + } + + break; // need to emulate goto via "continue" + } + } while (_in < last && _out < end); + + /* return unused bytes (on entry, bits < 8, so in won't go too far back) */ + len = bits >> 3; + _in -= len; + bits -= len << 3; + hold &= (1 << bits) - 1; + + /* update state and return */ + strm.next_in = _in; + strm.next_out = _out; + strm.avail_in = (_in < last ? 5 + (last - _in) : 5 - (_in - last)); + strm.avail_out = (_out < end ? 257 + (end - _out) : 257 - (_out - end)); + state.hold = hold; + state.bits = bits; + return; +}; + +},{}],36:[function(_dereq_,module,exports){ +'use strict'; + + +var utils = _dereq_('../utils/common'); +var adler32 = _dereq_('./adler32'); +var crc32 = _dereq_('./crc32'); +var inflate_fast = _dereq_('./inffast'); +var inflate_table = _dereq_('./inftrees'); + +var CODES = 0; +var LENS = 1; +var DISTS = 2; + +/* Public constants ==========================================================*/ +/* ===========================================================================*/ + + +/* Allowed flush values; see deflate() and inflate() below for details */ +//var Z_NO_FLUSH = 0; +//var Z_PARTIAL_FLUSH = 1; +//var Z_SYNC_FLUSH = 2; +//var Z_FULL_FLUSH = 3; +var Z_FINISH = 4; +var Z_BLOCK = 5; +var Z_TREES = 6; + + +/* Return codes for the compression/decompression functions. Negative values + * are errors, positive values are used for special but normal events. + */ +var Z_OK = 0; +var Z_STREAM_END = 1; +var Z_NEED_DICT = 2; +//var Z_ERRNO = -1; +var Z_STREAM_ERROR = -2; +var Z_DATA_ERROR = -3; +var Z_MEM_ERROR = -4; +var Z_BUF_ERROR = -5; +//var Z_VERSION_ERROR = -6; + +/* The deflate compression method */ +var Z_DEFLATED = 8; + + +/* STATES ====================================================================*/ +/* ===========================================================================*/ + + +var HEAD = 1; /* i: waiting for magic header */ +var FLAGS = 2; /* i: waiting for method and flags (gzip) */ +var TIME = 3; /* i: waiting for modification time (gzip) */ +var OS = 4; /* i: waiting for extra flags and operating system (gzip) */ +var EXLEN = 5; /* i: waiting for extra length (gzip) */ +var EXTRA = 6; /* i: waiting for extra bytes (gzip) */ +var NAME = 7; /* i: waiting for end of file name (gzip) */ +var COMMENT = 8; /* i: waiting for end of comment (gzip) */ +var HCRC = 9; /* i: waiting for header crc (gzip) */ +var DICTID = 10; /* i: waiting for dictionary check value */ +var DICT = 11; /* waiting for inflateSetDictionary() call */ +var TYPE = 12; /* i: waiting for type bits, including last-flag bit */ +var TYPEDO = 13; /* i: same, but skip check to exit inflate on new block */ +var STORED = 14; /* i: waiting for stored size (length and complement) */ +var COPY_ = 15; /* i/o: same as COPY below, but only first time in */ +var COPY = 16; /* i/o: waiting for input or output to copy stored block */ +var TABLE = 17; /* i: waiting for dynamic block table lengths */ +var LENLENS = 18; /* i: waiting for code length code lengths */ +var CODELENS = 19; /* i: waiting for length/lit and distance code lengths */ +var LEN_ = 20; /* i: same as LEN below, but only first time in */ +var LEN = 21; /* i: waiting for length/lit/eob code */ +var LENEXT = 22; /* i: waiting for length extra bits */ +var DIST = 23; /* i: waiting for distance code */ +var DISTEXT = 24; /* i: waiting for distance extra bits */ +var MATCH = 25; /* o: waiting for output space to copy string */ +var LIT = 26; /* o: waiting for output space to write literal */ +var CHECK = 27; /* i: waiting for 32-bit check value */ +var LENGTH = 28; /* i: waiting for 32-bit length (gzip) */ +var DONE = 29; /* finished check, done -- remain here until reset */ +var BAD = 30; /* got a data error -- remain here until reset */ +var MEM = 31; /* got an inflate() memory error -- remain here until reset */ +var SYNC = 32; /* looking for synchronization bytes to restart inflate() */ + +/* ===========================================================================*/ + + + +var ENOUGH_LENS = 852; +var ENOUGH_DISTS = 592; +//var ENOUGH = (ENOUGH_LENS+ENOUGH_DISTS); + +var MAX_WBITS = 15; +/* 32K LZ77 window */ +var DEF_WBITS = MAX_WBITS; + + +function ZSWAP32(q) { + return (((q >>> 24) & 0xff) + + ((q >>> 8) & 0xff00) + + ((q & 0xff00) << 8) + + ((q & 0xff) << 24)); +} + + +function InflateState() { + this.mode = 0; /* current inflate mode */ + this.last = false; /* true if processing last block */ + this.wrap = 0; /* bit 0 true for zlib, bit 1 true for gzip */ + this.havedict = false; /* true if dictionary provided */ + this.flags = 0; /* gzip header method and flags (0 if zlib) */ + this.dmax = 0; /* zlib header max distance (INFLATE_STRICT) */ + this.check = 0; /* protected copy of check value */ + this.total = 0; /* protected copy of output count */ + // TODO: may be {} + this.head = null; /* where to save gzip header information */ + + /* sliding window */ + this.wbits = 0; /* log base 2 of requested window size */ + this.wsize = 0; /* window size or zero if not using window */ + this.whave = 0; /* valid bytes in the window */ + this.wnext = 0; /* window write index */ + this.window = null; /* allocated sliding window, if needed */ + + /* bit accumulator */ + this.hold = 0; /* input bit accumulator */ + this.bits = 0; /* number of bits in "in" */ + + /* for string and stored block copying */ + this.length = 0; /* literal or length of data to copy */ + this.offset = 0; /* distance back to copy string from */ + + /* for table and code decoding */ + this.extra = 0; /* extra bits needed */ + + /* fixed and dynamic code tables */ + this.lencode = null; /* starting table for length/literal codes */ + this.distcode = null; /* starting table for distance codes */ + this.lenbits = 0; /* index bits for lencode */ + this.distbits = 0; /* index bits for distcode */ + + /* dynamic table building */ + this.ncode = 0; /* number of code length code lengths */ + this.nlen = 0; /* number of length code lengths */ + this.ndist = 0; /* number of distance code lengths */ + this.have = 0; /* number of code lengths in lens[] */ + this.next = null; /* next available space in codes[] */ + + this.lens = new utils.Buf16(320); /* temporary storage for code lengths */ + this.work = new utils.Buf16(288); /* work area for code table building */ + + /* + because we don't have pointers in js, we use lencode and distcode directly + as buffers so we don't need codes + */ + //this.codes = new utils.Buf32(ENOUGH); /* space for code tables */ + this.lendyn = null; /* dynamic table for length/literal codes (JS specific) */ + this.distdyn = null; /* dynamic table for distance codes (JS specific) */ + this.sane = 0; /* if false, allow invalid distance too far */ + this.back = 0; /* bits back of last unprocessed length/lit */ + this.was = 0; /* initial length of match */ +} + +function inflateResetKeep(strm) { + var state; + + if (!strm || !strm.state) { return Z_STREAM_ERROR; } + state = strm.state; + strm.total_in = strm.total_out = state.total = 0; + strm.msg = ''; /*Z_NULL*/ + if (state.wrap) { /* to support ill-conceived Java test suite */ + strm.adler = state.wrap & 1; + } + state.mode = HEAD; + state.last = 0; + state.havedict = 0; + state.dmax = 32768; + state.head = null/*Z_NULL*/; + state.hold = 0; + state.bits = 0; + //state.lencode = state.distcode = state.next = state.codes; + state.lencode = state.lendyn = new utils.Buf32(ENOUGH_LENS); + state.distcode = state.distdyn = new utils.Buf32(ENOUGH_DISTS); + + state.sane = 1; + state.back = -1; + //Tracev((stderr, "inflate: reset\n")); + return Z_OK; +} + +function inflateReset(strm) { + var state; + + if (!strm || !strm.state) { return Z_STREAM_ERROR; } + state = strm.state; + state.wsize = 0; + state.whave = 0; + state.wnext = 0; + return inflateResetKeep(strm); + +} + +function inflateReset2(strm, windowBits) { + var wrap; + var state; + + /* get the state */ + if (!strm || !strm.state) { return Z_STREAM_ERROR; } + state = strm.state; + + /* extract wrap request from windowBits parameter */ + if (windowBits < 0) { + wrap = 0; + windowBits = -windowBits; + } + else { + wrap = (windowBits >> 4) + 1; + if (windowBits < 48) { + windowBits &= 15; + } + } + + /* set number of window bits, free window if different */ + if (windowBits && (windowBits < 8 || windowBits > 15)) { + return Z_STREAM_ERROR; + } + if (state.window !== null && state.wbits !== windowBits) { + state.window = null; + } + + /* update state and reset the rest of it */ + state.wrap = wrap; + state.wbits = windowBits; + return inflateReset(strm); +} + +function inflateInit2(strm, windowBits) { + var ret; + var state; + + if (!strm) { return Z_STREAM_ERROR; } + //strm.msg = Z_NULL; /* in case we return an error */ + + state = new InflateState(); + + //if (state === Z_NULL) return Z_MEM_ERROR; + //Tracev((stderr, "inflate: allocated\n")); + strm.state = state; + state.window = null/*Z_NULL*/; + ret = inflateReset2(strm, windowBits); + if (ret !== Z_OK) { + strm.state = null/*Z_NULL*/; + } + return ret; +} + +function inflateInit(strm) { + return inflateInit2(strm, DEF_WBITS); +} + + +/* + Return state with length and distance decoding tables and index sizes set to + fixed code decoding. Normally this returns fixed tables from inffixed.h. + If BUILDFIXED is defined, then instead this routine builds the tables the + first time it's called, and returns those tables the first time and + thereafter. This reduces the size of the code by about 2K bytes, in + exchange for a little execution time. However, BUILDFIXED should not be + used for threaded applications, since the rewriting of the tables and virgin + may not be thread-safe. + */ +var virgin = true; + +var lenfix, distfix; // We have no pointers in JS, so keep tables separate + +function fixedtables(state) { + /* build fixed huffman tables if first call (may not be thread safe) */ + if (virgin) { + var sym; + + lenfix = new utils.Buf32(512); + distfix = new utils.Buf32(32); + + /* literal/length table */ + sym = 0; + while (sym < 144) { state.lens[sym++] = 8; } + while (sym < 256) { state.lens[sym++] = 9; } + while (sym < 280) { state.lens[sym++] = 7; } + while (sym < 288) { state.lens[sym++] = 8; } + + inflate_table(LENS, state.lens, 0, 288, lenfix, 0, state.work, {bits: 9}); + + /* distance table */ + sym = 0; + while (sym < 32) { state.lens[sym++] = 5; } + + inflate_table(DISTS, state.lens, 0, 32, distfix, 0, state.work, {bits: 5}); + + /* do this just once */ + virgin = false; + } + + state.lencode = lenfix; + state.lenbits = 9; + state.distcode = distfix; + state.distbits = 5; +} + + +/* + Update the window with the last wsize (normally 32K) bytes written before + returning. If window does not exist yet, create it. This is only called + when a window is already in use, or when output has been written during this + inflate call, but the end of the deflate stream has not been reached yet. + It is also called to create a window for dictionary data when a dictionary + is loaded. + + Providing output buffers larger than 32K to inflate() should provide a speed + advantage, since only the last 32K of output is copied to the sliding window + upon return from inflate(), and since all distances after the first 32K of + output will fall in the output data, making match copies simpler and faster. + The advantage may be dependent on the size of the processor's data caches. + */ +function updatewindow(strm, src, end, copy) { + var dist; + var state = strm.state; + + /* if it hasn't been done already, allocate space for the window */ + if (state.window === null) { + state.wsize = 1 << state.wbits; + state.wnext = 0; + state.whave = 0; + + state.window = new utils.Buf8(state.wsize); + } + + /* copy state->wsize or less output bytes into the circular window */ + if (copy >= state.wsize) { + utils.arraySet(state.window,src, end - state.wsize, state.wsize, 0); + state.wnext = 0; + state.whave = state.wsize; + } + else { + dist = state.wsize - state.wnext; + if (dist > copy) { + dist = copy; + } + //zmemcpy(state->window + state->wnext, end - copy, dist); + utils.arraySet(state.window,src, end - copy, dist, state.wnext); + copy -= dist; + if (copy) { + //zmemcpy(state->window, end - copy, copy); + utils.arraySet(state.window,src, end - copy, copy, 0); + state.wnext = copy; + state.whave = state.wsize; + } + else { + state.wnext += dist; + if (state.wnext === state.wsize) { state.wnext = 0; } + if (state.whave < state.wsize) { state.whave += dist; } + } + } + return 0; +} + +function inflate(strm, flush) { + var state; + var input, output; // input/output buffers + var next; /* next input INDEX */ + var put; /* next output INDEX */ + var have, left; /* available input and output */ + var hold; /* bit buffer */ + var bits; /* bits in bit buffer */ + var _in, _out; /* save starting available input and output */ + var copy; /* number of stored or match bytes to copy */ + var from; /* where to copy match bytes from */ + var from_source; + var here = 0; /* current decoding table entry */ + var here_bits, here_op, here_val; // paked "here" denormalized (JS specific) + //var last; /* parent table entry */ + var last_bits, last_op, last_val; // paked "last" denormalized (JS specific) + var len; /* length to copy for repeats, bits to drop */ + var ret; /* return code */ + var hbuf = new utils.Buf8(4); /* buffer for gzip header crc calculation */ + var opts; + + var n; // temporary var for NEED_BITS + + var order = /* permutation of code lengths */ + [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]; + + + if (!strm || !strm.state || !strm.output || + (!strm.input && strm.avail_in !== 0)) { + return Z_STREAM_ERROR; + } + + state = strm.state; + if (state.mode === TYPE) { state.mode = TYPEDO; } /* skip check */ + + + //--- LOAD() --- + put = strm.next_out; + output = strm.output; + left = strm.avail_out; + next = strm.next_in; + input = strm.input; + have = strm.avail_in; + hold = state.hold; + bits = state.bits; + //--- + + _in = have; + _out = left; + ret = Z_OK; + + inf_leave: // goto emulation + for (;;) { + switch (state.mode) { + case HEAD: + if (state.wrap === 0) { + state.mode = TYPEDO; + break; + } + //=== NEEDBITS(16); + while (bits < 16) { + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + if ((state.wrap & 2) && hold === 0x8b1f) { /* gzip header */ + state.check = 0/*crc32(0L, Z_NULL, 0)*/; + //=== CRC2(state.check, hold); + hbuf[0] = hold & 0xff; + hbuf[1] = (hold >>> 8) & 0xff; + state.check = crc32(state.check, hbuf, 2, 0); + //===// + + //=== INITBITS(); + hold = 0; + bits = 0; + //===// + state.mode = FLAGS; + break; + } + state.flags = 0; /* expect zlib header */ + if (state.head) { + state.head.done = false; + } + if (!(state.wrap & 1) || /* check if zlib header allowed */ + (((hold & 0xff)/*BITS(8)*/ << 8) + (hold >> 8)) % 31) { + strm.msg = 'incorrect header check'; + state.mode = BAD; + break; + } + if ((hold & 0x0f)/*BITS(4)*/ !== Z_DEFLATED) { + strm.msg = 'unknown compression method'; + state.mode = BAD; + break; + } + //--- DROPBITS(4) ---// + hold >>>= 4; + bits -= 4; + //---// + len = (hold & 0x0f)/*BITS(4)*/ + 8; + if (state.wbits === 0) { + state.wbits = len; + } + else if (len > state.wbits) { + strm.msg = 'invalid window size'; + state.mode = BAD; + break; + } + state.dmax = 1 << len; + //Tracev((stderr, "inflate: zlib header ok\n")); + strm.adler = state.check = 1/*adler32(0L, Z_NULL, 0)*/; + state.mode = hold & 0x200 ? DICTID : TYPE; + //=== INITBITS(); + hold = 0; + bits = 0; + //===// + break; + case FLAGS: + //=== NEEDBITS(16); */ + while (bits < 16) { + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + state.flags = hold; + if ((state.flags & 0xff) !== Z_DEFLATED) { + strm.msg = 'unknown compression method'; + state.mode = BAD; + break; + } + if (state.flags & 0xe000) { + strm.msg = 'unknown header flags set'; + state.mode = BAD; + break; + } + if (state.head) { + state.head.text = ((hold >> 8) & 1); + } + if (state.flags & 0x0200) { + //=== CRC2(state.check, hold); + hbuf[0] = hold & 0xff; + hbuf[1] = (hold >>> 8) & 0xff; + state.check = crc32(state.check, hbuf, 2, 0); + //===// + } + //=== INITBITS(); + hold = 0; + bits = 0; + //===// + state.mode = TIME; + /* falls through */ + case TIME: + //=== NEEDBITS(32); */ + while (bits < 32) { + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + if (state.head) { + state.head.time = hold; + } + if (state.flags & 0x0200) { + //=== CRC4(state.check, hold) + hbuf[0] = hold & 0xff; + hbuf[1] = (hold >>> 8) & 0xff; + hbuf[2] = (hold >>> 16) & 0xff; + hbuf[3] = (hold >>> 24) & 0xff; + state.check = crc32(state.check, hbuf, 4, 0); + //=== + } + //=== INITBITS(); + hold = 0; + bits = 0; + //===// + state.mode = OS; + /* falls through */ + case OS: + //=== NEEDBITS(16); */ + while (bits < 16) { + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + if (state.head) { + state.head.xflags = (hold & 0xff); + state.head.os = (hold >> 8); + } + if (state.flags & 0x0200) { + //=== CRC2(state.check, hold); + hbuf[0] = hold & 0xff; + hbuf[1] = (hold >>> 8) & 0xff; + state.check = crc32(state.check, hbuf, 2, 0); + //===// + } + //=== INITBITS(); + hold = 0; + bits = 0; + //===// + state.mode = EXLEN; + /* falls through */ + case EXLEN: + if (state.flags & 0x0400) { + //=== NEEDBITS(16); */ + while (bits < 16) { + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + state.length = hold; + if (state.head) { + state.head.extra_len = hold; + } + if (state.flags & 0x0200) { + //=== CRC2(state.check, hold); + hbuf[0] = hold & 0xff; + hbuf[1] = (hold >>> 8) & 0xff; + state.check = crc32(state.check, hbuf, 2, 0); + //===// + } + //=== INITBITS(); + hold = 0; + bits = 0; + //===// + } + else if (state.head) { + state.head.extra = null/*Z_NULL*/; + } + state.mode = EXTRA; + /* falls through */ + case EXTRA: + if (state.flags & 0x0400) { + copy = state.length; + if (copy > have) { copy = have; } + if (copy) { + if (state.head) { + len = state.head.extra_len - state.length; + if (!state.head.extra) { + // Use untyped array for more conveniend processing later + state.head.extra = new Array(state.head.extra_len); + } + utils.arraySet( + state.head.extra, + input, + next, + // extra field is limited to 65536 bytes + // - no need for additional size check + copy, + /*len + copy > state.head.extra_max - len ? state.head.extra_max : copy,*/ + len + ); + //zmemcpy(state.head.extra + len, next, + // len + copy > state.head.extra_max ? + // state.head.extra_max - len : copy); + } + if (state.flags & 0x0200) { + state.check = crc32(state.check, input, copy, next); + } + have -= copy; + next += copy; + state.length -= copy; + } + if (state.length) { break inf_leave; } + } + state.length = 0; + state.mode = NAME; + /* falls through */ + case NAME: + if (state.flags & 0x0800) { + if (have === 0) { break inf_leave; } + copy = 0; + do { + // TODO: 2 or 1 bytes? + len = input[next + copy++]; + /* use constant limit because in js we should not preallocate memory */ + if (state.head && len && + (state.length < 65536 /*state.head.name_max*/)) { + state.head.name += String.fromCharCode(len); + } + } while (len && copy < have); + + if (state.flags & 0x0200) { + state.check = crc32(state.check, input, copy, next); + } + have -= copy; + next += copy; + if (len) { break inf_leave; } + } + else if (state.head) { + state.head.name = null; + } + state.length = 0; + state.mode = COMMENT; + /* falls through */ + case COMMENT: + if (state.flags & 0x1000) { + if (have === 0) { break inf_leave; } + copy = 0; + do { + len = input[next + copy++]; + /* use constant limit because in js we should not preallocate memory */ + if (state.head && len && + (state.length < 65536 /*state.head.comm_max*/)) { + state.head.comment += String.fromCharCode(len); + } + } while (len && copy < have); + if (state.flags & 0x0200) { + state.check = crc32(state.check, input, copy, next); + } + have -= copy; + next += copy; + if (len) { break inf_leave; } + } + else if (state.head) { + state.head.comment = null; + } + state.mode = HCRC; + /* falls through */ + case HCRC: + if (state.flags & 0x0200) { + //=== NEEDBITS(16); */ + while (bits < 16) { + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + if (hold !== (state.check & 0xffff)) { + strm.msg = 'header crc mismatch'; + state.mode = BAD; + break; + } + //=== INITBITS(); + hold = 0; + bits = 0; + //===// + } + if (state.head) { + state.head.hcrc = ((state.flags >> 9) & 1); + state.head.done = true; + } + strm.adler = state.check = 0 /*crc32(0L, Z_NULL, 0)*/; + state.mode = TYPE; + break; + case DICTID: + //=== NEEDBITS(32); */ + while (bits < 32) { + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + strm.adler = state.check = ZSWAP32(hold); + //=== INITBITS(); + hold = 0; + bits = 0; + //===// + state.mode = DICT; + /* falls through */ + case DICT: + if (state.havedict === 0) { + //--- RESTORE() --- + strm.next_out = put; + strm.avail_out = left; + strm.next_in = next; + strm.avail_in = have; + state.hold = hold; + state.bits = bits; + //--- + return Z_NEED_DICT; + } + strm.adler = state.check = 1/*adler32(0L, Z_NULL, 0)*/; + state.mode = TYPE; + /* falls through */ + case TYPE: + if (flush === Z_BLOCK || flush === Z_TREES) { break inf_leave; } + /* falls through */ + case TYPEDO: + if (state.last) { + //--- BYTEBITS() ---// + hold >>>= bits & 7; + bits -= bits & 7; + //---// + state.mode = CHECK; + break; + } + //=== NEEDBITS(3); */ + while (bits < 3) { + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + state.last = (hold & 0x01)/*BITS(1)*/; + //--- DROPBITS(1) ---// + hold >>>= 1; + bits -= 1; + //---// + + switch ((hold & 0x03)/*BITS(2)*/) { + case 0: /* stored block */ + //Tracev((stderr, "inflate: stored block%s\n", + // state.last ? " (last)" : "")); + state.mode = STORED; + break; + case 1: /* fixed block */ + fixedtables(state); + //Tracev((stderr, "inflate: fixed codes block%s\n", + // state.last ? " (last)" : "")); + state.mode = LEN_; /* decode codes */ + if (flush === Z_TREES) { + //--- DROPBITS(2) ---// + hold >>>= 2; + bits -= 2; + //---// + break inf_leave; + } + break; + case 2: /* dynamic block */ + //Tracev((stderr, "inflate: dynamic codes block%s\n", + // state.last ? " (last)" : "")); + state.mode = TABLE; + break; + case 3: + strm.msg = 'invalid block type'; + state.mode = BAD; + } + //--- DROPBITS(2) ---// + hold >>>= 2; + bits -= 2; + //---// + break; + case STORED: + //--- BYTEBITS() ---// /* go to byte boundary */ + hold >>>= bits & 7; + bits -= bits & 7; + //---// + //=== NEEDBITS(32); */ + while (bits < 32) { + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + if ((hold & 0xffff) !== ((hold >>> 16) ^ 0xffff)) { + strm.msg = 'invalid stored block lengths'; + state.mode = BAD; + break; + } + state.length = hold & 0xffff; + //Tracev((stderr, "inflate: stored length %u\n", + // state.length)); + //=== INITBITS(); + hold = 0; + bits = 0; + //===// + state.mode = COPY_; + if (flush === Z_TREES) { break inf_leave; } + /* falls through */ + case COPY_: + state.mode = COPY; + /* falls through */ + case COPY: + copy = state.length; + if (copy) { + if (copy > have) { copy = have; } + if (copy > left) { copy = left; } + if (copy === 0) { break inf_leave; } + //--- zmemcpy(put, next, copy); --- + utils.arraySet(output, input, next, copy, put); + //---// + have -= copy; + next += copy; + left -= copy; + put += copy; + state.length -= copy; + break; + } + //Tracev((stderr, "inflate: stored end\n")); + state.mode = TYPE; + break; + case TABLE: + //=== NEEDBITS(14); */ + while (bits < 14) { + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + state.nlen = (hold & 0x1f)/*BITS(5)*/ + 257; + //--- DROPBITS(5) ---// + hold >>>= 5; + bits -= 5; + //---// + state.ndist = (hold & 0x1f)/*BITS(5)*/ + 1; + //--- DROPBITS(5) ---// + hold >>>= 5; + bits -= 5; + //---// + state.ncode = (hold & 0x0f)/*BITS(4)*/ + 4; + //--- DROPBITS(4) ---// + hold >>>= 4; + bits -= 4; + //---// +//#ifndef PKZIP_BUG_WORKAROUND + if (state.nlen > 286 || state.ndist > 30) { + strm.msg = 'too many length or distance symbols'; + state.mode = BAD; + break; + } +//#endif + //Tracev((stderr, "inflate: table sizes ok\n")); + state.have = 0; + state.mode = LENLENS; + /* falls through */ + case LENLENS: + while (state.have < state.ncode) { + //=== NEEDBITS(3); + while (bits < 3) { + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + state.lens[order[state.have++]] = (hold & 0x07);//BITS(3); + //--- DROPBITS(3) ---// + hold >>>= 3; + bits -= 3; + //---// + } + while (state.have < 19) { + state.lens[order[state.have++]] = 0; + } + // We have separate tables & no pointers. 2 commented lines below not needed. + //state.next = state.codes; + //state.lencode = state.next; + // Switch to use dynamic table + state.lencode = state.lendyn; + state.lenbits = 7; + + opts = {bits: state.lenbits}; + ret = inflate_table(CODES, state.lens, 0, 19, state.lencode, 0, state.work, opts); + state.lenbits = opts.bits; + + if (ret) { + strm.msg = 'invalid code lengths set'; + state.mode = BAD; + break; + } + //Tracev((stderr, "inflate: code lengths ok\n")); + state.have = 0; + state.mode = CODELENS; + /* falls through */ + case CODELENS: + while (state.have < state.nlen + state.ndist) { + for (;;) { + here = state.lencode[hold & ((1 << state.lenbits) - 1)];/*BITS(state.lenbits)*/ + here_bits = here >>> 24; + here_op = (here >>> 16) & 0xff; + here_val = here & 0xffff; + + if ((here_bits) <= bits) { break; } + //--- PULLBYTE() ---// + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + //---// + } + if (here_val < 16) { + //--- DROPBITS(here.bits) ---// + hold >>>= here_bits; + bits -= here_bits; + //---// + state.lens[state.have++] = here_val; + } + else { + if (here_val === 16) { + //=== NEEDBITS(here.bits + 2); + n = here_bits + 2; + while (bits < n) { + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + //--- DROPBITS(here.bits) ---// + hold >>>= here_bits; + bits -= here_bits; + //---// + if (state.have === 0) { + strm.msg = 'invalid bit length repeat'; + state.mode = BAD; + break; + } + len = state.lens[state.have - 1]; + copy = 3 + (hold & 0x03);//BITS(2); + //--- DROPBITS(2) ---// + hold >>>= 2; + bits -= 2; + //---// + } + else if (here_val === 17) { + //=== NEEDBITS(here.bits + 3); + n = here_bits + 3; + while (bits < n) { + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + //--- DROPBITS(here.bits) ---// + hold >>>= here_bits; + bits -= here_bits; + //---// + len = 0; + copy = 3 + (hold & 0x07);//BITS(3); + //--- DROPBITS(3) ---// + hold >>>= 3; + bits -= 3; + //---// + } + else { + //=== NEEDBITS(here.bits + 7); + n = here_bits + 7; + while (bits < n) { + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + //--- DROPBITS(here.bits) ---// + hold >>>= here_bits; + bits -= here_bits; + //---// + len = 0; + copy = 11 + (hold & 0x7f);//BITS(7); + //--- DROPBITS(7) ---// + hold >>>= 7; + bits -= 7; + //---// + } + if (state.have + copy > state.nlen + state.ndist) { + strm.msg = 'invalid bit length repeat'; + state.mode = BAD; + break; + } + while (copy--) { + state.lens[state.have++] = len; + } + } + } + + /* handle error breaks in while */ + if (state.mode === BAD) { break; } + + /* check for end-of-block code (better have one) */ + if (state.lens[256] === 0) { + strm.msg = 'invalid code -- missing end-of-block'; + state.mode = BAD; + break; + } + + /* build code tables -- note: do not change the lenbits or distbits + values here (9 and 6) without reading the comments in inftrees.h + concerning the ENOUGH constants, which depend on those values */ + state.lenbits = 9; + + opts = {bits: state.lenbits}; + ret = inflate_table(LENS, state.lens, 0, state.nlen, state.lencode, 0, state.work, opts); + // We have separate tables & no pointers. 2 commented lines below not needed. + // state.next_index = opts.table_index; + state.lenbits = opts.bits; + // state.lencode = state.next; + + if (ret) { + strm.msg = 'invalid literal/lengths set'; + state.mode = BAD; + break; + } + + state.distbits = 6; + //state.distcode.copy(state.codes); + // Switch to use dynamic table + state.distcode = state.distdyn; + opts = {bits: state.distbits}; + ret = inflate_table(DISTS, state.lens, state.nlen, state.ndist, state.distcode, 0, state.work, opts); + // We have separate tables & no pointers. 2 commented lines below not needed. + // state.next_index = opts.table_index; + state.distbits = opts.bits; + // state.distcode = state.next; + + if (ret) { + strm.msg = 'invalid distances set'; + state.mode = BAD; + break; + } + //Tracev((stderr, 'inflate: codes ok\n')); + state.mode = LEN_; + if (flush === Z_TREES) { break inf_leave; } + /* falls through */ + case LEN_: + state.mode = LEN; + /* falls through */ + case LEN: + if (have >= 6 && left >= 258) { + //--- RESTORE() --- + strm.next_out = put; + strm.avail_out = left; + strm.next_in = next; + strm.avail_in = have; + state.hold = hold; + state.bits = bits; + //--- + inflate_fast(strm, _out); + //--- LOAD() --- + put = strm.next_out; + output = strm.output; + left = strm.avail_out; + next = strm.next_in; + input = strm.input; + have = strm.avail_in; + hold = state.hold; + bits = state.bits; + //--- + + if (state.mode === TYPE) { + state.back = -1; + } + break; + } + state.back = 0; + for (;;) { + here = state.lencode[hold & ((1 << state.lenbits) -1)]; /*BITS(state.lenbits)*/ + here_bits = here >>> 24; + here_op = (here >>> 16) & 0xff; + here_val = here & 0xffff; + + if (here_bits <= bits) { break; } + //--- PULLBYTE() ---// + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + //---// + } + if (here_op && (here_op & 0xf0) === 0) { + last_bits = here_bits; + last_op = here_op; + last_val = here_val; + for (;;) { + here = state.lencode[last_val + + ((hold & ((1 << (last_bits + last_op)) -1))/*BITS(last.bits + last.op)*/ >> last_bits)]; + here_bits = here >>> 24; + here_op = (here >>> 16) & 0xff; + here_val = here & 0xffff; + + if ((last_bits + here_bits) <= bits) { break; } + //--- PULLBYTE() ---// + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + //---// + } + //--- DROPBITS(last.bits) ---// + hold >>>= last_bits; + bits -= last_bits; + //---// + state.back += last_bits; + } + //--- DROPBITS(here.bits) ---// + hold >>>= here_bits; + bits -= here_bits; + //---// + state.back += here_bits; + state.length = here_val; + if (here_op === 0) { + //Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? + // "inflate: literal '%c'\n" : + // "inflate: literal 0x%02x\n", here.val)); + state.mode = LIT; + break; + } + if (here_op & 32) { + //Tracevv((stderr, "inflate: end of block\n")); + state.back = -1; + state.mode = TYPE; + break; + } + if (here_op & 64) { + strm.msg = 'invalid literal/length code'; + state.mode = BAD; + break; + } + state.extra = here_op & 15; + state.mode = LENEXT; + /* falls through */ + case LENEXT: + if (state.extra) { + //=== NEEDBITS(state.extra); + n = state.extra; + while (bits < n) { + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + state.length += hold & ((1 << state.extra) -1)/*BITS(state.extra)*/; + //--- DROPBITS(state.extra) ---// + hold >>>= state.extra; + bits -= state.extra; + //---// + state.back += state.extra; + } + //Tracevv((stderr, "inflate: length %u\n", state.length)); + state.was = state.length; + state.mode = DIST; + /* falls through */ + case DIST: + for (;;) { + here = state.distcode[hold & ((1 << state.distbits) -1)];/*BITS(state.distbits)*/ + here_bits = here >>> 24; + here_op = (here >>> 16) & 0xff; + here_val = here & 0xffff; + + if ((here_bits) <= bits) { break; } + //--- PULLBYTE() ---// + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + //---// + } + if ((here_op & 0xf0) === 0) { + last_bits = here_bits; + last_op = here_op; + last_val = here_val; + for (;;) { + here = state.distcode[last_val + + ((hold & ((1 << (last_bits + last_op)) -1))/*BITS(last.bits + last.op)*/ >> last_bits)]; + here_bits = here >>> 24; + here_op = (here >>> 16) & 0xff; + here_val = here & 0xffff; + + if ((last_bits + here_bits) <= bits) { break; } + //--- PULLBYTE() ---// + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + //---// + } + //--- DROPBITS(last.bits) ---// + hold >>>= last_bits; + bits -= last_bits; + //---// + state.back += last_bits; + } + //--- DROPBITS(here.bits) ---// + hold >>>= here_bits; + bits -= here_bits; + //---// + state.back += here_bits; + if (here_op & 64) { + strm.msg = 'invalid distance code'; + state.mode = BAD; + break; + } + state.offset = here_val; + state.extra = (here_op) & 15; + state.mode = DISTEXT; + /* falls through */ + case DISTEXT: + if (state.extra) { + //=== NEEDBITS(state.extra); + n = state.extra; + while (bits < n) { + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + state.offset += hold & ((1 << state.extra) -1)/*BITS(state.extra)*/; + //--- DROPBITS(state.extra) ---// + hold >>>= state.extra; + bits -= state.extra; + //---// + state.back += state.extra; + } +//#ifdef INFLATE_STRICT + if (state.offset > state.dmax) { + strm.msg = 'invalid distance too far back'; + state.mode = BAD; + break; + } +//#endif + //Tracevv((stderr, "inflate: distance %u\n", state.offset)); + state.mode = MATCH; + /* falls through */ + case MATCH: + if (left === 0) { break inf_leave; } + copy = _out - left; + if (state.offset > copy) { /* copy from window */ + copy = state.offset - copy; + if (copy > state.whave) { + if (state.sane) { + strm.msg = 'invalid distance too far back'; + state.mode = BAD; + break; + } +// (!) This block is disabled in zlib defailts, +// don't enable it for binary compatibility +//#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR +// Trace((stderr, "inflate.c too far\n")); +// copy -= state.whave; +// if (copy > state.length) { copy = state.length; } +// if (copy > left) { copy = left; } +// left -= copy; +// state.length -= copy; +// do { +// output[put++] = 0; +// } while (--copy); +// if (state.length === 0) { state.mode = LEN; } +// break; +//#endif + } + if (copy > state.wnext) { + copy -= state.wnext; + from = state.wsize - copy; + } + else { + from = state.wnext - copy; + } + if (copy > state.length) { copy = state.length; } + from_source = state.window; + } + else { /* copy from output */ + from_source = output; + from = put - state.offset; + copy = state.length; + } + if (copy > left) { copy = left; } + left -= copy; + state.length -= copy; + do { + output[put++] = from_source[from++]; + } while (--copy); + if (state.length === 0) { state.mode = LEN; } + break; + case LIT: + if (left === 0) { break inf_leave; } + output[put++] = state.length; + left--; + state.mode = LEN; + break; + case CHECK: + if (state.wrap) { + //=== NEEDBITS(32); + while (bits < 32) { + if (have === 0) { break inf_leave; } + have--; + // Use '|' insdead of '+' to make sure that result is signed + hold |= input[next++] << bits; + bits += 8; + } + //===// + _out -= left; + strm.total_out += _out; + state.total += _out; + if (_out) { + strm.adler = state.check = + /*UPDATE(state.check, put - _out, _out);*/ + (state.flags ? crc32(state.check, output, _out, put - _out) : adler32(state.check, output, _out, put - _out)); + + } + _out = left; + // NB: crc32 stored as signed 32-bit int, ZSWAP32 returns signed too + if ((state.flags ? hold : ZSWAP32(hold)) !== state.check) { + strm.msg = 'incorrect data check'; + state.mode = BAD; + break; + } + //=== INITBITS(); + hold = 0; + bits = 0; + //===// + //Tracev((stderr, "inflate: check matches trailer\n")); + } + state.mode = LENGTH; + /* falls through */ + case LENGTH: + if (state.wrap && state.flags) { + //=== NEEDBITS(32); + while (bits < 32) { + if (have === 0) { break inf_leave; } + have--; + hold += input[next++] << bits; + bits += 8; + } + //===// + if (hold !== (state.total & 0xffffffff)) { + strm.msg = 'incorrect length check'; + state.mode = BAD; + break; + } + //=== INITBITS(); + hold = 0; + bits = 0; + //===// + //Tracev((stderr, "inflate: length matches trailer\n")); + } + state.mode = DONE; + /* falls through */ + case DONE: + ret = Z_STREAM_END; + break inf_leave; + case BAD: + ret = Z_DATA_ERROR; + break inf_leave; + case MEM: + return Z_MEM_ERROR; + case SYNC: + /* falls through */ + default: + return Z_STREAM_ERROR; + } + } + + // inf_leave <- here is real place for "goto inf_leave", emulated via "break inf_leave" + + /* + Return from inflate(), updating the total counts and the check value. + If there was no progress during the inflate() call, return a buffer + error. Call updatewindow() to create and/or update the window state. + Note: a memory error from inflate() is non-recoverable. + */ + + //--- RESTORE() --- + strm.next_out = put; + strm.avail_out = left; + strm.next_in = next; + strm.avail_in = have; + state.hold = hold; + state.bits = bits; + //--- + + if (state.wsize || (_out !== strm.avail_out && state.mode < BAD && + (state.mode < CHECK || flush !== Z_FINISH))) { + if (updatewindow(strm, strm.output, strm.next_out, _out - strm.avail_out)) { + state.mode = MEM; + return Z_MEM_ERROR; + } + } + _in -= strm.avail_in; + _out -= strm.avail_out; + strm.total_in += _in; + strm.total_out += _out; + state.total += _out; + if (state.wrap && _out) { + strm.adler = state.check = /*UPDATE(state.check, strm.next_out - _out, _out);*/ + (state.flags ? crc32(state.check, output, _out, strm.next_out - _out) : adler32(state.check, output, _out, strm.next_out - _out)); + } + strm.data_type = state.bits + (state.last ? 64 : 0) + + (state.mode === TYPE ? 128 : 0) + + (state.mode === LEN_ || state.mode === COPY_ ? 256 : 0); + if (((_in === 0 && _out === 0) || flush === Z_FINISH) && ret === Z_OK) { + ret = Z_BUF_ERROR; + } + return ret; +} + +function inflateEnd(strm) { + + if (!strm || !strm.state /*|| strm->zfree == (free_func)0*/) { + return Z_STREAM_ERROR; + } + + var state = strm.state; + if (state.window) { + state.window = null; + } + strm.state = null; + return Z_OK; +} + +function inflateGetHeader(strm, head) { + var state; + + /* check state */ + if (!strm || !strm.state) { return Z_STREAM_ERROR; } + state = strm.state; + if ((state.wrap & 2) === 0) { return Z_STREAM_ERROR; } + + /* save header structure */ + state.head = head; + head.done = false; + return Z_OK; +} + + +exports.inflateReset = inflateReset; +exports.inflateReset2 = inflateReset2; +exports.inflateResetKeep = inflateResetKeep; +exports.inflateInit = inflateInit; +exports.inflateInit2 = inflateInit2; +exports.inflate = inflate; +exports.inflateEnd = inflateEnd; +exports.inflateGetHeader = inflateGetHeader; +exports.inflateInfo = 'pako inflate (from Nodeca project)'; + +/* Not implemented +exports.inflateCopy = inflateCopy; +exports.inflateGetDictionary = inflateGetDictionary; +exports.inflateMark = inflateMark; +exports.inflatePrime = inflatePrime; +exports.inflateSetDictionary = inflateSetDictionary; +exports.inflateSync = inflateSync; +exports.inflateSyncPoint = inflateSyncPoint; +exports.inflateUndermine = inflateUndermine; +*/ +},{"../utils/common":28,"./adler32":30,"./crc32":32,"./inffast":35,"./inftrees":37}],37:[function(_dereq_,module,exports){ +'use strict'; + + +var utils = _dereq_('../utils/common'); + +var MAXBITS = 15; +var ENOUGH_LENS = 852; +var ENOUGH_DISTS = 592; +//var ENOUGH = (ENOUGH_LENS+ENOUGH_DISTS); + +var CODES = 0; +var LENS = 1; +var DISTS = 2; + +var lbase = [ /* Length codes 257..285 base */ + 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, 0, 0 +]; + +var lext = [ /* Length codes 257..285 extra */ + 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, + 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 78 +]; + +var dbase = [ /* Distance codes 0..29 base */ + 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, 0, 0 +]; + +var dext = [ /* Distance codes 0..29 extra */ + 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, + 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, + 28, 28, 29, 29, 64, 64 +]; + +module.exports = function inflate_table(type, lens, lens_index, codes, table, table_index, work, opts) +{ + var bits = opts.bits; + //here = opts.here; /* table entry for duplication */ + + var len = 0; /* a code's length in bits */ + var sym = 0; /* index of code symbols */ + var min = 0, max = 0; /* minimum and maximum code lengths */ + var root = 0; /* number of index bits for root table */ + var curr = 0; /* number of index bits for current table */ + var drop = 0; /* code bits to drop for sub-table */ + var left = 0; /* number of prefix codes available */ + var used = 0; /* code entries in table used */ + var huff = 0; /* Huffman code */ + var incr; /* for incrementing code, index */ + var fill; /* index for replicating entries */ + var low; /* low bits for current root entry */ + var mask; /* mask for low root bits */ + var next; /* next available space in table */ + var base = null; /* base value table to use */ + var base_index = 0; +// var shoextra; /* extra bits table to use */ + var end; /* use base and extra for symbol > end */ + var count = new utils.Buf16(MAXBITS+1); //[MAXBITS+1]; /* number of codes of each length */ + var offs = new utils.Buf16(MAXBITS+1); //[MAXBITS+1]; /* offsets in table for each length */ + var extra = null; + var extra_index = 0; + + var here_bits, here_op, here_val; + + /* + Process a set of code lengths to create a canonical Huffman code. The + code lengths are lens[0..codes-1]. Each length corresponds to the + symbols 0..codes-1. The Huffman code is generated by first sorting the + symbols by length from short to long, and retaining the symbol order + for codes with equal lengths. Then the code starts with all zero bits + for the first code of the shortest length, and the codes are integer + increments for the same length, and zeros are appended as the length + increases. For the deflate format, these bits are stored backwards + from their more natural integer increment ordering, and so when the + decoding tables are built in the large loop below, the integer codes + are incremented backwards. + + This routine assumes, but does not check, that all of the entries in + lens[] are in the range 0..MAXBITS. The caller must assure this. + 1..MAXBITS is interpreted as that code length. zero means that that + symbol does not occur in this code. + + The codes are sorted by computing a count of codes for each length, + creating from that a table of starting indices for each length in the + sorted table, and then entering the symbols in order in the sorted + table. The sorted table is work[], with that space being provided by + the caller. + + The length counts are used for other purposes as well, i.e. finding + the minimum and maximum length codes, determining if there are any + codes at all, checking for a valid set of lengths, and looking ahead + at length counts to determine sub-table sizes when building the + decoding tables. + */ + + /* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */ + for (len = 0; len <= MAXBITS; len++) { + count[len] = 0; + } + for (sym = 0; sym < codes; sym++) { + count[lens[lens_index + sym]]++; + } + + /* bound code lengths, force root to be within code lengths */ + root = bits; + for (max = MAXBITS; max >= 1; max--) { + if (count[max] !== 0) { break; } + } + if (root > max) { + root = max; + } + if (max === 0) { /* no symbols to code at all */ + //table.op[opts.table_index] = 64; //here.op = (var char)64; /* invalid code marker */ + //table.bits[opts.table_index] = 1; //here.bits = (var char)1; + //table.val[opts.table_index++] = 0; //here.val = (var short)0; + table[table_index++] = (1 << 24) | (64 << 16) | 0; + + + //table.op[opts.table_index] = 64; + //table.bits[opts.table_index] = 1; + //table.val[opts.table_index++] = 0; + table[table_index++] = (1 << 24) | (64 << 16) | 0; + + opts.bits = 1; + return 0; /* no symbols, but wait for decoding to report error */ + } + for (min = 1; min < max; min++) { + if (count[min] !== 0) { break; } + } + if (root < min) { + root = min; + } + + /* check for an over-subscribed or incomplete set of lengths */ + left = 1; + for (len = 1; len <= MAXBITS; len++) { + left <<= 1; + left -= count[len]; + if (left < 0) { + return -1; + } /* over-subscribed */ + } + if (left > 0 && (type === CODES || max !== 1)) { + return -1; /* incomplete set */ + } + + /* generate offsets into symbol table for each length for sorting */ + offs[1] = 0; + for (len = 1; len < MAXBITS; len++) { + offs[len + 1] = offs[len] + count[len]; + } + + /* sort symbols by length, by symbol order within each length */ + for (sym = 0; sym < codes; sym++) { + if (lens[lens_index + sym] !== 0) { + work[offs[lens[lens_index + sym]]++] = sym; + } + } + + /* + Create and fill in decoding tables. In this loop, the table being + filled is at next and has curr index bits. The code being used is huff + with length len. That code is converted to an index by dropping drop + bits off of the bottom. For codes where len is less than drop + curr, + those top drop + curr - len bits are incremented through all values to + fill the table with replicated entries. + + root is the number of index bits for the root table. When len exceeds + root, sub-tables are created pointed to by the root entry with an index + of the low root bits of huff. This is saved in low to check for when a + new sub-table should be started. drop is zero when the root table is + being filled, and drop is root when sub-tables are being filled. + + When a new sub-table is needed, it is necessary to look ahead in the + code lengths to determine what size sub-table is needed. The length + counts are used for this, and so count[] is decremented as codes are + entered in the tables. + + used keeps track of how many table entries have been allocated from the + provided *table space. It is checked for LENS and DIST tables against + the constants ENOUGH_LENS and ENOUGH_DISTS to guard against changes in + the initial root table size constants. See the comments in inftrees.h + for more information. + + sym increments through all symbols, and the loop terminates when + all codes of length max, i.e. all codes, have been processed. This + routine permits incomplete codes, so another loop after this one fills + in the rest of the decoding tables with invalid code markers. + */ + + /* set up for code type */ + switch (type) { + case CODES: + base = extra = work; /* dummy value--not used */ + end = 19; + break; + case LENS: + base = lbase; + base_index -= 257; + extra = lext; + extra_index -= 257; + end = 256; + break; + default: /* DISTS */ + base = dbase; + extra = dext; + end = -1; + } + + /* initialize opts for loop */ + huff = 0; /* starting code */ + sym = 0; /* starting code symbol */ + len = min; /* starting code length */ + next = table_index; /* current table to fill in */ + curr = root; /* current table index bits */ + drop = 0; /* current bits to drop from code for index */ + low = -1; /* trigger new sub-table when len > root */ + used = 1 << root; /* use root table entries */ + mask = used - 1; /* mask for comparing low */ + + /* check available table space */ + if ((type === LENS && used > ENOUGH_LENS) || + (type === DISTS && used > ENOUGH_DISTS)) { + return 1; + } + + var i=0; + /* process all codes and make table entries */ + for (;;) { + i++; + /* create table entry */ + here_bits = len - drop; + if (work[sym] < end) { + here_op = 0; + here_val = work[sym]; + } + else if (work[sym] > end) { + here_op = extra[extra_index + work[sym]]; + here_val = base[base_index + work[sym]]; + } + else { + here_op = 32 + 64; /* end of block */ + here_val = 0; + } + + /* replicate for those indices with low len bits equal to huff */ + incr = 1 << (len - drop); + fill = 1 << curr; + min = fill; /* save offset to next table */ + do { + fill -= incr; + table[next + (huff >> drop) + fill] = (here_bits << 24) | (here_op << 16) | here_val |0; + } while (fill !== 0); + + /* backwards increment the len-bit code huff */ + incr = 1 << (len - 1); + while (huff & incr) { + incr >>= 1; + } + if (incr !== 0) { + huff &= incr - 1; + huff += incr; + } else { + huff = 0; + } + + /* go to next symbol, update count, len */ + sym++; + if (--(count[len]) === 0) { + if (len === max) { break; } + len = lens[lens_index + work[sym]]; + } + + /* create new sub-table if needed */ + if (len > root && (huff & mask) !== low) { + /* if first time, transition to sub-tables */ + if (drop === 0) { + drop = root; + } + + /* increment past last table */ + next += min; /* here min is 1 << curr */ + + /* determine length of next table */ + curr = len - drop; + left = 1 << curr; + while (curr + drop < max) { + left -= count[curr + drop]; + if (left <= 0) { break; } + curr++; + left <<= 1; + } + + /* check for enough space */ + used += 1 << curr; + if ((type === LENS && used > ENOUGH_LENS) || + (type === DISTS && used > ENOUGH_DISTS)) { + return 1; + } + + /* point entry in root table to sub-table */ + low = huff & mask; + /*table.op[low] = curr; + table.bits[low] = root; + table.val[low] = next - opts.table_index;*/ + table[low] = (root << 24) | (curr << 16) | (next - table_index) |0; + } + } + + /* fill in remaining table entry if code is incomplete (guaranteed to have + at most one remaining entry, since if the code is incomplete, the + maximum code length that was allowed to get this far is one bit) */ + if (huff !== 0) { + //table.op[next + huff] = 64; /* invalid code marker */ + //table.bits[next + huff] = len - drop; + //table.val[next + huff] = 0; + table[next + huff] = ((len - drop) << 24) | (64 << 16) |0; + } + + /* set return parameters */ + //opts.table_index += used; + opts.bits = root; + return 0; +}; +},{"../utils/common":28}],38:[function(_dereq_,module,exports){ +'use strict'; + +module.exports = { + '2': 'need dictionary', /* Z_NEED_DICT 2 */ + '1': 'stream end', /* Z_STREAM_END 1 */ + '0': '', /* Z_OK 0 */ + '-1': 'file error', /* Z_ERRNO (-1) */ + '-2': 'stream error', /* Z_STREAM_ERROR (-2) */ + '-3': 'data error', /* Z_DATA_ERROR (-3) */ + '-4': 'insufficient memory', /* Z_MEM_ERROR (-4) */ + '-5': 'buffer error', /* Z_BUF_ERROR (-5) */ + '-6': 'incompatible version' /* Z_VERSION_ERROR (-6) */ +}; +},{}],39:[function(_dereq_,module,exports){ +'use strict'; + + +var utils = _dereq_('../utils/common'); + +/* Public constants ==========================================================*/ +/* ===========================================================================*/ + + +//var Z_FILTERED = 1; +//var Z_HUFFMAN_ONLY = 2; +//var Z_RLE = 3; +var Z_FIXED = 4; +//var Z_DEFAULT_STRATEGY = 0; + +/* Possible values of the data_type field (though see inflate()) */ +var Z_BINARY = 0; +var Z_TEXT = 1; +//var Z_ASCII = 1; // = Z_TEXT +var Z_UNKNOWN = 2; + +/*============================================================================*/ + + +function zero(buf) { var len = buf.length; while (--len >= 0) { buf[len] = 0; } } + +// From zutil.h + +var STORED_BLOCK = 0; +var STATIC_TREES = 1; +var DYN_TREES = 2; +/* The three kinds of block type */ + +var MIN_MATCH = 3; +var MAX_MATCH = 258; +/* The minimum and maximum match lengths */ + +// From deflate.h +/* =========================================================================== + * Internal compression state. + */ + +var LENGTH_CODES = 29; +/* number of length codes, not counting the special END_BLOCK code */ + +var LITERALS = 256; +/* number of literal bytes 0..255 */ + +var L_CODES = LITERALS + 1 + LENGTH_CODES; +/* number of Literal or Length codes, including the END_BLOCK code */ + +var D_CODES = 30; +/* number of distance codes */ + +var BL_CODES = 19; +/* number of codes used to transfer the bit lengths */ + +var HEAP_SIZE = 2*L_CODES + 1; +/* maximum heap size */ + +var MAX_BITS = 15; +/* All codes must not exceed MAX_BITS bits */ + +var Buf_size = 16; +/* size of bit buffer in bi_buf */ + + +/* =========================================================================== + * Constants + */ + +var MAX_BL_BITS = 7; +/* Bit length codes must not exceed MAX_BL_BITS bits */ + +var END_BLOCK = 256; +/* end of block literal code */ + +var REP_3_6 = 16; +/* repeat previous bit length 3-6 times (2 bits of repeat count) */ + +var REPZ_3_10 = 17; +/* repeat a zero length 3-10 times (3 bits of repeat count) */ + +var REPZ_11_138 = 18; +/* repeat a zero length 11-138 times (7 bits of repeat count) */ + +var extra_lbits = /* extra bits for each length code */ + [0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]; + +var extra_dbits = /* extra bits for each distance code */ + [0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]; + +var extra_blbits = /* extra bits for each bit length code */ + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]; + +var bl_order = + [16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]; +/* The lengths of the bit length codes are sent in order of decreasing + * probability, to avoid transmitting the lengths for unused bit length codes. + */ + +/* =========================================================================== + * Local data. These are initialized only once. + */ + +// We pre-fill arrays with 0 to avoid uninitialized gaps + +var DIST_CODE_LEN = 512; /* see definition of array dist_code below */ + +// !!!! Use flat array insdead of structure, Freq = i*2, Len = i*2+1 +var static_ltree = new Array((L_CODES+2) * 2); +zero(static_ltree); +/* The static literal tree. Since the bit lengths are imposed, there is no + * need for the L_CODES extra codes used during heap construction. However + * The codes 286 and 287 are needed to build a canonical tree (see _tr_init + * below). + */ + +var static_dtree = new Array(D_CODES * 2); +zero(static_dtree); +/* The static distance tree. (Actually a trivial tree since all codes use + * 5 bits.) + */ + +var _dist_code = new Array(DIST_CODE_LEN); +zero(_dist_code); +/* Distance codes. The first 256 values correspond to the distances + * 3 .. 258, the last 256 values correspond to the top 8 bits of + * the 15 bit distances. + */ + +var _length_code = new Array(MAX_MATCH-MIN_MATCH+1); +zero(_length_code); +/* length code for each normalized match length (0 == MIN_MATCH) */ + +var base_length = new Array(LENGTH_CODES); +zero(base_length); +/* First normalized length for each code (0 = MIN_MATCH) */ + +var base_dist = new Array(D_CODES); +zero(base_dist); +/* First normalized distance for each code (0 = distance of 1) */ + + +var StaticTreeDesc = function (static_tree, extra_bits, extra_base, elems, max_length) { + + this.static_tree = static_tree; /* static tree or NULL */ + this.extra_bits = extra_bits; /* extra bits for each code or NULL */ + this.extra_base = extra_base; /* base index for extra_bits */ + this.elems = elems; /* max number of elements in the tree */ + this.max_length = max_length; /* max bit length for the codes */ + + // show if `static_tree` has data or dummy - needed for monomorphic objects + this.has_stree = static_tree && static_tree.length; +}; + + +var static_l_desc; +var static_d_desc; +var static_bl_desc; + + +var TreeDesc = function(dyn_tree, stat_desc) { + this.dyn_tree = dyn_tree; /* the dynamic tree */ + this.max_code = 0; /* largest code with non zero frequency */ + this.stat_desc = stat_desc; /* the corresponding static tree */ +}; + + + +function d_code(dist) { + return dist < 256 ? _dist_code[dist] : _dist_code[256 + (dist >>> 7)]; +} + + +/* =========================================================================== + * Output a short LSB first on the stream. + * IN assertion: there is enough room in pendingBuf. + */ +function put_short (s, w) { +// put_byte(s, (uch)((w) & 0xff)); +// put_byte(s, (uch)((ush)(w) >> 8)); + s.pending_buf[s.pending++] = (w) & 0xff; + s.pending_buf[s.pending++] = (w >>> 8) & 0xff; +} + + +/* =========================================================================== + * Send a value on a given number of bits. + * IN assertion: length <= 16 and value fits in length bits. + */ +function send_bits(s, value, length) { + if (s.bi_valid > (Buf_size - length)) { + s.bi_buf |= (value << s.bi_valid) & 0xffff; + put_short(s, s.bi_buf); + s.bi_buf = value >> (Buf_size - s.bi_valid); + s.bi_valid += length - Buf_size; + } else { + s.bi_buf |= (value << s.bi_valid) & 0xffff; + s.bi_valid += length; + } +} + + +function send_code(s, c, tree) { + send_bits(s, tree[c*2]/*.Code*/, tree[c*2 + 1]/*.Len*/); +} + + +/* =========================================================================== + * Reverse the first len bits of a code, using straightforward code (a faster + * method would use a table) + * IN assertion: 1 <= len <= 15 + */ +function bi_reverse(code, len) { + var res = 0; + do { + res |= code & 1; + code >>>= 1; + res <<= 1; + } while (--len > 0); + return res >>> 1; +} + + +/* =========================================================================== + * Flush the bit buffer, keeping at most 7 bits in it. + */ +function bi_flush(s) { + if (s.bi_valid === 16) { + put_short(s, s.bi_buf); + s.bi_buf = 0; + s.bi_valid = 0; + + } else if (s.bi_valid >= 8) { + s.pending_buf[s.pending++] = s.bi_buf & 0xff; + s.bi_buf >>= 8; + s.bi_valid -= 8; + } +} + + +/* =========================================================================== + * Compute the optimal bit lengths for a tree and update the total bit length + * for the current block. + * IN assertion: the fields freq and dad are set, heap[heap_max] and + * above are the tree nodes sorted by increasing frequency. + * OUT assertions: the field len is set to the optimal bit length, the + * array bl_count contains the frequencies for each bit length. + * The length opt_len is updated; static_len is also updated if stree is + * not null. + */ +function gen_bitlen(s, desc) +// deflate_state *s; +// tree_desc *desc; /* the tree descriptor */ +{ + var tree = desc.dyn_tree; + var max_code = desc.max_code; + var stree = desc.stat_desc.static_tree; + var has_stree = desc.stat_desc.has_stree; + var extra = desc.stat_desc.extra_bits; + var base = desc.stat_desc.extra_base; + var max_length = desc.stat_desc.max_length; + var h; /* heap index */ + var n, m; /* iterate over the tree elements */ + var bits; /* bit length */ + var xbits; /* extra bits */ + var f; /* frequency */ + var overflow = 0; /* number of elements with bit length too large */ + + for (bits = 0; bits <= MAX_BITS; bits++) { + s.bl_count[bits] = 0; + } + + /* In a first pass, compute the optimal bit lengths (which may + * overflow in the case of the bit length tree). + */ + tree[s.heap[s.heap_max]*2 + 1]/*.Len*/ = 0; /* root of the heap */ + + for (h = s.heap_max+1; h < HEAP_SIZE; h++) { + n = s.heap[h]; + bits = tree[tree[n*2 +1]/*.Dad*/ * 2 + 1]/*.Len*/ + 1; + if (bits > max_length) { + bits = max_length; + overflow++; + } + tree[n*2 + 1]/*.Len*/ = bits; + /* We overwrite tree[n].Dad which is no longer needed */ + + if (n > max_code) { continue; } /* not a leaf node */ + + s.bl_count[bits]++; + xbits = 0; + if (n >= base) { + xbits = extra[n-base]; + } + f = tree[n * 2]/*.Freq*/; + s.opt_len += f * (bits + xbits); + if (has_stree) { + s.static_len += f * (stree[n*2 + 1]/*.Len*/ + xbits); + } + } + if (overflow === 0) { return; } + + // Trace((stderr,"\nbit length overflow\n")); + /* This happens for example on obj2 and pic of the Calgary corpus */ + + /* Find the first bit length which could increase: */ + do { + bits = max_length-1; + while (s.bl_count[bits] === 0) { bits--; } + s.bl_count[bits]--; /* move one leaf down the tree */ + s.bl_count[bits+1] += 2; /* move one overflow item as its brother */ + s.bl_count[max_length]--; + /* The brother of the overflow item also moves one step up, + * but this does not affect bl_count[max_length] + */ + overflow -= 2; + } while (overflow > 0); + + /* Now recompute all bit lengths, scanning in increasing frequency. + * h is still equal to HEAP_SIZE. (It is simpler to reconstruct all + * lengths instead of fixing only the wrong ones. This idea is taken + * from 'ar' written by Haruhiko Okumura.) + */ + for (bits = max_length; bits !== 0; bits--) { + n = s.bl_count[bits]; + while (n !== 0) { + m = s.heap[--h]; + if (m > max_code) { continue; } + if (tree[m*2 + 1]/*.Len*/ !== bits) { + // Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits)); + s.opt_len += (bits - tree[m*2 + 1]/*.Len*/)*tree[m*2]/*.Freq*/; + tree[m*2 + 1]/*.Len*/ = bits; + } + n--; + } + } +} + + +/* =========================================================================== + * Generate the codes for a given tree and bit counts (which need not be + * optimal). + * IN assertion: the array bl_count contains the bit length statistics for + * the given tree and the field len is set for all tree elements. + * OUT assertion: the field code is set for all tree elements of non + * zero code length. + */ +function gen_codes(tree, max_code, bl_count) +// ct_data *tree; /* the tree to decorate */ +// int max_code; /* largest code with non zero frequency */ +// ushf *bl_count; /* number of codes at each bit length */ +{ + var next_code = new Array(MAX_BITS+1); /* next code value for each bit length */ + var code = 0; /* running code value */ + var bits; /* bit index */ + var n; /* code index */ + + /* The distribution counts are first used to generate the code values + * without bit reversal. + */ + for (bits = 1; bits <= MAX_BITS; bits++) { + next_code[bits] = code = (code + bl_count[bits-1]) << 1; + } + /* Check that the bit counts in bl_count are consistent. The last code + * must be all ones. + */ + //Assert (code + bl_count[MAX_BITS]-1 == (1< length code (0..28) */ + length = 0; + for (code = 0; code < LENGTH_CODES-1; code++) { + base_length[code] = length; + for (n = 0; n < (1< dist code (0..29) */ + dist = 0; + for (code = 0 ; code < 16; code++) { + base_dist[code] = dist; + for (n = 0; n < (1<>= 7; /* from now on, all distances are divided by 128 */ + for ( ; code < D_CODES; code++) { + base_dist[code] = dist << 7; + for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) { + _dist_code[256 + dist++] = code; + } + } + //Assert (dist == 256, "tr_static_init: 256+dist != 512"); + + /* Construct the codes of the static literal tree */ + for (bits = 0; bits <= MAX_BITS; bits++) { + bl_count[bits] = 0; + } + + n = 0; + while (n <= 143) { + static_ltree[n*2 + 1]/*.Len*/ = 8; + n++; + bl_count[8]++; + } + while (n <= 255) { + static_ltree[n*2 + 1]/*.Len*/ = 9; + n++; + bl_count[9]++; + } + while (n <= 279) { + static_ltree[n*2 + 1]/*.Len*/ = 7; + n++; + bl_count[7]++; + } + while (n <= 287) { + static_ltree[n*2 + 1]/*.Len*/ = 8; + n++; + bl_count[8]++; + } + /* Codes 286 and 287 do not exist, but we must include them in the + * tree construction to get a canonical Huffman tree (longest code + * all ones) + */ + gen_codes(static_ltree, L_CODES+1, bl_count); + + /* The static distance tree is trivial: */ + for (n = 0; n < D_CODES; n++) { + static_dtree[n*2 + 1]/*.Len*/ = 5; + static_dtree[n*2]/*.Code*/ = bi_reverse(n, 5); + } + + // Now data ready and we can init static trees + static_l_desc = new StaticTreeDesc(static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS); + static_d_desc = new StaticTreeDesc(static_dtree, extra_dbits, 0, D_CODES, MAX_BITS); + static_bl_desc =new StaticTreeDesc(new Array(0), extra_blbits, 0, BL_CODES, MAX_BL_BITS); + + //static_init_done = true; +} + + +/* =========================================================================== + * Initialize a new block. + */ +function init_block(s) { + var n; /* iterates over tree elements */ + + /* Initialize the trees. */ + for (n = 0; n < L_CODES; n++) { s.dyn_ltree[n*2]/*.Freq*/ = 0; } + for (n = 0; n < D_CODES; n++) { s.dyn_dtree[n*2]/*.Freq*/ = 0; } + for (n = 0; n < BL_CODES; n++) { s.bl_tree[n*2]/*.Freq*/ = 0; } + + s.dyn_ltree[END_BLOCK*2]/*.Freq*/ = 1; + s.opt_len = s.static_len = 0; + s.last_lit = s.matches = 0; +} + + +/* =========================================================================== + * Flush the bit buffer and align the output on a byte boundary + */ +function bi_windup(s) +{ + if (s.bi_valid > 8) { + put_short(s, s.bi_buf); + } else if (s.bi_valid > 0) { + //put_byte(s, (Byte)s->bi_buf); + s.pending_buf[s.pending++] = s.bi_buf; + } + s.bi_buf = 0; + s.bi_valid = 0; +} + +/* =========================================================================== + * Copy a stored block, storing first the length and its + * one's complement if requested. + */ +function copy_block(s, buf, len, header) +//DeflateState *s; +//charf *buf; /* the input data */ +//unsigned len; /* its length */ +//int header; /* true if block header must be written */ +{ + bi_windup(s); /* align on byte boundary */ + + if (header) { + put_short(s, len); + put_short(s, ~len); + } +// while (len--) { +// put_byte(s, *buf++); +// } + utils.arraySet(s.pending_buf, s.window, buf, len, s.pending); + s.pending += len; +} + +/* =========================================================================== + * Compares to subtrees, using the tree depth as tie breaker when + * the subtrees have equal frequency. This minimizes the worst case length. + */ +function smaller(tree, n, m, depth) { + var _n2 = n*2; + var _m2 = m*2; + return (tree[_n2]/*.Freq*/ < tree[_m2]/*.Freq*/ || + (tree[_n2]/*.Freq*/ === tree[_m2]/*.Freq*/ && depth[n] <= depth[m])); +} + +/* =========================================================================== + * Restore the heap property by moving down the tree starting at node k, + * exchanging a node with the smallest of its two sons if necessary, stopping + * when the heap property is re-established (each father smaller than its + * two sons). + */ +function pqdownheap(s, tree, k) +// deflate_state *s; +// ct_data *tree; /* the tree to restore */ +// int k; /* node to move down */ +{ + var v = s.heap[k]; + var j = k << 1; /* left son of k */ + while (j <= s.heap_len) { + /* Set j to the smallest of the two sons: */ + if (j < s.heap_len && + smaller(tree, s.heap[j+1], s.heap[j], s.depth)) { + j++; + } + /* Exit if v is smaller than both sons */ + if (smaller(tree, v, s.heap[j], s.depth)) { break; } + + /* Exchange v with the smallest son */ + s.heap[k] = s.heap[j]; + k = j; + + /* And continue down the tree, setting j to the left son of k */ + j <<= 1; + } + s.heap[k] = v; +} + + +// inlined manually +// var SMALLEST = 1; + +/* =========================================================================== + * Send the block data compressed using the given Huffman trees + */ +function compress_block(s, ltree, dtree) +// deflate_state *s; +// const ct_data *ltree; /* literal tree */ +// const ct_data *dtree; /* distance tree */ +{ + var dist; /* distance of matched string */ + var lc; /* match length or unmatched char (if dist == 0) */ + var lx = 0; /* running index in l_buf */ + var code; /* the code to send */ + var extra; /* number of extra bits to send */ + + if (s.last_lit !== 0) { + do { + dist = (s.pending_buf[s.d_buf + lx*2] << 8) | (s.pending_buf[s.d_buf + lx*2 + 1]); + lc = s.pending_buf[s.l_buf + lx]; + lx++; + + if (dist === 0) { + send_code(s, lc, ltree); /* send a literal byte */ + //Tracecv(isgraph(lc), (stderr," '%c' ", lc)); + } else { + /* Here, lc is the match length - MIN_MATCH */ + code = _length_code[lc]; + send_code(s, code+LITERALS+1, ltree); /* send the length code */ + extra = extra_lbits[code]; + if (extra !== 0) { + lc -= base_length[code]; + send_bits(s, lc, extra); /* send the extra length bits */ + } + dist--; /* dist is now the match distance - 1 */ + code = d_code(dist); + //Assert (code < D_CODES, "bad d_code"); + + send_code(s, code, dtree); /* send the distance code */ + extra = extra_dbits[code]; + if (extra !== 0) { + dist -= base_dist[code]; + send_bits(s, dist, extra); /* send the extra distance bits */ + } + } /* literal or match pair ? */ + + /* Check that the overlay between pending_buf and d_buf+l_buf is ok: */ + //Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx, + // "pendingBuf overflow"); + + } while (lx < s.last_lit); + } + + send_code(s, END_BLOCK, ltree); +} + + +/* =========================================================================== + * Construct one Huffman tree and assigns the code bit strings and lengths. + * Update the total bit length for the current block. + * IN assertion: the field freq is set for all tree elements. + * OUT assertions: the fields len and code are set to the optimal bit length + * and corresponding code. The length opt_len is updated; static_len is + * also updated if stree is not null. The field max_code is set. + */ +function build_tree(s, desc) +// deflate_state *s; +// tree_desc *desc; /* the tree descriptor */ +{ + var tree = desc.dyn_tree; + var stree = desc.stat_desc.static_tree; + var has_stree = desc.stat_desc.has_stree; + var elems = desc.stat_desc.elems; + var n, m; /* iterate over heap elements */ + var max_code = -1; /* largest code with non zero frequency */ + var node; /* new node being created */ + + /* Construct the initial heap, with least frequent element in + * heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n+1]. + * heap[0] is not used. + */ + s.heap_len = 0; + s.heap_max = HEAP_SIZE; + + for (n = 0; n < elems; n++) { + if (tree[n * 2]/*.Freq*/ !== 0) { + s.heap[++s.heap_len] = max_code = n; + s.depth[n] = 0; + + } else { + tree[n*2 + 1]/*.Len*/ = 0; + } + } + + /* The pkzip format requires that at least one distance code exists, + * and that at least one bit should be sent even if there is only one + * possible code. So to avoid special checks later on we force at least + * two codes of non zero frequency. + */ + while (s.heap_len < 2) { + node = s.heap[++s.heap_len] = (max_code < 2 ? ++max_code : 0); + tree[node * 2]/*.Freq*/ = 1; + s.depth[node] = 0; + s.opt_len--; + + if (has_stree) { + s.static_len -= stree[node*2 + 1]/*.Len*/; + } + /* node is 0 or 1 so it does not have extra bits */ + } + desc.max_code = max_code; + + /* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree, + * establish sub-heaps of increasing lengths: + */ + for (n = (s.heap_len >> 1/*int /2*/); n >= 1; n--) { pqdownheap(s, tree, n); } + + /* Construct the Huffman tree by repeatedly combining the least two + * frequent nodes. + */ + node = elems; /* next internal node of the tree */ + do { + //pqremove(s, tree, n); /* n = node of least frequency */ + /*** pqremove ***/ + n = s.heap[1/*SMALLEST*/]; + s.heap[1/*SMALLEST*/] = s.heap[s.heap_len--]; + pqdownheap(s, tree, 1/*SMALLEST*/); + /***/ + + m = s.heap[1/*SMALLEST*/]; /* m = node of next least frequency */ + + s.heap[--s.heap_max] = n; /* keep the nodes sorted by frequency */ + s.heap[--s.heap_max] = m; + + /* Create a new node father of n and m */ + tree[node * 2]/*.Freq*/ = tree[n * 2]/*.Freq*/ + tree[m * 2]/*.Freq*/; + s.depth[node] = (s.depth[n] >= s.depth[m] ? s.depth[n] : s.depth[m]) + 1; + tree[n*2 + 1]/*.Dad*/ = tree[m*2 + 1]/*.Dad*/ = node; + + /* and insert the new node in the heap */ + s.heap[1/*SMALLEST*/] = node++; + pqdownheap(s, tree, 1/*SMALLEST*/); + + } while (s.heap_len >= 2); + + s.heap[--s.heap_max] = s.heap[1/*SMALLEST*/]; + + /* At this point, the fields freq and dad are set. We can now + * generate the bit lengths. + */ + gen_bitlen(s, desc); + + /* The field len is now set, we can generate the bit codes */ + gen_codes(tree, max_code, s.bl_count); +} + + +/* =========================================================================== + * Scan a literal or distance tree to determine the frequencies of the codes + * in the bit length tree. + */ +function scan_tree(s, tree, max_code) +// deflate_state *s; +// ct_data *tree; /* the tree to be scanned */ +// int max_code; /* and its largest code of non zero frequency */ +{ + var n; /* iterates over all tree elements */ + var prevlen = -1; /* last emitted length */ + var curlen; /* length of current code */ + + var nextlen = tree[0*2 + 1]/*.Len*/; /* length of next code */ + + var count = 0; /* repeat count of the current code */ + var max_count = 7; /* max repeat count */ + var min_count = 4; /* min repeat count */ + + if (nextlen === 0) { + max_count = 138; + min_count = 3; + } + tree[(max_code+1)*2 + 1]/*.Len*/ = 0xffff; /* guard */ + + for (n = 0; n <= max_code; n++) { + curlen = nextlen; + nextlen = tree[(n+1)*2 + 1]/*.Len*/; + + if (++count < max_count && curlen === nextlen) { + continue; + + } else if (count < min_count) { + s.bl_tree[curlen * 2]/*.Freq*/ += count; + + } else if (curlen !== 0) { + + if (curlen !== prevlen) { s.bl_tree[curlen * 2]/*.Freq*/++; } + s.bl_tree[REP_3_6*2]/*.Freq*/++; + + } else if (count <= 10) { + s.bl_tree[REPZ_3_10*2]/*.Freq*/++; + + } else { + s.bl_tree[REPZ_11_138*2]/*.Freq*/++; + } + + count = 0; + prevlen = curlen; + + if (nextlen === 0) { + max_count = 138; + min_count = 3; + + } else if (curlen === nextlen) { + max_count = 6; + min_count = 3; + + } else { + max_count = 7; + min_count = 4; + } + } +} + + +/* =========================================================================== + * Send a literal or distance tree in compressed form, using the codes in + * bl_tree. + */ +function send_tree(s, tree, max_code) +// deflate_state *s; +// ct_data *tree; /* the tree to be scanned */ +// int max_code; /* and its largest code of non zero frequency */ +{ + var n; /* iterates over all tree elements */ + var prevlen = -1; /* last emitted length */ + var curlen; /* length of current code */ + + var nextlen = tree[0*2 + 1]/*.Len*/; /* length of next code */ + + var count = 0; /* repeat count of the current code */ + var max_count = 7; /* max repeat count */ + var min_count = 4; /* min repeat count */ + + /* tree[max_code+1].Len = -1; */ /* guard already set */ + if (nextlen === 0) { + max_count = 138; + min_count = 3; + } + + for (n = 0; n <= max_code; n++) { + curlen = nextlen; + nextlen = tree[(n+1)*2 + 1]/*.Len*/; + + if (++count < max_count && curlen === nextlen) { + continue; + + } else if (count < min_count) { + do { send_code(s, curlen, s.bl_tree); } while (--count !== 0); + + } else if (curlen !== 0) { + if (curlen !== prevlen) { + send_code(s, curlen, s.bl_tree); + count--; + } + //Assert(count >= 3 && count <= 6, " 3_6?"); + send_code(s, REP_3_6, s.bl_tree); + send_bits(s, count-3, 2); + + } else if (count <= 10) { + send_code(s, REPZ_3_10, s.bl_tree); + send_bits(s, count-3, 3); + + } else { + send_code(s, REPZ_11_138, s.bl_tree); + send_bits(s, count-11, 7); + } + + count = 0; + prevlen = curlen; + if (nextlen === 0) { + max_count = 138; + min_count = 3; + + } else if (curlen === nextlen) { + max_count = 6; + min_count = 3; + + } else { + max_count = 7; + min_count = 4; + } + } +} + + +/* =========================================================================== + * Construct the Huffman tree for the bit lengths and return the index in + * bl_order of the last bit length code to send. + */ +function build_bl_tree(s) { + var max_blindex; /* index of last bit length code of non zero freq */ + + /* Determine the bit length frequencies for literal and distance trees */ + scan_tree(s, s.dyn_ltree, s.l_desc.max_code); + scan_tree(s, s.dyn_dtree, s.d_desc.max_code); + + /* Build the bit length tree: */ + build_tree(s, s.bl_desc); + /* opt_len now includes the length of the tree representations, except + * the lengths of the bit lengths codes and the 5+5+4 bits for the counts. + */ + + /* Determine the number of bit length codes to send. The pkzip format + * requires that at least 4 bit length codes be sent. (appnote.txt says + * 3 but the actual value used is 4.) + */ + for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) { + if (s.bl_tree[bl_order[max_blindex]*2 + 1]/*.Len*/ !== 0) { + break; + } + } + /* Update opt_len to include the bit length tree and counts */ + s.opt_len += 3*(max_blindex+1) + 5+5+4; + //Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld", + // s->opt_len, s->static_len)); + + return max_blindex; +} + + +/* =========================================================================== + * Send the header for a block using dynamic Huffman trees: the counts, the + * lengths of the bit length codes, the literal tree and the distance tree. + * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4. + */ +function send_all_trees(s, lcodes, dcodes, blcodes) +// deflate_state *s; +// int lcodes, dcodes, blcodes; /* number of codes for each tree */ +{ + var rank; /* index in bl_order */ + + //Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes"); + //Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES, + // "too many codes"); + //Tracev((stderr, "\nbl counts: ")); + send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */ + send_bits(s, dcodes-1, 5); + send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */ + for (rank = 0; rank < blcodes; rank++) { + //Tracev((stderr, "\nbl code %2d ", bl_order[rank])); + send_bits(s, s.bl_tree[bl_order[rank]*2 + 1]/*.Len*/, 3); + } + //Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent)); + + send_tree(s, s.dyn_ltree, lcodes-1); /* literal tree */ + //Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent)); + + send_tree(s, s.dyn_dtree, dcodes-1); /* distance tree */ + //Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent)); +} + + +/* =========================================================================== + * Check if the data type is TEXT or BINARY, using the following algorithm: + * - TEXT if the two conditions below are satisfied: + * a) There are no non-portable control characters belonging to the + * "black list" (0..6, 14..25, 28..31). + * b) There is at least one printable character belonging to the + * "white list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255). + * - BINARY otherwise. + * - The following partially-portable control characters form a + * "gray list" that is ignored in this detection algorithm: + * (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}). + * IN assertion: the fields Freq of dyn_ltree are set. + */ +function detect_data_type(s) { + /* black_mask is the bit mask of black-listed bytes + * set bits 0..6, 14..25, and 28..31 + * 0xf3ffc07f = binary 11110011111111111100000001111111 + */ + var black_mask = 0xf3ffc07f; + var n; + + /* Check for non-textual ("black-listed") bytes. */ + for (n = 0; n <= 31; n++, black_mask >>>= 1) { + if ((black_mask & 1) && (s.dyn_ltree[n*2]/*.Freq*/ !== 0)) { + return Z_BINARY; + } + } + + /* Check for textual ("white-listed") bytes. */ + if (s.dyn_ltree[9 * 2]/*.Freq*/ !== 0 || s.dyn_ltree[10 * 2]/*.Freq*/ !== 0 || + s.dyn_ltree[13 * 2]/*.Freq*/ !== 0) { + return Z_TEXT; + } + for (n = 32; n < LITERALS; n++) { + if (s.dyn_ltree[n * 2]/*.Freq*/ !== 0) { + return Z_TEXT; + } + } + + /* There are no "black-listed" or "white-listed" bytes: + * this stream either is empty or has tolerated ("gray-listed") bytes only. + */ + return Z_BINARY; +} + + +var static_init_done = false; + +/* =========================================================================== + * Initialize the tree data structures for a new zlib stream. + */ +function _tr_init(s) +{ + + if (!static_init_done) { + tr_static_init(); + static_init_done = true; + } + + s.l_desc = new TreeDesc(s.dyn_ltree, static_l_desc); + s.d_desc = new TreeDesc(s.dyn_dtree, static_d_desc); + s.bl_desc = new TreeDesc(s.bl_tree, static_bl_desc); + + s.bi_buf = 0; + s.bi_valid = 0; + + /* Initialize the first block of the first file: */ + init_block(s); +} + + +/* =========================================================================== + * Send a stored block + */ +function _tr_stored_block(s, buf, stored_len, last) +//DeflateState *s; +//charf *buf; /* input block */ +//ulg stored_len; /* length of input block */ +//int last; /* one if this is the last block for a file */ +{ + send_bits(s, (STORED_BLOCK<<1)+(last ? 1 : 0), 3); /* send block type */ + copy_block(s, buf, stored_len, true); /* with header */ +} + + +/* =========================================================================== + * Send one empty static block to give enough lookahead for inflate. + * This takes 10 bits, of which 7 may remain in the bit buffer. + */ +function _tr_align(s) { + send_bits(s, STATIC_TREES<<1, 3); + send_code(s, END_BLOCK, static_ltree); + bi_flush(s); +} + + +/* =========================================================================== + * Determine the best encoding for the current block: dynamic trees, static + * trees or store, and output the encoded block to the zip file. + */ +function _tr_flush_block(s, buf, stored_len, last) +//DeflateState *s; +//charf *buf; /* input block, or NULL if too old */ +//ulg stored_len; /* length of input block */ +//int last; /* one if this is the last block for a file */ +{ + var opt_lenb, static_lenb; /* opt_len and static_len in bytes */ + var max_blindex = 0; /* index of last bit length code of non zero freq */ + + /* Build the Huffman trees unless a stored block is forced */ + if (s.level > 0) { + + /* Check if the file is binary or text */ + if (s.strm.data_type === Z_UNKNOWN) { + s.strm.data_type = detect_data_type(s); + } + + /* Construct the literal and distance trees */ + build_tree(s, s.l_desc); + // Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len, + // s->static_len)); + + build_tree(s, s.d_desc); + // Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len, + // s->static_len)); + /* At this point, opt_len and static_len are the total bit lengths of + * the compressed block data, excluding the tree representations. + */ + + /* Build the bit length tree for the above two trees, and get the index + * in bl_order of the last bit length code to send. + */ + max_blindex = build_bl_tree(s); + + /* Determine the best encoding. Compute the block lengths in bytes. */ + opt_lenb = (s.opt_len+3+7) >>> 3; + static_lenb = (s.static_len+3+7) >>> 3; + + // Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ", + // opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len, + // s->last_lit)); + + if (static_lenb <= opt_lenb) { opt_lenb = static_lenb; } + + } else { + // Assert(buf != (char*)0, "lost buf"); + opt_lenb = static_lenb = stored_len + 5; /* force a stored block */ + } + + if ((stored_len+4 <= opt_lenb) && (buf !== -1)) { + /* 4: two words for the lengths */ + + /* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE. + * Otherwise we can't have processed more than WSIZE input bytes since + * the last block flush, because compression would have been + * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to + * transform a block into a stored block. + */ + _tr_stored_block(s, buf, stored_len, last); + + } else if (s.strategy === Z_FIXED || static_lenb === opt_lenb) { + + send_bits(s, (STATIC_TREES<<1) + (last ? 1 : 0), 3); + compress_block(s, static_ltree, static_dtree); + + } else { + send_bits(s, (DYN_TREES<<1) + (last ? 1 : 0), 3); + send_all_trees(s, s.l_desc.max_code+1, s.d_desc.max_code+1, max_blindex+1); + compress_block(s, s.dyn_ltree, s.dyn_dtree); + } + // Assert (s->compressed_len == s->bits_sent, "bad compressed size"); + /* The above check is made mod 2^32, for files larger than 512 MB + * and uLong implemented on 32 bits. + */ + init_block(s); + + if (last) { + bi_windup(s); + } + // Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3, + // s->compressed_len-7*last)); +} + +/* =========================================================================== + * Save the match info and tally the frequency counts. Return true if + * the current block must be flushed. + */ +function _tr_tally(s, dist, lc) +// deflate_state *s; +// unsigned dist; /* distance of matched string */ +// unsigned lc; /* match length-MIN_MATCH or unmatched char (if dist==0) */ +{ + //var out_length, in_length, dcode; + + s.pending_buf[s.d_buf + s.last_lit * 2] = (dist >>> 8) & 0xff; + s.pending_buf[s.d_buf + s.last_lit * 2 + 1] = dist & 0xff; + + s.pending_buf[s.l_buf + s.last_lit] = lc & 0xff; + s.last_lit++; + + if (dist === 0) { + /* lc is the unmatched char */ + s.dyn_ltree[lc*2]/*.Freq*/++; + } else { + s.matches++; + /* Here, lc is the match length - MIN_MATCH */ + dist--; /* dist = match distance - 1 */ + //Assert((ush)dist < (ush)MAX_DIST(s) && + // (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) && + // (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match"); + + s.dyn_ltree[(_length_code[lc]+LITERALS+1) * 2]/*.Freq*/++; + s.dyn_dtree[d_code(dist) * 2]/*.Freq*/++; + } + +// (!) This block is disabled in zlib defailts, +// don't enable it for binary compatibility + +//#ifdef TRUNCATE_BLOCK +// /* Try to guess if it is profitable to stop the current block here */ +// if ((s.last_lit & 0x1fff) === 0 && s.level > 2) { +// /* Compute an upper bound for the compressed length */ +// out_length = s.last_lit*8; +// in_length = s.strstart - s.block_start; +// +// for (dcode = 0; dcode < D_CODES; dcode++) { +// out_length += s.dyn_dtree[dcode*2]/*.Freq*/ * (5 + extra_dbits[dcode]); +// } +// out_length >>>= 3; +// //Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ", +// // s->last_lit, in_length, out_length, +// // 100L - out_length*100L/in_length)); +// if (s.matches < (s.last_lit>>1)/*int /2*/ && out_length < (in_length>>1)/*int /2*/) { +// return true; +// } +// } +//#endif + + return (s.last_lit === s.lit_bufsize-1); + /* We avoid equality with lit_bufsize because of wraparound at 64K + * on 16 bit machines and because stored blocks are restricted to + * 64K-1 bytes. + */ +} + +exports._tr_init = _tr_init; +exports._tr_stored_block = _tr_stored_block; +exports._tr_flush_block = _tr_flush_block; +exports._tr_tally = _tr_tally; +exports._tr_align = _tr_align; +},{"../utils/common":28}],40:[function(_dereq_,module,exports){ +'use strict'; + + +function ZStream() { + /* next input byte */ + this.input = null; // JS specific, because we have no pointers + this.next_in = 0; + /* number of bytes available at input */ + this.avail_in = 0; + /* total number of input bytes read so far */ + this.total_in = 0; + /* next output byte should be put there */ + this.output = null; // JS specific, because we have no pointers + this.next_out = 0; + /* remaining free space at output */ + this.avail_out = 0; + /* total number of bytes output so far */ + this.total_out = 0; + /* last error message, NULL if no error */ + this.msg = ''/*Z_NULL*/; + /* not visible by applications */ + this.state = null; + /* best guess about the data type: binary or text */ + this.data_type = 2/*Z_UNKNOWN*/; + /* adler32 value of the uncompressed data */ + this.adler = 0; +} + +module.exports = ZStream; +},{}],41:[function(_dereq_,module,exports){ var O_READ = 'READ'; var O_WRITE = 'WRITE'; var O_CREATE = 'CREATE'; @@ -2274,7 +10671,7 @@ module.exports = { } }; -},{}],9:[function(_dereq_,module,exports){ +},{}],42:[function(_dereq_,module,exports){ var MODE_FILE = _dereq_('./constants.js').MODE_FILE; module.exports = function DirectoryEntry(id, type) { @@ -2282,7 +10679,24 @@ module.exports = function DirectoryEntry(id, type) { this.type = type || MODE_FILE; }; -},{"./constants.js":8}],10:[function(_dereq_,module,exports){ +},{"./constants.js":41}],43:[function(_dereq_,module,exports){ +(function (Buffer){ +// Adapt encodings to work with Buffer or Uint8Array, they expect the latter +function decode(buf) { + return buf.toString('utf8'); +} + +function encode(string) { + return new Buffer(string, 'utf8'); +} + +module.exports = { + encode: encode, + decode: decode +}; + +}).call(this,_dereq_("buffer").Buffer) +},{}],44:[function(_dereq_,module,exports){ var errors = {}; [ /** @@ -2376,12 +10790,10 @@ var errors = {}; module.exports = errors; -},{}],11:[function(_dereq_,module,exports){ +},{}],45:[function(_dereq_,module,exports){ +(function (Buffer){ var _ = _dereq_('../../lib/nodash.js'); -var TextDecoder = _dereq_('../../lib/encoding.js').TextDecoder; -var TextEncoder = _dereq_('../../lib/encoding.js').TextEncoder; - var Path = _dereq_('../path.js'); var normalize = Path.normalize; var dirname = Path.dirname; @@ -2412,6 +10824,7 @@ var XATTR_REPLACE = Constants.XATTR_REPLACE; var FS_NOMTIME = Constants.FS_NOMTIME; var FS_NOCTIME = Constants.FS_NOCTIME; +var Encoding = _dereq_('../encoding.js'); var Errors = _dereq_('../errors.js'); var DirectoryEntry = _dereq_('../directory-entry.js'); var OpenFileDescription = _dereq_('../open-file-description.js'); @@ -3020,7 +11433,8 @@ function open_file(context, path, flags, callback) { if(error) { callback(error); } else { - fileData = new Uint8Array(0); + fileData = new Buffer(0); + fileData.fill(0); context.put(fileNode.data, fileData, update_directory_data); } } @@ -3085,9 +11499,9 @@ function replace_data(context, ofd, buffer, offset, length, callback) { callback(error); } else { fileNode = result; - var newData = new Uint8Array(length); - var bufferWindow = buffer.subarray(offset, offset + length); - newData.set(bufferWindow); + var newData = new Buffer(length); + newData.fill(0); + buffer.copy(newData, 0, offset, offset + length); ofd.position = length; fileNode.size = length; @@ -3136,12 +11550,12 @@ function write_data(context, ofd, buffer, offset, length, position, callback) { fileData = result; var _position = (!(undefined === position || null === position)) ? position : ofd.position; var newSize = Math.max(fileData.length, _position + length); - var newData = new Uint8Array(newSize); + var newData = new Buffer(newSize); + newData.fill(0); if(fileData) { - newData.set(fileData); - } - var bufferWindow = buffer.subarray(offset, offset + length); - newData.set(bufferWindow, _position); + fileData.copy(newData); + } + buffer.copy(newData, _position, offset, offset + length); if(undefined === position) { ofd.position += length; } @@ -3176,8 +11590,7 @@ function read_data(context, ofd, buffer, offset, length, position, callback) { fileData = result; var _position = (!(undefined === position || null === position)) ? position : ofd.position; length = (_position + length > buffer.length) ? length - _position : length; - var dataView = fileData.subarray(_position, _position + length); - buffer.set(dataView, offset); + fileData.copy(buffer, offset, _position, _position + length); if(undefined === position) { ofd.position += length; } @@ -3561,9 +11974,10 @@ function truncate_file(context, path, length, callback) { if (error) { callback(error); } else { - var data = new Uint8Array(length); + var data = new Buffer(length); + data.fill(0); if(fileData) { - data.set(fileData.subarray(0, length)); + fileData.copy(data); } context.put(fileNode.data, data, update_file_node); } @@ -3613,9 +12027,12 @@ function ftruncate_file(context, ofd, length, callback) { if (error) { callback(error); } else { - var data = new Uint8Array(length); + var data; if(fileData) { - data.set(fileData.subarray(0, length)); + data = fileData.slice(0, length); + } else { + data = new Buffer(length); + data.fill(0); } context.put(fileNode.data, data, update_file_node); } @@ -4030,7 +12447,8 @@ function readFile(fs, context, path, options, callback) { var stats = new Stats(fstatResult, fs.name); var size = stats.size; - var buffer = new Uint8Array(size); + var buffer = new Buffer(size); + buffer.fill(0); read_data(context, ofd, buffer, 0, size, 0, function(err3, nbytes) { if(err3) { @@ -4040,7 +12458,7 @@ function readFile(fs, context, path, options, callback) { var data; if(options.encoding === 'utf8') { - data = new TextDecoder('utf-8').decode(buffer); + data = Encoding.decode(buffer); } else { data = buffer; } @@ -4083,7 +12501,7 @@ function writeFile(fs, context, path, data, options, callback) { data = '' + data; } if(typeof data === "string" && options.encoding === 'utf8') { - data = new TextEncoder('utf-8').encode(data); + data = Encoding.encode(data); } open_file(context, path, flags, function(err, fileNode) { @@ -4119,7 +12537,7 @@ function appendFile(fs, context, path, data, options, callback) { data = '' + data; } if(typeof data === "string" && options.encoding === 'utf8') { - data = new TextEncoder('utf-8').encode(data); + data = Encoding.encode(data); } open_file(context, path, flags, function(err, fileNode) { @@ -4379,7 +12797,8 @@ module.exports = { ftruncate: ftruncate }; -},{"../../lib/encoding.js":2,"../../lib/nodash.js":5,"../constants.js":8,"../directory-entry.js":9,"../errors.js":10,"../node.js":16,"../open-file-description.js":17,"../path.js":18,"../stats.js":26,"../super-node.js":27}],12:[function(_dereq_,module,exports){ +}).call(this,_dereq_("buffer").Buffer) +},{"../../lib/nodash.js":4,"../constants.js":41,"../directory-entry.js":42,"../encoding.js":43,"../errors.js":44,"../node.js":49,"../open-file-description.js":50,"../path.js":51,"../stats.js":60,"../super-node.js":61}],46:[function(_dereq_,module,exports){ var _ = _dereq_('../../lib/nodash.js'); var isNullPath = _dereq_('../path.js').isNull; @@ -4676,7 +13095,7 @@ FileSystem.prototype.Shell = function(options) { module.exports = FileSystem; -},{"../../lib/intercom.js":4,"../../lib/nodash.js":5,"../constants.js":8,"../errors.js":10,"../fs-watcher.js":13,"../path.js":18,"../providers/index.js":19,"../shared.js":23,"../shell/shell.js":25,"./implementation.js":11}],13:[function(_dereq_,module,exports){ +},{"../../lib/intercom.js":3,"../../lib/nodash.js":4,"../constants.js":41,"../errors.js":44,"../fs-watcher.js":47,"../path.js":51,"../providers/index.js":52,"../shared.js":56,"../shell/shell.js":59,"./implementation.js":45}],47:[function(_dereq_,module,exports){ var EventEmitter = _dereq_('../lib/eventemitter.js'); var isNullPath = _dereq_('./path.js').isNull; var Intercom = _dereq_('../lib/intercom.js'); @@ -4729,75 +13148,17 @@ FSWatcher.prototype.constructor = FSWatcher; module.exports = FSWatcher; -},{"../lib/eventemitter.js":3,"../lib/intercom.js":4,"./path.js":18}],14:[function(_dereq_,module,exports){ +},{"../lib/eventemitter.js":2,"../lib/intercom.js":3,"./path.js":51}],48:[function(_dereq_,module,exports){ +(function (Buffer){ module.exports = { FileSystem: _dereq_('./filesystem/interface.js'), + Buffer: Buffer, Path: _dereq_('./path.js'), Errors: _dereq_('./errors.js') }; -},{"./errors.js":10,"./filesystem/interface.js":12,"./path.js":18}],15:[function(_dereq_,module,exports){ -function browserDownload(uri, callback) { - var query = new XMLHttpRequest(); - query.onload = function() { - var err = query.status != 200 ? { message: query.statusText, code: query.status } : null, - data = err ? null : new Uint8Array(query.response); - - callback(err, data); - }; - query.open("GET", uri); - if("withCredentials" in query) { - query.withCredentials = true; - } - - query.responseType = "arraybuffer"; - query.send(); -} - -function nodeDownload(uri, callback) { - _dereq_('request')({ - url: uri, - method: "GET", - encoding: null - }, function(err, msg, body) { - var data = null, - arrayBuffer, - statusCode, - arrayLength = body && body.length, - error; - - msg = msg || null; - statusCode = msg && msg.statusCode; - - error = statusCode != 200 ? { message: err || 'Not found!', code: statusCode } : null; - - if (error) { - return callback(error, null); - } - - arrayBuffer = arrayLength && new ArrayBuffer(arrayLength); - - // Convert buffer to Uint8Array - if (arrayBuffer && (statusCode == 200)) { - data = new Uint8Array(arrayBuffer); - for (var i = 0; i < body.length; ++i) { - data[i] = body[i]; - } - } - - callback(null, data); - }); -} - -module.exports.download = (function() { - if (typeof XMLHttpRequest === 'undefined') { - return nodeDownload; - } else { - return browserDownload; - } -}()); - -},{}],16:[function(_dereq_,module,exports){ +}).call(this,_dereq_("buffer").Buffer) +},{"./errors.js":44,"./filesystem/interface.js":46,"./path.js":51}],49:[function(_dereq_,module,exports){ var MODE_FILE = _dereq_('./constants.js').MODE_FILE; var guid = _dereq_('./shared.js').guid; @@ -4819,7 +13180,7 @@ module.exports = function Node(id, mode, size, atime, ctime, mtime, flags, xattr this.data = guid(); // id for data object }; -},{"./constants.js":8,"./shared.js":23}],17:[function(_dereq_,module,exports){ +},{"./constants.js":41,"./shared.js":56}],50:[function(_dereq_,module,exports){ module.exports = function OpenFileDescription(path, id, flags, position) { this.path = path; this.id = id; @@ -4827,7 +13188,7 @@ module.exports = function OpenFileDescription(path, id, flags, position) { this.position = position; }; -},{}],18:[function(_dereq_,module,exports){ +},{}],51:[function(_dereq_,module,exports){ // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -5053,7 +13414,7 @@ module.exports = { isNull: isNull }; -},{}],19:[function(_dereq_,module,exports){ +},{}],52:[function(_dereq_,module,exports){ var IndexedDB = _dereq_('./indexeddb.js'); var WebSQL = _dereq_('./websql.js'); var Memory = _dereq_('./memory.js'); @@ -5090,7 +13451,7 @@ module.exports = { }()) }; -},{"./indexeddb.js":20,"./memory.js":21,"./websql.js":22}],20:[function(_dereq_,module,exports){ +},{"./indexeddb.js":53,"./memory.js":54,"./websql.js":55}],53:[function(_dereq_,module,exports){ (function(global) { var FILE_SYSTEM_NAME = _dereq_('../constants.js').FILE_SYSTEM_NAME; var FILE_STORE_NAME = _dereq_('../constants.js').FILE_STORE_NAME; @@ -5222,7 +13583,7 @@ module.exports = { }(this)); -},{"../constants.js":8,"../errors.js":10}],21:[function(_dereq_,module,exports){ +},{"../constants.js":41,"../errors.js":44}],54:[function(_dereq_,module,exports){ var FILE_SYSTEM_NAME = _dereq_('../constants.js').FILE_SYSTEM_NAME; var asyncCallback = _dereq_('../../lib/async.js').nextTick; @@ -5311,7 +13672,7 @@ Memory.prototype.getReadWriteContext = function() { module.exports = Memory; -},{"../../lib/async.js":1,"../constants.js":8}],22:[function(_dereq_,module,exports){ +},{"../../lib/async.js":1,"../constants.js":41}],55:[function(_dereq_,module,exports){ (function(global) { var FILE_SYSTEM_NAME = _dereq_('../constants.js').FILE_SYSTEM_NAME; var FILE_STORE_NAME = _dereq_('../constants.js').FILE_STORE_NAME; @@ -5474,7 +13835,7 @@ module.exports = Memory; }(this)); -},{"../constants.js":8,"../errors.js":10,"../shared.js":23}],23:[function(_dereq_,module,exports){ +},{"../constants.js":41,"../errors.js":44,"../shared.js":56}],56:[function(_dereq_,module,exports){ function guid() { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8); @@ -5502,7 +13863,7 @@ module.exports = { nop: nop }; -},{}],24:[function(_dereq_,module,exports){ +},{}],57:[function(_dereq_,module,exports){ var defaults = _dereq_('../constants.js').ENVIRONMENT; module.exports = function Environment(env) { @@ -5519,14 +13880,38 @@ module.exports = function Environment(env) { }; }; -},{"../constants.js":8}],25:[function(_dereq_,module,exports){ +},{"../constants.js":41}],58:[function(_dereq_,module,exports){ +var request = _dereq_('request'); + +module.exports.download = function(uri, callback) { + request({ + url: uri, + method: 'GET', + encoding: null + }, function(err, msg, body) { + var statusCode; + var error; + + msg = msg || null; + statusCode = msg && msg.statusCode; + error = statusCode !== 200 ? { message: err || 'Not found!', code: statusCode } : null; + + if (error) { + callback(error, null); + return; + } + callback(null, body); + }); +}; + +},{"request":5}],59:[function(_dereq_,module,exports){ var Path = _dereq_('../path.js'); var Errors = _dereq_('../errors.js'); var Environment = _dereq_('./environment.js'); var async = _dereq_('../../lib/async.js'); -var Network = _dereq_('../network.js'); -var Zlib = _dereq_('../../lib/zip-utils.js'); -var TextEncoder = _dereq_('../../lib/encoding.js').TextEncoder; +var Network = _dereq_('./network.js'); +var Encoding = _dereq_('../encoding.js'); +var JSZip = _dereq_('jszip'); function Shell(fs, options) { options = options || {}; @@ -6011,24 +14396,24 @@ Shell.prototype.unzip = function(zipfile, options, callback) { fs.readFile(path, function(err, data) { if(err) return callback(err); - var unzip = new Zlib.Unzip(data); + var zip = new JSZip(data); + var filenames = []; + zip.filter(function(relPath, file) { + var isDir = file.options.dir; + var data = isDir ? null : file.asNodeBuffer(); - // Separate filenames within the zip archive with what will go in fs. - // Also mark any directories (i.e., paths with a trailing '/') - var filenames = unzip.getFilenames().map(function(filename) { - return { - zipFilename: filename, - fsFilename: Path.join(destination, filename), - isDirectory: /\/$/.test(filename) - }; + filenames.push({ + absPath: Path.join(destination, file.name), + isDirectory: isDir, + data: data + }); }); function decompress(path, callback) { - var data = unzip.decompress(path.zipFilename); if(path.isDirectory) { - sh.mkdirp(path.fsFilename, callback); + sh.mkdirp(path.absPath, callback); } else { - fs.writeFile(path.fsFilename, data, callback); + fs.writeFile(path.absPath, path.data, callback); } } @@ -6059,28 +14444,24 @@ Shell.prototype.zip = function(zipfile, paths, options, callback) { } zipfile = Path.resolve(this.cwd, zipfile); - function encode(s) { - return new TextEncoder('utf8').encode(s); + function toRelPath(path) { + // Make path relative within the zip + return path.replace(/^\//, ''); } function addFile(path, callback) { fs.readFile(path, function(err, data) { if(err) return callback(err); - // Make path relative within the zip - var relpath = path.replace(/^\//, ''); - zip.addFile(data, { filename: encode(relpath) }); + zip.file(toRelPath(path), data, {binary: true}); callback(); }); } function addDir(path, callback) { fs.readdir(path, function(err, list) { - // Add the directory itself (with no data) and a trailing / - zip.addFile([], { - filename: encode(path + '/'), - compressionMethod: Zlib.Zip.CompressionMethod.STORE - }); + // Add the directory itself + zip.folder(toRelPath(path)); if(!options.recursive) { callback(); @@ -6106,7 +14487,7 @@ Shell.prototype.zip = function(zipfile, paths, options, callback) { }); } - var zip = new Zlib.Zip(); + var zip = new JSZip(); // Make sure the zipfile doesn't already exist. fs.stat(zipfile, function(err, stats) { @@ -6117,7 +14498,9 @@ Shell.prototype.zip = function(zipfile, paths, options, callback) { async.eachSeries(paths, add, function(err) { if(err) return callback(err); - var compressed = zip.compress(); + var compressed; + compressed = zip.generate({type: 'nodebuffer'}); + fs.writeFile(zipfile, compressed, callback); }); }); @@ -6125,7 +14508,7 @@ Shell.prototype.zip = function(zipfile, paths, options, callback) { module.exports = Shell; -},{"../../lib/async.js":1,"../../lib/encoding.js":2,"../../lib/zip-utils.js":6,"../errors.js":10,"../network.js":15,"../path.js":18,"./environment.js":24}],26:[function(_dereq_,module,exports){ +},{"../../lib/async.js":1,"../encoding.js":43,"../errors.js":44,"../path.js":51,"./environment.js":57,"./network.js":58,"jszip":13}],60:[function(_dereq_,module,exports){ var Constants = _dereq_('./constants.js'); function Stats(fileNode, devName) { @@ -6162,7 +14545,7 @@ function() { module.exports = Stats; -},{"./constants.js":8}],27:[function(_dereq_,module,exports){ +},{"./constants.js":41}],61:[function(_dereq_,module,exports){ var Constants = _dereq_('./constants.js'); var guid = _dereq_('./shared.js').guid; @@ -6177,6 +14560,6 @@ module.exports = function SuperNode(atime, ctime, mtime) { this.rnode = guid(); // root node id (randomly generated) }; -},{"./constants.js":8,"./shared.js":23}]},{},[14]) -(14) +},{"./constants.js":41,"./shared.js":56}]},{},[48]) +(48) }); \ No newline at end of file diff --git a/dist/filer.min.js b/dist/filer.min.js index 238427a..9e38916 100644 --- a/dist/filer.min.js +++ b/dist/filer.min.js @@ -1,4 +1,6 @@ -/*! filer 0.0.8 2014-05-28 */ -!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n;"undefined"!=typeof window?n=window:"undefined"!=typeof global?n=global:"undefined"!=typeof self&&(n=self),n.Filer=t()}}(function(){var t;return function n(t,e,r){function i(a,s){if(!e[a]){if(!t[a]){var u="function"==typeof require&&require;if(!s&&u)return u(a,!0);if(o)return o(a,!0);throw Error("Cannot find module '"+a+"'")}var c=e[a]={exports:{}};t[a][0].call(c.exports,function(n){var e=t[a][1][n];return i(e?e:n)},c,c.exports,n,t,e,r)}return e[a].exports}for(var o="function"==typeof require&&require,a=0;r.length>a;a++)i(r[a]);return i}({1:[function(n,e){(function(n){(function(){function r(t){var n=!1;return function(){if(n)throw Error("Callback was already called.");n=!0,t.apply(i,arguments)}}var i,o,a={};i=this,null!=i&&(o=i.async),a.noConflict=function(){return i.async=o,a};var s=function(t,n){if(t.forEach)return t.forEach(n);for(var e=0;t.length>e;e+=1)n(t[e],e,t)},u=function(t,n){if(t.map)return t.map(n);var e=[];return s(t,function(t,r,i){e.push(n(t,r,i))}),e},c=function(t,n,e){return t.reduce?t.reduce(n,e):(s(t,function(t,r,i){e=n(e,t,r,i)}),e)},f=function(t){if(Object.keys)return Object.keys(t);var n=[];for(var e in t)t.hasOwnProperty(e)&&n.push(e);return n};void 0!==n&&n.nextTick?(a.nextTick=n.nextTick,a.setImmediate="undefined"!=typeof setImmediate?function(t){setImmediate(t)}:a.nextTick):"function"==typeof setImmediate?(a.nextTick=function(t){setImmediate(t)},a.setImmediate=a.nextTick):(a.nextTick=function(t){setTimeout(t,0)},a.setImmediate=a.nextTick),a.each=function(t,n,e){if(e=e||function(){},!t.length)return e();var i=0;s(t,function(o){n(o,r(function(n){n?(e(n),e=function(){}):(i+=1,i>=t.length&&e(null))}))})},a.forEach=a.each,a.eachSeries=function(t,n,e){if(e=e||function(){},!t.length)return e();var r=0,i=function(){n(t[r],function(n){n?(e(n),e=function(){}):(r+=1,r>=t.length?e(null):i())})};i()},a.forEachSeries=a.eachSeries,a.eachLimit=function(t,n,e,r){var i=l(n);i.apply(null,[t,e,r])},a.forEachLimit=a.eachLimit;var l=function(t){return function(n,e,r){if(r=r||function(){},!n.length||0>=t)return r();var i=0,o=0,a=0;(function s(){if(i>=n.length)return r();for(;t>a&&n.length>o;)o+=1,a+=1,e(n[o-1],function(t){t?(r(t),r=function(){}):(i+=1,a-=1,i>=n.length?r():s())})})()}},h=function(t){return function(){var n=Array.prototype.slice.call(arguments);return t.apply(null,[a.each].concat(n))}},p=function(t,n){return function(){var e=Array.prototype.slice.call(arguments);return n.apply(null,[l(t)].concat(e))}},d=function(t){return function(){var n=Array.prototype.slice.call(arguments);return t.apply(null,[a.eachSeries].concat(n))}},g=function(t,n,e,r){var i=[];n=u(n,function(t,n){return{index:n,value:t}}),t(n,function(t,n){e(t.value,function(e,r){i[t.index]=r,n(e)})},function(t){r(t,i)})};a.map=h(g),a.mapSeries=d(g),a.mapLimit=function(t,n,e,r){return v(n)(t,e,r)};var v=function(t){return p(t,g)};a.reduce=function(t,n,e,r){a.eachSeries(t,function(t,r){e(n,t,function(t,e){n=e,r(t)})},function(t){r(t,n)})},a.inject=a.reduce,a.foldl=a.reduce,a.reduceRight=function(t,n,e,r){var i=u(t,function(t){return t}).reverse();a.reduce(i,n,e,r)},a.foldr=a.reduceRight;var m=function(t,n,e,r){var i=[];n=u(n,function(t,n){return{index:n,value:t}}),t(n,function(t,n){e(t.value,function(e){e&&i.push(t),n()})},function(){r(u(i.sort(function(t,n){return t.index-n.index}),function(t){return t.value}))})};a.filter=h(m),a.filterSeries=d(m),a.select=a.filter,a.selectSeries=a.filterSeries;var y=function(t,n,e,r){var i=[];n=u(n,function(t,n){return{index:n,value:t}}),t(n,function(t,n){e(t.value,function(e){e||i.push(t),n()})},function(){r(u(i.sort(function(t,n){return t.index-n.index}),function(t){return t.value}))})};a.reject=h(y),a.rejectSeries=d(y);var E=function(t,n,e,r){t(n,function(t,n){e(t,function(e){e?(r(t),r=function(){}):n()})},function(){r()})};a.detect=h(E),a.detectSeries=d(E),a.some=function(t,n,e){a.each(t,function(t,r){n(t,function(t){t&&(e(!0),e=function(){}),r()})},function(){e(!1)})},a.any=a.some,a.every=function(t,n,e){a.each(t,function(t,r){n(t,function(t){t||(e(!1),e=function(){}),r()})},function(){e(!0)})},a.all=a.every,a.sortBy=function(t,n,e){a.map(t,function(t,e){n(t,function(n,r){n?e(n):e(null,{value:t,criteria:r})})},function(t,n){if(t)return e(t);var r=function(t,n){var e=t.criteria,r=n.criteria;return r>e?-1:e>r?1:0};e(null,u(n.sort(r),function(t){return t.value}))})},a.auto=function(t,n){n=n||function(){};var e=f(t);if(!e.length)return n(null);var r={},i=[],o=function(t){i.unshift(t)},u=function(t){for(var n=0;i.length>n;n+=1)if(i[n]===t)return i.splice(n,1),void 0},l=function(){s(i.slice(0),function(t){t()})};o(function(){f(r).length===e.length&&(n(null,r),n=function(){})}),s(e,function(e){var i=t[e]instanceof Function?[t[e]]:t[e],h=function(t){var i=Array.prototype.slice.call(arguments,1);if(1>=i.length&&(i=i[0]),t){var o={};s(f(r),function(t){o[t]=r[t]}),o[e]=i,n(t,o),n=function(){}}else r[e]=i,a.setImmediate(l)},p=i.slice(0,Math.abs(i.length-1))||[],d=function(){return c(p,function(t,n){return t&&r.hasOwnProperty(n)},!0)&&!r.hasOwnProperty(e)};if(d())i[i.length-1](h,r);else{var g=function(){d()&&(u(g),i[i.length-1](h,r))};o(g)}})},a.waterfall=function(t,n){if(n=n||function(){},t.constructor!==Array){var e=Error("First argument to waterfall must be an array of functions");return n(e)}if(!t.length)return n();var r=function(t){return function(e){if(e)n.apply(null,arguments),n=function(){};else{var i=Array.prototype.slice.call(arguments,1),o=t.next();o?i.push(r(o)):i.push(n),a.setImmediate(function(){t.apply(null,i)})}}};r(a.iterator(t))()};var w=function(t,n,e){if(e=e||function(){},n.constructor===Array)t.map(n,function(t,n){t&&t(function(t){var e=Array.prototype.slice.call(arguments,1);1>=e.length&&(e=e[0]),n.call(null,t,e)})},e);else{var r={};t.each(f(n),function(t,e){n[t](function(n){var i=Array.prototype.slice.call(arguments,1);1>=i.length&&(i=i[0]),r[t]=i,e(n)})},function(t){e(t,r)})}};a.parallel=function(t,n){w({map:a.map,each:a.each},t,n)},a.parallelLimit=function(t,n,e){w({map:v(n),each:l(n)},t,e)},a.series=function(t,n){if(n=n||function(){},t.constructor===Array)a.mapSeries(t,function(t,n){t&&t(function(t){var e=Array.prototype.slice.call(arguments,1);1>=e.length&&(e=e[0]),n.call(null,t,e)})},n);else{var e={};a.eachSeries(f(t),function(n,r){t[n](function(t){var i=Array.prototype.slice.call(arguments,1);1>=i.length&&(i=i[0]),e[n]=i,r(t)})},function(t){n(t,e)})}},a.iterator=function(t){var n=function(e){var r=function(){return t.length&&t[e].apply(null,arguments),r.next()};return r.next=function(){return t.length-1>e?n(e+1):null},r};return n(0)},a.apply=function(t){var n=Array.prototype.slice.call(arguments,1);return function(){return t.apply(null,n.concat(Array.prototype.slice.call(arguments)))}};var b=function(t,n,e,r){var i=[];t(n,function(t,n){e(t,function(t,e){i=i.concat(e||[]),n(t)})},function(t){r(t,i)})};a.concat=h(b),a.concatSeries=d(b),a.whilst=function(t,n,e){t()?n(function(r){return r?e(r):(a.whilst(t,n,e),void 0)}):e()},a.doWhilst=function(t,n,e){t(function(r){return r?e(r):(n()?a.doWhilst(t,n,e):e(),void 0)})},a.until=function(t,n,e){t()?e():n(function(r){return r?e(r):(a.until(t,n,e),void 0)})},a.doUntil=function(t,n,e){t(function(r){return r?e(r):(n()?e():a.doUntil(t,n,e),void 0)})},a.queue=function(t,n){function e(t,e,r,i){e.constructor!==Array&&(e=[e]),s(e,function(e){var o={data:e,callback:"function"==typeof i?i:null};r?t.tasks.unshift(o):t.tasks.push(o),t.saturated&&t.tasks.length===n&&t.saturated(),a.setImmediate(t.process)})}void 0===n&&(n=1);var i=0,o={tasks:[],concurrency:n,saturated:null,empty:null,drain:null,push:function(t,n){e(o,t,!1,n)},unshift:function(t,n){e(o,t,!0,n)},process:function(){if(o.concurrency>i&&o.tasks.length){var n=o.tasks.shift();o.empty&&0===o.tasks.length&&o.empty(),i+=1;var e=function(){i-=1,n.callback&&n.callback.apply(n,arguments),o.drain&&0===o.tasks.length+i&&o.drain(),o.process()},a=r(e);t(n.data,a)}},length:function(){return o.tasks.length},running:function(){return i}};return o},a.cargo=function(t,n){var e=!1,r=[],i={tasks:r,payload:n,saturated:null,empty:null,drain:null,push:function(t,e){t.constructor!==Array&&(t=[t]),s(t,function(t){r.push({data:t,callback:"function"==typeof e?e:null}),i.saturated&&r.length===n&&i.saturated()}),a.setImmediate(i.process)},process:function o(){if(!e){if(0===r.length)return i.drain&&i.drain(),void 0;var a="number"==typeof n?r.splice(0,n):r.splice(0),c=u(a,function(t){return t.data});i.empty&&i.empty(),e=!0,t(c,function(){e=!1;var t=arguments;s(a,function(n){n.callback&&n.callback.apply(null,t)}),o()})}},length:function(){return r.length},running:function(){return e}};return i};var A=function(t){return function(n){var e=Array.prototype.slice.call(arguments,1);n.apply(null,e.concat([function(n){var e=Array.prototype.slice.call(arguments,1);"undefined"!=typeof console&&(n?console.error&&console.error(n):console[t]&&s(e,function(n){console[t](n)}))}]))}};a.log=A("log"),a.dir=A("dir"),a.memoize=function(t,n){var e={},r={};n=n||function(t){return t};var i=function(){var i=Array.prototype.slice.call(arguments),o=i.pop(),a=n.apply(null,i);a in e?o.apply(null,e[a]):a in r?r[a].push(o):(r[a]=[o],t.apply(null,i.concat([function(){e[a]=arguments;var t=r[a];delete r[a];for(var n=0,i=t.length;i>n;n++)t[n].apply(null,arguments)}])))};return i.memo=e,i.unmemoized=t,i},a.unmemoize=function(t){return function(){return(t.unmemoized||t).apply(null,arguments)}},a.times=function(t,n,e){for(var r=[],i=0;t>i;i++)r.push(i);return a.map(r,n,e)},a.timesSeries=function(t,n,e){for(var r=[],i=0;t>i;i++)r.push(i);return a.mapSeries(r,n,e)},a.compose=function(){var t=Array.prototype.reverse.call(arguments);return function(){var n=this,e=Array.prototype.slice.call(arguments),r=e.pop();a.reduce(t,e,function(t,e,r){e.apply(n,t.concat([function(){var t=arguments[0],n=Array.prototype.slice.call(arguments,1);r(t,n)}]))},function(t,e){r.apply(n,[t].concat(e))})}};var O=function(t,n){var e=function(){var e=this,r=Array.prototype.slice.call(arguments),i=r.pop();return t(n,function(t,n){t.apply(e,r.concat([n]))},i)};if(arguments.length>2){var r=Array.prototype.slice.call(arguments,2);return e.apply(this,r)}return e};a.applyEach=h(O),a.applyEachSeries=d(O),a.forever=function(t,n){function e(r){if(r){if(n)return n(r);throw r}t(e)}e()},t!==void 0&&t.amd?t([],function(){return a}):e!==void 0&&e.exports?e.exports=a:i.async=a})()}).call(this,n("FWaASH"))},{FWaASH:7}],2:[function(t,n){(function(t){"use strict";function e(t,n,e){return t>=n&&e>=t}function r(t,n){return Math.floor(t/n)}function i(t){var n=0;this.get=function(){return n>=t.length?v:Number(t[n])},this.offset=function(e){if(n+=e,0>n)throw Error("Seeking past start of the buffer");if(n>t.length)throw Error("Seeking past EOF")},this.match=function(e){if(e.length>n+t.length)return!1;var r;for(r=0;e.length>r;r+=1)if(Number(t[n+r])!==e[r])return!1;return!0}}function o(t){var n=0;this.emit=function(){var e,r=v;for(e=0;arguments.length>e;++e)r=Number(arguments[e]),t[n++]=r;return r}}function a(t){function n(t){for(var n=[],r=0,i=t.length;t.length>r;){var o=t.charCodeAt(r);if(e(o,55296,57343))if(e(o,56320,57343))n.push(65533);else if(r===i-1)n.push(65533);else{var a=t.charCodeAt(r+1);if(e(a,56320,57343)){var s=1023&o,u=1023&a;r+=1,n.push(65536+(s<<10)+u)}else n.push(65533)}else n.push(o);r+=1}return n}var r=0,i=n(t);this.offset=function(t){if(r+=t,0>r)throw Error("Seeking past start of the buffer");if(r>i.length)throw Error("Seeking past EOF")},this.get=function(){return r>=i.length?m:i[r]}}function s(){var t="";this.string=function(){return t},this.emit=function(n){65535>=n?t+=String.fromCharCode(n):(n-=65536,t+=String.fromCharCode(55296+(1023&n>>10)),t+=String.fromCharCode(56320+(1023&n)))}}function u(t){this.name="EncodingError",this.message=t,this.code=0}function c(t,n){if(t)throw new u("Decoder error");return n||65533}function f(t){throw new u("The code point "+t+" could not be encoded.")}function l(t){return t=(t+"").trim().toLowerCase(),Object.prototype.hasOwnProperty.call(w,t)?w[t]:null}function h(t){var n=t.fatal,r=0,i=0,o=0,a=0;this.decode=function(t){var s=t.get();if(s===v)return 0!==i?c(n):m;if(t.offset(1),0===i){if(e(s,0,127))return s;if(e(s,194,223))i=1,a=128,r=s-192;else if(e(s,224,239))i=2,a=2048,r=s-224;else{if(!e(s,240,244))return c(n);i=3,a=65536,r=s-240}return r*=Math.pow(64,i),null}if(!e(s,128,191))return r=0,i=0,o=0,a=0,t.offset(-1),c(n);if(o+=1,r+=(s-128)*Math.pow(64,i-o),o!==i)return null;var u=r,f=a;return r=0,i=0,o=0,a=0,e(u,f,1114111)&&!e(u,55296,57343)?u:c(n)}}function p(t){t.fatal,this.encode=function(t,n){var i=n.get();if(i===m)return v;if(n.offset(1),e(i,55296,57343))return f(i);if(e(i,0,127))return t.emit(i);var o,a;e(i,128,2047)?(o=1,a=192):e(i,2048,65535)?(o=2,a=224):e(i,65536,1114111)&&(o=3,a=240);for(var s=t.emit(r(i,Math.pow(64,o))+a);o>0;){var u=r(i,Math.pow(64,o-1));s=t.emit(128+u%64),o-=1}return s}}function d(t,n){if(!(this instanceof d))throw new TypeError("Constructor cannot be called as a function");if(t=t?t+"":b,n=Object(n),this._encoding=l(t),null===this._encoding||"utf-8"!==this._encoding.name&&"utf-16le"!==this._encoding.name&&"utf-16be"!==this._encoding.name)throw new TypeError("Unknown encoding: "+t);return this._streaming=!1,this._encoder=null,this._options={fatal:Boolean(n.fatal)},Object.defineProperty?Object.defineProperty(this,"encoding",{get:function(){return this._encoding.name}}):this.encoding=this._encoding.name,this}function g(t,n){if(!(this instanceof g))throw new TypeError("Constructor cannot be called as a function");if(t=t?t+"":b,n=Object(n),this._encoding=l(t),null===this._encoding)throw new TypeError("Unknown encoding: "+t);return this._streaming=!1,this._decoder=null,this._options={fatal:Boolean(n.fatal)},Object.defineProperty?Object.defineProperty(this,"encoding",{get:function(){return this._encoding.name}}):this.encoding=this._encoding.name,this}var v=-1,m=-1;u.prototype=Error.prototype;var y=[{encodings:[{labels:["unicode-1-1-utf-8","utf-8","utf8"],name:"utf-8"}],heading:"The Encoding"}],E={},w={};y.forEach(function(t){t.encodings.forEach(function(t){E[t.name]=t,t.labels.forEach(function(n){w[n]=t})})}),E["utf-8"].getEncoder=function(t){return new p(t)},E["utf-8"].getDecoder=function(t){return new h(t)};var b="utf-8";d.prototype={encode:function(t,n){t=t?t+"":"",n=Object(n),this._streaming||(this._encoder=this._encoding.getEncoder(this._options)),this._streaming=Boolean(n.stream);for(var e=[],r=new o(e),i=new a(t);i.get()!==m;)this._encoder.encode(r,i);if(!this._streaming){var s;do s=this._encoder.encode(r,i);while(s!==v);this._encoder=null}return new Uint8Array(e)}},g.prototype={decode:function(t,n){if(t&&!("buffer"in t&&"byteOffset"in t&&"byteLength"in t))throw new TypeError("Expected ArrayBufferView");t||(t=new Uint8Array(0)),n=Object(n),this._streaming||(this._decoder=this._encoding.getDecoder(this._options),this._BOMseen=!1),this._streaming=Boolean(n.stream);for(var e,r=new Uint8Array(t.buffer,t.byteOffset,t.byteLength),o=new i(r),a=new s;o.get()!==v;)e=this._decoder.decode(o),null!==e&&e!==m&&a.emit(e);if(!this._streaming){do e=this._decoder.decode(o),null!==e&&e!==m&&a.emit(e);while(e!==m&&o.get()!=v);this._decoder=null}var u=a.string();return!this._BOMseen&&u.length&&(this._BOMseen=!0,-1!==["utf-8","utf-16le","utf-16be"].indexOf(this.encoding)&&65279===u.charCodeAt(0)&&(u=u.substring(1))),u}},n.exports={TextEncoder:t.TextEncoder||d,TextDecoder:t.TextDecoder||g}})(this)},{}],3:[function(t,n){function e(t,n){for(var e=n.length-1;e>=0;e--)n[e]===t&&n.splice(e,1);return n}var r=function(){};r.createInterface=function(t){var n={};return n.on=function(n,e){this[t]===void 0&&(this[t]={}),this[t].hasOwnProperty(n)||(this[t][n]=[]),this[t][n].push(e)},n.off=function(n,r){void 0!==this[t]&&this[t].hasOwnProperty(n)&&e(r,this[t][n])},n.trigger=function(n){if(this[t]!==void 0&&this[t].hasOwnProperty(n))for(var e=Array.prototype.slice.call(arguments,1),r=0;this[t][n].length>r;r++)this[t][n][r].apply(this[t][n][r],e)},n.removeAllListeners=function(n){if(void 0!==this[t]){var e=this;e[t][n].forEach(function(t){e.off(n,t)})}},n};var i=r.createInterface("_handlers");r.prototype._on=i.on,r.prototype._off=i.off,r.prototype._trigger=i.trigger;var o=r.createInterface("handlers");r.prototype.on=function(){o.on.apply(this,arguments),Array.prototype.unshift.call(arguments,"on"),this._trigger.apply(this,arguments)},r.prototype.off=o.off,r.prototype.trigger=o.trigger,r.prototype.removeAllListeners=o.removeAllListeners,n.exports=r},{}],4:[function(t,n){function e(t,n){var e=0;return function(){var r=Date.now();r-e>t&&(e=r,n.apply(this,arguments))}}function r(t,n){if(void 0!==t&&t||(t={}),"object"==typeof n)for(var e in n)n.hasOwnProperty(e)&&(t[e]=n[e]);return t}function i(){var t=this,n=Date.now();this.origin=a(),this.lastMessage=n,this.receivedIDs={},this.previousValues={};var e=function(){t._onStorageEvent.apply(t,arguments)};"undefined"!=typeof window&&"undefined"!=typeof document&&(document.attachEvent?document.attachEvent("onstorage",e):window.addEventListener("storage",e,!1))}var o=t("./eventemitter.js"),a=t("../src/shared.js").guid,s=function(t){return t===void 0||t.localStorage===void 0?{getItem:function(){},setItem:function(){},removeItem:function(){}}:t.localStorage}(this);i.prototype._transaction=function(t){function n(){if(!a){var l=Date.now(),h=0|s.getItem(f);if(h&&r>l-h)return u||(o._on("storage",n),u=!0),c=setTimeout(n,i),void 0;a=!0,s.setItem(f,l),t(),e()}}function e(){u&&o._off("storage",n),c&&clearTimeout(c),s.removeItem(f)}var r=1e3,i=20,o=this,a=!1,u=!1,c=null;n()},i.prototype._cleanup_emit=e(100,function(){var t=this;t._transaction(function(){var t,n=Date.now(),e=n-l,r=0;try{t=JSON.parse(s.getItem(u)||"[]")}catch(i){t=[]}for(var o=t.length-1;o>=0;o--)e>t[o].timestamp&&(t.splice(o,1),r++);r>0&&s.setItem(u,JSON.stringify(t))})}),i.prototype._cleanup_once=e(100,function(){var t=this;t._transaction(function(){var n,e;Date.now();var r=0;try{e=JSON.parse(s.getItem(c)||"{}")}catch(i){e={}}for(n in e)t._once_expired(n,e)&&(delete e[n],r++);r>0&&s.setItem(c,JSON.stringify(e))})}),i.prototype._once_expired=function(t,n){if(!n)return!0;if(!n.hasOwnProperty(t))return!0;if("object"!=typeof n[t])return!0;var e=n[t].ttl||h,r=Date.now(),i=n[t].timestamp;return r-e>i},i.prototype._localStorageChanged=function(t,n){if(t&&t.key)return t.key===n;var e=s.getItem(n);return e===this.previousValues[n]?!1:(this.previousValues[n]=e,!0)},i.prototype._onStorageEvent=function(t){t=t||window.event;var n=this;this._localStorageChanged(t,u)&&this._transaction(function(){var t,e=Date.now(),r=s.getItem(u);try{t=JSON.parse(r||"[]")}catch(i){t=[]}for(var o=0;t.length>o;o++)if(t[o].origin!==n.origin&&!(t[o].timestampr;r++)if(n.call(e,t[r],r,t)===m)return}else{var o=o(t);for(r=0,i=o.length;i>r;r++)if(n.call(e,t[o[r]],o[r],t)===m)return}}function a(t,n,e){n||(n=i);var r=!1;return null==t?r:p&&t.some===p?t.some(n,e):(o(t,function(t,i,o){return r||(r=n.call(e,t,i,o))?m:void 0}),!!r)}function s(t,n){return null==t?!1:h&&t.indexOf===h?-1!=t.indexOf(n):a(t,function(t){return t===n})}function u(t){this.value=t}function c(t){return t&&"object"==typeof t&&!Array.isArray(t)&&g.call(t,"__wrapped__")?t:new u(t)}var f=Array.prototype,l=f.forEach,h=f.indexOf,p=f.some,d=Object.prototype,g=d.hasOwnProperty,v=Object.keys,m={},y=v||function(t){if(t!==Object(t))throw new TypeError("Invalid object");var n=[];for(var r in t)e(t,r)&&n.push(r);return n};u.prototype.has=function(t){return e(this.value,t)},u.prototype.contains=function(t){return s(this.value,t)},u.prototype.size=function(){return r(this.value)},n.exports=c},{}],6:[function(t,n){var e={};(function(){"use strict";function t(t,n){var e=t.split("."),r=y;!(e[0]in r)&&r.execScript&&r.execScript("var "+e[0]);for(var i;e.length&&(i=e.shift());)e.length||n===v?r=r[i]?r[i]:r[i]={}:r[i]=n}function n(t,n){if(this.index="number"==typeof n?n:0,this.f=0,this.buffer=t instanceof(E?Uint8Array:Array)?t:new(E?Uint8Array:Array)(32768),2*this.buffer.length<=this.index)throw Error("invalid index");this.buffer.length<=this.index&&e(this)}function e(t){var n,e=t.buffer,r=e.length,i=new(E?Uint8Array:Array)(r<<1);if(E)i.set(e);else for(n=0;r>n;++n)i[n]=e[n];return t.buffer=i}function r(t){var n,e=v,r="number"==typeof e?e:e=0,i=t.length;for(n=-1,r=7&i;r--;++e)n=n>>>8^x[255&(n^t[e])];for(r=i>>3;r--;e+=8)n=n>>>8^x[255&(n^t[e])],n=n>>>8^x[255&(n^t[e+1])],n=n>>>8^x[255&(n^t[e+2])],n=n>>>8^x[255&(n^t[e+3])],n=n>>>8^x[255&(n^t[e+4])],n=n>>>8^x[255&(n^t[e+5])],n=n>>>8^x[255&(n^t[e+6])],n=n>>>8^x[255&(n^t[e+7])];return(4294967295^n)>>>0}function i(t){this.buffer=new(E?Uint16Array:Array)(2*t),this.length=0}function o(t,n){this.k=k,this.l=0,this.input=E&&t instanceof Array?new Uint8Array(t):t,this.e=0,n&&(n.lazy&&(this.l=n.lazy),"number"==typeof n.compressionType&&(this.k=n.compressionType),n.outputBuffer&&(this.c=E&&n.outputBuffer instanceof Array?new Uint8Array(n.outputBuffer):n.outputBuffer),"number"==typeof n.outputIndex&&(this.e=n.outputIndex)),this.c||(this.c=new(E?Uint8Array:Array)(32768))}function a(t,n){this.length=t,this.n=n}function s(t,n){function e(t,n){var e,r=t.n,i=[],o=0;e=R[t.length],i[o++]=65535&e,i[o++]=255&e>>16,i[o++]=e>>24;var a;switch(m){case 1===r:a=[0,r-1,0];break;case 2===r:a=[1,r-2,0];break;case 3===r:a=[2,r-3,0];break;case 4===r:a=[3,r-4,0];break;case 6>=r:a=[4,r-5,1];break;case 8>=r:a=[5,r-7,1];break;case 12>=r:a=[6,r-9,2];break;case 16>=r:a=[7,r-13,2];break;case 24>=r:a=[8,r-17,3];break;case 32>=r:a=[9,r-25,3];break;case 48>=r:a=[10,r-33,4];break;case 64>=r:a=[11,r-49,4];break;case 96>=r:a=[12,r-65,5];break;case 128>=r:a=[13,r-97,5];break;case 192>=r:a=[14,r-129,6];break;case 256>=r:a=[15,r-193,6];break;case 384>=r:a=[16,r-257,7];break;case 512>=r:a=[17,r-385,7];break;case 768>=r:a=[18,r-513,8];break;case 1024>=r:a=[19,r-769,8];break;case 1536>=r:a=[20,r-1025,9];break;case 2048>=r:a=[21,r-1537,9];break;case 3072>=r:a=[22,r-2049,10];break;case 4096>=r:a=[23,r-3073,10];break;case 6144>=r:a=[24,r-4097,11];break;case 8192>=r:a=[25,r-6145,11];break;case 12288>=r:a=[26,r-8193,12];break;case 16384>=r:a=[27,r-12289,12];break;case 24576>=r:a=[28,r-16385,13];break;case 32768>=r:a=[29,r-24577,13];break;default:throw"invalid distance"}e=a,i[o++]=e[0],i[o++]=e[1],i[o++]=e[2];var s,u;for(s=0,u=i.length;u>s;++s)d[g++]=i[s];w[i[0]]++,b[i[3]]++,y=t.length+n-1,l=null}var r,i,o,a,s,c,f,l,h,p={},d=E?new Uint16Array(2*n.length):[],g=0,y=0,w=new(E?Uint32Array:Array)(286),b=new(E?Uint32Array:Array)(30),A=t.l;if(!E){for(o=0;285>=o;)w[o++]=0;for(o=0;29>=o;)b[o++]=0}for(w[256]=1,r=0,i=n.length;i>r;++r){for(o=s=0,a=3;a>o&&r+o!==i;++o)s=s<<8|n[r+o];if(p[s]===v&&(p[s]=[]),c=p[s],!(y-->0)){for(;c.length>0&&r-c[0]>32768;)c.shift();if(r+3>=i){for(l&&e(l,-1),o=0,a=i-r;a>o;++o)h=n[r+o],d[g++]=h,++w[h];break}c.length>0?(f=u(n,r,c),l?l.lengthf.length?l=f:e(f,0)):l?e(l,-1):(h=n[r],d[g++]=h,++w[h])}c.push(r)}return d[g++]=256,w[256]++,t.p=w,t.o=b,E?d.subarray(0,g):d}function u(t,n,e){var r,i,o,s,u,c,f=0,l=t.length;s=0,c=e.length;t:for(;c>s;s++){if(r=e[c-s-1],o=3,f>3){for(u=f;u>3;u--)if(t[r+u-1]!==t[n+u-1])continue t;o=f}for(;258>o&&l>n+o&&t[r+o]===t[n+o];)++o;if(o>f&&(i=r,f=o),258===o)break}return new a(f,n-i)}function c(t,n){var e,r,o,a,s,u=t.length,c=new i(572),l=new(E?Uint8Array:Array)(u);if(!E)for(a=0;u>a;a++)l[a]=0;for(a=0;u>a;++a)t[a]>0&&c.push(a,t[a]);if(e=Array(c.length/2),r=new(E?Uint32Array:Array)(c.length/2),1===e.length)return l[c.pop().index]=1,l;for(a=0,s=c.length/2;s>a;++a)e[a]=c.pop(),r[a]=e[a].value;for(o=f(r,r.length,n),a=0,s=e.length;s>a;++a)l[e[a].index]=o[a];return l}function f(t,n,e){function r(t){var e=p[t][d[t]];e===n?(r(t+1),r(t+1)):--l[e],++d[t]}var i,o,a,s,u,c=new(E?Uint16Array:Array)(e),f=new(E?Uint8Array:Array)(e),l=new(E?Uint8Array:Array)(n),h=Array(e),p=Array(e),d=Array(e),g=(1<o;++o)v>g?f[o]=0:(f[o]=1,g-=v),g<<=1,c[e-2-o]=(0|c[e-1-o]/2)+n;for(c[0]=f[0],h[0]=Array(c[0]),p[0]=Array(c[0]),o=1;e>o;++o)c[o]>2*c[o-1]+f[o]&&(c[o]=2*c[o-1]+f[o]),h[o]=Array(c[o]),p[o]=Array(c[o]);for(i=0;n>i;++i)l[i]=e;for(a=0;c[e-1]>a;++a)h[e-1][a]=t[a],p[e-1][a]=a;for(i=0;e>i;++i)d[i]=0;for(1===f[e-1]&&(--l[0],++d[e-1]),o=e-2;o>=0;--o){for(s=i=0,u=d[o+1],a=0;c[o]>a;a++)s=h[o+1][u]+h[o+1][u+1],s>t[i]?(h[o][a]=s,p[o][a]=n,u+=2):(h[o][a]=t[i],p[o][a]=i,++i);d[o]=0,1===f[o]&&r(o)}return l}function l(t){var n,e,r,i,o=new(E?Uint16Array:Array)(t.length),a=[],s=[],u=0;for(n=0,e=t.length;e>n;n++)a[t[n]]=(0|a[t[n]])+1;for(n=1,e=16;e>=n;n++)s[n]=u,u+=0|a[n],u<<=1;for(n=0,e=t.length;e>n;n++)for(u=s[t[n]],s[t[n]]+=1,r=o[n]=0,i=t[n];i>r;r++)o[n]=o[n]<<1|1&u,u>>>=1;return o}function h(t){t=t||{},this.files=[],this.d=t.comment}function p(t,n){var e,r=2|65535&t[2];return e=255&r*(1^r)>>8,d(t,n),e^n}function d(t,n){t[0]=(x[255&(t[0]^n)]^t[0]>>>8)>>>0,t[1]=(6681*(20173*(t[1]+(255&t[0]))>>>0)>>>0)+1>>>0,t[2]=(x[255&(t[2]^t[1]>>>24)]^t[2]>>>8)>>>0}function g(n,e){var r,i,o,a;if(Object.keys)r=Object.keys(e);else for(i in r=[],o=0,e)r[o++]=i;for(o=0,a=r.length;a>o;++o)i=r[o],t(n+"."+i,e[i])}var v=void 0,m=!0,y=this,E="undefined"!=typeof Uint8Array&&"undefined"!=typeof Uint16Array&&"undefined"!=typeof Uint32Array&&"undefined"!=typeof DataView;n.prototype.b=function(t,n,r){var i,o=this.buffer,a=this.index,s=this.f,u=o[a];if(r&&n>1&&(t=n>8?(I[255&t]<<24|I[255&t>>>8]<<16|I[255&t>>>16]<<8|I[255&t>>>24])>>32-n:I[t]>>8-n),8>n+s)u=u<i;++i)u=u<<1|1&t>>n-i-1,8===++s&&(s=0,o[a++]=I[u],u=0,a===o.length&&(o=e(this)));o[a]=u,this.buffer=o,this.f=s,this.index=a},n.prototype.finish=function(){var t,n=this.buffer,e=this.index;return this.f>0&&(n[e]<<=8-this.f,n[e]=I[n[e]],e++),E?t=n.subarray(0,e):(n.length=e,t=n),t};var w,b=new(E?Uint8Array:Array)(256);for(w=0;256>w;++w){for(var A=w,O=A,T=7,A=A>>>1;A;A>>>=1)O<<=1,O|=1&A,--T;b[w]=(255&O<>>0}var I=b,S=[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],x=E?new Uint32Array(S):S;i.prototype.getParent=function(t){return 2*(0|(t-2)/4)},i.prototype.push=function(t,n){var e,r,i,o=this.buffer;for(e=this.length,o[this.length++]=n,o[this.length++]=t;e>0&&(r=this.getParent(e),o[e]>o[r]);)i=o[e],o[e]=o[r],o[r]=i,i=o[e+1],o[e+1]=o[r+1],o[r+1]=i,e=r;return this.length},i.prototype.pop=function(){var t,n,e,r,i,o=this.buffer;for(n=o[0],t=o[1],this.length-=2,o[0]=o[this.length],o[1]=o[this.length+1],i=0;(r=2*i+2,!(r>=this.length))&&(this.length>r+2&&o[r+2]>o[r]&&(r+=2),o[r]>o[i]);)e=o[i],o[i]=o[r],o[r]=e,e=o[i+1],o[i+1]=o[r+1],o[r+1]=e,i=r;return{index:t,value:n,length:this.length}};var N,k=2,_=[];for(N=0;288>N;N++)switch(m){case 143>=N:_.push([N+48,8]);break;case 255>=N:_.push([N-144+400,9]);break;case 279>=N:_.push([N-256+0,7]);break;case 287>=N:_.push([N-280+192,8]);break;default:throw"invalid literal: "+N}o.prototype.g=function(){var t,e,r,i,o=this.input;switch(this.k){case 0:for(r=0,i=o.length;i>r;){e=E?o.subarray(r,r+65535):o.slice(r,r+65535),r+=e.length;var a=e,u=r===i,f=v,h=v,p=v,d=v,g=v,y=this.c,w=this.e;if(E){for(y=new Uint8Array(this.c.buffer);y.length<=w+a.length+5;)y=new Uint8Array(y.length<<1);y.set(this.c)}if(f=u?1:0,y[w++]=0|f,h=a.length,p=65535&~h+65536,y[w++]=255&h,y[w++]=255&h>>>8,y[w++]=255&p,y[w++]=255&p>>>8,E)y.set(a,w),w+=a.length,y=y.subarray(0,w);else{for(d=0,g=a.length;g>d;++d)y[w++]=a[d];y.length=w}this.e=w,this.c=y}break;case 1:var b=new n(E?new Uint8Array(this.c.buffer):this.c,this.e);b.b(1,1,m),b.b(1,2,m);var A,O,T,I=s(this,o);for(A=0,O=I.length;O>A;A++)if(T=I[A],n.prototype.b.apply(b,_[T]),T>256)b.b(I[++A],I[++A],m),b.b(I[++A],5),b.b(I[++A],I[++A],m); -else if(256===T)break;this.c=b.finish(),this.e=this.c.length;break;case k:var S,x,N,D,R,j,L,M,F,U,C,P,V,B,z,Y=new n(E?new Uint8Array(this.c.buffer):this.c,this.e),W=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],X=Array(19);for(S=k,Y.b(1,1,m),Y.b(S,2,m),x=s(this,o),j=c(this.p,15),L=l(j),M=c(this.o,7),F=l(M),N=286;N>257&&0===j[N-1];N--);for(D=30;D>1&&0===M[D-1];D--);var q,Z,H,J,G,Q,K=N,$=D,tn=new(E?Uint32Array:Array)(K+$),nn=new(E?Uint32Array:Array)(316),en=new(E?Uint8Array:Array)(19);for(q=Z=0;K>q;q++)tn[Z++]=j[q];for(q=0;$>q;q++)tn[Z++]=M[q];if(!E)for(q=0,J=en.length;J>q;++q)en[q]=0;for(q=G=0,J=tn.length;J>q;q+=Z){for(Z=1;J>q+Z&&tn[q+Z]===tn[q];++Z);if(H=Z,0===tn[q])if(3>H)for(;H-->0;)nn[G++]=0,en[0]++;else for(;H>0;)Q=138>H?H:138,Q>H-3&&H>Q&&(Q=H-3),10>=Q?(nn[G++]=17,nn[G++]=Q-3,en[17]++):(nn[G++]=18,nn[G++]=Q-11,en[18]++),H-=Q;else if(nn[G++]=tn[q],en[tn[q]]++,H--,3>H)for(;H-->0;)nn[G++]=tn[q],en[tn[q]]++;else for(;H>0;)Q=6>H?H:6,Q>H-3&&H>Q&&(Q=H-3),nn[G++]=16,nn[G++]=Q-3,en[16]++,H-=Q}for(t=E?nn.subarray(0,G):nn.slice(0,G),U=c(en,7),B=0;19>B;B++)X[B]=U[W[B]];for(R=19;R>4&&0===X[R-1];R--);for(C=l(U),Y.b(N-257,5,m),Y.b(D-1,5,m),Y.b(R-4,4,m),B=0;R>B;B++)Y.b(X[B],3,m);for(B=0,z=t.length;z>B;B++)if(P=t[B],Y.b(C[P],U[P],m),P>=16){switch(B++,P){case 16:V=2;break;case 17:V=3;break;case 18:V=7;break;default:throw"invalid code: "+P}Y.b(t[B],V,m)}var rn,on,an,sn,un,cn,fn,ln,hn=[L,j],pn=[F,M];for(un=hn[0],cn=hn[1],fn=pn[0],ln=pn[1],rn=0,on=x.length;on>rn;++rn)if(an=x[rn],Y.b(un[an],cn[an],m),an>256)Y.b(x[++rn],x[++rn],m),sn=x[++rn],Y.b(fn[sn],ln[sn],m),Y.b(x[++rn],x[++rn],m);else if(256===an)break;this.c=Y.finish(),this.e=this.c.length;break;default:throw"invalid compression type"}return this.c};var D=function(){function t(t){switch(m){case 3===t:return[257,t-3,0];case 4===t:return[258,t-4,0];case 5===t:return[259,t-5,0];case 6===t:return[260,t-6,0];case 7===t:return[261,t-7,0];case 8===t:return[262,t-8,0];case 9===t:return[263,t-9,0];case 10===t:return[264,t-10,0];case 12>=t:return[265,t-11,1];case 14>=t:return[266,t-13,1];case 16>=t:return[267,t-15,1];case 18>=t:return[268,t-17,1];case 22>=t:return[269,t-19,2];case 26>=t:return[270,t-23,2];case 30>=t:return[271,t-27,2];case 34>=t:return[272,t-31,2];case 42>=t:return[273,t-35,3];case 50>=t:return[274,t-43,3];case 58>=t:return[275,t-51,3];case 66>=t:return[276,t-59,3];case 82>=t:return[277,t-67,4];case 98>=t:return[278,t-83,4];case 114>=t:return[279,t-99,4];case 130>=t:return[280,t-115,4];case 162>=t:return[281,t-131,5];case 194>=t:return[282,t-163,5];case 226>=t:return[283,t-195,5];case 257>=t:return[284,t-227,5];case 258===t:return[285,t-258,0];default:throw"invalid length: "+t}}var n,e,r=[];for(n=3;258>=n;n++)e=t(n),r[n]=e[2]<<24|e[1]<<16|e[0];return r}(),R=E?new Uint32Array(D):D,j=[80,75,1,2],L=[80,75,3,4],M=[80,75,5,6];h.prototype.m=function(t,n){n=n||{};var e,i=t.length,a=0;if(E&&t instanceof Array&&(t=new Uint8Array(t)),"number"!=typeof n.compressionMethod&&(n.compressionMethod=8),n.compress)switch(n.compressionMethod){case 0:break;case 8:a=r(t),t=new o(t,n.deflateOption).g(),e=m;break;default:throw Error("unknown compression method:"+n.compressionMethod)}this.files.push({buffer:t,a:n,j:e,r:!1,size:i,h:a})},h.prototype.q=function(t){this.i=t},h.prototype.g=function(){var t,n,e,i,a,s,u,c,f,l,h,g,y,w,b,A,O,T,I,S,x,N,k,_,D=this.files,R=0,F=0;for(x=0,N=D.length;N>x;++x){if(t=D[x],y=t.a.filename?t.a.filename.length:0,w=t.a.comment?t.a.comment.length:0,!t.j)switch(t.h=r(t.buffer),t.a.compressionMethod){case 0:break;case 8:t.buffer=new o(t.buffer,t.a.deflateOption).g(),t.j=m;break;default:throw Error("unknown compression method:"+t.a.compressionMethod)}if(t.a.password!==v||this.i!==v){var U=t.a.password||this.i,C=[305419896,591751049,878082192],P=v,V=v;for(E&&(C=new Uint32Array(C)),P=0,V=U.length;V>P;++P)d(C,255&U[P]);for(S=C,T=t.buffer,E?(I=new Uint8Array(T.length+12),I.set(T,12),T=I):T.unshift(0,0,0,0,0,0,0,0,0,0,0,0),k=0;12>k;++k)T[k]=p(S,11===x?255&t.h:0|256*Math.random());for(_=T.length;_>k;++k)T[k]=p(S,T[k]);t.buffer=T}R+=30+y+t.buffer.length,F+=46+y+w}for(n=new(E?Uint8Array:Array)(R+F+(46+(this.d?this.d.length:0))),e=0,i=R,a=i+F,x=0,N=D.length;N>x;++x){if(t=D[x],y=t.a.filename?t.a.filename.length:0,w=t.a.comment?t.a.comment.length:0,s=e,n[e++]=L[0],n[e++]=L[1],n[e++]=L[2],n[e++]=L[3],n[i++]=j[0],n[i++]=j[1],n[i++]=j[2],n[i++]=j[3],n[i++]=20,n[i++]=t.a.os||0,n[e++]=n[i++]=20,u=n[e++]=n[i++]=0,(t.a.password||this.i)&&(u|=1),n[e++]=n[i++]=255&u,n[e++]=n[i++]=255&u>>8,c=t.a.compressionMethod,n[e++]=n[i++]=255&c,n[e++]=n[i++]=255&c>>8,f=t.a.date||new Date,n[e++]=n[i++]=0|((7&f.getMinutes())<<5|f.getSeconds()/2),n[e++]=n[i++]=f.getHours()<<3|f.getMinutes()>>3,n[e++]=n[i++]=(7&f.getMonth()+1)<<5|f.getDate(),n[e++]=n[i++]=(127&f.getFullYear()-1980)<<1|f.getMonth()+1>>3,l=t.h,n[e++]=n[i++]=255&l,n[e++]=n[i++]=255&l>>8,n[e++]=n[i++]=255&l>>16,n[e++]=n[i++]=255&l>>24,h=t.buffer.length,n[e++]=n[i++]=255&h,n[e++]=n[i++]=255&h>>8,n[e++]=n[i++]=255&h>>16,n[e++]=n[i++]=255&h>>24,g=t.size,n[e++]=n[i++]=255&g,n[e++]=n[i++]=255&g>>8,n[e++]=n[i++]=255&g>>16,n[e++]=n[i++]=255&g>>24,n[e++]=n[i++]=255&y,n[e++]=n[i++]=255&y>>8,n[e++]=n[i++]=0,n[e++]=n[i++]=0,n[i++]=255&w,n[i++]=255&w>>8,n[i++]=0,n[i++]=0,n[i++]=0,n[i++]=0,n[i++]=0,n[i++]=0,n[i++]=0,n[i++]=0,n[i++]=255&s,n[i++]=255&s>>8,n[i++]=255&s>>16,n[i++]=255&s>>24,b=t.a.filename)if(E)n.set(b,e),n.set(b,i),e+=y,i+=y;else for(k=0;y>k;++k)n[e++]=n[i++]=b[k];if(A=t.a.extraField)if(E)n.set(A,e),n.set(A,i),e+=0,i+=0;else for(k=0;w>k;++k)n[e++]=n[i++]=A[k];if(O=t.a.comment)if(E)n.set(O,i),i+=w;else for(k=0;w>k;++k)n[i++]=O[k];if(E)n.set(t.buffer,e),e+=t.buffer.length;else for(k=0,_=t.buffer.length;_>k;++k)n[e++]=t.buffer[k]}if(n[a++]=M[0],n[a++]=M[1],n[a++]=M[2],n[a++]=M[3],n[a++]=0,n[a++]=0,n[a++]=0,n[a++]=0,n[a++]=255&N,n[a++]=255&N>>8,n[a++]=255&N,n[a++]=255&N>>8,n[a++]=255&F,n[a++]=255&F>>8,n[a++]=255&F>>16,n[a++]=255&F>>24,n[a++]=255&R,n[a++]=255&R>>8,n[a++]=255&R>>16,n[a++]=255&R>>24,w=this.d?this.d.length:0,n[a++]=255&w,n[a++]=255&w>>8,this.d)if(E)n.set(this.d,a);else for(k=0,_=w;_>k;++k)n[a++]=this.d[k];return n},t("Zlib.Zip",h),t("Zlib.Zip.prototype.addFile",h.prototype.m),t("Zlib.Zip.prototype.compress",h.prototype.g),t("Zlib.Zip.prototype.setPassword",h.prototype.q),g("Zlib.Zip.CompressionMethod",{STORE:0,DEFLATE:8}),g("Zlib.Zip.OperatingSystem",{MSDOS:0,UNIX:3,MACINTOSH:7})}).call(e),function(){"use strict";function t(t){throw t}function n(t,n){var e=t.split("."),r=g;!(e[0]in r)&&r.execScript&&r.execScript("var "+e[0]);for(var i;e.length&&(i=e.shift());)e.length||n===d?r=r[i]?r[i]:r[i]={}:r[i]=n}function e(t){var n,e,r,i,o,a,s,u,c,f,l=t.length,h=0,p=Number.POSITIVE_INFINITY;for(u=0;l>u;++u)t[u]>h&&(h=t[u]),p>t[u]&&(p=t[u]);for(n=1<=r;){for(u=0;l>u;++u)if(t[u]===r){for(a=0,s=i,c=0;r>c;++c)a=a<<1|1&s,s>>=1;for(f=r<<16|u,c=a;n>c;c+=o)e[c]=f;++i}++r,i<<=1,o<<=1}return[e,h,p]}function r(n,e){switch(this.l=[],this.m=32768,this.d=this.f=this.c=this.t=0,this.input=v?new Uint8Array(n):n,this.u=!1,this.n=S,this.L=!1,(e||!(e={}))&&(e.index&&(this.c=e.index),e.bufferSize&&(this.m=e.bufferSize),e.bufferType&&(this.n=e.bufferType),e.resize&&(this.L=e.resize)),this.n){case I:this.a=32768,this.b=new(v?Uint8Array:Array)(32768+this.m+258);break;case S:this.a=0,this.b=new(v?Uint8Array:Array)(this.m),this.e=this.X,this.B=this.S,this.q=this.W;break;default:t(Error("invalid inflate mode"))}}function i(n,e){for(var r,i=n.f,o=n.d,a=n.input,s=n.c,u=a.length;e>o;)s>=u&&t(Error("input buffer is broken")),i|=a[s++]<>>e,n.d=o-e,n.c=s,r}function o(t,n){for(var e,r,i=t.f,o=t.d,a=t.input,s=t.c,u=a.length,c=n[0],f=n[1];f>o&&!(s>=u);)i|=a[s++]<>>16,t.f=i>>r,t.d=o-r,t.c=s,65535&e}function a(t){function n(t,n,e){var r,a,s,u=this.K;for(s=0;t>s;)switch(r=o(this,n)){case 16:for(a=3+i(this,2);a--;)e[s++]=u;break;case 17:for(a=3+i(this,3);a--;)e[s++]=0;u=0;break;case 18:for(a=11+i(this,7);a--;)e[s++]=0;u=0;break;default:u=e[s++]=r}return this.K=u,e}var r,a,s,u,c=i(t,5)+257,f=i(t,5)+1,l=i(t,4)+4,h=new(v?Uint8Array:Array)(_.length);for(u=0;l>u;++u)h[_[u]]=i(t,3);if(!v)for(u=l,l=h.length;l>u;++u)h[_[u]]=0;r=e(h),a=new(v?Uint8Array:Array)(c),s=new(v?Uint8Array:Array)(f),t.K=0,t.q(e(n.call(t,c,r,a)),e(n.call(t,f,r,s)))}function s(t){t=t||{},this.files=[],this.v=t.comment}function u(t,n){n=n||{},this.input=v&&t instanceof Array?new Uint8Array(t):t,this.c=0,this.ca=n.verify||!1,this.j=n.password}function c(t,n){this.input=t,this.offset=n}function f(t,n){this.input=t,this.offset=n}function l(n){var e,r,i,o,a=[],s={};if(!n.i){if(n.o===d){var u,f=n.input;if(!n.D)t:{var l,h=n.input;for(l=h.length-12;l>0;--l)if(h[l]===H[0]&&h[l+1]===H[1]&&h[l+2]===H[2]&&h[l+3]===H[3]){n.D=l;break t}t(Error("End of Central Directory Record not found"))}u=n.D,(f[u++]!==H[0]||f[u++]!==H[1]||f[u++]!==H[2]||f[u++]!==H[3])&&t(Error("invalid signature")),n.ia=f[u++]|f[u++]<<8,n.ka=f[u++]|f[u++]<<8,n.la=f[u++]|f[u++]<<8,n.ba=f[u++]|f[u++]<<8,n.R=(f[u++]|f[u++]<<8|f[u++]<<16|f[u++]<<24)>>>0,n.o=(f[u++]|f[u++]<<8|f[u++]<<16|f[u++]<<24)>>>0,n.w=f[u++]|f[u++]<<8,n.v=v?f.subarray(u,u+n.w):f.slice(u,u+n.w)}for(e=n.o,i=0,o=n.ba;o>i;++i)r=new c(n.input,e),r.parse(),e+=r.length,a[i]=r,s[r.filename]=i;n.Rm;++m)for(var y=m,E=7,y=y>>>1;y;y>>>=1)--E;var w,b=[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],A=v?new Uint32Array(b):b,O=[];for(w=0;288>w;w++)switch(!0){case 143>=w:O.push([w+48,8]);break;case 255>=w:O.push([w-144+400,9]);break;case 279>=w:O.push([w-256+0,7]);break;case 287>=w:O.push([w-280+192,8]);break;default:t("invalid literal: "+w)}var T=function(){function n(n){switch(!0){case 3===n:return[257,n-3,0];case 4===n:return[258,n-4,0];case 5===n:return[259,n-5,0];case 6===n:return[260,n-6,0];case 7===n:return[261,n-7,0];case 8===n:return[262,n-8,0];case 9===n:return[263,n-9,0];case 10===n:return[264,n-10,0];case 12>=n:return[265,n-11,1];case 14>=n:return[266,n-13,1];case 16>=n:return[267,n-15,1];case 18>=n:return[268,n-17,1];case 22>=n:return[269,n-19,2];case 26>=n:return[270,n-23,2];case 30>=n:return[271,n-27,2];case 34>=n:return[272,n-31,2];case 42>=n:return[273,n-35,3];case 50>=n:return[274,n-43,3];case 58>=n:return[275,n-51,3];case 66>=n:return[276,n-59,3];case 82>=n:return[277,n-67,4];case 98>=n:return[278,n-83,4];case 114>=n:return[279,n-99,4];case 130>=n:return[280,n-115,4];case 162>=n:return[281,n-131,5];case 194>=n:return[282,n-163,5];case 226>=n:return[283,n-195,5];case 257>=n:return[284,n-227,5];case 258===n:return[285,n-258,0];default:t("invalid length: "+n)}}var e,r,i=[];for(e=3;258>=e;e++)r=n(e),i[e]=r[2]<<24|r[1]<<16|r[0];return i}();v&&new Uint32Array(T);var I=0,S=1;r.prototype.r=function(){for(;!this.u;){var n=i(this,3);switch(1&n&&(this.u=!0),n>>>=1){case 0:var e=this.input,r=this.c,o=this.b,s=this.a,u=e.length,c=d,f=d,l=o.length,h=d;switch(this.d=this.f=0,r+1>=u&&t(Error("invalid uncompressed block header: LEN")),c=e[r++]|e[r++]<<8,r+1>=u&&t(Error("invalid uncompressed block header: NLEN")),f=e[r++]|e[r++]<<8,c===~f&&t(Error("invalid uncompressed block header: length verify")),r+c>e.length&&t(Error("input buffer is broken")),this.n){case I:for(;s+c>o.length;){if(h=l-s,c-=h,v)o.set(e.subarray(r,r+h),s),s+=h,r+=h;else for(;h--;)o[s++]=e[r++];this.a=s,o=this.e(),s=this.a}break;case S:for(;s+c>o.length;)o=this.e({H:2});break;default:t(Error("invalid inflate mode"))}if(v)o.set(e.subarray(r,r+c),s),s+=c,r+=c;else for(;c--;)o[s++]=e[r++];this.c=r,this.a=s,this.b=o;break;case 1:this.q(z,W);break;case 2:a(this);break;default:t(Error("unknown BTYPE: "+n))}}return this.B()};var x,N,k=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],_=v?new Uint16Array(k):k,D=[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=v?new Uint16Array(D):D,j=[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],L=v?new Uint8Array(j):j,M=[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],F=v?new Uint16Array(M):M,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],C=v?new Uint8Array(U):U,P=new(v?Uint8Array:Array)(288);for(x=0,N=P.length;N>x;++x)P[x]=143>=x?8:255>=x?9:279>=x?7:8;var V,B,z=e(P),Y=new(v?Uint8Array:Array)(30);for(V=0,B=Y.length;B>V;++V)Y[V]=5;var W=e(Y);p=r.prototype,p.q=function(t,n){var e=this.b,r=this.a;this.C=t;for(var a,s,u,c,f=e.length-258;256!==(a=o(this,t));)if(256>a)r>=f&&(this.a=r,e=this.e(),r=this.a),e[r++]=a;else for(s=a-257,c=R[s],L[s]>0&&(c+=i(this,L[s])),a=o(this,n),u=F[a],C[a]>0&&(u+=i(this,C[a])),r>=f&&(this.a=r,e=this.e(),r=this.a);c--;)e[r]=e[r++-u];for(;this.d>=8;)this.d-=8,this.c--;this.a=r},p.W=function(t,n){var e=this.b,r=this.a;this.C=t;for(var a,s,u,c,f=e.length;256!==(a=o(this,t));)if(256>a)r>=f&&(e=this.e(),f=e.length),e[r++]=a;else for(s=a-257,c=R[s],L[s]>0&&(c+=i(this,L[s])),a=o(this,n),u=F[a],C[a]>0&&(u+=i(this,C[a])),r+c>f&&(e=this.e(),f=e.length);c--;)e[r]=e[r++-u];for(;this.d>=8;)this.d-=8,this.c--;this.a=r},p.e=function(){var t,n,e=new(v?Uint8Array:Array)(this.a-32768),r=this.a-32768,i=this.b;if(v)e.set(i.subarray(32768,e.length));else for(t=0,n=e.length;n>t;++t)e[t]=i[t+32768];if(this.l.push(e),this.t+=e.length,v)i.set(i.subarray(r,r+32768));else for(t=0;32768>t;++t)i[t]=i[r+t];return this.a=32768,i},p.X=function(t){var n,e,r,i,o=0|this.input.length/this.c+1,a=this.input,s=this.b;return t&&("number"==typeof t.H&&(o=t.H),"number"==typeof t.Q&&(o+=t.Q)),2>o?(e=(a.length-this.c)/this.C[2],i=0|258*(e/2),r=s.length>i?s.length+i:s.length<<1):r=s.length*o,v?(n=new Uint8Array(r),n.set(s)):n=s,this.b=n},p.B=function(){var t,n,e,r,i,o=0,a=this.b,s=this.l,u=new(v?Uint8Array:Array)(this.t+(this.a-32768));if(0===s.length)return v?this.b.subarray(32768,this.a):this.b.slice(32768,this.a);for(n=0,e=s.length;e>n;++n)for(t=s[n],r=0,i=t.length;i>r;++r)u[o++]=t[r];for(n=32768,e=this.a;e>n;++n)u[o++]=a[n];return this.l=[],this.buffer=u},p.S=function(){var t,n=this.a;return v?this.L?(t=new Uint8Array(n),t.set(this.b.subarray(0,n))):t=this.b.subarray(0,n):(this.b.length>n&&(this.b.length=n),t=this.b),this.buffer=t},s.prototype.M=function(t){this.j=t},s.prototype.s=function(t){var n=2|65535&t[2];return 255&n*(1^n)>>8},s.prototype.k=function(t,n){t[0]=(A[255&(t[0]^n)]^t[0]>>>8)>>>0,t[1]=(6681*(20173*(t[1]+(255&t[0]))>>>0)>>>0)+1>>>0,t[2]=(A[255&(t[2]^t[1]>>>24)]^t[2]>>>8)>>>0},s.prototype.U=function(t){var n,e,r=[305419896,591751049,878082192];for(v&&(r=new Uint32Array(r)),n=0,e=t.length;e>n;++n)this.k(r,255&t[n]);return r};var X={P:0,N:8},q=[80,75,1,2],Z=[80,75,3,4],H=[80,75,5,6];c.prototype.parse=function(){var n=this.input,e=this.offset;(n[e++]!==q[0]||n[e++]!==q[1]||n[e++]!==q[2]||n[e++]!==q[3])&&t(Error("invalid file header signature")),this.version=n[e++],this.ja=n[e++],this.$=n[e++]|n[e++]<<8,this.I=n[e++]|n[e++]<<8,this.A=n[e++]|n[e++]<<8,this.time=n[e++]|n[e++]<<8,this.V=n[e++]|n[e++]<<8,this.p=(n[e++]|n[e++]<<8|n[e++]<<16|n[e++]<<24)>>>0,this.z=(n[e++]|n[e++]<<8|n[e++]<<16|n[e++]<<24)>>>0,this.J=(n[e++]|n[e++]<<8|n[e++]<<16|n[e++]<<24)>>>0,this.h=n[e++]|n[e++]<<8,this.g=n[e++]|n[e++]<<8,this.F=n[e++]|n[e++]<<8,this.fa=n[e++]|n[e++]<<8,this.ha=n[e++]|n[e++]<<8,this.ga=n[e++]|n[e++]<<8|n[e++]<<16|n[e++]<<24,this.aa=(n[e++]|n[e++]<<8|n[e++]<<16|n[e++]<<24)>>>0,this.filename=String.fromCharCode.apply(null,v?n.subarray(e,e+=this.h):n.slice(e,e+=this.h)),this.Y=v?n.subarray(e,e+=this.g):n.slice(e,e+=this.g),this.v=v?n.subarray(e,e+this.F):n.slice(e,e+this.F),this.length=e-this.offset};var J={O:1,da:8,ea:2048};f.prototype.parse=function(){var n=this.input,e=this.offset;(n[e++]!==Z[0]||n[e++]!==Z[1]||n[e++]!==Z[2]||n[e++]!==Z[3])&&t(Error("invalid local file header signature")),this.$=n[e++]|n[e++]<<8,this.I=n[e++]|n[e++]<<8,this.A=n[e++]|n[e++]<<8,this.time=n[e++]|n[e++]<<8,this.V=n[e++]|n[e++]<<8,this.p=(n[e++]|n[e++]<<8|n[e++]<<16|n[e++]<<24)>>>0,this.z=(n[e++]|n[e++]<<8|n[e++]<<16|n[e++]<<24)>>>0,this.J=(n[e++]|n[e++]<<8|n[e++]<<16|n[e++]<<24)>>>0,this.h=n[e++]|n[e++]<<8,this.g=n[e++]|n[e++]<<8,this.filename=String.fromCharCode.apply(null,v?n.subarray(e,e+=this.h):n.slice(e,e+=this.h)),this.Y=v?n.subarray(e,e+=this.g):n.slice(e,e+=this.g),this.length=e-this.offset},p=u.prototype,p.Z=function(){var t,n,e,r=[];for(this.i||l(this),e=this.i,t=0,n=e.length;n>t;++t)r[t]=e[t].filename;return r},p.r=function(n,e){var i;this.G||l(this),i=this.G[n],i===d&&t(Error(n+" not found"));var o;o=e||{};var a,s,u,c,p,g,m,y,E=this.input,w=this.i;if(w||l(this),w[i]===d&&t(Error("wrong index")),s=w[i].aa,a=new f(this.input,s),a.parse(),s+=a.length,u=a.z,0!==(a.I&J.O)){for(!o.password&&!this.j&&t(Error("please set password")),g=this.T(o.password||this.j),m=s,y=s+12;y>m;++m)h(this,g,E[m]);for(s+=12,u-=12,m=s,y=s+u;y>m;++m)E[m]=h(this,g,E[m])}switch(a.A){case X.P:c=v?this.input.subarray(s,s+u):this.input.slice(s,s+u);break;case X.N:c=new r(this.input,{index:s,bufferSize:a.J}).r();break;default:t(Error("unknown compression type"))}if(this.ca){var b,O=d,T="number"==typeof O?O:O=0,I=c.length;for(b=-1,T=7&I;T--;++O)b=b>>>8^A[255&(b^c[O])];for(T=I>>3;T--;O+=8)b=b>>>8^A[255&(b^c[O])],b=b>>>8^A[255&(b^c[O+1])],b=b>>>8^A[255&(b^c[O+2])],b=b>>>8^A[255&(b^c[O+3])],b=b>>>8^A[255&(b^c[O+4])],b=b>>>8^A[255&(b^c[O+5])],b=b>>>8^A[255&(b^c[O+6])],b=b>>>8^A[255&(b^c[O+7])];p=(4294967295^b)>>>0,a.p!==p&&t(Error("wrong crc: file=0x"+a.p.toString(16)+", data=0x"+p.toString(16)))}return c},p.M=function(t){this.j=t},p.k=s.prototype.k,p.T=s.prototype.U,p.s=s.prototype.s,n("Zlib.Unzip",u),n("Zlib.Unzip.prototype.decompress",u.prototype.r),n("Zlib.Unzip.prototype.getFilenames",u.prototype.Z),n("Zlib.Unzip.prototype.setPassword",u.prototype.M)}.call(e),n.exports=e.Zlib},{}],7:[function(t,n){function e(){}var r=n.exports={};r.nextTick=function(){var t="undefined"!=typeof window&&window.setImmediate,n="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(t)return function(t){return window.setImmediate(t)};if(n){var e=[];return window.addEventListener("message",function(t){var n=t.source;if((n===window||null===n)&&"process-tick"===t.data&&(t.stopPropagation(),e.length>0)){var r=e.shift();r()}},!0),function(t){e.push(t),window.postMessage("process-tick","*")}}return function(t){setTimeout(t,0)}}(),r.title="browser",r.browser=!0,r.env={},r.argv=[],r.on=e,r.addListener=e,r.once=e,r.off=e,r.removeListener=e,r.removeAllListeners=e,r.emit=e,r.binding=function(){throw Error("process.binding is not supported")},r.cwd=function(){return"/"},r.chdir=function(){throw Error("process.chdir is not supported")}},{}],8:[function(t,n){var e="READ",r="WRITE",i="CREATE",o="EXCLUSIVE",a="TRUNCATE",s="APPEND",u="CREATE",c="REPLACE";n.exports={FILE_SYSTEM_NAME:"local",FILE_STORE_NAME:"files",IDB_RO:"readonly",IDB_RW:"readwrite",WSQL_VERSION:"1",WSQL_SIZE:5242880,WSQL_DESC:"FileSystem Storage",MODE_FILE:"FILE",MODE_DIRECTORY:"DIRECTORY",MODE_SYMBOLIC_LINK:"SYMLINK",MODE_META:"META",SYMLOOP_MAX:10,BINARY_MIME_TYPE:"application/octet-stream",JSON_MIME_TYPE:"application/json",ROOT_DIRECTORY_NAME:"/",FS_FORMAT:"FORMAT",FS_NOCTIME:"NOCTIME",FS_NOMTIME:"NOMTIME",O_READ:e,O_WRITE:r,O_CREATE:i,O_EXCLUSIVE:o,O_TRUNCATE:a,O_APPEND:s,O_FLAGS:{r:[e],"r+":[e,r],w:[r,i,a],"w+":[r,e,i,a],wx:[r,i,o,a],"wx+":[r,e,i,o,a],a:[r,i,s],"a+":[r,e,i,s],ax:[r,i,o,s],"ax+":[r,e,i,o,s]},XATTR_CREATE:u,XATTR_REPLACE:c,FS_READY:"READY",FS_PENDING:"PENDING",FS_ERROR:"ERROR",SUPER_NODE_ID:"00000000-0000-0000-0000-000000000000",STDIN:0,STDOUT:1,STDERR:2,FIRST_DESCRIPTOR:3,ENVIRONMENT:{TMP:"/tmp",PATH:""}}},{}],9:[function(t,n){var e=t("./constants.js").MODE_FILE;n.exports=function(t,n){this.id=t,this.type=n||e}},{"./constants.js":8}],10:[function(t,n){var e={};["-1:UNKNOWN:unknown error","0:OK:success","1:EOF:end of file","2:EADDRINFO:getaddrinfo error","3:EACCES:permission denied","4:EAGAIN:resource temporarily unavailable","5:EADDRINUSE:address already in use","6:EADDRNOTAVAIL:address not available","7:EAFNOSUPPORT:address family not supported","8:EALREADY:connection already in progress","9:EBADF:bad file descriptor","10:EBUSY:resource busy or locked","11:ECONNABORTED:software caused connection abort","12:ECONNREFUSED:connection refused","13:ECONNRESET:connection reset by peer","14:EDESTADDRREQ:destination address required","15:EFAULT:bad address in system call argument","16:EHOSTUNREACH:host is unreachable","17:EINTR:interrupted system call","18:EINVAL:invalid argument","19:EISCONN:socket is already connected","20:EMFILE:too many open files","21:EMSGSIZE:message too long","22:ENETDOWN:network is down","23:ENETUNREACH:network is unreachable","24:ENFILE:file table overflow","25:ENOBUFS:no buffer space available","26:ENOMEM:not enough memory","27:ENOTDIR:not a directory","28:EISDIR:illegal operation on a directory","29:ENONET:machine is not on the network","31:ENOTCONN:socket is not connected","32:ENOTSOCK:socket operation on non-socket","33:ENOTSUP:operation not supported on socket","34:ENOENT:no such file or directory","35:ENOSYS:function not implemented","36:EPIPE:broken pipe","37:EPROTO:protocol error","38:EPROTONOSUPPORT:protocol not supported","39:EPROTOTYPE:protocol wrong type for socket","40:ETIMEDOUT:connection timed out","41:ECHARSET:invalid Unicode character","42:EAIFAMNOSUPPORT:address family for hostname not supported","44:EAISERVICE:servname not supported for ai_socktype","45:EAISOCKTYPE:ai_socktype not supported","46:ESHUTDOWN:cannot send after transport endpoint shutdown","47:EEXIST:file already exists","48:ESRCH:no such process","49:ENAMETOOLONG:name too long","50:EPERM:operation not permitted","51:ELOOP:too many symbolic links encountered","52:EXDEV:cross-device link not permitted","53:ENOTEMPTY:directory not empty","54:ENOSPC:no space left on device","55:EIO:i/o error","56:EROFS:read-only file system","57:ENODEV:no such device","58:ESPIPE:invalid seek","59:ECANCELED:operation canceled","1000:ENOTMOUNTED:not mounted","1001:EFILESYSTEMERROR:missing super node, use 'FORMAT' flag to format filesystem.","1002:ENOATTR:attribute does not exist"].forEach(function(t){function n(t){this.message=t||o}t=t.split(":");var r=t[0],i=t[1],o=t[2],a=n.prototype=Error();a.errno=r,a.code=i,a.constructor=n,e[i]=e[r]=n}),n.exports=e},{}],11:[function(t,n){function e(t){return function(n,e){n?t(n):t(null,e)}}function r(t,n,e,r,i){function o(e){t.changes.push({event:"change",path:n}),i(e)}var a=t.flags;pn(a).contains(Pn)&&delete r.ctime,pn(a).contains(Cn)&&delete r.mtime;var s=!1;r.ctime&&(e.ctime=r.ctime,e.atime=r.ctime,s=!0),r.atime&&(e.atime=r.atime,s=!0),r.mtime&&(e.mtime=r.mtime,s=!0),s?t.put(e.id,e,o):o()}function i(t,n,e,i){function a(e,r){e?i(e):r.mode!==Tn?i(new Vn.ENOTDIR("a component of the path prefix is not a directory")):(l=r,o(t,n,s))}function s(n,e){!n&&e?i(new Vn.EEXIST("path name already exists")):!n||n instanceof Vn.ENOENT?t.get(l.data,u):i(n)}function u(n,r){n?i(n):(h=r,p=new Wn(void 0,e),p.nlinks+=1,t.put(p.id,p,f))}function c(n){if(n)i(n);else{var e=Date.now();r(t,g,p,{mtime:e,ctime:e},i)}}function f(n){n?i(n):(h[d]=new Bn(p.id,e),t.put(l.data,h,c))}if(e!==Tn&&e!==On)return i(new Vn.EINVAL("mode must be a directory or file"));n=mn(n);var l,h,p,d=En(n),g=yn(n);o(t,g,a)}function o(t,n,e){function r(n,r){n?e(n):r&&r.mode===Sn&&r.rnode?t.get(r.rnode,i):e(new Vn.EFILESYSTEMERROR)}function i(t,n){t?e(t):n?e(null,n):e(new Vn.ENOENT)}function a(n,r){n?e(n):r.mode===Tn&&r.data?t.get(r.data,s):e(new Vn.ENOTDIR("a component of the path prefix is not a directory"))}function s(n,r){if(n)e(n);else if(pn(r).has(f)){var i=r[f].id;t.get(i,u)}else e(new Vn.ENOENT)}function u(t,n){t?e(t):n.mode==In?(h++,h>kn?e(new Vn.ELOOP):c(n.data)):e(null,n)}function c(n){n=mn(n),l=yn(n),f=En(n),xn==f?t.get(Nn,r):o(t,l,a)}if(n=mn(n),!n)return e(new Vn.ENOENT("path is an empty string"));var f=En(n),l=yn(n),h=0;xn==f?t.get(Nn,r):o(t,l,a)}function a(t,n,e,i,a,s){function u(n,o){function u(n){n?s(n):r(t,c,o,{ctime:Date.now()},s)}o?o.xattrs[e]:null,n?s(n):a===Fn&&o.xattrs.hasOwnProperty(e)?s(new Vn.EEXIST("attribute already exists")):a!==Un||o.xattrs.hasOwnProperty(e)?(o.xattrs[e]=i,t.put(o.id,o,u)):s(new Vn.ENOATTR)}var c;"string"==typeof n?(c=n,o(t,n,u)):"object"==typeof n&&"string"==typeof n.id?(c=n.path,t.get(n.id,u)):s(new Vn.EINVAL("path or file descriptor of wrong type"))}function s(t,n){function e(e,i){!e&&i?n(new Vn.EEXIST):!e||e instanceof Vn.ENOENT?(o=new Yn,t.put(o.id,o,r)):n(e)}function r(e){e?n(e):(a=new Wn(o.rnode,Tn),a.nlinks+=1,t.put(a.id,a,i))}function i(e){e?n(e):(s={},t.put(a.data,s,n))}var o,a,s;t.get(Nn,e)}function u(t,n,e){function i(n,r){!n&&r?e(new Vn.EEXIST):!n||n instanceof Vn.ENOENT?o(t,v,a):e(n)}function a(n,r){n?e(n):(p=r,t.get(p.data,s))}function s(n,r){n?e(n):(d=r,l=new Wn(void 0,Tn),l.nlinks+=1,t.put(l.id,l,u))}function u(n){n?e(n):(h={},t.put(l.data,h,f))}function c(n){if(n)e(n);else{var i=Date.now();r(t,v,p,{mtime:i,ctime:i},e)}}function f(n){n?e(n):(d[g]=new Bn(l.id,Tn),t.put(p.data,d,c))}n=mn(n);var l,h,p,d,g=En(n),v=yn(n);o(t,n,i)}function c(t,n,e){function i(n,r){n?e(n):(g=r,t.get(g.data,a))}function a(n,r){n?e(n):xn==m?e(new Vn.EBUSY):pn(r).has(m)?(v=r,p=v[m].id,t.get(p,s)):e(new Vn.ENOENT)}function s(n,r){n?e(n):r.mode!=Tn?e(new Vn.ENOTDIR):(p=r,t.get(p.data,u))}function u(t,n){t?e(t):(d=n,pn(d).size()>0?e(new Vn.ENOTEMPTY):f())}function c(n){if(n)e(n);else{var i=Date.now();r(t,y,g,{mtime:i,ctime:i},l)}}function f(){delete v[m],t.put(g.data,v,c)}function l(n){n?e(n):t.delete(p.id,h)}function h(n){n?e(n):t.delete(p.data,e)}n=mn(n);var p,d,g,v,m=En(n),y=yn(n);o(t,y,i)}function f(t,n,e,i){function a(n,e){n?i(n):(v=e,t.get(v.data,s))}function s(n,r){n?i(n):(m=r,pn(m).has(b)?pn(e).contains(jn)?i(new Vn.ENOENT("O_CREATE and O_EXCLUSIVE are set, and the named file exists")):(y=m[b],y.type==Tn&&pn(e).contains(Dn)?i(new Vn.EISDIR("the named file is a directory and O_WRITE is set")):t.get(y.id,u)):pn(e).contains(Rn)?l():i(new Vn.ENOENT("O_CREATE is not set and the named file does not exist")))}function u(t,n){if(t)i(t);else{var e=n;e.mode==In?(O++,O>kn?i(new Vn.ELOOP):c(e.data)):f(void 0,e)}}function c(r){r=mn(r),A=yn(r),b=En(r),xn==b&&(pn(e).contains(Dn)?i(new Vn.EISDIR("the named file is a directory and O_WRITE is set")):o(t,n,f)),o(t,A,a)}function f(t,n){t?i(t):(E=n,i(null,E))}function l(){E=new Wn(void 0,On),E.nlinks+=1,t.put(E.id,E,h)}function h(n){n?i(n):(w=new Uint8Array(0),t.put(E.data,w,d))}function p(n){if(n)i(n);else{var e=Date.now();r(t,A,v,{mtime:e,ctime:e},g)}}function d(n){n?i(n):(m[b]=new Bn(E.id,On),t.put(v.data,m,p))}function g(t){t?i(t):i(null,E)}n=mn(n);var v,m,y,E,w,b=En(n),A=yn(n),O=0;xn==b?pn(e).contains(Dn)?i(new Vn.EISDIR("the named file is a directory and O_WRITE is set")):o(t,n,f):o(t,A,a)}function l(t,n,e,i,o,a){function s(t){t?a(t):a(null,o)}function u(e){if(e)a(e);else{var i=Date.now();r(t,n.path,l,{mtime:i,ctime:i},s)}}function c(n){n?a(n):t.put(l.id,l,u)}function f(r,s){if(r)a(r);else{l=s;var u=new Uint8Array(o),f=e.subarray(i,i+o);u.set(f),n.position=o,l.size=o,l.version+=1,t.put(l.data,u,c)}}var l;t.get(n.id,f)}function h(t,n,e,i,o,a,s){function u(t){t?s(t):s(null,o)}function c(e){if(e)s(e);else{var i=Date.now();r(t,n.path,p,{mtime:i,ctime:i},u)}}function f(n){n?s(n):t.put(p.id,p,c)}function l(r,u){if(r)s(r);else{d=u;var c=void 0!==a&&null!==a?a:n.position,l=Math.max(d.length,c+o),h=new Uint8Array(l);d&&h.set(d);var g=e.subarray(i,i+o);h.set(g,c),void 0===a&&(n.position+=o),p.size=l,p.version+=1,t.put(p.data,h,f)}}function h(n,e){n?s(n):(p=e,t.get(p.data,l))}var p,d;t.get(n.id,h)}function p(t,n,e,r,i,o,a){function s(t,s){if(t)a(t);else{f=s;var u=void 0!==o&&null!==o?o:n.position;i=u+i>e.length?i-u:i;var c=f.subarray(u,u+i);e.set(c,r),void 0===o&&(n.position+=i),a(null,i)}}function u(n,e){n?a(n):(c=e,t.get(c.data,s))}var c,f;t.get(n.id,u)}function d(t,n,r){n=mn(n),En(n),o(t,n,e(r))}function g(t,n,r){t.get(n.id,e(r))}function v(t,n,r){function i(n,e){n?r(n):(s=e,t.get(s.data,a))}function a(n,i){n?r(n):(u=i,pn(u).has(c)?t.get(u[c].id,e(r)):r(new Vn.ENOENT("a component of the path does not name an existing file")))}n=mn(n);var s,u,c=En(n),f=yn(n);xn==c?o(t,n,e(r)):o(t,f,i)}function m(t,n,e,i){function a(n){n?i(n):r(t,e,E,{ctime:Date.now()},i)}function s(n,e){n?i(n):(E=e,E.nlinks+=1,t.put(E.id,E,a))}function u(n){n?i(n):t.get(y[w].id,s)}function c(n,e){n?i(n):(y=e,pn(y).has(w)?i(new Vn.EEXIST("newpath resolves to an existing file")):(y[w]=v[p],t.put(m.data,y,u)))}function f(n,e){n?i(n):(m=e,t.get(m.data,c))}function l(n,e){n?i(n):(v=e,pn(v).has(p)?o(t,b,f):i(new Vn.ENOENT("a component of either path prefix does not exist")))}function h(n,e){n?i(n):(g=e,t.get(g.data,l))}n=mn(n);var p=En(n),d=yn(n);e=mn(e);var g,v,m,y,E,w=En(e),b=yn(e);o(t,d,h)}function y(t,n,e){function i(n){n?e(n):(delete l[p],t.put(f.data,l,function(){var n=Date.now();r(t,d,f,{mtime:n,ctime:n},e)}))}function a(n){n?e(n):t.delete(h.data,i)}function s(o,s){o?e(o):(h=s,h.nlinks-=1,1>h.nlinks?t.delete(h.id,a):t.put(h.id,h,function(){r(t,n,h,{ctime:Date.now()},i) -}))}function u(n,r){n?e(n):(l=r,pn(l).has(p)?t.get(l[p].id,s):e(new Vn.ENOENT("a component of the path does not name an existing file")))}function c(n,r){n?e(n):(f=r,t.get(f.data,u))}n=mn(n);var f,l,h,p=En(n),d=yn(n);o(t,d,c)}function E(t,n,e){function r(t,n){if(t)e(t);else{s=n;var r=Object.keys(s);e(null,r)}}function i(n,i){n?e(n):(a=i,t.get(a.data,r))}n=mn(n),En(n);var a,s;o(t,n,i)}function w(t,n,e,i){function a(n,e){n?i(n):(l=e,t.get(l.data,s))}function s(t,n){t?i(t):(h=n,pn(h).has(d)?i(new Vn.EEXIST):u())}function u(){p=new Wn(void 0,In),p.nlinks+=1,p.size=n.length,p.data=n,t.put(p.id,p,f)}function c(n){if(n)i(n);else{var e=Date.now();r(t,g,l,{mtime:e,ctime:e},i)}}function f(n){n?i(n):(h[d]=new Bn(p.id,In),t.put(l.data,h,c))}e=mn(e);var l,h,p,d=En(e),g=yn(e);xn==d?i(new Vn.EEXIST):o(t,g,a)}function b(t,n,e){function r(n,r){n?e(n):(s=r,t.get(s.data,i))}function i(n,r){n?e(n):(u=r,pn(u).has(c)?t.get(u[c].id,a):e(new Vn.ENOENT("a component of the path does not name an existing file")))}function a(t,n){t?e(t):n.mode!=In?e(new Vn.EINVAL("path not a symbolic link")):e(null,n.data)}n=mn(n);var s,u,c=En(n),f=yn(n);o(t,f,r)}function A(t,n,e,i){function a(n,e){n?i(n):e.mode==Tn?i(new Vn.EISDIR):(f=e,t.get(f.data,s))}function s(n,r){if(n)i(n);else{var o=new Uint8Array(e);r&&o.set(r.subarray(0,e)),t.put(f.data,o,c)}}function u(e){if(e)i(e);else{var o=Date.now();r(t,n,f,{mtime:o,ctime:o},i)}}function c(n){n?i(n):(f.size=e,f.version+=1,t.put(f.id,f,u))}n=mn(n);var f;0>e?i(new Vn.EINVAL("length cannot be negative")):o(t,n,a)}function O(t,n,e,i){function o(n,e){n?i(n):e.mode==Tn?i(new Vn.EISDIR):(c=e,t.get(c.data,a))}function a(n,r){if(n)i(n);else{var o=new Uint8Array(e);r&&o.set(r.subarray(0,e)),t.put(c.data,o,u)}}function s(e){if(e)i(e);else{var o=Date.now();r(t,n.path,c,{mtime:o,ctime:o},i)}}function u(n){n?i(n):(c.size=e,c.version+=1,t.put(c.id,c,s))}var c;0>e?i(new Vn.EINVAL("length cannot be negative")):t.get(n.id,o)}function T(t,n,e,i,a){function s(o,s){o?a(o):r(t,n,s,{atime:e,ctime:i,mtime:i},a)}n=mn(n),"number"!=typeof e||"number"!=typeof i?a(new Vn.EINVAL("atime and mtime must be number")):0>e||0>i?a(new Vn.EINVAL("atime and mtime must be positive integers")):o(t,n,s)}function I(t,n,e,i,o){function a(a,s){a?o(a):r(t,n.path,s,{atime:e,ctime:i,mtime:i},o)}"number"!=typeof e||"number"!=typeof i?o(new Vn.EINVAL("atime and mtime must be a number")):0>e||0>i?o(new Vn.EINVAL("atime and mtime must be positive integers")):t.get(n.id,a)}function S(t,n,e,r,i,o){n=mn(n),"string"!=typeof e?o(new Vn.EINVAL("attribute name must be a string")):e?null!==i&&i!==Fn&&i!==Un?o(new Vn.EINVAL("invalid flag, must be null, XATTR_CREATE or XATTR_REPLACE")):a(t,n,e,r,i,o):o(new Vn.EINVAL("attribute name cannot be an empty string"))}function x(t,n,e,r,i,o){"string"!=typeof e?o(new Vn.EINVAL("attribute name must be a string")):e?null!==i&&i!==Fn&&i!==Un?o(new Vn.EINVAL("invalid flag, must be null, XATTR_CREATE or XATTR_REPLACE")):a(t,n,e,r,i,o):o(new Vn.EINVAL("attribute name cannot be an empty string"))}function N(t,n,e,r){function i(t,n){n?n.xattrs[e]:null,t?r(t):n.xattrs.hasOwnProperty(e)?r(null,n.xattrs[e]):r(new Vn.ENOATTR)}n=mn(n),"string"!=typeof e?r(new Vn.EINVAL("attribute name must be a string")):e?o(t,n,i):r(new Vn.EINVAL("attribute name cannot be an empty string"))}function k(t,n,e,r){function i(t,n){n?n.xattrs[e]:null,t?r(t):n.xattrs.hasOwnProperty(e)?r(null,n.xattrs[e]):r(new Vn.ENOATTR)}"string"!=typeof e?r(new Vn.EINVAL):e?t.get(n.id,i):r(new Vn.EINVAL("attribute name cannot be an empty string"))}function _(t,n,e,i){function a(o,a){function s(e){e?i(e):r(t,n,a,{ctime:Date.now()},i)}var u=a?a.xattrs:null;o?i(o):u.hasOwnProperty(e)?(delete a.xattrs[e],t.put(a.id,a,s)):i(new Vn.ENOATTR)}n=mn(n),"string"!=typeof e?i(new Vn.EINVAL("attribute name must be a string")):e?o(t,n,a):i(new Vn.EINVAL("attribute name cannot be an empty string"))}function D(t,n,e,i){function o(o,a){function s(e){e?i(e):r(t,n.path,a,{ctime:Date.now()},i)}o?i(o):a.xattrs.hasOwnProperty(e)?(delete a.xattrs[e],t.put(a.id,a,s)):i(new Vn.ENOATTR)}"string"!=typeof e?i(new Vn.EINVAL("attribute name must be a string")):e?t.get(n.id,o):i(new Vn.EINVAL("attribute name cannot be an empty string"))}function R(t){return pn(Mn).has(t)?Mn[t]:null}function j(t,n,e){return t?"function"==typeof t?t={encoding:n,flag:e}:"string"==typeof t&&(t={encoding:t,flag:e}):t={encoding:n,flag:e},t}function L(t,n){var e;return bn(t)?e=Error("Path must be a string without null bytes."):wn(t)||(e=Error("Path must be absolute.")),e?(n(e),!1):!0}function M(t,n,e,r,i,o){function a(n,i){if(n)o(n);else{var a;a=pn(r).contains(Ln)?i.size:0;var s=new zn(e,i.id,r,a),u=t.allocDescriptor(s);o(null,u)}}o=arguments[arguments.length-1],L(e,o)&&(r=R(r),r||o(new Vn.EINVAL("flags is not valid")),f(n,e,r,a))}function F(t,n,e,r){pn(t.openFiles).has(e)?(t.releaseDescriptor(e),r(null)):r(new Vn.EBADF)}function U(t,n,e,r,o){L(e,o)&&i(n,e,r,o)}function C(t,n,r,i,o){o=arguments[arguments.length-1],L(r,o)&&u(n,r,e(o))}function P(t,n,r,i){L(r,i)&&c(n,r,e(i))}function V(t,n,e,r){function i(n,e){if(n)r(n);else{var i=new Xn(e,t.name);r(null,i)}}L(e,r)&&d(n,e,i)}function B(t,n,e,r){function i(n,e){if(n)r(n);else{var i=new Xn(e,t.name);r(null,i)}}var o=t.openFiles[e];o?g(n,o,i):r(new Vn.EBADF)}function z(t,n,r,i,o){L(r,o)&&L(i,o)&&m(n,r,i,e(o))}function Y(t,n,r,i){L(r,i)&&y(n,r,e(i))}function W(t,n,r,i,o,a,s,u){function c(t,n){u(t,n||0,i)}o=void 0===o?0:o,a=void 0===a?i.length-o:a,u=arguments[arguments.length-1];var f=t.openFiles[r];f?pn(f.flags).contains(_n)?p(n,f,i,o,a,s,e(c)):u(new Vn.EBADF("descriptor does not permit reading")):u(new Vn.EBADF)}function X(t,n,e,r,i){if(i=arguments[arguments.length-1],r=j(r,null,"r"),L(e,i)){var o=R(r.flag||"r");o||i(new Vn.EINVAL("flags is not valid")),f(n,e,o,function(a,s){if(a)return i(a);var u=new zn(e,s.id,o,0),c=t.allocDescriptor(u);g(n,u,function(e,o){if(e)return i(e);var a=new Xn(o,t.name),s=a.size,f=new Uint8Array(s);p(n,u,f,0,s,0,function(n){if(n)return i(n);t.releaseDescriptor(c);var e;e="utf8"===r.encoding?new dn("utf-8").decode(f):f,i(null,e)})})})}}function q(t,n,r,i,o,a,s,u){u=arguments[arguments.length-1],o=void 0===o?0:o,a=void 0===a?i.length-o:a;var c=t.openFiles[r];c?pn(c.flags).contains(Dn)?a>i.length-o?u(new Vn.EIO("intput buffer is too small")):h(n,c,i,o,a,s,e(u)):u(new Vn.EBADF("descriptor does not permit writing")):u(new Vn.EBADF)}function Z(t,n,e,r,i,o){if(o=arguments[arguments.length-1],i=j(i,"utf8","w"),L(e,o)){var a=R(i.flag||"w");a||o(new Vn.EINVAL("flags is not valid")),r=r||"","number"==typeof r&&(r=""+r),"string"==typeof r&&"utf8"===i.encoding&&(r=new gn("utf-8").encode(r)),f(n,e,a,function(i,s){if(i)return o(i);var u=new zn(e,s.id,a,0),c=t.allocDescriptor(u);l(n,u,r,0,r.length,function(n){return n?o(n):(t.releaseDescriptor(c),o(null),void 0)})})}}function H(t,n,e,r,i,o){if(o=arguments[arguments.length-1],i=j(i,"utf8","a"),L(e,o)){var a=R(i.flag||"a");a||o(new Vn.EINVAL("flags is not valid")),r=r||"","number"==typeof r&&(r=""+r),"string"==typeof r&&"utf8"===i.encoding&&(r=new gn("utf-8").encode(r)),f(n,e,a,function(i,s){if(i)return o(i);var u=new zn(e,s.id,a,s.size),c=t.allocDescriptor(u);h(n,u,r,0,r.length,u.position,function(n){return n?o(n):(t.releaseDescriptor(c),o(null),void 0)})})}}function J(t,n,e,r){function i(t){r(t?!1:!0)}V(t,n,e,i)}function G(t,n,r,i,o){L(r,o)&&N(n,r,i,e(o))}function Q(t,n,r,i,o){var a=t.openFiles[r];a?k(n,a,i,e(o)):o(new Vn.EBADF)}function K(t,n,r,i,o,a,s){"function"==typeof a&&(s=a,a=null),L(r,s)&&S(n,r,i,o,a,e(s))}function $(t,n,r,i,o,a,s){"function"==typeof a&&(s=a,a=null);var u=t.openFiles[r];u?pn(u.flags).contains(Dn)?x(n,u,i,o,a,e(s)):s(new Vn.EBADF("descriptor does not permit writing")):s(new Vn.EBADF)}function tn(t,n,r,i,o){L(r,o)&&_(n,r,i,e(o))}function nn(t,n,r,i,o){var a=t.openFiles[r];a?pn(a.flags).contains(Dn)?D(n,a,i,e(o)):o(new Vn.EBADF("descriptor does not permit writing")):o(new Vn.EBADF)}function en(t,n,e,r,i,o){function a(t,n){t?o(t):0>n.size+r?o(new Vn.EINVAL("resulting file offset would be negative")):(s.position=n.size+r,o(null,s.position))}var s=t.openFiles[e];s||o(new Vn.EBADF),"SET"===i?0>r?o(new Vn.EINVAL("resulting file offset would be negative")):(s.position=r,o(null,s.position)):"CUR"===i?0>s.position+r?o(new Vn.EINVAL("resulting file offset would be negative")):(s.position+=r,o(null,s.position)):"END"===i?g(n,s,a):o(new Vn.EINVAL("whence argument is not a proper value"))}function rn(t,n,r,i){L(r,i)&&E(n,r,e(i))}function on(t,n,r,i,o,a){if(L(r,a)){var s=Date.now();i=i?i:s,o=o?o:s,T(n,r,i,o,e(a))}}function an(t,n,r,i,o,a){var s=Date.now();i=i?i:s,o=o?o:s;var u=t.openFiles[r];u?pn(u.flags).contains(Dn)?I(n,u,i,o,e(a)):a(new Vn.EBADF("descriptor does not permit writing")):a(new Vn.EBADF)}function sn(t,n,r,i,o){function a(t){t?o(t):y(n,r,e(o))}L(r,o)&&L(i,o)&&m(n,r,i,a)}function un(t,n,r,i,o,a){a=arguments[arguments.length-1],L(r,a)&&L(i,a)&&w(n,r,i,e(a))}function cn(t,n,r,i){L(r,i)&&b(n,r,e(i))}function fn(t,n,e,r){function i(n,e){if(n)r(n);else{var i=new Xn(e,t.name);r(null,i)}}L(e,r)&&v(n,e,i)}function ln(t,n,r,i,o){o=arguments[arguments.length-1],i=i||0,L(r,o)&&A(n,r,i,e(o))}function hn(t,n,r,i,o){o=arguments[arguments.length-1],i=i||0;var a=t.openFiles[r];a?pn(a.flags).contains(Dn)?O(n,a,i,e(o)):o(new Vn.EBADF("descriptor does not permit writing")):o(new Vn.EBADF)}var pn=t("../../lib/nodash.js"),dn=t("../../lib/encoding.js").TextDecoder,gn=t("../../lib/encoding.js").TextEncoder,vn=t("../path.js"),mn=vn.normalize,yn=vn.dirname,En=vn.basename,wn=vn.isAbsolute,bn=vn.isNull,An=t("../constants.js"),On=An.MODE_FILE,Tn=An.MODE_DIRECTORY,In=An.MODE_SYMBOLIC_LINK,Sn=An.MODE_META,xn=An.ROOT_DIRECTORY_NAME,Nn=An.SUPER_NODE_ID,kn=An.SYMLOOP_MAX,_n=An.O_READ,Dn=An.O_WRITE,Rn=An.O_CREATE,jn=An.O_EXCLUSIVE;An.O_TRUNCATE;var Ln=An.O_APPEND,Mn=An.O_FLAGS,Fn=An.XATTR_CREATE,Un=An.XATTR_REPLACE,Cn=An.FS_NOMTIME,Pn=An.FS_NOCTIME,Vn=t("../errors.js"),Bn=t("../directory-entry.js"),zn=t("../open-file-description.js"),Yn=t("../super-node.js"),Wn=t("../node.js"),Xn=t("../stats.js");n.exports={makeRootDirectory:s,open:M,close:F,mknod:U,mkdir:C,rmdir:P,unlink:Y,stat:V,fstat:B,link:z,read:W,readFile:X,write:q,writeFile:Z,appendFile:H,exists:J,getxattr:G,fgetxattr:Q,setxattr:K,fsetxattr:$,removexattr:tn,fremovexattr:nn,lseek:en,readdir:rn,utimes:on,futimes:an,rename:sn,symlink:un,readlink:cn,lstat:fn,truncate:ln,ftruncate:hn}},{"../../lib/encoding.js":2,"../../lib/nodash.js":5,"../constants.js":8,"../directory-entry.js":9,"../errors.js":10,"../node.js":16,"../open-file-description.js":17,"../path.js":18,"../stats.js":26,"../super-node.js":27}],12:[function(t,n){function e(t){return"function"==typeof t?t:function(t){if(t)throw t}}function r(t,n){function e(){N.forEach(function(t){t.call(this)}.bind(I)),N=null}function r(t){if(t.length){var n=g.getInstance();t.forEach(function(t){n.emit(t.event,t.path)})}}t=t||{},n=n||a;var s=t.flags,d=t.provider||new p.Default(t.name||u),O=t.name||d.name,T=i(s).contains(c),I=this;I.readyState=l,I.name=O,I.error=null,I.stdin=y,I.stdout=E,I.stderr=w;var S={},x=b;Object.defineProperty(this,"openFiles",{get:function(){return S}}),this.allocDescriptor=function(t){var n=x++;return S[n]=t,n},this.releaseDescriptor=function(t){delete S[t]};var N=[];this.queueOrRun=function(t){var n;return f==I.readyState?t.call(I):h==I.readyState?n=new m.EFILESYSTEMERROR("unknown error"):N.push(t),n},this.watch=function(t,n,e){if(o(t))throw Error("Path must be a string without null bytes.");"function"==typeof n&&(e=n,n={}),n=n||{},e=e||a;var r=new v;return r.start(t,!1,n.recursive),r.on("change",e),r},d.open(function(t,i){function o(t){function i(t){var n=d[t]();return n.flags=s,n.changes=[],n.close=function(){var t=n.changes;r(t),t.length=0},n}I.provider={openReadWriteContext:function(){return i("getReadWriteContext")},openReadOnlyContext:function(){return i("getReadOnlyContext")}},t?I.readyState=h:(I.readyState=f,e()),n(t,I)}if(t)return o(t);if(!T&&!i)return o(null);var a=d.getReadWriteContext();a.clear(function(t){return t?(o(t),void 0):(A.makeRootDirectory(a,o),void 0)})})}var i=t("../../lib/nodash.js"),o=t("../path.js").isNull,a=t("../shared.js").nop,s=t("../constants.js"),u=s.FILE_SYSTEM_NAME,c=s.FS_FORMAT,f=s.FS_READY,l=s.FS_PENDING,h=s.FS_ERROR,p=t("../providers/index.js"),d=t("../shell/shell.js"),g=t("../../lib/intercom.js"),v=t("../fs-watcher.js"),m=t("../errors.js"),y=s.STDIN,E=s.STDOUT,w=s.STDERR,b=s.FIRST_DESCRIPTOR,A=t("./implementation.js");r.providers=p,["open","close","mknod","mkdir","rmdir","stat","fstat","link","unlink","read","readFile","write","writeFile","appendFile","exists","lseek","readdir","rename","readlink","symlink","lstat","truncate","ftruncate","utimes","futimes","setxattr","getxattr","fsetxattr","fgetxattr","removexattr","fremovexattr"].forEach(function(t){r.prototype[t]=function(){var n=this,r=Array.prototype.slice.call(arguments,0),i=r.length-1,o="function"!=typeof r[i],a=e(r[i]),s=n.queueOrRun(function(){function e(){s.close(),a.apply(n,arguments)}var s=n.provider.openReadWriteContext();o?r.push(e):r[i]=e;var u=[n,s].concat(r);A[t].apply(null,u)});s&&a(s)}}),r.prototype.Shell=function(t){return new d(this,t)},n.exports=r},{"../../lib/intercom.js":4,"../../lib/nodash.js":5,"../constants.js":8,"../errors.js":10,"../fs-watcher.js":13,"../path.js":18,"../providers/index.js":19,"../shared.js":23,"../shell/shell.js":25,"./implementation.js":11}],13:[function(t,n){function e(){function t(t){(n===t||a&&0===t.indexOf(n+"/"))&&e.trigger("change","change",t)}r.call(this);var n,e=this,a=!1;e.start=function(e,r,s){if(!n){if(i(e))throw Error("Path must be a string without null bytes.");n=e,a=s===!0;var u=o.getInstance();u.on("change",t)}},e.close=function(){var n=o.getInstance();n.off("change",t),e.removeAllListeners("change")}}var r=t("../lib/eventemitter.js"),i=t("./path.js").isNull,o=t("../lib/intercom.js");e.prototype=new r,e.prototype.constructor=e,n.exports=e},{"../lib/eventemitter.js":3,"../lib/intercom.js":4,"./path.js":18}],14:[function(t,n){n.exports={FileSystem:t("./filesystem/interface.js"),Path:t("./path.js"),Errors:t("./errors.js")}},{"./errors.js":10,"./filesystem/interface.js":12,"./path.js":18}],15:[function(t,n){function e(t,n){var e=new XMLHttpRequest;e.onload=function(){var t=200!=e.status?{message:e.statusText,code:e.status}:null,r=t?null:new Uint8Array(e.response);n(t,r)},e.open("GET",t),"withCredentials"in e&&(e.withCredentials=!0),e.responseType="arraybuffer",e.send()}function r(n,e){t("request")({url:n,method:"GET",encoding:null},function(t,n,r){var i,o,a,s=null,u=r&&r.length;if(n=n||null,o=n&&n.statusCode,a=200!=o?{message:t||"Not found!",code:o}:null)return e(a,null);if(i=u&&new ArrayBuffer(u),i&&200==o){s=new Uint8Array(i);for(var c=0;r.length>c;++c)s[c]=r[c]}e(null,s)})}n.exports.download=function(){return"undefined"==typeof XMLHttpRequest?r:e}()},{}],16:[function(t,n){var e=t("./constants.js").MODE_FILE,r=t("./shared.js").guid;n.exports=function(t,n,i,o,a,s,u,c,f,l){var h=Date.now();this.id=t||r(),this.mode=n||e,this.size=i||0,this.atime=o||h,this.ctime=a||h,this.mtime=s||h,this.flags=u||[],this.xattrs=c||{},this.nlinks=f||0,this.version=l||0,this.blksize=void 0,this.nblocks=1,this.data=r()}},{"./constants.js":8,"./shared.js":23}],17:[function(t,n){n.exports=function(t,n,e,r){this.path=t,this.id=n,this.flags=e,this.position=r}},{}],18:[function(t,n,e){function r(t,n){for(var e=0,r=t.length-1;r>=0;r--){var i=t[r];"."===i?t.splice(r,1):".."===i?(t.splice(r,1),e++):e&&(t.splice(r,1),e--)}if(n)for(;e--;e)t.unshift("..");return t}function i(){for(var t="",n=!1,e=arguments.length-1;e>=-1&&!n;e--){var i=e>=0?arguments[e]:"/";"string"==typeof i&&i&&(t=i+"/"+t,n="/"===i.charAt(0))}return t=r(t.split("/").filter(function(t){return!!t}),!n).join("/"),(n?"/":"")+t||"."}function o(t){var n="/"===t.charAt(0);return"/"===t.substr(-1),t=r(t.split("/").filter(function(t){return!!t}),!n).join("/"),t||n||(t="."),(n?"/":"")+t}function a(){var t=Array.prototype.slice.call(arguments,0);return o(t.filter(function(t){return t&&"string"==typeof t}).join("/"))}function s(t,n){function r(t){for(var n=0;t.length>n&&""===t[n];n++);for(var e=t.length-1;e>=0&&""===t[e];e--);return n>e?[]:t.slice(n,e-n+1)}t=e.resolve(t).substr(1),n=e.resolve(n).substr(1);for(var i=r(t.split("/")),o=r(n.split("/")),a=Math.min(i.length,o.length),s=a,u=0;a>u;u++)if(i[u]!==o[u]){s=u;break}for(var c=[],u=s;i.length>u;u++)c.push("..");return c=c.concat(o.slice(s)),c.join("/")}function u(t){var n=d(t),e=n[0],r=n[1];return e||r?(r&&(r=r.substr(0,r.length-1)),e+r):"."}function c(t,n){var e=d(t)[2];return n&&e.substr(-1*n.length)===n&&(e=e.substr(0,e.length-n.length)),""===e?"/":e}function f(t){return d(t)[3]}function l(t){return"/"===t.charAt(0)?!0:!1}function h(t){return-1!==(""+t).indexOf("\0")?!0:!1}var p=/^(\/?)([\s\S]+\/(?!$)|\/)?((?:\.{1,2}$|[\s\S]+?)?(\.[^.\/]*)?)$/,d=function(t){var n=p.exec(t);return[n[1]||"",n[2]||"",n[3]||"",n[4]||""]};n.exports={normalize:o,resolve:i,join:a,relative:s,sep:"/",delimiter:":",dirname:u,basename:c,extname:f,isAbsolute:l,isNull:h}},{}],19:[function(t,n){var e=t("./indexeddb.js"),r=t("./websql.js"),i=t("./memory.js");n.exports={IndexedDB:e,WebSQL:r,Memory:i,Default:e,Fallback:function(){function t(){throw"[Filer Error] Your browser doesn't support IndexedDB or WebSQL."}return e.isSupported()?e:r.isSupported()?r:(t.isSupported=function(){return!1},t)}()}},{"./indexeddb.js":20,"./memory.js":21,"./websql.js":22}],20:[function(t,n){(function(e){function r(t,n){var e=t.transaction(a,n);this.objectStore=e.objectStore(a)}function i(t){this.name=t||o,this.db=null}var o=t("../constants.js").FILE_SYSTEM_NAME,a=t("../constants.js").FILE_STORE_NAME,s=t("../constants.js").IDB_RW;t("../constants.js").IDB_RO;var u=t("../errors.js"),c=e.indexedDB||e.mozIndexedDB||e.webkitIndexedDB||e.msIndexedDB;r.prototype.clear=function(t){try{var n=this.objectStore.clear();n.onsuccess=function(){t()},n.onerror=function(n){t(n)}}catch(e){t(e)}},r.prototype.get=function(t,n){try{var e=this.objectStore.get(t);e.onsuccess=function(t){var e=t.target.result;n(null,e)},e.onerror=function(t){n(t)}}catch(r){n(r)}},r.prototype.put=function(t,n,e){try{var r=this.objectStore.put(n,t);r.onsuccess=function(t){var n=t.target.result;e(null,n)},r.onerror=function(t){e(t)}}catch(i){e(i)}},r.prototype.delete=function(t,n){try{var e=this.objectStore.delete(t);e.onsuccess=function(t){var e=t.target.result;n(null,e)},e.onerror=function(t){n(t)}}catch(r){n(r)}},i.isSupported=function(){return!!c},i.prototype.open=function(t){var n=this;if(n.db)return t(null,!1),void 0;var e=!1,r=c.open(n.name);r.onupgradeneeded=function(t){var n=t.target.result;n.objectStoreNames.contains(a)&&n.deleteObjectStore(a),n.createObjectStore(a),e=!0},r.onsuccess=function(r){n.db=r.target.result,t(null,e)},r.onerror=function(){t(new u.EINVAL("IndexedDB cannot be accessed. If private browsing is enabled, disable it."))}},i.prototype.getReadOnlyContext=function(){return new r(this.db,s)},i.prototype.getReadWriteContext=function(){return new r(this.db,s)},n.exports=i})(this)},{"../constants.js":8,"../errors.js":10}],21:[function(t,n){function e(t,n){this.readOnly=n,this.objectStore=t}function r(t){this.name=t||i}var i=t("../constants.js").FILE_SYSTEM_NAME,o=t("../../lib/async.js").nextTick,a=function(){var t={};return function(n){var e=!t.hasOwnProperty(n);return e&&(t[n]={}),{firstAccess:e,db:t[n]}}}();e.prototype.clear=function(t){if(this.readOnly)return o(function(){t("[MemoryContext] Error: write operation on read only context")}),void 0;var n=this.objectStore;Object.keys(n).forEach(function(t){delete n[t]}),o(t)},e.prototype.get=function(t,n){var e=this;o(function(){n(null,e.objectStore[t])})},e.prototype.put=function(t,n,e){return this.readOnly?(o(function(){e("[MemoryContext] Error: write operation on read only context")}),void 0):(this.objectStore[t]=n,o(e),void 0)},e.prototype.delete=function(t,n){return this.readOnly?(o(function(){n("[MemoryContext] Error: write operation on read only context")}),void 0):(delete this.objectStore[t],o(n),void 0)},r.isSupported=function(){return!0},r.prototype.open=function(t){var n=a(this.name);this.db=n.db,o(function(){t(null,n.firstAccess)})},r.prototype.getReadOnlyContext=function(){return new e(this.db,!0)},r.prototype.getReadWriteContext=function(){return new e(this.db,!1)},n.exports=r},{"../../lib/async.js":1,"../constants.js":8}],22:[function(t,n){(function(e){function r(t,n){var e=this;this.getTransaction=function(r){return e.transaction?(r(e.transaction),void 0):(t[n?"readTransaction":"transaction"](function(t){e.transaction=t,r(t)}),void 0)}}function i(t){this.name=t||o,this.db=null}var o=t("../constants.js").FILE_SYSTEM_NAME,a=t("../constants.js").FILE_STORE_NAME,s=t("../constants.js").WSQL_VERSION,u=t("../constants.js").WSQL_SIZE,c=t("../constants.js").WSQL_DESC,f=t("../shared.js").u8toArray,l=t("../errors.js");r.prototype.clear=function(t){function n(n,e){t(e)}function e(){t(null)}this.getTransaction(function(t){t.executeSql("DELETE FROM "+a+";",[],e,n)})},r.prototype.get=function(t,n){function e(t,e){var r=0===e.rows.length?null:e.rows.item(0).data;try{r&&(r=JSON.parse(r),r.__isUint8Array&&(r=new Uint8Array(r.__array))),n(null,r)}catch(i){n(i)}}function r(t,e){n(e)}this.getTransaction(function(n){n.executeSql("SELECT data FROM "+a+" WHERE id = ?;",[t],e,r)})},r.prototype.put=function(t,n,e){function r(){e(null)}function i(t,n){e(n)}"[object Uint8Array]"===Object.prototype.toString.call(n)&&(n={__isUint8Array:!0,__array:f(n)}),n=JSON.stringify(n),this.getTransaction(function(e){e.executeSql("INSERT OR REPLACE INTO "+a+" (id, data) VALUES (?, ?);",[t,n],r,i)})},r.prototype.delete=function(t,n){function e(){n(null)}function r(t,e){n(e)}this.getTransaction(function(n){n.executeSql("DELETE FROM "+a+" WHERE id = ?;",[t],e,r)})},i.isSupported=function(){return!!e.openDatabase},i.prototype.open=function(t){function n(n,e){5===e.code&&t(new l.EINVAL("WebSQL cannot be accessed. If private browsing is enabled, disable it.")),t(e)}function r(n){function e(n,e){var r=0===e.rows.item(0).count;t(null,r)}function r(n,e){t(e)}i.db=o,n.executeSql("SELECT COUNT(id) AS count FROM "+a+";",[],e,r)}var i=this;if(i.db)return t(null,!1),void 0;var o=e.openDatabase(i.name,s,c,u);return o?(o.transaction(function(t){function e(t){t.executeSql("CREATE INDEX IF NOT EXISTS idx_"+a+"_id"+" on "+a+" (id);",[],r,n)}t.executeSql("CREATE TABLE IF NOT EXISTS "+a+" (id unique, data TEXT);",[],e,n)}),void 0):(t("[WebSQL] Unable to open database."),void 0)},i.prototype.getReadOnlyContext=function(){return new r(this.db,!0)},i.prototype.getReadWriteContext=function(){return new r(this.db,!1)},n.exports=i})(this)},{"../constants.js":8,"../errors.js":10,"../shared.js":23}],23:[function(t,n){function e(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var n=0|16*Math.random(),e="x"==t?n:8|3&n;return e.toString(16)}).toUpperCase()}function r(){}function i(t){for(var n=[],e=t.length,r=0;e>r;r++)n[r]=t[r];return n}n.exports={guid:e,u8toArray:i,nop:r}},{}],24:[function(t,n){var e=t("../constants.js").ENVIRONMENT;n.exports=function(t){t=t||{},t.TMP=t.TMP||e.TMP,t.PATH=t.PATH||e.PATH,this.get=function(n){return t[n]},this.set=function(n,e){t[n]=e}}},{"../constants.js":8}],25:[function(t,n){function e(t,n){n=n||{};var e=new o(n.env),a="/";Object.defineProperty(this,"fs",{get:function(){return t},enumerable:!0}),Object.defineProperty(this,"env",{get:function(){return e},enumerable:!0}),this.cd=function(n,e){n=r.resolve(this.cwd,n),t.stat(n,function(t,r){return t?(e(new i.ENOTDIR),void 0):("DIRECTORY"===r.type?(a=n,e()):e(new i.ENOTDIR),void 0)})},this.pwd=function(){return a}}var r=t("../path.js"),i=t("../errors.js"),o=t("./environment.js"),a=t("../../lib/async.js"),s=t("../network.js"),u=t("../../lib/zip-utils.js"),c=t("../../lib/encoding.js").TextEncoder;e.prototype.exec=function(t,n,e){var i=this.fs;"function"==typeof n&&(e=n,n=[]),n=n||[],e=e||function(){},t=r.resolve(this.cwd,t),i.readFile(t,"utf8",function(t,r){if(t)return e(t),void 0;try{var o=Function("fs","args","callback",r);o(i,n,e)}catch(a){e(a)}})},e.prototype.touch=function(t,n,e){function i(t){a.writeFile(t,"",e)}function o(t){var r=Date.now(),i=n.date||r,o=n.date||r;a.utimes(t,i,o,e)}var a=this.fs;"function"==typeof n&&(e=n,n={}),n=n||{},e=e||function(){},t=r.resolve(this.cwd,t),a.stat(t,function(r){r?n.updateOnly===!0?e():i(t):o(t)})},e.prototype.cat=function(t,n){function e(t,n){var e=r.resolve(this.cwd,t);o.readFile(e,"utf8",function(t,e){return t?(n(t),void 0):(s+=e+"\n",n(),void 0)})}var o=this.fs,s="";return n=n||function(){},t?(t="string"==typeof t?[t]:t,a.eachSeries(t,e,function(t){t?n(t):n(null,s.replace(/\n$/,""))}),void 0):(n(new i.EINVAL("Missing files argument")),void 0)},e.prototype.ls=function(t,n,e){function o(t,e){var i=r.resolve(this.cwd,t),u=[];s.readdir(i,function(t,c){function f(t,e){t=r.join(i,t),s.stat(t,function(a,s){if(a)return e(a),void 0;var c={path:r.basename(t),links:s.nlinks,size:s.size,modified:s.mtime,type:s.type};n.recursive&&"DIRECTORY"===s.type?o(r.join(i,c.path),function(t,n){return t?(e(t),void 0):(c.contents=n,u.push(c),e(),void 0)}):(u.push(c),e())})}return t?(e(t),void 0):(a.each(c,f,function(t){e(t,u)}),void 0)})}var s=this.fs;return"function"==typeof n&&(e=n,n={}),n=n||{},e=e||function(){},t?(o(t,e),void 0):(e(new i.EINVAL("Missing dir argument")),void 0)},e.prototype.rm=function(t,n,e){function o(t,e){t=r.resolve(this.cwd,t),s.stat(t,function(u,c){return u?(e(u),void 0):"FILE"===c.type?(s.unlink(t,e),void 0):(s.readdir(t,function(u,c){return u?(e(u),void 0):0===c.length?(s.rmdir(t,e),void 0):n.recursive?(c=c.map(function(n){return r.join(t,n)}),a.each(c,o,function(n){return n?(e(n),void 0):(s.rmdir(t,e),void 0)}),void 0):(e(new i.ENOTEMPTY),void 0)}),void 0)})}var s=this.fs;return"function"==typeof n&&(e=n,n={}),n=n||{},e=e||function(){},t?(o(t,e),void 0):(e(new i.EINVAL("Missing path argument")),void 0)},e.prototype.tempDir=function(t){var n=this.fs,e=this.env.get("TMP");t=t||function(){},n.mkdir(e,function(){t(null,e)})},e.prototype.mkdirp=function(t,n){function e(t,n){o.stat(t,function(a,s){if(s){if(s.isDirectory())return n(),void 0;if(s.isFile())return n(new i.ENOTDIR),void 0}else{if(a&&"ENOENT"!==a.code)return n(a),void 0;var u=r.dirname(t);"/"===u?o.mkdir(t,function(t){return t&&"EEXIST"!=t.code?(n(t),void 0):(n(),void 0)}):e(u,function(e){return e?n(e):(o.mkdir(t,function(t){return t&&"EEXIST"!=t.code?(n(t),void 0):(n(),void 0)}),void 0)})}})}var o=this.fs;return n=n||function(){},t?"/"===t?(n(),void 0):(e(t,n),void 0):(n(new i.EINVAL("Missing path argument")),void 0)},e.prototype.wget=function(t,n,e){function o(){e(Error("unable to get resource"))}var a=this.fs;if("function"==typeof n&&(e=n,n={}),n=n||{},e=e||function(){},!t)return e(new i.EINVAL("missing url argument")),void 0;var u=n.filename||t.split("/").pop();u=r.resolve(a.cwd,u),s.download(t,function(t,n){return t||!n?o():(a.writeFile(u,n,function(t){t?e(t):e(null,u)}),void 0)})},e.prototype.unzip=function(t,n,e){var o=this.fs,s=this;if("function"==typeof n&&(e=n,n={}),n=n||{},e=e||function(){},!t)return e(new i.EINVAL("missing zipfile argument")),void 0;var c=r.resolve(this.cwd,t),f=r.resolve(n.destination||this.cwd);o.readFile(c,function(t,n){function i(t,n){var e=c.decompress(t.zipFilename);t.isDirectory?s.mkdirp(t.fsFilename,n):o.writeFile(t.fsFilename,e,n)}if(t)return e(t);var c=new u.Unzip(n),l=c.getFilenames().map(function(t){return{zipFilename:t,fsFilename:r.join(f,t),isDirectory:/\/$/.test(t)}});a.eachSeries(l,i,e)})},e.prototype.zip=function(t,n,e,o){function s(t){return new c("utf8").encode(t)}function f(t,n){p.readFile(t,function(e,r){if(e)return n(e);var i=t.replace(/^\//,"");g.addFile(r,{filename:s(i)}),n()})}function l(t,n){p.readdir(t,function(i,o){g.addFile([],{filename:s(t+"/"),compressionMethod:u.Zip.CompressionMethod.STORE}),e.recursive||n(),a.eachSeries(o,function(n,e){h(r.join(t,n),e)},n)})}function h(t,n){t=r.resolve(d.cwd,t),p.stat(t,function(e,r){return e?n(e):(r.isDirectory()?l(t,n):f(t,n),void 0)})}var p=this.fs,d=this;if("function"==typeof e&&(o=e,e={}),e=e||{},o=o||function(){},!t)return o(new i.EINVAL("missing zipfile argument")),void 0;if(!n)return o(new i.EINVAL("missing paths argument")),void 0;"string"==typeof n&&(n=[n]),t=r.resolve(this.cwd,t);var g=new u.Zip;p.stat(t,function(e,r){return r?o(new i.EEXIST("zipfile already exists")):(a.eachSeries(n,h,function(n){if(n)return o(n);var e=g.compress();p.writeFile(t,e,o)}),void 0)})},n.exports=e},{"../../lib/async.js":1,"../../lib/encoding.js":2,"../../lib/zip-utils.js":6,"../errors.js":10,"../network.js":15,"../path.js":18,"./environment.js":24}],26:[function(t,n){function e(t,n){this.node=t.id,this.dev=n,this.size=t.size,this.nlinks=t.nlinks,this.atime=t.atime,this.mtime=t.mtime,this.ctime=t.ctime,this.type=t.mode}var r=t("./constants.js");e.prototype.isFile=function(){return this.type===r.MODE_FILE},e.prototype.isDirectory=function(){return this.type===r.MODE_DIRECTORY},e.prototype.isSymbolicLink=function(){return this.type===r.MODE_SYMBOLIC_LINK},e.prototype.isSocket=e.prototype.isFIFO=e.prototype.isCharacterDevice=e.prototype.isBlockDevice=function(){return!1},n.exports=e},{"./constants.js":8}],27:[function(t,n){var e=t("./constants.js"),r=t("./shared.js").guid;n.exports=function(t,n,i){var o=Date.now();this.id=e.SUPER_NODE_ID,this.mode=e.MODE_META,this.atime=t||o,this.ctime=n||o,this.mtime=i||o,this.rnode=r()}},{"./constants.js":8,"./shared.js":23}]},{},[14])(14)}); \ No newline at end of file +/*! filer 0.0.9 2014-06-09 */ +!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;"undefined"!=typeof window?e=window:"undefined"!=typeof global?e=global:"undefined"!=typeof self&&(e=self),e.Filer=t()}}(function(){var t;return function e(t,n,r){function i(a,s){if(!n[a]){if(!t[a]){var u="function"==typeof require&&require;if(!s&&u)return u(a,!0);if(o)return o(a,!0);throw Error("Cannot find module '"+a+"'")}var c=n[a]={exports:{}};t[a][0].call(c.exports,function(e){var n=t[a][1][e];return i(n?n:e)},c,c.exports,e,t,n,r)}return n[a].exports}for(var o="function"==typeof require&&require,a=0;r.length>a;a++)i(r[a]);return i}({1:[function(e,n){(function(e){(function(){function r(t){var e=!1;return function(){if(e)throw Error("Callback was already called.");e=!0,t.apply(i,arguments)}}var i,o,a={};i=this,null!=i&&(o=i.async),a.noConflict=function(){return i.async=o,a};var s=function(t,e){if(t.forEach)return t.forEach(e);for(var n=0;t.length>n;n+=1)e(t[n],n,t)},u=function(t,e){if(t.map)return t.map(e);var n=[];return s(t,function(t,r,i){n.push(e(t,r,i))}),n},c=function(t,e,n){return t.reduce?t.reduce(e,n):(s(t,function(t,r,i){n=e(n,t,r,i)}),n)},f=function(t){if(Object.keys)return Object.keys(t);var e=[];for(var n in t)t.hasOwnProperty(n)&&e.push(n);return e};void 0!==e&&e.nextTick?(a.nextTick=e.nextTick,a.setImmediate="undefined"!=typeof setImmediate?function(t){setImmediate(t)}:a.nextTick):"function"==typeof setImmediate?(a.nextTick=function(t){setImmediate(t)},a.setImmediate=a.nextTick):(a.nextTick=function(t){setTimeout(t,0)},a.setImmediate=a.nextTick),a.each=function(t,e,n){if(n=n||function(){},!t.length)return n();var i=0;s(t,function(o){e(o,r(function(e){e?(n(e),n=function(){}):(i+=1,i>=t.length&&n(null))}))})},a.forEach=a.each,a.eachSeries=function(t,e,n){if(n=n||function(){},!t.length)return n();var r=0,i=function(){e(t[r],function(e){e?(n(e),n=function(){}):(r+=1,r>=t.length?n(null):i())})};i()},a.forEachSeries=a.eachSeries,a.eachLimit=function(t,e,n,r){var i=l(e);i.apply(null,[t,n,r])},a.forEachLimit=a.eachLimit;var l=function(t){return function(e,n,r){if(r=r||function(){},!e.length||0>=t)return r();var i=0,o=0,a=0;(function s(){if(i>=e.length)return r();for(;t>a&&e.length>o;)o+=1,a+=1,n(e[o-1],function(t){t?(r(t),r=function(){}):(i+=1,a-=1,i>=e.length?r():s())})})()}},d=function(t){return function(){var e=Array.prototype.slice.call(arguments);return t.apply(null,[a.each].concat(e))}},h=function(t,e){return function(){var n=Array.prototype.slice.call(arguments);return e.apply(null,[l(t)].concat(n))}},p=function(t){return function(){var e=Array.prototype.slice.call(arguments);return t.apply(null,[a.eachSeries].concat(e))}},m=function(t,e,n,r){var i=[];e=u(e,function(t,e){return{index:e,value:t}}),t(e,function(t,e){n(t.value,function(n,r){i[t.index]=r,e(n)})},function(t){r(t,i)})};a.map=d(m),a.mapSeries=p(m),a.mapLimit=function(t,e,n,r){return g(e)(t,n,r)};var g=function(t){return h(t,m)};a.reduce=function(t,e,n,r){a.eachSeries(t,function(t,r){n(e,t,function(t,n){e=n,r(t)})},function(t){r(t,e)})},a.inject=a.reduce,a.foldl=a.reduce,a.reduceRight=function(t,e,n,r){var i=u(t,function(t){return t}).reverse();a.reduce(i,e,n,r)},a.foldr=a.reduceRight;var v=function(t,e,n,r){var i=[];e=u(e,function(t,e){return{index:e,value:t}}),t(e,function(t,e){n(t.value,function(n){n&&i.push(t),e()})},function(){r(u(i.sort(function(t,e){return t.index-e.index}),function(t){return t.value}))})};a.filter=d(v),a.filterSeries=p(v),a.select=a.filter,a.selectSeries=a.filterSeries;var _=function(t,e,n,r){var i=[];e=u(e,function(t,e){return{index:e,value:t}}),t(e,function(t,e){n(t.value,function(n){n||i.push(t),e()})},function(){r(u(i.sort(function(t,e){return t.index-e.index}),function(t){return t.value}))})};a.reject=d(_),a.rejectSeries=p(_);var y=function(t,e,n,r){t(e,function(t,e){n(t,function(n){n?(r(t),r=function(){}):e()})},function(){r()})};a.detect=d(y),a.detectSeries=p(y),a.some=function(t,e,n){a.each(t,function(t,r){e(t,function(t){t&&(n(!0),n=function(){}),r()})},function(){n(!1)})},a.any=a.some,a.every=function(t,e,n){a.each(t,function(t,r){e(t,function(t){t||(n(!1),n=function(){}),r()})},function(){n(!0)})},a.all=a.every,a.sortBy=function(t,e,n){a.map(t,function(t,n){e(t,function(e,r){e?n(e):n(null,{value:t,criteria:r})})},function(t,e){if(t)return n(t);var r=function(t,e){var n=t.criteria,r=e.criteria;return r>n?-1:n>r?1:0};n(null,u(e.sort(r),function(t){return t.value}))})},a.auto=function(t,e){e=e||function(){};var n=f(t);if(!n.length)return e(null);var r={},i=[],o=function(t){i.unshift(t)},u=function(t){for(var e=0;i.length>e;e+=1)if(i[e]===t)return i.splice(e,1),void 0},l=function(){s(i.slice(0),function(t){t()})};o(function(){f(r).length===n.length&&(e(null,r),e=function(){})}),s(n,function(n){var i=t[n]instanceof Function?[t[n]]:t[n],d=function(t){var i=Array.prototype.slice.call(arguments,1);if(1>=i.length&&(i=i[0]),t){var o={};s(f(r),function(t){o[t]=r[t]}),o[n]=i,e(t,o),e=function(){}}else r[n]=i,a.setImmediate(l)},h=i.slice(0,Math.abs(i.length-1))||[],p=function(){return c(h,function(t,e){return t&&r.hasOwnProperty(e)},!0)&&!r.hasOwnProperty(n)};if(p())i[i.length-1](d,r);else{var m=function(){p()&&(u(m),i[i.length-1](d,r))};o(m)}})},a.waterfall=function(t,e){if(e=e||function(){},t.constructor!==Array){var n=Error("First argument to waterfall must be an array of functions");return e(n)}if(!t.length)return e();var r=function(t){return function(n){if(n)e.apply(null,arguments),e=function(){};else{var i=Array.prototype.slice.call(arguments,1),o=t.next();o?i.push(r(o)):i.push(e),a.setImmediate(function(){t.apply(null,i)})}}};r(a.iterator(t))()};var b=function(t,e,n){if(n=n||function(){},e.constructor===Array)t.map(e,function(t,e){t&&t(function(t){var n=Array.prototype.slice.call(arguments,1);1>=n.length&&(n=n[0]),e.call(null,t,n)})},n);else{var r={};t.each(f(e),function(t,n){e[t](function(e){var i=Array.prototype.slice.call(arguments,1);1>=i.length&&(i=i[0]),r[t]=i,n(e)})},function(t){n(t,r)})}};a.parallel=function(t,e){b({map:a.map,each:a.each},t,e)},a.parallelLimit=function(t,e,n){b({map:g(e),each:l(e)},t,n)},a.series=function(t,e){if(e=e||function(){},t.constructor===Array)a.mapSeries(t,function(t,e){t&&t(function(t){var n=Array.prototype.slice.call(arguments,1);1>=n.length&&(n=n[0]),e.call(null,t,n)})},e);else{var n={};a.eachSeries(f(t),function(e,r){t[e](function(t){var i=Array.prototype.slice.call(arguments,1);1>=i.length&&(i=i[0]),n[e]=i,r(t)})},function(t){e(t,n)})}},a.iterator=function(t){var e=function(n){var r=function(){return t.length&&t[n].apply(null,arguments),r.next()};return r.next=function(){return t.length-1>n?e(n+1):null},r};return e(0)},a.apply=function(t){var e=Array.prototype.slice.call(arguments,1);return function(){return t.apply(null,e.concat(Array.prototype.slice.call(arguments)))}};var w=function(t,e,n,r){var i=[];t(e,function(t,e){n(t,function(t,n){i=i.concat(n||[]),e(t)})},function(t){r(t,i)})};a.concat=d(w),a.concatSeries=p(w),a.whilst=function(t,e,n){t()?e(function(r){return r?n(r):(a.whilst(t,e,n),void 0)}):n()},a.doWhilst=function(t,e,n){t(function(r){return r?n(r):(e()?a.doWhilst(t,e,n):n(),void 0)})},a.until=function(t,e,n){t()?n():e(function(r){return r?n(r):(a.until(t,e,n),void 0)})},a.doUntil=function(t,e,n){t(function(r){return r?n(r):(e()?n():a.doUntil(t,e,n),void 0)})},a.queue=function(t,e){function n(t,n,r,i){n.constructor!==Array&&(n=[n]),s(n,function(n){var o={data:n,callback:"function"==typeof i?i:null};r?t.tasks.unshift(o):t.tasks.push(o),t.saturated&&t.tasks.length===e&&t.saturated(),a.setImmediate(t.process)})}void 0===e&&(e=1);var i=0,o={tasks:[],concurrency:e,saturated:null,empty:null,drain:null,push:function(t,e){n(o,t,!1,e)},unshift:function(t,e){n(o,t,!0,e)},process:function(){if(o.concurrency>i&&o.tasks.length){var e=o.tasks.shift();o.empty&&0===o.tasks.length&&o.empty(),i+=1;var n=function(){i-=1,e.callback&&e.callback.apply(e,arguments),o.drain&&0===o.tasks.length+i&&o.drain(),o.process()},a=r(n);t(e.data,a)}},length:function(){return o.tasks.length},running:function(){return i}};return o},a.cargo=function(t,e){var n=!1,r=[],i={tasks:r,payload:e,saturated:null,empty:null,drain:null,push:function(t,n){t.constructor!==Array&&(t=[t]),s(t,function(t){r.push({data:t,callback:"function"==typeof n?n:null}),i.saturated&&r.length===e&&i.saturated()}),a.setImmediate(i.process)},process:function o(){if(!n){if(0===r.length)return i.drain&&i.drain(),void 0;var a="number"==typeof e?r.splice(0,e):r.splice(0),c=u(a,function(t){return t.data});i.empty&&i.empty(),n=!0,t(c,function(){n=!1;var t=arguments;s(a,function(e){e.callback&&e.callback.apply(null,t)}),o()})}},length:function(){return r.length},running:function(){return n}};return i};var E=function(t){return function(e){var n=Array.prototype.slice.call(arguments,1);e.apply(null,n.concat([function(e){var n=Array.prototype.slice.call(arguments,1);"undefined"!=typeof console&&(e?console.error&&console.error(e):console[t]&&s(n,function(e){console[t](e)}))}]))}};a.log=E("log"),a.dir=E("dir"),a.memoize=function(t,e){var n={},r={};e=e||function(t){return t};var i=function(){var i=Array.prototype.slice.call(arguments),o=i.pop(),a=e.apply(null,i);a in n?o.apply(null,n[a]):a in r?r[a].push(o):(r[a]=[o],t.apply(null,i.concat([function(){n[a]=arguments;var t=r[a];delete r[a];for(var e=0,i=t.length;i>e;e++)t[e].apply(null,arguments)}])))};return i.memo=n,i.unmemoized=t,i},a.unmemoize=function(t){return function(){return(t.unmemoized||t).apply(null,arguments)}},a.times=function(t,e,n){for(var r=[],i=0;t>i;i++)r.push(i);return a.map(r,e,n)},a.timesSeries=function(t,e,n){for(var r=[],i=0;t>i;i++)r.push(i);return a.mapSeries(r,e,n)},a.compose=function(){var t=Array.prototype.reverse.call(arguments);return function(){var e=this,n=Array.prototype.slice.call(arguments),r=n.pop();a.reduce(t,n,function(t,n,r){n.apply(e,t.concat([function(){var t=arguments[0],e=Array.prototype.slice.call(arguments,1);r(t,e)}]))},function(t,n){r.apply(e,[t].concat(n))})}};var x=function(t,e){var n=function(){var n=this,r=Array.prototype.slice.call(arguments),i=r.pop();return t(e,function(t,e){t.apply(n,r.concat([e]))},i)};if(arguments.length>2){var r=Array.prototype.slice.call(arguments,2);return n.apply(this,r)}return n};a.applyEach=d(x),a.applyEachSeries=p(x),a.forever=function(t,e){function n(r){if(r){if(e)return e(r);throw r}t(n)}n()},t!==void 0&&t.amd?t([],function(){return a}):n!==void 0&&n.exports?n.exports=a:i.async=a})()}).call(this,e("FWaASH"))},{FWaASH:6}],2:[function(t,e){function n(t,e){for(var n=e.length-1;n>=0;n--)e[n]===t&&e.splice(n,1);return e}var r=function(){};r.createInterface=function(t){var e={};return e.on=function(e,n){this[t]===void 0&&(this[t]={}),this[t].hasOwnProperty(e)||(this[t][e]=[]),this[t][e].push(n)},e.off=function(e,r){void 0!==this[t]&&this[t].hasOwnProperty(e)&&n(r,this[t][e])},e.trigger=function(e){if(this[t]!==void 0&&this[t].hasOwnProperty(e))for(var n=Array.prototype.slice.call(arguments,1),r=0;this[t][e].length>r;r++)this[t][e][r].apply(this[t][e][r],n)},e.removeAllListeners=function(e){if(void 0!==this[t]){var n=this;n[t][e].forEach(function(t){n.off(e,t)})}},e};var i=r.createInterface("_handlers");r.prototype._on=i.on,r.prototype._off=i.off,r.prototype._trigger=i.trigger;var o=r.createInterface("handlers");r.prototype.on=function(){o.on.apply(this,arguments),Array.prototype.unshift.call(arguments,"on"),this._trigger.apply(this,arguments)},r.prototype.off=o.off,r.prototype.trigger=o.trigger,r.prototype.removeAllListeners=o.removeAllListeners,e.exports=r},{}],3:[function(t,e){function n(t,e){var n=0;return function(){var r=Date.now();r-n>t&&(n=r,e.apply(this,arguments))}}function r(t,e){if(void 0!==t&&t||(t={}),"object"==typeof e)for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);return t}function i(){var t=this,e=Date.now();this.origin=a(),this.lastMessage=e,this.receivedIDs={},this.previousValues={};var n=function(){t._onStorageEvent.apply(t,arguments)};"undefined"!=typeof window&&"undefined"!=typeof document&&(document.attachEvent?document.attachEvent("onstorage",n):window.addEventListener("storage",n,!1))}var o=t("./eventemitter.js"),a=t("../src/shared.js").guid,s=function(t){return t===void 0||t.localStorage===void 0?{getItem:function(){},setItem:function(){},removeItem:function(){}}:t.localStorage}(this);i.prototype._transaction=function(t){function e(){if(!a){var l=Date.now(),d=0|s.getItem(f);if(d&&r>l-d)return u||(o._on("storage",e),u=!0),c=setTimeout(e,i),void 0;a=!0,s.setItem(f,l),t(),n()}}function n(){u&&o._off("storage",e),c&&clearTimeout(c),s.removeItem(f)}var r=1e3,i=20,o=this,a=!1,u=!1,c=null;e()},i.prototype._cleanup_emit=n(100,function(){var t=this;t._transaction(function(){var t,e=Date.now(),n=e-l,r=0;try{t=JSON.parse(s.getItem(u)||"[]")}catch(i){t=[]}for(var o=t.length-1;o>=0;o--)n>t[o].timestamp&&(t.splice(o,1),r++);r>0&&s.setItem(u,JSON.stringify(t))})}),i.prototype._cleanup_once=n(100,function(){var t=this;t._transaction(function(){var e,n;Date.now();var r=0;try{n=JSON.parse(s.getItem(c)||"{}")}catch(i){n={}}for(e in n)t._once_expired(e,n)&&(delete n[e],r++);r>0&&s.setItem(c,JSON.stringify(n))})}),i.prototype._once_expired=function(t,e){if(!e)return!0;if(!e.hasOwnProperty(t))return!0;if("object"!=typeof e[t])return!0;var n=e[t].ttl||d,r=Date.now(),i=e[t].timestamp;return r-n>i},i.prototype._localStorageChanged=function(t,e){if(t&&t.key)return t.key===e;var n=s.getItem(e);return n===this.previousValues[e]?!1:(this.previousValues[e]=n,!0)},i.prototype._onStorageEvent=function(t){t=t||window.event;var e=this;this._localStorageChanged(t,u)&&this._transaction(function(){var t,n=Date.now(),r=s.getItem(u);try{t=JSON.parse(r||"[]")}catch(i){t=[]}for(var o=0;t.length>o;o++)if(t[o].origin!==e.origin&&!(t[o].timestampr;r++)if(e.call(n,t[r],r,t)===v)return}else{var o=o(t);for(r=0,i=o.length;i>r;r++)if(e.call(n,t[o[r]],o[r],t)===v)return}}function a(t,e,n){e||(e=i);var r=!1;return null==t?r:h&&t.some===h?t.some(e,n):(o(t,function(t,i,o){return r||(r=e.call(n,t,i,o))?v:void 0}),!!r)}function s(t,e){return null==t?!1:d&&t.indexOf===d?-1!=t.indexOf(e):a(t,function(t){return t===e})}function u(t){this.value=t}function c(t){return t&&"object"==typeof t&&!Array.isArray(t)&&m.call(t,"__wrapped__")?t:new u(t)}var f=Array.prototype,l=f.forEach,d=f.indexOf,h=f.some,p=Object.prototype,m=p.hasOwnProperty,g=Object.keys,v={},_=g||function(t){if(t!==Object(t))throw new TypeError("Invalid object");var e=[];for(var r in t)n(t,r)&&e.push(r);return e};u.prototype.has=function(t){return n(this.value,t)},u.prototype.contains=function(t){return s(this.value,t)},u.prototype.size=function(){return r(this.value)},e.exports=c},{}],5:[function(t,e){(function(t){function n(t,e){if("function"!=typeof e)throw Error("Bad callback given: "+e);if(!t)throw Error("No options given");var a=t.onResponse;if(t="string"==typeof t?{uri:t}:JSON.parse(JSON.stringify(t)),t.onResponse=a,t.verbose&&(n.log=o()),t.url&&(t.uri=t.url,delete t.url),!t.uri&&""!==t.uri)throw Error("options.uri is a required argument");if("string"!=typeof t.uri)throw Error("options.uri must be a string");for(var s=["proxy","_redirectsFollowed","maxRedirects","followRedirect"],c=0;s.length>c;c++)if(t[s[c]])throw Error("options."+s[c]+" is not supported");if(t.callback=e,t.method=t.method||"GET",t.headers=t.headers||{},t.body=t.body||null,t.timeout=t.timeout||n.DEFAULT_TIMEOUT,t.headers.host)throw Error("Options.headers.host is not supported");t.json&&(t.headers.accept=t.headers.accept||"application/json","GET"!==t.method&&(t.headers["content-type"]="application/json"),"boolean"!=typeof t.json?t.body=JSON.stringify(t.json):"string"!=typeof t.body&&(t.body=JSON.stringify(t.body)));var f=function(t){var e=[];for(var n in t)t.hasOwnProperty(n)&&e.push(encodeURIComponent(n)+"="+encodeURIComponent(t[n]));return e.join("&")};if(t.qs){var l="string"==typeof t.qs?t.qs:f(t.qs);t.uri=-1!==t.uri.indexOf("?")?t.uri+"&"+l:t.uri+"?"+l}var d=function(t){var e={};e.boundry="-------------------------------"+Math.floor(1e9*Math.random());var n=[];for(var r in t)t.hasOwnProperty(r)&&n.push("--"+e.boundry+"\n"+'Content-Disposition: form-data; name="'+r+'"'+"\n"+"\n"+t[r]+"\n");return n.push("--"+e.boundry+"--"),e.body=n.join(""),e.length=e.body.length,e.type="multipart/form-data; boundary="+e.boundry,e};if(t.form){if("string"==typeof t.form)throw"form name unsupported";if("POST"===t.method){var h=(t.encoding||"application/x-www-form-urlencoded").toLowerCase();switch(t.headers["content-type"]=h,h){case"application/x-www-form-urlencoded":t.body=f(t.form).replace(/%20/g,"+");break;case"multipart/form-data":var p=d(t.form);t.body=p.body,t.headers["content-type"]=p.type;break;default:throw Error("unsupported encoding:"+h)}}}return t.onResponse=t.onResponse||i,t.onResponse===!0&&(t.onResponse=e,t.callback=i),!t.headers.authorization&&t.auth&&(t.headers.authorization="Basic "+u(t.auth.username+":"+t.auth.password)),r(t)}function r(e){function r(){d=!0;var t=Error("ETIMEDOUT");return t.code="ETIMEDOUT",t.duration=e.timeout,n.log.error("Timeout",{id:f._id,milliseconds:e.timeout}),e.callback(t,f)}function i(){if(d)return n.log.debug("Ignoring timed out state change",{state:f.readyState,id:f.id});if(n.log.debug("State change",{state:f.readyState,id:f.id,timed_out:d}),f.readyState===c.OPENED){n.log.debug("Request started",{id:f.id});for(var t in e.headers)f.setRequestHeader(t,e.headers[t])}else f.readyState===c.HEADERS_RECEIVED?o():f.readyState===c.LOADING?(o(),a()):f.readyState===c.DONE&&(o(),a(),u())}function o(){if(!g.response){if(g.response=!0,n.log.debug("Got response",{id:f.id,status:f.status}),clearTimeout(f.timeoutTimer),f.statusCode=f.status,h&&0==f.statusCode){var t=Error("CORS request rejected: "+e.uri);return t.cors="rejected",g.loading=!0,g.end=!0,e.callback(t,f)}e.onResponse(null,f)}}function a(){g.loading||(g.loading=!0,n.log.debug("Response body loading",{id:f.id}))}function u(){if(!g.end){if(g.end=!0,n.log.debug("Request done",{id:f.id}),null===e.encoding)f.body=new t(new Uint8Array(f.response));else if(f.body=f.responseText,e.json)try{f.body=JSON.parse(f.responseText)}catch(r){return e.callback(r,f)}e.callback(null,f,f.body)}}var f=new c,d=!1,h=s(e.uri),p="withCredentials"in f;if(l+=1,f.seq_id=l,f.id=l+": "+e.method+" "+e.uri,f._id=f.id,h&&!p){var m=Error("Browser does not support cross-origin request: "+e.uri);return m.cors="unsupported",e.callback(m,f)}f.timeoutTimer=setTimeout(r,e.timeout);var g={response:!1,loading:!1,end:!1};return f.onreadystatechange=i,f.open(e.method,e.uri,!0),null===e.encoding&&(f.responseType="arraybuffer"),h&&(f.withCredentials=!!e.withCredentials),f.send(e.body),f}function i(){}function o(){var t,e,n={},r=["trace","debug","info","warn","error"];for(e=0;r.length>e;e++)t=r[e],n[t]=i,"undefined"!=typeof console&&console&&console[t]&&(n[t]=a(console,t));return n}function a(t,e){function n(n,r){return"object"==typeof r&&(n+=" "+JSON.stringify(r)),t[e].call(t,n)}return n}function s(t){var e,n=/^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?)?/;try{e=location.href}catch(r){e=document.createElement("a"),e.href="",e=e.href}var i=n.exec(e.toLowerCase())||[],o=n.exec(t.toLowerCase()),a=!(!o||o[1]==i[1]&&o[2]==i[2]&&(o[3]||("http:"===o[1]?80:443))==(i[3]||("http:"===i[1]?80:443)));return a}function u(t){var e,n,r,i,o,a,s,u,c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",f=0,l=0,d="",h=[];if(!t)return t;do e=t.charCodeAt(f++),n=t.charCodeAt(f++),r=t.charCodeAt(f++),u=e<<16|n<<8|r,i=63&u>>18,o=63&u>>12,a=63&u>>6,s=63&u,h[l++]=c.charAt(i)+c.charAt(o)+c.charAt(a)+c.charAt(s);while(t.length>f);switch(d=h.join(""),t.length%3){case 1:d=d.slice(0,-2)+"==";break;case 2:d=d.slice(0,-1)+"="}return d}var c=XMLHttpRequest;if(!c)throw Error("missing XMLHttpRequest");n.log={trace:i,debug:i,info:i,warn:i,error:i};var f=18e4,l=0;n.withCredentials=!1,n.DEFAULT_TIMEOUT=f,n.defaults=function(t){var e=function(e){var n=function(n,r){n="string"==typeof n?{uri:n}:JSON.parse(JSON.stringify(n));for(var i in t)void 0===n[i]&&(n[i]=t[i]);return e(n,r)};return n},r=e(n);return r.get=e(n.get),r.post=e(n.post),r.put=e(n.put),r.head=e(n.head),r};var d=["get","put","post","head"];d.forEach(function(t){var e=t.toUpperCase(),r=t.toLowerCase();n[r]=function(t){"string"==typeof t?t={method:e,uri:t}:(t=JSON.parse(JSON.stringify(t)),t.method=e);var r=[t].concat(Array.prototype.slice.apply(arguments,[1]));return n.apply(this,r)}}),n.couch=function(t,e){function r(t,n,r){if(t)return e(t,n,r);if((200>n.statusCode||n.statusCode>299)&&r.error){t=Error("CouchDB error: "+(r.error.reason||r.error.error));for(var i in r)t[i]=r[i];return e(t,n,r)}return e(t,n,r)}"string"==typeof t&&(t={uri:t}),t.json=!0,t.body&&(t.json=t.body),delete t.body,e=e||i;var o=n(t,r);return o},e.exports=n}).call(this,t("buffer").Buffer)},{}],6:[function(t,e){function n(){}var r=e.exports={};r.nextTick=function(){var t="undefined"!=typeof window&&window.setImmediate,e="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(t)return function(t){return window.setImmediate(t)};if(e){var n=[];return window.addEventListener("message",function(t){var e=t.source;if((e===window||null===e)&&"process-tick"===t.data&&(t.stopPropagation(),n.length>0)){var r=n.shift();r()}},!0),function(t){n.push(t),window.postMessage("process-tick","*")}}return function(t){setTimeout(t,0)}}(),r.title="browser",r.browser=!0,r.env={},r.argv=[],r.on=n,r.addListener=n,r.once=n,r.off=n,r.removeListener=n,r.removeAllListeners=n,r.emit=n,r.binding=function(){throw Error("process.binding is not supported")},r.cwd=function(){return"/"},r.chdir=function(){throw Error("process.chdir is not supported")}},{}],7:[function(t,e,n){"use strict";var r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";n.encode=function(t){for(var e,n,i,o,a,s,u,c="",f=0;t.length>f;)e=t.charCodeAt(f++),n=t.charCodeAt(f++),i=t.charCodeAt(f++),o=e>>2,a=(3&e)<<4|n>>4,s=(15&n)<<2|i>>6,u=63&i,isNaN(n)?s=u=64:isNaN(i)&&(u=64),c=c+r.charAt(o)+r.charAt(a)+r.charAt(s)+r.charAt(u);return c},n.decode=function(t){var e,n,i,o,a,s,u,c="",f=0;for(t=t.replace(/[^A-Za-z0-9\+\/\=]/g,"");t.length>f;)o=r.indexOf(t.charAt(f++)),a=r.indexOf(t.charAt(f++)),s=r.indexOf(t.charAt(f++)),u=r.indexOf(t.charAt(f++)),e=o<<2|a>>4,n=(15&a)<<4|s>>2,i=(3&s)<<6|u,c+=String.fromCharCode(e),64!=s&&(c+=String.fromCharCode(n)),64!=u&&(c+=String.fromCharCode(i));return c}},{}],8:[function(t,e){"use strict";function n(){this.compressedSize=0,this.uncompressedSize=0,this.crc32=0,this.compressionMethod=null,this.compressedContent=null}n.prototype={getContent:function(){return null},getCompressedContent:function(){return null}},e.exports=n},{}],9:[function(t,e,n){"use strict";n.STORE={magic:"\0\0",compress:function(t){return t},uncompress:function(t){return t},compressInputType:null,uncompressInputType:null},n.DEFLATE=t("./flate")},{"./flate":12}],10:[function(t,e){"use strict";function n(){this.data=null,this.length=0,this.index=0}var r=t("./utils");n.prototype={checkOffset:function(t){this.checkIndex(this.index+t)},checkIndex:function(t){if(t>this.length||0>t)throw Error("End of data reached (data length = "+this.length+", asked index = "+t+"). Corrupted zip ?")},setIndex:function(t){this.checkIndex(t),this.index=t},skip:function(t){this.setIndex(this.index+t)},byteAt:function(){},readInt:function(t){var e,n=0;for(this.checkOffset(t),e=this.index+t-1;e>=this.index;e--)n=(n<<8)+this.byteAt(e);return this.index+=t,n},readString:function(t){return r.transformTo("string",this.readData(t))},readData:function(){},lastIndexOfSignature:function(){},readDate:function(){var t=this.readInt(4);return new Date((127&t>>25)+1980,(15&t>>21)-1,31&t>>16,31&t>>11,63&t>>5,(31&t)<<1)}},e.exports=n},{"./utils":22}],11:[function(t,e,n){"use strict";n.base64=!1,n.binary=!1,n.dir=!1,n.date=null,n.compression=null},{}],12:[function(t,e,n){"use strict";var r="undefined"!=typeof Uint8Array&&"undefined"!=typeof Uint16Array&&"undefined"!=typeof Uint32Array,i=t("pako");n.uncompressInputType=r?"uint8array":"array",n.compressInputType=r?"uint8array":"array",n.magic="\b\0",n.compress=function(t){return i.deflateRaw(t)},n.uncompress=function(t){return i.inflateRaw(t)}},{pako:25}],13:[function(t,e){"use strict";function n(t,e){return this instanceof n?(this.files={},this.root="",t&&this.load(t,e),this.clone=function(){var t=new n;for(var e in this)"function"!=typeof this[e]&&(t[e]=this[e]);return t},void 0):new n(t,e)}n.prototype=t("./object"),n.prototype.load=t("./load"),n.support=t("./support"),n.defaults=t("./defaults"),n.utils=t("./utils"),n.base64=t("./base64"),n.compressions=t("./compressions"),e.exports=n},{"./base64":7,"./compressions":9,"./defaults":11,"./load":14,"./object":17,"./support":20,"./utils":22}],14:[function(t,e){"use strict";var n=t("./base64"),r=t("./zipEntries");e.exports=function(t,e){var i,o,a,s;for(e=e||{},e.base64&&(t=n.decode(t)),o=new r(t,e),i=o.files,a=0;i.length>a;a++)s=i[a],this.file(s.fileName,s.decompressed,{binary:!0,optimizedBinaryString:!0,date:s.date,dir:s.dir});return this}},{"./base64":7,"./zipEntries":23}],15:[function(t,e){(function(t){"use strict";e.exports=function(e,n){return new t(e,n)},e.exports.test=function(e){return t.isBuffer(e)}}).call(this,t("buffer").Buffer)},{}],16:[function(t,e){"use strict";function n(t){this.data=t,this.length=this.data.length,this.index=0}var r=t("./uint8ArrayReader");n.prototype=new r,n.prototype.readData=function(t){this.checkOffset(t);var e=this.data.slice(this.index,this.index+t);return this.index+=t,e},e.exports=n},{"./uint8ArrayReader":21}],17:[function(t,e){"use strict";var n,r,i=t("./support"),o=t("./utils"),a=t("./signature"),s=t("./defaults"),u=t("./base64"),c=t("./compressions"),f=t("./compressedObject"),l=t("./nodeBuffer");i.uint8array&&"function"==typeof TextEncoder&&"function"==typeof TextDecoder&&(n=new TextEncoder("utf-8"),r=new TextDecoder("utf-8"));var d=function(t){if(t._data instanceof f&&(t._data=t._data.getContent(),t.options.binary=!0,t.options.base64=!1,"uint8array"===o.getTypeOf(t._data))){var e=t._data;t._data=new Uint8Array(e.length),0!==e.length&&t._data.set(e,0)}return t._data},h=function(t){var e=d(t),r=o.getTypeOf(e);if("string"===r){if(!t.options.binary){if(n)return n.encode(e);if(i.nodebuffer)return l(e,"utf-8")}return t.asBinary()}return e},p=function(t){var e=d(this);return null===e||e===void 0?"":(this.options.base64&&(e=u.decode(e)),e=t&&this.options.binary?S.utf8decode(e):o.transformTo("string",e),t||this.options.binary||(e=S.utf8encode(e)),e)},m=function(t,e,n){this.name=t,this._data=e,this.options=n};m.prototype={asText:function(){return p.call(this,!0)},asBinary:function(){return p.call(this,!1)},asNodeBuffer:function(){var t=h(this);return o.transformTo("nodebuffer",t)},asUint8Array:function(){var t=h(this);return o.transformTo("uint8array",t)},asArrayBuffer:function(){return this.asUint8Array().buffer}};var g=function(t,e){var n,r="";for(n=0;e>n;n++)r+=String.fromCharCode(255&t),t>>>=8;return r},v=function(){var t,e,n={};for(t=0;arguments.length>t;t++)for(e in arguments[t])arguments[t].hasOwnProperty(e)&&n[e]===void 0&&(n[e]=arguments[t][e]);return n},_=function(t){return t=t||{},t.base64!==!0||null!==t.binary&&void 0!==t.binary||(t.binary=!0),t=v(t,s),t.date=t.date||new Date,null!==t.compression&&(t.compression=t.compression.toUpperCase()),t},y=function(t,e,n){var r=o.getTypeOf(e);if(n=_(n),n.dir||null===e||e===void 0)n.base64=!1,n.binary=!1,e=null;else if("string"===r)n.binary&&!n.base64&&n.optimizedBinaryString!==!0&&(e=o.string2binary(e));else{if(n.base64=!1,n.binary=!0,!(r||e instanceof f))throw Error("The data of '"+t+"' is in an unsupported format !");"arraybuffer"===r&&(e=o.transformTo("uint8array",e))}var i=new m(t,e,n);return this.files[t]=i,i},b=function(t){return"/"!=t.slice(-1)&&(t+="/"),this.files[t]||y.call(this,t,null,{dir:!0}),this.files[t]},w=function(t,e){var n,r=new f;return t._data instanceof f?(r.uncompressedSize=t._data.uncompressedSize,r.crc32=t._data.crc32,0===r.uncompressedSize||t.options.dir?(e=c.STORE,r.compressedContent="",r.crc32=0):t._data.compressionMethod===e.magic?r.compressedContent=t._data.getCompressedContent():(n=t._data.getContent(),r.compressedContent=e.compress(o.transformTo(e.compressInputType,n)))):(n=h(t),(!n||0===n.length||t.options.dir)&&(e=c.STORE,n=""),r.uncompressedSize=n.length,r.crc32=this.crc32(n),r.compressedContent=e.compress(o.transformTo(e.compressInputType,n))),r.compressedSize=r.compressedContent.length,r.compressionMethod=e.magic,r},E=function(t,e,n,r){var i,o,s=(n.compressedContent,this.utf8encode(e.name)),u=s!==e.name,c=e.options,f="",l="";i=c.date.getHours(),i<<=6,i|=c.date.getMinutes(),i<<=5,i|=c.date.getSeconds()/2,o=c.date.getFullYear()-1980,o<<=4,o|=c.date.getMonth()+1,o<<=5,o|=c.date.getDate(),u&&(l=g(1,1)+g(this.crc32(s),4)+s,f+="up"+g(l.length,2)+l);var d="";d+="\n\0",d+=u?"\0\b":"\0\0",d+=n.compressionMethod,d+=g(i,2),d+=g(o,2),d+=g(n.crc32,4),d+=g(n.compressedSize,4),d+=g(n.uncompressedSize,4),d+=g(s.length,2),d+=g(f.length,2);var h=a.LOCAL_FILE_HEADER+d+s+f,p=a.CENTRAL_FILE_HEADER+"\0"+d+"\0\0"+"\0\0"+"\0\0"+(e.options.dir===!0?"\0\0\0":"\0\0\0\0")+g(r,4)+s+f;return{fileRecord:h,dirRecord:p,compressedObject:n}},x=function(){this.data=[]};x.prototype={append:function(t){t=o.transformTo("string",t),this.data.push(t)},finalize:function(){return this.data.join("")}};var k=function(t){this.data=new Uint8Array(t),this.index=0};k.prototype={append:function(t){0!==t.length&&(t=o.transformTo("uint8array",t),this.data.set(t,this.index),this.index+=t.length)},finalize:function(){return this.data}};var S={load:function(){throw Error("Load method is not defined. Is the file jszip-load.js included ?")},filter:function(t){var e,n,r,i,o=[];for(e in this.files)this.files.hasOwnProperty(e)&&(r=this.files[e],i=new m(r.name,r._data,v(r.options)),n=e.slice(this.root.length,e.length),e.slice(0,this.root.length)===this.root&&t(n,i)&&o.push(i));return o},file:function(t,e,n){if(1===arguments.length){if(o.isRegExp(t)){var r=t;return this.filter(function(t,e){return!e.options.dir&&r.test(t)})}return this.filter(function(e,n){return!n.options.dir&&e===t})[0]||null}return t=this.root+t,y.call(this,t,e,n),this},folder:function(t){if(!t)return this;if(o.isRegExp(t))return this.filter(function(e,n){return n.options.dir&&t.test(e) +});var e=this.root+t,n=b.call(this,e),r=this.clone();return r.root=n.name,r},remove:function(t){t=this.root+t;var e=this.files[t];if(e||("/"!=t.slice(-1)&&(t+="/"),e=this.files[t]),e&&!e.options.dir)delete this.files[t];else for(var n=this.filter(function(e,n){return n.name.slice(0,t.length)===t}),r=0;n.length>r;r++)delete this.files[n[r].name];return this},generate:function(t){t=v(t||{},{base64:!0,compression:"STORE",type:"base64"}),o.checkSupport(t.type);var e,n,r=[],i=0,s=0;for(var f in this.files)if(this.files.hasOwnProperty(f)){var l=this.files[f],d=l.options.compression||t.compression.toUpperCase(),h=c[d];if(!h)throw Error(d+" is not a valid compression method !");var p=w.call(this,l,h),m=E.call(this,f,l,p,i);i+=m.fileRecord.length+p.compressedSize,s+=m.dirRecord.length,r.push(m)}var _="";_=a.CENTRAL_DIRECTORY_END+"\0\0"+"\0\0"+g(r.length,2)+g(r.length,2)+g(s,4)+g(i,4)+"\0\0";var y=t.type.toLowerCase();for(e="uint8array"===y||"arraybuffer"===y||"blob"===y||"nodebuffer"===y?new k(i+s+_.length):new x(i+s+_.length),n=0;r.length>n;n++)e.append(r[n].fileRecord),e.append(r[n].compressedObject.compressedContent);for(n=0;r.length>n;n++)e.append(r[n].dirRecord);e.append(_);var b=e.finalize();switch(t.type.toLowerCase()){case"uint8array":case"arraybuffer":case"nodebuffer":return o.transformTo(t.type.toLowerCase(),b);case"blob":return o.arrayBuffer2Blob(o.transformTo("arraybuffer",b));case"base64":return t.base64?u.encode(b):b;default:return b}},crc32:function(t,e){if(t===void 0||!t.length)return 0;var n="string"!==o.getTypeOf(t),r=[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];e===void 0&&(e=0);var i=0,a=0,s=0;e=-1^e;for(var u=0,c=t.length;c>u;u++)s=n?t[u]:t.charCodeAt(u),a=255&(e^s),i=r[a],e=e>>>8^i;return-1^e},utf8encode:function(t){if(n){var e=n.encode(t);return o.transformTo("string",e)}if(i.nodebuffer)return o.transformTo("string",l(t,"utf-8"));for(var r=[],a=0,s=0;t.length>s;s++){var u=t.charCodeAt(s);128>u?r[a++]=String.fromCharCode(u):u>127&&2048>u?(r[a++]=String.fromCharCode(192|u>>6),r[a++]=String.fromCharCode(128|63&u)):(r[a++]=String.fromCharCode(224|u>>12),r[a++]=String.fromCharCode(128|63&u>>6),r[a++]=String.fromCharCode(128|63&u))}return r.join("")},utf8decode:function(t){var e=[],n=0,a=o.getTypeOf(t),s="string"!==a,u=0,c=0,f=0,l=0;if(r)return r.decode(o.transformTo("uint8array",t));if(i.nodebuffer)return o.transformTo("nodebuffer",t).toString("utf-8");for(;t.length>u;)c=s?t[u]:t.charCodeAt(u),128>c?(e[n++]=String.fromCharCode(c),u++):c>191&&224>c?(f=s?t[u+1]:t.charCodeAt(u+1),e[n++]=String.fromCharCode((31&c)<<6|63&f),u+=2):(f=s?t[u+1]:t.charCodeAt(u+1),l=s?t[u+2]:t.charCodeAt(u+2),e[n++]=String.fromCharCode((15&c)<<12|(63&f)<<6|63&l),u+=3);return e.join("")}};e.exports=S},{"./base64":7,"./compressedObject":8,"./compressions":9,"./defaults":11,"./nodeBuffer":15,"./signature":18,"./support":20,"./utils":22}],18:[function(t,e,n){"use strict";n.LOCAL_FILE_HEADER="PK",n.CENTRAL_FILE_HEADER="PK",n.CENTRAL_DIRECTORY_END="PK",n.ZIP64_CENTRAL_DIRECTORY_LOCATOR="PK",n.ZIP64_CENTRAL_DIRECTORY_END="PK",n.DATA_DESCRIPTOR="PK\b"},{}],19:[function(t,e){"use strict";function n(t,e){this.data=t,e||(this.data=i.string2binary(this.data)),this.length=this.data.length,this.index=0}var r=t("./dataReader"),i=t("./utils");n.prototype=new r,n.prototype.byteAt=function(t){return this.data.charCodeAt(t)},n.prototype.lastIndexOfSignature=function(t){return this.data.lastIndexOf(t)},n.prototype.readData=function(t){this.checkOffset(t);var e=this.data.slice(this.index,this.index+t);return this.index+=t,e},e.exports=n},{"./dataReader":10,"./utils":22}],20:[function(t,e,n){(function(t){"use strict";if(n.base64=!0,n.array=!0,n.string=!0,n.arraybuffer="undefined"!=typeof ArrayBuffer&&"undefined"!=typeof Uint8Array,n.nodebuffer=t!==void 0,n.uint8array="undefined"!=typeof Uint8Array,"undefined"==typeof ArrayBuffer)n.blob=!1;else{var e=new ArrayBuffer(0);try{n.blob=0===new Blob([e],{type:"application/zip"}).size}catch(r){try{var i=window.BlobBuilder||window.WebKitBlobBuilder||window.MozBlobBuilder||window.MSBlobBuilder,o=new i;o.append(e),n.blob=0===o.getBlob("application/zip").size}catch(r){n.blob=!1}}}}).call(this,t("buffer").Buffer)},{}],21:[function(t,e){"use strict";function n(t){t&&(this.data=t,this.length=this.data.length,this.index=0)}var r=t("./dataReader");n.prototype=new r,n.prototype.byteAt=function(t){return this.data[t]},n.prototype.lastIndexOfSignature=function(t){for(var e=t.charCodeAt(0),n=t.charCodeAt(1),r=t.charCodeAt(2),i=t.charCodeAt(3),o=this.length-4;o>=0;--o)if(this.data[o]===e&&this.data[o+1]===n&&this.data[o+2]===r&&this.data[o+3]===i)return o;return-1},n.prototype.readData=function(t){this.checkOffset(t);var e=this.data.subarray(this.index,this.index+t);return this.index+=t,e},e.exports=n},{"./dataReader":10}],22:[function(t,e,n){"use strict";function r(t){return t}function i(t,e){for(var n=0;t.length>n;++n)e[n]=255&t.charCodeAt(n);return e}function o(t){var e=65536,r=[],i=t.length,o=n.getTypeOf(t),a=0,s=!0;try{switch(o){case"uint8array":String.fromCharCode.apply(null,new Uint8Array(0));break;case"nodebuffer":String.fromCharCode.apply(null,c(0))}}catch(u){s=!1}if(!s){for(var f="",l=0;t.length>l;l++)f+=String.fromCharCode(t[l]);return f}for(;i>a&&e>1;)try{"array"===o||"nodebuffer"===o?r.push(String.fromCharCode.apply(null,t.slice(a,Math.min(a+e,i)))):r.push(String.fromCharCode.apply(null,t.subarray(a,Math.min(a+e,i)))),a+=e}catch(u){e=Math.floor(e/2)}return r.join("")}function a(t,e){for(var n=0;t.length>n;n++)e[n]=t[n];return e}var s=t("./support"),u=t("./compressions"),c=t("./nodeBuffer");n.string2binary=function(t){for(var e="",n=0;t.length>n;n++)e+=String.fromCharCode(255&t.charCodeAt(n));return e},n.string2Uint8Array=function(t){return n.transformTo("uint8array",t)},n.uint8Array2String=function(t){return n.transformTo("string",t)},n.string2Blob=function(t){var e=n.transformTo("arraybuffer",t);return n.arrayBuffer2Blob(e)},n.arrayBuffer2Blob=function(t){n.checkSupport("blob");try{return new Blob([t],{type:"application/zip"})}catch(e){try{var r=window.BlobBuilder||window.WebKitBlobBuilder||window.MozBlobBuilder||window.MSBlobBuilder,i=new r;return i.append(t),i.getBlob("application/zip")}catch(e){throw Error("Bug : can't construct the Blob.")}}};var f={};f.string={string:r,array:function(t){return i(t,Array(t.length))},arraybuffer:function(t){return f.string.uint8array(t).buffer},uint8array:function(t){return i(t,new Uint8Array(t.length))},nodebuffer:function(t){return i(t,c(t.length))}},f.array={string:o,array:r,arraybuffer:function(t){return new Uint8Array(t).buffer},uint8array:function(t){return new Uint8Array(t)},nodebuffer:function(t){return c(t)}},f.arraybuffer={string:function(t){return o(new Uint8Array(t))},array:function(t){return a(new Uint8Array(t),Array(t.byteLength))},arraybuffer:r,uint8array:function(t){return new Uint8Array(t)},nodebuffer:function(t){return c(new Uint8Array(t))}},f.uint8array={string:o,array:function(t){return a(t,Array(t.length))},arraybuffer:function(t){return t.buffer},uint8array:r,nodebuffer:function(t){return c(t)}},f.nodebuffer={string:o,array:function(t){return a(t,Array(t.length))},arraybuffer:function(t){return f.nodebuffer.uint8array(t).buffer},uint8array:function(t){return a(t,new Uint8Array(t.length))},nodebuffer:r},n.transformTo=function(t,e){if(e||(e=""),!t)return e;n.checkSupport(t);var r=n.getTypeOf(e),i=f[r][t](e);return i},n.getTypeOf=function(t){return"string"==typeof t?"string":"[object Array]"===Object.prototype.toString.call(t)?"array":s.nodebuffer&&c.test(t)?"nodebuffer":s.uint8array&&t instanceof Uint8Array?"uint8array":s.arraybuffer&&t instanceof ArrayBuffer?"arraybuffer":void 0},n.checkSupport=function(t){var e=s[t.toLowerCase()];if(!e)throw Error(t+" is not supported by this browser")},n.MAX_VALUE_16BITS=65535,n.MAX_VALUE_32BITS=-1,n.pretty=function(t){var e,n,r="";for(n=0;(t||"").length>n;n++)e=t.charCodeAt(n),r+="\\x"+(16>e?"0":"")+e.toString(16).toUpperCase();return r},n.findCompression=function(t){for(var e in u)if(u.hasOwnProperty(e)&&u[e].magic===t)return u[e];return null},n.isRegExp=function(t){return"[object RegExp]"===Object.prototype.toString.call(t)}},{"./compressions":9,"./nodeBuffer":15,"./support":20}],23:[function(t,e){"use strict";function n(t,e){this.files=[],this.loadOptions=e,t&&this.load(t)}var r=t("./stringReader"),i=t("./nodeBufferReader"),o=t("./uint8ArrayReader"),a=t("./utils"),s=t("./signature"),u=t("./zipEntry"),c=t("./support");n.prototype={checkSignature:function(t){var e=this.reader.readString(4);if(e!==t)throw Error("Corrupted zip or bug : unexpected signature ("+a.pretty(e)+", expected "+a.pretty(t)+")")},readBlockEndOfCentral:function(){this.diskNumber=this.reader.readInt(2),this.diskWithCentralDirStart=this.reader.readInt(2),this.centralDirRecordsOnThisDisk=this.reader.readInt(2),this.centralDirRecords=this.reader.readInt(2),this.centralDirSize=this.reader.readInt(4),this.centralDirOffset=this.reader.readInt(4),this.zipCommentLength=this.reader.readInt(2),this.zipComment=this.reader.readString(this.zipCommentLength)},readBlockZip64EndOfCentral:function(){this.zip64EndOfCentralSize=this.reader.readInt(8),this.versionMadeBy=this.reader.readString(2),this.versionNeeded=this.reader.readInt(2),this.diskNumber=this.reader.readInt(4),this.diskWithCentralDirStart=this.reader.readInt(4),this.centralDirRecordsOnThisDisk=this.reader.readInt(8),this.centralDirRecords=this.reader.readInt(8),this.centralDirSize=this.reader.readInt(8),this.centralDirOffset=this.reader.readInt(8),this.zip64ExtensibleData={};for(var t,e,n,r=this.zip64EndOfCentralSize-44,i=0;r>i;)t=this.reader.readInt(2),e=this.reader.readInt(4),n=this.reader.readString(e),this.zip64ExtensibleData[t]={id:t,length:e,value:n}},readBlockZip64EndOfCentralLocator:function(){if(this.diskWithZip64CentralDirStart=this.reader.readInt(4),this.relativeOffsetEndOfZip64CentralDir=this.reader.readInt(8),this.disksCount=this.reader.readInt(4),this.disksCount>1)throw Error("Multi-volumes zip are not supported")},readLocalFiles:function(){var t,e;for(t=0;this.files.length>t;t++)e=this.files[t],this.reader.setIndex(e.localHeaderOffset),this.checkSignature(s.LOCAL_FILE_HEADER),e.readLocalPart(this.reader),e.handleUTF8()},readCentralDir:function(){var t;for(this.reader.setIndex(this.centralDirOffset);this.reader.readString(4)===s.CENTRAL_FILE_HEADER;)t=new u({zip64:this.zip64},this.loadOptions),t.readCentralPart(this.reader),this.files.push(t)},readEndOfCentral:function(){var t=this.reader.lastIndexOfSignature(s.CENTRAL_DIRECTORY_END);if(-1===t)throw Error("Corrupted zip : can't find end of central directory");if(this.reader.setIndex(t),this.checkSignature(s.CENTRAL_DIRECTORY_END),this.readBlockEndOfCentral(),this.diskNumber===a.MAX_VALUE_16BITS||this.diskWithCentralDirStart===a.MAX_VALUE_16BITS||this.centralDirRecordsOnThisDisk===a.MAX_VALUE_16BITS||this.centralDirRecords===a.MAX_VALUE_16BITS||this.centralDirSize===a.MAX_VALUE_32BITS||this.centralDirOffset===a.MAX_VALUE_32BITS){if(this.zip64=!0,t=this.reader.lastIndexOfSignature(s.ZIP64_CENTRAL_DIRECTORY_LOCATOR),-1===t)throw Error("Corrupted zip : can't find the ZIP64 end of central directory locator");this.reader.setIndex(t),this.checkSignature(s.ZIP64_CENTRAL_DIRECTORY_LOCATOR),this.readBlockZip64EndOfCentralLocator(),this.reader.setIndex(this.relativeOffsetEndOfZip64CentralDir),this.checkSignature(s.ZIP64_CENTRAL_DIRECTORY_END),this.readBlockZip64EndOfCentral()}},prepareReader:function(t){var e=a.getTypeOf(t);this.reader="string"!==e||c.uint8array?"nodebuffer"===e?new i(t):new o(a.transformTo("uint8array",t)):new r(t,this.loadOptions.optimizedBinaryString)},load:function(t){this.prepareReader(t),this.readEndOfCentral(),this.readCentralDir(),this.readLocalFiles()}},e.exports=n},{"./nodeBufferReader":16,"./signature":18,"./stringReader":19,"./support":20,"./uint8ArrayReader":21,"./utils":22,"./zipEntry":24}],24:[function(t,e){"use strict";function n(t,e){this.options=t,this.loadOptions=e}var r=t("./stringReader"),i=t("./utils"),o=t("./compressedObject"),a=t("./object");n.prototype={isEncrypted:function(){return 1===(1&this.bitFlag)},useUTF8:function(){return 2048===(2048&this.bitFlag)},prepareCompressedContent:function(t,e,n){return function(){var r=t.index;t.setIndex(e);var i=t.readData(n);return t.setIndex(r),i}},prepareContent:function(t,e,n,r,o){return function(){var t=i.transformTo(r.uncompressInputType,this.getCompressedContent()),e=r.uncompress(t);if(e.length!==o)throw Error("Bug : uncompressed data size mismatch");return e}},readLocalPart:function(t){var e,n;if(t.skip(22),this.fileNameLength=t.readInt(2),n=t.readInt(2),this.fileName=t.readString(this.fileNameLength),t.skip(n),-1==this.compressedSize||-1==this.uncompressedSize)throw Error("Bug or corrupted zip : didn't get enough informations from the central directory (compressedSize == -1 || uncompressedSize == -1)");if(e=i.findCompression(this.compressionMethod),null===e)throw Error("Corrupted zip : compression "+i.pretty(this.compressionMethod)+" unknown (inner file : "+this.fileName+")");if(this.decompressed=new o,this.decompressed.compressedSize=this.compressedSize,this.decompressed.uncompressedSize=this.uncompressedSize,this.decompressed.crc32=this.crc32,this.decompressed.compressionMethod=this.compressionMethod,this.decompressed.getCompressedContent=this.prepareCompressedContent(t,t.index,this.compressedSize,e),this.decompressed.getContent=this.prepareContent(t,t.index,this.compressedSize,e,this.uncompressedSize),this.loadOptions.checkCRC32&&(this.decompressed=i.transformTo("string",this.decompressed.getContent()),a.crc32(this.decompressed)!==this.crc32))throw Error("Corrupted zip : CRC32 mismatch")},readCentralPart:function(t){if(this.versionMadeBy=t.readString(2),this.versionNeeded=t.readInt(2),this.bitFlag=t.readInt(2),this.compressionMethod=t.readString(2),this.date=t.readDate(),this.crc32=t.readInt(4),this.compressedSize=t.readInt(4),this.uncompressedSize=t.readInt(4),this.fileNameLength=t.readInt(2),this.extraFieldsLength=t.readInt(2),this.fileCommentLength=t.readInt(2),this.diskNumberStart=t.readInt(2),this.internalFileAttributes=t.readInt(2),this.externalFileAttributes=t.readInt(4),this.localHeaderOffset=t.readInt(4),this.isEncrypted())throw Error("Encrypted zip are not supported");this.fileName=t.readString(this.fileNameLength),this.readExtraFields(t),this.parseZIP64ExtraField(t),this.fileComment=t.readString(this.fileCommentLength),this.dir=16&this.externalFileAttributes?!0:!1},parseZIP64ExtraField:function(){if(this.extraFields[1]){var t=new r(this.extraFields[1].value);this.uncompressedSize===i.MAX_VALUE_32BITS&&(this.uncompressedSize=t.readInt(8)),this.compressedSize===i.MAX_VALUE_32BITS&&(this.compressedSize=t.readInt(8)),this.localHeaderOffset===i.MAX_VALUE_32BITS&&(this.localHeaderOffset=t.readInt(8)),this.diskNumberStart===i.MAX_VALUE_32BITS&&(this.diskNumberStart=t.readInt(4))}},readExtraFields:function(t){var e,n,r,i=t.index;for(this.extraFields=this.extraFields||{};t.index0?e.windowBits=-e.windowBits:e.gzip&&e.windowBits>0&&16>e.windowBits&&(e.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new f,this.strm.avail_out=0;var n=a.deflateInit2(this.strm,e.level,e.method,e.windowBits,e.memLevel,e.strategy);if(n!==h)throw Error(c[n]);e.header&&a.deflateSetHeader(this.strm,e.header)};_.prototype.push=function(t,e){var n,r,i=this.strm,o=this.options.chunkSize;if(this.ended)return!1;r=e===~~e?e:e===!0?d:l,i.input="string"==typeof t?u.string2buf(t):t,i.next_in=0,i.avail_in=i.input.length;do{if(0===i.avail_out&&(i.output=new s.Buf8(o),i.next_out=0,i.avail_out=o),n=a.deflate(i,r),n!==p&&n!==h)return this.onEnd(n),this.ended=!0,!1;(0===i.avail_out||0===i.avail_in&&r===d)&&("string"===this.options.to?this.onData(u.buf2binstring(s.shrinkBuf(i.output,i.next_out))):this.onData(s.shrinkBuf(i.output,i.next_out)))}while((i.avail_in>0||0===i.avail_out)&&n!==p);return r===d?(n=a.deflateEnd(this.strm),this.onEnd(n),this.ended=!0,n===h):!0},_.prototype.onData=function(t){this.chunks.push(t)},_.prototype.onEnd=function(t){t===h&&(this.result="string"===this.options.to?this.chunks.join(""):s.flattenChunks(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg},n.Deflate=_,n.deflate=r,n.deflateRaw=i,n.gzip=o},{"./utils/common":28,"./utils/strings":29,"./zlib/deflate.js":33,"./zlib/messages":38,"./zlib/zstream":40}],27:[function(t,e,n){"use strict";function r(t,e){var n=new d(e);if(n.push(t,!0),n.err)throw n.msg;return n.result}function i(t,e){return e=e||{},e.raw=!0,r(t,e)}var o=t("./zlib/inflate.js"),a=t("./utils/common"),s=t("./utils/strings"),u=t("./zlib/constants"),c=t("./zlib/messages"),f=t("./zlib/zstream"),l=t("./zlib/gzheader"),d=function(t){this.options=a.assign({chunkSize:16384,windowBits:0,to:""},t||{});var e=this.options;e.raw&&e.windowBits>=0&&16>e.windowBits&&(e.windowBits=-e.windowBits,0===e.windowBits&&(e.windowBits=-15)),!(e.windowBits>=0&&16>e.windowBits)||t&&t.windowBits||(e.windowBits+=32),e.windowBits>15&&48>e.windowBits&&0===(15&e.windowBits)&&(e.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new f,this.strm.avail_out=0;var n=o.inflateInit2(this.strm,e.windowBits);if(n!==u.Z_OK)throw Error(c[n]);this.header=new l,o.inflateGetHeader(this.strm,this.header)};d.prototype.push=function(t,e){var n,r,i,c,f,l=this.strm,d=this.options.chunkSize;if(this.ended)return!1;r=e===~~e?e:e===!0?u.Z_FINISH:u.Z_NO_FLUSH,l.input="string"==typeof t?s.binstring2buf(t):t,l.next_in=0,l.avail_in=l.input.length;do{if(0===l.avail_out&&(l.output=new a.Buf8(d),l.next_out=0,l.avail_out=d),n=o.inflate(l,u.Z_NO_FLUSH),n!==u.Z_STREAM_END&&n!==u.Z_OK)return this.onEnd(n),this.ended=!0,!1;l.next_out&&(0===l.avail_out||n===u.Z_STREAM_END||0===l.avail_in&&r===u.Z_FINISH)&&("string"===this.options.to?(i=s.utf8border(l.output,l.next_out),c=l.next_out-i,f=s.buf2string(l.output,i),l.next_out=c,l.avail_out=d-c,c&&a.arraySet(l.output,l.output,i,c,0),this.onData(f)):this.onData(a.shrinkBuf(l.output,l.next_out)))}while((l.avail_in>0||0===l.avail_out)&&n!==u.Z_STREAM_END);return n===u.Z_STREAM_END&&(r=u.Z_FINISH),r===u.Z_FINISH?(n=o.inflateEnd(this.strm),this.onEnd(n),this.ended=!0,n===u.Z_OK):!0},d.prototype.onData=function(t){this.chunks.push(t)},d.prototype.onEnd=function(t){t===u.Z_OK&&(this.result="string"===this.options.to?this.chunks.join(""):a.flattenChunks(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg},n.Inflate=d,n.inflate=r,n.inflateRaw=i,n.ungzip=r},{"./utils/common":28,"./utils/strings":29,"./zlib/constants":31,"./zlib/gzheader":34,"./zlib/inflate.js":36,"./zlib/messages":38,"./zlib/zstream":40}],28:[function(t,e,n){"use strict";var r="undefined"!=typeof Uint8Array&&"undefined"!=typeof Uint16Array&&"undefined"!=typeof Int32Array;n.assign=function(t){for(var e=Array.prototype.slice.call(arguments,1);e.length;){var n=e.shift();if(n){if("object"!=typeof n)throw new TypeError(n+"must be non-object");for(var r in n)n.hasOwnProperty(r)&&(t[r]=n[r])}}return t},n.shrinkBuf=function(t,e){return t.length===e?t:t.subarray?t.subarray(0,e):(t.length=e,t)};var i={arraySet:function(t,e,n,r,i){if(e.subarray&&t.subarray)return t.set(e.subarray(n,n+r),i),void 0;for(var o=0;r>o;o++)t[i+o]=e[n+o]},flattenChunks:function(t){var e,n,r,i,o,a;for(r=0,e=0,n=t.length;n>e;e++)r+=t[e].length;for(a=new Uint8Array(r),i=0,e=0,n=t.length;n>e;e++)o=t[e],a.set(o,i),i+=o.length;return a}},o={arraySet:function(t,e,n,r,i){for(var o=0;r>o;o++)t[i+o]=e[n+o]},flattenChunks:function(t){return[].concat.apply([],t)}};n.setTyped=function(t){t?(n.Buf8=Uint8Array,n.Buf16=Uint16Array,n.Buf32=Int32Array,n.assign(n,i)):(n.Buf8=Array,n.Buf16=Array,n.Buf32=Array,n.assign(n,o))},n.setTyped(r)},{}],29:[function(t,e,n){"use strict";function r(t,e){if(65537>e&&(t.subarray&&a||!t.subarray&&o))return String.fromCharCode.apply(null,i.shrinkBuf(t,e));for(var n="",r=0;e>r;r++)n+=String.fromCharCode(t[r]);return n}var i=t("./common"),o=!0,a=!0;try{String.fromCharCode.apply(null,[0])}catch(s){o=!1}try{String.fromCharCode.apply(null,new Uint8Array(1))}catch(s){a=!1}for(var u=new i.Buf8(256),c=0;256>c;c++)u[c]=c>=252?6:c>=248?5:c>=240?4:c>=224?3:c>=192?2:1;u[254]=u[254]=1,n.string2buf=function(t){var e,n,r,o,a,s=t.length,u=0;for(o=0;s>o;o++)n=t.charCodeAt(o),55296===(64512&n)&&s>o+1&&(r=t.charCodeAt(o+1),56320===(64512&r)&&(n=65536+(n-55296<<10)+(r-56320),o++)),u+=128>n?1:2048>n?2:65536>n?3:4;for(e=new i.Buf8(u),a=0,o=0;u>a;o++)n=t.charCodeAt(o),55296===(64512&n)&&s>o+1&&(r=t.charCodeAt(o+1),56320===(64512&r)&&(n=65536+(n-55296<<10)+(r-56320),o++)),128>n?e[a++]=n:2048>n?(e[a++]=192|n>>>6,e[a++]=128|63&n):65536>n?(e[a++]=224|n>>>12,e[a++]=128|63&n>>>6,e[a++]=128|63&n):(e[a++]=240|n>>>18,e[a++]=128|63&n>>>12,e[a++]=128|63&n>>>6,e[a++]=128|63&n);return e},n.buf2binstring=function(t){return r(t,t.length)},n.binstring2buf=function(t){for(var e=new i.Buf8(t.length),n=0,r=e.length;r>n;n++)e[n]=t.charCodeAt(n);return e},n.buf2string=function(t,e){var n,i,o,a,s=e||t.length,c=Array(2*s);for(i=0,n=0;s>n;)if(o=t[n++],128>o)c[i++]=o;else if(a=u[o],a>4)c[i++]=65533,n+=a-1;else{for(o&=2===a?31:3===a?15:7;a>1&&s>n;)o=o<<6|63&t[n++],a--;a>1?c[i++]=65533:65536>o?c[i++]=o:(o-=65536,c[i++]=55296|1023&o>>10,c[i++]=56320|1023&o)}return r(c,i)},n.utf8border=function(t,e){var n;for(e=e||t.length,e>t.length&&(e=t.length),n=e-1;n>=0&&128===(192&t[n]);)n--;return 0>n?e:0===n?e:n+u[t[n]]>e?n:e}},{"./common":28}],30:[function(t,e){"use strict";function n(t,e,n,r){for(var i=0|65535&t,o=0|65535&t>>>16,a=0;0!==n;){a=n>2e3?2e3:n,n-=a;do i=0|i+e[r++],o=0|o+i;while(--a);i%=65521,o%=65521}return 0|(i|o<<16)}e.exports=n},{}],31:[function(t,e){e.exports={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8}},{}],32:[function(t,e){"use strict";function n(){for(var t,e=[],n=0;256>n;n++){t=n;for(var r=0;8>r;r++)t=1&t?3988292384^t>>>1:t>>>1;e[n]=t}return e}function r(t,e,n,r){var o=i,a=r+n;t=-1^t;for(var s=r;a>s;s++)t=t>>>8^o[255&(t^e[s])];return-1^t}var i=n();e.exports=r},{}],33:[function(t,e,n){"use strict";function r(t,e){return t.msg=N[e],e}function i(t){return(t<<1)-(t>4?9:0)}function o(t){for(var e=t.length;--e>=0;)t[e]=0}function a(t){var e=t.state,n=e.pending;n>t.avail_out&&(n=t.avail_out),0!==n&&(I.arraySet(t.output,e.pending_buf,e.pending_out,n,t.next_out),t.next_out+=n,e.pending_out+=n,t.total_out+=n,t.avail_out-=n,e.pending-=n,0===e.pending&&(e.pending_out=0))}function s(t,e){T._tr_flush_block(t,t.block_start>=0?t.block_start:-1,t.strstart-t.block_start,e),t.block_start=t.strstart,a(t.strm)}function u(t,e){t.pending_buf[t.pending++]=e}function c(t,e){t.pending_buf[t.pending++]=255&e>>>8,t.pending_buf[t.pending++]=255&e}function f(t,e,n,r){var i=t.avail_in;return i>r&&(i=r),0===i?0:(t.avail_in-=i,I.arraySet(e,t.input,t.next_in,i,n),1===t.state.wrap?t.adler=R(t.adler,e,i,n):2===t.state.wrap&&(t.adler=C(t.adler,e,i,n)),t.next_in+=i,t.total_in+=i,i)}function l(t,e){var n,r,i=t.max_chain_length,o=t.strstart,a=t.prev_length,s=t.nice_match,u=t.strstart>t.w_size-ce?t.strstart-(t.w_size-ce):0,c=t.window,f=t.w_mask,l=t.prev,d=t.strstart+ue,h=c[o+a-1],p=c[o+a];t.prev_length>=t.good_match&&(i>>=2),s>t.lookahead&&(s=t.lookahead);do if(n=e,c[n+a]===p&&c[n+a-1]===h&&c[n]===c[o]&&c[++n]===c[o+1]){o+=2,n++;do;while(c[++o]===c[++n]&&c[++o]===c[++n]&&c[++o]===c[++n]&&c[++o]===c[++n]&&c[++o]===c[++n]&&c[++o]===c[++n]&&c[++o]===c[++n]&&c[++o]===c[++n]&&d>o);if(r=ue-(d-o),o=d-ue,r>a){if(t.match_start=e,a=r,r>=s)break;h=c[o+a-1],p=c[o+a]}}while((e=l[e&f])>u&&0!==--i);return t.lookahead>=a?a:t.lookahead}function d(t){var e,n,r,i,o,a=t.w_size;do{if(i=t.window_size-t.lookahead-t.strstart,t.strstart>=a+(a-ce)){I.arraySet(t.window,t.window,a,a,0),t.match_start-=a,t.strstart-=a,t.block_start-=a,n=t.hash_size,e=n;do r=t.head[--e],t.head[e]=r>=a?r-a:0;while(--n);n=a,e=n;do r=t.prev[--e],t.prev[e]=r>=a?r-a:0;while(--n);i+=a}if(0===t.strm.avail_in)break;if(n=f(t.strm,t.window,t.strstart+t.lookahead,i),t.lookahead+=n,t.lookahead+t.insert>=se)for(o=t.strstart-t.insert,t.ins_h=t.window[o],t.ins_h=(t.ins_h<t.lookahead+t.insert)););}while(ce>t.lookahead&&0!==t.strm.avail_in)}function h(t,e){var n=65535;for(n>t.pending_buf_size-5&&(n=t.pending_buf_size-5);;){if(1>=t.lookahead){if(d(t),0===t.lookahead&&e===D)return _e;if(0===t.lookahead)break}t.strstart+=t.lookahead,t.lookahead=0;var r=t.block_start+n;if((0===t.strstart||t.strstart>=r)&&(t.lookahead=t.strstart-r,t.strstart=r,s(t,!1),0===t.strm.avail_out))return _e;if(t.strstart-t.block_start>=t.w_size-ce&&(s(t,!1),0===t.strm.avail_out))return _e}return t.insert=0,e===j?(s(t,!0),0===t.strm.avail_out?be:we):t.strstart>t.block_start&&(s(t,!1),0===t.strm.avail_out)?_e:_e}function p(t,e){for(var n,r;;){if(ce>t.lookahead){if(d(t),ce>t.lookahead&&e===D)return _e;if(0===t.lookahead)break}if(n=0,t.lookahead>=se&&(t.ins_h=(t.ins_h<=se)if(r=T._tr_tally(t,t.strstart-t.match_start,t.match_length-se),t.lookahead-=t.match_length,t.match_length<=t.max_lazy_match&&t.lookahead>=se){t.match_length--;do t.strstart++,t.ins_h=(t.ins_h<t.strstart?t.strstart:se-1,e===j?(s(t,!0),0===t.strm.avail_out?be:we):t.last_lit&&(s(t,!1),0===t.strm.avail_out)?_e:ye}function m(t,e){for(var n,r,i;;){if(ce>t.lookahead){if(d(t),ce>t.lookahead&&e===D)return _e;if(0===t.lookahead)break}if(n=0,t.lookahead>=se&&(t.ins_h=(t.ins_h<=t.match_length&&(t.strategy===Y||t.match_length===se&&t.strstart-t.match_start>4096)&&(t.match_length=se-1)),t.prev_length>=se&&t.match_length<=t.prev_length){i=t.strstart+t.lookahead-se,r=T._tr_tally(t,t.strstart-1-t.prev_match,t.prev_length-se),t.lookahead-=t.prev_length-1,t.prev_length-=2;do i>=++t.strstart&&(t.ins_h=(t.ins_h<t.strstart?t.strstart:se-1,e===j?(s(t,!0),0===t.strm.avail_out?be:we):t.last_lit&&(s(t,!1),0===t.strm.avail_out)?_e:ye}function g(t,e){for(var n,r,i,o,a=t.window;;){if(ue>=t.lookahead){if(d(t),ue>=t.lookahead&&e===D)return _e;if(0===t.lookahead)break +}if(t.match_length=0,t.lookahead>=se&&t.strstart>0&&(i=t.strstart-1,r=a[i],r===a[++i]&&r===a[++i]&&r===a[++i])){o=t.strstart+ue;do;while(r===a[++i]&&r===a[++i]&&r===a[++i]&&r===a[++i]&&r===a[++i]&&r===a[++i]&&r===a[++i]&&r===a[++i]&&o>i);t.match_length=ue-(o-i),t.match_length>t.lookahead&&(t.match_length=t.lookahead)}if(t.match_length>=se?(n=T._tr_tally(t,1,t.match_length-se),t.lookahead-=t.match_length,t.strstart+=t.match_length,t.match_length=0):(n=T._tr_tally(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++),n&&(s(t,!1),0===t.strm.avail_out))return _e}return t.insert=0,e===j?(s(t,!0),0===t.strm.avail_out?be:we):t.last_lit&&(s(t,!1),0===t.strm.avail_out)?_e:ye}function v(t,e){for(var n;;){if(0===t.lookahead&&(d(t),0===t.lookahead)){if(e===D)return _e;break}if(t.match_length=0,n=T._tr_tally(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++,n&&(s(t,!1),0===t.strm.avail_out))return _e}return t.insert=0,e===j?(s(t,!0),0===t.strm.avail_out?be:we):t.last_lit&&(s(t,!1),0===t.strm.avail_out)?_e:ye}function _(t){t.window_size=2*t.w_size,o(t.head),t.max_lazy_match=O[t.level].max_lazy,t.good_match=O[t.level].good_length,t.nice_match=O[t.level].nice_length,t.max_chain_length=O[t.level].max_chain,t.strstart=0,t.block_start=0,t.lookahead=0,t.insert=0,t.match_length=t.prev_length=se-1,t.match_available=0,t.ins_h=0}function y(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=J,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new I.Buf16(2*oe),this.dyn_dtree=new I.Buf16(2*(2*re+1)),this.bl_tree=new I.Buf16(2*(2*ie+1)),o(this.dyn_ltree),o(this.dyn_dtree),o(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new I.Buf16(ae+1),this.heap=new I.Buf16(2*ne+1),o(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new I.Buf16(2*ne+1),o(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}function b(t){var e;return t&&t.state?(t.total_in=t.total_out=0,t.data_type=K,e=t.state,e.pending=0,e.pending_out=0,0>e.wrap&&(e.wrap=-e.wrap),e.status=e.wrap?le:ge,t.adler=2===e.wrap?0:1,e.last_flush=D,T._tr_init(e),F):r(t,P)}function w(t){var e=b(t);return e===F&&_(t.state),e}function E(t,e){return t&&t.state?2!==t.state.wrap?P:(t.state.gzhead=e,F):P}function x(t,e,n,i,o,a){if(!t)return P;var s=1;if(e===Z&&(e=6),0>i?(s=0,i=-i):i>15&&(s=2,i-=16),1>o||o>G||n!==J||8>i||i>15||0>e||e>9||0>a||a>W)return r(t,P);8===i&&(i=9);var u=new y;return t.state=u,u.strm=t,u.wrap=s,u.gzhead=null,u.w_bits=i,u.w_size=1<>1,u.l_buf=3*u.lit_bufsize,u.level=e,u.strategy=a,u.method=n,w(t)}function k(t,e){return x(t,e,J,Q,$,q)}function S(t,e){var n,s,f,l;if(!t||!t.state||e>B||0>e)return t?r(t,P):P;if(s=t.state,!t.output||!t.input&&0!==t.avail_in||s.status===ve&&e!==j)return r(t,0===t.avail_out?V:P);if(s.strm=t,n=s.last_flush,s.last_flush=e,s.status===le)if(2===s.wrap)t.adler=0,u(s,31),u(s,139),u(s,8),s.gzhead?(u(s,(s.gzhead.text?1:0)+(s.gzhead.hcrc?2:0)+(s.gzhead.extra?4:0)+(s.gzhead.name?8:0)+(s.gzhead.comment?16:0)),u(s,255&s.gzhead.time),u(s,255&s.gzhead.time>>8),u(s,255&s.gzhead.time>>16),u(s,255&s.gzhead.time>>24),u(s,9===s.level?2:s.strategy>=X||2>s.level?4:0),u(s,255&s.gzhead.os),s.gzhead.extra&&s.gzhead.extra.length&&(u(s,255&s.gzhead.extra.length),u(s,255&s.gzhead.extra.length>>8)),s.gzhead.hcrc&&(t.adler=C(t.adler,s.pending_buf,s.pending,0)),s.gzindex=0,s.status=de):(u(s,0),u(s,0),u(s,0),u(s,0),u(s,0),u(s,9===s.level?2:s.strategy>=X||2>s.level?4:0),u(s,Ee),s.status=ge);else{var d=J+(s.w_bits-8<<4)<<8,h=-1;h=s.strategy>=X||2>s.level?0:6>s.level?1:6===s.level?2:3,d|=h<<6,0!==s.strstart&&(d|=fe),d+=31-d%31,s.status=ge,c(s,d),0!==s.strstart&&(c(s,t.adler>>>16),c(s,65535&t.adler)),t.adler=1}if(s.status===de)if(s.gzhead.extra){for(f=s.pending;s.gzindex<(65535&s.gzhead.extra.length)&&(s.pending!==s.pending_buf_size||(s.gzhead.hcrc&&s.pending>f&&(t.adler=C(t.adler,s.pending_buf,s.pending-f,f)),a(t),f=s.pending,s.pending!==s.pending_buf_size));)u(s,255&s.gzhead.extra[s.gzindex]),s.gzindex++;s.gzhead.hcrc&&s.pending>f&&(t.adler=C(t.adler,s.pending_buf,s.pending-f,f)),s.gzindex===s.gzhead.extra.length&&(s.gzindex=0,s.status=he)}else s.status=he;if(s.status===he)if(s.gzhead.name){f=s.pending;do{if(s.pending===s.pending_buf_size&&(s.gzhead.hcrc&&s.pending>f&&(t.adler=C(t.adler,s.pending_buf,s.pending-f,f)),a(t),f=s.pending,s.pending===s.pending_buf_size)){l=1;break}l=s.gzindexf&&(t.adler=C(t.adler,s.pending_buf,s.pending-f,f)),0===l&&(s.gzindex=0,s.status=pe)}else s.status=pe;if(s.status===pe)if(s.gzhead.comment){f=s.pending;do{if(s.pending===s.pending_buf_size&&(s.gzhead.hcrc&&s.pending>f&&(t.adler=C(t.adler,s.pending_buf,s.pending-f,f)),a(t),f=s.pending,s.pending===s.pending_buf_size)){l=1;break}l=s.gzindexf&&(t.adler=C(t.adler,s.pending_buf,s.pending-f,f)),0===l&&(s.status=me)}else s.status=me;if(s.status===me&&(s.gzhead.hcrc?(s.pending+2>s.pending_buf_size&&a(t),s.pending+2<=s.pending_buf_size&&(u(s,255&t.adler),u(s,255&t.adler>>8),t.adler=0,s.status=ge)):s.status=ge),0!==s.pending){if(a(t),0===t.avail_out)return s.last_flush=-1,F}else if(0===t.avail_in&&i(e)<=i(n)&&e!==j)return r(t,V);if(s.status===ve&&0!==t.avail_in)return r(t,V);if(0!==t.avail_in||0!==s.lookahead||e!==D&&s.status!==ve){var p=s.strategy===X?v(s,e):s.strategy===H?g(s,e):O[s.level].func(s,e);if((p===be||p===we)&&(s.status=ve),p===_e||p===be)return 0===t.avail_out&&(s.last_flush=-1),F;if(p===ye&&(e===z?T._tr_align(s):e!==B&&(T._tr_stored_block(s,0,0,!1),e===L&&(o(s.head),0===s.lookahead&&(s.strstart=0,s.block_start=0,s.insert=0))),a(t),0===t.avail_out))return s.last_flush=-1,F}return e!==j?F:0>=s.wrap?M:(2===s.wrap?(u(s,255&t.adler),u(s,255&t.adler>>8),u(s,255&t.adler>>16),u(s,255&t.adler>>24),u(s,255&t.total_in),u(s,255&t.total_in>>8),u(s,255&t.total_in>>16),u(s,255&t.total_in>>24)):(c(s,t.adler>>>16),c(s,65535&t.adler)),a(t),s.wrap>0&&(s.wrap=-s.wrap),0!==s.pending?F:M)}function A(t){var e;return t&&t.state?(e=t.state.status,e!==le&&e!==de&&e!==he&&e!==pe&&e!==me&&e!==ge&&e!==ve?r(t,P):(t.state=null,e===ge?r(t,U):F)):P}var O,I=t("../utils/common"),T=t("./trees"),R=t("./adler32"),C=t("./crc32"),N=t("./messages"),D=0,z=1,L=3,j=4,B=5,F=0,M=1,P=-2,U=-3,V=-5,Z=-1,Y=1,X=2,H=3,W=4,q=0,K=2,J=8,G=9,Q=15,$=8,te=29,ee=256,ne=ee+1+te,re=30,ie=19,oe=2*ne+1,ae=15,se=3,ue=258,ce=ue+se+1,fe=32,le=42,de=69,he=73,pe=91,me=103,ge=113,ve=666,_e=1,ye=2,be=3,we=4,Ee=3,xe=function(t,e,n,r,i){this.good_length=t,this.max_lazy=e,this.nice_length=n,this.max_chain=r,this.func=i};O=[new xe(0,0,0,0,h),new xe(4,4,8,4,p),new xe(4,5,16,8,p),new xe(4,6,32,32,p),new xe(4,4,16,16,m),new xe(8,16,32,32,m),new xe(8,16,128,128,m),new xe(8,32,128,256,m),new xe(32,128,258,1024,m),new xe(32,258,258,4096,m)],n.deflateInit=k,n.deflateInit2=x,n.deflateReset=w,n.deflateResetKeep=b,n.deflateSetHeader=E,n.deflate=S,n.deflateEnd=A,n.deflateInfo="pako deflate (from Nodeca project)"},{"../utils/common":28,"./adler32":30,"./crc32":32,"./messages":38,"./trees":39}],34:[function(t,e){"use strict";function n(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1}e.exports=n},{}],35:[function(t,e){"use strict";var n=30,r=12;e.exports=function(t,e){var i,o,a,s,u,c,f,l,d,h,p,m,g,v,_,y,b,w,E,x,k,S,A,O,I;i=t.state,o=t.next_in,O=t.input,a=o+(t.avail_in-5),s=t.next_out,I=t.output,u=s-(e-t.avail_out),c=s+(t.avail_out-257),f=i.dmax,l=i.wsize,d=i.whave,h=i.wnext,p=i.window,m=i.hold,g=i.bits,v=i.lencode,_=i.distcode,y=(1<g&&(m+=O[o++]<>>24,m>>>=E,g-=E,E=255&w>>>16,0===E)I[s++]=65535&w;else{if(!(16&E)){if(0===(64&E)){w=v[(65535&w)+(m&(1<g&&(m+=O[o++]<>>=E,g-=E),15>g&&(m+=O[o++]<>>24,m>>>=E,g-=E,E=255&w>>>16,!(16&E)){if(0===(64&E)){w=_[(65535&w)+(m&(1<g&&(m+=O[o++]<g&&(m+=O[o++]<f){t.msg="invalid distance too far back",i.mode=n;break t}if(m>>>=E,g-=E,E=s-u,k>E){if(E=k-E,E>d&&i.sane){t.msg="invalid distance too far back",i.mode=n;break t}if(S=0,A=p,0===h){if(S+=l-E,x>E){x-=E;do I[s++]=p[S++];while(--E);S=s-k,A=I}}else if(E>h){if(S+=l+h-E,E-=h,x>E){x-=E;do I[s++]=p[S++];while(--E);if(S=0,x>h){E=h,x-=E;do I[s++]=p[S++];while(--E);S=s-k,A=I}}}else if(S+=h-E,x>E){x-=E;do I[s++]=p[S++];while(--E);S=s-k,A=I}for(;x>2;)I[s++]=A[S++],I[s++]=A[S++],I[s++]=A[S++],x-=3;x&&(I[s++]=A[S++],x>1&&(I[s++]=A[S++]))}else{S=s-k;do I[s++]=I[S++],I[s++]=I[S++],I[s++]=I[S++],x-=3;while(x>2);x&&(I[s++]=I[S++],x>1&&(I[s++]=I[S++]))}break}}break}}while(a>o&&c>s);x=g>>3,o-=x,g-=x<<3,m&=(1<o?5+(a-o):5-(o-a),t.avail_out=c>s?257+(c-s):257-(s-c),i.hold=m,i.bits=g}},{}],36:[function(t,e,n){"use strict";function r(t){return(255&t>>>24)+(65280&t>>>8)+((65280&t)<<8)+((255&t)<<24)}function i(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new v.Buf16(320),this.work=new v.Buf16(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function o(t){var e;return t&&t.state?(e=t.state,t.total_in=t.total_out=e.total=0,t.msg="",e.wrap&&(t.adler=1&e.wrap),e.mode=j,e.last=0,e.havedict=0,e.dmax=32768,e.head=null,e.hold=0,e.bits=0,e.lencode=e.lendyn=new v.Buf32(pe),e.distcode=e.distdyn=new v.Buf32(me),e.sane=1,e.back=-1,I):C}function a(t){var e;return t&&t.state?(e=t.state,e.wsize=0,e.whave=0,e.wnext=0,o(t)):C}function s(t,e){var n,r;return t&&t.state?(r=t.state,0>e?(n=0,e=-e):(n=(e>>4)+1,48>e&&(e&=15)),e&&(8>e||e>15)?C:(null!==r.window&&r.wbits!==e&&(r.window=null),r.wrap=n,r.wbits=e,a(t))):C}function u(t,e){var n,r;return t?(r=new i,t.state=r,r.window=null,n=s(t,e),n!==I&&(t.state=null),n):C}function c(t){return u(t,ve)}function f(t){if(_e){var e;for(m=new v.Buf32(512),g=new v.Buf32(32),e=0;144>e;)t.lens[e++]=8;for(;256>e;)t.lens[e++]=9;for(;280>e;)t.lens[e++]=7;for(;288>e;)t.lens[e++]=8;for(w(x,t.lens,0,288,m,0,t.work,{bits:9}),e=0;32>e;)t.lens[e++]=5;w(k,t.lens,0,32,g,0,t.work,{bits:5}),_e=!1}t.lencode=m,t.lenbits=9,t.distcode=g,t.distbits=5}function l(t,e,n,r){var i,o=t.state;return null===o.window&&(o.wsize=1<=o.wsize?(v.arraySet(o.window,e,n-o.wsize,o.wsize,0),o.wnext=0,o.whave=o.wsize):(i=o.wsize-o.wnext,i>r&&(i=r),v.arraySet(o.window,e,n-r,i,o.wnext),r-=i,r?(v.arraySet(o.window,e,n-r,r,0),o.wnext=r,o.whave=o.wsize):(o.wnext+=i,o.wnext===o.wsize&&(o.wnext=0),o.whaveh;){if(0===u)break t;u--,d+=i[a++]<>>8,n.check=y(n.check,Oe,2,0),d=0,h=0,n.mode=B;break}if(n.flags=0,n.head&&(n.head.done=!1),!(1&n.wrap)||(((255&d)<<8)+(d>>8))%31){t.msg="incorrect header check",n.mode=le;break}if((15&d)!==L){t.msg="unknown compression method",n.mode=le;break}if(d>>>=4,h-=4,Ee=(15&d)+8,0===n.wbits)n.wbits=Ee;else if(Ee>n.wbits){t.msg="invalid window size",n.mode=le;break}n.dmax=1<h;){if(0===u)break t;u--,d+=i[a++]<>8),512&n.flags&&(Oe[0]=255&d,Oe[1]=255&d>>>8,n.check=y(n.check,Oe,2,0)),d=0,h=0,n.mode=F;case F:for(;32>h;){if(0===u)break t;u--,d+=i[a++]<>>8,Oe[2]=255&d>>>16,Oe[3]=255&d>>>24,n.check=y(n.check,Oe,4,0)),d=0,h=0,n.mode=M;case M:for(;16>h;){if(0===u)break t;u--,d+=i[a++]<>8),512&n.flags&&(Oe[0]=255&d,Oe[1]=255&d>>>8,n.check=y(n.check,Oe,2,0)),d=0,h=0,n.mode=P;case P:if(1024&n.flags){for(;16>h;){if(0===u)break t;u--,d+=i[a++]<>>8,n.check=y(n.check,Oe,2,0)),d=0,h=0}else n.head&&(n.head.extra=null);n.mode=U;case U:if(1024&n.flags&&(g=n.length,g>u&&(g=u),g&&(n.head&&(Ee=n.head.extra_len-n.length,n.head.extra||(n.head.extra=Array(n.head.extra_len)),v.arraySet(n.head.extra,i,a,g,Ee)),512&n.flags&&(n.check=y(n.check,i,g,a)),u-=g,a+=g,n.length-=g),n.length))break t;n.length=0,n.mode=V;case V:if(2048&n.flags){if(0===u)break t;g=0;do Ee=i[a+g++],n.head&&Ee&&65536>n.length&&(n.head.name+=String.fromCharCode(Ee));while(Ee&&u>g);if(512&n.flags&&(n.check=y(n.check,i,g,a)),u-=g,a+=g,Ee)break t}else n.head&&(n.head.name=null);n.length=0,n.mode=Z;case Z:if(4096&n.flags){if(0===u)break t;g=0;do Ee=i[a+g++],n.head&&Ee&&65536>n.length&&(n.head.comment+=String.fromCharCode(Ee));while(Ee&&u>g);if(512&n.flags&&(n.check=y(n.check,i,g,a)),u-=g,a+=g,Ee)break t}else n.head&&(n.head.comment=null);n.mode=Y;case Y:if(512&n.flags){for(;16>h;){if(0===u)break t;u--,d+=i[a++]<>9,n.head.done=!0),t.adler=n.check=0,n.mode=W;break;case X:for(;32>h;){if(0===u)break t;u--,d+=i[a++]<>>=7&h,h-=7&h,n.mode=ue;break}for(;3>h;){if(0===u)break t;u--,d+=i[a++]<>>=1,h-=1,3&d){case 0:n.mode=K;break;case 1:if(f(n),n.mode=ee,e===O){d>>>=2,h-=2;break t}break;case 2:n.mode=Q;break;case 3:t.msg="invalid block type",n.mode=le}d>>>=2,h-=2;break;case K:for(d>>>=7&h,h-=7&h;32>h;){if(0===u)break t;u--,d+=i[a++]<>>16)){t.msg="invalid stored block lengths",n.mode=le;break}if(n.length=65535&d,d=0,h=0,n.mode=J,e===O)break t;case J:n.mode=G;case G:if(g=n.length){if(g>u&&(g=u),g>c&&(g=c),0===g)break t;v.arraySet(o,i,a,g,s),u-=g,a+=g,c-=g,s+=g,n.length-=g;break}n.mode=W;break;case Q:for(;14>h;){if(0===u)break t;u--,d+=i[a++]<>>=5,h-=5,n.ndist=(31&d)+1,d>>>=5,h-=5,n.ncode=(15&d)+4,d>>>=4,h-=4,n.nlen>286||n.ndist>30){t.msg="too many length or distance symbols",n.mode=le;break}n.have=0,n.mode=$;case $:for(;n.haveh;){if(0===u)break t;u--,d+=i[a++]<>>=3,h-=3}for(;19>n.have;)n.lens[Ie[n.have++]]=0;if(n.lencode=n.lendyn,n.lenbits=7,ke={bits:n.lenbits},xe=w(E,n.lens,0,19,n.lencode,0,n.work,ke),n.lenbits=ke.bits,xe){t.msg="invalid code lengths set",n.mode=le;break}n.have=0,n.mode=te;case te:for(;n.have>>24,ve=255&Ae>>>16,_e=65535&Ae,!(h>=ge);){if(0===u)break t;u--,d+=i[a++]<_e)d>>>=ge,h-=ge,n.lens[n.have++]=_e;else{if(16===_e){for(Se=ge+2;Se>h;){if(0===u)break t;u--,d+=i[a++]<>>=ge,h-=ge,0===n.have){t.msg="invalid bit length repeat",n.mode=le;break}Ee=n.lens[n.have-1],g=3+(3&d),d>>>=2,h-=2}else if(17===_e){for(Se=ge+3;Se>h;){if(0===u)break t;u--,d+=i[a++]<>>=ge,h-=ge,Ee=0,g=3+(7&d),d>>>=3,h-=3}else{for(Se=ge+7;Se>h;){if(0===u)break t;u--,d+=i[a++]<>>=ge,h-=ge,Ee=0,g=11+(127&d),d>>>=7,h-=7}if(n.have+g>n.nlen+n.ndist){t.msg="invalid bit length repeat",n.mode=le;break}for(;g--;)n.lens[n.have++]=Ee}}if(n.mode===le)break;if(0===n.lens[256]){t.msg="invalid code -- missing end-of-block",n.mode=le;break}if(n.lenbits=9,ke={bits:n.lenbits},xe=w(x,n.lens,0,n.nlen,n.lencode,0,n.work,ke),n.lenbits=ke.bits,xe){t.msg="invalid literal/lengths set",n.mode=le;break}if(n.distbits=6,n.distcode=n.distdyn,ke={bits:n.distbits},xe=w(k,n.lens,n.nlen,n.ndist,n.distcode,0,n.work,ke),n.distbits=ke.bits,xe){t.msg="invalid distances set",n.mode=le;break}if(n.mode=ee,e===O)break t;case ee:n.mode=ne;case ne:if(u>=6&&c>=258){t.next_out=s,t.avail_out=c,t.next_in=a,t.avail_in=u,n.hold=d,n.bits=h,b(t,m),s=t.next_out,o=t.output,c=t.avail_out,a=t.next_in,i=t.input,u=t.avail_in,d=n.hold,h=n.bits,n.mode===W&&(n.back=-1);break}for(n.back=0;Ae=n.lencode[d&(1<>>24,ve=255&Ae>>>16,_e=65535&Ae,!(h>=ge);){if(0===u)break t;u--,d+=i[a++]<>ye)],ge=Ae>>>24,ve=255&Ae>>>16,_e=65535&Ae,!(h>=ye+ge);){if(0===u)break t;u--,d+=i[a++]<>>=ye,h-=ye,n.back+=ye}if(d>>>=ge,h-=ge,n.back+=ge,n.length=_e,0===ve){n.mode=se;break}if(32&ve){n.back=-1,n.mode=W;break}if(64&ve){t.msg="invalid literal/length code",n.mode=le;break}n.extra=15&ve,n.mode=re;case re:if(n.extra){for(Se=n.extra;Se>h;){if(0===u)break t;u--,d+=i[a++]<>>=n.extra,h-=n.extra,n.back+=n.extra}n.was=n.length,n.mode=ie;case ie:for(;Ae=n.distcode[d&(1<>>24,ve=255&Ae>>>16,_e=65535&Ae,!(h>=ge);){if(0===u)break t;u--,d+=i[a++]<>ye)],ge=Ae>>>24,ve=255&Ae>>>16,_e=65535&Ae,!(h>=ye+ge);){if(0===u)break t;u--,d+=i[a++]<>>=ye,h-=ye,n.back+=ye}if(d>>>=ge,h-=ge,n.back+=ge,64&ve){t.msg="invalid distance code",n.mode=le;break}n.offset=_e,n.extra=15&ve,n.mode=oe;case oe:if(n.extra){for(Se=n.extra;Se>h;){if(0===u)break t;u--,d+=i[a++]<>>=n.extra,h-=n.extra,n.back+=n.extra}if(n.offset>n.dmax){t.msg="invalid distance too far back",n.mode=le;break}n.mode=ae;case ae:if(0===c)break t;if(g=m-c,n.offset>g){if(g=n.offset-g,g>n.whave&&n.sane){t.msg="invalid distance too far back",n.mode=le;break}g>n.wnext?(g-=n.wnext,pe=n.wsize-g):pe=n.wnext-g,g>n.length&&(g=n.length),me=n.window}else me=o,pe=s-n.offset,g=n.length;g>c&&(g=c),c-=g,n.length-=g;do o[s++]=me[pe++];while(--g);0===n.length&&(n.mode=ne);break;case se:if(0===c)break t;o[s++]=n.length,c--,n.mode=ne;break;case ue:if(n.wrap){for(;32>h;){if(0===u)break t;u--,d|=i[a++]<h;){if(0===u)break t;u--,d+=i[a++]<n.mode&&(ue>n.mode||e!==S))&&l(t,t.output,t.next_out,m-t.avail_out)?(n.mode=de,D):(p-=t.avail_in,m-=t.avail_out,t.total_in+=p,t.total_out+=m,n.total+=m,n.wrap&&m&&(t.adler=n.check=n.flags?y(n.check,o,m,t.next_out-m):_(n.check,o,m,t.next_out-m)),t.data_type=n.bits+(n.last?64:0)+(n.mode===W?128:0)+(n.mode===ee||n.mode===J?256:0),(0===p&&0===m||e===S)&&xe===I&&(xe=z),xe)}function h(t){if(!t||!t.state)return C;var e=t.state;return e.window&&(e.window=null),t.state=null,I}function p(t,e){var n;return t&&t.state?(n=t.state,0===(2&n.wrap)?C:(n.head=e,e.done=!1,I)):C}var m,g,v=t("../utils/common"),_=t("./adler32"),y=t("./crc32"),b=t("./inffast"),w=t("./inftrees"),E=0,x=1,k=2,S=4,A=5,O=6,I=0,T=1,R=2,C=-2,N=-3,D=-4,z=-5,L=8,j=1,B=2,F=3,M=4,P=5,U=6,V=7,Z=8,Y=9,X=10,H=11,W=12,q=13,K=14,J=15,G=16,Q=17,$=18,te=19,ee=20,ne=21,re=22,ie=23,oe=24,ae=25,se=26,ue=27,ce=28,fe=29,le=30,de=31,he=32,pe=852,me=592,ge=15,ve=ge,_e=!0;n.inflateReset=a,n.inflateReset2=s,n.inflateResetKeep=o,n.inflateInit=c,n.inflateInit2=u,n.inflate=d,n.inflateEnd=h,n.inflateGetHeader=p,n.inflateInfo="pako inflate (from Nodeca project)"},{"../utils/common":28,"./adler32":30,"./crc32":32,"./inffast":35,"./inftrees":37}],37:[function(t,e){"use strict";var n=t("../utils/common"),r=15,i=852,o=592,a=0,s=1,u=2,c=[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,0,0],f=[16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78],l=[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,0,0],d=[16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64];e.exports=function(t,e,h,p,m,g,v,_){var y,b,w,E,x,k,S,A,O,I=_.bits,T=0,R=0,C=0,N=0,D=0,z=0,L=0,j=0,B=0,F=0,M=null,P=0,U=new n.Buf16(r+1),V=new n.Buf16(r+1),Z=null,Y=0;for(T=0;r>=T;T++)U[T]=0;for(R=0;p>R;R++)U[e[h+R]]++;for(D=I,N=r;N>=1&&0===U[N];N--);if(D>N&&(D=N),0===N)return m[g++]=20971520,m[g++]=20971520,_.bits=1,0;for(C=1;N>C&&0===U[C];C++);for(C>D&&(D=C),j=1,T=1;r>=T;T++)if(j<<=1,j-=U[T],0>j)return-1;if(j>0&&(t===a||1!==N))return-1;for(V[1]=0,T=1;r>T;T++)V[T+1]=V[T]+U[T];for(R=0;p>R;R++)0!==e[h+R]&&(v[V[e[h+R]]++]=R);switch(t){case a:M=Z=v,k=19;break;case s:M=c,P-=257,Z=f,Y-=257,k=256;break;default:M=l,Z=d,k=-1}if(F=0,R=0,T=C,x=g,z=D,L=0,w=-1,B=1<i||t===u&&B>o)return 1;for(var X=0;;){X++,S=T-L,k>v[R]?(A=0,O=v[R]):v[R]>k?(A=Z[Y+v[R]],O=M[P+v[R]]):(A=96,O=0),y=1<>L)+b]=0|(S<<24|A<<16|O);while(0!==b);for(y=1<>=1;if(0!==y?(F&=y-1,F+=y):F=0,R++,0===--U[T]){if(T===N)break;T=e[h+v[R]]}if(T>D&&(F&E)!==w){for(0===L&&(L=D),x+=C,z=T-L,j=1<z+L&&(j-=U[z+L],!(0>=j));)z++,j<<=1;if(B+=1<i||t===u&&B>o)return 1;w=F&E,m[w]=0|(D<<24|z<<16|x-g)}}return 0!==F&&(m[x+F]=0|(T-L<<24|64<<16)),_.bits=D,0}},{"../utils/common":28}],38:[function(t,e){"use strict";e.exports={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"}},{}],39:[function(t,e,n){"use strict";function r(t){for(var e=t.length;--e>=0;)t[e]=0}function i(t){return 256>t?ae[t]:ae[256+(t>>>7)]}function o(t,e){t.pending_buf[t.pending++]=255&e,t.pending_buf[t.pending++]=255&e>>>8}function a(t,e,n){t.bi_valid>W-n?(t.bi_buf|=65535&e<>W-t.bi_valid,t.bi_valid+=n-W):(t.bi_buf|=65535&e<>>=1,n<<=1;while(--e>0);return n>>>1}function c(t){16===t.bi_valid?(o(t,t.bi_buf),t.bi_buf=0,t.bi_valid=0):t.bi_valid>=8&&(t.pending_buf[t.pending++]=255&t.bi_buf,t.bi_buf>>=8,t.bi_valid-=8)}function f(t,e){var n,r,i,o,a,s,u=e.dyn_tree,c=e.max_code,f=e.stat_desc.static_tree,l=e.stat_desc.has_stree,d=e.stat_desc.extra_bits,h=e.stat_desc.extra_base,p=e.stat_desc.max_length,m=0;for(o=0;H>=o;o++)t.bl_count[o]=0;for(u[2*t.heap[t.heap_max]+1]=0,n=t.heap_max+1;X>n;n++)r=t.heap[n],o=u[2*u[2*r+1]+1]+1,o>p&&(o=p,m++),u[2*r+1]=o,r>c||(t.bl_count[o]++,a=0,r>=h&&(a=d[r-h]),s=u[2*r],t.opt_len+=s*(o+a),l&&(t.static_len+=s*(f[2*r+1]+a)));if(0!==m){do{for(o=p-1;0===t.bl_count[o];)o--;t.bl_count[o]--,t.bl_count[o+1]+=2,t.bl_count[p]--,m-=2}while(m>0);for(o=p;0!==o;o--)for(r=t.bl_count[o];0!==r;)i=t.heap[--n],i>c||(u[2*i+1]!==o&&(t.opt_len+=(o-u[2*i+1])*u[2*i],u[2*i+1]=o),r--)}}function l(t,e,n){var r,i,o=Array(H+1),a=0;for(r=1;H>=r;r++)o[r]=a=a+n[r-1]<<1;for(i=0;e>=i;i++){var s=t[2*i+1];0!==s&&(t[2*i]=u(o[s]++,s))}}function d(){var t,e,n,r,i,o=Array(H+1);for(n=0,r=0;P-1>r;r++)for(ue[r]=n,t=0;1<<$[r]>t;t++)se[n++]=r;for(se[n-1]=r,i=0,r=0;16>r;r++)for(ce[r]=i,t=0;1<t;t++)ae[i++]=r;for(i>>=7;Z>r;r++)for(ce[r]=i<<7,t=0;1<t;t++)ae[256+i++]=r;for(e=0;H>=e;e++)o[e]=0;for(t=0;143>=t;)ie[2*t+1]=8,t++,o[8]++;for(;255>=t;)ie[2*t+1]=9,t++,o[9]++;for(;279>=t;)ie[2*t+1]=7,t++,o[7]++;for(;287>=t;)ie[2*t+1]=8,t++,o[8]++;for(l(ie,V+1,o),t=0;Z>t;t++)oe[2*t+1]=5,oe[2*t]=u(t,5);fe=new he(ie,$,U+1,V,H),le=new he(oe,te,0,Z,H),de=new he(Array(0),ee,0,Y,q)}function h(t){var e;for(e=0;V>e;e++)t.dyn_ltree[2*e]=0;for(e=0;Z>e;e++)t.dyn_dtree[2*e]=0;for(e=0;Y>e;e++)t.bl_tree[2*e]=0;t.dyn_ltree[2*K]=1,t.opt_len=t.static_len=0,t.last_lit=t.matches=0}function p(t){t.bi_valid>8?o(t,t.bi_buf):t.bi_valid>0&&(t.pending_buf[t.pending++]=t.bi_buf),t.bi_buf=0,t.bi_valid=0}function m(t,e,n,r){p(t),r&&(o(t,n),o(t,~n)),R.arraySet(t.pending_buf,t.window,e,n,t.pending),t.pending+=n}function g(t,e,n,r){var i=2*e,o=2*n;return t[i]=i&&(t.heap_len>i&&g(e,t.heap[i+1],t.heap[i],t.depth)&&i++,!g(e,r,t.heap[i],t.depth));)t.heap[n]=t.heap[i],n=i,i<<=1;t.heap[n]=r}function _(t,e,n){var r,o,u,c,f=0;if(0!==t.last_lit)do r=t.pending_buf[t.d_buf+2*f]<<8|t.pending_buf[t.d_buf+2*f+1],o=t.pending_buf[t.l_buf+f],f++,0===r?s(t,o,e):(u=se[o],s(t,u+U+1,e),c=$[u],0!==c&&(o-=ue[u],a(t,o,c)),r--,u=i(r),s(t,u,n),c=te[u],0!==c&&(r-=ce[u],a(t,r,c)));while(t.last_lit>f);s(t,K,e)}function y(t,e){var n,r,i,o=e.dyn_tree,a=e.stat_desc.static_tree,s=e.stat_desc.has_stree,u=e.stat_desc.elems,c=-1;for(t.heap_len=0,t.heap_max=X,n=0;u>n;n++)0!==o[2*n]?(t.heap[++t.heap_len]=c=n,t.depth[n]=0):o[2*n+1]=0;for(;2>t.heap_len;)i=t.heap[++t.heap_len]=2>c?++c:0,o[2*i]=1,t.depth[i]=0,t.opt_len--,s&&(t.static_len-=a[2*i+1]);for(e.max_code=c,n=t.heap_len>>1;n>=1;n--)v(t,o,n);i=u;do n=t.heap[1],t.heap[1]=t.heap[t.heap_len--],v(t,o,1),r=t.heap[1],t.heap[--t.heap_max]=n,t.heap[--t.heap_max]=r,o[2*i]=o[2*n]+o[2*r],t.depth[i]=(t.depth[n]>=t.depth[r]?t.depth[n]:t.depth[r])+1,o[2*n+1]=o[2*r+1]=i,t.heap[1]=i++,v(t,o,1);while(t.heap_len>=2);t.heap[--t.heap_max]=t.heap[1],f(t,e),l(o,c,t.bl_count)}function b(t,e,n){var r,i,o=-1,a=e[1],s=0,u=7,c=4;for(0===a&&(u=138,c=3),e[2*(n+1)+1]=65535,r=0;n>=r;r++)i=a,a=e[2*(r+1)+1],u>++s&&i===a||(c>s?t.bl_tree[2*i]+=s:0!==i?(i!==o&&t.bl_tree[2*i]++,t.bl_tree[2*J]++):10>=s?t.bl_tree[2*G]++:t.bl_tree[2*Q]++,s=0,o=i,0===a?(u=138,c=3):i===a?(u=6,c=3):(u=7,c=4))}function w(t,e,n){var r,i,o=-1,u=e[1],c=0,f=7,l=4;for(0===u&&(f=138,l=3),r=0;n>=r;r++)if(i=u,u=e[2*(r+1)+1],!(f>++c&&i===u)){if(l>c){do s(t,i,t.bl_tree);while(0!==--c)}else 0!==i?(i!==o&&(s(t,i,t.bl_tree),c--),s(t,J,t.bl_tree),a(t,c-3,2)):10>=c?(s(t,G,t.bl_tree),a(t,c-3,3)):(s(t,Q,t.bl_tree),a(t,c-11,7));c=0,o=i,0===u?(f=138,l=3):i===u?(f=6,l=3):(f=7,l=4)}}function E(t){var e;for(b(t,t.dyn_ltree,t.l_desc.max_code),b(t,t.dyn_dtree,t.d_desc.max_code),y(t,t.bl_desc),e=Y-1;e>=3&&0===t.bl_tree[2*ne[e]+1];e--);return t.opt_len+=3*(e+1)+5+5+4,e}function x(t,e,n,r){var i;for(a(t,e-257,5),a(t,n-1,5),a(t,r-4,4),i=0;r>i;i++)a(t,t.bl_tree[2*ne[i]+1],3);w(t,t.dyn_ltree,e-1),w(t,t.dyn_dtree,n-1)}function k(t){var e,n=4093624447;for(e=0;31>=e;e++,n>>>=1)if(1&n&&0!==t.dyn_ltree[2*e])return N;if(0!==t.dyn_ltree[18]||0!==t.dyn_ltree[20]||0!==t.dyn_ltree[26])return D;for(e=32;U>e;e++)if(0!==t.dyn_ltree[2*e])return D;return N}function S(t){me||(d(),me=!0),t.l_desc=new pe(t.dyn_ltree,fe),t.d_desc=new pe(t.dyn_dtree,le),t.bl_desc=new pe(t.bl_tree,de),t.bi_buf=0,t.bi_valid=0,h(t)}function A(t,e,n,r){a(t,(L<<1)+(r?1:0),3),m(t,e,n,!0)}function O(t){a(t,j<<1,3),s(t,K,ie),c(t)}function I(t,e,n,r){var i,o,s=0;t.level>0?(t.strm.data_type===z&&(t.strm.data_type=k(t)),y(t,t.l_desc),y(t,t.d_desc),s=E(t),i=t.opt_len+3+7>>>3,o=t.static_len+3+7>>>3,i>=o&&(i=o)):i=o=n+5,i>=n+4&&-1!==e?A(t,e,n,r):t.strategy===C||o===i?(a(t,(j<<1)+(r?1:0),3),_(t,ie,oe)):(a(t,(B<<1)+(r?1:0),3),x(t,t.l_desc.max_code+1,t.d_desc.max_code+1,s+1),_(t,t.dyn_ltree,t.dyn_dtree)),h(t),r&&p(t)}function T(t,e,n){return t.pending_buf[t.d_buf+2*t.last_lit]=255&e>>>8,t.pending_buf[t.d_buf+2*t.last_lit+1]=255&e,t.pending_buf[t.l_buf+t.last_lit]=255&n,t.last_lit++,0===e?t.dyn_ltree[2*n]++:(t.matches++,e--,t.dyn_ltree[2*(se[n]+U+1)]++,t.dyn_dtree[2*i(e)]++),t.last_lit===t.lit_bufsize-1}var R=t("../utils/common"),C=4,N=0,D=1,z=2,L=0,j=1,B=2,F=3,M=258,P=29,U=256,V=U+1+P,Z=30,Y=19,X=2*V+1,H=15,W=16,q=7,K=256,J=16,G=17,Q=18,$=[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],te=[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],ee=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],ne=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],re=512,ie=Array(2*(V+2));r(ie);var oe=Array(2*Z);r(oe);var ae=Array(re);r(ae);var se=Array(M-F+1);r(se);var ue=Array(P);r(ue);var ce=Array(Z);r(ce);var fe,le,de,he=function(t,e,n,r,i){this.static_tree=t,this.extra_bits=e,this.extra_base=n,this.elems=r,this.max_length=i,this.has_stree=t&&t.length},pe=function(t,e){this.dyn_tree=t,this.max_code=0,this.stat_desc=e},me=!1;n._tr_init=S,n._tr_stored_block=A,n._tr_flush_block=I,n._tr_tally=T,n._tr_align=O},{"../utils/common":28}],40:[function(t,e){"use strict";function n(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}e.exports=n},{}],41:[function(t,e){var n="READ",r="WRITE",i="CREATE",o="EXCLUSIVE",a="TRUNCATE",s="APPEND",u="CREATE",c="REPLACE";e.exports={FILE_SYSTEM_NAME:"local",FILE_STORE_NAME:"files",IDB_RO:"readonly",IDB_RW:"readwrite",WSQL_VERSION:"1",WSQL_SIZE:5242880,WSQL_DESC:"FileSystem Storage",MODE_FILE:"FILE",MODE_DIRECTORY:"DIRECTORY",MODE_SYMBOLIC_LINK:"SYMLINK",MODE_META:"META",SYMLOOP_MAX:10,BINARY_MIME_TYPE:"application/octet-stream",JSON_MIME_TYPE:"application/json",ROOT_DIRECTORY_NAME:"/",FS_FORMAT:"FORMAT",FS_NOCTIME:"NOCTIME",FS_NOMTIME:"NOMTIME",O_READ:n,O_WRITE:r,O_CREATE:i,O_EXCLUSIVE:o,O_TRUNCATE:a,O_APPEND:s,O_FLAGS:{r:[n],"r+":[n,r],w:[r,i,a],"w+":[r,n,i,a],wx:[r,i,o,a],"wx+":[r,n,i,o,a],a:[r,i,s],"a+":[r,n,i,s],ax:[r,i,o,s],"ax+":[r,n,i,o,s]},XATTR_CREATE:u,XATTR_REPLACE:c,FS_READY:"READY",FS_PENDING:"PENDING",FS_ERROR:"ERROR",SUPER_NODE_ID:"00000000-0000-0000-0000-000000000000",STDIN:0,STDOUT:1,STDERR:2,FIRST_DESCRIPTOR:3,ENVIRONMENT:{TMP:"/tmp",PATH:""}}},{}],42:[function(t,e){var n=t("./constants.js").MODE_FILE;e.exports=function(t,e){this.id=t,this.type=e||n}},{"./constants.js":41}],43:[function(t,e){(function(t){function n(t){return t.toString("utf8")}function r(e){return new t(e,"utf8")}e.exports={encode:r,decode:n}}).call(this,t("buffer").Buffer)},{}],44:[function(t,e){var n={};["-1:UNKNOWN:unknown error","0:OK:success","1:EOF:end of file","2:EADDRINFO:getaddrinfo error","3:EACCES:permission denied","4:EAGAIN:resource temporarily unavailable","5:EADDRINUSE:address already in use","6:EADDRNOTAVAIL:address not available","7:EAFNOSUPPORT:address family not supported","8:EALREADY:connection already in progress","9:EBADF:bad file descriptor","10:EBUSY:resource busy or locked","11:ECONNABORTED:software caused connection abort","12:ECONNREFUSED:connection refused","13:ECONNRESET:connection reset by peer","14:EDESTADDRREQ:destination address required","15:EFAULT:bad address in system call argument","16:EHOSTUNREACH:host is unreachable","17:EINTR:interrupted system call","18:EINVAL:invalid argument","19:EISCONN:socket is already connected","20:EMFILE:too many open files","21:EMSGSIZE:message too long","22:ENETDOWN:network is down","23:ENETUNREACH:network is unreachable","24:ENFILE:file table overflow","25:ENOBUFS:no buffer space available","26:ENOMEM:not enough memory","27:ENOTDIR:not a directory","28:EISDIR:illegal operation on a directory","29:ENONET:machine is not on the network","31:ENOTCONN:socket is not connected","32:ENOTSOCK:socket operation on non-socket","33:ENOTSUP:operation not supported on socket","34:ENOENT:no such file or directory","35:ENOSYS:function not implemented","36:EPIPE:broken pipe","37:EPROTO:protocol error","38:EPROTONOSUPPORT:protocol not supported","39:EPROTOTYPE:protocol wrong type for socket","40:ETIMEDOUT:connection timed out","41:ECHARSET:invalid Unicode character","42:EAIFAMNOSUPPORT:address family for hostname not supported","44:EAISERVICE:servname not supported for ai_socktype","45:EAISOCKTYPE:ai_socktype not supported","46:ESHUTDOWN:cannot send after transport endpoint shutdown","47:EEXIST:file already exists","48:ESRCH:no such process","49:ENAMETOOLONG:name too long","50:EPERM:operation not permitted","51:ELOOP:too many symbolic links encountered","52:EXDEV:cross-device link not permitted","53:ENOTEMPTY:directory not empty","54:ENOSPC:no space left on device","55:EIO:i/o error","56:EROFS:read-only file system","57:ENODEV:no such device","58:ESPIPE:invalid seek","59:ECANCELED:operation canceled","1000:ENOTMOUNTED:not mounted","1001:EFILESYSTEMERROR:missing super node, use 'FORMAT' flag to format filesystem.","1002:ENOATTR:attribute does not exist"].forEach(function(t){function e(t){this.message=t||o +}t=t.split(":");var r=t[0],i=t[1],o=t[2],a=e.prototype=Error();a.errno=r,a.code=i,a.constructor=e,n[i]=n[r]=e}),e.exports=n},{}],45:[function(t,e){(function(n){function r(t){return function(e,n){e?t(e):t(null,n)}}function i(t,e,n,r,i){function o(n){t.changes.push({event:"change",path:e}),i(n)}var a=t.flags;he(a).contains(Be)&&delete r.ctime,he(a).contains(je)&&delete r.mtime;var s=!1;r.ctime&&(n.ctime=r.ctime,n.atime=r.ctime,s=!0),r.atime&&(n.atime=r.atime,s=!0),r.mtime&&(n.mtime=r.mtime,s=!0),s?t.put(n.id,n,o):o()}function o(t,e,n,r){function o(n,i){n?r(n):i.mode!==Ee?r(new Me.ENOTDIR("a component of the path prefix is not a directory")):(l=i,a(t,e,s))}function s(e,n){!e&&n?r(new Me.EEXIST("path name already exists")):!e||e instanceof Me.ENOENT?t.get(l.data,u):r(e)}function u(e,i){e?r(e):(d=i,h=new Ze(void 0,n),h.nlinks+=1,t.put(h.id,h,f))}function c(e){if(e)r(e);else{var n=Date.now();i(t,m,h,{mtime:n,ctime:n},r)}}function f(e){e?r(e):(d[p]=new Pe(h.id,n),t.put(l.data,d,c))}if(n!==Ee&&n!==we)return r(new Me.EINVAL("mode must be a directory or file"));e=me(e);var l,d,h,p=ve(e),m=ge(e);a(t,m,o)}function a(t,e,n){function r(e,r){e?n(e):r&&r.mode===ke&&r.rnode?t.get(r.rnode,i):n(new Me.EFILESYSTEMERROR)}function i(t,e){t?n(t):e?n(null,e):n(new Me.ENOENT)}function o(e,r){e?n(e):r.mode===Ee&&r.data?t.get(r.data,s):n(new Me.ENOTDIR("a component of the path prefix is not a directory"))}function s(e,r){if(e)n(e);else if(he(r).has(f)){var i=r[f].id;t.get(i,u)}else n(new Me.ENOENT)}function u(t,e){t?n(t):e.mode==xe?(d++,d>Oe?n(new Me.ELOOP):c(e.data)):n(null,e)}function c(e){e=me(e),l=ge(e),f=ve(e),Se==f?t.get(Ae,r):a(t,l,o)}if(e=me(e),!e)return n(new Me.ENOENT("path is an empty string"));var f=ve(e),l=ge(e),d=0;Se==f?t.get(Ae,r):a(t,l,o)}function s(t,e,n,r,o,s){function u(e,a){function u(e){e?s(e):i(t,c,a,{ctime:Date.now()},s)}a?a.xattrs[n]:null,e?s(e):o===ze&&a.xattrs.hasOwnProperty(n)?s(new Me.EEXIST("attribute already exists")):o!==Le||a.xattrs.hasOwnProperty(n)?(a.xattrs[n]=r,t.put(a.id,a,u)):s(new Me.ENOATTR)}var c;"string"==typeof e?(c=e,a(t,e,u)):"object"==typeof e&&"string"==typeof e.id?(c=e.path,t.get(e.id,u)):s(new Me.EINVAL("path or file descriptor of wrong type"))}function u(t,e){function n(n,i){!n&&i?e(new Me.EEXIST):!n||n instanceof Me.ENOENT?(o=new Ve,t.put(o.id,o,r)):e(n)}function r(n){n?e(n):(a=new Ze(o.rnode,Ee),a.nlinks+=1,t.put(a.id,a,i))}function i(n){n?e(n):(s={},t.put(a.data,s,e))}var o,a,s;t.get(Ae,n)}function c(t,e,n){function r(e,r){!e&&r?n(new Me.EEXIST):!e||e instanceof Me.ENOENT?a(t,g,o):n(e)}function o(e,r){e?n(e):(h=r,t.get(h.data,s))}function s(e,r){e?n(e):(p=r,l=new Ze(void 0,Ee),l.nlinks+=1,t.put(l.id,l,u))}function u(e){e?n(e):(d={},t.put(l.data,d,f))}function c(e){if(e)n(e);else{var r=Date.now();i(t,g,h,{mtime:r,ctime:r},n)}}function f(e){e?n(e):(p[m]=new Pe(l.id,Ee),t.put(h.data,p,c))}e=me(e);var l,d,h,p,m=ve(e),g=ge(e);a(t,e,r)}function f(t,e,n){function r(e,r){e?n(e):(m=r,t.get(m.data,o))}function o(e,r){e?n(e):Se==v?n(new Me.EBUSY):he(r).has(v)?(g=r,h=g[v].id,t.get(h,s)):n(new Me.ENOENT)}function s(e,r){e?n(e):r.mode!=Ee?n(new Me.ENOTDIR):(h=r,t.get(h.data,u))}function u(t,e){t?n(t):(p=e,he(p).size()>0?n(new Me.ENOTEMPTY):f())}function c(e){if(e)n(e);else{var r=Date.now();i(t,_,m,{mtime:r,ctime:r},l)}}function f(){delete g[v],t.put(m.data,g,c)}function l(e){e?n(e):t.delete(h.id,d)}function d(e){e?n(e):t.delete(h.data,n)}e=me(e);var h,p,m,g,v=ve(e),_=ge(e);a(t,_,r)}function l(t,e,r,o){function s(e,n){e?o(e):(v=n,t.get(v.data,u))}function u(e,n){e?o(e):(_=n,he(_).has(E)?he(r).contains(Ce)?o(new Me.ENOENT("O_CREATE and O_EXCLUSIVE are set, and the named file exists")):(y=_[E],y.type==Ee&&he(r).contains(Te)?o(new Me.EISDIR("the named file is a directory and O_WRITE is set")):t.get(y.id,c)):he(r).contains(Re)?d():o(new Me.ENOENT("O_CREATE is not set and the named file does not exist")))}function c(t,e){if(t)o(t);else{var n=e;n.mode==xe?(k++,k>Oe?o(new Me.ELOOP):f(n.data)):l(void 0,n)}}function f(n){n=me(n),x=ge(n),E=ve(n),Se==E&&(he(r).contains(Te)?o(new Me.EISDIR("the named file is a directory and O_WRITE is set")):a(t,e,l)),a(t,x,s)}function l(t,e){t?o(t):(b=e,o(null,b))}function d(){b=new Ze(void 0,we),b.nlinks+=1,t.put(b.id,b,h)}function h(e){e?o(e):(w=new n(0),w.fill(0),t.put(b.data,w,m))}function p(e){if(e)o(e);else{var n=Date.now();i(t,x,v,{mtime:n,ctime:n},g)}}function m(e){e?o(e):(_[E]=new Pe(b.id,we),t.put(v.data,_,p))}function g(t){t?o(t):o(null,b)}e=me(e);var v,_,y,b,w,E=ve(e),x=ge(e),k=0;Se==E?he(r).contains(Te)?o(new Me.EISDIR("the named file is a directory and O_WRITE is set")):a(t,e,l):a(t,x,s)}function d(t,e,r,o,a,s){function u(t){t?s(t):s(null,a)}function c(n){if(n)s(n);else{var r=Date.now();i(t,e.path,d,{mtime:r,ctime:r},u)}}function f(e){e?s(e):t.put(d.id,d,c)}function l(i,u){if(i)s(i);else{d=u;var c=new n(a);c.fill(0),r.copy(c,0,o,o+a),e.position=a,d.size=a,d.version+=1,t.put(d.data,c,f)}}var d;t.get(e.id,l)}function h(t,e,r,o,a,s,u){function c(t){t?u(t):u(null,a)}function f(n){if(n)u(n);else{var r=Date.now();i(t,e.path,p,{mtime:r,ctime:r},c)}}function l(e){e?u(e):t.put(p.id,p,f)}function d(i,c){if(i)u(i);else{m=c;var f=void 0!==s&&null!==s?s:e.position,d=Math.max(m.length,f+a),h=new n(d);h.fill(0),m&&m.copy(h),r.copy(h,f,o,o+a),void 0===s&&(e.position+=a),p.size=d,p.version+=1,t.put(p.data,h,l)}}function h(e,n){e?u(e):(p=n,t.get(p.data,d))}var p,m;t.get(e.id,h)}function p(t,e,n,r,i,o,a){function s(t,s){if(t)a(t);else{f=s;var u=void 0!==o&&null!==o?o:e.position;i=u+i>n.length?i-u:i,f.copy(n,r,u,u+i),void 0===o&&(e.position+=i),a(null,i)}}function u(e,n){e?a(e):(c=n,t.get(c.data,s))}var c,f;t.get(e.id,u)}function m(t,e,n){e=me(e),ve(e),a(t,e,r(n))}function g(t,e,n){t.get(e.id,r(n))}function v(t,e,n){function i(e,r){e?n(e):(s=r,t.get(s.data,o))}function o(e,i){e?n(e):(u=i,he(u).has(c)?t.get(u[c].id,r(n)):n(new Me.ENOENT("a component of the path does not name an existing file")))}e=me(e);var s,u,c=ve(e),f=ge(e);Se==c?a(t,e,r(n)):a(t,f,i)}function _(t,e,n,r){function o(e){e?r(e):i(t,n,y,{ctime:Date.now()},r)}function s(e,n){e?r(e):(y=n,y.nlinks+=1,t.put(y.id,y,o))}function u(e){e?r(e):t.get(_[b].id,s)}function c(e,n){e?r(e):(_=n,he(_).has(b)?r(new Me.EEXIST("newpath resolves to an existing file")):(_[b]=g[h],t.put(v.data,_,u)))}function f(e,n){e?r(e):(v=n,t.get(v.data,c))}function l(e,n){e?r(e):(g=n,he(g).has(h)?a(t,w,f):r(new Me.ENOENT("a component of either path prefix does not exist")))}function d(e,n){e?r(e):(m=n,t.get(m.data,l))}e=me(e);var h=ve(e),p=ge(e);n=me(n);var m,g,v,_,y,b=ve(n),w=ge(n);a(t,p,d)}function y(t,e,n){function r(e){e?n(e):(delete l[h],t.put(f.data,l,function(){var e=Date.now();i(t,p,f,{mtime:e,ctime:e},n)}))}function o(e){e?n(e):t.delete(d.data,r)}function s(a,s){a?n(a):(d=s,d.nlinks-=1,1>d.nlinks?t.delete(d.id,o):t.put(d.id,d,function(){i(t,e,d,{ctime:Date.now()},r)}))}function u(e,r){e?n(e):(l=r,he(l).has(h)?t.get(l[h].id,s):n(new Me.ENOENT("a component of the path does not name an existing file")))}function c(e,r){e?n(e):(f=r,t.get(f.data,u))}e=me(e);var f,l,d,h=ve(e),p=ge(e);a(t,p,c)}function b(t,e,n){function r(t,e){if(t)n(t);else{s=e;var r=Object.keys(s);n(null,r)}}function i(e,i){e?n(e):(o=i,t.get(o.data,r))}e=me(e),ve(e);var o,s;a(t,e,i)}function w(t,e,n,r){function o(e,n){e?r(e):(l=n,t.get(l.data,s))}function s(t,e){t?r(t):(d=e,he(d).has(p)?r(new Me.EEXIST):u())}function u(){h=new Ze(void 0,xe),h.nlinks+=1,h.size=e.length,h.data=e,t.put(h.id,h,f)}function c(e){if(e)r(e);else{var n=Date.now();i(t,m,l,{mtime:n,ctime:n},r)}}function f(e){e?r(e):(d[p]=new Pe(h.id,xe),t.put(l.data,d,c))}n=me(n);var l,d,h,p=ve(n),m=ge(n);Se==p?r(new Me.EEXIST):a(t,m,o)}function E(t,e,n){function r(e,r){e?n(e):(s=r,t.get(s.data,i))}function i(e,r){e?n(e):(u=r,he(u).has(c)?t.get(u[c].id,o):n(new Me.ENOENT("a component of the path does not name an existing file")))}function o(t,e){t?n(t):e.mode!=xe?n(new Me.EINVAL("path not a symbolic link")):n(null,e.data)}e=me(e);var s,u,c=ve(e),f=ge(e);a(t,f,r)}function x(t,e,r,o){function s(e,n){e?o(e):n.mode==Ee?o(new Me.EISDIR):(l=n,t.get(l.data,u))}function u(e,i){if(e)o(e);else{var a=new n(r);a.fill(0),i&&i.copy(a),t.put(l.data,a,f)}}function c(n){if(n)o(n);else{var r=Date.now();i(t,e,l,{mtime:r,ctime:r},o)}}function f(e){e?o(e):(l.size=r,l.version+=1,t.put(l.id,l,c))}e=me(e);var l;0>r?o(new Me.EINVAL("length cannot be negative")):a(t,e,s)}function k(t,e,r,o){function a(e,n){e?o(e):n.mode==Ee?o(new Me.EISDIR):(f=n,t.get(f.data,s))}function s(e,i){if(e)o(e);else{var a;i?a=i.slice(0,r):(a=new n(r),a.fill(0)),t.put(f.data,a,c)}}function u(n){if(n)o(n);else{var r=Date.now();i(t,e.path,f,{mtime:r,ctime:r},o)}}function c(e){e?o(e):(f.size=r,f.version+=1,t.put(f.id,f,u))}var f;0>r?o(new Me.EINVAL("length cannot be negative")):t.get(e.id,a)}function S(t,e,n,r,o){function s(a,s){a?o(a):i(t,e,s,{atime:n,ctime:r,mtime:r},o)}e=me(e),"number"!=typeof n||"number"!=typeof r?o(new Me.EINVAL("atime and mtime must be number")):0>n||0>r?o(new Me.EINVAL("atime and mtime must be positive integers")):a(t,e,s)}function A(t,e,n,r,o){function a(a,s){a?o(a):i(t,e.path,s,{atime:n,ctime:r,mtime:r},o)}"number"!=typeof n||"number"!=typeof r?o(new Me.EINVAL("atime and mtime must be a number")):0>n||0>r?o(new Me.EINVAL("atime and mtime must be positive integers")):t.get(e.id,a)}function O(t,e,n,r,i,o){e=me(e),"string"!=typeof n?o(new Me.EINVAL("attribute name must be a string")):n?null!==i&&i!==ze&&i!==Le?o(new Me.EINVAL("invalid flag, must be null, XATTR_CREATE or XATTR_REPLACE")):s(t,e,n,r,i,o):o(new Me.EINVAL("attribute name cannot be an empty string"))}function I(t,e,n,r,i,o){"string"!=typeof n?o(new Me.EINVAL("attribute name must be a string")):n?null!==i&&i!==ze&&i!==Le?o(new Me.EINVAL("invalid flag, must be null, XATTR_CREATE or XATTR_REPLACE")):s(t,e,n,r,i,o):o(new Me.EINVAL("attribute name cannot be an empty string"))}function T(t,e,n,r){function i(t,e){e?e.xattrs[n]:null,t?r(t):e.xattrs.hasOwnProperty(n)?r(null,e.xattrs[n]):r(new Me.ENOATTR)}e=me(e),"string"!=typeof n?r(new Me.EINVAL("attribute name must be a string")):n?a(t,e,i):r(new Me.EINVAL("attribute name cannot be an empty string"))}function R(t,e,n,r){function i(t,e){e?e.xattrs[n]:null,t?r(t):e.xattrs.hasOwnProperty(n)?r(null,e.xattrs[n]):r(new Me.ENOATTR)}"string"!=typeof n?r(new Me.EINVAL):n?t.get(e.id,i):r(new Me.EINVAL("attribute name cannot be an empty string"))}function C(t,e,n,r){function o(o,a){function s(n){n?r(n):i(t,e,a,{ctime:Date.now()},r)}var u=a?a.xattrs:null;o?r(o):u.hasOwnProperty(n)?(delete a.xattrs[n],t.put(a.id,a,s)):r(new Me.ENOATTR)}e=me(e),"string"!=typeof n?r(new Me.EINVAL("attribute name must be a string")):n?a(t,e,o):r(new Me.EINVAL("attribute name cannot be an empty string"))}function N(t,e,n,r){function o(o,a){function s(n){n?r(n):i(t,e.path,a,{ctime:Date.now()},r)}o?r(o):a.xattrs.hasOwnProperty(n)?(delete a.xattrs[n],t.put(a.id,a,s)):r(new Me.ENOATTR)}"string"!=typeof n?r(new Me.EINVAL("attribute name must be a string")):n?t.get(e.id,o):r(new Me.EINVAL("attribute name cannot be an empty string"))}function D(t){return he(De).has(t)?De[t]:null}function z(t,e,n){return t?"function"==typeof t?t={encoding:e,flag:n}:"string"==typeof t&&(t={encoding:t,flag:n}):t={encoding:e,flag:n},t}function L(t,e){var n;return ye(t)?n=Error("Path must be a string without null bytes."):_e(t)||(n=Error("Path must be absolute.")),n?(e(n),!1):!0}function j(t,e,n,r,i,o){function a(e,i){if(e)o(e);else{var a;a=he(r).contains(Ne)?i.size:0;var s=new Ue(n,i.id,r,a),u=t.allocDescriptor(s);o(null,u)}}o=arguments[arguments.length-1],L(n,o)&&(r=D(r),r||o(new Me.EINVAL("flags is not valid")),l(e,n,r,a))}function B(t,e,n,r){he(t.openFiles).has(n)?(t.releaseDescriptor(n),r(null)):r(new Me.EBADF)}function F(t,e,n,r,i){L(n,i)&&o(e,n,r,i)}function M(t,e,n,i,o){o=arguments[arguments.length-1],L(n,o)&&c(e,n,r(o))}function P(t,e,n,i){L(n,i)&&f(e,n,r(i))}function U(t,e,n,r){function i(e,n){if(e)r(e);else{var i=new Ye(n,t.name);r(null,i)}}L(n,r)&&m(e,n,i)}function V(t,e,n,r){function i(e,n){if(e)r(e);else{var i=new Ye(n,t.name);r(null,i)}}var o=t.openFiles[n];o?g(e,o,i):r(new Me.EBADF)}function Z(t,e,n,i,o){L(n,o)&&L(i,o)&&_(e,n,i,r(o))}function Y(t,e,n,i){L(n,i)&&y(e,n,r(i))}function X(t,e,n,i,o,a,s,u){function c(t,e){u(t,e||0,i)}o=void 0===o?0:o,a=void 0===a?i.length-o:a,u=arguments[arguments.length-1];var f=t.openFiles[n];f?he(f.flags).contains(Ie)?p(e,f,i,o,a,s,r(c)):u(new Me.EBADF("descriptor does not permit reading")):u(new Me.EBADF)}function H(t,e,r,i,o){if(o=arguments[arguments.length-1],i=z(i,null,"r"),L(r,o)){var a=D(i.flag||"r");a||o(new Me.EINVAL("flags is not valid")),l(e,r,a,function(s,u){if(s)return o(s);var c=new Ue(r,u.id,a,0),f=t.allocDescriptor(c);g(e,c,function(r,a){if(r)return o(r);var s=new Ye(a,t.name),u=s.size,l=new n(u);l.fill(0),p(e,c,l,0,u,0,function(e){if(e)return o(e);t.releaseDescriptor(f);var n;n="utf8"===i.encoding?Fe.decode(l):l,o(null,n)})})})}}function W(t,e,n,i,o,a,s,u){u=arguments[arguments.length-1],o=void 0===o?0:o,a=void 0===a?i.length-o:a;var c=t.openFiles[n];c?he(c.flags).contains(Te)?a>i.length-o?u(new Me.EIO("intput buffer is too small")):h(e,c,i,o,a,s,r(u)):u(new Me.EBADF("descriptor does not permit writing")):u(new Me.EBADF)}function q(t,e,n,r,i,o){if(o=arguments[arguments.length-1],i=z(i,"utf8","w"),L(n,o)){var a=D(i.flag||"w");a||o(new Me.EINVAL("flags is not valid")),r=r||"","number"==typeof r&&(r=""+r),"string"==typeof r&&"utf8"===i.encoding&&(r=Fe.encode(r)),l(e,n,a,function(i,s){if(i)return o(i);var u=new Ue(n,s.id,a,0),c=t.allocDescriptor(u);d(e,u,r,0,r.length,function(e){return e?o(e):(t.releaseDescriptor(c),o(null),void 0)})})}}function K(t,e,n,r,i,o){if(o=arguments[arguments.length-1],i=z(i,"utf8","a"),L(n,o)){var a=D(i.flag||"a");a||o(new Me.EINVAL("flags is not valid")),r=r||"","number"==typeof r&&(r=""+r),"string"==typeof r&&"utf8"===i.encoding&&(r=Fe.encode(r)),l(e,n,a,function(i,s){if(i)return o(i);var u=new Ue(n,s.id,a,s.size),c=t.allocDescriptor(u);h(e,u,r,0,r.length,u.position,function(e){return e?o(e):(t.releaseDescriptor(c),o(null),void 0)})})}}function J(t,e,n,r){function i(t){r(t?!1:!0)}U(t,e,n,i)}function G(t,e,n,i,o){L(n,o)&&T(e,n,i,r(o))}function Q(t,e,n,i,o){var a=t.openFiles[n];a?R(e,a,i,r(o)):o(new Me.EBADF)}function $(t,e,n,i,o,a,s){"function"==typeof a&&(s=a,a=null),L(n,s)&&O(e,n,i,o,a,r(s))}function te(t,e,n,i,o,a,s){"function"==typeof a&&(s=a,a=null);var u=t.openFiles[n];u?he(u.flags).contains(Te)?I(e,u,i,o,a,r(s)):s(new Me.EBADF("descriptor does not permit writing")):s(new Me.EBADF)}function ee(t,e,n,i,o){L(n,o)&&C(e,n,i,r(o))}function ne(t,e,n,i,o){var a=t.openFiles[n];a?he(a.flags).contains(Te)?N(e,a,i,r(o)):o(new Me.EBADF("descriptor does not permit writing")):o(new Me.EBADF)}function re(t,e,n,r,i,o){function a(t,e){t?o(t):0>e.size+r?o(new Me.EINVAL("resulting file offset would be negative")):(s.position=e.size+r,o(null,s.position))}var s=t.openFiles[n];s||o(new Me.EBADF),"SET"===i?0>r?o(new Me.EINVAL("resulting file offset would be negative")):(s.position=r,o(null,s.position)):"CUR"===i?0>s.position+r?o(new Me.EINVAL("resulting file offset would be negative")):(s.position+=r,o(null,s.position)):"END"===i?g(e,s,a):o(new Me.EINVAL("whence argument is not a proper value"))}function ie(t,e,n,i){L(n,i)&&b(e,n,r(i))}function oe(t,e,n,i,o,a){if(L(n,a)){var s=Date.now();i=i?i:s,o=o?o:s,S(e,n,i,o,r(a))}}function ae(t,e,n,i,o,a){var s=Date.now();i=i?i:s,o=o?o:s;var u=t.openFiles[n];u?he(u.flags).contains(Te)?A(e,u,i,o,r(a)):a(new Me.EBADF("descriptor does not permit writing")):a(new Me.EBADF)}function se(t,e,n,i,o){function a(t){t?o(t):y(e,n,r(o))}L(n,o)&&L(i,o)&&_(e,n,i,a)}function ue(t,e,n,i,o,a){a=arguments[arguments.length-1],L(n,a)&&L(i,a)&&w(e,n,i,r(a))}function ce(t,e,n,i){L(n,i)&&E(e,n,r(i))}function fe(t,e,n,r){function i(e,n){if(e)r(e);else{var i=new Ye(n,t.name);r(null,i)}}L(n,r)&&v(e,n,i)}function le(t,e,n,i,o){o=arguments[arguments.length-1],i=i||0,L(n,o)&&x(e,n,i,r(o))}function de(t,e,n,i,o){o=arguments[arguments.length-1],i=i||0;var a=t.openFiles[n];a?he(a.flags).contains(Te)?k(e,a,i,r(o)):o(new Me.EBADF("descriptor does not permit writing")):o(new Me.EBADF)}var he=t("../../lib/nodash.js"),pe=t("../path.js"),me=pe.normalize,ge=pe.dirname,ve=pe.basename,_e=pe.isAbsolute,ye=pe.isNull,be=t("../constants.js"),we=be.MODE_FILE,Ee=be.MODE_DIRECTORY,xe=be.MODE_SYMBOLIC_LINK,ke=be.MODE_META,Se=be.ROOT_DIRECTORY_NAME,Ae=be.SUPER_NODE_ID,Oe=be.SYMLOOP_MAX,Ie=be.O_READ,Te=be.O_WRITE,Re=be.O_CREATE,Ce=be.O_EXCLUSIVE;be.O_TRUNCATE;var Ne=be.O_APPEND,De=be.O_FLAGS,ze=be.XATTR_CREATE,Le=be.XATTR_REPLACE,je=be.FS_NOMTIME,Be=be.FS_NOCTIME,Fe=t("../encoding.js"),Me=t("../errors.js"),Pe=t("../directory-entry.js"),Ue=t("../open-file-description.js"),Ve=t("../super-node.js"),Ze=t("../node.js"),Ye=t("../stats.js");e.exports={makeRootDirectory:u,open:j,close:B,mknod:F,mkdir:M,rmdir:P,unlink:Y,stat:U,fstat:V,link:Z,read:X,readFile:H,write:W,writeFile:q,appendFile:K,exists:J,getxattr:G,fgetxattr:Q,setxattr:$,fsetxattr:te,removexattr:ee,fremovexattr:ne,lseek:re,readdir:ie,utimes:oe,futimes:ae,rename:se,symlink:ue,readlink:ce,lstat:fe,truncate:le,ftruncate:de}}).call(this,t("buffer").Buffer)},{"../../lib/nodash.js":4,"../constants.js":41,"../directory-entry.js":42,"../encoding.js":43,"../errors.js":44,"../node.js":49,"../open-file-description.js":50,"../path.js":51,"../stats.js":60,"../super-node.js":61}],46:[function(t,e){function n(t){return"function"==typeof t?t:function(t){if(t)throw t}}function r(t,e){function n(){I.forEach(function(t){t.call(this)}.bind(S)),I=null}function r(t){if(t.length){var e=m.getInstance();t.forEach(function(t){e.emit(t.event,t.path)})}}t=t||{},e=e||a;var s=t.flags,p=t.provider||new h.Default(t.name||u),x=t.name||p.name,k=i(s).contains(c),S=this;S.readyState=l,S.name=x,S.error=null,S.stdin=_,S.stdout=y,S.stderr=b;var A={},O=w;Object.defineProperty(this,"openFiles",{get:function(){return A}}),this.allocDescriptor=function(t){var e=O++;return A[e]=t,e},this.releaseDescriptor=function(t){delete A[t]};var I=[];this.queueOrRun=function(t){var e;return f==S.readyState?t.call(S):d==S.readyState?e=new v.EFILESYSTEMERROR("unknown error"):I.push(t),e},this.watch=function(t,e,n){if(o(t))throw Error("Path must be a string without null bytes.");"function"==typeof e&&(n=e,e={}),e=e||{},n=n||a;var r=new g;return r.start(t,!1,e.recursive),r.on("change",n),r},p.open(function(t,i){function o(t){function i(t){var e=p[t]();return e.flags=s,e.changes=[],e.close=function(){var t=e.changes;r(t),t.length=0},e}S.provider={openReadWriteContext:function(){return i("getReadWriteContext")},openReadOnlyContext:function(){return i("getReadOnlyContext")}},t?S.readyState=d:(S.readyState=f,n()),e(t,S)}if(t)return o(t);if(!k&&!i)return o(null);var a=p.getReadWriteContext();a.clear(function(t){return t?(o(t),void 0):(E.makeRootDirectory(a,o),void 0)})})}var i=t("../../lib/nodash.js"),o=t("../path.js").isNull,a=t("../shared.js").nop,s=t("../constants.js"),u=s.FILE_SYSTEM_NAME,c=s.FS_FORMAT,f=s.FS_READY,l=s.FS_PENDING,d=s.FS_ERROR,h=t("../providers/index.js"),p=t("../shell/shell.js"),m=t("../../lib/intercom.js"),g=t("../fs-watcher.js"),v=t("../errors.js"),_=s.STDIN,y=s.STDOUT,b=s.STDERR,w=s.FIRST_DESCRIPTOR,E=t("./implementation.js");r.providers=h,["open","close","mknod","mkdir","rmdir","stat","fstat","link","unlink","read","readFile","write","writeFile","appendFile","exists","lseek","readdir","rename","readlink","symlink","lstat","truncate","ftruncate","utimes","futimes","setxattr","getxattr","fsetxattr","fgetxattr","removexattr","fremovexattr"].forEach(function(t){r.prototype[t]=function(){var e=this,r=Array.prototype.slice.call(arguments,0),i=r.length-1,o="function"!=typeof r[i],a=n(r[i]),s=e.queueOrRun(function(){function n(){s.close(),a.apply(e,arguments)}var s=e.provider.openReadWriteContext();o?r.push(n):r[i]=n;var u=[e,s].concat(r);E[t].apply(null,u)});s&&a(s)}}),r.prototype.Shell=function(t){return new p(this,t)},e.exports=r},{"../../lib/intercom.js":3,"../../lib/nodash.js":4,"../constants.js":41,"../errors.js":44,"../fs-watcher.js":47,"../path.js":51,"../providers/index.js":52,"../shared.js":56,"../shell/shell.js":59,"./implementation.js":45}],47:[function(t,e){function n(){function t(t){(e===t||a&&0===t.indexOf(e+"/"))&&n.trigger("change","change",t)}r.call(this);var e,n=this,a=!1;n.start=function(n,r,s){if(!e){if(i(n))throw Error("Path must be a string without null bytes.");e=n,a=s===!0;var u=o.getInstance();u.on("change",t)}},n.close=function(){var e=o.getInstance();e.off("change",t),n.removeAllListeners("change")}}var r=t("../lib/eventemitter.js"),i=t("./path.js").isNull,o=t("../lib/intercom.js");n.prototype=new r,n.prototype.constructor=n,e.exports=n},{"../lib/eventemitter.js":2,"../lib/intercom.js":3,"./path.js":51}],48:[function(t,e){(function(n){e.exports={FileSystem:t("./filesystem/interface.js"),Buffer:n,Path:t("./path.js"),Errors:t("./errors.js")}}).call(this,t("buffer").Buffer)},{"./errors.js":44,"./filesystem/interface.js":46,"./path.js":51}],49:[function(t,e){var n=t("./constants.js").MODE_FILE,r=t("./shared.js").guid;e.exports=function(t,e,i,o,a,s,u,c,f,l){var d=Date.now();this.id=t||r(),this.mode=e||n,this.size=i||0,this.atime=o||d,this.ctime=a||d,this.mtime=s||d,this.flags=u||[],this.xattrs=c||{},this.nlinks=f||0,this.version=l||0,this.blksize=void 0,this.nblocks=1,this.data=r()}},{"./constants.js":41,"./shared.js":56}],50:[function(t,e){e.exports=function(t,e,n,r){this.path=t,this.id=e,this.flags=n,this.position=r}},{}],51:[function(t,e,n){function r(t,e){for(var n=0,r=t.length-1;r>=0;r--){var i=t[r];"."===i?t.splice(r,1):".."===i?(t.splice(r,1),n++):n&&(t.splice(r,1),n--)}if(e)for(;n--;n)t.unshift("..");return t}function i(){for(var t="",e=!1,n=arguments.length-1;n>=-1&&!e;n--){var i=n>=0?arguments[n]:"/";"string"==typeof i&&i&&(t=i+"/"+t,e="/"===i.charAt(0))}return t=r(t.split("/").filter(function(t){return!!t}),!e).join("/"),(e?"/":"")+t||"."}function o(t){var e="/"===t.charAt(0);return"/"===t.substr(-1),t=r(t.split("/").filter(function(t){return!!t}),!e).join("/"),t||e||(t="."),(e?"/":"")+t}function a(){var t=Array.prototype.slice.call(arguments,0);return o(t.filter(function(t){return t&&"string"==typeof t}).join("/"))}function s(t,e){function r(t){for(var e=0;t.length>e&&""===t[e];e++);for(var n=t.length-1;n>=0&&""===t[n];n--);return e>n?[]:t.slice(e,n-e+1)}t=n.resolve(t).substr(1),e=n.resolve(e).substr(1);for(var i=r(t.split("/")),o=r(e.split("/")),a=Math.min(i.length,o.length),s=a,u=0;a>u;u++)if(i[u]!==o[u]){s=u;break}for(var c=[],u=s;i.length>u;u++)c.push("..");return c=c.concat(o.slice(s)),c.join("/")}function u(t){var e=p(t),n=e[0],r=e[1];return n||r?(r&&(r=r.substr(0,r.length-1)),n+r):"."}function c(t,e){var n=p(t)[2];return e&&n.substr(-1*e.length)===e&&(n=n.substr(0,n.length-e.length)),""===n?"/":n}function f(t){return p(t)[3]}function l(t){return"/"===t.charAt(0)?!0:!1}function d(t){return-1!==(""+t).indexOf("\0")?!0:!1}var h=/^(\/?)([\s\S]+\/(?!$)|\/)?((?:\.{1,2}$|[\s\S]+?)?(\.[^.\/]*)?)$/,p=function(t){var e=h.exec(t);return[e[1]||"",e[2]||"",e[3]||"",e[4]||""]};e.exports={normalize:o,resolve:i,join:a,relative:s,sep:"/",delimiter:":",dirname:u,basename:c,extname:f,isAbsolute:l,isNull:d}},{}],52:[function(t,e){var n=t("./indexeddb.js"),r=t("./websql.js"),i=t("./memory.js");e.exports={IndexedDB:n,WebSQL:r,Memory:i,Default:n,Fallback:function(){function t(){throw"[Filer Error] Your browser doesn't support IndexedDB or WebSQL."}return n.isSupported()?n:r.isSupported()?r:(t.isSupported=function(){return!1},t)}()}},{"./indexeddb.js":53,"./memory.js":54,"./websql.js":55}],53:[function(t,e){(function(n){function r(t,e){var n=t.transaction(a,e);this.objectStore=n.objectStore(a)}function i(t){this.name=t||o,this.db=null}var o=t("../constants.js").FILE_SYSTEM_NAME,a=t("../constants.js").FILE_STORE_NAME,s=t("../constants.js").IDB_RW;t("../constants.js").IDB_RO;var u=t("../errors.js"),c=n.indexedDB||n.mozIndexedDB||n.webkitIndexedDB||n.msIndexedDB;r.prototype.clear=function(t){try{var e=this.objectStore.clear();e.onsuccess=function(){t()},e.onerror=function(e){t(e)}}catch(n){t(n)}},r.prototype.get=function(t,e){try{var n=this.objectStore.get(t);n.onsuccess=function(t){var n=t.target.result;e(null,n)},n.onerror=function(t){e(t)}}catch(r){e(r)}},r.prototype.put=function(t,e,n){try{var r=this.objectStore.put(e,t);r.onsuccess=function(t){var e=t.target.result;n(null,e)},r.onerror=function(t){n(t)}}catch(i){n(i)}},r.prototype.delete=function(t,e){try{var n=this.objectStore.delete(t);n.onsuccess=function(t){var n=t.target.result;e(null,n)},n.onerror=function(t){e(t)}}catch(r){e(r)}},i.isSupported=function(){return!!c},i.prototype.open=function(t){var e=this;if(e.db)return t(null,!1),void 0;var n=!1,r=c.open(e.name);r.onupgradeneeded=function(t){var e=t.target.result;e.objectStoreNames.contains(a)&&e.deleteObjectStore(a),e.createObjectStore(a),n=!0},r.onsuccess=function(r){e.db=r.target.result,t(null,n)},r.onerror=function(){t(new u.EINVAL("IndexedDB cannot be accessed. If private browsing is enabled, disable it."))}},i.prototype.getReadOnlyContext=function(){return new r(this.db,s)},i.prototype.getReadWriteContext=function(){return new r(this.db,s)},e.exports=i})(this)},{"../constants.js":41,"../errors.js":44}],54:[function(t,e){function n(t,e){this.readOnly=e,this.objectStore=t}function r(t){this.name=t||i}var i=t("../constants.js").FILE_SYSTEM_NAME,o=t("../../lib/async.js").nextTick,a=function(){var t={};return function(e){var n=!t.hasOwnProperty(e);return n&&(t[e]={}),{firstAccess:n,db:t[e]}}}();n.prototype.clear=function(t){if(this.readOnly)return o(function(){t("[MemoryContext] Error: write operation on read only context")}),void 0;var e=this.objectStore;Object.keys(e).forEach(function(t){delete e[t]}),o(t)},n.prototype.get=function(t,e){var n=this;o(function(){e(null,n.objectStore[t])})},n.prototype.put=function(t,e,n){return this.readOnly?(o(function(){n("[MemoryContext] Error: write operation on read only context")}),void 0):(this.objectStore[t]=e,o(n),void 0)},n.prototype.delete=function(t,e){return this.readOnly?(o(function(){e("[MemoryContext] Error: write operation on read only context")}),void 0):(delete this.objectStore[t],o(e),void 0)},r.isSupported=function(){return!0},r.prototype.open=function(t){var e=a(this.name);this.db=e.db,o(function(){t(null,e.firstAccess)})},r.prototype.getReadOnlyContext=function(){return new n(this.db,!0)},r.prototype.getReadWriteContext=function(){return new n(this.db,!1)},e.exports=r},{"../../lib/async.js":1,"../constants.js":41}],55:[function(t,e){(function(n){function r(t,e){var n=this;this.getTransaction=function(r){return n.transaction?(r(n.transaction),void 0):(t[e?"readTransaction":"transaction"](function(t){n.transaction=t,r(t)}),void 0)}}function i(t){this.name=t||o,this.db=null}var o=t("../constants.js").FILE_SYSTEM_NAME,a=t("../constants.js").FILE_STORE_NAME,s=t("../constants.js").WSQL_VERSION,u=t("../constants.js").WSQL_SIZE,c=t("../constants.js").WSQL_DESC,f=t("../shared.js").u8toArray,l=t("../errors.js");r.prototype.clear=function(t){function e(e,n){t(n)}function n(){t(null)}this.getTransaction(function(t){t.executeSql("DELETE FROM "+a+";",[],n,e)})},r.prototype.get=function(t,e){function n(t,n){var r=0===n.rows.length?null:n.rows.item(0).data;try{r&&(r=JSON.parse(r),r.__isUint8Array&&(r=new Uint8Array(r.__array))),e(null,r)}catch(i){e(i)}}function r(t,n){e(n)}this.getTransaction(function(e){e.executeSql("SELECT data FROM "+a+" WHERE id = ?;",[t],n,r)})},r.prototype.put=function(t,e,n){function r(){n(null)}function i(t,e){n(e)}"[object Uint8Array]"===Object.prototype.toString.call(e)&&(e={__isUint8Array:!0,__array:f(e)}),e=JSON.stringify(e),this.getTransaction(function(n){n.executeSql("INSERT OR REPLACE INTO "+a+" (id, data) VALUES (?, ?);",[t,e],r,i)})},r.prototype.delete=function(t,e){function n(){e(null)}function r(t,n){e(n)}this.getTransaction(function(e){e.executeSql("DELETE FROM "+a+" WHERE id = ?;",[t],n,r)})},i.isSupported=function(){return!!n.openDatabase},i.prototype.open=function(t){function e(e,n){5===n.code&&t(new l.EINVAL("WebSQL cannot be accessed. If private browsing is enabled, disable it.")),t(n)}function r(e){function n(e,n){var r=0===n.rows.item(0).count;t(null,r)}function r(e,n){t(n)}i.db=o,e.executeSql("SELECT COUNT(id) AS count FROM "+a+";",[],n,r)}var i=this;if(i.db)return t(null,!1),void 0;var o=n.openDatabase(i.name,s,c,u);return o?(o.transaction(function(t){function n(t){t.executeSql("CREATE INDEX IF NOT EXISTS idx_"+a+"_id"+" on "+a+" (id);",[],r,e)}t.executeSql("CREATE TABLE IF NOT EXISTS "+a+" (id unique, data TEXT);",[],n,e)}),void 0):(t("[WebSQL] Unable to open database."),void 0)},i.prototype.getReadOnlyContext=function(){return new r(this.db,!0)},i.prototype.getReadWriteContext=function(){return new r(this.db,!1)},e.exports=i})(this)},{"../constants.js":41,"../errors.js":44,"../shared.js":56}],56:[function(t,e){function n(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var e=0|16*Math.random(),n="x"==t?e:8|3&e;return n.toString(16)}).toUpperCase()}function r(){}function i(t){for(var e=[],n=t.length,r=0;n>r;r++)e[r]=t[r];return e}e.exports={guid:n,u8toArray:i,nop:r}},{}],57:[function(t,e){var n=t("../constants.js").ENVIRONMENT;e.exports=function(t){t=t||{},t.TMP=t.TMP||n.TMP,t.PATH=t.PATH||n.PATH,this.get=function(e){return t[e]},this.set=function(e,n){t[e]=n}}},{"../constants.js":41}],58:[function(t,e){var n=t("request");e.exports.download=function(t,e){n({url:t,method:"GET",encoding:null},function(t,n,r){var i,o;return n=n||null,i=n&&n.statusCode,(o=200!==i?{message:t||"Not found!",code:i}:null)?(e(o,null),void 0):(e(null,r),void 0)})}},{request:5}],59:[function(t,e){function n(t,e){e=e||{};var n=new o(e.env),a="/";Object.defineProperty(this,"fs",{get:function(){return t},enumerable:!0}),Object.defineProperty(this,"env",{get:function(){return n},enumerable:!0}),this.cd=function(e,n){e=r.resolve(this.cwd,e),t.stat(e,function(t,r){return t?(n(new i.ENOTDIR),void 0):("DIRECTORY"===r.type?(a=e,n()):n(new i.ENOTDIR),void 0)})},this.pwd=function(){return a}}var r=t("../path.js"),i=t("../errors.js"),o=t("./environment.js"),a=t("../../lib/async.js"),s=t("./network.js");t("../encoding.js");var u=t("jszip");n.prototype.exec=function(t,e,n){var i=this.fs;"function"==typeof e&&(n=e,e=[]),e=e||[],n=n||function(){},t=r.resolve(this.cwd,t),i.readFile(t,"utf8",function(t,r){if(t)return n(t),void 0;try{var o=Function("fs","args","callback",r);o(i,e,n)}catch(a){n(a)}})},n.prototype.touch=function(t,e,n){function i(t){a.writeFile(t,"",n)}function o(t){var r=Date.now(),i=e.date||r,o=e.date||r;a.utimes(t,i,o,n)}var a=this.fs;"function"==typeof e&&(n=e,e={}),e=e||{},n=n||function(){},t=r.resolve(this.cwd,t),a.stat(t,function(r){r?e.updateOnly===!0?n():i(t):o(t)})},n.prototype.cat=function(t,e){function n(t,e){var n=r.resolve(this.cwd,t);o.readFile(n,"utf8",function(t,n){return t?(e(t),void 0):(s+=n+"\n",e(),void 0)})}var o=this.fs,s="";return e=e||function(){},t?(t="string"==typeof t?[t]:t,a.eachSeries(t,n,function(t){t?e(t):e(null,s.replace(/\n$/,""))}),void 0):(e(new i.EINVAL("Missing files argument")),void 0)},n.prototype.ls=function(t,e,n){function o(t,n){var i=r.resolve(this.cwd,t),u=[];s.readdir(i,function(t,c){function f(t,n){t=r.join(i,t),s.stat(t,function(a,s){if(a)return n(a),void 0;var c={path:r.basename(t),links:s.nlinks,size:s.size,modified:s.mtime,type:s.type};e.recursive&&"DIRECTORY"===s.type?o(r.join(i,c.path),function(t,e){return t?(n(t),void 0):(c.contents=e,u.push(c),n(),void 0)}):(u.push(c),n())})}return t?(n(t),void 0):(a.each(c,f,function(t){n(t,u)}),void 0)})}var s=this.fs;return"function"==typeof e&&(n=e,e={}),e=e||{},n=n||function(){},t?(o(t,n),void 0):(n(new i.EINVAL("Missing dir argument")),void 0)},n.prototype.rm=function(t,e,n){function o(t,n){t=r.resolve(this.cwd,t),s.stat(t,function(u,c){return u?(n(u),void 0):"FILE"===c.type?(s.unlink(t,n),void 0):(s.readdir(t,function(u,c){return u?(n(u),void 0):0===c.length?(s.rmdir(t,n),void 0):e.recursive?(c=c.map(function(e){return r.join(t,e) +}),a.each(c,o,function(e){return e?(n(e),void 0):(s.rmdir(t,n),void 0)}),void 0):(n(new i.ENOTEMPTY),void 0)}),void 0)})}var s=this.fs;return"function"==typeof e&&(n=e,e={}),e=e||{},n=n||function(){},t?(o(t,n),void 0):(n(new i.EINVAL("Missing path argument")),void 0)},n.prototype.tempDir=function(t){var e=this.fs,n=this.env.get("TMP");t=t||function(){},e.mkdir(n,function(){t(null,n)})},n.prototype.mkdirp=function(t,e){function n(t,e){o.stat(t,function(a,s){if(s){if(s.isDirectory())return e(),void 0;if(s.isFile())return e(new i.ENOTDIR),void 0}else{if(a&&"ENOENT"!==a.code)return e(a),void 0;var u=r.dirname(t);"/"===u?o.mkdir(t,function(t){return t&&"EEXIST"!=t.code?(e(t),void 0):(e(),void 0)}):n(u,function(n){return n?e(n):(o.mkdir(t,function(t){return t&&"EEXIST"!=t.code?(e(t),void 0):(e(),void 0)}),void 0)})}})}var o=this.fs;return e=e||function(){},t?"/"===t?(e(),void 0):(n(t,e),void 0):(e(new i.EINVAL("Missing path argument")),void 0)},n.prototype.wget=function(t,e,n){function o(){n(Error("unable to get resource"))}var a=this.fs;if("function"==typeof e&&(n=e,e={}),e=e||{},n=n||function(){},!t)return n(new i.EINVAL("missing url argument")),void 0;var u=e.filename||t.split("/").pop();u=r.resolve(a.cwd,u),s.download(t,function(t,e){return t||!e?o():(a.writeFile(u,e,function(t){t?n(t):n(null,u)}),void 0)})},n.prototype.unzip=function(t,e,n){var o=this.fs,s=this;if("function"==typeof e&&(n=e,e={}),e=e||{},n=n||function(){},!t)return n(new i.EINVAL("missing zipfile argument")),void 0;var c=r.resolve(this.cwd,t),f=r.resolve(e.destination||this.cwd);o.readFile(c,function(t,e){function i(t,e){t.isDirectory?s.mkdirp(t.absPath,e):o.writeFile(t.absPath,t.data,e)}if(t)return n(t);var c=new u(e),l=[];c.filter(function(t,e){var n=e.options.dir,i=n?null:e.asNodeBuffer();l.push({absPath:r.join(f,e.name),isDirectory:n,data:i})}),a.eachSeries(l,i,n)})},n.prototype.zip=function(t,e,n,o){function s(t){return t.replace(/^\//,"")}function c(t,e){d.readFile(t,function(n,r){return n?e(n):(p.file(s(t),r,{binary:!0}),e(),void 0)})}function f(t,e){d.readdir(t,function(i,o){p.folder(s(t)),n.recursive||e(),a.eachSeries(o,function(e,n){l(r.join(t,e),n)},e)})}function l(t,e){t=r.resolve(h.cwd,t),d.stat(t,function(n,r){return n?e(n):(r.isDirectory()?f(t,e):c(t,e),void 0)})}var d=this.fs,h=this;if("function"==typeof n&&(o=n,n={}),n=n||{},o=o||function(){},!t)return o(new i.EINVAL("missing zipfile argument")),void 0;if(!e)return o(new i.EINVAL("missing paths argument")),void 0;"string"==typeof e&&(e=[e]),t=r.resolve(this.cwd,t);var p=new u;d.stat(t,function(n,r){return r?o(new i.EEXIST("zipfile already exists")):(a.eachSeries(e,l,function(e){if(e)return o(e);var n;n=p.generate({type:"nodebuffer"}),d.writeFile(t,n,o)}),void 0)})},e.exports=n},{"../../lib/async.js":1,"../encoding.js":43,"../errors.js":44,"../path.js":51,"./environment.js":57,"./network.js":58,jszip:13}],60:[function(t,e){function n(t,e){this.node=t.id,this.dev=e,this.size=t.size,this.nlinks=t.nlinks,this.atime=t.atime,this.mtime=t.mtime,this.ctime=t.ctime,this.type=t.mode}var r=t("./constants.js");n.prototype.isFile=function(){return this.type===r.MODE_FILE},n.prototype.isDirectory=function(){return this.type===r.MODE_DIRECTORY},n.prototype.isSymbolicLink=function(){return this.type===r.MODE_SYMBOLIC_LINK},n.prototype.isSocket=n.prototype.isFIFO=n.prototype.isCharacterDevice=n.prototype.isBlockDevice=function(){return!1},e.exports=n},{"./constants.js":41}],61:[function(t,e){var n=t("./constants.js"),r=t("./shared.js").guid;e.exports=function(t,e,i){var o=Date.now();this.id=n.SUPER_NODE_ID,this.mode=n.MODE_META,this.atime=t||o,this.ctime=e||o,this.mtime=i||o,this.rnode=r()}},{"./constants.js":41,"./shared.js":56}]},{},[48])(48)}); \ No newline at end of file diff --git a/package.json b/package.json index b8cf9a5..2e93433 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "idb", "websql" ], - "version": "0.0.9", + "version": "0.0.10", "author": "Alan K (http://blog.modeswitch.org)", "homepage": "http://js-platform.github.io/filer", "bugs": "https://github.com/js-platform/filer/issues",