;(function(e,t,n){function i(n,s){if(!t[n]){if(!e[n]){var o=typeof require=="function"&&require;if(!s&&o)return o(n,!0);if(r)return r(n,!0);throw new Error("Cannot find module '"+n+"'")}var u=t[n]={exports:{}};e[n][0].call(u.exports,function(t){var r=e[n][1][t];return i(r?r:t)},u,u.exports)}return t[n].exports}var r=typeof require=="function"&&require;for(var s=0;s 0 && this._events[type].length > m) { this._events[type].warned = true; console.error('(node) warning: possible EventEmitter memory ' + 'leak detected. %d listeners added. ' + 'Use emitter.setMaxListeners() to increase limit.', this._events[type].length); console.trace(); } } // If we've already got an array, just append. this._events[type].push(listener); } else { // Adding the second element, need to change to array. this._events[type] = [this._events[type], listener]; } return this; }; EventEmitter.prototype.on = EventEmitter.prototype.addListener; EventEmitter.prototype.once = function(type, listener) { var self = this; self.on(type, function g() { self.removeListener(type, g); listener.apply(this, arguments); }); return this; }; EventEmitter.prototype.removeListener = function(type, listener) { if ('function' !== typeof listener) { throw new Error('removeListener only takes instances of Function'); } // does not use listeners(), so no side effect of creating _events[type] if (!this._events || !this._events[type]) return this; var list = this._events[type]; if (isArray(list)) { var i = indexOf(list, listener); if (i < 0) return this; list.splice(i, 1); if (list.length == 0) delete this._events[type]; } else if (this._events[type] === listener) { delete this._events[type]; } return this; }; EventEmitter.prototype.removeAllListeners = function(type) { if (arguments.length === 0) { this._events = {}; return this; } // does not use listeners(), so no side effect of creating _events[type] if (type && this._events && this._events[type]) this._events[type] = null; return this; }; EventEmitter.prototype.listeners = function(type) { if (!this._events) this._events = {}; if (!this._events[type]) this._events[type] = []; if (!isArray(this._events[type])) { this._events[type] = [this._events[type]]; } return this._events[type]; }; EventEmitter.listenerCount = function(emitter, type) { var ret; if (!emitter._events || !emitter._events[type]) ret = 0; else if (typeof emitter._events[type] === 'function') ret = 1; else ret = emitter._events[type].length; return ret; }; },{"__browserify_process":9}],2:[function(require,module,exports){ // nothing to see here... no file methods for the browser },{}],3:[function(require,module,exports){ var process=require("__browserify_process");function filter (xs, fn) { var res = []; for (var i = 0; i < xs.length; i++) { if (fn(xs[i], i, xs)) res.push(xs[i]); } return res; } // resolves . and .. elements in a path array with directory names there // must be no slashes, empty elements, or device names (c:\) in the array // (so also no leading and trailing slashes - it does not distinguish // relative and absolute paths) function normalizeArray(parts, allowAboveRoot) { // if the path tries to go above the root, `up` ends up > 0 var up = 0; for (var i = parts.length; i >= 0; i--) { var last = parts[i]; if (last == '.') { parts.splice(i, 1); } else if (last === '..') { parts.splice(i, 1); up++; } else if (up) { parts.splice(i, 1); up--; } } // if the path is allowed to go above the root, restore leading ..s if (allowAboveRoot) { for (; up--; up) { parts.unshift('..'); } } return parts; } // Regex to split a filename into [*, dir, basename, ext] // posix version var splitPathRe = /^(.+\/(?!$)|\/)?((?:.+?)?(\.[^.]*)?)$/; // path.resolve([from ...], to) // posix version exports.resolve = function() { var resolvedPath = '', resolvedAbsolute = false; for (var i = arguments.length; i >= -1 && !resolvedAbsolute; i--) { var path = (i >= 0) ? arguments[i] : process.cwd(); // Skip empty and invalid entries if (typeof path !== 'string' || !path) { continue; } resolvedPath = path + '/' + resolvedPath; resolvedAbsolute = path.charAt(0) === '/'; } // At this point the path should be resolved to a full absolute path, but // handle relative paths to be safe (might happen when process.cwd() fails) // Normalize the path resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) { return !!p; }), !resolvedAbsolute).join('/'); return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.'; }; // path.normalize(path) // posix version exports.normalize = function(path) { var isAbsolute = path.charAt(0) === '/', trailingSlash = path.slice(-1) === '/'; // Normalize the path path = normalizeArray(filter(path.split('/'), function(p) { return !!p; }), !isAbsolute).join('/'); if (!path && !isAbsolute) { path = '.'; } if (path && trailingSlash) { path += '/'; } return (isAbsolute ? '/' : '') + path; }; // posix version exports.join = function() { var paths = Array.prototype.slice.call(arguments, 0); return exports.normalize(filter(paths, function(p, index) { return p && typeof p === 'string'; }).join('/')); }; exports.dirname = function(path) { var dir = splitPathRe.exec(path)[1] || ''; var isWindows = false; if (!dir) { // No dirname return '.'; } else if (dir.length === 1 || (isWindows && dir.length <= 3 && dir.charAt(1) === ':')) { // It is just a slash or a drive letter with a slash return dir; } else { // It is a full dirname, strip trailing slash return dir.substring(0, dir.length - 1); } }; exports.basename = function(path, ext) { var f = splitPathRe.exec(path)[2] || ''; // TODO: make this comparison case-insensitive on windows? if (ext && f.substr(-1 * ext.length) === ext) { f = f.substr(0, f.length - ext.length); } return f; }; exports.extname = function(path) { return splitPathRe.exec(path)[3] || ''; }; exports.relative = function(from, to) { from = exports.resolve(from).substr(1); to = exports.resolve(to).substr(1); function trim(arr) { var start = 0; for (; start < arr.length; start++) { if (arr[start] !== '') break; } var end = arr.length - 1; for (; end >= 0; end--) { if (arr[end] !== '') break; } if (start > end) return []; return arr.slice(start, end - start + 1); } var fromParts = trim(from.split('/')); var toParts = trim(to.split('/')); var length = Math.min(fromParts.length, toParts.length); var samePartsLength = length; for (var i = 0; i < length; i++) { if (fromParts[i] !== toParts[i]) { samePartsLength = i; break; } } var outputParts = []; for (var i = samePartsLength; i < fromParts.length; i++) { outputParts.push('..'); } outputParts = outputParts.concat(toParts.slice(samePartsLength)); return outputParts.join('/'); }; exports.sep = '/'; },{"__browserify_process":9}],4:[function(require,module,exports){ var events = require('events'); var util = require('util'); function Stream() { events.EventEmitter.call(this); } util.inherits(Stream, events.EventEmitter); module.exports = Stream; // Backwards-compat with node 0.4.x Stream.Stream = Stream; Stream.prototype.pipe = function(dest, options) { var source = this; function ondata(chunk) { if (dest.writable) { if (false === dest.write(chunk) && source.pause) { source.pause(); } } } source.on('data', ondata); function ondrain() { if (source.readable && source.resume) { source.resume(); } } dest.on('drain', ondrain); // If the 'end' option is not supplied, dest.end() will be called when // source gets the 'end' or 'close' events. Only dest.end() once, and // only when all sources have ended. if (!dest._isStdio && (!options || options.end !== false)) { dest._pipeCount = dest._pipeCount || 0; dest._pipeCount++; source.on('end', onend); source.on('close', onclose); } var didOnEnd = false; function onend() { if (didOnEnd) return; didOnEnd = true; dest._pipeCount--; // remove the listeners cleanup(); if (dest._pipeCount > 0) { // waiting for other incoming streams to end. return; } dest.end(); } function onclose() { if (didOnEnd) return; didOnEnd = true; dest._pipeCount--; // remove the listeners cleanup(); if (dest._pipeCount > 0) { // waiting for other incoming streams to end. return; } dest.destroy(); } // don't leave dangling pipes when there are errors. function onerror(er) { cleanup(); if (this.listeners('error').length === 0) { throw er; // Unhandled stream error in pipe. } } source.on('error', onerror); dest.on('error', onerror); // remove all the event listeners that were added. function cleanup() { source.removeListener('data', ondata); dest.removeListener('drain', ondrain); source.removeListener('end', onend); source.removeListener('close', onclose); source.removeListener('error', onerror); dest.removeListener('error', onerror); source.removeListener('end', cleanup); source.removeListener('close', cleanup); dest.removeListener('end', cleanup); dest.removeListener('close', cleanup); } source.on('end', cleanup); source.on('close', cleanup); dest.on('end', cleanup); dest.on('close', cleanup); dest.emit('pipe', source); // Allow for unix-like usage: A.pipe(B).pipe(C) return dest; }; },{"events":1,"util":5}],5:[function(require,module,exports){ var events = require('events'); exports.isArray = isArray; exports.isDate = function(obj){return Object.prototype.toString.call(obj) === '[object Date]'}; exports.isRegExp = function(obj){return Object.prototype.toString.call(obj) === '[object RegExp]'}; exports.print = function () {}; exports.puts = function () {}; exports.debug = function() {}; exports.inspect = function(obj, showHidden, depth, colors) { var seen = []; var stylize = function(str, styleType) { // http://en.wikipedia.org/wiki/ANSI_escape_code#graphics var styles = { 'bold' : [1, 22], 'italic' : [3, 23], 'underline' : [4, 24], 'inverse' : [7, 27], 'white' : [37, 39], 'grey' : [90, 39], 'black' : [30, 39], 'blue' : [34, 39], 'cyan' : [36, 39], 'green' : [32, 39], 'magenta' : [35, 39], 'red' : [31, 39], 'yellow' : [33, 39] }; var style = { 'special': 'cyan', 'number': 'blue', 'boolean': 'yellow', 'undefined': 'grey', 'null': 'bold', 'string': 'green', 'date': 'magenta', // "name": intentionally not styling 'regexp': 'red' }[styleType]; if (style) { return '\u001b[' + styles[style][0] + 'm' + str + '\u001b[' + styles[style][1] + 'm'; } else { return str; } }; if (! colors) { stylize = function(str, styleType) { return str; }; } function format(value, recurseTimes) { // Provide a hook for user-specified inspect functions. // Check that value is an object with an inspect function on it if (value && typeof value.inspect === 'function' && // Filter out the util module, it's inspect function is special value !== exports && // Also filter out any prototype objects using the circular check. !(value.constructor && value.constructor.prototype === value)) { return value.inspect(recurseTimes); } // Primitive types cannot have properties switch (typeof value) { case 'undefined': return stylize('undefined', 'undefined'); case 'string': var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '') .replace(/'/g, "\\'") .replace(/\\"/g, '"') + '\''; return stylize(simple, 'string'); case 'number': return stylize('' + value, 'number'); case 'boolean': return stylize('' + value, 'boolean'); } // For some reason typeof null is "object", so special case here. if (value === null) { return stylize('null', 'null'); } // Look up the keys of the object. var visible_keys = Object_keys(value); var keys = showHidden ? Object_getOwnPropertyNames(value) : visible_keys; // Functions without properties can be shortcutted. if (typeof value === 'function' && keys.length === 0) { if (isRegExp(value)) { return stylize('' + value, 'regexp'); } else { var name = value.name ? ': ' + value.name : ''; return stylize('[Function' + name + ']', 'special'); } } // Dates without properties can be shortcutted if (isDate(value) && keys.length === 0) { return stylize(value.toUTCString(), 'date'); } var base, type, braces; // Determine the object type if (isArray(value)) { type = 'Array'; braces = ['[', ']']; } else { type = 'Object'; braces = ['{', '}']; } // Make functions say that they are functions if (typeof value === 'function') { var n = value.name ? ': ' + value.name : ''; base = (isRegExp(value)) ? ' ' + value : ' [Function' + n + ']'; } else { base = ''; } // Make dates with properties first say the date if (isDate(value)) { base = ' ' + value.toUTCString(); } if (keys.length === 0) { return braces[0] + base + braces[1]; } if (recurseTimes < 0) { if (isRegExp(value)) { return stylize('' + value, 'regexp'); } else { return stylize('[Object]', 'special'); } } seen.push(value); var output = keys.map(function(key) { var name, str; if (value.__lookupGetter__) { if (value.__lookupGetter__(key)) { if (value.__lookupSetter__(key)) { str = stylize('[Getter/Setter]', 'special'); } else { str = stylize('[Getter]', 'special'); } } else { if (value.__lookupSetter__(key)) { str = stylize('[Setter]', 'special'); } } } if (visible_keys.indexOf(key) < 0) { name = '[' + key + ']'; } if (!str) { if (seen.indexOf(value[key]) < 0) { if (recurseTimes === null) { str = format(value[key]); } else { str = format(value[key], recurseTimes - 1); } if (str.indexOf('\n') > -1) { if (isArray(value)) { str = str.split('\n').map(function(line) { return ' ' + line; }).join('\n').substr(2); } else { str = '\n' + str.split('\n').map(function(line) { return ' ' + line; }).join('\n'); } } } else { str = stylize('[Circular]', 'special'); } } if (typeof name === 'undefined') { if (type === 'Array' && key.match(/^\d+$/)) { return str; } name = JSON.stringify('' + key); if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) { name = name.substr(1, name.length - 2); name = stylize(name, 'name'); } else { name = name.replace(/'/g, "\\'") .replace(/\\"/g, '"') .replace(/(^"|"$)/g, "'"); name = stylize(name, 'string'); } } return name + ': ' + str; }); seen.pop(); var numLinesEst = 0; var length = output.reduce(function(prev, cur) { numLinesEst++; if (cur.indexOf('\n') >= 0) numLinesEst++; return prev + cur.length + 1; }, 0); if (length > 50) { output = braces[0] + (base === '' ? '' : base + '\n ') + ' ' + output.join(',\n ') + ' ' + braces[1]; } else { output = braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1]; } return output; } return format(obj, (typeof depth === 'undefined' ? 2 : depth)); }; function isArray(ar) { return Array.isArray(ar) || (typeof ar === 'object' && Object.prototype.toString.call(ar) === '[object Array]'); } function isRegExp(re) { typeof re === 'object' && Object.prototype.toString.call(re) === '[object RegExp]'; } function isDate(d) { return typeof d === 'object' && Object.prototype.toString.call(d) === '[object Date]'; } function pad(n) { return n < 10 ? '0' + n.toString(10) : n.toString(10); } var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; // 26 Feb 16:19:34 function timestamp() { var d = new Date(); var time = [pad(d.getHours()), pad(d.getMinutes()), pad(d.getSeconds())].join(':'); return [d.getDate(), months[d.getMonth()], time].join(' '); } exports.log = function (msg) {}; exports.pump = null; var Object_keys = Object.keys || function (obj) { var res = []; for (var key in obj) res.push(key); return res; }; var Object_getOwnPropertyNames = Object.getOwnPropertyNames || function (obj) { var res = []; for (var key in obj) { if (Object.hasOwnProperty.call(obj, key)) res.push(key); } return res; }; var Object_create = Object.create || function (prototype, properties) { // from es5-shim var object; if (prototype === null) { object = { '__proto__' : null }; } else { if (typeof prototype !== 'object') { throw new TypeError( 'typeof prototype[' + (typeof prototype) + '] != \'object\'' ); } var Type = function () {}; Type.prototype = prototype; object = new Type(); object.__proto__ = prototype; } if (typeof properties !== 'undefined' && Object.defineProperties) { Object.defineProperties(object, properties); } return object; }; exports.inherits = function(ctor, superCtor) { ctor.super_ = superCtor; ctor.prototype = Object_create(superCtor.prototype, { constructor: { value: ctor, enumerable: false, writable: true, configurable: true } }); }; var formatRegExp = /%[sdj%]/g; exports.format = function(f) { if (typeof f !== 'string') { var objects = []; for (var i = 0; i < arguments.length; i++) { objects.push(exports.inspect(arguments[i])); } return objects.join(' '); } var i = 1; var args = arguments; var len = args.length; var str = String(f).replace(formatRegExp, function(x) { if (x === '%%') return '%'; if (i >= len) return x; switch (x) { case '%s': return String(args[i++]); case '%d': return Number(args[i++]); case '%j': return JSON.stringify(args[i++]); default: return x; } }); for(var x = args[i]; i < len; x = args[++i]){ if (x === null || typeof x !== 'object') { str += ' ' + x; } else { str += ' ' + exports.inspect(x); } } return str; }; },{"events":1}],6:[function(require,module,exports){ var Buffer=require("__browserify_Buffer").Buffer;const Zlib = module.exports = require('./zlib'); // the least I can do is make error messages for the rest of the node.js/zlib api. // (thanks, dominictarr) function error () { var m = [].slice.call(arguments).join(' ') throw new Error([ m, 'we accept pull requests', 'http://github.com/brianloveswords/zlib-browserify' ].join('\n')) } ;['createGzip' , 'createGunzip' , 'createDeflate' , 'createDeflateRaw' , 'createInflate' , 'createInflateRaw' , 'createUnzip' , 'Gzip' , 'Gunzip' , 'Inflate' , 'InflateRaw' , 'Deflate' , 'DeflateRaw' , 'Unzip' , 'inflateRaw' , 'deflateRaw'].forEach(function (name) { Zlib[name] = function () { error('sorry,', name, 'is not implemented yet') } }); const _deflate = Zlib.deflate; const _gzip = Zlib.gzip; Zlib.deflate = function deflate(stringOrBuffer, callback) { return _deflate(Buffer(stringOrBuffer), callback); }; Zlib.gzip = function gzip(stringOrBuffer, callback) { return _gzip(Buffer(stringOrBuffer), callback); }; },{"./zlib":7,"__browserify_Buffer":8}],7:[function(require,module,exports){ var process=require("__browserify_process"),Buffer=require("__browserify_Buffer").Buffer;/** @license zlib.js 2012 - imaya [ https://github.com/imaya/zlib.js ] The MIT License */ (function() {'use strict';function m(c){throw c;}var r=void 0,u=!0;var B="undefined"!==typeof Uint8Array&&"undefined"!==typeof Uint16Array&&"undefined"!==typeof Uint32Array;function aa(c){if("string"===typeof c){var a=c.split(""),b,e;b=0;for(e=a.length;b>>0;c=a}for(var f=1,d=0,g=c.length,h,j=0;0>>0};function I(c,a){this.index="number"===typeof a?a:0;this.n=0;this.buffer=c instanceof(B?Uint8Array:Array)?c:new (B?Uint8Array:Array)(32768);2*this.buffer.length<=this.index&&m(Error("invalid index"));this.buffer.length<=this.index&&this.f()}I.prototype.f=function(){var c=this.buffer,a,b=c.length,e=new (B?Uint8Array:Array)(b<<1);if(B)e.set(c);else for(a=0;a>>8&255]<<16|K[c>>>16&255]<<8|K[c>>>24&255])>>32-a:K[c]>>8-a);if(8>a+d)g=g<>a-h-1&1,8===++d&&(d=0,e[f++]=K[g],g=0,f===e.length&&(e=this.f()));e[f]=g;this.buffer=e;this.n=d;this.index=f};I.prototype.finish=function(){var c=this.buffer,a=this.index,b;0Q;++Q){for(var R=Q,ga=R,ha=7,R=R>>>1;R;R>>>=1)ga<<=1,ga|=R&1,--ha;ba[Q]=(ga<>>0}var K=ba;var S={k:function(c,a,b){return S.update(c,0,a,b)},update:function(c,a,b,e){for(var f=S.L,d="number"===typeof b?b:b=0,g="number"===typeof e?e:c.length,a=a^4294967295,d=g&7;d--;++b)a=a>>>8^f[(a^c[b])&255];for(d=g>>3;d--;b+=8)a=a>>>8^f[(a^c[b])&255],a=a>>>8^f[(a^c[b+1])&255],a=a>>>8^f[(a^c[b+2])&255],a=a>>>8^f[(a^c[b+3])&255],a=a>>>8^f[(a^c[b+4])&255],a=a>>>8^f[(a^c[b+5])&255],a=a>>>8^f[(a^c[b+6])&255],a=a>>>8^f[(a^c[b+7])&255];return(a^4294967295)>>>0}},ia=S,ja,ka=[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];ja=B?new Uint32Array(ka):ka;ia.L=ja;function na(){};function oa(c){this.buffer=new (B?Uint16Array:Array)(2*c);this.length=0}oa.prototype.getParent=function(c){return 2*((c-2)/4|0)};oa.prototype.push=function(c,a){var b,e,f=this.buffer,d;b=this.length;f[this.length++]=a;for(f[this.length++]=c;0f[e])d=f[b],f[b]=f[e],f[e]=d,d=f[b+1],f[b+1]=f[e+1],f[e+1]=d,b=e;else break;return this.length}; oa.prototype.pop=function(){var c,a,b=this.buffer,e,f,d;a=b[0];c=b[1];this.length-=2;b[0]=b[this.length];b[1]=b[this.length+1];for(d=0;;){f=2*d+2;if(f>=this.length)break;f+2b[f]&&(f+=2);if(b[f]>b[d])e=b[d],b[d]=b[f],b[f]=e,e=b[d+1],b[d+1]=b[f+1],b[f+1]=e;else break;d=f}return{index:c,value:a,length:this.length}};function T(c){var a=c.length,b=0,e=Number.POSITIVE_INFINITY,f,d,g,h,j,i,q,l,k;for(l=0;lb&&(b=c[l]),c[l]>=1;for(k=i;kU;U++)switch(u){case 143>=U:sa.push([U+48,8]);break;case 255>=U:sa.push([U-144+400,9]);break;case 279>=U:sa.push([U-256+0,7]);break;case 287>=U:sa.push([U-280+192,8]);break;default:m("invalid literal: "+U)} pa.prototype.h=function(){var c,a,b,e,f=this.input;switch(this.l){case 0:b=0;for(e=f.length;b>>8&255;k[p++]=i&255;k[p++]=i>>>8&255;if(B)k.set(d,p),p+=d.length,k=k.subarray(0,p);else{q=0;for(l=d.length;qz)for(;0z?z:138,H>z-3&&H=H?(L[J++]=17,L[J++]=H-3,O[17]++):(L[J++]=18,L[J++]=H-11,O[18]++),z-=H;else if(L[J++]=M[y],O[M[y]]++,z--,3>z)for(;0z?z:6,H>z-3&&HG;G++)va[G]=la[ca[G]];for(D=19;4=c:return[265,c-11,1];case 14>=c:return[266,c-13,1];case 16>=c:return[267,c-15,1];case 18>=c:return[268,c-17,1];case 22>=c:return[269,c-19,2];case 26>=c:return[270,c-23,2];case 30>=c:return[271,c-27,2];case 34>=c:return[272,c- 31,2];case 42>=c:return[273,c-35,3];case 50>=c:return[274,c-43,3];case 58>=c:return[275,c-51,3];case 66>=c:return[276,c-59,3];case 82>=c:return[277,c-67,4];case 98>=c:return[278,c-83,4];case 114>=c:return[279,c-99,4];case 130>=c:return[280,c-115,4];case 162>=c:return[281,c-131,5];case 194>=c:return[282,c-163,5];case 226>=c:return[283,c-195,5];case 257>=c:return[284,c-227,5];case 258===c:return[285,c-258,0];default:m("invalid length: "+c)}}var Ba=[],Aa,Ca; for(Aa=3;258>=Aa;Aa++)Ca=za(),Ba[Aa]=Ca[2]<<24|Ca[1]<<16|Ca[0];var Da=B?new Uint32Array(Ba):Ba; function ta(c,a){function b(a,c){var b=a.N,d=[],e=0,f;f=Da[a.length];d[e++]=f&65535;d[e++]=f>>16&255;d[e++]=f>>24;var g;switch(u){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:m("invalid distance")}f=g;d[e++]=f[0];d[e++]=f[1];d[e++]=f[2];var h,i;h=0;for(i=d.length;h=d;)v[d++]=0;for(d=0;29>=d;)x[d++]=0}v[256]=1;e=0;for(f=a.length;e=f){l&&b(l,-1);d=0;for(g=f-e;ds&&e+sn&&(C=A,n=s);if(258===s)break}q=new xa(n,e-C);l?l.length2*k[n-1]+p[n]&&(k[n]=2*k[n-1]+p[n]),v[n]=Array(k[n]),x[n]=Array(k[n]);for(C=0;Ch[C]?(v[n][s]=E,x[n][s]=l,D+=2): (v[n][s]=h[C],x[n][s]=C,++C);F[n]=0;1===p[n]&&b(n)}j=t;i=0;for(q=g.length;i>>=1}return a};function Ea(c,a){this.input=c;this.a=new (B?Uint8Array:Array)(32768);this.l=Fa.u;var b={},e;if((a||!(a={}))&&"number"===typeof a.compressionType)this.l=a.compressionType;for(e in a)b[e]=a[e];b.outputBuffer=this.a;this.H=new pa(this.input,b)}var Fa=ra; Ea.prototype.h=function(){var c,a,b,e,f,d,g,h=0;g=this.a;c=Ga;switch(c){case Ga:a=Math.LOG2E*Math.log(32768)-8;break;default:m(Error("invalid compression method"))}b=a<<4|c;g[h++]=b;switch(c){case Ga:switch(this.l){case Fa.NONE:f=0;break;case Fa.K:f=1;break;case Fa.u:f=2;break;default:m(Error("unsupported compression type"))}break;default:m(Error("invalid compression method"))}e=f<<6|0;g[h++]=e|31-(256*b+e)%31;d=aa(this.input);this.H.b=h;g=this.H.h();h=g.length;B&&(g=new Uint8Array(g.buffer),g.length<= h+4&&(this.a=new Uint8Array(g.length+4),this.a.set(g),g=this.a),g=g.subarray(0,h+4));g[h++]=d>>24&255;g[h++]=d>>16&255;g[h++]=d>>8&255;g[h++]=d&255;return g};function Ha(c,a){this.input=c;this.b=this.c=0;this.g={};a&&(a.flags&&(this.g=a.flags),"string"===typeof a.filename&&(this.filename=a.filename),"string"===typeof a.comment&&(this.comment=a.comment),a.deflateOptions&&(this.m=a.deflateOptions));this.m||(this.m={})} Ha.prototype.h=function(){var c,a,b,e,f,d,g,h,j=new (B?Uint8Array:Array)(32768),i=0,q=this.input,l=this.c,k=this.filename,p=this.comment;j[i++]=31;j[i++]=139;j[i++]=8;c=0;this.g.fname&&(c|=Ia);this.g.fcomment&&(c|=Ja);this.g.fhcrc&&(c|=Ka);j[i++]=c;a=(Date.now?Date.now():+new Date)/1E3|0;j[i++]=a&255;j[i++]=a>>>8&255;j[i++]=a>>>16&255;j[i++]=a>>>24&255;j[i++]=0;j[i++]=Ya;if(this.g.fname!==r){g=0;for(h=k.length;g>>8&255),j[i++]=d&255;j[i++]=0}if(this.g.comment){g= 0;for(h=p.length;g>>8&255),j[i++]=d&255;j[i++]=0}this.g.fhcrc&&(b=S.k(j,0,i)&65535,j[i++]=b&255,j[i++]=b>>>8&255);this.m.outputBuffer=j;this.m.outputIndex=i;f=new pa(q,this.m);j=f.h();i=f.b;B&&(i+8>j.buffer.byteLength?(this.a=new Uint8Array(i+8),this.a.set(new Uint8Array(j.buffer)),j=this.a):j=new Uint8Array(j.buffer));e=S.k(q);j[i++]=e&255;j[i++]=e>>>8&255;j[i++]=e>>>16&255;j[i++]=e>>>24&255;h=q.length;j[i++]=h&255;j[i++]=h>>>8&255;j[i++]=h>>>16&255;j[i++]= h>>>24&255;this.c=l;B&&i>>=1;switch(c){case 0:var a=this.input,b=this.c,e=this.a,f=this.b,d=r,g=r,h=r,j=e.length,i=r;this.e=this.j=0;d=a[b++];d===r&&m(Error("invalid uncompressed block header: LEN (first byte)"));g=d;d=a[b++];d===r&&m(Error("invalid uncompressed block header: LEN (second byte)"));g|=d<<8;d=a[b++];d===r&&m(Error("invalid uncompressed block header: NLEN (first byte)"));h=d;d=a[b++];d===r&&m(Error("invalid uncompressed block header: NLEN (second byte)"));h|= d<<8;g===~h&&m(Error("invalid uncompressed block header: length verify"));b+g>a.length&&m(Error("input buffer is broken"));switch(this.r){case $a:for(;f+g>e.length;){i=j-f;g-=i;if(B)e.set(a.subarray(b,b+i),f),f+=i,b+=i;else for(;i--;)e[f++]=a[b++];this.b=f;e=this.f();f=this.b}break;case Za:for(;f+g>e.length;)e=this.f({B:2});break;default:m(Error("invalid inflate mode"))}if(B)e.set(a.subarray(b,b+g),f),f+=g,b+=g;else for(;g--;)e[f++]=a[b++];this.c=b;this.b=f;this.a=e;break;case 1:this.s(ab,bb);break; case 2:cb(this);break;default:m(Error("unknown BTYPE: "+c))}}return this.z()}; var db=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],eb=B?new Uint16Array(db):db,fb=[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],gb=B?new Uint16Array(fb):fb,hb=[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],ib=B?new Uint8Array(hb):hb,jb=[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],kb=B?new Uint16Array(jb):jb,lb=[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],mb=B?new Uint8Array(lb):lb,nb=new (B?Uint8Array:Array)(288),Y,ob;Y=0;for(ob=nb.length;Y=Y?8:255>=Y?9:279>=Y?7:8;var ab=T(nb),pb=new (B?Uint8Array:Array)(30),qb,rb;qb=0;for(rb=pb.length;qb>>a;c.e=e-a;c.c=d;return g} function sb(c,a){for(var b=c.j,e=c.e,f=c.input,d=c.c,g=a[0],h=a[1],j,i,q;e>>16;c.j=b>>q;c.e=e-q;c.c=d;return i&65535} function cb(c){function a(a,b,c){var d,f,e,g;for(g=0;gd)e>=f&&(this.b=e,b=this.f(),e=this.b),b[e++]=d;else{g=d-257;j=gb[g];0=f&&(this.b=e,b=this.f(),e=this.b);for(;j--;)b[e]=b[e++-h]}for(;8<=this.e;)this.e-=8,this.c--;this.b=e}; W.prototype.Q=function(c,a){var b=this.a,e=this.b;this.A=c;for(var f=b.length,d,g,h,j;256!==(d=sb(this,c));)if(256>d)e>=f&&(b=this.f(),f=b.length),b[e++]=d;else{g=d-257;j=gb[g];0f&&(b=this.f(),f=b.length);for(;j--;)b[e]=b[e++-h]}for(;8<=this.e;)this.e-=8,this.c--;this.b=e}; W.prototype.f=function(){var c=new (B?Uint8Array:Array)(this.b-32768),a=this.b-32768,b,e,f=this.a;if(B)c.set(f.subarray(32768,c.length));else{b=0;for(e=c.length;bb;++b)f[b]=f[a+b];this.b=32768;return f}; W.prototype.R=function(c){var a,b=this.input.length/this.c+1|0,e,f,d,g=this.input,h=this.a;c&&("number"===typeof c.B&&(b=c.B),"number"===typeof c.M&&(b+=c.M));2>b?(e=(g.length-this.c)/this.A[2],d=258*(e/2)|0,f=da&&(this.a.length=a),c=this.a);return this.buffer=c};function tb(c){this.input=c;this.c=0;this.member=[]} tb.prototype.i=function(){for(var c=this.input.length;this.c>>0;S.k(f)!==q&&m(Error("invalid CRC-32 checksum: 0x"+S.k(f).toString(16)+" / 0x"+q.toString(16))); a.Y=b=(l[k++]|l[k++]<<8|l[k++]<<16|l[k++]<<24)>>>0;(f.length&4294967295)!==b&&m(Error("invalid input size: "+(f.length&4294967295)+" / "+b));this.member.push(a);this.c=k}var p=this.member,t,v,x=0,F=0,w;t=0;for(v=p.length;t>>0,b!==aa(a)&&m(Error("invalid adler-32 checksum")));return a};exports.deflate=vb;exports.deflateSync=wb;exports.inflate=xb;exports.inflateSync=yb;exports.gzip=zb;exports.gzipSync=Ab;exports.gunzip=Bb;exports.gunzipSync=Cb;function vb(c,a,b){process.nextTick(function(){var e,f;try{f=wb(c,b)}catch(d){e=d}a(e,f)})}function wb(c,a){var b;b=(new Ea(c)).h();a||(a={});return a.G?b:Db(b)}function xb(c,a,b){process.nextTick(function(){var e,f;try{f=yb(c,b)}catch(d){e=d}a(e,f)})} function yb(c,a){var b;c.subarray=c.slice;b=(new ub(c)).i();a||(a={});return a.noBuffer?b:Db(b)}function zb(c,a,b){process.nextTick(function(){var e,f;try{f=Ab(c,b)}catch(d){e=d}a(e,f)})}function Ab(c,a){var b;c.subarray=c.slice;b=(new Ha(c)).h();a||(a={});return a.G?b:Db(b)}function Bb(c,a,b){process.nextTick(function(){var e,f;try{f=Cb(c,b)}catch(d){e=d}a(e,f)})}function Cb(c,a){var b;c.subarray=c.slice;b=(new tb(c)).i();a||(a={});return a.G?b:Db(b)} function Db(c){var a=new Buffer(c.length),b,e;b=0;for(e=c.length;b=$?8:255>=$?9:279>=$?7:8;T(Jb);var Lb=new (B?Uint8Array:Array)(30),Mb,Nb;Mb=0;for(Nb=Lb.length;Mb= 0; i--) { if (ka[i] != kb[i]) return false; } //equivalent values for every corresponding key, and //~~~possibly expensive deep test for (i = ka.length - 1; i >= 0; i--) { key = ka[i]; if (!_deepEqual(a[key], b[key])) return false; } return true; } // 8. The non-equivalence assertion tests for any deep inequality. // assert.notDeepEqual(actual, expected, message_opt); assert.notDeepEqual = function notDeepEqual(actual, expected, message) { if (_deepEqual(actual, expected)) { fail(actual, expected, message, 'notDeepEqual', assert.notDeepEqual); } }; // 9. The strict equality assertion tests strict equality, as determined by ===. // assert.strictEqual(actual, expected, message_opt); assert.strictEqual = function strictEqual(actual, expected, message) { if (actual !== expected) { fail(actual, expected, message, '===', assert.strictEqual); } }; // 10. The strict non-equality assertion tests for strict inequality, as // determined by !==. assert.notStrictEqual(actual, expected, message_opt); assert.notStrictEqual = function notStrictEqual(actual, expected, message) { if (actual === expected) { fail(actual, expected, message, '!==', assert.notStrictEqual); } }; function expectedException(actual, expected) { if (!actual || !expected) { return false; } if (expected instanceof RegExp) { return expected.test(actual); } else if (actual instanceof expected) { return true; } else if (expected.call({}, actual) === true) { return true; } return false; } function _throws(shouldThrow, block, expected, message) { var actual; if (typeof expected === 'string') { message = expected; expected = null; } try { block(); } catch (e) { actual = e; } message = (expected && expected.name ? ' (' + expected.name + ').' : '.') + (message ? ' ' + message : '.'); if (shouldThrow && !actual) { fail('Missing expected exception' + message); } if (!shouldThrow && expectedException(actual, expected)) { fail('Got unwanted exception' + message); } if ((shouldThrow && actual && expected && !expectedException(actual, expected)) || (!shouldThrow && actual)) { throw actual; } } // 11. Expected to throw an error: // assert.throws(block, Error_opt, message_opt); assert.throws = function(block, /*optional*/error, /*optional*/message) { _throws.apply(this, [true].concat(pSlice.call(arguments))); }; // EXTENSION! This is annoying to write outside this module. assert.doesNotThrow = function(block, /*optional*/error, /*optional*/message) { _throws.apply(this, [false].concat(pSlice.call(arguments))); }; assert.ifError = function(err) { if (err) {throw err;}}; },{"util":2,"buffer":3}],2:[function(require,module,exports){ var events = require('events'); exports.isArray = isArray; exports.isDate = function(obj){return Object.prototype.toString.call(obj) === '[object Date]'}; exports.isRegExp = function(obj){return Object.prototype.toString.call(obj) === '[object RegExp]'}; exports.print = function () {}; exports.puts = function () {}; exports.debug = function() {}; exports.inspect = function(obj, showHidden, depth, colors) { var seen = []; var stylize = function(str, styleType) { // http://en.wikipedia.org/wiki/ANSI_escape_code#graphics var styles = { 'bold' : [1, 22], 'italic' : [3, 23], 'underline' : [4, 24], 'inverse' : [7, 27], 'white' : [37, 39], 'grey' : [90, 39], 'black' : [30, 39], 'blue' : [34, 39], 'cyan' : [36, 39], 'green' : [32, 39], 'magenta' : [35, 39], 'red' : [31, 39], 'yellow' : [33, 39] }; var style = { 'special': 'cyan', 'number': 'blue', 'boolean': 'yellow', 'undefined': 'grey', 'null': 'bold', 'string': 'green', 'date': 'magenta', // "name": intentionally not styling 'regexp': 'red' }[styleType]; if (style) { return '\033[' + styles[style][0] + 'm' + str + '\033[' + styles[style][1] + 'm'; } else { return str; } }; if (! colors) { stylize = function(str, styleType) { return str; }; } function format(value, recurseTimes) { // Provide a hook for user-specified inspect functions. // Check that value is an object with an inspect function on it if (value && typeof value.inspect === 'function' && // Filter out the util module, it's inspect function is special value !== exports && // Also filter out any prototype objects using the circular check. !(value.constructor && value.constructor.prototype === value)) { return value.inspect(recurseTimes); } // Primitive types cannot have properties switch (typeof value) { case 'undefined': return stylize('undefined', 'undefined'); case 'string': var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '') .replace(/'/g, "\\'") .replace(/\\"/g, '"') + '\''; return stylize(simple, 'string'); case 'number': return stylize('' + value, 'number'); case 'boolean': return stylize('' + value, 'boolean'); } // For some reason typeof null is "object", so special case here. if (value === null) { return stylize('null', 'null'); } // Look up the keys of the object. var visible_keys = Object_keys(value); var keys = showHidden ? Object_getOwnPropertyNames(value) : visible_keys; // Functions without properties can be shortcutted. if (typeof value === 'function' && keys.length === 0) { if (isRegExp(value)) { return stylize('' + value, 'regexp'); } else { var name = value.name ? ': ' + value.name : ''; return stylize('[Function' + name + ']', 'special'); } } // Dates without properties can be shortcutted if (isDate(value) && keys.length === 0) { return stylize(value.toUTCString(), 'date'); } var base, type, braces; // Determine the object type if (isArray(value)) { type = 'Array'; braces = ['[', ']']; } else { type = 'Object'; braces = ['{', '}']; } // Make functions say that they are functions if (typeof value === 'function') { var n = value.name ? ': ' + value.name : ''; base = (isRegExp(value)) ? ' ' + value : ' [Function' + n + ']'; } else { base = ''; } // Make dates with properties first say the date if (isDate(value)) { base = ' ' + value.toUTCString(); } if (keys.length === 0) { return braces[0] + base + braces[1]; } if (recurseTimes < 0) { if (isRegExp(value)) { return stylize('' + value, 'regexp'); } else { return stylize('[Object]', 'special'); } } seen.push(value); var output = keys.map(function(key) { var name, str; if (value.__lookupGetter__) { if (value.__lookupGetter__(key)) { if (value.__lookupSetter__(key)) { str = stylize('[Getter/Setter]', 'special'); } else { str = stylize('[Getter]', 'special'); } } else { if (value.__lookupSetter__(key)) { str = stylize('[Setter]', 'special'); } } } if (visible_keys.indexOf(key) < 0) { name = '[' + key + ']'; } if (!str) { if (seen.indexOf(value[key]) < 0) { if (recurseTimes === null) { str = format(value[key]); } else { str = format(value[key], recurseTimes - 1); } if (str.indexOf('\n') > -1) { if (isArray(value)) { str = str.split('\n').map(function(line) { return ' ' + line; }).join('\n').substr(2); } else { str = '\n' + str.split('\n').map(function(line) { return ' ' + line; }).join('\n'); } } } else { str = stylize('[Circular]', 'special'); } } if (typeof name === 'undefined') { if (type === 'Array' && key.match(/^\d+$/)) { return str; } name = JSON.stringify('' + key); if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) { name = name.substr(1, name.length - 2); name = stylize(name, 'name'); } else { name = name.replace(/'/g, "\\'") .replace(/\\"/g, '"') .replace(/(^"|"$)/g, "'"); name = stylize(name, 'string'); } } return name + ': ' + str; }); seen.pop(); var numLinesEst = 0; var length = output.reduce(function(prev, cur) { numLinesEst++; if (cur.indexOf('\n') >= 0) numLinesEst++; return prev + cur.length + 1; }, 0); if (length > 50) { output = braces[0] + (base === '' ? '' : base + '\n ') + ' ' + output.join(',\n ') + ' ' + braces[1]; } else { output = braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1]; } return output; } return format(obj, (typeof depth === 'undefined' ? 2 : depth)); }; function isArray(ar) { return ar instanceof Array || Array.isArray(ar) || (ar && ar !== Object.prototype && isArray(ar.__proto__)); } function isRegExp(re) { return re instanceof RegExp || (typeof re === 'object' && Object.prototype.toString.call(re) === '[object RegExp]'); } function isDate(d) { if (d instanceof Date) return true; if (typeof d !== 'object') return false; var properties = Date.prototype && Object_getOwnPropertyNames(Date.prototype); var proto = d.__proto__ && Object_getOwnPropertyNames(d.__proto__); return JSON.stringify(proto) === JSON.stringify(properties); } function pad(n) { return n < 10 ? '0' + n.toString(10) : n.toString(10); } var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; // 26 Feb 16:19:34 function timestamp() { var d = new Date(); var time = [pad(d.getHours()), pad(d.getMinutes()), pad(d.getSeconds())].join(':'); return [d.getDate(), months[d.getMonth()], time].join(' '); } exports.log = function (msg) {}; exports.pump = null; var Object_keys = Object.keys || function (obj) { var res = []; for (var key in obj) res.push(key); return res; }; var Object_getOwnPropertyNames = Object.getOwnPropertyNames || function (obj) { var res = []; for (var key in obj) { if (Object.hasOwnProperty.call(obj, key)) res.push(key); } return res; }; var Object_create = Object.create || function (prototype, properties) { // from es5-shim var object; if (prototype === null) { object = { '__proto__' : null }; } else { if (typeof prototype !== 'object') { throw new TypeError( 'typeof prototype[' + (typeof prototype) + '] != \'object\'' ); } var Type = function () {}; Type.prototype = prototype; object = new Type(); object.__proto__ = prototype; } if (typeof properties !== 'undefined' && Object.defineProperties) { Object.defineProperties(object, properties); } return object; }; exports.inherits = function(ctor, superCtor) { ctor.super_ = superCtor; ctor.prototype = Object_create(superCtor.prototype, { constructor: { value: ctor, enumerable: false, writable: true, configurable: true } }); }; var formatRegExp = /%[sdj%]/g; exports.format = function(f) { if (typeof f !== 'string') { var objects = []; for (var i = 0; i < arguments.length; i++) { objects.push(exports.inspect(arguments[i])); } return objects.join(' '); } var i = 1; var args = arguments; var len = args.length; var str = String(f).replace(formatRegExp, function(x) { if (x === '%%') return '%'; if (i >= len) return x; switch (x) { case '%s': return String(args[i++]); case '%d': return Number(args[i++]); case '%j': return JSON.stringify(args[i++]); default: return x; } }); for(var x = args[i]; i < len; x = args[++i]){ if (x === null || typeof x !== 'object') { str += ' ' + x; } else { str += ' ' + exports.inspect(x); } } return str; }; },{"events":4}],5:[function(require,module,exports){ exports.readIEEE754 = function(buffer, offset, isBE, mLen, nBytes) { var e, m, eLen = nBytes * 8 - mLen - 1, eMax = (1 << eLen) - 1, eBias = eMax >> 1, nBits = -7, i = isBE ? 0 : (nBytes - 1), d = isBE ? 1 : -1, s = buffer[offset + i]; i += d; e = s & ((1 << (-nBits)) - 1); s >>= (-nBits); nBits += eLen; for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8); m = e & ((1 << (-nBits)) - 1); e >>= (-nBits); nBits += mLen; for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8); if (e === 0) { e = 1 - eBias; } else if (e === eMax) { return m ? NaN : ((s ? -1 : 1) * Infinity); } else { m = m + Math.pow(2, mLen); e = e - eBias; } return (s ? -1 : 1) * m * Math.pow(2, e - mLen); }; exports.writeIEEE754 = function(buffer, value, offset, isBE, mLen, nBytes) { var e, m, c, eLen = nBytes * 8 - mLen - 1, eMax = (1 << eLen) - 1, eBias = eMax >> 1, rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0), i = isBE ? (nBytes - 1) : 0, d = isBE ? -1 : 1, s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0; value = Math.abs(value); if (isNaN(value) || value === Infinity) { m = isNaN(value) ? 1 : 0; e = eMax; } else { e = Math.floor(Math.log(value) / Math.LN2); if (value * (c = Math.pow(2, -e)) < 1) { e--; c *= 2; } if (e + eBias >= 1) { value += rt / c; } else { value += rt * Math.pow(2, 1 - eBias); } if (value * c >= 2) { e++; c /= 2; } if (e + eBias >= eMax) { m = 0; e = eMax; } else if (e + eBias >= 1) { m = (value * c - 1) * Math.pow(2, mLen); e = e + eBias; } else { m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen); e = 0; } } for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8); e = (e << mLen) | m; eLen += mLen; for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8); buffer[offset + i - d] |= s * 128; }; },{}],6:[function(require,module,exports){ // shim for using process in browser var process = module.exports = {}; process.nextTick = (function () { var canSetImmediate = typeof window !== 'undefined' && window.setImmediate; var canPost = typeof window !== 'undefined' && window.postMessage && window.addEventListener ; if (canSetImmediate) { return function (f) { return window.setImmediate(f) }; } if (canPost) { var queue = []; window.addEventListener('message', function (ev) { if (ev.source === window && ev.data === 'process-tick') { ev.stopPropagation(); if (queue.length > 0) { var fn = queue.shift(); fn(); } } }, true); return function nextTick(fn) { queue.push(fn); window.postMessage('process-tick', '*'); }; } return function nextTick(fn) { setTimeout(fn, 0); }; })(); process.title = 'browser'; process.browser = true; process.env = {}; process.argv = []; process.binding = function (name) { throw new Error('process.binding is not supported'); } // TODO(shtylman) process.cwd = function () { return '/' }; process.chdir = function (dir) { throw new Error('process.chdir is not supported'); }; },{}],4:[function(require,module,exports){ (function(process){if (!process.EventEmitter) process.EventEmitter = function () {}; var EventEmitter = exports.EventEmitter = process.EventEmitter; var isArray = typeof Array.isArray === 'function' ? Array.isArray : function (xs) { return Object.prototype.toString.call(xs) === '[object Array]' } ; function indexOf (xs, x) { if (xs.indexOf) return xs.indexOf(x); for (var i = 0; i < xs.length; i++) { if (x === xs[i]) return i; } return -1; } // By default EventEmitters will print a warning if more than // 10 listeners are added to it. This is a useful default which // helps finding memory leaks. // // Obviously not all Emitters should be limited to 10. This function allows // that to be increased. Set to zero for unlimited. var defaultMaxListeners = 10; EventEmitter.prototype.setMaxListeners = function(n) { if (!this._events) this._events = {}; this._events.maxListeners = n; }; EventEmitter.prototype.emit = function(type) { // If there is no 'error' event listener then throw. if (type === 'error') { if (!this._events || !this._events.error || (isArray(this._events.error) && !this._events.error.length)) { if (arguments[1] instanceof Error) { throw arguments[1]; // Unhandled 'error' event } else { throw new Error("Uncaught, unspecified 'error' event."); } return false; } } if (!this._events) return false; var handler = this._events[type]; if (!handler) return false; if (typeof handler == 'function') { switch (arguments.length) { // fast cases case 1: handler.call(this); break; case 2: handler.call(this, arguments[1]); break; case 3: handler.call(this, arguments[1], arguments[2]); break; // slower default: var args = Array.prototype.slice.call(arguments, 1); handler.apply(this, args); } return true; } else if (isArray(handler)) { var args = Array.prototype.slice.call(arguments, 1); var listeners = handler.slice(); for (var i = 0, l = listeners.length; i < l; i++) { listeners[i].apply(this, args); } return true; } else { return false; } }; // EventEmitter is defined in src/node_events.cc // EventEmitter.prototype.emit() is also defined there. EventEmitter.prototype.addListener = function(type, listener) { if ('function' !== typeof listener) { throw new Error('addListener only takes instances of Function'); } if (!this._events) this._events = {}; // To avoid recursion in the case that type == "newListeners"! Before // adding it to the listeners, first emit "newListeners". this.emit('newListener', type, listener); if (!this._events[type]) { // Optimize the case of one listener. Don't need the extra array object. this._events[type] = listener; } else if (isArray(this._events[type])) { // Check for listener leak if (!this._events[type].warned) { var m; if (this._events.maxListeners !== undefined) { m = this._events.maxListeners; } else { m = defaultMaxListeners; } if (m && m > 0 && this._events[type].length > m) { this._events[type].warned = true; console.error('(node) warning: possible EventEmitter memory ' + 'leak detected. %d listeners added. ' + 'Use emitter.setMaxListeners() to increase limit.', this._events[type].length); console.trace(); } } // If we've already got an array, just append. this._events[type].push(listener); } else { // Adding the second element, need to change to array. this._events[type] = [this._events[type], listener]; } return this; }; EventEmitter.prototype.on = EventEmitter.prototype.addListener; EventEmitter.prototype.once = function(type, listener) { var self = this; self.on(type, function g() { self.removeListener(type, g); listener.apply(this, arguments); }); return this; }; EventEmitter.prototype.removeListener = function(type, listener) { if ('function' !== typeof listener) { throw new Error('removeListener only takes instances of Function'); } // does not use listeners(), so no side effect of creating _events[type] if (!this._events || !this._events[type]) return this; var list = this._events[type]; if (isArray(list)) { var i = indexOf(list, listener); if (i < 0) return this; list.splice(i, 1); if (list.length == 0) delete this._events[type]; } else if (this._events[type] === listener) { delete this._events[type]; } return this; }; EventEmitter.prototype.removeAllListeners = function(type) { if (arguments.length === 0) { this._events = {}; return this; } // does not use listeners(), so no side effect of creating _events[type] if (type && this._events && this._events[type]) this._events[type] = null; return this; }; EventEmitter.prototype.listeners = function(type) { if (!this._events) this._events = {}; if (!this._events[type]) this._events[type] = []; if (!isArray(this._events[type])) { this._events[type] = [this._events[type]]; } return this._events[type]; }; })(require("__browserify_process")) },{"__browserify_process":6}],"buffer-browserify":[function(require,module,exports){ module.exports=require('q9TxCC'); },{}],"q9TxCC":[function(require,module,exports){ function SlowBuffer (size) { this.length = size; }; var assert = require('assert'); exports.INSPECT_MAX_BYTES = 50; function toHex(n) { if (n < 16) return '0' + n.toString(16); return n.toString(16); } function utf8ToBytes(str) { var byteArray = []; for (var i = 0; i < str.length; i++) if (str.charCodeAt(i) <= 0x7F) byteArray.push(str.charCodeAt(i)); else { var h = encodeURIComponent(str.charAt(i)).substr(1).split('%'); for (var j = 0; j < h.length; j++) byteArray.push(parseInt(h[j], 16)); } return byteArray; } function asciiToBytes(str) { var byteArray = [] for (var i = 0; i < str.length; i++ ) // Node's code seems to be doing this and not & 0x7F.. byteArray.push( str.charCodeAt(i) & 0xFF ); return byteArray; } function base64ToBytes(str) { return require("base64-js").toByteArray(str); } SlowBuffer.byteLength = function (str, encoding) { switch (encoding || "utf8") { case 'hex': return str.length / 2; case 'utf8': case 'utf-8': return utf8ToBytes(str).length; case 'ascii': case 'binary': return str.length; case 'base64': return base64ToBytes(str).length; default: throw new Error('Unknown encoding'); } }; function blitBuffer(src, dst, offset, length) { var pos, i = 0; while (i < length) { if ((i+offset >= dst.length) || (i >= src.length)) break; dst[i + offset] = src[i]; i++; } return i; } SlowBuffer.prototype.utf8Write = function (string, offset, length) { var bytes, pos; return SlowBuffer._charsWritten = blitBuffer(utf8ToBytes(string), this, offset, length); }; SlowBuffer.prototype.asciiWrite = function (string, offset, length) { var bytes, pos; return SlowBuffer._charsWritten = blitBuffer(asciiToBytes(string), this, offset, length); }; SlowBuffer.prototype.binaryWrite = SlowBuffer.prototype.asciiWrite; SlowBuffer.prototype.base64Write = function (string, offset, length) { var bytes, pos; return SlowBuffer._charsWritten = blitBuffer(base64ToBytes(string), this, offset, length); }; SlowBuffer.prototype.base64Slice = function (start, end) { var bytes = Array.prototype.slice.apply(this, arguments) return require("base64-js").fromByteArray(bytes); } function decodeUtf8Char(str) { try { return decodeURIComponent(str); } catch (err) { return String.fromCharCode(0xFFFD); // UTF 8 invalid char } } SlowBuffer.prototype.utf8Slice = function () { var bytes = Array.prototype.slice.apply(this, arguments); var res = ""; var tmp = ""; var i = 0; while (i < bytes.length) { if (bytes[i] <= 0x7F) { res += decodeUtf8Char(tmp) + String.fromCharCode(bytes[i]); tmp = ""; } else tmp += "%" + bytes[i].toString(16); i++; } return res + decodeUtf8Char(tmp); } SlowBuffer.prototype.asciiSlice = function () { var bytes = Array.prototype.slice.apply(this, arguments); var ret = ""; for (var i = 0; i < bytes.length; i++) ret += String.fromCharCode(bytes[i]); return ret; } SlowBuffer.prototype.binarySlice = SlowBuffer.prototype.asciiSlice; SlowBuffer.prototype.inspect = function() { var out = [], len = this.length; for (var i = 0; i < len; i++) { out[i] = toHex(this[i]); if (i == exports.INSPECT_MAX_BYTES) { out[i + 1] = '...'; break; } } return ''; }; SlowBuffer.prototype.hexSlice = function(start, end) { var len = this.length; if (!start || start < 0) start = 0; if (!end || end < 0 || end > len) end = len; var out = ''; for (var i = start; i < end; i++) { out += toHex(this[i]); } return out; }; SlowBuffer.prototype.toString = function(encoding, start, end) { encoding = String(encoding || 'utf8').toLowerCase(); start = +start || 0; if (typeof end == 'undefined') end = this.length; // Fastpath empty strings if (+end == start) { return ''; } switch (encoding) { case 'hex': return this.hexSlice(start, end); case 'utf8': case 'utf-8': return this.utf8Slice(start, end); case 'ascii': return this.asciiSlice(start, end); case 'binary': return this.binarySlice(start, end); case 'base64': return this.base64Slice(start, end); case 'ucs2': case 'ucs-2': return this.ucs2Slice(start, end); default: throw new Error('Unknown encoding'); } }; SlowBuffer.prototype.hexWrite = function(string, offset, length) { offset = +offset || 0; var remaining = this.length - offset; if (!length) { length = remaining; } else { length = +length; if (length > remaining) { length = remaining; } } // must be an even number of digits var strLen = string.length; if (strLen % 2) { throw new Error('Invalid hex string'); } if (length > strLen / 2) { length = strLen / 2; } for (var i = 0; i < length; i++) { var byte = parseInt(string.substr(i * 2, 2), 16); if (isNaN(byte)) throw new Error('Invalid hex string'); this[offset + i] = byte; } SlowBuffer._charsWritten = i * 2; return i; }; SlowBuffer.prototype.write = function(string, offset, length, encoding) { // Support both (string, offset, length, encoding) // and the legacy (string, encoding, offset, length) if (isFinite(offset)) { if (!isFinite(length)) { encoding = length; length = undefined; } } else { // legacy var swap = encoding; encoding = offset; offset = length; length = swap; } offset = +offset || 0; var remaining = this.length - offset; if (!length) { length = remaining; } else { length = +length; if (length > remaining) { length = remaining; } } encoding = String(encoding || 'utf8').toLowerCase(); switch (encoding) { case 'hex': return this.hexWrite(string, offset, length); case 'utf8': case 'utf-8': return this.utf8Write(string, offset, length); case 'ascii': return this.asciiWrite(string, offset, length); case 'binary': return this.binaryWrite(string, offset, length); case 'base64': return this.base64Write(string, offset, length); case 'ucs2': case 'ucs-2': return this.ucs2Write(string, offset, length); default: throw new Error('Unknown encoding'); } }; // slice(start, end) SlowBuffer.prototype.slice = function(start, end) { if (end === undefined) end = this.length; if (end > this.length) { throw new Error('oob'); } if (start > end) { throw new Error('oob'); } return new Buffer(this, end - start, +start); }; SlowBuffer.prototype.copy = function(target, targetstart, sourcestart, sourceend) { var temp = []; for (var i=sourcestart; i this.length) { throw new Error('oob'); } if (start > end) { throw new Error('oob'); } for (var i = start; i < end; i++) { this[i] = value; } } function coerce(length) { // Coerce length to a number (possibly NaN), round up // in case it's fractional (e.g. 123.456) then do a // double negate to coerce a NaN to 0. Easy, right? length = ~~Math.ceil(+length); return length < 0 ? 0 : length; } // Buffer function Buffer(subject, encoding, offset) { if (!(this instanceof Buffer)) { return new Buffer(subject, encoding, offset); } var type; // Are we slicing? if (typeof offset === 'number') { this.length = coerce(encoding); this.parent = subject; this.offset = offset; } else { // Find the length switch (type = typeof subject) { case 'number': this.length = coerce(subject); break; case 'string': this.length = Buffer.byteLength(subject, encoding); break; case 'object': // Assume object is an array this.length = coerce(subject.length); break; default: throw new Error('First argument needs to be a number, ' + 'array or string.'); } if (this.length > Buffer.poolSize) { // Big buffer, just alloc one. this.parent = new SlowBuffer(this.length); this.offset = 0; } else { // Small buffer. if (!pool || pool.length - pool.used < this.length) allocPool(); this.parent = pool; this.offset = pool.used; pool.used += this.length; } // Treat array-ish objects as a byte array. if (isArrayIsh(subject)) { for (var i = 0; i < this.length; i++) { if (subject instanceof Buffer) { this.parent[i + this.offset] = subject.readUInt8(i); } else { this.parent[i + this.offset] = subject[i]; } } } else if (type == 'string') { // We are a string this.length = this.write(subject, 0, encoding); } } } function isArrayIsh(subject) { return Array.isArray(subject) || Buffer.isBuffer(subject) || subject && typeof subject === 'object' && typeof subject.length === 'number'; } exports.SlowBuffer = SlowBuffer; exports.Buffer = Buffer; Buffer.poolSize = 8 * 1024; var pool; function allocPool() { pool = new SlowBuffer(Buffer.poolSize); pool.used = 0; } // Static methods Buffer.isBuffer = function isBuffer(b) { return b instanceof Buffer || b instanceof SlowBuffer; }; Buffer.concat = function (list, totalLength) { if (!Array.isArray(list)) { throw new Error("Usage: Buffer.concat(list, [totalLength])\n \ list should be an Array."); } if (list.length === 0) { return new Buffer(0); } else if (list.length === 1) { return list[0]; } if (typeof totalLength !== 'number') { totalLength = 0; for (var i = 0; i < list.length; i++) { var buf = list[i]; totalLength += buf.length; } } var buffer = new Buffer(totalLength); var pos = 0; for (var i = 0; i < list.length; i++) { var buf = list[i]; buf.copy(buffer, pos); pos += buf.length; } return buffer; }; // Inspect Buffer.prototype.inspect = function inspect() { var out = [], len = this.length; for (var i = 0; i < len; i++) { out[i] = toHex(this.parent[i + this.offset]); if (i == exports.INSPECT_MAX_BYTES) { out[i + 1] = '...'; break; } } return ''; }; Buffer.prototype.get = function get(i) { if (i < 0 || i >= this.length) throw new Error('oob'); return this.parent[this.offset + i]; }; Buffer.prototype.set = function set(i, v) { if (i < 0 || i >= this.length) throw new Error('oob'); return this.parent[this.offset + i] = v; }; // write(string, offset = 0, length = buffer.length-offset, encoding = 'utf8') Buffer.prototype.write = function(string, offset, length, encoding) { // Support both (string, offset, length, encoding) // and the legacy (string, encoding, offset, length) if (isFinite(offset)) { if (!isFinite(length)) { encoding = length; length = undefined; } } else { // legacy var swap = encoding; encoding = offset; offset = length; length = swap; } offset = +offset || 0; var remaining = this.length - offset; if (!length) { length = remaining; } else { length = +length; if (length > remaining) { length = remaining; } } encoding = String(encoding || 'utf8').toLowerCase(); var ret; switch (encoding) { case 'hex': ret = this.parent.hexWrite(string, this.offset + offset, length); break; case 'utf8': case 'utf-8': ret = this.parent.utf8Write(string, this.offset + offset, length); break; case 'ascii': ret = this.parent.asciiWrite(string, this.offset + offset, length); break; case 'binary': ret = this.parent.binaryWrite(string, this.offset + offset, length); break; case 'base64': // Warning: maxLength not taken into account in base64Write ret = this.parent.base64Write(string, this.offset + offset, length); break; case 'ucs2': case 'ucs-2': ret = this.parent.ucs2Write(string, this.offset + offset, length); break; default: throw new Error('Unknown encoding'); } Buffer._charsWritten = SlowBuffer._charsWritten; return ret; }; // toString(encoding, start=0, end=buffer.length) Buffer.prototype.toString = function(encoding, start, end) { encoding = String(encoding || 'utf8').toLowerCase(); if (typeof start == 'undefined' || start < 0) { start = 0; } else if (start > this.length) { start = this.length; } if (typeof end == 'undefined' || end > this.length) { end = this.length; } else if (end < 0) { end = 0; } start = start + this.offset; end = end + this.offset; switch (encoding) { case 'hex': return this.parent.hexSlice(start, end); case 'utf8': case 'utf-8': return this.parent.utf8Slice(start, end); case 'ascii': return this.parent.asciiSlice(start, end); case 'binary': return this.parent.binarySlice(start, end); case 'base64': return this.parent.base64Slice(start, end); case 'ucs2': case 'ucs-2': return this.parent.ucs2Slice(start, end); default: throw new Error('Unknown encoding'); } }; // byteLength Buffer.byteLength = SlowBuffer.byteLength; // fill(value, start=0, end=buffer.length) Buffer.prototype.fill = function fill(value, start, end) { value || (value = 0); start || (start = 0); end || (end = this.length); if (typeof value === 'string') { value = value.charCodeAt(0); } if (!(typeof value === 'number') || isNaN(value)) { throw new Error('value is not a number'); } if (end < start) throw new Error('end < start'); // Fill 0 bytes; we're done if (end === start) return 0; if (this.length == 0) return 0; if (start < 0 || start >= this.length) { throw new Error('start out of bounds'); } if (end < 0 || end > this.length) { throw new Error('end out of bounds'); } return this.parent.fill(value, start + this.offset, end + this.offset); }; // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length) Buffer.prototype.copy = function(target, target_start, start, end) { var source = this; start || (start = 0); end || (end = this.length); target_start || (target_start = 0); if (end < start) throw new Error('sourceEnd < sourceStart'); // Copy 0 bytes; we're done if (end === start) return 0; if (target.length == 0 || source.length == 0) return 0; if (target_start < 0 || target_start >= target.length) { throw new Error('targetStart out of bounds'); } if (start < 0 || start >= source.length) { throw new Error('sourceStart out of bounds'); } if (end < 0 || end > source.length) { throw new Error('sourceEnd out of bounds'); } // Are we oob? if (end > this.length) { end = this.length; } if (target.length - target_start < end - start) { end = target.length - target_start + start; } return this.parent.copy(target.parent, target_start + target.offset, start + this.offset, end + this.offset); }; // slice(start, end) Buffer.prototype.slice = function(start, end) { if (end === undefined) end = this.length; if (end > this.length) throw new Error('oob'); if (start > end) throw new Error('oob'); return new Buffer(this.parent, end - start, +start + this.offset); }; // Legacy methods for backwards compatibility. Buffer.prototype.utf8Slice = function(start, end) { return this.toString('utf8', start, end); }; Buffer.prototype.binarySlice = function(start, end) { return this.toString('binary', start, end); }; Buffer.prototype.asciiSlice = function(start, end) { return this.toString('ascii', start, end); }; Buffer.prototype.utf8Write = function(string, offset) { return this.write(string, offset, 'utf8'); }; Buffer.prototype.binaryWrite = function(string, offset) { return this.write(string, offset, 'binary'); }; Buffer.prototype.asciiWrite = function(string, offset) { return this.write(string, offset, 'ascii'); }; Buffer.prototype.readUInt8 = function(offset, noAssert) { var buffer = this; if (!noAssert) { assert.ok(offset !== undefined && offset !== null, 'missing offset'); assert.ok(offset < buffer.length, 'Trying to read beyond buffer length'); } if (offset >= buffer.length) return; return buffer.parent[buffer.offset + offset]; }; function readUInt16(buffer, offset, isBigEndian, noAssert) { var val = 0; if (!noAssert) { assert.ok(typeof (isBigEndian) === 'boolean', 'missing or invalid endian'); assert.ok(offset !== undefined && offset !== null, 'missing offset'); assert.ok(offset + 1 < buffer.length, 'Trying to read beyond buffer length'); } if (offset >= buffer.length) return 0; if (isBigEndian) { val = buffer.parent[buffer.offset + offset] << 8; if (offset + 1 < buffer.length) { val |= buffer.parent[buffer.offset + offset + 1]; } } else { val = buffer.parent[buffer.offset + offset]; if (offset + 1 < buffer.length) { val |= buffer.parent[buffer.offset + offset + 1] << 8; } } return val; } Buffer.prototype.readUInt16LE = function(offset, noAssert) { return readUInt16(this, offset, false, noAssert); }; Buffer.prototype.readUInt16BE = function(offset, noAssert) { return readUInt16(this, offset, true, noAssert); }; function readUInt32(buffer, offset, isBigEndian, noAssert) { var val = 0; if (!noAssert) { assert.ok(typeof (isBigEndian) === 'boolean', 'missing or invalid endian'); assert.ok(offset !== undefined && offset !== null, 'missing offset'); assert.ok(offset + 3 < buffer.length, 'Trying to read beyond buffer length'); } if (offset >= buffer.length) return 0; if (isBigEndian) { if (offset + 1 < buffer.length) val = buffer.parent[buffer.offset + offset + 1] << 16; if (offset + 2 < buffer.length) val |= buffer.parent[buffer.offset + offset + 2] << 8; if (offset + 3 < buffer.length) val |= buffer.parent[buffer.offset + offset + 3]; val = val + (buffer.parent[buffer.offset + offset] << 24 >>> 0); } else { if (offset + 2 < buffer.length) val = buffer.parent[buffer.offset + offset + 2] << 16; if (offset + 1 < buffer.length) val |= buffer.parent[buffer.offset + offset + 1] << 8; val |= buffer.parent[buffer.offset + offset]; if (offset + 3 < buffer.length) val = val + (buffer.parent[buffer.offset + offset + 3] << 24 >>> 0); } return val; } Buffer.prototype.readUInt32LE = function(offset, noAssert) { return readUInt32(this, offset, false, noAssert); }; Buffer.prototype.readUInt32BE = function(offset, noAssert) { return readUInt32(this, offset, true, noAssert); }; /* * Signed integer types, yay team! A reminder on how two's complement actually * works. The first bit is the signed bit, i.e. tells us whether or not the * number should be positive or negative. If the two's complement value is * positive, then we're done, as it's equivalent to the unsigned representation. * * Now if the number is positive, you're pretty much done, you can just leverage * the unsigned translations and return those. Unfortunately, negative numbers * aren't quite that straightforward. * * At first glance, one might be inclined to use the traditional formula to * translate binary numbers between the positive and negative values in two's * complement. (Though it doesn't quite work for the most negative value) * Mainly: * - invert all the bits * - add one to the result * * Of course, this doesn't quite work in Javascript. Take for example the value * of -128. This could be represented in 16 bits (big-endian) as 0xff80. But of * course, Javascript will do the following: * * > ~0xff80 * -65409 * * Whoh there, Javascript, that's not quite right. But wait, according to * Javascript that's perfectly correct. When Javascript ends up seeing the * constant 0xff80, it has no notion that it is actually a signed number. It * assumes that we've input the unsigned value 0xff80. Thus, when it does the * binary negation, it casts it into a signed value, (positive 0xff80). Then * when you perform binary negation on that, it turns it into a negative number. * * Instead, we're going to have to use the following general formula, that works * in a rather Javascript friendly way. I'm glad we don't support this kind of * weird numbering scheme in the kernel. * * (BIT-MAX - (unsigned)val + 1) * -1 * * The astute observer, may think that this doesn't make sense for 8-bit numbers * (really it isn't necessary for them). However, when you get 16-bit numbers, * you do. Let's go back to our prior example and see how this will look: * * (0xffff - 0xff80 + 1) * -1 * (0x007f + 1) * -1 * (0x0080) * -1 */ Buffer.prototype.readInt8 = function(offset, noAssert) { var buffer = this; var neg; if (!noAssert) { assert.ok(offset !== undefined && offset !== null, 'missing offset'); assert.ok(offset < buffer.length, 'Trying to read beyond buffer length'); } if (offset >= buffer.length) return; neg = buffer.parent[buffer.offset + offset] & 0x80; if (!neg) { return (buffer.parent[buffer.offset + offset]); } return ((0xff - buffer.parent[buffer.offset + offset] + 1) * -1); }; function readInt16(buffer, offset, isBigEndian, noAssert) { var neg, val; if (!noAssert) { assert.ok(typeof (isBigEndian) === 'boolean', 'missing or invalid endian'); assert.ok(offset !== undefined && offset !== null, 'missing offset'); assert.ok(offset + 1 < buffer.length, 'Trying to read beyond buffer length'); } val = readUInt16(buffer, offset, isBigEndian, noAssert); neg = val & 0x8000; if (!neg) { return val; } return (0xffff - val + 1) * -1; } Buffer.prototype.readInt16LE = function(offset, noAssert) { return readInt16(this, offset, false, noAssert); }; Buffer.prototype.readInt16BE = function(offset, noAssert) { return readInt16(this, offset, true, noAssert); }; function readInt32(buffer, offset, isBigEndian, noAssert) { var neg, val; if (!noAssert) { assert.ok(typeof (isBigEndian) === 'boolean', 'missing or invalid endian'); assert.ok(offset !== undefined && offset !== null, 'missing offset'); assert.ok(offset + 3 < buffer.length, 'Trying to read beyond buffer length'); } val = readUInt32(buffer, offset, isBigEndian, noAssert); neg = val & 0x80000000; if (!neg) { return (val); } return (0xffffffff - val + 1) * -1; } Buffer.prototype.readInt32LE = function(offset, noAssert) { return readInt32(this, offset, false, noAssert); }; Buffer.prototype.readInt32BE = function(offset, noAssert) { return readInt32(this, offset, true, noAssert); }; function readFloat(buffer, offset, isBigEndian, noAssert) { if (!noAssert) { assert.ok(typeof (isBigEndian) === 'boolean', 'missing or invalid endian'); assert.ok(offset + 3 < buffer.length, 'Trying to read beyond buffer length'); } return require('./buffer_ieee754').readIEEE754(buffer, offset, isBigEndian, 23, 4); } Buffer.prototype.readFloatLE = function(offset, noAssert) { return readFloat(this, offset, false, noAssert); }; Buffer.prototype.readFloatBE = function(offset, noAssert) { return readFloat(this, offset, true, noAssert); }; function readDouble(buffer, offset, isBigEndian, noAssert) { if (!noAssert) { assert.ok(typeof (isBigEndian) === 'boolean', 'missing or invalid endian'); assert.ok(offset + 7 < buffer.length, 'Trying to read beyond buffer length'); } return require('./buffer_ieee754').readIEEE754(buffer, offset, isBigEndian, 52, 8); } Buffer.prototype.readDoubleLE = function(offset, noAssert) { return readDouble(this, offset, false, noAssert); }; Buffer.prototype.readDoubleBE = function(offset, noAssert) { return readDouble(this, offset, true, noAssert); }; /* * We have to make sure that the value is a valid integer. This means that it is * non-negative. It has no fractional component and that it does not exceed the * maximum allowed value. * * value The number to check for validity * * max The maximum value */ function verifuint(value, max) { assert.ok(typeof (value) == 'number', 'cannot write a non-number as a number'); assert.ok(value >= 0, 'specified a negative value for writing an unsigned value'); assert.ok(value <= max, 'value is larger than maximum value for type'); assert.ok(Math.floor(value) === value, 'value has a fractional component'); } Buffer.prototype.writeUInt8 = function(value, offset, noAssert) { var buffer = this; if (!noAssert) { assert.ok(value !== undefined && value !== null, 'missing value'); assert.ok(offset !== undefined && offset !== null, 'missing offset'); assert.ok(offset < buffer.length, 'trying to write beyond buffer length'); verifuint(value, 0xff); } if (offset < buffer.length) { buffer.parent[buffer.offset + offset] = value; } }; function writeUInt16(buffer, value, offset, isBigEndian, noAssert) { if (!noAssert) { assert.ok(value !== undefined && value !== null, 'missing value'); assert.ok(typeof (isBigEndian) === 'boolean', 'missing or invalid endian'); assert.ok(offset !== undefined && offset !== null, 'missing offset'); assert.ok(offset + 1 < buffer.length, 'trying to write beyond buffer length'); verifuint(value, 0xffff); } for (var i = 0; i < Math.min(buffer.length - offset, 2); i++) { buffer.parent[buffer.offset + offset + i] = (value & (0xff << (8 * (isBigEndian ? 1 - i : i)))) >>> (isBigEndian ? 1 - i : i) * 8; } } Buffer.prototype.writeUInt16LE = function(value, offset, noAssert) { writeUInt16(this, value, offset, false, noAssert); }; Buffer.prototype.writeUInt16BE = function(value, offset, noAssert) { writeUInt16(this, value, offset, true, noAssert); }; function writeUInt32(buffer, value, offset, isBigEndian, noAssert) { if (!noAssert) { assert.ok(value !== undefined && value !== null, 'missing value'); assert.ok(typeof (isBigEndian) === 'boolean', 'missing or invalid endian'); assert.ok(offset !== undefined && offset !== null, 'missing offset'); assert.ok(offset + 3 < buffer.length, 'trying to write beyond buffer length'); verifuint(value, 0xffffffff); } for (var i = 0; i < Math.min(buffer.length - offset, 4); i++) { buffer.parent[buffer.offset + offset + i] = (value >>> (isBigEndian ? 3 - i : i) * 8) & 0xff; } } Buffer.prototype.writeUInt32LE = function(value, offset, noAssert) { writeUInt32(this, value, offset, false, noAssert); }; Buffer.prototype.writeUInt32BE = function(value, offset, noAssert) { writeUInt32(this, value, offset, true, noAssert); }; /* * We now move onto our friends in the signed number category. Unlike unsigned * numbers, we're going to have to worry a bit more about how we put values into * arrays. Since we are only worrying about signed 32-bit values, we're in * slightly better shape. Unfortunately, we really can't do our favorite binary * & in this system. It really seems to do the wrong thing. For example: * * > -32 & 0xff * 224 * * What's happening above is really: 0xe0 & 0xff = 0xe0. However, the results of * this aren't treated as a signed number. Ultimately a bad thing. * * What we're going to want to do is basically create the unsigned equivalent of * our representation and pass that off to the wuint* functions. To do that * we're going to do the following: * * - if the value is positive * we can pass it directly off to the equivalent wuint * - if the value is negative * we do the following computation: * mb + val + 1, where * mb is the maximum unsigned value in that byte size * val is the Javascript negative integer * * * As a concrete value, take -128. In signed 16 bits this would be 0xff80. If * you do out the computations: * * 0xffff - 128 + 1 * 0xffff - 127 * 0xff80 * * You can then encode this value as the signed version. This is really rather * hacky, but it should work and get the job done which is our goal here. */ /* * A series of checks to make sure we actually have a signed 32-bit number */ function verifsint(value, max, min) { assert.ok(typeof (value) == 'number', 'cannot write a non-number as a number'); assert.ok(value <= max, 'value larger than maximum allowed value'); assert.ok(value >= min, 'value smaller than minimum allowed value'); assert.ok(Math.floor(value) === value, 'value has a fractional component'); } function verifIEEE754(value, max, min) { assert.ok(typeof (value) == 'number', 'cannot write a non-number as a number'); assert.ok(value <= max, 'value larger than maximum allowed value'); assert.ok(value >= min, 'value smaller than minimum allowed value'); } Buffer.prototype.writeInt8 = function(value, offset, noAssert) { var buffer = this; if (!noAssert) { assert.ok(value !== undefined && value !== null, 'missing value'); assert.ok(offset !== undefined && offset !== null, 'missing offset'); assert.ok(offset < buffer.length, 'Trying to write beyond buffer length'); verifsint(value, 0x7f, -0x80); } if (value >= 0) { buffer.writeUInt8(value, offset, noAssert); } else { buffer.writeUInt8(0xff + value + 1, offset, noAssert); } }; function writeInt16(buffer, value, offset, isBigEndian, noAssert) { if (!noAssert) { assert.ok(value !== undefined && value !== null, 'missing value'); assert.ok(typeof (isBigEndian) === 'boolean', 'missing or invalid endian'); assert.ok(offset !== undefined && offset !== null, 'missing offset'); assert.ok(offset + 1 < buffer.length, 'Trying to write beyond buffer length'); verifsint(value, 0x7fff, -0x8000); } if (value >= 0) { writeUInt16(buffer, value, offset, isBigEndian, noAssert); } else { writeUInt16(buffer, 0xffff + value + 1, offset, isBigEndian, noAssert); } } Buffer.prototype.writeInt16LE = function(value, offset, noAssert) { writeInt16(this, value, offset, false, noAssert); }; Buffer.prototype.writeInt16BE = function(value, offset, noAssert) { writeInt16(this, value, offset, true, noAssert); }; function writeInt32(buffer, value, offset, isBigEndian, noAssert) { if (!noAssert) { assert.ok(value !== undefined && value !== null, 'missing value'); assert.ok(typeof (isBigEndian) === 'boolean', 'missing or invalid endian'); assert.ok(offset !== undefined && offset !== null, 'missing offset'); assert.ok(offset + 3 < buffer.length, 'Trying to write beyond buffer length'); verifsint(value, 0x7fffffff, -0x80000000); } if (value >= 0) { writeUInt32(buffer, value, offset, isBigEndian, noAssert); } else { writeUInt32(buffer, 0xffffffff + value + 1, offset, isBigEndian, noAssert); } } Buffer.prototype.writeInt32LE = function(value, offset, noAssert) { writeInt32(this, value, offset, false, noAssert); }; Buffer.prototype.writeInt32BE = function(value, offset, noAssert) { writeInt32(this, value, offset, true, noAssert); }; function writeFloat(buffer, value, offset, isBigEndian, noAssert) { if (!noAssert) { assert.ok(value !== undefined && value !== null, 'missing value'); assert.ok(typeof (isBigEndian) === 'boolean', 'missing or invalid endian'); assert.ok(offset !== undefined && offset !== null, 'missing offset'); assert.ok(offset + 3 < buffer.length, 'Trying to write beyond buffer length'); verifIEEE754(value, 3.4028234663852886e+38, -3.4028234663852886e+38); } require('./buffer_ieee754').writeIEEE754(buffer, value, offset, isBigEndian, 23, 4); } Buffer.prototype.writeFloatLE = function(value, offset, noAssert) { writeFloat(this, value, offset, false, noAssert); }; Buffer.prototype.writeFloatBE = function(value, offset, noAssert) { writeFloat(this, value, offset, true, noAssert); }; function writeDouble(buffer, value, offset, isBigEndian, noAssert) { if (!noAssert) { assert.ok(value !== undefined && value !== null, 'missing value'); assert.ok(typeof (isBigEndian) === 'boolean', 'missing or invalid endian'); assert.ok(offset !== undefined && offset !== null, 'missing offset'); assert.ok(offset + 7 < buffer.length, 'Trying to write beyond buffer length'); verifIEEE754(value, 1.7976931348623157E+308, -1.7976931348623157E+308); } require('./buffer_ieee754').writeIEEE754(buffer, value, offset, isBigEndian, 52, 8); } Buffer.prototype.writeDoubleLE = function(value, offset, noAssert) { writeDouble(this, value, offset, false, noAssert); }; Buffer.prototype.writeDoubleBE = function(value, offset, noAssert) { writeDouble(this, value, offset, true, noAssert); }; SlowBuffer.prototype.readUInt8 = Buffer.prototype.readUInt8; SlowBuffer.prototype.readUInt16LE = Buffer.prototype.readUInt16LE; SlowBuffer.prototype.readUInt16BE = Buffer.prototype.readUInt16BE; SlowBuffer.prototype.readUInt32LE = Buffer.prototype.readUInt32LE; SlowBuffer.prototype.readUInt32BE = Buffer.prototype.readUInt32BE; SlowBuffer.prototype.readInt8 = Buffer.prototype.readInt8; SlowBuffer.prototype.readInt16LE = Buffer.prototype.readInt16LE; SlowBuffer.prototype.readInt16BE = Buffer.prototype.readInt16BE; SlowBuffer.prototype.readInt32LE = Buffer.prototype.readInt32LE; SlowBuffer.prototype.readInt32BE = Buffer.prototype.readInt32BE; SlowBuffer.prototype.readFloatLE = Buffer.prototype.readFloatLE; SlowBuffer.prototype.readFloatBE = Buffer.prototype.readFloatBE; SlowBuffer.prototype.readDoubleLE = Buffer.prototype.readDoubleLE; SlowBuffer.prototype.readDoubleBE = Buffer.prototype.readDoubleBE; SlowBuffer.prototype.writeUInt8 = Buffer.prototype.writeUInt8; SlowBuffer.prototype.writeUInt16LE = Buffer.prototype.writeUInt16LE; SlowBuffer.prototype.writeUInt16BE = Buffer.prototype.writeUInt16BE; SlowBuffer.prototype.writeUInt32LE = Buffer.prototype.writeUInt32LE; SlowBuffer.prototype.writeUInt32BE = Buffer.prototype.writeUInt32BE; SlowBuffer.prototype.writeInt8 = Buffer.prototype.writeInt8; SlowBuffer.prototype.writeInt16LE = Buffer.prototype.writeInt16LE; SlowBuffer.prototype.writeInt16BE = Buffer.prototype.writeInt16BE; SlowBuffer.prototype.writeInt32LE = Buffer.prototype.writeInt32LE; SlowBuffer.prototype.writeInt32BE = Buffer.prototype.writeInt32BE; SlowBuffer.prototype.writeFloatLE = Buffer.prototype.writeFloatLE; SlowBuffer.prototype.writeFloatBE = Buffer.prototype.writeFloatBE; SlowBuffer.prototype.writeDoubleLE = Buffer.prototype.writeDoubleLE; SlowBuffer.prototype.writeDoubleBE = Buffer.prototype.writeDoubleBE; },{"assert":1,"./buffer_ieee754":5,"base64-js":7}],7:[function(require,module,exports){ (function (exports) { 'use strict'; var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; function b64ToByteArray(b64) { var i, j, l, tmp, placeHolders, arr; if (b64.length % 4 > 0) { throw 'Invalid string. Length must be a multiple of 4'; } // the number of equal signs (place holders) // if there are two placeholders, than the two characters before it // represent one byte // if there is only one, then the three characters before it represent 2 bytes // this is just a cheap hack to not do indexOf twice placeHolders = b64.indexOf('='); placeHolders = placeHolders > 0 ? b64.length - placeHolders : 0; // base64 is 4/3 + up to two characters of the original data arr = [];//new Uint8Array(b64.length * 3 / 4 - placeHolders); // if there are placeholders, only get up to the last complete 4 chars l = placeHolders > 0 ? b64.length - 4 : b64.length; for (i = 0, j = 0; i < l; i += 4, j += 3) { tmp = (lookup.indexOf(b64[i]) << 18) | (lookup.indexOf(b64[i + 1]) << 12) | (lookup.indexOf(b64[i + 2]) << 6) | lookup.indexOf(b64[i + 3]); arr.push((tmp & 0xFF0000) >> 16); arr.push((tmp & 0xFF00) >> 8); arr.push(tmp & 0xFF); } if (placeHolders === 2) { tmp = (lookup.indexOf(b64[i]) << 2) | (lookup.indexOf(b64[i + 1]) >> 4); arr.push(tmp & 0xFF); } else if (placeHolders === 1) { tmp = (lookup.indexOf(b64[i]) << 10) | (lookup.indexOf(b64[i + 1]) << 4) | (lookup.indexOf(b64[i + 2]) >> 2); arr.push((tmp >> 8) & 0xFF); arr.push(tmp & 0xFF); } return arr; } function uint8ToBase64(uint8) { var i, extraBytes = uint8.length % 3, // if we have 1 byte left, pad 2 bytes output = "", temp, length; function tripletToBase64 (num) { return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F]; }; // go through the array every three bytes, we'll deal with trailing stuff later for (i = 0, length = uint8.length - extraBytes; i < length; i += 3) { temp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]); output += tripletToBase64(temp); } // pad the end with zeros, but make sure to not forget the extra bytes switch (extraBytes) { case 1: temp = uint8[uint8.length - 1]; output += lookup[temp >> 2]; output += lookup[(temp << 4) & 0x3F]; output += '=='; break; case 2: temp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1]); output += lookup[temp >> 10]; output += lookup[(temp >> 4) & 0x3F]; output += lookup[(temp << 2) & 0x3F]; output += '='; break; } return output; } module.exports.toByteArray = b64ToByteArray; module.exports.fromByteArray = uint8ToBase64; }()); },{}],8:[function(require,module,exports){ exports.readIEEE754 = function(buffer, offset, isBE, mLen, nBytes) { var e, m, eLen = nBytes * 8 - mLen - 1, eMax = (1 << eLen) - 1, eBias = eMax >> 1, nBits = -7, i = isBE ? 0 : (nBytes - 1), d = isBE ? 1 : -1, s = buffer[offset + i]; i += d; e = s & ((1 << (-nBits)) - 1); s >>= (-nBits); nBits += eLen; for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8); m = e & ((1 << (-nBits)) - 1); e >>= (-nBits); nBits += mLen; for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8); if (e === 0) { e = 1 - eBias; } else if (e === eMax) { return m ? NaN : ((s ? -1 : 1) * Infinity); } else { m = m + Math.pow(2, mLen); e = e - eBias; } return (s ? -1 : 1) * m * Math.pow(2, e - mLen); }; exports.writeIEEE754 = function(buffer, value, offset, isBE, mLen, nBytes) { var e, m, c, eLen = nBytes * 8 - mLen - 1, eMax = (1 << eLen) - 1, eBias = eMax >> 1, rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0), i = isBE ? (nBytes - 1) : 0, d = isBE ? -1 : 1, s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0; value = Math.abs(value); if (isNaN(value) || value === Infinity) { m = isNaN(value) ? 1 : 0; e = eMax; } else { e = Math.floor(Math.log(value) / Math.LN2); if (value * (c = Math.pow(2, -e)) < 1) { e--; c *= 2; } if (e + eBias >= 1) { value += rt / c; } else { value += rt * Math.pow(2, 1 - eBias); } if (value * c >= 2) { e++; c /= 2; } if (e + eBias >= eMax) { m = 0; e = eMax; } else if (e + eBias >= 1) { m = (value * c - 1) * Math.pow(2, mLen); e = e + eBias; } else { m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen); e = 0; } } for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8); e = (e << mLen) | m; eLen += mLen; for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8); buffer[offset + i - d] |= s * 128; }; },{}],3:[function(require,module,exports){ function SlowBuffer (size) { this.length = size; }; var assert = require('assert'); exports.INSPECT_MAX_BYTES = 50; function toHex(n) { if (n < 16) return '0' + n.toString(16); return n.toString(16); } function utf8ToBytes(str) { var byteArray = []; for (var i = 0; i < str.length; i++) if (str.charCodeAt(i) <= 0x7F) byteArray.push(str.charCodeAt(i)); else { var h = encodeURIComponent(str.charAt(i)).substr(1).split('%'); for (var j = 0; j < h.length; j++) byteArray.push(parseInt(h[j], 16)); } return byteArray; } function asciiToBytes(str) { var byteArray = [] for (var i = 0; i < str.length; i++ ) // Node's code seems to be doing this and not & 0x7F.. byteArray.push( str.charCodeAt(i) & 0xFF ); return byteArray; } function base64ToBytes(str) { return require("base64-js").toByteArray(str); } SlowBuffer.byteLength = function (str, encoding) { switch (encoding || "utf8") { case 'hex': return str.length / 2; case 'utf8': case 'utf-8': return utf8ToBytes(str).length; case 'ascii': return str.length; case 'base64': return base64ToBytes(str).length; default: throw new Error('Unknown encoding'); } }; function blitBuffer(src, dst, offset, length) { var pos, i = 0; while (i < length) { if ((i+offset >= dst.length) || (i >= src.length)) break; dst[i + offset] = src[i]; i++; } return i; } SlowBuffer.prototype.utf8Write = function (string, offset, length) { var bytes, pos; return SlowBuffer._charsWritten = blitBuffer(utf8ToBytes(string), this, offset, length); }; SlowBuffer.prototype.asciiWrite = function (string, offset, length) { var bytes, pos; return SlowBuffer._charsWritten = blitBuffer(asciiToBytes(string), this, offset, length); }; SlowBuffer.prototype.base64Write = function (string, offset, length) { var bytes, pos; return SlowBuffer._charsWritten = blitBuffer(base64ToBytes(string), this, offset, length); }; SlowBuffer.prototype.base64Slice = function (start, end) { var bytes = Array.prototype.slice.apply(this, arguments) return require("base64-js").fromByteArray(bytes); } function decodeUtf8Char(str) { try { return decodeURIComponent(str); } catch (err) { return String.fromCharCode(0xFFFD); // UTF 8 invalid char } } SlowBuffer.prototype.utf8Slice = function () { var bytes = Array.prototype.slice.apply(this, arguments); var res = ""; var tmp = ""; var i = 0; while (i < bytes.length) { if (bytes[i] <= 0x7F) { res += decodeUtf8Char(tmp) + String.fromCharCode(bytes[i]); tmp = ""; } else tmp += "%" + bytes[i].toString(16); i++; } return res + decodeUtf8Char(tmp); } SlowBuffer.prototype.asciiSlice = function () { var bytes = Array.prototype.slice.apply(this, arguments); var ret = ""; for (var i = 0; i < bytes.length; i++) ret += String.fromCharCode(bytes[i]); return ret; } SlowBuffer.prototype.inspect = function() { var out = [], len = this.length; for (var i = 0; i < len; i++) { out[i] = toHex(this[i]); if (i == exports.INSPECT_MAX_BYTES) { out[i + 1] = '...'; break; } } return ''; }; SlowBuffer.prototype.hexSlice = function(start, end) { var len = this.length; if (!start || start < 0) start = 0; if (!end || end < 0 || end > len) end = len; var out = ''; for (var i = start; i < end; i++) { out += toHex(this[i]); } return out; }; SlowBuffer.prototype.toString = function(encoding, start, end) { encoding = String(encoding || 'utf8').toLowerCase(); start = +start || 0; if (typeof end == 'undefined') end = this.length; // Fastpath empty strings if (+end == start) { return ''; } switch (encoding) { case 'hex': return this.hexSlice(start, end); case 'utf8': case 'utf-8': return this.utf8Slice(start, end); case 'ascii': return this.asciiSlice(start, end); case 'binary': return this.binarySlice(start, end); case 'base64': return this.base64Slice(start, end); case 'ucs2': case 'ucs-2': return this.ucs2Slice(start, end); default: throw new Error('Unknown encoding'); } }; SlowBuffer.prototype.hexWrite = function(string, offset, length) { offset = +offset || 0; var remaining = this.length - offset; if (!length) { length = remaining; } else { length = +length; if (length > remaining) { length = remaining; } } // must be an even number of digits var strLen = string.length; if (strLen % 2) { throw new Error('Invalid hex string'); } if (length > strLen / 2) { length = strLen / 2; } for (var i = 0; i < length; i++) { var byte = parseInt(string.substr(i * 2, 2), 16); if (isNaN(byte)) throw new Error('Invalid hex string'); this[offset + i] = byte; } SlowBuffer._charsWritten = i * 2; return i; }; SlowBuffer.prototype.write = function(string, offset, length, encoding) { // Support both (string, offset, length, encoding) // and the legacy (string, encoding, offset, length) if (isFinite(offset)) { if (!isFinite(length)) { encoding = length; length = undefined; } } else { // legacy var swap = encoding; encoding = offset; offset = length; length = swap; } offset = +offset || 0; var remaining = this.length - offset; if (!length) { length = remaining; } else { length = +length; if (length > remaining) { length = remaining; } } encoding = String(encoding || 'utf8').toLowerCase(); switch (encoding) { case 'hex': return this.hexWrite(string, offset, length); case 'utf8': case 'utf-8': return this.utf8Write(string, offset, length); case 'ascii': return this.asciiWrite(string, offset, length); case 'binary': return this.binaryWrite(string, offset, length); case 'base64': return this.base64Write(string, offset, length); case 'ucs2': case 'ucs-2': return this.ucs2Write(string, offset, length); default: throw new Error('Unknown encoding'); } }; // slice(start, end) SlowBuffer.prototype.slice = function(start, end) { if (end === undefined) end = this.length; if (end > this.length) { throw new Error('oob'); } if (start > end) { throw new Error('oob'); } return new Buffer(this, end - start, +start); }; SlowBuffer.prototype.copy = function(target, targetstart, sourcestart, sourceend) { var temp = []; for (var i=sourcestart; i Buffer.poolSize) { // Big buffer, just alloc one. this.parent = new SlowBuffer(this.length); this.offset = 0; } else { // Small buffer. if (!pool || pool.length - pool.used < this.length) allocPool(); this.parent = pool; this.offset = pool.used; pool.used += this.length; } // Treat array-ish objects as a byte array. if (isArrayIsh(subject)) { for (var i = 0; i < this.length; i++) { this.parent[i + this.offset] = subject[i]; } } else if (type == 'string') { // We are a string this.length = this.write(subject, 0, encoding); } } } function isArrayIsh(subject) { return Array.isArray(subject) || Buffer.isBuffer(subject) || subject && typeof subject === 'object' && typeof subject.length === 'number'; } exports.SlowBuffer = SlowBuffer; exports.Buffer = Buffer; Buffer.poolSize = 8 * 1024; var pool; function allocPool() { pool = new SlowBuffer(Buffer.poolSize); pool.used = 0; } // Static methods Buffer.isBuffer = function isBuffer(b) { return b instanceof Buffer || b instanceof SlowBuffer; }; Buffer.concat = function (list, totalLength) { if (!Array.isArray(list)) { throw new Error("Usage: Buffer.concat(list, [totalLength])\n \ list should be an Array."); } if (list.length === 0) { return new Buffer(0); } else if (list.length === 1) { return list[0]; } if (typeof totalLength !== 'number') { totalLength = 0; for (var i = 0; i < list.length; i++) { var buf = list[i]; totalLength += buf.length; } } var buffer = new Buffer(totalLength); var pos = 0; for (var i = 0; i < list.length; i++) { var buf = list[i]; buf.copy(buffer, pos); pos += buf.length; } return buffer; }; // Inspect Buffer.prototype.inspect = function inspect() { var out = [], len = this.length; for (var i = 0; i < len; i++) { out[i] = toHex(this.parent[i + this.offset]); if (i == exports.INSPECT_MAX_BYTES) { out[i + 1] = '...'; break; } } return ''; }; Buffer.prototype.get = function get(i) { if (i < 0 || i >= this.length) throw new Error('oob'); return this.parent[this.offset + i]; }; Buffer.prototype.set = function set(i, v) { if (i < 0 || i >= this.length) throw new Error('oob'); return this.parent[this.offset + i] = v; }; // write(string, offset = 0, length = buffer.length-offset, encoding = 'utf8') Buffer.prototype.write = function(string, offset, length, encoding) { // Support both (string, offset, length, encoding) // and the legacy (string, encoding, offset, length) if (isFinite(offset)) { if (!isFinite(length)) { encoding = length; length = undefined; } } else { // legacy var swap = encoding; encoding = offset; offset = length; length = swap; } offset = +offset || 0; var remaining = this.length - offset; if (!length) { length = remaining; } else { length = +length; if (length > remaining) { length = remaining; } } encoding = String(encoding || 'utf8').toLowerCase(); var ret; switch (encoding) { case 'hex': ret = this.parent.hexWrite(string, this.offset + offset, length); break; case 'utf8': case 'utf-8': ret = this.parent.utf8Write(string, this.offset + offset, length); break; case 'ascii': ret = this.parent.asciiWrite(string, this.offset + offset, length); break; case 'binary': ret = this.parent.binaryWrite(string, this.offset + offset, length); break; case 'base64': // Warning: maxLength not taken into account in base64Write ret = this.parent.base64Write(string, this.offset + offset, length); break; case 'ucs2': case 'ucs-2': ret = this.parent.ucs2Write(string, this.offset + offset, length); break; default: throw new Error('Unknown encoding'); } Buffer._charsWritten = SlowBuffer._charsWritten; return ret; }; // toString(encoding, start=0, end=buffer.length) Buffer.prototype.toString = function(encoding, start, end) { encoding = String(encoding || 'utf8').toLowerCase(); if (typeof start == 'undefined' || start < 0) { start = 0; } else if (start > this.length) { start = this.length; } if (typeof end == 'undefined' || end > this.length) { end = this.length; } else if (end < 0) { end = 0; } start = start + this.offset; end = end + this.offset; switch (encoding) { case 'hex': return this.parent.hexSlice(start, end); case 'utf8': case 'utf-8': return this.parent.utf8Slice(start, end); case 'ascii': return this.parent.asciiSlice(start, end); case 'binary': return this.parent.binarySlice(start, end); case 'base64': return this.parent.base64Slice(start, end); case 'ucs2': case 'ucs-2': return this.parent.ucs2Slice(start, end); default: throw new Error('Unknown encoding'); } }; // byteLength Buffer.byteLength = SlowBuffer.byteLength; // fill(value, start=0, end=buffer.length) Buffer.prototype.fill = function fill(value, start, end) { value || (value = 0); start || (start = 0); end || (end = this.length); if (typeof value === 'string') { value = value.charCodeAt(0); } if (!(typeof value === 'number') || isNaN(value)) { throw new Error('value is not a number'); } if (end < start) throw new Error('end < start'); // Fill 0 bytes; we're done if (end === start) return 0; if (this.length == 0) return 0; if (start < 0 || start >= this.length) { throw new Error('start out of bounds'); } if (end < 0 || end > this.length) { throw new Error('end out of bounds'); } return this.parent.fill(value, start + this.offset, end + this.offset); }; // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length) Buffer.prototype.copy = function(target, target_start, start, end) { var source = this; start || (start = 0); end || (end = this.length); target_start || (target_start = 0); if (end < start) throw new Error('sourceEnd < sourceStart'); // Copy 0 bytes; we're done if (end === start) return 0; if (target.length == 0 || source.length == 0) return 0; if (target_start < 0 || target_start >= target.length) { throw new Error('targetStart out of bounds'); } if (start < 0 || start >= source.length) { throw new Error('sourceStart out of bounds'); } if (end < 0 || end > source.length) { throw new Error('sourceEnd out of bounds'); } // Are we oob? if (end > this.length) { end = this.length; } if (target.length - target_start < end - start) { end = target.length - target_start + start; } return this.parent.copy(target.parent, target_start + target.offset, start + this.offset, end + this.offset); }; // slice(start, end) Buffer.prototype.slice = function(start, end) { if (end === undefined) end = this.length; if (end > this.length) throw new Error('oob'); if (start > end) throw new Error('oob'); return new Buffer(this.parent, end - start, +start + this.offset); }; // Legacy methods for backwards compatibility. Buffer.prototype.utf8Slice = function(start, end) { return this.toString('utf8', start, end); }; Buffer.prototype.binarySlice = function(start, end) { return this.toString('binary', start, end); }; Buffer.prototype.asciiSlice = function(start, end) { return this.toString('ascii', start, end); }; Buffer.prototype.utf8Write = function(string, offset) { return this.write(string, offset, 'utf8'); }; Buffer.prototype.binaryWrite = function(string, offset) { return this.write(string, offset, 'binary'); }; Buffer.prototype.asciiWrite = function(string, offset) { return this.write(string, offset, 'ascii'); }; Buffer.prototype.readUInt8 = function(offset, noAssert) { var buffer = this; if (!noAssert) { assert.ok(offset !== undefined && offset !== null, 'missing offset'); assert.ok(offset < buffer.length, 'Trying to read beyond buffer length'); } return buffer.parent[buffer.offset + offset]; }; function readUInt16(buffer, offset, isBigEndian, noAssert) { var val = 0; if (!noAssert) { assert.ok(typeof (isBigEndian) === 'boolean', 'missing or invalid endian'); assert.ok(offset !== undefined && offset !== null, 'missing offset'); assert.ok(offset + 1 < buffer.length, 'Trying to read beyond buffer length'); } if (isBigEndian) { val = buffer.parent[buffer.offset + offset] << 8; val |= buffer.parent[buffer.offset + offset + 1]; } else { val = buffer.parent[buffer.offset + offset]; val |= buffer.parent[buffer.offset + offset + 1] << 8; } return val; } Buffer.prototype.readUInt16LE = function(offset, noAssert) { return readUInt16(this, offset, false, noAssert); }; Buffer.prototype.readUInt16BE = function(offset, noAssert) { return readUInt16(this, offset, true, noAssert); }; function readUInt32(buffer, offset, isBigEndian, noAssert) { var val = 0; if (!noAssert) { assert.ok(typeof (isBigEndian) === 'boolean', 'missing or invalid endian'); assert.ok(offset !== undefined && offset !== null, 'missing offset'); assert.ok(offset + 3 < buffer.length, 'Trying to read beyond buffer length'); } if (isBigEndian) { val = buffer.parent[buffer.offset + offset + 1] << 16; val |= buffer.parent[buffer.offset + offset + 2] << 8; val |= buffer.parent[buffer.offset + offset + 3]; val = val + (buffer.parent[buffer.offset + offset] << 24 >>> 0); } else { val = buffer.parent[buffer.offset + offset + 2] << 16; val |= buffer.parent[buffer.offset + offset + 1] << 8; val |= buffer.parent[buffer.offset + offset]; val = val + (buffer.parent[buffer.offset + offset + 3] << 24 >>> 0); } return val; } Buffer.prototype.readUInt32LE = function(offset, noAssert) { return readUInt32(this, offset, false, noAssert); }; Buffer.prototype.readUInt32BE = function(offset, noAssert) { return readUInt32(this, offset, true, noAssert); }; /* * Signed integer types, yay team! A reminder on how two's complement actually * works. The first bit is the signed bit, i.e. tells us whether or not the * number should be positive or negative. If the two's complement value is * positive, then we're done, as it's equivalent to the unsigned representation. * * Now if the number is positive, you're pretty much done, you can just leverage * the unsigned translations and return those. Unfortunately, negative numbers * aren't quite that straightforward. * * At first glance, one might be inclined to use the traditional formula to * translate binary numbers between the positive and negative values in two's * complement. (Though it doesn't quite work for the most negative value) * Mainly: * - invert all the bits * - add one to the result * * Of course, this doesn't quite work in Javascript. Take for example the value * of -128. This could be represented in 16 bits (big-endian) as 0xff80. But of * course, Javascript will do the following: * * > ~0xff80 * -65409 * * Whoh there, Javascript, that's not quite right. But wait, according to * Javascript that's perfectly correct. When Javascript ends up seeing the * constant 0xff80, it has no notion that it is actually a signed number. It * assumes that we've input the unsigned value 0xff80. Thus, when it does the * binary negation, it casts it into a signed value, (positive 0xff80). Then * when you perform binary negation on that, it turns it into a negative number. * * Instead, we're going to have to use the following general formula, that works * in a rather Javascript friendly way. I'm glad we don't support this kind of * weird numbering scheme in the kernel. * * (BIT-MAX - (unsigned)val + 1) * -1 * * The astute observer, may think that this doesn't make sense for 8-bit numbers * (really it isn't necessary for them). However, when you get 16-bit numbers, * you do. Let's go back to our prior example and see how this will look: * * (0xffff - 0xff80 + 1) * -1 * (0x007f + 1) * -1 * (0x0080) * -1 */ Buffer.prototype.readInt8 = function(offset, noAssert) { var buffer = this; var neg; if (!noAssert) { assert.ok(offset !== undefined && offset !== null, 'missing offset'); assert.ok(offset < buffer.length, 'Trying to read beyond buffer length'); } neg = buffer.parent[buffer.offset + offset] & 0x80; if (!neg) { return (buffer.parent[buffer.offset + offset]); } return ((0xff - buffer.parent[buffer.offset + offset] + 1) * -1); }; function readInt16(buffer, offset, isBigEndian, noAssert) { var neg, val; if (!noAssert) { assert.ok(typeof (isBigEndian) === 'boolean', 'missing or invalid endian'); assert.ok(offset !== undefined && offset !== null, 'missing offset'); assert.ok(offset + 1 < buffer.length, 'Trying to read beyond buffer length'); } val = readUInt16(buffer, offset, isBigEndian, noAssert); neg = val & 0x8000; if (!neg) { return val; } return (0xffff - val + 1) * -1; } Buffer.prototype.readInt16LE = function(offset, noAssert) { return readInt16(this, offset, false, noAssert); }; Buffer.prototype.readInt16BE = function(offset, noAssert) { return readInt16(this, offset, true, noAssert); }; function readInt32(buffer, offset, isBigEndian, noAssert) { var neg, val; if (!noAssert) { assert.ok(typeof (isBigEndian) === 'boolean', 'missing or invalid endian'); assert.ok(offset !== undefined && offset !== null, 'missing offset'); assert.ok(offset + 3 < buffer.length, 'Trying to read beyond buffer length'); } val = readUInt32(buffer, offset, isBigEndian, noAssert); neg = val & 0x80000000; if (!neg) { return (val); } return (0xffffffff - val + 1) * -1; } Buffer.prototype.readInt32LE = function(offset, noAssert) { return readInt32(this, offset, false, noAssert); }; Buffer.prototype.readInt32BE = function(offset, noAssert) { return readInt32(this, offset, true, noAssert); }; function readFloat(buffer, offset, isBigEndian, noAssert) { if (!noAssert) { assert.ok(typeof (isBigEndian) === 'boolean', 'missing or invalid endian'); assert.ok(offset + 3 < buffer.length, 'Trying to read beyond buffer length'); } return require('./buffer_ieee754').readIEEE754(buffer, offset, isBigEndian, 23, 4); } Buffer.prototype.readFloatLE = function(offset, noAssert) { return readFloat(this, offset, false, noAssert); }; Buffer.prototype.readFloatBE = function(offset, noAssert) { return readFloat(this, offset, true, noAssert); }; function readDouble(buffer, offset, isBigEndian, noAssert) { if (!noAssert) { assert.ok(typeof (isBigEndian) === 'boolean', 'missing or invalid endian'); assert.ok(offset + 7 < buffer.length, 'Trying to read beyond buffer length'); } return require('./buffer_ieee754').readIEEE754(buffer, offset, isBigEndian, 52, 8); } Buffer.prototype.readDoubleLE = function(offset, noAssert) { return readDouble(this, offset, false, noAssert); }; Buffer.prototype.readDoubleBE = function(offset, noAssert) { return readDouble(this, offset, true, noAssert); }; /* * We have to make sure that the value is a valid integer. This means that it is * non-negative. It has no fractional component and that it does not exceed the * maximum allowed value. * * value The number to check for validity * * max The maximum value */ function verifuint(value, max) { assert.ok(typeof (value) == 'number', 'cannot write a non-number as a number'); assert.ok(value >= 0, 'specified a negative value for writing an unsigned value'); assert.ok(value <= max, 'value is larger than maximum value for type'); assert.ok(Math.floor(value) === value, 'value has a fractional component'); } Buffer.prototype.writeUInt8 = function(value, offset, noAssert) { var buffer = this; if (!noAssert) { assert.ok(value !== undefined && value !== null, 'missing value'); assert.ok(offset !== undefined && offset !== null, 'missing offset'); assert.ok(offset < buffer.length, 'trying to write beyond buffer length'); verifuint(value, 0xff); } buffer.parent[buffer.offset + offset] = value; }; function writeUInt16(buffer, value, offset, isBigEndian, noAssert) { if (!noAssert) { assert.ok(value !== undefined && value !== null, 'missing value'); assert.ok(typeof (isBigEndian) === 'boolean', 'missing or invalid endian'); assert.ok(offset !== undefined && offset !== null, 'missing offset'); assert.ok(offset + 1 < buffer.length, 'trying to write beyond buffer length'); verifuint(value, 0xffff); } if (isBigEndian) { buffer.parent[buffer.offset + offset] = (value & 0xff00) >>> 8; buffer.parent[buffer.offset + offset + 1] = value & 0x00ff; } else { buffer.parent[buffer.offset + offset + 1] = (value & 0xff00) >>> 8; buffer.parent[buffer.offset + offset] = value & 0x00ff; } } Buffer.prototype.writeUInt16LE = function(value, offset, noAssert) { writeUInt16(this, value, offset, false, noAssert); }; Buffer.prototype.writeUInt16BE = function(value, offset, noAssert) { writeUInt16(this, value, offset, true, noAssert); }; function writeUInt32(buffer, value, offset, isBigEndian, noAssert) { if (!noAssert) { assert.ok(value !== undefined && value !== null, 'missing value'); assert.ok(typeof (isBigEndian) === 'boolean', 'missing or invalid endian'); assert.ok(offset !== undefined && offset !== null, 'missing offset'); assert.ok(offset + 3 < buffer.length, 'trying to write beyond buffer length'); verifuint(value, 0xffffffff); } if (isBigEndian) { buffer.parent[buffer.offset + offset] = (value >>> 24) & 0xff; buffer.parent[buffer.offset + offset + 1] = (value >>> 16) & 0xff; buffer.parent[buffer.offset + offset + 2] = (value >>> 8) & 0xff; buffer.parent[buffer.offset + offset + 3] = value & 0xff; } else { buffer.parent[buffer.offset + offset + 3] = (value >>> 24) & 0xff; buffer.parent[buffer.offset + offset + 2] = (value >>> 16) & 0xff; buffer.parent[buffer.offset + offset + 1] = (value >>> 8) & 0xff; buffer.parent[buffer.offset + offset] = value & 0xff; } } Buffer.prototype.writeUInt32LE = function(value, offset, noAssert) { writeUInt32(this, value, offset, false, noAssert); }; Buffer.prototype.writeUInt32BE = function(value, offset, noAssert) { writeUInt32(this, value, offset, true, noAssert); }; /* * We now move onto our friends in the signed number category. Unlike unsigned * numbers, we're going to have to worry a bit more about how we put values into * arrays. Since we are only worrying about signed 32-bit values, we're in * slightly better shape. Unfortunately, we really can't do our favorite binary * & in this system. It really seems to do the wrong thing. For example: * * > -32 & 0xff * 224 * * What's happening above is really: 0xe0 & 0xff = 0xe0. However, the results of * this aren't treated as a signed number. Ultimately a bad thing. * * What we're going to want to do is basically create the unsigned equivalent of * our representation and pass that off to the wuint* functions. To do that * we're going to do the following: * * - if the value is positive * we can pass it directly off to the equivalent wuint * - if the value is negative * we do the following computation: * mb + val + 1, where * mb is the maximum unsigned value in that byte size * val is the Javascript negative integer * * * As a concrete value, take -128. In signed 16 bits this would be 0xff80. If * you do out the computations: * * 0xffff - 128 + 1 * 0xffff - 127 * 0xff80 * * You can then encode this value as the signed version. This is really rather * hacky, but it should work and get the job done which is our goal here. */ /* * A series of checks to make sure we actually have a signed 32-bit number */ function verifsint(value, max, min) { assert.ok(typeof (value) == 'number', 'cannot write a non-number as a number'); assert.ok(value <= max, 'value larger than maximum allowed value'); assert.ok(value >= min, 'value smaller than minimum allowed value'); assert.ok(Math.floor(value) === value, 'value has a fractional component'); } function verifIEEE754(value, max, min) { assert.ok(typeof (value) == 'number', 'cannot write a non-number as a number'); assert.ok(value <= max, 'value larger than maximum allowed value'); assert.ok(value >= min, 'value smaller than minimum allowed value'); } Buffer.prototype.writeInt8 = function(value, offset, noAssert) { var buffer = this; if (!noAssert) { assert.ok(value !== undefined && value !== null, 'missing value'); assert.ok(offset !== undefined && offset !== null, 'missing offset'); assert.ok(offset < buffer.length, 'Trying to write beyond buffer length'); verifsint(value, 0x7f, -0x80); } if (value >= 0) { buffer.writeUInt8(value, offset, noAssert); } else { buffer.writeUInt8(0xff + value + 1, offset, noAssert); } }; function writeInt16(buffer, value, offset, isBigEndian, noAssert) { if (!noAssert) { assert.ok(value !== undefined && value !== null, 'missing value'); assert.ok(typeof (isBigEndian) === 'boolean', 'missing or invalid endian'); assert.ok(offset !== undefined && offset !== null, 'missing offset'); assert.ok(offset + 1 < buffer.length, 'Trying to write beyond buffer length'); verifsint(value, 0x7fff, -0x8000); } if (value >= 0) { writeUInt16(buffer, value, offset, isBigEndian, noAssert); } else { writeUInt16(buffer, 0xffff + value + 1, offset, isBigEndian, noAssert); } } Buffer.prototype.writeInt16LE = function(value, offset, noAssert) { writeInt16(this, value, offset, false, noAssert); }; Buffer.prototype.writeInt16BE = function(value, offset, noAssert) { writeInt16(this, value, offset, true, noAssert); }; function writeInt32(buffer, value, offset, isBigEndian, noAssert) { if (!noAssert) { assert.ok(value !== undefined && value !== null, 'missing value'); assert.ok(typeof (isBigEndian) === 'boolean', 'missing or invalid endian'); assert.ok(offset !== undefined && offset !== null, 'missing offset'); assert.ok(offset + 3 < buffer.length, 'Trying to write beyond buffer length'); verifsint(value, 0x7fffffff, -0x80000000); } if (value >= 0) { writeUInt32(buffer, value, offset, isBigEndian, noAssert); } else { writeUInt32(buffer, 0xffffffff + value + 1, offset, isBigEndian, noAssert); } } Buffer.prototype.writeInt32LE = function(value, offset, noAssert) { writeInt32(this, value, offset, false, noAssert); }; Buffer.prototype.writeInt32BE = function(value, offset, noAssert) { writeInt32(this, value, offset, true, noAssert); }; function writeFloat(buffer, value, offset, isBigEndian, noAssert) { if (!noAssert) { assert.ok(value !== undefined && value !== null, 'missing value'); assert.ok(typeof (isBigEndian) === 'boolean', 'missing or invalid endian'); assert.ok(offset !== undefined && offset !== null, 'missing offset'); assert.ok(offset + 3 < buffer.length, 'Trying to write beyond buffer length'); verifIEEE754(value, 3.4028234663852886e+38, -3.4028234663852886e+38); } require('./buffer_ieee754').writeIEEE754(buffer, value, offset, isBigEndian, 23, 4); } Buffer.prototype.writeFloatLE = function(value, offset, noAssert) { writeFloat(this, value, offset, false, noAssert); }; Buffer.prototype.writeFloatBE = function(value, offset, noAssert) { writeFloat(this, value, offset, true, noAssert); }; function writeDouble(buffer, value, offset, isBigEndian, noAssert) { if (!noAssert) { assert.ok(value !== undefined && value !== null, 'missing value'); assert.ok(typeof (isBigEndian) === 'boolean', 'missing or invalid endian'); assert.ok(offset !== undefined && offset !== null, 'missing offset'); assert.ok(offset + 7 < buffer.length, 'Trying to write beyond buffer length'); verifIEEE754(value, 1.7976931348623157E+308, -1.7976931348623157E+308); } require('./buffer_ieee754').writeIEEE754(buffer, value, offset, isBigEndian, 52, 8); } Buffer.prototype.writeDoubleLE = function(value, offset, noAssert) { writeDouble(this, value, offset, false, noAssert); }; Buffer.prototype.writeDoubleBE = function(value, offset, noAssert) { writeDouble(this, value, offset, true, noAssert); }; SlowBuffer.prototype.readUInt8 = Buffer.prototype.readUInt8; SlowBuffer.prototype.readUInt16LE = Buffer.prototype.readUInt16LE; SlowBuffer.prototype.readUInt16BE = Buffer.prototype.readUInt16BE; SlowBuffer.prototype.readUInt32LE = Buffer.prototype.readUInt32LE; SlowBuffer.prototype.readUInt32BE = Buffer.prototype.readUInt32BE; SlowBuffer.prototype.readInt8 = Buffer.prototype.readInt8; SlowBuffer.prototype.readInt16LE = Buffer.prototype.readInt16LE; SlowBuffer.prototype.readInt16BE = Buffer.prototype.readInt16BE; SlowBuffer.prototype.readInt32LE = Buffer.prototype.readInt32LE; SlowBuffer.prototype.readInt32BE = Buffer.prototype.readInt32BE; SlowBuffer.prototype.readFloatLE = Buffer.prototype.readFloatLE; SlowBuffer.prototype.readFloatBE = Buffer.prototype.readFloatBE; SlowBuffer.prototype.readDoubleLE = Buffer.prototype.readDoubleLE; SlowBuffer.prototype.readDoubleBE = Buffer.prototype.readDoubleBE; SlowBuffer.prototype.writeUInt8 = Buffer.prototype.writeUInt8; SlowBuffer.prototype.writeUInt16LE = Buffer.prototype.writeUInt16LE; SlowBuffer.prototype.writeUInt16BE = Buffer.prototype.writeUInt16BE; SlowBuffer.prototype.writeUInt32LE = Buffer.prototype.writeUInt32LE; SlowBuffer.prototype.writeUInt32BE = Buffer.prototype.writeUInt32BE; SlowBuffer.prototype.writeInt8 = Buffer.prototype.writeInt8; SlowBuffer.prototype.writeInt16LE = Buffer.prototype.writeInt16LE; SlowBuffer.prototype.writeInt16BE = Buffer.prototype.writeInt16BE; SlowBuffer.prototype.writeInt32LE = Buffer.prototype.writeInt32LE; SlowBuffer.prototype.writeInt32BE = Buffer.prototype.writeInt32BE; SlowBuffer.prototype.writeFloatLE = Buffer.prototype.writeFloatLE; SlowBuffer.prototype.writeFloatBE = Buffer.prototype.writeFloatBE; SlowBuffer.prototype.writeDoubleLE = Buffer.prototype.writeDoubleLE; SlowBuffer.prototype.writeDoubleBE = Buffer.prototype.writeDoubleBE; },{"assert":1,"./buffer_ieee754":8,"base64-js":9}],9:[function(require,module,exports){ (function (exports) { 'use strict'; var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; function b64ToByteArray(b64) { var i, j, l, tmp, placeHolders, arr; if (b64.length % 4 > 0) { throw 'Invalid string. Length must be a multiple of 4'; } // the number of equal signs (place holders) // if there are two placeholders, than the two characters before it // represent one byte // if there is only one, then the three characters before it represent 2 bytes // this is just a cheap hack to not do indexOf twice placeHolders = b64.indexOf('='); placeHolders = placeHolders > 0 ? b64.length - placeHolders : 0; // base64 is 4/3 + up to two characters of the original data arr = [];//new Uint8Array(b64.length * 3 / 4 - placeHolders); // if there are placeholders, only get up to the last complete 4 chars l = placeHolders > 0 ? b64.length - 4 : b64.length; for (i = 0, j = 0; i < l; i += 4, j += 3) { tmp = (lookup.indexOf(b64[i]) << 18) | (lookup.indexOf(b64[i + 1]) << 12) | (lookup.indexOf(b64[i + 2]) << 6) | lookup.indexOf(b64[i + 3]); arr.push((tmp & 0xFF0000) >> 16); arr.push((tmp & 0xFF00) >> 8); arr.push(tmp & 0xFF); } if (placeHolders === 2) { tmp = (lookup.indexOf(b64[i]) << 2) | (lookup.indexOf(b64[i + 1]) >> 4); arr.push(tmp & 0xFF); } else if (placeHolders === 1) { tmp = (lookup.indexOf(b64[i]) << 10) | (lookup.indexOf(b64[i + 1]) << 4) | (lookup.indexOf(b64[i + 2]) >> 2); arr.push((tmp >> 8) & 0xFF); arr.push(tmp & 0xFF); } return arr; } function uint8ToBase64(uint8) { var i, extraBytes = uint8.length % 3, // if we have 1 byte left, pad 2 bytes output = "", temp, length; function tripletToBase64 (num) { return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F]; }; // go through the array every three bytes, we'll deal with trailing stuff later for (i = 0, length = uint8.length - extraBytes; i < length; i += 3) { temp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]); output += tripletToBase64(temp); } // pad the end with zeros, but make sure to not forget the extra bytes switch (extraBytes) { case 1: temp = uint8[uint8.length - 1]; output += lookup[temp >> 2]; output += lookup[(temp << 4) & 0x3F]; output += '=='; break; case 2: temp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1]); output += lookup[temp >> 10]; output += lookup[(temp >> 4) & 0x3F]; output += lookup[(temp << 2) & 0x3F]; output += '='; break; } return output; } module.exports.toByteArray = b64ToByteArray; module.exports.fromByteArray = uint8ToBase64; }()); },{}]},{},[]) ;;module.exports=require("buffer-browserify") },{}],9:[function(require,module,exports){ // shim for using process in browser var process = module.exports = {}; process.nextTick = (function () { var canSetImmediate = typeof window !== 'undefined' && window.setImmediate; var canPost = typeof window !== 'undefined' && window.postMessage && window.addEventListener ; if (canSetImmediate) { return function (f) { return window.setImmediate(f) }; } if (canPost) { var queue = []; window.addEventListener('message', function (ev) { if (ev.source === window && ev.data === 'process-tick') { ev.stopPropagation(); if (queue.length > 0) { var fn = queue.shift(); fn(); } } }, true); return function nextTick(fn) { queue.push(fn); window.postMessage('process-tick', '*'); }; } return function nextTick(fn) { setTimeout(fn, 0); }; })(); process.title = 'browser'; process.browser = true; process.env = {}; process.argv = []; process.binding = function (name) { throw new Error('process.binding is not supported'); } // TODO(shtylman) process.cwd = function () { return '/' }; process.chdir = function (dir) { throw new Error('process.chdir is not supported'); }; },{}],10:[function(require,module,exports){ var path = require('path'); exports.tmx = require('tmx-parser'); exports.load = load; function load(chem, fileName, cb) { var v = chem.vec2d; var error = null; exports.tmx.readFile = chemReadFile; exports.tmx.parseFile(fileName, function(err, map) { if (err) { cb(err); return; } map.tileSets.forEach(resolveTileSet); if (error) { cb(error); return; } cb(null, map); }); function chemReadFile(name, cb) { var text = chem.resources.text[name]; if (text == null) { cb(new Error("File not found: public/text/" + name)); } else { cb(null, text); } } function resolveTileSet(tileSet) { if (error) return; // resolve the image file name to something in chem.resources.images var imgName = path.relative("img", path.join("text/", tileSet.image.source)); var img = chem.resources.images[imgName]; if (!img) { error = new Error("Image not found: public/img/" + imgName); return; } var spacing = v(tileSet.spacing || 0, tileSet.spacing || 0); var margin = v(tileSet.margin || 0, tileSet.margin || 0); var offset = v(tileSet.tileOffset); var imgSize = v(img.width, img.height); var tileSize = v(tileSet.tileWidth, tileSet.tileHeight); var tileCount = imgSize.minus(margin).div(tileSize.plus(spacing)).floor(); for (var i = 0; i < tileSet.tiles.length; i += 1) { var tile = tileSet.tiles[i]; // calculate x and y based on id var intPos = v( tile.id % tileCount.x, Math.floor(tile.id / tileCount.x)); var pos = intPos.mult(tileSize.plus(spacing)).plus(margin).plus(offset); tile.animation = new chem.Animation(); tile.animation.spritesheet = img; tile.animation.anchor = v(); tile.animation.addFrame(pos, tileSize); } } } },{"path":3,"tmx-parser":11}],11:[function(require,module,exports){ var sax = require('sax'); var fs = require('fs'); var path = require('path'); var zlib = require('zlib'); var Pend = require('pend'); var bops = require('bops'); exports.readFile = defaultReadFile; exports.parseFile = parseFile; exports.parse = parse; exports.Map = Map; exports.TileSet = TileSet; exports.Image = Image; exports.Tile = Tile; exports.TileLayer = TileLayer; exports.ObjectLayer = ObjectLayer; exports.ImageLayer = ImageLayer; exports.TmxObject = TmxObject; exports.Terrain = Terrain; var FLIPPED_HORIZONTALLY_FLAG = 0x80000000; var FLIPPED_VERTICALLY_FLAG = 0x40000000; var FLIPPED_DIAGONALLY_FLAG = 0x20000000; var STATE_START = 0; var STATE_MAP = 1; var STATE_COLLECT_PROPS = 2; var STATE_WAIT_FOR_CLOSE = 3; var STATE_TILESET = 4; var STATE_TILE = 5; var STATE_TILE_LAYER = 6; var STATE_OBJECT_LAYER = 7; var STATE_OBJECT = 8; var STATE_IMAGE_LAYER = 9; var STATE_TILE_DATA_XML = 10; var STATE_TILE_DATA_CSV = 11; var STATE_TILE_DATA_B64_RAW = 12; var STATE_TILE_DATA_B64_GZIP = 13; var STATE_TILE_DATA_B64_ZLIB = 14; var STATE_TERRAIN_TYPES = 15; var STATE_TERRAIN = 16; var STATE_COUNT = 17; function parse(content, pathToFile, cb) { var pathToDir = path.dirname(pathToFile); var parser = sax.parser(); var map; var topLevelObject = null; var state = STATE_START; var states = new Array(STATE_COUNT); var waitForCloseNextState = 0; var waitForCloseOpenCount = 0; var propertiesObject = null; var propertiesNextState = 0; var tileIndex = 0; var tileSet = null; var tileSetNextState = 0; var tile; var layer; var object; var terrain; var pend = new Pend(); // this holds the numerical tile ids // later we use it to resolve the real tiles var unresolvedLayers = []; var unresolvedLayer; states[STATE_START] = { opentag: function(tag) { if (tag.name === 'MAP') { map = new Map(); topLevelObject = map; map.version = tag.attributes.VERSION; map.orientation = tag.attributes.ORIENTATION; map.width = int(tag.attributes.WIDTH); map.height = int(tag.attributes.HEIGHT); map.tileWidth = int(tag.attributes.TILEWIDTH); map.tileHeight = int(tag.attributes.TILEHEIGHT); map.backgroundColor = tag.attributes.BACKGROUNDCOLOR; state = STATE_MAP; } else if (tag.name === 'TILESET') { collectTileSet(tag, STATE_START); topLevelObject = tileSet; } else { waitForClose(); } }, closetag: noop, text: noop, }; states[STATE_MAP] = { opentag: function(tag) { switch (tag.name) { case 'PROPERTIES': collectProperties(map.properties); break; case 'TILESET': collectTileSet(tag, STATE_MAP); map.tileSets.push(tileSet); break; case 'LAYER': layer = new TileLayer(map); tileIndex = 0; layer.name = tag.attributes.NAME; layer.opacity = float(tag.attributes.OPACITY, 1); layer.visible = bool(tag.attributes.VISIBLE, true); map.layers.push(layer); unresolvedLayer = { layer: layer, tiles: new Array(map.width * map.height), }; unresolvedLayers.push(unresolvedLayer); state = STATE_TILE_LAYER; break; case 'OBJECTGROUP': layer = new ObjectLayer(); layer.name = tag.attributes.NAME; layer.color = tag.attributes.COLOR; layer.opacity = float(tag.attributes.OPACITY, 1); layer.visible = bool(tag.attributes.VISIBLE, true); map.layers.push(layer); state = STATE_OBJECT_LAYER; break; case 'IMAGELAYER': layer = new ImageLayer(); layer.name = tag.attributes.NAME; layer.opacity = float(tag.attributes.OPACITY, 1); layer.visible = bool(tag.attributes.VISIBLE, true); map.layers.push(layer); state = STATE_IMAGE_LAYER; break; default: waitForClose(); } }, closetag: noop, text: noop, }; states[STATE_TILESET] = { opentag: function(tag) { switch (tag.name) { case 'TILEOFFSET': tileSet.tileOffset.x = int(tag.attributes.X); tileSet.tileOffset.y = int(tag.attributes.Y); waitForClose(); break; case 'PROPERTIES': collectProperties(tileSet.properties); break; case 'IMAGE': tileSet.image = collectImage(tag); break; case 'TERRAINTYPES': state = STATE_TERRAIN_TYPES; break; case 'TILE': tile = new Tile(); tile.id = int(tag.attributes.ID); if (tag.attributes.TERRAIN) { var indexes = tag.attributes.TERRAIN.split(","); tile.terrain = indexes.map(resolveTerrain); } tile.probability = float(tag.attributes.PROBABILITY); tileSet.tiles[tile.id] = tile; state = STATE_TILE; break; default: waitForClose(); } }, closetag: function(name) { state = tileSetNextState; }, text: noop, }; states[STATE_COLLECT_PROPS] = { opentag: function(tag) { if (tag.name === 'PROPERTY') { propertiesObject[tag.attributes.NAME] = tag.attributes.VALUE; } waitForClose(); }, closetag: function(name) { state = propertiesNextState; }, text: noop, }; states[STATE_WAIT_FOR_CLOSE] = { opentag: function(tag) { waitForCloseOpenCount += 1; }, closetag: function(name) { waitForCloseOpenCount -= 1; if (waitForCloseOpenCount === 0) state = waitForCloseNextState; }, text: noop, }; states[STATE_TILE] = { opentag: function(tag) { if (tag.name === 'PROPERTIES') { collectProperties(tile.properties); } else if (tag.name === 'IMAGE') { tile.image = collectImage(tag); } else { waitForClose(); } }, closetag: function(name) { state = STATE_TILESET }, text: noop, }; states[STATE_TILE_LAYER] = { opentag: function(tag) { if (tag.name === 'PROPERTIES') { collectProperties(layer.properties); } else if (tag.name === 'DATA') { var dataEncoding = tag.attributes.ENCODING; var dataCompression = tag.attributes.COMPRESSION; switch (dataEncoding) { case undefined: case null: state = STATE_TILE_DATA_XML; break; case 'csv': state = STATE_TILE_DATA_CSV; break; case 'base64': switch (dataCompression) { case undefined: case null: state = STATE_TILE_DATA_B64_RAW; break; case 'gzip': state = STATE_TILE_DATA_B64_GZIP; break; case 'zlib': state = STATE_TILE_DATA_B64_ZLIB; break; default: error(new Error("unsupported data compression: " + dataCompression)); return; } break; default: error(new Error("unsupported data encoding: " + dataEncoding)); return; } } else { waitForClose(); } }, closetag: function(name) { state = STATE_MAP; }, text: noop, }; states[STATE_OBJECT_LAYER] = { opentag: function(tag) { if (tag.name === 'PROPERTIES') { collectProperties(layer.properties); } else if (tag.name === 'OBJECT') { object = new TmxObject(); object.name = tag.attributes.NAME; object.type = tag.attributes.TYPE; object.x = int(tag.attributes.X); object.y = int(tag.attributes.Y); object.width = int(tag.attributes.WIDTH, 0); object.height = int(tag.attributes.HEIGHT, 0); object.rotation = float(tag.attributes.ROTATION, 0); object.gid = int(tag.attributes.GID); object.visible = bool(tag.attributes.VISIBLE, true); layer.objects.push(object); state = STATE_OBJECT; } else { waitForClose(); } }, closetag: function(name) { state = STATE_MAP; }, text: noop, }; states[STATE_IMAGE_LAYER] = { opentag: function(tag) { if (tag.name === 'PROPERTIES') { collectProperties(layer.properties); } else if (tag.name === 'IMAGE') { layer.image = collectImage(tag); } else { waitForClose(); } }, closetag: function(name) { state = STATE_MAP; }, text: noop, }; states[STATE_OBJECT] = { opentag: function(tag) { switch (tag.name) { case 'PROPERTIES': collectProperties(object.properties); break; case 'ELLIPSE': object.ellipse = true; waitForClose(); break; case 'POLYGON': object.polygon = parsePoints(tag.attributes.POINTS); waitForClose(); break; case 'POLYLINE': object.polyline = parsePoints(tag.attributes.POINTS); waitForClose(); break; case 'IMAGE': object.image = collectImage(tag); break; default: waitForClose(); } }, closetag: function(name) { state = STATE_OBJECT_LAYER; }, text: noop, }; states[STATE_TILE_DATA_XML] = { opentag: function(tag) { if (tag.name === 'TILE') { saveTile(int(tag.attributes.GID, 0)); } waitForClose(); }, closetag: function(name) { state = STATE_TILE_LAYER; }, text: noop, }; states[STATE_TILE_DATA_CSV] = { opentag: function(tag) { waitForClose(); }, closetag: function(name) { state = STATE_TILE_LAYER; }, text: function(text) { var buffer = ""; for (var i = 0; i < text.length; i += 1) { var c = text[i]; if (c === ',') { saveTile(parseInt(buffer, 10)); buffer = ""; } else { buffer += c; } } }, }; states[STATE_TILE_DATA_B64_RAW] = { opentag: function(tag) { waitForClose(); }, closetag: function(name) { state = STATE_TILE_LAYER; }, text: function(text) { unpackTileBytes(bops.from(text.trim(), 'base64')); }, }; states[STATE_TILE_DATA_B64_GZIP] = { opentag: function(tag) { waitForClose(); }, closetag: function(name) { state = STATE_TILE_LAYER; }, text: function(text) { var zipped = bops.from(text.trim(), 'base64'); var oldUnresolvedLayer = unresolvedLayer; var oldLayer = layer; pend.go(function(cb) { zlib.gunzip(zipped, function(err, buf) { if (err) { cb(err); return; } unresolvedLayer = oldUnresolvedLayer; layer = oldLayer; unpackTileBytes(buf); cb(); }); }); }, }; states[STATE_TILE_DATA_B64_ZLIB] = { opentag: function(tag) { waitForClose(); }, closetag: function(name) { state = STATE_TILE_LAYER; }, text: function(text) { var zipped = bops.from(text.trim(), 'base64'); var oldUnresolvedLayer = unresolvedLayer; var oldLayer = layer; pend.go(function(cb) { zlib.inflate(zipped, function(err, buf) { if (err) { cb(err); return; } layer = oldLayer; unresolvedLayer = oldUnresolvedLayer; unpackTileBytes(buf); cb(); }); }); }, }; states[STATE_TERRAIN_TYPES] = { opentag: function(tag) { if (tag.name === 'TERRAIN') { terrain = new Terrain(); terrain.name = tag.attributes.NAME; terrain.tile = int(tag.attributes.TILE); tileSet.terrainTypes.push(terrain); state = STATE_TERRAIN; } else { waitForClose(); } }, closetag: function(name) { state = STATE_TILESET; }, text: noop, }; states[STATE_TERRAIN] = { opentag: function(tag) { if (tag.name === 'PROPERTIES') { collectProperties(terrain.properties); } else { waitForClose(); } }, closetag: function(name) { state = STATE_TERRAIN_TYPES; }, text: noop, }; parser.onerror = cb; parser.onopentag = function(tag) { states[state].opentag(tag); }; parser.onclosetag = function(name) { states[state].closetag(name); }; parser.ontext = function(text) { states[state].text(text); }; parser.onend = function() { // wait until async stuff has finished pend.wait(function(err) { if (err) { cb(err); return; } // now all tilesets are resolved and all data is decoded unresolvedLayers.forEach(resolveLayer); cb(null, topLevelObject); }); }; parser.write(content).close(); function resolveTerrain(terrainIndexStr) { return tileSet.terrainTypes[parseInt(terrainIndexStr, 10)]; } function saveTile(gid) { layer.horizontalFlips[tileIndex] = !!(gid & FLIPPED_HORIZONTALLY_FLAG); layer.verticalFlips[tileIndex] = !!(gid & FLIPPED_VERTICALLY_FLAG); layer.diagonalFlips[tileIndex] = !!(gid & FLIPPED_DIAGONALLY_FLAG); gid &= ~(FLIPPED_HORIZONTALLY_FLAG | FLIPPED_VERTICALLY_FLAG | FLIPPED_DIAGONALLY_FLAG); unresolvedLayer.tiles[tileIndex] = gid; tileIndex += 1; } function collectImage(tag) { var img = new Image(); img.format = tag.attributes.FORMAT; img.source = tag.attributes.SOURCE; img.trans = tag.attributes.TRANS; img.width = int(tag.attributes.WIDTH); img.height = int(tag.attributes.HEIGHT); // TODO: read possible waitForClose(); return img; } function collectTileSet(tag, nextState) { tileSet = new TileSet(); tileSet.firstGid = int(tag.attributes.FIRSTGID); tileSet.source = tag.attributes.SOURCE; tileSet.name = tag.attributes.NAME; tileSet.tileWidth = int(tag.attributes.TILEWIDTH); tileSet.tileHeight = int(tag.attributes.TILEHEIGHT); tileSet.spacing = int(tag.attributes.SPACING); tileSet.margin = int(tag.attributes.MARGIN); if (tileSet.source) { pend.go(function(cb) { resolveTileSet(tileSet, cb); }); } state = STATE_TILESET; tileSetNextState = nextState; } function collectProperties(obj) { propertiesObject = obj; propertiesNextState = state; state = STATE_COLLECT_PROPS; } function waitForClose() { waitForCloseNextState = state; state = STATE_WAIT_FOR_CLOSE; waitForCloseOpenCount = 1; } function error(err) { parser.onerror = null; parser.onopentag = null; parser.onclosetag = null; parser.ontext = null; parser.onend = null; cb(err); } function resolveTileSet(unresolvedTileSet, cb) { var target = path.join(pathToDir, unresolvedTileSet.source); parseFile(target, function(err, resolvedTileSet) { if (err) { cb(err); return; } resolvedTileSet.mergeTo(unresolvedTileSet); cb(); }); } function resolveLayer(unresolvedLayer) { for (var i = 0; i < unresolvedLayer.tiles.length; i += 1) { var globalTileId = unresolvedLayer.tiles[i]; for (var tileSetIndex = map.tileSets.length - 1; tileSetIndex >= 0; tileSetIndex -= 1) { var tileSet = map.tileSets[tileSetIndex]; if (tileSet.firstGid <= globalTileId) { var tileId = globalTileId - tileSet.firstGid; var tile = tileSet.tiles[tileId]; if (!tile) { // implicit tile tile = new Tile(); tile.id = tileId; tileSet.tiles[tileId] = tile; } unresolvedLayer.layer.tiles[i] = tile; break; } } } } function unpackTileBytes(buf) { var expectedCount = map.width * map.height * 4; if (buf.length !== expectedCount) { error(new Error("Expected " + expectedCount + " bytes of tile data; received " + buf.length)); return; } tileIndex = 0; for (var i = 0; i < expectedCount; i += 4) { saveTile(readUInt32LE(buf, i)); } } } function defaultReadFile(name, cb) { fs.readFile(name, { encoding: 'utf8' }, cb); } function parseFile(name, cb) { exports.readFile(name, function(err, content) { if (err) { cb(err); } else { parse(content, name, cb); } }); } function parsePoints(str) { var points = str.split(" "); return points.map(function(pt) { var xy = pt.split(","); return { x: xy[0], y: xy[1], }; }); } // needed until https://github.com/chrisdickinson/bops/pull/7 is resolved function readUInt32LE(buf, offset) { offset = ~~offset; var val = 0; val = buf[offset + 2] << 16; val |= buf[offset + 1] << 8; val |= buf[offset]; return val + (buf[offset + 3] << 24 >>> 0); } function noop() {} function int(value, defaultValue) { defaultValue = defaultValue == null ? null : defaultValue; return value == null ? defaultValue : parseInt(value, 10); } function bool(value, defaultValue) { defaultValue = defaultValue == null ? null : defaultValue; return value == null ? defaultValue : !!parseInt(value, 10); } function float(value, defaultValue) { defaultValue = defaultValue == null ? null : defaultValue; return value == null ? defaultValue : parseFloat(value, 10); } function Map() { this.version = null; this.orientation = "orthogonal"; this.width = 0; this.height = 0; this.tileWidth = 0; this.tileHeight = 0; this.backgroundColor = null; this.layers = []; this.properties = {}; this.tileSets = []; } function TileSet() { this.firstGid = 0; this.source = ""; this.name = ""; this.tileWidth = 0; this.tileHeight = 0; this.spacing = 0; this.margin = 0; this.tileOffset = {x: 0, y: 0}; this.properties = {}; this.image = null; this.tiles = []; this.terrainTypes = []; } TileSet.prototype.mergeTo = function(other) { other.firstGid = this.firstGid == null ? other.firstGid : this.firstGid; other.source = this.source == null ? other.source : this.source; other.name = this.name == null ? other.name : this.name; other.tileWidth = this.tileWidth == null ? other.tileWidth : this.tileWidth; other.tileHeight = this.tileHeight == null ? other.tileHeight : this.tileHeight; other.spacing = this.spacing == null ? other.spacing : this.spacing; other.margin = this.margin == null ? other.margin : this.margin; other.tileOffset = this.tileOffset == null ? other.tileOffset : this.tileOffset; other.properties = this.properties == null ? other.properties : this.properties; other.image = this.image == null ? other.image : this.image; other.tiles = this.tiles == null ? other.tiles : this.tiles; other.terrainTypes = this.terrainTypes == null ? other.terrainTypes : this.terrainTypes; }; function Image() { this.format = null; this.source = ""; this.trans = null; this.width = 0; this.height = 0; } function Tile() { this.id = 0; this.terrain = []; this.probability = null; this.properties = {}; this.image = null; } function TileLayer(map) { var tileCount = map.width * map.height; this.map = map; this.type = "tile"; this.name = null; this.opacity = 1; this.visible = true; this.properties = {}; this.tiles = new Array(tileCount); this.horizontalFlips = new Array(tileCount); this.verticalFlips = new Array(tileCount); this.diagonalFlips = new Array(tileCount); } TileLayer.prototype.tileAt = function(x, y) { return this.tiles[y * this.map.width + x]; }; TileLayer.prototype.setTileAt = function(x, y, tile) { this.tiles[y * this.map.width + x] = tile; }; function ObjectLayer() { this.type = "object"; this.name = null; this.color = null; this.opacity = 1; this.visible = true; this.properties = {}; this.objects = []; } function ImageLayer() { this.type = "image"; this.name = null; this.opacity = 1; this.visible = true; this.properties = {}; this.image = null; } function TmxObject() { this.name = null; this.type = null; this.x = 0; this.y = 0; this.width = 0; this.height = 0; this.rotation = 0; this.properties = {}; this.gid = null; this.visible = true; this.ellipse = false; this.polygon = null; this.polyline = null; } function Terrain() { this.name = ""; this.tile = 0; this.properties = {}; } },{"bops":12,"fs":2,"path":3,"pend":25,"sax":26,"zlib":6}],12:[function(require,module,exports){ var proto = {} module.exports = proto proto.from = require('./from.js') proto.to = require('./to.js') proto.is = require('./is.js') proto.subarray = require('./subarray.js') proto.join = require('./join.js') proto.copy = require('./copy.js') proto.create = require('./create.js') mix(require('./read.js'), proto) mix(require('./write.js'), proto) function mix(from, into) { for(var key in from) { into[key] = from[key] } } },{"./copy.js":15,"./create.js":16,"./from.js":17,"./is.js":18,"./join.js":19,"./read.js":21,"./subarray.js":22,"./to.js":23,"./write.js":24}],13:[function(require,module,exports){ (function (exports) { 'use strict'; var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; function b64ToByteArray(b64) { var i, j, l, tmp, placeHolders, arr; if (b64.length % 4 > 0) { throw 'Invalid string. Length must be a multiple of 4'; } // the number of equal signs (place holders) // if there are two placeholders, than the two characters before it // represent one byte // if there is only one, then the three characters before it represent 2 bytes // this is just a cheap hack to not do indexOf twice placeHolders = b64.indexOf('='); placeHolders = placeHolders > 0 ? b64.length - placeHolders : 0; // base64 is 4/3 + up to two characters of the original data arr = [];//new Uint8Array(b64.length * 3 / 4 - placeHolders); // if there are placeholders, only get up to the last complete 4 chars l = placeHolders > 0 ? b64.length - 4 : b64.length; for (i = 0, j = 0; i < l; i += 4, j += 3) { tmp = (lookup.indexOf(b64[i]) << 18) | (lookup.indexOf(b64[i + 1]) << 12) | (lookup.indexOf(b64[i + 2]) << 6) | lookup.indexOf(b64[i + 3]); arr.push((tmp & 0xFF0000) >> 16); arr.push((tmp & 0xFF00) >> 8); arr.push(tmp & 0xFF); } if (placeHolders === 2) { tmp = (lookup.indexOf(b64[i]) << 2) | (lookup.indexOf(b64[i + 1]) >> 4); arr.push(tmp & 0xFF); } else if (placeHolders === 1) { tmp = (lookup.indexOf(b64[i]) << 10) | (lookup.indexOf(b64[i + 1]) << 4) | (lookup.indexOf(b64[i + 2]) >> 2); arr.push((tmp >> 8) & 0xFF); arr.push(tmp & 0xFF); } return arr; } function uint8ToBase64(uint8) { var i, extraBytes = uint8.length % 3, // if we have 1 byte left, pad 2 bytes output = "", temp, length; function tripletToBase64 (num) { return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F]; }; // go through the array every three bytes, we'll deal with trailing stuff later for (i = 0, length = uint8.length - extraBytes; i < length; i += 3) { temp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]); output += tripletToBase64(temp); } // pad the end with zeros, but make sure to not forget the extra bytes switch (extraBytes) { case 1: temp = uint8[uint8.length - 1]; output += lookup[temp >> 2]; output += lookup[(temp << 4) & 0x3F]; output += '=='; break; case 2: temp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1]); output += lookup[temp >> 10]; output += lookup[(temp >> 4) & 0x3F]; output += lookup[(temp << 2) & 0x3F]; output += '='; break; } return output; } module.exports.toByteArray = b64ToByteArray; module.exports.fromByteArray = uint8ToBase64; }()); },{}],14:[function(require,module,exports){ module.exports = to_utf8 var out = [] , col = [] , fcc = String.fromCharCode , mask = [0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01] , unmask = [ 0x00 , 0x01 , 0x02 | 0x01 , 0x04 | 0x02 | 0x01 , 0x08 | 0x04 | 0x02 | 0x01 , 0x10 | 0x08 | 0x04 | 0x02 | 0x01 , 0x20 | 0x10 | 0x08 | 0x04 | 0x02 | 0x01 , 0x40 | 0x20 | 0x10 | 0x08 | 0x04 | 0x02 | 0x01 ] function to_utf8(bytes, start, end) { start = start === undefined ? 0 : start end = end === undefined ? bytes.length : end var idx = 0 , hi = 0x80 , collecting = 0 , pos , by col.length = out.length = 0 while(idx < bytes.length) { by = bytes[idx] if(!collecting && by & hi) { pos = find_pad_position(by) collecting += pos if(pos < 8) { col[col.length] = by & unmask[6 - pos] } } else if(collecting) { col[col.length] = by & unmask[6] --collecting if(!collecting && col.length) { out[out.length] = fcc(reduced(col, pos)) col.length = 0 } } else { out[out.length] = fcc(by) } ++idx } if(col.length && !collecting) { out[out.length] = fcc(reduced(col, pos)) col.length = 0 } return out.join('') } function find_pad_position(byt) { for(var i = 0; i < 7; ++i) { if(!(byt & mask[i])) { break } } return i } function reduced(list) { var out = 0 for(var i = 0, len = list.length; i < len; ++i) { out |= list[i] << ((len - i - 1) * 6) } return out } },{}],15:[function(require,module,exports){ module.exports = copy var slice = [].slice function copy(source, target, target_start, source_start, source_end) { target_start = arguments.length < 3 ? 0 : target_start source_start = arguments.length < 4 ? 0 : source_start source_end = arguments.length < 5 ? source.length : source_end if(source_end === source_start) { return } if(target.length === 0 || source.length === 0) { return } if(source_end > source.length) { source_end = source.length } if(target.length - target_start < source_end - source_start) { source_end = target.length - target_start + start } if(source.buffer !== target.buffer) { return fast_copy(source, target, target_start, source_start, source_end) } return slow_copy(source, target, target_start, source_start, source_end) } function fast_copy(source, target, target_start, source_start, source_end) { var len = (source_end - source_start) + target_start for(var i = target_start, j = source_start; i < len; ++i, ++j) { target[i] = source[j] } } function slow_copy(from, to, j, i, jend) { // the buffers could overlap. var iend = jend + i , tmp = new Uint8Array(slice.call(from, i, iend)) , x = 0 for(; i < iend; ++i, ++x) { to[j++] = tmp[x] } } },{}],16:[function(require,module,exports){ module.exports = function(size) { return new Uint8Array(size) } },{}],17:[function(require,module,exports){ module.exports = from var base64 = require('base64-js') var decoders = { hex: from_hex , utf8: from_utf , base64: from_base64 } function from(source, encoding) { if(Array.isArray(source)) { return new Uint8Array(source) } return decoders[encoding || 'utf8'](source) } function from_hex(str) { var size = str.length / 2 , buf = new Uint8Array(size) , character = '' for(var i = 0, len = str.length; i < len; ++i) { character += str.charAt(i) if(i > 0 && (i % 2) === 1) { buf[i>>>1] = parseInt(character, 16) character = '' } } return buf } function from_utf(str) { var bytes = [] , tmp , ch for(var i = 0, len = str.length; i < len; ++i) { ch = str.charCodeAt(i) if(ch & 0x80) { tmp = encodeURIComponent(str.charAt(i)).substr(1).split('%') for(var j = 0, jlen = tmp.length; j < jlen; ++j) { bytes[bytes.length] = parseInt(tmp[j], 16) } } else { bytes[bytes.length] = ch } } return new Uint8Array(bytes) } function from_base64(str) { return new Uint8Array(base64.toByteArray(str)) } },{"base64-js":13}],18:[function(require,module,exports){ module.exports = function(buffer) { return buffer instanceof Uint8Array; } },{}],19:[function(require,module,exports){ module.exports = join function join(targets, hint) { if(!targets.length) { return new Uint8Array(0) } var len = hint !== undefined ? hint : get_length(targets) , out = new Uint8Array(len) , cur = targets[0] , curlen = cur.length , curidx = 0 , curoff = 0 , i = 0 while(i < len) { if(curoff === curlen) { curoff = 0 ++curidx cur = targets[curidx] curlen = cur && cur.length continue } out[i++] = cur[curoff++] } return out } function get_length(targets) { var size = 0 for(var i = 0, len = targets.length; i < len; ++i) { size += targets[i].byteLength } return size } },{}],20:[function(require,module,exports){ var proto , map module.exports = proto = {} map = typeof WeakMap === 'undefined' ? null : new WeakMap proto.get = !map ? no_weakmap_get : get function no_weakmap_get(target) { return new DataView(target.buffer, 0) } function get(target) { var out = map.get(target.buffer) if(!out) { map.set(target.buffer, out = new DataView(target.buffer, 0)) } return out } },{}],21:[function(require,module,exports){ module.exports = { readUInt8: read_uint8 , readInt8: read_int8 , readUInt16LE: read_uint16_le , readUInt32LE: read_uint32_le , readInt16LE: read_int16_le , readInt32LE: read_int32_le , readFloatLE: read_float_le , readDoubleLE: read_double_le , readUInt16BE: read_uint16_be , readUInt32BE: read_uint32_be , readInt16BE: read_int16_be , readInt32BE: read_int32_be , readFloatBE: read_float_be , readDoubleBE: read_double_be } var map = require('./mapped.js') function read_uint8(target, at) { return target[at] } function read_int8(target, at) { var v = target[at]; return v < 0x80 ? v : v - 0x100 } function read_uint16_le(target, at) { var dv = map.get(target); return dv.getUint16(at + target.byteOffset, true) } function read_uint32_le(target, at) { var dv = map.get(target); return dv.getUint32(at + target.byteOffset, true) } function read_int16_le(target, at) { var dv = map.get(target); return dv.getInt16(at + target.byteOffset, true) } function read_int32_le(target, at) { var dv = map.get(target); return dv.getInt32(at + target.byteOffset, true) } function read_float_le(target, at) { var dv = map.get(target); return dv.getFloat32(at + target.byteOffset, true) } function read_double_le(target, at) { var dv = map.get(target); return dv.getFloat64(at + target.byteOffset, true) } function read_uint16_be(target, at) { var dv = map.get(target); return dv.getUint16(at + target.byteOffset, false) } function read_uint32_be(target, at) { var dv = map.get(target); return dv.getUint32(at + target.byteOffset, false) } function read_int16_be(target, at) { var dv = map.get(target); return dv.getInt16(at + target.byteOffset, false) } function read_int32_be(target, at) { var dv = map.get(target); return dv.getInt32(at + target.byteOffset, false) } function read_float_be(target, at) { var dv = map.get(target); return dv.getFloat32(at + target.byteOffset, false) } function read_double_be(target, at) { var dv = map.get(target); return dv.getFloat64(at + target.byteOffset, false) } },{"./mapped.js":20}],22:[function(require,module,exports){ module.exports = subarray function subarray(buf, from, to) { return buf.subarray(from || 0, to || buf.length) } },{}],23:[function(require,module,exports){ module.exports = to var base64 = require('base64-js') , toutf8 = require('to-utf8') var encoders = { hex: to_hex , utf8: to_utf , base64: to_base64 } function to(buf, encoding) { return encoders[encoding || 'utf8'](buf) } function to_hex(buf) { var str = '' , byt for(var i = 0, len = buf.length; i < len; ++i) { byt = buf[i] str += ((byt & 0xF0) >>> 4).toString(16) str += (byt & 0x0F).toString(16) } return str } function to_utf(buf) { return toutf8(buf) } function to_base64(buf) { return base64.fromByteArray(buf) } },{"base64-js":13,"to-utf8":14}],24:[function(require,module,exports){ module.exports = { writeUInt8: write_uint8 , writeInt8: write_int8 , writeUInt16LE: write_uint16_le , writeUInt32LE: write_uint32_le , writeInt16LE: write_int16_le , writeInt32LE: write_int32_le , writeFloatLE: write_float_le , writeDoubleLE: write_double_le , writeUInt16BE: write_uint16_be , writeUInt32BE: write_uint32_be , writeInt16BE: write_int16_be , writeInt32BE: write_int32_be , writeFloatBE: write_float_be , writeDoubleBE: write_double_be } var map = require('./mapped.js') function write_uint8(target, value, at) { return target[at] = value } function write_int8(target, value, at) { return target[at] = value < 0 ? value + 0x100 : value } function write_uint16_le(target, value, at) { var dv = map.get(target); return dv.setUint16(at + target.byteOffset, value, true) } function write_uint32_le(target, value, at) { var dv = map.get(target); return dv.setUint32(at + target.byteOffset, value, true) } function write_int16_le(target, value, at) { var dv = map.get(target); return dv.setInt16(at + target.byteOffset, value, true) } function write_int32_le(target, value, at) { var dv = map.get(target); return dv.setInt32(at + target.byteOffset, value, true) } function write_float_le(target, value, at) { var dv = map.get(target); return dv.setFloat32(at + target.byteOffset, value, true) } function write_double_le(target, value, at) { var dv = map.get(target); return dv.setFloat64(at + target.byteOffset, value, true) } function write_uint16_be(target, value, at) { var dv = map.get(target); return dv.setUint16(at + target.byteOffset, value, false) } function write_uint32_be(target, value, at) { var dv = map.get(target); return dv.setUint32(at + target.byteOffset, value, false) } function write_int16_be(target, value, at) { var dv = map.get(target); return dv.setInt16(at + target.byteOffset, value, false) } function write_int32_be(target, value, at) { var dv = map.get(target); return dv.setInt32(at + target.byteOffset, value, false) } function write_float_be(target, value, at) { var dv = map.get(target); return dv.setFloat32(at + target.byteOffset, value, false) } function write_double_be(target, value, at) { var dv = map.get(target); return dv.setFloat64(at + target.byteOffset, value, false) } },{"./mapped.js":20}],25:[function(require,module,exports){ module.exports = Pend; function Pend() { this.pending = 0; this.listeners = []; this.error = null; } Pend.prototype.go = function(fn) { pendGo(this, fn); }; Pend.prototype.wait = function(cb) { if (this.pending === 0) { cb(this.error); } else { this.listeners.push(cb); } }; function pendGo(self, fn) { self.pending += 1; fn(onCb); function onCb(err) { self.error = self.error || err; self.pending -= 1; if (self.pending < 0) throw new Error("Callback called twice."); if (self.pending === 0) { self.listeners.forEach(cbListener); self.listeners = []; } } function cbListener(listener) { listener(self.error); } } },{}],26:[function(require,module,exports){ // wrapper for non-node envs ;(function (sax) { sax.parser = function (strict, opt) { return new SAXParser(strict, opt) } sax.SAXParser = SAXParser sax.SAXStream = SAXStream sax.createStream = createStream // When we pass the MAX_BUFFER_LENGTH position, start checking for buffer overruns. // When we check, schedule the next check for MAX_BUFFER_LENGTH - (max(buffer lengths)), // since that's the earliest that a buffer overrun could occur. This way, checks are // as rare as required, but as often as necessary to ensure never crossing this bound. // Furthermore, buffers are only tested at most once per write(), so passing a very // large string into write() might have undesirable effects, but this is manageable by // the caller, so it is assumed to be safe. Thus, a call to write() may, in the extreme // edge case, result in creating at most one complete copy of the string passed in. // Set to Infinity to have unlimited buffers. sax.MAX_BUFFER_LENGTH = 64 * 1024 var buffers = [ "comment", "sgmlDecl", "textNode", "tagName", "doctype", "procInstName", "procInstBody", "entity", "attribName", "attribValue", "cdata", "script" ] sax.EVENTS = // for discoverability. [ "text" , "processinginstruction" , "sgmldeclaration" , "doctype" , "comment" , "attribute" , "opentag" , "closetag" , "opencdata" , "cdata" , "closecdata" , "error" , "end" , "ready" , "script" , "opennamespace" , "closenamespace" ] function SAXParser (strict, opt) { if (!(this instanceof SAXParser)) return new SAXParser(strict, opt) var parser = this clearBuffers(parser) parser.q = parser.c = "" parser.bufferCheckPosition = sax.MAX_BUFFER_LENGTH parser.opt = opt || {} parser.opt.lowercase = parser.opt.lowercase || parser.opt.lowercasetags parser.looseCase = parser.opt.lowercase ? "toLowerCase" : "toUpperCase" parser.tags = [] parser.closed = parser.closedRoot = parser.sawRoot = false parser.tag = parser.error = null parser.strict = !!strict parser.noscript = !!(strict || parser.opt.noscript) parser.state = S.BEGIN parser.ENTITIES = Object.create(sax.ENTITIES) parser.attribList = [] // namespaces form a prototype chain. // it always points at the current tag, // which protos to its parent tag. if (parser.opt.xmlns) parser.ns = Object.create(rootNS) // mostly just for error reporting parser.trackPosition = parser.opt.position !== false if (parser.trackPosition) { parser.position = parser.line = parser.column = 0 } emit(parser, "onready") } if (!Object.create) Object.create = function (o) { function f () { this.__proto__ = o } f.prototype = o return new f } if (!Object.getPrototypeOf) Object.getPrototypeOf = function (o) { return o.__proto__ } if (!Object.keys) Object.keys = function (o) { var a = [] for (var i in o) if (o.hasOwnProperty(i)) a.push(i) return a } function checkBufferLength (parser) { var maxAllowed = Math.max(sax.MAX_BUFFER_LENGTH, 10) , maxActual = 0 for (var i = 0, l = buffers.length; i < l; i ++) { var len = parser[buffers[i]].length if (len > maxAllowed) { // Text/cdata nodes can get big, and since they're buffered, // we can get here under normal conditions. // Avoid issues by emitting the text node now, // so at least it won't get any bigger. switch (buffers[i]) { case "textNode": closeText(parser) break case "cdata": emitNode(parser, "oncdata", parser.cdata) parser.cdata = "" break case "script": emitNode(parser, "onscript", parser.script) parser.script = "" break default: error(parser, "Max buffer length exceeded: "+buffers[i]) } } maxActual = Math.max(maxActual, len) } // schedule the next check for the earliest possible buffer overrun. parser.bufferCheckPosition = (sax.MAX_BUFFER_LENGTH - maxActual) + parser.position } function clearBuffers (parser) { for (var i = 0, l = buffers.length; i < l; i ++) { parser[buffers[i]] = "" } } SAXParser.prototype = { end: function () { end(this) } , write: write , resume: function () { this.error = null; return this } , close: function () { return this.write(null) } } try { var Stream = require("stream").Stream } catch (ex) { var Stream = function () {} } var streamWraps = sax.EVENTS.filter(function (ev) { return ev !== "error" && ev !== "end" }) function createStream (strict, opt) { return new SAXStream(strict, opt) } function SAXStream (strict, opt) { if (!(this instanceof SAXStream)) return new SAXStream(strict, opt) Stream.apply(this) this._parser = new SAXParser(strict, opt) this.writable = true this.readable = true var me = this this._parser.onend = function () { me.emit("end") } this._parser.onerror = function (er) { me.emit("error", er) // if didn't throw, then means error was handled. // go ahead and clear error, so we can write again. me._parser.error = null } streamWraps.forEach(function (ev) { Object.defineProperty(me, "on" + ev, { get: function () { return me._parser["on" + ev] }, set: function (h) { if (!h) { me.removeAllListeners(ev) return me._parser["on"+ev] = h } me.on(ev, h) }, enumerable: true, configurable: false }) }) } SAXStream.prototype = Object.create(Stream.prototype, { constructor: { value: SAXStream } }) SAXStream.prototype.write = function (data) { this._parser.write(data.toString()) this.emit("data", data) return true } SAXStream.prototype.end = function (chunk) { if (chunk && chunk.length) this._parser.write(chunk.toString()) this._parser.end() return true } SAXStream.prototype.on = function (ev, handler) { var me = this if (!me._parser["on"+ev] && streamWraps.indexOf(ev) !== -1) { me._parser["on"+ev] = function () { var args = arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments) args.splice(0, 0, ev) me.emit.apply(me, args) } } return Stream.prototype.on.call(me, ev, handler) } // character classes and tokens var whitespace = "\r\n\t " // this really needs to be replaced with character classes. // XML allows all manner of ridiculous numbers and digits. , number = "0124356789" , letter = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" // (Letter | "_" | ":") , quote = "'\"" , entity = number+letter+"#" , attribEnd = whitespace + ">" , CDATA = "[CDATA[" , DOCTYPE = "DOCTYPE" , XML_NAMESPACE = "http://www.w3.org/XML/1998/namespace" , XMLNS_NAMESPACE = "http://www.w3.org/2000/xmlns/" , rootNS = { xml: XML_NAMESPACE, xmlns: XMLNS_NAMESPACE } // turn all the string character sets into character class objects. whitespace = charClass(whitespace) number = charClass(number) letter = charClass(letter) // http://www.w3.org/TR/REC-xml/#NT-NameStartChar // This implementation works on strings, a single character at a time // as such, it cannot ever support astral-plane characters (10000-EFFFF) // without a significant breaking change to either this parser, or the // JavaScript language. Implementation of an emoji-capable xml parser // is left as an exercise for the reader. var nameStart = /[:_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]/ var nameBody = /[:_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u00B7\u0300-\u036F\u203F-\u2040\.\d-]/ quote = charClass(quote) entity = charClass(entity) attribEnd = charClass(attribEnd) function charClass (str) { return str.split("").reduce(function (s, c) { s[c] = true return s }, {}) } function isRegExp (c) { return Object.prototype.toString.call(c) === '[object RegExp]' } function is (charclass, c) { return isRegExp(charclass) ? !!c.match(charclass) : charclass[c] } function not (charclass, c) { return !is(charclass, c) } var S = 0 sax.STATE = { BEGIN : S++ , TEXT : S++ // general stuff , TEXT_ENTITY : S++ // & and such. , OPEN_WAKA : S++ // < , SGML_DECL : S++ // , SCRIPT : S++ //