From b7f195f435099d6f26fdea861f72329aae006f20 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Fri, 2 Sep 2016 16:57:10 -0700 Subject: [PATCH] build --- dist/pouchdb.replication-stream.js | 1394 +++++++++++++----------- dist/pouchdb.replication-stream.min.js | 8 +- 2 files changed, 768 insertions(+), 634 deletions(-) diff --git a/dist/pouchdb.replication-stream.js b/dist/pouchdb.replication-stream.js index 11eb437..f251805 100644 --- a/dist/pouchdb.replication-stream.js +++ b/dist/pouchdb.replication-stream.js @@ -2,7 +2,7 @@ (function (process){ 'use strict'; -var Promise = _dereq_(25); +var Promise = _dereq_(26); /* istanbul ignore next */ exports.once = function (fun) { @@ -79,11 +79,11 @@ exports.toPromise = function (func) { exports.inherits = _dereq_(14); }).call(this,_dereq_(28)) -},{"14":14,"25":25,"28":28}],2:[function(_dereq_,module,exports){ +},{"14":14,"26":26,"28":28}],2:[function(_dereq_,module,exports){ (function (Buffer){ 'use strict'; -var through = _dereq_(57).obj; +var through = _dereq_(58).obj; module.exports = function () { return through(function (chunk, _, next) { @@ -98,23 +98,23 @@ module.exports = function () { }; }).call(this,_dereq_(8).Buffer) -},{"57":57,"8":8}],3:[function(_dereq_,module,exports){ +},{"58":58,"8":8}],3:[function(_dereq_,module,exports){ 'use strict'; -module.exports = _dereq_(62).version; +module.exports = _dereq_(63).version; -},{"62":62}],4:[function(_dereq_,module,exports){ +},{"63":63}],4:[function(_dereq_,module,exports){ (function (process){ 'use strict'; var utils = _dereq_(1); -var Promise = _dereq_(25); +var Promise = _dereq_(26); var ERROR_REV_CONFLICT = { status: 409, name: 'conflict', message: 'Document update conflict' }; -var ldj = _dereq_(17); +var ndj = _dereq_(19); var ERROR_MISSING_DOC = { status: 404, name: 'not_found', @@ -123,14 +123,14 @@ var ERROR_MISSING_DOC = { function WritableStreamPouch(opts, callback) { var api = this; api.instanceId = Math.random().toString(); - api.ldj = ldj.serialize(); + api.ndj = ndj.serialize(); api.localStore = {}; api.originalName = opts.name; // TODO: I would pass this in as a constructor opt, but // PouchDB changed how it clones in 5.0.0 so this broke api.setupStream = function (stream) { - api.ldj.pipe(stream); + api.ndj.pipe(stream); }; /* istanbul ignore next */ @@ -149,7 +149,7 @@ function WritableStreamPouch(opts, callback) { if (opts.new_edits === false) { // assume we're only getting this with new_edits=false, // since this adapter is just a replication target - this.ldj.write({docs: docs}, function () { + this.ndj.write({docs: docs}, function () { callback(null, docs.map(function (doc) { return { ok: true, @@ -177,7 +177,7 @@ function WritableStreamPouch(opts, callback) { }; api._close = function (callback) { - this.ldj.end(callback); + this.ndj.end(callback); }; api._getLocal = function (id, callback) { @@ -222,7 +222,7 @@ function WritableStreamPouch(opts, callback) { }; /* istanbul ignore else */ if ('last_seq' in doc) { - self.ldj.write({seq: doc.last_seq}, done); + self.ndj.write({seq: doc.last_seq}, done); } else { done(); } @@ -268,7 +268,7 @@ WritableStreamPouch.valid = function () { module.exports = WritableStreamPouch; }).call(this,_dereq_(28)) -},{"1":1,"17":17,"25":25,"28":28}],5:[function(_dereq_,module,exports){ +},{"1":1,"19":19,"26":26,"28":28}],5:[function(_dereq_,module,exports){ var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; ;(function (exports) { @@ -2666,22 +2666,26 @@ if (typeof Object.create === 'function') { } },{}],15:[function(_dereq_,module,exports){ -/** - * Determine if an object is Buffer - * - * Author: Feross Aboukhadijeh - * License: MIT +/*! + * Determine if an object is a Buffer * - * `npm install is-buffer` + * @author Feross Aboukhadijeh + * @license MIT */ +// The _isBuffer check is for Safari 5-7 support, because it's missing +// Object.prototype.constructor. Remove this eventually module.exports = function (obj) { - return !!(obj != null && - (obj._isBuffer || // For Safari 5-7 (missing Object.prototype.constructor) - (obj.constructor && - typeof obj.constructor.isBuffer === 'function' && - obj.constructor.isBuffer(obj)) - )) + return obj != null && (isBuffer(obj) || isSlowBuffer(obj) || !!obj._isBuffer) +} + +function isBuffer (obj) { + return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj) +} + +// For Node v0.10 support. Remove this eventually. +function isSlowBuffer (obj) { + return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isBuffer(obj.slice(0, 0)) } },{}],16:[function(_dereq_,module,exports){ @@ -2690,140 +2694,261 @@ module.exports = Array.isArray || function (arr) { }; },{}],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 -module.exports.parse = parse - -function parse(opts) { - opts = opts || {} - opts.strict = opts.strict !== false - - function strict(row) { - if (row) return JSON.parse(row) - } +'use strict'; +var immediate = _dereq_(13); - function nonStrict(row) { - try { - if (row) return JSON.parse(row) - } catch(e) { - // ignore - } - } +/* istanbul ignore next */ +function INTERNAL() {} - return opts.strict ? split(strict) : split(nonStrict) -} +var handlers = {}; -function serialize() { - return through.obj(function(obj, enc, cb) { - cb(null, JSON.stringify(obj) + EOL) - }) -} +var REJECTED = ['REJECTED']; +var FULFILLED = ['FULFILLED']; +var PENDING = ['PENDING']; -},{"18":18,"20":20,"36":36}],18:[function(_dereq_,module,exports){ -(function (process){ -var Transform = _dereq_(35) - , inherits = _dereq_(60).inherits - , xtend = _dereq_(61) +module.exports = Promise; -function DestroyableTransform(opts) { - Transform.call(this, opts) - this._destroyed = false +function Promise(resolver) { + if (typeof resolver !== 'function') { + throw new TypeError('resolver must be a function'); + } + this.state = PENDING; + this.queue = []; + this.outcome = void 0; + if (resolver !== INTERNAL) { + safelyResolveThenable(this, resolver); + } } -inherits(DestroyableTransform, Transform) +Promise.prototype["catch"] = function (onRejected) { + return this.then(null, onRejected); +}; +Promise.prototype.then = function (onFulfilled, onRejected) { + if (typeof onFulfilled !== 'function' && this.state === FULFILLED || + typeof onRejected !== 'function' && this.state === REJECTED) { + return this; + } + var promise = new this.constructor(INTERNAL); + if (this.state !== PENDING) { + var resolver = this.state === FULFILLED ? onFulfilled : onRejected; + unwrap(promise, resolver, this.outcome); + } else { + this.queue.push(new QueueItem(promise, onFulfilled, onRejected)); + } -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') - }) + return promise; +}; +function QueueItem(promise, onFulfilled, onRejected) { + this.promise = promise; + if (typeof onFulfilled === 'function') { + this.onFulfilled = onFulfilled; + this.callFulfilled = this.otherCallFulfilled; + } + if (typeof onRejected === 'function') { + this.onRejected = onRejected; + this.callRejected = this.otherCallRejected; + } } +QueueItem.prototype.callFulfilled = function (value) { + handlers.resolve(this.promise, value); +}; +QueueItem.prototype.otherCallFulfilled = function (value) { + unwrap(this.promise, this.onFulfilled, value); +}; +QueueItem.prototype.callRejected = function (value) { + handlers.reject(this.promise, value); +}; +QueueItem.prototype.otherCallRejected = function (value) { + unwrap(this.promise, this.onRejected, value); +}; -// a noop _transform function -function noop (chunk, enc, callback) { - callback(null, chunk) +function unwrap(promise, func, value) { + immediate(function () { + var returnValue; + try { + returnValue = func(value); + } catch (e) { + return handlers.reject(promise, e); + } + if (returnValue === promise) { + handlers.reject(promise, new TypeError('Cannot resolve promise with itself')); + } else { + handlers.resolve(promise, returnValue); + } + }); } +handlers.resolve = function (self, value) { + var result = tryCatch(getThen, value); + if (result.status === 'error') { + return handlers.reject(self, result.value); + } + var thenable = result.value; -// 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 (thenable) { + safelyResolveThenable(self, thenable); + } else { + self.state = FULFILLED; + self.outcome = value; + var i = -1; + var len = self.queue.length; + while (++i < len) { + self.queue[i].callFulfilled(value); } + } + return self; +}; +handlers.reject = function (self, error) { + self.state = REJECTED; + self.outcome = error; + var i = -1; + var len = self.queue.length; + while (++i < len) { + self.queue[i].callRejected(error); + } + return self; +}; - if (typeof transform != 'function') - transform = noop - - if (typeof flush != 'function') - flush = null - - return construct(options, transform, flush) +function getThen(obj) { + // Make sure we only access the accessor once as required by the spec + var then = obj && obj.then; + if (obj && typeof obj === 'object' && typeof then === 'function') { + return function appyThen() { + then.apply(obj, arguments); + }; } } +function safelyResolveThenable(self, thenable) { + // Either fulfill, reject or reject with error + var called = false; + function onError(value) { + if (called) { + return; + } + called = true; + handlers.reject(self, value); + } -// 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 -}) + function onSuccess(value) { + if (called) { + return; + } + called = true; + handlers.resolve(self, value); + } + function tryToUnwrap() { + thenable(onSuccess, onError); + } -// 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) + var result = tryCatch(tryToUnwrap); + if (result.status === 'error') { + onError(result.value); + } +} - this.options = xtend(options, override) +function tryCatch(func, value) { + var out = {}; + try { + out.value = func(value); + out.status = 'success'; + } catch (e) { + out.status = 'error'; + out.value = e; + } + return out; +} - DestroyableTransform.call(this, this.options) +Promise.resolve = resolve; +function resolve(value) { + if (value instanceof this) { + return value; } + return handlers.resolve(new this(INTERNAL), value); +} - inherits(Through2, DestroyableTransform) +Promise.reject = reject; +function reject(reason) { + var promise = new this(INTERNAL); + return handlers.reject(promise, reason); +} - Through2.prototype._transform = transform +Promise.all = all; +function all(iterable) { + var self = this; + if (Object.prototype.toString.call(iterable) !== '[object Array]') { + return this.reject(new TypeError('must be an array')); + } - if (flush) - Through2.prototype._flush = flush + var len = iterable.length; + var called = false; + if (!len) { + return this.resolve([]); + } - return Through2 -}) + var values = new Array(len); + var resolved = 0; + var i = -1; + var promise = new this(INTERNAL); + while (++i < len) { + allResolver(iterable[i], i); + } + return promise; + function allResolver(value, i) { + self.resolve(value).then(resolveFromAll, function (error) { + if (!called) { + called = true; + handlers.reject(promise, error); + } + }); + function resolveFromAll(outValue) { + values[i] = outValue; + if (++resolved === len && !called) { + called = true; + handlers.resolve(promise, values); + } + } + } +} -module.exports.obj = through2(function (options, transform, flush) { - var t2 = new DestroyableTransform(xtend({ objectMode: true, highWaterMark: 16 }, options)) +Promise.race = race; +function race(iterable) { + var self = this; + if (Object.prototype.toString.call(iterable) !== '[object Array]') { + return this.reject(new TypeError('must be an array')); + } - t2._transform = transform + var len = iterable.length; + var called = false; + if (!len) { + return this.resolve([]); + } - if (flush) - t2._flush = flush + var i = -1; + var promise = new this(INTERNAL); - return t2 -}) + while (++i < len) { + resolver(iterable[i]); + } + return promise; + function resolver(value) { + self.resolve(value).then(function (response) { + if (!called) { + called = true; + handlers.resolve(promise, response); + } + }, function (error) { + if (!called) { + called = true; + handlers.reject(promise, error); + } + }); + } +} -}).call(this,_dereq_(28)) -},{"28":28,"35":35,"60":60,"61":61}],19:[function(_dereq_,module,exports){ +},{"13":13}],18:[function(_dereq_,module,exports){ (function (global){ /** * lodash (Custom Build) @@ -2912,19 +3037,6 @@ function arrayPush(array, values) { return array; } -/** - * 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; @@ -2933,7 +3045,7 @@ var hasOwnProperty = objectProto.hasOwnProperty; /** * Used to resolve the - * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) + * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) * of values. */ var objectToString = objectProto.toString; @@ -3050,19 +3162,6 @@ function baseRest(func, start) { }; } -/** - * 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. - * - * @private - * @param {Object} object The object to query. - * @returns {*} Returns the "length" value. - */ -var getLength = baseProperty('length'); - /** * Checks if `value` is a flattenable `arguments` object or array. * @@ -3072,7 +3171,7 @@ var getLength = baseProperty('length'); */ function isFlattenable(value) { return isArray(value) || isArguments(value) || - !!(spreadableSymbol && value && value[spreadableSymbol]) + !!(spreadableSymbol && value && value[spreadableSymbol]); } /** @@ -3109,7 +3208,7 @@ function toKey(value) { * // => false */ function isArguments(value) { - // Safari 8.1 incorrectly makes `arguments.callee` enumerable in strict mode. + // Safari 8.1 makes `arguments.callee` enumerable in strict mode. return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') && (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag); } @@ -3165,7 +3264,7 @@ var isArray = Array.isArray; * // => false */ function isArrayLike(value) { - return value != null && isLength(getLength(value)) && !isFunction(value); + return value != null && isLength(value.length) && !isFunction(value); } /** @@ -3216,8 +3315,7 @@ function isArrayLikeObject(value) { */ function isFunction(value) { // The use of `Object#toString` avoids issues with the `typeof` operator - // in Safari 8 which returns 'object' for typed array and weak map constructors, - // and PhantomJS 1.9 which returns 'function' for `NodeList` instances. + // in Safari 8-9 which returns 'object' for typed array and other constructors. var tag = isObject(value) ? objectToString.call(value) : ''; return tag == funcTag || tag == genTag; } @@ -3225,16 +3323,15 @@ function isFunction(value) { /** * 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). + * **Note:** This method is loosely based on + * [`ToLength`](http://ecma-international.org/ecma-262/7.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 valid length, - * else `false`. + * @returns {boolean} Returns `true` if `value` is a valid length, else `false`. * @example * * _.isLength(3); @@ -3256,7 +3353,7 @@ function isLength(value) { /** * Checks if `value` is the - * [language type](http://www.ecma-international.org/ecma-262/6.0/#sec-ecmascript-language-types) + * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types) * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) * * @static @@ -3355,10 +3452,142 @@ var pick = baseRest(function(object, props) { return object == null ? {} : basePick(object, arrayMap(baseFlatten(props, 1), toKey)); }); -module.exports = pick; +module.exports = pick; + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{}],19:[function(_dereq_,module,exports){ +var through = _dereq_(20) +var split = _dereq_(36) +var EOL = _dereq_(21).EOL + +module.exports = parse +module.exports.serialize = module.exports.stringify = serialize +module.exports.parse = parse + +function parse (opts) { + opts = opts || {} + opts.strict = opts.strict !== false + + function parseRow (row) { + try { + if (row) return JSON.parse(row) + } catch (e) { + if (opts.strict) { + this.emit('error', new Error('Could not parse row ' + row.slice(0, 50) + '...')) + } + } + } + + return split(parseRow) +} + +function serialize (opts) { + return through.obj(opts, function(obj, enc, cb) { + cb(null, JSON.stringify(obj) + EOL) + }) +} + +},{"20":20,"21":21,"36":36}],20:[function(_dereq_,module,exports){ +(function (process){ +var Transform = _dereq_(35) + , inherits = _dereq_(61).inherits + , xtend = _dereq_(62) + +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 +}) -}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{}],20:[function(_dereq_,module,exports){ + +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,"61":61,"62":62}],21:[function(_dereq_,module,exports){ exports.endianness = function () { return 'LE' }; exports.hostname = function () { @@ -3405,7 +3634,7 @@ exports.tmpdir = exports.tmpDir = function () { exports.EOL = '\n'; -},{}],21:[function(_dereq_,module,exports){ +},{}],22:[function(_dereq_,module,exports){ 'use strict'; module.exports = function (source, target, events) { source.on('newListener', function (event, listener) { @@ -3420,10 +3649,10 @@ module.exports = function (source, target, events) { }); }; -},{}],22:[function(_dereq_,module,exports){ +},{}],23:[function(_dereq_,module,exports){ 'use strict'; -var Writable = _dereq_(24); -var Readable = _dereq_(23); +var Writable = _dereq_(25); +var Readable = _dereq_(24); exports.createReadStream = function (opts) { opts = opts || {}; @@ -3433,7 +3662,7 @@ exports.createWriteStream = function (opts) { opts = opts || {}; return new Writable(this, opts); }; -var ep = _dereq_(21); +var ep = _dereq_(22); var streamEvents = [ 'drain', 'pipe', @@ -3454,7 +3683,7 @@ exports.end = function () { this.emit('done'); }; -},{"21":21,"23":23,"24":24}],23:[function(_dereq_,module,exports){ +},{"22":22,"24":24,"25":25}],24:[function(_dereq_,module,exports){ 'use strict'; var inherits = _dereq_(14); var Readable = _dereq_(34).Readable; @@ -3509,7 +3738,7 @@ ReadStream.prototype.cancel = function () { } }; -},{"14":14,"34":34}],24:[function(_dereq_,module,exports){ +},{"14":14,"34":34}],25:[function(_dereq_,module,exports){ (function (Buffer){ 'use strict'; var inherits = _dereq_(14); @@ -3527,302 +3756,47 @@ function WriteStream(db, opts) { }); this.db = db; this.opts = opts || {}; -} - -WriteStream.prototype._write = function (chunk, _, next) { - if (Buffer.isBuffer(chunk)) { - chunk = chunk.toString(); - } - if (typeof chunk === 'string') { - try { - chunk = JSON.parse(chunk); - } catch (e) { - return next(e); - } - } - if (Array.isArray(chunk)) { - this.db.bulkDocs({docs: chunk}, this.opts).then(function () { - next(); - }, next); - } else if ('_id' in chunk) { - this.db.put(chunk, this.opts).then(function () { - next(); - }, next); - } else { - this.db.post(chunk, this.opts).then(function () { - next(); - }, next); - } -}; - -}).call(this,{"isBuffer":_dereq_(15)}) -},{"14":14,"15":15,"34":34}],25:[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 */ -var PouchPromise = typeof Promise === 'function' ? Promise : lie; - -module.exports = PouchPromise; -},{"26":26}],26:[function(_dereq_,module,exports){ -'use strict'; -var immediate = _dereq_(13); - -/* istanbul ignore next */ -function INTERNAL() {} - -var handlers = {}; - -var REJECTED = ['REJECTED']; -var FULFILLED = ['FULFILLED']; -var PENDING = ['PENDING']; - -module.exports = Promise; - -function Promise(resolver) { - if (typeof resolver !== 'function') { - throw new TypeError('resolver must be a function'); - } - this.state = PENDING; - this.queue = []; - this.outcome = void 0; - if (resolver !== INTERNAL) { - safelyResolveThenable(this, resolver); - } -} - -Promise.prototype["catch"] = function (onRejected) { - return this.then(null, onRejected); -}; -Promise.prototype.then = function (onFulfilled, onRejected) { - if (typeof onFulfilled !== 'function' && this.state === FULFILLED || - typeof onRejected !== 'function' && this.state === REJECTED) { - return this; - } - var promise = new this.constructor(INTERNAL); - if (this.state !== PENDING) { - var resolver = this.state === FULFILLED ? onFulfilled : onRejected; - unwrap(promise, resolver, this.outcome); - } else { - this.queue.push(new QueueItem(promise, onFulfilled, onRejected)); - } - - return promise; -}; -function QueueItem(promise, onFulfilled, onRejected) { - this.promise = promise; - if (typeof onFulfilled === 'function') { - this.onFulfilled = onFulfilled; - this.callFulfilled = this.otherCallFulfilled; - } - if (typeof onRejected === 'function') { - this.onRejected = onRejected; - this.callRejected = this.otherCallRejected; - } -} -QueueItem.prototype.callFulfilled = function (value) { - handlers.resolve(this.promise, value); -}; -QueueItem.prototype.otherCallFulfilled = function (value) { - unwrap(this.promise, this.onFulfilled, value); -}; -QueueItem.prototype.callRejected = function (value) { - handlers.reject(this.promise, value); -}; -QueueItem.prototype.otherCallRejected = function (value) { - unwrap(this.promise, this.onRejected, value); -}; - -function unwrap(promise, func, value) { - immediate(function () { - var returnValue; - try { - returnValue = func(value); - } catch (e) { - return handlers.reject(promise, e); - } - if (returnValue === promise) { - handlers.reject(promise, new TypeError('Cannot resolve promise with itself')); - } else { - handlers.resolve(promise, returnValue); - } - }); -} - -handlers.resolve = function (self, value) { - var result = tryCatch(getThen, value); - if (result.status === 'error') { - return handlers.reject(self, result.value); - } - var thenable = result.value; - - if (thenable) { - safelyResolveThenable(self, thenable); - } else { - self.state = FULFILLED; - self.outcome = value; - var i = -1; - var len = self.queue.length; - while (++i < len) { - self.queue[i].callFulfilled(value); - } - } - return self; -}; -handlers.reject = function (self, error) { - self.state = REJECTED; - self.outcome = error; - var i = -1; - var len = self.queue.length; - while (++i < len) { - self.queue[i].callRejected(error); - } - return self; -}; - -function getThen(obj) { - // Make sure we only access the accessor once as required by the spec - var then = obj && obj.then; - if (obj && typeof obj === 'object' && typeof then === 'function') { - return function appyThen() { - then.apply(obj, arguments); - }; - } -} - -function safelyResolveThenable(self, thenable) { - // Either fulfill, reject or reject with error - var called = false; - function onError(value) { - if (called) { - return; - } - called = true; - handlers.reject(self, value); - } - - function onSuccess(value) { - if (called) { - return; - } - called = true; - handlers.resolve(self, value); - } - - function tryToUnwrap() { - thenable(onSuccess, onError); - } - - var result = tryCatch(tryToUnwrap); - if (result.status === 'error') { - onError(result.value); - } -} - -function tryCatch(func, value) { - var out = {}; - try { - out.value = func(value); - out.status = 'success'; - } catch (e) { - out.status = 'error'; - out.value = e; - } - return out; -} - -Promise.resolve = resolve; -function resolve(value) { - if (value instanceof this) { - return value; - } - return handlers.resolve(new this(INTERNAL), value); -} - -Promise.reject = reject; -function reject(reason) { - var promise = new this(INTERNAL); - return handlers.reject(promise, reason); -} - -Promise.all = all; -function all(iterable) { - var self = this; - if (Object.prototype.toString.call(iterable) !== '[object Array]') { - return this.reject(new TypeError('must be an array')); - } - - var len = iterable.length; - var called = false; - if (!len) { - return this.resolve([]); - } - - var values = new Array(len); - var resolved = 0; - var i = -1; - var promise = new this(INTERNAL); +} - while (++i < len) { - allResolver(iterable[i], i); +WriteStream.prototype._write = function (chunk, _, next) { + if (Buffer.isBuffer(chunk)) { + chunk = chunk.toString(); } - return promise; - function allResolver(value, i) { - self.resolve(value).then(resolveFromAll, function (error) { - if (!called) { - called = true; - handlers.reject(promise, error); - } - }); - function resolveFromAll(outValue) { - values[i] = outValue; - if (++resolved === len && !called) { - called = true; - handlers.resolve(promise, values); - } + if (typeof chunk === 'string') { + try { + chunk = JSON.parse(chunk); + } catch (e) { + return next(e); } } -} - -Promise.race = race; -function race(iterable) { - var self = this; - if (Object.prototype.toString.call(iterable) !== '[object Array]') { - return this.reject(new TypeError('must be an array')); + if (Array.isArray(chunk)) { + this.db.bulkDocs({docs: chunk}, this.opts).then(function () { + next(); + }, next); + } else if ('_id' in chunk) { + this.db.put(chunk, this.opts).then(function () { + next(); + }, next); + } else { + this.db.post(chunk, this.opts).then(function () { + next(); + }, next); } +}; - var len = iterable.length; - var called = false; - if (!len) { - return this.resolve([]); - } +}).call(this,{"isBuffer":_dereq_(15)}) +},{"14":14,"15":15,"34":34}],26:[function(_dereq_,module,exports){ +'use strict'; - var i = -1; - var promise = new this(INTERNAL); +function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } - while (++i < len) { - resolver(iterable[i]); - } - return promise; - function resolver(value) { - self.resolve(value).then(function (response) { - if (!called) { - called = true; - handlers.resolve(promise, response); - } - }, function (error) { - if (!called) { - called = true; - handlers.reject(promise, error); - } - }); - } -} +var lie = _interopDefault(_dereq_(17)); + +/* istanbul ignore next */ +var PouchPromise = typeof Promise === 'function' ? Promise : lie; -},{"13":13}],27:[function(_dereq_,module,exports){ +module.exports = PouchPromise; +},{"17":17}],27:[function(_dereq_,module,exports){ (function (process){ 'use strict'; @@ -3871,7 +3845,6 @@ function nextTick(fn, arg1, arg2, arg3) { }).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 @@ -3883,21 +3856,63 @@ var cachedSetTimeout; var cachedClearTimeout; (function () { - try { - cachedSetTimeout = setTimeout; - } catch (e) { - cachedSetTimeout = function () { - throw new Error('setTimeout is not defined'); + 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'); + try { + cachedClearTimeout = clearTimeout; + } catch (e) { + cachedClearTimeout = function () { + throw new Error('clearTimeout is not defined'); + } } - } } ()) +function runTimeout(fun) { + if (cachedSetTimeout === setTimeout) { + //normal enviroments in sane situations + return setTimeout(fun, 0); + } + try { + // when when somebody has screwed with setTimeout but no I.E. maddness + return cachedSetTimeout(fun, 0); + } catch(e){ + try { + // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally + return cachedSetTimeout.call(null, fun, 0); + } catch(e){ + // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error + return cachedSetTimeout.call(this, fun, 0); + } + } + + +} +function runClearTimeout(marker) { + if (cachedClearTimeout === clearTimeout) { + //normal enviroments in sane situations + return clearTimeout(marker); + } + try { + // when when somebody has screwed with setTimeout but no I.E. maddness + return cachedClearTimeout(marker); + } catch (e){ + try { + // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally + return cachedClearTimeout.call(null, marker); + } catch (e){ + // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error. + // Some versions of I.E. have different rules for clearTimeout vs setTimeout + return cachedClearTimeout.call(this, marker); + } + } + + + +} var queue = []; var draining = false; var currentQueue; @@ -3922,7 +3937,7 @@ function drainQueue() { if (draining) { return; } - var timeout = cachedSetTimeout.call(null, cleanUpNextTick); + var timeout = runTimeout(cleanUpNextTick); draining = true; var len = queue.length; @@ -3939,7 +3954,7 @@ function drainQueue() { } currentQueue = null; draining = false; - cachedClearTimeout.call(null, timeout); + runClearTimeout(timeout); } process.nextTick = function (fun) { @@ -3951,7 +3966,7 @@ process.nextTick = function (fun) { } queue.push(new Item(fun, args)); if (queue.length === 1 && !draining) { - cachedSetTimeout.call(null, drainQueue, 0); + runTimeout(drainQueue); } }; @@ -4248,7 +4263,7 @@ function ReadableState(options, stream) { this.encoding = null; if (options.encoding) { if (!StringDecoder) - StringDecoder = _dereq_(50).StringDecoder; + StringDecoder = _dereq_(51).StringDecoder; this.decoder = new StringDecoder(options.encoding); this.encoding = options.encoding; } @@ -4349,7 +4364,7 @@ function needMoreData(state) { // backwards compatibility. Readable.prototype.setEncoding = function(enc) { if (!StringDecoder) - StringDecoder = _dereq_(50).StringDecoder; + StringDecoder = _dereq_(51).StringDecoder; this._readableState.decoder = new StringDecoder(enc); this._readableState.encoding = enc; }; @@ -5117,7 +5132,7 @@ function indexOf (xs, x) { } }).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){ +},{"10":10,"11":11,"14":14,"16":16,"28":28,"38":38,"51":51,"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 @@ -5823,8 +5838,8 @@ function split(matcher, mapper, options) { module.exports = split },{"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){ +arguments[4][20][0].apply(exports,arguments) +},{"20":20,"28":28,"35":35,"61":61,"62":62}],38:[function(_dereq_,module,exports){ // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -5852,11 +5867,11 @@ var EE = _dereq_(11).EventEmitter; var inherits = _dereq_(14); inherits(Stream, EE); -Stream.Readable = _dereq_(47); -Stream.Writable = _dereq_(49); +Stream.Readable = _dereq_(48); +Stream.Writable = _dereq_(50); Stream.Duplex = _dereq_(40); -Stream.Transform = _dereq_(48); -Stream.PassThrough = _dereq_(46); +Stream.Transform = _dereq_(49); +Stream.PassThrough = _dereq_(47); // Backwards-compat with node 0.4.x Stream.Stream = Stream; @@ -5953,7 +5968,7 @@ Stream.prototype.pipe = function(dest, options) { return dest; }; -},{"11":11,"14":14,"40":40,"46":46,"47":47,"48":48,"49":49}],39:[function(_dereq_,module,exports){ +},{"11":11,"14":14,"40":40,"47":47,"48":48,"49":49,"50":50}],39:[function(_dereq_,module,exports){ arguments[4][9][0].apply(exports,arguments) },{"9":9}],40:[function(_dereq_,module,exports){ module.exports = _dereq_(41) @@ -6116,21 +6131,21 @@ if (debugUtil && debugUtil.debuglog) { } /**/ +var BufferList = _dereq_(46); 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]]; + if (typeof emitter.prependListener === 'function') { + return emitter.prependListener(event, fn); + } else { + // This is a 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; @@ -6154,7 +6169,10 @@ function ReadableState(options, stream) { // cast to ints. this.highWaterMark = ~ ~this.highWaterMark; - this.buffer = []; + // A linked list is used to store data chunks instead of an array because the + // linked list can remove elements from the beginning faster than + // array.shift() + this.buffer = new BufferList(); this.length = 0; this.pipes = null; this.pipesCount = 0; @@ -6194,7 +6212,7 @@ function ReadableState(options, stream) { this.decoder = null; this.encoding = null; if (options.encoding) { - if (!StringDecoder) StringDecoder = _dereq_(50).StringDecoder; + if (!StringDecoder) StringDecoder = _dereq_(51).StringDecoder; this.decoder = new StringDecoder(options.encoding); this.encoding = options.encoding; } @@ -6305,7 +6323,7 @@ function needMoreData(state) { // backwards compatibility. Readable.prototype.setEncoding = function (enc) { - if (!StringDecoder) StringDecoder = _dereq_(50).StringDecoder; + if (!StringDecoder) StringDecoder = _dereq_(51).StringDecoder; this._readableState.decoder = new StringDecoder(enc); this._readableState.encoding = enc; return this; @@ -6317,7 +6335,8 @@ function computeNewHighWaterMark(n) { if (n >= MAX_HWM) { n = MAX_HWM; } else { - // Get the next highest power of 2 + // Get the next highest power of 2 to prevent increasing hwm excessively in + // tiny amounts n--; n |= n >>> 1; n |= n >>> 2; @@ -6329,44 +6348,34 @@ function computeNewHighWaterMark(n) { return n; } +// This function is designed to be inlinable, so please take care when making +// changes to the function body. 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 || state.length === 0 && state.ended) return 0; + if (state.objectMode) return 1; + if (n !== n) { + // Only flow one buffer at a time + if (state.flowing && state.length) return state.buffer.head.data.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 we're asking for more than the current hwm, then raise the hwm. 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; - } + if (n <= state.length) return n; + // Don't have enough + if (!state.ended) { + state.needReadable = true; + return 0; } - - return n; + return state.length; } // you can override either this method, or the async _read(n) below. Readable.prototype.read = function (n) { debug('read', n); + n = parseInt(n, 10); var state = this._readableState; var nOrig = n; - if (typeof n !== 'number' || n > 0) state.emittedReadable = false; + if (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 @@ -6422,9 +6431,7 @@ Readable.prototype.read = function (n) { if (state.ended || state.reading) { doRead = false; debug('reading or ended', doRead); - } - - if (doRead) { + } else if (doRead) { debug('do read'); state.reading = true; state.sync = true; @@ -6433,28 +6440,29 @@ Readable.prototype.read = function (n) { // 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 (!state.reading) n = howMuchToRead(nOrig, state); } - // 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; + } else { + state.length -= n; } - 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 (state.length === 0) { + // If we have nothing in the buffer, then we want to know + // as soon as we *do* get something into the buffer. + if (!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 we tried to read() past the EOF, then emit end on the next tick. + if (nOrig !== n && state.ended) endReadable(this); + } if (ret !== null) this.emit('data', ret); @@ -6602,11 +6610,17 @@ Readable.prototype.pipe = function (dest, pipeOpts) { if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain(); } + // If the user pushes more data while we're writing to dest then we'll end up + // in ondata again. However, we only want to increase awaitDrain once because + // dest will only emit one 'drain' event for the multiple writes. + // => Introduce a guard on increasing awaitDrain. + var increasedAwaitDrain = false; src.on('data', ondata); function ondata(chunk) { debug('ondata'); + increasedAwaitDrain = false; var ret = dest.write(chunk); - if (false === ret) { + if (false === ret && !increasedAwaitDrain) { // If the user unpiped during `dest.write()`, it is possible // to get stuck in a permanently paused state if that write // also returned false. @@ -6614,6 +6628,7 @@ Readable.prototype.pipe = function (dest, pipeOpts) { 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++; + increasedAwaitDrain = true; } src.pause(); } @@ -6727,18 +6742,14 @@ Readable.prototype.unpipe = function (dest) { 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) { + if (ev === 'data') { + // Start flowing on next tick if stream isn't explicitly paused + if (this._readableState.flowing !== false) this.resume(); + } else if (ev === 'readable') { var state = this._readableState; - if (!state.readableListening) { - state.readableListening = true; + if (!state.endEmitted && !state.readableListening) { + state.readableListening = state.needReadable = true; state.emittedReadable = false; - state.needReadable = true; if (!state.reading) { processNextTick(nReadingNextTick, this); } else if (state.length) { @@ -6782,6 +6793,7 @@ function resume_(stream, state) { } state.resumeScheduled = false; + state.awaitDrain = 0; stream.emit('resume'); flow(stream); if (state.flowing && !state.reading) stream.read(0); @@ -6800,11 +6812,7 @@ Readable.prototype.pause = function () { function flow(stream) { var state = stream._readableState; debug('flow', state.flowing); - if (state.flowing) { - do { - var chunk = stream.read(); - } while (null !== chunk && state.flowing); - } + while (state.flowing && stream.read() !== null) {} } // wrap an old-style stream as the async data source. @@ -6875,50 +6883,101 @@ Readable._fromList = fromList; // Pluck off n bytes from an array of buffers. // Length is the combined lengths of all the buffers in the list. +// This function is designed to be inlinable, so please take care when making +// changes to the function body. function fromList(n, state) { - var list = state.buffer; - var length = state.length; - var stringMode = !!state.decoder; - var objectMode = !!state.objectMode; - var ret; + // nothing buffered + if (state.length === 0) return null; - // 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; + var ret; + if (state.objectMode) ret = state.buffer.shift();else if (!n || n >= state.length) { + // read it all, truncate the list + if (state.decoder) ret = state.buffer.join('');else if (state.buffer.length === 1) ret = state.buffer.head.data;else ret = state.buffer.concat(state.length); + state.buffer.clear(); } 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 = 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); + // read part of list + ret = fromListPartial(n, state.buffer, state.decoder); + } - if (stringMode) ret += _buf.slice(0, cpy);else _buf.copy(ret, c, 0, cpy); + return ret; +} - if (cpy < _buf.length) list[0] = _buf.slice(cpy);else list.shift(); +// Extracts only enough buffered data to satisfy the amount requested. +// This function is designed to be inlinable, so please take care when making +// changes to the function body. +function fromListPartial(n, list, hasStrings) { + var ret; + if (n < list.head.data.length) { + // slice is the same for buffers and strings + ret = list.head.data.slice(0, n); + list.head.data = list.head.data.slice(n); + } else if (n === list.head.data.length) { + // first chunk is a perfect match + ret = list.shift(); + } else { + // result spans more than one buffer + ret = hasStrings ? copyFromBufferString(n, list) : copyFromBuffer(n, list); + } + return ret; +} - c += cpy; +// Copies a specified amount of characters from the list of buffered data +// chunks. +// This function is designed to be inlinable, so please take care when making +// changes to the function body. +function copyFromBufferString(n, list) { + var p = list.head; + var c = 1; + var ret = p.data; + n -= ret.length; + while (p = p.next) { + var str = p.data; + var nb = n > str.length ? str.length : n; + if (nb === str.length) ret += str;else ret += str.slice(0, n); + n -= nb; + if (n === 0) { + if (nb === str.length) { + ++c; + if (p.next) list.head = p.next;else list.head = list.tail = null; + } else { + list.head = p; + p.data = str.slice(nb); } + break; } + ++c; } + list.length -= c; + return ret; +} +// Copies a specified amount of bytes from the list of buffered data chunks. +// This function is designed to be inlinable, so please take care when making +// changes to the function body. +function copyFromBuffer(n, list) { + var ret = bufferShim.allocUnsafe(n); + var p = list.head; + var c = 1; + p.data.copy(ret); + n -= p.data.length; + while (p = p.next) { + var buf = p.data; + var nb = n > buf.length ? buf.length : n; + buf.copy(ret, ret.length - n, 0, nb); + n -= nb; + if (n === 0) { + if (nb === buf.length) { + ++c; + if (p.next) list.head = p.next;else list.head = list.tail = null; + } else { + list.head = p; + p.data = buf.slice(nb); + } + break; + } + ++c; + } + list.length -= c; return ret; } @@ -6957,7 +7016,7 @@ function indexOf(xs, x) { return -1; } }).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){ +},{"10":10,"11":11,"14":14,"27":27,"28":28,"39":39,"41":41,"46":46,"51":51,"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 @@ -7165,7 +7224,7 @@ util.inherits = _dereq_(14); /**/ var internalUtil = { - deprecate: _dereq_(58) + deprecate: _dereq_(59) }; /**/ @@ -7667,10 +7726,75 @@ function CorkedRequest(state) { }; } }).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){ +},{"10":10,"11":11,"14":14,"27":27,"28":28,"41":41,"59":59,"7":7,"8":8}],46:[function(_dereq_,module,exports){ +'use strict'; + +var Buffer = _dereq_(8).Buffer; +/**/ +var bufferShim = _dereq_(7); +/**/ + +module.exports = BufferList; + +function BufferList() { + this.head = null; + this.tail = null; + this.length = 0; +} + +BufferList.prototype.push = function (v) { + var entry = { data: v, next: null }; + if (this.length > 0) this.tail.next = entry;else this.head = entry; + this.tail = entry; + ++this.length; +}; + +BufferList.prototype.unshift = function (v) { + var entry = { data: v, next: this.head }; + if (this.length === 0) this.tail = entry; + this.head = entry; + ++this.length; +}; + +BufferList.prototype.shift = function () { + if (this.length === 0) return; + var ret = this.head.data; + if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next; + --this.length; + return ret; +}; + +BufferList.prototype.clear = function () { + this.head = this.tail = null; + this.length = 0; +}; + +BufferList.prototype.join = function (s) { + if (this.length === 0) return ''; + var p = this.head; + var ret = '' + p.data; + while (p = p.next) { + ret += s + p.data; + }return ret; +}; + +BufferList.prototype.concat = function (n) { + if (this.length === 0) return bufferShim.alloc(0); + if (this.length === 1) return this.head.data; + var ret = bufferShim.allocUnsafe(n >>> 0); + var p = this.head; + var i = 0; + while (p) { + p.data.copy(ret, i); + i += p.data.length; + p = p.next; + } + return ret; +}; +},{"7":7,"8":8}],47:[function(_dereq_,module,exports){ module.exports = _dereq_(42) -},{"42":42}],47:[function(_dereq_,module,exports){ +},{"42":42}],48:[function(_dereq_,module,exports){ (function (process){ var Stream = (function (){ try { @@ -7690,12 +7814,12 @@ if (!process.browser && process.env.READABLE_STREAM === 'disable' && Stream) { } }).call(this,_dereq_(28)) -},{"28":28,"41":41,"42":42,"43":43,"44":44,"45":45}],48:[function(_dereq_,module,exports){ +},{"28":28,"41":41,"42":42,"43":43,"44":44,"45":45}],49:[function(_dereq_,module,exports){ arguments[4][35][0].apply(exports,arguments) -},{"35":35,"44":44}],49:[function(_dereq_,module,exports){ +},{"35":35,"44":44}],50:[function(_dereq_,module,exports){ module.exports = _dereq_(45) -},{"45":45}],50:[function(_dereq_,module,exports){ +},{"45":45}],51:[function(_dereq_,module,exports){ // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -7918,11 +8042,11 @@ function base64DetectIncompleteChar(buffer) { this.charLength = this.charReceived ? 3 : 0; } -},{"8":8}],51:[function(_dereq_,module,exports){ +},{"8":8}],52:[function(_dereq_,module,exports){ arguments[4][9][0].apply(exports,arguments) -},{"9":9}],52:[function(_dereq_,module,exports){ +},{"9":9}],53:[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){ +},{"10":10,"14":14,"27":27,"41":41,"54":54,"56":56}],54:[function(_dereq_,module,exports){ (function (process){ 'use strict'; @@ -7933,7 +8057,7 @@ var processNextTick = _dereq_(27); /**/ /**/ -var isArray = _dereq_(51); +var isArray = _dereq_(52); /**/ /**/ @@ -7984,7 +8108,7 @@ util.inherits(Readable, Stream); var Duplex; function ReadableState(options, stream) { - Duplex = Duplex || _dereq_(52); + Duplex = Duplex || _dereq_(53); options = options || {}; @@ -8043,7 +8167,7 @@ function ReadableState(options, stream) { this.decoder = null; this.encoding = null; if (options.encoding) { - if (!StringDecoder) StringDecoder = _dereq_(50).StringDecoder; + if (!StringDecoder) StringDecoder = _dereq_(51).StringDecoder; this.decoder = new StringDecoder(options.encoding); this.encoding = options.encoding; } @@ -8051,7 +8175,7 @@ function ReadableState(options, stream) { var Duplex; function Readable(options) { - Duplex = Duplex || _dereq_(52); + Duplex = Duplex || _dereq_(53); if (!(this instanceof Readable)) return new Readable(options); @@ -8154,7 +8278,7 @@ function needMoreData(state) { // backwards compatibility. Readable.prototype.setEncoding = function (enc) { - if (!StringDecoder) StringDecoder = _dereq_(50).StringDecoder; + if (!StringDecoder) StringDecoder = _dereq_(51).StringDecoder; this._readableState.decoder = new StringDecoder(enc); this._readableState.encoding = enc; return this; @@ -8805,7 +8929,7 @@ function indexOf(xs, x) { 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){ +},{"10":10,"11":11,"14":14,"27":27,"28":28,"51":51,"52":52,"53":53,"6":6,"8":8}],55:[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 @@ -8852,7 +8976,7 @@ function indexOf(xs, x) { module.exports = Transform; -var Duplex = _dereq_(52); +var Duplex = _dereq_(53); /**/ var util = _dereq_(10); @@ -8986,7 +9110,7 @@ function done(stream, er) { return stream.push(null); } -},{"10":10,"14":14,"52":52}],55:[function(_dereq_,module,exports){ +},{"10":10,"14":14,"53":53}],56:[function(_dereq_,module,exports){ (function (process){ // A bit simpler than readable streams. // Implement an async ._write(chunk, encoding, cb), and it'll handle all @@ -9017,7 +9141,7 @@ util.inherits = _dereq_(14); /**/ var internalUtil = { - deprecate: _dereq_(58) + deprecate: _dereq_(59) }; /**/ @@ -9047,7 +9171,7 @@ function WriteReq(chunk, encoding, cb) { var Duplex; function WritableState(options, stream) { - Duplex = Duplex || _dereq_(52); + Duplex = Duplex || _dereq_(53); options = options || {}; @@ -9164,7 +9288,7 @@ WritableState.prototype.getBuffer = function writableStateGetBuffer() { var Duplex; function Writable(options) { - Duplex = Duplex || _dereq_(52); + Duplex = Duplex || _dereq_(53); // Writable ctor is applied to Duplexes, though they're not // instanceof Writable, they're instanceof Readable. @@ -9505,11 +9629,11 @@ function CorkedRequest(state) { }; } }).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){ +},{"10":10,"11":11,"14":14,"27":27,"28":28,"53":53,"59":59,"8":8}],57:[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){ +},{"35":35,"55":55}],58:[function(_dereq_,module,exports){ +arguments[4][20][0].apply(exports,arguments) +},{"20":20,"28":28,"57":57,"61":61,"62":62}],59:[function(_dereq_,module,exports){ (function (global){ /** @@ -9580,14 +9704,14 @@ function config (name) { } }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{}],59:[function(_dereq_,module,exports){ +},{}],60:[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'; } -},{}],60:[function(_dereq_,module,exports){ +},{}],61:[function(_dereq_,module,exports){ (function (process,global){ // Copyright Joyent, Inc. and other Node contributors. // @@ -10114,7 +10238,7 @@ function isPrimitive(arg) { } exports.isPrimitive = isPrimitive; -exports.isBuffer = _dereq_(59); +exports.isBuffer = _dereq_(60); function objectToString(o) { return Object.prototype.toString.call(o); @@ -10177,7 +10301,7 @@ function hasOwnProperty(obj, prop) { } }).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){ +},{"14":14,"28":28,"60":60}],62:[function(_dereq_,module,exports){ module.exports = extend var hasOwnProperty = Object.prototype.hasOwnProperty; @@ -10198,10 +10322,10 @@ function extend() { return target } -},{}],62:[function(_dereq_,module,exports){ +},{}],63:[function(_dereq_,module,exports){ module.exports={ "name": "pouchdb-replication-stream", - "version": "1.2.7", + "version": "1.2.8", "description": "PouchDB/CouchDB replication as a stream", "main": "lib/index.js", "repository": { @@ -10237,7 +10361,7 @@ module.exports={ "dependencies": { "argsarray": "0.0.1", "inherits": "~2.0.1", - "ldjson-stream": "^1.2.1", + "ndjson": "^1.4.3", "lodash.pick": "^4.0.0", "pouchdb-promise": "^5.4.4", "pouch-stream": "^0.4.0", @@ -10271,14 +10395,14 @@ module.exports={ } } -},{}],63:[function(_dereq_,module,exports){ +},{}],64:[function(_dereq_,module,exports){ 'use strict'; var utils = _dereq_(1); var version = _dereq_(3); -var ldj = _dereq_(17); -var through = _dereq_(57).obj; -var pick = _dereq_(19); +var ndj = _dereq_(19); +var through = _dereq_(58).obj; +var pick = _dereq_(18); var toBufferStream = _dereq_(2); var DEFAULT_BATCH_SIZE = 50; @@ -10296,7 +10420,7 @@ var ALLOWED_PARAMS = [ exports.adapters = {}; exports.adapters.writableStream = _dereq_(4); -exports.plugin = _dereq_(22); +exports.plugin = _dereq_(23); exports.plugin.dump = utils.toPromise(function (writableStream, opts, callback) { var self = this; @@ -10353,8 +10477,18 @@ exports.plugin.load = utils.toPromise(function (readableStream, opts, callback) batchSize = DEFAULT_BATCH_SIZE; } + // We need this variable in order to call the callback only once. + // The stream is not closed when the 'error' event is emitted. + var error = null; + var queue = []; - readableStream.pipe(toBufferStream()).pipe(ldj.parse()).pipe(through(function (data, _, next) { + readableStream + .pipe(toBufferStream()) + .pipe(ndj.parse()) + .on('error', function (errorCatched) { + error = errorCatched; + }) + .pipe(through(function (data, _, next) { if (!data.docs) { return next(); } @@ -10380,7 +10514,7 @@ exports.plugin.load = utils.toPromise(function (readableStream, opts, callback) .pipe(this.createWriteStream({new_edits: false})) .on('error', callback) .on('finish', function () { - callback(null, {ok: true}); + callback(error, {ok: true}); }); }); @@ -10390,5 +10524,5 @@ if (typeof window !== 'undefined' && window.PouchDB) { window.PouchDB.adapter('writableStream', exports.adapters.writableStream); } -},{"1":1,"17":17,"19":19,"2":2,"22":22,"3":3,"4":4,"57":57}]},{},[63])(63) +},{"1":1,"18":18,"19":19,"2":2,"23":23,"3":3,"4":4,"58":58}]},{},[64])(64) }); \ No newline at end of file diff --git a/dist/pouchdb.replication-stream.min.js b/dist/pouchdb.replication-stream.min.js index e39025c..d95ec6e 100644 --- a/dist/pouchdb.replication-stream.min.js +++ b/dist/pouchdb.replication-stream.min.js @@ -1,4 +1,4 @@ -!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)}); +!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(a,s){if(!n[a]){if(!t[a]){var u="function"==typeof require&&require;if(!s&&u)return u(a,!0);if(o)return o(a,!0);var f=new Error("Cannot find module '"+a+"'");throw f.code="MODULE_NOT_FOUND",f}var c=n[a]={exports:{}};t[a][0].call(c.exports,function(e){var n=t[a][1][e];return i(n?n:e)},c,c.exports,e,t,n,r)}return n[a].exports}for(var o="function"==typeof require&&require,a=0;a0)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),a=u>0?e.length-4:e.length;var h=0;for(r=0,i=0;r>16),n((65280&s)>>8),n(255&s);return 2===u?(s=t(e.charAt(r))<<2|t(e.charAt(r+1))>>4,n(255&s)):1===u&&(s=t(e.charAt(r))<<10|t(e.charAt(r+1))<<4|t(e.charAt(r+2))>>2,n(s>>8&255),n(255&s)),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,a,s=e.length%3,u="";for(i=0,a=e.length-s;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,a="+".charCodeAt(0),s="/".charCodeAt(0),u="0".charCodeAt(0),f="a".charCodeAt(0),c="A".charCodeAt(0),h="-".charCodeAt(0),l="_".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,a=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>a)throw new RangeError("size is too large");var r=n,o=t;void 0===o&&(r=void 0,o=0);var s=new i(e);if("string"==typeof o)for(var u=new i(o,r),f=u.length,c=-1;++ca)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 a=r;if("undefined"==typeof a&&(a=e.byteLength-o),o>=e.byteLength)throw new RangeError("'offset' is out of bounds");if(a>e.byteLength-o)throw new RangeError("'length' is out of bounds");return new i(e.slice(o,o+a))}if(i.isBuffer(e)){var s=new i(e.length);return e.copy(s,0,0,e.length),s}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>=a)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?a(this,e):"string"==typeof e?s(this,e,arguments.length>1?arguments[1]:"utf8"):u(this,e)):arguments.length>1?new o(e,arguments[1]):new o(e)}function a(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 a=0;a239?4:o>223?3:o>191?2:1;if(i+s<=n){var u,f,c,h;switch(s){case 1:o<128&&(a=o);break;case 2:u=e[i+1],128===(192&u)&&(h=(31&o)<<6|63&u,h>127&&(a=h));break;case 3:u=e[i+1],f=e[i+2],128===(192&u)&&128===(192&f)&&(h=(15&o)<<12|(63&u)<<6|63&f,h>2047&&(h<55296||h>57343)&&(a=h));break;case 4:u=e[i+1],f=e[i+2],c=e[i+3],128===(192&u)&&128===(192&f)&&128===(192&c)&&(h=(15&o)<<18|(63&u)<<12|(63&f)<<6|63&c,h>65535&&h<1114112&&(a=h))}}null===a?(a=65533,s=1):a>65535&&(a-=65536,r.push(a>>>10&1023|55296),a=56320|1023&a),r.push(a),i+=s}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,a){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=[],a=0;a55295&&n<57344){if(!i){if(n>56319){(t-=3)>-1&&o.push(239,191,189);continue}if(a+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,a=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 a=!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(a)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase(),a=!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,a=1,s=e<0?1:0;for(this[t]=255&e;++o>0)-s&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,a=1,s=e<0?1:0;for(this[t+o]=255&e;--o>=0&&(a*=256);)this[t+o]=(e/a>>0)-s&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(a<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,s;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(a(n)){for(s=o;s-- >0;)if(n[s]===t||n[s].listener&&n[s].listener===t){r=s;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,a,s=8*i-r-1,u=(1<>1,c=-7,h=n?i-1:0,l=n?-1:1,d=e[t+h];for(h+=l,o=d&(1<<-c)-1,d>>=-c,c+=s;c>0;o=256*o+e[t+h],h+=l,c-=8);for(a=o&(1<<-c)-1,o>>=-c,c+=r;c>0;a=256*a+e[t+h],h+=l,c-=8);if(0===o)o=1-f;else{if(o===u)return a?NaN:(d?-1:1)*(1/0);a+=Math.pow(2,r),o-=f}return(d?-1:1)*a*Math.pow(2,o-r)},n.write=function(e,t,n,r,i,o){var a,s,u,f=8*o-i-1,c=(1<>1,l=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?(s=isNaN(t)?1:0,a=c):(a=Math.floor(Math.log(t)/Math.LN2),t*(u=Math.pow(2,-a))<1&&(a--,u*=2),t+=a+h>=1?l/u:l*Math.pow(2,1-h),t*u>=2&&(a++,u/=2),a+h>=c?(s=0,a=c):a+h>=1?(s=(t*u-1)*Math.pow(2,i),a+=h):(s=t*Math.pow(2,h-1)*Math.pow(2,i),a=0));i>=8;e[n+d]=255&s,d+=p,s/=256,i-=8);for(a=a<0;e[n+d]=255&a,d+=p,a/=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=h.length;n;){for(t=h,h=[],e=-1;++e0&&n(c)?t>1?o(c,t-1,n,r,a):i(a,c):r||(a[a.length]=c)}return a}function a(e,t){return e=Object(e),s(e,t,function(t,n){return n in e})}function s(e,t,n){for(var r=-1,i=t.length,o={};++r-1&&e%1==0&&e<=m}function v(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function b(e){return!!e&&"object"==typeof e}function w(e){return"symbol"==typeof e||b(e)&&A.call(e)==R}var y=1/0,m=9007199254740991,_="[object Arguments]",E="[object Function]",S="[object GeneratorFunction]",R="[object Symbol]",k="object"==typeof e&&e&&e.Object===Object&&e,M="object"==typeof self&&self&&self.Object===Object&&self,j=k||M||Function("return this")(),L=Object.prototype,x=L.hasOwnProperty,A=L.toString,B=j.Symbol,T=L.propertyIsEnumerable,D=B?B.isConcatSpreadable:void 0,O=Math.max,I=Array.isArray,C=u(function(e,t){return null==e?{}:a(e,r(o(t,1),c))});t.exports=C}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],19:[function(e,t,n){function r(e){function t(t){try{if(t)return JSON.parse(t)}catch(n){e.strict&&this.emit("error",new Error("Could not parse row "+t.slice(0,50)+"..."))}}return e=e||{},e.strict=e.strict!==!1,a(t)}function i(e){return o.obj(e,function(e,t,n){n(null,JSON.stringify(e)+s)})}var o=e(20),a=e(36),s=e(21).EOL;t.exports=r,t.exports.serialize=t.exports.stringify=i,t.exports.parse=r},{20:20,21:21,36:36}],20:[function(e,t,n){(function(n){function r(e){a.call(this,e),this._destroyed=!1}function i(e,t,n){n(null,e)}function o(e){return function(t,n,r){return"function"==typeof t&&(r=n,n=t,t={}),"function"!=typeof n&&(n=i),"function"!=typeof r&&(r=null),e(t,n,r)}}var a=e(35),s=e(61).inherits,u=e(62);s(r,a),r.prototype.destroy=function(e){if(!this._destroyed){this._destroyed=!0;var t=this;n.nextTick(function(){e&&t.emit("error",e),t.emit("close")})}},t.exports=o(function(e,t,n){var i=new r(e);return i._transform=t,n&&(i._flush=n),i}),t.exports.ctor=o(function(e,t,n){function i(t){return this instanceof i?(this.options=u(e,t),void r.call(this,this.options)):new i(t)}return s(i,r),i.prototype._transform=t,n&&(i.prototype._flush=n),i}),t.exports.obj=o(function(e,t,n){var i=new r(u({objectMode:!0,highWaterMark:16},e));return i._transform=t,n&&(i._flush=n),i})}).call(this,e(28))},{28:28,35:35,61:61,62:62}],21:[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"},{}],22:[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)})}},{}],23:[function(e,t,n){"use strict";var r=e(25),i=e(24);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(22),a=["drain","pipe","unpipe","error"];n.write=function(e,t,n){return this.__stream||(this.__stream=new r(this),o(this,this.__stream,a),this.on("destroy",function(){this.__stream.end()})),this.__stream.write(e,t,n)},n.end=function(){this.emit("done")}},{22:22,24:24,25:25}],24:[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}],25:[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}],26:[function(e,t,n){"use strict";function r(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var i=r(e(17)),o="function"==typeof Promise?Promise:i;t.exports=o},{17:17}],27:[function(e,t,n){(function(e){"use strict";function n(t,n,r,i){if("function"!=typeof t)throw new TypeError('"callback" argument must be a function');var o,a,s=arguments.length;switch(s){case 0:case 1:return e.nextTick(t);case 2:return e.nextTick(function(){t.call(null,n)});case 3:return e.nextTick(function(){t.call(null,n,r)});case 4:return e.nextTick(function(){t.call(null,n,r,i)});default:for(o=new Array(s-1),a=0;a1)for(var n=1;n0)if(t.ended&&!i){var s=new Error("stream.push() after EOF");e.emit("error",s)}else if(t.endEmitted&&i){var s=new Error("stream.unshift() after end event");e.emit("error",s)}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&&h(e),d(e,t);else i||(t.reading=!1);return a(t)}function a(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=s(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?h(e):m(e)}function h(e){var t=e._readableState;t.needReadable=!1,t.emittedReadable||(t.emittedReadable=!0,t.sync?n.nextTick(function(){l(e)}):l(e))}function l(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,a=!!t.objectMode;if(0===r.length)return null;if(0===i)n=null;else if(a)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 h(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",s),e.removeListener("finish",u),e.removeListener("drain",p),e.removeListener("error",a),e.removeListener("unpipe",r),c.removeListener("end",i),c.removeListener("end",o),e._writableState&&!e._writableState.needDrain||p()}function a(t){f(),e.removeListener("error",a),0===k.listenerCount(e,"error")&&e.emit("error",t)}function s(){e.removeListener("finish",u),f()}function u(){e.removeListener("close",s),f()}function f(){c.unpipe(e)}var c=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;var l=(!t||t.end!==!1)&&e!==n.stdout&&e!==n.stderr,d=l?i:o;h.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(a):e._events.error=[a,e._events.error]:e.on("error",a),e.once("close",s),e.once("finish",u),e.emit("pipe",c),h.flowing||(this.on("readable",b),h.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())):a=this._last+a,r=0;r0)if(t.ended&&!i){var a=new Error("stream.push() after EOF");e.emit("error",a)}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&&l(e))),p(e,t)}else i||(t.reading=!1);return s(t)}function s(e){return!e.ended&&(e.needReadable||e.length=N?e=N:(e--,e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e++),e}function f(e,t){return e<=0||0===t.length&&t.ended?0:t.objectMode?1:e!==e?t.flowing&&t.length?t.buffer.head.data.length:t.length:(e>t.highWaterMark&&(t.highWaterMark=u(e)),e<=t.length?e:t.ended?t.length:(t.needReadable=!0, +0))}function c(e,t){var n=null;return D.isBuffer(t)||"string"==typeof t||null===t||void 0===t||e.objectMode||(n=new TypeError("Invalid non-string/buffer chunk")),n}function h(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||(P("emitReadable",t.flowing),t.emittedReadable=!0,t.sync?x(d,e):d(e))}function d(e){P("emit readable"),e.emit("readable"),m(e)}function p(e,t){t.readingMore||(t.readingMore=!0,x(g,e,t))}function g(e,t){for(var n=t.length;!t.reading&&!t.flowing&&!t.ended&&t.length=t.length?(n=t.decoder?t.buffer.join(""):1===t.buffer.length?t.buffer.head.data:t.buffer.concat(t.length),t.buffer.clear()):n=E(e,t.buffer,t.decoder),n}function E(e,t,n){var r;return eo.length?o.length:e;if(i+=a===o.length?o:o.slice(0,e),e-=a,0===e){a===o.length?(++r,n.next?t.head=n.next:t.head=t.tail=null):(t.head=n,n.data=o.slice(a));break}++r}return t.length-=r,i}function R(e,t){var n=O.allocUnsafe(e),r=t.head,i=1;for(r.data.copy(n),e-=r.data.length;r=r.next;){var o=r.data,a=e>o.length?o.length:e;if(o.copy(n,n.length-e,0,a),e-=a,0===e){a===o.length?(++i,r.next?t.head=r.next:t.head=t.tail=null):(t.head=r,r.data=o.slice(a));break}++i}return t.length-=i,n}function k(e){var t=e._readableState;if(t.length>0)throw new Error('"endReadable()" called on non-empty stream');t.endEmitted||(t.ended=!0,x(M,t,e))}function M(e,t){e.endEmitted||0!==e.length||(e.endEmitted=!0,t.readable=!1,t.emit("end"))}function j(e,t){for(var n=0,r=e.length;n=t.highWaterMark||t.ended))return P("read: emitReadable",t.length,t.ended),0===t.length&&t.ended?k(this):l(this),null;if(e=f(e,t),0===e&&t.ended)return 0===t.length&&k(this),null;var r=t.needReadable;P("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&&k(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){P("onunpipe"),e===l&&a()}function o(){P("onend"),e.end()}function a(){P("cleanup"),e.removeListener("close",f),e.removeListener("finish",c),e.removeListener("drain",b),e.removeListener("error",u),e.removeListener("unpipe",i),l.removeListener("end",o),l.removeListener("end",a),l.removeListener("data",s),w=!0,!d.awaitDrain||e._writableState&&!e._writableState.needDrain||b()}function s(t){P("ondata"),y=!1;var n=e.write(t);!1!==n||y||((1===d.pipesCount&&d.pipes===e||d.pipesCount>1&&L(d.pipes,e)!==-1)&&!w&&(P("false write response, pause",l._readableState.awaitDrain),l._readableState.awaitDrain++,y=!0),l.pause())}function u(t){P("onerror",t),h(),e.removeListener("error",u),0===T(e,"error")&&e.emit("error",t)}function f(){e.removeListener("finish",c),h()}function c(){P("onfinish"),e.removeListener("close",f),h()}function h(){P("unpipe"),l.unpipe(e)}var l=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,P("pipe count=%d opts=%j",d.pipesCount,t);var p=(!t||t.end!==!1)&&e!==n.stdout&&e!==n.stderr,g=p?o:a;d.endEmitted?x(g):l.once("end",g),e.on("unpipe",i);var b=v(l);e.on("drain",b);var w=!1,y=!1;return l.on("data",s),r(e,"error",u),e.once("close",f),e.once("finish",c),e.emit("pipe",l),d.flowing||(P("pipe resume"),l.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;a.WritableState=o;var k=e(10);k.inherits=e(14);var M,j={deprecate:e(59)};!function(){try{M=e("stream")}catch(e){}finally{M||(M=e(11).EventEmitter)}}();var L=e(8).Buffer,x=e(7);k.inherits(a,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;a.prototype.pipe=function(){this.emit("error",new Error("Cannot pipe, not readable"))},a.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?s(this,n):u(this,i,e,n)&&(i.pendingcb++,o=c(this,i,e,t,n)),o},a.prototype.cork=function(){var e=this._writableState;e.corked++},a.prototype.uncork=function(){var e=this._writableState;e.corked&&(e.corked--,e.writing||e.corked||e.finished||e.bufferProcessing||!e.bufferedRequest||b(this,e))},a.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},a.prototype._write=function(e,t,n){n(new Error("not implemented"))},a.prototype._writev=null,a.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,59:59,7:7,8:8}],46:[function(e,t,n){"use strict";function r(){this.head=null,this.tail=null,this.length=0}var i=(e(8).Buffer,e(7));t.exports=r,r.prototype.push=function(e){var t={data:e,next:null};this.length>0?this.tail.next=t:this.head=t,this.tail=t,++this.length},r.prototype.unshift=function(e){var t={data:e,next:this.head};0===this.length&&(this.tail=t),this.head=t,++this.length},r.prototype.shift=function(){if(0!==this.length){var e=this.head.data;return 1===this.length?this.head=this.tail=null:this.head=this.head.next,--this.length,e}},r.prototype.clear=function(){this.head=this.tail=null,this.length=0},r.prototype.join=function(e){if(0===this.length)return"";for(var t=this.head,n=""+t.data;t=t.next;)n+=e+t.data;return n},r.prototype.concat=function(e){if(0===this.length)return i.alloc(0);if(1===this.length)return this.head.data;for(var t=i.allocUnsafe(e>>>0),n=this.head,r=0;n;)n.data.copy(t,r),r+=n.data.length,n=n.next;return t}},{7:7,8:8}],47:[function(e,t,n){t.exports=e(42)},{42:42}],48:[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}],49:[function(e,t,n){arguments[4][35][0].apply(n,arguments)},{35:35,44:44}],50:[function(e,t,n){t.exports=e(45)},{45:45}],51:[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 a(e){this.charReceived=e.length%3,this.charLength=this.charReceived?3:0}var s=e(8).Buffer,u=s.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=a;break;default:return void(this.write=i)}this.charBuffer=new s(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}],52:[function(e,t,n){arguments[4][9][0].apply(n,arguments)},{9:9}],53:[function(e,t,n){arguments[4][41][0].apply(n,arguments)},{10:10,14:14,27:27,41:41,54:54,56:56}],54:[function(e,t,n){(function(n){"use strict";function r(t,n){O=O||e(53),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(51).StringDecoder),this.decoder=new D(t.encoding),this.encoding=t.encoding)}function i(t){return O=O||e(53),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 s=new Error("stream.push() after EOF");e.emit("error",s)}else if(t.endEmitted&&i){var s=new Error("stream.unshift() after end event");e.emit("error",s)}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&&h(e))),d(e,t)}else i||(t.reading=!1);return a(t)}function a(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=s(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,h(e)}}function h(e){var t=e._readableState;t.needReadable=!1,t.emittedReadable||(T("emitReadable",t.flowing),t.emittedReadable=!0,t.sync?k(l,e):l(e))}function l(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):h(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===h&&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",s),e.removeListener("unpipe",r),h.removeListener("end",i),h.removeListener("end",o),h.removeListener("data",a),b=!0,!l.awaitDrain||e._writableState&&!e._writableState.needDrain||v()}function a(t){T("ondata");var n=e.write(t);!1===n&&(1!==l.pipesCount||l.pipes[0]!==e||1!==h.listenerCount("data")||b||(T("false write response, pause",h._readableState.awaitDrain),h._readableState.awaitDrain++),h.pause())}function s(t){T("onerror",t),c(),e.removeListener("error",s),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"),h.unpipe(e)}var h=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,T("pipe count=%d opts=%j",l.pipesCount,t);var d=(!t||t.end!==!1)&&e!==n.stdout&&e!==n.stderr,p=d?i:o;l.endEmitted?k(p):h.once("end",p),e.on("unpipe",r);var v=g(h);e.on("drain",v);var b=!1;return h.on("data",a),e._events&&e._events.error?M(e._events.error)?e._events.error.unshift(s):e._events.error=[s,e._events.error]:e.on("error",s),e.once("close",u),e.once("finish",f),e.emit("pipe",h),l.flowing||(T("pipe resume"),h.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;a.WritableState=o;var M=e(10);M.inherits=e(14);var j,L={deprecate:e(59)};!function(){try{j=e("stream")}catch(e){}finally{j||(j=e(11).EventEmitter)}}();var k=e(8).Buffer;M.inherits(a,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;a.prototype.pipe=function(){this.emit("error",new Error("Cannot pipe. Not readable."))},a.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?s(this,n):u(this,i,e,n)&&(i.pendingcb++,o=c(this,i,e,t,n)),o},a.prototype.cork=function(){var e=this._writableState;e.corked++},a.prototype.uncork=function(){var e=this._writableState;e.corked&&(e.corked--,e.writing||e.corked||e.finished||e.bufferProcessing||!e.bufferedRequest||b(this,e))},a.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},a.prototype._write=function(e,t,n){n(new Error("not implemented"))},a.prototype._writev=null,a.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,53:53,59:59,8:8}],57:[function(e,t,n){arguments[4][35][0].apply(n,arguments)},{35:35,55:55}],58:[function(e,t,n){arguments[4][20][0].apply(n,arguments)},{20:20,28:28,57:57,61:61,62:62}],59:[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:{})},{}],60:[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}},{}],61:[function(e,t,n){(function(t,r){function i(e,t){var r={seen:[],stylize:a};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 a(e,t){return e}function s(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 a=Object.keys(t),g=s(a);if(e.showHidden&&(a=Object.getOwnPropertyNames(t)),k(t)&&(a.indexOf("message")>=0||a.indexOf("description")>=0))return c(t);if(0===a.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===a.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?h(e,t,r,g,a):a.map(function(n){return l(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 h(e,t,n,r,i){for(var o=[],a=0,s=t.length;a-1&&(s=o?s.split("\n").map(function(e){return" "+e}).join("\n").substr(2):"\n"+s.split("\n").map(function(e){return" "+e}).join("\n"))):s=e.stylize("[Circular]","special")),_(a)){if(o&&i.match(/^\d+$/))return s;a=JSON.stringify(""+i),a.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(a=a.substr(1,a.length-2),a=e.stylize(a,"name")):(a=a.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),a=e.stylize(a,"string"))}return a+": "+s}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}}),s=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",ndjson:"^1.4.3","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"}}},{}],64:[function(e,t,n){"use strict";var r=e(1),i=e(3),o=e(19),a=e(58).obj,s=e(18),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(23),n.plugin.dump=r.toPromise(function(e,t,n){function r(e){n(e)}var o=this;"function"==typeof t&&(n=t,t={});var a=o.constructor,u=new a(o._db_name,{adapter:"writableStream"});u.setupStream(e);var h=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=s(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})});h.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=null,s=[];e.pipe(u()).pipe(o.parse()).on("error",function(e){i=e}).pipe(a(function(e,t,n){return e.docs?(e.docs.forEach(function(e){this.push(e)},this),void n()):n()})).pipe(a(function(e,t,n){s.push(e),s.length>=r&&(this.push(s),s=[]),n()},function(e){s.length&&this.push(s),e()})).pipe(this.createWriteStream({new_edits:!1})).on("error",n).on("finish",function(){n(i,{ok:!0})})}),"undefined"!=typeof window&&window.PouchDB&&(window.PouchDB.plugin(n.plugin),window.PouchDB.adapter("writableStream",n.adapters.writableStream))},{1:1,18:18,19:19,2:2,23:23,3:3,4:4,58:58}]},{},[64])(64)});