diff --git a/dist/pouchdb.replication-stream.js b/dist/pouchdb.replication-stream.js index fb57085..11eb437 100644 --- a/dist/pouchdb.replication-stream.js +++ b/dist/pouchdb.replication-stream.js @@ -1,8 +1,8 @@ -(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o MAX_LEN) { + throw new RangeError('size is too large'); + } + var enc = encoding; + var _fill = fill; + if (_fill === undefined) { + enc = undefined; + _fill = 0; + } + var buf = new Buffer(size); + if (typeof _fill === 'string') { + var fillBuf = new Buffer(_fill, enc); + var flen = fillBuf.length; + var i = -1; + while (++i < size) { + buf[i] = fillBuf[i % flen]; + } + } else { + buf.fill(_fill); + } + return buf; +} +exports.allocUnsafe = function allocUnsafe(size) { + if (typeof Buffer.allocUnsafe === 'function') { + return Buffer.allocUnsafe(size); + } + if (typeof size !== 'number') { + throw new TypeError('size must be a number'); + } + if (size > MAX_LEN) { + throw new RangeError('size is too large'); + } + return new Buffer(size); +} +exports.from = function from(value, encodingOrOffset, length) { + if (typeof Buffer.from === 'function' && (!global.Uint8Array || Uint8Array.from !== Buffer.from)) { + return Buffer.from(value, encodingOrOffset, length); + } + if (typeof value === 'number') { + throw new TypeError('"value" argument must not be a number'); + } + if (typeof value === 'string') { + return new Buffer(value, encodingOrOffset); + } + if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) { + var offset = encodingOrOffset; + if (arguments.length === 1) { + return new Buffer(value); + } + if (typeof offset === 'undefined') { + offset = 0; + } + var len = length; + if (typeof len === 'undefined') { + len = value.byteLength - offset; + } + if (offset >= value.byteLength) { + throw new RangeError('\'offset\' is out of bounds'); + } + if (len > value.byteLength - offset) { + throw new RangeError('\'length\' is out of bounds'); + } + return new Buffer(value.slice(offset, offset + len)); + } + if (Buffer.isBuffer(value)) { + var out = new Buffer(value.length); + value.copy(out, 0, 0, value.length); + return out; + } + if (value) { + if (Array.isArray(value) || (typeof ArrayBuffer !== 'undefined' && value.buffer instanceof ArrayBuffer) || 'length' in value) { + return new Buffer(value); + } + if (value.type === 'Buffer' && Array.isArray(value.data)) { + return new Buffer(value.data); + } + } + + throw new TypeError('First argument must be a string, Buffer, ' + 'ArrayBuffer, Array, or array-like object.'); +} +exports.allocUnsafeSlow = function allocUnsafeSlow(size) { + if (typeof Buffer.allocUnsafeSlow === 'function') { + return Buffer.allocUnsafeSlow(size); + } + if (typeof size !== 'number') { + throw new TypeError('size must be a number'); + } + if (size >= MAX_LEN) { + throw new RangeError('size is too large'); + } + return new SlowBuffer(size); +} + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"8":8}],8:[function(_dereq_,module,exports){ +(function (global){ /*! * The buffer module from node.js, for the browser. * @@ -407,9 +520,9 @@ var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; 'use strict' -var base64 = _dereq_('base64-js') -var ieee754 = _dereq_('ieee754') -var isArray = _dereq_('isarray') +var base64 = _dereq_(5) +var ieee754 = _dereq_(12) +var isArray = _dereq_(9) exports.Buffer = Buffer exports.SlowBuffer = SlowBuffer @@ -1947,14 +2060,14 @@ function blitBuffer (src, dst, offset, length) { } }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"base64-js":5,"ieee754":11,"isarray":8}],8:[function(_dereq_,module,exports){ +},{"12":12,"5":5,"9":9}],9:[function(_dereq_,module,exports){ var toString = {}.toString; module.exports = Array.isArray || function (arr) { return toString.call(arr) == '[object Array]'; }; -},{}],9:[function(_dereq_,module,exports){ +},{}],10:[function(_dereq_,module,exports){ (function (Buffer){ // Copyright Joyent, Inc. and other Node contributors. // @@ -2064,8 +2177,8 @@ function objectToString(o) { return Object.prototype.toString.call(o); } -}).call(this,{"isBuffer":_dereq_("../../is-buffer/index.js")}) -},{"../../is-buffer/index.js":14}],10:[function(_dereq_,module,exports){ +}).call(this,{"isBuffer":_dereq_(15)}) +},{"15":15}],11:[function(_dereq_,module,exports){ // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -2368,7 +2481,7 @@ function isUndefined(arg) { return arg === void 0; } -},{}],11:[function(_dereq_,module,exports){ +},{}],12:[function(_dereq_,module,exports){ exports.read = function (buffer, offset, isLE, mLen, nBytes) { var e, m var eLen = nBytes * 8 - mLen - 1 @@ -2454,7 +2567,7 @@ exports.write = function (buffer, value, offset, isLE, mLen, nBytes) { buffer[offset + i - d] |= s * 128 } -},{}],12:[function(_dereq_,module,exports){ +},{}],13:[function(_dereq_,module,exports){ (function (global){ 'use strict'; var Mutation = global.MutationObserver || global.WebKitMutationObserver; @@ -2527,7 +2640,7 @@ function immediate(task) { } }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{}],13:[function(_dereq_,module,exports){ +},{}],14:[function(_dereq_,module,exports){ if (typeof Object.create === 'function') { // implementation from standard node.js 'util' module module.exports = function inherits(ctor, superCtor) { @@ -2552,7 +2665,7 @@ if (typeof Object.create === 'function') { } } -},{}],14:[function(_dereq_,module,exports){ +},{}],15:[function(_dereq_,module,exports){ /** * Determine if an object is Buffer * @@ -2571,15 +2684,15 @@ module.exports = function (obj) { )) } -},{}],15:[function(_dereq_,module,exports){ +},{}],16:[function(_dereq_,module,exports){ module.exports = Array.isArray || function (arr) { return Object.prototype.toString.call(arr) == '[object Array]'; }; -},{}],16:[function(_dereq_,module,exports){ -var through = _dereq_('through2') -var split = _dereq_('split2') -var EOL = _dereq_('os').EOL +},{}],17:[function(_dereq_,module,exports){ +var through = _dereq_(18) +var split = _dereq_(36) +var EOL = _dereq_(20).EOL module.exports = parse module.exports.serialize = serialize @@ -2610,67 +2723,176 @@ function serialize() { }) } -},{"os":42,"split2":59,"through2":72}],17:[function(_dereq_,module,exports){ -/** Used as the `TypeError` message for "Functions" methods. */ -var FUNC_ERROR_TEXT = 'Expected a function'; +},{"18":18,"20":20,"36":36}],18:[function(_dereq_,module,exports){ +(function (process){ +var Transform = _dereq_(35) + , inherits = _dereq_(60).inherits + , xtend = _dereq_(61) + +function DestroyableTransform(opts) { + Transform.call(this, opts) + this._destroyed = false +} + +inherits(DestroyableTransform, Transform) + +DestroyableTransform.prototype.destroy = function(err) { + if (this._destroyed) return + this._destroyed = true + + var self = this + process.nextTick(function() { + if (err) + self.emit('error', err) + self.emit('close') + }) +} + +// a noop _transform function +function noop (chunk, enc, callback) { + callback(null, chunk) +} + + +// create a new export function, used by both the main export and +// the .ctor export, contains common logic for dealing with arguments +function through2 (construct) { + return function (options, transform, flush) { + if (typeof options == 'function') { + flush = transform + transform = options + options = {} + } + + if (typeof transform != 'function') + transform = noop + + if (typeof flush != 'function') + flush = null + + return construct(options, transform, flush) + } +} + + +// main export, just make me a transform stream! +module.exports = through2(function (options, transform, flush) { + var t2 = new DestroyableTransform(options) + + t2._transform = transform + + if (flush) + t2._flush = flush + + return t2 +}) + + +// make me a reusable prototype that I can `new`, or implicitly `new` +// with a constructor call +module.exports.ctor = through2(function (options, transform, flush) { + function Through2 (override) { + if (!(this instanceof Through2)) + return new Through2(override) + + this.options = xtend(options, override) + + DestroyableTransform.call(this, this.options) + } + + inherits(Through2, DestroyableTransform) + + Through2.prototype._transform = transform + + if (flush) + Through2.prototype._flush = flush + + return Through2 +}) -/* Native method references for those with the same name as other `lodash` methods. */ -var nativeMax = Math.max; +module.exports.obj = through2(function (options, transform, flush) { + var t2 = new DestroyableTransform(xtend({ objectMode: true, highWaterMark: 16 }, options)) + + t2._transform = transform + + if (flush) + t2._flush = flush + + return t2 +}) + +}).call(this,_dereq_(28)) +},{"28":28,"35":35,"60":60,"61":61}],19:[function(_dereq_,module,exports){ +(function (global){ /** - * Creates a function that invokes `func` with the `this` binding of the - * created function and arguments from `start` and beyond provided as an array. - * - * **Note:** This method is based on the [rest parameter](https://developer.mozilla.org/Web/JavaScript/Reference/Functions/rest_parameters). - * - * @static - * @memberOf _ - * @category Function - * @param {Function} func The function to apply a rest parameter to. - * @param {number} [start=func.length-1] The start position of the rest parameter. - * @returns {Function} Returns the new function. - * @example - * - * var say = _.restParam(function(what, names) { - * return what + ' ' + _.initial(names).join(', ') + - * (_.size(names) > 1 ? ', & ' : '') + _.last(names); - * }); + * lodash (Custom Build) + * Build: `lodash modularize exports="npm" -o ./` + * Copyright jQuery Foundation and other contributors + * Released under MIT license + * Based on Underscore.js 1.8.3 + * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors + */ + +/** Used as references for various `Number` constants. */ +var INFINITY = 1 / 0, + MAX_SAFE_INTEGER = 9007199254740991; + +/** `Object#toString` result references. */ +var argsTag = '[object Arguments]', + funcTag = '[object Function]', + genTag = '[object GeneratorFunction]', + symbolTag = '[object Symbol]'; + +/** Detect free variable `global` from Node.js. */ +var freeGlobal = typeof global == 'object' && global && global.Object === Object && global; + +/** Detect free variable `self`. */ +var freeSelf = typeof self == 'object' && self && self.Object === Object && self; + +/** Used as a reference to the global object. */ +var root = freeGlobal || freeSelf || Function('return this')(); + +/** + * A faster alternative to `Function#apply`, this function invokes `func` + * with the `this` binding of `thisArg` and the arguments of `args`. * - * say('hello', 'fred', 'barney', 'pebbles'); - * // => 'hello fred, barney, & pebbles' + * @private + * @param {Function} func The function to invoke. + * @param {*} thisArg The `this` binding of `func`. + * @param {Array} args The arguments to invoke `func` with. + * @returns {*} Returns the result of `func`. */ -function restParam(func, start) { - if (typeof func != 'function') { - throw new TypeError(FUNC_ERROR_TEXT); +function apply(func, thisArg, args) { + switch (args.length) { + case 0: return func.call(thisArg); + case 1: return func.call(thisArg, args[0]); + case 2: return func.call(thisArg, args[0], args[1]); + case 3: return func.call(thisArg, args[0], args[1], args[2]); } - start = nativeMax(start === undefined ? (func.length - 1) : (+start || 0), 0); - return function() { - var args = arguments, - index = -1, - length = nativeMax(args.length - start, 0), - rest = Array(length); - - while (++index < length) { - rest[index] = args[start + index]; - } - switch (start) { - case 0: return func.call(this, rest); - case 1: return func.call(this, args[0], rest); - case 2: return func.call(this, args[0], args[1], rest); - } - var otherArgs = Array(start + 1); - index = -1; - while (++index < start) { - otherArgs[index] = args[index]; - } - otherArgs[start] = rest; - return func.apply(this, otherArgs); - }; + return func.apply(thisArg, args); } -module.exports = restParam; +/** + * A specialized version of `_.map` for arrays without support for iteratee + * shorthands. + * + * @private + * @param {Array} [array] The array to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Array} Returns the new mapped array. + */ +function arrayMap(array, iteratee) { + var index = -1, + length = array ? array.length : 0, + result = Array(length); + + while (++index < length) { + result[index] = iteratee(array[index], index, array); + } + return result; +} -},{}],18:[function(_dereq_,module,exports){ /** * Appends the elements of `values` to `array`. * @@ -2690,39 +2912,64 @@ function arrayPush(array, values) { return array; } -module.exports = arrayPush; +/** + * The base implementation of `_.property` without support for deep paths. + * + * @private + * @param {string} key The key of the property to get. + * @returns {Function} Returns the new accessor function. + */ +function baseProperty(key) { + return function(object) { + return object == null ? undefined : object[key]; + }; +} + +/** Used for built-in method references. */ +var objectProto = Object.prototype; + +/** Used to check objects for own properties. */ +var hasOwnProperty = objectProto.hasOwnProperty; + +/** + * Used to resolve the + * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) + * of values. + */ +var objectToString = objectProto.toString; + +/** Built-in value references. */ +var Symbol = root.Symbol, + propertyIsEnumerable = objectProto.propertyIsEnumerable, + spreadableSymbol = Symbol ? Symbol.isConcatSpreadable : undefined; -},{}],19:[function(_dereq_,module,exports){ -var arrayPush = _dereq_('./arrayPush'), - isArguments = _dereq_('../lang/isArguments'), - isArray = _dereq_('../lang/isArray'), - isArrayLike = _dereq_('./isArrayLike'), - isObjectLike = _dereq_('./isObjectLike'); +/* Built-in method references for those with the same name as other `lodash` methods. */ +var nativeMax = Math.max; /** - * The base implementation of `_.flatten` with added support for restricting - * flattening and specifying the start index. + * The base implementation of `_.flatten` with support for restricting flattening. * * @private * @param {Array} array The array to flatten. - * @param {boolean} [isDeep] Specify a deep flatten. - * @param {boolean} [isStrict] Restrict flattening to arrays-like objects. + * @param {number} depth The maximum recursion depth. + * @param {boolean} [predicate=isFlattenable] The function invoked per iteration. + * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks. * @param {Array} [result=[]] The initial result value. * @returns {Array} Returns the new flattened array. */ -function baseFlatten(array, isDeep, isStrict, result) { - result || (result = []); - +function baseFlatten(array, depth, predicate, isStrict, result) { var index = -1, length = array.length; + predicate || (predicate = isFlattenable); + result || (result = []); + while (++index < length) { var value = array[index]; - if (isObjectLike(value) && isArrayLike(value) && - (isStrict || isArray(value) || isArguments(value))) { - if (isDeep) { + if (depth > 0 && predicate(value)) { + if (depth > 1) { // Recursively flatten arrays (susceptible to call stack limits). - baseFlatten(value, isDeep, isStrict, result); + baseFlatten(value, depth - 1, predicate, isStrict, result); } else { arrayPush(result, value); } @@ -2733,140 +2980,82 @@ function baseFlatten(array, isDeep, isStrict, result) { return result; } -module.exports = baseFlatten; - -},{"../lang/isArguments":34,"../lang/isArray":35,"./arrayPush":18,"./isArrayLike":27,"./isObjectLike":30}],20:[function(_dereq_,module,exports){ -var createBaseFor = _dereq_('./createBaseFor'); - /** - * The base implementation of `baseForIn` and `baseForOwn` which iterates - * over `object` properties returned by `keysFunc` invoking `iteratee` for - * each property. Iteratee functions may exit iteration early by explicitly - * returning `false`. + * The base implementation of `_.pick` without support for individual + * property identifiers. * * @private - * @param {Object} object The object to iterate over. - * @param {Function} iteratee The function invoked per iteration. - * @param {Function} keysFunc The function to get the keys of `object`. - * @returns {Object} Returns `object`. + * @param {Object} object The source object. + * @param {string[]} props The property identifiers to pick. + * @returns {Object} Returns the new object. */ -var baseFor = createBaseFor(); - -module.exports = baseFor; - -},{"./createBaseFor":24}],21:[function(_dereq_,module,exports){ -var baseFor = _dereq_('./baseFor'), - keysIn = _dereq_('../object/keysIn'); +function basePick(object, props) { + object = Object(object); + return basePickBy(object, props, function(value, key) { + return key in object; + }); +} /** - * The base implementation of `_.forIn` without support for callback - * shorthands and `this` binding. + * The base implementation of `_.pickBy` without support for iteratee shorthands. * * @private - * @param {Object} object The object to iterate over. - * @param {Function} iteratee The function invoked per iteration. - * @returns {Object} Returns `object`. + * @param {Object} object The source object. + * @param {string[]} props The property identifiers to pick from. + * @param {Function} predicate The function invoked per property. + * @returns {Object} Returns the new object. */ -function baseForIn(object, iteratee) { - return baseFor(object, iteratee, keysIn); -} +function basePickBy(object, props, predicate) { + var index = -1, + length = props.length, + result = {}; + + while (++index < length) { + var key = props[index], + value = object[key]; -module.exports = baseForIn; + if (predicate(value, key)) { + result[key] = value; + } + } + return result; +} -},{"../object/keysIn":39,"./baseFor":20}],22:[function(_dereq_,module,exports){ /** - * The base implementation of `_.property` without support for deep paths. + * The base implementation of `_.rest` which doesn't validate or coerce arguments. * * @private - * @param {string} key The key of the property to get. + * @param {Function} func The function to apply a rest parameter to. + * @param {number} [start=func.length-1] The start position of the rest parameter. * @returns {Function} Returns the new function. */ -function baseProperty(key) { - return function(object) { - return object == null ? undefined : object[key]; +function baseRest(func, start) { + start = nativeMax(start === undefined ? (func.length - 1) : start, 0); + return function() { + var args = arguments, + index = -1, + length = nativeMax(args.length - start, 0), + array = Array(length); + + while (++index < length) { + array[index] = args[start + index]; + } + index = -1; + var otherArgs = Array(start + 1); + while (++index < start) { + otherArgs[index] = args[index]; + } + otherArgs[start] = array; + return apply(func, this, otherArgs); }; } -module.exports = baseProperty; - -},{}],23:[function(_dereq_,module,exports){ -var identity = _dereq_('../utility/identity'); - /** - * A specialized version of `baseCallback` which only supports `this` binding - * and specifying the number of arguments to provide to `func`. + * Gets the "length" property value of `object`. * - * @private - * @param {Function} func The function to bind. - * @param {*} thisArg The `this` binding of `func`. - * @param {number} [argCount] The number of arguments to provide to `func`. - * @returns {Function} Returns the callback. - */ -function bindCallback(func, thisArg, argCount) { - if (typeof func != 'function') { - return identity; - } - if (thisArg === undefined) { - return func; - } - switch (argCount) { - case 1: return function(value) { - return func.call(thisArg, value); - }; - case 3: return function(value, index, collection) { - return func.call(thisArg, value, index, collection); - }; - case 4: return function(accumulator, value, index, collection) { - return func.call(thisArg, accumulator, value, index, collection); - }; - case 5: return function(value, other, key, object, source) { - return func.call(thisArg, value, other, key, object, source); - }; - } - return function() { - return func.apply(thisArg, arguments); - }; -} - -module.exports = bindCallback; - -},{"../utility/identity":41}],24:[function(_dereq_,module,exports){ -var toObject = _dereq_('./toObject'); - -/** - * Creates a base function for `_.forIn` or `_.forInRight`. - * - * @private - * @param {boolean} [fromRight] Specify iterating from right to left. - * @returns {Function} Returns the new base function. - */ -function createBaseFor(fromRight) { - return function(object, iteratee, keysFunc) { - var iterable = toObject(object), - props = keysFunc(object), - length = props.length, - index = fromRight ? length : -1; - - while ((fromRight ? index-- : ++index < length)) { - var key = props[index]; - if (iteratee(iterable[key], key, iterable) === false) { - break; - } - } - return object; - }; -} - -module.exports = createBaseFor; - -},{"./toObject":33}],25:[function(_dereq_,module,exports){ -var baseProperty = _dereq_('./baseProperty'); - -/** - * Gets the "length" property value of `object`. - * - * **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792) - * that affects Safari on at least iOS 8.1-8.3 ARM64. + * **Note:** This function is used to avoid a + * [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792) that affects + * Safari on at least iOS 8.1-8.3 ARM64. * * @private * @param {Object} object The object to query. @@ -2874,276 +3063,149 @@ var baseProperty = _dereq_('./baseProperty'); */ var getLength = baseProperty('length'); -module.exports = getLength; - -},{"./baseProperty":22}],26:[function(_dereq_,module,exports){ -var isNative = _dereq_('../lang/isNative'); - /** - * Gets the native function at `key` of `object`. + * Checks if `value` is a flattenable `arguments` object or array. * * @private - * @param {Object} object The object to query. - * @param {string} key The key of the method to get. - * @returns {*} Returns the function if it's native, else `undefined`. + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is flattenable, else `false`. */ -function getNative(object, key) { - var value = object == null ? undefined : object[key]; - return isNative(value) ? value : undefined; +function isFlattenable(value) { + return isArray(value) || isArguments(value) || + !!(spreadableSymbol && value && value[spreadableSymbol]) } -module.exports = getNative; - -},{"../lang/isNative":37}],27:[function(_dereq_,module,exports){ -var getLength = _dereq_('./getLength'), - isLength = _dereq_('./isLength'); - /** - * Checks if `value` is array-like. + * Converts `value` to a string key if it's not a string or symbol. * * @private - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is array-like, else `false`. + * @param {*} value The value to inspect. + * @returns {string|symbol} Returns the key. */ -function isArrayLike(value) { - return value != null && isLength(getLength(value)); +function toKey(value) { + if (typeof value == 'string' || isSymbol(value)) { + return value; + } + var result = (value + ''); + return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result; } -module.exports = isArrayLike; - -},{"./getLength":25,"./isLength":29}],28:[function(_dereq_,module,exports){ -/** Used to detect unsigned integer values. */ -var reIsUint = /^\d+$/; - /** - * Used as the [maximum length](http://ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer) - * of an array-like value. - */ -var MAX_SAFE_INTEGER = 9007199254740991; - -/** - * Checks if `value` is a valid array-like index. + * Checks if `value` is likely an `arguments` object. * - * @private + * @static + * @memberOf _ + * @since 0.1.0 + * @category Lang * @param {*} value The value to check. - * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index. - * @returns {boolean} Returns `true` if `value` is a valid index, else `false`. - */ -function isIndex(value, length) { - value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1; - length = length == null ? MAX_SAFE_INTEGER : length; - return value > -1 && value % 1 == 0 && value < length; -} - -module.exports = isIndex; - -},{}],29:[function(_dereq_,module,exports){ -/** - * Used as the [maximum length](http://ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer) - * of an array-like value. - */ -var MAX_SAFE_INTEGER = 9007199254740991; - -/** - * Checks if `value` is a valid array-like length. + * @returns {boolean} Returns `true` if `value` is an `arguments` object, + * else `false`. + * @example * - * **Note:** This function is based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength). + * _.isArguments(function() { return arguments; }()); + * // => true * - * @private - * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a valid length, else `false`. + * _.isArguments([1, 2, 3]); + * // => false */ -function isLength(value) { - return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER; +function isArguments(value) { + // Safari 8.1 incorrectly makes `arguments.callee` enumerable in strict mode. + return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') && + (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag); } -module.exports = isLength; - -},{}],30:[function(_dereq_,module,exports){ /** - * Checks if `value` is object-like. + * Checks if `value` is classified as an `Array` object. * - * @private + * @static + * @memberOf _ + * @since 0.1.0 + * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is object-like, else `false`. - */ -function isObjectLike(value) { - return !!value && typeof value == 'object'; -} - -module.exports = isObjectLike; - -},{}],31:[function(_dereq_,module,exports){ -var toObject = _dereq_('./toObject'); - -/** - * A specialized version of `_.pick` which picks `object` properties specified - * by `props`. + * @returns {boolean} Returns `true` if `value` is an array, else `false`. + * @example * - * @private - * @param {Object} object The source object. - * @param {string[]} props The property names to pick. - * @returns {Object} Returns the new object. - */ -function pickByArray(object, props) { - object = toObject(object); - - var index = -1, - length = props.length, - result = {}; - - while (++index < length) { - var key = props[index]; - if (key in object) { - result[key] = object[key]; - } - } - return result; -} - -module.exports = pickByArray; - -},{"./toObject":33}],32:[function(_dereq_,module,exports){ -var baseForIn = _dereq_('./baseForIn'); - -/** - * A specialized version of `_.pick` which picks `object` properties `predicate` - * returns truthy for. + * _.isArray([1, 2, 3]); + * // => true * - * @private - * @param {Object} object The source object. - * @param {Function} predicate The function invoked per iteration. - * @returns {Object} Returns the new object. - */ -function pickByCallback(object, predicate) { - var result = {}; - baseForIn(object, function(value, key, object) { - if (predicate(value, key, object)) { - result[key] = value; - } - }); - return result; -} - -module.exports = pickByCallback; - -},{"./baseForIn":21}],33:[function(_dereq_,module,exports){ -var isObject = _dereq_('../lang/isObject'); - -/** - * Converts `value` to an object if it's not one. + * _.isArray(document.body.children); + * // => false * - * @private - * @param {*} value The value to process. - * @returns {Object} Returns the object. + * _.isArray('abc'); + * // => false + * + * _.isArray(_.noop); + * // => false */ -function toObject(value) { - return isObject(value) ? value : Object(value); -} - -module.exports = toObject; - -},{"../lang/isObject":38}],34:[function(_dereq_,module,exports){ -var isArrayLike = _dereq_('../internal/isArrayLike'), - isObjectLike = _dereq_('../internal/isObjectLike'); - -/** Used for native method references. */ -var objectProto = Object.prototype; - -/** Used to check objects for own properties. */ -var hasOwnProperty = objectProto.hasOwnProperty; - -/** Native method references. */ -var propertyIsEnumerable = objectProto.propertyIsEnumerable; +var isArray = Array.isArray; /** - * Checks if `value` is classified as an `arguments` object. + * Checks if `value` is array-like. A value is considered array-like if it's + * not a function and has a `value.length` that's an integer greater than or + * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`. * * @static * @memberOf _ + * @since 4.0.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @returns {boolean} Returns `true` if `value` is array-like, else `false`. * @example * - * _.isArguments(function() { return arguments; }()); + * _.isArrayLike([1, 2, 3]); * // => true * - * _.isArguments([1, 2, 3]); + * _.isArrayLike(document.body.children); + * // => true + * + * _.isArrayLike('abc'); + * // => true + * + * _.isArrayLike(_.noop); * // => false */ -function isArguments(value) { - return isObjectLike(value) && isArrayLike(value) && - hasOwnProperty.call(value, 'callee') && !propertyIsEnumerable.call(value, 'callee'); +function isArrayLike(value) { + return value != null && isLength(getLength(value)) && !isFunction(value); } -module.exports = isArguments; - -},{"../internal/isArrayLike":27,"../internal/isObjectLike":30}],35:[function(_dereq_,module,exports){ -var getNative = _dereq_('../internal/getNative'), - isLength = _dereq_('../internal/isLength'), - isObjectLike = _dereq_('../internal/isObjectLike'); - -/** `Object#toString` result references. */ -var arrayTag = '[object Array]'; - -/** Used for native method references. */ -var objectProto = Object.prototype; - -/** - * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) - * of values. - */ -var objToString = objectProto.toString; - -/* Native method references for those with the same name as other `lodash` methods. */ -var nativeIsArray = getNative(Array, 'isArray'); - /** - * Checks if `value` is classified as an `Array` object. + * This method is like `_.isArrayLike` except that it also checks if `value` + * is an object. * * @static * @memberOf _ + * @since 4.0.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @returns {boolean} Returns `true` if `value` is an array-like object, + * else `false`. * @example * - * _.isArray([1, 2, 3]); + * _.isArrayLikeObject([1, 2, 3]); + * // => true + * + * _.isArrayLikeObject(document.body.children); * // => true * - * _.isArray(function() { return arguments; }()); + * _.isArrayLikeObject('abc'); + * // => false + * + * _.isArrayLikeObject(_.noop); * // => false */ -var isArray = nativeIsArray || function(value) { - return isObjectLike(value) && isLength(value.length) && objToString.call(value) == arrayTag; -}; - -module.exports = isArray; - -},{"../internal/getNative":26,"../internal/isLength":29,"../internal/isObjectLike":30}],36:[function(_dereq_,module,exports){ -var isObject = _dereq_('./isObject'); - -/** `Object#toString` result references. */ -var funcTag = '[object Function]'; - -/** Used for native method references. */ -var objectProto = Object.prototype; - -/** - * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) - * of values. - */ -var objToString = objectProto.toString; +function isArrayLikeObject(value) { + return isObjectLike(value) && isArrayLike(value); +} /** * Checks if `value` is classified as a `Function` object. * * @static * @memberOf _ + * @since 0.1.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @returns {boolean} Returns `true` if `value` is a function, else `false`. * @example * * _.isFunction(_); @@ -3154,70 +3216,52 @@ var objToString = objectProto.toString; */ function isFunction(value) { // The use of `Object#toString` avoids issues with the `typeof` operator - // in older versions of Chrome and Safari which return 'function' for regexes - // and Safari 8 which returns 'object' for typed array constructors. - return isObject(value) && objToString.call(value) == funcTag; + // in Safari 8 which returns 'object' for typed array and weak map constructors, + // and PhantomJS 1.9 which returns 'function' for `NodeList` instances. + var tag = isObject(value) ? objectToString.call(value) : ''; + return tag == funcTag || tag == genTag; } -module.exports = isFunction; - -},{"./isObject":38}],37:[function(_dereq_,module,exports){ -var isFunction = _dereq_('./isFunction'), - isObjectLike = _dereq_('../internal/isObjectLike'); - -/** Used to detect host constructors (Safari > 5). */ -var reIsHostCtor = /^\[object .+?Constructor\]$/; - -/** Used for native method references. */ -var objectProto = Object.prototype; - -/** Used to resolve the decompiled source of functions. */ -var fnToString = Function.prototype.toString; - -/** Used to check objects for own properties. */ -var hasOwnProperty = objectProto.hasOwnProperty; - -/** Used to detect if a method is native. */ -var reIsNative = RegExp('^' + - fnToString.call(hasOwnProperty).replace(/[\\^$.*+?()[\]{}|]/g, '\\$&') - .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$' -); - /** - * Checks if `value` is a native function. + * Checks if `value` is a valid array-like length. + * + * **Note:** This function is loosely based on + * [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength). * * @static * @memberOf _ + * @since 4.0.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is a native function, else `false`. + * @returns {boolean} Returns `true` if `value` is a valid length, + * else `false`. * @example * - * _.isNative(Array.prototype.push); + * _.isLength(3); * // => true * - * _.isNative(_); + * _.isLength(Number.MIN_VALUE); + * // => false + * + * _.isLength(Infinity); + * // => false + * + * _.isLength('3'); * // => false */ -function isNative(value) { - if (value == null) { - return false; - } - if (isFunction(value)) { - return reIsNative.test(fnToString.call(value)); - } - return isObjectLike(value) && reIsHostCtor.test(value); +function isLength(value) { + return typeof value == 'number' && + value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER; } -module.exports = isNative; - -},{"../internal/isObjectLike":30,"./isFunction":36}],38:[function(_dereq_,module,exports){ /** - * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`. - * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) + * Checks if `value` is the + * [language type](http://www.ecma-international.org/ecma-262/6.0/#sec-ecmascript-language-types) + * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) * * @static * @memberOf _ + * @since 0.1.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is an object, else `false`. @@ -3229,151 +3273,92 @@ module.exports = isNative; * _.isObject([1, 2, 3]); * // => true * - * _.isObject(1); + * _.isObject(_.noop); + * // => true + * + * _.isObject(null); * // => false */ function isObject(value) { - // Avoid a V8 JIT bug in Chrome 19-20. - // See https://code.google.com/p/v8/issues/detail?id=2291 for more details. var type = typeof value; return !!value && (type == 'object' || type == 'function'); } -module.exports = isObject; - -},{}],39:[function(_dereq_,module,exports){ -var isArguments = _dereq_('../lang/isArguments'), - isArray = _dereq_('../lang/isArray'), - isIndex = _dereq_('../internal/isIndex'), - isLength = _dereq_('../internal/isLength'), - isObject = _dereq_('../lang/isObject'); - -/** Used for native method references. */ -var objectProto = Object.prototype; - -/** Used to check objects for own properties. */ -var hasOwnProperty = objectProto.hasOwnProperty; - /** - * Creates an array of the own and inherited enumerable property names of `object`. - * - * **Note:** Non-object values are coerced to objects. + * Checks if `value` is object-like. A value is object-like if it's not `null` + * and has a `typeof` result of "object". * * @static * @memberOf _ - * @category Object - * @param {Object} object The object to query. - * @returns {Array} Returns the array of property names. + * @since 4.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is object-like, else `false`. * @example * - * function Foo() { - * this.a = 1; - * this.b = 2; - * } + * _.isObjectLike({}); + * // => true + * + * _.isObjectLike([1, 2, 3]); + * // => true * - * Foo.prototype.c = 3; + * _.isObjectLike(_.noop); + * // => false * - * _.keysIn(new Foo); - * // => ['a', 'b', 'c'] (iteration order is not guaranteed) + * _.isObjectLike(null); + * // => false */ -function keysIn(object) { - if (object == null) { - return []; - } - if (!isObject(object)) { - object = Object(object); - } - var length = object.length; - length = (length && isLength(length) && - (isArray(object) || isArguments(object)) && length) || 0; - - var Ctor = object.constructor, - index = -1, - isProto = typeof Ctor == 'function' && Ctor.prototype === object, - result = Array(length), - skipIndexes = length > 0; - - while (++index < length) { - result[index] = (index + ''); - } - for (var key in object) { - if (!(skipIndexes && isIndex(key, length)) && - !(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) { - result.push(key); - } - } - return result; +function isObjectLike(value) { + return !!value && typeof value == 'object'; } -module.exports = keysIn; - -},{"../internal/isIndex":28,"../internal/isLength":29,"../lang/isArguments":34,"../lang/isArray":35,"../lang/isObject":38}],40:[function(_dereq_,module,exports){ -var baseFlatten = _dereq_('../internal/baseFlatten'), - bindCallback = _dereq_('../internal/bindCallback'), - pickByArray = _dereq_('../internal/pickByArray'), - pickByCallback = _dereq_('../internal/pickByCallback'), - restParam = _dereq_('../function/restParam'); - /** - * Creates an object composed of the picked `object` properties. Property - * names may be specified as individual arguments or as arrays of property - * names. If `predicate` is provided it's invoked for each property of `object` - * picking the properties `predicate` returns truthy for. The predicate is - * bound to `thisArg` and invoked with three arguments: (value, key, object). + * Checks if `value` is classified as a `Symbol` primitive or object. * * @static * @memberOf _ - * @category Object - * @param {Object} object The source object. - * @param {Function|...(string|string[])} [predicate] The function invoked per - * iteration or property names to pick, specified as individual property - * names or arrays of property names. - * @param {*} [thisArg] The `this` binding of `predicate`. - * @returns {Object} Returns the new object. + * @since 4.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a symbol, else `false`. * @example * - * var object = { 'user': 'fred', 'age': 40 }; - * - * _.pick(object, 'user'); - * // => { 'user': 'fred' } + * _.isSymbol(Symbol.iterator); + * // => true * - * _.pick(object, _.isString); - * // => { 'user': 'fred' } + * _.isSymbol('abc'); + * // => false */ -var pick = restParam(function(object, props) { - if (object == null) { - return {}; - } - return typeof props[0] == 'function' - ? pickByCallback(object, bindCallback(props[0], props[1], 3)) - : pickByArray(object, baseFlatten(props)); -}); - -module.exports = pick; +function isSymbol(value) { + return typeof value == 'symbol' || + (isObjectLike(value) && objectToString.call(value) == symbolTag); +} -},{"../function/restParam":17,"../internal/baseFlatten":19,"../internal/bindCallback":23,"../internal/pickByArray":31,"../internal/pickByCallback":32}],41:[function(_dereq_,module,exports){ /** - * This method returns the first argument provided to it. + * Creates an object composed of the picked `object` properties. * * @static + * @since 0.1.0 * @memberOf _ - * @category Utility - * @param {*} value Any value. - * @returns {*} Returns `value`. + * @category Object + * @param {Object} object The source object. + * @param {...(string|string[])} [props] The property identifiers to pick. + * @returns {Object} Returns the new object. * @example * - * var object = { 'user': 'fred' }; + * var object = { 'a': 1, 'b': '2', 'c': 3 }; * - * _.identity(object) === object; - * // => true + * _.pick(object, ['a', 'c']); + * // => { 'a': 1, 'c': 3 } */ -function identity(value) { - return value; -} +var pick = baseRest(function(object, props) { + return object == null ? {} : basePick(object, arrayMap(baseFlatten(props, 1), toKey)); +}); -module.exports = identity; +module.exports = pick; -},{}],42:[function(_dereq_,module,exports){ +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{}],20:[function(_dereq_,module,exports){ exports.endianness = function () { return 'LE' }; exports.hostname = function () { @@ -3420,7 +3405,7 @@ exports.tmpdir = exports.tmpDir = function () { exports.EOL = '\n'; -},{}],43:[function(_dereq_,module,exports){ +},{}],21:[function(_dereq_,module,exports){ 'use strict'; module.exports = function (source, target, events) { source.on('newListener', function (event, listener) { @@ -3435,10 +3420,10 @@ module.exports = function (source, target, events) { }); }; -},{}],44:[function(_dereq_,module,exports){ +},{}],22:[function(_dereq_,module,exports){ 'use strict'; -var Writable = _dereq_('./writable'); -var Readable = _dereq_('./readable'); +var Writable = _dereq_(24); +var Readable = _dereq_(23); exports.createReadStream = function (opts) { opts = opts || {}; @@ -3448,7 +3433,7 @@ exports.createWriteStream = function (opts) { opts = opts || {}; return new Writable(this, opts); }; -var ep = _dereq_('./eventProxy'); +var ep = _dereq_(21); var streamEvents = [ 'drain', 'pipe', @@ -3469,10 +3454,10 @@ exports.end = function () { this.emit('done'); }; -},{"./eventProxy":43,"./readable":45,"./writable":46}],45:[function(_dereq_,module,exports){ +},{"21":21,"23":23,"24":24}],23:[function(_dereq_,module,exports){ 'use strict'; -var inherits = _dereq_('inherits'); -var Readable = _dereq_('readable-stream').Readable; +var inherits = _dereq_(14); +var Readable = _dereq_(34).Readable; module.exports = ReadStream; inherits(ReadStream, Readable); @@ -3524,11 +3509,11 @@ ReadStream.prototype.cancel = function () { } }; -},{"inherits":13,"readable-stream":57}],46:[function(_dereq_,module,exports){ +},{"14":14,"34":34}],24:[function(_dereq_,module,exports){ (function (Buffer){ 'use strict'; -var inherits = _dereq_('inherits'); -var Writable = _dereq_('readable-stream').Writable; +var inherits = _dereq_(14); +var Writable = _dereq_(34).Writable; module.exports = WriteStream; inherits(WriteStream, Writable); @@ -3570,20 +3555,21 @@ WriteStream.prototype._write = function (chunk, _, next) { } }; -}).call(this,{"isBuffer":_dereq_("../is-buffer/index.js")}) -},{"../is-buffer/index.js":14,"inherits":13,"readable-stream":57}],47:[function(_dereq_,module,exports){ +}).call(this,{"isBuffer":_dereq_(15)}) +},{"14":14,"15":15,"34":34}],25:[function(_dereq_,module,exports){ 'use strict'; -// allow external plugins to require('pouchdb/extras/promise') -module.exports = _dereq_('../lib/deps/promise'); -},{"../lib/deps/promise":48}],48:[function(_dereq_,module,exports){ -'use strict'; +function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } + +var lie = _interopDefault(_dereq_(26)); + /* istanbul ignore next */ -module.exports = typeof Promise === 'function' ? Promise : _dereq_('lie'); +var PouchPromise = typeof Promise === 'function' ? Promise : lie; -},{"lie":49}],49:[function(_dereq_,module,exports){ +module.exports = PouchPromise; +},{"26":26}],26:[function(_dereq_,module,exports){ 'use strict'; -var immediate = _dereq_('immediate'); +var immediate = _dereq_(13); /* istanbul ignore next */ function INTERNAL() {} @@ -3594,7 +3580,7 @@ var REJECTED = ['REJECTED']; var FULFILLED = ['FULFILLED']; var PENDING = ['PENDING']; -module.exports = exports = Promise; +module.exports = Promise; function Promise(resolver) { if (typeof resolver !== 'function') { @@ -3748,7 +3734,7 @@ function tryCatch(func, value) { return out; } -exports.resolve = resolve; +Promise.resolve = resolve; function resolve(value) { if (value instanceof this) { return value; @@ -3756,13 +3742,13 @@ function resolve(value) { return handlers.resolve(new this(INTERNAL), value); } -exports.reject = reject; +Promise.reject = reject; function reject(reason) { var promise = new this(INTERNAL); return handlers.reject(promise, reason); } -exports.all = all; +Promise.all = all; function all(iterable) { var self = this; if (Object.prototype.toString.call(iterable) !== '[object Array]') { @@ -3801,7 +3787,7 @@ function all(iterable) { } } -exports.race = race; +Promise.race = race; function race(iterable) { var self = this; if (Object.prototype.toString.call(iterable) !== '[object Array]') { @@ -3836,7 +3822,7 @@ function race(iterable) { } } -},{"immediate":12}],50:[function(_dereq_,module,exports){ +},{"13":13}],27:[function(_dereq_,module,exports){ (function (process){ 'use strict'; @@ -3848,28 +3834,79 @@ if (!process.version || module.exports = process.nextTick; } -function nextTick(fn) { - var args = new Array(arguments.length - 1); - var i = 0; - while (i < args.length) { - args[i++] = arguments[i]; +function nextTick(fn, arg1, arg2, arg3) { + if (typeof fn !== 'function') { + throw new TypeError('"callback" argument must be a function'); } - process.nextTick(function afterTick() { - fn.apply(null, args); - }); -} - -}).call(this,_dereq_('_process')) -},{"_process":51}],51:[function(_dereq_,module,exports){ -// shim for using process in browser + var len = arguments.length; + var args, i; + switch (len) { + case 0: + case 1: + return process.nextTick(fn); + case 2: + return process.nextTick(function afterTickOne() { + fn.call(null, arg1); + }); + case 3: + return process.nextTick(function afterTickTwo() { + fn.call(null, arg1, arg2); + }); + case 4: + return process.nextTick(function afterTickThree() { + fn.call(null, arg1, arg2, arg3); + }); + default: + args = new Array(len - 1); + i = 0; + while (i < args.length) { + args[i++] = arguments[i]; + } + return process.nextTick(function afterTick() { + fn.apply(null, args); + }); + } +} + +}).call(this,_dereq_(28)) +},{"28":28}],28:[function(_dereq_,module,exports){ +// shim for using process in browser var process = module.exports = {}; + +// cached from whatever global is present so that test runners that stub it +// don't break things. But we need to wrap it in a try catch in case it is +// wrapped in strict mode code which doesn't define any globals. It's inside a +// function because try/catches deoptimize in certain engines. + +var cachedSetTimeout; +var cachedClearTimeout; + +(function () { + try { + cachedSetTimeout = setTimeout; + } catch (e) { + cachedSetTimeout = function () { + throw new Error('setTimeout is not defined'); + } + } + try { + cachedClearTimeout = clearTimeout; + } catch (e) { + cachedClearTimeout = function () { + throw new Error('clearTimeout is not defined'); + } + } +} ()) var queue = []; var draining = false; var currentQueue; var queueIndex = -1; function cleanUpNextTick() { + if (!draining || !currentQueue) { + return; + } draining = false; if (currentQueue.length) { queue = currentQueue.concat(queue); @@ -3885,7 +3922,7 @@ function drainQueue() { if (draining) { return; } - var timeout = setTimeout(cleanUpNextTick); + var timeout = cachedSetTimeout.call(null, cleanUpNextTick); draining = true; var len = queue.length; @@ -3902,7 +3939,7 @@ function drainQueue() { } currentQueue = null; draining = false; - clearTimeout(timeout); + cachedClearTimeout.call(null, timeout); } process.nextTick = function (fun) { @@ -3914,7 +3951,7 @@ process.nextTick = function (fun) { } queue.push(new Item(fun, args)); if (queue.length === 1 && !draining) { - setTimeout(drainQueue, 0); + cachedSetTimeout.call(null, drainQueue, 0); } }; @@ -3953,7 +3990,7 @@ process.chdir = function (dir) { }; process.umask = function() { return 0; }; -},{}],52:[function(_dereq_,module,exports){ +},{}],29:[function(_dereq_,module,exports){ (function (process){ // Copyright Joyent, Inc. and other Node contributors. // @@ -3993,12 +4030,12 @@ var objectKeys = Object.keys || function (obj) { /**/ -var util = _dereq_('core-util-is'); -util.inherits = _dereq_('inherits'); +var util = _dereq_(10); +util.inherits = _dereq_(14); /**/ -var Readable = _dereq_('./_stream_readable'); -var Writable = _dereq_('./_stream_writable'); +var Readable = _dereq_(31); +var Writable = _dereq_(33); util.inherits(Duplex, Readable); @@ -4045,8 +4082,8 @@ function forEach (xs, f) { } } -}).call(this,_dereq_('_process')) -},{"./_stream_readable":54,"./_stream_writable":56,"_process":51,"core-util-is":9,"inherits":13}],53:[function(_dereq_,module,exports){ +}).call(this,_dereq_(28)) +},{"10":10,"14":14,"28":28,"31":31,"33":33}],30:[function(_dereq_,module,exports){ // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -4074,11 +4111,11 @@ function forEach (xs, f) { module.exports = PassThrough; -var Transform = _dereq_('./_stream_transform'); +var Transform = _dereq_(32); /**/ -var util = _dereq_('core-util-is'); -util.inherits = _dereq_('inherits'); +var util = _dereq_(10); +util.inherits = _dereq_(14); /**/ util.inherits(PassThrough, Transform); @@ -4094,7 +4131,7 @@ PassThrough.prototype._transform = function(chunk, encoding, cb) { cb(null, chunk); }; -},{"./_stream_transform":55,"core-util-is":9,"inherits":13}],54:[function(_dereq_,module,exports){ +},{"10":10,"14":14,"32":32}],31:[function(_dereq_,module,exports){ (function (process){ // Copyright Joyent, Inc. and other Node contributors. // @@ -4120,17 +4157,17 @@ PassThrough.prototype._transform = function(chunk, encoding, cb) { module.exports = Readable; /**/ -var isArray = _dereq_('isarray'); +var isArray = _dereq_(16); /**/ /**/ -var Buffer = _dereq_('buffer').Buffer; +var Buffer = _dereq_(8).Buffer; /**/ Readable.ReadableState = ReadableState; -var EE = _dereq_('events').EventEmitter; +var EE = _dereq_(11).EventEmitter; /**/ if (!EE.listenerCount) EE.listenerCount = function(emitter, type) { @@ -4138,11 +4175,11 @@ if (!EE.listenerCount) EE.listenerCount = function(emitter, type) { }; /**/ -var Stream = _dereq_('stream'); +var Stream = _dereq_(38); /**/ -var util = _dereq_('core-util-is'); -util.inherits = _dereq_('inherits'); +var util = _dereq_(10); +util.inherits = _dereq_(14); /**/ var StringDecoder; @@ -4211,7 +4248,7 @@ function ReadableState(options, stream) { this.encoding = null; if (options.encoding) { if (!StringDecoder) - StringDecoder = _dereq_('string_decoder/').StringDecoder; + StringDecoder = _dereq_(50).StringDecoder; this.decoder = new StringDecoder(options.encoding); this.encoding = options.encoding; } @@ -4312,7 +4349,7 @@ function needMoreData(state) { // backwards compatibility. Readable.prototype.setEncoding = function(enc) { if (!StringDecoder) - StringDecoder = _dereq_('string_decoder/').StringDecoder; + StringDecoder = _dereq_(50).StringDecoder; this._readableState.decoder = new StringDecoder(enc); this._readableState.encoding = enc; }; @@ -5079,8 +5116,8 @@ function indexOf (xs, x) { return -1; } -}).call(this,_dereq_('_process')) -},{"_process":51,"buffer":7,"core-util-is":9,"events":10,"inherits":13,"isarray":15,"stream":60,"string_decoder/":71}],55:[function(_dereq_,module,exports){ +}).call(this,_dereq_(28)) +},{"10":10,"11":11,"14":14,"16":16,"28":28,"38":38,"50":50,"8":8}],32:[function(_dereq_,module,exports){ // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -5147,11 +5184,11 @@ function indexOf (xs, x) { module.exports = Transform; -var Duplex = _dereq_('./_stream_duplex'); +var Duplex = _dereq_(29); /**/ -var util = _dereq_('core-util-is'); -util.inherits = _dereq_('inherits'); +var util = _dereq_(10); +util.inherits = _dereq_(14); /**/ util.inherits(Transform, Duplex); @@ -5292,7 +5329,7 @@ function done(stream, er) { return stream.push(null); } -},{"./_stream_duplex":52,"core-util-is":9,"inherits":13}],56:[function(_dereq_,module,exports){ +},{"10":10,"14":14,"29":29}],33:[function(_dereq_,module,exports){ (function (process){ // Copyright Joyent, Inc. and other Node contributors. // @@ -5322,18 +5359,18 @@ function done(stream, er) { module.exports = Writable; /**/ -var Buffer = _dereq_('buffer').Buffer; +var Buffer = _dereq_(8).Buffer; /**/ Writable.WritableState = WritableState; /**/ -var util = _dereq_('core-util-is'); -util.inherits = _dereq_('inherits'); +var util = _dereq_(10); +util.inherits = _dereq_(14); /**/ -var Stream = _dereq_('stream'); +var Stream = _dereq_(38); util.inherits(Writable, Stream); @@ -5415,7 +5452,7 @@ function WritableState(options, stream) { } function Writable(options) { - var Duplex = _dereq_('./_stream_duplex'); + var Duplex = _dereq_(29); // Writable ctor is applied to Duplexes, though they're not // instanceof Writable, they're instanceof Readable. @@ -5681,21 +5718,26 @@ function endWritable(stream, state, cb) { state.ended = true; } -}).call(this,_dereq_('_process')) -},{"./_stream_duplex":52,"_process":51,"buffer":7,"core-util-is":9,"inherits":13,"stream":60}],57:[function(_dereq_,module,exports){ -var Stream = _dereq_('stream'); // hack to fix a circular dependency issue when used with browserify -exports = module.exports = _dereq_('./lib/_stream_readable.js'); +}).call(this,_dereq_(28)) +},{"10":10,"14":14,"28":28,"29":29,"38":38,"8":8}],34:[function(_dereq_,module,exports){ +(function (process){ +var Stream = _dereq_(38); // hack to fix a circular dependency issue when used with browserify +exports = module.exports = _dereq_(31); exports.Stream = Stream; exports.Readable = exports; -exports.Writable = _dereq_('./lib/_stream_writable.js'); -exports.Duplex = _dereq_('./lib/_stream_duplex.js'); -exports.Transform = _dereq_('./lib/_stream_transform.js'); -exports.PassThrough = _dereq_('./lib/_stream_passthrough.js'); +exports.Writable = _dereq_(33); +exports.Duplex = _dereq_(29); +exports.Transform = _dereq_(32); +exports.PassThrough = _dereq_(30); +if (!process.browser && process.env.READABLE_STREAM === 'disable') { + module.exports = _dereq_(38); +} -},{"./lib/_stream_duplex.js":52,"./lib/_stream_passthrough.js":53,"./lib/_stream_readable.js":54,"./lib/_stream_transform.js":55,"./lib/_stream_writable.js":56,"stream":60}],58:[function(_dereq_,module,exports){ -module.exports = _dereq_("./lib/_stream_transform.js") +}).call(this,_dereq_(28)) +},{"28":28,"29":29,"30":30,"31":31,"32":32,"33":33,"38":38}],35:[function(_dereq_,module,exports){ +module.exports = _dereq_(32) -},{"./lib/_stream_transform.js":55}],59:[function(_dereq_,module,exports){ +},{"32":32}],36:[function(_dereq_,module,exports){ /* Copyright (c) 2014, Matteo Collina @@ -5714,7 +5756,7 @@ IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 'use strict'; -var through = _dereq_('through2') +var through = _dereq_(37) function transform(chunk, enc, cb) { var list = chunk.toString('utf8').split(this.matcher) @@ -5780,7 +5822,9 @@ function split(matcher, mapper, options) { module.exports = split -},{"through2":72}],60:[function(_dereq_,module,exports){ +},{"37":37}],37:[function(_dereq_,module,exports){ +arguments[4][18][0].apply(exports,arguments) +},{"18":18,"28":28,"35":35,"60":60,"61":61}],38:[function(_dereq_,module,exports){ // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -5804,15 +5848,15 @@ module.exports = split module.exports = Stream; -var EE = _dereq_('events').EventEmitter; -var inherits = _dereq_('inherits'); +var EE = _dereq_(11).EventEmitter; +var inherits = _dereq_(14); inherits(Stream, EE); -Stream.Readable = _dereq_('readable-stream/readable.js'); -Stream.Writable = _dereq_('readable-stream/writable.js'); -Stream.Duplex = _dereq_('readable-stream/duplex.js'); -Stream.Transform = _dereq_('readable-stream/transform.js'); -Stream.PassThrough = _dereq_('readable-stream/passthrough.js'); +Stream.Readable = _dereq_(47); +Stream.Writable = _dereq_(49); +Stream.Duplex = _dereq_(40); +Stream.Transform = _dereq_(48); +Stream.PassThrough = _dereq_(46); // Backwards-compat with node 0.4.x Stream.Stream = Stream; @@ -5909,10 +5953,12 @@ Stream.prototype.pipe = function(dest, options) { return dest; }; -},{"events":10,"inherits":13,"readable-stream/duplex.js":61,"readable-stream/passthrough.js":67,"readable-stream/readable.js":68,"readable-stream/transform.js":69,"readable-stream/writable.js":70}],61:[function(_dereq_,module,exports){ -module.exports = _dereq_("./lib/_stream_duplex.js") +},{"11":11,"14":14,"40":40,"46":46,"47":47,"48":48,"49":49}],39:[function(_dereq_,module,exports){ +arguments[4][9][0].apply(exports,arguments) +},{"9":9}],40:[function(_dereq_,module,exports){ +module.exports = _dereq_(41) -},{"./lib/_stream_duplex.js":62}],62:[function(_dereq_,module,exports){ +},{"41":41}],41:[function(_dereq_,module,exports){ // a duplex stream is just a stream that is both readable and writable. // Since JS doesn't have multiple prototypal inheritance, this class // prototypally inherits from Readable, and then parasitically from @@ -5921,55 +5967,49 @@ module.exports = _dereq_("./lib/_stream_duplex.js") 'use strict'; /**/ + var objectKeys = Object.keys || function (obj) { var keys = []; - for (var key in obj) keys.push(key); - return keys; -} + for (var key in obj) { + keys.push(key); + }return keys; +}; /**/ - module.exports = Duplex; /**/ -var processNextTick = _dereq_('process-nextick-args'); +var processNextTick = _dereq_(27); /**/ - - /**/ -var util = _dereq_('core-util-is'); -util.inherits = _dereq_('inherits'); +var util = _dereq_(10); +util.inherits = _dereq_(14); /**/ -var Readable = _dereq_('./_stream_readable'); -var Writable = _dereq_('./_stream_writable'); +var Readable = _dereq_(43); +var Writable = _dereq_(45); util.inherits(Duplex, Readable); var keys = objectKeys(Writable.prototype); for (var v = 0; v < keys.length; v++) { var method = keys[v]; - if (!Duplex.prototype[method]) - Duplex.prototype[method] = Writable.prototype[method]; + if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method]; } function Duplex(options) { - if (!(this instanceof Duplex)) - return new Duplex(options); + if (!(this instanceof Duplex)) return new Duplex(options); Readable.call(this, options); Writable.call(this, options); - if (options && options.readable === false) - this.readable = false; + if (options && options.readable === false) this.readable = false; - if (options && options.writable === false) - this.writable = false; + if (options && options.writable === false) this.writable = false; this.allowHalfOpen = true; - if (options && options.allowHalfOpen === false) - this.allowHalfOpen = false; + if (options && options.allowHalfOpen === false) this.allowHalfOpen = false; this.once('end', onend); } @@ -5978,8 +6018,7 @@ function Duplex(options) { function onend() { // if we allow half-open state, or if the writable side ended, // then we're ok. - if (this.allowHalfOpen || this._writableState.ended) - return; + if (this.allowHalfOpen || this._writableState.ended) return; // no more data can be written. // But allow more writes to happen in this tick. @@ -5990,13 +6029,12 @@ function onEndNT(self) { self.end(); } -function forEach (xs, f) { +function forEach(xs, f) { for (var i = 0, l = xs.length; i < l; i++) { f(xs[i], i); } } - -},{"./_stream_readable":64,"./_stream_writable":66,"core-util-is":9,"inherits":13,"process-nextick-args":50}],63:[function(_dereq_,module,exports){ +},{"10":10,"14":14,"27":27,"43":43,"45":45}],42:[function(_dereq_,module,exports){ // a passthrough stream. // basically just the most minimal sort of Transform stream. // Every written chunk gets output as-is. @@ -6005,80 +6043,72 @@ function forEach (xs, f) { module.exports = PassThrough; -var Transform = _dereq_('./_stream_transform'); +var Transform = _dereq_(44); /**/ -var util = _dereq_('core-util-is'); -util.inherits = _dereq_('inherits'); +var util = _dereq_(10); +util.inherits = _dereq_(14); /**/ util.inherits(PassThrough, Transform); function PassThrough(options) { - if (!(this instanceof PassThrough)) - return new PassThrough(options); + if (!(this instanceof PassThrough)) return new PassThrough(options); Transform.call(this, options); } -PassThrough.prototype._transform = function(chunk, encoding, cb) { +PassThrough.prototype._transform = function (chunk, encoding, cb) { cb(null, chunk); }; - -},{"./_stream_transform":65,"core-util-is":9,"inherits":13}],64:[function(_dereq_,module,exports){ +},{"10":10,"14":14,"44":44}],43:[function(_dereq_,module,exports){ (function (process){ 'use strict'; module.exports = Readable; /**/ -var processNextTick = _dereq_('process-nextick-args'); -/**/ - - -/**/ -var isArray = _dereq_('isarray'); +var processNextTick = _dereq_(27); /**/ - /**/ -var Buffer = _dereq_('buffer').Buffer; +var isArray = _dereq_(39); /**/ Readable.ReadableState = ReadableState; -var EE = _dereq_('events'); - /**/ -var EElistenerCount = function(emitter, type) { +var EE = _dereq_(11).EventEmitter; + +var EElistenerCount = function (emitter, type) { return emitter.listeners(type).length; }; /**/ - - /**/ var Stream; -(function (){try{ - Stream = _dereq_('st' + 'ream'); -}catch(_){}finally{ - if (!Stream) - Stream = _dereq_('events').EventEmitter; -}}()) +(function () { + try { + Stream = _dereq_('st' + 'ream'); + } catch (_) {} finally { + if (!Stream) Stream = _dereq_(11).EventEmitter; + } +})(); /**/ -var Buffer = _dereq_('buffer').Buffer; - +var Buffer = _dereq_(8).Buffer; /**/ -var util = _dereq_('core-util-is'); -util.inherits = _dereq_('inherits'); +var bufferShim = _dereq_(7); /**/ - +/**/ +var util = _dereq_(10); +util.inherits = _dereq_(14); +/**/ /**/ -var debugUtil = _dereq_('util'); -var debug; +var debugUtil = _dereq_(6); +var debug = void 0; if (debugUtil && debugUtil.debuglog) { debug = debugUtil.debuglog('stream'); } else { @@ -6090,9 +6120,22 @@ var StringDecoder; util.inherits(Readable, Stream); +var hasPrependListener = typeof EE.prototype.prependListener === 'function'; + +function prependListener(emitter, event, fn) { + if (hasPrependListener) return emitter.prependListener(event, fn); + + // This is a brutally ugly hack to make sure that our error handler + // is attached before any userland ones. NEVER DO THIS. This is here + // only because this code needs to continue to work with older versions + // of Node.js that do not include the prependListener() method. The goal + // is to eventually remove this hack. + if (!emitter._events || !emitter._events[event]) emitter.on(event, fn);else if (isArray(emitter._events[event])) emitter._events[event].unshift(fn);else emitter._events[event] = [fn, emitter._events[event]]; +} + var Duplex; function ReadableState(options, stream) { - Duplex = Duplex || _dereq_('./_stream_duplex'); + Duplex = Duplex || _dereq_(41); options = options || {}; @@ -6100,17 +6143,16 @@ function ReadableState(options, stream) { // make all the buffer merging and length checks go away this.objectMode = !!options.objectMode; - if (stream instanceof Duplex) - this.objectMode = this.objectMode || !!options.readableObjectMode; + if (stream instanceof Duplex) this.objectMode = this.objectMode || !!options.readableObjectMode; // the point at which it stops calling _read() to fill the buffer // Note: 0 is a valid value, means "don't call _read preemptively ever" var hwm = options.highWaterMark; var defaultHwm = this.objectMode ? 16 : 16 * 1024; - this.highWaterMark = (hwm || hwm === 0) ? hwm : defaultHwm; + this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm; // cast to ints. - this.highWaterMark = ~~this.highWaterMark; + this.highWaterMark = ~ ~this.highWaterMark; this.buffer = []; this.length = 0; @@ -6132,6 +6174,7 @@ function ReadableState(options, stream) { this.needReadable = false; this.emittedReadable = false; this.readableListening = false; + this.resumeScheduled = false; // Crypto is kind of old and crusty. Historically, its default string // encoding is 'binary' so we have to make this configurable. @@ -6151,8 +6194,7 @@ function ReadableState(options, stream) { this.decoder = null; this.encoding = null; if (options.encoding) { - if (!StringDecoder) - StringDecoder = _dereq_('string_decoder/').StringDecoder; + if (!StringDecoder) StringDecoder = _dereq_(50).StringDecoder; this.decoder = new StringDecoder(options.encoding); this.encoding = options.encoding; } @@ -6160,18 +6202,16 @@ function ReadableState(options, stream) { var Duplex; function Readable(options) { - Duplex = Duplex || _dereq_('./_stream_duplex'); + Duplex = Duplex || _dereq_(41); - if (!(this instanceof Readable)) - return new Readable(options); + if (!(this instanceof Readable)) return new Readable(options); this._readableState = new ReadableState(options, this); // legacy this.readable = true; - if (options && typeof options.read === 'function') - this._read = options.read; + if (options && typeof options.read === 'function') this._read = options.read; Stream.call(this); } @@ -6180,13 +6220,13 @@ function Readable(options) { // This returns true if the highWaterMark has not been hit yet, // similar to how Writable.write() returns true if you should // write() some more. -Readable.prototype.push = function(chunk, encoding) { +Readable.prototype.push = function (chunk, encoding) { var state = this._readableState; if (!state.objectMode && typeof chunk === 'string') { encoding = encoding || state.defaultEncoding; if (encoding !== state.encoding) { - chunk = new Buffer(chunk, encoding); + chunk = bufferShim.from(chunk, encoding); encoding = ''; } } @@ -6195,12 +6235,12 @@ Readable.prototype.push = function(chunk, encoding) { }; // Unshift should *always* be something directly out of read() -Readable.prototype.unshift = function(chunk) { +Readable.prototype.unshift = function (chunk) { var state = this._readableState; return readableAddChunk(this, state, chunk, '', true); }; -Readable.prototype.isPaused = function() { +Readable.prototype.isPaused = function () { return this._readableState.flowing === false; }; @@ -6216,29 +6256,31 @@ function readableAddChunk(stream, state, chunk, encoding, addToFront) { var e = new Error('stream.push() after EOF'); stream.emit('error', e); } else if (state.endEmitted && addToFront) { - var e = new Error('stream.unshift() after end event'); - stream.emit('error', e); + var _e = new Error('stream.unshift() after end event'); + stream.emit('error', _e); } else { - if (state.decoder && !addToFront && !encoding) + var skipAdd; + if (state.decoder && !addToFront && !encoding) { chunk = state.decoder.write(chunk); + skipAdd = !state.objectMode && chunk.length === 0; + } - if (!addToFront) - state.reading = false; + if (!addToFront) state.reading = false; - // if we want the data now, just emit it. - if (state.flowing && state.length === 0 && !state.sync) { - stream.emit('data', chunk); - stream.read(0); - } else { - // update the buffer info. - state.length += state.objectMode ? 1 : chunk.length; - if (addToFront) - state.buffer.unshift(chunk); - else - state.buffer.push(chunk); + // Don't add to the buffer if we've decoded to an empty string chunk and + // we're not in object mode + if (!skipAdd) { + // if we want the data now, just emit it. + if (state.flowing && state.length === 0 && !state.sync) { + stream.emit('data', chunk); + stream.read(0); + } else { + // update the buffer info. + state.length += state.objectMode ? 1 : chunk.length; + if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk); - if (state.needReadable) - emitReadable(stream); + if (state.needReadable) emitReadable(stream); + } } maybeReadMore(stream, state); @@ -6250,7 +6292,6 @@ function readableAddChunk(stream, state, chunk, encoding, addToFront) { return needMoreData(state); } - // if it's past the high water mark, we can push in some more. // Also, if we have no data yet, we can stand some // more bytes. This is to work around cases where hwm=0, @@ -6259,16 +6300,12 @@ function readableAddChunk(stream, state, chunk, encoding, addToFront) { // needReadable was set, then we ought to push more, so that another // 'readable' event will be triggered. function needMoreData(state) { - return !state.ended && - (state.needReadable || - state.length < state.highWaterMark || - state.length === 0); + return !state.ended && (state.needReadable || state.length < state.highWaterMark || state.length === 0); } // backwards compatibility. -Readable.prototype.setEncoding = function(enc) { - if (!StringDecoder) - StringDecoder = _dereq_('string_decoder/').StringDecoder; +Readable.prototype.setEncoding = function (enc) { + if (!StringDecoder) StringDecoder = _dereq_(50).StringDecoder; this._readableState.decoder = new StringDecoder(enc); this._readableState.encoding = enc; return this; @@ -6293,29 +6330,22 @@ function computeNewHighWaterMark(n) { } function howMuchToRead(n, state) { - if (state.length === 0 && state.ended) - return 0; + if (state.length === 0 && state.ended) return 0; - if (state.objectMode) - return n === 0 ? 0 : 1; + if (state.objectMode) return n === 0 ? 0 : 1; if (n === null || isNaN(n)) { // only flow one buffer at a time - if (state.flowing && state.buffer.length) - return state.buffer[0].length; - else - return state.length; + if (state.flowing && state.buffer.length) return state.buffer[0].length;else return state.length; } - if (n <= 0) - return 0; + if (n <= 0) return 0; // If we're asking for more than the target buffer level, // then raise the water mark. Bump up to the next highest // power of 2, to prevent increasing it excessively in tiny // amounts. - if (n > state.highWaterMark) - state.highWaterMark = computeNewHighWaterMark(n); + if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n); // don't have that much. return null, unless we've ended. if (n > state.length) { @@ -6331,25 +6361,19 @@ function howMuchToRead(n, state) { } // you can override either this method, or the async _read(n) below. -Readable.prototype.read = function(n) { +Readable.prototype.read = function (n) { debug('read', n); var state = this._readableState; var nOrig = n; - if (typeof n !== 'number' || n > 0) - state.emittedReadable = false; + if (typeof n !== 'number' || n > 0) state.emittedReadable = false; // if we're doing read(0) to trigger a readable event, but we // already have a bunch of data in the buffer, then just trigger // the 'readable' event and move on. - if (n === 0 && - state.needReadable && - (state.length >= state.highWaterMark || state.ended)) { + if (n === 0 && state.needReadable && (state.length >= state.highWaterMark || state.ended)) { debug('read: emitReadable', state.length, state.ended); - if (state.length === 0 && state.ended) - endReadable(this); - else - emitReadable(this); + if (state.length === 0 && state.ended) endReadable(this);else emitReadable(this); return null; } @@ -6357,8 +6381,7 @@ Readable.prototype.read = function(n) { // if we've ended, and we're now clear, then finish it up. if (n === 0 && state.ended) { - if (state.length === 0) - endReadable(this); + if (state.length === 0) endReadable(this); return null; } @@ -6406,8 +6429,7 @@ Readable.prototype.read = function(n) { state.reading = true; state.sync = true; // if the length is currently zero, then we *need* a readable event. - if (state.length === 0) - state.needReadable = true; + if (state.length === 0) state.needReadable = true; // call internal read method this._read(state.highWaterMark); state.sync = false; @@ -6415,14 +6437,10 @@ Readable.prototype.read = function(n) { // If _read pushed data synchronously, then `reading` will be false, // and we need to re-evaluate how much data we can return to the user. - if (doRead && !state.reading) - n = howMuchToRead(nOrig, state); + if (doRead && !state.reading) n = howMuchToRead(nOrig, state); var ret; - if (n > 0) - ret = fromList(n, state); - else - ret = null; + if (n > 0) ret = fromList(n, state);else ret = null; if (ret === null) { state.needReadable = true; @@ -6433,32 +6451,24 @@ Readable.prototype.read = function(n) { // If we have nothing in the buffer, then we want to know // as soon as we *do* get something into the buffer. - if (state.length === 0 && !state.ended) - state.needReadable = true; + if (state.length === 0 && !state.ended) state.needReadable = true; // If we tried to read() past the EOF, then emit end on the next tick. - if (nOrig !== n && state.ended && state.length === 0) - endReadable(this); + if (nOrig !== n && state.ended && state.length === 0) endReadable(this); - if (ret !== null) - this.emit('data', ret); + if (ret !== null) this.emit('data', ret); return ret; }; function chunkInvalid(state, chunk) { var er = null; - if (!(Buffer.isBuffer(chunk)) && - typeof chunk !== 'string' && - chunk !== null && - chunk !== undefined && - !state.objectMode) { + if (!Buffer.isBuffer(chunk) && typeof chunk !== 'string' && chunk !== null && chunk !== undefined && !state.objectMode) { er = new TypeError('Invalid non-string/buffer chunk'); } return er; } - function onEofChunk(stream, state) { if (state.ended) return; if (state.decoder) { @@ -6483,10 +6493,7 @@ function emitReadable(stream) { if (!state.emittedReadable) { debug('emitReadable', state.flowing); state.emittedReadable = true; - if (state.sync) - processNextTick(emitReadable_, stream); - else - emitReadable_(stream); + if (state.sync) processNextTick(emitReadable_, stream);else emitReadable_(stream); } } @@ -6496,7 +6503,6 @@ function emitReadable_(stream) { flow(stream); } - // at this point, the user has presumably seen the 'readable' event, // and called read() to consume some data. that may have triggered // in turn another _read(n) call, in which case reading = true if @@ -6512,15 +6518,12 @@ function maybeReadMore(stream, state) { function maybeReadMore_(stream, state) { var len = state.length; - while (!state.reading && !state.flowing && !state.ended && - state.length < state.highWaterMark) { + while (!state.reading && !state.flowing && !state.ended && state.length < state.highWaterMark) { debug('maybeReadMore read 0'); stream.read(0); if (len === state.length) // didn't get any data, stop spinning. - break; - else - len = state.length; + break;else len = state.length; } state.readingMore = false; } @@ -6529,11 +6532,11 @@ function maybeReadMore_(stream, state) { // call cb(er, data) where data is <= n in length. // for virtual (non-string, non-buffer) streams, "length" is somewhat // arbitrary, and perhaps not very meaningful. -Readable.prototype._read = function(n) { +Readable.prototype._read = function (n) { this.emit('error', new Error('not implemented')); }; -Readable.prototype.pipe = function(dest, pipeOpts) { +Readable.prototype.pipe = function (dest, pipeOpts) { var src = this; var state = this._readableState; @@ -6551,15 +6554,10 @@ Readable.prototype.pipe = function(dest, pipeOpts) { state.pipesCount += 1; debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts); - var doEnd = (!pipeOpts || pipeOpts.end !== false) && - dest !== process.stdout && - dest !== process.stderr; + var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr; var endFn = doEnd ? onend : cleanup; - if (state.endEmitted) - processNextTick(endFn); - else - src.once('end', endFn); + if (state.endEmitted) processNextTick(endFn);else src.once('end', endFn); dest.on('unpipe', onunpipe); function onunpipe(readable) { @@ -6601,9 +6599,7 @@ Readable.prototype.pipe = function(dest, pipeOpts) { // flowing again. // So, if this is awaiting a drain, then we just call it now. // If we don't know, then assume that we are waiting for one. - if (state.awaitDrain && - (!dest._writableState || dest._writableState.needDrain)) - ondrain(); + if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain(); } src.on('data', ondata); @@ -6614,10 +6610,8 @@ Readable.prototype.pipe = function(dest, pipeOpts) { // If the user unpiped during `dest.write()`, it is possible // to get stuck in a permanently paused state if that write // also returned false. - if (state.pipesCount === 1 && - state.pipes[0] === dest && - src.listenerCount('data') === 1 && - !cleanedUp) { + // => Check whether `dest` is still a piping destination. + if ((state.pipesCount === 1 && state.pipes === dest || state.pipesCount > 1 && indexOf(state.pipes, dest) !== -1) && !cleanedUp) { debug('false write response, pause', src._readableState.awaitDrain); src._readableState.awaitDrain++; } @@ -6631,18 +6625,11 @@ Readable.prototype.pipe = function(dest, pipeOpts) { debug('onerror', er); unpipe(); dest.removeListener('error', onerror); - if (EElistenerCount(dest, 'error') === 0) - dest.emit('error', er); + if (EElistenerCount(dest, 'error') === 0) dest.emit('error', er); } - // This is a brutally ugly hack to make sure that our error handler - // is attached before any userland ones. NEVER DO THIS. - if (!dest._events || !dest._events.error) - dest.on('error', onerror); - else if (isArray(dest._events.error)) - dest._events.error.unshift(onerror); - else - dest._events.error = [onerror, dest._events.error]; + // Make sure our error handler is attached before userland ones. + prependListener(dest, 'error', onerror); // Both close and finish should trigger unpipe, but only once. function onclose() { @@ -6675,11 +6662,10 @@ Readable.prototype.pipe = function(dest, pipeOpts) { }; function pipeOnDrain(src) { - return function() { + return function () { var state = src._readableState; debug('pipeOnDrain', state.awaitDrain); - if (state.awaitDrain) - state.awaitDrain--; + if (state.awaitDrain) state.awaitDrain--; if (state.awaitDrain === 0 && EElistenerCount(src, 'data')) { state.flowing = true; flow(src); @@ -6687,29 +6673,24 @@ function pipeOnDrain(src) { }; } - -Readable.prototype.unpipe = function(dest) { +Readable.prototype.unpipe = function (dest) { var state = this._readableState; // if we're not piping anywhere, then do nothing. - if (state.pipesCount === 0) - return this; + if (state.pipesCount === 0) return this; // just one destination. most common case. if (state.pipesCount === 1) { // passed in one, but it's not the right one. - if (dest && dest !== state.pipes) - return this; + if (dest && dest !== state.pipes) return this; - if (!dest) - dest = state.pipes; + if (!dest) dest = state.pipes; // got a match. state.pipes = null; state.pipesCount = 0; state.flowing = false; - if (dest) - dest.emit('unpipe', this); + if (dest) dest.emit('unpipe', this); return this; } @@ -6723,20 +6704,18 @@ Readable.prototype.unpipe = function(dest) { state.pipesCount = 0; state.flowing = false; - for (var i = 0; i < len; i++) - dests[i].emit('unpipe', this); - return this; + for (var _i = 0; _i < len; _i++) { + dests[_i].emit('unpipe', this); + }return this; } // try to find the right one. var i = indexOf(state.pipes, dest); - if (i === -1) - return this; + if (i === -1) return this; state.pipes.splice(i, 1); state.pipesCount -= 1; - if (state.pipesCount === 1) - state.pipes = state.pipes[0]; + if (state.pipesCount === 1) state.pipes = state.pipes[0]; dest.emit('unpipe', this); @@ -6745,7 +6724,7 @@ Readable.prototype.unpipe = function(dest) { // set up data events if they are asked for // Ensure readable listeners eventually get something -Readable.prototype.on = function(ev, fn) { +Readable.prototype.on = function (ev, fn) { var res = Stream.prototype.on.call(this, ev, fn); // If listening to data, and it has not explicitly been paused, @@ -6754,7 +6733,7 @@ Readable.prototype.on = function(ev, fn) { this.resume(); } - if (ev === 'readable' && this.readable) { + if (ev === 'readable' && !this._readableState.endEmitted) { var state = this._readableState; if (!state.readableListening) { state.readableListening = true; @@ -6779,7 +6758,7 @@ function nReadingNextTick(self) { // pause() and resume() are remnants of the legacy readable stream API // If the user uses them, then switch into old mode. -Readable.prototype.resume = function() { +Readable.prototype.resume = function () { var state = this._readableState; if (!state.flowing) { debug('resume'); @@ -6805,11 +6784,10 @@ function resume_(stream, state) { state.resumeScheduled = false; stream.emit('resume'); flow(stream); - if (state.flowing && !state.reading) - stream.read(0); + if (state.flowing && !state.reading) stream.read(0); } -Readable.prototype.pause = function() { +Readable.prototype.pause = function () { debug('call pause flowing=%j', this._readableState.flowing); if (false !== this._readableState.flowing) { debug('pause'); @@ -6832,32 +6810,27 @@ function flow(stream) { // wrap an old-style stream as the async data source. // This is *not* part of the readable stream interface. // It is an ugly unfortunate mess of history. -Readable.prototype.wrap = function(stream) { +Readable.prototype.wrap = function (stream) { var state = this._readableState; var paused = false; var self = this; - stream.on('end', function() { + stream.on('end', function () { debug('wrapped end'); if (state.decoder && !state.ended) { var chunk = state.decoder.end(); - if (chunk && chunk.length) - self.push(chunk); + if (chunk && chunk.length) self.push(chunk); } self.push(null); }); - stream.on('data', function(chunk) { + stream.on('data', function (chunk) { debug('wrapped data'); - if (state.decoder) - chunk = state.decoder.write(chunk); + if (state.decoder) chunk = state.decoder.write(chunk); // don't skip over falsy values in objectMode - if (state.objectMode && (chunk === null || chunk === undefined)) - return; - else if (!state.objectMode && (!chunk || !chunk.length)) - return; + if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return; var ret = self.push(chunk); if (!ret) { @@ -6870,21 +6843,23 @@ Readable.prototype.wrap = function(stream) { // important when wrapping filters and duplexes. for (var i in stream) { if (this[i] === undefined && typeof stream[i] === 'function') { - this[i] = function(method) { return function() { - return stream[method].apply(stream, arguments); - }; }(i); + this[i] = function (method) { + return function () { + return stream[method].apply(stream, arguments); + }; + }(i); } } // proxy certain important events. var events = ['error', 'close', 'destroy', 'pause', 'resume']; - forEach(events, function(ev) { + forEach(events, function (ev) { stream.on(ev, self.emit.bind(self, ev)); }); // when we try to consume some more bytes, simply unpause the // underlying stream. - self._read = function(n) { + self._read = function (n) { debug('wrapped _read', n); if (paused) { paused = false; @@ -6895,7 +6870,6 @@ Readable.prototype.wrap = function(stream) { return self; }; - // exposed for testing purposes only. Readable._fromList = fromList; @@ -6909,21 +6883,11 @@ function fromList(n, state) { var ret; // nothing in the list, definitely empty. - if (list.length === 0) - return null; + if (list.length === 0) return null; - if (length === 0) - ret = null; - else if (objectMode) - ret = list.shift(); - else if (!n || n >= length) { + if (length === 0) ret = null;else if (objectMode) ret = list.shift();else if (!n || n >= length) { // read it all, truncate the array. - if (stringMode) - ret = list.join(''); - else if (list.length === 1) - ret = list[0]; - else - ret = Buffer.concat(list, length); + if (stringMode) ret = list.join('');else if (list.length === 1) ret = list[0];else ret = Buffer.concat(list, length); list.length = 0; } else { // read just some of it. @@ -6939,25 +6903,16 @@ function fromList(n, state) { } else { // complex case. // we have enough to cover it, but it spans past the first buffer. - if (stringMode) - ret = ''; - else - ret = new Buffer(n); + if (stringMode) ret = '';else ret = bufferShim.allocUnsafe(n); var c = 0; for (var i = 0, l = list.length; i < l && c < n; i++) { - var buf = list[0]; - var cpy = Math.min(n - c, buf.length); + var _buf = list[0]; + var cpy = Math.min(n - c, _buf.length); - if (stringMode) - ret += buf.slice(0, cpy); - else - buf.copy(ret, c, 0, cpy); + if (stringMode) ret += _buf.slice(0, cpy);else _buf.copy(ret, c, 0, cpy); - if (cpy < buf.length) - list[0] = buf.slice(cpy); - else - list.shift(); + if (cpy < _buf.length) list[0] = _buf.slice(cpy);else list.shift(); c += cpy; } @@ -6972,8 +6927,7 @@ function endReadable(stream) { // If we get here before consuming all the bytes, then that is a // bug in node. Should never happen. - if (state.length > 0) - throw new Error('endReadable called on non-empty stream'); + if (state.length > 0) throw new Error('"endReadable()" called on non-empty stream'); if (!state.endEmitted) { state.ended = true; @@ -6990,21 +6944,20 @@ function endReadableNT(state, stream) { } } -function forEach (xs, f) { +function forEach(xs, f) { for (var i = 0, l = xs.length; i < l; i++) { f(xs[i], i); } } -function indexOf (xs, x) { +function indexOf(xs, x) { for (var i = 0, l = xs.length; i < l; i++) { if (xs[i] === x) return i; } return -1; } - -}).call(this,_dereq_('_process')) -},{"./_stream_duplex":62,"_process":51,"buffer":7,"core-util-is":9,"events":10,"inherits":13,"isarray":15,"process-nextick-args":50,"string_decoder/":71,"util":6}],65:[function(_dereq_,module,exports){ +}).call(this,_dereq_(28)) +},{"10":10,"11":11,"14":14,"27":27,"28":28,"39":39,"41":41,"50":50,"6":6,"7":7,"8":8}],44:[function(_dereq_,module,exports){ // a transform stream is a readable/writable stream where you do // something with the data. Sometimes it's called a "filter", // but that's not a great name for it, since that implies a thing where @@ -7051,18 +7004,17 @@ function indexOf (xs, x) { module.exports = Transform; -var Duplex = _dereq_('./_stream_duplex'); +var Duplex = _dereq_(41); /**/ -var util = _dereq_('core-util-is'); -util.inherits = _dereq_('inherits'); +var util = _dereq_(10); +util.inherits = _dereq_(14); /**/ util.inherits(Transform, Duplex); - function TransformState(stream) { - this.afterTransform = function(er, data) { + this.afterTransform = function (er, data) { return afterTransform(stream, er, data); }; @@ -7070,6 +7022,7 @@ function TransformState(stream) { this.transforming = false; this.writecb = null; this.writechunk = null; + this.writeencoding = null; } function afterTransform(stream, er, data) { @@ -7078,17 +7031,14 @@ function afterTransform(stream, er, data) { var cb = ts.writecb; - if (!cb) - return stream.emit('error', new Error('no writecb in Transform class')); + if (!cb) return stream.emit('error', new Error('no writecb in Transform class')); ts.writechunk = null; ts.writecb = null; - if (data !== null && data !== undefined) - stream.push(data); + if (data !== null && data !== undefined) stream.push(data); - if (cb) - cb(er); + cb(er); var rs = stream._readableState; rs.reading = false; @@ -7097,10 +7047,8 @@ function afterTransform(stream, er, data) { } } - function Transform(options) { - if (!(this instanceof Transform)) - return new Transform(options); + if (!(this instanceof Transform)) return new Transform(options); Duplex.call(this, options); @@ -7118,24 +7066,19 @@ function Transform(options) { this._readableState.sync = false; if (options) { - if (typeof options.transform === 'function') - this._transform = options.transform; + if (typeof options.transform === 'function') this._transform = options.transform; - if (typeof options.flush === 'function') - this._flush = options.flush; + if (typeof options.flush === 'function') this._flush = options.flush; } - this.once('prefinish', function() { - if (typeof this._flush === 'function') - this._flush(function(er) { - done(stream, er); - }); - else - done(stream); + this.once('prefinish', function () { + if (typeof this._flush === 'function') this._flush(function (er) { + done(stream, er); + });else done(stream); }); } -Transform.prototype.push = function(chunk, encoding) { +Transform.prototype.push = function (chunk, encoding) { this._transformState.needTransform = false; return Duplex.prototype.push.call(this, chunk, encoding); }; @@ -7150,28 +7093,25 @@ Transform.prototype.push = function(chunk, encoding) { // Call `cb(err)` when you are done with this chunk. If you pass // an error, then that'll put the hurt on the whole operation. If you // never call cb(), then you'll never get another chunk. -Transform.prototype._transform = function(chunk, encoding, cb) { - throw new Error('not implemented'); +Transform.prototype._transform = function (chunk, encoding, cb) { + throw new Error('Not implemented'); }; -Transform.prototype._write = function(chunk, encoding, cb) { +Transform.prototype._write = function (chunk, encoding, cb) { var ts = this._transformState; ts.writecb = cb; ts.writechunk = chunk; ts.writeencoding = encoding; if (!ts.transforming) { var rs = this._readableState; - if (ts.needTransform || - rs.needReadable || - rs.length < rs.highWaterMark) - this._read(rs.highWaterMark); + if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) this._read(rs.highWaterMark); } }; // Doesn't matter what the args are here. // _transform does all the work. // That we got here means that the readable side wants more data. -Transform.prototype._read = function(n) { +Transform.prototype._read = function (n) { var ts = this._transformState; if (ts.writechunk !== null && ts.writecb && !ts.transforming) { @@ -7184,26 +7124,22 @@ Transform.prototype._read = function(n) { } }; - function done(stream, er) { - if (er) - return stream.emit('error', er); + if (er) return stream.emit('error', er); // if there's nothing in the write buffer, then that means // that nothing more will ever be provided var ws = stream._writableState; var ts = stream._transformState; - if (ws.length) - throw new Error('calling transform done when ws.length != 0'); + if (ws.length) throw new Error('Calling transform done when ws.length != 0'); - if (ts.transforming) - throw new Error('calling transform done when still transforming'); + if (ts.transforming) throw new Error('Calling transform done when still transforming'); return stream.push(null); } - -},{"./_stream_duplex":62,"core-util-is":9,"inherits":13}],66:[function(_dereq_,module,exports){ +},{"10":10,"14":14,"41":41}],45:[function(_dereq_,module,exports){ +(function (process){ // A bit simpler than readable streams. // Implement an async ._write(chunk, encoding, cb), and it'll handle all // the drain event emission and buffering. @@ -7213,42 +7149,41 @@ function done(stream, er) { module.exports = Writable; /**/ -var processNextTick = _dereq_('process-nextick-args'); +var processNextTick = _dereq_(27); /**/ - /**/ -var Buffer = _dereq_('buffer').Buffer; +var asyncWrite = !process.browser && ['v0.10', 'v0.9.'].indexOf(process.version.slice(0, 5)) > -1 ? setImmediate : processNextTick; /**/ Writable.WritableState = WritableState; - /**/ -var util = _dereq_('core-util-is'); -util.inherits = _dereq_('inherits'); +var util = _dereq_(10); +util.inherits = _dereq_(14); /**/ - /**/ var internalUtil = { - deprecate: _dereq_('util-deprecate') + deprecate: _dereq_(58) }; /**/ - - /**/ var Stream; -(function (){try{ - Stream = _dereq_('st' + 'ream'); -}catch(_){}finally{ - if (!Stream) - Stream = _dereq_('events').EventEmitter; -}}()) +(function () { + try { + Stream = _dereq_('st' + 'ream'); + } catch (_) {} finally { + if (!Stream) Stream = _dereq_(11).EventEmitter; + } +})(); /**/ -var Buffer = _dereq_('buffer').Buffer; +var Buffer = _dereq_(8).Buffer; +/**/ +var bufferShim = _dereq_(7); +/**/ util.inherits(Writable, Stream); @@ -7263,7 +7198,7 @@ function WriteReq(chunk, encoding, cb) { var Duplex; function WritableState(options, stream) { - Duplex = Duplex || _dereq_('./_stream_duplex'); + Duplex = Duplex || _dereq_(41); options = options || {}; @@ -7271,18 +7206,17 @@ function WritableState(options, stream) { // contains buffers or objects. this.objectMode = !!options.objectMode; - if (stream instanceof Duplex) - this.objectMode = this.objectMode || !!options.writableObjectMode; + if (stream instanceof Duplex) this.objectMode = this.objectMode || !!options.writableObjectMode; // the point at which write() starts returning false // Note: 0 is a valid value, means that we always return false if // the entire buffer is not flushed immediately on write() var hwm = options.highWaterMark; var defaultHwm = this.objectMode ? 16 : 16 * 1024; - this.highWaterMark = (hwm || hwm === 0) ? hwm : defaultHwm; + this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm; // cast to ints. - this.highWaterMark = ~~this.highWaterMark; + this.highWaterMark = ~ ~this.highWaterMark; this.needDrain = false; // at the start of calling end() @@ -7326,7 +7260,7 @@ function WritableState(options, stream) { this.bufferProcessing = false; // the callback that's passed to _write(chunk,cb) - this.onwrite = function(er) { + this.onwrite = function (er) { onwrite(stream, er); }; @@ -7349,6 +7283,13 @@ function WritableState(options, stream) { // True if the error was already emitted and should not be thrown again this.errorEmitted = false; + + // count buffered requests + this.bufferedRequestCount = 0; + + // allocate the first CorkedRequest, there is always + // one allocated and free to use, and we maintain at most two + this.corkedRequestsFree = new CorkedRequest(this); } WritableState.prototype.getBuffer = function writableStateGetBuffer() { @@ -7361,24 +7302,23 @@ WritableState.prototype.getBuffer = function writableStateGetBuffer() { return out; }; -(function (){try { -Object.defineProperty(WritableState.prototype, 'buffer', { - get: internalUtil.deprecate(function() { - return this.getBuffer(); - }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + - 'instead.') -}); -}catch(_){}}()); - +(function () { + try { + Object.defineProperty(WritableState.prototype, 'buffer', { + get: internalUtil.deprecate(function () { + return this.getBuffer(); + }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.') + }); + } catch (_) {} +})(); var Duplex; function Writable(options) { - Duplex = Duplex || _dereq_('./_stream_duplex'); + Duplex = Duplex || _dereq_(41); // Writable ctor is applied to Duplexes, though they're not // instanceof Writable, they're instanceof Readable. - if (!(this instanceof Writable) && !(this instanceof Duplex)) - return new Writable(options); + if (!(this instanceof Writable) && !(this instanceof Duplex)) return new Writable(options); this._writableState = new WritableState(options, this); @@ -7386,22 +7326,19 @@ function Writable(options) { this.writable = true; if (options) { - if (typeof options.write === 'function') - this._write = options.write; + if (typeof options.write === 'function') this._write = options.write; - if (typeof options.writev === 'function') - this._writev = options.writev; + if (typeof options.writev === 'function') this._writev = options.writev; } Stream.call(this); } // Otherwise people can pipe Writable streams, which is just wrong. -Writable.prototype.pipe = function() { - this.emit('error', new Error('Cannot pipe. Not readable.')); +Writable.prototype.pipe = function () { + this.emit('error', new Error('Cannot pipe, not readable')); }; - function writeAfterEnd(stream, cb) { var er = new Error('write after end'); // TODO: defer error events consistently everywhere, not just the cb @@ -7416,13 +7353,16 @@ function writeAfterEnd(stream, cb) { // how many bytes or characters. function validChunk(stream, state, chunk, cb) { var valid = true; - - if (!(Buffer.isBuffer(chunk)) && - typeof chunk !== 'string' && - chunk !== null && - chunk !== undefined && - !state.objectMode) { - var er = new TypeError('Invalid non-string/buffer chunk'); + var er = false; + // Always throw error if a null is written + // if we are not in object mode then throw + // if it is not a buffer, string, or undefined. + if (chunk === null) { + er = new TypeError('May not write null values to stream'); + } else if (!Buffer.isBuffer(chunk) && typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) { + er = new TypeError('Invalid non-string/buffer chunk'); + } + if (er) { stream.emit('error', er); processNextTick(cb, er); valid = false; @@ -7430,7 +7370,7 @@ function validChunk(stream, state, chunk, cb) { return valid; } -Writable.prototype.write = function(chunk, encoding, cb) { +Writable.prototype.write = function (chunk, encoding, cb) { var state = this._writableState; var ret = false; @@ -7439,17 +7379,11 @@ Writable.prototype.write = function(chunk, encoding, cb) { encoding = null; } - if (Buffer.isBuffer(chunk)) - encoding = 'buffer'; - else if (!encoding) - encoding = state.defaultEncoding; + if (Buffer.isBuffer(chunk)) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding; - if (typeof cb !== 'function') - cb = nop; + if (typeof cb !== 'function') cb = nop; - if (state.ended) - writeAfterEnd(this, cb); - else if (validChunk(this, state, chunk, cb)) { + if (state.ended) writeAfterEnd(this, cb);else if (validChunk(this, state, chunk, cb)) { state.pendingcb++; ret = writeOrBuffer(this, state, chunk, encoding, cb); } @@ -7457,43 +7391,33 @@ Writable.prototype.write = function(chunk, encoding, cb) { return ret; }; -Writable.prototype.cork = function() { +Writable.prototype.cork = function () { var state = this._writableState; state.corked++; }; -Writable.prototype.uncork = function() { +Writable.prototype.uncork = function () { var state = this._writableState; if (state.corked) { state.corked--; - if (!state.writing && - !state.corked && - !state.finished && - !state.bufferProcessing && - state.bufferedRequest) - clearBuffer(this, state); + if (!state.writing && !state.corked && !state.finished && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state); } }; Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) { // node::ParseEncoding() requires lower case. - if (typeof encoding === 'string') - encoding = encoding.toLowerCase(); - if (!(['hex', 'utf8', 'utf-8', 'ascii', 'binary', 'base64', -'ucs2', 'ucs-2','utf16le', 'utf-16le', 'raw'] -.indexOf((encoding + '').toLowerCase()) > -1)) - throw new TypeError('Unknown encoding: ' + encoding); + if (typeof encoding === 'string') encoding = encoding.toLowerCase(); + if (!(['hex', 'utf8', 'utf-8', 'ascii', 'binary', 'base64', 'ucs2', 'ucs-2', 'utf16le', 'utf-16le', 'raw'].indexOf((encoding + '').toLowerCase()) > -1)) throw new TypeError('Unknown encoding: ' + encoding); this._writableState.defaultEncoding = encoding; + return this; }; function decodeChunk(state, chunk, encoding) { - if (!state.objectMode && - state.decodeStrings !== false && - typeof chunk === 'string') { - chunk = new Buffer(chunk, encoding); + if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') { + chunk = bufferShim.from(chunk, encoding); } return chunk; } @@ -7504,16 +7428,14 @@ function decodeChunk(state, chunk, encoding) { function writeOrBuffer(stream, state, chunk, encoding, cb) { chunk = decodeChunk(state, chunk, encoding); - if (Buffer.isBuffer(chunk)) - encoding = 'buffer'; + if (Buffer.isBuffer(chunk)) encoding = 'buffer'; var len = state.objectMode ? 1 : chunk.length; state.length += len; var ret = state.length < state.highWaterMark; // we must ensure that previous needDrain will not be reset to false. - if (!ret) - state.needDrain = true; + if (!ret) state.needDrain = true; if (state.writing || state.corked) { var last = state.lastBufferedRequest; @@ -7523,6 +7445,7 @@ function writeOrBuffer(stream, state, chunk, encoding, cb) { } else { state.bufferedRequest = state.lastBufferedRequest; } + state.bufferedRequestCount += 1; } else { doWrite(stream, state, false, len, chunk, encoding, cb); } @@ -7535,19 +7458,13 @@ function doWrite(stream, state, writev, len, chunk, encoding, cb) { state.writecb = cb; state.writing = true; state.sync = true; - if (writev) - stream._writev(chunk, state.onwrite); - else - stream._write(chunk, encoding, state.onwrite); + if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite); state.sync = false; } function onwriteError(stream, state, sync, er, cb) { --state.pendingcb; - if (sync) - processNextTick(cb, er); - else - cb(er); + if (sync) processNextTick(cb, er);else cb(er); stream._writableState.errorEmitted = true; stream.emit('error', er); @@ -7567,30 +7484,26 @@ function onwrite(stream, er) { onwriteStateUpdate(state); - if (er) - onwriteError(stream, state, sync, er, cb); - else { + if (er) onwriteError(stream, state, sync, er, cb);else { // Check if we're actually ready to finish, but don't emit yet var finished = needFinish(state); - if (!finished && - !state.corked && - !state.bufferProcessing && - state.bufferedRequest) { + if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) { clearBuffer(stream, state); } if (sync) { - processNextTick(afterWrite, stream, state, finished, cb); + /**/ + asyncWrite(afterWrite, stream, state, finished, cb); + /**/ } else { - afterWrite(stream, state, finished, cb); - } + afterWrite(stream, state, finished, cb); + } } } function afterWrite(stream, state, finished, cb) { - if (!finished) - onwriteDrain(stream, state); + if (!finished) onwriteDrain(stream, state); state.pendingcb--; cb(); finishMaybe(stream, state); @@ -7606,7 +7519,6 @@ function onwriteDrain(stream, state) { } } - // if there's something in the buffer waiting, then process it function clearBuffer(stream, state) { state.bufferProcessing = true; @@ -7614,26 +7526,30 @@ function clearBuffer(stream, state) { if (stream._writev && entry && entry.next) { // Fast case, write everything using _writev() - var buffer = []; - var cbs = []; + var l = state.bufferedRequestCount; + var buffer = new Array(l); + var holder = state.corkedRequestsFree; + holder.entry = entry; + + var count = 0; while (entry) { - cbs.push(entry.callback); - buffer.push(entry); + buffer[count] = entry; entry = entry.next; + count += 1; } - // count the one we are adding, as well. - // TODO(isaacs) clean this up + doWrite(stream, state, true, state.length, buffer, '', holder.finish); + + // doWrite is almost always async, defer these to save a bit of time + // as the hot path ends with doWrite state.pendingcb++; state.lastBufferedRequest = null; - doWrite(stream, state, true, state.length, buffer, '', function(err) { - for (var i = 0; i < cbs.length; i++) { - state.pendingcb--; - cbs[i](err); - } - }); - - // Clear buffer + if (holder.next) { + state.corkedRequestsFree = holder.next; + holder.next = null; + } else { + state.corkedRequestsFree = new CorkedRequest(state); + } } else { // Slow case, write chunks one-by-one while (entry) { @@ -7653,20 +7569,21 @@ function clearBuffer(stream, state) { } } - if (entry === null) - state.lastBufferedRequest = null; + if (entry === null) state.lastBufferedRequest = null; } + + state.bufferedRequestCount = 0; state.bufferedRequest = entry; state.bufferProcessing = false; } -Writable.prototype._write = function(chunk, encoding, cb) { +Writable.prototype._write = function (chunk, encoding, cb) { cb(new Error('not implemented')); }; Writable.prototype._writev = null; -Writable.prototype.end = function(chunk, encoding, cb) { +Writable.prototype.end = function (chunk, encoding, cb) { var state = this._writableState; if (typeof chunk === 'function') { @@ -7678,8 +7595,7 @@ Writable.prototype.end = function(chunk, encoding, cb) { encoding = null; } - if (chunk !== null && chunk !== undefined) - this.write(chunk, encoding); + if (chunk !== null && chunk !== undefined) this.write(chunk, encoding); // .end() fully uncorks if (state.corked) { @@ -7688,17 +7604,11 @@ Writable.prototype.end = function(chunk, encoding, cb) { } // ignore unnecessary end() calls. - if (!state.ending && !state.finished) - endWritable(this, state, cb); + if (!state.ending && !state.finished) endWritable(this, state, cb); }; - function needFinish(state) { - return (state.ending && - state.length === 0 && - state.bufferedRequest === null && - !state.finished && - !state.writing); + return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing; } function prefinish(stream, state) { @@ -7726,37 +7636,66 @@ function endWritable(stream, state, cb) { state.ending = true; finishMaybe(stream, state); if (cb) { - if (state.finished) - processNextTick(cb); - else - stream.once('finish', cb); + if (state.finished) processNextTick(cb);else stream.once('finish', cb); } state.ended = true; + stream.writable = false; } -},{"./_stream_duplex":62,"buffer":7,"core-util-is":9,"events":10,"inherits":13,"process-nextick-args":50,"util-deprecate":73}],67:[function(_dereq_,module,exports){ -module.exports = _dereq_("./lib/_stream_passthrough.js") +// It seems a linked list but it is not +// there will be only 2 of these for each stream +function CorkedRequest(state) { + var _this = this; + + this.next = null; + this.entry = null; + + this.finish = function (err) { + var entry = _this.entry; + _this.entry = null; + while (entry) { + var cb = entry.callback; + state.pendingcb--; + cb(err); + entry = entry.next; + } + if (state.corkedRequestsFree) { + state.corkedRequestsFree.next = _this; + } else { + state.corkedRequestsFree = _this; + } + }; +} +}).call(this,_dereq_(28)) +},{"10":10,"11":11,"14":14,"27":27,"28":28,"41":41,"58":58,"7":7,"8":8}],46:[function(_dereq_,module,exports){ +module.exports = _dereq_(42) -},{"./lib/_stream_passthrough.js":63}],68:[function(_dereq_,module,exports){ +},{"42":42}],47:[function(_dereq_,module,exports){ +(function (process){ var Stream = (function (){ try { return _dereq_('st' + 'ream'); // hack to fix a circular dependency issue when used with browserify } catch(_){} }()); -exports = module.exports = _dereq_('./lib/_stream_readable.js'); +exports = module.exports = _dereq_(43); exports.Stream = Stream || exports; exports.Readable = exports; -exports.Writable = _dereq_('./lib/_stream_writable.js'); -exports.Duplex = _dereq_('./lib/_stream_duplex.js'); -exports.Transform = _dereq_('./lib/_stream_transform.js'); -exports.PassThrough = _dereq_('./lib/_stream_passthrough.js'); +exports.Writable = _dereq_(45); +exports.Duplex = _dereq_(41); +exports.Transform = _dereq_(44); +exports.PassThrough = _dereq_(42); -},{"./lib/_stream_duplex.js":62,"./lib/_stream_passthrough.js":63,"./lib/_stream_readable.js":64,"./lib/_stream_transform.js":65,"./lib/_stream_writable.js":66}],69:[function(_dereq_,module,exports){ -arguments[4][58][0].apply(exports,arguments) -},{"./lib/_stream_transform.js":65,"dup":58}],70:[function(_dereq_,module,exports){ -module.exports = _dereq_("./lib/_stream_writable.js") +if (!process.browser && process.env.READABLE_STREAM === 'disable' && Stream) { + module.exports = Stream; +} + +}).call(this,_dereq_(28)) +},{"28":28,"41":41,"42":42,"43":43,"44":44,"45":45}],48:[function(_dereq_,module,exports){ +arguments[4][35][0].apply(exports,arguments) +},{"35":35,"44":44}],49:[function(_dereq_,module,exports){ +module.exports = _dereq_(45) -},{"./lib/_stream_writable.js":66}],71:[function(_dereq_,module,exports){ +},{"45":45}],50:[function(_dereq_,module,exports){ // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -7778,7 +7717,7 @@ module.exports = _dereq_("./lib/_stream_writable.js") // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE // USE OR OTHER DEALINGS IN THE SOFTWARE. -var Buffer = _dereq_('buffer').Buffer; +var Buffer = _dereq_(8).Buffer; var isBufferEncoding = Buffer.isEncoding || function(encoding) { @@ -7979,107 +7918,1598 @@ function base64DetectIncompleteChar(buffer) { this.charLength = this.charReceived ? 3 : 0; } -},{"buffer":7}],72:[function(_dereq_,module,exports){ +},{"8":8}],51:[function(_dereq_,module,exports){ +arguments[4][9][0].apply(exports,arguments) +},{"9":9}],52:[function(_dereq_,module,exports){ +arguments[4][41][0].apply(exports,arguments) +},{"10":10,"14":14,"27":27,"41":41,"53":53,"55":55}],53:[function(_dereq_,module,exports){ (function (process){ -var Transform = _dereq_('readable-stream/transform') - , inherits = _dereq_('util').inherits - , xtend = _dereq_('xtend') - -function DestroyableTransform(opts) { - Transform.call(this, opts) - this._destroyed = false -} +'use strict'; -inherits(DestroyableTransform, Transform) +module.exports = Readable; -DestroyableTransform.prototype.destroy = function(err) { - if (this._destroyed) return - this._destroyed = true - - var self = this - process.nextTick(function() { - if (err) - self.emit('error', err) - self.emit('close') - }) -} +/**/ +var processNextTick = _dereq_(27); +/**/ -// a noop _transform function -function noop (chunk, enc, callback) { - callback(null, chunk) -} +/**/ +var isArray = _dereq_(51); +/**/ +/**/ +var Buffer = _dereq_(8).Buffer; +/**/ -// create a new export function, used by both the main export and -// the .ctor export, contains common logic for dealing with arguments -function through2 (construct) { - return function (options, transform, flush) { - if (typeof options == 'function') { - flush = transform - transform = options - options = {} - } +Readable.ReadableState = ReadableState; - if (typeof transform != 'function') - transform = noop +var EE = _dereq_(11); - if (typeof flush != 'function') - flush = null +/**/ +var EElistenerCount = function (emitter, type) { + return emitter.listeners(type).length; +}; +/**/ - return construct(options, transform, flush) +/**/ +var Stream; +(function () { + try { + Stream = _dereq_('st' + 'ream'); + } catch (_) {} finally { + if (!Stream) Stream = _dereq_(11).EventEmitter; } +})(); +/**/ + +var Buffer = _dereq_(8).Buffer; + +/**/ +var util = _dereq_(10); +util.inherits = _dereq_(14); +/**/ + +/**/ +var debugUtil = _dereq_(6); +var debug = undefined; +if (debugUtil && debugUtil.debuglog) { + debug = debugUtil.debuglog('stream'); +} else { + debug = function () {}; } +/**/ +var StringDecoder; -// main export, just make me a transform stream! -module.exports = through2(function (options, transform, flush) { - var t2 = new DestroyableTransform(options) +util.inherits(Readable, Stream); - t2._transform = transform +var Duplex; +function ReadableState(options, stream) { + Duplex = Duplex || _dereq_(52); - if (flush) - t2._flush = flush + options = options || {}; - return t2 -}) + // object stream flag. Used to make read(n) ignore n and to + // make all the buffer merging and length checks go away + this.objectMode = !!options.objectMode; + if (stream instanceof Duplex) this.objectMode = this.objectMode || !!options.readableObjectMode; -// make me a reusable prototype that I can `new`, or implicitly `new` -// with a constructor call -module.exports.ctor = through2(function (options, transform, flush) { - function Through2 (override) { - if (!(this instanceof Through2)) - return new Through2(override) + // the point at which it stops calling _read() to fill the buffer + // Note: 0 is a valid value, means "don't call _read preemptively ever" + var hwm = options.highWaterMark; + var defaultHwm = this.objectMode ? 16 : 16 * 1024; + this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm; - this.options = xtend(options, override) + // cast to ints. + this.highWaterMark = ~ ~this.highWaterMark; - DestroyableTransform.call(this, this.options) - } + this.buffer = []; + this.length = 0; + this.pipes = null; + this.pipesCount = 0; + this.flowing = null; + this.ended = false; + this.endEmitted = false; + this.reading = false; - inherits(Through2, DestroyableTransform) + // a flag to be able to tell if the onwrite cb is called immediately, + // or on a later tick. We set this to true at first, because any + // actions that shouldn't happen until "later" should generally also + // not happen before the first write call. + this.sync = true; - Through2.prototype._transform = transform + // whenever we return null, then we set a flag to say + // that we're awaiting a 'readable' event emission. + this.needReadable = false; + this.emittedReadable = false; + this.readableListening = false; + this.resumeScheduled = false; - if (flush) - Through2.prototype._flush = flush + // Crypto is kind of old and crusty. Historically, its default string + // encoding is 'binary' so we have to make this configurable. + // Everything else in the universe uses 'utf8', though. + this.defaultEncoding = options.defaultEncoding || 'utf8'; - return Through2 -}) + // when piping, we only care about 'readable' events that happen + // after read()ing all the bytes and not getting any pushback. + this.ranOut = false; + // the number of writers that are awaiting a drain event in .pipe()s + this.awaitDrain = 0; -module.exports.obj = through2(function (options, transform, flush) { - var t2 = new DestroyableTransform(xtend({ objectMode: true, highWaterMark: 16 }, options)) + // if true, a maybeReadMore has been scheduled + this.readingMore = false; - t2._transform = transform + this.decoder = null; + this.encoding = null; + if (options.encoding) { + if (!StringDecoder) StringDecoder = _dereq_(50).StringDecoder; + this.decoder = new StringDecoder(options.encoding); + this.encoding = options.encoding; + } +} - if (flush) - t2._flush = flush +var Duplex; +function Readable(options) { + Duplex = Duplex || _dereq_(52); - return t2 -}) + if (!(this instanceof Readable)) return new Readable(options); + + this._readableState = new ReadableState(options, this); -}).call(this,_dereq_('_process')) -},{"_process":51,"readable-stream/transform":58,"util":75,"xtend":76}],73:[function(_dereq_,module,exports){ + // legacy + this.readable = true; + + if (options && typeof options.read === 'function') this._read = options.read; + + Stream.call(this); +} + +// Manually shove something into the read() buffer. +// This returns true if the highWaterMark has not been hit yet, +// similar to how Writable.write() returns true if you should +// write() some more. +Readable.prototype.push = function (chunk, encoding) { + var state = this._readableState; + + if (!state.objectMode && typeof chunk === 'string') { + encoding = encoding || state.defaultEncoding; + if (encoding !== state.encoding) { + chunk = new Buffer(chunk, encoding); + encoding = ''; + } + } + + return readableAddChunk(this, state, chunk, encoding, false); +}; + +// Unshift should *always* be something directly out of read() +Readable.prototype.unshift = function (chunk) { + var state = this._readableState; + return readableAddChunk(this, state, chunk, '', true); +}; + +Readable.prototype.isPaused = function () { + return this._readableState.flowing === false; +}; + +function readableAddChunk(stream, state, chunk, encoding, addToFront) { + var er = chunkInvalid(state, chunk); + if (er) { + stream.emit('error', er); + } else if (chunk === null) { + state.reading = false; + onEofChunk(stream, state); + } else if (state.objectMode || chunk && chunk.length > 0) { + if (state.ended && !addToFront) { + var e = new Error('stream.push() after EOF'); + stream.emit('error', e); + } else if (state.endEmitted && addToFront) { + var e = new Error('stream.unshift() after end event'); + stream.emit('error', e); + } else { + var skipAdd; + if (state.decoder && !addToFront && !encoding) { + chunk = state.decoder.write(chunk); + skipAdd = !state.objectMode && chunk.length === 0; + } + + if (!addToFront) state.reading = false; + + // Don't add to the buffer if we've decoded to an empty string chunk and + // we're not in object mode + if (!skipAdd) { + // if we want the data now, just emit it. + if (state.flowing && state.length === 0 && !state.sync) { + stream.emit('data', chunk); + stream.read(0); + } else { + // update the buffer info. + state.length += state.objectMode ? 1 : chunk.length; + if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk); + + if (state.needReadable) emitReadable(stream); + } + } + + maybeReadMore(stream, state); + } + } else if (!addToFront) { + state.reading = false; + } + + return needMoreData(state); +} + +// if it's past the high water mark, we can push in some more. +// Also, if we have no data yet, we can stand some +// more bytes. This is to work around cases where hwm=0, +// such as the repl. Also, if the push() triggered a +// readable event, and the user called read(largeNumber) such that +// needReadable was set, then we ought to push more, so that another +// 'readable' event will be triggered. +function needMoreData(state) { + return !state.ended && (state.needReadable || state.length < state.highWaterMark || state.length === 0); +} + +// backwards compatibility. +Readable.prototype.setEncoding = function (enc) { + if (!StringDecoder) StringDecoder = _dereq_(50).StringDecoder; + this._readableState.decoder = new StringDecoder(enc); + this._readableState.encoding = enc; + return this; +}; + +// Don't raise the hwm > 8MB +var MAX_HWM = 0x800000; +function computeNewHighWaterMark(n) { + if (n >= MAX_HWM) { + n = MAX_HWM; + } else { + // Get the next highest power of 2 + n--; + n |= n >>> 1; + n |= n >>> 2; + n |= n >>> 4; + n |= n >>> 8; + n |= n >>> 16; + n++; + } + return n; +} + +function howMuchToRead(n, state) { + if (state.length === 0 && state.ended) return 0; + + if (state.objectMode) return n === 0 ? 0 : 1; + + if (n === null || isNaN(n)) { + // only flow one buffer at a time + if (state.flowing && state.buffer.length) return state.buffer[0].length;else return state.length; + } + + if (n <= 0) return 0; + + // If we're asking for more than the target buffer level, + // then raise the water mark. Bump up to the next highest + // power of 2, to prevent increasing it excessively in tiny + // amounts. + if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n); + + // don't have that much. return null, unless we've ended. + if (n > state.length) { + if (!state.ended) { + state.needReadable = true; + return 0; + } else { + return state.length; + } + } + + return n; +} + +// you can override either this method, or the async _read(n) below. +Readable.prototype.read = function (n) { + debug('read', n); + var state = this._readableState; + var nOrig = n; + + if (typeof n !== 'number' || n > 0) state.emittedReadable = false; + + // if we're doing read(0) to trigger a readable event, but we + // already have a bunch of data in the buffer, then just trigger + // the 'readable' event and move on. + if (n === 0 && state.needReadable && (state.length >= state.highWaterMark || state.ended)) { + debug('read: emitReadable', state.length, state.ended); + if (state.length === 0 && state.ended) endReadable(this);else emitReadable(this); + return null; + } + + n = howMuchToRead(n, state); + + // if we've ended, and we're now clear, then finish it up. + if (n === 0 && state.ended) { + if (state.length === 0) endReadable(this); + return null; + } + + // All the actual chunk generation logic needs to be + // *below* the call to _read. The reason is that in certain + // synthetic stream cases, such as passthrough streams, _read + // may be a completely synchronous operation which may change + // the state of the read buffer, providing enough data when + // before there was *not* enough. + // + // So, the steps are: + // 1. Figure out what the state of things will be after we do + // a read from the buffer. + // + // 2. If that resulting state will trigger a _read, then call _read. + // Note that this may be asynchronous, or synchronous. Yes, it is + // deeply ugly to write APIs this way, but that still doesn't mean + // that the Readable class should behave improperly, as streams are + // designed to be sync/async agnostic. + // Take note if the _read call is sync or async (ie, if the read call + // has returned yet), so that we know whether or not it's safe to emit + // 'readable' etc. + // + // 3. Actually pull the requested chunks out of the buffer and return. + + // if we need a readable event, then we need to do some reading. + var doRead = state.needReadable; + debug('need readable', doRead); + + // if we currently have less than the highWaterMark, then also read some + if (state.length === 0 || state.length - n < state.highWaterMark) { + doRead = true; + debug('length less than watermark', doRead); + } + + // however, if we've ended, then there's no point, and if we're already + // reading, then it's unnecessary. + if (state.ended || state.reading) { + doRead = false; + debug('reading or ended', doRead); + } + + if (doRead) { + debug('do read'); + state.reading = true; + state.sync = true; + // if the length is currently zero, then we *need* a readable event. + if (state.length === 0) state.needReadable = true; + // call internal read method + this._read(state.highWaterMark); + state.sync = false; + } + + // If _read pushed data synchronously, then `reading` will be false, + // and we need to re-evaluate how much data we can return to the user. + if (doRead && !state.reading) n = howMuchToRead(nOrig, state); + + var ret; + if (n > 0) ret = fromList(n, state);else ret = null; + + if (ret === null) { + state.needReadable = true; + n = 0; + } + + state.length -= n; + + // If we have nothing in the buffer, then we want to know + // as soon as we *do* get something into the buffer. + if (state.length === 0 && !state.ended) state.needReadable = true; + + // If we tried to read() past the EOF, then emit end on the next tick. + if (nOrig !== n && state.ended && state.length === 0) endReadable(this); + + if (ret !== null) this.emit('data', ret); + + return ret; +}; + +function chunkInvalid(state, chunk) { + var er = null; + if (!Buffer.isBuffer(chunk) && typeof chunk !== 'string' && chunk !== null && chunk !== undefined && !state.objectMode) { + er = new TypeError('Invalid non-string/buffer chunk'); + } + return er; +} + +function onEofChunk(stream, state) { + if (state.ended) return; + if (state.decoder) { + var chunk = state.decoder.end(); + if (chunk && chunk.length) { + state.buffer.push(chunk); + state.length += state.objectMode ? 1 : chunk.length; + } + } + state.ended = true; + + // emit 'readable' now to make sure it gets picked up. + emitReadable(stream); +} + +// Don't emit readable right away in sync mode, because this can trigger +// another read() call => stack overflow. This way, it might trigger +// a nextTick recursion warning, but that's not so bad. +function emitReadable(stream) { + var state = stream._readableState; + state.needReadable = false; + if (!state.emittedReadable) { + debug('emitReadable', state.flowing); + state.emittedReadable = true; + if (state.sync) processNextTick(emitReadable_, stream);else emitReadable_(stream); + } +} + +function emitReadable_(stream) { + debug('emit readable'); + stream.emit('readable'); + flow(stream); +} + +// at this point, the user has presumably seen the 'readable' event, +// and called read() to consume some data. that may have triggered +// in turn another _read(n) call, in which case reading = true if +// it's in progress. +// However, if we're not ended, or reading, and the length < hwm, +// then go ahead and try to read some more preemptively. +function maybeReadMore(stream, state) { + if (!state.readingMore) { + state.readingMore = true; + processNextTick(maybeReadMore_, stream, state); + } +} + +function maybeReadMore_(stream, state) { + var len = state.length; + while (!state.reading && !state.flowing && !state.ended && state.length < state.highWaterMark) { + debug('maybeReadMore read 0'); + stream.read(0); + if (len === state.length) + // didn't get any data, stop spinning. + break;else len = state.length; + } + state.readingMore = false; +} + +// abstract method. to be overridden in specific implementation classes. +// call cb(er, data) where data is <= n in length. +// for virtual (non-string, non-buffer) streams, "length" is somewhat +// arbitrary, and perhaps not very meaningful. +Readable.prototype._read = function (n) { + this.emit('error', new Error('not implemented')); +}; + +Readable.prototype.pipe = function (dest, pipeOpts) { + var src = this; + var state = this._readableState; + + switch (state.pipesCount) { + case 0: + state.pipes = dest; + break; + case 1: + state.pipes = [state.pipes, dest]; + break; + default: + state.pipes.push(dest); + break; + } + state.pipesCount += 1; + debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts); + + var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr; + + var endFn = doEnd ? onend : cleanup; + if (state.endEmitted) processNextTick(endFn);else src.once('end', endFn); + + dest.on('unpipe', onunpipe); + function onunpipe(readable) { + debug('onunpipe'); + if (readable === src) { + cleanup(); + } + } + + function onend() { + debug('onend'); + dest.end(); + } + + // when the dest drains, it reduces the awaitDrain counter + // on the source. This would be more elegant with a .once() + // handler in flow(), but adding and removing repeatedly is + // too slow. + var ondrain = pipeOnDrain(src); + dest.on('drain', ondrain); + + var cleanedUp = false; + function cleanup() { + debug('cleanup'); + // cleanup event handlers once the pipe is broken + dest.removeListener('close', onclose); + dest.removeListener('finish', onfinish); + dest.removeListener('drain', ondrain); + dest.removeListener('error', onerror); + dest.removeListener('unpipe', onunpipe); + src.removeListener('end', onend); + src.removeListener('end', cleanup); + src.removeListener('data', ondata); + + cleanedUp = true; + + // if the reader is waiting for a drain event from this + // specific writer, then it would cause it to never start + // flowing again. + // So, if this is awaiting a drain, then we just call it now. + // If we don't know, then assume that we are waiting for one. + if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain(); + } + + src.on('data', ondata); + function ondata(chunk) { + debug('ondata'); + var ret = dest.write(chunk); + if (false === ret) { + // If the user unpiped during `dest.write()`, it is possible + // to get stuck in a permanently paused state if that write + // also returned false. + if (state.pipesCount === 1 && state.pipes[0] === dest && src.listenerCount('data') === 1 && !cleanedUp) { + debug('false write response, pause', src._readableState.awaitDrain); + src._readableState.awaitDrain++; + } + src.pause(); + } + } + + // if the dest has an error, then stop piping into it. + // however, don't suppress the throwing behavior for this. + function onerror(er) { + debug('onerror', er); + unpipe(); + dest.removeListener('error', onerror); + if (EElistenerCount(dest, 'error') === 0) dest.emit('error', er); + } + // This is a brutally ugly hack to make sure that our error handler + // is attached before any userland ones. NEVER DO THIS. + if (!dest._events || !dest._events.error) dest.on('error', onerror);else if (isArray(dest._events.error)) dest._events.error.unshift(onerror);else dest._events.error = [onerror, dest._events.error]; + + // Both close and finish should trigger unpipe, but only once. + function onclose() { + dest.removeListener('finish', onfinish); + unpipe(); + } + dest.once('close', onclose); + function onfinish() { + debug('onfinish'); + dest.removeListener('close', onclose); + unpipe(); + } + dest.once('finish', onfinish); + + function unpipe() { + debug('unpipe'); + src.unpipe(dest); + } + + // tell the dest that it's being piped to + dest.emit('pipe', src); + + // start the flow if it hasn't been started already. + if (!state.flowing) { + debug('pipe resume'); + src.resume(); + } + + return dest; +}; + +function pipeOnDrain(src) { + return function () { + var state = src._readableState; + debug('pipeOnDrain', state.awaitDrain); + if (state.awaitDrain) state.awaitDrain--; + if (state.awaitDrain === 0 && EElistenerCount(src, 'data')) { + state.flowing = true; + flow(src); + } + }; +} + +Readable.prototype.unpipe = function (dest) { + var state = this._readableState; + + // if we're not piping anywhere, then do nothing. + if (state.pipesCount === 0) return this; + + // just one destination. most common case. + if (state.pipesCount === 1) { + // passed in one, but it's not the right one. + if (dest && dest !== state.pipes) return this; + + if (!dest) dest = state.pipes; + + // got a match. + state.pipes = null; + state.pipesCount = 0; + state.flowing = false; + if (dest) dest.emit('unpipe', this); + return this; + } + + // slow case. multiple pipe destinations. + + if (!dest) { + // remove all. + var dests = state.pipes; + var len = state.pipesCount; + state.pipes = null; + state.pipesCount = 0; + state.flowing = false; + + for (var _i = 0; _i < len; _i++) { + dests[_i].emit('unpipe', this); + }return this; + } + + // try to find the right one. + var i = indexOf(state.pipes, dest); + if (i === -1) return this; + + state.pipes.splice(i, 1); + state.pipesCount -= 1; + if (state.pipesCount === 1) state.pipes = state.pipes[0]; + + dest.emit('unpipe', this); + + return this; +}; + +// set up data events if they are asked for +// Ensure readable listeners eventually get something +Readable.prototype.on = function (ev, fn) { + var res = Stream.prototype.on.call(this, ev, fn); + + // If listening to data, and it has not explicitly been paused, + // then call resume to start the flow of data on the next tick. + if (ev === 'data' && false !== this._readableState.flowing) { + this.resume(); + } + + if (ev === 'readable' && !this._readableState.endEmitted) { + var state = this._readableState; + if (!state.readableListening) { + state.readableListening = true; + state.emittedReadable = false; + state.needReadable = true; + if (!state.reading) { + processNextTick(nReadingNextTick, this); + } else if (state.length) { + emitReadable(this, state); + } + } + } + + return res; +}; +Readable.prototype.addListener = Readable.prototype.on; + +function nReadingNextTick(self) { + debug('readable nexttick read 0'); + self.read(0); +} + +// pause() and resume() are remnants of the legacy readable stream API +// If the user uses them, then switch into old mode. +Readable.prototype.resume = function () { + var state = this._readableState; + if (!state.flowing) { + debug('resume'); + state.flowing = true; + resume(this, state); + } + return this; +}; + +function resume(stream, state) { + if (!state.resumeScheduled) { + state.resumeScheduled = true; + processNextTick(resume_, stream, state); + } +} + +function resume_(stream, state) { + if (!state.reading) { + debug('resume read 0'); + stream.read(0); + } + + state.resumeScheduled = false; + stream.emit('resume'); + flow(stream); + if (state.flowing && !state.reading) stream.read(0); +} + +Readable.prototype.pause = function () { + debug('call pause flowing=%j', this._readableState.flowing); + if (false !== this._readableState.flowing) { + debug('pause'); + this._readableState.flowing = false; + this.emit('pause'); + } + return this; +}; + +function flow(stream) { + var state = stream._readableState; + debug('flow', state.flowing); + if (state.flowing) { + do { + var chunk = stream.read(); + } while (null !== chunk && state.flowing); + } +} + +// wrap an old-style stream as the async data source. +// This is *not* part of the readable stream interface. +// It is an ugly unfortunate mess of history. +Readable.prototype.wrap = function (stream) { + var state = this._readableState; + var paused = false; + + var self = this; + stream.on('end', function () { + debug('wrapped end'); + if (state.decoder && !state.ended) { + var chunk = state.decoder.end(); + if (chunk && chunk.length) self.push(chunk); + } + + self.push(null); + }); + + stream.on('data', function (chunk) { + debug('wrapped data'); + if (state.decoder) chunk = state.decoder.write(chunk); + + // don't skip over falsy values in objectMode + if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return; + + var ret = self.push(chunk); + if (!ret) { + paused = true; + stream.pause(); + } + }); + + // proxy all the other methods. + // important when wrapping filters and duplexes. + for (var i in stream) { + if (this[i] === undefined && typeof stream[i] === 'function') { + this[i] = function (method) { + return function () { + return stream[method].apply(stream, arguments); + }; + }(i); + } + } + + // proxy certain important events. + var events = ['error', 'close', 'destroy', 'pause', 'resume']; + forEach(events, function (ev) { + stream.on(ev, self.emit.bind(self, ev)); + }); + + // when we try to consume some more bytes, simply unpause the + // underlying stream. + self._read = function (n) { + debug('wrapped _read', n); + if (paused) { + paused = false; + stream.resume(); + } + }; + + return self; +}; + +// exposed for testing purposes only. +Readable._fromList = fromList; + +// Pluck off n bytes from an array of buffers. +// Length is the combined lengths of all the buffers in the list. +function fromList(n, state) { + var list = state.buffer; + var length = state.length; + var stringMode = !!state.decoder; + var objectMode = !!state.objectMode; + var ret; + + // nothing in the list, definitely empty. + if (list.length === 0) return null; + + if (length === 0) ret = null;else if (objectMode) ret = list.shift();else if (!n || n >= length) { + // read it all, truncate the array. + if (stringMode) ret = list.join('');else if (list.length === 1) ret = list[0];else ret = Buffer.concat(list, length); + list.length = 0; + } else { + // read just some of it. + if (n < list[0].length) { + // just take a part of the first list item. + // slice is the same for buffers and strings. + var buf = list[0]; + ret = buf.slice(0, n); + list[0] = buf.slice(n); + } else if (n === list[0].length) { + // first list is a perfect match + ret = list.shift(); + } else { + // complex case. + // we have enough to cover it, but it spans past the first buffer. + if (stringMode) ret = '';else ret = new Buffer(n); + + var c = 0; + for (var i = 0, l = list.length; i < l && c < n; i++) { + var buf = list[0]; + var cpy = Math.min(n - c, buf.length); + + if (stringMode) ret += buf.slice(0, cpy);else buf.copy(ret, c, 0, cpy); + + if (cpy < buf.length) list[0] = buf.slice(cpy);else list.shift(); + + c += cpy; + } + } + } + + return ret; +} + +function endReadable(stream) { + var state = stream._readableState; + + // If we get here before consuming all the bytes, then that is a + // bug in node. Should never happen. + if (state.length > 0) throw new Error('endReadable called on non-empty stream'); + + if (!state.endEmitted) { + state.ended = true; + processNextTick(endReadableNT, state, stream); + } +} + +function endReadableNT(state, stream) { + // Check that we didn't get one last unshift. + if (!state.endEmitted && state.length === 0) { + state.endEmitted = true; + stream.readable = false; + stream.emit('end'); + } +} + +function forEach(xs, f) { + for (var i = 0, l = xs.length; i < l; i++) { + f(xs[i], i); + } +} + +function indexOf(xs, x) { + for (var i = 0, l = xs.length; i < l; i++) { + if (xs[i] === x) return i; + } + return -1; +} +}).call(this,_dereq_(28)) +},{"10":10,"11":11,"14":14,"27":27,"28":28,"50":50,"51":51,"52":52,"6":6,"8":8}],54:[function(_dereq_,module,exports){ +// a transform stream is a readable/writable stream where you do +// something with the data. Sometimes it's called a "filter", +// but that's not a great name for it, since that implies a thing where +// some bits pass through, and others are simply ignored. (That would +// be a valid example of a transform, of course.) +// +// While the output is causally related to the input, it's not a +// necessarily symmetric or synchronous transformation. For example, +// a zlib stream might take multiple plain-text writes(), and then +// emit a single compressed chunk some time in the future. +// +// Here's how this works: +// +// The Transform stream has all the aspects of the readable and writable +// stream classes. When you write(chunk), that calls _write(chunk,cb) +// internally, and returns false if there's a lot of pending writes +// buffered up. When you call read(), that calls _read(n) until +// there's enough pending readable data buffered up. +// +// In a transform stream, the written data is placed in a buffer. When +// _read(n) is called, it transforms the queued up data, calling the +// buffered _write cb's as it consumes chunks. If consuming a single +// written chunk would result in multiple output chunks, then the first +// outputted bit calls the readcb, and subsequent chunks just go into +// the read buffer, and will cause it to emit 'readable' if necessary. +// +// This way, back-pressure is actually determined by the reading side, +// since _read has to be called to start processing a new chunk. However, +// a pathological inflate type of transform can cause excessive buffering +// here. For example, imagine a stream where every byte of input is +// interpreted as an integer from 0-255, and then results in that many +// bytes of output. Writing the 4 bytes {ff,ff,ff,ff} would result in +// 1kb of data being output. In this case, you could write a very small +// amount of input, and end up with a very large amount of output. In +// such a pathological inflating mechanism, there'd be no way to tell +// the system to stop doing the transform. A single 4MB write could +// cause the system to run out of memory. +// +// However, even in such a pathological case, only a single written chunk +// would be consumed, and then the rest would wait (un-transformed) until +// the results of the previous transformed chunk were consumed. + +'use strict'; + +module.exports = Transform; + +var Duplex = _dereq_(52); + +/**/ +var util = _dereq_(10); +util.inherits = _dereq_(14); +/**/ + +util.inherits(Transform, Duplex); + +function TransformState(stream) { + this.afterTransform = function (er, data) { + return afterTransform(stream, er, data); + }; + + this.needTransform = false; + this.transforming = false; + this.writecb = null; + this.writechunk = null; + this.writeencoding = null; +} + +function afterTransform(stream, er, data) { + var ts = stream._transformState; + ts.transforming = false; + + var cb = ts.writecb; + + if (!cb) return stream.emit('error', new Error('no writecb in Transform class')); + + ts.writechunk = null; + ts.writecb = null; + + if (data !== null && data !== undefined) stream.push(data); + + cb(er); + + var rs = stream._readableState; + rs.reading = false; + if (rs.needReadable || rs.length < rs.highWaterMark) { + stream._read(rs.highWaterMark); + } +} + +function Transform(options) { + if (!(this instanceof Transform)) return new Transform(options); + + Duplex.call(this, options); + + this._transformState = new TransformState(this); + + // when the writable side finishes, then flush out anything remaining. + var stream = this; + + // start out asking for a readable event once data is transformed. + this._readableState.needReadable = true; + + // we have implemented the _read method, and done the other things + // that Readable wants before the first _read call, so unset the + // sync guard flag. + this._readableState.sync = false; + + if (options) { + if (typeof options.transform === 'function') this._transform = options.transform; + + if (typeof options.flush === 'function') this._flush = options.flush; + } + + this.once('prefinish', function () { + if (typeof this._flush === 'function') this._flush(function (er) { + done(stream, er); + });else done(stream); + }); +} + +Transform.prototype.push = function (chunk, encoding) { + this._transformState.needTransform = false; + return Duplex.prototype.push.call(this, chunk, encoding); +}; + +// This is the part where you do stuff! +// override this function in implementation classes. +// 'chunk' is an input chunk. +// +// Call `push(newChunk)` to pass along transformed output +// to the readable side. You may call 'push' zero or more times. +// +// Call `cb(err)` when you are done with this chunk. If you pass +// an error, then that'll put the hurt on the whole operation. If you +// never call cb(), then you'll never get another chunk. +Transform.prototype._transform = function (chunk, encoding, cb) { + throw new Error('not implemented'); +}; + +Transform.prototype._write = function (chunk, encoding, cb) { + var ts = this._transformState; + ts.writecb = cb; + ts.writechunk = chunk; + ts.writeencoding = encoding; + if (!ts.transforming) { + var rs = this._readableState; + if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) this._read(rs.highWaterMark); + } +}; + +// Doesn't matter what the args are here. +// _transform does all the work. +// That we got here means that the readable side wants more data. +Transform.prototype._read = function (n) { + var ts = this._transformState; + + if (ts.writechunk !== null && ts.writecb && !ts.transforming) { + ts.transforming = true; + this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform); + } else { + // mark that we need a transform, so that any data that comes in + // will get processed, now that we've asked for it. + ts.needTransform = true; + } +}; + +function done(stream, er) { + if (er) return stream.emit('error', er); + + // if there's nothing in the write buffer, then that means + // that nothing more will ever be provided + var ws = stream._writableState; + var ts = stream._transformState; + + if (ws.length) throw new Error('calling transform done when ws.length != 0'); + + if (ts.transforming) throw new Error('calling transform done when still transforming'); + + return stream.push(null); +} +},{"10":10,"14":14,"52":52}],55:[function(_dereq_,module,exports){ +(function (process){ +// A bit simpler than readable streams. +// Implement an async ._write(chunk, encoding, cb), and it'll handle all +// the drain event emission and buffering. + +'use strict'; + +module.exports = Writable; + +/**/ +var processNextTick = _dereq_(27); +/**/ + +/**/ +var asyncWrite = !process.browser && ['v0.10', 'v0.9.'].indexOf(process.version.slice(0, 5)) > -1 ? setImmediate : processNextTick; +/**/ + +/**/ +var Buffer = _dereq_(8).Buffer; +/**/ + +Writable.WritableState = WritableState; + +/**/ +var util = _dereq_(10); +util.inherits = _dereq_(14); +/**/ + +/**/ +var internalUtil = { + deprecate: _dereq_(58) +}; +/**/ + +/**/ +var Stream; +(function () { + try { + Stream = _dereq_('st' + 'ream'); + } catch (_) {} finally { + if (!Stream) Stream = _dereq_(11).EventEmitter; + } +})(); +/**/ + +var Buffer = _dereq_(8).Buffer; + +util.inherits(Writable, Stream); + +function nop() {} + +function WriteReq(chunk, encoding, cb) { + this.chunk = chunk; + this.encoding = encoding; + this.callback = cb; + this.next = null; +} + +var Duplex; +function WritableState(options, stream) { + Duplex = Duplex || _dereq_(52); + + options = options || {}; + + // object stream flag to indicate whether or not this stream + // contains buffers or objects. + this.objectMode = !!options.objectMode; + + if (stream instanceof Duplex) this.objectMode = this.objectMode || !!options.writableObjectMode; + + // the point at which write() starts returning false + // Note: 0 is a valid value, means that we always return false if + // the entire buffer is not flushed immediately on write() + var hwm = options.highWaterMark; + var defaultHwm = this.objectMode ? 16 : 16 * 1024; + this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm; + + // cast to ints. + this.highWaterMark = ~ ~this.highWaterMark; + + this.needDrain = false; + // at the start of calling end() + this.ending = false; + // when end() has been called, and returned + this.ended = false; + // when 'finish' is emitted + this.finished = false; + + // should we decode strings into buffers before passing to _write? + // this is here so that some node-core streams can optimize string + // handling at a lower level. + var noDecode = options.decodeStrings === false; + this.decodeStrings = !noDecode; + + // Crypto is kind of old and crusty. Historically, its default string + // encoding is 'binary' so we have to make this configurable. + // Everything else in the universe uses 'utf8', though. + this.defaultEncoding = options.defaultEncoding || 'utf8'; + + // not an actual buffer we keep track of, but a measurement + // of how much we're waiting to get pushed to some underlying + // socket or file. + this.length = 0; + + // a flag to see when we're in the middle of a write. + this.writing = false; + + // when true all writes will be buffered until .uncork() call + this.corked = 0; + + // a flag to be able to tell if the onwrite cb is called immediately, + // or on a later tick. We set this to true at first, because any + // actions that shouldn't happen until "later" should generally also + // not happen before the first write call. + this.sync = true; + + // a flag to know if we're processing previously buffered items, which + // may call the _write() callback in the same tick, so that we don't + // end up in an overlapped onwrite situation. + this.bufferProcessing = false; + + // the callback that's passed to _write(chunk,cb) + this.onwrite = function (er) { + onwrite(stream, er); + }; + + // the callback that the user supplies to write(chunk,encoding,cb) + this.writecb = null; + + // the amount that is being written when _write is called. + this.writelen = 0; + + this.bufferedRequest = null; + this.lastBufferedRequest = null; + + // number of pending user-supplied write callbacks + // this must be 0 before 'finish' can be emitted + this.pendingcb = 0; + + // emit prefinish if the only thing we're waiting for is _write cbs + // This is relevant for synchronous Transform streams + this.prefinished = false; + + // True if the error was already emitted and should not be thrown again + this.errorEmitted = false; + + // count buffered requests + this.bufferedRequestCount = 0; + + // create the two objects needed to store the corked requests + // they are not a linked list, as no new elements are inserted in there + this.corkedRequestsFree = new CorkedRequest(this); + this.corkedRequestsFree.next = new CorkedRequest(this); +} + +WritableState.prototype.getBuffer = function writableStateGetBuffer() { + var current = this.bufferedRequest; + var out = []; + while (current) { + out.push(current); + current = current.next; + } + return out; +}; + +(function () { + try { + Object.defineProperty(WritableState.prototype, 'buffer', { + get: internalUtil.deprecate(function () { + return this.getBuffer(); + }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.') + }); + } catch (_) {} +})(); + +var Duplex; +function Writable(options) { + Duplex = Duplex || _dereq_(52); + + // Writable ctor is applied to Duplexes, though they're not + // instanceof Writable, they're instanceof Readable. + if (!(this instanceof Writable) && !(this instanceof Duplex)) return new Writable(options); + + this._writableState = new WritableState(options, this); + + // legacy. + this.writable = true; + + if (options) { + if (typeof options.write === 'function') this._write = options.write; + + if (typeof options.writev === 'function') this._writev = options.writev; + } + + Stream.call(this); +} + +// Otherwise people can pipe Writable streams, which is just wrong. +Writable.prototype.pipe = function () { + this.emit('error', new Error('Cannot pipe. Not readable.')); +}; + +function writeAfterEnd(stream, cb) { + var er = new Error('write after end'); + // TODO: defer error events consistently everywhere, not just the cb + stream.emit('error', er); + processNextTick(cb, er); +} + +// If we get something that is not a buffer, string, null, or undefined, +// and we're not in objectMode, then that's an error. +// Otherwise stream chunks are all considered to be of length=1, and the +// watermarks determine how many objects to keep in the buffer, rather than +// how many bytes or characters. +function validChunk(stream, state, chunk, cb) { + var valid = true; + + if (!Buffer.isBuffer(chunk) && typeof chunk !== 'string' && chunk !== null && chunk !== undefined && !state.objectMode) { + var er = new TypeError('Invalid non-string/buffer chunk'); + stream.emit('error', er); + processNextTick(cb, er); + valid = false; + } + return valid; +} + +Writable.prototype.write = function (chunk, encoding, cb) { + var state = this._writableState; + var ret = false; + + if (typeof encoding === 'function') { + cb = encoding; + encoding = null; + } + + if (Buffer.isBuffer(chunk)) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding; + + if (typeof cb !== 'function') cb = nop; + + if (state.ended) writeAfterEnd(this, cb);else if (validChunk(this, state, chunk, cb)) { + state.pendingcb++; + ret = writeOrBuffer(this, state, chunk, encoding, cb); + } + + return ret; +}; + +Writable.prototype.cork = function () { + var state = this._writableState; + + state.corked++; +}; + +Writable.prototype.uncork = function () { + var state = this._writableState; + + if (state.corked) { + state.corked--; + + if (!state.writing && !state.corked && !state.finished && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state); + } +}; + +Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) { + // node::ParseEncoding() requires lower case. + if (typeof encoding === 'string') encoding = encoding.toLowerCase(); + if (!(['hex', 'utf8', 'utf-8', 'ascii', 'binary', 'base64', 'ucs2', 'ucs-2', 'utf16le', 'utf-16le', 'raw'].indexOf((encoding + '').toLowerCase()) > -1)) throw new TypeError('Unknown encoding: ' + encoding); + this._writableState.defaultEncoding = encoding; +}; + +function decodeChunk(state, chunk, encoding) { + if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') { + chunk = new Buffer(chunk, encoding); + } + return chunk; +} + +// if we're already writing something, then just put this +// in the queue, and wait our turn. Otherwise, call _write +// If we return false, then we need a drain event, so set that flag. +function writeOrBuffer(stream, state, chunk, encoding, cb) { + chunk = decodeChunk(state, chunk, encoding); + + if (Buffer.isBuffer(chunk)) encoding = 'buffer'; + var len = state.objectMode ? 1 : chunk.length; + + state.length += len; + + var ret = state.length < state.highWaterMark; + // we must ensure that previous needDrain will not be reset to false. + if (!ret) state.needDrain = true; + + if (state.writing || state.corked) { + var last = state.lastBufferedRequest; + state.lastBufferedRequest = new WriteReq(chunk, encoding, cb); + if (last) { + last.next = state.lastBufferedRequest; + } else { + state.bufferedRequest = state.lastBufferedRequest; + } + state.bufferedRequestCount += 1; + } else { + doWrite(stream, state, false, len, chunk, encoding, cb); + } + + return ret; +} + +function doWrite(stream, state, writev, len, chunk, encoding, cb) { + state.writelen = len; + state.writecb = cb; + state.writing = true; + state.sync = true; + if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite); + state.sync = false; +} + +function onwriteError(stream, state, sync, er, cb) { + --state.pendingcb; + if (sync) processNextTick(cb, er);else cb(er); + + stream._writableState.errorEmitted = true; + stream.emit('error', er); +} + +function onwriteStateUpdate(state) { + state.writing = false; + state.writecb = null; + state.length -= state.writelen; + state.writelen = 0; +} + +function onwrite(stream, er) { + var state = stream._writableState; + var sync = state.sync; + var cb = state.writecb; + + onwriteStateUpdate(state); + + if (er) onwriteError(stream, state, sync, er, cb);else { + // Check if we're actually ready to finish, but don't emit yet + var finished = needFinish(state); + + if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) { + clearBuffer(stream, state); + } + + if (sync) { + /**/ + asyncWrite(afterWrite, stream, state, finished, cb); + /**/ + } else { + afterWrite(stream, state, finished, cb); + } + } +} + +function afterWrite(stream, state, finished, cb) { + if (!finished) onwriteDrain(stream, state); + state.pendingcb--; + cb(); + finishMaybe(stream, state); +} + +// Must force callback to be called on nextTick, so that we don't +// emit 'drain' before the write() consumer gets the 'false' return +// value, and has a chance to attach a 'drain' listener. +function onwriteDrain(stream, state) { + if (state.length === 0 && state.needDrain) { + state.needDrain = false; + stream.emit('drain'); + } +} + +// if there's something in the buffer waiting, then process it +function clearBuffer(stream, state) { + state.bufferProcessing = true; + var entry = state.bufferedRequest; + + if (stream._writev && entry && entry.next) { + // Fast case, write everything using _writev() + var l = state.bufferedRequestCount; + var buffer = new Array(l); + var holder = state.corkedRequestsFree; + holder.entry = entry; + + var count = 0; + while (entry) { + buffer[count] = entry; + entry = entry.next; + count += 1; + } + + doWrite(stream, state, true, state.length, buffer, '', holder.finish); + + // doWrite is always async, defer these to save a bit of time + // as the hot path ends with doWrite + state.pendingcb++; + state.lastBufferedRequest = null; + state.corkedRequestsFree = holder.next; + holder.next = null; + } else { + // Slow case, write chunks one-by-one + while (entry) { + var chunk = entry.chunk; + var encoding = entry.encoding; + var cb = entry.callback; + var len = state.objectMode ? 1 : chunk.length; + + doWrite(stream, state, false, len, chunk, encoding, cb); + entry = entry.next; + // if we didn't call the onwrite immediately, then + // it means that we need to wait until it does. + // also, that means that the chunk and cb are currently + // being processed, so move the buffer counter past them. + if (state.writing) { + break; + } + } + + if (entry === null) state.lastBufferedRequest = null; + } + + state.bufferedRequestCount = 0; + state.bufferedRequest = entry; + state.bufferProcessing = false; +} + +Writable.prototype._write = function (chunk, encoding, cb) { + cb(new Error('not implemented')); +}; + +Writable.prototype._writev = null; + +Writable.prototype.end = function (chunk, encoding, cb) { + var state = this._writableState; + + if (typeof chunk === 'function') { + cb = chunk; + chunk = null; + encoding = null; + } else if (typeof encoding === 'function') { + cb = encoding; + encoding = null; + } + + if (chunk !== null && chunk !== undefined) this.write(chunk, encoding); + + // .end() fully uncorks + if (state.corked) { + state.corked = 1; + this.uncork(); + } + + // ignore unnecessary end() calls. + if (!state.ending && !state.finished) endWritable(this, state, cb); +}; + +function needFinish(state) { + return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing; +} + +function prefinish(stream, state) { + if (!state.prefinished) { + state.prefinished = true; + stream.emit('prefinish'); + } +} + +function finishMaybe(stream, state) { + var need = needFinish(state); + if (need) { + if (state.pendingcb === 0) { + prefinish(stream, state); + state.finished = true; + stream.emit('finish'); + } else { + prefinish(stream, state); + } + } + return need; +} + +function endWritable(stream, state, cb) { + state.ending = true; + finishMaybe(stream, state); + if (cb) { + if (state.finished) processNextTick(cb);else stream.once('finish', cb); + } + state.ended = true; + stream.writable = false; +} + +// It seems a linked list but it is not +// there will be only 2 of these for each stream +function CorkedRequest(state) { + var _this = this; + + this.next = null; + this.entry = null; + + this.finish = function (err) { + var entry = _this.entry; + _this.entry = null; + while (entry) { + var cb = entry.callback; + state.pendingcb--; + cb(err); + entry = entry.next; + } + if (state.corkedRequestsFree) { + state.corkedRequestsFree.next = _this; + } else { + state.corkedRequestsFree = _this; + } + }; +} +}).call(this,_dereq_(28)) +},{"10":10,"11":11,"14":14,"27":27,"28":28,"52":52,"58":58,"8":8}],56:[function(_dereq_,module,exports){ +arguments[4][35][0].apply(exports,arguments) +},{"35":35,"54":54}],57:[function(_dereq_,module,exports){ +arguments[4][18][0].apply(exports,arguments) +},{"18":18,"28":28,"56":56,"60":60,"61":61}],58:[function(_dereq_,module,exports){ (function (global){ /** @@ -8150,14 +9580,14 @@ function config (name) { } }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{}],74:[function(_dereq_,module,exports){ +},{}],59:[function(_dereq_,module,exports){ module.exports = function isBuffer(arg) { return arg && typeof arg === 'object' && typeof arg.copy === 'function' && typeof arg.fill === 'function' && typeof arg.readUInt8 === 'function'; } -},{}],75:[function(_dereq_,module,exports){ +},{}],60:[function(_dereq_,module,exports){ (function (process,global){ // Copyright Joyent, Inc. and other Node contributors. // @@ -8684,7 +10114,7 @@ function isPrimitive(arg) { } exports.isPrimitive = isPrimitive; -exports.isBuffer = _dereq_('./support/isBuffer'); +exports.isBuffer = _dereq_(59); function objectToString(o) { return Object.prototype.toString.call(o); @@ -8728,7 +10158,7 @@ exports.log = function() { * prototype. * @param {function} superCtor Constructor function to inherit prototype from. */ -exports.inherits = _dereq_('inherits'); +exports.inherits = _dereq_(14); exports._extend = function(origin, add) { // Don't do anything if add isn't an object @@ -8746,8 +10176,8 @@ function hasOwnProperty(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); } -}).call(this,_dereq_('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"./support/isBuffer":74,"_process":51,"inherits":13}],76:[function(_dereq_,module,exports){ +}).call(this,_dereq_(28),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"14":14,"28":28,"59":59}],61:[function(_dereq_,module,exports){ module.exports = extend var hasOwnProperty = Object.prototype.hasOwnProperty; @@ -8768,10 +10198,10 @@ function extend() { return target } -},{}],77:[function(_dereq_,module,exports){ +},{}],62:[function(_dereq_,module,exports){ module.exports={ "name": "pouchdb-replication-stream", - "version": "1.2.5", + "version": "1.2.7", "description": "PouchDB/CouchDB replication as a stream", "main": "lib/index.js", "repository": { @@ -8798,7 +10228,7 @@ module.exports={ "jshint": "jshint -c .jshintrc lib test/test.js", "test": "npm run jshint && ./bin/run-test.sh", "build": "mkdirp dist && npm run browserify && npm run min", - "browserify": "browserify . | ./bin/es3ify.js | derequire > dist/pouchdb.replication-stream.js", + "browserify": "browserify -p bundle-collapser/plugin -s PouchReplicationStream . | ./bin/es3ify.js | derequire > dist/pouchdb.replication-stream.js", "min": "uglifyjs dist/pouchdb.replication-stream.js -mc > dist/pouchdb.replication-stream.min.js", "dev": "browserify test/test.js > test/test-bundle.js && npm run dev-server", "dev-server": "./bin/dev-server.js", @@ -8808,14 +10238,15 @@ module.exports={ "argsarray": "0.0.1", "inherits": "~2.0.1", "ldjson-stream": "^1.2.1", - "lie": "^2.6.0", - "lodash": "^3.3.0", + "lodash.pick": "^4.0.0", + "pouchdb-promise": "^5.4.4", "pouch-stream": "^0.4.0", - "through2": "^0.6.1" + "through2": "^2.0.0" }, "devDependencies": { "bluebird": "^1.0.7", "browserify": "^11.2.0", + "bundle-collapser": "^1.2.1", "chai": "^3.3.0", "chai-as-promised": "^5.1.0", "derequire": "^2.0.0", @@ -8823,12 +10254,13 @@ module.exports={ "http-server": "~0.8.5", "istanbul": "^0.2.7", "jshint": "^2.3.0", + "lie": "^3.1.0", "memorystream": "^0.3.0", "mkdirp": "^0.5.0", "mocha": "~1.18", "noms": "0.0.0", "phantomjs": "^1.9.7-5", - "pouchdb": "^5.0.0", + "pouchdb-memory": "^1.0.0", "random-document-stream": "0.0.0", "request": "^2.36.0", "sauce-connect-launcher": "^0.4.2", @@ -8839,15 +10271,15 @@ module.exports={ } } -},{}],78:[function(_dereq_,module,exports){ +},{}],63:[function(_dereq_,module,exports){ 'use strict'; -var utils = _dereq_('./pouch-utils'); -var version = _dereq_('./version'); -var ldj = _dereq_('ldjson-stream'); -var through = _dereq_('through2').obj; -var pick = _dereq_('lodash/object/pick'); -var toBufferStream = _dereq_('./to-buffer-stream'); +var utils = _dereq_(1); +var version = _dereq_(3); +var ldj = _dereq_(17); +var through = _dereq_(57).obj; +var pick = _dereq_(19); +var toBufferStream = _dereq_(2); var DEFAULT_BATCH_SIZE = 50; // params to the replicate() API that the user is allowed to specify @@ -8862,9 +10294,9 @@ var ALLOWED_PARAMS = [ ]; exports.adapters = {}; -exports.adapters.writableStream = _dereq_('./writable-stream'); +exports.adapters.writableStream = _dereq_(4); -exports.plugin = _dereq_('pouch-stream'); +exports.plugin = _dereq_(22); exports.plugin.dump = utils.toPromise(function (writableStream, opts, callback) { var self = this; @@ -8958,4 +10390,5 @@ if (typeof window !== 'undefined' && window.PouchDB) { window.PouchDB.adapter('writableStream', exports.adapters.writableStream); } -},{"./pouch-utils":1,"./to-buffer-stream":2,"./version":3,"./writable-stream":4,"ldjson-stream":16,"lodash/object/pick":40,"pouch-stream":44,"through2":72}]},{},[78]); +},{"1":1,"17":17,"19":19,"2":2,"22":22,"3":3,"4":4,"57":57}]},{},[63])(63) +}); \ No newline at end of file diff --git a/dist/pouchdb.replication-stream.min.js b/dist/pouchdb.replication-stream.min.js index 52f0d23..e39025c 100644 --- a/dist/pouchdb.replication-stream.min.js +++ b/dist/pouchdb.replication-stream.min.js @@ -1,3 +1,4 @@ -!function e(t,r,n){function i(s,a){if(!r[s]){if(!t[s]){var u="function"==typeof require&&require;if(!a&&u)return u(s,!0);if(o)return o(s,!0);var c=new Error("Cannot find module '"+s+"'");throw c.code="MODULE_NOT_FOUND",c}var f=r[s]={exports:{}};t[s][0].call(f.exports,function(e){var r=t[s][1][e];return i(r?r:e)},f,f.exports,e,t,r,n)}return r[s].exports}for(var o="function"==typeof require&&require,s=0;st?-1:u+10>t?t-u+26+26:f+26>t?t-f:c+26>t?t-c+26:void 0}function r(e){function r(e){c[l++]=e}var n,i,s,a,u,c;if(e.length%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var f=e.length;u="="===e.charAt(f-2)?2:"="===e.charAt(f-1)?1:0,c=new o(3*e.length/4-u),s=u>0?e.length-4:e.length;var l=0;for(n=0,i=0;s>n;n+=4,i+=3)a=t(e.charAt(n))<<18|t(e.charAt(n+1))<<12|t(e.charAt(n+2))<<6|t(e.charAt(n+3)),r((16711680&a)>>16),r((65280&a)>>8),r(255&a);return 2===u?(a=t(e.charAt(n))<<2|t(e.charAt(n+1))>>4,r(255&a)):1===u&&(a=t(e.charAt(n))<<10|t(e.charAt(n+1))<<4|t(e.charAt(n+2))>>2,r(a>>8&255),r(255&a)),c}function i(e){function t(e){return n.charAt(e)}function r(e){return t(e>>18&63)+t(e>>12&63)+t(e>>6&63)+t(63&e)}var i,o,s,a=e.length%3,u="";for(i=0,s=e.length-a;s>i;i+=3)o=(e[i]<<16)+(e[i+1]<<8)+e[i+2],u+=r(o);switch(a){case 1:o=e[e.length-1],u+=t(o>>2),u+=t(o<<4&63),u+="==";break;case 2:o=(e[e.length-2]<<8)+e[e.length-1],u+=t(o>>10),u+=t(o>>4&63),u+=t(o<<2&63),u+="="}return u}var o="undefined"!=typeof Uint8Array?Uint8Array:Array,s="+".charCodeAt(0),a="/".charCodeAt(0),u="0".charCodeAt(0),c="a".charCodeAt(0),f="A".charCodeAt(0),l="-".charCodeAt(0),h="_".charCodeAt(0);e.toByteArray=r,e.fromByteArray=i}("undefined"==typeof r?this.base64js={}:r)},{}],6:[function(e,t,r){},{}],7:[function(e,t,r){(function(t){"use strict";function n(){function e(){}try{var t=new Uint8Array(1);return t.foo=function(){return 42},t.constructor=e,42===t.foo()&&t.constructor===e&&"function"==typeof t.subarray&&0===t.subarray(1,1).byteLength}catch(r){return!1}}function i(){return o.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function o(e){return this instanceof o?(o.TYPED_ARRAY_SUPPORT||(this.length=0,this.parent=void 0),"number"==typeof e?s(this,e):"string"==typeof e?a(this,e,arguments.length>1?arguments[1]:"utf8"):u(this,e)):arguments.length>1?new o(e,arguments[1]):new o(e)}function s(e,t){if(e=g(e,0>t?0:0|v(t)),!o.TYPED_ARRAY_SUPPORT)for(var r=0;t>r;r++)e[r]=0;return e}function a(e,t,r){("string"!=typeof r||""===r)&&(r="utf8");var n=0|m(t,r);return e=g(e,n),e.write(t,r),e}function u(e,t){if(o.isBuffer(t))return c(e,t);if(V(t))return f(e,t);if(null==t)throw new TypeError("must start with number, buffer, array or string");if("undefined"!=typeof ArrayBuffer){if(t.buffer instanceof ArrayBuffer)return l(e,t);if(t instanceof ArrayBuffer)return h(e,t)}return t.length?d(e,t):p(e,t)}function c(e,t){var r=0|v(t.length);return e=g(e,r),t.copy(e,0,0,r),e}function f(e,t){var r=0|v(t.length);e=g(e,r);for(var n=0;r>n;n+=1)e[n]=255&t[n];return e}function l(e,t){var r=0|v(t.length);e=g(e,r);for(var n=0;r>n;n+=1)e[n]=255&t[n];return e}function h(e,t){return o.TYPED_ARRAY_SUPPORT?(t.byteLength,e=o._augment(new Uint8Array(t))):e=l(e,new Uint8Array(t)),e}function d(e,t){var r=0|v(t.length);e=g(e,r);for(var n=0;r>n;n+=1)e[n]=255&t[n];return e}function p(e,t){var r,n=0;"Buffer"===t.type&&V(t.data)&&(r=t.data,n=0|v(r.length)),e=g(e,n);for(var i=0;n>i;i+=1)e[i]=255&r[i];return e}function g(e,t){o.TYPED_ARRAY_SUPPORT?(e=o._augment(new Uint8Array(t)),e.__proto__=o.prototype):(e.length=t,e._isBuffer=!0);var r=0!==t&&t<=o.poolSize>>>1;return r&&(e.parent=Z),e}function v(e){if(e>=i())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+i().toString(16)+" bytes");return 0|e}function b(e,t){if(!(this instanceof b))return new b(e,t);var r=new o(e,t);return delete r.parent,r}function m(e,t){"string"!=typeof e&&(e=""+e);var r=e.length;if(0===r)return 0;for(var n=!1;;)switch(t){case"ascii":case"binary":case"raw":case"raws":return r;case"utf8":case"utf-8":return q(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return H(e).length;default:if(n)return q(e).length;t=(""+t).toLowerCase(),n=!0}}function y(e,t,r){var n=!1;if(t=0|t,r=void 0===r||r===1/0?this.length:0|r,e||(e="utf8"),0>t&&(t=0),r>this.length&&(r=this.length),t>=r)return"";for(;;)switch(e){case"hex":return M(this,t,r);case"utf8":case"utf-8":return L(this,t,r);case"ascii":return A(this,t,r);case"binary":return B(this,t,r);case"base64":return R(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return O(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}function w(e,t,r,n){r=Number(r)||0;var i=e.length-r;n?(n=Number(n),n>i&&(n=i)):n=i;var o=t.length;if(o%2!==0)throw new Error("Invalid hex string");n>o/2&&(n=o/2);for(var s=0;n>s;s++){var a=parseInt(t.substr(2*s,2),16);if(isNaN(a))throw new Error("Invalid hex string");e[r+s]=a}return s}function _(e,t,r,n){return $(q(t,e.length-r),e,r,n)}function E(e,t,r,n){return $(z(t),e,r,n)}function S(e,t,r,n){return E(e,t,r,n)}function j(e,t,r,n){return $(H(t),e,r,n)}function x(e,t,r,n){return $(J(t,e.length-r),e,r,n)}function R(e,t,r){return 0===t&&r===e.length?G.fromByteArray(e):G.fromByteArray(e.slice(t,r))}function L(e,t,r){r=Math.min(e.length,r);for(var n=[],i=t;r>i;){var o=e[i],s=null,a=o>239?4:o>223?3:o>191?2:1;if(r>=i+a){var u,c,f,l;switch(a){case 1:128>o&&(s=o);break;case 2:u=e[i+1],128===(192&u)&&(l=(31&o)<<6|63&u,l>127&&(s=l));break;case 3:u=e[i+1],c=e[i+2],128===(192&u)&&128===(192&c)&&(l=(15&o)<<12|(63&u)<<6|63&c,l>2047&&(55296>l||l>57343)&&(s=l));break;case 4:u=e[i+1],c=e[i+2],f=e[i+3],128===(192&u)&&128===(192&c)&&128===(192&f)&&(l=(15&o)<<18|(63&u)<<12|(63&c)<<6|63&f,l>65535&&1114112>l&&(s=l))}}null===s?(s=65533,a=1):s>65535&&(s-=65536,n.push(s>>>10&1023|55296),s=56320|1023&s),n.push(s),i+=a}return k(n)}function k(e){var t=e.length;if(K>=t)return String.fromCharCode.apply(String,e);for(var r="",n=0;t>n;)r+=String.fromCharCode.apply(String,e.slice(n,n+=K));return r}function A(e,t,r){var n="";r=Math.min(e.length,r);for(var i=t;r>i;i++)n+=String.fromCharCode(127&e[i]);return n}function B(e,t,r){var n="";r=Math.min(e.length,r);for(var i=t;r>i;i++)n+=String.fromCharCode(e[i]);return n}function M(e,t,r){var n=e.length;(!t||0>t)&&(t=0),(!r||0>r||r>n)&&(r=n);for(var i="",o=t;r>o;o++)i+=F(e[o]);return i}function O(e,t,r){for(var n=e.slice(t,r),i="",o=0;oe)throw new RangeError("offset is not uint");if(e+t>r)throw new RangeError("Trying to access beyond buffer length")}function I(e,t,r,n,i,s){if(!o.isBuffer(e))throw new TypeError("buffer must be a Buffer instance");if(t>i||s>t)throw new RangeError("value is out of bounds");if(r+n>e.length)throw new RangeError("index out of range")}function P(e,t,r,n){0>t&&(t=65535+t+1);for(var i=0,o=Math.min(e.length-r,2);o>i;i++)e[r+i]=(t&255<<8*(n?i:1-i))>>>8*(n?i:1-i)}function D(e,t,r,n){0>t&&(t=4294967295+t+1);for(var i=0,o=Math.min(e.length-r,4);o>i;i++)e[r+i]=t>>>8*(n?i:3-i)&255}function U(e,t,r,n,i,o){if(t>i||o>t)throw new RangeError("value is out of bounds");if(r+n>e.length)throw new RangeError("index out of range");if(0>r)throw new RangeError("index out of range")}function C(e,t,r,n,i){return i||U(e,t,r,4,3.4028234663852886e38,-3.4028234663852886e38),X.write(e,t,r,n,23,4),r+4}function N(e,t,r,n,i){return i||U(e,t,r,8,1.7976931348623157e308,-1.7976931348623157e308),X.write(e,t,r,n,52,8),r+8}function W(e){if(e=Y(e).replace(ee,""),e.length<2)return"";for(;e.length%4!==0;)e+="=";return e}function Y(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}function F(e){return 16>e?"0"+e.toString(16):e.toString(16)}function q(e,t){t=t||1/0;for(var r,n=e.length,i=null,o=[],s=0;n>s;s++){if(r=e.charCodeAt(s),r>55295&&57344>r){if(!i){if(r>56319){(t-=3)>-1&&o.push(239,191,189);continue}if(s+1===n){(t-=3)>-1&&o.push(239,191,189);continue}i=r;continue}if(56320>r){(t-=3)>-1&&o.push(239,191,189),i=r;continue}r=(i-55296<<10|r-56320)+65536}else i&&(t-=3)>-1&&o.push(239,191,189);if(i=null,128>r){if((t-=1)<0)break;o.push(r)}else if(2048>r){if((t-=2)<0)break;o.push(r>>6|192,63&r|128)}else if(65536>r){if((t-=3)<0)break;o.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(1114112>r))throw new Error("Invalid code point");if((t-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return o}function z(e){for(var t=[],r=0;r>8,i=r%256,o.push(i),o.push(n);return o}function H(e){return G.toByteArray(W(e))}function $(e,t,r,n){for(var i=0;n>i&&!(i+r>=t.length||i>=e.length);i++)t[i+r]=e[i];return i}var G=e("base64-js"),X=e("ieee754"),V=e("isarray");r.Buffer=o,r.SlowBuffer=b,r.INSPECT_MAX_BYTES=50,o.poolSize=8192;var Z={};o.TYPED_ARRAY_SUPPORT=void 0!==t.TYPED_ARRAY_SUPPORT?t.TYPED_ARRAY_SUPPORT:n(),o.TYPED_ARRAY_SUPPORT?(o.prototype.__proto__=Uint8Array.prototype,o.__proto__=Uint8Array):(o.prototype.length=void 0,o.prototype.parent=void 0),o.isBuffer=function(e){return!(null==e||!e._isBuffer)},o.compare=function(e,t){if(!o.isBuffer(e)||!o.isBuffer(t))throw new TypeError("Arguments must be Buffers");if(e===t)return 0;for(var r=e.length,n=t.length,i=0,s=Math.min(r,n);s>i&&e[i]===t[i];)++i;return i!==s&&(r=e[i],n=t[i]),n>r?-1:r>n?1:0},o.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"raw":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},o.concat=function(e,t){if(!V(e))throw new TypeError("list argument must be an Array of Buffers.");if(0===e.length)return new o(0);var r;if(void 0===t)for(t=0,r=0;r0&&(e=this.toString("hex",0,t).match(/.{2}/g).join(" "),this.length>t&&(e+=" ... ")),""},o.prototype.compare=function(e){if(!o.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e?0:o.compare(this,e)},o.prototype.indexOf=function(e,t){function r(e,t,r){for(var n=-1,i=0;r+i2147483647?t=2147483647:-2147483648>t&&(t=-2147483648),t>>=0,0===this.length)return-1;if(t>=this.length)return-1;if(0>t&&(t=Math.max(this.length+t,0)),"string"==typeof e)return 0===e.length?-1:String.prototype.indexOf.call(this,e,t);if(o.isBuffer(e))return r(this,e,t);if("number"==typeof e)return o.TYPED_ARRAY_SUPPORT&&"function"===Uint8Array.prototype.indexOf?Uint8Array.prototype.indexOf.call(this,e,t):r(this,[e],t);throw new TypeError("val must be string, number or Buffer")},o.prototype.get=function(e){return console.log(".get() is deprecated. Access using array indexes instead."),this.readUInt8(e)},o.prototype.set=function(e,t){return console.log(".set() is deprecated. Access using array indexes instead."),this.writeUInt8(e,t)},o.prototype.write=function(e,t,r,n){if(void 0===t)n="utf8",r=this.length,t=0;else if(void 0===r&&"string"==typeof t)n=t,r=this.length,t=0;else if(isFinite(t))t=0|t,isFinite(r)?(r=0|r,void 0===n&&(n="utf8")):(n=r,r=void 0);else{var i=n;n=t,t=0|r,r=i}var o=this.length-t;if((void 0===r||r>o)&&(r=o),e.length>0&&(0>r||0>t)||t>this.length)throw new RangeError("attempt to write outside buffer bounds");n||(n="utf8");for(var s=!1;;)switch(n){case"hex":return w(this,e,t,r);case"utf8":case"utf-8":return _(this,e,t,r);case"ascii":return E(this,e,t,r);case"binary":return S(this,e,t,r);case"base64":return j(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return x(this,e,t,r);default:if(s)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),s=!0}},o.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var K=4096;o.prototype.slice=function(e,t){var r=this.length;e=~~e,t=void 0===t?r:~~t,0>e?(e+=r,0>e&&(e=0)):e>r&&(e=r),0>t?(t+=r,0>t&&(t=0)):t>r&&(t=r),e>t&&(t=e);var n;if(o.TYPED_ARRAY_SUPPORT)n=o._augment(this.subarray(e,t));else{var i=t-e;n=new o(i,void 0);for(var s=0;i>s;s++)n[s]=this[s+e]}return n.length&&(n.parent=this.parent||this),n},o.prototype.readUIntLE=function(e,t,r){e=0|e,t=0|t,r||T(e,t,this.length);for(var n=this[e],i=1,o=0;++o0&&(i*=256);)n+=this[e+--t]*i;return n},o.prototype.readUInt8=function(e,t){return t||T(e,1,this.length),this[e]},o.prototype.readUInt16LE=function(e,t){return t||T(e,2,this.length),this[e]|this[e+1]<<8},o.prototype.readUInt16BE=function(e,t){return t||T(e,2,this.length),this[e]<<8|this[e+1]},o.prototype.readUInt32LE=function(e,t){return t||T(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},o.prototype.readUInt32BE=function(e,t){return t||T(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},o.prototype.readIntLE=function(e,t,r){e=0|e,t=0|t,r||T(e,t,this.length);for(var n=this[e],i=1,o=0;++o=i&&(n-=Math.pow(2,8*t)),n},o.prototype.readIntBE=function(e,t,r){e=0|e,t=0|t,r||T(e,t,this.length);for(var n=t,i=1,o=this[e+--n];n>0&&(i*=256);)o+=this[e+--n]*i;return i*=128,o>=i&&(o-=Math.pow(2,8*t)),o},o.prototype.readInt8=function(e,t){return t||T(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},o.prototype.readInt16LE=function(e,t){t||T(e,2,this.length);var r=this[e]|this[e+1]<<8;return 32768&r?4294901760|r:r},o.prototype.readInt16BE=function(e,t){t||T(e,2,this.length);var r=this[e+1]|this[e]<<8;return 32768&r?4294901760|r:r},o.prototype.readInt32LE=function(e,t){return t||T(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},o.prototype.readInt32BE=function(e,t){return t||T(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},o.prototype.readFloatLE=function(e,t){return t||T(e,4,this.length),X.read(this,e,!0,23,4)},o.prototype.readFloatBE=function(e,t){return t||T(e,4,this.length),X.read(this,e,!1,23,4)},o.prototype.readDoubleLE=function(e,t){return t||T(e,8,this.length),X.read(this,e,!0,52,8)},o.prototype.readDoubleBE=function(e,t){return t||T(e,8,this.length),X.read(this,e,!1,52,8)},o.prototype.writeUIntLE=function(e,t,r,n){e=+e,t=0|t,r=0|r,n||I(this,e,t,r,Math.pow(2,8*r),0);var i=1,o=0;for(this[t]=255&e;++o=0&&(o*=256);)this[t+i]=e/o&255;return t+r},o.prototype.writeUInt8=function(e,t,r){return e=+e,t=0|t,r||I(this,e,t,1,255,0),o.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),this[t]=255&e,t+1},o.prototype.writeUInt16LE=function(e,t,r){return e=+e,t=0|t,r||I(this,e,t,2,65535,0),o.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):P(this,e,t,!0),t+2},o.prototype.writeUInt16BE=function(e,t,r){return e=+e,t=0|t,r||I(this,e,t,2,65535,0),o.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):P(this,e,t,!1),t+2},o.prototype.writeUInt32LE=function(e,t,r){return e=+e,t=0|t,r||I(this,e,t,4,4294967295,0),o.TYPED_ARRAY_SUPPORT?(this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e):D(this,e,t,!0),t+4},o.prototype.writeUInt32BE=function(e,t,r){return e=+e,t=0|t,r||I(this,e,t,4,4294967295,0),o.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):D(this,e,t,!1),t+4},o.prototype.writeIntLE=function(e,t,r,n){if(e=+e,t=0|t,!n){var i=Math.pow(2,8*r-1);I(this,e,t,r,i-1,-i)}var o=0,s=1,a=0>e?1:0;for(this[t]=255&e;++o>0)-a&255;return t+r},o.prototype.writeIntBE=function(e,t,r,n){if(e=+e,t=0|t,!n){var i=Math.pow(2,8*r-1);I(this,e,t,r,i-1,-i)}var o=r-1,s=1,a=0>e?1:0;for(this[t+o]=255&e;--o>=0&&(s*=256);)this[t+o]=(e/s>>0)-a&255;return t+r},o.prototype.writeInt8=function(e,t,r){return e=+e,t=0|t,r||I(this,e,t,1,127,-128),o.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),0>e&&(e=255+e+1),this[t]=255&e,t+1},o.prototype.writeInt16LE=function(e,t,r){return e=+e,t=0|t,r||I(this,e,t,2,32767,-32768),o.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):P(this,e,t,!0),t+2},o.prototype.writeInt16BE=function(e,t,r){return e=+e,t=0|t,r||I(this,e,t,2,32767,-32768),o.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):P(this,e,t,!1),t+2},o.prototype.writeInt32LE=function(e,t,r){return e=+e,t=0|t,r||I(this,e,t,4,2147483647,-2147483648),o.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24):D(this,e,t,!0),t+4},o.prototype.writeInt32BE=function(e,t,r){return e=+e,t=0|t,r||I(this,e,t,4,2147483647,-2147483648),0>e&&(e=4294967295+e+1),o.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):D(this,e,t,!1),t+4},o.prototype.writeFloatLE=function(e,t,r){return C(this,e,t,!0,r)},o.prototype.writeFloatBE=function(e,t,r){return C(this,e,t,!1,r)},o.prototype.writeDoubleLE=function(e,t,r){return N(this,e,t,!0,r)},o.prototype.writeDoubleBE=function(e,t,r){return N(this,e,t,!1,r)},o.prototype.copy=function(e,t,r,n){if(r||(r=0),n||0===n||(n=this.length),t>=e.length&&(t=e.length),t||(t=0),n>0&&r>n&&(n=r),n===r)return 0;if(0===e.length||0===this.length)return 0;if(0>t)throw new RangeError("targetStart out of bounds");if(0>r||r>=this.length)throw new RangeError("sourceStart out of bounds");if(0>n)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),e.length-tr&&n>t)for(i=s-1;i>=0;i--)e[i+t]=this[i+r];else if(1e3>s||!o.TYPED_ARRAY_SUPPORT)for(i=0;s>i;i++)e[i+t]=this[i+r];else e._set(this.subarray(r,r+s),t);return s},o.prototype.fill=function(e,t,r){if(e||(e=0),t||(t=0),r||(r=this.length),t>r)throw new RangeError("end < start");if(r!==t&&0!==this.length){if(0>t||t>=this.length)throw new RangeError("start out of bounds");if(0>r||r>this.length)throw new RangeError("end out of bounds");var n;if("number"==typeof e)for(n=t;r>n;n++)this[n]=e;else{var i=q(e.toString()),o=i.length;for(n=t;r>n;n++)this[n]=i[n%o]}return this}},o.prototype.toArrayBuffer=function(){if("undefined"!=typeof Uint8Array){if(o.TYPED_ARRAY_SUPPORT)return new o(this).buffer;for(var e=new Uint8Array(this.length),t=0,r=e.length;r>t;t+=1)e[t]=this[t];return e.buffer}throw new TypeError("Buffer.toArrayBuffer not supported in this browser")};var Q=o.prototype;o._augment=function(e){return e.constructor=o,e._isBuffer=!0,e._set=e.set,e.get=Q.get,e.set=Q.set,e.write=Q.write,e.toString=Q.toString,e.toLocaleString=Q.toString,e.toJSON=Q.toJSON,e.equals=Q.equals,e.compare=Q.compare,e.indexOf=Q.indexOf,e.copy=Q.copy,e.slice=Q.slice,e.readUIntLE=Q.readUIntLE,e.readUIntBE=Q.readUIntBE,e.readUInt8=Q.readUInt8,e.readUInt16LE=Q.readUInt16LE,e.readUInt16BE=Q.readUInt16BE,e.readUInt32LE=Q.readUInt32LE,e.readUInt32BE=Q.readUInt32BE,e.readIntLE=Q.readIntLE,e.readIntBE=Q.readIntBE,e.readInt8=Q.readInt8,e.readInt16LE=Q.readInt16LE,e.readInt16BE=Q.readInt16BE,e.readInt32LE=Q.readInt32LE,e.readInt32BE=Q.readInt32BE,e.readFloatLE=Q.readFloatLE,e.readFloatBE=Q.readFloatBE,e.readDoubleLE=Q.readDoubleLE,e.readDoubleBE=Q.readDoubleBE,e.writeUInt8=Q.writeUInt8,e.writeUIntLE=Q.writeUIntLE,e.writeUIntBE=Q.writeUIntBE,e.writeUInt16LE=Q.writeUInt16LE,e.writeUInt16BE=Q.writeUInt16BE,e.writeUInt32LE=Q.writeUInt32LE,e.writeUInt32BE=Q.writeUInt32BE,e.writeIntLE=Q.writeIntLE,e.writeIntBE=Q.writeIntBE,e.writeInt8=Q.writeInt8,e.writeInt16LE=Q.writeInt16LE,e.writeInt16BE=Q.writeInt16BE,e.writeInt32LE=Q.writeInt32LE,e.writeInt32BE=Q.writeInt32BE,e.writeFloatLE=Q.writeFloatLE,e.writeFloatBE=Q.writeFloatBE,e.writeDoubleLE=Q.writeDoubleLE,e.writeDoubleBE=Q.writeDoubleBE,e.fill=Q.fill,e.inspect=Q.inspect,e.toArrayBuffer=Q.toArrayBuffer,e};var ee=/[^+\/0-9A-Za-z-_]/g}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"base64-js":5,ieee754:11,isarray:8}],8:[function(e,t,r){var n={}.toString;t.exports=Array.isArray||function(e){return"[object Array]"==n.call(e)}},{}],9:[function(e,t,r){(function(e){function t(e){return Array.isArray?Array.isArray(e):"[object Array]"===v(e)}function n(e){return"boolean"==typeof e}function i(e){return null===e}function o(e){return null==e}function s(e){return"number"==typeof e}function a(e){return"string"==typeof e}function u(e){return"symbol"==typeof e}function c(e){return void 0===e}function f(e){return"[object RegExp]"===v(e)}function l(e){return"object"==typeof e&&null!==e}function h(e){return"[object Date]"===v(e)}function d(e){return"[object Error]"===v(e)||e instanceof Error}function p(e){return"function"==typeof e}function g(e){return null===e||"boolean"==typeof e||"number"==typeof e||"string"==typeof e||"symbol"==typeof e||"undefined"==typeof e}function v(e){return Object.prototype.toString.call(e)}r.isArray=t,r.isBoolean=n,r.isNull=i,r.isNullOrUndefined=o,r.isNumber=s,r.isString=a,r.isSymbol=u,r.isUndefined=c,r.isRegExp=f,r.isObject=l,r.isDate=h,r.isError=d,r.isFunction=p,r.isPrimitive=g,r.isBuffer=e.isBuffer}).call(this,{isBuffer:e("../../is-buffer/index.js")})},{"../../is-buffer/index.js":14}],10:[function(e,t,r){function n(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function i(e){return"function"==typeof e}function o(e){return"number"==typeof e}function s(e){return"object"==typeof e&&null!==e}function a(e){return void 0===e}t.exports=n,n.EventEmitter=n,n.prototype._events=void 0,n.prototype._maxListeners=void 0,n.defaultMaxListeners=10,n.prototype.setMaxListeners=function(e){if(!o(e)||0>e||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},n.prototype.emit=function(e){var t,r,n,o,u,c;if(this._events||(this._events={}),"error"===e&&(!this._events.error||s(this._events.error)&&!this._events.error.length)){if(t=arguments[1],t instanceof Error)throw t;throw TypeError('Uncaught, unspecified "error" event.')}if(r=this._events[e],a(r))return!1;if(i(r))switch(arguments.length){case 1:r.call(this);break;case 2:r.call(this,arguments[1]);break;case 3:r.call(this,arguments[1],arguments[2]);break;default:for(n=arguments.length,o=new Array(n-1),u=1;n>u;u++)o[u-1]=arguments[u];r.apply(this,o)}else if(s(r)){for(n=arguments.length,o=new Array(n-1),u=1;n>u;u++)o[u-1]=arguments[u];for(c=r.slice(),n=c.length,u=0;n>u;u++)c[u].apply(this,o)}return!0},n.prototype.addListener=function(e,t){var r;if(!i(t))throw TypeError("listener must be a function");if(this._events||(this._events={}),this._events.newListener&&this.emit("newListener",e,i(t.listener)?t.listener:t),this._events[e]?s(this._events[e])?this._events[e].push(t):this._events[e]=[this._events[e],t]:this._events[e]=t,s(this._events[e])&&!this._events[e].warned){var r;r=a(this._maxListeners)?n.defaultMaxListeners:this._maxListeners,r&&r>0&&this._events[e].length>r&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace())}return this},n.prototype.on=n.prototype.addListener,n.prototype.once=function(e,t){function r(){this.removeListener(e,r),n||(n=!0,t.apply(this,arguments))}if(!i(t))throw TypeError("listener must be a function");var n=!1;return r.listener=t,this.on(e,r),this},n.prototype.removeListener=function(e,t){var r,n,o,a;if(!i(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(r=this._events[e],o=r.length,n=-1,r===t||i(r.listener)&&r.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(s(r)){for(a=o;a-- >0;)if(r[a]===t||r[a].listener&&r[a].listener===t){n=a;break}if(0>n)return this;1===r.length?(r.length=0,delete this._events[e]):r.splice(n,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},n.prototype.removeAllListeners=function(e){var t,r;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(r=this._events[e],i(r))this.removeListener(e,r);else for(;r.length;)this.removeListener(e,r[r.length-1]);return delete this._events[e],this},n.prototype.listeners=function(e){var t;return t=this._events&&this._events[e]?i(this._events[e])?[this._events[e]]:this._events[e].slice():[]},n.listenerCount=function(e,t){var r;return r=e._events&&e._events[t]?i(e._events[t])?1:e._events[t].length:0}},{}],11:[function(e,t,r){r.read=function(e,t,r,n,i){var o,s,a=8*i-n-1,u=(1<>1,f=-7,l=r?i-1:0,h=r?-1:1,d=e[t+l];for(l+=h,o=d&(1<<-f)-1,d>>=-f,f+=a;f>0;o=256*o+e[t+l],l+=h,f-=8);for(s=o&(1<<-f)-1,o>>=-f,f+=n;f>0;s=256*s+e[t+l],l+=h,f-=8);if(0===o)o=1-c;else{if(o===u)return s?NaN:(d?-1:1)*(1/0);s+=Math.pow(2,n),o-=c}return(d?-1:1)*s*Math.pow(2,o-n)},r.write=function(e,t,r,n,i,o){var s,a,u,c=8*o-i-1,f=(1<>1,h=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,d=n?0:o-1,p=n?1:-1,g=0>t||0===t&&0>1/t?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,s=f):(s=Math.floor(Math.log(t)/Math.LN2),t*(u=Math.pow(2,-s))<1&&(s--,u*=2),t+=s+l>=1?h/u:h*Math.pow(2,1-l),t*u>=2&&(s++,u/=2),s+l>=f?(a=0,s=f):s+l>=1?(a=(t*u-1)*Math.pow(2,i),s+=l):(a=t*Math.pow(2,l-1)*Math.pow(2,i),s=0));i>=8;e[r+d]=255&a,d+=p,a/=256,i-=8);for(s=s<0;e[r+d]=255&s,d+=p,s/=256,c-=8);e[r+d-p]|=128*g}},{}],12:[function(e,t,r){(function(e){"use strict";function r(){f=!0;for(var e,t,r=l.length;r;){for(t=l,l=[],e=-1;++e-1&&e%1==0&&t>e}var i=/^\d+$/,o=9007199254740991;t.exports=n},{}],29:[function(e,t,r){function n(e){return"number"==typeof e&&e>-1&&e%1==0&&i>=e}var i=9007199254740991;t.exports=n},{}],30:[function(e,t,r){function n(e){return!!e&&"object"==typeof e}t.exports=n},{}],31:[function(e,t,r){function n(e,t){e=i(e);for(var r=-1,n=t.length,o={};++r0;++n1)for(var r=1;rr;r++)t(e[r],r)}t.exports=n;var s=Object.keys||function(e){var t=[];for(var r in e)t.push(r);return t},a=e("core-util-is");a.inherits=e("inherits");var u=e("./_stream_readable"),c=e("./_stream_writable");a.inherits(n,u),o(s(c.prototype),function(e){n.prototype[e]||(n.prototype[e]=c.prototype[e])})}).call(this,e("_process"))},{"./_stream_readable":54,"./_stream_writable":56,_process:51,"core-util-is":9,inherits:13}],53:[function(e,t,r){function n(e){return this instanceof n?void i.call(this,e):new n(e)}t.exports=n;var i=e("./_stream_transform"),o=e("core-util-is");o.inherits=e("inherits"),o.inherits(n,i),n.prototype._transform=function(e,t,r){r(null,e)}},{"./_stream_transform":55,"core-util-is":9,inherits:13}],54:[function(e,t,r){(function(r){function n(t,r){t=t||{};var n=t.highWaterMark;this.highWaterMark=n||0===n?n:16384,this.highWaterMark=~~this.highWaterMark,this.buffer=[],this.length=0,this.pipes=null,this.pipesCount=0,this.flowing=!1,this.ended=!1,this.endEmitted=!1,this.reading=!1,this.calledRead=!1,this.sync=!0,this.needReadable=!1,this.emittedReadable=!1,this.readableListening=!1,this.objectMode=!!t.objectMode,this.defaultEncoding=t.defaultEncoding||"utf8",this.ranOut=!1,this.awaitDrain=0,this.readingMore=!1,this.decoder=null,this.encoding=null,t.encoding&&(k||(k=e("string_decoder/").StringDecoder),this.decoder=new k(t.encoding),this.encoding=t.encoding)}function i(e){return this instanceof i?(this._readableState=new n(e,this),this.readable=!0,void R.call(this)):new i(e)}function o(e,t,r,n,i){var o=c(t,r);if(o)e.emit("error",o);else if(null===r||void 0===r)t.reading=!1,t.ended||f(e,t);else if(t.objectMode||r&&r.length>0)if(t.ended&&!i){var a=new Error("stream.push() after EOF");e.emit("error",a)}else if(t.endEmitted&&i){var a=new Error("stream.unshift() after end event");e.emit("error",a)}else!t.decoder||i||n||(r=t.decoder.write(r)),t.length+=t.objectMode?1:r.length,i?t.buffer.unshift(r):(t.reading=!1,t.buffer.push(r)),t.needReadable&&l(e),d(e,t);else i||(t.reading=!1);return s(t)}function s(e){return!e.ended&&(e.needReadable||e.length=A)e=A;else{e--;for(var t=1;32>t;t<<=1)e|=e>>t;e++}return e}function u(e,t){return 0===t.length&&t.ended?0:t.objectMode?0===e?0:1:null===e||isNaN(e)?t.flowing&&t.buffer.length?t.buffer[0].length:t.length:0>=e?0:(e>t.highWaterMark&&(t.highWaterMark=a(e)),e>t.length?t.ended?t.length:(t.needReadable=!0,0):e)}function c(e,t){var r=null;return j.isBuffer(t)||"string"==typeof t||null===t||void 0===t||e.objectMode||(r=new TypeError("Invalid non-string/buffer chunk")),r}function f(e,t){if(t.decoder&&!t.ended){var r=t.decoder.end();r&&r.length&&(t.buffer.push(r),t.length+=t.objectMode?1:r.length)}t.ended=!0,t.length>0?l(e):w(e)}function l(e){var t=e._readableState;t.needReadable=!1,t.emittedReadable||(t.emittedReadable=!0,t.sync?r.nextTick(function(){h(e)}):h(e))}function h(e){e.emit("readable")}function d(e,t){t.readingMore||(t.readingMore=!0,r.nextTick(function(){p(e,t)}))}function p(e,t){for(var r=t.length;!t.reading&&!t.flowing&&!t.ended&&t.length0)return;return 0===n.pipesCount?(n.flowing=!1,void(x.listenerCount(e,"data")>0&&m(e))):void(n.ranOut=!0)}function b(){this._readableState.ranOut&&(this._readableState.ranOut=!1,v(this))}function m(e,t){var n=e._readableState;if(n.flowing)throw new Error("Cannot switch to old mode now.");var i=t||!1,o=!1;e.readable=!0,e.pipe=R.prototype.pipe,e.on=e.addListener=R.prototype.on,e.on("readable",function(){o=!0;for(var t;!i&&null!==(t=e.read());)e.emit("data",t);null===t&&(o=!1,e._readableState.needReadable=!0)}),e.pause=function(){i=!0,this.emit("pause")},e.resume=function(){i=!1,o?r.nextTick(function(){e.emit("readable")}):this.read(0),this.emit("resume")},e.emit("readable")}function y(e,t){var r,n=t.buffer,i=t.length,o=!!t.decoder,s=!!t.objectMode;if(0===n.length)return null;if(0===i)r=null;else if(s)r=n.shift();else if(!e||e>=i)r=o?n.join(""):j.concat(n,i),n.length=0;else if(ec&&e>u;c++){var a=n[0],l=Math.min(e-u,a.length);o?r+=a.slice(0,l):a.copy(r,u,0,l),l0)throw new Error("endReadable called on non-empty stream");!t.endEmitted&&t.calledRead&&(t.ended=!0,r.nextTick(function(){t.endEmitted||0!==t.length||(t.endEmitted=!0,e.readable=!1,e.emit("end"))}))}function _(e,t){for(var r=0,n=e.length;n>r;r++)t(e[r],r)}function E(e,t){for(var r=0,n=e.length;n>r;r++)if(e[r]===t)return r;return-1}t.exports=i;var S=e("isarray"),j=e("buffer").Buffer;i.ReadableState=n;var x=e("events").EventEmitter;x.listenerCount||(x.listenerCount=function(e,t){return e.listeners(t).length});var R=e("stream"),L=e("core-util-is");L.inherits=e("inherits");var k;L.inherits(i,R),i.prototype.push=function(e,t){var r=this._readableState;return"string"!=typeof e||r.objectMode||(t=t||r.defaultEncoding,t!==r.encoding&&(e=new j(e,t),t="")),o(this,r,e,t,!1)},i.prototype.unshift=function(e){var t=this._readableState;return o(this,t,e,"",!0)},i.prototype.setEncoding=function(t){k||(k=e("string_decoder/").StringDecoder),this._readableState.decoder=new k(t),this._readableState.encoding=t};var A=8388608;i.prototype.read=function(e){var t=this._readableState;t.calledRead=!0;var r,n=e;if(("number"!=typeof e||e>0)&&(t.emittedReadable=!1),0===e&&t.needReadable&&(t.length>=t.highWaterMark||t.ended))return l(this),null;if(e=u(e,t),0===e&&t.ended)return r=null,t.length>0&&t.decoder&&(r=y(e,t),t.length-=r.length),0===t.length&&w(this),r;var i=t.needReadable;return t.length-e<=t.highWaterMark&&(i=!0),(t.ended||t.reading)&&(i=!1),i&&(t.reading=!0,t.sync=!0,0===t.length&&(t.needReadable=!0),this._read(t.highWaterMark),t.sync=!1),i&&!t.reading&&(e=u(n,t)),r=e>0?y(e,t):null,null===r&&(t.needReadable=!0,e=0),t.length-=e,0!==t.length||t.ended||(t.needReadable=!0),t.ended&&!t.endEmitted&&0===t.length&&w(this),r},i.prototype._read=function(e){this.emit("error",new Error("not implemented"))},i.prototype.pipe=function(e,t){function n(e){e===f&&o()}function i(){e.end()}function o(){e.removeListener("close",a),e.removeListener("finish",u),e.removeListener("drain",p),e.removeListener("error",s),e.removeListener("unpipe",n),f.removeListener("end",i),f.removeListener("end",o),(!e._writableState||e._writableState.needDrain)&&p()}function s(t){c(),e.removeListener("error",s),0===x.listenerCount(e,"error")&&e.emit("error",t)}function a(){e.removeListener("finish",u),c()}function u(){e.removeListener("close",a),c()}function c(){f.unpipe(e)}var f=this,l=this._readableState;switch(l.pipesCount){case 0:l.pipes=e;break;case 1:l.pipes=[l.pipes,e];break;default:l.pipes.push(e)}l.pipesCount+=1;var h=(!t||t.end!==!1)&&e!==r.stdout&&e!==r.stderr,d=h?i:o;l.endEmitted?r.nextTick(d):f.once("end",d),e.on("unpipe",n);var p=g(f);return e.on("drain",p),e._events&&e._events.error?S(e._events.error)?e._events.error.unshift(s):e._events.error=[s,e._events.error]:e.on("error",s),e.once("close",a),e.once("finish",u),e.emit("pipe",f),l.flowing||(this.on("readable",b),l.flowing=!0,r.nextTick(function(){v(f)})),e},i.prototype.unpipe=function(e){var t=this._readableState;if(0===t.pipesCount)return this;if(1===t.pipesCount)return e&&e!==t.pipes?this:(e||(e=t.pipes),t.pipes=null,t.pipesCount=0,this.removeListener("readable",b),t.flowing=!1,e&&e.emit("unpipe",this),this);if(!e){var r=t.pipes,n=t.pipesCount;t.pipes=null,t.pipesCount=0,this.removeListener("readable",b),t.flowing=!1;for(var i=0;n>i;i++)r[i].emit("unpipe",this);return this}var i=E(t.pipes,e);return-1===i?this:(t.pipes.splice(i,1),t.pipesCount-=1,1===t.pipesCount&&(t.pipes=t.pipes[0]),e.emit("unpipe",this),this)},i.prototype.on=function(e,t){var r=R.prototype.on.call(this,e,t);if("data"!==e||this._readableState.flowing||m(this),"readable"===e&&this.readable){var n=this._readableState;n.readableListening||(n.readableListening=!0,n.emittedReadable=!1,n.needReadable=!0,n.reading?n.length&&l(this,n):this.read(0))}return r},i.prototype.addListener=i.prototype.on,i.prototype.resume=function(){m(this),this.read(0),this.emit("resume")},i.prototype.pause=function(){m(this,!0),this.emit("pause")},i.prototype.wrap=function(e){var t=this._readableState,r=!1,n=this;e.on("end",function(){if(t.decoder&&!t.ended){var e=t.decoder.end();e&&e.length&&n.push(e)}n.push(null)}),e.on("data",function(i){if(t.decoder&&(i=t.decoder.write(i)),(!t.objectMode||null!==i&&void 0!==i)&&(t.objectMode||i&&i.length)){var o=n.push(i);o||(r=!0,e.pause())}});for(var i in e)"function"==typeof e[i]&&"undefined"==typeof this[i]&&(this[i]=function(t){return function(){return e[t].apply(e,arguments)}}(i));var o=["error","close","destroy","pause","resume"];return _(o,function(t){e.on(t,n.emit.bind(n,t))}),n._read=function(t){r&&(r=!1,e.resume())},n},i._fromList=y}).call(this,e("_process"))},{_process:51,buffer:7,"core-util-is":9,events:10,inherits:13,isarray:15,stream:60,"string_decoder/":71}],55:[function(e,t,r){function n(e,t){this.afterTransform=function(e,r){return i(t,e,r)},this.needTransform=!1,this.transforming=!1,this.writecb=null,this.writechunk=null}function i(e,t,r){var n=e._transformState;n.transforming=!1;var i=n.writecb;if(!i)return e.emit("error",new Error("no writecb in Transform class"));n.writechunk=null,n.writecb=null,null!==r&&void 0!==r&&e.push(r),i&&i(t);var o=e._readableState;o.reading=!1,(o.needReadable||o.length=1?o(this,this.mapper(this._last+i.shift())):s=this._last+s,n=0;n0)if(t.ended&&!i){var a=new Error("stream.push() after EOF"); -e.emit("error",a)}else if(t.endEmitted&&i){var a=new Error("stream.unshift() after end event");e.emit("error",a)}else!t.decoder||i||n||(r=t.decoder.write(r)),i||(t.reading=!1),t.flowing&&0===t.length&&!t.sync?(e.emit("data",r),e.read(0)):(t.length+=t.objectMode?1:r.length,i?t.buffer.unshift(r):t.buffer.push(r),t.needReadable&&l(e)),d(e,t);else i||(t.reading=!1);return s(t)}function s(e){return!e.ended&&(e.needReadable||e.length=P?e=P:(e--,e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e++),e}function u(e,t){return 0===t.length&&t.ended?0:t.objectMode?0===e?0:1:null===e||isNaN(e)?t.flowing&&t.buffer.length?t.buffer[0].length:t.length:0>=e?0:(e>t.highWaterMark&&(t.highWaterMark=a(e)),e>t.length?t.ended?t.length:(t.needReadable=!0,0):e)}function c(e,t){var r=null;return L.isBuffer(t)||"string"==typeof t||null===t||void 0===t||e.objectMode||(r=new TypeError("Invalid non-string/buffer chunk")),r}function f(e,t){if(!t.ended){if(t.decoder){var r=t.decoder.end();r&&r.length&&(t.buffer.push(r),t.length+=t.objectMode?1:r.length)}t.ended=!0,l(e)}}function l(e){var t=e._readableState;t.needReadable=!1,t.emittedReadable||(M("emitReadable",t.flowing),t.emittedReadable=!0,t.sync?x(h,e):h(e))}function h(e){M("emit readable"),e.emit("readable"),y(e)}function d(e,t){t.readingMore||(t.readingMore=!0,x(p,e,t))}function p(e,t){for(var r=t.length;!t.reading&&!t.flowing&&!t.ended&&t.length=i)r=o?n.join(""):1===n.length?n[0]:L.concat(n,i),n.length=0;else if(ec&&e>u;c++){var a=n[0],l=Math.min(e-u,a.length);o?r+=a.slice(0,l):a.copy(r,u,0,l),l0)throw new Error("endReadable called on non-empty stream");t.endEmitted||(t.ended=!0,x(E,t,e))}function E(e,t){e.endEmitted||0!==e.length||(e.endEmitted=!0,t.readable=!1,t.emit("end"))}function S(e,t){for(var r=0,n=e.length;n>r;r++)t(e[r],r)}function j(e,t){for(var r=0,n=e.length;n>r;r++)if(e[r]===t)return r;return-1}t.exports=i;var x=e("process-nextick-args"),R=e("isarray"),L=e("buffer").Buffer;i.ReadableState=n;var k,A=(e("events"),function(e,t){return e.listeners(t).length});!function(){try{k=e("stream")}catch(t){}finally{k||(k=e("events").EventEmitter)}}();var L=e("buffer").Buffer,B=e("core-util-is");B.inherits=e("inherits");var M,O=e("util");M=O&&O.debuglog?O.debuglog("stream"):function(){};var T;B.inherits(i,k);var I,I;i.prototype.push=function(e,t){var r=this._readableState;return r.objectMode||"string"!=typeof e||(t=t||r.defaultEncoding,t!==r.encoding&&(e=new L(e,t),t="")),o(this,r,e,t,!1)},i.prototype.unshift=function(e){var t=this._readableState;return o(this,t,e,"",!0)},i.prototype.isPaused=function(){return this._readableState.flowing===!1},i.prototype.setEncoding=function(t){return T||(T=e("string_decoder/").StringDecoder),this._readableState.decoder=new T(t),this._readableState.encoding=t,this};var P=8388608;i.prototype.read=function(e){M("read",e);var t=this._readableState,r=e;if(("number"!=typeof e||e>0)&&(t.emittedReadable=!1),0===e&&t.needReadable&&(t.length>=t.highWaterMark||t.ended))return M("read: emitReadable",t.length,t.ended),0===t.length&&t.ended?_(this):l(this),null;if(e=u(e,t),0===e&&t.ended)return 0===t.length&&_(this),null;var n=t.needReadable;M("need readable",n),(0===t.length||t.length-e0?w(e,t):null,null===i&&(t.needReadable=!0,e=0),t.length-=e,0!==t.length||t.ended||(t.needReadable=!0),r!==e&&t.ended&&0===t.length&&_(this),null!==i&&this.emit("data",i),i},i.prototype._read=function(e){this.emit("error",new Error("not implemented"))},i.prototype.pipe=function(e,t){function n(e){M("onunpipe"),e===l&&o()}function i(){M("onend"),e.end()}function o(){M("cleanup"),e.removeListener("close",u),e.removeListener("finish",c),e.removeListener("drain",v),e.removeListener("error",a),e.removeListener("unpipe",n),l.removeListener("end",i),l.removeListener("end",o),l.removeListener("data",s),b=!0,!h.awaitDrain||e._writableState&&!e._writableState.needDrain||v()}function s(t){M("ondata");var r=e.write(t);!1===r&&(1!==h.pipesCount||h.pipes[0]!==e||1!==l.listenerCount("data")||b||(M("false write response, pause",l._readableState.awaitDrain),l._readableState.awaitDrain++),l.pause())}function a(t){M("onerror",t),f(),e.removeListener("error",a),0===A(e,"error")&&e.emit("error",t)}function u(){e.removeListener("finish",c),f()}function c(){M("onfinish"),e.removeListener("close",u),f()}function f(){M("unpipe"),l.unpipe(e)}var l=this,h=this._readableState;switch(h.pipesCount){case 0:h.pipes=e;break;case 1:h.pipes=[h.pipes,e];break;default:h.pipes.push(e)}h.pipesCount+=1,M("pipe count=%d opts=%j",h.pipesCount,t);var d=(!t||t.end!==!1)&&e!==r.stdout&&e!==r.stderr,p=d?i:o;h.endEmitted?x(p):l.once("end",p),e.on("unpipe",n);var v=g(l);e.on("drain",v);var b=!1;return l.on("data",s),e._events&&e._events.error?R(e._events.error)?e._events.error.unshift(a):e._events.error=[a,e._events.error]:e.on("error",a),e.once("close",u),e.once("finish",c),e.emit("pipe",l),h.flowing||(M("pipe resume"),l.resume()),e},i.prototype.unpipe=function(e){var t=this._readableState;if(0===t.pipesCount)return this;if(1===t.pipesCount)return e&&e!==t.pipes?this:(e||(e=t.pipes),t.pipes=null,t.pipesCount=0,t.flowing=!1,e&&e.emit("unpipe",this),this);if(!e){var r=t.pipes,n=t.pipesCount;t.pipes=null,t.pipesCount=0,t.flowing=!1;for(var i=0;n>i;i++)r[i].emit("unpipe",this);return this}var i=j(t.pipes,e);return-1===i?this:(t.pipes.splice(i,1),t.pipesCount-=1,1===t.pipesCount&&(t.pipes=t.pipes[0]),e.emit("unpipe",this),this)},i.prototype.on=function(e,t){var r=k.prototype.on.call(this,e,t);if("data"===e&&!1!==this._readableState.flowing&&this.resume(),"readable"===e&&this.readable){var n=this._readableState;n.readableListening||(n.readableListening=!0,n.emittedReadable=!1,n.needReadable=!0,n.reading?n.length&&l(this,n):x(v,this))}return r},i.prototype.addListener=i.prototype.on,i.prototype.resume=function(){var e=this._readableState;return e.flowing||(M("resume"),e.flowing=!0,b(this,e)),this},i.prototype.pause=function(){return M("call pause flowing=%j",this._readableState.flowing),!1!==this._readableState.flowing&&(M("pause"),this._readableState.flowing=!1,this.emit("pause")),this},i.prototype.wrap=function(e){var t=this._readableState,r=!1,n=this;e.on("end",function(){if(M("wrapped end"),t.decoder&&!t.ended){var e=t.decoder.end();e&&e.length&&n.push(e)}n.push(null)}),e.on("data",function(i){if(M("wrapped data"),t.decoder&&(i=t.decoder.write(i)),(!t.objectMode||null!==i&&void 0!==i)&&(t.objectMode||i&&i.length)){var o=n.push(i);o||(r=!0,e.pause())}});for(var i in e)void 0===this[i]&&"function"==typeof e[i]&&(this[i]=function(t){return function(){return e[t].apply(e,arguments)}}(i));var o=["error","close","destroy","pause","resume"];return S(o,function(t){e.on(t,n.emit.bind(n,t))}),n._read=function(t){M("wrapped _read",t),r&&(r=!1,e.resume())},n},i._fromList=w}).call(this,e("_process"))},{"./_stream_duplex":62,_process:51,buffer:7,"core-util-is":9,events:10,inherits:13,isarray:15,"process-nextick-args":50,"string_decoder/":71,util:6}],65:[function(e,t,r){"use strict";function n(e){this.afterTransform=function(t,r){return i(e,t,r)},this.needTransform=!1,this.transforming=!1,this.writecb=null,this.writechunk=null}function i(e,t,r){var n=e._transformState;n.transforming=!1;var i=n.writecb;if(!i)return e.emit("error",new Error("no writecb in Transform class"));n.writechunk=null,n.writecb=null,null!==r&&void 0!==r&&e.push(r),i&&i(t);var o=e._readableState;o.reading=!1,(o.needReadable||o.length-1))throw new TypeError("Unknown encoding: "+e);this._writableState.defaultEncoding=e},s.prototype._write=function(e,t,r){r(new Error("not implemented"))},s.prototype._writev=null,s.prototype.end=function(e,t,r){var n=this._writableState;"function"==typeof e?(r=e,e=null,t=null):"function"==typeof t&&(r=t,t=null),null!==e&&void 0!==e&&this.write(e,t),n.corked&&(n.corked=1,this.uncork()),n.ending||n.finished||_(this,n,r)}},{"./_stream_duplex":62,buffer:7,"core-util-is":9,events:10,inherits:13,"process-nextick-args":50,"util-deprecate":73}],67:[function(e,t,r){t.exports=e("./lib/_stream_passthrough.js")},{"./lib/_stream_passthrough.js":63}],68:[function(e,t,r){var n=function(){try{return e("stream")}catch(t){}}();r=t.exports=e("./lib/_stream_readable.js"),r.Stream=n||r,r.Readable=r,r.Writable=e("./lib/_stream_writable.js"),r.Duplex=e("./lib/_stream_duplex.js"),r.Transform=e("./lib/_stream_transform.js"),r.PassThrough=e("./lib/_stream_passthrough.js")},{"./lib/_stream_duplex.js":62,"./lib/_stream_passthrough.js":63,"./lib/_stream_readable.js":64,"./lib/_stream_transform.js":65,"./lib/_stream_writable.js":66}],69:[function(e,t,r){arguments[4][58][0].apply(r,arguments)},{"./lib/_stream_transform.js":65,dup:58}],70:[function(e,t,r){t.exports=e("./lib/_stream_writable.js")},{"./lib/_stream_writable.js":66}],71:[function(e,t,r){function n(e){if(e&&!u(e))throw new Error("Unknown encoding: "+e)}function i(e){return e.toString(this.encoding)}function o(e){this.charReceived=e.length%2,this.charLength=this.charReceived?2:0}function s(e){this.charReceived=e.length%3,this.charLength=this.charReceived?3:0}var a=e("buffer").Buffer,u=a.isEncoding||function(e){switch(e&&e.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return!0;default:return!1}},c=r.StringDecoder=function(e){switch(this.encoding=(e||"utf8").toLowerCase().replace(/[-_]/,""),n(e),this.encoding){case"utf8":this.surrogateSize=3;break;case"ucs2":case"utf16le":this.surrogateSize=2,this.detectIncompleteChar=o;break;case"base64":this.surrogateSize=3,this.detectIncompleteChar=s;break;default:return void(this.write=i)}this.charBuffer=new a(6),this.charReceived=0,this.charLength=0};c.prototype.write=function(e){for(var t="";this.charLength;){var r=e.length>=this.charLength-this.charReceived?this.charLength-this.charReceived:e.length;if(e.copy(this.charBuffer,this.charReceived,0,r),this.charReceived+=r,this.charReceived=55296&&56319>=n)){if(this.charReceived=this.charLength=0,0===e.length)return t;break}this.charLength+=this.surrogateSize,t=""}this.detectIncompleteChar(e);var i=e.length;this.charLength&&(e.copy(this.charBuffer,0,e.length-this.charReceived,i),i-=this.charReceived),t+=e.toString(this.encoding,0,i);var i=t.length-1,n=t.charCodeAt(i);if(n>=55296&&56319>=n){var o=this.surrogateSize;return this.charLength+=o,this.charReceived+=o,this.charBuffer.copy(this.charBuffer,o,0,o),e.copy(this.charBuffer,0,0,o),t.substring(0,i)}return t},c.prototype.detectIncompleteChar=function(e){for(var t=e.length>=3?3:e.length;t>0;t--){var r=e[e.length-t];if(1==t&&r>>5==6){this.charLength=2;break}if(2>=t&&r>>4==14){this.charLength=3;break}if(3>=t&&r>>3==30){this.charLength=4;break}}this.charReceived=t},c.prototype.end=function(e){var t="";if(e&&e.length&&(t=this.write(e)),this.charReceived){var r=this.charReceived,n=this.charBuffer,i=this.encoding;t+=n.slice(0,r).toString(i)}return t}},{buffer:7}],72:[function(e,t,r){(function(r){function n(e){s.call(this,e),this._destroyed=!1}function i(e,t,r){r(null,e)}function o(e){return function(t,r,n){return"function"==typeof t&&(n=r,r=t,t={}),"function"!=typeof r&&(r=i),"function"!=typeof n&&(n=null),e(t,r,n)}}var s=e("readable-stream/transform"),a=e("util").inherits,u=e("xtend");a(n,s),n.prototype.destroy=function(e){if(!this._destroyed){this._destroyed=!0;var t=this;r.nextTick(function(){e&&t.emit("error",e),t.emit("close")})}},t.exports=o(function(e,t,r){var i=new n(e);return i._transform=t,r&&(i._flush=r),i}),t.exports.ctor=o(function(e,t,r){function i(t){return this instanceof i?(this.options=u(e,t),void n.call(this,this.options)):new i(t)}return a(i,n),i.prototype._transform=t,r&&(i.prototype._flush=r),i}),t.exports.obj=o(function(e,t,r){var i=new n(u({objectMode:!0,highWaterMark:16},e));return i._transform=t,r&&(i._flush=r),i})}).call(this,e("_process"))},{_process:51,"readable-stream/transform":58,util:75,xtend:76}],73:[function(e,t,r){(function(e){function r(e,t){function r(){if(!i){if(n("throwDeprecation"))throw new Error(t);n("traceDeprecation")?console.trace(t):console.warn(t),i=!0}return e.apply(this,arguments)}if(n("noDeprecation"))return e;var i=!1;return r}function n(t){try{if(!e.localStorage)return!1}catch(r){return!1}var n=e.localStorage[t];return null==n?!1:"true"===String(n).toLowerCase()}t.exports=r}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],74:[function(e,t,r){t.exports=function(e){return e&&"object"==typeof e&&"function"==typeof e.copy&&"function"==typeof e.fill&&"function"==typeof e.readUInt8}},{}],75:[function(e,t,r){(function(t,n){function i(e,t){var n={seen:[],stylize:s};return arguments.length>=3&&(n.depth=arguments[2]),arguments.length>=4&&(n.colors=arguments[3]),g(t)?n.showHidden=t:t&&r._extend(n,t),_(n.showHidden)&&(n.showHidden=!1),_(n.depth)&&(n.depth=2),_(n.colors)&&(n.colors=!1),_(n.customInspect)&&(n.customInspect=!0),n.colors&&(n.stylize=o),u(n,e,n.depth)}function o(e,t){var r=i.styles[t];return r?"["+i.colors[r][0]+"m"+e+"["+i.colors[r][1]+"m":e}function s(e,t){return e}function a(e){var t={};return e.forEach(function(e,r){t[e]=!0}),t}function u(e,t,n){if(e.customInspect&&t&&R(t.inspect)&&t.inspect!==r.inspect&&(!t.constructor||t.constructor.prototype!==t)){var i=t.inspect(n,e);return y(i)||(i=u(e,i,n)),i}var o=c(e,t);if(o)return o;var s=Object.keys(t),g=a(s);if(e.showHidden&&(s=Object.getOwnPropertyNames(t)),x(t)&&(s.indexOf("message")>=0||s.indexOf("description")>=0))return f(t);if(0===s.length){if(R(t)){var v=t.name?": "+t.name:"";return e.stylize("[Function"+v+"]","special")}if(E(t))return e.stylize(RegExp.prototype.toString.call(t),"regexp");if(j(t))return e.stylize(Date.prototype.toString.call(t),"date");if(x(t))return f(t)}var b="",m=!1,w=["{","}"];if(p(t)&&(m=!0,w=["[","]"]),R(t)){var _=t.name?": "+t.name:"";b=" [Function"+_+"]"}if(E(t)&&(b=" "+RegExp.prototype.toString.call(t)),j(t)&&(b=" "+Date.prototype.toUTCString.call(t)),x(t)&&(b=" "+f(t)),0===s.length&&(!m||0==t.length))return w[0]+b+w[1];if(0>n)return E(t)?e.stylize(RegExp.prototype.toString.call(t),"regexp"):e.stylize("[Object]","special");e.seen.push(t);var S;return S=m?l(e,t,n,g,s):s.map(function(r){return h(e,t,n,g,r,m)}),e.seen.pop(),d(S,b,w)}function c(e,t){if(_(t))return e.stylize("undefined","undefined");if(y(t)){var r="'"+JSON.stringify(t).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return e.stylize(r,"string")}return m(t)?e.stylize(""+t,"number"):g(t)?e.stylize(""+t,"boolean"):v(t)?e.stylize("null","null"):void 0}function f(e){return"["+Error.prototype.toString.call(e)+"]"}function l(e,t,r,n,i){for(var o=[],s=0,a=t.length;a>s;++s)M(t,String(s))?o.push(h(e,t,r,n,String(s),!0)):o.push("");return i.forEach(function(i){i.match(/^\d+$/)||o.push(h(e,t,r,n,i,!0))}),o}function h(e,t,r,n,i,o){var s,a,c;if(c=Object.getOwnPropertyDescriptor(t,i)||{value:t[i]},c.get?a=c.set?e.stylize("[Getter/Setter]","special"):e.stylize("[Getter]","special"):c.set&&(a=e.stylize("[Setter]","special")),M(n,i)||(s="["+i+"]"),a||(e.seen.indexOf(c.value)<0?(a=v(r)?u(e,c.value,null):u(e,c.value,r-1),a.indexOf("\n")>-1&&(a=o?a.split("\n").map(function(e){return" "+e}).join("\n").substr(2):"\n"+a.split("\n").map(function(e){return" "+e}).join("\n"))):a=e.stylize("[Circular]","special")),_(s)){if(o&&i.match(/^\d+$/))return a;s=JSON.stringify(""+i),s.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(s=s.substr(1,s.length-2),s=e.stylize(s,"name")):(s=s.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),s=e.stylize(s,"string"))}return s+": "+a}function d(e,t,r){var n=0,i=e.reduce(function(e,t){return n++,t.indexOf("\n")>=0&&n++,e+t.replace(/\u001b\[\d\d?m/g,"").length+1},0);return i>60?r[0]+(""===t?"":t+"\n ")+" "+e.join(",\n ")+" "+r[1]:r[0]+t+" "+e.join(", ")+" "+r[1]}function p(e){return Array.isArray(e)}function g(e){return"boolean"==typeof e}function v(e){return null===e}function b(e){return null==e}function m(e){return"number"==typeof e}function y(e){return"string"==typeof e}function w(e){return"symbol"==typeof e}function _(e){return void 0===e}function E(e){return S(e)&&"[object RegExp]"===k(e)}function S(e){return"object"==typeof e&&null!==e}function j(e){return S(e)&&"[object Date]"===k(e)}function x(e){return S(e)&&("[object Error]"===k(e)||e instanceof Error)}function R(e){return"function"==typeof e}function L(e){return null===e||"boolean"==typeof e||"number"==typeof e||"string"==typeof e||"symbol"==typeof e||"undefined"==typeof e}function k(e){return Object.prototype.toString.call(e)}function A(e){return 10>e?"0"+e.toString(10):e.toString(10)}function B(){var e=new Date,t=[A(e.getHours()),A(e.getMinutes()),A(e.getSeconds())].join(":");return[e.getDate(),P[e.getMonth()],t].join(" ")}function M(e,t){return Object.prototype.hasOwnProperty.call(e,t)}var O=/%[sdj%]/g;r.format=function(e){if(!y(e)){for(var t=[],r=0;r=o)return e;switch(e){case"%s":return String(n[r++]);case"%d":return Number(n[r++]);case"%j":try{return JSON.stringify(n[r++])}catch(t){return"[Circular]"}default:return e}}),a=n[r];o>r;a=n[++r])s+=v(a)||!S(a)?" "+a:" "+i(a);return s},r.deprecate=function(e,i){function o(){if(!s){if(t.throwDeprecation)throw new Error(i);t.traceDeprecation?console.trace(i):console.error(i),s=!0}return e.apply(this,arguments)}if(_(n.process))return function(){return r.deprecate(e,i).apply(this,arguments)};if(t.noDeprecation===!0)return e;var s=!1;return o};var T,I={};r.debuglog=function(e){if(_(T)&&(T=t.env.NODE_DEBUG||""),e=e.toUpperCase(),!I[e])if(new RegExp("\\b"+e+"\\b","i").test(T)){var n=t.pid;I[e]=function(){var t=r.format.apply(r,arguments);console.error("%s %d: %s",e,n,t)}}else I[e]=function(){};return I[e]},r.inspect=i,i.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},i.styles={special:"cyan",number:"yellow","boolean":"yellow",undefined:"grey","null":"bold",string:"green",date:"magenta",regexp:"red"},r.isArray=p,r.isBoolean=g,r.isNull=v,r.isNullOrUndefined=b,r.isNumber=m,r.isString=y,r.isSymbol=w,r.isUndefined=_,r.isRegExp=E,r.isObject=S,r.isDate=j,r.isError=x,r.isFunction=R,r.isPrimitive=L,r.isBuffer=e("./support/isBuffer");var P=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];r.log=function(){console.log("%s - %s",B(),r.format.apply(r,arguments))},r.inherits=e("inherits"),r._extend=function(e,t){if(!t||!S(t))return e;for(var r=Object.keys(t),n=r.length;n--;)e[r[n]]=t[r[n]];return e}}).call(this,e("_process"),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./support/isBuffer":74,_process:51,inherits:13}],76:[function(e,t,r){function n(){for(var e={},t=0;t dist/pouchdb.replication-stream.js",min:"uglifyjs dist/pouchdb.replication-stream.js -mc > dist/pouchdb.replication-stream.min.js",dev:"browserify test/test.js > test/test-bundle.js && npm run dev-server","dev-server":"./bin/dev-server.js",coverage:"npm test --coverage && istanbul check-coverage --lines 100 --function 100 --statements 100 --branches 100"},dependencies:{argsarray:"0.0.1",inherits:"~2.0.1","ldjson-stream":"^1.2.1",lie:"^2.6.0",lodash:"^3.3.0","pouch-stream":"^0.4.0",through2:"^0.6.1"},devDependencies:{bluebird:"^1.0.7",browserify:"^11.2.0",chai:"^3.3.0","chai-as-promised":"^5.1.0",derequire:"^2.0.0",es3ify:"^0.1.3","http-server":"~0.8.5",istanbul:"^0.2.7",jshint:"^2.3.0",memorystream:"^0.3.0",mkdirp:"^0.5.0",mocha:"~1.18",noms:"0.0.0",phantomjs:"^1.9.7-5",pouchdb:"^5.0.0","random-document-stream":"0.0.0",request:"^2.36.0","sauce-connect-launcher":"^0.4.2","selenium-standalone":"3.0.2","uglify-js":"^2.4.13",watchify:"^3.1.0",wd:"^0.2.21"}}},{}],78:[function(e,t,r){"use strict";var n=e("./pouch-utils"),i=e("./version"),o=e("ldjson-stream"),s=e("through2").obj,a=e("lodash/object/pick"),u=e("./to-buffer-stream"),c=50,f=["batch_size","batches_limit","filter","doc_ids","query_params","since","view"];r.adapters={},r.adapters.writableStream=e("./writable-stream"),r.plugin=e("pouch-stream"),r.plugin.dump=n.toPromise(function(e,t,r){function n(e){r(e)}var o=this;"function"==typeof t&&(r=t,t={});var s=o.constructor,u=new s(o._db_name,{adapter:"writableStream"});u.setupStream(e);var l=o.info().then(function(r){var n={version:i,db_type:o.type(),start_time:(new Date).toJSON(),db_info:r};return e.write(JSON.stringify(n)+"\n"),t=a(t,f),t.batch_size||(t.batch_size=c),o.replicate.to(u,t)}).then(function(){return u.close()}).then(function(){r(null,{ok:!0})});l["catch"](n)}),r.plugin.load=n.toPromise(function(e,t,r){"function"==typeof t&&(r=t,t={});var n;n="batch_size"in t?t.batch_size:c;var i=[];e.pipe(u()).pipe(o.parse()).pipe(s(function(e,t,r){return e.docs?(e.docs.forEach(function(e){this.push(e)},this),void r()):r()})).pipe(s(function(e,t,r){i.push(e),i.length>=n&&(this.push(i),i=[]),r()},function(e){i.length&&this.push(i),e()})).pipe(this.createWriteStream({new_edits:!1})).on("error",r).on("finish",function(){r(null,{ok:!0})})}),"undefined"!=typeof window&&window.PouchDB&&(window.PouchDB.plugin(r.plugin),window.PouchDB.adapter("writableStream",r.adapters.writableStream))},{"./pouch-utils":1,"./to-buffer-stream":2,"./version":3,"./writable-stream":4,"ldjson-stream":16,"lodash/object/pick":40,"pouch-stream":44,through2:72}]},{},[78]); +!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.PouchReplicationStream=e()}}(function(){return function e(t,n,r){function i(s,a){if(!n[s]){if(!t[s]){var u="function"==typeof require&&require;if(!a&&u)return u(s,!0);if(o)return o(s,!0);var f=new Error("Cannot find module '"+s+"'");throw f.code="MODULE_NOT_FOUND",f}var c=n[s]={exports:{}};t[s][0].call(c.exports,function(e){var n=t[s][1][e];return i(n?n:e)},c,c.exports,e,t,n,r)}return n[s].exports}for(var o="function"==typeof require&&require,s=0;s0)throw new Error("Invalid string. Length must be a multiple of 4");var c=e.length;u="="===e.charAt(c-2)?2:"="===e.charAt(c-1)?1:0,f=new o(3*e.length/4-u),s=u>0?e.length-4:e.length;var l=0;for(r=0,i=0;r>16),n((65280&a)>>8),n(255&a);return 2===u?(a=t(e.charAt(r))<<2|t(e.charAt(r+1))>>4,n(255&a)):1===u&&(a=t(e.charAt(r))<<10|t(e.charAt(r+1))<<4|t(e.charAt(r+2))>>2,n(a>>8&255),n(255&a)),f}function i(e){function t(e){return r.charAt(e)}function n(e){return t(e>>18&63)+t(e>>12&63)+t(e>>6&63)+t(63&e)}var i,o,s,a=e.length%3,u="";for(i=0,s=e.length-a;i>2),u+=t(o<<4&63),u+="==";break;case 2:o=(e[e.length-2]<<8)+e[e.length-1],u+=t(o>>10),u+=t(o>>4&63),u+=t(o<<2&63),u+="="}return u}var o="undefined"!=typeof Uint8Array?Uint8Array:Array,s="+".charCodeAt(0),a="/".charCodeAt(0),u="0".charCodeAt(0),f="a".charCodeAt(0),c="A".charCodeAt(0),l="-".charCodeAt(0),h="_".charCodeAt(0);e.toByteArray=n,e.fromByteArray=i}("undefined"==typeof n?this.base64js={}:n)},{}],6:[function(e,t,n){},{}],7:[function(e,t,n){(function(t){"use strict";var r=e(8),i=r.Buffer,o=r.SlowBuffer,s=r.kMaxLength||2147483647;n.alloc=function(e,t,n){if("function"==typeof i.alloc)return i.alloc(e,t,n);if("number"==typeof n)throw new TypeError("encoding must not be number");if("number"!=typeof e)throw new TypeError("size must be a number");if(e>s)throw new RangeError("size is too large");var r=n,o=t;void 0===o&&(r=void 0,o=0);var a=new i(e);if("string"==typeof o)for(var u=new i(o,r),f=u.length,c=-1;++cs)throw new RangeError("size is too large");return new i(e)},n.from=function(e,n,r){if("function"==typeof i.from&&(!t.Uint8Array||Uint8Array.from!==i.from))return i.from(e,n,r);if("number"==typeof e)throw new TypeError('"value" argument must not be a number');if("string"==typeof e)return new i(e,n);if("undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer){var o=n;if(1===arguments.length)return new i(e);"undefined"==typeof o&&(o=0);var s=r;if("undefined"==typeof s&&(s=e.byteLength-o),o>=e.byteLength)throw new RangeError("'offset' is out of bounds");if(s>e.byteLength-o)throw new RangeError("'length' is out of bounds");return new i(e.slice(o,o+s))}if(i.isBuffer(e)){var a=new i(e.length);return e.copy(a,0,0,e.length),a}if(e){if(Array.isArray(e)||"undefined"!=typeof ArrayBuffer&&e.buffer instanceof ArrayBuffer||"length"in e)return new i(e);if("Buffer"===e.type&&Array.isArray(e.data))return new i(e.data)}throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")},n.allocUnsafeSlow=function(e){if("function"==typeof i.allocUnsafeSlow)return i.allocUnsafeSlow(e);if("number"!=typeof e)throw new TypeError("size must be a number");if(e>=s)throw new RangeError("size is too large");return new o(e)}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{8:8}],8:[function(e,t,n){(function(t){"use strict";function r(){function e(){}try{var t=new Uint8Array(1);return t.foo=function(){return 42},t.constructor=e,42===t.foo()&&t.constructor===e&&"function"==typeof t.subarray&&0===t.subarray(1,1).byteLength}catch(e){return!1}}function i(){return o.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function o(e){return this instanceof o?(o.TYPED_ARRAY_SUPPORT||(this.length=0,this.parent=void 0),"number"==typeof e?s(this,e):"string"==typeof e?a(this,e,arguments.length>1?arguments[1]:"utf8"):u(this,e)):arguments.length>1?new o(e,arguments[1]):new o(e)}function s(e,t){if(e=g(e,t<0?0:0|v(t)),!o.TYPED_ARRAY_SUPPORT)for(var n=0;n>>1;return n&&(e.parent=Z),e}function v(e){if(e>=i())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+i().toString(16)+" bytes");return 0|e}function b(e,t){if(!(this instanceof b))return new b(e,t);var n=new o(e,t);return delete n.parent,n}function w(e,t){"string"!=typeof e&&(e=""+e);var n=e.length;if(0===n)return 0;for(var r=!1;;)switch(t){case"ascii":case"binary":case"raw":case"raws":return n;case"utf8":case"utf-8":return Y(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return H(e).length;default:if(r)return Y(e).length;t=(""+t).toLowerCase(),r=!0}}function y(e,t,n){var r=!1;if(t=0|t,n=void 0===n||n===1/0?this.length:0|n,e||(e="utf8"),t<0&&(t=0),n>this.length&&(n=this.length),n<=t)return"";for(;;)switch(e){case"hex":return B(this,t,n);case"utf8":case"utf-8":return j(this,t,n);case"ascii":return x(this,t,n);case"binary":return A(this,t,n);case"base64":return M(this,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return T(this,t,n);default:if(r)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),r=!0}}function m(e,t,n,r){n=Number(n)||0;var i=e.length-n;r?(r=Number(r),r>i&&(r=i)):r=i;var o=t.length;if(o%2!==0)throw new Error("Invalid hex string");r>o/2&&(r=o/2);for(var s=0;s239?4:o>223?3:o>191?2:1;if(i+a<=n){var u,f,c,l;switch(a){case 1:o<128&&(s=o);break;case 2:u=e[i+1],128===(192&u)&&(l=(31&o)<<6|63&u,l>127&&(s=l));break;case 3:u=e[i+1],f=e[i+2],128===(192&u)&&128===(192&f)&&(l=(15&o)<<12|(63&u)<<6|63&f,l>2047&&(l<55296||l>57343)&&(s=l));break;case 4:u=e[i+1],f=e[i+2],c=e[i+3],128===(192&u)&&128===(192&f)&&128===(192&c)&&(l=(15&o)<<18|(63&u)<<12|(63&f)<<6|63&c,l>65535&&l<1114112&&(s=l))}}null===s?(s=65533,a=1):s>65535&&(s-=65536,r.push(s>>>10&1023|55296),s=56320|1023&s),r.push(s),i+=a}return L(r)}function L(e){var t=e.length;if(t<=K)return String.fromCharCode.apply(String,e);for(var n="",r=0;rr)&&(n=r);for(var i="",o=t;on)throw new RangeError("Trying to access beyond buffer length")}function O(e,t,n,r,i,s){if(!o.isBuffer(e))throw new TypeError("buffer must be a Buffer instance");if(t>i||te.length)throw new RangeError("index out of range")}function I(e,t,n,r){t<0&&(t=65535+t+1);for(var i=0,o=Math.min(e.length-n,2);i>>8*(r?i:1-i)}function C(e,t,n,r){t<0&&(t=4294967295+t+1);for(var i=0,o=Math.min(e.length-n,4);i>>8*(r?i:3-i)&255}function P(e,t,n,r,i,o){if(t>i||te.length)throw new RangeError("index out of range");if(n<0)throw new RangeError("index out of range")}function U(e,t,n,r,i){return i||P(e,t,n,4,3.4028234663852886e38,-3.4028234663852886e38),X.write(e,t,n,r,23,4),n+4}function q(e,t,n,r,i){return i||P(e,t,n,8,1.7976931348623157e308,-1.7976931348623157e308),X.write(e,t,n,r,52,8),n+8}function W(e){if(e=N(e).replace(ee,""),e.length<2)return"";for(;e.length%4!==0;)e+="=";return e}function N(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}function F(e){return e<16?"0"+e.toString(16):e.toString(16)}function Y(e,t){t=t||1/0;for(var n,r=e.length,i=null,o=[],s=0;s55295&&n<57344){if(!i){if(n>56319){(t-=3)>-1&&o.push(239,191,189);continue}if(s+1===r){(t-=3)>-1&&o.push(239,191,189);continue}i=n;continue}if(n<56320){(t-=3)>-1&&o.push(239,191,189),i=n;continue}n=(i-55296<<10|n-56320)+65536}else i&&(t-=3)>-1&&o.push(239,191,189);if(i=null,n<128){if((t-=1)<0)break;o.push(n)}else if(n<2048){if((t-=2)<0)break;o.push(n>>6|192,63&n|128)}else if(n<65536){if((t-=3)<0)break;o.push(n>>12|224,n>>6&63|128,63&n|128)}else{if(!(n<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;o.push(n>>18|240,n>>12&63|128,n>>6&63|128,63&n|128)}}return o}function z(e){for(var t=[],n=0;n>8,i=n%256,o.push(i),o.push(r);return o}function H(e){return $.toByteArray(W(e))}function G(e,t,n,r){for(var i=0;i=t.length||i>=e.length);i++)t[i+n]=e[i];return i}var $=e(5),X=e(12),V=e(9);n.Buffer=o,n.SlowBuffer=b,n.INSPECT_MAX_BYTES=50,o.poolSize=8192;var Z={};o.TYPED_ARRAY_SUPPORT=void 0!==t.TYPED_ARRAY_SUPPORT?t.TYPED_ARRAY_SUPPORT:r(),o.TYPED_ARRAY_SUPPORT?(o.prototype.__proto__=Uint8Array.prototype,o.__proto__=Uint8Array):(o.prototype.length=void 0,o.prototype.parent=void 0),o.isBuffer=function(e){return!(null==e||!e._isBuffer)},o.compare=function(e,t){if(!o.isBuffer(e)||!o.isBuffer(t))throw new TypeError("Arguments must be Buffers");if(e===t)return 0;for(var n=e.length,r=t.length,i=0,s=Math.min(n,r);i0&&(e=this.toString("hex",0,t).match(/.{2}/g).join(" "),this.length>t&&(e+=" ... ")),""},o.prototype.compare=function(e){if(!o.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e?0:o.compare(this,e)},o.prototype.indexOf=function(e,t){function n(e,t,n){for(var r=-1,i=0;n+i2147483647?t=2147483647:t<-2147483648&&(t=-2147483648),t>>=0,0===this.length)return-1;if(t>=this.length)return-1;if(t<0&&(t=Math.max(this.length+t,0)),"string"==typeof e)return 0===e.length?-1:String.prototype.indexOf.call(this,e,t);if(o.isBuffer(e))return n(this,e,t);if("number"==typeof e)return o.TYPED_ARRAY_SUPPORT&&"function"===Uint8Array.prototype.indexOf?Uint8Array.prototype.indexOf.call(this,e,t):n(this,[e],t);throw new TypeError("val must be string, number or Buffer")},o.prototype.get=function(e){return console.log(".get() is deprecated. Access using array indexes instead."),this.readUInt8(e)},o.prototype.set=function(e,t){return console.log(".set() is deprecated. Access using array indexes instead."),this.writeUInt8(e,t)},o.prototype.write=function(e,t,n,r){if(void 0===t)r="utf8",n=this.length,t=0;else if(void 0===n&&"string"==typeof t)r=t,n=this.length,t=0;else if(isFinite(t))t=0|t,isFinite(n)?(n=0|n,void 0===r&&(r="utf8")):(r=n,n=void 0);else{var i=r;r=t,t=0|n,n=i}var o=this.length-t;if((void 0===n||n>o)&&(n=o),e.length>0&&(n<0||t<0)||t>this.length)throw new RangeError("attempt to write outside buffer bounds");r||(r="utf8");for(var s=!1;;)switch(r){case"hex":return m(this,e,t,n);case"utf8":case"utf-8":return _(this,e,t,n);case"ascii":return E(this,e,t,n);case"binary":return S(this,e,t,n);case"base64":return R(this,e,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return k(this,e,t,n);default:if(s)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase(),s=!0}},o.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var K=4096;o.prototype.slice=function(e,t){var n=this.length;e=~~e,t=void 0===t?n:~~t,e<0?(e+=n,e<0&&(e=0)):e>n&&(e=n),t<0?(t+=n,t<0&&(t=0)):t>n&&(t=n),t0&&(i*=256);)r+=this[e+--t]*i;return r},o.prototype.readUInt8=function(e,t){return t||D(e,1,this.length),this[e]},o.prototype.readUInt16LE=function(e,t){return t||D(e,2,this.length),this[e]|this[e+1]<<8},o.prototype.readUInt16BE=function(e,t){return t||D(e,2,this.length),this[e]<<8|this[e+1]},o.prototype.readUInt32LE=function(e,t){return t||D(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},o.prototype.readUInt32BE=function(e,t){return t||D(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},o.prototype.readIntLE=function(e,t,n){e=0|e,t=0|t,n||D(e,t,this.length);for(var r=this[e],i=1,o=0;++o=i&&(r-=Math.pow(2,8*t)),r},o.prototype.readIntBE=function(e,t,n){e=0|e,t=0|t,n||D(e,t,this.length);for(var r=t,i=1,o=this[e+--r];r>0&&(i*=256);)o+=this[e+--r]*i;return i*=128,o>=i&&(o-=Math.pow(2,8*t)),o},o.prototype.readInt8=function(e,t){return t||D(e,1,this.length),128&this[e]?(255-this[e]+1)*-1:this[e]},o.prototype.readInt16LE=function(e,t){t||D(e,2,this.length);var n=this[e]|this[e+1]<<8;return 32768&n?4294901760|n:n},o.prototype.readInt16BE=function(e,t){t||D(e,2,this.length);var n=this[e+1]|this[e]<<8;return 32768&n?4294901760|n:n},o.prototype.readInt32LE=function(e,t){return t||D(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},o.prototype.readInt32BE=function(e,t){return t||D(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},o.prototype.readFloatLE=function(e,t){return t||D(e,4,this.length),X.read(this,e,!0,23,4)},o.prototype.readFloatBE=function(e,t){return t||D(e,4,this.length),X.read(this,e,!1,23,4)},o.prototype.readDoubleLE=function(e,t){return t||D(e,8,this.length),X.read(this,e,!0,52,8)},o.prototype.readDoubleBE=function(e,t){return t||D(e,8,this.length),X.read(this,e,!1,52,8)},o.prototype.writeUIntLE=function(e,t,n,r){e=+e,t=0|t,n=0|n,r||O(this,e,t,n,Math.pow(2,8*n),0);var i=1,o=0;for(this[t]=255&e;++o=0&&(o*=256);)this[t+i]=e/o&255;return t+n},o.prototype.writeUInt8=function(e,t,n){return e=+e,t=0|t,n||O(this,e,t,1,255,0),o.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),this[t]=255&e,t+1},o.prototype.writeUInt16LE=function(e,t,n){return e=+e,t=0|t,n||O(this,e,t,2,65535,0),o.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):I(this,e,t,!0),t+2},o.prototype.writeUInt16BE=function(e,t,n){return e=+e,t=0|t,n||O(this,e,t,2,65535,0),o.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):I(this,e,t,!1),t+2},o.prototype.writeUInt32LE=function(e,t,n){return e=+e,t=0|t,n||O(this,e,t,4,4294967295,0),o.TYPED_ARRAY_SUPPORT?(this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e):C(this,e,t,!0),t+4},o.prototype.writeUInt32BE=function(e,t,n){return e=+e,t=0|t,n||O(this,e,t,4,4294967295,0),o.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):C(this,e,t,!1),t+4},o.prototype.writeIntLE=function(e,t,n,r){if(e=+e,t=0|t,!r){var i=Math.pow(2,8*n-1);O(this,e,t,n,i-1,-i)}var o=0,s=1,a=e<0?1:0;for(this[t]=255&e;++o>0)-a&255;return t+n},o.prototype.writeIntBE=function(e,t,n,r){if(e=+e,t=0|t,!r){var i=Math.pow(2,8*n-1);O(this,e,t,n,i-1,-i)}var o=n-1,s=1,a=e<0?1:0;for(this[t+o]=255&e;--o>=0&&(s*=256);)this[t+o]=(e/s>>0)-a&255;return t+n},o.prototype.writeInt8=function(e,t,n){return e=+e,t=0|t,n||O(this,e,t,1,127,-128),o.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),e<0&&(e=255+e+1),this[t]=255&e,t+1},o.prototype.writeInt16LE=function(e,t,n){return e=+e,t=0|t,n||O(this,e,t,2,32767,-32768),o.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):I(this,e,t,!0),t+2},o.prototype.writeInt16BE=function(e,t,n){return e=+e,t=0|t,n||O(this,e,t,2,32767,-32768),o.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):I(this,e,t,!1),t+2},o.prototype.writeInt32LE=function(e,t,n){return e=+e,t=0|t,n||O(this,e,t,4,2147483647,-2147483648),o.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24):C(this,e,t,!0),t+4},o.prototype.writeInt32BE=function(e,t,n){return e=+e,t=0|t,n||O(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),o.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):C(this,e,t,!1),t+4},o.prototype.writeFloatLE=function(e,t,n){return U(this,e,t,!0,n)},o.prototype.writeFloatBE=function(e,t,n){return U(this,e,t,!1,n)},o.prototype.writeDoubleLE=function(e,t,n){return q(this,e,t,!0,n)},o.prototype.writeDoubleBE=function(e,t,n){return q(this,e,t,!1,n)},o.prototype.copy=function(e,t,n,r){if(n||(n=0),r||0===r||(r=this.length),t>=e.length&&(t=e.length),t||(t=0),r>0&&r=this.length)throw new RangeError("sourceStart out of bounds");if(r<0)throw new RangeError("sourceEnd out of bounds");r>this.length&&(r=this.length),e.length-t=0;i--)e[i+t]=this[i+n];else if(s<1e3||!o.TYPED_ARRAY_SUPPORT)for(i=0;i=this.length)throw new RangeError("start out of bounds");if(n<0||n>this.length)throw new RangeError("end out of bounds");var r;if("number"==typeof e)for(r=t;r0&&this._events[e].length>n&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace())}return this},r.prototype.on=r.prototype.addListener,r.prototype.once=function(e,t){function n(){this.removeListener(e,n),r||(r=!0,t.apply(this,arguments))}if(!i(t))throw TypeError("listener must be a function");var r=!1;return n.listener=t,this.on(e,n),this},r.prototype.removeListener=function(e,t){var n,r,o,a;if(!i(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(n=this._events[e],o=n.length,r=-1,n===t||i(n.listener)&&n.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(s(n)){for(a=o;a-- >0;)if(n[a]===t||n[a].listener&&n[a].listener===t){r=a;break}if(r<0)return this;1===n.length?(n.length=0,delete this._events[e]):n.splice(r,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},r.prototype.removeAllListeners=function(e){var t,n;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(n=this._events[e],i(n))this.removeListener(e,n);else for(;n.length;)this.removeListener(e,n[n.length-1]);return delete this._events[e],this},r.prototype.listeners=function(e){var t;return t=this._events&&this._events[e]?i(this._events[e])?[this._events[e]]:this._events[e].slice():[]},r.listenerCount=function(e,t){var n;return n=e._events&&e._events[t]?i(e._events[t])?1:e._events[t].length:0}},{}],12:[function(e,t,n){n.read=function(e,t,n,r,i){var o,s,a=8*i-r-1,u=(1<>1,c=-7,l=n?i-1:0,h=n?-1:1,d=e[t+l];for(l+=h,o=d&(1<<-c)-1,d>>=-c,c+=a;c>0;o=256*o+e[t+l],l+=h,c-=8);for(s=o&(1<<-c)-1,o>>=-c,c+=r;c>0;s=256*s+e[t+l],l+=h,c-=8);if(0===o)o=1-f;else{if(o===u)return s?NaN:(d?-1:1)*(1/0);s+=Math.pow(2,r),o-=f}return(d?-1:1)*s*Math.pow(2,o-r)},n.write=function(e,t,n,r,i,o){var s,a,u,f=8*o-i-1,c=(1<>1,h=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,d=r?0:o-1,p=r?1:-1,g=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,s=c):(s=Math.floor(Math.log(t)/Math.LN2),t*(u=Math.pow(2,-s))<1&&(s--,u*=2),t+=s+l>=1?h/u:h*Math.pow(2,1-l),t*u>=2&&(s++,u/=2),s+l>=c?(a=0,s=c):s+l>=1?(a=(t*u-1)*Math.pow(2,i),s+=l):(a=t*Math.pow(2,l-1)*Math.pow(2,i),s=0));i>=8;e[n+d]=255&a,d+=p,a/=256,i-=8);for(s=s<0;e[n+d]=255&s,d+=p,s/=256,f-=8);e[n+d-p]|=128*g}},{}],13:[function(e,t,n){(function(e){"use strict";function n(){c=!0;for(var e,t,n=l.length;n;){for(t=l,l=[],e=-1;++e0&&n(f)?t>1?s(f,t-1,n,r,o):i(o,f):r||(o[o.length]=f)}return o}function a(e,t){return e=Object(e),u(e,t,function(t,n){return n in e})}function u(e,t,n){for(var r=-1,i=t.length,o={};++r-1&&e%1==0&&e<=_}function b(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function w(e){return!!e&&"object"==typeof e}function y(e){return"symbol"==typeof e||w(e)&&B.call(e)==k}var m=1/0,_=9007199254740991,E="[object Arguments]",S="[object Function]",R="[object GeneratorFunction]",k="[object Symbol]",M="object"==typeof e&&e&&e.Object===Object&&e,j="object"==typeof self&&self&&self.Object===Object&&self,L=M||j||Function("return this")(),x=Object.prototype,A=x.hasOwnProperty,B=x.toString,T=L.Symbol,D=x.propertyIsEnumerable,O=T?T.isConcatSpreadable:void 0,I=Math.max,C=o("length"),P=Array.isArray,U=f(function(e,t){return null==e?{}:a(e,r(s(t,1),l))});t.exports=U}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],20:[function(e,t,n){n.endianness=function(){return"LE"},n.hostname=function(){return"undefined"!=typeof location?location.hostname:""},n.loadavg=function(){return[]},n.uptime=function(){return 0},n.freemem=function(){return Number.MAX_VALUE},n.totalmem=function(){return Number.MAX_VALUE},n.cpus=function(){return[]},n.type=function(){return"Browser"},n.release=function(){return"undefined"!=typeof navigator?navigator.appVersion:""},n.networkInterfaces=n.getNetworkInterfaces=function(){return{}},n.arch=function(){return"javascript"},n.platform=function(){return"browser"},n.tmpdir=n.tmpDir=function(){return"/tmp"},n.EOL="\n"},{}],21:[function(e,t,n){"use strict";t.exports=function(e,t,n){e.on("newListener",function(e,r){~n.indexOf(e)&&t.on(e,r)}),e.on("removeListener",function(e,r){~n.indexOf(e)&&t.removeListener(e,r)})}},{}],22:[function(e,t,n){"use strict";var r=e(24),i=e(23);n.createReadStream=function(e){return e=e||{},new i(this,e)},n.createWriteStream=function(e){return e=e||{},new r(this,e)};var o=e(21),s=["drain","pipe","unpipe","error"];n.write=function(e,t,n){return this.__stream||(this.__stream=new r(this),o(this,this.__stream,s),this.on("destroy",function(){this.__stream.end()})),this.__stream.write(e,t,n)},n.end=function(){this.emit("done")}},{21:21,23:23,24:24}],23:[function(e,t,n){"use strict";function r(e,t){if(!(this instanceof r))return new r(e,t);o.call(this,{objectMode:!0}),t=t||{};var n=this.opts={since:0};Object.keys(t).forEach(function(e){n[e]=t[e]}),this.opts.returnDocs=!1,this.last=t.since,this.db=e,this.changes=void 0,this.canceled=!1}var i=e(14),o=e(34).Readable;t.exports=r,i(r,o),r.prototype._read=function(){if(!this.changes){var e=this;this.opts.since=this.last,this.changes=this.db.changes(this.opts).on("complete",function(t){e.cancel=function(){},t.canceled||e.push(null)}),this.changes.on("change",function(t){e.last=t.seq;var n=e.push(t);n||e.changes.cancel()})}},r.prototype.cancel=function(){if(this.canceled=!0,this.changes&&"function"==typeof this.changes.cancel)return this.changes.cancel()}},{14:14,34:34}],24:[function(e,t,n){(function(n){"use strict";function r(e,t){return this instanceof r?(o.call(this,{objectMode:!0}),this.db=e,void(this.opts=t||{})):new r(e)}var i=e(14),o=e(34).Writable;t.exports=r,i(r,o),r.prototype._write=function(e,t,r){if(n.isBuffer(e)&&(e=e.toString()),"string"==typeof e)try{e=JSON.parse(e)}catch(e){return r(e)}Array.isArray(e)?this.db.bulkDocs({docs:e},this.opts).then(function(){r()},r):"_id"in e?this.db.put(e,this.opts).then(function(){r()},r):this.db.post(e,this.opts).then(function(){r()},r)}}).call(this,{isBuffer:e(15)})},{14:14,15:15,34:34}],25:[function(e,t,n){"use strict";function r(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var i=r(e(26)),o="function"==typeof Promise?Promise:i;t.exports=o},{26:26}],26:[function(e,t,n){"use strict";function r(){}function i(e){if("function"!=typeof e)throw new TypeError("resolver must be a function");this.state=w,this.queue=[],this.outcome=void 0,e!==r&&u(this,e)}function o(e,t,n){this.promise=e,"function"==typeof t&&(this.onFulfilled=t,this.callFulfilled=this.otherCallFulfilled),"function"==typeof n&&(this.onRejected=n,this.callRejected=this.otherCallRejected)}function s(e,t,n){p(function(){var r;try{r=t(n)}catch(t){return g.reject(e,t)}r===e?g.reject(e,new TypeError("Cannot resolve promise with itself")):g.resolve(e,r)})}function a(e){var t=e&&e.then;if(e&&"object"==typeof e&&"function"==typeof t)return function(){t.apply(e,arguments)}}function u(e,t){function n(t){o||(o=!0,g.reject(e,t))}function r(t){o||(o=!0,g.resolve(e,t))}function i(){t(r,n)}var o=!1,s=f(i);"error"===s.status&&n(s.value)}function f(e,t){var n={};try{n.value=e(t),n.status="success"}catch(e){n.status="error",n.value=e}return n}function c(e){return e instanceof this?e:g.resolve(new this(r),e)}function l(e){var t=new this(r);return g.reject(t,e)}function h(e){function t(e,t){function r(e){s[t]=e,++a!==i||o||(o=!0,g.resolve(f,s))}n.resolve(e).then(r,function(e){o||(o=!0,g.reject(f,e))})}var n=this;if("[object Array]"!==Object.prototype.toString.call(e))return this.reject(new TypeError("must be an array"));var i=e.length,o=!1;if(!i)return this.resolve([]);for(var s=new Array(i),a=0,u=-1,f=new this(r);++u1)for(var n=1;n0)if(t.ended&&!i){var a=new Error("stream.push() after EOF");e.emit("error",a)}else if(t.endEmitted&&i){var a=new Error("stream.unshift() after end event");e.emit("error",a)}else!t.decoder||i||r||(n=t.decoder.write(n)),t.length+=t.objectMode?1:n.length,i?t.buffer.unshift(n):(t.reading=!1,t.buffer.push(n)),t.needReadable&&l(e),d(e,t);else i||(t.reading=!1);return s(t)}function s(e){return!e.ended&&(e.needReadable||e.length=x)e=x;else{e--;for(var t=1;t<32;t<<=1)e|=e>>t;e++}return e}function u(e,t){return 0===t.length&&t.ended?0:t.objectMode?0===e?0:1:null===e||isNaN(e)?t.flowing&&t.buffer.length?t.buffer[0].length:t.length:e<=0?0:(e>t.highWaterMark&&(t.highWaterMark=a(e)),e>t.length?t.ended?t.length:(t.needReadable=!0,0):e)}function f(e,t){var n=null;return R.isBuffer(t)||"string"==typeof t||null===t||void 0===t||e.objectMode||(n=new TypeError("Invalid non-string/buffer chunk")),n}function c(e,t){if(t.decoder&&!t.ended){var n=t.decoder.end();n&&n.length&&(t.buffer.push(n),t.length+=t.objectMode?1:n.length)}t.ended=!0,t.length>0?l(e):m(e)}function l(e){var t=e._readableState;t.needReadable=!1,t.emittedReadable||(t.emittedReadable=!0,t.sync?n.nextTick(function(){h(e)}):h(e))}function h(e){e.emit("readable")}function d(e,t){t.readingMore||(t.readingMore=!0,n.nextTick(function(){p(e,t)}))}function p(e,t){for(var n=t.length;!t.reading&&!t.flowing&&!t.ended&&t.length0)return;return 0===r.pipesCount?(r.flowing=!1,void(k.listenerCount(e,"data")>0&&w(e))):void(r.ranOut=!0)}function b(){this._readableState.ranOut&&(this._readableState.ranOut=!1,v(this))}function w(e,t){var r=e._readableState;if(r.flowing)throw new Error("Cannot switch to old mode now.");var i=t||!1,o=!1;e.readable=!0,e.pipe=M.prototype.pipe,e.on=e.addListener=M.prototype.on,e.on("readable",function(){o=!0;for(var t;!i&&null!==(t=e.read());)e.emit("data",t);null===t&&(o=!1,e._readableState.needReadable=!0)}),e.pause=function(){i=!0,this.emit("pause")},e.resume=function(){i=!1,o?n.nextTick(function(){e.emit("readable")}):this.read(0),this.emit("resume")},e.emit("readable")}function y(e,t){var n,r=t.buffer,i=t.length,o=!!t.decoder,s=!!t.objectMode;if(0===r.length)return null;if(0===i)n=null;else if(s)n=r.shift();else if(!e||e>=i)n=o?r.join(""):R.concat(r,i),r.length=0;else if(e0)throw new Error("endReadable called on non-empty stream");!t.endEmitted&&t.calledRead&&(t.ended=!0,n.nextTick(function(){t.endEmitted||0!==t.length||(t.endEmitted=!0,e.readable=!1,e.emit("end"))}))}function _(e,t){for(var n=0,r=e.length;n0)&&(t.emittedReadable=!1),0===e&&t.needReadable&&(t.length>=t.highWaterMark||t.ended))return l(this),null;if(e=u(e,t),0===e&&t.ended)return n=null,t.length>0&&t.decoder&&(n=y(e,t),t.length-=n.length),0===t.length&&m(this),n;var i=t.needReadable;return t.length-e<=t.highWaterMark&&(i=!0),(t.ended||t.reading)&&(i=!1),i&&(t.reading=!0,t.sync=!0,0===t.length&&(t.needReadable=!0),this._read(t.highWaterMark),t.sync=!1),i&&!t.reading&&(e=u(r,t)),n=e>0?y(e,t):null,null===n&&(t.needReadable=!0,e=0),t.length-=e,0!==t.length||t.ended||(t.needReadable=!0),t.ended&&!t.endEmitted&&0===t.length&&m(this),n},i.prototype._read=function(e){this.emit("error",new Error("not implemented"))},i.prototype.pipe=function(e,t){function r(e){e===c&&o()}function i(){e.end()}function o(){e.removeListener("close",a),e.removeListener("finish",u),e.removeListener("drain",p),e.removeListener("error",s),e.removeListener("unpipe",r),c.removeListener("end",i),c.removeListener("end",o),e._writableState&&!e._writableState.needDrain||p()}function s(t){f(),e.removeListener("error",s),0===k.listenerCount(e,"error")&&e.emit("error",t)}function a(){e.removeListener("finish",u),f()}function u(){e.removeListener("close",a),f()}function f(){c.unpipe(e)}var c=this,l=this._readableState;switch(l.pipesCount){case 0:l.pipes=e;break;case 1:l.pipes=[l.pipes,e];break;default:l.pipes.push(e)}l.pipesCount+=1;var h=(!t||t.end!==!1)&&e!==n.stdout&&e!==n.stderr,d=h?i:o;l.endEmitted?n.nextTick(d):c.once("end",d),e.on("unpipe",r);var p=g(c);return e.on("drain",p),e._events&&e._events.error?S(e._events.error)?e._events.error.unshift(s):e._events.error=[s,e._events.error]:e.on("error",s),e.once("close",a),e.once("finish",u),e.emit("pipe",c),l.flowing||(this.on("readable",b),l.flowing=!0,n.nextTick(function(){v(c)})),e},i.prototype.unpipe=function(e){var t=this._readableState;if(0===t.pipesCount)return this;if(1===t.pipesCount)return e&&e!==t.pipes?this:(e||(e=t.pipes),t.pipes=null,t.pipesCount=0,this.removeListener("readable",b),t.flowing=!1,e&&e.emit("unpipe",this),this);if(!e){var n=t.pipes,r=t.pipesCount;t.pipes=null,t.pipesCount=0,this.removeListener("readable",b),t.flowing=!1;for(var i=0;i=1?o(this,this.mapper(this._last+i.shift())):s=this._last+s,r=0;r0)if(t.ended&&!i){var s=new Error("stream.push() after EOF");e.emit("error",s)}else if(t.endEmitted&&i){var u=new Error("stream.unshift() after end event");e.emit("error",u)}else{var f;!t.decoder||i||r||(n=t.decoder.write(n),f=!t.objectMode&&0===n.length),i||(t.reading=!1),f||(t.flowing&&0===t.length&&!t.sync?(e.emit("data",n),e.read(0)):(t.length+=t.objectMode?1:n.length,i?t.buffer.unshift(n):t.buffer.push(n),t.needReadable&&h(e))),p(e,t)}else i||(t.reading=!1);return a(t)}function a(e){return!e.ended&&(e.needReadable||e.length=q?e=q:(e--,e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e++),e}function f(e,t){return 0===t.length&&t.ended?0:t.objectMode?0===e?0:1:null===e||isNaN(e)?t.flowing&&t.buffer.length?t.buffer[0].length:t.length:e<=0?0:(e>t.highWaterMark&&(t.highWaterMark=u(e)),e>t.length?t.ended?t.length:(t.needReadable=!0,0):e)}function c(e,t){var n=null;return B.isBuffer(t)||"string"==typeof t||null===t||void 0===t||e.objectMode||(n=new TypeError("Invalid non-string/buffer chunk")),n}function l(e,t){if(!t.ended){if(t.decoder){var n=t.decoder.end();n&&n.length&&(t.buffer.push(n),t.length+=t.objectMode?1:n.length)}t.ended=!0,h(e)}}function h(e){var t=e._readableState;t.needReadable=!1,t.emittedReadable||(I("emitReadable",t.flowing), +t.emittedReadable=!0,t.sync?M(d,e):d(e))}function d(e){I("emit readable"),e.emit("readable"),m(e)}function p(e,t){t.readingMore||(t.readingMore=!0,M(g,e,t))}function g(e,t){for(var n=t.length;!t.reading&&!t.flowing&&!t.ended&&t.length=i)n=o?r.join(""):1===r.length?r[0]:B.concat(r,i),r.length=0;else if(e0)throw new Error('"endReadable()" called on non-empty stream');t.endEmitted||(t.ended=!0,M(S,t,e))}function S(e,t){e.endEmitted||0!==e.length||(e.endEmitted=!0,t.readable=!1,t.emit("end"))}function R(e,t){for(var n=0,r=e.length;n0)&&(t.emittedReadable=!1),0===e&&t.needReadable&&(t.length>=t.highWaterMark||t.ended))return I("read: emitReadable",t.length,t.ended),0===t.length&&t.ended?E(this):h(this),null;if(e=f(e,t),0===e&&t.ended)return 0===t.length&&E(this),null;var r=t.needReadable;I("need readable",r),(0===t.length||t.length-e0?_(e,t):null,null===i&&(t.needReadable=!0,e=0),t.length-=e,0!==t.length||t.ended||(t.needReadable=!0),n!==e&&t.ended&&0===t.length&&E(this),null!==i&&this.emit("data",i),i},o.prototype._read=function(e){this.emit("error",new Error("not implemented"))},o.prototype.pipe=function(e,t){function i(e){I("onunpipe"),e===h&&s()}function o(){I("onend"),e.end()}function s(){I("cleanup"),e.removeListener("close",f),e.removeListener("finish",c),e.removeListener("drain",b),e.removeListener("error",u),e.removeListener("unpipe",i),h.removeListener("end",o),h.removeListener("end",s),h.removeListener("data",a),w=!0,!d.awaitDrain||e._writableState&&!e._writableState.needDrain||b()}function a(t){I("ondata");var n=e.write(t);!1===n&&((1===d.pipesCount&&d.pipes===e||d.pipesCount>1&&k(d.pipes,e)!==-1)&&!w&&(I("false write response, pause",h._readableState.awaitDrain),h._readableState.awaitDrain++),h.pause())}function u(t){I("onerror",t),l(),e.removeListener("error",u),0===A(e,"error")&&e.emit("error",t)}function f(){e.removeListener("finish",c),l()}function c(){I("onfinish"),e.removeListener("close",f),l()}function l(){I("unpipe"),h.unpipe(e)}var h=this,d=this._readableState;switch(d.pipesCount){case 0:d.pipes=e;break;case 1:d.pipes=[d.pipes,e];break;default:d.pipes.push(e)}d.pipesCount+=1,I("pipe count=%d opts=%j",d.pipesCount,t);var p=(!t||t.end!==!1)&&e!==n.stdout&&e!==n.stderr,g=p?o:s;d.endEmitted?M(g):h.once("end",g),e.on("unpipe",i);var b=v(h);e.on("drain",b);var w=!1;return h.on("data",a),r(e,"error",u),e.once("close",f),e.once("finish",c),e.emit("pipe",h),d.flowing||(I("pipe resume"),h.resume()),e},o.prototype.unpipe=function(e){var t=this._readableState;if(0===t.pipesCount)return this;if(1===t.pipesCount)return e&&e!==t.pipes?this:(e||(e=t.pipes),t.pipes=null,t.pipesCount=0,t.flowing=!1,e&&e.emit("unpipe",this),this);if(!e){var n=t.pipes,r=t.pipesCount;t.pipes=null,t.pipesCount=0,t.flowing=!1;for(var i=0;i-1?setImmediate:S;s.WritableState=o;var k=e(10);k.inherits=e(14);var M,j={deprecate:e(58)};!function(){try{M=e("stream")}catch(e){}finally{M||(M=e(11).EventEmitter)}}();var L=e(8).Buffer,x=e(7);k.inherits(s,M);var A;o.prototype.getBuffer=function(){for(var e=this.bufferedRequest,t=[];e;)t.push(e),e=e.next;return t},function(){try{Object.defineProperty(o.prototype,"buffer",{get:j.deprecate(function(){return this.getBuffer()},"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.")})}catch(e){}}();var A;s.prototype.pipe=function(){this.emit("error",new Error("Cannot pipe, not readable"))},s.prototype.write=function(e,t,n){var i=this._writableState,o=!1;return"function"==typeof t&&(n=t,t=null),L.isBuffer(e)?t="buffer":t||(t=i.defaultEncoding),"function"!=typeof n&&(n=r),i.ended?a(this,n):u(this,i,e,n)&&(i.pendingcb++,o=c(this,i,e,t,n)),o},s.prototype.cork=function(){var e=this._writableState;e.corked++},s.prototype.uncork=function(){var e=this._writableState;e.corked&&(e.corked--,e.writing||e.corked||e.finished||e.bufferProcessing||!e.bufferedRequest||b(this,e))},s.prototype.setDefaultEncoding=function(e){if("string"==typeof e&&(e=e.toLowerCase()),!(["hex","utf8","utf-8","ascii","binary","base64","ucs2","ucs-2","utf16le","utf-16le","raw"].indexOf((e+"").toLowerCase())>-1))throw new TypeError("Unknown encoding: "+e);return this._writableState.defaultEncoding=e,this},s.prototype._write=function(e,t,n){n(new Error("not implemented"))},s.prototype._writev=null,s.prototype.end=function(e,t,n){var r=this._writableState;"function"==typeof e?(n=e,e=null,t=null):"function"==typeof t&&(n=t,t=null),null!==e&&void 0!==e&&this.write(e,t),r.corked&&(r.corked=1,this.uncork()),r.ending||r.finished||_(this,r,n)}}).call(this,e(28))},{10:10,11:11,14:14,27:27,28:28,41:41,58:58,7:7,8:8}],46:[function(e,t,n){t.exports=e(42)},{42:42}],47:[function(e,t,n){(function(r){var i=function(){try{return e("stream")}catch(e){}}();n=t.exports=e(43),n.Stream=i||n,n.Readable=n,n.Writable=e(45),n.Duplex=e(41),n.Transform=e(44),n.PassThrough=e(42),!r.browser&&"disable"===r.env.READABLE_STREAM&&i&&(t.exports=i)}).call(this,e(28))},{28:28,41:41,42:42,43:43,44:44,45:45}],48:[function(e,t,n){arguments[4][35][0].apply(n,arguments)},{35:35,44:44}],49:[function(e,t,n){t.exports=e(45)},{45:45}],50:[function(e,t,n){function r(e){if(e&&!u(e))throw new Error("Unknown encoding: "+e)}function i(e){return e.toString(this.encoding)}function o(e){this.charReceived=e.length%2,this.charLength=this.charReceived?2:0}function s(e){this.charReceived=e.length%3,this.charLength=this.charReceived?3:0}var a=e(8).Buffer,u=a.isEncoding||function(e){switch(e&&e.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return!0;default:return!1}},f=n.StringDecoder=function(e){switch(this.encoding=(e||"utf8").toLowerCase().replace(/[-_]/,""),r(e),this.encoding){case"utf8":this.surrogateSize=3;break;case"ucs2":case"utf16le":this.surrogateSize=2,this.detectIncompleteChar=o;break;case"base64":this.surrogateSize=3,this.detectIncompleteChar=s;break;default:return void(this.write=i)}this.charBuffer=new a(6),this.charReceived=0,this.charLength=0};f.prototype.write=function(e){for(var t="";this.charLength;){var n=e.length>=this.charLength-this.charReceived?this.charLength-this.charReceived:e.length;if(e.copy(this.charBuffer,this.charReceived,0,n),this.charReceived+=n,this.charReceived=55296&&r<=56319)){if(this.charReceived=this.charLength=0,0===e.length)return t;break}this.charLength+=this.surrogateSize,t=""}this.detectIncompleteChar(e);var i=e.length;this.charLength&&(e.copy(this.charBuffer,0,e.length-this.charReceived,i),i-=this.charReceived),t+=e.toString(this.encoding,0,i);var i=t.length-1,r=t.charCodeAt(i);if(r>=55296&&r<=56319){var o=this.surrogateSize;return this.charLength+=o,this.charReceived+=o,this.charBuffer.copy(this.charBuffer,o,0,o),e.copy(this.charBuffer,0,0,o),t.substring(0,i)}return t},f.prototype.detectIncompleteChar=function(e){for(var t=e.length>=3?3:e.length;t>0;t--){var n=e[e.length-t];if(1==t&&n>>5==6){this.charLength=2;break}if(t<=2&&n>>4==14){this.charLength=3;break}if(t<=3&&n>>3==30){this.charLength=4;break}}this.charReceived=t},f.prototype.end=function(e){var t="";if(e&&e.length&&(t=this.write(e)),this.charReceived){var n=this.charReceived,r=this.charBuffer,i=this.encoding;t+=r.slice(0,n).toString(i)}return t}},{8:8}],51:[function(e,t,n){arguments[4][9][0].apply(n,arguments)},{9:9}],52:[function(e,t,n){arguments[4][41][0].apply(n,arguments)},{10:10,14:14,27:27,41:41,53:53,55:55}],53:[function(e,t,n){(function(n){"use strict";function r(t,n){O=O||e(52),t=t||{},this.objectMode=!!t.objectMode,n instanceof O&&(this.objectMode=this.objectMode||!!t.readableObjectMode);var r=t.highWaterMark,i=this.objectMode?16:16384;this.highWaterMark=r||0===r?r:i,this.highWaterMark=~~this.highWaterMark,this.buffer=[],this.length=0,this.pipes=null,this.pipesCount=0,this.flowing=null,this.ended=!1,this.endEmitted=!1,this.reading=!1,this.sync=!0,this.needReadable=!1,this.emittedReadable=!1,this.readableListening=!1,this.resumeScheduled=!1,this.defaultEncoding=t.defaultEncoding||"utf8",this.ranOut=!1,this.awaitDrain=0,this.readingMore=!1,this.decoder=null,this.encoding=null,t.encoding&&(D||(D=e(50).StringDecoder),this.decoder=new D(t.encoding),this.encoding=t.encoding)}function i(t){return O=O||e(52),this instanceof i?(this._readableState=new r(t,this),this.readable=!0,t&&"function"==typeof t.read&&(this._read=t.read),void L.call(this)):new i(t)}function o(e,t,n,r,i){var o=f(t,n);if(o)e.emit("error",o);else if(null===n)t.reading=!1,c(e,t);else if(t.objectMode||n&&n.length>0)if(t.ended&&!i){var a=new Error("stream.push() after EOF");e.emit("error",a)}else if(t.endEmitted&&i){var a=new Error("stream.unshift() after end event");e.emit("error",a)}else{var u;!t.decoder||i||r||(n=t.decoder.write(n),u=!t.objectMode&&0===n.length),i||(t.reading=!1),u||(t.flowing&&0===t.length&&!t.sync?(e.emit("data",n),e.read(0)):(t.length+=t.objectMode?1:n.length,i?t.buffer.unshift(n):t.buffer.push(n),t.needReadable&&l(e))),d(e,t)}else i||(t.reading=!1);return s(t)}function s(e){return!e.ended&&(e.needReadable||e.length=I?e=I:(e--,e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e++),e}function u(e,t){return 0===t.length&&t.ended?0:t.objectMode?0===e?0:1:null===e||isNaN(e)?t.flowing&&t.buffer.length?t.buffer[0].length:t.length:e<=0?0:(e>t.highWaterMark&&(t.highWaterMark=a(e)),e>t.length?t.ended?t.length:(t.needReadable=!0,0):e)}function f(e,t){var n=null;return j.isBuffer(t)||"string"==typeof t||null===t||void 0===t||e.objectMode||(n=new TypeError("Invalid non-string/buffer chunk")),n}function c(e,t){if(!t.ended){if(t.decoder){var n=t.decoder.end();n&&n.length&&(t.buffer.push(n),t.length+=t.objectMode?1:n.length)}t.ended=!0,l(e)}}function l(e){var t=e._readableState;t.needReadable=!1,t.emittedReadable||(T("emitReadable",t.flowing),t.emittedReadable=!0,t.sync?k(h,e):h(e))}function h(e){T("emit readable"),e.emit("readable"),y(e)}function d(e,t){t.readingMore||(t.readingMore=!0,k(p,e,t))}function p(e,t){for(var n=t.length;!t.reading&&!t.flowing&&!t.ended&&t.length=i)n=o?r.join(""):1===r.length?r[0]:j.concat(r,i),r.length=0;else if(e0)throw new Error("endReadable called on non-empty stream");t.endEmitted||(t.ended=!0,k(E,t,e))}function E(e,t){e.endEmitted||0!==e.length||(e.endEmitted=!0,t.readable=!1,t.emit("end"))}function S(e,t){for(var n=0,r=e.length;n0)&&(t.emittedReadable=!1),0===e&&t.needReadable&&(t.length>=t.highWaterMark||t.ended))return T("read: emitReadable",t.length,t.ended),0===t.length&&t.ended?_(this):l(this),null;if(e=u(e,t),0===e&&t.ended)return 0===t.length&&_(this),null;var r=t.needReadable;T("need readable",r),(0===t.length||t.length-e0?m(e,t):null,null===i&&(t.needReadable=!0,e=0),t.length-=e,0!==t.length||t.ended||(t.needReadable=!0),n!==e&&t.ended&&0===t.length&&_(this),null!==i&&this.emit("data",i),i},i.prototype._read=function(e){this.emit("error",new Error("not implemented"))},i.prototype.pipe=function(e,t){function r(e){T("onunpipe"),e===l&&o()}function i(){T("onend"),e.end()}function o(){T("cleanup"),e.removeListener("close",u),e.removeListener("finish",f),e.removeListener("drain",v),e.removeListener("error",a),e.removeListener("unpipe",r),l.removeListener("end",i),l.removeListener("end",o),l.removeListener("data",s),b=!0,!h.awaitDrain||e._writableState&&!e._writableState.needDrain||v()}function s(t){T("ondata");var n=e.write(t);!1===n&&(1!==h.pipesCount||h.pipes[0]!==e||1!==l.listenerCount("data")||b||(T("false write response, pause",l._readableState.awaitDrain),l._readableState.awaitDrain++),l.pause())}function a(t){T("onerror",t),c(),e.removeListener("error",a),0===x(e,"error")&&e.emit("error",t)}function u(){e.removeListener("finish",f),c()}function f(){T("onfinish"),e.removeListener("close",u),c()}function c(){T("unpipe"),l.unpipe(e)}var l=this,h=this._readableState;switch(h.pipesCount){case 0:h.pipes=e;break;case 1:h.pipes=[h.pipes,e];break;default:h.pipes.push(e)}h.pipesCount+=1,T("pipe count=%d opts=%j",h.pipesCount,t);var d=(!t||t.end!==!1)&&e!==n.stdout&&e!==n.stderr,p=d?i:o;h.endEmitted?k(p):l.once("end",p),e.on("unpipe",r);var v=g(l);e.on("drain",v);var b=!1;return l.on("data",s),e._events&&e._events.error?M(e._events.error)?e._events.error.unshift(a):e._events.error=[a,e._events.error]:e.on("error",a),e.once("close",u),e.once("finish",f),e.emit("pipe",l),h.flowing||(T("pipe resume"),l.resume()),e},i.prototype.unpipe=function(e){var t=this._readableState;if(0===t.pipesCount)return this;if(1===t.pipesCount)return e&&e!==t.pipes?this:(e||(e=t.pipes),t.pipes=null,t.pipesCount=0,t.flowing=!1,e&&e.emit("unpipe",this),this);if(!e){var n=t.pipes,r=t.pipesCount;t.pipes=null,t.pipesCount=0,t.flowing=!1;for(var i=0;i-1?setImmediate:S,k=e(8).Buffer;s.WritableState=o;var M=e(10);M.inherits=e(14);var j,L={deprecate:e(58)};!function(){try{j=e("stream")}catch(e){}finally{j||(j=e(11).EventEmitter)}}();var k=e(8).Buffer;M.inherits(s,j);var x;o.prototype.getBuffer=function(){for(var e=this.bufferedRequest,t=[];e;)t.push(e),e=e.next;return t},function(){try{Object.defineProperty(o.prototype,"buffer",{get:L.deprecate(function(){return this.getBuffer()},"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.")})}catch(e){}}();var x;s.prototype.pipe=function(){this.emit("error",new Error("Cannot pipe. Not readable."))},s.prototype.write=function(e,t,n){var i=this._writableState,o=!1;return"function"==typeof t&&(n=t,t=null),k.isBuffer(e)?t="buffer":t||(t=i.defaultEncoding),"function"!=typeof n&&(n=r),i.ended?a(this,n):u(this,i,e,n)&&(i.pendingcb++,o=c(this,i,e,t,n)),o},s.prototype.cork=function(){var e=this._writableState;e.corked++},s.prototype.uncork=function(){var e=this._writableState;e.corked&&(e.corked--,e.writing||e.corked||e.finished||e.bufferProcessing||!e.bufferedRequest||b(this,e))},s.prototype.setDefaultEncoding=function(e){if("string"==typeof e&&(e=e.toLowerCase()),!(["hex","utf8","utf-8","ascii","binary","base64","ucs2","ucs-2","utf16le","utf-16le","raw"].indexOf((e+"").toLowerCase())>-1))throw new TypeError("Unknown encoding: "+e);this._writableState.defaultEncoding=e},s.prototype._write=function(e,t,n){n(new Error("not implemented"))},s.prototype._writev=null,s.prototype.end=function(e,t,n){var r=this._writableState;"function"==typeof e?(n=e,e=null,t=null):"function"==typeof t&&(n=t,t=null),null!==e&&void 0!==e&&this.write(e,t),r.corked&&(r.corked=1,this.uncork()),r.ending||r.finished||_(this,r,n)}}).call(this,e(28))},{10:10,11:11,14:14,27:27,28:28,52:52,58:58,8:8}],56:[function(e,t,n){arguments[4][35][0].apply(n,arguments)},{35:35,54:54}],57:[function(e,t,n){arguments[4][18][0].apply(n,arguments)},{18:18,28:28,56:56,60:60,61:61}],58:[function(e,t,n){(function(e){function n(e,t){function n(){if(!i){if(r("throwDeprecation"))throw new Error(t);r("traceDeprecation")?console.trace(t):console.warn(t),i=!0}return e.apply(this,arguments)}if(r("noDeprecation"))return e;var i=!1;return n}function r(t){try{if(!e.localStorage)return!1}catch(e){return!1}var n=e.localStorage[t];return null!=n&&"true"===String(n).toLowerCase()}t.exports=n}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],59:[function(e,t,n){t.exports=function(e){return e&&"object"==typeof e&&"function"==typeof e.copy&&"function"==typeof e.fill&&"function"==typeof e.readUInt8}},{}],60:[function(e,t,n){(function(t,r){function i(e,t){var r={seen:[],stylize:s};return arguments.length>=3&&(r.depth=arguments[2]),arguments.length>=4&&(r.colors=arguments[3]),g(t)?r.showHidden=t:t&&n._extend(r,t),_(r.showHidden)&&(r.showHidden=!1),_(r.depth)&&(r.depth=2),_(r.colors)&&(r.colors=!1),_(r.customInspect)&&(r.customInspect=!0),r.colors&&(r.stylize=o),u(r,e,r.depth)}function o(e,t){var n=i.styles[t];return n?"["+i.colors[n][0]+"m"+e+"["+i.colors[n][1]+"m":e}function s(e,t){return e}function a(e){var t={};return e.forEach(function(e,n){t[e]=!0}),t}function u(e,t,r){if(e.customInspect&&t&&M(t.inspect)&&t.inspect!==n.inspect&&(!t.constructor||t.constructor.prototype!==t)){var i=t.inspect(r,e);return y(i)||(i=u(e,i,r)),i}var o=f(e,t);if(o)return o;var s=Object.keys(t),g=a(s);if(e.showHidden&&(s=Object.getOwnPropertyNames(t)),k(t)&&(s.indexOf("message")>=0||s.indexOf("description")>=0))return c(t);if(0===s.length){if(M(t)){var v=t.name?": "+t.name:"";return e.stylize("[Function"+v+"]","special")}if(E(t))return e.stylize(RegExp.prototype.toString.call(t),"regexp");if(R(t))return e.stylize(Date.prototype.toString.call(t),"date");if(k(t))return c(t)}var b="",w=!1,m=["{","}"];if(p(t)&&(w=!0,m=["[","]"]),M(t)){var _=t.name?": "+t.name:"";b=" [Function"+_+"]"}if(E(t)&&(b=" "+RegExp.prototype.toString.call(t)),R(t)&&(b=" "+Date.prototype.toUTCString.call(t)),k(t)&&(b=" "+c(t)),0===s.length&&(!w||0==t.length))return m[0]+b+m[1];if(r<0)return E(t)?e.stylize(RegExp.prototype.toString.call(t),"regexp"):e.stylize("[Object]","special");e.seen.push(t);var S;return S=w?l(e,t,r,g,s):s.map(function(n){return h(e,t,r,g,n,w)}),e.seen.pop(),d(S,b,m)}function f(e,t){if(_(t))return e.stylize("undefined","undefined");if(y(t)){var n="'"+JSON.stringify(t).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return e.stylize(n,"string")}return w(t)?e.stylize(""+t,"number"):g(t)?e.stylize(""+t,"boolean"):v(t)?e.stylize("null","null"):void 0}function c(e){return"["+Error.prototype.toString.call(e)+"]"}function l(e,t,n,r,i){for(var o=[],s=0,a=t.length;s-1&&(a=o?a.split("\n").map(function(e){return" "+e}).join("\n").substr(2):"\n"+a.split("\n").map(function(e){return" "+e}).join("\n"))):a=e.stylize("[Circular]","special")),_(s)){if(o&&i.match(/^\d+$/))return a;s=JSON.stringify(""+i),s.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(s=s.substr(1,s.length-2),s=e.stylize(s,"name")):(s=s.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),s=e.stylize(s,"string"))}return s+": "+a}function d(e,t,n){var r=0,i=e.reduce(function(e,t){return r++,t.indexOf("\n")>=0&&r++,e+t.replace(/\u001b\[\d\d?m/g,"").length+1},0);return i>60?n[0]+(""===t?"":t+"\n ")+" "+e.join(",\n ")+" "+n[1]:n[0]+t+" "+e.join(", ")+" "+n[1]}function p(e){return Array.isArray(e)}function g(e){return"boolean"==typeof e}function v(e){return null===e}function b(e){return null==e}function w(e){return"number"==typeof e}function y(e){return"string"==typeof e}function m(e){return"symbol"==typeof e}function _(e){return void 0===e}function E(e){return S(e)&&"[object RegExp]"===L(e)}function S(e){return"object"==typeof e&&null!==e}function R(e){return S(e)&&"[object Date]"===L(e)}function k(e){return S(e)&&("[object Error]"===L(e)||e instanceof Error)}function M(e){return"function"==typeof e}function j(e){return null===e||"boolean"==typeof e||"number"==typeof e||"string"==typeof e||"symbol"==typeof e||"undefined"==typeof e}function L(e){return Object.prototype.toString.call(e)}function x(e){return e<10?"0"+e.toString(10):e.toString(10)}function A(){var e=new Date,t=[x(e.getHours()),x(e.getMinutes()),x(e.getSeconds())].join(":");return[e.getDate(),I[e.getMonth()],t].join(" ")}function B(e,t){return Object.prototype.hasOwnProperty.call(e,t)}var T=/%[sdj%]/g;n.format=function(e){if(!y(e)){for(var t=[],n=0;n=o)return e;switch(e){case"%s":return String(r[n++]);case"%d":return Number(r[n++]);case"%j":try{return JSON.stringify(r[n++])}catch(e){return"[Circular]"}default:return e}}),a=r[n];n dist/pouchdb.replication-stream.js",min:"uglifyjs dist/pouchdb.replication-stream.js -mc > dist/pouchdb.replication-stream.min.js",dev:"browserify test/test.js > test/test-bundle.js && npm run dev-server","dev-server":"./bin/dev-server.js",coverage:"npm test --coverage && istanbul check-coverage --lines 100 --function 100 --statements 100 --branches 100"},dependencies:{argsarray:"0.0.1",inherits:"~2.0.1","ldjson-stream":"^1.2.1","lodash.pick":"^4.0.0","pouchdb-promise":"^5.4.4","pouch-stream":"^0.4.0",through2:"^2.0.0"},devDependencies:{bluebird:"^1.0.7",browserify:"^11.2.0","bundle-collapser":"^1.2.1",chai:"^3.3.0","chai-as-promised":"^5.1.0",derequire:"^2.0.0",es3ify:"^0.1.3","http-server":"~0.8.5",istanbul:"^0.2.7",jshint:"^2.3.0",lie:"^3.1.0",memorystream:"^0.3.0",mkdirp:"^0.5.0",mocha:"~1.18",noms:"0.0.0",phantomjs:"^1.9.7-5","pouchdb-memory":"^1.0.0","random-document-stream":"0.0.0",request:"^2.36.0","sauce-connect-launcher":"^0.4.2","selenium-standalone":"3.0.2","uglify-js":"^2.4.13",watchify:"^3.1.0",wd:"^0.2.21"}}},{}],63:[function(e,t,n){"use strict";var r=e(1),i=e(3),o=e(17),s=e(57).obj,a=e(19),u=e(2),f=50,c=["batch_size","batches_limit","filter","doc_ids","query_params","since","view"];n.adapters={},n.adapters.writableStream=e(4),n.plugin=e(22),n.plugin.dump=r.toPromise(function(e,t,n){function r(e){n(e)}var o=this;"function"==typeof t&&(n=t,t={});var s=o.constructor,u=new s(o._db_name,{adapter:"writableStream"});u.setupStream(e);var l=o.info().then(function(n){var r={version:i,db_type:o.type(),start_time:(new Date).toJSON(),db_info:n};return e.write(JSON.stringify(r)+"\n"),t=a(t,c),t.batch_size||(t.batch_size=f),o.replicate.to(u,t)}).then(function(){return u.close()}).then(function(){n(null,{ok:!0})});l.catch(r)}),n.plugin.load=r.toPromise(function(e,t,n){"function"==typeof t&&(n=t,t={});var r;r="batch_size"in t?t.batch_size:f;var i=[];e.pipe(u()).pipe(o.parse()).pipe(s(function(e,t,n){return e.docs?(e.docs.forEach(function(e){this.push(e)},this),void n()):n()})).pipe(s(function(e,t,n){i.push(e),i.length>=r&&(this.push(i),i=[]),n()},function(e){i.length&&this.push(i),e()})).pipe(this.createWriteStream({new_edits:!1})).on("error",n).on("finish",function(){n(null,{ok:!0})})}),"undefined"!=typeof window&&window.PouchDB&&(window.PouchDB.plugin(n.plugin),window.PouchDB.adapter("writableStream",n.adapters.writableStream))},{1:1,17:17,19:19,2:2,22:22,3:3,4:4,57:57}]},{},[63])(63)}); diff --git a/package.json b/package.json index a63eba7..34f1b75 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "jshint": "jshint -c .jshintrc lib test/test.js", "test": "npm run jshint && ./bin/run-test.sh", "build": "mkdirp dist && npm run browserify && npm run min", - "browserify": "browserify . | ./bin/es3ify.js | derequire > dist/pouchdb.replication-stream.js", + "browserify": "browserify -p bundle-collapser/plugin -s PouchReplicationStream . | ./bin/es3ify.js | derequire > dist/pouchdb.replication-stream.js", "min": "uglifyjs dist/pouchdb.replication-stream.js -mc > dist/pouchdb.replication-stream.min.js", "dev": "browserify test/test.js > test/test-bundle.js && npm run dev-server", "dev-server": "./bin/dev-server.js", @@ -45,6 +45,7 @@ "devDependencies": { "bluebird": "^1.0.7", "browserify": "^11.2.0", + "bundle-collapser": "^1.2.1", "chai": "^3.3.0", "chai-as-promised": "^5.1.0", "derequire": "^2.0.0",