diff --git a/README.md b/README.md index 37bd36d..4e15472 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,30 @@ room.onLeave.add(function() { - [Server documentation](https://github.com/gamestdio/colyseus/wiki) - [Official examples](https://github.com/gamestdio/colyseus-examples) +## React Native compatibility + +This client works with React Native. You need to install an aditional dependency +for compatibility. +``` +npm install react-native-browser-polyfill +``` + +``` +// App.js +require('react-native-browser-polyfill'); +``` + +The only caveat inside React Native environment is that you can only join rooms +after the first connection open. + +``` +var client = new Colyseus.Client('ws://localhost:2657'); + +client.onOpen.add(() => { + let room = client.join("your_room"); +}) +``` + ## License MIT diff --git a/dist/colyseus.js b/dist/colyseus.js index 888bf3d..3df576e 100644 --- a/dist/colyseus.js +++ b/dist/colyseus.js @@ -34,9 +34,6 @@ var Colyseus = /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ -/******/ // identity function for calling harmony imports with the correct context -/******/ __webpack_require__.i = function(value) { return value; }; -/******/ /******/ // define getter function for harmony exports /******/ __webpack_require__.d = function(exports, name, getter) { /******/ if(!__webpack_require__.o(exports, name)) { @@ -64,7 +61,7 @@ var Colyseus = /******/ __webpack_require__.p = ""; /******/ /******/ // Load entry module and return exports -/******/ return __webpack_require__(__webpack_require__.s = 59); +/******/ return __webpack_require__(__webpack_require__.s = 27); /******/ }) /************************************************************************/ /******/ ([ @@ -73,7 +70,7 @@ var Colyseus = // bufferish.js -var Buffer = exports.global = __webpack_require__(36); +var Buffer = exports.global = __webpack_require__(29); var hasBuffer = exports.hasBuffer = Buffer && !!Buffer.isBuffer; var hasArrayBuffer = exports.hasArrayBuffer = ("undefined" !== typeof ArrayBuffer); @@ -86,9 +83,9 @@ exports.alloc = alloc; exports.concat = concat; exports.from = from; -var BufferArray = exports.Array = __webpack_require__(38); -var BufferBuffer = exports.Buffer = __webpack_require__(39); -var BufferUint8Array = exports.Uint8Array = __webpack_require__(40); +var BufferArray = exports.Array = __webpack_require__(32); +var BufferBuffer = exports.Buffer = __webpack_require__(33); +var BufferUint8Array = exports.Uint8Array = __webpack_require__(34); var BufferProto = exports.prototype = __webpack_require__(8); /** @@ -456,28 +453,112 @@ exports.Slot = Slot; /* 4 */ /***/ (function(module, exports, __webpack_require__) { -"use strict"; +// browser.js -// Use codes between 0~127 for lesser throughput (1 byte) -Object.defineProperty(exports, "__esModule", { value: true }); -var Protocol; -(function (Protocol) { - // User-related (0~10) - Protocol[Protocol["USER_ID"] = 1] = "USER_ID"; - // Room-related (10~20) - Protocol[Protocol["JOIN_ROOM"] = 10] = "JOIN_ROOM"; - Protocol[Protocol["JOIN_ERROR"] = 11] = "JOIN_ERROR"; - Protocol[Protocol["LEAVE_ROOM"] = 12] = "LEAVE_ROOM"; - Protocol[Protocol["ROOM_DATA"] = 13] = "ROOM_DATA"; - Protocol[Protocol["ROOM_STATE"] = 14] = "ROOM_STATE"; - Protocol[Protocol["ROOM_STATE_PATCH"] = 15] = "ROOM_STATE_PATCH"; - // Generic messages (50~60) - Protocol[Protocol["BAD_REQUEST"] = 50] = "BAD_REQUEST"; -})(Protocol = exports.Protocol || (exports.Protocol = {})); +exports.encode = __webpack_require__(13).encode; +exports.decode = __webpack_require__(18).decode; + +exports.Encoder = __webpack_require__(41).Encoder; +exports.Decoder = __webpack_require__(42).Decoder; + +exports.createCodec = __webpack_require__(43).createCodec; +exports.codec = __webpack_require__(44).codec; /***/ }), /* 5 */ +/***/ (function(module, exports, __webpack_require__) { + +// write-core.js + +var ExtBuffer = __webpack_require__(6).ExtBuffer; +var ExtPacker = __webpack_require__(36); +var WriteType = __webpack_require__(37); +var CodecBase = __webpack_require__(2); + +CodecBase.install({ + addExtPacker: addExtPacker, + getExtPacker: getExtPacker, + init: init +}); + +exports.preset = init.call(CodecBase.preset); + +function getEncoder(options) { + var writeType = WriteType.getWriteType(options); + return encode; + + function encode(encoder, value) { + var func = writeType[typeof value]; + if (!func) throw new Error("Unsupported type \"" + (typeof value) + "\": " + value); + func(encoder, value); + } +} + +function init() { + var options = this.options; + this.encode = getEncoder(options); + + if (options && options.preset) { + ExtPacker.setExtPackers(this); + } + + return this; +} + +function addExtPacker(etype, Class, packer) { + packer = CodecBase.filter(packer); + var name = Class.name; + if (name && name !== "Object") { + var packers = this.extPackers || (this.extPackers = {}); + packers[name] = extPacker; + } else { + // fallback for IE + var list = this.extEncoderList || (this.extEncoderList = []); + list.unshift([Class, extPacker]); + } + + function extPacker(value) { + if (packer) value = packer(value); + return new ExtBuffer(value, etype); + } +} + +function getExtPacker(value) { + var packers = this.extPackers || (this.extPackers = {}); + var c = value.constructor; + var e = c && c.name && packers[c.name]; + if (e) return e; + + // fallback for IE + var list = this.extEncoderList || (this.extEncoderList = []); + var len = list.length; + for (var i = 0; i < len; i++) { + var pair = list[i]; + if (c === pair[0]) return pair[1]; + } +} + + +/***/ }), +/* 6 */ +/***/ (function(module, exports, __webpack_require__) { + +// ext-buffer.js + +exports.ExtBuffer = ExtBuffer; + +var Bufferish = __webpack_require__(0); + +function ExtBuffer(buffer, type) { + if (!(this instanceof ExtBuffer)) return new ExtBuffer(buffer, type); + this.buffer = Bufferish.from(buffer); + this.type = type; +} + + +/***/ }), +/* 7 */ /***/ (function(module, exports) { exports.read = function (buffer, offset, isLE, mLen, nBytes) { @@ -567,7 +648,99 @@ exports.write = function (buffer, value, offset, isLE, mLen, nBytes) { /***/ }), -/* 6 */ +/* 8 */ +/***/ (function(module, exports, __webpack_require__) { + +// bufferish-proto.js + +/* jshint eqnull:true */ + +var BufferLite = __webpack_require__(35); + +exports.copy = copy; +exports.slice = slice; +exports.toString = toString; +exports.write = gen("write"); + +var Bufferish = __webpack_require__(0); +var Buffer = Bufferish.global; + +var isBufferShim = Bufferish.hasBuffer && ("TYPED_ARRAY_SUPPORT" in Buffer); +var brokenTypedArray = isBufferShim && !Buffer.TYPED_ARRAY_SUPPORT; + +/** + * @param target {Buffer|Uint8Array|Array} + * @param [targetStart] {Number} + * @param [start] {Number} + * @param [end] {Number} + * @returns {Buffer|Uint8Array|Array} + */ + +function copy(target, targetStart, start, end) { + var thisIsBuffer = Bufferish.isBuffer(this); + var targetIsBuffer = Bufferish.isBuffer(target); + if (thisIsBuffer && targetIsBuffer) { + // Buffer to Buffer + return this.copy(target, targetStart, start, end); + } else if (!brokenTypedArray && !thisIsBuffer && !targetIsBuffer && + Bufferish.isView(this) && Bufferish.isView(target)) { + // Uint8Array to Uint8Array (except for minor some browsers) + var buffer = (start || end != null) ? slice.call(this, start, end) : this; + target.set(buffer, targetStart); + return buffer.length; + } else { + // other cases + return BufferLite.copy.call(this, target, targetStart, start, end); + } +} + +/** + * @param [start] {Number} + * @param [end] {Number} + * @returns {Buffer|Uint8Array|Array} + */ + +function slice(start, end) { + // for Buffer, Uint8Array (except for minor some browsers) and Array + var f = this.slice || (!brokenTypedArray && this.subarray); + if (f) return f.call(this, start, end); + + // Uint8Array (for minor some browsers) + var target = Bufferish.alloc.call(this, end - start); + copy.call(this, target, 0, start, end); + return target; +} + +/** + * Buffer.prototype.toString() + * + * @param [encoding] {String} ignored + * @param [start] {Number} + * @param [end] {Number} + * @returns {String} + */ + +function toString(encoding, start, end) { + var f = (!isBufferShim && Bufferish.isBuffer(this)) ? this.toString : BufferLite.toString; + return f.apply(this, arguments); +} + +/** + * @private + */ + +function gen(method) { + return wrap; + + function wrap() { + var f = this[method] || BufferLite[method]; + return f.apply(this, arguments); + } +} + + +/***/ }), +/* 9 */ /***/ (function(module, exports, __webpack_require__) { /* WEBPACK VAR INJECTION */(function(Buffer) {// int64-buffer.js @@ -864,184 +1037,59 @@ var Uint64BE, Int64BE, Uint64LE, Int64LE; }(typeof exports === 'object' && typeof exports.nodeName !== 'string' ? exports : (this || {})); -/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(22).Buffer)) +/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(15).Buffer)) /***/ }), -/* 7 */ +/* 10 */ /***/ (function(module, exports, __webpack_require__) { -// browser.js - -exports.encode = __webpack_require__(18).encode; -exports.decode = __webpack_require__(16).decode; +// read-core.js -exports.Encoder = __webpack_require__(43).Encoder; -exports.Decoder = __webpack_require__(42).Decoder; +var ExtBuffer = __webpack_require__(6).ExtBuffer; +var ExtUnpacker = __webpack_require__(39); +var readUint8 = __webpack_require__(20).readUint8; +var ReadToken = __webpack_require__(40); +var CodecBase = __webpack_require__(2); -exports.createCodec = __webpack_require__(46).createCodec; -exports.codec = __webpack_require__(41).codec; +CodecBase.install({ + addExtUnpacker: addExtUnpacker, + getExtUnpacker: getExtUnpacker, + init: init +}); +exports.preset = init.call(CodecBase.preset); -/***/ }), -/* 8 */ -/***/ (function(module, exports, __webpack_require__) { +function getDecoder(options) { + var readToken = ReadToken.getReadToken(options); + return decode; -// bufferish-proto.js + function decode(decoder) { + var type = readUint8(decoder); + var func = readToken[type]; + if (!func) throw new Error("Invalid type: " + (type ? ("0x" + type.toString(16)) : type)); + return func(decoder); + } +} -/* jshint eqnull:true */ +function init() { + var options = this.options; + this.decode = getDecoder(options); -var BufferLite = __webpack_require__(37); + if (options && options.preset) { + ExtUnpacker.setExtUnpackers(this); + } -exports.copy = copy; -exports.slice = slice; -exports.toString = toString; -exports.write = gen("write"); + return this; +} -var Bufferish = __webpack_require__(0); -var Buffer = Bufferish.global; +function addExtUnpacker(etype, unpacker) { + var unpackers = this.extUnpackers || (this.extUnpackers = []); + unpackers[etype] = CodecBase.filter(unpacker); +} -var isBufferShim = Bufferish.hasBuffer && ("TYPED_ARRAY_SUPPORT" in Buffer); -var brokenTypedArray = isBufferShim && !Buffer.TYPED_ARRAY_SUPPORT; - -/** - * @param target {Buffer|Uint8Array|Array} - * @param [targetStart] {Number} - * @param [start] {Number} - * @param [end] {Number} - * @returns {Buffer|Uint8Array|Array} - */ - -function copy(target, targetStart, start, end) { - var thisIsBuffer = Bufferish.isBuffer(this); - var targetIsBuffer = Bufferish.isBuffer(target); - if (thisIsBuffer && targetIsBuffer) { - // Buffer to Buffer - return this.copy(target, targetStart, start, end); - } else if (!brokenTypedArray && !thisIsBuffer && !targetIsBuffer && - Bufferish.isView(this) && Bufferish.isView(target)) { - // Uint8Array to Uint8Array (except for minor some browsers) - var buffer = (start || end != null) ? slice.call(this, start, end) : this; - target.set(buffer, targetStart); - return buffer.length; - } else { - // other cases - return BufferLite.copy.call(this, target, targetStart, start, end); - } -} - -/** - * @param [start] {Number} - * @param [end] {Number} - * @returns {Buffer|Uint8Array|Array} - */ - -function slice(start, end) { - // for Buffer, Uint8Array (except for minor some browsers) and Array - var f = this.slice || (!brokenTypedArray && this.subarray); - if (f) return f.call(this, start, end); - - // Uint8Array (for minor some browsers) - var target = Bufferish.alloc.call(this, end - start); - copy.call(this, target, 0, start, end); - return target; -} - -/** - * Buffer.prototype.toString() - * - * @param [encoding] {String} ignored - * @param [start] {Number} - * @param [end] {Number} - * @returns {String} - */ - -function toString(encoding, start, end) { - var f = (!isBufferShim && Bufferish.isBuffer(this)) ? this.toString : BufferLite.toString; - return f.apply(this, arguments); -} - -/** - * @private - */ - -function gen(method) { - return wrap; - - function wrap() { - var f = this[method] || BufferLite[method]; - return f.apply(this, arguments); - } -} - - -/***/ }), -/* 9 */ -/***/ (function(module, exports, __webpack_require__) { - -// ext-buffer.js - -exports.ExtBuffer = ExtBuffer; - -var Bufferish = __webpack_require__(0); - -function ExtBuffer(buffer, type) { - if (!(this instanceof ExtBuffer)) return new ExtBuffer(buffer, type); - this.buffer = Bufferish.from(buffer); - this.type = type; -} - - -/***/ }), -/* 10 */ -/***/ (function(module, exports, __webpack_require__) { - -// read-core.js - -var ExtBuffer = __webpack_require__(9).ExtBuffer; -var ExtUnpacker = __webpack_require__(45); -var readUint8 = __webpack_require__(20).readUint8; -var ReadToken = __webpack_require__(47); -var CodecBase = __webpack_require__(2); - -CodecBase.install({ - addExtUnpacker: addExtUnpacker, - getExtUnpacker: getExtUnpacker, - init: init -}); - -exports.preset = init.call(CodecBase.preset); - -function getDecoder(options) { - var readToken = ReadToken.getReadToken(options); - return decode; - - function decode(decoder) { - var type = readUint8(decoder); - var func = readToken[type]; - if (!func) throw new Error("Invalid type: " + (type ? ("0x" + type.toString(16)) : type)); - return func(decoder); - } -} - -function init() { - var options = this.options; - this.decode = getDecoder(options); - - if (options && options.preset) { - ExtUnpacker.setExtUnpackers(this); - } - - return this; -} - -function addExtUnpacker(etype, unpacker) { - var unpackers = this.extUnpackers || (this.extUnpackers = []); - unpackers[etype] = CodecBase.filter(unpacker); -} - -function getExtUnpacker(type) { - var unpackers = this.extUnpackers || (this.extUnpackers = []); - return unpackers[type] || extUnpacker; +function getExtUnpacker(type) { + var unpackers = this.extUnpackers || (this.extUnpackers = []); + return unpackers[type] || extUnpacker; function extUnpacker(buffer) { return new ExtBuffer(buffer, type); @@ -1053,85 +1101,10 @@ function getExtUnpacker(type) { /* 11 */ /***/ (function(module, exports, __webpack_require__) { -// write-core.js - -var ExtBuffer = __webpack_require__(9).ExtBuffer; -var ExtPacker = __webpack_require__(44); -var WriteType = __webpack_require__(49); -var CodecBase = __webpack_require__(2); - -CodecBase.install({ - addExtPacker: addExtPacker, - getExtPacker: getExtPacker, - init: init -}); - -exports.preset = init.call(CodecBase.preset); - -function getEncoder(options) { - var writeType = WriteType.getWriteType(options); - return encode; - - function encode(encoder, value) { - var func = writeType[typeof value]; - if (!func) throw new Error("Unsupported type \"" + (typeof value) + "\": " + value); - func(encoder, value); - } -} - -function init() { - var options = this.options; - this.encode = getEncoder(options); - - if (options && options.preset) { - ExtPacker.setExtPackers(this); - } - - return this; -} - -function addExtPacker(etype, Class, packer) { - packer = CodecBase.filter(packer); - var name = Class.name; - if (name && name !== "Object") { - var packers = this.extPackers || (this.extPackers = {}); - packers[name] = extPacker; - } else { - // fallback for IE - var list = this.extEncoderList || (this.extEncoderList = []); - list.unshift([Class, extPacker]); - } - - function extPacker(value) { - if (packer) value = packer(value); - return new ExtBuffer(value, etype); - } -} - -function getExtPacker(value) { - var packers = this.extPackers || (this.extPackers = {}); - var c = value.constructor; - var e = c && c.name && packers[c.name]; - if (e) return e; - - // fallback for IE - var list = this.extEncoderList || (this.extEncoderList = []); - var len = list.length; - for (var i = 0; i < len; i++) { - var pair = list[i]; - if (c === pair[0]) return pair[1]; - } -} - - -/***/ }), -/* 12 */ -/***/ (function(module, exports, __webpack_require__) { - "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -var SlotList_1 = __webpack_require__(26); +var SlotList_1 = __webpack_require__(25); var Slot_1 = __webpack_require__(3); /** * Allows the valueClasses to be set in MXML, e.g. @@ -1286,2669 +1259,2573 @@ exports.OnceSignal = OnceSignal; //# sourceMappingURL=OnceSignal.js.map /***/ }), -/* 13 */ +/* 12 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); +// Use codes between 0~127 for lesser throughput (1 byte) Object.defineProperty(exports, "__esModule", { value: true }); -var signals_js_1 = __webpack_require__(23); -var Clock = __webpack_require__(28); -var delta_listener_1 = __webpack_require__(34); -var msgpack = __webpack_require__(7); -var fossilDelta = __webpack_require__(35); -var Protocol_1 = __webpack_require__(4); -var Room = /** @class */ (function (_super) { - __extends(Room, _super); - function Room(name) { - var _this = _super.call(this, {}) || this; - _this.clock = new Clock(); // experimental - _this.remoteClock = new Clock(); // experimental - // Public signals - _this.onJoin = new signals_js_1.Signal(); - _this.onUpdate = new signals_js_1.Signal(); - _this.onData = new signals_js_1.Signal(); - _this.onError = new signals_js_1.Signal(); - _this.onLeave = new signals_js_1.Signal(); - _this.id = null; - _this.name = name; - _this.onLeave.add(function () { return _this.removeAllListeners(); }); - return _this; - } - Room.prototype.connect = function (connection) { - var _this = this; - this.connection = connection; - this.connection.onmessage = this.onMessageCallback.bind(this); - this.connection.onclose = function (e) { return _this.onLeave.dispatch(); }; - }; - Room.prototype.onMessageCallback = function (event) { - var message = msgpack.decode(new Uint8Array(event.data)); - var code = message[0]; - if (code == Protocol_1.Protocol.JOIN_ROOM) { - this.sessionId = message[1]; - this.onJoin.dispatch(); - } - else if (code == Protocol_1.Protocol.JOIN_ERROR) { - this.onError.dispatch(message[2]); - } - else if (code == Protocol_1.Protocol.ROOM_STATE) { - var state = message[2]; - var remoteCurrentTime = message[3]; - var remoteElapsedTime = message[4]; - this.setState(state, remoteCurrentTime, remoteElapsedTime); - } - else if (code == Protocol_1.Protocol.ROOM_STATE_PATCH) { - this.patch(message[2]); - } - else if (code == Protocol_1.Protocol.ROOM_DATA) { - this.onData.dispatch(message[2]); - } - else if (code == Protocol_1.Protocol.LEAVE_ROOM) { - this.leave(); - } - }; - Room.prototype.setState = function (state, remoteCurrentTime, remoteElapsedTime) { - this.set(state); - this._previousState = msgpack.encode(state); - // set remote clock properties - if (remoteCurrentTime && remoteElapsedTime) { - this.remoteClock.currentTime = remoteCurrentTime; - this.remoteClock.elapsedTime = remoteElapsedTime; - } - this.clock.start(); - this.onUpdate.dispatch(state); - }; - Room.prototype.patch = function (binaryPatch) { - // - // calculate client-side ping - // - var patchTime = Date.now(); - if (this.lastPatchTime) { - this.ping = patchTime - this.lastPatchTime; - } - this.lastPatchTime = patchTime; - this.clock.tick(); - // apply patch - this._previousState = fossilDelta.apply(this._previousState, binaryPatch); - // trigger state callbacks - this.set(msgpack.decode(this._previousState)); - this.onUpdate.dispatch(this.data); - }; - Room.prototype.leave = function () { - if (this.id) { - this.connection.close(); - } - }; - Room.prototype.send = function (data) { - this.connection.send([Protocol_1.Protocol.ROOM_DATA, this.id, data]); - }; - Room.prototype.removeAllListeners = function () { - _super.prototype.removeAllListeners.call(this); - this.onJoin.removeAll(); - this.onUpdate.removeAll(); - this.onData.removeAll(); - this.onError.removeAll(); - this.onLeave.removeAll(); - }; - return Room; -}(delta_listener_1.DeltaContainer)); -exports.Room = Room; +var Protocol; +(function (Protocol) { + // User-related (0~10) + Protocol[Protocol["USER_ID"] = 1] = "USER_ID"; + // Room-related (10~20) + Protocol[Protocol["JOIN_ROOM"] = 10] = "JOIN_ROOM"; + Protocol[Protocol["JOIN_ERROR"] = 11] = "JOIN_ERROR"; + Protocol[Protocol["LEAVE_ROOM"] = 12] = "LEAVE_ROOM"; + Protocol[Protocol["ROOM_DATA"] = 13] = "ROOM_DATA"; + Protocol[Protocol["ROOM_STATE"] = 14] = "ROOM_STATE"; + Protocol[Protocol["ROOM_STATE_PATCH"] = 15] = "ROOM_STATE_PATCH"; + // Generic messages (50~60) + Protocol[Protocol["BAD_REQUEST"] = 50] = "BAD_REQUEST"; +})(Protocol = exports.Protocol || (exports.Protocol = {})); /***/ }), -/* 14 */ +/* 13 */ /***/ (function(module, exports, __webpack_require__) { -/** - * event-lite.js - Light-weight EventEmitter (less than 1KB when gzipped) - * - * @copyright Yusuke Kawasaki - * @license MIT - * @constructor - * @see https://github.com/kawanet/event-lite - * @see http://kawanet.github.io/event-lite/EventLite.html - * @example - * var EventLite = require("event-lite"); - * - * function MyClass() {...} // your class - * - * EventLite.mixin(MyClass.prototype); // import event methods - * - * var obj = new MyClass(); - * obj.on("foo", function() {...}); // add event listener - * obj.once("bar", function() {...}); // add one-time event listener - * obj.emit("foo"); // dispatch event - * obj.emit("bar"); // dispatch another event - * obj.off("foo"); // remove event listener - */ - -function EventLite() { - if (!(this instanceof EventLite)) return new EventLite(); -} +// encode.js -(function(EventLite) { - // export the class for node.js - if (true) module.exports = EventLite; +exports.encode = encode; - // property name to hold listeners - var LISTENERS = "listeners"; +var EncodeBuffer = __webpack_require__(14).EncodeBuffer; - // methods to export - var methods = { - on: on, - once: once, - off: off, - emit: emit - }; +function encode(input, options) { + var encoder = new EncodeBuffer(options); + encoder.write(input); + return encoder.read(); +} - // mixin to self - mixin(EventLite.prototype); - // export mixin function - EventLite.mixin = mixin; +/***/ }), +/* 14 */ +/***/ (function(module, exports, __webpack_require__) { - /** - * Import on(), once(), off() and emit() methods into target object. - * - * @function EventLite.mixin - * @param target {Prototype} - */ +// encode-buffer.js - function mixin(target) { - for (var key in methods) { - target[key] = methods[key]; - } - return target; - } +exports.EncodeBuffer = EncodeBuffer; - /** - * Add an event listener. - * - * @function EventLite.prototype.on - * @param type {string} - * @param func {Function} - * @returns {EventLite} Self for method chaining - */ +var preset = __webpack_require__(5).preset; - function on(type, func) { - getListeners(this, type).push(func); - return this; - } +var FlexEncoder = __webpack_require__(17).FlexEncoder; - /** - * Add one-time event listener. - * - * @function EventLite.prototype.once - * @param type {string} - * @param func {Function} - * @returns {EventLite} Self for method chaining - */ +FlexEncoder.mixin(EncodeBuffer.prototype); - function once(type, func) { - var that = this; - wrap.originalListener = func; - getListeners(that, type).push(wrap); - return that; +function EncodeBuffer(options) { + if (!(this instanceof EncodeBuffer)) return new EncodeBuffer(options); - function wrap() { - off.call(that, type, wrap); - func.apply(this, arguments); + if (options) { + this.options = options; + if (options.codec) { + var codec = this.codec = options.codec; + if (codec.bufferish) this.bufferish = codec.bufferish; } } +} - /** - * Remove an event listener. - * - * @function EventLite.prototype.off - * @param [type] {string} - * @param [func] {Function} - * @returns {EventLite} Self for method chaining - */ +EncodeBuffer.prototype.codec = preset; - function off(type, func) { - var that = this; - var listners; - if (!arguments.length) { - delete that[LISTENERS]; - } else if (!func) { - listners = that[LISTENERS]; - if (listners) { - delete listners[type]; - if (!Object.keys(listners).length) return off.call(that); - } - } else { - listners = getListeners(that, type, true); - if (listners) { - listners = listners.filter(ne); - if (!listners.length) return off.call(that, type); - that[LISTENERS][type] = listners; - } - } - return that; +EncodeBuffer.prototype.write = function(input) { + this.codec.encode(this, input); +}; - function ne(test) { - return test !== func && test.originalListener !== func; - } - } - /** - * Dispatch (trigger) an event. - * - * @function EventLite.prototype.emit - * @param type {string} - * @param [value] {*} - * @returns {boolean} True when a listener received the event - */ +/***/ }), +/* 15 */ +/***/ (function(module, exports, __webpack_require__) { - function emit(type, value) { - var that = this; - var listeners = getListeners(that, type, true); - if (!listeners) return false; - var arglen = arguments.length; - if (arglen === 1) { - listeners.forEach(zeroarg); - } else if (arglen === 2) { - listeners.forEach(onearg); - } else { - var args = Array.prototype.slice.call(arguments, 1); - listeners.forEach(moreargs); - } - return !!listeners.length; +"use strict"; +/* WEBPACK VAR INJECTION */(function(global) {/*! + * The buffer module from node.js, for the browser. + * + * @author Feross Aboukhadijeh + * @license MIT + */ +/* eslint-disable no-proto */ - function zeroarg(func) { - func.call(that); - } - function onearg(func) { - func.call(that, value); - } - function moreargs(func) { - func.apply(that, args); - } - } - - /** - * @ignore - */ +var base64 = __webpack_require__(31) +var ieee754 = __webpack_require__(7) +var isArray = __webpack_require__(1) - function getListeners(that, type, readonly) { - if (readonly && !that[LISTENERS]) return; - var listeners = that[LISTENERS] || (that[LISTENERS] = {}); - return listeners[type] || (listeners[type] = []); - } +exports.Buffer = Buffer +exports.SlowBuffer = SlowBuffer +exports.INSPECT_MAX_BYTES = 50 -})(EventLite); +/** + * If `Buffer.TYPED_ARRAY_SUPPORT`: + * === true Use Uint8Array implementation (fastest) + * === false Use Object implementation (most compatible, even IE6) + * + * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+, + * Opera 11.6+, iOS 4.2+. + * + * Due to various browser bugs, sometimes the Object implementation will be used even + * when the browser supports typed arrays. + * + * Note: + * + * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances, + * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438. + * + * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function. + * + * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of + * incorrect length in some situations. + * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they + * get the Object implementation, which is slower but behaves correctly. + */ +Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined + ? global.TYPED_ARRAY_SUPPORT + : typedArraySupport() -/***/ }), -/* 15 */ -/***/ (function(module, exports, __webpack_require__) { +/* + * Export kMaxLength after typed array support is determined. + */ +exports.kMaxLength = kMaxLength() -// decode-buffer.js +function typedArraySupport () { + try { + var arr = new Uint8Array(1) + arr.__proto__ = {__proto__: Uint8Array.prototype, foo: function () { return 42 }} + return arr.foo() === 42 && // typed array instances can be augmented + typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray` + arr.subarray(1, 1).byteLength === 0 // ie10 has broken `subarray` + } catch (e) { + return false + } +} -exports.DecodeBuffer = DecodeBuffer; +function kMaxLength () { + return Buffer.TYPED_ARRAY_SUPPORT + ? 0x7fffffff + : 0x3fffffff +} -var preset = __webpack_require__(10).preset; +function createBuffer (that, length) { + if (kMaxLength() < length) { + throw new RangeError('Invalid typed array length') + } + if (Buffer.TYPED_ARRAY_SUPPORT) { + // Return an augmented `Uint8Array` instance, for best performance + that = new Uint8Array(length) + that.__proto__ = Buffer.prototype + } else { + // Fallback: Return an object instance of the Buffer class + if (that === null) { + that = new Buffer(length) + } + that.length = length + } -var FlexDecoder = __webpack_require__(19).FlexDecoder; + return that +} -FlexDecoder.mixin(DecodeBuffer.prototype); +/** + * The Buffer constructor returns instances of `Uint8Array` that have their + * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of + * `Uint8Array`, so the returned instances will have all the node `Buffer` methods + * and the `Uint8Array` methods. Square bracket notation works as expected -- it + * returns a single octet. + * + * The `Uint8Array` prototype remains unmodified. + */ -function DecodeBuffer(options) { - if (!(this instanceof DecodeBuffer)) return new DecodeBuffer(options); +function Buffer (arg, encodingOrOffset, length) { + if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) { + return new Buffer(arg, encodingOrOffset, length) + } - if (options) { - this.options = options; - if (options.codec) { - var codec = this.codec = options.codec; - if (codec.bufferish) this.bufferish = codec.bufferish; + // Common case. + if (typeof arg === 'number') { + if (typeof encodingOrOffset === 'string') { + throw new Error( + 'If encoding is specified then the first argument must be a string' + ) } + return allocUnsafe(this, arg) } + return from(this, arg, encodingOrOffset, length) } -DecodeBuffer.prototype.codec = preset; - -DecodeBuffer.prototype.fetch = function() { - return this.codec.decode(this); -}; - +Buffer.poolSize = 8192 // not used by this implementation -/***/ }), -/* 16 */ -/***/ (function(module, exports, __webpack_require__) { +// TODO: Legacy, not needed anymore. Remove in next major version. +Buffer._augment = function (arr) { + arr.__proto__ = Buffer.prototype + return arr +} -// decode.js +function from (that, value, encodingOrOffset, length) { + if (typeof value === 'number') { + throw new TypeError('"value" argument must not be a number') + } -exports.decode = decode; + if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) { + return fromArrayBuffer(that, value, encodingOrOffset, length) + } -var DecodeBuffer = __webpack_require__(15).DecodeBuffer; + if (typeof value === 'string') { + return fromString(that, value, encodingOrOffset) + } -function decode(input, options) { - var decoder = new DecodeBuffer(options); - decoder.write(input); - return decoder.read(); + return fromObject(that, value) } -/***/ }), -/* 17 */ -/***/ (function(module, exports, __webpack_require__) { - -// encode-buffer.js - -exports.EncodeBuffer = EncodeBuffer; +/** + * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError + * if value is a number. + * Buffer.from(str[, encoding]) + * Buffer.from(array) + * Buffer.from(buffer) + * Buffer.from(arrayBuffer[, byteOffset[, length]]) + **/ +Buffer.from = function (value, encodingOrOffset, length) { + return from(null, value, encodingOrOffset, length) +} -var preset = __webpack_require__(11).preset; +if (Buffer.TYPED_ARRAY_SUPPORT) { + Buffer.prototype.__proto__ = Uint8Array.prototype + Buffer.__proto__ = Uint8Array + if (typeof Symbol !== 'undefined' && Symbol.species && + Buffer[Symbol.species] === Buffer) { + // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97 + Object.defineProperty(Buffer, Symbol.species, { + value: null, + configurable: true + }) + } +} -var FlexEncoder = __webpack_require__(19).FlexEncoder; +function assertSize (size) { + if (typeof size !== 'number') { + throw new TypeError('"size" argument must be a number') + } else if (size < 0) { + throw new RangeError('"size" argument must not be negative') + } +} -FlexEncoder.mixin(EncodeBuffer.prototype); +function alloc (that, size, fill, encoding) { + assertSize(size) + if (size <= 0) { + return createBuffer(that, size) + } + if (fill !== undefined) { + // Only pay attention to encoding if it's a string. This + // prevents accidentally sending in a number that would + // be interpretted as a start offset. + return typeof encoding === 'string' + ? createBuffer(that, size).fill(fill, encoding) + : createBuffer(that, size).fill(fill) + } + return createBuffer(that, size) +} -function EncodeBuffer(options) { - if (!(this instanceof EncodeBuffer)) return new EncodeBuffer(options); +/** + * Creates a new filled Buffer instance. + * alloc(size[, fill[, encoding]]) + **/ +Buffer.alloc = function (size, fill, encoding) { + return alloc(null, size, fill, encoding) +} - if (options) { - this.options = options; - if (options.codec) { - var codec = this.codec = options.codec; - if (codec.bufferish) this.bufferish = codec.bufferish; +function allocUnsafe (that, size) { + assertSize(size) + that = createBuffer(that, size < 0 ? 0 : checked(size) | 0) + if (!Buffer.TYPED_ARRAY_SUPPORT) { + for (var i = 0; i < size; ++i) { + that[i] = 0 } } + return that } -EncodeBuffer.prototype.codec = preset; - -EncodeBuffer.prototype.write = function(input) { - this.codec.encode(this, input); -}; - +/** + * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance. + * */ +Buffer.allocUnsafe = function (size) { + return allocUnsafe(null, size) +} +/** + * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. + */ +Buffer.allocUnsafeSlow = function (size) { + return allocUnsafe(null, size) +} -/***/ }), -/* 18 */ -/***/ (function(module, exports, __webpack_require__) { +function fromString (that, string, encoding) { + if (typeof encoding !== 'string' || encoding === '') { + encoding = 'utf8' + } -// encode.js + if (!Buffer.isEncoding(encoding)) { + throw new TypeError('"encoding" must be a valid string encoding') + } -exports.encode = encode; + var length = byteLength(string, encoding) | 0 + that = createBuffer(that, length) -var EncodeBuffer = __webpack_require__(17).EncodeBuffer; + var actual = that.write(string, encoding) -function encode(input, options) { - var encoder = new EncodeBuffer(options); - encoder.write(input); - return encoder.read(); -} - - -/***/ }), -/* 19 */ -/***/ (function(module, exports, __webpack_require__) { - -// flex-buffer.js - -exports.FlexDecoder = FlexDecoder; -exports.FlexEncoder = FlexEncoder; - -var Bufferish = __webpack_require__(0); - -var MIN_BUFFER_SIZE = 2048; -var MAX_BUFFER_SIZE = 65536; -var BUFFER_SHORTAGE = "BUFFER_SHORTAGE"; + if (actual !== length) { + // Writing a hex string, for example, that contains invalid characters will + // cause everything after the first invalid character to be ignored. (e.g. + // 'abxxcd' will be treated as 'ab') + that = that.slice(0, actual) + } -function FlexDecoder() { - if (!(this instanceof FlexDecoder)) return new FlexDecoder(); + return that } -function FlexEncoder() { - if (!(this instanceof FlexEncoder)) return new FlexEncoder(); +function fromArrayLike (that, array) { + var length = array.length < 0 ? 0 : checked(array.length) | 0 + that = createBuffer(that, length) + for (var i = 0; i < length; i += 1) { + that[i] = array[i] & 255 + } + return that } -FlexDecoder.mixin = mixinFactory(getDecoderMethods()); -FlexDecoder.mixin(FlexDecoder.prototype); - -FlexEncoder.mixin = mixinFactory(getEncoderMethods()); -FlexEncoder.mixin(FlexEncoder.prototype); +function fromArrayBuffer (that, array, byteOffset, length) { + array.byteLength // this throws if `array` is not a valid ArrayBuffer -function getDecoderMethods() { - return { - bufferish: Bufferish, - write: write, - fetch: fetch, - flush: flush, - push: push, - pull: pull, - read: read, - reserve: reserve, - offset: 0 - }; + if (byteOffset < 0 || array.byteLength < byteOffset) { + throw new RangeError('\'offset\' is out of bounds') + } - function write(chunk) { - var prev = this.offset ? Bufferish.prototype.slice.call(this.buffer, this.offset) : this.buffer; - this.buffer = prev ? (chunk ? this.bufferish.concat([prev, chunk]) : prev) : chunk; - this.offset = 0; + if (array.byteLength < byteOffset + (length || 0)) { + throw new RangeError('\'length\' is out of bounds') } - function flush() { - while (this.offset < this.buffer.length) { - var start = this.offset; - var value; - try { - value = this.fetch(); - } catch (e) { - if (e && e.message != BUFFER_SHORTAGE) throw e; - // rollback - this.offset = start; - break; - } - this.push(value); - } + if (byteOffset === undefined && length === undefined) { + array = new Uint8Array(array) + } else if (length === undefined) { + array = new Uint8Array(array, byteOffset) + } else { + array = new Uint8Array(array, byteOffset, length) } - function reserve(length) { - var start = this.offset; - var end = start + length; - if (end > this.buffer.length) throw new Error(BUFFER_SHORTAGE); - this.offset = end; - return start; + if (Buffer.TYPED_ARRAY_SUPPORT) { + // Return an augmented `Uint8Array` instance, for best performance + that = array + that.__proto__ = Buffer.prototype + } else { + // Fallback: Return an object instance of the Buffer class + that = fromArrayLike(that, array) } + return that } -function getEncoderMethods() { - return { - bufferish: Bufferish, - write: write, - fetch: fetch, - flush: flush, - push: push, - pull: pull, - read: read, - reserve: reserve, - send: send, - maxBufferSize: MAX_BUFFER_SIZE, - minBufferSize: MIN_BUFFER_SIZE, - offset: 0, - start: 0 - }; - - function fetch() { - var start = this.start; - if (start < this.offset) { - var end = this.start = this.offset; - return Bufferish.prototype.slice.call(this.buffer, start, end); - } - } +function fromObject (that, obj) { + if (Buffer.isBuffer(obj)) { + var len = checked(obj.length) | 0 + that = createBuffer(that, len) - function flush() { - while (this.start < this.offset) { - var value = this.fetch(); - if (value) this.push(value); + if (that.length === 0) { + return that } - } - function pull() { - var buffers = this.buffers || (this.buffers = []); - var chunk = buffers.length > 1 ? this.bufferish.concat(buffers) : buffers[0]; - buffers.length = 0; // buffer exhausted - return chunk; + obj.copy(that, 0, 0, len) + return that } - function reserve(length) { - var req = length | 0; - - if (this.buffer) { - var size = this.buffer.length; - var start = this.offset | 0; - var end = start + req; - - // is it long enough? - if (end < size) { - this.offset = end; - return start; + if (obj) { + if ((typeof ArrayBuffer !== 'undefined' && + obj.buffer instanceof ArrayBuffer) || 'length' in obj) { + if (typeof obj.length !== 'number' || isnan(obj.length)) { + return createBuffer(that, 0) } - - // flush current buffer - this.flush(); - - // resize it to 2x current length - length = Math.max(length, Math.min(size * 2, this.maxBufferSize)); + return fromArrayLike(that, obj) } - // minimum buffer size - length = Math.max(length, this.minBufferSize); - - // allocate new buffer - this.buffer = this.bufferish.alloc(length); - this.start = 0; - this.offset = req; - return 0; - } - - function send(buffer) { - var length = buffer.length; - if (length > this.minBufferSize) { - this.flush(); - this.push(buffer); - } else { - var offset = this.reserve(length); - Bufferish.prototype.copy.call(buffer, this.buffer, offset); + if (obj.type === 'Buffer' && isArray(obj.data)) { + return fromArrayLike(that, obj.data) } } -} - -// common methods -function write() { - throw new Error("method not implemented: write()"); + throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.') } -function fetch() { - throw new Error("method not implemented: fetch()"); +function checked (length) { + // Note: cannot use `length < kMaxLength()` here because that fails when + // length is NaN (which is otherwise coerced to zero.) + if (length >= kMaxLength()) { + throw new RangeError('Attempt to allocate Buffer larger than maximum ' + + 'size: 0x' + kMaxLength().toString(16) + ' bytes') + } + return length | 0 } -function read() { - var length = this.buffers && this.buffers.length; - - // fetch the first result - if (!length) return this.fetch(); - - // flush current buffer - this.flush(); - - // read from the results - return this.pull(); +function SlowBuffer (length) { + if (+length != length) { // eslint-disable-line eqeqeq + length = 0 + } + return Buffer.alloc(+length) } -function push(chunk) { - var buffers = this.buffers || (this.buffers = []); - buffers.push(chunk); +Buffer.isBuffer = function isBuffer (b) { + return !!(b != null && b._isBuffer) } -function pull() { - var buffers = this.buffers || (this.buffers = []); - return buffers.shift(); -} +Buffer.compare = function compare (a, b) { + if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) { + throw new TypeError('Arguments must be Buffers') + } -function mixinFactory(source) { - return mixin; + if (a === b) return 0 - function mixin(target) { - for (var key in source) { - target[key] = source[key]; + var x = a.length + var y = b.length + + for (var i = 0, len = Math.min(x, y); i < len; ++i) { + if (a[i] !== b[i]) { + x = a[i] + y = b[i] + break } - return target; } -} - -/***/ }), -/* 20 */ -/***/ (function(module, exports, __webpack_require__) { + if (x < y) return -1 + if (y < x) return 1 + return 0 +} -// read-format.js +Buffer.isEncoding = function isEncoding (encoding) { + switch (String(encoding).toLowerCase()) { + case 'hex': + case 'utf8': + case 'utf-8': + case 'ascii': + case 'latin1': + case 'binary': + case 'base64': + case 'ucs2': + case 'ucs-2': + case 'utf16le': + case 'utf-16le': + return true + default: + return false + } +} -var ieee754 = __webpack_require__(5); -var Int64Buffer = __webpack_require__(6); -var Uint64BE = Int64Buffer.Uint64BE; -var Int64BE = Int64Buffer.Int64BE; +Buffer.concat = function concat (list, length) { + if (!isArray(list)) { + throw new TypeError('"list" argument must be an Array of Buffers') + } -exports.getReadFormat = getReadFormat; -exports.readUint8 = uint8; + if (list.length === 0) { + return Buffer.alloc(0) + } -var Bufferish = __webpack_require__(0); -var BufferProto = __webpack_require__(8); + var i + if (length === undefined) { + length = 0 + for (i = 0; i < list.length; ++i) { + length += list[i].length + } + } -var HAS_MAP = ("undefined" !== typeof Map); -var NO_ASSERT = true; + var buffer = Buffer.allocUnsafe(length) + var pos = 0 + for (i = 0; i < list.length; ++i) { + var buf = list[i] + if (!Buffer.isBuffer(buf)) { + throw new TypeError('"list" argument must be an Array of Buffers') + } + buf.copy(buffer, pos) + pos += buf.length + } + return buffer +} -function getReadFormat(options) { - var binarraybuffer = Bufferish.hasArrayBuffer && options && options.binarraybuffer; - var int64 = options && options.int64; - var usemap = HAS_MAP && options && options.usemap; +function byteLength (string, encoding) { + if (Buffer.isBuffer(string)) { + return string.length + } + if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' && + (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) { + return string.byteLength + } + if (typeof string !== 'string') { + string = '' + string + } - var readFormat = { - map: (usemap ? map_to_map : map_to_obj), - array: array, - str: str, - bin: (binarraybuffer ? bin_arraybuffer : bin_buffer), - ext: ext, - uint8: uint8, - uint16: uint16, - uint32: uint32, - uint64: read(8, int64 ? readUInt64BE_int64 : readUInt64BE), - int8: int8, - int16: int16, - int32: int32, - int64: read(8, int64 ? readInt64BE_int64 : readInt64BE), - float32: read(4, readFloatBE), - float64: read(8, readDoubleBE) - }; + var len = string.length + if (len === 0) return 0 - return readFormat; + // Use a for loop to avoid recursion + var loweredCase = false + for (;;) { + switch (encoding) { + case 'ascii': + case 'latin1': + case 'binary': + return len + case 'utf8': + case 'utf-8': + case undefined: + return utf8ToBytes(string).length + case 'ucs2': + case 'ucs-2': + case 'utf16le': + case 'utf-16le': + return len * 2 + case 'hex': + return len >>> 1 + case 'base64': + return base64ToBytes(string).length + default: + if (loweredCase) return utf8ToBytes(string).length // assume utf8 + encoding = ('' + encoding).toLowerCase() + loweredCase = true + } + } } +Buffer.byteLength = byteLength -function map_to_obj(decoder, len) { - var value = {}; - var i; - var k = new Array(len); - var v = new Array(len); +function slowToString (encoding, start, end) { + var loweredCase = false - var decode = decoder.codec.decode; - for (i = 0; i < len; i++) { - k[i] = decode(decoder); - v[i] = decode(decoder); + // No need to verify that "this.length <= MAX_UINT32" since it's a read-only + // property of a typed array. + + // This behaves neither like String nor Uint8Array in that we set start/end + // to their upper/lower bounds if the value passed is out of range. + // undefined is handled specially as per ECMA-262 6th Edition, + // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization. + if (start === undefined || start < 0) { + start = 0 } - for (i = 0; i < len; i++) { - value[k[i]] = v[i]; + // Return early if start > this.length. Done here to prevent potential uint32 + // coercion fail below. + if (start > this.length) { + return '' } - return value; -} - -function map_to_map(decoder, len) { - var value = new Map(); - var i; - var k = new Array(len); - var v = new Array(len); - var decode = decoder.codec.decode; - for (i = 0; i < len; i++) { - k[i] = decode(decoder); - v[i] = decode(decoder); - } - for (i = 0; i < len; i++) { - value.set(k[i], v[i]); + if (end === undefined || end > this.length) { + end = this.length } - return value; -} -function array(decoder, len) { - var value = new Array(len); - var decode = decoder.codec.decode; - for (var i = 0; i < len; i++) { - value[i] = decode(decoder); + if (end <= 0) { + return '' } - return value; -} -function str(decoder, len) { - var start = decoder.reserve(len); - var end = start + len; - return BufferProto.toString.call(decoder.buffer, "utf-8", start, end); -} + // Force coersion to uint32. This will also coerce falsey/NaN values to 0. + end >>>= 0 + start >>>= 0 -function bin_buffer(decoder, len) { - var start = decoder.reserve(len); - var end = start + len; - var buf = BufferProto.slice.call(decoder.buffer, start, end); - return Bufferish.from(buf); -} + if (end <= start) { + return '' + } -function bin_arraybuffer(decoder, len) { - var start = decoder.reserve(len); - var end = start + len; - var buf = BufferProto.slice.call(decoder.buffer, start, end); - return Bufferish.Uint8Array.from(buf).buffer; -} + if (!encoding) encoding = 'utf8' -function ext(decoder, len) { - var start = decoder.reserve(len+1); - var type = decoder.buffer[start++]; - var end = start + len; - var unpack = decoder.codec.getExtUnpacker(type); - if (!unpack) throw new Error("Invalid ext type: " + (type ? ("0x" + type.toString(16)) : type)); - var buf = BufferProto.slice.call(decoder.buffer, start, end); - return unpack(buf); -} + while (true) { + switch (encoding) { + case 'hex': + return hexSlice(this, start, end) -function uint8(decoder) { - var start = decoder.reserve(1); - return decoder.buffer[start]; -} + case 'utf8': + case 'utf-8': + return utf8Slice(this, start, end) -function int8(decoder) { - var start = decoder.reserve(1); - var value = decoder.buffer[start]; - return (value & 0x80) ? value - 0x100 : value; -} + case 'ascii': + return asciiSlice(this, start, end) -function uint16(decoder) { - var start = decoder.reserve(2); - var buffer = decoder.buffer; - return (buffer[start++] << 8) | buffer[start]; -} + case 'latin1': + case 'binary': + return latin1Slice(this, start, end) -function int16(decoder) { - var start = decoder.reserve(2); - var buffer = decoder.buffer; - var value = (buffer[start++] << 8) | buffer[start]; - return (value & 0x8000) ? value - 0x10000 : value; -} + case 'base64': + return base64Slice(this, start, end) -function uint32(decoder) { - var start = decoder.reserve(4); - var buffer = decoder.buffer; - return (buffer[start++] * 16777216) + (buffer[start++] << 16) + (buffer[start++] << 8) + buffer[start]; -} + case 'ucs2': + case 'ucs-2': + case 'utf16le': + case 'utf-16le': + return utf16leSlice(this, start, end) -function int32(decoder) { - var start = decoder.reserve(4); - var buffer = decoder.buffer; - return (buffer[start++] << 24) | (buffer[start++] << 16) | (buffer[start++] << 8) | buffer[start]; + default: + if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding) + encoding = (encoding + '').toLowerCase() + loweredCase = true + } + } } -function read(len, method) { - return function(decoder) { - var start = decoder.reserve(len); - return method.call(decoder.buffer, start, NO_ASSERT); - }; -} +// The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect +// Buffer instances. +Buffer.prototype._isBuffer = true -function readUInt64BE(start) { - return new Uint64BE(this, start).toNumber(); +function swap (b, n, m) { + var i = b[n] + b[n] = b[m] + b[m] = i } -function readInt64BE(start) { - return new Int64BE(this, start).toNumber(); +Buffer.prototype.swap16 = function swap16 () { + var len = this.length + if (len % 2 !== 0) { + throw new RangeError('Buffer size must be a multiple of 16-bits') + } + for (var i = 0; i < len; i += 2) { + swap(this, i, i + 1) + } + return this } -function readUInt64BE_int64(start) { - return new Uint64BE(this, start); +Buffer.prototype.swap32 = function swap32 () { + var len = this.length + if (len % 4 !== 0) { + throw new RangeError('Buffer size must be a multiple of 32-bits') + } + for (var i = 0; i < len; i += 4) { + swap(this, i, i + 3) + swap(this, i + 1, i + 2) + } + return this } -function readInt64BE_int64(start) { - return new Int64BE(this, start); +Buffer.prototype.swap64 = function swap64 () { + var len = this.length + if (len % 8 !== 0) { + throw new RangeError('Buffer size must be a multiple of 64-bits') + } + for (var i = 0; i < len; i += 8) { + swap(this, i, i + 7) + swap(this, i + 1, i + 6) + swap(this, i + 2, i + 5) + swap(this, i + 3, i + 4) + } + return this } -function readFloatBE(start) { - return ieee754.read(this, start, false, 23, 4); +Buffer.prototype.toString = function toString () { + var length = this.length | 0 + if (length === 0) return '' + if (arguments.length === 0) return utf8Slice(this, 0, length) + return slowToString.apply(this, arguments) } -function readDoubleBE(start) { - return ieee754.read(this, start, false, 52, 8); +Buffer.prototype.equals = function equals (b) { + if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer') + if (this === b) return true + return Buffer.compare(this, b) === 0 } -/***/ }), -/* 21 */ -/***/ (function(module, exports) { +Buffer.prototype.inspect = function inspect () { + var str = '' + var max = exports.INSPECT_MAX_BYTES + if (this.length > 0) { + str = this.toString('hex', 0, max).match(/.{2}/g).join(' ') + if (this.length > max) str += ' ... ' + } + return '' +} -// write-unit8.js +Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) { + if (!Buffer.isBuffer(target)) { + throw new TypeError('Argument must be a Buffer') + } -var constant = exports.uint8 = new Array(256); + if (start === undefined) { + start = 0 + } + if (end === undefined) { + end = target ? target.length : 0 + } + if (thisStart === undefined) { + thisStart = 0 + } + if (thisEnd === undefined) { + thisEnd = this.length + } -for (var i = 0x00; i <= 0xFF; i++) { - constant[i] = write0(i); -} + if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) { + throw new RangeError('out of range index') + } -function write0(type) { - return function(encoder) { - var offset = encoder.reserve(1); - encoder.buffer[offset] = type; - }; -} + if (thisStart >= thisEnd && start >= end) { + return 0 + } + if (thisStart >= thisEnd) { + return -1 + } + if (start >= end) { + return 1 + } + start >>>= 0 + end >>>= 0 + thisStart >>>= 0 + thisEnd >>>= 0 -/***/ }), -/* 22 */ -/***/ (function(module, exports, __webpack_require__) { + if (this === target) return 0 -"use strict"; -/* WEBPACK VAR INJECTION */(function(global) {/*! - * The buffer module from node.js, for the browser. - * - * @author Feross Aboukhadijeh - * @license MIT - */ -/* eslint-disable no-proto */ + var x = thisEnd - thisStart + var y = end - start + var len = Math.min(x, y) + var thisCopy = this.slice(thisStart, thisEnd) + var targetCopy = target.slice(start, end) + for (var i = 0; i < len; ++i) { + if (thisCopy[i] !== targetCopy[i]) { + x = thisCopy[i] + y = targetCopy[i] + break + } + } -var base64 = __webpack_require__(31) -var ieee754 = __webpack_require__(5) -var isArray = __webpack_require__(1) + if (x < y) return -1 + if (y < x) return 1 + return 0 +} -exports.Buffer = Buffer -exports.SlowBuffer = SlowBuffer -exports.INSPECT_MAX_BYTES = 50 +// Finds either the first index of `val` in `buffer` at offset >= `byteOffset`, +// OR the last index of `val` in `buffer` at offset <= `byteOffset`. +// +// Arguments: +// - buffer - a Buffer to search +// - val - a string, Buffer, or number +// - byteOffset - an index into `buffer`; will be clamped to an int32 +// - encoding - an optional encoding, relevant is val is a string +// - dir - true for indexOf, false for lastIndexOf +function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) { + // Empty buffer means no match + if (buffer.length === 0) return -1 -/** - * If `Buffer.TYPED_ARRAY_SUPPORT`: - * === true Use Uint8Array implementation (fastest) - * === false Use Object implementation (most compatible, even IE6) - * - * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+, - * Opera 11.6+, iOS 4.2+. - * - * Due to various browser bugs, sometimes the Object implementation will be used even - * when the browser supports typed arrays. - * - * Note: - * - * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances, - * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438. - * - * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function. - * - * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of - * incorrect length in some situations. + // Normalize byteOffset + if (typeof byteOffset === 'string') { + encoding = byteOffset + byteOffset = 0 + } else if (byteOffset > 0x7fffffff) { + byteOffset = 0x7fffffff + } else if (byteOffset < -0x80000000) { + byteOffset = -0x80000000 + } + byteOffset = +byteOffset // Coerce to Number. + if (isNaN(byteOffset)) { + // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer + byteOffset = dir ? 0 : (buffer.length - 1) + } - * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they - * get the Object implementation, which is slower but behaves correctly. - */ -Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined - ? global.TYPED_ARRAY_SUPPORT - : typedArraySupport() + // Normalize byteOffset: negative offsets start from the end of the buffer + if (byteOffset < 0) byteOffset = buffer.length + byteOffset + if (byteOffset >= buffer.length) { + if (dir) return -1 + else byteOffset = buffer.length - 1 + } else if (byteOffset < 0) { + if (dir) byteOffset = 0 + else return -1 + } -/* - * Export kMaxLength after typed array support is determined. - */ -exports.kMaxLength = kMaxLength() + // Normalize val + if (typeof val === 'string') { + val = Buffer.from(val, encoding) + } -function typedArraySupport () { - try { - var arr = new Uint8Array(1) - arr.__proto__ = {__proto__: Uint8Array.prototype, foo: function () { return 42 }} - return arr.foo() === 42 && // typed array instances can be augmented - typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray` - arr.subarray(1, 1).byteLength === 0 // ie10 has broken `subarray` - } catch (e) { - return false + // Finally, search either indexOf (if dir is true) or lastIndexOf + if (Buffer.isBuffer(val)) { + // Special case: looking for empty string/buffer always fails + if (val.length === 0) { + return -1 + } + return arrayIndexOf(buffer, val, byteOffset, encoding, dir) + } else if (typeof val === 'number') { + val = val & 0xFF // Search for a byte value [0-255] + if (Buffer.TYPED_ARRAY_SUPPORT && + typeof Uint8Array.prototype.indexOf === 'function') { + if (dir) { + return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset) + } else { + return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset) + } + } + return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir) } -} -function kMaxLength () { - return Buffer.TYPED_ARRAY_SUPPORT - ? 0x7fffffff - : 0x3fffffff + throw new TypeError('val must be string, number or Buffer') } -function createBuffer (that, length) { - if (kMaxLength() < length) { - throw new RangeError('Invalid typed array length') - } - if (Buffer.TYPED_ARRAY_SUPPORT) { - // Return an augmented `Uint8Array` instance, for best performance - that = new Uint8Array(length) - that.__proto__ = Buffer.prototype - } else { - // Fallback: Return an object instance of the Buffer class - if (that === null) { - that = new Buffer(length) +function arrayIndexOf (arr, val, byteOffset, encoding, dir) { + var indexSize = 1 + var arrLength = arr.length + var valLength = val.length + + if (encoding !== undefined) { + encoding = String(encoding).toLowerCase() + if (encoding === 'ucs2' || encoding === 'ucs-2' || + encoding === 'utf16le' || encoding === 'utf-16le') { + if (arr.length < 2 || val.length < 2) { + return -1 + } + indexSize = 2 + arrLength /= 2 + valLength /= 2 + byteOffset /= 2 } - that.length = length } - return that -} - -/** - * The Buffer constructor returns instances of `Uint8Array` that have their - * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of - * `Uint8Array`, so the returned instances will have all the node `Buffer` methods - * and the `Uint8Array` methods. Square bracket notation works as expected -- it - * returns a single octet. - * - * The `Uint8Array` prototype remains unmodified. - */ - -function Buffer (arg, encodingOrOffset, length) { - if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) { - return new Buffer(arg, encodingOrOffset, length) + function read (buf, i) { + if (indexSize === 1) { + return buf[i] + } else { + return buf.readUInt16BE(i * indexSize) + } } - // Common case. - if (typeof arg === 'number') { - if (typeof encodingOrOffset === 'string') { - throw new Error( - 'If encoding is specified then the first argument must be a string' - ) + var i + if (dir) { + var foundIndex = -1 + for (i = byteOffset; i < arrLength; i++) { + if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) { + if (foundIndex === -1) foundIndex = i + if (i - foundIndex + 1 === valLength) return foundIndex * indexSize + } else { + if (foundIndex !== -1) i -= i - foundIndex + foundIndex = -1 + } + } + } else { + if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength + for (i = byteOffset; i >= 0; i--) { + var found = true + for (var j = 0; j < valLength; j++) { + if (read(arr, i + j) !== read(val, j)) { + found = false + break + } + } + if (found) return i } - return allocUnsafe(this, arg) } - return from(this, arg, encodingOrOffset, length) + + return -1 } -Buffer.poolSize = 8192 // not used by this implementation +Buffer.prototype.includes = function includes (val, byteOffset, encoding) { + return this.indexOf(val, byteOffset, encoding) !== -1 +} -// TODO: Legacy, not needed anymore. Remove in next major version. -Buffer._augment = function (arr) { - arr.__proto__ = Buffer.prototype - return arr +Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) { + return bidirectionalIndexOf(this, val, byteOffset, encoding, true) } -function from (that, value, encodingOrOffset, length) { - if (typeof value === 'number') { - throw new TypeError('"value" argument must not be a number') - } +Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) { + return bidirectionalIndexOf(this, val, byteOffset, encoding, false) +} - if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) { - return fromArrayBuffer(that, value, encodingOrOffset, length) +function hexWrite (buf, string, offset, length) { + offset = Number(offset) || 0 + var remaining = buf.length - offset + if (!length) { + length = remaining + } else { + length = Number(length) + if (length > remaining) { + length = remaining + } } - if (typeof value === 'string') { - return fromString(that, value, encodingOrOffset) - } + // must be an even number of digits + var strLen = string.length + if (strLen % 2 !== 0) throw new TypeError('Invalid hex string') - return fromObject(that, value) + if (length > strLen / 2) { + length = strLen / 2 + } + for (var i = 0; i < length; ++i) { + var parsed = parseInt(string.substr(i * 2, 2), 16) + if (isNaN(parsed)) return i + buf[offset + i] = parsed + } + return i } -/** - * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError - * if value is a number. - * Buffer.from(str[, encoding]) - * Buffer.from(array) - * Buffer.from(buffer) - * Buffer.from(arrayBuffer[, byteOffset[, length]]) - **/ -Buffer.from = function (value, encodingOrOffset, length) { - return from(null, value, encodingOrOffset, length) +function utf8Write (buf, string, offset, length) { + return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length) } -if (Buffer.TYPED_ARRAY_SUPPORT) { - Buffer.prototype.__proto__ = Uint8Array.prototype - Buffer.__proto__ = Uint8Array - if (typeof Symbol !== 'undefined' && Symbol.species && - Buffer[Symbol.species] === Buffer) { - // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97 - Object.defineProperty(Buffer, Symbol.species, { - value: null, - configurable: true - }) - } +function asciiWrite (buf, string, offset, length) { + return blitBuffer(asciiToBytes(string), buf, offset, length) } -function assertSize (size) { - if (typeof size !== 'number') { - throw new TypeError('"size" argument must be a number') - } else if (size < 0) { - throw new RangeError('"size" argument must not be negative') - } +function latin1Write (buf, string, offset, length) { + return asciiWrite(buf, string, offset, length) } -function alloc (that, size, fill, encoding) { - assertSize(size) - if (size <= 0) { - return createBuffer(that, size) - } - if (fill !== undefined) { - // Only pay attention to encoding if it's a string. This - // prevents accidentally sending in a number that would - // be interpretted as a start offset. - return typeof encoding === 'string' - ? createBuffer(that, size).fill(fill, encoding) - : createBuffer(that, size).fill(fill) - } - return createBuffer(that, size) +function base64Write (buf, string, offset, length) { + return blitBuffer(base64ToBytes(string), buf, offset, length) } -/** - * Creates a new filled Buffer instance. - * alloc(size[, fill[, encoding]]) - **/ -Buffer.alloc = function (size, fill, encoding) { - return alloc(null, size, fill, encoding) +function ucs2Write (buf, string, offset, length) { + return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length) } -function allocUnsafe (that, size) { - assertSize(size) - that = createBuffer(that, size < 0 ? 0 : checked(size) | 0) - if (!Buffer.TYPED_ARRAY_SUPPORT) { - for (var i = 0; i < size; ++i) { - that[i] = 0 +Buffer.prototype.write = function write (string, offset, length, encoding) { + // Buffer#write(string) + if (offset === undefined) { + encoding = 'utf8' + length = this.length + offset = 0 + // Buffer#write(string, encoding) + } else if (length === undefined && typeof offset === 'string') { + encoding = offset + length = this.length + offset = 0 + // Buffer#write(string, offset[, length][, encoding]) + } else if (isFinite(offset)) { + offset = offset | 0 + if (isFinite(length)) { + length = length | 0 + if (encoding === undefined) encoding = 'utf8' + } else { + encoding = length + length = undefined } + // legacy write(string, encoding, offset, length) - remove in v0.13 + } else { + throw new Error( + 'Buffer.write(string, encoding, offset[, length]) is no longer supported' + ) } - return that -} -/** - * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance. - * */ -Buffer.allocUnsafe = function (size) { - return allocUnsafe(null, size) -} -/** - * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. - */ -Buffer.allocUnsafeSlow = function (size) { - return allocUnsafe(null, size) -} + var remaining = this.length - offset + if (length === undefined || length > remaining) length = remaining -function fromString (that, string, encoding) { - if (typeof encoding !== 'string' || encoding === '') { - encoding = 'utf8' + if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) { + throw new RangeError('Attempt to write outside buffer bounds') } - if (!Buffer.isEncoding(encoding)) { - throw new TypeError('"encoding" must be a valid string encoding') - } + if (!encoding) encoding = 'utf8' - var length = byteLength(string, encoding) | 0 - that = createBuffer(that, length) + var loweredCase = false + for (;;) { + switch (encoding) { + case 'hex': + return hexWrite(this, string, offset, length) - var actual = that.write(string, encoding) + case 'utf8': + case 'utf-8': + return utf8Write(this, string, offset, length) - if (actual !== length) { - // Writing a hex string, for example, that contains invalid characters will - // cause everything after the first invalid character to be ignored. (e.g. - // 'abxxcd' will be treated as 'ab') - that = that.slice(0, actual) - } - - return that -} + case 'ascii': + return asciiWrite(this, string, offset, length) -function fromArrayLike (that, array) { - var length = array.length < 0 ? 0 : checked(array.length) | 0 - that = createBuffer(that, length) - for (var i = 0; i < length; i += 1) { - that[i] = array[i] & 255 - } - return that -} + case 'latin1': + case 'binary': + return latin1Write(this, string, offset, length) -function fromArrayBuffer (that, array, byteOffset, length) { - array.byteLength // this throws if `array` is not a valid ArrayBuffer + case 'base64': + // Warning: maxLength not taken into account in base64Write + return base64Write(this, string, offset, length) - if (byteOffset < 0 || array.byteLength < byteOffset) { - throw new RangeError('\'offset\' is out of bounds') - } + case 'ucs2': + case 'ucs-2': + case 'utf16le': + case 'utf-16le': + return ucs2Write(this, string, offset, length) - if (array.byteLength < byteOffset + (length || 0)) { - throw new RangeError('\'length\' is out of bounds') + default: + if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding) + encoding = ('' + encoding).toLowerCase() + loweredCase = true + } } +} - if (byteOffset === undefined && length === undefined) { - array = new Uint8Array(array) - } else if (length === undefined) { - array = new Uint8Array(array, byteOffset) - } else { - array = new Uint8Array(array, byteOffset, length) +Buffer.prototype.toJSON = function toJSON () { + return { + type: 'Buffer', + data: Array.prototype.slice.call(this._arr || this, 0) } +} - if (Buffer.TYPED_ARRAY_SUPPORT) { - // Return an augmented `Uint8Array` instance, for best performance - that = array - that.__proto__ = Buffer.prototype +function base64Slice (buf, start, end) { + if (start === 0 && end === buf.length) { + return base64.fromByteArray(buf) } else { - // Fallback: Return an object instance of the Buffer class - that = fromArrayLike(that, array) + return base64.fromByteArray(buf.slice(start, end)) } - return that } -function fromObject (that, obj) { - if (Buffer.isBuffer(obj)) { - var len = checked(obj.length) | 0 - that = createBuffer(that, len) +function utf8Slice (buf, start, end) { + end = Math.min(buf.length, end) + var res = [] - if (that.length === 0) { - return that - } + var i = start + while (i < end) { + var firstByte = buf[i] + var codePoint = null + var bytesPerSequence = (firstByte > 0xEF) ? 4 + : (firstByte > 0xDF) ? 3 + : (firstByte > 0xBF) ? 2 + : 1 - obj.copy(that, 0, 0, len) - return that - } + if (i + bytesPerSequence <= end) { + var secondByte, thirdByte, fourthByte, tempCodePoint - if (obj) { - if ((typeof ArrayBuffer !== 'undefined' && - obj.buffer instanceof ArrayBuffer) || 'length' in obj) { - if (typeof obj.length !== 'number' || isnan(obj.length)) { - return createBuffer(that, 0) + switch (bytesPerSequence) { + case 1: + if (firstByte < 0x80) { + codePoint = firstByte + } + break + case 2: + secondByte = buf[i + 1] + if ((secondByte & 0xC0) === 0x80) { + tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F) + if (tempCodePoint > 0x7F) { + codePoint = tempCodePoint + } + } + break + case 3: + secondByte = buf[i + 1] + thirdByte = buf[i + 2] + if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) { + tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F) + if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) { + codePoint = tempCodePoint + } + } + break + case 4: + secondByte = buf[i + 1] + thirdByte = buf[i + 2] + fourthByte = buf[i + 3] + if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) { + tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F) + if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) { + codePoint = tempCodePoint + } + } } - return fromArrayLike(that, obj) } - if (obj.type === 'Buffer' && isArray(obj.data)) { - return fromArrayLike(that, obj.data) + if (codePoint === null) { + // we did not generate a valid codePoint so insert a + // replacement char (U+FFFD) and advance only 1 byte + codePoint = 0xFFFD + bytesPerSequence = 1 + } else if (codePoint > 0xFFFF) { + // encode to utf16 (surrogate pair dance) + codePoint -= 0x10000 + res.push(codePoint >>> 10 & 0x3FF | 0xD800) + codePoint = 0xDC00 | codePoint & 0x3FF } + + res.push(codePoint) + i += bytesPerSequence } - throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.') + return decodeCodePointsArray(res) } -function checked (length) { - // Note: cannot use `length < kMaxLength()` here because that fails when - // length is NaN (which is otherwise coerced to zero.) - if (length >= kMaxLength()) { - throw new RangeError('Attempt to allocate Buffer larger than maximum ' + - 'size: 0x' + kMaxLength().toString(16) + ' bytes') +// Based on http://stackoverflow.com/a/22747272/680742, the browser with +// the lowest limit is Chrome, with 0x10000 args. +// We go 1 magnitude less, for safety +var MAX_ARGUMENTS_LENGTH = 0x1000 + +function decodeCodePointsArray (codePoints) { + var len = codePoints.length + if (len <= MAX_ARGUMENTS_LENGTH) { + return String.fromCharCode.apply(String, codePoints) // avoid extra slice() } - return length | 0 -} -function SlowBuffer (length) { - if (+length != length) { // eslint-disable-line eqeqeq - length = 0 + // Decode in chunks to avoid "call stack size exceeded". + var res = '' + var i = 0 + while (i < len) { + res += String.fromCharCode.apply( + String, + codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH) + ) } - return Buffer.alloc(+length) + return res } -Buffer.isBuffer = function isBuffer (b) { - return !!(b != null && b._isBuffer) +function asciiSlice (buf, start, end) { + var ret = '' + end = Math.min(buf.length, end) + + for (var i = start; i < end; ++i) { + ret += String.fromCharCode(buf[i] & 0x7F) + } + return ret } -Buffer.compare = function compare (a, b) { - if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) { - throw new TypeError('Arguments must be Buffers') +function latin1Slice (buf, start, end) { + var ret = '' + end = Math.min(buf.length, end) + + for (var i = start; i < end; ++i) { + ret += String.fromCharCode(buf[i]) } + return ret +} - if (a === b) return 0 +function hexSlice (buf, start, end) { + var len = buf.length - var x = a.length - var y = b.length + if (!start || start < 0) start = 0 + if (!end || end < 0 || end > len) end = len - for (var i = 0, len = Math.min(x, y); i < len; ++i) { - if (a[i] !== b[i]) { - x = a[i] - y = b[i] - break - } + var out = '' + for (var i = start; i < end; ++i) { + out += toHex(buf[i]) } - - if (x < y) return -1 - if (y < x) return 1 - return 0 + return out } -Buffer.isEncoding = function isEncoding (encoding) { - switch (String(encoding).toLowerCase()) { - case 'hex': - case 'utf8': - case 'utf-8': - case 'ascii': - case 'latin1': - case 'binary': - case 'base64': - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - return true - default: - return false +function utf16leSlice (buf, start, end) { + var bytes = buf.slice(start, end) + var res = '' + for (var i = 0; i < bytes.length; i += 2) { + res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256) } + return res } -Buffer.concat = function concat (list, length) { - if (!isArray(list)) { - throw new TypeError('"list" argument must be an Array of Buffers') +Buffer.prototype.slice = function slice (start, end) { + var len = this.length + start = ~~start + end = end === undefined ? len : ~~end + + if (start < 0) { + start += len + if (start < 0) start = 0 + } else if (start > len) { + start = len } - if (list.length === 0) { - return Buffer.alloc(0) + if (end < 0) { + end += len + if (end < 0) end = 0 + } else if (end > len) { + end = len } - var i - if (length === undefined) { - length = 0 - for (i = 0; i < list.length; ++i) { - length += list[i].length - } - } + if (end < start) end = start - var buffer = Buffer.allocUnsafe(length) - var pos = 0 - for (i = 0; i < list.length; ++i) { - var buf = list[i] - if (!Buffer.isBuffer(buf)) { - throw new TypeError('"list" argument must be an Array of Buffers') + var newBuf + if (Buffer.TYPED_ARRAY_SUPPORT) { + newBuf = this.subarray(start, end) + newBuf.__proto__ = Buffer.prototype + } else { + var sliceLen = end - start + newBuf = new Buffer(sliceLen, undefined) + for (var i = 0; i < sliceLen; ++i) { + newBuf[i] = this[i + start] } - buf.copy(buffer, pos) - pos += buf.length - } - return buffer -} - -function byteLength (string, encoding) { - if (Buffer.isBuffer(string)) { - return string.length } - if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' && - (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) { - return string.byteLength - } - if (typeof string !== 'string') { - string = '' + string - } - - var len = string.length - if (len === 0) return 0 - // Use a for loop to avoid recursion - var loweredCase = false - for (;;) { - switch (encoding) { - case 'ascii': - case 'latin1': - case 'binary': - return len - case 'utf8': - case 'utf-8': - case undefined: - return utf8ToBytes(string).length - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - return len * 2 - case 'hex': - return len >>> 1 - case 'base64': - return base64ToBytes(string).length - default: - if (loweredCase) return utf8ToBytes(string).length // assume utf8 - encoding = ('' + encoding).toLowerCase() - loweredCase = true - } - } + return newBuf } -Buffer.byteLength = byteLength -function slowToString (encoding, start, end) { - var loweredCase = false +/* + * Need to make sure that buffer isn't trying to write out of bounds. + */ +function checkOffset (offset, ext, length) { + if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint') + if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length') +} - // No need to verify that "this.length <= MAX_UINT32" since it's a read-only - // property of a typed array. +Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) { + offset = offset | 0 + byteLength = byteLength | 0 + if (!noAssert) checkOffset(offset, byteLength, this.length) - // This behaves neither like String nor Uint8Array in that we set start/end - // to their upper/lower bounds if the value passed is out of range. - // undefined is handled specially as per ECMA-262 6th Edition, - // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization. - if (start === undefined || start < 0) { - start = 0 - } - // Return early if start > this.length. Done here to prevent potential uint32 - // coercion fail below. - if (start > this.length) { - return '' + var val = this[offset] + var mul = 1 + var i = 0 + while (++i < byteLength && (mul *= 0x100)) { + val += this[offset + i] * mul } - if (end === undefined || end > this.length) { - end = this.length + return val +} + +Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) { + offset = offset | 0 + byteLength = byteLength | 0 + if (!noAssert) { + checkOffset(offset, byteLength, this.length) } - if (end <= 0) { - return '' + var val = this[offset + --byteLength] + var mul = 1 + while (byteLength > 0 && (mul *= 0x100)) { + val += this[offset + --byteLength] * mul } - // Force coersion to uint32. This will also coerce falsey/NaN values to 0. - end >>>= 0 - start >>>= 0 + return val +} - if (end <= start) { - return '' - } +Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) { + if (!noAssert) checkOffset(offset, 1, this.length) + return this[offset] +} - if (!encoding) encoding = 'utf8' +Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 2, this.length) + return this[offset] | (this[offset + 1] << 8) +} - while (true) { - switch (encoding) { - case 'hex': - return hexSlice(this, start, end) +Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 2, this.length) + return (this[offset] << 8) | this[offset + 1] +} - case 'utf8': - case 'utf-8': - return utf8Slice(this, start, end) +Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 4, this.length) - case 'ascii': - return asciiSlice(this, start, end) + return ((this[offset]) | + (this[offset + 1] << 8) | + (this[offset + 2] << 16)) + + (this[offset + 3] * 0x1000000) +} - case 'latin1': - case 'binary': - return latin1Slice(this, start, end) +Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 4, this.length) - case 'base64': - return base64Slice(this, start, end) + return (this[offset] * 0x1000000) + + ((this[offset + 1] << 16) | + (this[offset + 2] << 8) | + this[offset + 3]) +} - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - return utf16leSlice(this, start, end) +Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) { + offset = offset | 0 + byteLength = byteLength | 0 + if (!noAssert) checkOffset(offset, byteLength, this.length) - default: - if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding) - encoding = (encoding + '').toLowerCase() - loweredCase = true - } + var val = this[offset] + var mul = 1 + var i = 0 + while (++i < byteLength && (mul *= 0x100)) { + val += this[offset + i] * mul } -} + mul *= 0x80 -// The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect -// Buffer instances. -Buffer.prototype._isBuffer = true + if (val >= mul) val -= Math.pow(2, 8 * byteLength) -function swap (b, n, m) { - var i = b[n] - b[n] = b[m] - b[m] = i + return val } -Buffer.prototype.swap16 = function swap16 () { - var len = this.length - if (len % 2 !== 0) { - throw new RangeError('Buffer size must be a multiple of 16-bits') - } - for (var i = 0; i < len; i += 2) { - swap(this, i, i + 1) - } - return this -} +Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) { + offset = offset | 0 + byteLength = byteLength | 0 + if (!noAssert) checkOffset(offset, byteLength, this.length) -Buffer.prototype.swap32 = function swap32 () { - var len = this.length - if (len % 4 !== 0) { - throw new RangeError('Buffer size must be a multiple of 32-bits') - } - for (var i = 0; i < len; i += 4) { - swap(this, i, i + 3) - swap(this, i + 1, i + 2) + var i = byteLength + var mul = 1 + var val = this[offset + --i] + while (i > 0 && (mul *= 0x100)) { + val += this[offset + --i] * mul } - return this -} + mul *= 0x80 -Buffer.prototype.swap64 = function swap64 () { - var len = this.length - if (len % 8 !== 0) { - throw new RangeError('Buffer size must be a multiple of 64-bits') - } - for (var i = 0; i < len; i += 8) { - swap(this, i, i + 7) - swap(this, i + 1, i + 6) - swap(this, i + 2, i + 5) - swap(this, i + 3, i + 4) - } - return this -} + if (val >= mul) val -= Math.pow(2, 8 * byteLength) -Buffer.prototype.toString = function toString () { - var length = this.length | 0 - if (length === 0) return '' - if (arguments.length === 0) return utf8Slice(this, 0, length) - return slowToString.apply(this, arguments) + return val } -Buffer.prototype.equals = function equals (b) { - if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer') - if (this === b) return true - return Buffer.compare(this, b) === 0 +Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) { + if (!noAssert) checkOffset(offset, 1, this.length) + if (!(this[offset] & 0x80)) return (this[offset]) + return ((0xff - this[offset] + 1) * -1) } -Buffer.prototype.inspect = function inspect () { - var str = '' - var max = exports.INSPECT_MAX_BYTES - if (this.length > 0) { - str = this.toString('hex', 0, max).match(/.{2}/g).join(' ') - if (this.length > max) str += ' ... ' - } - return '' +Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 2, this.length) + var val = this[offset] | (this[offset + 1] << 8) + return (val & 0x8000) ? val | 0xFFFF0000 : val } -Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) { - if (!Buffer.isBuffer(target)) { - throw new TypeError('Argument must be a Buffer') - } - - if (start === undefined) { - start = 0 - } - if (end === undefined) { - end = target ? target.length : 0 - } - if (thisStart === undefined) { - thisStart = 0 - } - if (thisEnd === undefined) { - thisEnd = this.length - } +Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 2, this.length) + var val = this[offset + 1] | (this[offset] << 8) + return (val & 0x8000) ? val | 0xFFFF0000 : val +} - if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) { - throw new RangeError('out of range index') - } +Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 4, this.length) - if (thisStart >= thisEnd && start >= end) { - return 0 - } - if (thisStart >= thisEnd) { - return -1 - } - if (start >= end) { - return 1 - } + return (this[offset]) | + (this[offset + 1] << 8) | + (this[offset + 2] << 16) | + (this[offset + 3] << 24) +} - start >>>= 0 - end >>>= 0 - thisStart >>>= 0 - thisEnd >>>= 0 +Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 4, this.length) - if (this === target) return 0 + return (this[offset] << 24) | + (this[offset + 1] << 16) | + (this[offset + 2] << 8) | + (this[offset + 3]) +} - var x = thisEnd - thisStart - var y = end - start - var len = Math.min(x, y) +Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 4, this.length) + return ieee754.read(this, offset, true, 23, 4) +} - var thisCopy = this.slice(thisStart, thisEnd) - var targetCopy = target.slice(start, end) +Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 4, this.length) + return ieee754.read(this, offset, false, 23, 4) +} - for (var i = 0; i < len; ++i) { - if (thisCopy[i] !== targetCopy[i]) { - x = thisCopy[i] - y = targetCopy[i] - break - } - } +Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 8, this.length) + return ieee754.read(this, offset, true, 52, 8) +} - if (x < y) return -1 - if (y < x) return 1 - return 0 +Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 8, this.length) + return ieee754.read(this, offset, false, 52, 8) } -// Finds either the first index of `val` in `buffer` at offset >= `byteOffset`, -// OR the last index of `val` in `buffer` at offset <= `byteOffset`. -// -// Arguments: -// - buffer - a Buffer to search -// - val - a string, Buffer, or number -// - byteOffset - an index into `buffer`; will be clamped to an int32 -// - encoding - an optional encoding, relevant is val is a string -// - dir - true for indexOf, false for lastIndexOf -function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) { - // Empty buffer means no match - if (buffer.length === 0) return -1 +function checkInt (buf, value, offset, ext, max, min) { + if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance') + if (value > max || value < min) throw new RangeError('"value" argument is out of bounds') + if (offset + ext > buf.length) throw new RangeError('Index out of range') +} - // Normalize byteOffset - if (typeof byteOffset === 'string') { - encoding = byteOffset - byteOffset = 0 - } else if (byteOffset > 0x7fffffff) { - byteOffset = 0x7fffffff - } else if (byteOffset < -0x80000000) { - byteOffset = -0x80000000 - } - byteOffset = +byteOffset // Coerce to Number. - if (isNaN(byteOffset)) { - // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer - byteOffset = dir ? 0 : (buffer.length - 1) +Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) { + value = +value + offset = offset | 0 + byteLength = byteLength | 0 + if (!noAssert) { + var maxBytes = Math.pow(2, 8 * byteLength) - 1 + checkInt(this, value, offset, byteLength, maxBytes, 0) } - // Normalize byteOffset: negative offsets start from the end of the buffer - if (byteOffset < 0) byteOffset = buffer.length + byteOffset - if (byteOffset >= buffer.length) { - if (dir) return -1 - else byteOffset = buffer.length - 1 - } else if (byteOffset < 0) { - if (dir) byteOffset = 0 - else return -1 + var mul = 1 + var i = 0 + this[offset] = value & 0xFF + while (++i < byteLength && (mul *= 0x100)) { + this[offset + i] = (value / mul) & 0xFF } - // Normalize val - if (typeof val === 'string') { - val = Buffer.from(val, encoding) + return offset + byteLength +} + +Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) { + value = +value + offset = offset | 0 + byteLength = byteLength | 0 + if (!noAssert) { + var maxBytes = Math.pow(2, 8 * byteLength) - 1 + checkInt(this, value, offset, byteLength, maxBytes, 0) } - // Finally, search either indexOf (if dir is true) or lastIndexOf - if (Buffer.isBuffer(val)) { - // Special case: looking for empty string/buffer always fails - if (val.length === 0) { - return -1 - } - return arrayIndexOf(buffer, val, byteOffset, encoding, dir) - } else if (typeof val === 'number') { - val = val & 0xFF // Search for a byte value [0-255] - if (Buffer.TYPED_ARRAY_SUPPORT && - typeof Uint8Array.prototype.indexOf === 'function') { - if (dir) { - return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset) - } else { - return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset) - } - } - return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir) + var i = byteLength - 1 + var mul = 1 + this[offset + i] = value & 0xFF + while (--i >= 0 && (mul *= 0x100)) { + this[offset + i] = (value / mul) & 0xFF } - throw new TypeError('val must be string, number or Buffer') + return offset + byteLength } -function arrayIndexOf (arr, val, byteOffset, encoding, dir) { - var indexSize = 1 - var arrLength = arr.length - var valLength = val.length - - if (encoding !== undefined) { - encoding = String(encoding).toLowerCase() - if (encoding === 'ucs2' || encoding === 'ucs-2' || - encoding === 'utf16le' || encoding === 'utf-16le') { - if (arr.length < 2 || val.length < 2) { - return -1 - } - indexSize = 2 - arrLength /= 2 - valLength /= 2 - byteOffset /= 2 - } - } +Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0) + if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value) + this[offset] = (value & 0xff) + return offset + 1 +} - function read (buf, i) { - if (indexSize === 1) { - return buf[i] - } else { - return buf.readUInt16BE(i * indexSize) - } +function objectWriteUInt16 (buf, value, offset, littleEndian) { + if (value < 0) value = 0xffff + value + 1 + for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) { + buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>> + (littleEndian ? i : 1 - i) * 8 } +} - var i - if (dir) { - var foundIndex = -1 - for (i = byteOffset; i < arrLength; i++) { - if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) { - if (foundIndex === -1) foundIndex = i - if (i - foundIndex + 1 === valLength) return foundIndex * indexSize - } else { - if (foundIndex !== -1) i -= i - foundIndex - foundIndex = -1 - } - } +Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) + if (Buffer.TYPED_ARRAY_SUPPORT) { + this[offset] = (value & 0xff) + this[offset + 1] = (value >>> 8) } else { - if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength - for (i = byteOffset; i >= 0; i--) { - var found = true - for (var j = 0; j < valLength; j++) { - if (read(arr, i + j) !== read(val, j)) { - found = false - break - } - } - if (found) return i - } + objectWriteUInt16(this, value, offset, true) } - - return -1 + return offset + 2 } -Buffer.prototype.includes = function includes (val, byteOffset, encoding) { - return this.indexOf(val, byteOffset, encoding) !== -1 +Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) + if (Buffer.TYPED_ARRAY_SUPPORT) { + this[offset] = (value >>> 8) + this[offset + 1] = (value & 0xff) + } else { + objectWriteUInt16(this, value, offset, false) + } + return offset + 2 } -Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) { - return bidirectionalIndexOf(this, val, byteOffset, encoding, true) +function objectWriteUInt32 (buf, value, offset, littleEndian) { + if (value < 0) value = 0xffffffff + value + 1 + for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) { + buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff + } } -Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) { - return bidirectionalIndexOf(this, val, byteOffset, encoding, false) +Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) + if (Buffer.TYPED_ARRAY_SUPPORT) { + this[offset + 3] = (value >>> 24) + this[offset + 2] = (value >>> 16) + this[offset + 1] = (value >>> 8) + this[offset] = (value & 0xff) + } else { + objectWriteUInt32(this, value, offset, true) + } + return offset + 4 } -function hexWrite (buf, string, offset, length) { - offset = Number(offset) || 0 - var remaining = buf.length - offset - if (!length) { - length = remaining +Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) + if (Buffer.TYPED_ARRAY_SUPPORT) { + this[offset] = (value >>> 24) + this[offset + 1] = (value >>> 16) + this[offset + 2] = (value >>> 8) + this[offset + 3] = (value & 0xff) } else { - length = Number(length) - if (length > remaining) { - length = remaining - } + objectWriteUInt32(this, value, offset, false) } + return offset + 4 +} - // must be an even number of digits - var strLen = string.length - if (strLen % 2 !== 0) throw new TypeError('Invalid hex string') +Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) { + var limit = Math.pow(2, 8 * byteLength - 1) - if (length > strLen / 2) { - length = strLen / 2 + checkInt(this, value, offset, byteLength, limit - 1, -limit) } - for (var i = 0; i < length; ++i) { - var parsed = parseInt(string.substr(i * 2, 2), 16) - if (isNaN(parsed)) return i - buf[offset + i] = parsed + + var i = 0 + var mul = 1 + var sub = 0 + this[offset] = value & 0xFF + while (++i < byteLength && (mul *= 0x100)) { + if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) { + sub = 1 + } + this[offset + i] = ((value / mul) >> 0) - sub & 0xFF } - return i -} -function utf8Write (buf, string, offset, length) { - return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length) + return offset + byteLength } -function asciiWrite (buf, string, offset, length) { - return blitBuffer(asciiToBytes(string), buf, offset, length) -} +Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) { + var limit = Math.pow(2, 8 * byteLength - 1) -function latin1Write (buf, string, offset, length) { - return asciiWrite(buf, string, offset, length) -} + checkInt(this, value, offset, byteLength, limit - 1, -limit) + } -function base64Write (buf, string, offset, length) { - return blitBuffer(base64ToBytes(string), buf, offset, length) + var i = byteLength - 1 + var mul = 1 + var sub = 0 + this[offset + i] = value & 0xFF + while (--i >= 0 && (mul *= 0x100)) { + if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) { + sub = 1 + } + this[offset + i] = ((value / mul) >> 0) - sub & 0xFF + } + + return offset + byteLength } -function ucs2Write (buf, string, offset, length) { - return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length) +Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80) + if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value) + if (value < 0) value = 0xff + value + 1 + this[offset] = (value & 0xff) + return offset + 1 } -Buffer.prototype.write = function write (string, offset, length, encoding) { - // Buffer#write(string) - if (offset === undefined) { - encoding = 'utf8' - length = this.length - offset = 0 - // Buffer#write(string, encoding) - } else if (length === undefined && typeof offset === 'string') { - encoding = offset - length = this.length - offset = 0 - // Buffer#write(string, offset[, length][, encoding]) - } else if (isFinite(offset)) { - offset = offset | 0 - if (isFinite(length)) { - length = length | 0 - if (encoding === undefined) encoding = 'utf8' - } else { - encoding = length - length = undefined - } - // legacy write(string, encoding, offset, length) - remove in v0.13 +Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) + if (Buffer.TYPED_ARRAY_SUPPORT) { + this[offset] = (value & 0xff) + this[offset + 1] = (value >>> 8) } else { - throw new Error( - 'Buffer.write(string, encoding, offset[, length]) is no longer supported' - ) + objectWriteUInt16(this, value, offset, true) } + return offset + 2 +} - var remaining = this.length - offset - if (length === undefined || length > remaining) length = remaining - - if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) { - throw new RangeError('Attempt to write outside buffer bounds') +Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) + if (Buffer.TYPED_ARRAY_SUPPORT) { + this[offset] = (value >>> 8) + this[offset + 1] = (value & 0xff) + } else { + objectWriteUInt16(this, value, offset, false) } + return offset + 2 +} - if (!encoding) encoding = 'utf8' - - var loweredCase = false - for (;;) { - switch (encoding) { - case 'hex': - return hexWrite(this, string, offset, length) - - case 'utf8': - case 'utf-8': - return utf8Write(this, string, offset, length) - - case 'ascii': - return asciiWrite(this, string, offset, length) - - case 'latin1': - case 'binary': - return latin1Write(this, string, offset, length) - - case 'base64': - // Warning: maxLength not taken into account in base64Write - return base64Write(this, string, offset, length) - - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - return ucs2Write(this, string, offset, length) - - default: - if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding) - encoding = ('' + encoding).toLowerCase() - loweredCase = true - } +Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) + if (Buffer.TYPED_ARRAY_SUPPORT) { + this[offset] = (value & 0xff) + this[offset + 1] = (value >>> 8) + this[offset + 2] = (value >>> 16) + this[offset + 3] = (value >>> 24) + } else { + objectWriteUInt32(this, value, offset, true) } + return offset + 4 } -Buffer.prototype.toJSON = function toJSON () { - return { - type: 'Buffer', - data: Array.prototype.slice.call(this._arr || this, 0) +Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) + if (value < 0) value = 0xffffffff + value + 1 + if (Buffer.TYPED_ARRAY_SUPPORT) { + this[offset] = (value >>> 24) + this[offset + 1] = (value >>> 16) + this[offset + 2] = (value >>> 8) + this[offset + 3] = (value & 0xff) + } else { + objectWriteUInt32(this, value, offset, false) } + return offset + 4 } -function base64Slice (buf, start, end) { - if (start === 0 && end === buf.length) { - return base64.fromByteArray(buf) - } else { - return base64.fromByteArray(buf.slice(start, end)) +function checkIEEE754 (buf, value, offset, ext, max, min) { + if (offset + ext > buf.length) throw new RangeError('Index out of range') + if (offset < 0) throw new RangeError('Index out of range') +} + +function writeFloat (buf, value, offset, littleEndian, noAssert) { + if (!noAssert) { + checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38) } + ieee754.write(buf, value, offset, littleEndian, 23, 4) + return offset + 4 } -function utf8Slice (buf, start, end) { - end = Math.min(buf.length, end) - var res = [] +Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) { + return writeFloat(this, value, offset, true, noAssert) +} - var i = start - while (i < end) { - var firstByte = buf[i] - var codePoint = null - var bytesPerSequence = (firstByte > 0xEF) ? 4 - : (firstByte > 0xDF) ? 3 - : (firstByte > 0xBF) ? 2 - : 1 - - if (i + bytesPerSequence <= end) { - var secondByte, thirdByte, fourthByte, tempCodePoint - - switch (bytesPerSequence) { - case 1: - if (firstByte < 0x80) { - codePoint = firstByte - } - break - case 2: - secondByte = buf[i + 1] - if ((secondByte & 0xC0) === 0x80) { - tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F) - if (tempCodePoint > 0x7F) { - codePoint = tempCodePoint - } - } - break - case 3: - secondByte = buf[i + 1] - thirdByte = buf[i + 2] - if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) { - tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F) - if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) { - codePoint = tempCodePoint - } - } - break - case 4: - secondByte = buf[i + 1] - thirdByte = buf[i + 2] - fourthByte = buf[i + 3] - if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) { - tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F) - if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) { - codePoint = tempCodePoint - } - } - } - } - - if (codePoint === null) { - // we did not generate a valid codePoint so insert a - // replacement char (U+FFFD) and advance only 1 byte - codePoint = 0xFFFD - bytesPerSequence = 1 - } else if (codePoint > 0xFFFF) { - // encode to utf16 (surrogate pair dance) - codePoint -= 0x10000 - res.push(codePoint >>> 10 & 0x3FF | 0xD800) - codePoint = 0xDC00 | codePoint & 0x3FF - } - - res.push(codePoint) - i += bytesPerSequence - } - - return decodeCodePointsArray(res) +Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) { + return writeFloat(this, value, offset, false, noAssert) } -// Based on http://stackoverflow.com/a/22747272/680742, the browser with -// the lowest limit is Chrome, with 0x10000 args. -// We go 1 magnitude less, for safety -var MAX_ARGUMENTS_LENGTH = 0x1000 - -function decodeCodePointsArray (codePoints) { - var len = codePoints.length - if (len <= MAX_ARGUMENTS_LENGTH) { - return String.fromCharCode.apply(String, codePoints) // avoid extra slice() - } - - // Decode in chunks to avoid "call stack size exceeded". - var res = '' - var i = 0 - while (i < len) { - res += String.fromCharCode.apply( - String, - codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH) - ) +function writeDouble (buf, value, offset, littleEndian, noAssert) { + if (!noAssert) { + checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308) } - return res + ieee754.write(buf, value, offset, littleEndian, 52, 8) + return offset + 8 } -function asciiSlice (buf, start, end) { - var ret = '' - end = Math.min(buf.length, end) +Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) { + return writeDouble(this, value, offset, true, noAssert) +} - for (var i = start; i < end; ++i) { - ret += String.fromCharCode(buf[i] & 0x7F) - } - return ret +Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) { + return writeDouble(this, value, offset, false, noAssert) } -function latin1Slice (buf, start, end) { - var ret = '' - end = Math.min(buf.length, end) +// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length) +Buffer.prototype.copy = function copy (target, targetStart, start, end) { + if (!start) start = 0 + if (!end && end !== 0) end = this.length + if (targetStart >= target.length) targetStart = target.length + if (!targetStart) targetStart = 0 + if (end > 0 && end < start) end = start - for (var i = start; i < end; ++i) { - ret += String.fromCharCode(buf[i]) + // Copy 0 bytes; we're done + if (end === start) return 0 + if (target.length === 0 || this.length === 0) return 0 + + // Fatal error conditions + if (targetStart < 0) { + throw new RangeError('targetStart out of bounds') } - return ret -} + if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds') + if (end < 0) throw new RangeError('sourceEnd out of bounds') -function hexSlice (buf, start, end) { - var len = buf.length + // Are we oob? + if (end > this.length) end = this.length + if (target.length - targetStart < end - start) { + end = target.length - targetStart + start + } - if (!start || start < 0) start = 0 - if (!end || end < 0 || end > len) end = len + var len = end - start + var i - var out = '' - for (var i = start; i < end; ++i) { - out += toHex(buf[i]) + if (this === target && start < targetStart && targetStart < end) { + // descending copy from end + for (i = len - 1; i >= 0; --i) { + target[i + targetStart] = this[i + start] + } + } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) { + // ascending copy from start + for (i = 0; i < len; ++i) { + target[i + targetStart] = this[i + start] + } + } else { + Uint8Array.prototype.set.call( + target, + this.subarray(start, start + len), + targetStart + ) } - return out -} -function utf16leSlice (buf, start, end) { - var bytes = buf.slice(start, end) - var res = '' - for (var i = 0; i < bytes.length; i += 2) { - res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256) - } - return res + return len } -Buffer.prototype.slice = function slice (start, end) { - var len = this.length - start = ~~start - end = end === undefined ? len : ~~end +// Usage: +// buffer.fill(number[, offset[, end]]) +// buffer.fill(buffer[, offset[, end]]) +// buffer.fill(string[, offset[, end]][, encoding]) +Buffer.prototype.fill = function fill (val, start, end, encoding) { + // Handle string cases: + if (typeof val === 'string') { + if (typeof start === 'string') { + encoding = start + start = 0 + end = this.length + } else if (typeof end === 'string') { + encoding = end + end = this.length + } + if (val.length === 1) { + var code = val.charCodeAt(0) + if (code < 256) { + val = code + } + } + if (encoding !== undefined && typeof encoding !== 'string') { + throw new TypeError('encoding must be a string') + } + if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) { + throw new TypeError('Unknown encoding: ' + encoding) + } + } else if (typeof val === 'number') { + val = val & 255 + } - if (start < 0) { - start += len - if (start < 0) start = 0 - } else if (start > len) { - start = len + // Invalid ranges are not set to a default, so can range check early. + if (start < 0 || this.length < start || this.length < end) { + throw new RangeError('Out of range index') } - if (end < 0) { - end += len - if (end < 0) end = 0 - } else if (end > len) { - end = len + if (end <= start) { + return this } - if (end < start) end = start + start = start >>> 0 + end = end === undefined ? this.length : end >>> 0 - var newBuf - if (Buffer.TYPED_ARRAY_SUPPORT) { - newBuf = this.subarray(start, end) - newBuf.__proto__ = Buffer.prototype + if (!val) val = 0 + + var i + if (typeof val === 'number') { + for (i = start; i < end; ++i) { + this[i] = val + } } else { - var sliceLen = end - start - newBuf = new Buffer(sliceLen, undefined) - for (var i = 0; i < sliceLen; ++i) { - newBuf[i] = this[i + start] + var bytes = Buffer.isBuffer(val) + ? val + : utf8ToBytes(new Buffer(val, encoding).toString()) + var len = bytes.length + for (i = 0; i < end - start; ++i) { + this[i + start] = bytes[i % len] } } - return newBuf + return this } -/* - * Need to make sure that buffer isn't trying to write out of bounds. - */ -function checkOffset (offset, ext, length) { - if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint') - if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length') -} +// HELPER FUNCTIONS +// ================ -Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) { - offset = offset | 0 - byteLength = byteLength | 0 - if (!noAssert) checkOffset(offset, byteLength, this.length) +var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g - var val = this[offset] - var mul = 1 - var i = 0 - while (++i < byteLength && (mul *= 0x100)) { - val += this[offset + i] * mul +function base64clean (str) { + // Node strips out invalid characters like \n and \t from the string, base64-js does not + str = stringtrim(str).replace(INVALID_BASE64_RE, '') + // Node converts strings with length < 2 to '' + if (str.length < 2) return '' + // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not + while (str.length % 4 !== 0) { + str = str + '=' } - - return val + return str } -Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) { - offset = offset | 0 - byteLength = byteLength | 0 - if (!noAssert) { - checkOffset(offset, byteLength, this.length) - } - - var val = this[offset + --byteLength] - var mul = 1 - while (byteLength > 0 && (mul *= 0x100)) { - val += this[offset + --byteLength] * mul - } - - return val +function stringtrim (str) { + if (str.trim) return str.trim() + return str.replace(/^\s+|\s+$/g, '') } -Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) { - if (!noAssert) checkOffset(offset, 1, this.length) - return this[offset] +function toHex (n) { + if (n < 16) return '0' + n.toString(16) + return n.toString(16) } -Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 2, this.length) - return this[offset] | (this[offset + 1] << 8) -} +function utf8ToBytes (string, units) { + units = units || Infinity + var codePoint + var length = string.length + var leadSurrogate = null + var bytes = [] -Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 2, this.length) - return (this[offset] << 8) | this[offset + 1] -} + for (var i = 0; i < length; ++i) { + codePoint = string.charCodeAt(i) -Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 4, this.length) + // is surrogate component + if (codePoint > 0xD7FF && codePoint < 0xE000) { + // last char was a lead + if (!leadSurrogate) { + // no lead yet + if (codePoint > 0xDBFF) { + // unexpected trail + if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) + continue + } else if (i + 1 === length) { + // unpaired lead + if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) + continue + } - return ((this[offset]) | - (this[offset + 1] << 8) | - (this[offset + 2] << 16)) + - (this[offset + 3] * 0x1000000) -} + // valid lead + leadSurrogate = codePoint -Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 4, this.length) + continue + } - return (this[offset] * 0x1000000) + - ((this[offset + 1] << 16) | - (this[offset + 2] << 8) | - this[offset + 3]) -} + // 2 leads in a row + if (codePoint < 0xDC00) { + if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) + leadSurrogate = codePoint + continue + } -Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) { - offset = offset | 0 - byteLength = byteLength | 0 - if (!noAssert) checkOffset(offset, byteLength, this.length) + // valid surrogate pair + codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000 + } else if (leadSurrogate) { + // valid bmp char, but last char was a lead + if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) + } - var val = this[offset] - var mul = 1 - var i = 0 - while (++i < byteLength && (mul *= 0x100)) { - val += this[offset + i] * mul + leadSurrogate = null + + // encode utf8 + if (codePoint < 0x80) { + if ((units -= 1) < 0) break + bytes.push(codePoint) + } else if (codePoint < 0x800) { + if ((units -= 2) < 0) break + bytes.push( + codePoint >> 0x6 | 0xC0, + codePoint & 0x3F | 0x80 + ) + } else if (codePoint < 0x10000) { + if ((units -= 3) < 0) break + bytes.push( + codePoint >> 0xC | 0xE0, + codePoint >> 0x6 & 0x3F | 0x80, + codePoint & 0x3F | 0x80 + ) + } else if (codePoint < 0x110000) { + if ((units -= 4) < 0) break + bytes.push( + codePoint >> 0x12 | 0xF0, + codePoint >> 0xC & 0x3F | 0x80, + codePoint >> 0x6 & 0x3F | 0x80, + codePoint & 0x3F | 0x80 + ) + } else { + throw new Error('Invalid code point') + } } - mul *= 0x80 - if (val >= mul) val -= Math.pow(2, 8 * byteLength) + return bytes +} - return val +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 } -Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) { - offset = offset | 0 - byteLength = byteLength | 0 - if (!noAssert) checkOffset(offset, byteLength, this.length) +function utf16leToBytes (str, units) { + var c, hi, lo + var byteArray = [] + for (var i = 0; i < str.length; ++i) { + if ((units -= 2) < 0) break - var i = byteLength - var mul = 1 - var val = this[offset + --i] - while (i > 0 && (mul *= 0x100)) { - val += this[offset + --i] * mul + c = str.charCodeAt(i) + hi = c >> 8 + lo = c % 256 + byteArray.push(lo) + byteArray.push(hi) } - mul *= 0x80 - if (val >= mul) val -= Math.pow(2, 8 * byteLength) - - return val + return byteArray } -Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) { - if (!noAssert) checkOffset(offset, 1, this.length) - if (!(this[offset] & 0x80)) return (this[offset]) - return ((0xff - this[offset] + 1) * -1) +function base64ToBytes (str) { + return base64.toByteArray(base64clean(str)) } -Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 2, this.length) - var val = this[offset] | (this[offset + 1] << 8) - return (val & 0x8000) ? val | 0xFFFF0000 : val +function blitBuffer (src, dst, offset, length) { + for (var i = 0; i < length; ++i) { + if ((i + offset >= dst.length) || (i >= src.length)) break + dst[i + offset] = src[i] + } + return i } -Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 2, this.length) - var val = this[offset + 1] | (this[offset] << 8) - return (val & 0x8000) ? val | 0xFFFF0000 : val +function isnan (val) { + return val !== val // eslint-disable-line no-self-compare } -Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 4, this.length) +/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(30))) - return (this[offset]) | - (this[offset + 1] << 8) | - (this[offset + 2] << 16) | - (this[offset + 3] << 24) -} +/***/ }), +/* 16 */ +/***/ (function(module, exports) { -Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 4, this.length) +// write-unit8.js - return (this[offset] << 24) | - (this[offset + 1] << 16) | - (this[offset + 2] << 8) | - (this[offset + 3]) -} +var constant = exports.uint8 = new Array(256); -Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 4, this.length) - return ieee754.read(this, offset, true, 23, 4) +for (var i = 0x00; i <= 0xFF; i++) { + constant[i] = write0(i); } -Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 4, this.length) - return ieee754.read(this, offset, false, 23, 4) +function write0(type) { + return function(encoder) { + var offset = encoder.reserve(1); + encoder.buffer[offset] = type; + }; } -Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 8, this.length) - return ieee754.read(this, offset, true, 52, 8) + +/***/ }), +/* 17 */ +/***/ (function(module, exports, __webpack_require__) { + +// flex-buffer.js + +exports.FlexDecoder = FlexDecoder; +exports.FlexEncoder = FlexEncoder; + +var Bufferish = __webpack_require__(0); + +var MIN_BUFFER_SIZE = 2048; +var MAX_BUFFER_SIZE = 65536; +var BUFFER_SHORTAGE = "BUFFER_SHORTAGE"; + +function FlexDecoder() { + if (!(this instanceof FlexDecoder)) return new FlexDecoder(); } -Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) { - if (!noAssert) checkOffset(offset, 8, this.length) - return ieee754.read(this, offset, false, 52, 8) +function FlexEncoder() { + if (!(this instanceof FlexEncoder)) return new FlexEncoder(); } -function checkInt (buf, value, offset, ext, max, min) { - if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance') - if (value > max || value < min) throw new RangeError('"value" argument is out of bounds') - if (offset + ext > buf.length) throw new RangeError('Index out of range') -} - -Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) { - value = +value - offset = offset | 0 - byteLength = byteLength | 0 - if (!noAssert) { - var maxBytes = Math.pow(2, 8 * byteLength) - 1 - checkInt(this, value, offset, byteLength, maxBytes, 0) - } +FlexDecoder.mixin = mixinFactory(getDecoderMethods()); +FlexDecoder.mixin(FlexDecoder.prototype); - var mul = 1 - var i = 0 - this[offset] = value & 0xFF - while (++i < byteLength && (mul *= 0x100)) { - this[offset + i] = (value / mul) & 0xFF - } +FlexEncoder.mixin = mixinFactory(getEncoderMethods()); +FlexEncoder.mixin(FlexEncoder.prototype); - return offset + byteLength -} +function getDecoderMethods() { + return { + bufferish: Bufferish, + write: write, + fetch: fetch, + flush: flush, + push: push, + pull: pull, + read: read, + reserve: reserve, + offset: 0 + }; -Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) { - value = +value - offset = offset | 0 - byteLength = byteLength | 0 - if (!noAssert) { - var maxBytes = Math.pow(2, 8 * byteLength) - 1 - checkInt(this, value, offset, byteLength, maxBytes, 0) + function write(chunk) { + var prev = this.offset ? Bufferish.prototype.slice.call(this.buffer, this.offset) : this.buffer; + this.buffer = prev ? (chunk ? this.bufferish.concat([prev, chunk]) : prev) : chunk; + this.offset = 0; } - var i = byteLength - 1 - var mul = 1 - this[offset + i] = value & 0xFF - while (--i >= 0 && (mul *= 0x100)) { - this[offset + i] = (value / mul) & 0xFF + function flush() { + while (this.offset < this.buffer.length) { + var start = this.offset; + var value; + try { + value = this.fetch(); + } catch (e) { + if (e && e.message != BUFFER_SHORTAGE) throw e; + // rollback + this.offset = start; + break; + } + this.push(value); + } } - return offset + byteLength -} - -Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) { - value = +value - offset = offset | 0 - if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0) - if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value) - this[offset] = (value & 0xff) - return offset + 1 -} - -function objectWriteUInt16 (buf, value, offset, littleEndian) { - if (value < 0) value = 0xffff + value + 1 - for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) { - buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>> - (littleEndian ? i : 1 - i) * 8 + function reserve(length) { + var start = this.offset; + var end = start + length; + if (end > this.buffer.length) throw new Error(BUFFER_SHORTAGE); + this.offset = end; + return start; } } -Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) { - value = +value - offset = offset | 0 - if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value & 0xff) - this[offset + 1] = (value >>> 8) - } else { - objectWriteUInt16(this, value, offset, true) - } - return offset + 2 -} +function getEncoderMethods() { + return { + bufferish: Bufferish, + write: write, + fetch: fetch, + flush: flush, + push: push, + pull: pull, + read: read, + reserve: reserve, + send: send, + maxBufferSize: MAX_BUFFER_SIZE, + minBufferSize: MIN_BUFFER_SIZE, + offset: 0, + start: 0 + }; -Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) { - value = +value - offset = offset | 0 - if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value >>> 8) - this[offset + 1] = (value & 0xff) - } else { - objectWriteUInt16(this, value, offset, false) + function fetch() { + var start = this.start; + if (start < this.offset) { + var end = this.start = this.offset; + return Bufferish.prototype.slice.call(this.buffer, start, end); + } } - return offset + 2 -} -function objectWriteUInt32 (buf, value, offset, littleEndian) { - if (value < 0) value = 0xffffffff + value + 1 - for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) { - buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff + function flush() { + while (this.start < this.offset) { + var value = this.fetch(); + if (value) this.push(value); + } } -} -Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) { - value = +value - offset = offset | 0 - if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset + 3] = (value >>> 24) - this[offset + 2] = (value >>> 16) - this[offset + 1] = (value >>> 8) - this[offset] = (value & 0xff) - } else { - objectWriteUInt32(this, value, offset, true) + function pull() { + var buffers = this.buffers || (this.buffers = []); + var chunk = buffers.length > 1 ? this.bufferish.concat(buffers) : buffers[0]; + buffers.length = 0; // buffer exhausted + return chunk; } - return offset + 4 -} -Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) { - value = +value - offset = offset | 0 - if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value >>> 24) - this[offset + 1] = (value >>> 16) - this[offset + 2] = (value >>> 8) - this[offset + 3] = (value & 0xff) - } else { - objectWriteUInt32(this, value, offset, false) - } - return offset + 4 -} + function reserve(length) { + var req = length | 0; -Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) { - value = +value - offset = offset | 0 - if (!noAssert) { - var limit = Math.pow(2, 8 * byteLength - 1) + if (this.buffer) { + var size = this.buffer.length; + var start = this.offset | 0; + var end = start + req; - checkInt(this, value, offset, byteLength, limit - 1, -limit) - } + // is it long enough? + if (end < size) { + this.offset = end; + return start; + } - var i = 0 - var mul = 1 - var sub = 0 - this[offset] = value & 0xFF - while (++i < byteLength && (mul *= 0x100)) { - if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) { - sub = 1 - } - this[offset + i] = ((value / mul) >> 0) - sub & 0xFF - } + // flush current buffer + this.flush(); - return offset + byteLength -} + // resize it to 2x current length + length = Math.max(length, Math.min(size * 2, this.maxBufferSize)); + } -Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) { - value = +value - offset = offset | 0 - if (!noAssert) { - var limit = Math.pow(2, 8 * byteLength - 1) + // minimum buffer size + length = Math.max(length, this.minBufferSize); - checkInt(this, value, offset, byteLength, limit - 1, -limit) + // allocate new buffer + this.buffer = this.bufferish.alloc(length); + this.start = 0; + this.offset = req; + return 0; } - var i = byteLength - 1 - var mul = 1 - var sub = 0 - this[offset + i] = value & 0xFF - while (--i >= 0 && (mul *= 0x100)) { - if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) { - sub = 1 + function send(buffer) { + var length = buffer.length; + if (length > this.minBufferSize) { + this.flush(); + this.push(buffer); + } else { + var offset = this.reserve(length); + Bufferish.prototype.copy.call(buffer, this.buffer, offset); } - this[offset + i] = ((value / mul) >> 0) - sub & 0xFF } - - return offset + byteLength } -Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) { - value = +value - offset = offset | 0 - if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80) - if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value) - if (value < 0) value = 0xff + value + 1 - this[offset] = (value & 0xff) - return offset + 1 +// common methods + +function write() { + throw new Error("method not implemented: write()"); } -Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) { - value = +value - offset = offset | 0 - if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value & 0xff) - this[offset + 1] = (value >>> 8) - } else { - objectWriteUInt16(this, value, offset, true) - } - return offset + 2 +function fetch() { + throw new Error("method not implemented: fetch()"); } -Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) { - value = +value - offset = offset | 0 - if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value >>> 8) - this[offset + 1] = (value & 0xff) - } else { - objectWriteUInt16(this, value, offset, false) - } - return offset + 2 -} +function read() { + var length = this.buffers && this.buffers.length; -Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) { - value = +value - offset = offset | 0 - if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value & 0xff) - this[offset + 1] = (value >>> 8) - this[offset + 2] = (value >>> 16) - this[offset + 3] = (value >>> 24) - } else { - objectWriteUInt32(this, value, offset, true) - } - return offset + 4 -} + // fetch the first result + if (!length) return this.fetch(); -Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) { - value = +value - offset = offset | 0 - if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) - if (value < 0) value = 0xffffffff + value + 1 - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value >>> 24) - this[offset + 1] = (value >>> 16) - this[offset + 2] = (value >>> 8) - this[offset + 3] = (value & 0xff) - } else { - objectWriteUInt32(this, value, offset, false) - } - return offset + 4 -} + // flush current buffer + this.flush(); -function checkIEEE754 (buf, value, offset, ext, max, min) { - if (offset + ext > buf.length) throw new RangeError('Index out of range') - if (offset < 0) throw new RangeError('Index out of range') + // read from the results + return this.pull(); } -function writeFloat (buf, value, offset, littleEndian, noAssert) { - if (!noAssert) { - checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38) - } - ieee754.write(buf, value, offset, littleEndian, 23, 4) - return offset + 4 +function push(chunk) { + var buffers = this.buffers || (this.buffers = []); + buffers.push(chunk); } -Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) { - return writeFloat(this, value, offset, true, noAssert) +function pull() { + var buffers = this.buffers || (this.buffers = []); + return buffers.shift(); } -Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) { - return writeFloat(this, value, offset, false, noAssert) -} +function mixinFactory(source) { + return mixin; -function writeDouble (buf, value, offset, littleEndian, noAssert) { - if (!noAssert) { - checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308) + function mixin(target) { + for (var key in source) { + target[key] = source[key]; + } + return target; } - ieee754.write(buf, value, offset, littleEndian, 52, 8) - return offset + 8 -} - -Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) { - return writeDouble(this, value, offset, true, noAssert) } -Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) { - return writeDouble(this, value, offset, false, noAssert) -} -// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length) -Buffer.prototype.copy = function copy (target, targetStart, start, end) { - if (!start) start = 0 - if (!end && end !== 0) end = this.length - if (targetStart >= target.length) targetStart = target.length - if (!targetStart) targetStart = 0 - if (end > 0 && end < start) end = start +/***/ }), +/* 18 */ +/***/ (function(module, exports, __webpack_require__) { - // Copy 0 bytes; we're done - if (end === start) return 0 - if (target.length === 0 || this.length === 0) return 0 +// decode.js - // Fatal error conditions - if (targetStart < 0) { - throw new RangeError('targetStart out of bounds') - } - if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds') - if (end < 0) throw new RangeError('sourceEnd out of bounds') +exports.decode = decode; - // Are we oob? - if (end > this.length) end = this.length - if (target.length - targetStart < end - start) { - end = target.length - targetStart + start - } +var DecodeBuffer = __webpack_require__(19).DecodeBuffer; - var len = end - start - var i +function decode(input, options) { + var decoder = new DecodeBuffer(options); + decoder.write(input); + return decoder.read(); +} - if (this === target && start < targetStart && targetStart < end) { - // descending copy from end - for (i = len - 1; i >= 0; --i) { - target[i + targetStart] = this[i + start] - } - } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) { - // ascending copy from start - for (i = 0; i < len; ++i) { - target[i + targetStart] = this[i + start] - } - } else { - Uint8Array.prototype.set.call( - target, - this.subarray(start, start + len), - targetStart - ) - } +/***/ }), +/* 19 */ +/***/ (function(module, exports, __webpack_require__) { - return len -} +// decode-buffer.js -// Usage: -// buffer.fill(number[, offset[, end]]) -// buffer.fill(buffer[, offset[, end]]) -// buffer.fill(string[, offset[, end]][, encoding]) -Buffer.prototype.fill = function fill (val, start, end, encoding) { - // Handle string cases: - if (typeof val === 'string') { - if (typeof start === 'string') { - encoding = start - start = 0 - end = this.length - } else if (typeof end === 'string') { - encoding = end - end = this.length - } - if (val.length === 1) { - var code = val.charCodeAt(0) - if (code < 256) { - val = code - } - } - if (encoding !== undefined && typeof encoding !== 'string') { - throw new TypeError('encoding must be a string') - } - if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) { - throw new TypeError('Unknown encoding: ' + encoding) - } - } else if (typeof val === 'number') { - val = val & 255 - } +exports.DecodeBuffer = DecodeBuffer; - // Invalid ranges are not set to a default, so can range check early. - if (start < 0 || this.length < start || this.length < end) { - throw new RangeError('Out of range index') - } +var preset = __webpack_require__(10).preset; - if (end <= start) { - return this - } +var FlexDecoder = __webpack_require__(17).FlexDecoder; - start = start >>> 0 - end = end === undefined ? this.length : end >>> 0 +FlexDecoder.mixin(DecodeBuffer.prototype); - if (!val) val = 0 +function DecodeBuffer(options) { + if (!(this instanceof DecodeBuffer)) return new DecodeBuffer(options); - var i - if (typeof val === 'number') { - for (i = start; i < end; ++i) { - this[i] = val - } - } else { - var bytes = Buffer.isBuffer(val) - ? val - : utf8ToBytes(new Buffer(val, encoding).toString()) - var len = bytes.length - for (i = 0; i < end - start; ++i) { - this[i + start] = bytes[i % len] + if (options) { + this.options = options; + if (options.codec) { + var codec = this.codec = options.codec; + if (codec.bufferish) this.bufferish = codec.bufferish; } } - - return this } -// HELPER FUNCTIONS -// ================ +DecodeBuffer.prototype.codec = preset; -var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g +DecodeBuffer.prototype.fetch = function() { + return this.codec.decode(this); +}; -function base64clean (str) { - // Node strips out invalid characters like \n and \t from the string, base64-js does not - str = stringtrim(str).replace(INVALID_BASE64_RE, '') - // Node converts strings with length < 2 to '' - if (str.length < 2) return '' - // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not - while (str.length % 4 !== 0) { - str = str + '=' - } - return str -} -function stringtrim (str) { - if (str.trim) return str.trim() - return str.replace(/^\s+|\s+$/g, '') -} +/***/ }), +/* 20 */ +/***/ (function(module, exports, __webpack_require__) { -function toHex (n) { - if (n < 16) return '0' + n.toString(16) - return n.toString(16) -} +// read-format.js -function utf8ToBytes (string, units) { - units = units || Infinity - var codePoint - var length = string.length - var leadSurrogate = null - var bytes = [] +var ieee754 = __webpack_require__(7); +var Int64Buffer = __webpack_require__(9); +var Uint64BE = Int64Buffer.Uint64BE; +var Int64BE = Int64Buffer.Int64BE; - for (var i = 0; i < length; ++i) { - codePoint = string.charCodeAt(i) +exports.getReadFormat = getReadFormat; +exports.readUint8 = uint8; - // is surrogate component - if (codePoint > 0xD7FF && codePoint < 0xE000) { - // last char was a lead - if (!leadSurrogate) { - // no lead yet - if (codePoint > 0xDBFF) { - // unexpected trail - if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) - continue - } else if (i + 1 === length) { - // unpaired lead - if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) - continue - } +var Bufferish = __webpack_require__(0); +var BufferProto = __webpack_require__(8); - // valid lead - leadSurrogate = codePoint +var HAS_MAP = ("undefined" !== typeof Map); +var NO_ASSERT = true; - continue - } +function getReadFormat(options) { + var binarraybuffer = Bufferish.hasArrayBuffer && options && options.binarraybuffer; + var int64 = options && options.int64; + var usemap = HAS_MAP && options && options.usemap; - // 2 leads in a row - if (codePoint < 0xDC00) { - if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) - leadSurrogate = codePoint - continue - } + var readFormat = { + map: (usemap ? map_to_map : map_to_obj), + array: array, + str: str, + bin: (binarraybuffer ? bin_arraybuffer : bin_buffer), + ext: ext, + uint8: uint8, + uint16: uint16, + uint32: uint32, + uint64: read(8, int64 ? readUInt64BE_int64 : readUInt64BE), + int8: int8, + int16: int16, + int32: int32, + int64: read(8, int64 ? readInt64BE_int64 : readInt64BE), + float32: read(4, readFloatBE), + float64: read(8, readDoubleBE) + }; - // valid surrogate pair - codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000 - } else if (leadSurrogate) { - // valid bmp char, but last char was a lead - if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) - } + return readFormat; +} - leadSurrogate = null +function map_to_obj(decoder, len) { + var value = {}; + var i; + var k = new Array(len); + var v = new Array(len); - // encode utf8 - if (codePoint < 0x80) { - if ((units -= 1) < 0) break - bytes.push(codePoint) - } else if (codePoint < 0x800) { - if ((units -= 2) < 0) break - bytes.push( - codePoint >> 0x6 | 0xC0, - codePoint & 0x3F | 0x80 - ) - } else if (codePoint < 0x10000) { - if ((units -= 3) < 0) break - bytes.push( - codePoint >> 0xC | 0xE0, - codePoint >> 0x6 & 0x3F | 0x80, - codePoint & 0x3F | 0x80 - ) - } else if (codePoint < 0x110000) { - if ((units -= 4) < 0) break - bytes.push( - codePoint >> 0x12 | 0xF0, - codePoint >> 0xC & 0x3F | 0x80, - codePoint >> 0x6 & 0x3F | 0x80, - codePoint & 0x3F | 0x80 - ) - } else { - throw new Error('Invalid code point') - } + var decode = decoder.codec.decode; + for (i = 0; i < len; i++) { + k[i] = decode(decoder); + v[i] = decode(decoder); + } + for (i = 0; i < len; i++) { + value[k[i]] = v[i]; } + return value; +} - return bytes +function map_to_map(decoder, len) { + var value = new Map(); + var i; + var k = new Array(len); + var v = new Array(len); + + var decode = decoder.codec.decode; + for (i = 0; i < len; i++) { + k[i] = decode(decoder); + v[i] = decode(decoder); + } + for (i = 0; i < len; i++) { + value.set(k[i], v[i]); + } + return value; } -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) +function array(decoder, len) { + var value = new Array(len); + var decode = decoder.codec.decode; + for (var i = 0; i < len; i++) { + value[i] = decode(decoder); } - return byteArray + return value; } -function utf16leToBytes (str, units) { - var c, hi, lo - var byteArray = [] - for (var i = 0; i < str.length; ++i) { - if ((units -= 2) < 0) break +function str(decoder, len) { + var start = decoder.reserve(len); + var end = start + len; + return BufferProto.toString.call(decoder.buffer, "utf-8", start, end); +} - c = str.charCodeAt(i) - hi = c >> 8 - lo = c % 256 - byteArray.push(lo) - byteArray.push(hi) - } +function bin_buffer(decoder, len) { + var start = decoder.reserve(len); + var end = start + len; + var buf = BufferProto.slice.call(decoder.buffer, start, end); + return Bufferish.from(buf); +} - return byteArray +function bin_arraybuffer(decoder, len) { + var start = decoder.reserve(len); + var end = start + len; + var buf = BufferProto.slice.call(decoder.buffer, start, end); + return Bufferish.Uint8Array.from(buf).buffer; } -function base64ToBytes (str) { - return base64.toByteArray(base64clean(str)) +function ext(decoder, len) { + var start = decoder.reserve(len+1); + var type = decoder.buffer[start++]; + var end = start + len; + var unpack = decoder.codec.getExtUnpacker(type); + if (!unpack) throw new Error("Invalid ext type: " + (type ? ("0x" + type.toString(16)) : type)); + var buf = BufferProto.slice.call(decoder.buffer, start, end); + return unpack(buf); } -function blitBuffer (src, dst, offset, length) { - for (var i = 0; i < length; ++i) { - if ((i + offset >= dst.length) || (i >= src.length)) break - dst[i + offset] = src[i] - } - return i +function uint8(decoder) { + var start = decoder.reserve(1); + return decoder.buffer[start]; } -function isnan (val) { - return val !== val // eslint-disable-line no-self-compare +function int8(decoder) { + var start = decoder.reserve(1); + var value = decoder.buffer[start]; + return (value & 0x80) ? value - 0x100 : value; } -/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(60))) +function uint16(decoder) { + var start = decoder.reserve(2); + var buffer = decoder.buffer; + return (buffer[start++] << 8) | buffer[start]; +} -/***/ }), -/* 23 */ -/***/ (function(module, exports, __webpack_require__) { +function int16(decoder) { + var start = decoder.reserve(2); + var buffer = decoder.buffer; + var value = (buffer[start++] << 8) | buffer[start]; + return (value & 0x8000) ? value - 0x10000 : value; +} -"use strict"; +function uint32(decoder) { + var start = decoder.reserve(4); + var buffer = decoder.buffer; + return (buffer[start++] * 16777216) + (buffer[start++] << 16) + (buffer[start++] << 8) + buffer[start]; +} -Object.defineProperty(exports, "__esModule", { value: true }); -var DeluxeSignal_1 = __webpack_require__(50); -exports.DeluxeSignal = DeluxeSignal_1.DeluxeSignal; -var GenericEvent_1 = __webpack_require__(57); -exports.GenericEvent = GenericEvent_1.GenericEvent; -var IOnceSignal_1 = __webpack_require__(51); -exports.IOnceSignal = IOnceSignal_1.IOnceSignal; -var IPrioritySignal_1 = __webpack_require__(52); -exports.IPrioritySignal = IPrioritySignal_1.IPrioritySignal; -var ISignal_1 = __webpack_require__(53); -exports.ISignal = ISignal_1.ISignal; -var ISlot_1 = __webpack_require__(54); -exports.ISlot = ISlot_1.ISlot; -var MonoSignal_1 = __webpack_require__(55); -exports.MonoSignal = MonoSignal_1.MonoSignal; -var OnceSignal_1 = __webpack_require__(12); -exports.OnceSignal = OnceSignal_1.OnceSignal; -var PrioritySignal_1 = __webpack_require__(24); -exports.PrioritySignal = PrioritySignal_1.PrioritySignal; -var Promise_1 = __webpack_require__(56); -exports.Promise = Promise_1.Promise; -var Signal_1 = __webpack_require__(25); -exports.Signal = Signal_1.Signal; -var Slot_1 = __webpack_require__(3); -exports.Slot = Slot_1.Slot; -var SlotList_1 = __webpack_require__(26); -exports.SlotList = SlotList_1.SlotList; -//# sourceMappingURL=index.js.map +function int32(decoder) { + var start = decoder.reserve(4); + var buffer = decoder.buffer; + return (buffer[start++] << 24) | (buffer[start++] << 16) | (buffer[start++] << 8) | buffer[start]; +} -/***/ }), -/* 24 */ -/***/ (function(module, exports, __webpack_require__) { +function read(len, method) { + return function(decoder) { + var start = decoder.reserve(len); + return method.call(decoder.buffer, start, NO_ASSERT); + }; +} -"use strict"; +function readUInt64BE(start) { + return new Uint64BE(this, start).toNumber(); +} -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var Signal_1 = __webpack_require__(25); -var Slot_1 = __webpack_require__(3); -var PrioritySignal = (function (_super) { - __extends(PrioritySignal, _super); +function readInt64BE(start) { + return new Int64BE(this, start).toNumber(); +} + +function readUInt64BE_int64(start) { + return new Uint64BE(this, start); +} + +function readInt64BE_int64(start) { + return new Int64BE(this, start); +} + +function readFloatBE(start) { + return ieee754.read(this, start, false, 23, 4); +} + +function readDoubleBE(start) { + return ieee754.read(this, start, false, 52, 8); +} + +/***/ }), +/* 21 */ +/***/ (function(module, exports, __webpack_require__) { + +/** + * event-lite.js - Light-weight EventEmitter (less than 1KB when gzipped) + * + * @copyright Yusuke Kawasaki + * @license MIT + * @constructor + * @see https://github.com/kawanet/event-lite + * @see http://kawanet.github.io/event-lite/EventLite.html + * @example + * var EventLite = require("event-lite"); + * + * function MyClass() {...} // your class + * + * EventLite.mixin(MyClass.prototype); // import event methods + * + * var obj = new MyClass(); + * obj.on("foo", function() {...}); // add event listener + * obj.once("bar", function() {...}); // add one-time event listener + * obj.emit("foo"); // dispatch event + * obj.emit("bar"); // dispatch another event + * obj.off("foo"); // remove event listener + */ + +function EventLite() { + if (!(this instanceof EventLite)) return new EventLite(); +} + +(function(EventLite) { + // export the class for node.js + if (true) module.exports = EventLite; + + // property name to hold listeners + var LISTENERS = "listeners"; + + // methods to export + var methods = { + on: on, + once: once, + off: off, + emit: emit + }; + + // mixin to self + mixin(EventLite.prototype); + + // export mixin function + EventLite.mixin = mixin; + + /** + * Import on(), once(), off() and emit() methods into target object. + * + * @function EventLite.mixin + * @param target {Prototype} + */ + + function mixin(target) { + for (var key in methods) { + target[key] = methods[key]; + } + return target; + } + + /** + * Add an event listener. + * + * @function EventLite.prototype.on + * @param type {string} + * @param func {Function} + * @returns {EventLite} Self for method chaining + */ + + function on(type, func) { + getListeners(this, type).push(func); + return this; + } + + /** + * Add one-time event listener. + * + * @function EventLite.prototype.once + * @param type {string} + * @param func {Function} + * @returns {EventLite} Self for method chaining + */ + + function once(type, func) { + var that = this; + wrap.originalListener = func; + getListeners(that, type).push(wrap); + return that; + + function wrap() { + off.call(that, type, wrap); + func.apply(this, arguments); + } + } + + /** + * Remove an event listener. + * + * @function EventLite.prototype.off + * @param [type] {string} + * @param [func] {Function} + * @returns {EventLite} Self for method chaining + */ + + function off(type, func) { + var that = this; + var listners; + if (!arguments.length) { + delete that[LISTENERS]; + } else if (!func) { + listners = that[LISTENERS]; + if (listners) { + delete listners[type]; + if (!Object.keys(listners).length) return off.call(that); + } + } else { + listners = getListeners(that, type, true); + if (listners) { + listners = listners.filter(ne); + if (!listners.length) return off.call(that, type); + that[LISTENERS][type] = listners; + } + } + return that; + + function ne(test) { + return test !== func && test.originalListener !== func; + } + } + + /** + * Dispatch (trigger) an event. + * + * @function EventLite.prototype.emit + * @param type {string} + * @param [value] {*} + * @returns {boolean} True when a listener received the event + */ + + function emit(type, value) { + var that = this; + var listeners = getListeners(that, type, true); + if (!listeners) return false; + var arglen = arguments.length; + if (arglen === 1) { + listeners.forEach(zeroarg); + } else if (arglen === 2) { + listeners.forEach(onearg); + } else { + var args = Array.prototype.slice.call(arguments, 1); + listeners.forEach(moreargs); + } + return !!listeners.length; + + function zeroarg(func) { + func.call(that); + } + + function onearg(func) { + func.call(that, value); + } + + function moreargs(func) { + func.apply(that, args); + } + } + + /** + * @ignore + */ + + function getListeners(that, type, readonly) { + if (readonly && !that[LISTENERS]) return; + var listeners = that[LISTENERS] || (that[LISTENERS] = {}); + return listeners[type] || (listeners[type] = []); + } + +})(EventLite); + + +/***/ }), +/* 22 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + +Object.defineProperty(exports, "__esModule", { value: true }); +var DeluxeSignal_1 = __webpack_require__(45); +exports.DeluxeSignal = DeluxeSignal_1.DeluxeSignal; +var GenericEvent_1 = __webpack_require__(46); +exports.GenericEvent = GenericEvent_1.GenericEvent; +var IOnceSignal_1 = __webpack_require__(47); +exports.IOnceSignal = IOnceSignal_1.IOnceSignal; +var IPrioritySignal_1 = __webpack_require__(48); +exports.IPrioritySignal = IPrioritySignal_1.IPrioritySignal; +var ISignal_1 = __webpack_require__(49); +exports.ISignal = ISignal_1.ISignal; +var ISlot_1 = __webpack_require__(50); +exports.ISlot = ISlot_1.ISlot; +var MonoSignal_1 = __webpack_require__(51); +exports.MonoSignal = MonoSignal_1.MonoSignal; +var OnceSignal_1 = __webpack_require__(11); +exports.OnceSignal = OnceSignal_1.OnceSignal; +var PrioritySignal_1 = __webpack_require__(23); +exports.PrioritySignal = PrioritySignal_1.PrioritySignal; +var Promise_1 = __webpack_require__(52); +exports.Promise = Promise_1.Promise; +var Signal_1 = __webpack_require__(24); +exports.Signal = Signal_1.Signal; +var Slot_1 = __webpack_require__(3); +exports.Slot = Slot_1.Slot; +var SlotList_1 = __webpack_require__(25); +exports.SlotList = SlotList_1.SlotList; +//# sourceMappingURL=index.js.map + +/***/ }), +/* 23 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + +var __extends = (this && this.__extends) || (function () { + var extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +Object.defineProperty(exports, "__esModule", { value: true }); +var Signal_1 = __webpack_require__(24); +var Slot_1 = __webpack_require__(3); +var PrioritySignal = (function (_super) { + __extends(PrioritySignal, _super); function PrioritySignal() { var valueClasses = []; for (var _i = 0; _i < arguments.length; _i++) { @@ -3999,7 +3876,7 @@ exports.PrioritySignal = PrioritySignal; //# sourceMappingURL=PrioritySignal.js.map /***/ }), -/* 25 */ +/* 24 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -4015,7 +3892,7 @@ var __extends = (this && this.__extends) || (function () { }; })(); Object.defineProperty(exports, "__esModule", { value: true }); -var OnceSignal_1 = __webpack_require__(12); +var OnceSignal_1 = __webpack_require__(11); /** * Allows the valueClasses to be set in MXML, e.g. * {[String, uint]} @@ -4069,7 +3946,7 @@ exports.Signal = Signal; //# sourceMappingURL=Signal.js.map /***/ }), -/* 26 */ +/* 25 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -4284,17 +4161,156 @@ exports.SlotList = SlotList; //# sourceMappingURL=SlotList.js.map /***/ }), -/* 27 */ +/* 26 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var msgpack = __webpack_require__(7); -var signals_js_1 = __webpack_require__(23); -var Protocol_1 = __webpack_require__(4); -var Room_1 = __webpack_require__(13); +var __extends = (this && this.__extends) || (function () { + var extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +Object.defineProperty(exports, "__esModule", { value: true }); +var signals_js_1 = __webpack_require__(22); +var Clock = __webpack_require__(53); +var delta_listener_1 = __webpack_require__(54); +var msgpack = __webpack_require__(4); +var fossilDelta = __webpack_require__(57); +var Protocol_1 = __webpack_require__(12); +var Room = /** @class */ (function (_super) { + __extends(Room, _super); + function Room(name) { + var _this = _super.call(this, {}) || this; + _this.clock = new Clock(); // experimental + _this.remoteClock = new Clock(); // experimental + // Public signals + _this.onJoin = new signals_js_1.Signal(); + _this.onUpdate = new signals_js_1.Signal(); + _this.onData = new signals_js_1.Signal(); + _this.onError = new signals_js_1.Signal(); + _this.onLeave = new signals_js_1.Signal(); + _this.id = null; + _this.name = name; + _this.onLeave.add(function () { return _this.removeAllListeners(); }); + return _this; + } + Room.prototype.connect = function (connection) { + var _this = this; + this.connection = connection; + this.connection.onmessage = this.onMessageCallback.bind(this); + this.connection.onclose = function (e) { return _this.onLeave.dispatch(); }; + }; + Room.prototype.onMessageCallback = function (event) { + var message = msgpack.decode(new Uint8Array(event.data)); + var code = message[0]; + if (code == Protocol_1.Protocol.JOIN_ROOM) { + this.sessionId = message[1]; + this.onJoin.dispatch(); + } + else if (code == Protocol_1.Protocol.JOIN_ERROR) { + this.onError.dispatch(message[2]); + } + else if (code == Protocol_1.Protocol.ROOM_STATE) { + var state = message[2]; + var remoteCurrentTime = message[3]; + var remoteElapsedTime = message[4]; + this.setState(state, remoteCurrentTime, remoteElapsedTime); + } + else if (code == Protocol_1.Protocol.ROOM_STATE_PATCH) { + this.patch(message[2]); + } + else if (code == Protocol_1.Protocol.ROOM_DATA) { + this.onData.dispatch(message[2]); + } + else if (code == Protocol_1.Protocol.LEAVE_ROOM) { + this.leave(); + } + }; + Room.prototype.setState = function (state, remoteCurrentTime, remoteElapsedTime) { + this.set(state); + this._previousState = msgpack.encode(state); + // set remote clock properties + if (remoteCurrentTime && remoteElapsedTime) { + this.remoteClock.currentTime = remoteCurrentTime; + this.remoteClock.elapsedTime = remoteElapsedTime; + } + this.clock.start(); + this.onUpdate.dispatch(state); + }; + Room.prototype.patch = function (binaryPatch) { + // + // calculate client-side ping + // + var patchTime = Date.now(); + if (this.lastPatchTime) { + this.ping = patchTime - this.lastPatchTime; + } + this.lastPatchTime = patchTime; + this.clock.tick(); + // apply patch + this._previousState = fossilDelta.apply(this._previousState, binaryPatch); + // trigger state callbacks + this.set(msgpack.decode(this._previousState)); + this.onUpdate.dispatch(this.data); + }; + Room.prototype.leave = function () { + if (this.id) { + this.connection.close(); + } + }; + Room.prototype.send = function (data) { + this.connection.send([Protocol_1.Protocol.ROOM_DATA, this.id, data]); + }; + Room.prototype.removeAllListeners = function () { + _super.prototype.removeAllListeners.call(this); + this.onJoin.removeAll(); + this.onUpdate.removeAll(); + this.onData.removeAll(); + this.onError.removeAll(); + this.onLeave.removeAll(); + }; + return Room; +}(delta_listener_1.DeltaContainer)); +exports.Room = Room; + + +/***/ }), +/* 27 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + +Object.defineProperty(exports, "__esModule", { value: true }); +var Client_1 = __webpack_require__(28); +exports.Client = Client_1.Client; +var Protocol_1 = __webpack_require__(12); +exports.Protocol = Protocol_1.Protocol; +var Room_1 = __webpack_require__(26); +exports.Room = Room_1.Room; + + +/***/ }), +/* 28 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + +Object.defineProperty(exports, "__esModule", { value: true }); +var msgpack = __webpack_require__(4); +var signals_js_1 = __webpack_require__(22); +var Protocol_1 = __webpack_require__(12); +var Room_1 = __webpack_require__(26); var Connection_1 = __webpack_require__(58); +// compatibility with react-native +var storage = (typeof (localStorage) === "undefined") + ? __webpack_require__(61).AsyncStorage + : window.localStorage; var Client = /** @class */ (function () { function Client(url) { var _this = this; @@ -4304,8 +4320,20 @@ var Client = /** @class */ (function () { this.onClose = new signals_js_1.Signal(); this.onError = new signals_js_1.Signal(); this.rooms = {}; - this.id = localStorage.getItem('colyseusid') || ""; this.hostname = url; + var colyseusid = storage.getItem('colyseusid'); + if (!(colyseusid instanceof Promise)) { + // browser has synchronous return + this.createConnection(colyseusid); + } + else { + // react-native is asynchronous + colyseusid.then(function (id) { return _this.createConnection(id); }); + } + } + Client.prototype.createConnection = function (colyseusid) { + var _this = this; + this.id = colyseusid || ""; this.connection = new Connection_1.Connection(this.hostname + "/?colyseusid=" + this.id); this.connection.onmessage = this.onMessageCallback.bind(this); this.connection.onclose = function (e) { return _this.onClose.dispatch(); }; @@ -4316,7 +4344,7 @@ var Client = /** @class */ (function () { _this.onOpen.dispatch(); } }; - } + }; Client.prototype.join = function (roomName, options) { if (options === void 0) { options = {}; } this.room = new Room_1.Room(roomName); @@ -4331,7 +4359,7 @@ var Client = /** @class */ (function () { var message = msgpack.decode(new Uint8Array(event.data)); var code = message[0]; if (code == Protocol_1.Protocol.USER_ID) { - localStorage.setItem('colyseusid', message[1]); + storage.setItem('colyseusid', message[1]); this.id = message[1]; this.onOpen.dispatch(); } @@ -4357,136 +4385,51 @@ exports.Client = Client; /***/ }), -/* 28 */ +/* 29 */ /***/ (function(module, exports, __webpack_require__) { -"use strict"; +/* WEBPACK VAR INJECTION */(function(Buffer) {/* globals Buffer */ -var Clock = (function () { - function Clock(useInterval) { - if (useInterval === void 0) { useInterval = false; } - this.running = false; - this.now = (typeof (window) !== "undefined" && window.performance && (window.performance.now).bind(window.performance)) || Date.now; - this.start(useInterval); - } - Clock.prototype.start = function (useInterval) { - if (useInterval === void 0) { useInterval = false; } - this.deltaTime = 0; - this.currentTime = this.now(); - this.elapsedTime = 0; - this.running = true; - if (useInterval) { - // auto set interval to 60 ticks per second - this._interval = setInterval(this.tick.bind(this), 1000 / 60); - } - }; - Clock.prototype.stop = function () { - this.running = false; - if (this._interval) { - clearInterval(this._interval); - } - }; - Clock.prototype.tick = function (newTime) { - if (newTime === void 0) { newTime = this.now(); } - this.deltaTime = newTime - this.currentTime; - this.currentTime = newTime; - this.elapsedTime += this.deltaTime; - }; - return Clock; -}()); -module.exports = Clock; +module.exports = + c(("undefined" !== typeof Buffer) && Buffer) || + c(this.Buffer) || + c(("undefined" !== typeof window) && window.Buffer) || + this.Buffer; +function c(B) { + return B && B.isBuffer && B; +} +/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(15).Buffer)) /***/ }), -/* 29 */ -/***/ (function(module, exports, __webpack_require__) { +/* 30 */ +/***/ (function(module, exports) { + +var g; + +// This works in non-strict mode +g = (function() { + return this; +})(); + +try { + // This works if eval is allowed (see CSP) + g = g || Function("return this")() || (1,eval)("this"); +} catch(e) { + // This works if the window reference is available + if(typeof window === "object") + g = window; +} + +// g can still be undefined, but nothing to do about it... +// We return undefined, instead of nothing here, so it's +// easier to handle this case. if(!global) { ...} + +module.exports = g; -"use strict"; -Object.defineProperty(exports,"__esModule",{value:true});exports.createBackoff=createBackoff;var backoff={exponential:function exponential(attempt,delay){return Math.floor(Math.random()*Math.pow(2,attempt)*delay);},fibonacci:function fibonacci(attempt,delay){var current=1;if(attempt>current){var prev=1,current=2;for(var index=2;index2&&arguments[2]!==undefined?arguments[2]:{};_classCallCheck(this,WebSocketClient);this.url=url;this.protocols=protocols;this.reconnectEnabled=true;this.listeners={};this.backoff=createBackoff(options.backoff||'exponential',options);this.backoff.onReady=this.onBackoffReady.bind(this);this.open();}_createClass(WebSocketClient,[{key:'open',value:function open(){var reconnect=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;this.isReconnect=reconnect;this.ws=new WebSocket(this.url,this.protocols);this.ws.onclose=this.onCloseCallback.bind(this);this.ws.onerror=this.onErrorCallback.bind(this);this.ws.onmessage=this.onMessageCallback.bind(this);this.ws.onopen=this.onOpenCallback.bind(this);}/** - * @ignore - */},{key:'onBackoffReady',value:function onBackoffReady(number,delay){// console.log("onBackoffReady", number + ' ' + delay + 'ms'); -this.open(true);}/** - * @ignore - */},{key:'onCloseCallback',value:function onCloseCallback(){if(!this.isReconnect&&this.listeners['onclose']){this.listeners['onclose'].apply(null,arguments);}if(this.reconnectEnabled){this.backoff.backoff();}}/** - * @ignore - */},{key:'onErrorCallback',value:function onErrorCallback(){if(this.listeners['onerror']){this.listeners['onerror'].apply(null,arguments);}}/** - * @ignore - */},{key:'onMessageCallback',value:function onMessageCallback(){if(this.listeners['onmessage']){this.listeners['onmessage'].apply(null,arguments);}}/** - * @ignore - */},{key:'onOpenCallback',value:function onOpenCallback(){if(this.listeners['onopen']){this.listeners['onopen'].apply(null,arguments);}if(this.isReconnect&&this.listeners['onreconnect']){this.listeners['onreconnect'].apply(null,arguments);}this.isReconnect=false;}/** - * The number of bytes of data that have been queued using calls to send() - * but not yet transmitted to the network. This value does not reset to zero - * when the connection is closed; if you keep calling send(), this will - * continue to climb. - * - * @type unsigned long - * @readonly - */},{key:'close',/** - * Closes the WebSocket connection or connection attempt, if any. If the - * connection is already CLOSED, this method does nothing. - * - * @param code A numeric value indicating the status code explaining why the connection is being closed. If this parameter is not specified, a default value of 1000 (indicating a normal "transaction complete" closure) is assumed. See the list of status codes on the CloseEvent page for permitted values. - * @param reason A human-readable string explaining why the connection is closing. This string must be no longer than 123 bytes of UTF-8 text (not characters). - * - * @return void - */value:function close(code,reason){if(typeof code=='undefined'){code=1000;}this.reconnectEnabled=false;this.ws.close(code,reason);}/** - * Transmits data to the server over the WebSocket connection. - * @param data DOMString|ArrayBuffer|Blob - * @return void - */},{key:'send',value:function send(data){this.ws.send(data);}/** - * An event listener to be called when the WebSocket connection's readyState changes to CLOSED. The listener receives a CloseEvent named "close". - * @param listener EventListener - */},{key:'bufferedAmount',get:function get(){return this.ws.bufferedAmount;}/** - * The current state of the connection; this is one of the Ready state constants. - * @type unsigned short - * @readonly - */},{key:'readyState',get:function get(){return this.ws.readyState;}/** - * A string indicating the type of binary data being transmitted by the - * connection. This should be either "blob" if DOM Blob objects are being - * used or "arraybuffer" if ArrayBuffer objects are being used. - * @type DOMString - */},{key:'binaryType',get:function get(){return this.ws.binaryType;},set:function set(binaryType){this.ws.binaryType=binaryType;}/** - * The extensions selected by the server. This is currently only the empty - * string or a list of extensions as negotiated by the connection. - * @type DOMString - */},{key:'extensions',get:function get(){return this.ws.extensions;},set:function set(extensions){this.ws.extensions=extensions;}/** - * A string indicating the name of the sub-protocol the server selected; - * this will be one of the strings specified in the protocols parameter when - * creating the WebSocket object. - * @type DOMString - */},{key:'protocol',get:function get(){return this.ws.protocol;},set:function set(protocol){this.ws.protocol=protocol;}},{key:'onclose',set:function set(listener){this.listeners['onclose']=listener;},get:function get(){return this.listeners['onclose'];}/** - * An event listener to be called when an error occurs. This is a simple event named "error". - * @param listener EventListener - */},{key:'onerror',set:function set(listener){this.listeners['onerror']=listener;},get:function get(){return this.listeners['onerror'];}/** - * An event listener to be called when a message is received from the server. The listener receives a MessageEvent named "message". - * @param listener EventListener - */},{key:'onmessage',set:function set(listener){this.listeners['onmessage']=listener;},get:function get(){return this.listeners['onmessage'];}/** - * An event listener to be called when the WebSocket connection's readyState changes to OPEN; this indicates that the connection is ready to send and receive data. The event is a simple one with the name "open". - * @param listener EventListener - */},{key:'onopen',set:function set(listener){this.listeners['onopen']=listener;},get:function get(){return this.listeners['onopen'];}/** - * @param listener EventListener - */},{key:'onreconnect',set:function set(listener){this.listeners['onreconnect']=listener;},get:function get(){return this.listeners['onreconnect'];}}]);return WebSocketClient;}();/** - * The connection is not yet open. - */WebSocketClient.CONNECTING=WebSocket.CONNECTING;/** - * The connection is open and ready to communicate. - */WebSocketClient.OPEN=WebSocket.OPEN;/** - * The connection is in the process of closing. - */WebSocketClient.CLOSING=WebSocket.CLOSING;/** - * The connection is closed or couldn't be opened. - */WebSocketClient.CLOSED=WebSocket.CLOSED;exports.default=WebSocketClient; - -/***/ }), -/* 31 */ +/* 31 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -4610,1150 +4553,892 @@ function fromByteArray (uint8) { /* 32 */ /***/ (function(module, exports, __webpack_require__) { -"use strict"; +// bufferish-array.js -var compare_1 = __webpack_require__(33); -var DeltaContainer = (function () { - function DeltaContainer(data) { - this.listeners = []; - this.matcherPlaceholders = { - ":id": /^([a-zA-Z0-9\-_]+)$/, - ":number": /^([0-9]+)$/, - ":string": /^(\w+)$/, - ":axis": /^([xyz])$/, - ":*": /(.*)/, - }; - this.data = data; - this.reset(); - } - DeltaContainer.prototype.set = function (newData) { - var patches = compare_1.compare(this.data, newData); - this.checkPatches(patches); - this.data = newData; - return patches; - }; - DeltaContainer.prototype.registerPlaceholder = function (placeholder, matcher) { - this.matcherPlaceholders[placeholder] = matcher; - }; - DeltaContainer.prototype.listen = function (segments, callback) { - var _this = this; - var rules; - if (typeof (segments) === "function") { - rules = []; - callback = segments; - } - else { - rules = segments.split("/"); - } - var listener = { - callback: callback, - rawRules: rules, - rules: rules.map(function (segment) { - if (typeof (segment) === "string") { - // replace placeholder matchers - return (segment.indexOf(":") === 0) - ? _this.matcherPlaceholders[segment] || _this.matcherPlaceholders[":*"] - : new RegExp("^" + segment + "$"); - } - else { - return segment; - } - }) - }; - if (rules.length === 0) { - this.defaultListener = listener; - } - else { - this.listeners.push(listener); - } - return listener; - }; - DeltaContainer.prototype.removeListener = function (listener) { - for (var i = this.listeners.length - 1; i >= 0; i--) { - if (this.listeners[i] === listener) { - this.listeners.splice(i, 1); - } - } - }; - DeltaContainer.prototype.removeAllListeners = function () { - this.reset(); - }; - DeltaContainer.prototype.checkPatches = function (patches) { - for (var i = patches.length - 1; i >= 0; i--) { - var matched = false; - for (var j = 0, len = this.listeners.length; j < len; j++) { - var listener = this.listeners[j]; - var pathVariables = this.getPathVariables(patches[i], listener); - if (pathVariables) { - listener.callback({ - path: pathVariables, - operation: patches[i].operation, - value: patches[i].value - }); - matched = true; - } - } - // check for fallback listener - if (!matched && this.defaultListener) { - this.defaultListener.callback(patches[i]); - } - } - }; - DeltaContainer.prototype.getPathVariables = function (patch, listener) { - // skip if rules count differ from patch - if (patch.path.length !== listener.rules.length) { - return false; - } - var path = {}; - for (var i = 0, len = listener.rules.length; i < len; i++) { - var matches = patch.path[i].match(listener.rules[i]); - if (!matches || matches.length === 0 || matches.length > 2) { - return false; - } - else if (listener.rawRules[i].substr(0, 1) === ":") { - path[listener.rawRules[i].substr(1)] = matches[1]; - } - } - return path; - }; - DeltaContainer.prototype.reset = function () { - this.listeners = []; - }; - return DeltaContainer; -}()); -exports.DeltaContainer = DeltaContainer; +var Bufferish = __webpack_require__(0); +var exports = module.exports = alloc(0); -/***/ }), -/* 33 */ -/***/ (function(module, exports, __webpack_require__) { +exports.alloc = alloc; +exports.concat = Bufferish.concat; +exports.from = from; -"use strict"; +/** + * @param size {Number} + * @returns {Buffer|Uint8Array|Array} + */ -function compare(tree1, tree2) { - var patches = []; - generate(tree1, tree2, patches, []); - return patches; -} -exports.compare = compare; -function deepClone(obj) { - switch (typeof obj) { - case "object": - return JSON.parse(JSON.stringify(obj)); //Faster than ES5 clone - http://jsperf.com/deep-cloning-of-objects/5 - case "undefined": - return null; //this is how JSON.stringify behaves for array items - default: - return obj; //no need to clone primitives - } -} -function objectKeys(obj) { - if (Array.isArray(obj)) { - var keys = new Array(obj.length); - for (var k = 0; k < keys.length; k++) { - keys[k] = "" + k; - } - return keys; - } - if (Object.keys) { - return Object.keys(obj); - } - var keys = []; - for (var i in obj) { - if (obj.hasOwnProperty(i)) { - keys.push(i); - } - } - return keys; +function alloc(size) { + return new Array(size); } -; -// Dirty check if obj is different from mirror, generate patches and update mirror -function generate(mirror, obj, patches, path) { - var newKeys = objectKeys(obj); - var oldKeys = objectKeys(mirror); - var changed = false; - var deleted = false; - for (var t = oldKeys.length - 1; t >= 0; t--) { - var key = oldKeys[t]; - var oldVal = mirror[key]; - if (obj.hasOwnProperty(key) && !(obj[key] === undefined && oldVal !== undefined && Array.isArray(obj) === false)) { - var newVal = obj[key]; - if (typeof oldVal == "object" && oldVal != null && typeof newVal == "object" && newVal != null) { - generate(oldVal, newVal, patches, path.concat(key)); - } - else { - if (oldVal !== newVal) { - changed = true; - patches.push({ operation: "replace", path: path.concat(key), value: deepClone(newVal) }); - } - } - } - else { - patches.push({ operation: "remove", path: path.concat(key) }); - deleted = true; // property has been deleted - } - } - if (!deleted && newKeys.length == oldKeys.length) { - return; - } - for (var t = 0; t < newKeys.length; t++) { - var key = newKeys[t]; - if (!mirror.hasOwnProperty(key) && obj[key] !== undefined) { - patches.push({ operation: "add", path: path.concat(key), value: deepClone(obj[key]) }); - } - } + +/** + * @param value {Array|ArrayBuffer|Buffer|String} + * @returns {Array} + */ + +function from(value) { + if (!Bufferish.isBuffer(value) && Bufferish.isView(value)) { + // TypedArray to Uint8Array + value = Bufferish.Uint8Array.from(value); + } else if (Bufferish.isArrayBuffer(value)) { + // ArrayBuffer to Uint8Array + value = new Uint8Array(value); + } else if (typeof value === "string") { + // String to Array + return Bufferish.from.call(exports, value); + } else if (typeof value === "number") { + throw new TypeError('"value" argument must not be a number'); + } + + // Array-like to Array + return Array.prototype.slice.call(value); } /***/ }), -/* 34 */ +/* 33 */ /***/ (function(module, exports, __webpack_require__) { -"use strict"; - -var DeltaContainer_1 = __webpack_require__(32); -exports.DeltaContainer = DeltaContainer_1.DeltaContainer; +// bufferish-buffer.js +var Bufferish = __webpack_require__(0); +var Buffer = Bufferish.global; -/***/ }), -/* 35 */ -/***/ (function(module, exports) { - -// Fossil SCM delta compression algorithm -// ====================================== -// -// Format: -// http://www.fossil-scm.org/index.html/doc/tip/www/delta_format.wiki -// -// Algorithm: -// http://www.fossil-scm.org/index.html/doc/tip/www/delta_encoder_algorithm.wiki -// -// Original implementation: -// http://www.fossil-scm.org/index.html/artifact/d1b0598adcd650b3551f63b17dfc864e73775c3d -// -// LICENSE -// ------- -// -// Copyright 2014 Dmitry Chestnykh (JavaScript port) -// Copyright 2007 D. Richard Hipp (original C version) -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or -// without modification, are permitted provided that the -// following conditions are met: -// -// 1. Redistributions of source code must retain the above -// copyright notice, this list of conditions and the -// following disclaimer. -// -// 2. Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the -// following disclaimer in the documentation and/or other -// materials provided with the distribution. -// -// THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS -// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE -// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, -// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// The views and conclusions contained in the software and documentation -// are those of the authors and contributors and should not be interpreted -// as representing official policies, either expressed or implied, of anybody -// else. -// -(function(root, factory) { - if (typeof module !== 'undefined' && module.exports) module.exports = factory(); - else root.fossilDelta = factory(); -})(this, function() { -'use strict'; +var exports = module.exports = Bufferish.hasBuffer ? alloc(0) : []; -var fossilDelta = {}; +exports.alloc = Bufferish.hasBuffer && Buffer.alloc || alloc; +exports.concat = Bufferish.concat; +exports.from = from; -// Hash window width in bytes. Must be a power of two. -var NHASH = 16; +/** + * @param size {Number} + * @returns {Buffer|Uint8Array|Array} + */ -function RollingHash() { - this.a = 0; // hash (16-bit unsigned) - this.b = 0; // values (16-bit unsigned) - this.i = 0; // start of the hash window (16-bit unsigned) - this.z = new Array(NHASH); // the values that have been hashed. +function alloc(size) { + return new Buffer(size); } -// Initialize the rolling hash using the first NHASH bytes of -// z at the given position. -RollingHash.prototype.init = function(z, pos) { - var a = 0, b = 0, i, x; - for(i = 0; i < NHASH; i++){ - x = z[pos+i]; - a = (a + x) & 0xffff; - b = (b + (NHASH-i)*x) & 0xffff; - this.z[i] = x; +/** + * @param value {Array|ArrayBuffer|Buffer|String} + * @returns {Buffer} + */ + +function from(value) { + if (!Bufferish.isBuffer(value) && Bufferish.isView(value)) { + // TypedArray to Uint8Array + value = Bufferish.Uint8Array.from(value); + } else if (Bufferish.isArrayBuffer(value)) { + // ArrayBuffer to Uint8Array + value = new Uint8Array(value); + } else if (typeof value === "string") { + // String to Buffer + return Bufferish.from.call(exports, value); + } else if (typeof value === "number") { + throw new TypeError('"value" argument must not be a number'); } - this.a = a & 0xffff; - this.b = b & 0xffff; - this.i = 0; -}; -// Advance the rolling hash by a single byte "c". -RollingHash.prototype.next = function(c) { - var old = this.z[this.i]; - this.z[this.i] = c; - this.i = (this.i+1)&(NHASH-1); - this.a = (this.a - old + c) & 0xffff; - this.b = (this.b - NHASH*old + this.a) & 0xffff; -}; + // Array-like to Buffer + if (Buffer.from && Buffer.from.length !== 1) { + return Buffer.from(value); // node v6+ + } else { + return new Buffer(value); // node v4 + } +} -// Return a 32-bit hash value. -RollingHash.prototype.value = function() { - return ((this.a & 0xffff) | (this.b & 0xffff)<<16)>>>0; -}; -var zDigits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~". - split('').map(function (x) { return x.charCodeAt(0); }); +/***/ }), +/* 34 */ +/***/ (function(module, exports, __webpack_require__) { -var zValue = [ - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, - -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, - 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, 36, - -1, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, - 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, -1, -1, -1, 63, -1 -]; +// bufferish-uint8array.js -// Reader reads bytes, chars, ints from array. -function Reader(array) { - this.a = array; // source array - this.pos = 0; // current position in array -} +var Bufferish = __webpack_require__(0); -Reader.prototype.haveBytes = function() { - return this.pos < this.a.length; -}; +var exports = module.exports = Bufferish.hasArrayBuffer ? alloc(0) : []; -Reader.prototype.getByte = function() { - var b = this.a[this.pos]; - this.pos++; - if (this.pos > this.a.length) throw new RangeError('out of bounds'); - return b; -}; +exports.alloc = alloc; +exports.concat = Bufferish.concat; +exports.from = from; -Reader.prototype.getChar = function() { - return String.fromCharCode(this.getByte()); -}; +/** + * @param size {Number} + * @returns {Buffer|Uint8Array|Array} + */ - // Read base64-encoded unsigned integer. -Reader.prototype.getInt = function(){ - var v = 0, c; - while(this.haveBytes() && (c = zValue[0x7f & this.getByte()]) >= 0) { - v = (v<<6) + c; - } - this.pos--; - return v >>> 0; -}; +function alloc(size) { + return new Uint8Array(size); +} +/** + * @param value {Array|ArrayBuffer|Buffer|String} + * @returns {Uint8Array} + */ -// Write writes an array. -function Writer() { - this.a = []; -} +function from(value) { + if (Bufferish.isView(value)) { + // TypedArray to ArrayBuffer + var byteOffset = value.byteOffset; + var byteLength = value.byteLength; + value = value.buffer; + if (value.byteLength !== byteLength) { + if (value.slice) { + value = value.slice(byteOffset, byteOffset + byteLength); + } else { + // Android 4.1 does not have ArrayBuffer.prototype.slice + value = new Uint8Array(value); + if (value.byteLength !== byteLength) { + // TypedArray to ArrayBuffer to Uint8Array to Array + value = Array.prototype.slice.call(value, byteOffset, byteOffset + byteLength); + } + } + } + } else if (typeof value === "string") { + // String to Uint8Array + return Bufferish.from.call(exports, value); + } else if (typeof value === "number") { + throw new TypeError('"value" argument must not be a number'); + } -Writer.prototype.toArray = function() { - return this.a; -}; + return new Uint8Array(value); +} -Writer.prototype.putByte = function(b) { - this.a.push(b & 0xff); -}; -// Write an ASCII character (s is a one-char string). -Writer.prototype.putChar = function(s) { - this.putByte(s.charCodeAt(0)); -}; +/***/ }), +/* 35 */ +/***/ (function(module, exports) { -// Write a base64 unsigned integer. -Writer.prototype.putInt = function(v){ - var i, j, zBuf = []; - if (v === 0) { - this.putChar('0'); - return; - } - for (i = 0; v > 0; i++, v >>>= 6) - zBuf.push(zDigits[v&0x3f]); - for (j = i-1; j >= 0; j--) - this.putByte(zBuf[j]); -}; +// buffer-lite.js -// Copy from array at start to end. -Writer.prototype.putArray = function(a, start, end) { - for (var i = start; i < end; i++) this.a.push(a[i]); -}; +var MAXBUFLEN = 8192; -// Return the number digits in the base64 representation of a positive integer. -function digitCount(v){ - var i, x; - for (i = 1, x = 64; v >= x; i++, x <<= 6){ /* nothing */ } - return i; -} +exports.copy = copy; +exports.toString = toString; +exports.write = write; -// Return a 32-bit checksum of the array. -function checksum(arr) { - var sum0 = 0, sum1 = 0, sum2 = 0, sum3 = 0, - z = 0, N = arr.length; - //TODO measure if this unrolling is helpful. - while (N >= 16) { - sum0 = sum0 + arr[z+0] | 0; - sum1 = sum1 + arr[z+1] | 0; - sum2 = sum2 + arr[z+2] | 0; - sum3 = sum3 + arr[z+3] | 0; +/** + * Buffer.prototype.write() + * + * @param string {String} + * @param [offset] {Number} + * @returns {Number} + */ - sum0 = sum0 + arr[z+4] | 0; - sum1 = sum1 + arr[z+5] | 0; - sum2 = sum2 + arr[z+6] | 0; - sum3 = sum3 + arr[z+7] | 0; +function write(string, offset) { + var buffer = this; + var index = offset || (offset |= 0); + var length = string.length; + var chr = 0; + var i = 0; + while (i < length) { + chr = string.charCodeAt(i++); - sum0 = sum0 + arr[z+8] | 0; - sum1 = sum1 + arr[z+9] | 0; - sum2 = sum2 + arr[z+10] | 0; - sum3 = sum3 + arr[z+11] | 0; + if (chr < 128) { + buffer[index++] = chr; + } else if (chr < 0x800) { + // 2 bytes + buffer[index++] = 0xC0 | (chr >>> 6); + buffer[index++] = 0x80 | (chr & 0x3F); + } else if (chr < 0xD800 || chr > 0xDFFF) { + // 3 bytes + buffer[index++] = 0xE0 | (chr >>> 12); + buffer[index++] = 0x80 | ((chr >>> 6) & 0x3F); + buffer[index++] = 0x80 | (chr & 0x3F); + } else { + // 4 bytes - surrogate pair + chr = (((chr - 0xD800) << 10) | (string.charCodeAt(i++) - 0xDC00)) + 0x10000; + buffer[index++] = 0xF0 | (chr >>> 18); + buffer[index++] = 0x80 | ((chr >>> 12) & 0x3F); + buffer[index++] = 0x80 | ((chr >>> 6) & 0x3F); + buffer[index++] = 0x80 | (chr & 0x3F); + } + } + return index - offset; +} - sum0 = sum0 + arr[z+12] | 0; - sum1 = sum1 + arr[z+13] | 0; - sum2 = sum2 + arr[z+14] | 0; - sum3 = sum3 + arr[z+15] | 0; +/** + * Buffer.prototype.toString() + * + * @param [encoding] {String} ignored + * @param [start] {Number} + * @param [end] {Number} + * @returns {String} + */ - z += 16; - N -= 16; - } - while (N >= 4) { - sum0 = sum0 + arr[z+0] | 0; - sum1 = sum1 + arr[z+1] | 0; - sum2 = sum2 + arr[z+2] | 0; - sum3 = sum3 + arr[z+3] | 0; - z += 4; - N -= 4; - } - sum3 = (((sum3 + (sum2 << 8) | 0) + (sum1 << 16) | 0) + (sum0 << 24) | 0); - /* jshint -W086 */ - switch (N) { - case 3: sum3 = sum3 + (arr[z+2] << 8) | 0; /* falls through */ - case 2: sum3 = sum3 + (arr[z+1] << 16) | 0; /* falls through */ - case 1: sum3 = sum3 + (arr[z+0] << 24) | 0; /* falls through */ +function toString(encoding, start, end) { + var buffer = this; + var index = start|0; + if (!end) end = buffer.length; + var string = ''; + var chr = 0; + + while (index < end) { + chr = buffer[index++]; + if (chr < 128) { + string += String.fromCharCode(chr); + continue; + } + + if ((chr & 0xE0) === 0xC0) { + // 2 bytes + chr = (chr & 0x1F) << 6 | + (buffer[index++] & 0x3F); + + } else if ((chr & 0xF0) === 0xE0) { + // 3 bytes + chr = (chr & 0x0F) << 12 | + (buffer[index++] & 0x3F) << 6 | + (buffer[index++] & 0x3F); + + } else if ((chr & 0xF8) === 0xF0) { + // 4 bytes + chr = (chr & 0x07) << 18 | + (buffer[index++] & 0x3F) << 12 | + (buffer[index++] & 0x3F) << 6 | + (buffer[index++] & 0x3F); + } + + if (chr >= 0x010000) { + // A surrogate pair + chr -= 0x010000; + + string += String.fromCharCode((chr >>> 10) + 0xD800, (chr & 0x3FF) + 0xDC00); + } else { + string += String.fromCharCode(chr); + } } - return sum3 >>> 0; + + return string; } -// Create a new delta from src to out. -fossilDelta.create = function(src, out) { - var zDelta = new Writer(); - var lenOut = out.length; - var lenSrc = src.length; - var i, lastRead = -1; +/** + * Buffer.prototype.copy() + * + * @param target {Buffer} + * @param [targetStart] {Number} + * @param [start] {Number} + * @param [end] {Number} + * @returns {number} + */ - zDelta.putInt(lenOut); - zDelta.putChar('\n'); +function copy(target, targetStart, start, end) { + var i; + if (!start) start = 0; + if (!end && end !== 0) end = this.length; + if (!targetStart) targetStart = 0; + var len = end - start; - // If the source is very small, it means that we have no - // chance of ever doing a copy command. Just output a single - // literal segment for the entire target and exit. - if (lenSrc <= NHASH) { - zDelta.putInt(lenOut); - zDelta.putChar(':'); - zDelta.putArray(out, 0, lenOut); - zDelta.putInt(checksum(out)); - zDelta.putChar(';'); - return zDelta.toArray(); + if (target === this && start < targetStart && targetStart < end) { + // descending + for (i = len - 1; i >= 0; i--) { + target[i + targetStart] = this[i + start]; + } + } else { + // ascending + for (i = 0; i < len; i++) { + target[i + targetStart] = this[i + start]; + } } - // Compute the hash table used to locate matching sections in the source. - var nHash = Math.ceil(lenSrc / NHASH); - var collide = new Array(nHash); - var landmark = new Array(nHash); - for (i = 0; i < collide.length; i++) collide[i] = -1; - for (i = 0; i < landmark.length; i++) landmark[i] = -1; - var hv, h = new RollingHash(); - for (i = 0; i < lenSrc-NHASH; i += NHASH) { - h.init(src, i); - hv = h.value() % nHash; - collide[i/NHASH] = landmark[hv]; - landmark[hv] = i/NHASH; - } + return len; +} - var base = 0; - var iSrc, iBlock, bestCnt, bestOfst, bestLitsz; - while (base+NHASH= 0 && (limit--)>0 ) { - // - // The hash window has identified a potential match against - // landmark block iBlock. But we need to investigate further. - // - // Look for a region in zOut that matches zSrc. Anchor the search - // at zSrc[iSrc] and zOut[base+i]. Do not include anything prior to - // zOut[base] or after zOut[outLen] nor anything after zSrc[srcLen]. - // - // Set cnt equal to the length of the match and set ofst so that - // zSrc[ofst] is the first element of the match. litsz is the number - // of characters between zOut[base] and the beginning of the match. - // sz will be the overhead (in bytes) needed to encode the copy - // command. Only generate copy command if the overhead of the - // copy command is less than the amount of literal text to be copied. - // - var cnt, ofst, litsz; - var j, k, x, y; - var sz; - // Beginning at iSrc, match forwards as far as we can. - // j counts the number of characters that match. - iSrc = iBlock*NHASH; - for (j = 0, x = iSrc, y = base+i; x < lenSrc && y < lenOut; j++, x++, y++) { - if (src[x] !== out[y]) break; - } - j--; +/***/ }), +/* 36 */ +/***/ (function(module, exports, __webpack_require__) { - // Beginning at iSrc-1, match backwards as far as we can. - // k counts the number of characters that match. - for (k = 1; k < iSrc && k <= i; k++) { - if (src[iSrc-k] !== out[base+i-k]) break; - } - k--; +// ext-packer.js - // Compute the offset and size of the matching region. - ofst = iSrc-k; - cnt = j+k+1; - litsz = i-k; // Number of bytes of literal text before the copy - // sz will hold the number of bytes needed to encode the "insert" - // command and the copy command, not counting the "insert" text. - sz = digitCount(i-k)+digitCount(cnt)+digitCount(ofst)+3; - if (cnt >= sz && cnt > bestCnt) { - // Remember this match only if it is the best so far and it - // does not increase the file size. - bestCnt = cnt; - bestOfst = iSrc-k; - bestLitsz = litsz; - } +exports.setExtPackers = setExtPackers; - // Check the next matching block - iBlock = collide[iBlock]; - } +var Bufferish = __webpack_require__(0); +var Buffer = Bufferish.global; +var packTypedArray = Bufferish.Uint8Array.from; +var _encode; - // We have a copy command that does not cause the delta to be larger - // than a literal insert. So add the copy command to the delta. - if (bestCnt > 0) { - if (bestLitsz > 0) { - // Add an insert command before the copy. - zDelta.putInt(bestLitsz); - zDelta.putChar(':'); - zDelta.putArray(out, base, base+bestLitsz); - base += bestLitsz; - } - base += bestCnt; - zDelta.putInt(bestCnt); - zDelta.putChar('@'); - zDelta.putInt(bestOfst); - zDelta.putChar(','); - if (bestOfst + bestCnt -1 > lastRead) { - lastRead = bestOfst + bestCnt - 1; - } - bestCnt = 0; - break; - } +var ERROR_COLUMNS = {name: 1, message: 1, stack: 1, columnNumber: 1, fileName: 1, lineNumber: 1}; - // If we reach this point, it means no match is found so far - if (base+i+NHASH >= lenOut){ - // We have reached the end and have not found any - // matches. Do an "insert" for everything that does not match - zDelta.putInt(lenOut-base); - zDelta.putChar(':'); - zDelta.putArray(out, base, base+lenOut-base); - base = lenOut; - break; - } +function setExtPackers(codec) { + codec.addExtPacker(0x0E, Error, [packError, encode]); + codec.addExtPacker(0x01, EvalError, [packError, encode]); + codec.addExtPacker(0x02, RangeError, [packError, encode]); + codec.addExtPacker(0x03, ReferenceError, [packError, encode]); + codec.addExtPacker(0x04, SyntaxError, [packError, encode]); + codec.addExtPacker(0x05, TypeError, [packError, encode]); + codec.addExtPacker(0x06, URIError, [packError, encode]); - // Advance the hash by one character. Keep looking for a match. - h.next(out[base+i+NHASH]); - i++; - } - } - // Output a final "insert" record to get all the text at the end of - // the file that does not match anything in the source. - if(base < lenOut) { - zDelta.putInt(lenOut-base); - zDelta.putChar(':'); - zDelta.putArray(out, base, base+lenOut-base); - } - // Output the final checksum record. - zDelta.putInt(checksum(out)); - zDelta.putChar(';'); - return zDelta.toArray(); -}; + codec.addExtPacker(0x0A, RegExp, [packRegExp, encode]); + codec.addExtPacker(0x0B, Boolean, [packValueOf, encode]); + codec.addExtPacker(0x0C, String, [packValueOf, encode]); + codec.addExtPacker(0x0D, Date, [Number, encode]); + codec.addExtPacker(0x0F, Number, [packValueOf, encode]); -// Return the size (in bytes) of the output from applying a delta. -fossilDelta.outputSize = function(delta){ - var zDelta = new Reader(delta); - var size = zDelta.getInt(); - if (zDelta.getChar() !== '\n') - throw new Error('size integer not terminated by \'\\n\''); - return size; -}; + if ("undefined" !== typeof Uint8Array) { + codec.addExtPacker(0x11, Int8Array, packTypedArray); + codec.addExtPacker(0x12, Uint8Array, packTypedArray); + codec.addExtPacker(0x13, Int16Array, packTypedArray); + codec.addExtPacker(0x14, Uint16Array, packTypedArray); + codec.addExtPacker(0x15, Int32Array, packTypedArray); + codec.addExtPacker(0x16, Uint32Array, packTypedArray); + codec.addExtPacker(0x17, Float32Array, packTypedArray); -// Apply a delta. -fossilDelta.apply = function(src, delta) { - var limit, total = 0; - var zDelta = new Reader(delta); - var lenSrc = src.length; - var lenDelta = delta.length; + // PhantomJS/1.9.7 doesn't have Float64Array + if ("undefined" !== typeof Float64Array) { + codec.addExtPacker(0x18, Float64Array, packTypedArray); + } - limit = zDelta.getInt(); - if (zDelta.getChar() !== '\n') - throw new Error('size integer not terminated by \'\\n\''); - var zOut = new Writer(); - while(zDelta.haveBytes()) { - var cnt, ofst; - cnt = zDelta.getInt(); + // IE10 doesn't have Uint8ClampedArray + if ("undefined" !== typeof Uint8ClampedArray) { + codec.addExtPacker(0x19, Uint8ClampedArray, packTypedArray); + } - switch (zDelta.getChar()) { - case '@': - ofst = zDelta.getInt(); - if (zDelta.haveBytes() && zDelta.getChar() !== ',') - throw new Error('copy command not terminated by \',\''); - total += cnt; - if (total > limit) - throw new Error('copy exceeds output file size'); - if (ofst+cnt > lenSrc) - throw new Error('copy extends past end of input'); - zOut.putArray(src, ofst, ofst+cnt); - break; + codec.addExtPacker(0x1A, ArrayBuffer, packTypedArray); + codec.addExtPacker(0x1D, DataView, packTypedArray); + } - case ':': - total += cnt; - if (total > limit) - throw new Error('insert command gives an output larger than predicted'); - if (cnt > lenDelta) - throw new Error('insert count exceeds size of delta'); - zOut.putArray(zDelta.a, zDelta.pos, zDelta.pos+cnt); - zDelta.pos += cnt; - break; + if (Bufferish.hasBuffer) { + codec.addExtPacker(0x1B, Buffer, Bufferish.from); + } +} - case ';': - var out = zOut.toArray(); - if (cnt !== checksum(out)) - throw new Error('bad checksum'); - if (total !== limit) - throw new Error('generated size does not match predicted size'); - return out; +function encode(input) { + if (!_encode) _encode = __webpack_require__(13).encode; // lazy load + return _encode(input); +} - default: - throw new Error('unknown delta operator'); - } - } - throw new Error('unterminated delta'); -}; +function packValueOf(value) { + return (value).valueOf(); +} -return fossilDelta; +function packRegExp(value) { + value = RegExp.prototype.toString.call(value).split("/"); + value.shift(); + var out = [value.pop()]; + out.unshift(value.join("/")); + return out; +} -}); +function packError(value) { + var out = {}; + for (var key in ERROR_COLUMNS) { + out[key] = value[key]; + } + return out; +} /***/ }), -/* 36 */ +/* 37 */ /***/ (function(module, exports, __webpack_require__) { -/* WEBPACK VAR INJECTION */(function(Buffer) {/* globals Buffer */ +// write-type.js -module.exports = - c(("undefined" !== typeof Buffer) && Buffer) || - c(this.Buffer) || - c(("undefined" !== typeof window) && window.Buffer) || - this.Buffer; +var IS_ARRAY = __webpack_require__(1); +var Int64Buffer = __webpack_require__(9); +var Uint64BE = Int64Buffer.Uint64BE; +var Int64BE = Int64Buffer.Int64BE; -function c(B) { - return B && B.isBuffer && B; -} -/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(22).Buffer)) +var Bufferish = __webpack_require__(0); +var BufferProto = __webpack_require__(8); +var WriteToken = __webpack_require__(38); +var uint8 = __webpack_require__(16).uint8; +var ExtBuffer = __webpack_require__(6).ExtBuffer; -/***/ }), -/* 37 */ -/***/ (function(module, exports) { +var HAS_UINT8ARRAY = ("undefined" !== typeof Uint8Array); +var HAS_MAP = ("undefined" !== typeof Map); -// buffer-lite.js +var extmap = []; +extmap[1] = 0xd4; +extmap[2] = 0xd5; +extmap[4] = 0xd6; +extmap[8] = 0xd7; +extmap[16] = 0xd8; -var MAXBUFLEN = 8192; +exports.getWriteType = getWriteType; -exports.copy = copy; -exports.toString = toString; -exports.write = write; +function getWriteType(options) { + var token = WriteToken.getWriteToken(options); + var useraw = options && options.useraw; + var binarraybuffer = HAS_UINT8ARRAY && options && options.binarraybuffer; + var isBuffer = binarraybuffer ? Bufferish.isArrayBuffer : Bufferish.isBuffer; + var bin = binarraybuffer ? bin_arraybuffer : bin_buffer; + var usemap = HAS_MAP && options && options.usemap; + var map = usemap ? map_to_map : obj_to_map; -/** - * Buffer.prototype.write() - * - * @param string {String} - * @param [offset] {Number} - * @returns {Number} - */ + var writeType = { + "boolean": bool, + "function": nil, + "number": number, + "object": (useraw ? object_raw : object), + "string": _string(useraw ? raw_head_size : str_head_size), + "symbol": nil, + "undefined": nil + }; -function write(string, offset) { - var buffer = this; - var index = offset || (offset |= 0); - var length = string.length; - var chr = 0; - var i = 0; - while (i < length) { - chr = string.charCodeAt(i++); + return writeType; - if (chr < 128) { - buffer[index++] = chr; - } else if (chr < 0x800) { - // 2 bytes - buffer[index++] = 0xC0 | (chr >>> 6); - buffer[index++] = 0x80 | (chr & 0x3F); - } else if (chr < 0xD800 || chr > 0xDFFF) { - // 3 bytes - buffer[index++] = 0xE0 | (chr >>> 12); - buffer[index++] = 0x80 | ((chr >>> 6) & 0x3F); - buffer[index++] = 0x80 | (chr & 0x3F); - } else { - // 4 bytes - surrogate pair - chr = (((chr - 0xD800) << 10) | (string.charCodeAt(i++) - 0xDC00)) + 0x10000; - buffer[index++] = 0xF0 | (chr >>> 18); - buffer[index++] = 0x80 | ((chr >>> 12) & 0x3F); - buffer[index++] = 0x80 | ((chr >>> 6) & 0x3F); - buffer[index++] = 0x80 | (chr & 0x3F); - } + // false -- 0xc2 + // true -- 0xc3 + function bool(encoder, value) { + var type = value ? 0xc3 : 0xc2; + token[type](encoder, value); } - return index - offset; -} -/** - * Buffer.prototype.toString() - * - * @param [encoding] {String} ignored - * @param [start] {Number} - * @param [end] {Number} - * @returns {String} - */ - -function toString(encoding, start, end) { - var buffer = this; - var index = start|0; - if (!end) end = buffer.length; - var string = ''; - var chr = 0; - - while (index < end) { - chr = buffer[index++]; - if (chr < 128) { - string += String.fromCharCode(chr); - continue; - } - - if ((chr & 0xE0) === 0xC0) { - // 2 bytes - chr = (chr & 0x1F) << 6 | - (buffer[index++] & 0x3F); - - } else if ((chr & 0xF0) === 0xE0) { - // 3 bytes - chr = (chr & 0x0F) << 12 | - (buffer[index++] & 0x3F) << 6 | - (buffer[index++] & 0x3F); - - } else if ((chr & 0xF8) === 0xF0) { - // 4 bytes - chr = (chr & 0x07) << 18 | - (buffer[index++] & 0x3F) << 12 | - (buffer[index++] & 0x3F) << 6 | - (buffer[index++] & 0x3F); - } - - if (chr >= 0x010000) { - // A surrogate pair - chr -= 0x010000; - - string += String.fromCharCode((chr >>> 10) + 0xD800, (chr & 0x3FF) + 0xDC00); + function number(encoder, value) { + var ivalue = value | 0; + var type; + if (value !== ivalue) { + // float 64 -- 0xcb + type = 0xcb; + token[type](encoder, value); + return; + } else if (-0x20 <= ivalue && ivalue <= 0x7F) { + // positive fixint -- 0x00 - 0x7f + // negative fixint -- 0xe0 - 0xff + type = ivalue & 0xFF; + } else if (0 <= ivalue) { + // uint 8 -- 0xcc + // uint 16 -- 0xcd + // uint 32 -- 0xce + type = (ivalue <= 0xFF) ? 0xcc : (ivalue <= 0xFFFF) ? 0xcd : 0xce; } else { - string += String.fromCharCode(chr); + // int 8 -- 0xd0 + // int 16 -- 0xd1 + // int 32 -- 0xd2 + type = (-0x80 <= ivalue) ? 0xd0 : (-0x8000 <= ivalue) ? 0xd1 : 0xd2; } + token[type](encoder, ivalue); } - return string; -} - -/** - * Buffer.prototype.copy() - * - * @param target {Buffer} - * @param [targetStart] {Number} - * @param [start] {Number} - * @param [end] {Number} - * @returns {number} - */ - -function copy(target, targetStart, start, end) { - var i; - if (!start) start = 0; - if (!end && end !== 0) end = this.length; - if (!targetStart) targetStart = 0; - var len = end - start; + // uint 64 -- 0xcf + function uint64(encoder, value) { + var type = 0xcf; + token[type](encoder, value.toArray()); + } - if (target === this && start < targetStart && targetStart < end) { - // descending - for (i = len - 1; i >= 0; i--) { - target[i + targetStart] = this[i + start]; - } - } else { - // ascending - for (i = 0; i < len; i++) { - target[i + targetStart] = this[i + start]; - } + // int 64 -- 0xd3 + function int64(encoder, value) { + var type = 0xd3; + token[type](encoder, value.toArray()); } - return len; -} + // str 8 -- 0xd9 + // str 16 -- 0xda + // str 32 -- 0xdb + // fixstr -- 0xa0 - 0xbf + function str_head_size(length) { + return (length < 32) ? 1 : (length <= 0xFF) ? 2 : (length <= 0xFFFF) ? 3 : 5; + } + // raw 16 -- 0xda + // raw 32 -- 0xdb + // fixraw -- 0xa0 - 0xbf + function raw_head_size(length) { + return (length < 32) ? 1 : (length <= 0xFFFF) ? 3 : 5; + } -/***/ }), -/* 38 */ -/***/ (function(module, exports, __webpack_require__) { + function _string(head_size) { + return string; -// bufferish-array.js + function string(encoder, value) { + // prepare buffer + var length = value.length; + var maxsize = 5 + length * 3; + encoder.offset = encoder.reserve(maxsize); + var buffer = encoder.buffer; -var Bufferish = __webpack_require__(0); + // expected header size + var expected = head_size(length); -var exports = module.exports = alloc(0); + // expected start point + var start = encoder.offset + expected; -exports.alloc = alloc; -exports.concat = Bufferish.concat; -exports.from = from; + // write string + length = BufferProto.write.call(buffer, value, start); -/** - * @param size {Number} - * @returns {Buffer|Uint8Array|Array} - */ + // actual header size + var actual = head_size(length); -function alloc(size) { - return new Array(size); -} + // move content when needed + if (expected !== actual) { + var targetStart = start + actual - expected; + var end = start + length; + BufferProto.copy.call(buffer, buffer, targetStart, start, end); + } -/** - * @param value {Array|ArrayBuffer|Buffer|String} - * @returns {Array} - */ + // write header + var type = (actual === 1) ? (0xa0 + length) : (actual <= 3) ? (0xd7 + actual) : 0xdb; + token[type](encoder, length); -function from(value) { - if (!Bufferish.isBuffer(value) && Bufferish.isView(value)) { - // TypedArray to Uint8Array - value = Bufferish.Uint8Array.from(value); - } else if (Bufferish.isArrayBuffer(value)) { - // ArrayBuffer to Uint8Array - value = new Uint8Array(value); - } else if (typeof value === "string") { - // String to Array - return Bufferish.from.call(exports, value); - } else if (typeof value === "number") { - throw new TypeError('"value" argument must not be a number'); + // move cursor + encoder.offset += length; + } } - // Array-like to Array - return Array.prototype.slice.call(value); -} + function object(encoder, value) { + // null + if (value === null) return nil(encoder, value); + // Buffer + if (isBuffer(value)) return bin(encoder, value); -/***/ }), -/* 39 */ -/***/ (function(module, exports, __webpack_require__) { + // Array + if (IS_ARRAY(value)) return array(encoder, value); -// bufferish-buffer.js + // int64-buffer objects + if (Uint64BE.isUint64BE(value)) return uint64(encoder, value); + if (Int64BE.isInt64BE(value)) return int64(encoder, value); -var Bufferish = __webpack_require__(0); -var Buffer = Bufferish.global; + // ext formats + var packer = encoder.codec.getExtPacker(value); + if (packer) value = packer(value); + if (value instanceof ExtBuffer) return ext(encoder, value); -var exports = module.exports = Bufferish.hasBuffer ? alloc(0) : []; + // plain old Objects or Map + map(encoder, value); + } -exports.alloc = Bufferish.hasBuffer && Buffer.alloc || alloc; -exports.concat = Bufferish.concat; -exports.from = from; + function object_raw(encoder, value) { + // Buffer + if (isBuffer(value)) return raw(encoder, value); -/** - * @param size {Number} - * @returns {Buffer|Uint8Array|Array} - */ + // others + object(encoder, value); + } -function alloc(size) { - return new Buffer(size); -} + // nil -- 0xc0 + function nil(encoder, value) { + var type = 0xc0; + token[type](encoder, value); + } -/** - * @param value {Array|ArrayBuffer|Buffer|String} - * @returns {Buffer} - */ + // fixarray -- 0x90 - 0x9f + // array 16 -- 0xdc + // array 32 -- 0xdd + function array(encoder, value) { + var length = value.length; + var type = (length < 16) ? (0x90 + length) : (length <= 0xFFFF) ? 0xdc : 0xdd; + token[type](encoder, length); -function from(value) { - if (!Bufferish.isBuffer(value) && Bufferish.isView(value)) { - // TypedArray to Uint8Array - value = Bufferish.Uint8Array.from(value); - } else if (Bufferish.isArrayBuffer(value)) { - // ArrayBuffer to Uint8Array - value = new Uint8Array(value); - } else if (typeof value === "string") { - // String to Buffer - return Bufferish.from.call(exports, value); - } else if (typeof value === "number") { - throw new TypeError('"value" argument must not be a number'); + var encode = encoder.codec.encode; + for (var i = 0; i < length; i++) { + encode(encoder, value[i]); + } } - // Array-like to Buffer - if (Buffer.from && Buffer.from.length !== 1) { - return Buffer.from(value); // node v6+ - } else { - return new Buffer(value); // node v4 + // bin 8 -- 0xc4 + // bin 16 -- 0xc5 + // bin 32 -- 0xc6 + function bin_buffer(encoder, value) { + var length = value.length; + var type = (length < 0xFF) ? 0xc4 : (length <= 0xFFFF) ? 0xc5 : 0xc6; + token[type](encoder, length); + encoder.send(value); } -} - - -/***/ }), -/* 40 */ -/***/ (function(module, exports, __webpack_require__) { - -// bufferish-uint8array.js -var Bufferish = __webpack_require__(0); + function bin_arraybuffer(encoder, value) { + bin_buffer(encoder, new Uint8Array(value)); + } -var exports = module.exports = Bufferish.hasArrayBuffer ? alloc(0) : []; + // fixext 1 -- 0xd4 + // fixext 2 -- 0xd5 + // fixext 4 -- 0xd6 + // fixext 8 -- 0xd7 + // fixext 16 -- 0xd8 + // ext 8 -- 0xc7 + // ext 16 -- 0xc8 + // ext 32 -- 0xc9 + function ext(encoder, value) { + var buffer = value.buffer; + var length = buffer.length; + var type = extmap[length] || ((length < 0xFF) ? 0xc7 : (length <= 0xFFFF) ? 0xc8 : 0xc9); + token[type](encoder, length); + uint8[value.type](encoder); + encoder.send(buffer); + } -exports.alloc = alloc; -exports.concat = Bufferish.concat; -exports.from = from; + // fixmap -- 0x80 - 0x8f + // map 16 -- 0xde + // map 32 -- 0xdf + function obj_to_map(encoder, value) { + var keys = Object.keys(value); + var length = keys.length; + var type = (length < 16) ? (0x80 + length) : (length <= 0xFFFF) ? 0xde : 0xdf; + token[type](encoder, length); -/** - * @param size {Number} - * @returns {Buffer|Uint8Array|Array} - */ + var encode = encoder.codec.encode; + keys.forEach(function(key) { + encode(encoder, key); + encode(encoder, value[key]); + }); + } -function alloc(size) { - return new Uint8Array(size); -} + // fixmap -- 0x80 - 0x8f + // map 16 -- 0xde + // map 32 -- 0xdf + function map_to_map(encoder, value) { + if (!(value instanceof Map)) return obj_to_map(encoder, value); -/** - * @param value {Array|ArrayBuffer|Buffer|String} - * @returns {Uint8Array} - */ + var length = value.size; + var type = (length < 16) ? (0x80 + length) : (length <= 0xFFFF) ? 0xde : 0xdf; + token[type](encoder, length); -function from(value) { - if (Bufferish.isView(value)) { - // TypedArray to ArrayBuffer - var byteOffset = value.byteOffset; - var byteLength = value.byteLength; - value = value.buffer; - if (value.byteLength !== byteLength) { - if (value.slice) { - value = value.slice(byteOffset, byteOffset + byteLength); - } else { - // Android 4.1 does not have ArrayBuffer.prototype.slice - value = new Uint8Array(value); - if (value.byteLength !== byteLength) { - // TypedArray to ArrayBuffer to Uint8Array to Array - value = Array.prototype.slice.call(value, byteOffset, byteOffset + byteLength); - } - } - } - } else if (typeof value === "string") { - // String to Uint8Array - return Bufferish.from.call(exports, value); - } else if (typeof value === "number") { - throw new TypeError('"value" argument must not be a number'); + var encode = encoder.codec.encode; + value.forEach(function(val, key, m) { + encode(encoder, key); + encode(encoder, val); + }); } - return new Uint8Array(value); + // raw 16 -- 0xda + // raw 32 -- 0xdb + // fixraw -- 0xa0 - 0xbf + function raw(encoder, value) { + var length = value.length; + var type = (length < 32) ? (0xa0 + length) : (length <= 0xFFFF) ? 0xda : 0xdb; + token[type](encoder, length); + encoder.send(value); + } } /***/ }), -/* 41 */ +/* 38 */ /***/ (function(module, exports, __webpack_require__) { -// codec.js - -// load both interfaces -__webpack_require__(10); -__webpack_require__(11); - -// @public -// msgpack.codec.preset +// write-token.js -exports.codec = { - preset: __webpack_require__(2).preset -}; +var ieee754 = __webpack_require__(7); +var Int64Buffer = __webpack_require__(9); +var Uint64BE = Int64Buffer.Uint64BE; +var Int64BE = Int64Buffer.Int64BE; +var uint8 = __webpack_require__(16).uint8; +var Bufferish = __webpack_require__(0); +var Buffer = Bufferish.global; +var IS_BUFFER_SHIM = Bufferish.hasBuffer && ("TYPED_ARRAY_SUPPORT" in Buffer); +var NO_TYPED_ARRAY = IS_BUFFER_SHIM && !Buffer.TYPED_ARRAY_SUPPORT; +var Buffer_prototype = Bufferish.hasBuffer && Buffer.prototype || {}; -/***/ }), -/* 42 */ -/***/ (function(module, exports, __webpack_require__) { +exports.getWriteToken = getWriteToken; -// decoder.js +function getWriteToken(options) { + if (options && options.uint8array) { + return init_uint8array(); + } else if (NO_TYPED_ARRAY || (Bufferish.hasBuffer && options && options.safe)) { + return init_safe(); + } else { + return init_token(); + } +} -exports.Decoder = Decoder; +function init_uint8array() { + var token = init_token(); -var EventLite = __webpack_require__(14); -var DecodeBuffer = __webpack_require__(15).DecodeBuffer; + // float 32 -- 0xca + // float 64 -- 0xcb + token[0xca] = writeN(0xca, 4, writeFloatBE); + token[0xcb] = writeN(0xcb, 8, writeDoubleBE); -function Decoder(options) { - if (!(this instanceof Decoder)) return new Decoder(options); - DecodeBuffer.call(this, options); + return token; } -Decoder.prototype = new DecodeBuffer(); +// Node.js and browsers with TypedArray -EventLite.mixin(Decoder.prototype); +function init_token() { + // (immediate values) + // positive fixint -- 0x00 - 0x7f + // nil -- 0xc0 + // false -- 0xc2 + // true -- 0xc3 + // negative fixint -- 0xe0 - 0xff + var token = uint8.slice(); -Decoder.prototype.decode = function(chunk) { - if (arguments.length) this.write(chunk); - this.flush(); -}; + // bin 8 -- 0xc4 + // bin 16 -- 0xc5 + // bin 32 -- 0xc6 + token[0xc4] = write1(0xc4); + token[0xc5] = write2(0xc5); + token[0xc6] = write4(0xc6); -Decoder.prototype.push = function(chunk) { - this.emit("data", chunk); -}; + // ext 8 -- 0xc7 + // ext 16 -- 0xc8 + // ext 32 -- 0xc9 + token[0xc7] = write1(0xc7); + token[0xc8] = write2(0xc8); + token[0xc9] = write4(0xc9); -Decoder.prototype.end = function(chunk) { - this.decode(chunk); - this.emit("end"); -}; + // float 32 -- 0xca + // float 64 -- 0xcb + token[0xca] = writeN(0xca, 4, (Buffer_prototype.writeFloatBE || writeFloatBE), true); + token[0xcb] = writeN(0xcb, 8, (Buffer_prototype.writeDoubleBE || writeDoubleBE), true); + // uint 8 -- 0xcc + // uint 16 -- 0xcd + // uint 32 -- 0xce + // uint 64 -- 0xcf + token[0xcc] = write1(0xcc); + token[0xcd] = write2(0xcd); + token[0xce] = write4(0xce); + token[0xcf] = writeN(0xcf, 8, writeUInt64BE); -/***/ }), -/* 43 */ -/***/ (function(module, exports, __webpack_require__) { + // int 8 -- 0xd0 + // int 16 -- 0xd1 + // int 32 -- 0xd2 + // int 64 -- 0xd3 + token[0xd0] = write1(0xd0); + token[0xd1] = write2(0xd1); + token[0xd2] = write4(0xd2); + token[0xd3] = writeN(0xd3, 8, writeInt64BE); -// encoder.js + // str 8 -- 0xd9 + // str 16 -- 0xda + // str 32 -- 0xdb + token[0xd9] = write1(0xd9); + token[0xda] = write2(0xda); + token[0xdb] = write4(0xdb); -exports.Encoder = Encoder; + // array 16 -- 0xdc + // array 32 -- 0xdd + token[0xdc] = write2(0xdc); + token[0xdd] = write4(0xdd); -var EventLite = __webpack_require__(14); -var EncodeBuffer = __webpack_require__(17).EncodeBuffer; + // map 16 -- 0xde + // map 32 -- 0xdf + token[0xde] = write2(0xde); + token[0xdf] = write4(0xdf); -function Encoder(options) { - if (!(this instanceof Encoder)) return new Encoder(options); - EncodeBuffer.call(this, options); + return token; } -Encoder.prototype = new EncodeBuffer(); - -EventLite.mixin(Encoder.prototype); +// safe mode: for old browsers and who needs asserts -Encoder.prototype.encode = function(chunk) { - this.write(chunk); - this.emit("data", this.read()); -}; - -Encoder.prototype.end = function(chunk) { - if (arguments.length) this.encode(chunk); - this.flush(); - this.emit("end"); -}; +function init_safe() { + // (immediate values) + // positive fixint -- 0x00 - 0x7f + // nil -- 0xc0 + // false -- 0xc2 + // true -- 0xc3 + // negative fixint -- 0xe0 - 0xff + var token = uint8.slice(); + // bin 8 -- 0xc4 + // bin 16 -- 0xc5 + // bin 32 -- 0xc6 + token[0xc4] = writeN(0xc4, 1, Buffer.prototype.writeUInt8); + token[0xc5] = writeN(0xc5, 2, Buffer.prototype.writeUInt16BE); + token[0xc6] = writeN(0xc6, 4, Buffer.prototype.writeUInt32BE); -/***/ }), -/* 44 */ -/***/ (function(module, exports, __webpack_require__) { + // ext 8 -- 0xc7 + // ext 16 -- 0xc8 + // ext 32 -- 0xc9 + token[0xc7] = writeN(0xc7, 1, Buffer.prototype.writeUInt8); + token[0xc8] = writeN(0xc8, 2, Buffer.prototype.writeUInt16BE); + token[0xc9] = writeN(0xc9, 4, Buffer.prototype.writeUInt32BE); -// ext-packer.js + // float 32 -- 0xca + // float 64 -- 0xcb + token[0xca] = writeN(0xca, 4, Buffer.prototype.writeFloatBE); + token[0xcb] = writeN(0xcb, 8, Buffer.prototype.writeDoubleBE); -exports.setExtPackers = setExtPackers; + // uint 8 -- 0xcc + // uint 16 -- 0xcd + // uint 32 -- 0xce + // uint 64 -- 0xcf + token[0xcc] = writeN(0xcc, 1, Buffer.prototype.writeUInt8); + token[0xcd] = writeN(0xcd, 2, Buffer.prototype.writeUInt16BE); + token[0xce] = writeN(0xce, 4, Buffer.prototype.writeUInt32BE); + token[0xcf] = writeN(0xcf, 8, writeUInt64BE); -var Bufferish = __webpack_require__(0); -var Buffer = Bufferish.global; -var packTypedArray = Bufferish.Uint8Array.from; -var _encode; + // int 8 -- 0xd0 + // int 16 -- 0xd1 + // int 32 -- 0xd2 + // int 64 -- 0xd3 + token[0xd0] = writeN(0xd0, 1, Buffer.prototype.writeInt8); + token[0xd1] = writeN(0xd1, 2, Buffer.prototype.writeInt16BE); + token[0xd2] = writeN(0xd2, 4, Buffer.prototype.writeInt32BE); + token[0xd3] = writeN(0xd3, 8, writeInt64BE); -var ERROR_COLUMNS = {name: 1, message: 1, stack: 1, columnNumber: 1, fileName: 1, lineNumber: 1}; + // str 8 -- 0xd9 + // str 16 -- 0xda + // str 32 -- 0xdb + token[0xd9] = writeN(0xd9, 1, Buffer.prototype.writeUInt8); + token[0xda] = writeN(0xda, 2, Buffer.prototype.writeUInt16BE); + token[0xdb] = writeN(0xdb, 4, Buffer.prototype.writeUInt32BE); -function setExtPackers(codec) { - codec.addExtPacker(0x0E, Error, [packError, encode]); - codec.addExtPacker(0x01, EvalError, [packError, encode]); - codec.addExtPacker(0x02, RangeError, [packError, encode]); - codec.addExtPacker(0x03, ReferenceError, [packError, encode]); - codec.addExtPacker(0x04, SyntaxError, [packError, encode]); - codec.addExtPacker(0x05, TypeError, [packError, encode]); - codec.addExtPacker(0x06, URIError, [packError, encode]); + // array 16 -- 0xdc + // array 32 -- 0xdd + token[0xdc] = writeN(0xdc, 2, Buffer.prototype.writeUInt16BE); + token[0xdd] = writeN(0xdd, 4, Buffer.prototype.writeUInt32BE); - codec.addExtPacker(0x0A, RegExp, [packRegExp, encode]); - codec.addExtPacker(0x0B, Boolean, [packValueOf, encode]); - codec.addExtPacker(0x0C, String, [packValueOf, encode]); - codec.addExtPacker(0x0D, Date, [Number, encode]); - codec.addExtPacker(0x0F, Number, [packValueOf, encode]); + // map 16 -- 0xde + // map 32 -- 0xdf + token[0xde] = writeN(0xde, 2, Buffer.prototype.writeUInt16BE); + token[0xdf] = writeN(0xdf, 4, Buffer.prototype.writeUInt32BE); - if ("undefined" !== typeof Uint8Array) { - codec.addExtPacker(0x11, Int8Array, packTypedArray); - codec.addExtPacker(0x12, Uint8Array, packTypedArray); - codec.addExtPacker(0x13, Int16Array, packTypedArray); - codec.addExtPacker(0x14, Uint16Array, packTypedArray); - codec.addExtPacker(0x15, Int32Array, packTypedArray); - codec.addExtPacker(0x16, Uint32Array, packTypedArray); - codec.addExtPacker(0x17, Float32Array, packTypedArray); + return token; +} - // PhantomJS/1.9.7 doesn't have Float64Array - if ("undefined" !== typeof Float64Array) { - codec.addExtPacker(0x18, Float64Array, packTypedArray); - } +function write1(type) { + return function(encoder, value) { + var offset = encoder.reserve(2); + var buffer = encoder.buffer; + buffer[offset++] = type; + buffer[offset] = value; + }; +} - // IE10 doesn't have Uint8ClampedArray - if ("undefined" !== typeof Uint8ClampedArray) { - codec.addExtPacker(0x19, Uint8ClampedArray, packTypedArray); - } +function write2(type) { + return function(encoder, value) { + var offset = encoder.reserve(3); + var buffer = encoder.buffer; + buffer[offset++] = type; + buffer[offset++] = value >>> 8; + buffer[offset] = value; + }; +} - codec.addExtPacker(0x1A, ArrayBuffer, packTypedArray); - codec.addExtPacker(0x1D, DataView, packTypedArray); - } +function write4(type) { + return function(encoder, value) { + var offset = encoder.reserve(5); + var buffer = encoder.buffer; + buffer[offset++] = type; + buffer[offset++] = value >>> 24; + buffer[offset++] = value >>> 16; + buffer[offset++] = value >>> 8; + buffer[offset] = value; + }; +} - if (Bufferish.hasBuffer) { - codec.addExtPacker(0x1B, Buffer, Bufferish.from); - } +function writeN(type, len, method, noAssert) { + return function(encoder, value) { + var offset = encoder.reserve(len + 1); + encoder.buffer[offset++] = type; + method.call(encoder.buffer, value, offset, noAssert); + }; } -function encode(input) { - if (!_encode) _encode = __webpack_require__(18).encode; // lazy load - return _encode(input); +function writeUInt64BE(value, offset) { + new Uint64BE(this, offset, value); } -function packValueOf(value) { - return (value).valueOf(); +function writeInt64BE(value, offset) { + new Int64BE(this, offset, value); } -function packRegExp(value) { - value = RegExp.prototype.toString.call(value).split("/"); - value.shift(); - var out = [value.pop()]; - out.unshift(value.join("/")); - return out; +function writeFloatBE(value, offset) { + ieee754.write(this, value, offset, false, 23, 4); } -function packError(value) { - var out = {}; - for (var key in ERROR_COLUMNS) { - out[key] = value[key]; - } - return out; +function writeDoubleBE(value, offset) { + ieee754.write(this, value, offset, false, 52, 8); } /***/ }), -/* 45 */ +/* 39 */ /***/ (function(module, exports, __webpack_require__) { // ext-unpacker.js @@ -5810,7 +5495,7 @@ function setExtUnpackers(codec) { } function decode(input) { - if (!_decode) _decode = __webpack_require__(16).decode; // lazy load + if (!_decode) _decode = __webpack_require__(18).decode; // lazy load return _decode(input); } @@ -5840,20 +5525,7 @@ function unpackArrayBuffer(value) { /***/ }), -/* 46 */ -/***/ (function(module, exports, __webpack_require__) { - -// ext.js - -// load both interfaces -__webpack_require__(10); -__webpack_require__(11); - -exports.createCodec = __webpack_require__(2).createCodec; - - -/***/ }), -/* 47 */ +/* 40 */ /***/ (function(module, exports, __webpack_require__) { // read-token.js @@ -6020,518 +5692,108 @@ function fix(len, method) { /***/ }), -/* 48 */ +/* 41 */ /***/ (function(module, exports, __webpack_require__) { -// write-token.js - -var ieee754 = __webpack_require__(5); -var Int64Buffer = __webpack_require__(6); -var Uint64BE = Int64Buffer.Uint64BE; -var Int64BE = Int64Buffer.Int64BE; +// encoder.js -var uint8 = __webpack_require__(21).uint8; -var Bufferish = __webpack_require__(0); -var Buffer = Bufferish.global; -var IS_BUFFER_SHIM = Bufferish.hasBuffer && ("TYPED_ARRAY_SUPPORT" in Buffer); -var NO_TYPED_ARRAY = IS_BUFFER_SHIM && !Buffer.TYPED_ARRAY_SUPPORT; -var Buffer_prototype = Bufferish.hasBuffer && Buffer.prototype || {}; +exports.Encoder = Encoder; -exports.getWriteToken = getWriteToken; +var EventLite = __webpack_require__(21); +var EncodeBuffer = __webpack_require__(14).EncodeBuffer; -function getWriteToken(options) { - if (options && options.uint8array) { - return init_uint8array(); - } else if (NO_TYPED_ARRAY || (Bufferish.hasBuffer && options && options.safe)) { - return init_safe(); - } else { - return init_token(); - } +function Encoder(options) { + if (!(this instanceof Encoder)) return new Encoder(options); + EncodeBuffer.call(this, options); } -function init_uint8array() { - var token = init_token(); +Encoder.prototype = new EncodeBuffer(); - // float 32 -- 0xca - // float 64 -- 0xcb - token[0xca] = writeN(0xca, 4, writeFloatBE); - token[0xcb] = writeN(0xcb, 8, writeDoubleBE); +EventLite.mixin(Encoder.prototype); - return token; -} +Encoder.prototype.encode = function(chunk) { + this.write(chunk); + this.emit("data", this.read()); +}; -// Node.js and browsers with TypedArray +Encoder.prototype.end = function(chunk) { + if (arguments.length) this.encode(chunk); + this.flush(); + this.emit("end"); +}; -function init_token() { - // (immediate values) - // positive fixint -- 0x00 - 0x7f - // nil -- 0xc0 - // false -- 0xc2 - // true -- 0xc3 - // negative fixint -- 0xe0 - 0xff - var token = uint8.slice(); - // bin 8 -- 0xc4 - // bin 16 -- 0xc5 - // bin 32 -- 0xc6 - token[0xc4] = write1(0xc4); - token[0xc5] = write2(0xc5); - token[0xc6] = write4(0xc6); +/***/ }), +/* 42 */ +/***/ (function(module, exports, __webpack_require__) { - // ext 8 -- 0xc7 - // ext 16 -- 0xc8 - // ext 32 -- 0xc9 - token[0xc7] = write1(0xc7); - token[0xc8] = write2(0xc8); - token[0xc9] = write4(0xc9); +// decoder.js - // float 32 -- 0xca - // float 64 -- 0xcb - token[0xca] = writeN(0xca, 4, (Buffer_prototype.writeFloatBE || writeFloatBE), true); - token[0xcb] = writeN(0xcb, 8, (Buffer_prototype.writeDoubleBE || writeDoubleBE), true); +exports.Decoder = Decoder; - // uint 8 -- 0xcc - // uint 16 -- 0xcd - // uint 32 -- 0xce - // uint 64 -- 0xcf - token[0xcc] = write1(0xcc); - token[0xcd] = write2(0xcd); - token[0xce] = write4(0xce); - token[0xcf] = writeN(0xcf, 8, writeUInt64BE); +var EventLite = __webpack_require__(21); +var DecodeBuffer = __webpack_require__(19).DecodeBuffer; - // int 8 -- 0xd0 - // int 16 -- 0xd1 - // int 32 -- 0xd2 - // int 64 -- 0xd3 - token[0xd0] = write1(0xd0); - token[0xd1] = write2(0xd1); - token[0xd2] = write4(0xd2); - token[0xd3] = writeN(0xd3, 8, writeInt64BE); - - // str 8 -- 0xd9 - // str 16 -- 0xda - // str 32 -- 0xdb - token[0xd9] = write1(0xd9); - token[0xda] = write2(0xda); - token[0xdb] = write4(0xdb); - - // array 16 -- 0xdc - // array 32 -- 0xdd - token[0xdc] = write2(0xdc); - token[0xdd] = write4(0xdd); - - // map 16 -- 0xde - // map 32 -- 0xdf - token[0xde] = write2(0xde); - token[0xdf] = write4(0xdf); - - return token; -} - -// safe mode: for old browsers and who needs asserts - -function init_safe() { - // (immediate values) - // positive fixint -- 0x00 - 0x7f - // nil -- 0xc0 - // false -- 0xc2 - // true -- 0xc3 - // negative fixint -- 0xe0 - 0xff - var token = uint8.slice(); - - // bin 8 -- 0xc4 - // bin 16 -- 0xc5 - // bin 32 -- 0xc6 - token[0xc4] = writeN(0xc4, 1, Buffer.prototype.writeUInt8); - token[0xc5] = writeN(0xc5, 2, Buffer.prototype.writeUInt16BE); - token[0xc6] = writeN(0xc6, 4, Buffer.prototype.writeUInt32BE); - - // ext 8 -- 0xc7 - // ext 16 -- 0xc8 - // ext 32 -- 0xc9 - token[0xc7] = writeN(0xc7, 1, Buffer.prototype.writeUInt8); - token[0xc8] = writeN(0xc8, 2, Buffer.prototype.writeUInt16BE); - token[0xc9] = writeN(0xc9, 4, Buffer.prototype.writeUInt32BE); - - // float 32 -- 0xca - // float 64 -- 0xcb - token[0xca] = writeN(0xca, 4, Buffer.prototype.writeFloatBE); - token[0xcb] = writeN(0xcb, 8, Buffer.prototype.writeDoubleBE); - - // uint 8 -- 0xcc - // uint 16 -- 0xcd - // uint 32 -- 0xce - // uint 64 -- 0xcf - token[0xcc] = writeN(0xcc, 1, Buffer.prototype.writeUInt8); - token[0xcd] = writeN(0xcd, 2, Buffer.prototype.writeUInt16BE); - token[0xce] = writeN(0xce, 4, Buffer.prototype.writeUInt32BE); - token[0xcf] = writeN(0xcf, 8, writeUInt64BE); - - // int 8 -- 0xd0 - // int 16 -- 0xd1 - // int 32 -- 0xd2 - // int 64 -- 0xd3 - token[0xd0] = writeN(0xd0, 1, Buffer.prototype.writeInt8); - token[0xd1] = writeN(0xd1, 2, Buffer.prototype.writeInt16BE); - token[0xd2] = writeN(0xd2, 4, Buffer.prototype.writeInt32BE); - token[0xd3] = writeN(0xd3, 8, writeInt64BE); - - // str 8 -- 0xd9 - // str 16 -- 0xda - // str 32 -- 0xdb - token[0xd9] = writeN(0xd9, 1, Buffer.prototype.writeUInt8); - token[0xda] = writeN(0xda, 2, Buffer.prototype.writeUInt16BE); - token[0xdb] = writeN(0xdb, 4, Buffer.prototype.writeUInt32BE); - - // array 16 -- 0xdc - // array 32 -- 0xdd - token[0xdc] = writeN(0xdc, 2, Buffer.prototype.writeUInt16BE); - token[0xdd] = writeN(0xdd, 4, Buffer.prototype.writeUInt32BE); - - // map 16 -- 0xde - // map 32 -- 0xdf - token[0xde] = writeN(0xde, 2, Buffer.prototype.writeUInt16BE); - token[0xdf] = writeN(0xdf, 4, Buffer.prototype.writeUInt32BE); - - return token; -} - -function write1(type) { - return function(encoder, value) { - var offset = encoder.reserve(2); - var buffer = encoder.buffer; - buffer[offset++] = type; - buffer[offset] = value; - }; -} - -function write2(type) { - return function(encoder, value) { - var offset = encoder.reserve(3); - var buffer = encoder.buffer; - buffer[offset++] = type; - buffer[offset++] = value >>> 8; - buffer[offset] = value; - }; -} - -function write4(type) { - return function(encoder, value) { - var offset = encoder.reserve(5); - var buffer = encoder.buffer; - buffer[offset++] = type; - buffer[offset++] = value >>> 24; - buffer[offset++] = value >>> 16; - buffer[offset++] = value >>> 8; - buffer[offset] = value; - }; +function Decoder(options) { + if (!(this instanceof Decoder)) return new Decoder(options); + DecodeBuffer.call(this, options); } -function writeN(type, len, method, noAssert) { - return function(encoder, value) { - var offset = encoder.reserve(len + 1); - encoder.buffer[offset++] = type; - method.call(encoder.buffer, value, offset, noAssert); - }; -} +Decoder.prototype = new DecodeBuffer(); -function writeUInt64BE(value, offset) { - new Uint64BE(this, offset, value); -} +EventLite.mixin(Decoder.prototype); -function writeInt64BE(value, offset) { - new Int64BE(this, offset, value); -} +Decoder.prototype.decode = function(chunk) { + if (arguments.length) this.write(chunk); + this.flush(); +}; -function writeFloatBE(value, offset) { - ieee754.write(this, value, offset, false, 23, 4); -} +Decoder.prototype.push = function(chunk) { + this.emit("data", chunk); +}; -function writeDoubleBE(value, offset) { - ieee754.write(this, value, offset, false, 52, 8); -} +Decoder.prototype.end = function(chunk) { + this.decode(chunk); + this.emit("end"); +}; /***/ }), -/* 49 */ +/* 43 */ /***/ (function(module, exports, __webpack_require__) { -// write-type.js - -var IS_ARRAY = __webpack_require__(1); -var Int64Buffer = __webpack_require__(6); -var Uint64BE = Int64Buffer.Uint64BE; -var Int64BE = Int64Buffer.Int64BE; +// ext.js -var Bufferish = __webpack_require__(0); -var BufferProto = __webpack_require__(8); -var WriteToken = __webpack_require__(48); -var uint8 = __webpack_require__(21).uint8; -var ExtBuffer = __webpack_require__(9).ExtBuffer; +// load both interfaces +__webpack_require__(10); +__webpack_require__(5); -var HAS_UINT8ARRAY = ("undefined" !== typeof Uint8Array); -var HAS_MAP = ("undefined" !== typeof Map); +exports.createCodec = __webpack_require__(2).createCodec; -var extmap = []; -extmap[1] = 0xd4; -extmap[2] = 0xd5; -extmap[4] = 0xd6; -extmap[8] = 0xd7; -extmap[16] = 0xd8; -exports.getWriteType = getWriteType; +/***/ }), +/* 44 */ +/***/ (function(module, exports, __webpack_require__) { -function getWriteType(options) { - var token = WriteToken.getWriteToken(options); - var useraw = options && options.useraw; - var binarraybuffer = HAS_UINT8ARRAY && options && options.binarraybuffer; - var isBuffer = binarraybuffer ? Bufferish.isArrayBuffer : Bufferish.isBuffer; - var bin = binarraybuffer ? bin_arraybuffer : bin_buffer; - var usemap = HAS_MAP && options && options.usemap; - var map = usemap ? map_to_map : obj_to_map; +// codec.js - var writeType = { - "boolean": bool, - "function": nil, - "number": number, - "object": (useraw ? object_raw : object), - "string": _string(useraw ? raw_head_size : str_head_size), - "symbol": nil, - "undefined": nil - }; +// load both interfaces +__webpack_require__(10); +__webpack_require__(5); - return writeType; +// @public +// msgpack.codec.preset - // false -- 0xc2 - // true -- 0xc3 - function bool(encoder, value) { - var type = value ? 0xc3 : 0xc2; - token[type](encoder, value); - } +exports.codec = { + preset: __webpack_require__(2).preset +}; - function number(encoder, value) { - var ivalue = value | 0; - var type; - if (value !== ivalue) { - // float 64 -- 0xcb - type = 0xcb; - token[type](encoder, value); - return; - } else if (-0x20 <= ivalue && ivalue <= 0x7F) { - // positive fixint -- 0x00 - 0x7f - // negative fixint -- 0xe0 - 0xff - type = ivalue & 0xFF; - } else if (0 <= ivalue) { - // uint 8 -- 0xcc - // uint 16 -- 0xcd - // uint 32 -- 0xce - type = (ivalue <= 0xFF) ? 0xcc : (ivalue <= 0xFFFF) ? 0xcd : 0xce; - } else { - // int 8 -- 0xd0 - // int 16 -- 0xd1 - // int 32 -- 0xd2 - type = (-0x80 <= ivalue) ? 0xd0 : (-0x8000 <= ivalue) ? 0xd1 : 0xd2; - } - token[type](encoder, ivalue); - } - // uint 64 -- 0xcf - function uint64(encoder, value) { - var type = 0xcf; - token[type](encoder, value.toArray()); - } +/***/ }), +/* 45 */ +/***/ (function(module, exports, __webpack_require__) { - // int 64 -- 0xd3 - function int64(encoder, value) { - var type = 0xd3; - token[type](encoder, value.toArray()); - } - - // str 8 -- 0xd9 - // str 16 -- 0xda - // str 32 -- 0xdb - // fixstr -- 0xa0 - 0xbf - function str_head_size(length) { - return (length < 32) ? 1 : (length <= 0xFF) ? 2 : (length <= 0xFFFF) ? 3 : 5; - } - - // raw 16 -- 0xda - // raw 32 -- 0xdb - // fixraw -- 0xa0 - 0xbf - function raw_head_size(length) { - return (length < 32) ? 1 : (length <= 0xFFFF) ? 3 : 5; - } - - function _string(head_size) { - return string; - - function string(encoder, value) { - // prepare buffer - var length = value.length; - var maxsize = 5 + length * 3; - encoder.offset = encoder.reserve(maxsize); - var buffer = encoder.buffer; - - // expected header size - var expected = head_size(length); - - // expected start point - var start = encoder.offset + expected; - - // write string - length = BufferProto.write.call(buffer, value, start); - - // actual header size - var actual = head_size(length); - - // move content when needed - if (expected !== actual) { - var targetStart = start + actual - expected; - var end = start + length; - BufferProto.copy.call(buffer, buffer, targetStart, start, end); - } - - // write header - var type = (actual === 1) ? (0xa0 + length) : (actual <= 3) ? (0xd7 + actual) : 0xdb; - token[type](encoder, length); - - // move cursor - encoder.offset += length; - } - } - - function object(encoder, value) { - // null - if (value === null) return nil(encoder, value); - - // Buffer - if (isBuffer(value)) return bin(encoder, value); - - // Array - if (IS_ARRAY(value)) return array(encoder, value); - - // int64-buffer objects - if (Uint64BE.isUint64BE(value)) return uint64(encoder, value); - if (Int64BE.isInt64BE(value)) return int64(encoder, value); - - // ext formats - var packer = encoder.codec.getExtPacker(value); - if (packer) value = packer(value); - if (value instanceof ExtBuffer) return ext(encoder, value); - - // plain old Objects or Map - map(encoder, value); - } - - function object_raw(encoder, value) { - // Buffer - if (isBuffer(value)) return raw(encoder, value); - - // others - object(encoder, value); - } - - // nil -- 0xc0 - function nil(encoder, value) { - var type = 0xc0; - token[type](encoder, value); - } - - // fixarray -- 0x90 - 0x9f - // array 16 -- 0xdc - // array 32 -- 0xdd - function array(encoder, value) { - var length = value.length; - var type = (length < 16) ? (0x90 + length) : (length <= 0xFFFF) ? 0xdc : 0xdd; - token[type](encoder, length); - - var encode = encoder.codec.encode; - for (var i = 0; i < length; i++) { - encode(encoder, value[i]); - } - } - - // bin 8 -- 0xc4 - // bin 16 -- 0xc5 - // bin 32 -- 0xc6 - function bin_buffer(encoder, value) { - var length = value.length; - var type = (length < 0xFF) ? 0xc4 : (length <= 0xFFFF) ? 0xc5 : 0xc6; - token[type](encoder, length); - encoder.send(value); - } - - function bin_arraybuffer(encoder, value) { - bin_buffer(encoder, new Uint8Array(value)); - } - - // fixext 1 -- 0xd4 - // fixext 2 -- 0xd5 - // fixext 4 -- 0xd6 - // fixext 8 -- 0xd7 - // fixext 16 -- 0xd8 - // ext 8 -- 0xc7 - // ext 16 -- 0xc8 - // ext 32 -- 0xc9 - function ext(encoder, value) { - var buffer = value.buffer; - var length = buffer.length; - var type = extmap[length] || ((length < 0xFF) ? 0xc7 : (length <= 0xFFFF) ? 0xc8 : 0xc9); - token[type](encoder, length); - uint8[value.type](encoder); - encoder.send(buffer); - } - - // fixmap -- 0x80 - 0x8f - // map 16 -- 0xde - // map 32 -- 0xdf - function obj_to_map(encoder, value) { - var keys = Object.keys(value); - var length = keys.length; - var type = (length < 16) ? (0x80 + length) : (length <= 0xFFFF) ? 0xde : 0xdf; - token[type](encoder, length); - - var encode = encoder.codec.encode; - keys.forEach(function(key) { - encode(encoder, key); - encode(encoder, value[key]); - }); - } - - // fixmap -- 0x80 - 0x8f - // map 16 -- 0xde - // map 32 -- 0xdf - function map_to_map(encoder, value) { - if (!(value instanceof Map)) return obj_to_map(encoder, value); - - var length = value.size; - var type = (length < 16) ? (0x80 + length) : (length <= 0xFFFF) ? 0xde : 0xdf; - token[type](encoder, length); - - var encode = encoder.codec.encode; - value.forEach(function(val, key, m) { - encode(encoder, key); - encode(encoder, val); - }); - } - - // raw 16 -- 0xda - // raw 32 -- 0xdb - // fixraw -- 0xa0 - 0xbf - function raw(encoder, value) { - var length = value.length; - var type = (length < 32) ? (0xa0 + length) : (length <= 0xFFFF) ? 0xda : 0xdb; - token[type](encoder, length); - encoder.send(value); - } -} - - -/***/ }), -/* 50 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; +"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = Object.setPrototypeOf || @@ -6544,7 +5806,7 @@ var __extends = (this && this.__extends) || (function () { }; })(); Object.defineProperty(exports, "__esModule", { value: true }); -var PrioritySignal_1 = __webpack_require__(24); +var PrioritySignal_1 = __webpack_require__(23); /** * Allows the valueClasses to be set in MXML, e.g. * {[String, uint]} @@ -6669,7 +5931,7 @@ exports.DeluxeSignal = DeluxeSignal; //# sourceMappingURL=DeluxeSignal.js.map /***/ }), -/* 51 */ +/* 46 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -6677,12 +5939,69 @@ exports.DeluxeSignal = DeluxeSignal; Object.defineProperty(exports, "__esModule", { value: true }); /** * + * @see org.osflash.signals.events.IEvent + * Documentation for the event interface being maintained in IEvent to avoid duplication for now. */ -exports.IOnceSignal = Symbol("IOnceSignal"); -//# sourceMappingURL=IOnceSignal.js.map +var GenericEvent = (function () { + function GenericEvent(bubbles) { + if (bubbles === void 0) { bubbles = false; } + this._bubbles = bubbles; + } + Object.defineProperty(GenericEvent.prototype, "signal", { + /** @inheritDoc */ + get: function () { + return this._signal; + }, + set: function (value) { + this._signal = value; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(GenericEvent.prototype, "target", { + /** @inheritDoc */ + get: function () { + return this._target; + }, + set: function (value) { + this._target = value; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(GenericEvent.prototype, "currentTarget", { + /** @inheritDoc */ + get: function () { + return this._currentTarget; + }, + set: function (value) { + this._currentTarget = value; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(GenericEvent.prototype, "bubbles", { + /** @inheritDoc */ + get: function () { + return this._bubbles; + }, + set: function (value) { + this._bubbles = value; + }, + enumerable: true, + configurable: true + }); + /** @inheritDoc */ + GenericEvent.prototype.clone = function () { + return new GenericEvent(this._bubbles); + }; + return GenericEvent; +}()); +exports.GenericEvent = GenericEvent; +//# sourceMappingURL=GenericEvent.js.map /***/ }), -/* 52 */ +/* 47 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -6691,11 +6010,11 @@ Object.defineProperty(exports, "__esModule", { value: true }); /** * */ -exports.IPrioritySignal = Symbol("IPrioritySignal"); -//# sourceMappingURL=IPrioritySignal.js.map +exports.IOnceSignal = Symbol("IOnceSignal"); +//# sourceMappingURL=IOnceSignal.js.map /***/ }), -/* 53 */ +/* 48 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -6704,11 +6023,24 @@ Object.defineProperty(exports, "__esModule", { value: true }); /** * */ -exports.ISignal = Symbol("ISignal"); +exports.IPrioritySignal = Symbol("IPrioritySignal"); +//# sourceMappingURL=IPrioritySignal.js.map + +/***/ }), +/* 49 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + +Object.defineProperty(exports, "__esModule", { value: true }); +/** + * + */ +exports.ISignal = Symbol("ISignal"); //# sourceMappingURL=ISignal.js.map /***/ }), -/* 54 */ +/* 50 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -6725,7 +6057,7 @@ exports.ISlot = Symbol("ISlot"); //# sourceMappingURL=ISlot.js.map /***/ }), -/* 55 */ +/* 51 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -6868,132 +6200,767 @@ var MonoSignal = (function () { exports.MonoSignal = MonoSignal; //# sourceMappingURL=MonoSignal.js.map -/***/ }), -/* 56 */ -/***/ (function(module, exports, __webpack_require__) { +/***/ }), +/* 52 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + +var __extends = (this && this.__extends) || (function () { + var extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +Object.defineProperty(exports, "__esModule", { value: true }); +var OnceSignal_1 = __webpack_require__(11); +var Promise = (function (_super) { + __extends(Promise, _super); + function Promise() { + return _super !== null && _super.apply(this, arguments) || this; + } + /** @inheritDoc */ + /*override*/ + Promise.prototype.addOnce = function (listener) { + var slot = _super.prototype.addOnce.call(this, listener); + if (this.isDispatched) { + slot.execute(this.valueObjects); + slot.remove(); + } + return slot; + }; + /** + * @inheritDoc + * @throws flash.errors.IllegalOperationError IllegalOperationError: You cannot dispatch() a Promise more than once + */ + /*override*/ + Promise.prototype.dispatch = function () { + var valueObjects = []; + for (var _i = 0; _i < arguments.length; _i++) { + valueObjects[_i] = arguments[_i]; + } + if (this.isDispatched) { + throw new Error("You cannot dispatch() a Promise more than once"); + } + else { + this.isDispatched = true; + this.valueObjects = valueObjects; + _super.prototype.dispatch.apply(this, valueObjects); + } + }; + return Promise; +}(OnceSignal_1.OnceSignal)); +exports.Promise = Promise; +//# sourceMappingURL=Promise.js.map + +/***/ }), +/* 53 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + +var Clock = (function () { + function Clock(useInterval) { + if (useInterval === void 0) { useInterval = false; } + this.running = false; + this.now = (typeof (window) !== "undefined" && window.performance && window.performance.now && (window.performance.now).bind(window.performance)) || Date.now; + this.start(useInterval); + } + Clock.prototype.start = function (useInterval) { + if (useInterval === void 0) { useInterval = false; } + this.deltaTime = 0; + this.currentTime = this.now(); + this.elapsedTime = 0; + this.running = true; + if (useInterval) { + // auto set interval to 60 ticks per second + this._interval = setInterval(this.tick.bind(this), 1000 / 60); + } + }; + Clock.prototype.stop = function () { + this.running = false; + if (this._interval) { + clearInterval(this._interval); + } + }; + Clock.prototype.tick = function (newTime) { + if (newTime === void 0) { newTime = this.now(); } + this.deltaTime = newTime - this.currentTime; + this.currentTime = newTime; + this.elapsedTime += this.deltaTime; + }; + return Clock; +}()); +module.exports = Clock; + + +/***/ }), +/* 54 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + +var DeltaContainer_1 = __webpack_require__(55); +exports.DeltaContainer = DeltaContainer_1.DeltaContainer; + + +/***/ }), +/* 55 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + +var compare_1 = __webpack_require__(56); +var DeltaContainer = (function () { + function DeltaContainer(data) { + this.listeners = []; + this.matcherPlaceholders = { + ":id": /^([a-zA-Z0-9\-_]+)$/, + ":number": /^([0-9]+)$/, + ":string": /^(\w+)$/, + ":axis": /^([xyz])$/, + ":*": /(.*)/, + }; + this.data = data; + this.reset(); + } + DeltaContainer.prototype.set = function (newData) { + var patches = compare_1.compare(this.data, newData); + this.checkPatches(patches); + this.data = newData; + return patches; + }; + DeltaContainer.prototype.registerPlaceholder = function (placeholder, matcher) { + this.matcherPlaceholders[placeholder] = matcher; + }; + DeltaContainer.prototype.listen = function (segments, callback) { + var _this = this; + var rules; + if (typeof (segments) === "function") { + rules = []; + callback = segments; + } + else { + rules = segments.split("/"); + } + var listener = { + callback: callback, + rawRules: rules, + rules: rules.map(function (segment) { + if (typeof (segment) === "string") { + // replace placeholder matchers + return (segment.indexOf(":") === 0) + ? _this.matcherPlaceholders[segment] || _this.matcherPlaceholders[":*"] + : new RegExp("^" + segment + "$"); + } + else { + return segment; + } + }) + }; + if (rules.length === 0) { + this.defaultListener = listener; + } + else { + this.listeners.push(listener); + } + return listener; + }; + DeltaContainer.prototype.removeListener = function (listener) { + for (var i = this.listeners.length - 1; i >= 0; i--) { + if (this.listeners[i] === listener) { + this.listeners.splice(i, 1); + } + } + }; + DeltaContainer.prototype.removeAllListeners = function () { + this.reset(); + }; + DeltaContainer.prototype.checkPatches = function (patches) { + for (var i = patches.length - 1; i >= 0; i--) { + var matched = false; + for (var j = 0, len = this.listeners.length; j < len; j++) { + var listener = this.listeners[j]; + var pathVariables = this.getPathVariables(patches[i], listener); + if (pathVariables) { + listener.callback({ + path: pathVariables, + operation: patches[i].operation, + value: patches[i].value + }); + matched = true; + } + } + // check for fallback listener + if (!matched && this.defaultListener) { + this.defaultListener.callback(patches[i]); + } + } + }; + DeltaContainer.prototype.getPathVariables = function (patch, listener) { + // skip if rules count differ from patch + if (patch.path.length !== listener.rules.length) { + return false; + } + var path = {}; + for (var i = 0, len = listener.rules.length; i < len; i++) { + var matches = patch.path[i].match(listener.rules[i]); + if (!matches || matches.length === 0 || matches.length > 2) { + return false; + } + else if (listener.rawRules[i].substr(0, 1) === ":") { + path[listener.rawRules[i].substr(1)] = matches[1]; + } + } + return path; + }; + DeltaContainer.prototype.reset = function () { + this.listeners = []; + }; + return DeltaContainer; +}()); +exports.DeltaContainer = DeltaContainer; + + +/***/ }), +/* 56 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + +function compare(tree1, tree2) { + var patches = []; + generate(tree1, tree2, patches, []); + return patches; +} +exports.compare = compare; +function deepClone(obj) { + switch (typeof obj) { + case "object": + return JSON.parse(JSON.stringify(obj)); //Faster than ES5 clone - http://jsperf.com/deep-cloning-of-objects/5 + case "undefined": + return null; //this is how JSON.stringify behaves for array items + default: + return obj; //no need to clone primitives + } +} +function objectKeys(obj) { + if (Array.isArray(obj)) { + var keys = new Array(obj.length); + for (var k = 0; k < keys.length; k++) { + keys[k] = "" + k; + } + return keys; + } + if (Object.keys) { + return Object.keys(obj); + } + var keys = []; + for (var i in obj) { + if (obj.hasOwnProperty(i)) { + keys.push(i); + } + } + return keys; +} +; +// Dirty check if obj is different from mirror, generate patches and update mirror +function generate(mirror, obj, patches, path) { + var newKeys = objectKeys(obj); + var oldKeys = objectKeys(mirror); + var changed = false; + var deleted = false; + for (var t = oldKeys.length - 1; t >= 0; t--) { + var key = oldKeys[t]; + var oldVal = mirror[key]; + if (obj.hasOwnProperty(key) && !(obj[key] === undefined && oldVal !== undefined && Array.isArray(obj) === false)) { + var newVal = obj[key]; + if (typeof oldVal == "object" && oldVal != null && typeof newVal == "object" && newVal != null) { + generate(oldVal, newVal, patches, path.concat(key)); + } + else { + if (oldVal !== newVal) { + changed = true; + patches.push({ operation: "replace", path: path.concat(key), value: deepClone(newVal) }); + } + } + } + else { + patches.push({ operation: "remove", path: path.concat(key) }); + deleted = true; // property has been deleted + } + } + if (!deleted && newKeys.length == oldKeys.length) { + return; + } + for (var t = 0; t < newKeys.length; t++) { + var key = newKeys[t]; + if (!mirror.hasOwnProperty(key) && obj[key] !== undefined) { + patches.push({ operation: "add", path: path.concat(key), value: deepClone(obj[key]) }); + } + } +} + + +/***/ }), +/* 57 */ +/***/ (function(module, exports) { + +// Fossil SCM delta compression algorithm +// ====================================== +// +// Format: +// http://www.fossil-scm.org/index.html/doc/tip/www/delta_format.wiki +// +// Algorithm: +// http://www.fossil-scm.org/index.html/doc/tip/www/delta_encoder_algorithm.wiki +// +// Original implementation: +// http://www.fossil-scm.org/index.html/artifact/d1b0598adcd650b3551f63b17dfc864e73775c3d +// +// LICENSE +// ------- +// +// Copyright 2014 Dmitry Chestnykh (JavaScript port) +// Copyright 2007 D. Richard Hipp (original C version) +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or +// without modification, are permitted provided that the +// following conditions are met: +// +// 1. Redistributions of source code must retain the above +// copyright notice, this list of conditions and the +// following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the +// following disclaimer in the documentation and/or other +// materials provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS +// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, +// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// The views and conclusions contained in the software and documentation +// are those of the authors and contributors and should not be interpreted +// as representing official policies, either expressed or implied, of anybody +// else. +// +(function(root, factory) { + if (typeof module !== 'undefined' && module.exports) module.exports = factory(); + else root.fossilDelta = factory(); +})(this, function() { +'use strict'; + +var fossilDelta = {}; + +// Hash window width in bytes. Must be a power of two. +var NHASH = 16; + +function RollingHash() { + this.a = 0; // hash (16-bit unsigned) + this.b = 0; // values (16-bit unsigned) + this.i = 0; // start of the hash window (16-bit unsigned) + this.z = new Array(NHASH); // the values that have been hashed. +} + +// Initialize the rolling hash using the first NHASH bytes of +// z at the given position. +RollingHash.prototype.init = function(z, pos) { + var a = 0, b = 0, i, x; + for(i = 0; i < NHASH; i++){ + x = z[pos+i]; + a = (a + x) & 0xffff; + b = (b + (NHASH-i)*x) & 0xffff; + this.z[i] = x; + } + this.a = a & 0xffff; + this.b = b & 0xffff; + this.i = 0; +}; + +// Advance the rolling hash by a single byte "c". +RollingHash.prototype.next = function(c) { + var old = this.z[this.i]; + this.z[this.i] = c; + this.i = (this.i+1)&(NHASH-1); + this.a = (this.a - old + c) & 0xffff; + this.b = (this.b - NHASH*old + this.a) & 0xffff; +}; + +// Return a 32-bit hash value. +RollingHash.prototype.value = function() { + return ((this.a & 0xffff) | (this.b & 0xffff)<<16)>>>0; +}; + +var zDigits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~". + split('').map(function (x) { return x.charCodeAt(0); }); + +var zValue = [ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, + -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, + 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, 36, + -1, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, + 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, -1, -1, -1, 63, -1 +]; + +// Reader reads bytes, chars, ints from array. +function Reader(array) { + this.a = array; // source array + this.pos = 0; // current position in array +} + +Reader.prototype.haveBytes = function() { + return this.pos < this.a.length; +}; + +Reader.prototype.getByte = function() { + var b = this.a[this.pos]; + this.pos++; + if (this.pos > this.a.length) throw new RangeError('out of bounds'); + return b; +}; + +Reader.prototype.getChar = function() { + return String.fromCharCode(this.getByte()); +}; + + // Read base64-encoded unsigned integer. +Reader.prototype.getInt = function(){ + var v = 0, c; + while(this.haveBytes() && (c = zValue[0x7f & this.getByte()]) >= 0) { + v = (v<<6) + c; + } + this.pos--; + return v >>> 0; +}; + + +// Write writes an array. +function Writer() { + this.a = []; +} + +Writer.prototype.toArray = function() { + return this.a; +}; + +Writer.prototype.putByte = function(b) { + this.a.push(b & 0xff); +}; + +// Write an ASCII character (s is a one-char string). +Writer.prototype.putChar = function(s) { + this.putByte(s.charCodeAt(0)); +}; + +// Write a base64 unsigned integer. +Writer.prototype.putInt = function(v){ + var i, j, zBuf = []; + if (v === 0) { + this.putChar('0'); + return; + } + for (i = 0; v > 0; i++, v >>>= 6) + zBuf.push(zDigits[v&0x3f]); + for (j = i-1; j >= 0; j--) + this.putByte(zBuf[j]); +}; + +// Copy from array at start to end. +Writer.prototype.putArray = function(a, start, end) { + for (var i = start; i < end; i++) this.a.push(a[i]); +}; + +// Return the number digits in the base64 representation of a positive integer. +function digitCount(v){ + var i, x; + for (i = 1, x = 64; v >= x; i++, x <<= 6){ /* nothing */ } + return i; +} + +// Return a 32-bit checksum of the array. +function checksum(arr) { + var sum0 = 0, sum1 = 0, sum2 = 0, sum3 = 0, + z = 0, N = arr.length; + //TODO measure if this unrolling is helpful. + while (N >= 16) { + sum0 = sum0 + arr[z+0] | 0; + sum1 = sum1 + arr[z+1] | 0; + sum2 = sum2 + arr[z+2] | 0; + sum3 = sum3 + arr[z+3] | 0; + + sum0 = sum0 + arr[z+4] | 0; + sum1 = sum1 + arr[z+5] | 0; + sum2 = sum2 + arr[z+6] | 0; + sum3 = sum3 + arr[z+7] | 0; + + sum0 = sum0 + arr[z+8] | 0; + sum1 = sum1 + arr[z+9] | 0; + sum2 = sum2 + arr[z+10] | 0; + sum3 = sum3 + arr[z+11] | 0; + + sum0 = sum0 + arr[z+12] | 0; + sum1 = sum1 + arr[z+13] | 0; + sum2 = sum2 + arr[z+14] | 0; + sum3 = sum3 + arr[z+15] | 0; + + z += 16; + N -= 16; + } + while (N >= 4) { + sum0 = sum0 + arr[z+0] | 0; + sum1 = sum1 + arr[z+1] | 0; + sum2 = sum2 + arr[z+2] | 0; + sum3 = sum3 + arr[z+3] | 0; + z += 4; + N -= 4; + } + sum3 = (((sum3 + (sum2 << 8) | 0) + (sum1 << 16) | 0) + (sum0 << 24) | 0); + /* jshint -W086 */ + switch (N) { + case 3: sum3 = sum3 + (arr[z+2] << 8) | 0; /* falls through */ + case 2: sum3 = sum3 + (arr[z+1] << 16) | 0; /* falls through */ + case 1: sum3 = sum3 + (arr[z+0] << 24) | 0; /* falls through */ + } + return sum3 >>> 0; +} + +// Create a new delta from src to out. +fossilDelta.create = function(src, out) { + var zDelta = new Writer(); + var lenOut = out.length; + var lenSrc = src.length; + var i, lastRead = -1; + + zDelta.putInt(lenOut); + zDelta.putChar('\n'); + + // If the source is very small, it means that we have no + // chance of ever doing a copy command. Just output a single + // literal segment for the entire target and exit. + if (lenSrc <= NHASH) { + zDelta.putInt(lenOut); + zDelta.putChar(':'); + zDelta.putArray(out, 0, lenOut); + zDelta.putInt(checksum(out)); + zDelta.putChar(';'); + return zDelta.toArray(); + } + + // Compute the hash table used to locate matching sections in the source. + var nHash = Math.ceil(lenSrc / NHASH); + var collide = new Array(nHash); + var landmark = new Array(nHash); + for (i = 0; i < collide.length; i++) collide[i] = -1; + for (i = 0; i < landmark.length; i++) landmark[i] = -1; + var hv, h = new RollingHash(); + for (i = 0; i < lenSrc-NHASH; i += NHASH) { + h.init(src, i); + hv = h.value() % nHash; + collide[i/NHASH] = landmark[hv]; + landmark[hv] = i/NHASH; + } + + var base = 0; + var iSrc, iBlock, bestCnt, bestOfst, bestLitsz; + while (base+NHASH= 0 && (limit--)>0 ) { + // + // The hash window has identified a potential match against + // landmark block iBlock. But we need to investigate further. + // + // Look for a region in zOut that matches zSrc. Anchor the search + // at zSrc[iSrc] and zOut[base+i]. Do not include anything prior to + // zOut[base] or after zOut[outLen] nor anything after zSrc[srcLen]. + // + // Set cnt equal to the length of the match and set ofst so that + // zSrc[ofst] is the first element of the match. litsz is the number + // of characters between zOut[base] and the beginning of the match. + // sz will be the overhead (in bytes) needed to encode the copy + // command. Only generate copy command if the overhead of the + // copy command is less than the amount of literal text to be copied. + // + var cnt, ofst, litsz; + var j, k, x, y; + var sz; + + // Beginning at iSrc, match forwards as far as we can. + // j counts the number of characters that match. + iSrc = iBlock*NHASH; + for (j = 0, x = iSrc, y = base+i; x < lenSrc && y < lenOut; j++, x++, y++) { + if (src[x] !== out[y]) break; + } + j--; + + // Beginning at iSrc-1, match backwards as far as we can. + // k counts the number of characters that match. + for (k = 1; k < iSrc && k <= i; k++) { + if (src[iSrc-k] !== out[base+i-k]) break; + } + k--; + + // Compute the offset and size of the matching region. + ofst = iSrc-k; + cnt = j+k+1; + litsz = i-k; // Number of bytes of literal text before the copy + // sz will hold the number of bytes needed to encode the "insert" + // command and the copy command, not counting the "insert" text. + sz = digitCount(i-k)+digitCount(cnt)+digitCount(ofst)+3; + if (cnt >= sz && cnt > bestCnt) { + // Remember this match only if it is the best so far and it + // does not increase the file size. + bestCnt = cnt; + bestOfst = iSrc-k; + bestLitsz = litsz; + } + + // Check the next matching block + iBlock = collide[iBlock]; + } + + // We have a copy command that does not cause the delta to be larger + // than a literal insert. So add the copy command to the delta. + if (bestCnt > 0) { + if (bestLitsz > 0) { + // Add an insert command before the copy. + zDelta.putInt(bestLitsz); + zDelta.putChar(':'); + zDelta.putArray(out, base, base+bestLitsz); + base += bestLitsz; + } + base += bestCnt; + zDelta.putInt(bestCnt); + zDelta.putChar('@'); + zDelta.putInt(bestOfst); + zDelta.putChar(','); + if (bestOfst + bestCnt -1 > lastRead) { + lastRead = bestOfst + bestCnt - 1; + } + bestCnt = 0; + break; + } + + // If we reach this point, it means no match is found so far + if (base+i+NHASH >= lenOut){ + // We have reached the end and have not found any + // matches. Do an "insert" for everything that does not match + zDelta.putInt(lenOut-base); + zDelta.putChar(':'); + zDelta.putArray(out, base, base+lenOut-base); + base = lenOut; + break; + } + + // Advance the hash by one character. Keep looking for a match. + h.next(out[base+i+NHASH]); + i++; + } + } + // Output a final "insert" record to get all the text at the end of + // the file that does not match anything in the source. + if(base < lenOut) { + zDelta.putInt(lenOut-base); + zDelta.putChar(':'); + zDelta.putArray(out, base, base+lenOut-base); + } + // Output the final checksum record. + zDelta.putInt(checksum(out)); + zDelta.putChar(';'); + return zDelta.toArray(); +}; + +// Return the size (in bytes) of the output from applying a delta. +fossilDelta.outputSize = function(delta){ + var zDelta = new Reader(delta); + var size = zDelta.getInt(); + if (zDelta.getChar() !== '\n') + throw new Error('size integer not terminated by \'\\n\''); + return size; +}; + +// Apply a delta. +fossilDelta.apply = function(src, delta) { + var limit, total = 0; + var zDelta = new Reader(delta); + var lenSrc = src.length; + var lenDelta = delta.length; + + limit = zDelta.getInt(); + if (zDelta.getChar() !== '\n') + throw new Error('size integer not terminated by \'\\n\''); + var zOut = new Writer(); + while(zDelta.haveBytes()) { + var cnt, ofst; + cnt = zDelta.getInt(); + + switch (zDelta.getChar()) { + case '@': + ofst = zDelta.getInt(); + if (zDelta.haveBytes() && zDelta.getChar() !== ',') + throw new Error('copy command not terminated by \',\''); + total += cnt; + if (total > limit) + throw new Error('copy exceeds output file size'); + if (ofst+cnt > lenSrc) + throw new Error('copy extends past end of input'); + zOut.putArray(src, ofst, ofst+cnt); + break; + + case ':': + total += cnt; + if (total > limit) + throw new Error('insert command gives an output larger than predicted'); + if (cnt > lenDelta) + throw new Error('insert count exceeds size of delta'); + zOut.putArray(zDelta.a, zDelta.pos, zDelta.pos+cnt); + zDelta.pos += cnt; + break; -"use strict"; + case ';': + var out = zOut.toArray(); + if (cnt !== checksum(out)) + throw new Error('bad checksum'); + if (total !== limit) + throw new Error('generated size does not match predicted size'); + return out; -var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -var OnceSignal_1 = __webpack_require__(12); -var Promise = (function (_super) { - __extends(Promise, _super); - function Promise() { - return _super !== null && _super.apply(this, arguments) || this; + default: + throw new Error('unknown delta operator'); } - /** @inheritDoc */ - /*override*/ - Promise.prototype.addOnce = function (listener) { - var slot = _super.prototype.addOnce.call(this, listener); - if (this.isDispatched) { - slot.execute(this.valueObjects); - slot.remove(); - } - return slot; - }; - /** - * @inheritDoc - * @throws flash.errors.IllegalOperationError IllegalOperationError: You cannot dispatch() a Promise more than once - */ - /*override*/ - Promise.prototype.dispatch = function () { - var valueObjects = []; - for (var _i = 0; _i < arguments.length; _i++) { - valueObjects[_i] = arguments[_i]; - } - if (this.isDispatched) { - throw new Error("You cannot dispatch() a Promise more than once"); - } - else { - this.isDispatched = true; - this.valueObjects = valueObjects; - _super.prototype.dispatch.apply(this, valueObjects); - } - }; - return Promise; -}(OnceSignal_1.OnceSignal)); -exports.Promise = Promise; -//# sourceMappingURL=Promise.js.map + } + throw new Error('unterminated delta'); +}; -/***/ }), -/* 57 */ -/***/ (function(module, exports, __webpack_require__) { +return fossilDelta; -"use strict"; +}); -Object.defineProperty(exports, "__esModule", { value: true }); -/** - * - * @see org.osflash.signals.events.IEvent - * Documentation for the event interface being maintained in IEvent to avoid duplication for now. - */ -var GenericEvent = (function () { - function GenericEvent(bubbles) { - if (bubbles === void 0) { bubbles = false; } - this._bubbles = bubbles; - } - Object.defineProperty(GenericEvent.prototype, "signal", { - /** @inheritDoc */ - get: function () { - return this._signal; - }, - set: function (value) { - this._signal = value; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(GenericEvent.prototype, "target", { - /** @inheritDoc */ - get: function () { - return this._target; - }, - set: function (value) { - this._target = value; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(GenericEvent.prototype, "currentTarget", { - /** @inheritDoc */ - get: function () { - return this._currentTarget; - }, - set: function (value) { - this._currentTarget = value; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(GenericEvent.prototype, "bubbles", { - /** @inheritDoc */ - get: function () { - return this._bubbles; - }, - set: function (value) { - this._bubbles = value; - }, - enumerable: true, - configurable: true - }); - /** @inheritDoc */ - GenericEvent.prototype.clone = function () { - return new GenericEvent(this._bubbles); - }; - return GenericEvent; -}()); -exports.GenericEvent = GenericEvent; -//# sourceMappingURL=GenericEvent.js.map /***/ }), /* 58 */ @@ -7012,8 +6979,8 @@ var __extends = (this && this.__extends) || (function () { }; })(); Object.defineProperty(exports, "__esModule", { value: true }); -var websocket_1 = __webpack_require__(30); -var msgpack = __webpack_require__(7); +var websocket_1 = __webpack_require__(59); +var msgpack = __webpack_require__(4); var Connection = /** @class */ (function (_super) { __extends(Connection, _super); function Connection(url, query) { @@ -7053,43 +7020,95 @@ exports.Connection = Connection; /***/ (function(module, exports, __webpack_require__) { "use strict"; +Object.defineProperty(exports,"__esModule",{value:true});var _createClass=function(){function defineProperties(target,props){for(var i=0;i2&&arguments[2]!==undefined?arguments[2]:{};_classCallCheck(this,WebSocketClient);this.url=url;this.protocols=protocols;this.reconnectEnabled=true;this.listeners={};this.backoff=createBackoff(options.backoff||'exponential',options);this.backoff.onReady=this.onBackoffReady.bind(this);this.open();}_createClass(WebSocketClient,[{key:'open',value:function open(){var reconnect=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;this.isReconnect=reconnect;this.ws=new WebSocket(this.url,this.protocols);this.ws.onclose=this.onCloseCallback.bind(this);this.ws.onerror=this.onErrorCallback.bind(this);this.ws.onmessage=this.onMessageCallback.bind(this);this.ws.onopen=this.onOpenCallback.bind(this);}/** + * @ignore + */},{key:'onBackoffReady',value:function onBackoffReady(number,delay){// console.log("onBackoffReady", number + ' ' + delay + 'ms'); +this.open(true);}/** + * @ignore + */},{key:'onCloseCallback',value:function onCloseCallback(){if(!this.isReconnect&&this.listeners['onclose']){this.listeners['onclose'].apply(null,arguments);}if(this.reconnectEnabled){this.backoff.backoff();}}/** + * @ignore + */},{key:'onErrorCallback',value:function onErrorCallback(){if(this.listeners['onerror']){this.listeners['onerror'].apply(null,arguments);}}/** + * @ignore + */},{key:'onMessageCallback',value:function onMessageCallback(){if(this.listeners['onmessage']){this.listeners['onmessage'].apply(null,arguments);}}/** + * @ignore + */},{key:'onOpenCallback',value:function onOpenCallback(){if(this.listeners['onopen']){this.listeners['onopen'].apply(null,arguments);}if(this.isReconnect&&this.listeners['onreconnect']){this.listeners['onreconnect'].apply(null,arguments);}this.isReconnect=false;}/** + * The number of bytes of data that have been queued using calls to send() + * but not yet transmitted to the network. This value does not reset to zero + * when the connection is closed; if you keep calling send(), this will + * continue to climb. + * + * @type unsigned long + * @readonly + */},{key:'close',/** + * Closes the WebSocket connection or connection attempt, if any. If the + * connection is already CLOSED, this method does nothing. + * + * @param code A numeric value indicating the status code explaining why the connection is being closed. If this parameter is not specified, a default value of 1000 (indicating a normal "transaction complete" closure) is assumed. See the list of status codes on the CloseEvent page for permitted values. + * @param reason A human-readable string explaining why the connection is closing. This string must be no longer than 123 bytes of UTF-8 text (not characters). + * + * @return void + */value:function close(code,reason){if(typeof code=='undefined'){code=1000;}this.reconnectEnabled=false;this.ws.close(code,reason);}/** + * Transmits data to the server over the WebSocket connection. + * @param data DOMString|ArrayBuffer|Blob + * @return void + */},{key:'send',value:function send(data){this.ws.send(data);}/** + * An event listener to be called when the WebSocket connection's readyState changes to CLOSED. The listener receives a CloseEvent named "close". + * @param listener EventListener + */},{key:'bufferedAmount',get:function get(){return this.ws.bufferedAmount;}/** + * The current state of the connection; this is one of the Ready state constants. + * @type unsigned short + * @readonly + */},{key:'readyState',get:function get(){return this.ws.readyState;}/** + * A string indicating the type of binary data being transmitted by the + * connection. This should be either "blob" if DOM Blob objects are being + * used or "arraybuffer" if ArrayBuffer objects are being used. + * @type DOMString + */},{key:'binaryType',get:function get(){return this.ws.binaryType;},set:function set(binaryType){this.ws.binaryType=binaryType;}/** + * The extensions selected by the server. This is currently only the empty + * string or a list of extensions as negotiated by the connection. + * @type DOMString + */},{key:'extensions',get:function get(){return this.ws.extensions;},set:function set(extensions){this.ws.extensions=extensions;}/** + * A string indicating the name of the sub-protocol the server selected; + * this will be one of the strings specified in the protocols parameter when + * creating the WebSocket object. + * @type DOMString + */},{key:'protocol',get:function get(){return this.ws.protocol;},set:function set(protocol){this.ws.protocol=protocol;}},{key:'onclose',set:function set(listener){this.listeners['onclose']=listener;},get:function get(){return this.listeners['onclose'];}/** + * An event listener to be called when an error occurs. This is a simple event named "error". + * @param listener EventListener + */},{key:'onerror',set:function set(listener){this.listeners['onerror']=listener;},get:function get(){return this.listeners['onerror'];}/** + * An event listener to be called when a message is received from the server. The listener receives a MessageEvent named "message". + * @param listener EventListener + */},{key:'onmessage',set:function set(listener){this.listeners['onmessage']=listener;},get:function get(){return this.listeners['onmessage'];}/** + * An event listener to be called when the WebSocket connection's readyState changes to OPEN; this indicates that the connection is ready to send and receive data. The event is a simple one with the name "open". + * @param listener EventListener + */},{key:'onopen',set:function set(listener){this.listeners['onopen']=listener;},get:function get(){return this.listeners['onopen'];}/** + * @param listener EventListener + */},{key:'onreconnect',set:function set(listener){this.listeners['onreconnect']=listener;},get:function get(){return this.listeners['onreconnect'];}}]);return WebSocketClient;}();/** + * The connection is not yet open. + */WebSocketClient.CONNECTING=WebSocket.CONNECTING;/** + * The connection is open and ready to communicate. + */WebSocketClient.OPEN=WebSocket.OPEN;/** + * The connection is in the process of closing. + */WebSocketClient.CLOSING=WebSocket.CLOSING;/** + * The connection is closed or couldn't be opened. + */WebSocketClient.CLOSED=WebSocket.CLOSED;exports.default=WebSocketClient; -Object.defineProperty(exports, "__esModule", { value: true }); -var Client_1 = __webpack_require__(27); -exports.Client = Client_1.Client; -var Protocol_1 = __webpack_require__(4); -exports.Protocol = Protocol_1.Protocol; -var Room_1 = __webpack_require__(13); -exports.Room = Room_1.Room; +/***/ }), +/* 60 */ +/***/ (function(module, exports, __webpack_require__) { +"use strict"; +Object.defineProperty(exports,"__esModule",{value:true});exports.createBackoff=createBackoff;var backoff={exponential:function exponential(attempt,delay){return Math.floor(Math.random()*Math.pow(2,attempt)*delay);},fibonacci:function fibonacci(attempt,delay){var current=1;if(attempt>current){var prev=1,current=2;for(var index=2;index this.createConnection(id)); + } + } + + protected createConnection (colyseusid: string) { + this.id = colyseusid || ""; this.connection = new Connection(`${ this.hostname }/?colyseusid=${ this.id }`); this.connection.onmessage = this.onMessageCallback.bind(this); @@ -53,7 +71,7 @@ export class Client { let code = message[0]; if (code == Protocol.USER_ID) { - localStorage.setItem('colyseusid', message[1]); + storage.setItem('colyseusid', message[1]); this.id = message[1]; this.onOpen.dispatch(); diff --git a/tsconfig.json b/tsconfig.json index e52b017..0f08168 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { "target": "es5", "module": "commonjs", - "lib": ["dom", "es5"], + "lib": ["dom", "es6"], "allowSyntheticDefaultImports": true, "noImplicitAny": false, "sourceMap": false, diff --git a/webpack.config.js b/webpack.config.js index 03e176e..fa8b72e 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -22,6 +22,10 @@ module.exports = function(options) { ], }, + // hack: react-native is not used for the distribution build + externals: { + 'react-native': "ReactNative" + }, plugins: ( (options.production)