1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(_dereq_,module,exports){
|
9 | 'use strict';
|
10 |
|
11 | module.exports = argsArray;
|
12 |
|
13 | function argsArray(fun) {
|
14 | return function () {
|
15 | var len = arguments.length;
|
16 | if (len) {
|
17 | var args = [];
|
18 | var i = -1;
|
19 | while (++i < len) {
|
20 | args[i] = arguments[i];
|
21 | }
|
22 | return fun.call(this, args);
|
23 | } else {
|
24 | return fun.call(this, []);
|
25 | }
|
26 | };
|
27 | }
|
28 | },{}],2:[function(_dereq_,module,exports){
|
29 | (function (global){
|
30 | 'use strict';
|
31 |
|
32 | var objectAssign = _dereq_(68);
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 | function compare(a, b) {
|
44 | if (a === b) {
|
45 | return 0;
|
46 | }
|
47 |
|
48 | var x = a.length;
|
49 | var y = b.length;
|
50 |
|
51 | for (var i = 0, len = Math.min(x, y); i < len; ++i) {
|
52 | if (a[i] !== b[i]) {
|
53 | x = a[i];
|
54 | y = b[i];
|
55 | break;
|
56 | }
|
57 | }
|
58 |
|
59 | if (x < y) {
|
60 | return -1;
|
61 | }
|
62 | if (y < x) {
|
63 | return 1;
|
64 | }
|
65 | return 0;
|
66 | }
|
67 | function isBuffer(b) {
|
68 | if (global.Buffer && typeof global.Buffer.isBuffer === 'function') {
|
69 | return global.Buffer.isBuffer(b);
|
70 | }
|
71 | return !!(b != null && b._isBuffer);
|
72 | }
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 | var util = _dereq_(5);
|
103 | var hasOwn = Object.prototype.hasOwnProperty;
|
104 | var pSlice = Array.prototype.slice;
|
105 | var functionsHaveNames = (function () {
|
106 | return function foo() {}.name === 'foo';
|
107 | }());
|
108 | function pToString (obj) {
|
109 | return Object.prototype.toString.call(obj);
|
110 | }
|
111 | function isView(arrbuf) {
|
112 | if (isBuffer(arrbuf)) {
|
113 | return false;
|
114 | }
|
115 | if (typeof global.ArrayBuffer !== 'function') {
|
116 | return false;
|
117 | }
|
118 | if (typeof ArrayBuffer.isView === 'function') {
|
119 | return ArrayBuffer.isView(arrbuf);
|
120 | }
|
121 | if (!arrbuf) {
|
122 | return false;
|
123 | }
|
124 | if (arrbuf instanceof DataView) {
|
125 | return true;
|
126 | }
|
127 | if (arrbuf.buffer && arrbuf.buffer instanceof ArrayBuffer) {
|
128 | return true;
|
129 | }
|
130 | return false;
|
131 | }
|
132 |
|
133 |
|
134 |
|
135 |
|
136 | var assert = module.exports = ok;
|
137 |
|
138 |
|
139 |
|
140 |
|
141 |
|
142 |
|
143 | var regex = /\s*function\s+([^\(\s]*)\s*/;
|
144 |
|
145 | function getName(func) {
|
146 | if (!util.isFunction(func)) {
|
147 | return;
|
148 | }
|
149 | if (functionsHaveNames) {
|
150 | return func.name;
|
151 | }
|
152 | var str = func.toString();
|
153 | var match = str.match(regex);
|
154 | return match && match[1];
|
155 | }
|
156 | assert.AssertionError = function AssertionError(options) {
|
157 | this.name = 'AssertionError';
|
158 | this.actual = options.actual;
|
159 | this.expected = options.expected;
|
160 | this.operator = options.operator;
|
161 | if (options.message) {
|
162 | this.message = options.message;
|
163 | this.generatedMessage = false;
|
164 | } else {
|
165 | this.message = getMessage(this);
|
166 | this.generatedMessage = true;
|
167 | }
|
168 | var stackStartFunction = options.stackStartFunction || fail;
|
169 | if (Error.captureStackTrace) {
|
170 | Error.captureStackTrace(this, stackStartFunction);
|
171 | } else {
|
172 |
|
173 | var err = new Error();
|
174 | if (err.stack) {
|
175 | var out = err.stack;
|
176 |
|
177 |
|
178 | var fn_name = getName(stackStartFunction);
|
179 | var idx = out.indexOf('\n' + fn_name);
|
180 | if (idx >= 0) {
|
181 |
|
182 |
|
183 | var next_line = out.indexOf('\n', idx + 1);
|
184 | out = out.substring(next_line + 1);
|
185 | }
|
186 |
|
187 | this.stack = out;
|
188 | }
|
189 | }
|
190 | };
|
191 |
|
192 |
|
193 | util.inherits(assert.AssertionError, Error);
|
194 |
|
195 | function truncate(s, n) {
|
196 | if (typeof s === 'string') {
|
197 | return s.length < n ? s : s.slice(0, n);
|
198 | } else {
|
199 | return s;
|
200 | }
|
201 | }
|
202 | function inspect(something) {
|
203 | if (functionsHaveNames || !util.isFunction(something)) {
|
204 | return util.inspect(something);
|
205 | }
|
206 | var rawname = getName(something);
|
207 | var name = rawname ? ': ' + rawname : '';
|
208 | return '[Function' + name + ']';
|
209 | }
|
210 | function getMessage(self) {
|
211 | return truncate(inspect(self.actual), 128) + ' ' +
|
212 | self.operator + ' ' +
|
213 | truncate(inspect(self.expected), 128);
|
214 | }
|
215 |
|
216 |
|
217 |
|
218 |
|
219 |
|
220 |
|
221 |
|
222 |
|
223 |
|
224 |
|
225 |
|
226 |
|
227 | function fail(actual, expected, message, operator, stackStartFunction) {
|
228 | throw new assert.AssertionError({
|
229 | message: message,
|
230 | actual: actual,
|
231 | expected: expected,
|
232 | operator: operator,
|
233 | stackStartFunction: stackStartFunction
|
234 | });
|
235 | }
|
236 |
|
237 |
|
238 | assert.fail = fail;
|
239 |
|
240 |
|
241 |
|
242 |
|
243 |
|
244 |
|
245 |
|
246 |
|
247 | function ok(value, message) {
|
248 | if (!value) fail(value, true, message, '==', assert.ok);
|
249 | }
|
250 | assert.ok = ok;
|
251 |
|
252 |
|
253 |
|
254 |
|
255 |
|
256 | assert.equal = function equal(actual, expected, message) {
|
257 | if (actual != expected) fail(actual, expected, message, '==', assert.equal);
|
258 | };
|
259 |
|
260 |
|
261 |
|
262 |
|
263 | assert.notEqual = function notEqual(actual, expected, message) {
|
264 | if (actual == expected) {
|
265 | fail(actual, expected, message, '!=', assert.notEqual);
|
266 | }
|
267 | };
|
268 |
|
269 |
|
270 |
|
271 |
|
272 | assert.deepEqual = function deepEqual(actual, expected, message) {
|
273 | if (!_deepEqual(actual, expected, false)) {
|
274 | fail(actual, expected, message, 'deepEqual', assert.deepEqual);
|
275 | }
|
276 | };
|
277 |
|
278 | assert.deepStrictEqual = function deepStrictEqual(actual, expected, message) {
|
279 | if (!_deepEqual(actual, expected, true)) {
|
280 | fail(actual, expected, message, 'deepStrictEqual', assert.deepStrictEqual);
|
281 | }
|
282 | };
|
283 |
|
284 | function _deepEqual(actual, expected, strict, memos) {
|
285 |
|
286 | if (actual === expected) {
|
287 | return true;
|
288 | } else if (isBuffer(actual) && isBuffer(expected)) {
|
289 | return compare(actual, expected) === 0;
|
290 |
|
291 |
|
292 |
|
293 | } else if (util.isDate(actual) && util.isDate(expected)) {
|
294 | return actual.getTime() === expected.getTime();
|
295 |
|
296 |
|
297 |
|
298 |
|
299 | } else if (util.isRegExp(actual) && util.isRegExp(expected)) {
|
300 | return actual.source === expected.source &&
|
301 | actual.global === expected.global &&
|
302 | actual.multiline === expected.multiline &&
|
303 | actual.lastIndex === expected.lastIndex &&
|
304 | actual.ignoreCase === expected.ignoreCase;
|
305 |
|
306 |
|
307 |
|
308 | } else if ((actual === null || typeof actual !== 'object') &&
|
309 | (expected === null || typeof expected !== 'object')) {
|
310 | return strict ? actual === expected : actual == expected;
|
311 |
|
312 |
|
313 |
|
314 |
|
315 |
|
316 |
|
317 |
|
318 | } else if (isView(actual) && isView(expected) &&
|
319 | pToString(actual) === pToString(expected) &&
|
320 | !(actual instanceof Float32Array ||
|
321 | actual instanceof Float64Array)) {
|
322 | return compare(new Uint8Array(actual.buffer),
|
323 | new Uint8Array(expected.buffer)) === 0;
|
324 |
|
325 |
|
326 |
|
327 |
|
328 |
|
329 |
|
330 |
|
331 | } else if (isBuffer(actual) !== isBuffer(expected)) {
|
332 | return false;
|
333 | } else {
|
334 | memos = memos || {actual: [], expected: []};
|
335 |
|
336 | var actualIndex = memos.actual.indexOf(actual);
|
337 | if (actualIndex !== -1) {
|
338 | if (actualIndex === memos.expected.indexOf(expected)) {
|
339 | return true;
|
340 | }
|
341 | }
|
342 |
|
343 | memos.actual.push(actual);
|
344 | memos.expected.push(expected);
|
345 |
|
346 | return objEquiv(actual, expected, strict, memos);
|
347 | }
|
348 | }
|
349 |
|
350 | function isArguments(object) {
|
351 | return Object.prototype.toString.call(object) == '[object Arguments]';
|
352 | }
|
353 |
|
354 | function objEquiv(a, b, strict, actualVisitedObjects) {
|
355 | if (a === null || a === undefined || b === null || b === undefined)
|
356 | return false;
|
357 |
|
358 | if (util.isPrimitive(a) || util.isPrimitive(b))
|
359 | return a === b;
|
360 | if (strict && Object.getPrototypeOf(a) !== Object.getPrototypeOf(b))
|
361 | return false;
|
362 | var aIsArgs = isArguments(a);
|
363 | var bIsArgs = isArguments(b);
|
364 | if ((aIsArgs && !bIsArgs) || (!aIsArgs && bIsArgs))
|
365 | return false;
|
366 | if (aIsArgs) {
|
367 | a = pSlice.call(a);
|
368 | b = pSlice.call(b);
|
369 | return _deepEqual(a, b, strict);
|
370 | }
|
371 | var ka = objectKeys(a);
|
372 | var kb = objectKeys(b);
|
373 | var key, i;
|
374 |
|
375 |
|
376 | if (ka.length !== kb.length)
|
377 | return false;
|
378 |
|
379 | ka.sort();
|
380 | kb.sort();
|
381 |
|
382 | for (i = ka.length - 1; i >= 0; i--) {
|
383 | if (ka[i] !== kb[i])
|
384 | return false;
|
385 | }
|
386 |
|
387 |
|
388 | for (i = ka.length - 1; i >= 0; i--) {
|
389 | key = ka[i];
|
390 | if (!_deepEqual(a[key], b[key], strict, actualVisitedObjects))
|
391 | return false;
|
392 | }
|
393 | return true;
|
394 | }
|
395 |
|
396 |
|
397 |
|
398 |
|
399 | assert.notDeepEqual = function notDeepEqual(actual, expected, message) {
|
400 | if (_deepEqual(actual, expected, false)) {
|
401 | fail(actual, expected, message, 'notDeepEqual', assert.notDeepEqual);
|
402 | }
|
403 | };
|
404 |
|
405 | assert.notDeepStrictEqual = notDeepStrictEqual;
|
406 | function notDeepStrictEqual(actual, expected, message) {
|
407 | if (_deepEqual(actual, expected, true)) {
|
408 | fail(actual, expected, message, 'notDeepStrictEqual', notDeepStrictEqual);
|
409 | }
|
410 | }
|
411 |
|
412 |
|
413 |
|
414 |
|
415 |
|
416 | assert.strictEqual = function strictEqual(actual, expected, message) {
|
417 | if (actual !== expected) {
|
418 | fail(actual, expected, message, '===', assert.strictEqual);
|
419 | }
|
420 | };
|
421 |
|
422 |
|
423 |
|
424 |
|
425 | assert.notStrictEqual = function notStrictEqual(actual, expected, message) {
|
426 | if (actual === expected) {
|
427 | fail(actual, expected, message, '!==', assert.notStrictEqual);
|
428 | }
|
429 | };
|
430 |
|
431 | function expectedException(actual, expected) {
|
432 | if (!actual || !expected) {
|
433 | return false;
|
434 | }
|
435 |
|
436 | if (Object.prototype.toString.call(expected) == '[object RegExp]') {
|
437 | return expected.test(actual);
|
438 | }
|
439 |
|
440 | try {
|
441 | if (actual instanceof expected) {
|
442 | return true;
|
443 | }
|
444 | } catch (e) {
|
445 |
|
446 | }
|
447 |
|
448 | if (Error.isPrototypeOf(expected)) {
|
449 | return false;
|
450 | }
|
451 |
|
452 | return expected.call({}, actual) === true;
|
453 | }
|
454 |
|
455 | function _tryBlock(block) {
|
456 | var error;
|
457 | try {
|
458 | block();
|
459 | } catch (e) {
|
460 | error = e;
|
461 | }
|
462 | return error;
|
463 | }
|
464 |
|
465 | function _throws(shouldThrow, block, expected, message) {
|
466 | var actual;
|
467 |
|
468 | if (typeof block !== 'function') {
|
469 | throw new TypeError('"block" argument must be a function');
|
470 | }
|
471 |
|
472 | if (typeof expected === 'string') {
|
473 | message = expected;
|
474 | expected = null;
|
475 | }
|
476 |
|
477 | actual = _tryBlock(block);
|
478 |
|
479 | message = (expected && expected.name ? ' (' + expected.name + ').' : '.') +
|
480 | (message ? ' ' + message : '.');
|
481 |
|
482 | if (shouldThrow && !actual) {
|
483 | fail(actual, expected, 'Missing expected exception' + message);
|
484 | }
|
485 |
|
486 | var userProvidedMessage = typeof message === 'string';
|
487 | var isUnwantedException = !shouldThrow && util.isError(actual);
|
488 | var isUnexpectedException = !shouldThrow && actual && !expected;
|
489 |
|
490 | if ((isUnwantedException &&
|
491 | userProvidedMessage &&
|
492 | expectedException(actual, expected)) ||
|
493 | isUnexpectedException) {
|
494 | fail(actual, expected, 'Got unwanted exception' + message);
|
495 | }
|
496 |
|
497 | if ((shouldThrow && actual && expected &&
|
498 | !expectedException(actual, expected)) || (!shouldThrow && actual)) {
|
499 | throw actual;
|
500 | }
|
501 | }
|
502 |
|
503 |
|
504 |
|
505 |
|
506 | assert.throws = function(block, /*optional*/error, /*optional*/message) {
|
507 | _throws(true, block, error, message);
|
508 | };
|
509 |
|
510 |
|
511 | assert.doesNotThrow = function(block, /*optional*/error, /*optional*/message) {
|
512 | _throws(false, block, error, message);
|
513 | };
|
514 |
|
515 | assert.ifError = function(err) { if (err) throw err; };
|
516 |
|
517 |
|
518 | function strict(value, message) {
|
519 | if (!value) fail(value, true, message, '==', strict);
|
520 | }
|
521 | assert.strict = objectAssign(strict, assert, {
|
522 | equal: assert.strictEqual,
|
523 | deepEqual: assert.deepStrictEqual,
|
524 | notEqual: assert.notStrictEqual,
|
525 | notDeepEqual: assert.notDeepStrictEqual
|
526 | });
|
527 | assert.strict.strict = assert.strict;
|
528 |
|
529 | var objectKeys = Object.keys || function (obj) {
|
530 | var keys = [];
|
531 | for (var key in obj) {
|
532 | if (hasOwn.call(obj, key)) keys.push(key);
|
533 | }
|
534 | return keys;
|
535 | };
|
536 |
|
537 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
538 | },{"5":5,"68":68}],3:[function(_dereq_,module,exports){
|
539 | if (typeof Object.create === 'function') {
|
540 |
|
541 | module.exports = function inherits(ctor, superCtor) {
|
542 | ctor.super_ = superCtor
|
543 | ctor.prototype = Object.create(superCtor.prototype, {
|
544 | constructor: {
|
545 | value: ctor,
|
546 | enumerable: false,
|
547 | writable: true,
|
548 | configurable: true
|
549 | }
|
550 | });
|
551 | };
|
552 | } else {
|
553 |
|
554 | module.exports = function inherits(ctor, superCtor) {
|
555 | ctor.super_ = superCtor
|
556 | var TempCtor = function () {}
|
557 | TempCtor.prototype = superCtor.prototype
|
558 | ctor.prototype = new TempCtor()
|
559 | ctor.prototype.constructor = ctor
|
560 | }
|
561 | }
|
562 |
|
563 | },{}],4:[function(_dereq_,module,exports){
|
564 | module.exports = function isBuffer(arg) {
|
565 | return arg && typeof arg === 'object'
|
566 | && typeof arg.copy === 'function'
|
567 | && typeof arg.fill === 'function'
|
568 | && typeof arg.readUInt8 === 'function';
|
569 | }
|
570 | },{}],5:[function(_dereq_,module,exports){
|
571 | (function (process,global){
|
572 |
|
573 |
|
574 |
|
575 |
|
576 |
|
577 |
|
578 |
|
579 |
|
580 |
|
581 |
|
582 |
|
583 |
|
584 |
|
585 |
|
586 |
|
587 |
|
588 |
|
589 |
|
590 |
|
591 |
|
592 |
|
593 | var formatRegExp = /%[sdj%]/g;
|
594 | exports.format = function(f) {
|
595 | if (!isString(f)) {
|
596 | var objects = [];
|
597 | for (var i = 0; i < arguments.length; i++) {
|
598 | objects.push(inspect(arguments[i]));
|
599 | }
|
600 | return objects.join(' ');
|
601 | }
|
602 |
|
603 | var i = 1;
|
604 | var args = arguments;
|
605 | var len = args.length;
|
606 | var str = String(f).replace(formatRegExp, function(x) {
|
607 | if (x === '%%') return '%';
|
608 | if (i >= len) return x;
|
609 | switch (x) {
|
610 | case '%s': return String(args[i++]);
|
611 | case '%d': return Number(args[i++]);
|
612 | case '%j':
|
613 | try {
|
614 | return JSON.stringify(args[i++]);
|
615 | } catch (_) {
|
616 | return '[Circular]';
|
617 | }
|
618 | default:
|
619 | return x;
|
620 | }
|
621 | });
|
622 | for (var x = args[i]; i < len; x = args[++i]) {
|
623 | if (isNull(x) || !isObject(x)) {
|
624 | str += ' ' + x;
|
625 | } else {
|
626 | str += ' ' + inspect(x);
|
627 | }
|
628 | }
|
629 | return str;
|
630 | };
|
631 |
|
632 |
|
633 |
|
634 |
|
635 |
|
636 | exports.deprecate = function(fn, msg) {
|
637 |
|
638 | if (isUndefined(global.process)) {
|
639 | return function() {
|
640 | return exports.deprecate(fn, msg).apply(this, arguments);
|
641 | };
|
642 | }
|
643 |
|
644 | if (process.noDeprecation === true) {
|
645 | return fn;
|
646 | }
|
647 |
|
648 | var warned = false;
|
649 | function deprecated() {
|
650 | if (!warned) {
|
651 | if (process.throwDeprecation) {
|
652 | throw new Error(msg);
|
653 | } else if (process.traceDeprecation) {
|
654 | console.trace(msg);
|
655 | } else {
|
656 | console.error(msg);
|
657 | }
|
658 | warned = true;
|
659 | }
|
660 | return fn.apply(this, arguments);
|
661 | }
|
662 |
|
663 | return deprecated;
|
664 | };
|
665 |
|
666 |
|
667 | var debugs = {};
|
668 | var debugEnviron;
|
669 | exports.debuglog = function(set) {
|
670 | if (isUndefined(debugEnviron))
|
671 | debugEnviron = process.env.NODE_DEBUG || '';
|
672 | set = set.toUpperCase();
|
673 | if (!debugs[set]) {
|
674 | if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
|
675 | var pid = process.pid;
|
676 | debugs[set] = function() {
|
677 | var msg = exports.format.apply(exports, arguments);
|
678 | console.error('%s %d: %s', set, pid, msg);
|
679 | };
|
680 | } else {
|
681 | debugs[set] = function() {};
|
682 | }
|
683 | }
|
684 | return debugs[set];
|
685 | };
|
686 |
|
687 |
|
688 | /**
|
689 | * Echos the value of a value. Trys to print the value out
|
690 | * in the best way possible given the different types.
|
691 | *
|
692 | * @param {Object} obj The object to print out.
|
693 | * @param {Object} opts Optional options object that alters the output.
|
694 | */
|
695 |
|
696 | function inspect(obj, opts) {
|
697 |
|
698 | var ctx = {
|
699 | seen: [],
|
700 | stylize: stylizeNoColor
|
701 | };
|
702 |
|
703 | if (arguments.length >= 3) ctx.depth = arguments[2];
|
704 | if (arguments.length >= 4) ctx.colors = arguments[3];
|
705 | if (isBoolean(opts)) {
|
706 |
|
707 | ctx.showHidden = opts;
|
708 | } else if (opts) {
|
709 |
|
710 | exports._extend(ctx, opts);
|
711 | }
|
712 |
|
713 | if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
|
714 | if (isUndefined(ctx.depth)) ctx.depth = 2;
|
715 | if (isUndefined(ctx.colors)) ctx.colors = false;
|
716 | if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
|
717 | if (ctx.colors) ctx.stylize = stylizeWithColor;
|
718 | return formatValue(ctx, obj, ctx.depth);
|
719 | }
|
720 | exports.inspect = inspect;
|
721 |
|
722 |
|
723 |
|
724 | inspect.colors = {
|
725 | 'bold' : [1, 22],
|
726 | 'italic' : [3, 23],
|
727 | 'underline' : [4, 24],
|
728 | 'inverse' : [7, 27],
|
729 | 'white' : [37, 39],
|
730 | 'grey' : [90, 39],
|
731 | 'black' : [30, 39],
|
732 | 'blue' : [34, 39],
|
733 | 'cyan' : [36, 39],
|
734 | 'green' : [32, 39],
|
735 | 'magenta' : [35, 39],
|
736 | 'red' : [31, 39],
|
737 | 'yellow' : [33, 39]
|
738 | };
|
739 |
|
740 |
|
741 | inspect.styles = {
|
742 | 'special': 'cyan',
|
743 | 'number': 'yellow',
|
744 | 'boolean': 'yellow',
|
745 | 'undefined': 'grey',
|
746 | 'null': 'bold',
|
747 | 'string': 'green',
|
748 | 'date': 'magenta',
|
749 |
|
750 | 'regexp': 'red'
|
751 | };
|
752 |
|
753 |
|
754 | function stylizeWithColor(str, styleType) {
|
755 | var style = inspect.styles[styleType];
|
756 |
|
757 | if (style) {
|
758 | return '\u001b[' + inspect.colors[style][0] + 'm' + str +
|
759 | '\u001b[' + inspect.colors[style][1] + 'm';
|
760 | } else {
|
761 | return str;
|
762 | }
|
763 | }
|
764 |
|
765 |
|
766 | function stylizeNoColor(str, styleType) {
|
767 | return str;
|
768 | }
|
769 |
|
770 |
|
771 | function arrayToHash(array) {
|
772 | var hash = {};
|
773 |
|
774 | array.forEach(function(val, idx) {
|
775 | hash[val] = true;
|
776 | });
|
777 |
|
778 | return hash;
|
779 | }
|
780 |
|
781 |
|
782 | function formatValue(ctx, value, recurseTimes) {
|
783 |
|
784 |
|
785 | if (ctx.customInspect &&
|
786 | value &&
|
787 | isFunction(value.inspect) &&
|
788 |
|
789 | value.inspect !== exports.inspect &&
|
790 |
|
791 | !(value.constructor && value.constructor.prototype === value)) {
|
792 | var ret = value.inspect(recurseTimes, ctx);
|
793 | if (!isString(ret)) {
|
794 | ret = formatValue(ctx, ret, recurseTimes);
|
795 | }
|
796 | return ret;
|
797 | }
|
798 |
|
799 |
|
800 | var primitive = formatPrimitive(ctx, value);
|
801 | if (primitive) {
|
802 | return primitive;
|
803 | }
|
804 |
|
805 |
|
806 | var keys = Object.keys(value);
|
807 | var visibleKeys = arrayToHash(keys);
|
808 |
|
809 | if (ctx.showHidden) {
|
810 | keys = Object.getOwnPropertyNames(value);
|
811 | }
|
812 |
|
813 |
|
814 |
|
815 | if (isError(value)
|
816 | && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
|
817 | return formatError(value);
|
818 | }
|
819 |
|
820 |
|
821 | if (keys.length === 0) {
|
822 | if (isFunction(value)) {
|
823 | var name = value.name ? ': ' + value.name : '';
|
824 | return ctx.stylize('[Function' + name + ']', 'special');
|
825 | }
|
826 | if (isRegExp(value)) {
|
827 | return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
|
828 | }
|
829 | if (isDate(value)) {
|
830 | return ctx.stylize(Date.prototype.toString.call(value), 'date');
|
831 | }
|
832 | if (isError(value)) {
|
833 | return formatError(value);
|
834 | }
|
835 | }
|
836 |
|
837 | var base = '', array = false, braces = ['{', '}'];
|
838 |
|
839 |
|
840 | if (isArray(value)) {
|
841 | array = true;
|
842 | braces = ['[', ']'];
|
843 | }
|
844 |
|
845 |
|
846 | if (isFunction(value)) {
|
847 | var n = value.name ? ': ' + value.name : '';
|
848 | base = ' [Function' + n + ']';
|
849 | }
|
850 |
|
851 |
|
852 | if (isRegExp(value)) {
|
853 | base = ' ' + RegExp.prototype.toString.call(value);
|
854 | }
|
855 |
|
856 |
|
857 | if (isDate(value)) {
|
858 | base = ' ' + Date.prototype.toUTCString.call(value);
|
859 | }
|
860 |
|
861 |
|
862 | if (isError(value)) {
|
863 | base = ' ' + formatError(value);
|
864 | }
|
865 |
|
866 | if (keys.length === 0 && (!array || value.length == 0)) {
|
867 | return braces[0] + base + braces[1];
|
868 | }
|
869 |
|
870 | if (recurseTimes < 0) {
|
871 | if (isRegExp(value)) {
|
872 | return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
|
873 | } else {
|
874 | return ctx.stylize('[Object]', 'special');
|
875 | }
|
876 | }
|
877 |
|
878 | ctx.seen.push(value);
|
879 |
|
880 | var output;
|
881 | if (array) {
|
882 | output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
|
883 | } else {
|
884 | output = keys.map(function(key) {
|
885 | return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
|
886 | });
|
887 | }
|
888 |
|
889 | ctx.seen.pop();
|
890 |
|
891 | return reduceToSingleString(output, base, braces);
|
892 | }
|
893 |
|
894 |
|
895 | function formatPrimitive(ctx, value) {
|
896 | if (isUndefined(value))
|
897 | return ctx.stylize('undefined', 'undefined');
|
898 | if (isString(value)) {
|
899 | var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
|
900 | .replace(/'/g, "\\'")
|
901 | .replace(/\\"/g, '"') + '\'';
|
902 | return ctx.stylize(simple, 'string');
|
903 | }
|
904 | if (isNumber(value))
|
905 | return ctx.stylize('' + value, 'number');
|
906 | if (isBoolean(value))
|
907 | return ctx.stylize('' + value, 'boolean');
|
908 |
|
909 | if (isNull(value))
|
910 | return ctx.stylize('null', 'null');
|
911 | }
|
912 |
|
913 |
|
914 | function formatError(value) {
|
915 | return '[' + Error.prototype.toString.call(value) + ']';
|
916 | }
|
917 |
|
918 |
|
919 | function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
|
920 | var output = [];
|
921 | for (var i = 0, l = value.length; i < l; ++i) {
|
922 | if (hasOwnProperty(value, String(i))) {
|
923 | output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
|
924 | String(i), true));
|
925 | } else {
|
926 | output.push('');
|
927 | }
|
928 | }
|
929 | keys.forEach(function(key) {
|
930 | if (!key.match(/^\d+$/)) {
|
931 | output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
|
932 | key, true));
|
933 | }
|
934 | });
|
935 | return output;
|
936 | }
|
937 |
|
938 |
|
939 | function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
|
940 | var name, str, desc;
|
941 | desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
|
942 | if (desc.get) {
|
943 | if (desc.set) {
|
944 | str = ctx.stylize('[Getter/Setter]', 'special');
|
945 | } else {
|
946 | str = ctx.stylize('[Getter]', 'special');
|
947 | }
|
948 | } else {
|
949 | if (desc.set) {
|
950 | str = ctx.stylize('[Setter]', 'special');
|
951 | }
|
952 | }
|
953 | if (!hasOwnProperty(visibleKeys, key)) {
|
954 | name = '[' + key + ']';
|
955 | }
|
956 | if (!str) {
|
957 | if (ctx.seen.indexOf(desc.value) < 0) {
|
958 | if (isNull(recurseTimes)) {
|
959 | str = formatValue(ctx, desc.value, null);
|
960 | } else {
|
961 | str = formatValue(ctx, desc.value, recurseTimes - 1);
|
962 | }
|
963 | if (str.indexOf('\n') > -1) {
|
964 | if (array) {
|
965 | str = str.split('\n').map(function(line) {
|
966 | return ' ' + line;
|
967 | }).join('\n').substr(2);
|
968 | } else {
|
969 | str = '\n' + str.split('\n').map(function(line) {
|
970 | return ' ' + line;
|
971 | }).join('\n');
|
972 | }
|
973 | }
|
974 | } else {
|
975 | str = ctx.stylize('[Circular]', 'special');
|
976 | }
|
977 | }
|
978 | if (isUndefined(name)) {
|
979 | if (array && key.match(/^\d+$/)) {
|
980 | return str;
|
981 | }
|
982 | name = JSON.stringify('' + key);
|
983 | if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
|
984 | name = name.substr(1, name.length - 2);
|
985 | name = ctx.stylize(name, 'name');
|
986 | } else {
|
987 | name = name.replace(/'/g, "\\'")
|
988 | .replace(/\\"/g, '"')
|
989 | .replace(/(^"|"$)/g, "'");
|
990 | name = ctx.stylize(name, 'string');
|
991 | }
|
992 | }
|
993 |
|
994 | return name + ': ' + str;
|
995 | }
|
996 |
|
997 |
|
998 | function reduceToSingleString(output, base, braces) {
|
999 | var numLinesEst = 0;
|
1000 | var length = output.reduce(function(prev, cur) {
|
1001 | numLinesEst++;
|
1002 | if (cur.indexOf('\n') >= 0) numLinesEst++;
|
1003 | return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
|
1004 | }, 0);
|
1005 |
|
1006 | if (length > 60) {
|
1007 | return braces[0] +
|
1008 | (base === '' ? '' : base + '\n ') +
|
1009 | ' ' +
|
1010 | output.join(',\n ') +
|
1011 | ' ' +
|
1012 | braces[1];
|
1013 | }
|
1014 |
|
1015 | return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
|
1016 | }
|
1017 |
|
1018 |
|
1019 |
|
1020 |
|
1021 | function isArray(ar) {
|
1022 | return Array.isArray(ar);
|
1023 | }
|
1024 | exports.isArray = isArray;
|
1025 |
|
1026 | function isBoolean(arg) {
|
1027 | return typeof arg === 'boolean';
|
1028 | }
|
1029 | exports.isBoolean = isBoolean;
|
1030 |
|
1031 | function isNull(arg) {
|
1032 | return arg === null;
|
1033 | }
|
1034 | exports.isNull = isNull;
|
1035 |
|
1036 | function isNullOrUndefined(arg) {
|
1037 | return arg == null;
|
1038 | }
|
1039 | exports.isNullOrUndefined = isNullOrUndefined;
|
1040 |
|
1041 | function isNumber(arg) {
|
1042 | return typeof arg === 'number';
|
1043 | }
|
1044 | exports.isNumber = isNumber;
|
1045 |
|
1046 | function isString(arg) {
|
1047 | return typeof arg === 'string';
|
1048 | }
|
1049 | exports.isString = isString;
|
1050 |
|
1051 | function isSymbol(arg) {
|
1052 | return typeof arg === 'symbol';
|
1053 | }
|
1054 | exports.isSymbol = isSymbol;
|
1055 |
|
1056 | function isUndefined(arg) {
|
1057 | return arg === void 0;
|
1058 | }
|
1059 | exports.isUndefined = isUndefined;
|
1060 |
|
1061 | function isRegExp(re) {
|
1062 | return isObject(re) && objectToString(re) === '[object RegExp]';
|
1063 | }
|
1064 | exports.isRegExp = isRegExp;
|
1065 |
|
1066 | function isObject(arg) {
|
1067 | return typeof arg === 'object' && arg !== null;
|
1068 | }
|
1069 | exports.isObject = isObject;
|
1070 |
|
1071 | function isDate(d) {
|
1072 | return isObject(d) && objectToString(d) === '[object Date]';
|
1073 | }
|
1074 | exports.isDate = isDate;
|
1075 |
|
1076 | function isError(e) {
|
1077 | return isObject(e) &&
|
1078 | (objectToString(e) === '[object Error]' || e instanceof Error);
|
1079 | }
|
1080 | exports.isError = isError;
|
1081 |
|
1082 | function isFunction(arg) {
|
1083 | return typeof arg === 'function';
|
1084 | }
|
1085 | exports.isFunction = isFunction;
|
1086 |
|
1087 | function isPrimitive(arg) {
|
1088 | return arg === null ||
|
1089 | typeof arg === 'boolean' ||
|
1090 | typeof arg === 'number' ||
|
1091 | typeof arg === 'string' ||
|
1092 | typeof arg === 'symbol' ||
|
1093 | typeof arg === 'undefined';
|
1094 | }
|
1095 | exports.isPrimitive = isPrimitive;
|
1096 |
|
1097 | exports.isBuffer = _dereq_(4);
|
1098 |
|
1099 | function objectToString(o) {
|
1100 | return Object.prototype.toString.call(o);
|
1101 | }
|
1102 |
|
1103 |
|
1104 | function pad(n) {
|
1105 | return n < 10 ? '0' + n.toString(10) : n.toString(10);
|
1106 | }
|
1107 |
|
1108 |
|
1109 | var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
|
1110 | 'Oct', 'Nov', 'Dec'];
|
1111 |
|
1112 |
|
1113 | function timestamp() {
|
1114 | var d = new Date();
|
1115 | var time = [pad(d.getHours()),
|
1116 | pad(d.getMinutes()),
|
1117 | pad(d.getSeconds())].join(':');
|
1118 | return [d.getDate(), months[d.getMonth()], time].join(' ');
|
1119 | }
|
1120 |
|
1121 |
|
1122 |
|
1123 | exports.log = function() {
|
1124 | console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments));
|
1125 | };
|
1126 |
|
1127 |
|
1128 |
|
1129 |
|
1130 |
|
1131 |
|
1132 |
|
1133 |
|
1134 |
|
1135 |
|
1136 |
|
1137 |
|
1138 |
|
1139 |
|
1140 |
|
1141 | exports.inherits = _dereq_(3);
|
1142 |
|
1143 | exports._extend = function(origin, add) {
|
1144 |
|
1145 | if (!add || !isObject(add)) return origin;
|
1146 |
|
1147 | var keys = Object.keys(add);
|
1148 | var i = keys.length;
|
1149 | while (i--) {
|
1150 | origin[keys[i]] = add[keys[i]];
|
1151 | }
|
1152 | return origin;
|
1153 | };
|
1154 |
|
1155 | function hasOwnProperty(obj, prop) {
|
1156 | return Object.prototype.hasOwnProperty.call(obj, prop);
|
1157 | }
|
1158 |
|
1159 | }).call(this,_dereq_(70),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
1160 | },{"3":3,"4":4,"70":70}],6:[function(_dereq_,module,exports){
|
1161 | 'use strict'
|
1162 |
|
1163 | exports.byteLength = byteLength
|
1164 | exports.toByteArray = toByteArray
|
1165 | exports.fromByteArray = fromByteArray
|
1166 |
|
1167 | var lookup = []
|
1168 | var revLookup = []
|
1169 | var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array
|
1170 |
|
1171 | var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
|
1172 | for (var i = 0, len = code.length; i < len; ++i) {
|
1173 | lookup[i] = code[i]
|
1174 | revLookup[code.charCodeAt(i)] = i
|
1175 | }
|
1176 |
|
1177 |
|
1178 |
|
1179 | revLookup['-'.charCodeAt(0)] = 62
|
1180 | revLookup['_'.charCodeAt(0)] = 63
|
1181 |
|
1182 | function getLens (b64) {
|
1183 | var len = b64.length
|
1184 |
|
1185 | if (len % 4 > 0) {
|
1186 | throw new Error('Invalid string. Length must be a multiple of 4')
|
1187 | }
|
1188 |
|
1189 |
|
1190 |
|
1191 | var validLen = b64.indexOf('=')
|
1192 | if (validLen === -1) validLen = len
|
1193 |
|
1194 | var placeHoldersLen = validLen === len
|
1195 | ? 0
|
1196 | : 4 - (validLen % 4)
|
1197 |
|
1198 | return [validLen, placeHoldersLen]
|
1199 | }
|
1200 |
|
1201 |
|
1202 | function byteLength (b64) {
|
1203 | var lens = getLens(b64)
|
1204 | var validLen = lens[0]
|
1205 | var placeHoldersLen = lens[1]
|
1206 | return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
|
1207 | }
|
1208 |
|
1209 | function _byteLength (b64, validLen, placeHoldersLen) {
|
1210 | return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
|
1211 | }
|
1212 |
|
1213 | function toByteArray (b64) {
|
1214 | var tmp
|
1215 | var lens = getLens(b64)
|
1216 | var validLen = lens[0]
|
1217 | var placeHoldersLen = lens[1]
|
1218 |
|
1219 | var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen))
|
1220 |
|
1221 | var curByte = 0
|
1222 |
|
1223 |
|
1224 | var len = placeHoldersLen > 0
|
1225 | ? validLen - 4
|
1226 | : validLen
|
1227 |
|
1228 | var i
|
1229 | for (i = 0; i < len; i += 4) {
|
1230 | tmp =
|
1231 | (revLookup[b64.charCodeAt(i)] << 18) |
|
1232 | (revLookup[b64.charCodeAt(i + 1)] << 12) |
|
1233 | (revLookup[b64.charCodeAt(i + 2)] << 6) |
|
1234 | revLookup[b64.charCodeAt(i + 3)]
|
1235 | arr[curByte++] = (tmp >> 16) & 0xFF
|
1236 | arr[curByte++] = (tmp >> 8) & 0xFF
|
1237 | arr[curByte++] = tmp & 0xFF
|
1238 | }
|
1239 |
|
1240 | if (placeHoldersLen === 2) {
|
1241 | tmp =
|
1242 | (revLookup[b64.charCodeAt(i)] << 2) |
|
1243 | (revLookup[b64.charCodeAt(i + 1)] >> 4)
|
1244 | arr[curByte++] = tmp & 0xFF
|
1245 | }
|
1246 |
|
1247 | if (placeHoldersLen === 1) {
|
1248 | tmp =
|
1249 | (revLookup[b64.charCodeAt(i)] << 10) |
|
1250 | (revLookup[b64.charCodeAt(i + 1)] << 4) |
|
1251 | (revLookup[b64.charCodeAt(i + 2)] >> 2)
|
1252 | arr[curByte++] = (tmp >> 8) & 0xFF
|
1253 | arr[curByte++] = tmp & 0xFF
|
1254 | }
|
1255 |
|
1256 | return arr
|
1257 | }
|
1258 |
|
1259 | function tripletToBase64 (num) {
|
1260 | return lookup[num >> 18 & 0x3F] +
|
1261 | lookup[num >> 12 & 0x3F] +
|
1262 | lookup[num >> 6 & 0x3F] +
|
1263 | lookup[num & 0x3F]
|
1264 | }
|
1265 |
|
1266 | function encodeChunk (uint8, start, end) {
|
1267 | var tmp
|
1268 | var output = []
|
1269 | for (var i = start; i < end; i += 3) {
|
1270 | tmp =
|
1271 | ((uint8[i] << 16) & 0xFF0000) +
|
1272 | ((uint8[i + 1] << 8) & 0xFF00) +
|
1273 | (uint8[i + 2] & 0xFF)
|
1274 | output.push(tripletToBase64(tmp))
|
1275 | }
|
1276 | return output.join('')
|
1277 | }
|
1278 |
|
1279 | function fromByteArray (uint8) {
|
1280 | var tmp
|
1281 | var len = uint8.length
|
1282 | var extraBytes = len % 3
|
1283 | var parts = []
|
1284 | var maxChunkLength = 16383
|
1285 |
|
1286 |
|
1287 | for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
|
1288 | parts.push(encodeChunk(
|
1289 | uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)
|
1290 | ))
|
1291 | }
|
1292 |
|
1293 |
|
1294 | if (extraBytes === 1) {
|
1295 | tmp = uint8[len - 1]
|
1296 | parts.push(
|
1297 | lookup[tmp >> 2] +
|
1298 | lookup[(tmp << 4) & 0x3F] +
|
1299 | '=='
|
1300 | )
|
1301 | } else if (extraBytes === 2) {
|
1302 | tmp = (uint8[len - 2] << 8) + uint8[len - 1]
|
1303 | parts.push(
|
1304 | lookup[tmp >> 10] +
|
1305 | lookup[(tmp >> 4) & 0x3F] +
|
1306 | lookup[(tmp << 2) & 0x3F] +
|
1307 | '='
|
1308 | )
|
1309 | }
|
1310 |
|
1311 | return parts.join('')
|
1312 | }
|
1313 |
|
1314 | },{}],7:[function(_dereq_,module,exports){
|
1315 |
|
1316 | },{}],8:[function(_dereq_,module,exports){
|
1317 | (function (Buffer){
|
1318 | var toString = Object.prototype.toString
|
1319 |
|
1320 | var isModern = (
|
1321 | typeof Buffer.alloc === 'function' &&
|
1322 | typeof Buffer.allocUnsafe === 'function' &&
|
1323 | typeof Buffer.from === 'function'
|
1324 | )
|
1325 |
|
1326 | function isArrayBuffer (input) {
|
1327 | return toString.call(input).slice(8, -1) === 'ArrayBuffer'
|
1328 | }
|
1329 |
|
1330 | function fromArrayBuffer (obj, byteOffset, length) {
|
1331 | byteOffset >>>= 0
|
1332 |
|
1333 | var maxLength = obj.byteLength - byteOffset
|
1334 |
|
1335 | if (maxLength < 0) {
|
1336 | throw new RangeError("'offset' is out of bounds")
|
1337 | }
|
1338 |
|
1339 | if (length === undefined) {
|
1340 | length = maxLength
|
1341 | } else {
|
1342 | length >>>= 0
|
1343 |
|
1344 | if (length > maxLength) {
|
1345 | throw new RangeError("'length' is out of bounds")
|
1346 | }
|
1347 | }
|
1348 |
|
1349 | return isModern
|
1350 | ? Buffer.from(obj.slice(byteOffset, byteOffset + length))
|
1351 | : new Buffer(new Uint8Array(obj.slice(byteOffset, byteOffset + length)))
|
1352 | }
|
1353 |
|
1354 | function fromString (string, encoding) {
|
1355 | if (typeof encoding !== 'string' || encoding === '') {
|
1356 | encoding = 'utf8'
|
1357 | }
|
1358 |
|
1359 | if (!Buffer.isEncoding(encoding)) {
|
1360 | throw new TypeError('"encoding" must be a valid string encoding')
|
1361 | }
|
1362 |
|
1363 | return isModern
|
1364 | ? Buffer.from(string, encoding)
|
1365 | : new Buffer(string, encoding)
|
1366 | }
|
1367 |
|
1368 | function bufferFrom (value, encodingOrOffset, length) {
|
1369 | if (typeof value === 'number') {
|
1370 | throw new TypeError('"value" argument must not be a number')
|
1371 | }
|
1372 |
|
1373 | if (isArrayBuffer(value)) {
|
1374 | return fromArrayBuffer(value, encodingOrOffset, length)
|
1375 | }
|
1376 |
|
1377 | if (typeof value === 'string') {
|
1378 | return fromString(value, encodingOrOffset)
|
1379 | }
|
1380 |
|
1381 | return isModern
|
1382 | ? Buffer.from(value)
|
1383 | : new Buffer(value)
|
1384 | }
|
1385 |
|
1386 | module.exports = bufferFrom
|
1387 |
|
1388 | }).call(this,_dereq_(9).Buffer)
|
1389 | },{"9":9}],9:[function(_dereq_,module,exports){
|
1390 | (function (Buffer){
|
1391 |
|
1392 |
|
1393 |
|
1394 |
|
1395 |
|
1396 |
|
1397 |
|
1398 |
|
1399 | 'use strict'
|
1400 |
|
1401 | var base64 = _dereq_(6)
|
1402 | var ieee754 = _dereq_(16)
|
1403 | var customInspectSymbol =
|
1404 | (typeof Symbol === 'function' && typeof Symbol.for === 'function')
|
1405 | ? Symbol.for('nodejs.util.inspect.custom')
|
1406 | : null
|
1407 |
|
1408 | exports.Buffer = Buffer
|
1409 | exports.SlowBuffer = SlowBuffer
|
1410 | exports.INSPECT_MAX_BYTES = 50
|
1411 |
|
1412 | var K_MAX_LENGTH = 0x7fffffff
|
1413 | exports.kMaxLength = K_MAX_LENGTH
|
1414 |
|
1415 |
|
1416 |
|
1417 |
|
1418 |
|
1419 |
|
1420 |
|
1421 |
|
1422 |
|
1423 |
|
1424 |
|
1425 |
|
1426 |
|
1427 |
|
1428 |
|
1429 | Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport()
|
1430 |
|
1431 | if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' &&
|
1432 | typeof console.error === 'function') {
|
1433 | console.error(
|
1434 | 'This browser lacks typed array (Uint8Array) support which is required by ' +
|
1435 | '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.'
|
1436 | )
|
1437 | }
|
1438 |
|
1439 | function typedArraySupport () {
|
1440 |
|
1441 | try {
|
1442 | var arr = new Uint8Array(1)
|
1443 | var proto = { foo: function () { return 42 } }
|
1444 | Object.setPrototypeOf(proto, Uint8Array.prototype)
|
1445 | Object.setPrototypeOf(arr, proto)
|
1446 | return arr.foo() === 42
|
1447 | } catch (e) {
|
1448 | return false
|
1449 | }
|
1450 | }
|
1451 |
|
1452 | Object.defineProperty(Buffer.prototype, 'parent', {
|
1453 | enumerable: true,
|
1454 | get: function () {
|
1455 | if (!Buffer.isBuffer(this)) return undefined
|
1456 | return this.buffer
|
1457 | }
|
1458 | })
|
1459 |
|
1460 | Object.defineProperty(Buffer.prototype, 'offset', {
|
1461 | enumerable: true,
|
1462 | get: function () {
|
1463 | if (!Buffer.isBuffer(this)) return undefined
|
1464 | return this.byteOffset
|
1465 | }
|
1466 | })
|
1467 |
|
1468 | function createBuffer (length) {
|
1469 | if (length > K_MAX_LENGTH) {
|
1470 | throw new RangeError('The value "' + length + '" is invalid for option "size"')
|
1471 | }
|
1472 |
|
1473 | var buf = new Uint8Array(length)
|
1474 | Object.setPrototypeOf(buf, Buffer.prototype)
|
1475 | return buf
|
1476 | }
|
1477 |
|
1478 |
|
1479 |
|
1480 |
|
1481 |
|
1482 |
|
1483 |
|
1484 |
|
1485 |
|
1486 |
|
1487 |
|
1488 | function Buffer (arg, encodingOrOffset, length) {
|
1489 |
|
1490 | if (typeof arg === 'number') {
|
1491 | if (typeof encodingOrOffset === 'string') {
|
1492 | throw new TypeError(
|
1493 | 'The "string" argument must be of type string. Received type number'
|
1494 | )
|
1495 | }
|
1496 | return allocUnsafe(arg)
|
1497 | }
|
1498 | return from(arg, encodingOrOffset, length)
|
1499 | }
|
1500 |
|
1501 |
|
1502 | if (typeof Symbol !== 'undefined' && Symbol.species != null &&
|
1503 | Buffer[Symbol.species] === Buffer) {
|
1504 | Object.defineProperty(Buffer, Symbol.species, {
|
1505 | value: null,
|
1506 | configurable: true,
|
1507 | enumerable: false,
|
1508 | writable: false
|
1509 | })
|
1510 | }
|
1511 |
|
1512 | Buffer.poolSize = 8192
|
1513 |
|
1514 | function from (value, encodingOrOffset, length) {
|
1515 | if (typeof value === 'string') {
|
1516 | return fromString(value, encodingOrOffset)
|
1517 | }
|
1518 |
|
1519 | if (ArrayBuffer.isView(value)) {
|
1520 | return fromArrayLike(value)
|
1521 | }
|
1522 |
|
1523 | if (value == null) {
|
1524 | throw new TypeError(
|
1525 | 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
|
1526 | 'or Array-like Object. Received type ' + (typeof value)
|
1527 | )
|
1528 | }
|
1529 |
|
1530 | if (isInstance(value, ArrayBuffer) ||
|
1531 | (value && isInstance(value.buffer, ArrayBuffer))) {
|
1532 | return fromArrayBuffer(value, encodingOrOffset, length)
|
1533 | }
|
1534 |
|
1535 | if (typeof value === 'number') {
|
1536 | throw new TypeError(
|
1537 | 'The "value" argument must not be of type number. Received type number'
|
1538 | )
|
1539 | }
|
1540 |
|
1541 | var valueOf = value.valueOf && value.valueOf()
|
1542 | if (valueOf != null && valueOf !== value) {
|
1543 | return Buffer.from(valueOf, encodingOrOffset, length)
|
1544 | }
|
1545 |
|
1546 | var b = fromObject(value)
|
1547 | if (b) return b
|
1548 |
|
1549 | if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null &&
|
1550 | typeof value[Symbol.toPrimitive] === 'function') {
|
1551 | return Buffer.from(
|
1552 | value[Symbol.toPrimitive]('string'), encodingOrOffset, length
|
1553 | )
|
1554 | }
|
1555 |
|
1556 | throw new TypeError(
|
1557 | 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
|
1558 | 'or Array-like Object. Received type ' + (typeof value)
|
1559 | )
|
1560 | }
|
1561 |
|
1562 |
|
1563 |
|
1564 |
|
1565 |
|
1566 |
|
1567 |
|
1568 |
|
1569 |
|
1570 | Buffer.from = function (value, encodingOrOffset, length) {
|
1571 | return from(value, encodingOrOffset, length)
|
1572 | }
|
1573 |
|
1574 |
|
1575 |
|
1576 | Object.setPrototypeOf(Buffer.prototype, Uint8Array.prototype)
|
1577 | Object.setPrototypeOf(Buffer, Uint8Array)
|
1578 |
|
1579 | function assertSize (size) {
|
1580 | if (typeof size !== 'number') {
|
1581 | throw new TypeError('"size" argument must be of type number')
|
1582 | } else if (size < 0) {
|
1583 | throw new RangeError('The value "' + size + '" is invalid for option "size"')
|
1584 | }
|
1585 | }
|
1586 |
|
1587 | function alloc (size, fill, encoding) {
|
1588 | assertSize(size)
|
1589 | if (size <= 0) {
|
1590 | return createBuffer(size)
|
1591 | }
|
1592 | if (fill !== undefined) {
|
1593 |
|
1594 |
|
1595 |
|
1596 | return typeof encoding === 'string'
|
1597 | ? createBuffer(size).fill(fill, encoding)
|
1598 | : createBuffer(size).fill(fill)
|
1599 | }
|
1600 | return createBuffer(size)
|
1601 | }
|
1602 |
|
1603 |
|
1604 |
|
1605 |
|
1606 |
|
1607 | Buffer.alloc = function (size, fill, encoding) {
|
1608 | return alloc(size, fill, encoding)
|
1609 | }
|
1610 |
|
1611 | function allocUnsafe (size) {
|
1612 | assertSize(size)
|
1613 | return createBuffer(size < 0 ? 0 : checked(size) | 0)
|
1614 | }
|
1615 |
|
1616 |
|
1617 |
|
1618 |
|
1619 | Buffer.allocUnsafe = function (size) {
|
1620 | return allocUnsafe(size)
|
1621 | }
|
1622 |
|
1623 |
|
1624 |
|
1625 | Buffer.allocUnsafeSlow = function (size) {
|
1626 | return allocUnsafe(size)
|
1627 | }
|
1628 |
|
1629 | function fromString (string, encoding) {
|
1630 | if (typeof encoding !== 'string' || encoding === '') {
|
1631 | encoding = 'utf8'
|
1632 | }
|
1633 |
|
1634 | if (!Buffer.isEncoding(encoding)) {
|
1635 | throw new TypeError('Unknown encoding: ' + encoding)
|
1636 | }
|
1637 |
|
1638 | var length = byteLength(string, encoding) | 0
|
1639 | var buf = createBuffer(length)
|
1640 |
|
1641 | var actual = buf.write(string, encoding)
|
1642 |
|
1643 | if (actual !== length) {
|
1644 |
|
1645 |
|
1646 |
|
1647 | buf = buf.slice(0, actual)
|
1648 | }
|
1649 |
|
1650 | return buf
|
1651 | }
|
1652 |
|
1653 | function fromArrayLike (array) {
|
1654 | var length = array.length < 0 ? 0 : checked(array.length) | 0
|
1655 | var buf = createBuffer(length)
|
1656 | for (var i = 0; i < length; i += 1) {
|
1657 | buf[i] = array[i] & 255
|
1658 | }
|
1659 | return buf
|
1660 | }
|
1661 |
|
1662 | function fromArrayBuffer (array, byteOffset, length) {
|
1663 | if (byteOffset < 0 || array.byteLength < byteOffset) {
|
1664 | throw new RangeError('"offset" is outside of buffer bounds')
|
1665 | }
|
1666 |
|
1667 | if (array.byteLength < byteOffset + (length || 0)) {
|
1668 | throw new RangeError('"length" is outside of buffer bounds')
|
1669 | }
|
1670 |
|
1671 | var buf
|
1672 | if (byteOffset === undefined && length === undefined) {
|
1673 | buf = new Uint8Array(array)
|
1674 | } else if (length === undefined) {
|
1675 | buf = new Uint8Array(array, byteOffset)
|
1676 | } else {
|
1677 | buf = new Uint8Array(array, byteOffset, length)
|
1678 | }
|
1679 |
|
1680 |
|
1681 | Object.setPrototypeOf(buf, Buffer.prototype)
|
1682 |
|
1683 | return buf
|
1684 | }
|
1685 |
|
1686 | function fromObject (obj) {
|
1687 | if (Buffer.isBuffer(obj)) {
|
1688 | var len = checked(obj.length) | 0
|
1689 | var buf = createBuffer(len)
|
1690 |
|
1691 | if (buf.length === 0) {
|
1692 | return buf
|
1693 | }
|
1694 |
|
1695 | obj.copy(buf, 0, 0, len)
|
1696 | return buf
|
1697 | }
|
1698 |
|
1699 | if (obj.length !== undefined) {
|
1700 | if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
|
1701 | return createBuffer(0)
|
1702 | }
|
1703 | return fromArrayLike(obj)
|
1704 | }
|
1705 |
|
1706 | if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
|
1707 | return fromArrayLike(obj.data)
|
1708 | }
|
1709 | }
|
1710 |
|
1711 | function checked (length) {
|
1712 |
|
1713 |
|
1714 | if (length >= K_MAX_LENGTH) {
|
1715 | throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
|
1716 | 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes')
|
1717 | }
|
1718 | return length | 0
|
1719 | }
|
1720 |
|
1721 | function SlowBuffer (length) {
|
1722 | if (+length != length) {
|
1723 | length = 0
|
1724 | }
|
1725 | return Buffer.alloc(+length)
|
1726 | }
|
1727 |
|
1728 | Buffer.isBuffer = function isBuffer (b) {
|
1729 | return b != null && b._isBuffer === true &&
|
1730 | b !== Buffer.prototype
|
1731 | }
|
1732 |
|
1733 | Buffer.compare = function compare (a, b) {
|
1734 | if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength)
|
1735 | if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength)
|
1736 | if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
|
1737 | throw new TypeError(
|
1738 | 'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'
|
1739 | )
|
1740 | }
|
1741 |
|
1742 | if (a === b) return 0
|
1743 |
|
1744 | var x = a.length
|
1745 | var y = b.length
|
1746 |
|
1747 | for (var i = 0, len = Math.min(x, y); i < len; ++i) {
|
1748 | if (a[i] !== b[i]) {
|
1749 | x = a[i]
|
1750 | y = b[i]
|
1751 | break
|
1752 | }
|
1753 | }
|
1754 |
|
1755 | if (x < y) return -1
|
1756 | if (y < x) return 1
|
1757 | return 0
|
1758 | }
|
1759 |
|
1760 | Buffer.isEncoding = function isEncoding (encoding) {
|
1761 | switch (String(encoding).toLowerCase()) {
|
1762 | case 'hex':
|
1763 | case 'utf8':
|
1764 | case 'utf-8':
|
1765 | case 'ascii':
|
1766 | case 'latin1':
|
1767 | case 'binary':
|
1768 | case 'base64':
|
1769 | case 'ucs2':
|
1770 | case 'ucs-2':
|
1771 | case 'utf16le':
|
1772 | case 'utf-16le':
|
1773 | return true
|
1774 | default:
|
1775 | return false
|
1776 | }
|
1777 | }
|
1778 |
|
1779 | Buffer.concat = function concat (list, length) {
|
1780 | if (!Array.isArray(list)) {
|
1781 | throw new TypeError('"list" argument must be an Array of Buffers')
|
1782 | }
|
1783 |
|
1784 | if (list.length === 0) {
|
1785 | return Buffer.alloc(0)
|
1786 | }
|
1787 |
|
1788 | var i
|
1789 | if (length === undefined) {
|
1790 | length = 0
|
1791 | for (i = 0; i < list.length; ++i) {
|
1792 | length += list[i].length
|
1793 | }
|
1794 | }
|
1795 |
|
1796 | var buffer = Buffer.allocUnsafe(length)
|
1797 | var pos = 0
|
1798 | for (i = 0; i < list.length; ++i) {
|
1799 | var buf = list[i]
|
1800 | if (isInstance(buf, Uint8Array)) {
|
1801 | buf = Buffer.from(buf)
|
1802 | }
|
1803 | if (!Buffer.isBuffer(buf)) {
|
1804 | throw new TypeError('"list" argument must be an Array of Buffers')
|
1805 | }
|
1806 | buf.copy(buffer, pos)
|
1807 | pos += buf.length
|
1808 | }
|
1809 | return buffer
|
1810 | }
|
1811 |
|
1812 | function byteLength (string, encoding) {
|
1813 | if (Buffer.isBuffer(string)) {
|
1814 | return string.length
|
1815 | }
|
1816 | if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
|
1817 | return string.byteLength
|
1818 | }
|
1819 | if (typeof string !== 'string') {
|
1820 | throw new TypeError(
|
1821 | 'The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' +
|
1822 | 'Received type ' + typeof string
|
1823 | )
|
1824 | }
|
1825 |
|
1826 | var len = string.length
|
1827 | var mustMatch = (arguments.length > 2 && arguments[2] === true)
|
1828 | if (!mustMatch && len === 0) return 0
|
1829 |
|
1830 |
|
1831 | var loweredCase = false
|
1832 | for (;;) {
|
1833 | switch (encoding) {
|
1834 | case 'ascii':
|
1835 | case 'latin1':
|
1836 | case 'binary':
|
1837 | return len
|
1838 | case 'utf8':
|
1839 | case 'utf-8':
|
1840 | return utf8ToBytes(string).length
|
1841 | case 'ucs2':
|
1842 | case 'ucs-2':
|
1843 | case 'utf16le':
|
1844 | case 'utf-16le':
|
1845 | return len * 2
|
1846 | case 'hex':
|
1847 | return len >>> 1
|
1848 | case 'base64':
|
1849 | return base64ToBytes(string).length
|
1850 | default:
|
1851 | if (loweredCase) {
|
1852 | return mustMatch ? -1 : utf8ToBytes(string).length
|
1853 | }
|
1854 | encoding = ('' + encoding).toLowerCase()
|
1855 | loweredCase = true
|
1856 | }
|
1857 | }
|
1858 | }
|
1859 | Buffer.byteLength = byteLength
|
1860 |
|
1861 | function slowToString (encoding, start, end) {
|
1862 | var loweredCase = false
|
1863 |
|
1864 |
|
1865 |
|
1866 |
|
1867 |
|
1868 |
|
1869 |
|
1870 |
|
1871 | if (start === undefined || start < 0) {
|
1872 | start = 0
|
1873 | }
|
1874 |
|
1875 |
|
1876 | if (start > this.length) {
|
1877 | return ''
|
1878 | }
|
1879 |
|
1880 | if (end === undefined || end > this.length) {
|
1881 | end = this.length
|
1882 | }
|
1883 |
|
1884 | if (end <= 0) {
|
1885 | return ''
|
1886 | }
|
1887 |
|
1888 |
|
1889 | end >>>= 0
|
1890 | start >>>= 0
|
1891 |
|
1892 | if (end <= start) {
|
1893 | return ''
|
1894 | }
|
1895 |
|
1896 | if (!encoding) encoding = 'utf8'
|
1897 |
|
1898 | while (true) {
|
1899 | switch (encoding) {
|
1900 | case 'hex':
|
1901 | return hexSlice(this, start, end)
|
1902 |
|
1903 | case 'utf8':
|
1904 | case 'utf-8':
|
1905 | return utf8Slice(this, start, end)
|
1906 |
|
1907 | case 'ascii':
|
1908 | return asciiSlice(this, start, end)
|
1909 |
|
1910 | case 'latin1':
|
1911 | case 'binary':
|
1912 | return latin1Slice(this, start, end)
|
1913 |
|
1914 | case 'base64':
|
1915 | return base64Slice(this, start, end)
|
1916 |
|
1917 | case 'ucs2':
|
1918 | case 'ucs-2':
|
1919 | case 'utf16le':
|
1920 | case 'utf-16le':
|
1921 | return utf16leSlice(this, start, end)
|
1922 |
|
1923 | default:
|
1924 | if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
|
1925 | encoding = (encoding + '').toLowerCase()
|
1926 | loweredCase = true
|
1927 | }
|
1928 | }
|
1929 | }
|
1930 |
|
1931 |
|
1932 |
|
1933 |
|
1934 |
|
1935 |
|
1936 |
|
1937 | Buffer.prototype._isBuffer = true
|
1938 |
|
1939 | function swap (b, n, m) {
|
1940 | var i = b[n]
|
1941 | b[n] = b[m]
|
1942 | b[m] = i
|
1943 | }
|
1944 |
|
1945 | Buffer.prototype.swap16 = function swap16 () {
|
1946 | var len = this.length
|
1947 | if (len % 2 !== 0) {
|
1948 | throw new RangeError('Buffer size must be a multiple of 16-bits')
|
1949 | }
|
1950 | for (var i = 0; i < len; i += 2) {
|
1951 | swap(this, i, i + 1)
|
1952 | }
|
1953 | return this
|
1954 | }
|
1955 |
|
1956 | Buffer.prototype.swap32 = function swap32 () {
|
1957 | var len = this.length
|
1958 | if (len % 4 !== 0) {
|
1959 | throw new RangeError('Buffer size must be a multiple of 32-bits')
|
1960 | }
|
1961 | for (var i = 0; i < len; i += 4) {
|
1962 | swap(this, i, i + 3)
|
1963 | swap(this, i + 1, i + 2)
|
1964 | }
|
1965 | return this
|
1966 | }
|
1967 |
|
1968 | Buffer.prototype.swap64 = function swap64 () {
|
1969 | var len = this.length
|
1970 | if (len % 8 !== 0) {
|
1971 | throw new RangeError('Buffer size must be a multiple of 64-bits')
|
1972 | }
|
1973 | for (var i = 0; i < len; i += 8) {
|
1974 | swap(this, i, i + 7)
|
1975 | swap(this, i + 1, i + 6)
|
1976 | swap(this, i + 2, i + 5)
|
1977 | swap(this, i + 3, i + 4)
|
1978 | }
|
1979 | return this
|
1980 | }
|
1981 |
|
1982 | Buffer.prototype.toString = function toString () {
|
1983 | var length = this.length
|
1984 | if (length === 0) return ''
|
1985 | if (arguments.length === 0) return utf8Slice(this, 0, length)
|
1986 | return slowToString.apply(this, arguments)
|
1987 | }
|
1988 |
|
1989 | Buffer.prototype.toLocaleString = Buffer.prototype.toString
|
1990 |
|
1991 | Buffer.prototype.equals = function equals (b) {
|
1992 | if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
|
1993 | if (this === b) return true
|
1994 | return Buffer.compare(this, b) === 0
|
1995 | }
|
1996 |
|
1997 | Buffer.prototype.inspect = function inspect () {
|
1998 | var str = ''
|
1999 | var max = exports.INSPECT_MAX_BYTES
|
2000 | str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim()
|
2001 | if (this.length > max) str += ' ... '
|
2002 | return '<Buffer ' + str + '>'
|
2003 | }
|
2004 | if (customInspectSymbol) {
|
2005 | Buffer.prototype[customInspectSymbol] = Buffer.prototype.inspect
|
2006 | }
|
2007 |
|
2008 | Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
|
2009 | if (isInstance(target, Uint8Array)) {
|
2010 | target = Buffer.from(target, target.offset, target.byteLength)
|
2011 | }
|
2012 | if (!Buffer.isBuffer(target)) {
|
2013 | throw new TypeError(
|
2014 | 'The "target" argument must be one of type Buffer or Uint8Array. ' +
|
2015 | 'Received type ' + (typeof target)
|
2016 | )
|
2017 | }
|
2018 |
|
2019 | if (start === undefined) {
|
2020 | start = 0
|
2021 | }
|
2022 | if (end === undefined) {
|
2023 | end = target ? target.length : 0
|
2024 | }
|
2025 | if (thisStart === undefined) {
|
2026 | thisStart = 0
|
2027 | }
|
2028 | if (thisEnd === undefined) {
|
2029 | thisEnd = this.length
|
2030 | }
|
2031 |
|
2032 | if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
|
2033 | throw new RangeError('out of range index')
|
2034 | }
|
2035 |
|
2036 | if (thisStart >= thisEnd && start >= end) {
|
2037 | return 0
|
2038 | }
|
2039 | if (thisStart >= thisEnd) {
|
2040 | return -1
|
2041 | }
|
2042 | if (start >= end) {
|
2043 | return 1
|
2044 | }
|
2045 |
|
2046 | start >>>= 0
|
2047 | end >>>= 0
|
2048 | thisStart >>>= 0
|
2049 | thisEnd >>>= 0
|
2050 |
|
2051 | if (this === target) return 0
|
2052 |
|
2053 | var x = thisEnd - thisStart
|
2054 | var y = end - start
|
2055 | var len = Math.min(x, y)
|
2056 |
|
2057 | var thisCopy = this.slice(thisStart, thisEnd)
|
2058 | var targetCopy = target.slice(start, end)
|
2059 |
|
2060 | for (var i = 0; i < len; ++i) {
|
2061 | if (thisCopy[i] !== targetCopy[i]) {
|
2062 | x = thisCopy[i]
|
2063 | y = targetCopy[i]
|
2064 | break
|
2065 | }
|
2066 | }
|
2067 |
|
2068 | if (x < y) return -1
|
2069 | if (y < x) return 1
|
2070 | return 0
|
2071 | }
|
2072 |
|
2073 |
|
2074 |
|
2075 |
|
2076 |
|
2077 |
|
2078 |
|
2079 |
|
2080 |
|
2081 |
|
2082 | function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
|
2083 |
|
2084 | if (buffer.length === 0) return -1
|
2085 |
|
2086 |
|
2087 | if (typeof byteOffset === 'string') {
|
2088 | encoding = byteOffset
|
2089 | byteOffset = 0
|
2090 | } else if (byteOffset > 0x7fffffff) {
|
2091 | byteOffset = 0x7fffffff
|
2092 | } else if (byteOffset < -0x80000000) {
|
2093 | byteOffset = -0x80000000
|
2094 | }
|
2095 | byteOffset = +byteOffset
|
2096 | if (numberIsNaN(byteOffset)) {
|
2097 |
|
2098 | byteOffset = dir ? 0 : (buffer.length - 1)
|
2099 | }
|
2100 |
|
2101 |
|
2102 | if (byteOffset < 0) byteOffset = buffer.length + byteOffset
|
2103 | if (byteOffset >= buffer.length) {
|
2104 | if (dir) return -1
|
2105 | else byteOffset = buffer.length - 1
|
2106 | } else if (byteOffset < 0) {
|
2107 | if (dir) byteOffset = 0
|
2108 | else return -1
|
2109 | }
|
2110 |
|
2111 |
|
2112 | if (typeof val === 'string') {
|
2113 | val = Buffer.from(val, encoding)
|
2114 | }
|
2115 |
|
2116 |
|
2117 | if (Buffer.isBuffer(val)) {
|
2118 |
|
2119 | if (val.length === 0) {
|
2120 | return -1
|
2121 | }
|
2122 | return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
|
2123 | } else if (typeof val === 'number') {
|
2124 | val = val & 0xFF
|
2125 | if (typeof Uint8Array.prototype.indexOf === 'function') {
|
2126 | if (dir) {
|
2127 | return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
|
2128 | } else {
|
2129 | return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
|
2130 | }
|
2131 | }
|
2132 | return arrayIndexOf(buffer, [val], byteOffset, encoding, dir)
|
2133 | }
|
2134 |
|
2135 | throw new TypeError('val must be string, number or Buffer')
|
2136 | }
|
2137 |
|
2138 | function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
|
2139 | var indexSize = 1
|
2140 | var arrLength = arr.length
|
2141 | var valLength = val.length
|
2142 |
|
2143 | if (encoding !== undefined) {
|
2144 | encoding = String(encoding).toLowerCase()
|
2145 | if (encoding === 'ucs2' || encoding === 'ucs-2' ||
|
2146 | encoding === 'utf16le' || encoding === 'utf-16le') {
|
2147 | if (arr.length < 2 || val.length < 2) {
|
2148 | return -1
|
2149 | }
|
2150 | indexSize = 2
|
2151 | arrLength /= 2
|
2152 | valLength /= 2
|
2153 | byteOffset /= 2
|
2154 | }
|
2155 | }
|
2156 |
|
2157 | function read (buf, i) {
|
2158 | if (indexSize === 1) {
|
2159 | return buf[i]
|
2160 | } else {
|
2161 | return buf.readUInt16BE(i * indexSize)
|
2162 | }
|
2163 | }
|
2164 |
|
2165 | var i
|
2166 | if (dir) {
|
2167 | var foundIndex = -1
|
2168 | for (i = byteOffset; i < arrLength; i++) {
|
2169 | if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
|
2170 | if (foundIndex === -1) foundIndex = i
|
2171 | if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
|
2172 | } else {
|
2173 | if (foundIndex !== -1) i -= i - foundIndex
|
2174 | foundIndex = -1
|
2175 | }
|
2176 | }
|
2177 | } else {
|
2178 | if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength
|
2179 | for (i = byteOffset; i >= 0; i--) {
|
2180 | var found = true
|
2181 | for (var j = 0; j < valLength; j++) {
|
2182 | if (read(arr, i + j) !== read(val, j)) {
|
2183 | found = false
|
2184 | break
|
2185 | }
|
2186 | }
|
2187 | if (found) return i
|
2188 | }
|
2189 | }
|
2190 |
|
2191 | return -1
|
2192 | }
|
2193 |
|
2194 | Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
|
2195 | return this.indexOf(val, byteOffset, encoding) !== -1
|
2196 | }
|
2197 |
|
2198 | Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
|
2199 | return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
|
2200 | }
|
2201 |
|
2202 | Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
|
2203 | return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
|
2204 | }
|
2205 |
|
2206 | function hexWrite (buf, string, offset, length) {
|
2207 | offset = Number(offset) || 0
|
2208 | var remaining = buf.length - offset
|
2209 | if (!length) {
|
2210 | length = remaining
|
2211 | } else {
|
2212 | length = Number(length)
|
2213 | if (length > remaining) {
|
2214 | length = remaining
|
2215 | }
|
2216 | }
|
2217 |
|
2218 | var strLen = string.length
|
2219 |
|
2220 | if (length > strLen / 2) {
|
2221 | length = strLen / 2
|
2222 | }
|
2223 | for (var i = 0; i < length; ++i) {
|
2224 | var parsed = parseInt(string.substr(i * 2, 2), 16)
|
2225 | if (numberIsNaN(parsed)) return i
|
2226 | buf[offset + i] = parsed
|
2227 | }
|
2228 | return i
|
2229 | }
|
2230 |
|
2231 | function utf8Write (buf, string, offset, length) {
|
2232 | return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
|
2233 | }
|
2234 |
|
2235 | function asciiWrite (buf, string, offset, length) {
|
2236 | return blitBuffer(asciiToBytes(string), buf, offset, length)
|
2237 | }
|
2238 |
|
2239 | function latin1Write (buf, string, offset, length) {
|
2240 | return asciiWrite(buf, string, offset, length)
|
2241 | }
|
2242 |
|
2243 | function base64Write (buf, string, offset, length) {
|
2244 | return blitBuffer(base64ToBytes(string), buf, offset, length)
|
2245 | }
|
2246 |
|
2247 | function ucs2Write (buf, string, offset, length) {
|
2248 | return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
|
2249 | }
|
2250 |
|
2251 | Buffer.prototype.write = function write (string, offset, length, encoding) {
|
2252 |
|
2253 | if (offset === undefined) {
|
2254 | encoding = 'utf8'
|
2255 | length = this.length
|
2256 | offset = 0
|
2257 |
|
2258 | } else if (length === undefined && typeof offset === 'string') {
|
2259 | encoding = offset
|
2260 | length = this.length
|
2261 | offset = 0
|
2262 |
|
2263 | } else if (isFinite(offset)) {
|
2264 | offset = offset >>> 0
|
2265 | if (isFinite(length)) {
|
2266 | length = length >>> 0
|
2267 | if (encoding === undefined) encoding = 'utf8'
|
2268 | } else {
|
2269 | encoding = length
|
2270 | length = undefined
|
2271 | }
|
2272 | } else {
|
2273 | throw new Error(
|
2274 | 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
|
2275 | )
|
2276 | }
|
2277 |
|
2278 | var remaining = this.length - offset
|
2279 | if (length === undefined || length > remaining) length = remaining
|
2280 |
|
2281 | if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
|
2282 | throw new RangeError('Attempt to write outside buffer bounds')
|
2283 | }
|
2284 |
|
2285 | if (!encoding) encoding = 'utf8'
|
2286 |
|
2287 | var loweredCase = false
|
2288 | for (;;) {
|
2289 | switch (encoding) {
|
2290 | case 'hex':
|
2291 | return hexWrite(this, string, offset, length)
|
2292 |
|
2293 | case 'utf8':
|
2294 | case 'utf-8':
|
2295 | return utf8Write(this, string, offset, length)
|
2296 |
|
2297 | case 'ascii':
|
2298 | return asciiWrite(this, string, offset, length)
|
2299 |
|
2300 | case 'latin1':
|
2301 | case 'binary':
|
2302 | return latin1Write(this, string, offset, length)
|
2303 |
|
2304 | case 'base64':
|
2305 |
|
2306 | return base64Write(this, string, offset, length)
|
2307 |
|
2308 | case 'ucs2':
|
2309 | case 'ucs-2':
|
2310 | case 'utf16le':
|
2311 | case 'utf-16le':
|
2312 | return ucs2Write(this, string, offset, length)
|
2313 |
|
2314 | default:
|
2315 | if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
|
2316 | encoding = ('' + encoding).toLowerCase()
|
2317 | loweredCase = true
|
2318 | }
|
2319 | }
|
2320 | }
|
2321 |
|
2322 | Buffer.prototype.toJSON = function toJSON () {
|
2323 | return {
|
2324 | type: 'Buffer',
|
2325 | data: Array.prototype.slice.call(this._arr || this, 0)
|
2326 | }
|
2327 | }
|
2328 |
|
2329 | function base64Slice (buf, start, end) {
|
2330 | if (start === 0 && end === buf.length) {
|
2331 | return base64.fromByteArray(buf)
|
2332 | } else {
|
2333 | return base64.fromByteArray(buf.slice(start, end))
|
2334 | }
|
2335 | }
|
2336 |
|
2337 | function utf8Slice (buf, start, end) {
|
2338 | end = Math.min(buf.length, end)
|
2339 | var res = []
|
2340 |
|
2341 | var i = start
|
2342 | while (i < end) {
|
2343 | var firstByte = buf[i]
|
2344 | var codePoint = null
|
2345 | var bytesPerSequence = (firstByte > 0xEF) ? 4
|
2346 | : (firstByte > 0xDF) ? 3
|
2347 | : (firstByte > 0xBF) ? 2
|
2348 | : 1
|
2349 |
|
2350 | if (i + bytesPerSequence <= end) {
|
2351 | var secondByte, thirdByte, fourthByte, tempCodePoint
|
2352 |
|
2353 | switch (bytesPerSequence) {
|
2354 | case 1:
|
2355 | if (firstByte < 0x80) {
|
2356 | codePoint = firstByte
|
2357 | }
|
2358 | break
|
2359 | case 2:
|
2360 | secondByte = buf[i + 1]
|
2361 | if ((secondByte & 0xC0) === 0x80) {
|
2362 | tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F)
|
2363 | if (tempCodePoint > 0x7F) {
|
2364 | codePoint = tempCodePoint
|
2365 | }
|
2366 | }
|
2367 | break
|
2368 | case 3:
|
2369 | secondByte = buf[i + 1]
|
2370 | thirdByte = buf[i + 2]
|
2371 | if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
|
2372 | tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F)
|
2373 | if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
|
2374 | codePoint = tempCodePoint
|
2375 | }
|
2376 | }
|
2377 | break
|
2378 | case 4:
|
2379 | secondByte = buf[i + 1]
|
2380 | thirdByte = buf[i + 2]
|
2381 | fourthByte = buf[i + 3]
|
2382 | if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
|
2383 | tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F)
|
2384 | if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
|
2385 | codePoint = tempCodePoint
|
2386 | }
|
2387 | }
|
2388 | }
|
2389 | }
|
2390 |
|
2391 | if (codePoint === null) {
|
2392 |
|
2393 |
|
2394 | codePoint = 0xFFFD
|
2395 | bytesPerSequence = 1
|
2396 | } else if (codePoint > 0xFFFF) {
|
2397 |
|
2398 | codePoint -= 0x10000
|
2399 | res.push(codePoint >>> 10 & 0x3FF | 0xD800)
|
2400 | codePoint = 0xDC00 | codePoint & 0x3FF
|
2401 | }
|
2402 |
|
2403 | res.push(codePoint)
|
2404 | i += bytesPerSequence
|
2405 | }
|
2406 |
|
2407 | return decodeCodePointsArray(res)
|
2408 | }
|
2409 |
|
2410 |
|
2411 |
|
2412 |
|
2413 | var MAX_ARGUMENTS_LENGTH = 0x1000
|
2414 |
|
2415 | function decodeCodePointsArray (codePoints) {
|
2416 | var len = codePoints.length
|
2417 | if (len <= MAX_ARGUMENTS_LENGTH) {
|
2418 | return String.fromCharCode.apply(String, codePoints)
|
2419 | }
|
2420 |
|
2421 |
|
2422 | var res = ''
|
2423 | var i = 0
|
2424 | while (i < len) {
|
2425 | res += String.fromCharCode.apply(
|
2426 | String,
|
2427 | codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
|
2428 | )
|
2429 | }
|
2430 | return res
|
2431 | }
|
2432 |
|
2433 | function asciiSlice (buf, start, end) {
|
2434 | var ret = ''
|
2435 | end = Math.min(buf.length, end)
|
2436 |
|
2437 | for (var i = start; i < end; ++i) {
|
2438 | ret += String.fromCharCode(buf[i] & 0x7F)
|
2439 | }
|
2440 | return ret
|
2441 | }
|
2442 |
|
2443 | function latin1Slice (buf, start, end) {
|
2444 | var ret = ''
|
2445 | end = Math.min(buf.length, end)
|
2446 |
|
2447 | for (var i = start; i < end; ++i) {
|
2448 | ret += String.fromCharCode(buf[i])
|
2449 | }
|
2450 | return ret
|
2451 | }
|
2452 |
|
2453 | function hexSlice (buf, start, end) {
|
2454 | var len = buf.length
|
2455 |
|
2456 | if (!start || start < 0) start = 0
|
2457 | if (!end || end < 0 || end > len) end = len
|
2458 |
|
2459 | var out = ''
|
2460 | for (var i = start; i < end; ++i) {
|
2461 | out += hexSliceLookupTable[buf[i]]
|
2462 | }
|
2463 | return out
|
2464 | }
|
2465 |
|
2466 | function utf16leSlice (buf, start, end) {
|
2467 | var bytes = buf.slice(start, end)
|
2468 | var res = ''
|
2469 | for (var i = 0; i < bytes.length; i += 2) {
|
2470 | res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256))
|
2471 | }
|
2472 | return res
|
2473 | }
|
2474 |
|
2475 | Buffer.prototype.slice = function slice (start, end) {
|
2476 | var len = this.length
|
2477 | start = ~~start
|
2478 | end = end === undefined ? len : ~~end
|
2479 |
|
2480 | if (start < 0) {
|
2481 | start += len
|
2482 | if (start < 0) start = 0
|
2483 | } else if (start > len) {
|
2484 | start = len
|
2485 | }
|
2486 |
|
2487 | if (end < 0) {
|
2488 | end += len
|
2489 | if (end < 0) end = 0
|
2490 | } else if (end > len) {
|
2491 | end = len
|
2492 | }
|
2493 |
|
2494 | if (end < start) end = start
|
2495 |
|
2496 | var newBuf = this.subarray(start, end)
|
2497 |
|
2498 | Object.setPrototypeOf(newBuf, Buffer.prototype)
|
2499 |
|
2500 | return newBuf
|
2501 | }
|
2502 |
|
2503 |
|
2504 |
|
2505 |
|
2506 | function checkOffset (offset, ext, length) {
|
2507 | if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
|
2508 | if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
|
2509 | }
|
2510 |
|
2511 | Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
|
2512 | offset = offset >>> 0
|
2513 | byteLength = byteLength >>> 0
|
2514 | if (!noAssert) checkOffset(offset, byteLength, this.length)
|
2515 |
|
2516 | var val = this[offset]
|
2517 | var mul = 1
|
2518 | var i = 0
|
2519 | while (++i < byteLength && (mul *= 0x100)) {
|
2520 | val += this[offset + i] * mul
|
2521 | }
|
2522 |
|
2523 | return val
|
2524 | }
|
2525 |
|
2526 | Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
|
2527 | offset = offset >>> 0
|
2528 | byteLength = byteLength >>> 0
|
2529 | if (!noAssert) {
|
2530 | checkOffset(offset, byteLength, this.length)
|
2531 | }
|
2532 |
|
2533 | var val = this[offset + --byteLength]
|
2534 | var mul = 1
|
2535 | while (byteLength > 0 && (mul *= 0x100)) {
|
2536 | val += this[offset + --byteLength] * mul
|
2537 | }
|
2538 |
|
2539 | return val
|
2540 | }
|
2541 |
|
2542 | Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
|
2543 | offset = offset >>> 0
|
2544 | if (!noAssert) checkOffset(offset, 1, this.length)
|
2545 | return this[offset]
|
2546 | }
|
2547 |
|
2548 | Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
|
2549 | offset = offset >>> 0
|
2550 | if (!noAssert) checkOffset(offset, 2, this.length)
|
2551 | return this[offset] | (this[offset + 1] << 8)
|
2552 | }
|
2553 |
|
2554 | Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
|
2555 | offset = offset >>> 0
|
2556 | if (!noAssert) checkOffset(offset, 2, this.length)
|
2557 | return (this[offset] << 8) | this[offset + 1]
|
2558 | }
|
2559 |
|
2560 | Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
|
2561 | offset = offset >>> 0
|
2562 | if (!noAssert) checkOffset(offset, 4, this.length)
|
2563 |
|
2564 | return ((this[offset]) |
|
2565 | (this[offset + 1] << 8) |
|
2566 | (this[offset + 2] << 16)) +
|
2567 | (this[offset + 3] * 0x1000000)
|
2568 | }
|
2569 |
|
2570 | Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
|
2571 | offset = offset >>> 0
|
2572 | if (!noAssert) checkOffset(offset, 4, this.length)
|
2573 |
|
2574 | return (this[offset] * 0x1000000) +
|
2575 | ((this[offset + 1] << 16) |
|
2576 | (this[offset + 2] << 8) |
|
2577 | this[offset + 3])
|
2578 | }
|
2579 |
|
2580 | Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
|
2581 | offset = offset >>> 0
|
2582 | byteLength = byteLength >>> 0
|
2583 | if (!noAssert) checkOffset(offset, byteLength, this.length)
|
2584 |
|
2585 | var val = this[offset]
|
2586 | var mul = 1
|
2587 | var i = 0
|
2588 | while (++i < byteLength && (mul *= 0x100)) {
|
2589 | val += this[offset + i] * mul
|
2590 | }
|
2591 | mul *= 0x80
|
2592 |
|
2593 | if (val >= mul) val -= Math.pow(2, 8 * byteLength)
|
2594 |
|
2595 | return val
|
2596 | }
|
2597 |
|
2598 | Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
|
2599 | offset = offset >>> 0
|
2600 | byteLength = byteLength >>> 0
|
2601 | if (!noAssert) checkOffset(offset, byteLength, this.length)
|
2602 |
|
2603 | var i = byteLength
|
2604 | var mul = 1
|
2605 | var val = this[offset + --i]
|
2606 | while (i > 0 && (mul *= 0x100)) {
|
2607 | val += this[offset + --i] * mul
|
2608 | }
|
2609 | mul *= 0x80
|
2610 |
|
2611 | if (val >= mul) val -= Math.pow(2, 8 * byteLength)
|
2612 |
|
2613 | return val
|
2614 | }
|
2615 |
|
2616 | Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
|
2617 | offset = offset >>> 0
|
2618 | if (!noAssert) checkOffset(offset, 1, this.length)
|
2619 | if (!(this[offset] & 0x80)) return (this[offset])
|
2620 | return ((0xff - this[offset] + 1) * -1)
|
2621 | }
|
2622 |
|
2623 | Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
|
2624 | offset = offset >>> 0
|
2625 | if (!noAssert) checkOffset(offset, 2, this.length)
|
2626 | var val = this[offset] | (this[offset + 1] << 8)
|
2627 | return (val & 0x8000) ? val | 0xFFFF0000 : val
|
2628 | }
|
2629 |
|
2630 | Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
|
2631 | offset = offset >>> 0
|
2632 | if (!noAssert) checkOffset(offset, 2, this.length)
|
2633 | var val = this[offset + 1] | (this[offset] << 8)
|
2634 | return (val & 0x8000) ? val | 0xFFFF0000 : val
|
2635 | }
|
2636 |
|
2637 | Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
|
2638 | offset = offset >>> 0
|
2639 | if (!noAssert) checkOffset(offset, 4, this.length)
|
2640 |
|
2641 | return (this[offset]) |
|
2642 | (this[offset + 1] << 8) |
|
2643 | (this[offset + 2] << 16) |
|
2644 | (this[offset + 3] << 24)
|
2645 | }
|
2646 |
|
2647 | Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
|
2648 | offset = offset >>> 0
|
2649 | if (!noAssert) checkOffset(offset, 4, this.length)
|
2650 |
|
2651 | return (this[offset] << 24) |
|
2652 | (this[offset + 1] << 16) |
|
2653 | (this[offset + 2] << 8) |
|
2654 | (this[offset + 3])
|
2655 | }
|
2656 |
|
2657 | Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
|
2658 | offset = offset >>> 0
|
2659 | if (!noAssert) checkOffset(offset, 4, this.length)
|
2660 | return ieee754.read(this, offset, true, 23, 4)
|
2661 | }
|
2662 |
|
2663 | Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
|
2664 | offset = offset >>> 0
|
2665 | if (!noAssert) checkOffset(offset, 4, this.length)
|
2666 | return ieee754.read(this, offset, false, 23, 4)
|
2667 | }
|
2668 |
|
2669 | Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
|
2670 | offset = offset >>> 0
|
2671 | if (!noAssert) checkOffset(offset, 8, this.length)
|
2672 | return ieee754.read(this, offset, true, 52, 8)
|
2673 | }
|
2674 |
|
2675 | Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
|
2676 | offset = offset >>> 0
|
2677 | if (!noAssert) checkOffset(offset, 8, this.length)
|
2678 | return ieee754.read(this, offset, false, 52, 8)
|
2679 | }
|
2680 |
|
2681 | function checkInt (buf, value, offset, ext, max, min) {
|
2682 | if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
|
2683 | if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
|
2684 | if (offset + ext > buf.length) throw new RangeError('Index out of range')
|
2685 | }
|
2686 |
|
2687 | Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
|
2688 | value = +value
|
2689 | offset = offset >>> 0
|
2690 | byteLength = byteLength >>> 0
|
2691 | if (!noAssert) {
|
2692 | var maxBytes = Math.pow(2, 8 * byteLength) - 1
|
2693 | checkInt(this, value, offset, byteLength, maxBytes, 0)
|
2694 | }
|
2695 |
|
2696 | var mul = 1
|
2697 | var i = 0
|
2698 | this[offset] = value & 0xFF
|
2699 | while (++i < byteLength && (mul *= 0x100)) {
|
2700 | this[offset + i] = (value / mul) & 0xFF
|
2701 | }
|
2702 |
|
2703 | return offset + byteLength
|
2704 | }
|
2705 |
|
2706 | Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
|
2707 | value = +value
|
2708 | offset = offset >>> 0
|
2709 | byteLength = byteLength >>> 0
|
2710 | if (!noAssert) {
|
2711 | var maxBytes = Math.pow(2, 8 * byteLength) - 1
|
2712 | checkInt(this, value, offset, byteLength, maxBytes, 0)
|
2713 | }
|
2714 |
|
2715 | var i = byteLength - 1
|
2716 | var mul = 1
|
2717 | this[offset + i] = value & 0xFF
|
2718 | while (--i >= 0 && (mul *= 0x100)) {
|
2719 | this[offset + i] = (value / mul) & 0xFF
|
2720 | }
|
2721 |
|
2722 | return offset + byteLength
|
2723 | }
|
2724 |
|
2725 | Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
|
2726 | value = +value
|
2727 | offset = offset >>> 0
|
2728 | if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)
|
2729 | this[offset] = (value & 0xff)
|
2730 | return offset + 1
|
2731 | }
|
2732 |
|
2733 | Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
|
2734 | value = +value
|
2735 | offset = offset >>> 0
|
2736 | if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
|
2737 | this[offset] = (value & 0xff)
|
2738 | this[offset + 1] = (value >>> 8)
|
2739 | return offset + 2
|
2740 | }
|
2741 |
|
2742 | Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
|
2743 | value = +value
|
2744 | offset = offset >>> 0
|
2745 | if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
|
2746 | this[offset] = (value >>> 8)
|
2747 | this[offset + 1] = (value & 0xff)
|
2748 | return offset + 2
|
2749 | }
|
2750 |
|
2751 | Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
|
2752 | value = +value
|
2753 | offset = offset >>> 0
|
2754 | if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
|
2755 | this[offset + 3] = (value >>> 24)
|
2756 | this[offset + 2] = (value >>> 16)
|
2757 | this[offset + 1] = (value >>> 8)
|
2758 | this[offset] = (value & 0xff)
|
2759 | return offset + 4
|
2760 | }
|
2761 |
|
2762 | Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
|
2763 | value = +value
|
2764 | offset = offset >>> 0
|
2765 | if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
|
2766 | this[offset] = (value >>> 24)
|
2767 | this[offset + 1] = (value >>> 16)
|
2768 | this[offset + 2] = (value >>> 8)
|
2769 | this[offset + 3] = (value & 0xff)
|
2770 | return offset + 4
|
2771 | }
|
2772 |
|
2773 | Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
|
2774 | value = +value
|
2775 | offset = offset >>> 0
|
2776 | if (!noAssert) {
|
2777 | var limit = Math.pow(2, (8 * byteLength) - 1)
|
2778 |
|
2779 | checkInt(this, value, offset, byteLength, limit - 1, -limit)
|
2780 | }
|
2781 |
|
2782 | var i = 0
|
2783 | var mul = 1
|
2784 | var sub = 0
|
2785 | this[offset] = value & 0xFF
|
2786 | while (++i < byteLength && (mul *= 0x100)) {
|
2787 | if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
|
2788 | sub = 1
|
2789 | }
|
2790 | this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
|
2791 | }
|
2792 |
|
2793 | return offset + byteLength
|
2794 | }
|
2795 |
|
2796 | Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
|
2797 | value = +value
|
2798 | offset = offset >>> 0
|
2799 | if (!noAssert) {
|
2800 | var limit = Math.pow(2, (8 * byteLength) - 1)
|
2801 |
|
2802 | checkInt(this, value, offset, byteLength, limit - 1, -limit)
|
2803 | }
|
2804 |
|
2805 | var i = byteLength - 1
|
2806 | var mul = 1
|
2807 | var sub = 0
|
2808 | this[offset + i] = value & 0xFF
|
2809 | while (--i >= 0 && (mul *= 0x100)) {
|
2810 | if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
|
2811 | sub = 1
|
2812 | }
|
2813 | this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
|
2814 | }
|
2815 |
|
2816 | return offset + byteLength
|
2817 | }
|
2818 |
|
2819 | Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
|
2820 | value = +value
|
2821 | offset = offset >>> 0
|
2822 | if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80)
|
2823 | if (value < 0) value = 0xff + value + 1
|
2824 | this[offset] = (value & 0xff)
|
2825 | return offset + 1
|
2826 | }
|
2827 |
|
2828 | Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
|
2829 | value = +value
|
2830 | offset = offset >>> 0
|
2831 | if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
|
2832 | this[offset] = (value & 0xff)
|
2833 | this[offset + 1] = (value >>> 8)
|
2834 | return offset + 2
|
2835 | }
|
2836 |
|
2837 | Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
|
2838 | value = +value
|
2839 | offset = offset >>> 0
|
2840 | if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
|
2841 | this[offset] = (value >>> 8)
|
2842 | this[offset + 1] = (value & 0xff)
|
2843 | return offset + 2
|
2844 | }
|
2845 |
|
2846 | Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
|
2847 | value = +value
|
2848 | offset = offset >>> 0
|
2849 | if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
|
2850 | this[offset] = (value & 0xff)
|
2851 | this[offset + 1] = (value >>> 8)
|
2852 | this[offset + 2] = (value >>> 16)
|
2853 | this[offset + 3] = (value >>> 24)
|
2854 | return offset + 4
|
2855 | }
|
2856 |
|
2857 | Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
|
2858 | value = +value
|
2859 | offset = offset >>> 0
|
2860 | if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
|
2861 | if (value < 0) value = 0xffffffff + value + 1
|
2862 | this[offset] = (value >>> 24)
|
2863 | this[offset + 1] = (value >>> 16)
|
2864 | this[offset + 2] = (value >>> 8)
|
2865 | this[offset + 3] = (value & 0xff)
|
2866 | return offset + 4
|
2867 | }
|
2868 |
|
2869 | function checkIEEE754 (buf, value, offset, ext, max, min) {
|
2870 | if (offset + ext > buf.length) throw new RangeError('Index out of range')
|
2871 | if (offset < 0) throw new RangeError('Index out of range')
|
2872 | }
|
2873 |
|
2874 | function writeFloat (buf, value, offset, littleEndian, noAssert) {
|
2875 | value = +value
|
2876 | offset = offset >>> 0
|
2877 | if (!noAssert) {
|
2878 | checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
|
2879 | }
|
2880 | ieee754.write(buf, value, offset, littleEndian, 23, 4)
|
2881 | return offset + 4
|
2882 | }
|
2883 |
|
2884 | Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
|
2885 | return writeFloat(this, value, offset, true, noAssert)
|
2886 | }
|
2887 |
|
2888 | Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
|
2889 | return writeFloat(this, value, offset, false, noAssert)
|
2890 | }
|
2891 |
|
2892 | function writeDouble (buf, value, offset, littleEndian, noAssert) {
|
2893 | value = +value
|
2894 | offset = offset >>> 0
|
2895 | if (!noAssert) {
|
2896 | checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
|
2897 | }
|
2898 | ieee754.write(buf, value, offset, littleEndian, 52, 8)
|
2899 | return offset + 8
|
2900 | }
|
2901 |
|
2902 | Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
|
2903 | return writeDouble(this, value, offset, true, noAssert)
|
2904 | }
|
2905 |
|
2906 | Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
|
2907 | return writeDouble(this, value, offset, false, noAssert)
|
2908 | }
|
2909 |
|
2910 |
|
2911 | Buffer.prototype.copy = function copy (target, targetStart, start, end) {
|
2912 | if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer')
|
2913 | if (!start) start = 0
|
2914 | if (!end && end !== 0) end = this.length
|
2915 | if (targetStart >= target.length) targetStart = target.length
|
2916 | if (!targetStart) targetStart = 0
|
2917 | if (end > 0 && end < start) end = start
|
2918 |
|
2919 |
|
2920 | if (end === start) return 0
|
2921 | if (target.length === 0 || this.length === 0) return 0
|
2922 |
|
2923 |
|
2924 | if (targetStart < 0) {
|
2925 | throw new RangeError('targetStart out of bounds')
|
2926 | }
|
2927 | if (start < 0 || start >= this.length) throw new RangeError('Index out of range')
|
2928 | if (end < 0) throw new RangeError('sourceEnd out of bounds')
|
2929 |
|
2930 |
|
2931 | if (end > this.length) end = this.length
|
2932 | if (target.length - targetStart < end - start) {
|
2933 | end = target.length - targetStart + start
|
2934 | }
|
2935 |
|
2936 | var len = end - start
|
2937 |
|
2938 | if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {
|
2939 |
|
2940 | this.copyWithin(targetStart, start, end)
|
2941 | } else if (this === target && start < targetStart && targetStart < end) {
|
2942 |
|
2943 | for (var i = len - 1; i >= 0; --i) {
|
2944 | target[i + targetStart] = this[i + start]
|
2945 | }
|
2946 | } else {
|
2947 | Uint8Array.prototype.set.call(
|
2948 | target,
|
2949 | this.subarray(start, end),
|
2950 | targetStart
|
2951 | )
|
2952 | }
|
2953 |
|
2954 | return len
|
2955 | }
|
2956 |
|
2957 |
|
2958 |
|
2959 |
|
2960 |
|
2961 | Buffer.prototype.fill = function fill (val, start, end, encoding) {
|
2962 |
|
2963 | if (typeof val === 'string') {
|
2964 | if (typeof start === 'string') {
|
2965 | encoding = start
|
2966 | start = 0
|
2967 | end = this.length
|
2968 | } else if (typeof end === 'string') {
|
2969 | encoding = end
|
2970 | end = this.length
|
2971 | }
|
2972 | if (encoding !== undefined && typeof encoding !== 'string') {
|
2973 | throw new TypeError('encoding must be a string')
|
2974 | }
|
2975 | if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
|
2976 | throw new TypeError('Unknown encoding: ' + encoding)
|
2977 | }
|
2978 | if (val.length === 1) {
|
2979 | var code = val.charCodeAt(0)
|
2980 | if ((encoding === 'utf8' && code < 128) ||
|
2981 | encoding === 'latin1') {
|
2982 |
|
2983 | val = code
|
2984 | }
|
2985 | }
|
2986 | } else if (typeof val === 'number') {
|
2987 | val = val & 255
|
2988 | } else if (typeof val === 'boolean') {
|
2989 | val = Number(val)
|
2990 | }
|
2991 |
|
2992 |
|
2993 | if (start < 0 || this.length < start || this.length < end) {
|
2994 | throw new RangeError('Out of range index')
|
2995 | }
|
2996 |
|
2997 | if (end <= start) {
|
2998 | return this
|
2999 | }
|
3000 |
|
3001 | start = start >>> 0
|
3002 | end = end === undefined ? this.length : end >>> 0
|
3003 |
|
3004 | if (!val) val = 0
|
3005 |
|
3006 | var i
|
3007 | if (typeof val === 'number') {
|
3008 | for (i = start; i < end; ++i) {
|
3009 | this[i] = val
|
3010 | }
|
3011 | } else {
|
3012 | var bytes = Buffer.isBuffer(val)
|
3013 | ? val
|
3014 | : Buffer.from(val, encoding)
|
3015 | var len = bytes.length
|
3016 | if (len === 0) {
|
3017 | throw new TypeError('The value "' + val +
|
3018 | '" is invalid for argument "value"')
|
3019 | }
|
3020 | for (i = 0; i < end - start; ++i) {
|
3021 | this[i + start] = bytes[i % len]
|
3022 | }
|
3023 | }
|
3024 |
|
3025 | return this
|
3026 | }
|
3027 |
|
3028 |
|
3029 |
|
3030 |
|
3031 | var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g
|
3032 |
|
3033 | function base64clean (str) {
|
3034 |
|
3035 | str = str.split('=')[0]
|
3036 |
|
3037 | str = str.trim().replace(INVALID_BASE64_RE, '')
|
3038 |
|
3039 | if (str.length < 2) return ''
|
3040 |
|
3041 | while (str.length % 4 !== 0) {
|
3042 | str = str + '='
|
3043 | }
|
3044 | return str
|
3045 | }
|
3046 |
|
3047 | function utf8ToBytes (string, units) {
|
3048 | units = units || Infinity
|
3049 | var codePoint
|
3050 | var length = string.length
|
3051 | var leadSurrogate = null
|
3052 | var bytes = []
|
3053 |
|
3054 | for (var i = 0; i < length; ++i) {
|
3055 | codePoint = string.charCodeAt(i)
|
3056 |
|
3057 |
|
3058 | if (codePoint > 0xD7FF && codePoint < 0xE000) {
|
3059 |
|
3060 | if (!leadSurrogate) {
|
3061 |
|
3062 | if (codePoint > 0xDBFF) {
|
3063 |
|
3064 | if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
|
3065 | continue
|
3066 | } else if (i + 1 === length) {
|
3067 |
|
3068 | if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
|
3069 | continue
|
3070 | }
|
3071 |
|
3072 |
|
3073 | leadSurrogate = codePoint
|
3074 |
|
3075 | continue
|
3076 | }
|
3077 |
|
3078 |
|
3079 | if (codePoint < 0xDC00) {
|
3080 | if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
|
3081 | leadSurrogate = codePoint
|
3082 | continue
|
3083 | }
|
3084 |
|
3085 |
|
3086 | codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000
|
3087 | } else if (leadSurrogate) {
|
3088 |
|
3089 | if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
|
3090 | }
|
3091 |
|
3092 | leadSurrogate = null
|
3093 |
|
3094 |
|
3095 | if (codePoint < 0x80) {
|
3096 | if ((units -= 1) < 0) break
|
3097 | bytes.push(codePoint)
|
3098 | } else if (codePoint < 0x800) {
|
3099 | if ((units -= 2) < 0) break
|
3100 | bytes.push(
|
3101 | codePoint >> 0x6 | 0xC0,
|
3102 | codePoint & 0x3F | 0x80
|
3103 | )
|
3104 | } else if (codePoint < 0x10000) {
|
3105 | if ((units -= 3) < 0) break
|
3106 | bytes.push(
|
3107 | codePoint >> 0xC | 0xE0,
|
3108 | codePoint >> 0x6 & 0x3F | 0x80,
|
3109 | codePoint & 0x3F | 0x80
|
3110 | )
|
3111 | } else if (codePoint < 0x110000) {
|
3112 | if ((units -= 4) < 0) break
|
3113 | bytes.push(
|
3114 | codePoint >> 0x12 | 0xF0,
|
3115 | codePoint >> 0xC & 0x3F | 0x80,
|
3116 | codePoint >> 0x6 & 0x3F | 0x80,
|
3117 | codePoint & 0x3F | 0x80
|
3118 | )
|
3119 | } else {
|
3120 | throw new Error('Invalid code point')
|
3121 | }
|
3122 | }
|
3123 |
|
3124 | return bytes
|
3125 | }
|
3126 |
|
3127 | function asciiToBytes (str) {
|
3128 | var byteArray = []
|
3129 | for (var i = 0; i < str.length; ++i) {
|
3130 |
|
3131 | byteArray.push(str.charCodeAt(i) & 0xFF)
|
3132 | }
|
3133 | return byteArray
|
3134 | }
|
3135 |
|
3136 | function utf16leToBytes (str, units) {
|
3137 | var c, hi, lo
|
3138 | var byteArray = []
|
3139 | for (var i = 0; i < str.length; ++i) {
|
3140 | if ((units -= 2) < 0) break
|
3141 |
|
3142 | c = str.charCodeAt(i)
|
3143 | hi = c >> 8
|
3144 | lo = c % 256
|
3145 | byteArray.push(lo)
|
3146 | byteArray.push(hi)
|
3147 | }
|
3148 |
|
3149 | return byteArray
|
3150 | }
|
3151 |
|
3152 | function base64ToBytes (str) {
|
3153 | return base64.toByteArray(base64clean(str))
|
3154 | }
|
3155 |
|
3156 | function blitBuffer (src, dst, offset, length) {
|
3157 | for (var i = 0; i < length; ++i) {
|
3158 | if ((i + offset >= dst.length) || (i >= src.length)) break
|
3159 | dst[i + offset] = src[i]
|
3160 | }
|
3161 | return i
|
3162 | }
|
3163 |
|
3164 |
|
3165 |
|
3166 |
|
3167 | function isInstance (obj, type) {
|
3168 | return obj instanceof type ||
|
3169 | (obj != null && obj.constructor != null && obj.constructor.name != null &&
|
3170 | obj.constructor.name === type.name)
|
3171 | }
|
3172 | function numberIsNaN (obj) {
|
3173 |
|
3174 | return obj !== obj
|
3175 | }
|
3176 |
|
3177 |
|
3178 |
|
3179 | var hexSliceLookupTable = (function () {
|
3180 | var alphabet = '0123456789abcdef'
|
3181 | var table = new Array(256)
|
3182 | for (var i = 0; i < 16; ++i) {
|
3183 | var i16 = i * 16
|
3184 | for (var j = 0; j < 16; ++j) {
|
3185 | table[i16 + j] = alphabet[i] + alphabet[j]
|
3186 | }
|
3187 | }
|
3188 | return table
|
3189 | })()
|
3190 |
|
3191 | }).call(this,_dereq_(9).Buffer)
|
3192 | },{"16":16,"6":6,"9":9}],10:[function(_dereq_,module,exports){
|
3193 | (function (Buffer){
|
3194 |
|
3195 |
|
3196 |
|
3197 |
|
3198 |
|
3199 |
|
3200 |
|
3201 |
|
3202 |
|
3203 |
|
3204 |
|
3205 |
|
3206 |
|
3207 |
|
3208 |
|
3209 |
|
3210 |
|
3211 |
|
3212 |
|
3213 |
|
3214 |
|
3215 |
|
3216 |
|
3217 |
|
3218 | function isArray(arg) {
|
3219 | if (Array.isArray) {
|
3220 | return Array.isArray(arg);
|
3221 | }
|
3222 | return objectToString(arg) === '[object Array]';
|
3223 | }
|
3224 | exports.isArray = isArray;
|
3225 |
|
3226 | function isBoolean(arg) {
|
3227 | return typeof arg === 'boolean';
|
3228 | }
|
3229 | exports.isBoolean = isBoolean;
|
3230 |
|
3231 | function isNull(arg) {
|
3232 | return arg === null;
|
3233 | }
|
3234 | exports.isNull = isNull;
|
3235 |
|
3236 | function isNullOrUndefined(arg) {
|
3237 | return arg == null;
|
3238 | }
|
3239 | exports.isNullOrUndefined = isNullOrUndefined;
|
3240 |
|
3241 | function isNumber(arg) {
|
3242 | return typeof arg === 'number';
|
3243 | }
|
3244 | exports.isNumber = isNumber;
|
3245 |
|
3246 | function isString(arg) {
|
3247 | return typeof arg === 'string';
|
3248 | }
|
3249 | exports.isString = isString;
|
3250 |
|
3251 | function isSymbol(arg) {
|
3252 | return typeof arg === 'symbol';
|
3253 | }
|
3254 | exports.isSymbol = isSymbol;
|
3255 |
|
3256 | function isUndefined(arg) {
|
3257 | return arg === void 0;
|
3258 | }
|
3259 | exports.isUndefined = isUndefined;
|
3260 |
|
3261 | function isRegExp(re) {
|
3262 | return objectToString(re) === '[object RegExp]';
|
3263 | }
|
3264 | exports.isRegExp = isRegExp;
|
3265 |
|
3266 | function isObject(arg) {
|
3267 | return typeof arg === 'object' && arg !== null;
|
3268 | }
|
3269 | exports.isObject = isObject;
|
3270 |
|
3271 | function isDate(d) {
|
3272 | return objectToString(d) === '[object Date]';
|
3273 | }
|
3274 | exports.isDate = isDate;
|
3275 |
|
3276 | function isError(e) {
|
3277 | return (objectToString(e) === '[object Error]' || e instanceof Error);
|
3278 | }
|
3279 | exports.isError = isError;
|
3280 |
|
3281 | function isFunction(arg) {
|
3282 | return typeof arg === 'function';
|
3283 | }
|
3284 | exports.isFunction = isFunction;
|
3285 |
|
3286 | function isPrimitive(arg) {
|
3287 | return arg === null ||
|
3288 | typeof arg === 'boolean' ||
|
3289 | typeof arg === 'number' ||
|
3290 | typeof arg === 'string' ||
|
3291 | typeof arg === 'symbol' ||
|
3292 | typeof arg === 'undefined';
|
3293 | }
|
3294 | exports.isPrimitive = isPrimitive;
|
3295 |
|
3296 | exports.isBuffer = Buffer.isBuffer;
|
3297 |
|
3298 | function objectToString(o) {
|
3299 | return Object.prototype.toString.call(o);
|
3300 | }
|
3301 |
|
3302 | }).call(this,{"isBuffer":_dereq_(19)})
|
3303 | },{"19":19}],11:[function(_dereq_,module,exports){
|
3304 |
|
3305 |
|
3306 |
|
3307 |
|
3308 |
|
3309 |
|
3310 |
|
3311 |
|
3312 |
|
3313 |
|
3314 |
|
3315 |
|
3316 |
|
3317 |
|
3318 |
|
3319 |
|
3320 |
|
3321 |
|
3322 |
|
3323 |
|
3324 |
|
3325 | "use strict";
|
3326 | function Deque(capacity) {
|
3327 | this._capacity = getCapacity(capacity);
|
3328 | this._length = 0;
|
3329 | this._front = 0;
|
3330 | if (isArray(capacity)) {
|
3331 | var len = capacity.length;
|
3332 | for (var i = 0; i < len; ++i) {
|
3333 | this[i] = capacity[i];
|
3334 | }
|
3335 | this._length = len;
|
3336 | }
|
3337 | }
|
3338 |
|
3339 | Deque.prototype.toArray = function Deque$toArray() {
|
3340 | var len = this._length;
|
3341 | var ret = new Array(len);
|
3342 | var front = this._front;
|
3343 | var capacity = this._capacity;
|
3344 | for (var j = 0; j < len; ++j) {
|
3345 | ret[j] = this[(front + j) & (capacity - 1)];
|
3346 | }
|
3347 | return ret;
|
3348 | };
|
3349 |
|
3350 | Deque.prototype.push = function Deque$push(item) {
|
3351 | var argsLength = arguments.length;
|
3352 | var length = this._length;
|
3353 | if (argsLength > 1) {
|
3354 | var capacity = this._capacity;
|
3355 | if (length + argsLength > capacity) {
|
3356 | for (var i = 0; i < argsLength; ++i) {
|
3357 | this._checkCapacity(length + 1);
|
3358 | var j = (this._front + length) & (this._capacity - 1);
|
3359 | this[j] = arguments[i];
|
3360 | length++;
|
3361 | this._length = length;
|
3362 | }
|
3363 | return length;
|
3364 | }
|
3365 | else {
|
3366 | var j = this._front;
|
3367 | for (var i = 0; i < argsLength; ++i) {
|
3368 | this[(j + length) & (capacity - 1)] = arguments[i];
|
3369 | j++;
|
3370 | }
|
3371 | this._length = length + argsLength;
|
3372 | return length + argsLength;
|
3373 | }
|
3374 |
|
3375 | }
|
3376 |
|
3377 | if (argsLength === 0) return length;
|
3378 |
|
3379 | this._checkCapacity(length + 1);
|
3380 | var i = (this._front + length) & (this._capacity - 1);
|
3381 | this[i] = item;
|
3382 | this._length = length + 1;
|
3383 | return length + 1;
|
3384 | };
|
3385 |
|
3386 | Deque.prototype.pop = function Deque$pop() {
|
3387 | var length = this._length;
|
3388 | if (length === 0) {
|
3389 | return void 0;
|
3390 | }
|
3391 | var i = (this._front + length - 1) & (this._capacity - 1);
|
3392 | var ret = this[i];
|
3393 | this[i] = void 0;
|
3394 | this._length = length - 1;
|
3395 | return ret;
|
3396 | };
|
3397 |
|
3398 | Deque.prototype.shift = function Deque$shift() {
|
3399 | var length = this._length;
|
3400 | if (length === 0) {
|
3401 | return void 0;
|
3402 | }
|
3403 | var front = this._front;
|
3404 | var ret = this[front];
|
3405 | this[front] = void 0;
|
3406 | this._front = (front + 1) & (this._capacity - 1);
|
3407 | this._length = length - 1;
|
3408 | return ret;
|
3409 | };
|
3410 |
|
3411 | Deque.prototype.unshift = function Deque$unshift(item) {
|
3412 | var length = this._length;
|
3413 | var argsLength = arguments.length;
|
3414 |
|
3415 |
|
3416 | if (argsLength > 1) {
|
3417 | var capacity = this._capacity;
|
3418 | if (length + argsLength > capacity) {
|
3419 | for (var i = argsLength - 1; i >= 0; i--) {
|
3420 | this._checkCapacity(length + 1);
|
3421 | var capacity = this._capacity;
|
3422 | var j = (((( this._front - 1 ) &
|
3423 | ( capacity - 1) ) ^ capacity ) - capacity );
|
3424 | this[j] = arguments[i];
|
3425 | length++;
|
3426 | this._length = length;
|
3427 | this._front = j;
|
3428 | }
|
3429 | return length;
|
3430 | }
|
3431 | else {
|
3432 | var front = this._front;
|
3433 | for (var i = argsLength - 1; i >= 0; i--) {
|
3434 | var j = (((( front - 1 ) &
|
3435 | ( capacity - 1) ) ^ capacity ) - capacity );
|
3436 | this[j] = arguments[i];
|
3437 | front = j;
|
3438 | }
|
3439 | this._front = front;
|
3440 | this._length = length + argsLength;
|
3441 | return length + argsLength;
|
3442 | }
|
3443 | }
|
3444 |
|
3445 | if (argsLength === 0) return length;
|
3446 |
|
3447 | this._checkCapacity(length + 1);
|
3448 | var capacity = this._capacity;
|
3449 | var i = (((( this._front - 1 ) &
|
3450 | ( capacity - 1) ) ^ capacity ) - capacity );
|
3451 | this[i] = item;
|
3452 | this._length = length + 1;
|
3453 | this._front = i;
|
3454 | return length + 1;
|
3455 | };
|
3456 |
|
3457 | Deque.prototype.peekBack = function Deque$peekBack() {
|
3458 | var length = this._length;
|
3459 | if (length === 0) {
|
3460 | return void 0;
|
3461 | }
|
3462 | var index = (this._front + length - 1) & (this._capacity - 1);
|
3463 | return this[index];
|
3464 | };
|
3465 |
|
3466 | Deque.prototype.peekFront = function Deque$peekFront() {
|
3467 | if (this._length === 0) {
|
3468 | return void 0;
|
3469 | }
|
3470 | return this[this._front];
|
3471 | };
|
3472 |
|
3473 | Deque.prototype.get = function Deque$get(index) {
|
3474 | var i = index;
|
3475 | if ((i !== (i | 0))) {
|
3476 | return void 0;
|
3477 | }
|
3478 | var len = this._length;
|
3479 | if (i < 0) {
|
3480 | i = i + len;
|
3481 | }
|
3482 | if (i < 0 || i >= len) {
|
3483 | return void 0;
|
3484 | }
|
3485 | return this[(this._front + i) & (this._capacity - 1)];
|
3486 | };
|
3487 |
|
3488 | Deque.prototype.isEmpty = function Deque$isEmpty() {
|
3489 | return this._length === 0;
|
3490 | };
|
3491 |
|
3492 | Deque.prototype.clear = function Deque$clear() {
|
3493 | var len = this._length;
|
3494 | var front = this._front;
|
3495 | var capacity = this._capacity;
|
3496 | for (var j = 0; j < len; ++j) {
|
3497 | this[(front + j) & (capacity - 1)] = void 0;
|
3498 | }
|
3499 | this._length = 0;
|
3500 | this._front = 0;
|
3501 | };
|
3502 |
|
3503 | Deque.prototype.toString = function Deque$toString() {
|
3504 | return this.toArray().toString();
|
3505 | };
|
3506 |
|
3507 | Deque.prototype.valueOf = Deque.prototype.toString;
|
3508 | Deque.prototype.removeFront = Deque.prototype.shift;
|
3509 | Deque.prototype.removeBack = Deque.prototype.pop;
|
3510 | Deque.prototype.insertFront = Deque.prototype.unshift;
|
3511 | Deque.prototype.insertBack = Deque.prototype.push;
|
3512 | Deque.prototype.enqueue = Deque.prototype.push;
|
3513 | Deque.prototype.dequeue = Deque.prototype.shift;
|
3514 | Deque.prototype.toJSON = Deque.prototype.toArray;
|
3515 |
|
3516 | Object.defineProperty(Deque.prototype, "length", {
|
3517 | get: function() {
|
3518 | return this._length;
|
3519 | },
|
3520 | set: function() {
|
3521 | throw new RangeError("");
|
3522 | }
|
3523 | });
|
3524 |
|
3525 | Deque.prototype._checkCapacity = function Deque$_checkCapacity(size) {
|
3526 | if (this._capacity < size) {
|
3527 | this._resizeTo(getCapacity(this._capacity * 1.5 + 16));
|
3528 | }
|
3529 | };
|
3530 |
|
3531 | Deque.prototype._resizeTo = function Deque$_resizeTo(capacity) {
|
3532 | var oldCapacity = this._capacity;
|
3533 | this._capacity = capacity;
|
3534 | var front = this._front;
|
3535 | var length = this._length;
|
3536 | if (front + length > oldCapacity) {
|
3537 | var moveItemsCount = (front + length) & (oldCapacity - 1);
|
3538 | arrayMove(this, 0, this, oldCapacity, moveItemsCount);
|
3539 | }
|
3540 | };
|
3541 |
|
3542 |
|
3543 | var isArray = Array.isArray;
|
3544 |
|
3545 | function arrayMove(src, srcIndex, dst, dstIndex, len) {
|
3546 | for (var j = 0; j < len; ++j) {
|
3547 | dst[j + dstIndex] = src[j + srcIndex];
|
3548 | src[j + srcIndex] = void 0;
|
3549 | }
|
3550 | }
|
3551 |
|
3552 | function pow2AtLeast(n) {
|
3553 | n = n >>> 0;
|
3554 | n = n - 1;
|
3555 | n = n | (n >> 1);
|
3556 | n = n | (n >> 2);
|
3557 | n = n | (n >> 4);
|
3558 | n = n | (n >> 8);
|
3559 | n = n | (n >> 16);
|
3560 | return n + 1;
|
3561 | }
|
3562 |
|
3563 | function getCapacity(capacity) {
|
3564 | if (typeof capacity !== "number") {
|
3565 | if (isArray(capacity)) {
|
3566 | capacity = capacity.length;
|
3567 | }
|
3568 | else {
|
3569 | return 16;
|
3570 | }
|
3571 | }
|
3572 | return pow2AtLeast(
|
3573 | Math.min(
|
3574 | Math.max(16, capacity), 1073741824)
|
3575 | );
|
3576 | }
|
3577 |
|
3578 | module.exports = Deque;
|
3579 |
|
3580 | },{}],12:[function(_dereq_,module,exports){
|
3581 | var prr = _dereq_(71)
|
3582 |
|
3583 | function init (type, message, cause) {
|
3584 | if (!!message && typeof message != 'string') {
|
3585 | message = message.message || message.name
|
3586 | }
|
3587 | prr(this, {
|
3588 | type : type
|
3589 | , name : type
|
3590 |
|
3591 | , cause : typeof message != 'string' ? message : cause
|
3592 | , message : message
|
3593 | }, 'ewr')
|
3594 | }
|
3595 |
|
3596 |
|
3597 | function CustomError (message, cause) {
|
3598 | Error.call(this)
|
3599 | if (Error.captureStackTrace)
|
3600 | Error.captureStackTrace(this, this.constructor)
|
3601 | init.call(this, 'CustomError', message, cause)
|
3602 | }
|
3603 |
|
3604 | CustomError.prototype = new Error()
|
3605 |
|
3606 | function createError (errno, type, proto) {
|
3607 | var err = function (message, cause) {
|
3608 | init.call(this, type, message, cause)
|
3609 |
|
3610 | if (type == 'FilesystemError') {
|
3611 | this.code = this.cause.code
|
3612 | this.path = this.cause.path
|
3613 | this.errno = this.cause.errno
|
3614 | this.message =
|
3615 | (errno.errno[this.cause.errno]
|
3616 | ? errno.errno[this.cause.errno].description
|
3617 | : this.cause.message)
|
3618 | + (this.cause.path ? ' [' + this.cause.path + ']' : '')
|
3619 | }
|
3620 | Error.call(this)
|
3621 | if (Error.captureStackTrace)
|
3622 | Error.captureStackTrace(this, err)
|
3623 | }
|
3624 | err.prototype = !!proto ? new proto() : new CustomError()
|
3625 | return err
|
3626 | }
|
3627 |
|
3628 | module.exports = function (errno) {
|
3629 | var ce = function (type, proto) {
|
3630 | return createError(errno, type, proto)
|
3631 | }
|
3632 | return {
|
3633 | CustomError : CustomError
|
3634 | , FilesystemError : ce('FilesystemError')
|
3635 | , createError : ce
|
3636 | }
|
3637 | }
|
3638 |
|
3639 | },{"71":71}],13:[function(_dereq_,module,exports){
|
3640 | var all = module.exports.all = [
|
3641 | {
|
3642 | errno: -2,
|
3643 | code: 'ENOENT',
|
3644 | description: 'no such file or directory'
|
3645 | },
|
3646 | {
|
3647 | errno: -1,
|
3648 | code: 'UNKNOWN',
|
3649 | description: 'unknown error'
|
3650 | },
|
3651 | {
|
3652 | errno: 0,
|
3653 | code: 'OK',
|
3654 | description: 'success'
|
3655 | },
|
3656 | {
|
3657 | errno: 1,
|
3658 | code: 'EOF',
|
3659 | description: 'end of file'
|
3660 | },
|
3661 | {
|
3662 | errno: 2,
|
3663 | code: 'EADDRINFO',
|
3664 | description: 'getaddrinfo error'
|
3665 | },
|
3666 | {
|
3667 | errno: 3,
|
3668 | code: 'EACCES',
|
3669 | description: 'permission denied'
|
3670 | },
|
3671 | {
|
3672 | errno: 4,
|
3673 | code: 'EAGAIN',
|
3674 | description: 'resource temporarily unavailable'
|
3675 | },
|
3676 | {
|
3677 | errno: 5,
|
3678 | code: 'EADDRINUSE',
|
3679 | description: 'address already in use'
|
3680 | },
|
3681 | {
|
3682 | errno: 6,
|
3683 | code: 'EADDRNOTAVAIL',
|
3684 | description: 'address not available'
|
3685 | },
|
3686 | {
|
3687 | errno: 7,
|
3688 | code: 'EAFNOSUPPORT',
|
3689 | description: 'address family not supported'
|
3690 | },
|
3691 | {
|
3692 | errno: 8,
|
3693 | code: 'EALREADY',
|
3694 | description: 'connection already in progress'
|
3695 | },
|
3696 | {
|
3697 | errno: 9,
|
3698 | code: 'EBADF',
|
3699 | description: 'bad file descriptor'
|
3700 | },
|
3701 | {
|
3702 | errno: 10,
|
3703 | code: 'EBUSY',
|
3704 | description: 'resource busy or locked'
|
3705 | },
|
3706 | {
|
3707 | errno: 11,
|
3708 | code: 'ECONNABORTED',
|
3709 | description: 'software caused connection abort'
|
3710 | },
|
3711 | {
|
3712 | errno: 12,
|
3713 | code: 'ECONNREFUSED',
|
3714 | description: 'connection refused'
|
3715 | },
|
3716 | {
|
3717 | errno: 13,
|
3718 | code: 'ECONNRESET',
|
3719 | description: 'connection reset by peer'
|
3720 | },
|
3721 | {
|
3722 | errno: 14,
|
3723 | code: 'EDESTADDRREQ',
|
3724 | description: 'destination address required'
|
3725 | },
|
3726 | {
|
3727 | errno: 15,
|
3728 | code: 'EFAULT',
|
3729 | description: 'bad address in system call argument'
|
3730 | },
|
3731 | {
|
3732 | errno: 16,
|
3733 | code: 'EHOSTUNREACH',
|
3734 | description: 'host is unreachable'
|
3735 | },
|
3736 | {
|
3737 | errno: 17,
|
3738 | code: 'EINTR',
|
3739 | description: 'interrupted system call'
|
3740 | },
|
3741 | {
|
3742 | errno: 18,
|
3743 | code: 'EINVAL',
|
3744 | description: 'invalid argument'
|
3745 | },
|
3746 | {
|
3747 | errno: 19,
|
3748 | code: 'EISCONN',
|
3749 | description: 'socket is already connected'
|
3750 | },
|
3751 | {
|
3752 | errno: 20,
|
3753 | code: 'EMFILE',
|
3754 | description: 'too many open files'
|
3755 | },
|
3756 | {
|
3757 | errno: 21,
|
3758 | code: 'EMSGSIZE',
|
3759 | description: 'message too long'
|
3760 | },
|
3761 | {
|
3762 | errno: 22,
|
3763 | code: 'ENETDOWN',
|
3764 | description: 'network is down'
|
3765 | },
|
3766 | {
|
3767 | errno: 23,
|
3768 | code: 'ENETUNREACH',
|
3769 | description: 'network is unreachable'
|
3770 | },
|
3771 | {
|
3772 | errno: 24,
|
3773 | code: 'ENFILE',
|
3774 | description: 'file table overflow'
|
3775 | },
|
3776 | {
|
3777 | errno: 25,
|
3778 | code: 'ENOBUFS',
|
3779 | description: 'no buffer space available'
|
3780 | },
|
3781 | {
|
3782 | errno: 26,
|
3783 | code: 'ENOMEM',
|
3784 | description: 'not enough memory'
|
3785 | },
|
3786 | {
|
3787 | errno: 27,
|
3788 | code: 'ENOTDIR',
|
3789 | description: 'not a directory'
|
3790 | },
|
3791 | {
|
3792 | errno: 28,
|
3793 | code: 'EISDIR',
|
3794 | description: 'illegal operation on a directory'
|
3795 | },
|
3796 | {
|
3797 | errno: 29,
|
3798 | code: 'ENONET',
|
3799 | description: 'machine is not on the network'
|
3800 | },
|
3801 | {
|
3802 | errno: 31,
|
3803 | code: 'ENOTCONN',
|
3804 | description: 'socket is not connected'
|
3805 | },
|
3806 | {
|
3807 | errno: 32,
|
3808 | code: 'ENOTSOCK',
|
3809 | description: 'socket operation on non-socket'
|
3810 | },
|
3811 | {
|
3812 | errno: 33,
|
3813 | code: 'ENOTSUP',
|
3814 | description: 'operation not supported on socket'
|
3815 | },
|
3816 | {
|
3817 | errno: 34,
|
3818 | code: 'ENOENT',
|
3819 | description: 'no such file or directory'
|
3820 | },
|
3821 | {
|
3822 | errno: 35,
|
3823 | code: 'ENOSYS',
|
3824 | description: 'function not implemented'
|
3825 | },
|
3826 | {
|
3827 | errno: 36,
|
3828 | code: 'EPIPE',
|
3829 | description: 'broken pipe'
|
3830 | },
|
3831 | {
|
3832 | errno: 37,
|
3833 | code: 'EPROTO',
|
3834 | description: 'protocol error'
|
3835 | },
|
3836 | {
|
3837 | errno: 38,
|
3838 | code: 'EPROTONOSUPPORT',
|
3839 | description: 'protocol not supported'
|
3840 | },
|
3841 | {
|
3842 | errno: 39,
|
3843 | code: 'EPROTOTYPE',
|
3844 | description: 'protocol wrong type for socket'
|
3845 | },
|
3846 | {
|
3847 | errno: 40,
|
3848 | code: 'ETIMEDOUT',
|
3849 | description: 'connection timed out'
|
3850 | },
|
3851 | {
|
3852 | errno: 41,
|
3853 | code: 'ECHARSET',
|
3854 | description: 'invalid Unicode character'
|
3855 | },
|
3856 | {
|
3857 | errno: 42,
|
3858 | code: 'EAIFAMNOSUPPORT',
|
3859 | description: 'address family for hostname not supported'
|
3860 | },
|
3861 | {
|
3862 | errno: 44,
|
3863 | code: 'EAISERVICE',
|
3864 | description: 'servname not supported for ai_socktype'
|
3865 | },
|
3866 | {
|
3867 | errno: 45,
|
3868 | code: 'EAISOCKTYPE',
|
3869 | description: 'ai_socktype not supported'
|
3870 | },
|
3871 | {
|
3872 | errno: 46,
|
3873 | code: 'ESHUTDOWN',
|
3874 | description: 'cannot send after transport endpoint shutdown'
|
3875 | },
|
3876 | {
|
3877 | errno: 47,
|
3878 | code: 'EEXIST',
|
3879 | description: 'file already exists'
|
3880 | },
|
3881 | {
|
3882 | errno: 48,
|
3883 | code: 'ESRCH',
|
3884 | description: 'no such process'
|
3885 | },
|
3886 | {
|
3887 | errno: 49,
|
3888 | code: 'ENAMETOOLONG',
|
3889 | description: 'name too long'
|
3890 | },
|
3891 | {
|
3892 | errno: 50,
|
3893 | code: 'EPERM',
|
3894 | description: 'operation not permitted'
|
3895 | },
|
3896 | {
|
3897 | errno: 51,
|
3898 | code: 'ELOOP',
|
3899 | description: 'too many symbolic links encountered'
|
3900 | },
|
3901 | {
|
3902 | errno: 52,
|
3903 | code: 'EXDEV',
|
3904 | description: 'cross-device link not permitted'
|
3905 | },
|
3906 | {
|
3907 | errno: 53,
|
3908 | code: 'ENOTEMPTY',
|
3909 | description: 'directory not empty'
|
3910 | },
|
3911 | {
|
3912 | errno: 54,
|
3913 | code: 'ENOSPC',
|
3914 | description: 'no space left on device'
|
3915 | },
|
3916 | {
|
3917 | errno: 55,
|
3918 | code: 'EIO',
|
3919 | description: 'i/o error'
|
3920 | },
|
3921 | {
|
3922 | errno: 56,
|
3923 | code: 'EROFS',
|
3924 | description: 'read-only file system'
|
3925 | },
|
3926 | {
|
3927 | errno: 57,
|
3928 | code: 'ENODEV',
|
3929 | description: 'no such device'
|
3930 | },
|
3931 | {
|
3932 | errno: 58,
|
3933 | code: 'ESPIPE',
|
3934 | description: 'invalid seek'
|
3935 | },
|
3936 | {
|
3937 | errno: 59,
|
3938 | code: 'ECANCELED',
|
3939 | description: 'operation canceled'
|
3940 | }
|
3941 | ]
|
3942 |
|
3943 | module.exports.errno = {}
|
3944 | module.exports.code = {}
|
3945 |
|
3946 | all.forEach(function (error) {
|
3947 | module.exports.errno[error.errno] = error
|
3948 | module.exports.code[error.code] = error
|
3949 | })
|
3950 |
|
3951 | module.exports.custom = _dereq_(12)(module.exports)
|
3952 | module.exports.create = module.exports.custom.createError
|
3953 |
|
3954 | },{"12":12}],14:[function(_dereq_,module,exports){
|
3955 |
|
3956 |
|
3957 |
|
3958 |
|
3959 |
|
3960 |
|
3961 |
|
3962 |
|
3963 |
|
3964 |
|
3965 |
|
3966 |
|
3967 |
|
3968 |
|
3969 |
|
3970 |
|
3971 |
|
3972 |
|
3973 |
|
3974 |
|
3975 |
|
3976 | var objectCreate = Object.create || objectCreatePolyfill
|
3977 | var objectKeys = Object.keys || objectKeysPolyfill
|
3978 | var bind = Function.prototype.bind || functionBindPolyfill
|
3979 |
|
3980 | function EventEmitter() {
|
3981 | if (!this._events || !Object.prototype.hasOwnProperty.call(this, '_events')) {
|
3982 | this._events = objectCreate(null);
|
3983 | this._eventsCount = 0;
|
3984 | }
|
3985 |
|
3986 | this._maxListeners = this._maxListeners || undefined;
|
3987 | }
|
3988 | module.exports = EventEmitter;
|
3989 |
|
3990 |
|
3991 | EventEmitter.EventEmitter = EventEmitter;
|
3992 |
|
3993 | EventEmitter.prototype._events = undefined;
|
3994 | EventEmitter.prototype._maxListeners = undefined;
|
3995 |
|
3996 |
|
3997 |
|
3998 | var defaultMaxListeners = 10;
|
3999 |
|
4000 | var hasDefineProperty;
|
4001 | try {
|
4002 | var o = {};
|
4003 | if (Object.defineProperty) Object.defineProperty(o, 'x', { value: 0 });
|
4004 | hasDefineProperty = o.x === 0;
|
4005 | } catch (err) { hasDefineProperty = false }
|
4006 | if (hasDefineProperty) {
|
4007 | Object.defineProperty(EventEmitter, 'defaultMaxListeners', {
|
4008 | enumerable: true,
|
4009 | get: function() {
|
4010 | return defaultMaxListeners;
|
4011 | },
|
4012 | set: function(arg) {
|
4013 |
|
4014 |
|
4015 | if (typeof arg !== 'number' || arg < 0 || arg !== arg)
|
4016 | throw new TypeError('"defaultMaxListeners" must be a positive number');
|
4017 | defaultMaxListeners = arg;
|
4018 | }
|
4019 | });
|
4020 | } else {
|
4021 | EventEmitter.defaultMaxListeners = defaultMaxListeners;
|
4022 | }
|
4023 |
|
4024 |
|
4025 |
|
4026 | EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
|
4027 | if (typeof n !== 'number' || n < 0 || isNaN(n))
|
4028 | throw new TypeError('"n" argument must be a positive number');
|
4029 | this._maxListeners = n;
|
4030 | return this;
|
4031 | };
|
4032 |
|
4033 | function $getMaxListeners(that) {
|
4034 | if (that._maxListeners === undefined)
|
4035 | return EventEmitter.defaultMaxListeners;
|
4036 | return that._maxListeners;
|
4037 | }
|
4038 |
|
4039 | EventEmitter.prototype.getMaxListeners = function getMaxListeners() {
|
4040 | return $getMaxListeners(this);
|
4041 | };
|
4042 |
|
4043 |
|
4044 |
|
4045 |
|
4046 |
|
4047 |
|
4048 | function emitNone(handler, isFn, self) {
|
4049 | if (isFn)
|
4050 | handler.call(self);
|
4051 | else {
|
4052 | var len = handler.length;
|
4053 | var listeners = arrayClone(handler, len);
|
4054 | for (var i = 0; i < len; ++i)
|
4055 | listeners[i].call(self);
|
4056 | }
|
4057 | }
|
4058 | function emitOne(handler, isFn, self, arg1) {
|
4059 | if (isFn)
|
4060 | handler.call(self, arg1);
|
4061 | else {
|
4062 | var len = handler.length;
|
4063 | var listeners = arrayClone(handler, len);
|
4064 | for (var i = 0; i < len; ++i)
|
4065 | listeners[i].call(self, arg1);
|
4066 | }
|
4067 | }
|
4068 | function emitTwo(handler, isFn, self, arg1, arg2) {
|
4069 | if (isFn)
|
4070 | handler.call(self, arg1, arg2);
|
4071 | else {
|
4072 | var len = handler.length;
|
4073 | var listeners = arrayClone(handler, len);
|
4074 | for (var i = 0; i < len; ++i)
|
4075 | listeners[i].call(self, arg1, arg2);
|
4076 | }
|
4077 | }
|
4078 | function emitThree(handler, isFn, self, arg1, arg2, arg3) {
|
4079 | if (isFn)
|
4080 | handler.call(self, arg1, arg2, arg3);
|
4081 | else {
|
4082 | var len = handler.length;
|
4083 | var listeners = arrayClone(handler, len);
|
4084 | for (var i = 0; i < len; ++i)
|
4085 | listeners[i].call(self, arg1, arg2, arg3);
|
4086 | }
|
4087 | }
|
4088 |
|
4089 | function emitMany(handler, isFn, self, args) {
|
4090 | if (isFn)
|
4091 | handler.apply(self, args);
|
4092 | else {
|
4093 | var len = handler.length;
|
4094 | var listeners = arrayClone(handler, len);
|
4095 | for (var i = 0; i < len; ++i)
|
4096 | listeners[i].apply(self, args);
|
4097 | }
|
4098 | }
|
4099 |
|
4100 | EventEmitter.prototype.emit = function emit(type) {
|
4101 | var er, handler, len, args, i, events;
|
4102 | var doError = (type === 'error');
|
4103 |
|
4104 | events = this._events;
|
4105 | if (events)
|
4106 | doError = (doError && events.error == null);
|
4107 | else if (!doError)
|
4108 | return false;
|
4109 |
|
4110 |
|
4111 | if (doError) {
|
4112 | if (arguments.length > 1)
|
4113 | er = arguments[1];
|
4114 | if (er instanceof Error) {
|
4115 | throw er;
|
4116 | } else {
|
4117 |
|
4118 | var err = new Error('Unhandled "error" event. (' + er + ')');
|
4119 | err.context = er;
|
4120 | throw err;
|
4121 | }
|
4122 | return false;
|
4123 | }
|
4124 |
|
4125 | handler = events[type];
|
4126 |
|
4127 | if (!handler)
|
4128 | return false;
|
4129 |
|
4130 | var isFn = typeof handler === 'function';
|
4131 | len = arguments.length;
|
4132 | switch (len) {
|
4133 |
|
4134 | case 1:
|
4135 | emitNone(handler, isFn, this);
|
4136 | break;
|
4137 | case 2:
|
4138 | emitOne(handler, isFn, this, arguments[1]);
|
4139 | break;
|
4140 | case 3:
|
4141 | emitTwo(handler, isFn, this, arguments[1], arguments[2]);
|
4142 | break;
|
4143 | case 4:
|
4144 | emitThree(handler, isFn, this, arguments[1], arguments[2], arguments[3]);
|
4145 | break;
|
4146 |
|
4147 | default:
|
4148 | args = new Array(len - 1);
|
4149 | for (i = 1; i < len; i++)
|
4150 | args[i - 1] = arguments[i];
|
4151 | emitMany(handler, isFn, this, args);
|
4152 | }
|
4153 |
|
4154 | return true;
|
4155 | };
|
4156 |
|
4157 | function _addListener(target, type, listener, prepend) {
|
4158 | var m;
|
4159 | var events;
|
4160 | var existing;
|
4161 |
|
4162 | if (typeof listener !== 'function')
|
4163 | throw new TypeError('"listener" argument must be a function');
|
4164 |
|
4165 | events = target._events;
|
4166 | if (!events) {
|
4167 | events = target._events = objectCreate(null);
|
4168 | target._eventsCount = 0;
|
4169 | } else {
|
4170 |
|
4171 |
|
4172 | if (events.newListener) {
|
4173 | target.emit('newListener', type,
|
4174 | listener.listener ? listener.listener : listener);
|
4175 |
|
4176 |
|
4177 |
|
4178 | events = target._events;
|
4179 | }
|
4180 | existing = events[type];
|
4181 | }
|
4182 |
|
4183 | if (!existing) {
|
4184 |
|
4185 | existing = events[type] = listener;
|
4186 | ++target._eventsCount;
|
4187 | } else {
|
4188 | if (typeof existing === 'function') {
|
4189 |
|
4190 | existing = events[type] =
|
4191 | prepend ? [listener, existing] : [existing, listener];
|
4192 | } else {
|
4193 |
|
4194 | if (prepend) {
|
4195 | existing.unshift(listener);
|
4196 | } else {
|
4197 | existing.push(listener);
|
4198 | }
|
4199 | }
|
4200 |
|
4201 |
|
4202 | if (!existing.warned) {
|
4203 | m = $getMaxListeners(target);
|
4204 | if (m && m > 0 && existing.length > m) {
|
4205 | existing.warned = true;
|
4206 | var w = new Error('Possible EventEmitter memory leak detected. ' +
|
4207 | existing.length + ' "' + String(type) + '" listeners ' +
|
4208 | 'added. Use emitter.setMaxListeners() to ' +
|
4209 | 'increase limit.');
|
4210 | w.name = 'MaxListenersExceededWarning';
|
4211 | w.emitter = target;
|
4212 | w.type = type;
|
4213 | w.count = existing.length;
|
4214 | if (typeof console === 'object' && console.warn) {
|
4215 | console.warn('%s: %s', w.name, w.message);
|
4216 | }
|
4217 | }
|
4218 | }
|
4219 | }
|
4220 |
|
4221 | return target;
|
4222 | }
|
4223 |
|
4224 | EventEmitter.prototype.addListener = function addListener(type, listener) {
|
4225 | return _addListener(this, type, listener, false);
|
4226 | };
|
4227 |
|
4228 | EventEmitter.prototype.on = EventEmitter.prototype.addListener;
|
4229 |
|
4230 | EventEmitter.prototype.prependListener =
|
4231 | function prependListener(type, listener) {
|
4232 | return _addListener(this, type, listener, true);
|
4233 | };
|
4234 |
|
4235 | function onceWrapper() {
|
4236 | if (!this.fired) {
|
4237 | this.target.removeListener(this.type, this.wrapFn);
|
4238 | this.fired = true;
|
4239 | switch (arguments.length) {
|
4240 | case 0:
|
4241 | return this.listener.call(this.target);
|
4242 | case 1:
|
4243 | return this.listener.call(this.target, arguments[0]);
|
4244 | case 2:
|
4245 | return this.listener.call(this.target, arguments[0], arguments[1]);
|
4246 | case 3:
|
4247 | return this.listener.call(this.target, arguments[0], arguments[1],
|
4248 | arguments[2]);
|
4249 | default:
|
4250 | var args = new Array(arguments.length);
|
4251 | for (var i = 0; i < args.length; ++i)
|
4252 | args[i] = arguments[i];
|
4253 | this.listener.apply(this.target, args);
|
4254 | }
|
4255 | }
|
4256 | }
|
4257 |
|
4258 | function _onceWrap(target, type, listener) {
|
4259 | var state = { fired: false, wrapFn: undefined, target: target, type: type, listener: listener };
|
4260 | var wrapped = bind.call(onceWrapper, state);
|
4261 | wrapped.listener = listener;
|
4262 | state.wrapFn = wrapped;
|
4263 | return wrapped;
|
4264 | }
|
4265 |
|
4266 | EventEmitter.prototype.once = function once(type, listener) {
|
4267 | if (typeof listener !== 'function')
|
4268 | throw new TypeError('"listener" argument must be a function');
|
4269 | this.on(type, _onceWrap(this, type, listener));
|
4270 | return this;
|
4271 | };
|
4272 |
|
4273 | EventEmitter.prototype.prependOnceListener =
|
4274 | function prependOnceListener(type, listener) {
|
4275 | if (typeof listener !== 'function')
|
4276 | throw new TypeError('"listener" argument must be a function');
|
4277 | this.prependListener(type, _onceWrap(this, type, listener));
|
4278 | return this;
|
4279 | };
|
4280 |
|
4281 |
|
4282 | EventEmitter.prototype.removeListener =
|
4283 | function removeListener(type, listener) {
|
4284 | var list, events, position, i, originalListener;
|
4285 |
|
4286 | if (typeof listener !== 'function')
|
4287 | throw new TypeError('"listener" argument must be a function');
|
4288 |
|
4289 | events = this._events;
|
4290 | if (!events)
|
4291 | return this;
|
4292 |
|
4293 | list = events[type];
|
4294 | if (!list)
|
4295 | return this;
|
4296 |
|
4297 | if (list === listener || list.listener === listener) {
|
4298 | if (--this._eventsCount === 0)
|
4299 | this._events = objectCreate(null);
|
4300 | else {
|
4301 | delete events[type];
|
4302 | if (events.removeListener)
|
4303 | this.emit('removeListener', type, list.listener || listener);
|
4304 | }
|
4305 | } else if (typeof list !== 'function') {
|
4306 | position = -1;
|
4307 |
|
4308 | for (i = list.length - 1; i >= 0; i--) {
|
4309 | if (list[i] === listener || list[i].listener === listener) {
|
4310 | originalListener = list[i].listener;
|
4311 | position = i;
|
4312 | break;
|
4313 | }
|
4314 | }
|
4315 |
|
4316 | if (position < 0)
|
4317 | return this;
|
4318 |
|
4319 | if (position === 0)
|
4320 | list.shift();
|
4321 | else
|
4322 | spliceOne(list, position);
|
4323 |
|
4324 | if (list.length === 1)
|
4325 | events[type] = list[0];
|
4326 |
|
4327 | if (events.removeListener)
|
4328 | this.emit('removeListener', type, originalListener || listener);
|
4329 | }
|
4330 |
|
4331 | return this;
|
4332 | };
|
4333 |
|
4334 | EventEmitter.prototype.removeAllListeners =
|
4335 | function removeAllListeners(type) {
|
4336 | var listeners, events, i;
|
4337 |
|
4338 | events = this._events;
|
4339 | if (!events)
|
4340 | return this;
|
4341 |
|
4342 |
|
4343 | if (!events.removeListener) {
|
4344 | if (arguments.length === 0) {
|
4345 | this._events = objectCreate(null);
|
4346 | this._eventsCount = 0;
|
4347 | } else if (events[type]) {
|
4348 | if (--this._eventsCount === 0)
|
4349 | this._events = objectCreate(null);
|
4350 | else
|
4351 | delete events[type];
|
4352 | }
|
4353 | return this;
|
4354 | }
|
4355 |
|
4356 |
|
4357 | if (arguments.length === 0) {
|
4358 | var keys = objectKeys(events);
|
4359 | var key;
|
4360 | for (i = 0; i < keys.length; ++i) {
|
4361 | key = keys[i];
|
4362 | if (key === 'removeListener') continue;
|
4363 | this.removeAllListeners(key);
|
4364 | }
|
4365 | this.removeAllListeners('removeListener');
|
4366 | this._events = objectCreate(null);
|
4367 | this._eventsCount = 0;
|
4368 | return this;
|
4369 | }
|
4370 |
|
4371 | listeners = events[type];
|
4372 |
|
4373 | if (typeof listeners === 'function') {
|
4374 | this.removeListener(type, listeners);
|
4375 | } else if (listeners) {
|
4376 |
|
4377 | for (i = listeners.length - 1; i >= 0; i--) {
|
4378 | this.removeListener(type, listeners[i]);
|
4379 | }
|
4380 | }
|
4381 |
|
4382 | return this;
|
4383 | };
|
4384 |
|
4385 | function _listeners(target, type, unwrap) {
|
4386 | var events = target._events;
|
4387 |
|
4388 | if (!events)
|
4389 | return [];
|
4390 |
|
4391 | var evlistener = events[type];
|
4392 | if (!evlistener)
|
4393 | return [];
|
4394 |
|
4395 | if (typeof evlistener === 'function')
|
4396 | return unwrap ? [evlistener.listener || evlistener] : [evlistener];
|
4397 |
|
4398 | return unwrap ? unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length);
|
4399 | }
|
4400 |
|
4401 | EventEmitter.prototype.listeners = function listeners(type) {
|
4402 | return _listeners(this, type, true);
|
4403 | };
|
4404 |
|
4405 | EventEmitter.prototype.rawListeners = function rawListeners(type) {
|
4406 | return _listeners(this, type, false);
|
4407 | };
|
4408 |
|
4409 | EventEmitter.listenerCount = function(emitter, type) {
|
4410 | if (typeof emitter.listenerCount === 'function') {
|
4411 | return emitter.listenerCount(type);
|
4412 | } else {
|
4413 | return listenerCount.call(emitter, type);
|
4414 | }
|
4415 | };
|
4416 |
|
4417 | EventEmitter.prototype.listenerCount = listenerCount;
|
4418 | function listenerCount(type) {
|
4419 | var events = this._events;
|
4420 |
|
4421 | if (events) {
|
4422 | var evlistener = events[type];
|
4423 |
|
4424 | if (typeof evlistener === 'function') {
|
4425 | return 1;
|
4426 | } else if (evlistener) {
|
4427 | return evlistener.length;
|
4428 | }
|
4429 | }
|
4430 |
|
4431 | return 0;
|
4432 | }
|
4433 |
|
4434 | EventEmitter.prototype.eventNames = function eventNames() {
|
4435 | return this._eventsCount > 0 ? Reflect.ownKeys(this._events) : [];
|
4436 | };
|
4437 |
|
4438 |
|
4439 | function spliceOne(list, index) {
|
4440 | for (var i = index, k = i + 1, n = list.length; k < n; i += 1, k += 1)
|
4441 | list[i] = list[k];
|
4442 | list.pop();
|
4443 | }
|
4444 |
|
4445 | function arrayClone(arr, n) {
|
4446 | var copy = new Array(n);
|
4447 | for (var i = 0; i < n; ++i)
|
4448 | copy[i] = arr[i];
|
4449 | return copy;
|
4450 | }
|
4451 |
|
4452 | function unwrapListeners(arr) {
|
4453 | var ret = new Array(arr.length);
|
4454 | for (var i = 0; i < ret.length; ++i) {
|
4455 | ret[i] = arr[i].listener || arr[i];
|
4456 | }
|
4457 | return ret;
|
4458 | }
|
4459 |
|
4460 | function objectCreatePolyfill(proto) {
|
4461 | var F = function() {};
|
4462 | F.prototype = proto;
|
4463 | return new F;
|
4464 | }
|
4465 | function objectKeysPolyfill(obj) {
|
4466 | var keys = [];
|
4467 | for (var k in obj) if (Object.prototype.hasOwnProperty.call(obj, k)) {
|
4468 | keys.push(k);
|
4469 | }
|
4470 | return k;
|
4471 | }
|
4472 | function functionBindPolyfill(context) {
|
4473 | var fn = this;
|
4474 | return function () {
|
4475 | return fn.apply(context, arguments);
|
4476 | };
|
4477 | }
|
4478 |
|
4479 | },{}],15:[function(_dereq_,module,exports){
|
4480 | "use strict"
|
4481 |
|
4482 | module.exports = createRBTree
|
4483 |
|
4484 | var RED = 0
|
4485 | var BLACK = 1
|
4486 |
|
4487 | function RBNode(color, key, value, left, right, count) {
|
4488 | this._color = color
|
4489 | this.key = key
|
4490 | this.value = value
|
4491 | this.left = left
|
4492 | this.right = right
|
4493 | this._count = count
|
4494 | }
|
4495 |
|
4496 | function cloneNode(node) {
|
4497 | return new RBNode(node._color, node.key, node.value, node.left, node.right, node._count)
|
4498 | }
|
4499 |
|
4500 | function repaint(color, node) {
|
4501 | return new RBNode(color, node.key, node.value, node.left, node.right, node._count)
|
4502 | }
|
4503 |
|
4504 | function recount(node) {
|
4505 | node._count = 1 + (node.left ? node.left._count : 0) + (node.right ? node.right._count : 0)
|
4506 | }
|
4507 |
|
4508 | function RedBlackTree(compare, root) {
|
4509 | this._compare = compare
|
4510 | this.root = root
|
4511 | }
|
4512 |
|
4513 | var proto = RedBlackTree.prototype
|
4514 |
|
4515 | Object.defineProperty(proto, "keys", {
|
4516 | get: function() {
|
4517 | var result = []
|
4518 | this.forEach(function(k,v) {
|
4519 | result.push(k)
|
4520 | })
|
4521 | return result
|
4522 | }
|
4523 | })
|
4524 |
|
4525 | Object.defineProperty(proto, "values", {
|
4526 | get: function() {
|
4527 | var result = []
|
4528 | this.forEach(function(k,v) {
|
4529 | result.push(v)
|
4530 | })
|
4531 | return result
|
4532 | }
|
4533 | })
|
4534 |
|
4535 |
|
4536 | Object.defineProperty(proto, "length", {
|
4537 | get: function() {
|
4538 | if(this.root) {
|
4539 | return this.root._count
|
4540 | }
|
4541 | return 0
|
4542 | }
|
4543 | })
|
4544 |
|
4545 |
|
4546 | proto.insert = function(key, value) {
|
4547 | var cmp = this._compare
|
4548 |
|
4549 | var n = this.root
|
4550 | var n_stack = []
|
4551 | var d_stack = []
|
4552 | while(n) {
|
4553 | var d = cmp(key, n.key)
|
4554 | n_stack.push(n)
|
4555 | d_stack.push(d)
|
4556 | if(d <= 0) {
|
4557 | n = n.left
|
4558 | } else {
|
4559 | n = n.right
|
4560 | }
|
4561 | }
|
4562 |
|
4563 | n_stack.push(new RBNode(RED, key, value, null, null, 1))
|
4564 | for(var s=n_stack.length-2; s>=0; --s) {
|
4565 | var n = n_stack[s]
|
4566 | if(d_stack[s] <= 0) {
|
4567 | n_stack[s] = new RBNode(n._color, n.key, n.value, n_stack[s+1], n.right, n._count+1)
|
4568 | } else {
|
4569 | n_stack[s] = new RBNode(n._color, n.key, n.value, n.left, n_stack[s+1], n._count+1)
|
4570 | }
|
4571 | }
|
4572 |
|
4573 |
|
4574 | for(var s=n_stack.length-1; s>1; --s) {
|
4575 | var p = n_stack[s-1]
|
4576 | var n = n_stack[s]
|
4577 | if(p._color === BLACK || n._color === BLACK) {
|
4578 | break
|
4579 | }
|
4580 | var pp = n_stack[s-2]
|
4581 | if(pp.left === p) {
|
4582 | if(p.left === n) {
|
4583 | var y = pp.right
|
4584 | if(y && y._color === RED) {
|
4585 |
|
4586 | p._color = BLACK
|
4587 | pp.right = repaint(BLACK, y)
|
4588 | pp._color = RED
|
4589 | s -= 1
|
4590 | } else {
|
4591 |
|
4592 | pp._color = RED
|
4593 | pp.left = p.right
|
4594 | p._color = BLACK
|
4595 | p.right = pp
|
4596 | n_stack[s-2] = p
|
4597 | n_stack[s-1] = n
|
4598 | recount(pp)
|
4599 | recount(p)
|
4600 | if(s >= 3) {
|
4601 | var ppp = n_stack[s-3]
|
4602 | if(ppp.left === pp) {
|
4603 | ppp.left = p
|
4604 | } else {
|
4605 | ppp.right = p
|
4606 | }
|
4607 | }
|
4608 | break
|
4609 | }
|
4610 | } else {
|
4611 | var y = pp.right
|
4612 | if(y && y._color === RED) {
|
4613 |
|
4614 | p._color = BLACK
|
4615 | pp.right = repaint(BLACK, y)
|
4616 | pp._color = RED
|
4617 | s -= 1
|
4618 | } else {
|
4619 |
|
4620 | p.right = n.left
|
4621 | pp._color = RED
|
4622 | pp.left = n.right
|
4623 | n._color = BLACK
|
4624 | n.left = p
|
4625 | n.right = pp
|
4626 | n_stack[s-2] = n
|
4627 | n_stack[s-1] = p
|
4628 | recount(pp)
|
4629 | recount(p)
|
4630 | recount(n)
|
4631 | if(s >= 3) {
|
4632 | var ppp = n_stack[s-3]
|
4633 | if(ppp.left === pp) {
|
4634 | ppp.left = n
|
4635 | } else {
|
4636 | ppp.right = n
|
4637 | }
|
4638 | }
|
4639 | break
|
4640 | }
|
4641 | }
|
4642 | } else {
|
4643 | if(p.right === n) {
|
4644 | var y = pp.left
|
4645 | if(y && y._color === RED) {
|
4646 |
|
4647 | p._color = BLACK
|
4648 | pp.left = repaint(BLACK, y)
|
4649 | pp._color = RED
|
4650 | s -= 1
|
4651 | } else {
|
4652 |
|
4653 | pp._color = RED
|
4654 | pp.right = p.left
|
4655 | p._color = BLACK
|
4656 | p.left = pp
|
4657 | n_stack[s-2] = p
|
4658 | n_stack[s-1] = n
|
4659 | recount(pp)
|
4660 | recount(p)
|
4661 | if(s >= 3) {
|
4662 | var ppp = n_stack[s-3]
|
4663 | if(ppp.right === pp) {
|
4664 | ppp.right = p
|
4665 | } else {
|
4666 | ppp.left = p
|
4667 | }
|
4668 | }
|
4669 | break
|
4670 | }
|
4671 | } else {
|
4672 | var y = pp.left
|
4673 | if(y && y._color === RED) {
|
4674 |
|
4675 | p._color = BLACK
|
4676 | pp.left = repaint(BLACK, y)
|
4677 | pp._color = RED
|
4678 | s -= 1
|
4679 | } else {
|
4680 |
|
4681 | p.left = n.right
|
4682 | pp._color = RED
|
4683 | pp.right = n.left
|
4684 | n._color = BLACK
|
4685 | n.right = p
|
4686 | n.left = pp
|
4687 | n_stack[s-2] = n
|
4688 | n_stack[s-1] = p
|
4689 | recount(pp)
|
4690 | recount(p)
|
4691 | recount(n)
|
4692 | if(s >= 3) {
|
4693 | var ppp = n_stack[s-3]
|
4694 | if(ppp.right === pp) {
|
4695 | ppp.right = n
|
4696 | } else {
|
4697 | ppp.left = n
|
4698 | }
|
4699 | }
|
4700 | break
|
4701 | }
|
4702 | }
|
4703 | }
|
4704 | }
|
4705 |
|
4706 | n_stack[0]._color = BLACK
|
4707 | return new RedBlackTree(cmp, n_stack[0])
|
4708 | }
|
4709 |
|
4710 |
|
4711 |
|
4712 | function doVisitFull(visit, node) {
|
4713 | if(node.left) {
|
4714 | var v = doVisitFull(visit, node.left)
|
4715 | if(v) { return v }
|
4716 | }
|
4717 | var v = visit(node.key, node.value)
|
4718 | if(v) { return v }
|
4719 | if(node.right) {
|
4720 | return doVisitFull(visit, node.right)
|
4721 | }
|
4722 | }
|
4723 |
|
4724 |
|
4725 | function doVisitHalf(lo, compare, visit, node) {
|
4726 | var l = compare(lo, node.key)
|
4727 | if(l <= 0) {
|
4728 | if(node.left) {
|
4729 | var v = doVisitHalf(lo, compare, visit, node.left)
|
4730 | if(v) { return v }
|
4731 | }
|
4732 | var v = visit(node.key, node.value)
|
4733 | if(v) { return v }
|
4734 | }
|
4735 | if(node.right) {
|
4736 | return doVisitHalf(lo, compare, visit, node.right)
|
4737 | }
|
4738 | }
|
4739 |
|
4740 |
|
4741 | function doVisit(lo, hi, compare, visit, node) {
|
4742 | var l = compare(lo, node.key)
|
4743 | var h = compare(hi, node.key)
|
4744 | var v
|
4745 | if(l <= 0) {
|
4746 | if(node.left) {
|
4747 | v = doVisit(lo, hi, compare, visit, node.left)
|
4748 | if(v) { return v }
|
4749 | }
|
4750 | if(h > 0) {
|
4751 | v = visit(node.key, node.value)
|
4752 | if(v) { return v }
|
4753 | }
|
4754 | }
|
4755 | if(h > 0 && node.right) {
|
4756 | return doVisit(lo, hi, compare, visit, node.right)
|
4757 | }
|
4758 | }
|
4759 |
|
4760 |
|
4761 | proto.forEach = function rbTreeForEach(visit, lo, hi) {
|
4762 | if(!this.root) {
|
4763 | return
|
4764 | }
|
4765 | switch(arguments.length) {
|
4766 | case 1:
|
4767 | return doVisitFull(visit, this.root)
|
4768 | break
|
4769 |
|
4770 | case 2:
|
4771 | return doVisitHalf(lo, this._compare, visit, this.root)
|
4772 | break
|
4773 |
|
4774 | case 3:
|
4775 | if(this._compare(lo, hi) >= 0) {
|
4776 | return
|
4777 | }
|
4778 | return doVisit(lo, hi, this._compare, visit, this.root)
|
4779 | break
|
4780 | }
|
4781 | }
|
4782 |
|
4783 |
|
4784 | Object.defineProperty(proto, "begin", {
|
4785 | get: function() {
|
4786 | var stack = []
|
4787 | var n = this.root
|
4788 | while(n) {
|
4789 | stack.push(n)
|
4790 | n = n.left
|
4791 | }
|
4792 | return new RedBlackTreeIterator(this, stack)
|
4793 | }
|
4794 | })
|
4795 |
|
4796 |
|
4797 | Object.defineProperty(proto, "end", {
|
4798 | get: function() {
|
4799 | var stack = []
|
4800 | var n = this.root
|
4801 | while(n) {
|
4802 | stack.push(n)
|
4803 | n = n.right
|
4804 | }
|
4805 | return new RedBlackTreeIterator(this, stack)
|
4806 | }
|
4807 | })
|
4808 |
|
4809 |
|
4810 | proto.at = function(idx) {
|
4811 | if(idx < 0) {
|
4812 | return new RedBlackTreeIterator(this, [])
|
4813 | }
|
4814 | var n = this.root
|
4815 | var stack = []
|
4816 | while(true) {
|
4817 | stack.push(n)
|
4818 | if(n.left) {
|
4819 | if(idx < n.left._count) {
|
4820 | n = n.left
|
4821 | continue
|
4822 | }
|
4823 | idx -= n.left._count
|
4824 | }
|
4825 | if(!idx) {
|
4826 | return new RedBlackTreeIterator(this, stack)
|
4827 | }
|
4828 | idx -= 1
|
4829 | if(n.right) {
|
4830 | if(idx >= n.right._count) {
|
4831 | break
|
4832 | }
|
4833 | n = n.right
|
4834 | } else {
|
4835 | break
|
4836 | }
|
4837 | }
|
4838 | return new RedBlackTreeIterator(this, [])
|
4839 | }
|
4840 |
|
4841 | proto.ge = function(key) {
|
4842 | var cmp = this._compare
|
4843 | var n = this.root
|
4844 | var stack = []
|
4845 | var last_ptr = 0
|
4846 | while(n) {
|
4847 | var d = cmp(key, n.key)
|
4848 | stack.push(n)
|
4849 | if(d <= 0) {
|
4850 | last_ptr = stack.length
|
4851 | }
|
4852 | if(d <= 0) {
|
4853 | n = n.left
|
4854 | } else {
|
4855 | n = n.right
|
4856 | }
|
4857 | }
|
4858 | stack.length = last_ptr
|
4859 | return new RedBlackTreeIterator(this, stack)
|
4860 | }
|
4861 |
|
4862 | proto.gt = function(key) {
|
4863 | var cmp = this._compare
|
4864 | var n = this.root
|
4865 | var stack = []
|
4866 | var last_ptr = 0
|
4867 | while(n) {
|
4868 | var d = cmp(key, n.key)
|
4869 | stack.push(n)
|
4870 | if(d < 0) {
|
4871 | last_ptr = stack.length
|
4872 | }
|
4873 | if(d < 0) {
|
4874 | n = n.left
|
4875 | } else {
|
4876 | n = n.right
|
4877 | }
|
4878 | }
|
4879 | stack.length = last_ptr
|
4880 | return new RedBlackTreeIterator(this, stack)
|
4881 | }
|
4882 |
|
4883 | proto.lt = function(key) {
|
4884 | var cmp = this._compare
|
4885 | var n = this.root
|
4886 | var stack = []
|
4887 | var last_ptr = 0
|
4888 | while(n) {
|
4889 | var d = cmp(key, n.key)
|
4890 | stack.push(n)
|
4891 | if(d > 0) {
|
4892 | last_ptr = stack.length
|
4893 | }
|
4894 | if(d <= 0) {
|
4895 | n = n.left
|
4896 | } else {
|
4897 | n = n.right
|
4898 | }
|
4899 | }
|
4900 | stack.length = last_ptr
|
4901 | return new RedBlackTreeIterator(this, stack)
|
4902 | }
|
4903 |
|
4904 | proto.le = function(key) {
|
4905 | var cmp = this._compare
|
4906 | var n = this.root
|
4907 | var stack = []
|
4908 | var last_ptr = 0
|
4909 | while(n) {
|
4910 | var d = cmp(key, n.key)
|
4911 | stack.push(n)
|
4912 | if(d >= 0) {
|
4913 | last_ptr = stack.length
|
4914 | }
|
4915 | if(d < 0) {
|
4916 | n = n.left
|
4917 | } else {
|
4918 | n = n.right
|
4919 | }
|
4920 | }
|
4921 | stack.length = last_ptr
|
4922 | return new RedBlackTreeIterator(this, stack)
|
4923 | }
|
4924 |
|
4925 |
|
4926 | proto.find = function(key) {
|
4927 | var cmp = this._compare
|
4928 | var n = this.root
|
4929 | var stack = []
|
4930 | while(n) {
|
4931 | var d = cmp(key, n.key)
|
4932 | stack.push(n)
|
4933 | if(d === 0) {
|
4934 | return new RedBlackTreeIterator(this, stack)
|
4935 | }
|
4936 | if(d <= 0) {
|
4937 | n = n.left
|
4938 | } else {
|
4939 | n = n.right
|
4940 | }
|
4941 | }
|
4942 | return new RedBlackTreeIterator(this, [])
|
4943 | }
|
4944 |
|
4945 |
|
4946 | proto.remove = function(key) {
|
4947 | var iter = this.find(key)
|
4948 | if(iter) {
|
4949 | return iter.remove()
|
4950 | }
|
4951 | return this
|
4952 | }
|
4953 |
|
4954 |
|
4955 | proto.get = function(key) {
|
4956 | var cmp = this._compare
|
4957 | var n = this.root
|
4958 | while(n) {
|
4959 | var d = cmp(key, n.key)
|
4960 | if(d === 0) {
|
4961 | return n.value
|
4962 | }
|
4963 | if(d <= 0) {
|
4964 | n = n.left
|
4965 | } else {
|
4966 | n = n.right
|
4967 | }
|
4968 | }
|
4969 | return
|
4970 | }
|
4971 |
|
4972 |
|
4973 | function RedBlackTreeIterator(tree, stack) {
|
4974 | this.tree = tree
|
4975 | this._stack = stack
|
4976 | }
|
4977 |
|
4978 | var iproto = RedBlackTreeIterator.prototype
|
4979 |
|
4980 |
|
4981 | Object.defineProperty(iproto, "valid", {
|
4982 | get: function() {
|
4983 | return this._stack.length > 0
|
4984 | }
|
4985 | })
|
4986 |
|
4987 |
|
4988 | Object.defineProperty(iproto, "node", {
|
4989 | get: function() {
|
4990 | if(this._stack.length > 0) {
|
4991 | return this._stack[this._stack.length-1]
|
4992 | }
|
4993 | return null
|
4994 | },
|
4995 | enumerable: true
|
4996 | })
|
4997 |
|
4998 |
|
4999 | iproto.clone = function() {
|
5000 | return new RedBlackTreeIterator(this.tree, this._stack.slice())
|
5001 | }
|
5002 |
|
5003 |
|
5004 | function swapNode(n, v) {
|
5005 | n.key = v.key
|
5006 | n.value = v.value
|
5007 | n.left = v.left
|
5008 | n.right = v.right
|
5009 | n._color = v._color
|
5010 | n._count = v._count
|
5011 | }
|
5012 |
|
5013 |
|
5014 | function fixDoubleBlack(stack) {
|
5015 | var n, p, s, z
|
5016 | for(var i=stack.length-1; i>=0; --i) {
|
5017 | n = stack[i]
|
5018 | if(i === 0) {
|
5019 | n._color = BLACK
|
5020 | return
|
5021 | }
|
5022 |
|
5023 | p = stack[i-1]
|
5024 | if(p.left === n) {
|
5025 |
|
5026 | s = p.right
|
5027 | if(s.right && s.right._color === RED) {
|
5028 |
|
5029 | s = p.right = cloneNode(s)
|
5030 | z = s.right = cloneNode(s.right)
|
5031 | p.right = s.left
|
5032 | s.left = p
|
5033 | s.right = z
|
5034 | s._color = p._color
|
5035 | n._color = BLACK
|
5036 | p._color = BLACK
|
5037 | z._color = BLACK
|
5038 | recount(p)
|
5039 | recount(s)
|
5040 | if(i > 1) {
|
5041 | var pp = stack[i-2]
|
5042 | if(pp.left === p) {
|
5043 | pp.left = s
|
5044 | } else {
|
5045 | pp.right = s
|
5046 | }
|
5047 | }
|
5048 | stack[i-1] = s
|
5049 | return
|
5050 | } else if(s.left && s.left._color === RED) {
|
5051 |
|
5052 | s = p.right = cloneNode(s)
|
5053 | z = s.left = cloneNode(s.left)
|
5054 | p.right = z.left
|
5055 | s.left = z.right
|
5056 | z.left = p
|
5057 | z.right = s
|
5058 | z._color = p._color
|
5059 | p._color = BLACK
|
5060 | s._color = BLACK
|
5061 | n._color = BLACK
|
5062 | recount(p)
|
5063 | recount(s)
|
5064 | recount(z)
|
5065 | if(i > 1) {
|
5066 | var pp = stack[i-2]
|
5067 | if(pp.left === p) {
|
5068 | pp.left = z
|
5069 | } else {
|
5070 | pp.right = z
|
5071 | }
|
5072 | }
|
5073 | stack[i-1] = z
|
5074 | return
|
5075 | }
|
5076 | if(s._color === BLACK) {
|
5077 | if(p._color === RED) {
|
5078 |
|
5079 | p._color = BLACK
|
5080 | p.right = repaint(RED, s)
|
5081 | return
|
5082 | } else {
|
5083 |
|
5084 | p.right = repaint(RED, s)
|
5085 | continue
|
5086 | }
|
5087 | } else {
|
5088 |
|
5089 | s = cloneNode(s)
|
5090 | p.right = s.left
|
5091 | s.left = p
|
5092 | s._color = p._color
|
5093 | p._color = RED
|
5094 | recount(p)
|
5095 | recount(s)
|
5096 | if(i > 1) {
|
5097 | var pp = stack[i-2]
|
5098 | if(pp.left === p) {
|
5099 | pp.left = s
|
5100 | } else {
|
5101 | pp.right = s
|
5102 | }
|
5103 | }
|
5104 | stack[i-1] = s
|
5105 | stack[i] = p
|
5106 | if(i+1 < stack.length) {
|
5107 | stack[i+1] = n
|
5108 | } else {
|
5109 | stack.push(n)
|
5110 | }
|
5111 | i = i+2
|
5112 | }
|
5113 | } else {
|
5114 |
|
5115 | s = p.left
|
5116 | if(s.left && s.left._color === RED) {
|
5117 |
|
5118 | s = p.left = cloneNode(s)
|
5119 | z = s.left = cloneNode(s.left)
|
5120 | p.left = s.right
|
5121 | s.right = p
|
5122 | s.left = z
|
5123 | s._color = p._color
|
5124 | n._color = BLACK
|
5125 | p._color = BLACK
|
5126 | z._color = BLACK
|
5127 | recount(p)
|
5128 | recount(s)
|
5129 | if(i > 1) {
|
5130 | var pp = stack[i-2]
|
5131 | if(pp.right === p) {
|
5132 | pp.right = s
|
5133 | } else {
|
5134 | pp.left = s
|
5135 | }
|
5136 | }
|
5137 | stack[i-1] = s
|
5138 | return
|
5139 | } else if(s.right && s.right._color === RED) {
|
5140 |
|
5141 | s = p.left = cloneNode(s)
|
5142 | z = s.right = cloneNode(s.right)
|
5143 | p.left = z.right
|
5144 | s.right = z.left
|
5145 | z.right = p
|
5146 | z.left = s
|
5147 | z._color = p._color
|
5148 | p._color = BLACK
|
5149 | s._color = BLACK
|
5150 | n._color = BLACK
|
5151 | recount(p)
|
5152 | recount(s)
|
5153 | recount(z)
|
5154 | if(i > 1) {
|
5155 | var pp = stack[i-2]
|
5156 | if(pp.right === p) {
|
5157 | pp.right = z
|
5158 | } else {
|
5159 | pp.left = z
|
5160 | }
|
5161 | }
|
5162 | stack[i-1] = z
|
5163 | return
|
5164 | }
|
5165 | if(s._color === BLACK) {
|
5166 | if(p._color === RED) {
|
5167 |
|
5168 | p._color = BLACK
|
5169 | p.left = repaint(RED, s)
|
5170 | return
|
5171 | } else {
|
5172 |
|
5173 | p.left = repaint(RED, s)
|
5174 | continue
|
5175 | }
|
5176 | } else {
|
5177 |
|
5178 | s = cloneNode(s)
|
5179 | p.left = s.right
|
5180 | s.right = p
|
5181 | s._color = p._color
|
5182 | p._color = RED
|
5183 | recount(p)
|
5184 | recount(s)
|
5185 | if(i > 1) {
|
5186 | var pp = stack[i-2]
|
5187 | if(pp.right === p) {
|
5188 | pp.right = s
|
5189 | } else {
|
5190 | pp.left = s
|
5191 | }
|
5192 | }
|
5193 | stack[i-1] = s
|
5194 | stack[i] = p
|
5195 | if(i+1 < stack.length) {
|
5196 | stack[i+1] = n
|
5197 | } else {
|
5198 | stack.push(n)
|
5199 | }
|
5200 | i = i+2
|
5201 | }
|
5202 | }
|
5203 | }
|
5204 | }
|
5205 |
|
5206 |
|
5207 | iproto.remove = function() {
|
5208 | var stack = this._stack
|
5209 | if(stack.length === 0) {
|
5210 | return this.tree
|
5211 | }
|
5212 |
|
5213 | var cstack = new Array(stack.length)
|
5214 | var n = stack[stack.length-1]
|
5215 | cstack[cstack.length-1] = new RBNode(n._color, n.key, n.value, n.left, n.right, n._count)
|
5216 | for(var i=stack.length-2; i>=0; --i) {
|
5217 | var n = stack[i]
|
5218 | if(n.left === stack[i+1]) {
|
5219 | cstack[i] = new RBNode(n._color, n.key, n.value, cstack[i+1], n.right, n._count)
|
5220 | } else {
|
5221 | cstack[i] = new RBNode(n._color, n.key, n.value, n.left, cstack[i+1], n._count)
|
5222 | }
|
5223 | }
|
5224 |
|
5225 |
|
5226 | n = cstack[cstack.length-1]
|
5227 |
|
5228 |
|
5229 |
|
5230 | if(n.left && n.right) {
|
5231 |
|
5232 |
|
5233 |
|
5234 | var split = cstack.length
|
5235 | n = n.left
|
5236 | while(n.right) {
|
5237 | cstack.push(n)
|
5238 | n = n.right
|
5239 | }
|
5240 |
|
5241 | var v = cstack[split-1]
|
5242 | cstack.push(new RBNode(n._color, v.key, v.value, n.left, n.right, n._count))
|
5243 | cstack[split-1].key = n.key
|
5244 | cstack[split-1].value = n.value
|
5245 |
|
5246 |
|
5247 | for(var i=cstack.length-2; i>=split; --i) {
|
5248 | n = cstack[i]
|
5249 | cstack[i] = new RBNode(n._color, n.key, n.value, n.left, cstack[i+1], n._count)
|
5250 | }
|
5251 | cstack[split-1].left = cstack[split]
|
5252 | }
|
5253 |
|
5254 |
|
5255 |
|
5256 | n = cstack[cstack.length-1]
|
5257 | if(n._color === RED) {
|
5258 |
|
5259 |
|
5260 | var p = cstack[cstack.length-2]
|
5261 | if(p.left === n) {
|
5262 | p.left = null
|
5263 | } else if(p.right === n) {
|
5264 | p.right = null
|
5265 | }
|
5266 | cstack.pop()
|
5267 | for(var i=0; i<cstack.length; ++i) {
|
5268 | cstack[i]._count--
|
5269 | }
|
5270 | return new RedBlackTree(this.tree._compare, cstack[0])
|
5271 | } else {
|
5272 | if(n.left || n.right) {
|
5273 |
|
5274 |
|
5275 | if(n.left) {
|
5276 | swapNode(n, n.left)
|
5277 | } else if(n.right) {
|
5278 | swapNode(n, n.right)
|
5279 | }
|
5280 |
|
5281 | n._color = BLACK
|
5282 | for(var i=0; i<cstack.length-1; ++i) {
|
5283 | cstack[i]._count--
|
5284 | }
|
5285 | return new RedBlackTree(this.tree._compare, cstack[0])
|
5286 | } else if(cstack.length === 1) {
|
5287 |
|
5288 |
|
5289 | return new RedBlackTree(this.tree._compare, null)
|
5290 | } else {
|
5291 |
|
5292 |
|
5293 | for(var i=0; i<cstack.length; ++i) {
|
5294 | cstack[i]._count--
|
5295 | }
|
5296 | var parent = cstack[cstack.length-2]
|
5297 | fixDoubleBlack(cstack)
|
5298 |
|
5299 | if(parent.left === n) {
|
5300 | parent.left = null
|
5301 | } else {
|
5302 | parent.right = null
|
5303 | }
|
5304 | }
|
5305 | }
|
5306 | return new RedBlackTree(this.tree._compare, cstack[0])
|
5307 | }
|
5308 |
|
5309 |
|
5310 | Object.defineProperty(iproto, "key", {
|
5311 | get: function() {
|
5312 | if(this._stack.length > 0) {
|
5313 | return this._stack[this._stack.length-1].key
|
5314 | }
|
5315 | return
|
5316 | },
|
5317 | enumerable: true
|
5318 | })
|
5319 |
|
5320 |
|
5321 | Object.defineProperty(iproto, "value", {
|
5322 | get: function() {
|
5323 | if(this._stack.length > 0) {
|
5324 | return this._stack[this._stack.length-1].value
|
5325 | }
|
5326 | return
|
5327 | },
|
5328 | enumerable: true
|
5329 | })
|
5330 |
|
5331 |
|
5332 |
|
5333 | Object.defineProperty(iproto, "index", {
|
5334 | get: function() {
|
5335 | var idx = 0
|
5336 | var stack = this._stack
|
5337 | if(stack.length === 0) {
|
5338 | var r = this.tree.root
|
5339 | if(r) {
|
5340 | return r._count
|
5341 | }
|
5342 | return 0
|
5343 | } else if(stack[stack.length-1].left) {
|
5344 | idx = stack[stack.length-1].left._count
|
5345 | }
|
5346 | for(var s=stack.length-2; s>=0; --s) {
|
5347 | if(stack[s+1] === stack[s].right) {
|
5348 | ++idx
|
5349 | if(stack[s].left) {
|
5350 | idx += stack[s].left._count
|
5351 | }
|
5352 | }
|
5353 | }
|
5354 | return idx
|
5355 | },
|
5356 | enumerable: true
|
5357 | })
|
5358 |
|
5359 |
|
5360 | iproto.next = function() {
|
5361 | var stack = this._stack
|
5362 | if(stack.length === 0) {
|
5363 | return
|
5364 | }
|
5365 | var n = stack[stack.length-1]
|
5366 | if(n.right) {
|
5367 | n = n.right
|
5368 | while(n) {
|
5369 | stack.push(n)
|
5370 | n = n.left
|
5371 | }
|
5372 | } else {
|
5373 | stack.pop()
|
5374 | while(stack.length > 0 && stack[stack.length-1].right === n) {
|
5375 | n = stack[stack.length-1]
|
5376 | stack.pop()
|
5377 | }
|
5378 | }
|
5379 | }
|
5380 |
|
5381 |
|
5382 | Object.defineProperty(iproto, "hasNext", {
|
5383 | get: function() {
|
5384 | var stack = this._stack
|
5385 | if(stack.length === 0) {
|
5386 | return false
|
5387 | }
|
5388 | if(stack[stack.length-1].right) {
|
5389 | return true
|
5390 | }
|
5391 | for(var s=stack.length-1; s>0; --s) {
|
5392 | if(stack[s-1].left === stack[s]) {
|
5393 | return true
|
5394 | }
|
5395 | }
|
5396 | return false
|
5397 | }
|
5398 | })
|
5399 |
|
5400 |
|
5401 | iproto.update = function(value) {
|
5402 | var stack = this._stack
|
5403 | if(stack.length === 0) {
|
5404 | throw new Error("Can't update empty node!")
|
5405 | }
|
5406 | var cstack = new Array(stack.length)
|
5407 | var n = stack[stack.length-1]
|
5408 | cstack[cstack.length-1] = new RBNode(n._color, n.key, value, n.left, n.right, n._count)
|
5409 | for(var i=stack.length-2; i>=0; --i) {
|
5410 | n = stack[i]
|
5411 | if(n.left === stack[i+1]) {
|
5412 | cstack[i] = new RBNode(n._color, n.key, n.value, cstack[i+1], n.right, n._count)
|
5413 | } else {
|
5414 | cstack[i] = new RBNode(n._color, n.key, n.value, n.left, cstack[i+1], n._count)
|
5415 | }
|
5416 | }
|
5417 | return new RedBlackTree(this.tree._compare, cstack[0])
|
5418 | }
|
5419 |
|
5420 |
|
5421 | iproto.prev = function() {
|
5422 | var stack = this._stack
|
5423 | if(stack.length === 0) {
|
5424 | return
|
5425 | }
|
5426 | var n = stack[stack.length-1]
|
5427 | if(n.left) {
|
5428 | n = n.left
|
5429 | while(n) {
|
5430 | stack.push(n)
|
5431 | n = n.right
|
5432 | }
|
5433 | } else {
|
5434 | stack.pop()
|
5435 | while(stack.length > 0 && stack[stack.length-1].left === n) {
|
5436 | n = stack[stack.length-1]
|
5437 | stack.pop()
|
5438 | }
|
5439 | }
|
5440 | }
|
5441 |
|
5442 |
|
5443 | Object.defineProperty(iproto, "hasPrev", {
|
5444 | get: function() {
|
5445 | var stack = this._stack
|
5446 | if(stack.length === 0) {
|
5447 | return false
|
5448 | }
|
5449 | if(stack[stack.length-1].left) {
|
5450 | return true
|
5451 | }
|
5452 | for(var s=stack.length-1; s>0; --s) {
|
5453 | if(stack[s-1].right === stack[s]) {
|
5454 | return true
|
5455 | }
|
5456 | }
|
5457 | return false
|
5458 | }
|
5459 | })
|
5460 |
|
5461 |
|
5462 | function defaultCompare(a, b) {
|
5463 | if(a < b) {
|
5464 | return -1
|
5465 | }
|
5466 | if(a > b) {
|
5467 | return 1
|
5468 | }
|
5469 | return 0
|
5470 | }
|
5471 |
|
5472 |
|
5473 | function createRBTree(compare) {
|
5474 | return new RedBlackTree(compare || defaultCompare, null)
|
5475 | }
|
5476 | },{}],16:[function(_dereq_,module,exports){
|
5477 | exports.read = function (buffer, offset, isLE, mLen, nBytes) {
|
5478 | var e, m
|
5479 | var eLen = (nBytes * 8) - mLen - 1
|
5480 | var eMax = (1 << eLen) - 1
|
5481 | var eBias = eMax >> 1
|
5482 | var nBits = -7
|
5483 | var i = isLE ? (nBytes - 1) : 0
|
5484 | var d = isLE ? -1 : 1
|
5485 | var s = buffer[offset + i]
|
5486 |
|
5487 | i += d
|
5488 |
|
5489 | e = s & ((1 << (-nBits)) - 1)
|
5490 | s >>= (-nBits)
|
5491 | nBits += eLen
|
5492 | for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {}
|
5493 |
|
5494 | m = e & ((1 << (-nBits)) - 1)
|
5495 | e >>= (-nBits)
|
5496 | nBits += mLen
|
5497 | for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {}
|
5498 |
|
5499 | if (e === 0) {
|
5500 | e = 1 - eBias
|
5501 | } else if (e === eMax) {
|
5502 | return m ? NaN : ((s ? -1 : 1) * Infinity)
|
5503 | } else {
|
5504 | m = m + Math.pow(2, mLen)
|
5505 | e = e - eBias
|
5506 | }
|
5507 | return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
|
5508 | }
|
5509 |
|
5510 | exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
|
5511 | var e, m, c
|
5512 | var eLen = (nBytes * 8) - mLen - 1
|
5513 | var eMax = (1 << eLen) - 1
|
5514 | var eBias = eMax >> 1
|
5515 | var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
|
5516 | var i = isLE ? 0 : (nBytes - 1)
|
5517 | var d = isLE ? 1 : -1
|
5518 | var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
|
5519 |
|
5520 | value = Math.abs(value)
|
5521 |
|
5522 | if (isNaN(value) || value === Infinity) {
|
5523 | m = isNaN(value) ? 1 : 0
|
5524 | e = eMax
|
5525 | } else {
|
5526 | e = Math.floor(Math.log(value) / Math.LN2)
|
5527 | if (value * (c = Math.pow(2, -e)) < 1) {
|
5528 | e--
|
5529 | c *= 2
|
5530 | }
|
5531 | if (e + eBias >= 1) {
|
5532 | value += rt / c
|
5533 | } else {
|
5534 | value += rt * Math.pow(2, 1 - eBias)
|
5535 | }
|
5536 | if (value * c >= 2) {
|
5537 | e++
|
5538 | c /= 2
|
5539 | }
|
5540 |
|
5541 | if (e + eBias >= eMax) {
|
5542 | m = 0
|
5543 | e = eMax
|
5544 | } else if (e + eBias >= 1) {
|
5545 | m = ((value * c) - 1) * Math.pow(2, mLen)
|
5546 | e = e + eBias
|
5547 | } else {
|
5548 | m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
|
5549 | e = 0
|
5550 | }
|
5551 | }
|
5552 |
|
5553 | for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
|
5554 |
|
5555 | e = (e << mLen) | m
|
5556 | eLen += mLen
|
5557 | for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
|
5558 |
|
5559 | buffer[offset + i - d] |= s * 128
|
5560 | }
|
5561 |
|
5562 | },{}],17:[function(_dereq_,module,exports){
|
5563 | (function (global){
|
5564 | 'use strict';
|
5565 | var Mutation = global.MutationObserver || global.WebKitMutationObserver;
|
5566 |
|
5567 | var scheduleDrain;
|
5568 |
|
5569 | {
|
5570 | if (Mutation) {
|
5571 | var called = 0;
|
5572 | var observer = new Mutation(nextTick);
|
5573 | var element = global.document.createTextNode('');
|
5574 | observer.observe(element, {
|
5575 | characterData: true
|
5576 | });
|
5577 | scheduleDrain = function () {
|
5578 | element.data = (called = ++called % 2);
|
5579 | };
|
5580 | } else if (!global.setImmediate && typeof global.MessageChannel !== 'undefined') {
|
5581 | var channel = new global.MessageChannel();
|
5582 | channel.port1.onmessage = nextTick;
|
5583 | scheduleDrain = function () {
|
5584 | channel.port2.postMessage(0);
|
5585 | };
|
5586 | } else if ('document' in global && 'onreadystatechange' in global.document.createElement('script')) {
|
5587 | scheduleDrain = function () {
|
5588 |
|
5589 |
|
5590 |
|
5591 | var scriptEl = global.document.createElement('script');
|
5592 | scriptEl.onreadystatechange = function () {
|
5593 | nextTick();
|
5594 |
|
5595 | scriptEl.onreadystatechange = null;
|
5596 | scriptEl.parentNode.removeChild(scriptEl);
|
5597 | scriptEl = null;
|
5598 | };
|
5599 | global.document.documentElement.appendChild(scriptEl);
|
5600 | };
|
5601 | } else {
|
5602 | scheduleDrain = function () {
|
5603 | setTimeout(nextTick, 0);
|
5604 | };
|
5605 | }
|
5606 | }
|
5607 |
|
5608 | var draining;
|
5609 | var queue = [];
|
5610 |
|
5611 | function nextTick() {
|
5612 | draining = true;
|
5613 | var i, oldQueue;
|
5614 | var len = queue.length;
|
5615 | while (len) {
|
5616 | oldQueue = queue;
|
5617 | queue = [];
|
5618 | i = -1;
|
5619 | while (++i < len) {
|
5620 | oldQueue[i]();
|
5621 | }
|
5622 | len = queue.length;
|
5623 | }
|
5624 | draining = false;
|
5625 | }
|
5626 |
|
5627 | module.exports = immediate;
|
5628 | function immediate(task) {
|
5629 | if (queue.push(task) === 1 && !draining) {
|
5630 | scheduleDrain();
|
5631 | }
|
5632 | }
|
5633 |
|
5634 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
5635 | },{}],18:[function(_dereq_,module,exports){
|
5636 | if (typeof Object.create === 'function') {
|
5637 |
|
5638 | module.exports = function inherits(ctor, superCtor) {
|
5639 | if (superCtor) {
|
5640 | ctor.super_ = superCtor
|
5641 | ctor.prototype = Object.create(superCtor.prototype, {
|
5642 | constructor: {
|
5643 | value: ctor,
|
5644 | enumerable: false,
|
5645 | writable: true,
|
5646 | configurable: true
|
5647 | }
|
5648 | })
|
5649 | }
|
5650 | };
|
5651 | } else {
|
5652 |
|
5653 | module.exports = function inherits(ctor, superCtor) {
|
5654 | if (superCtor) {
|
5655 | ctor.super_ = superCtor
|
5656 | var TempCtor = function () {}
|
5657 | TempCtor.prototype = superCtor.prototype
|
5658 | ctor.prototype = new TempCtor()
|
5659 | ctor.prototype.constructor = ctor
|
5660 | }
|
5661 | }
|
5662 | }
|
5663 |
|
5664 | },{}],19:[function(_dereq_,module,exports){
|
5665 |
|
5666 |
|
5667 |
|
5668 |
|
5669 |
|
5670 |
|
5671 |
|
5672 |
|
5673 |
|
5674 | module.exports = function (obj) {
|
5675 | return obj != null && (isBuffer(obj) || isSlowBuffer(obj) || !!obj._isBuffer)
|
5676 | }
|
5677 |
|
5678 | function isBuffer (obj) {
|
5679 | return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)
|
5680 | }
|
5681 |
|
5682 |
|
5683 | function isSlowBuffer (obj) {
|
5684 | return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isBuffer(obj.slice(0, 0))
|
5685 | }
|
5686 |
|
5687 | },{}],20:[function(_dereq_,module,exports){
|
5688 | module.exports = Array.isArray || function (arr) {
|
5689 | return Object.prototype.toString.call(arr) == '[object Array]';
|
5690 | };
|
5691 |
|
5692 | },{}],21:[function(_dereq_,module,exports){
|
5693 | var encodings = _dereq_(22)
|
5694 |
|
5695 | module.exports = Codec
|
5696 |
|
5697 | function Codec (opts) {
|
5698 | if (!(this instanceof Codec)) {
|
5699 | return new Codec(opts)
|
5700 | }
|
5701 | this.opts = opts || {}
|
5702 | this.encodings = encodings
|
5703 | }
|
5704 |
|
5705 | Codec.prototype._encoding = function (encoding) {
|
5706 | if (typeof encoding === 'string') encoding = encodings[encoding]
|
5707 | if (!encoding) encoding = encodings.id
|
5708 | return encoding
|
5709 | }
|
5710 |
|
5711 | Codec.prototype._keyEncoding = function (opts, batchOpts) {
|
5712 | return this._encoding((batchOpts && batchOpts.keyEncoding) ||
|
5713 | (opts && opts.keyEncoding) ||
|
5714 | this.opts.keyEncoding)
|
5715 | }
|
5716 |
|
5717 | Codec.prototype._valueEncoding = function (opts, batchOpts) {
|
5718 | return this._encoding((batchOpts && (batchOpts.valueEncoding || batchOpts.encoding)) ||
|
5719 | (opts && (opts.valueEncoding || opts.encoding)) ||
|
5720 | (this.opts.valueEncoding || this.opts.encoding))
|
5721 | }
|
5722 |
|
5723 | Codec.prototype.encodeKey = function (key, opts, batchOpts) {
|
5724 | return this._keyEncoding(opts, batchOpts).encode(key)
|
5725 | }
|
5726 |
|
5727 | Codec.prototype.encodeValue = function (value, opts, batchOpts) {
|
5728 | return this._valueEncoding(opts, batchOpts).encode(value)
|
5729 | }
|
5730 |
|
5731 | Codec.prototype.decodeKey = function (key, opts) {
|
5732 | return this._keyEncoding(opts).decode(key)
|
5733 | }
|
5734 |
|
5735 | Codec.prototype.decodeValue = function (value, opts) {
|
5736 | return this._valueEncoding(opts).decode(value)
|
5737 | }
|
5738 |
|
5739 | Codec.prototype.encodeBatch = function (ops, opts) {
|
5740 | var self = this
|
5741 |
|
5742 | return ops.map(function (_op) {
|
5743 | var op = {
|
5744 | type: _op.type,
|
5745 | key: self.encodeKey(_op.key, opts, _op)
|
5746 | }
|
5747 | if (self.keyAsBuffer(opts, _op)) op.keyEncoding = 'binary'
|
5748 | if (_op.prefix) op.prefix = _op.prefix
|
5749 | if ('value' in _op) {
|
5750 | op.value = self.encodeValue(_op.value, opts, _op)
|
5751 | if (self.valueAsBuffer(opts, _op)) op.valueEncoding = 'binary'
|
5752 | }
|
5753 | return op
|
5754 | })
|
5755 | }
|
5756 |
|
5757 | var ltgtKeys = ['lt', 'gt', 'lte', 'gte', 'start', 'end']
|
5758 |
|
5759 | Codec.prototype.encodeLtgt = function (ltgt) {
|
5760 | var self = this
|
5761 | var ret = {}
|
5762 | Object.keys(ltgt).forEach(function (key) {
|
5763 | ret[key] = ltgtKeys.indexOf(key) > -1
|
5764 | ? self.encodeKey(ltgt[key], ltgt)
|
5765 | : ltgt[key]
|
5766 | })
|
5767 | return ret
|
5768 | }
|
5769 |
|
5770 | Codec.prototype.createStreamDecoder = function (opts) {
|
5771 | var self = this
|
5772 |
|
5773 | if (opts.keys && opts.values) {
|
5774 | return function (key, value) {
|
5775 | return {
|
5776 | key: self.decodeKey(key, opts),
|
5777 | value: self.decodeValue(value, opts)
|
5778 | }
|
5779 | }
|
5780 | } else if (opts.keys) {
|
5781 | return function (key) {
|
5782 | return self.decodeKey(key, opts)
|
5783 | }
|
5784 | } else if (opts.values) {
|
5785 | return function (_, value) {
|
5786 | return self.decodeValue(value, opts)
|
5787 | }
|
5788 | } else {
|
5789 | return function () {}
|
5790 | }
|
5791 | }
|
5792 |
|
5793 | Codec.prototype.keyAsBuffer = function (opts) {
|
5794 | return this._keyEncoding(opts).buffer
|
5795 | }
|
5796 |
|
5797 | Codec.prototype.valueAsBuffer = function (opts) {
|
5798 | return this._valueEncoding(opts).buffer
|
5799 | }
|
5800 |
|
5801 | },{"22":22}],22:[function(_dereq_,module,exports){
|
5802 | (function (Buffer){
|
5803 | exports.utf8 = exports['utf-8'] = {
|
5804 | encode: function (data) {
|
5805 | return isBinary(data) ? data : String(data)
|
5806 | },
|
5807 | decode: identity,
|
5808 | buffer: false,
|
5809 | type: 'utf8'
|
5810 | }
|
5811 |
|
5812 | exports.json = {
|
5813 | encode: JSON.stringify,
|
5814 | decode: JSON.parse,
|
5815 | buffer: false,
|
5816 | type: 'json'
|
5817 | }
|
5818 |
|
5819 | exports.binary = {
|
5820 | encode: function (data) {
|
5821 | return isBinary(data) ? data : Buffer.from(data)
|
5822 | },
|
5823 | decode: identity,
|
5824 | buffer: true,
|
5825 | type: 'binary'
|
5826 | }
|
5827 |
|
5828 | exports.none = {
|
5829 | encode: identity,
|
5830 | decode: identity,
|
5831 | buffer: false,
|
5832 | type: 'id'
|
5833 | }
|
5834 |
|
5835 | exports.id = exports.none
|
5836 |
|
5837 | var bufferEncodings = [
|
5838 | 'hex',
|
5839 | 'ascii',
|
5840 | 'base64',
|
5841 | 'ucs2',
|
5842 | 'ucs-2',
|
5843 | 'utf16le',
|
5844 | 'utf-16le'
|
5845 | ]
|
5846 |
|
5847 | bufferEncodings.forEach(function (type) {
|
5848 | exports[type] = {
|
5849 | encode: function (data) {
|
5850 | return isBinary(data) ? data : Buffer.from(data, type)
|
5851 | },
|
5852 | decode: function (buffer) {
|
5853 | return buffer.toString(type)
|
5854 | },
|
5855 | buffer: true,
|
5856 | type: type
|
5857 | }
|
5858 | })
|
5859 |
|
5860 | function identity (value) {
|
5861 | return value
|
5862 | }
|
5863 |
|
5864 | function isBinary (data) {
|
5865 | return data === undefined || data === null || Buffer.isBuffer(data)
|
5866 | }
|
5867 |
|
5868 | }).call(this,_dereq_(9).Buffer)
|
5869 | },{"9":9}],23:[function(_dereq_,module,exports){
|
5870 | var createError = _dereq_(13).create
|
5871 | var LevelUPError = createError('LevelUPError')
|
5872 | var NotFoundError = createError('NotFoundError', LevelUPError)
|
5873 |
|
5874 | NotFoundError.prototype.notFound = true
|
5875 | NotFoundError.prototype.status = 404
|
5876 |
|
5877 | module.exports = {
|
5878 | LevelUPError: LevelUPError,
|
5879 | InitializationError: createError('InitializationError', LevelUPError),
|
5880 | OpenError: createError('OpenError', LevelUPError),
|
5881 | ReadError: createError('ReadError', LevelUPError),
|
5882 | WriteError: createError('WriteError', LevelUPError),
|
5883 | NotFoundError: NotFoundError,
|
5884 | EncodingError: createError('EncodingError', LevelUPError)
|
5885 | }
|
5886 |
|
5887 | },{"13":13}],24:[function(_dereq_,module,exports){
|
5888 | var inherits = _dereq_(18)
|
5889 | var Readable = _dereq_(39).Readable
|
5890 | var extend = _dereq_(40)
|
5891 |
|
5892 | module.exports = ReadStream
|
5893 | inherits(ReadStream, Readable)
|
5894 |
|
5895 | function ReadStream (iterator, options) {
|
5896 | if (!(this instanceof ReadStream)) return new ReadStream(iterator, options)
|
5897 | options = options || {}
|
5898 | Readable.call(this, extend(options, {
|
5899 | objectMode: true
|
5900 | }))
|
5901 | this._iterator = iterator
|
5902 | this._options = options
|
5903 | this.on('end', this.destroy.bind(this, null, null))
|
5904 | }
|
5905 |
|
5906 | ReadStream.prototype._read = function () {
|
5907 | var self = this
|
5908 | var options = this._options
|
5909 | if (this.destroyed) return
|
5910 |
|
5911 | this._iterator.next(function (err, key, value) {
|
5912 | if (self.destroyed) return
|
5913 | if (err) return self.destroy(err)
|
5914 |
|
5915 | if (key === undefined && value === undefined) {
|
5916 | self.push(null)
|
5917 | } else if (options.keys !== false && options.values === false) {
|
5918 | self.push(key)
|
5919 | } else if (options.keys === false && options.values !== false) {
|
5920 | self.push(value)
|
5921 | } else {
|
5922 | self.push({ key: key, value: value })
|
5923 | }
|
5924 | })
|
5925 | }
|
5926 |
|
5927 | ReadStream.prototype._destroy = function (err, callback) {
|
5928 | this._iterator.end(function (err2) {
|
5929 | callback(err || err2)
|
5930 | })
|
5931 | }
|
5932 |
|
5933 | },{"18":18,"39":39,"40":40}],25:[function(_dereq_,module,exports){
|
5934 | 'use strict';
|
5935 |
|
5936 | function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
|
5937 |
|
5938 | var codes = {};
|
5939 |
|
5940 | function createErrorType(code, message, Base) {
|
5941 | if (!Base) {
|
5942 | Base = Error;
|
5943 | }
|
5944 |
|
5945 | function getMessage(arg1, arg2, arg3) {
|
5946 | if (typeof message === 'string') {
|
5947 | return message;
|
5948 | } else {
|
5949 | return message(arg1, arg2, arg3);
|
5950 | }
|
5951 | }
|
5952 |
|
5953 | var NodeError =
|
5954 |
|
5955 | function (_Base) {
|
5956 | _inheritsLoose(NodeError, _Base);
|
5957 |
|
5958 | function NodeError(arg1, arg2, arg3) {
|
5959 | return _Base.call(this, getMessage(arg1, arg2, arg3)) || this;
|
5960 | }
|
5961 |
|
5962 | return NodeError;
|
5963 | }(Base);
|
5964 |
|
5965 | NodeError.prototype.name = Base.name;
|
5966 | NodeError.prototype.code = code;
|
5967 | codes[code] = NodeError;
|
5968 | }
|
5969 |
|
5970 |
|
5971 | function oneOf(expected, thing) {
|
5972 | if (Array.isArray(expected)) {
|
5973 | var len = expected.length;
|
5974 | expected = expected.map(function (i) {
|
5975 | return String(i);
|
5976 | });
|
5977 |
|
5978 | if (len > 2) {
|
5979 | return "one of ".concat(thing, " ").concat(expected.slice(0, len - 1).join(', '), ", or ") + expected[len - 1];
|
5980 | } else if (len === 2) {
|
5981 | return "one of ".concat(thing, " ").concat(expected[0], " or ").concat(expected[1]);
|
5982 | } else {
|
5983 | return "of ".concat(thing, " ").concat(expected[0]);
|
5984 | }
|
5985 | } else {
|
5986 | return "of ".concat(thing, " ").concat(String(expected));
|
5987 | }
|
5988 | }
|
5989 |
|
5990 |
|
5991 | function startsWith(str, search, pos) {
|
5992 | return str.substr(!pos || pos < 0 ? 0 : +pos, search.length) === search;
|
5993 | }
|
5994 |
|
5995 |
|
5996 | function endsWith(str, search, this_len) {
|
5997 | if (this_len === undefined || this_len > str.length) {
|
5998 | this_len = str.length;
|
5999 | }
|
6000 |
|
6001 | return str.substring(this_len - search.length, this_len) === search;
|
6002 | }
|
6003 |
|
6004 |
|
6005 | function includes(str, search, start) {
|
6006 | if (typeof start !== 'number') {
|
6007 | start = 0;
|
6008 | }
|
6009 |
|
6010 | if (start + search.length > str.length) {
|
6011 | return false;
|
6012 | } else {
|
6013 | return str.indexOf(search, start) !== -1;
|
6014 | }
|
6015 | }
|
6016 |
|
6017 | createErrorType('ERR_INVALID_OPT_VALUE', function (name, value) {
|
6018 | return 'The value "' + value + '" is invalid for option "' + name + '"';
|
6019 | }, TypeError);
|
6020 | createErrorType('ERR_INVALID_ARG_TYPE', function (name, expected, actual) {
|
6021 |
|
6022 | var determiner;
|
6023 |
|
6024 | if (typeof expected === 'string' && startsWith(expected, 'not ')) {
|
6025 | determiner = 'must not be';
|
6026 | expected = expected.replace(/^not /, '');
|
6027 | } else {
|
6028 | determiner = 'must be';
|
6029 | }
|
6030 |
|
6031 | var msg;
|
6032 |
|
6033 | if (endsWith(name, ' argument')) {
|
6034 |
|
6035 | msg = "The ".concat(name, " ").concat(determiner, " ").concat(oneOf(expected, 'type'));
|
6036 | } else {
|
6037 | var type = includes(name, '.') ? 'property' : 'argument';
|
6038 | msg = "The \"".concat(name, "\" ").concat(type, " ").concat(determiner, " ").concat(oneOf(expected, 'type'));
|
6039 | }
|
6040 |
|
6041 | msg += ". Received type ".concat(typeof actual);
|
6042 | return msg;
|
6043 | }, TypeError);
|
6044 | createErrorType('ERR_STREAM_PUSH_AFTER_EOF', 'stream.push() after EOF');
|
6045 | createErrorType('ERR_METHOD_NOT_IMPLEMENTED', function (name) {
|
6046 | return 'The ' + name + ' method is not implemented';
|
6047 | });
|
6048 | createErrorType('ERR_STREAM_PREMATURE_CLOSE', 'Premature close');
|
6049 | createErrorType('ERR_STREAM_DESTROYED', function (name) {
|
6050 | return 'Cannot call ' + name + ' after a stream was destroyed';
|
6051 | });
|
6052 | createErrorType('ERR_MULTIPLE_CALLBACK', 'Callback called multiple times');
|
6053 | createErrorType('ERR_STREAM_CANNOT_PIPE', 'Cannot pipe, not readable');
|
6054 | createErrorType('ERR_STREAM_WRITE_AFTER_END', 'write after end');
|
6055 | createErrorType('ERR_STREAM_NULL_VALUES', 'May not write null values to stream', TypeError);
|
6056 | createErrorType('ERR_UNKNOWN_ENCODING', function (arg) {
|
6057 | return 'Unknown encoding: ' + arg;
|
6058 | }, TypeError);
|
6059 | createErrorType('ERR_STREAM_UNSHIFT_AFTER_END_EVENT', 'stream.unshift() after end event');
|
6060 | module.exports.codes = codes;
|
6061 |
|
6062 | },{}],26:[function(_dereq_,module,exports){
|
6063 | (function (process){
|
6064 |
|
6065 |
|
6066 |
|
6067 |
|
6068 |
|
6069 |
|
6070 |
|
6071 |
|
6072 |
|
6073 |
|
6074 |
|
6075 |
|
6076 |
|
6077 |
|
6078 |
|
6079 |
|
6080 |
|
6081 |
|
6082 |
|
6083 |
|
6084 |
|
6085 |
|
6086 |
|
6087 |
|
6088 | 'use strict';
|
6089 |
|
6090 |
|
6091 | var objectKeys = Object.keys || function (obj) {
|
6092 | var keys = [];
|
6093 |
|
6094 | for (var key in obj) {
|
6095 | keys.push(key);
|
6096 | }
|
6097 |
|
6098 | return keys;
|
6099 | };
|
6100 |
|
6101 |
|
6102 |
|
6103 | module.exports = Duplex;
|
6104 |
|
6105 | var Readable = _dereq_(28);
|
6106 |
|
6107 | var Writable = _dereq_(30);
|
6108 |
|
6109 | _dereq_(18)(Duplex, Readable);
|
6110 |
|
6111 | {
|
6112 |
|
6113 | var keys = objectKeys(Writable.prototype);
|
6114 |
|
6115 | for (var v = 0; v < keys.length; v++) {
|
6116 | var method = keys[v];
|
6117 | if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method];
|
6118 | }
|
6119 | }
|
6120 |
|
6121 | function Duplex(options) {
|
6122 | if (!(this instanceof Duplex)) return new Duplex(options);
|
6123 | Readable.call(this, options);
|
6124 | Writable.call(this, options);
|
6125 | this.allowHalfOpen = true;
|
6126 |
|
6127 | if (options) {
|
6128 | if (options.readable === false) this.readable = false;
|
6129 | if (options.writable === false) this.writable = false;
|
6130 |
|
6131 | if (options.allowHalfOpen === false) {
|
6132 | this.allowHalfOpen = false;
|
6133 | this.once('end', onend);
|
6134 | }
|
6135 | }
|
6136 | }
|
6137 |
|
6138 | Object.defineProperty(Duplex.prototype, 'writableHighWaterMark', {
|
6139 |
|
6140 |
|
6141 |
|
6142 | enumerable: false,
|
6143 | get: function get() {
|
6144 | return this._writableState.highWaterMark;
|
6145 | }
|
6146 | });
|
6147 | Object.defineProperty(Duplex.prototype, 'writableBuffer', {
|
6148 |
|
6149 |
|
6150 |
|
6151 | enumerable: false,
|
6152 | get: function get() {
|
6153 | return this._writableState && this._writableState.getBuffer();
|
6154 | }
|
6155 | });
|
6156 | Object.defineProperty(Duplex.prototype, 'writableLength', {
|
6157 |
|
6158 |
|
6159 |
|
6160 | enumerable: false,
|
6161 | get: function get() {
|
6162 | return this._writableState.length;
|
6163 | }
|
6164 | });
|
6165 |
|
6166 | function onend() {
|
6167 |
|
6168 | if (this._writableState.ended) return;
|
6169 |
|
6170 |
|
6171 | process.nextTick(onEndNT, this);
|
6172 | }
|
6173 |
|
6174 | function onEndNT(self) {
|
6175 | self.end();
|
6176 | }
|
6177 |
|
6178 | Object.defineProperty(Duplex.prototype, 'destroyed', {
|
6179 |
|
6180 |
|
6181 |
|
6182 | enumerable: false,
|
6183 | get: function get() {
|
6184 | if (this._readableState === undefined || this._writableState === undefined) {
|
6185 | return false;
|
6186 | }
|
6187 |
|
6188 | return this._readableState.destroyed && this._writableState.destroyed;
|
6189 | },
|
6190 | set: function set(value) {
|
6191 |
|
6192 |
|
6193 | if (this._readableState === undefined || this._writableState === undefined) {
|
6194 | return;
|
6195 | }
|
6196 |
|
6197 |
|
6198 |
|
6199 | this._readableState.destroyed = value;
|
6200 | this._writableState.destroyed = value;
|
6201 | }
|
6202 | });
|
6203 | }).call(this,_dereq_(70))
|
6204 | },{"18":18,"28":28,"30":30,"70":70}],27:[function(_dereq_,module,exports){
|
6205 |
|
6206 |
|
6207 |
|
6208 |
|
6209 |
|
6210 |
|
6211 |
|
6212 |
|
6213 |
|
6214 |
|
6215 |
|
6216 |
|
6217 |
|
6218 |
|
6219 |
|
6220 |
|
6221 |
|
6222 |
|
6223 |
|
6224 |
|
6225 |
|
6226 |
|
6227 |
|
6228 | 'use strict';
|
6229 |
|
6230 | module.exports = PassThrough;
|
6231 |
|
6232 | var Transform = _dereq_(29);
|
6233 |
|
6234 | _dereq_(18)(PassThrough, Transform);
|
6235 |
|
6236 | function PassThrough(options) {
|
6237 | if (!(this instanceof PassThrough)) return new PassThrough(options);
|
6238 | Transform.call(this, options);
|
6239 | }
|
6240 |
|
6241 | PassThrough.prototype._transform = function (chunk, encoding, cb) {
|
6242 | cb(null, chunk);
|
6243 | };
|
6244 | },{"18":18,"29":29}],28:[function(_dereq_,module,exports){
|
6245 | (function (process,global){
|
6246 |
|
6247 |
|
6248 |
|
6249 |
|
6250 |
|
6251 |
|
6252 |
|
6253 |
|
6254 |
|
6255 |
|
6256 |
|
6257 |
|
6258 |
|
6259 |
|
6260 |
|
6261 |
|
6262 |
|
6263 |
|
6264 |
|
6265 |
|
6266 | 'use strict';
|
6267 |
|
6268 | module.exports = Readable;
|
6269 |
|
6270 |
|
6271 | var Duplex;
|
6272 |
|
6273 |
|
6274 | Readable.ReadableState = ReadableState;
|
6275 |
|
6276 |
|
6277 | var EE = _dereq_(14).EventEmitter;
|
6278 |
|
6279 | var EElistenerCount = function EElistenerCount(emitter, type) {
|
6280 | return emitter.listeners(type).length;
|
6281 | };
|
6282 |
|
6283 |
|
6284 |
|
6285 |
|
6286 |
|
6287 | var Stream = _dereq_(38);
|
6288 |
|
6289 |
|
6290 |
|
6291 | var Buffer = _dereq_(9).Buffer;
|
6292 |
|
6293 | var OurUint8Array = global.Uint8Array || function () {};
|
6294 |
|
6295 | function _uint8ArrayToBuffer(chunk) {
|
6296 | return Buffer.from(chunk);
|
6297 | }
|
6298 |
|
6299 | function _isUint8Array(obj) {
|
6300 | return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
|
6301 | }
|
6302 |
|
6303 |
|
6304 |
|
6305 | var debugUtil = _dereq_(7);
|
6306 |
|
6307 | var debug;
|
6308 |
|
6309 | if (debugUtil && debugUtil.debuglog) {
|
6310 | debug = debugUtil.debuglog('stream');
|
6311 | } else {
|
6312 | debug = function debug() {};
|
6313 | }
|
6314 |
|
6315 |
|
6316 |
|
6317 | var BufferList = _dereq_(32);
|
6318 |
|
6319 | var destroyImpl = _dereq_(33);
|
6320 |
|
6321 | var _require = _dereq_(37),
|
6322 | getHighWaterMark = _require.getHighWaterMark;
|
6323 |
|
6324 | var _require$codes = _dereq_(25).codes,
|
6325 | ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE,
|
6326 | ERR_STREAM_PUSH_AFTER_EOF = _require$codes.ERR_STREAM_PUSH_AFTER_EOF,
|
6327 | ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED,
|
6328 | ERR_STREAM_UNSHIFT_AFTER_END_EVENT = _require$codes.ERR_STREAM_UNSHIFT_AFTER_END_EVENT;
|
6329 |
|
6330 |
|
6331 | var StringDecoder;
|
6332 | var createReadableStreamAsyncIterator;
|
6333 | var from;
|
6334 |
|
6335 | _dereq_(18)(Readable, Stream);
|
6336 |
|
6337 | var errorOrDestroy = destroyImpl.errorOrDestroy;
|
6338 | var kProxyEvents = ['error', 'close', 'destroy', 'pause', 'resume'];
|
6339 |
|
6340 | function prependListener(emitter, event, fn) {
|
6341 |
|
6342 |
|
6343 | if (typeof emitter.prependListener === 'function') return emitter.prependListener(event, fn);
|
6344 |
|
6345 |
|
6346 |
|
6347 |
|
6348 | if (!emitter._events || !emitter._events[event]) emitter.on(event, fn);else if (Array.isArray(emitter._events[event])) emitter._events[event].unshift(fn);else emitter._events[event] = [fn, emitter._events[event]];
|
6349 | }
|
6350 |
|
6351 | function ReadableState(options, stream, isDuplex) {
|
6352 | Duplex = Duplex || _dereq_(26);
|
6353 | options = options || {};
|
6354 |
|
6355 |
|
6356 |
|
6357 |
|
6358 |
|
6359 | if (typeof isDuplex !== 'boolean') isDuplex = stream instanceof Duplex;
|
6360 |
|
6361 |
|
6362 | this.objectMode = !!options.objectMode;
|
6363 | if (isDuplex) this.objectMode = this.objectMode || !!options.readableObjectMode;
|
6364 |
|
6365 |
|
6366 | this.highWaterMark = getHighWaterMark(this, options, 'readableHighWaterMark', isDuplex);
|
6367 |
|
6368 |
|
6369 |
|
6370 | this.buffer = new BufferList();
|
6371 | this.length = 0;
|
6372 | this.pipes = null;
|
6373 | this.pipesCount = 0;
|
6374 | this.flowing = null;
|
6375 | this.ended = false;
|
6376 | this.endEmitted = false;
|
6377 | this.reading = false;
|
6378 |
|
6379 |
|
6380 |
|
6381 |
|
6382 | this.sync = true;
|
6383 |
|
6384 |
|
6385 | this.needReadable = false;
|
6386 | this.emittedReadable = false;
|
6387 | this.readableListening = false;
|
6388 | this.resumeScheduled = false;
|
6389 | this.paused = true;
|
6390 |
|
6391 | this.emitClose = options.emitClose !== false;
|
6392 |
|
6393 | this.autoDestroy = !!options.autoDestroy;
|
6394 |
|
6395 | this.destroyed = false;
|
6396 |
|
6397 |
|
6398 |
|
6399 | this.defaultEncoding = options.defaultEncoding || 'utf8';
|
6400 |
|
6401 | this.awaitDrain = 0;
|
6402 |
|
6403 | this.readingMore = false;
|
6404 | this.decoder = null;
|
6405 | this.encoding = null;
|
6406 |
|
6407 | if (options.encoding) {
|
6408 | if (!StringDecoder) StringDecoder = _dereq_(98).StringDecoder;
|
6409 | this.decoder = new StringDecoder(options.encoding);
|
6410 | this.encoding = options.encoding;
|
6411 | }
|
6412 | }
|
6413 |
|
6414 | function Readable(options) {
|
6415 | Duplex = Duplex || _dereq_(26);
|
6416 | if (!(this instanceof Readable)) return new Readable(options);
|
6417 |
|
6418 |
|
6419 | var isDuplex = this instanceof Duplex;
|
6420 | this._readableState = new ReadableState(options, this, isDuplex);
|
6421 |
|
6422 | this.readable = true;
|
6423 |
|
6424 | if (options) {
|
6425 | if (typeof options.read === 'function') this._read = options.read;
|
6426 | if (typeof options.destroy === 'function') this._destroy = options.destroy;
|
6427 | }
|
6428 |
|
6429 | Stream.call(this);
|
6430 | }
|
6431 |
|
6432 | Object.defineProperty(Readable.prototype, 'destroyed', {
|
6433 |
|
6434 |
|
6435 |
|
6436 | enumerable: false,
|
6437 | get: function get() {
|
6438 | if (this._readableState === undefined) {
|
6439 | return false;
|
6440 | }
|
6441 |
|
6442 | return this._readableState.destroyed;
|
6443 | },
|
6444 | set: function set(value) {
|
6445 |
|
6446 |
|
6447 | if (!this._readableState) {
|
6448 | return;
|
6449 | }
|
6450 |
|
6451 |
|
6452 |
|
6453 | this._readableState.destroyed = value;
|
6454 | }
|
6455 | });
|
6456 | Readable.prototype.destroy = destroyImpl.destroy;
|
6457 | Readable.prototype._undestroy = destroyImpl.undestroy;
|
6458 |
|
6459 | Readable.prototype._destroy = function (err, cb) {
|
6460 | cb(err);
|
6461 | };
|
6462 |
|
6463 |
|
6464 |
|
6465 |
|
6466 |
|
6467 | Readable.prototype.push = function (chunk, encoding) {
|
6468 | var state = this._readableState;
|
6469 | var skipChunkCheck;
|
6470 |
|
6471 | if (!state.objectMode) {
|
6472 | if (typeof chunk === 'string') {
|
6473 | encoding = encoding || state.defaultEncoding;
|
6474 |
|
6475 | if (encoding !== state.encoding) {
|
6476 | chunk = Buffer.from(chunk, encoding);
|
6477 | encoding = '';
|
6478 | }
|
6479 |
|
6480 | skipChunkCheck = true;
|
6481 | }
|
6482 | } else {
|
6483 | skipChunkCheck = true;
|
6484 | }
|
6485 |
|
6486 | return readableAddChunk(this, chunk, encoding, false, skipChunkCheck);
|
6487 | };
|
6488 |
|
6489 |
|
6490 | Readable.prototype.unshift = function (chunk) {
|
6491 | return readableAddChunk(this, chunk, null, true, false);
|
6492 | };
|
6493 |
|
6494 | function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) {
|
6495 | debug('readableAddChunk', chunk);
|
6496 | var state = stream._readableState;
|
6497 |
|
6498 | if (chunk === null) {
|
6499 | state.reading = false;
|
6500 | onEofChunk(stream, state);
|
6501 | } else {
|
6502 | var er;
|
6503 | if (!skipChunkCheck) er = chunkInvalid(state, chunk);
|
6504 |
|
6505 | if (er) {
|
6506 | errorOrDestroy(stream, er);
|
6507 | } else if (state.objectMode || chunk && chunk.length > 0) {
|
6508 | if (typeof chunk !== 'string' && !state.objectMode && Object.getPrototypeOf(chunk) !== Buffer.prototype) {
|
6509 | chunk = _uint8ArrayToBuffer(chunk);
|
6510 | }
|
6511 |
|
6512 | if (addToFront) {
|
6513 | if (state.endEmitted) errorOrDestroy(stream, new ERR_STREAM_UNSHIFT_AFTER_END_EVENT());else addChunk(stream, state, chunk, true);
|
6514 | } else if (state.ended) {
|
6515 | errorOrDestroy(stream, new ERR_STREAM_PUSH_AFTER_EOF());
|
6516 | } else if (state.destroyed) {
|
6517 | return false;
|
6518 | } else {
|
6519 | state.reading = false;
|
6520 |
|
6521 | if (state.decoder && !encoding) {
|
6522 | chunk = state.decoder.write(chunk);
|
6523 | if (state.objectMode || chunk.length !== 0) addChunk(stream, state, chunk, false);else maybeReadMore(stream, state);
|
6524 | } else {
|
6525 | addChunk(stream, state, chunk, false);
|
6526 | }
|
6527 | }
|
6528 | } else if (!addToFront) {
|
6529 | state.reading = false;
|
6530 | maybeReadMore(stream, state);
|
6531 | }
|
6532 | }
|
6533 |
|
6534 |
|
6535 |
|
6536 |
|
6537 | return !state.ended && (state.length < state.highWaterMark || state.length === 0);
|
6538 | }
|
6539 |
|
6540 | function addChunk(stream, state, chunk, addToFront) {
|
6541 | if (state.flowing && state.length === 0 && !state.sync) {
|
6542 | state.awaitDrain = 0;
|
6543 | stream.emit('data', chunk);
|
6544 | } else {
|
6545 |
|
6546 | state.length += state.objectMode ? 1 : chunk.length;
|
6547 | if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk);
|
6548 | if (state.needReadable) emitReadable(stream);
|
6549 | }
|
6550 |
|
6551 | maybeReadMore(stream, state);
|
6552 | }
|
6553 |
|
6554 | function chunkInvalid(state, chunk) {
|
6555 | var er;
|
6556 |
|
6557 | if (!_isUint8Array(chunk) && typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
|
6558 | er = new ERR_INVALID_ARG_TYPE('chunk', ['string', 'Buffer', 'Uint8Array'], chunk);
|
6559 | }
|
6560 |
|
6561 | return er;
|
6562 | }
|
6563 |
|
6564 | Readable.prototype.isPaused = function () {
|
6565 | return this._readableState.flowing === false;
|
6566 | };
|
6567 |
|
6568 |
|
6569 | Readable.prototype.setEncoding = function (enc) {
|
6570 | if (!StringDecoder) StringDecoder = _dereq_(98).StringDecoder;
|
6571 | var decoder = new StringDecoder(enc);
|
6572 | this._readableState.decoder = decoder;
|
6573 |
|
6574 | this._readableState.encoding = this._readableState.decoder.encoding;
|
6575 |
|
6576 | var p = this._readableState.buffer.head;
|
6577 | var content = '';
|
6578 |
|
6579 | while (p !== null) {
|
6580 | content += decoder.write(p.data);
|
6581 | p = p.next;
|
6582 | }
|
6583 |
|
6584 | this._readableState.buffer.clear();
|
6585 |
|
6586 | if (content !== '') this._readableState.buffer.push(content);
|
6587 | this._readableState.length = content.length;
|
6588 | return this;
|
6589 | };
|
6590 |
|
6591 |
|
6592 | var MAX_HWM = 0x40000000;
|
6593 |
|
6594 | function computeNewHighWaterMark(n) {
|
6595 | if (n >= MAX_HWM) {
|
6596 |
|
6597 | n = MAX_HWM;
|
6598 | } else {
|
6599 |
|
6600 |
|
6601 | n--;
|
6602 | n |= n >>> 1;
|
6603 | n |= n >>> 2;
|
6604 | n |= n >>> 4;
|
6605 | n |= n >>> 8;
|
6606 | n |= n >>> 16;
|
6607 | n++;
|
6608 | }
|
6609 |
|
6610 | return n;
|
6611 | }
|
6612 |
|
6613 |
|
6614 |
|
6615 | function howMuchToRead(n, state) {
|
6616 | if (n <= 0 || state.length === 0 && state.ended) return 0;
|
6617 | if (state.objectMode) return 1;
|
6618 |
|
6619 | if (n !== n) {
|
6620 |
|
6621 | if (state.flowing && state.length) return state.buffer.head.data.length;else return state.length;
|
6622 | }
|
6623 |
|
6624 |
|
6625 | if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n);
|
6626 | if (n <= state.length) return n;
|
6627 |
|
6628 | if (!state.ended) {
|
6629 | state.needReadable = true;
|
6630 | return 0;
|
6631 | }
|
6632 |
|
6633 | return state.length;
|
6634 | }
|
6635 |
|
6636 |
|
6637 | Readable.prototype.read = function (n) {
|
6638 | debug('read', n);
|
6639 | n = parseInt(n, 10);
|
6640 | var state = this._readableState;
|
6641 | var nOrig = n;
|
6642 | if (n !== 0) state.emittedReadable = false;
|
6643 |
|
6644 |
|
6645 |
|
6646 | if (n === 0 && state.needReadable && ((state.highWaterMark !== 0 ? state.length >= state.highWaterMark : state.length > 0) || state.ended)) {
|
6647 | debug('read: emitReadable', state.length, state.ended);
|
6648 | if (state.length === 0 && state.ended) endReadable(this);else emitReadable(this);
|
6649 | return null;
|
6650 | }
|
6651 |
|
6652 | n = howMuchToRead(n, state);
|
6653 |
|
6654 | if (n === 0 && state.ended) {
|
6655 | if (state.length === 0) endReadable(this);
|
6656 | return null;
|
6657 | }
|
6658 |
|
6659 |
|
6660 |
|
6661 |
|
6662 |
|
6663 |
|
6664 |
|
6665 |
|
6666 |
|
6667 |
|
6668 |
|
6669 |
|
6670 |
|
6671 |
|
6672 |
|
6673 |
|
6674 |
|
6675 |
|
6676 |
|
6677 |
|
6678 |
|
6679 |
|
6680 |
|
6681 | var doRead = state.needReadable;
|
6682 | debug('need readable', doRead);
|
6683 |
|
6684 | if (state.length === 0 || state.length - n < state.highWaterMark) {
|
6685 | doRead = true;
|
6686 | debug('length less than watermark', doRead);
|
6687 | }
|
6688 |
|
6689 |
|
6690 |
|
6691 | if (state.ended || state.reading) {
|
6692 | doRead = false;
|
6693 | debug('reading or ended', doRead);
|
6694 | } else if (doRead) {
|
6695 | debug('do read');
|
6696 | state.reading = true;
|
6697 | state.sync = true;
|
6698 |
|
6699 | if (state.length === 0) state.needReadable = true;
|
6700 |
|
6701 | this._read(state.highWaterMark);
|
6702 |
|
6703 | state.sync = false;
|
6704 |
|
6705 |
|
6706 | if (!state.reading) n = howMuchToRead(nOrig, state);
|
6707 | }
|
6708 |
|
6709 | var ret;
|
6710 | if (n > 0) ret = fromList(n, state);else ret = null;
|
6711 |
|
6712 | if (ret === null) {
|
6713 | state.needReadable = state.length <= state.highWaterMark;
|
6714 | n = 0;
|
6715 | } else {
|
6716 | state.length -= n;
|
6717 | state.awaitDrain = 0;
|
6718 | }
|
6719 |
|
6720 | if (state.length === 0) {
|
6721 |
|
6722 |
|
6723 | if (!state.ended) state.needReadable = true;
|
6724 |
|
6725 | if (nOrig !== n && state.ended) endReadable(this);
|
6726 | }
|
6727 |
|
6728 | if (ret !== null) this.emit('data', ret);
|
6729 | return ret;
|
6730 | };
|
6731 |
|
6732 | function onEofChunk(stream, state) {
|
6733 | debug('onEofChunk');
|
6734 | if (state.ended) return;
|
6735 |
|
6736 | if (state.decoder) {
|
6737 | var chunk = state.decoder.end();
|
6738 |
|
6739 | if (chunk && chunk.length) {
|
6740 | state.buffer.push(chunk);
|
6741 | state.length += state.objectMode ? 1 : chunk.length;
|
6742 | }
|
6743 | }
|
6744 |
|
6745 | state.ended = true;
|
6746 |
|
6747 | if (state.sync) {
|
6748 |
|
6749 |
|
6750 |
|
6751 | emitReadable(stream);
|
6752 | } else {
|
6753 |
|
6754 | state.needReadable = false;
|
6755 |
|
6756 | if (!state.emittedReadable) {
|
6757 | state.emittedReadable = true;
|
6758 | emitReadable_(stream);
|
6759 | }
|
6760 | }
|
6761 | }
|
6762 |
|
6763 |
|
6764 |
|
6765 |
|
6766 | function emitReadable(stream) {
|
6767 | var state = stream._readableState;
|
6768 | debug('emitReadable', state.needReadable, state.emittedReadable);
|
6769 | state.needReadable = false;
|
6770 |
|
6771 | if (!state.emittedReadable) {
|
6772 | debug('emitReadable', state.flowing);
|
6773 | state.emittedReadable = true;
|
6774 | process.nextTick(emitReadable_, stream);
|
6775 | }
|
6776 | }
|
6777 |
|
6778 | function emitReadable_(stream) {
|
6779 | var state = stream._readableState;
|
6780 | debug('emitReadable_', state.destroyed, state.length, state.ended);
|
6781 |
|
6782 | if (!state.destroyed && (state.length || state.ended)) {
|
6783 | stream.emit('readable');
|
6784 | state.emittedReadable = false;
|
6785 | }
|
6786 |
|
6787 |
|
6788 |
|
6789 |
|
6790 |
|
6791 |
|
6792 |
|
6793 | state.needReadable = !state.flowing && !state.ended && state.length <= state.highWaterMark;
|
6794 | flow(stream);
|
6795 | }
|
6796 |
|
6797 |
|
6798 |
|
6799 |
|
6800 |
|
6801 |
|
6802 |
|
6803 | function maybeReadMore(stream, state) {
|
6804 | if (!state.readingMore) {
|
6805 | state.readingMore = true;
|
6806 | process.nextTick(maybeReadMore_, stream, state);
|
6807 | }
|
6808 | }
|
6809 |
|
6810 | function maybeReadMore_(stream, state) {
|
6811 |
|
6812 |
|
6813 |
|
6814 |
|
6815 |
|
6816 |
|
6817 |
|
6818 |
|
6819 |
|
6820 |
|
6821 |
|
6822 |
|
6823 |
|
6824 |
|
6825 |
|
6826 |
|
6827 |
|
6828 |
|
6829 |
|
6830 |
|
6831 |
|
6832 |
|
6833 |
|
6834 | while (!state.reading && !state.ended && (state.length < state.highWaterMark || state.flowing && state.length === 0)) {
|
6835 | var len = state.length;
|
6836 | debug('maybeReadMore read 0');
|
6837 | stream.read(0);
|
6838 | if (len === state.length)
|
6839 | break;
|
6840 | }
|
6841 |
|
6842 | state.readingMore = false;
|
6843 | }
|
6844 |
|
6845 |
|
6846 |
|
6847 |
|
6848 |
|
6849 | Readable.prototype._read = function (n) {
|
6850 | errorOrDestroy(this, new ERR_METHOD_NOT_IMPLEMENTED('_read()'));
|
6851 | };
|
6852 |
|
6853 | Readable.prototype.pipe = function (dest, pipeOpts) {
|
6854 | var src = this;
|
6855 | var state = this._readableState;
|
6856 |
|
6857 | switch (state.pipesCount) {
|
6858 | case 0:
|
6859 | state.pipes = dest;
|
6860 | break;
|
6861 |
|
6862 | case 1:
|
6863 | state.pipes = [state.pipes, dest];
|
6864 | break;
|
6865 |
|
6866 | default:
|
6867 | state.pipes.push(dest);
|
6868 | break;
|
6869 | }
|
6870 |
|
6871 | state.pipesCount += 1;
|
6872 | debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts);
|
6873 | var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr;
|
6874 | var endFn = doEnd ? onend : unpipe;
|
6875 | if (state.endEmitted) process.nextTick(endFn);else src.once('end', endFn);
|
6876 | dest.on('unpipe', onunpipe);
|
6877 |
|
6878 | function onunpipe(readable, unpipeInfo) {
|
6879 | debug('onunpipe');
|
6880 |
|
6881 | if (readable === src) {
|
6882 | if (unpipeInfo && unpipeInfo.hasUnpiped === false) {
|
6883 | unpipeInfo.hasUnpiped = true;
|
6884 | cleanup();
|
6885 | }
|
6886 | }
|
6887 | }
|
6888 |
|
6889 | function onend() {
|
6890 | debug('onend');
|
6891 | dest.end();
|
6892 | }
|
6893 |
|
6894 |
|
6895 |
|
6896 |
|
6897 |
|
6898 | var ondrain = pipeOnDrain(src);
|
6899 | dest.on('drain', ondrain);
|
6900 | var cleanedUp = false;
|
6901 |
|
6902 | function cleanup() {
|
6903 | debug('cleanup');
|
6904 |
|
6905 | dest.removeListener('close', onclose);
|
6906 | dest.removeListener('finish', onfinish);
|
6907 | dest.removeListener('drain', ondrain);
|
6908 | dest.removeListener('error', onerror);
|
6909 | dest.removeListener('unpipe', onunpipe);
|
6910 | src.removeListener('end', onend);
|
6911 | src.removeListener('end', unpipe);
|
6912 | src.removeListener('data', ondata);
|
6913 | cleanedUp = true;
|
6914 |
|
6915 |
|
6916 |
|
6917 |
|
6918 |
|
6919 | if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain();
|
6920 | }
|
6921 |
|
6922 | src.on('data', ondata);
|
6923 |
|
6924 | function ondata(chunk) {
|
6925 | debug('ondata');
|
6926 | var ret = dest.write(chunk);
|
6927 | debug('dest.write', ret);
|
6928 |
|
6929 | if (ret === false) {
|
6930 |
|
6931 |
|
6932 |
|
6933 |
|
6934 | if ((state.pipesCount === 1 && state.pipes === dest || state.pipesCount > 1 && indexOf(state.pipes, dest) !== -1) && !cleanedUp) {
|
6935 | debug('false write response, pause', state.awaitDrain);
|
6936 | state.awaitDrain++;
|
6937 | }
|
6938 |
|
6939 | src.pause();
|
6940 | }
|
6941 | }
|
6942 |
|
6943 |
|
6944 |
|
6945 | function onerror(er) {
|
6946 | debug('onerror', er);
|
6947 | unpipe();
|
6948 | dest.removeListener('error', onerror);
|
6949 | if (EElistenerCount(dest, 'error') === 0) errorOrDestroy(dest, er);
|
6950 | }
|
6951 |
|
6952 |
|
6953 | prependListener(dest, 'error', onerror);
|
6954 |
|
6955 | function onclose() {
|
6956 | dest.removeListener('finish', onfinish);
|
6957 | unpipe();
|
6958 | }
|
6959 |
|
6960 | dest.once('close', onclose);
|
6961 |
|
6962 | function onfinish() {
|
6963 | debug('onfinish');
|
6964 | dest.removeListener('close', onclose);
|
6965 | unpipe();
|
6966 | }
|
6967 |
|
6968 | dest.once('finish', onfinish);
|
6969 |
|
6970 | function unpipe() {
|
6971 | debug('unpipe');
|
6972 | src.unpipe(dest);
|
6973 | }
|
6974 |
|
6975 |
|
6976 | dest.emit('pipe', src);
|
6977 |
|
6978 | if (!state.flowing) {
|
6979 | debug('pipe resume');
|
6980 | src.resume();
|
6981 | }
|
6982 |
|
6983 | return dest;
|
6984 | };
|
6985 |
|
6986 | function pipeOnDrain(src) {
|
6987 | return function pipeOnDrainFunctionResult() {
|
6988 | var state = src._readableState;
|
6989 | debug('pipeOnDrain', state.awaitDrain);
|
6990 | if (state.awaitDrain) state.awaitDrain--;
|
6991 |
|
6992 | if (state.awaitDrain === 0 && EElistenerCount(src, 'data')) {
|
6993 | state.flowing = true;
|
6994 | flow(src);
|
6995 | }
|
6996 | };
|
6997 | }
|
6998 |
|
6999 | Readable.prototype.unpipe = function (dest) {
|
7000 | var state = this._readableState;
|
7001 | var unpipeInfo = {
|
7002 | hasUnpiped: false
|
7003 | };
|
7004 |
|
7005 | if (state.pipesCount === 0) return this;
|
7006 |
|
7007 | if (state.pipesCount === 1) {
|
7008 |
|
7009 | if (dest && dest !== state.pipes) return this;
|
7010 | if (!dest) dest = state.pipes;
|
7011 |
|
7012 | state.pipes = null;
|
7013 | state.pipesCount = 0;
|
7014 | state.flowing = false;
|
7015 | if (dest) dest.emit('unpipe', this, unpipeInfo);
|
7016 | return this;
|
7017 | }
|
7018 |
|
7019 |
|
7020 | if (!dest) {
|
7021 |
|
7022 | var dests = state.pipes;
|
7023 | var len = state.pipesCount;
|
7024 | state.pipes = null;
|
7025 | state.pipesCount = 0;
|
7026 | state.flowing = false;
|
7027 |
|
7028 | for (var i = 0; i < len; i++) {
|
7029 | dests[i].emit('unpipe', this, {
|
7030 | hasUnpiped: false
|
7031 | });
|
7032 | }
|
7033 |
|
7034 | return this;
|
7035 | }
|
7036 |
|
7037 |
|
7038 | var index = indexOf(state.pipes, dest);
|
7039 | if (index === -1) return this;
|
7040 | state.pipes.splice(index, 1);
|
7041 | state.pipesCount -= 1;
|
7042 | if (state.pipesCount === 1) state.pipes = state.pipes[0];
|
7043 | dest.emit('unpipe', this, unpipeInfo);
|
7044 | return this;
|
7045 | };
|
7046 |
|
7047 |
|
7048 |
|
7049 | Readable.prototype.on = function (ev, fn) {
|
7050 | var res = Stream.prototype.on.call(this, ev, fn);
|
7051 | var state = this._readableState;
|
7052 |
|
7053 | if (ev === 'data') {
|
7054 |
|
7055 |
|
7056 | state.readableListening = this.listenerCount('readable') > 0;
|
7057 |
|
7058 | if (state.flowing !== false) this.resume();
|
7059 | } else if (ev === 'readable') {
|
7060 | if (!state.endEmitted && !state.readableListening) {
|
7061 | state.readableListening = state.needReadable = true;
|
7062 | state.flowing = false;
|
7063 | state.emittedReadable = false;
|
7064 | debug('on readable', state.length, state.reading);
|
7065 |
|
7066 | if (state.length) {
|
7067 | emitReadable(this);
|
7068 | } else if (!state.reading) {
|
7069 | process.nextTick(nReadingNextTick, this);
|
7070 | }
|
7071 | }
|
7072 | }
|
7073 |
|
7074 | return res;
|
7075 | };
|
7076 |
|
7077 | Readable.prototype.addListener = Readable.prototype.on;
|
7078 |
|
7079 | Readable.prototype.removeListener = function (ev, fn) {
|
7080 | var res = Stream.prototype.removeListener.call(this, ev, fn);
|
7081 |
|
7082 | if (ev === 'readable') {
|
7083 |
|
7084 |
|
7085 |
|
7086 |
|
7087 |
|
7088 |
|
7089 | process.nextTick(updateReadableListening, this);
|
7090 | }
|
7091 |
|
7092 | return res;
|
7093 | };
|
7094 |
|
7095 | Readable.prototype.removeAllListeners = function (ev) {
|
7096 | var res = Stream.prototype.removeAllListeners.apply(this, arguments);
|
7097 |
|
7098 | if (ev === 'readable' || ev === undefined) {
|
7099 |
|
7100 |
|
7101 |
|
7102 |
|
7103 |
|
7104 |
|
7105 | process.nextTick(updateReadableListening, this);
|
7106 | }
|
7107 |
|
7108 | return res;
|
7109 | };
|
7110 |
|
7111 | function updateReadableListening(self) {
|
7112 | var state = self._readableState;
|
7113 | state.readableListening = self.listenerCount('readable') > 0;
|
7114 |
|
7115 | if (state.resumeScheduled && !state.paused) {
|
7116 |
|
7117 |
|
7118 | state.flowing = true;
|
7119 | } else if (self.listenerCount('data') > 0) {
|
7120 | self.resume();
|
7121 | }
|
7122 | }
|
7123 |
|
7124 | function nReadingNextTick(self) {
|
7125 | debug('readable nexttick read 0');
|
7126 | self.read(0);
|
7127 | }
|
7128 |
|
7129 |
|
7130 |
|
7131 | Readable.prototype.resume = function () {
|
7132 | var state = this._readableState;
|
7133 |
|
7134 | if (!state.flowing) {
|
7135 | debug('resume');
|
7136 |
|
7137 |
|
7138 |
|
7139 | state.flowing = !state.readableListening;
|
7140 | resume(this, state);
|
7141 | }
|
7142 |
|
7143 | state.paused = false;
|
7144 | return this;
|
7145 | };
|
7146 |
|
7147 | function resume(stream, state) {
|
7148 | if (!state.resumeScheduled) {
|
7149 | state.resumeScheduled = true;
|
7150 | process.nextTick(resume_, stream, state);
|
7151 | }
|
7152 | }
|
7153 |
|
7154 | function resume_(stream, state) {
|
7155 | debug('resume', state.reading);
|
7156 |
|
7157 | if (!state.reading) {
|
7158 | stream.read(0);
|
7159 | }
|
7160 |
|
7161 | state.resumeScheduled = false;
|
7162 | stream.emit('resume');
|
7163 | flow(stream);
|
7164 | if (state.flowing && !state.reading) stream.read(0);
|
7165 | }
|
7166 |
|
7167 | Readable.prototype.pause = function () {
|
7168 | debug('call pause flowing=%j', this._readableState.flowing);
|
7169 |
|
7170 | if (this._readableState.flowing !== false) {
|
7171 | debug('pause');
|
7172 | this._readableState.flowing = false;
|
7173 | this.emit('pause');
|
7174 | }
|
7175 |
|
7176 | this._readableState.paused = true;
|
7177 | return this;
|
7178 | };
|
7179 |
|
7180 | function flow(stream) {
|
7181 | var state = stream._readableState;
|
7182 | debug('flow', state.flowing);
|
7183 |
|
7184 | while (state.flowing && stream.read() !== null) {
|
7185 | ;
|
7186 | }
|
7187 | }
|
7188 |
|
7189 |
|
7190 |
|
7191 |
|
7192 | Readable.prototype.wrap = function (stream) {
|
7193 | var _this = this;
|
7194 |
|
7195 | var state = this._readableState;
|
7196 | var paused = false;
|
7197 | stream.on('end', function () {
|
7198 | debug('wrapped end');
|
7199 |
|
7200 | if (state.decoder && !state.ended) {
|
7201 | var chunk = state.decoder.end();
|
7202 | if (chunk && chunk.length) _this.push(chunk);
|
7203 | }
|
7204 |
|
7205 | _this.push(null);
|
7206 | });
|
7207 | stream.on('data', function (chunk) {
|
7208 | debug('wrapped data');
|
7209 | if (state.decoder) chunk = state.decoder.write(chunk);
|
7210 |
|
7211 | if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return;
|
7212 |
|
7213 | var ret = _this.push(chunk);
|
7214 |
|
7215 | if (!ret) {
|
7216 | paused = true;
|
7217 | stream.pause();
|
7218 | }
|
7219 | });
|
7220 |
|
7221 |
|
7222 | for (var i in stream) {
|
7223 | if (this[i] === undefined && typeof stream[i] === 'function') {
|
7224 | this[i] = function methodWrap(method) {
|
7225 | return function methodWrapReturnFunction() {
|
7226 | return stream[method].apply(stream, arguments);
|
7227 | };
|
7228 | }(i);
|
7229 | }
|
7230 | }
|
7231 |
|
7232 |
|
7233 | for (var n = 0; n < kProxyEvents.length; n++) {
|
7234 | stream.on(kProxyEvents[n], this.emit.bind(this, kProxyEvents[n]));
|
7235 | }
|
7236 |
|
7237 |
|
7238 |
|
7239 | this._read = function (n) {
|
7240 | debug('wrapped _read', n);
|
7241 |
|
7242 | if (paused) {
|
7243 | paused = false;
|
7244 | stream.resume();
|
7245 | }
|
7246 | };
|
7247 |
|
7248 | return this;
|
7249 | };
|
7250 |
|
7251 | if (typeof Symbol === 'function') {
|
7252 | Readable.prototype[Symbol.asyncIterator] = function () {
|
7253 | if (createReadableStreamAsyncIterator === undefined) {
|
7254 | createReadableStreamAsyncIterator = _dereq_(31);
|
7255 | }
|
7256 |
|
7257 | return createReadableStreamAsyncIterator(this);
|
7258 | };
|
7259 | }
|
7260 |
|
7261 | Object.defineProperty(Readable.prototype, 'readableHighWaterMark', {
|
7262 |
|
7263 |
|
7264 |
|
7265 | enumerable: false,
|
7266 | get: function get() {
|
7267 | return this._readableState.highWaterMark;
|
7268 | }
|
7269 | });
|
7270 | Object.defineProperty(Readable.prototype, 'readableBuffer', {
|
7271 |
|
7272 |
|
7273 |
|
7274 | enumerable: false,
|
7275 | get: function get() {
|
7276 | return this._readableState && this._readableState.buffer;
|
7277 | }
|
7278 | });
|
7279 | Object.defineProperty(Readable.prototype, 'readableFlowing', {
|
7280 |
|
7281 |
|
7282 |
|
7283 | enumerable: false,
|
7284 | get: function get() {
|
7285 | return this._readableState.flowing;
|
7286 | },
|
7287 | set: function set(state) {
|
7288 | if (this._readableState) {
|
7289 | this._readableState.flowing = state;
|
7290 | }
|
7291 | }
|
7292 | });
|
7293 |
|
7294 | Readable._fromList = fromList;
|
7295 | Object.defineProperty(Readable.prototype, 'readableLength', {
|
7296 |
|
7297 |
|
7298 |
|
7299 | enumerable: false,
|
7300 | get: function get() {
|
7301 | return this._readableState.length;
|
7302 | }
|
7303 | });
|
7304 |
|
7305 |
|
7306 |
|
7307 |
|
7308 | function fromList(n, state) {
|
7309 |
|
7310 | if (state.length === 0) return null;
|
7311 | var ret;
|
7312 | if (state.objectMode) ret = state.buffer.shift();else if (!n || n >= state.length) {
|
7313 |
|
7314 | if (state.decoder) ret = state.buffer.join('');else if (state.buffer.length === 1) ret = state.buffer.first();else ret = state.buffer.concat(state.length);
|
7315 | state.buffer.clear();
|
7316 | } else {
|
7317 |
|
7318 | ret = state.buffer.consume(n, state.decoder);
|
7319 | }
|
7320 | return ret;
|
7321 | }
|
7322 |
|
7323 | function endReadable(stream) {
|
7324 | var state = stream._readableState;
|
7325 | debug('endReadable', state.endEmitted);
|
7326 |
|
7327 | if (!state.endEmitted) {
|
7328 | state.ended = true;
|
7329 | process.nextTick(endReadableNT, state, stream);
|
7330 | }
|
7331 | }
|
7332 |
|
7333 | function endReadableNT(state, stream) {
|
7334 | debug('endReadableNT', state.endEmitted, state.length);
|
7335 |
|
7336 | if (!state.endEmitted && state.length === 0) {
|
7337 | state.endEmitted = true;
|
7338 | stream.readable = false;
|
7339 | stream.emit('end');
|
7340 |
|
7341 | if (state.autoDestroy) {
|
7342 |
|
7343 |
|
7344 | var wState = stream._writableState;
|
7345 |
|
7346 | if (!wState || wState.autoDestroy && wState.finished) {
|
7347 | stream.destroy();
|
7348 | }
|
7349 | }
|
7350 | }
|
7351 | }
|
7352 |
|
7353 | if (typeof Symbol === 'function') {
|
7354 | Readable.from = function (iterable, opts) {
|
7355 | if (from === undefined) {
|
7356 | from = _dereq_(35);
|
7357 | }
|
7358 |
|
7359 | return from(Readable, iterable, opts);
|
7360 | };
|
7361 | }
|
7362 |
|
7363 | function indexOf(xs, x) {
|
7364 | for (var i = 0, l = xs.length; i < l; i++) {
|
7365 | if (xs[i] === x) return i;
|
7366 | }
|
7367 |
|
7368 | return -1;
|
7369 | }
|
7370 | }).call(this,_dereq_(70),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
7371 | },{"14":14,"18":18,"25":25,"26":26,"31":31,"32":32,"33":33,"35":35,"37":37,"38":38,"7":7,"70":70,"9":9,"98":98}],29:[function(_dereq_,module,exports){
|
7372 |
|
7373 |
|
7374 |
|
7375 |
|
7376 |
|
7377 |
|
7378 |
|
7379 |
|
7380 |
|
7381 |
|
7382 |
|
7383 |
|
7384 |
|
7385 |
|
7386 |
|
7387 |
|
7388 |
|
7389 |
|
7390 |
|
7391 |
|
7392 |
|
7393 |
|
7394 |
|
7395 |
|
7396 |
|
7397 |
|
7398 |
|
7399 |
|
7400 |
|
7401 |
|
7402 |
|
7403 |
|
7404 |
|
7405 |
|
7406 |
|
7407 |
|
7408 |
|
7409 |
|
7410 |
|
7411 |
|
7412 |
|
7413 |
|
7414 |
|
7415 |
|
7416 |
|
7417 |
|
7418 |
|
7419 |
|
7420 |
|
7421 |
|
7422 |
|
7423 |
|
7424 |
|
7425 |
|
7426 |
|
7427 |
|
7428 |
|
7429 |
|
7430 |
|
7431 |
|
7432 |
|
7433 | 'use strict';
|
7434 |
|
7435 | module.exports = Transform;
|
7436 |
|
7437 | var _require$codes = _dereq_(25).codes,
|
7438 | ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED,
|
7439 | ERR_MULTIPLE_CALLBACK = _require$codes.ERR_MULTIPLE_CALLBACK,
|
7440 | ERR_TRANSFORM_ALREADY_TRANSFORMING = _require$codes.ERR_TRANSFORM_ALREADY_TRANSFORMING,
|
7441 | ERR_TRANSFORM_WITH_LENGTH_0 = _require$codes.ERR_TRANSFORM_WITH_LENGTH_0;
|
7442 |
|
7443 | var Duplex = _dereq_(26);
|
7444 |
|
7445 | _dereq_(18)(Transform, Duplex);
|
7446 |
|
7447 | function afterTransform(er, data) {
|
7448 | var ts = this._transformState;
|
7449 | ts.transforming = false;
|
7450 | var cb = ts.writecb;
|
7451 |
|
7452 | if (cb === null) {
|
7453 | return this.emit('error', new ERR_MULTIPLE_CALLBACK());
|
7454 | }
|
7455 |
|
7456 | ts.writechunk = null;
|
7457 | ts.writecb = null;
|
7458 | if (data != null)
|
7459 | this.push(data);
|
7460 | cb(er);
|
7461 | var rs = this._readableState;
|
7462 | rs.reading = false;
|
7463 |
|
7464 | if (rs.needReadable || rs.length < rs.highWaterMark) {
|
7465 | this._read(rs.highWaterMark);
|
7466 | }
|
7467 | }
|
7468 |
|
7469 | function Transform(options) {
|
7470 | if (!(this instanceof Transform)) return new Transform(options);
|
7471 | Duplex.call(this, options);
|
7472 | this._transformState = {
|
7473 | afterTransform: afterTransform.bind(this),
|
7474 | needTransform: false,
|
7475 | transforming: false,
|
7476 | writecb: null,
|
7477 | writechunk: null,
|
7478 | writeencoding: null
|
7479 | };
|
7480 |
|
7481 | this._readableState.needReadable = true;
|
7482 |
|
7483 |
|
7484 |
|
7485 | this._readableState.sync = false;
|
7486 |
|
7487 | if (options) {
|
7488 | if (typeof options.transform === 'function') this._transform = options.transform;
|
7489 | if (typeof options.flush === 'function') this._flush = options.flush;
|
7490 | }
|
7491 |
|
7492 |
|
7493 | this.on('prefinish', prefinish);
|
7494 | }
|
7495 |
|
7496 | function prefinish() {
|
7497 | var _this = this;
|
7498 |
|
7499 | if (typeof this._flush === 'function' && !this._readableState.destroyed) {
|
7500 | this._flush(function (er, data) {
|
7501 | done(_this, er, data);
|
7502 | });
|
7503 | } else {
|
7504 | done(this, null, null);
|
7505 | }
|
7506 | }
|
7507 |
|
7508 | Transform.prototype.push = function (chunk, encoding) {
|
7509 | this._transformState.needTransform = false;
|
7510 | return Duplex.prototype.push.call(this, chunk, encoding);
|
7511 | };
|
7512 |
|
7513 |
|
7514 |
|
7515 |
|
7516 |
|
7517 |
|
7518 |
|
7519 |
|
7520 |
|
7521 |
|
7522 |
|
7523 | Transform.prototype._transform = function (chunk, encoding, cb) {
|
7524 | cb(new ERR_METHOD_NOT_IMPLEMENTED('_transform()'));
|
7525 | };
|
7526 |
|
7527 | Transform.prototype._write = function (chunk, encoding, cb) {
|
7528 | var ts = this._transformState;
|
7529 | ts.writecb = cb;
|
7530 | ts.writechunk = chunk;
|
7531 | ts.writeencoding = encoding;
|
7532 |
|
7533 | if (!ts.transforming) {
|
7534 | var rs = this._readableState;
|
7535 | if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) this._read(rs.highWaterMark);
|
7536 | }
|
7537 | };
|
7538 |
|
7539 |
|
7540 |
|
7541 |
|
7542 | Transform.prototype._read = function (n) {
|
7543 | var ts = this._transformState;
|
7544 |
|
7545 | if (ts.writechunk !== null && !ts.transforming) {
|
7546 | ts.transforming = true;
|
7547 |
|
7548 | this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
|
7549 | } else {
|
7550 |
|
7551 |
|
7552 | ts.needTransform = true;
|
7553 | }
|
7554 | };
|
7555 |
|
7556 | Transform.prototype._destroy = function (err, cb) {
|
7557 | Duplex.prototype._destroy.call(this, err, function (err2) {
|
7558 | cb(err2);
|
7559 | });
|
7560 | };
|
7561 |
|
7562 | function done(stream, er, data) {
|
7563 | if (er) return stream.emit('error', er);
|
7564 | if (data != null)
|
7565 | stream.push(data);
|
7566 |
|
7567 |
|
7568 |
|
7569 | if (stream._writableState.length) throw new ERR_TRANSFORM_WITH_LENGTH_0();
|
7570 | if (stream._transformState.transforming) throw new ERR_TRANSFORM_ALREADY_TRANSFORMING();
|
7571 | return stream.push(null);
|
7572 | }
|
7573 | },{"18":18,"25":25,"26":26}],30:[function(_dereq_,module,exports){
|
7574 | (function (process,global){
|
7575 |
|
7576 |
|
7577 |
|
7578 |
|
7579 |
|
7580 |
|
7581 |
|
7582 |
|
7583 |
|
7584 |
|
7585 |
|
7586 |
|
7587 |
|
7588 |
|
7589 |
|
7590 |
|
7591 |
|
7592 |
|
7593 |
|
7594 |
|
7595 |
|
7596 |
|
7597 |
|
7598 | 'use strict';
|
7599 |
|
7600 | module.exports = Writable;
|
7601 |
|
7602 |
|
7603 | function WriteReq(chunk, encoding, cb) {
|
7604 | this.chunk = chunk;
|
7605 | this.encoding = encoding;
|
7606 | this.callback = cb;
|
7607 | this.next = null;
|
7608 | }
|
7609 |
|
7610 |
|
7611 |
|
7612 | function CorkedRequest(state) {
|
7613 | var _this = this;
|
7614 |
|
7615 | this.next = null;
|
7616 | this.entry = null;
|
7617 |
|
7618 | this.finish = function () {
|
7619 | onCorkedFinish(_this, state);
|
7620 | };
|
7621 | }
|
7622 |
|
7623 |
|
7624 |
|
7625 |
|
7626 |
|
7627 | var Duplex;
|
7628 |
|
7629 |
|
7630 | Writable.WritableState = WritableState;
|
7631 |
|
7632 |
|
7633 | var internalUtil = {
|
7634 | deprecate: _dereq_(116)
|
7635 | };
|
7636 |
|
7637 |
|
7638 |
|
7639 |
|
7640 | var Stream = _dereq_(38);
|
7641 |
|
7642 |
|
7643 |
|
7644 | var Buffer = _dereq_(9).Buffer;
|
7645 |
|
7646 | var OurUint8Array = global.Uint8Array || function () {};
|
7647 |
|
7648 | function _uint8ArrayToBuffer(chunk) {
|
7649 | return Buffer.from(chunk);
|
7650 | }
|
7651 |
|
7652 | function _isUint8Array(obj) {
|
7653 | return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
|
7654 | }
|
7655 |
|
7656 | var destroyImpl = _dereq_(33);
|
7657 |
|
7658 | var _require = _dereq_(37),
|
7659 | getHighWaterMark = _require.getHighWaterMark;
|
7660 |
|
7661 | var _require$codes = _dereq_(25).codes,
|
7662 | ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE,
|
7663 | ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED,
|
7664 | ERR_MULTIPLE_CALLBACK = _require$codes.ERR_MULTIPLE_CALLBACK,
|
7665 | ERR_STREAM_CANNOT_PIPE = _require$codes.ERR_STREAM_CANNOT_PIPE,
|
7666 | ERR_STREAM_DESTROYED = _require$codes.ERR_STREAM_DESTROYED,
|
7667 | ERR_STREAM_NULL_VALUES = _require$codes.ERR_STREAM_NULL_VALUES,
|
7668 | ERR_STREAM_WRITE_AFTER_END = _require$codes.ERR_STREAM_WRITE_AFTER_END,
|
7669 | ERR_UNKNOWN_ENCODING = _require$codes.ERR_UNKNOWN_ENCODING;
|
7670 |
|
7671 | var errorOrDestroy = destroyImpl.errorOrDestroy;
|
7672 |
|
7673 | _dereq_(18)(Writable, Stream);
|
7674 |
|
7675 | function nop() {}
|
7676 |
|
7677 | function WritableState(options, stream, isDuplex) {
|
7678 | Duplex = Duplex || _dereq_(26);
|
7679 | options = options || {};
|
7680 |
|
7681 |
|
7682 |
|
7683 |
|
7684 |
|
7685 | if (typeof isDuplex !== 'boolean') isDuplex = stream instanceof Duplex;
|
7686 |
|
7687 |
|
7688 | this.objectMode = !!options.objectMode;
|
7689 | if (isDuplex) this.objectMode = this.objectMode || !!options.writableObjectMode;
|
7690 |
|
7691 |
|
7692 |
|
7693 | this.highWaterMark = getHighWaterMark(this, options, 'writableHighWaterMark', isDuplex);
|
7694 |
|
7695 | this.finalCalled = false;
|
7696 |
|
7697 | this.needDrain = false;
|
7698 |
|
7699 | this.ending = false;
|
7700 |
|
7701 | this.ended = false;
|
7702 |
|
7703 | this.finished = false;
|
7704 |
|
7705 | this.destroyed = false;
|
7706 |
|
7707 |
|
7708 |
|
7709 | var noDecode = options.decodeStrings === false;
|
7710 | this.decodeStrings = !noDecode;
|
7711 |
|
7712 |
|
7713 |
|
7714 | this.defaultEncoding = options.defaultEncoding || 'utf8';
|
7715 |
|
7716 |
|
7717 |
|
7718 | this.length = 0;
|
7719 |
|
7720 | this.writing = false;
|
7721 |
|
7722 | this.corked = 0;
|
7723 |
|
7724 |
|
7725 |
|
7726 |
|
7727 | this.sync = true;
|
7728 |
|
7729 |
|
7730 |
|
7731 | this.bufferProcessing = false;
|
7732 |
|
7733 | this.onwrite = function (er) {
|
7734 | onwrite(stream, er);
|
7735 | };
|
7736 |
|
7737 |
|
7738 | this.writecb = null;
|
7739 |
|
7740 | this.writelen = 0;
|
7741 | this.bufferedRequest = null;
|
7742 | this.lastBufferedRequest = null;
|
7743 |
|
7744 |
|
7745 | this.pendingcb = 0;
|
7746 |
|
7747 |
|
7748 | this.prefinished = false;
|
7749 |
|
7750 | this.errorEmitted = false;
|
7751 |
|
7752 | this.emitClose = options.emitClose !== false;
|
7753 |
|
7754 | this.autoDestroy = !!options.autoDestroy;
|
7755 |
|
7756 | this.bufferedRequestCount = 0;
|
7757 |
|
7758 |
|
7759 | this.corkedRequestsFree = new CorkedRequest(this);
|
7760 | }
|
7761 |
|
7762 | WritableState.prototype.getBuffer = function getBuffer() {
|
7763 | var current = this.bufferedRequest;
|
7764 | var out = [];
|
7765 |
|
7766 | while (current) {
|
7767 | out.push(current);
|
7768 | current = current.next;
|
7769 | }
|
7770 |
|
7771 | return out;
|
7772 | };
|
7773 |
|
7774 | (function () {
|
7775 | try {
|
7776 | Object.defineProperty(WritableState.prototype, 'buffer', {
|
7777 | get: internalUtil.deprecate(function writableStateBufferGetter() {
|
7778 | return this.getBuffer();
|
7779 | }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.', 'DEP0003')
|
7780 | });
|
7781 | } catch (_) {}
|
7782 | })();
|
7783 |
|
7784 |
|
7785 |
|
7786 | var realHasInstance;
|
7787 |
|
7788 | if (typeof Symbol === 'function' && Symbol.hasInstance && typeof Function.prototype[Symbol.hasInstance] === 'function') {
|
7789 | realHasInstance = Function.prototype[Symbol.hasInstance];
|
7790 | Object.defineProperty(Writable, Symbol.hasInstance, {
|
7791 | value: function value(object) {
|
7792 | if (realHasInstance.call(this, object)) return true;
|
7793 | if (this !== Writable) return false;
|
7794 | return object && object._writableState instanceof WritableState;
|
7795 | }
|
7796 | });
|
7797 | } else {
|
7798 | realHasInstance = function realHasInstance(object) {
|
7799 | return object instanceof this;
|
7800 | };
|
7801 | }
|
7802 |
|
7803 | function Writable(options) {
|
7804 | Duplex = Duplex || _dereq_(26);
|
7805 |
|
7806 |
|
7807 |
|
7808 |
|
7809 |
|
7810 |
|
7811 |
|
7812 |
|
7813 | var isDuplex = this instanceof Duplex;
|
7814 | if (!isDuplex && !realHasInstance.call(Writable, this)) return new Writable(options);
|
7815 | this._writableState = new WritableState(options, this, isDuplex);
|
7816 |
|
7817 | this.writable = true;
|
7818 |
|
7819 | if (options) {
|
7820 | if (typeof options.write === 'function') this._write = options.write;
|
7821 | if (typeof options.writev === 'function') this._writev = options.writev;
|
7822 | if (typeof options.destroy === 'function') this._destroy = options.destroy;
|
7823 | if (typeof options.final === 'function') this._final = options.final;
|
7824 | }
|
7825 |
|
7826 | Stream.call(this);
|
7827 | }
|
7828 |
|
7829 |
|
7830 | Writable.prototype.pipe = function () {
|
7831 | errorOrDestroy(this, new ERR_STREAM_CANNOT_PIPE());
|
7832 | };
|
7833 |
|
7834 | function writeAfterEnd(stream, cb) {
|
7835 | var er = new ERR_STREAM_WRITE_AFTER_END();
|
7836 |
|
7837 | errorOrDestroy(stream, er);
|
7838 | process.nextTick(cb, er);
|
7839 | }
|
7840 |
|
7841 |
|
7842 |
|
7843 |
|
7844 | function validChunk(stream, state, chunk, cb) {
|
7845 | var er;
|
7846 |
|
7847 | if (chunk === null) {
|
7848 | er = new ERR_STREAM_NULL_VALUES();
|
7849 | } else if (typeof chunk !== 'string' && !state.objectMode) {
|
7850 | er = new ERR_INVALID_ARG_TYPE('chunk', ['string', 'Buffer'], chunk);
|
7851 | }
|
7852 |
|
7853 | if (er) {
|
7854 | errorOrDestroy(stream, er);
|
7855 | process.nextTick(cb, er);
|
7856 | return false;
|
7857 | }
|
7858 |
|
7859 | return true;
|
7860 | }
|
7861 |
|
7862 | Writable.prototype.write = function (chunk, encoding, cb) {
|
7863 | var state = this._writableState;
|
7864 | var ret = false;
|
7865 |
|
7866 | var isBuf = !state.objectMode && _isUint8Array(chunk);
|
7867 |
|
7868 | if (isBuf && !Buffer.isBuffer(chunk)) {
|
7869 | chunk = _uint8ArrayToBuffer(chunk);
|
7870 | }
|
7871 |
|
7872 | if (typeof encoding === 'function') {
|
7873 | cb = encoding;
|
7874 | encoding = null;
|
7875 | }
|
7876 |
|
7877 | if (isBuf) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding;
|
7878 | if (typeof cb !== 'function') cb = nop;
|
7879 | if (state.ending) writeAfterEnd(this, cb);else if (isBuf || validChunk(this, state, chunk, cb)) {
|
7880 | state.pendingcb++;
|
7881 | ret = writeOrBuffer(this, state, isBuf, chunk, encoding, cb);
|
7882 | }
|
7883 | return ret;
|
7884 | };
|
7885 |
|
7886 | Writable.prototype.cork = function () {
|
7887 | this._writableState.corked++;
|
7888 | };
|
7889 |
|
7890 | Writable.prototype.uncork = function () {
|
7891 | var state = this._writableState;
|
7892 |
|
7893 | if (state.corked) {
|
7894 | state.corked--;
|
7895 | if (!state.writing && !state.corked && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state);
|
7896 | }
|
7897 | };
|
7898 |
|
7899 | Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
|
7900 |
|
7901 | if (typeof encoding === 'string') encoding = encoding.toLowerCase();
|
7902 | if (!(['hex', 'utf8', 'utf-8', 'ascii', 'binary', 'base64', 'ucs2', 'ucs-2', 'utf16le', 'utf-16le', 'raw'].indexOf((encoding + '').toLowerCase()) > -1)) throw new ERR_UNKNOWN_ENCODING(encoding);
|
7903 | this._writableState.defaultEncoding = encoding;
|
7904 | return this;
|
7905 | };
|
7906 |
|
7907 | Object.defineProperty(Writable.prototype, 'writableBuffer', {
|
7908 |
|
7909 |
|
7910 |
|
7911 | enumerable: false,
|
7912 | get: function get() {
|
7913 | return this._writableState && this._writableState.getBuffer();
|
7914 | }
|
7915 | });
|
7916 |
|
7917 | function decodeChunk(state, chunk, encoding) {
|
7918 | if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') {
|
7919 | chunk = Buffer.from(chunk, encoding);
|
7920 | }
|
7921 |
|
7922 | return chunk;
|
7923 | }
|
7924 |
|
7925 | Object.defineProperty(Writable.prototype, 'writableHighWaterMark', {
|
7926 |
|
7927 |
|
7928 |
|
7929 | enumerable: false,
|
7930 | get: function get() {
|
7931 | return this._writableState.highWaterMark;
|
7932 | }
|
7933 | });
|
7934 |
|
7935 |
|
7936 |
|
7937 | function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) {
|
7938 | if (!isBuf) {
|
7939 | var newChunk = decodeChunk(state, chunk, encoding);
|
7940 |
|
7941 | if (chunk !== newChunk) {
|
7942 | isBuf = true;
|
7943 | encoding = 'buffer';
|
7944 | chunk = newChunk;
|
7945 | }
|
7946 | }
|
7947 |
|
7948 | var len = state.objectMode ? 1 : chunk.length;
|
7949 | state.length += len;
|
7950 | var ret = state.length < state.highWaterMark;
|
7951 |
|
7952 | if (!ret) state.needDrain = true;
|
7953 |
|
7954 | if (state.writing || state.corked) {
|
7955 | var last = state.lastBufferedRequest;
|
7956 | state.lastBufferedRequest = {
|
7957 | chunk: chunk,
|
7958 | encoding: encoding,
|
7959 | isBuf: isBuf,
|
7960 | callback: cb,
|
7961 | next: null
|
7962 | };
|
7963 |
|
7964 | if (last) {
|
7965 | last.next = state.lastBufferedRequest;
|
7966 | } else {
|
7967 | state.bufferedRequest = state.lastBufferedRequest;
|
7968 | }
|
7969 |
|
7970 | state.bufferedRequestCount += 1;
|
7971 | } else {
|
7972 | doWrite(stream, state, false, len, chunk, encoding, cb);
|
7973 | }
|
7974 |
|
7975 | return ret;
|
7976 | }
|
7977 |
|
7978 | function doWrite(stream, state, writev, len, chunk, encoding, cb) {
|
7979 | state.writelen = len;
|
7980 | state.writecb = cb;
|
7981 | state.writing = true;
|
7982 | state.sync = true;
|
7983 | if (state.destroyed) state.onwrite(new ERR_STREAM_DESTROYED('write'));else if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite);
|
7984 | state.sync = false;
|
7985 | }
|
7986 |
|
7987 | function onwriteError(stream, state, sync, er, cb) {
|
7988 | --state.pendingcb;
|
7989 |
|
7990 | if (sync) {
|
7991 |
|
7992 |
|
7993 | process.nextTick(cb, er);
|
7994 |
|
7995 |
|
7996 | process.nextTick(finishMaybe, stream, state);
|
7997 | stream._writableState.errorEmitted = true;
|
7998 | errorOrDestroy(stream, er);
|
7999 | } else {
|
8000 |
|
8001 |
|
8002 | cb(er);
|
8003 | stream._writableState.errorEmitted = true;
|
8004 | errorOrDestroy(stream, er);
|
8005 |
|
8006 |
|
8007 | finishMaybe(stream, state);
|
8008 | }
|
8009 | }
|
8010 |
|
8011 | function onwriteStateUpdate(state) {
|
8012 | state.writing = false;
|
8013 | state.writecb = null;
|
8014 | state.length -= state.writelen;
|
8015 | state.writelen = 0;
|
8016 | }
|
8017 |
|
8018 | function onwrite(stream, er) {
|
8019 | var state = stream._writableState;
|
8020 | var sync = state.sync;
|
8021 | var cb = state.writecb;
|
8022 | if (typeof cb !== 'function') throw new ERR_MULTIPLE_CALLBACK();
|
8023 | onwriteStateUpdate(state);
|
8024 | if (er) onwriteError(stream, state, sync, er, cb);else {
|
8025 |
|
8026 | var finished = needFinish(state) || stream.destroyed;
|
8027 |
|
8028 | if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) {
|
8029 | clearBuffer(stream, state);
|
8030 | }
|
8031 |
|
8032 | if (sync) {
|
8033 | process.nextTick(afterWrite, stream, state, finished, cb);
|
8034 | } else {
|
8035 | afterWrite(stream, state, finished, cb);
|
8036 | }
|
8037 | }
|
8038 | }
|
8039 |
|
8040 | function afterWrite(stream, state, finished, cb) {
|
8041 | if (!finished) onwriteDrain(stream, state);
|
8042 | state.pendingcb--;
|
8043 | cb();
|
8044 | finishMaybe(stream, state);
|
8045 | }
|
8046 |
|
8047 |
|
8048 |
|
8049 |
|
8050 | function onwriteDrain(stream, state) {
|
8051 | if (state.length === 0 && state.needDrain) {
|
8052 | state.needDrain = false;
|
8053 | stream.emit('drain');
|
8054 | }
|
8055 | }
|
8056 |
|
8057 |
|
8058 | function clearBuffer(stream, state) {
|
8059 | state.bufferProcessing = true;
|
8060 | var entry = state.bufferedRequest;
|
8061 |
|
8062 | if (stream._writev && entry && entry.next) {
|
8063 |
|
8064 | var l = state.bufferedRequestCount;
|
8065 | var buffer = new Array(l);
|
8066 | var holder = state.corkedRequestsFree;
|
8067 | holder.entry = entry;
|
8068 | var count = 0;
|
8069 | var allBuffers = true;
|
8070 |
|
8071 | while (entry) {
|
8072 | buffer[count] = entry;
|
8073 | if (!entry.isBuf) allBuffers = false;
|
8074 | entry = entry.next;
|
8075 | count += 1;
|
8076 | }
|
8077 |
|
8078 | buffer.allBuffers = allBuffers;
|
8079 | doWrite(stream, state, true, state.length, buffer, '', holder.finish);
|
8080 |
|
8081 |
|
8082 | state.pendingcb++;
|
8083 | state.lastBufferedRequest = null;
|
8084 |
|
8085 | if (holder.next) {
|
8086 | state.corkedRequestsFree = holder.next;
|
8087 | holder.next = null;
|
8088 | } else {
|
8089 | state.corkedRequestsFree = new CorkedRequest(state);
|
8090 | }
|
8091 |
|
8092 | state.bufferedRequestCount = 0;
|
8093 | } else {
|
8094 |
|
8095 | while (entry) {
|
8096 | var chunk = entry.chunk;
|
8097 | var encoding = entry.encoding;
|
8098 | var cb = entry.callback;
|
8099 | var len = state.objectMode ? 1 : chunk.length;
|
8100 | doWrite(stream, state, false, len, chunk, encoding, cb);
|
8101 | entry = entry.next;
|
8102 | state.bufferedRequestCount--;
|
8103 |
|
8104 |
|
8105 |
|
8106 |
|
8107 | if (state.writing) {
|
8108 | break;
|
8109 | }
|
8110 | }
|
8111 |
|
8112 | if (entry === null) state.lastBufferedRequest = null;
|
8113 | }
|
8114 |
|
8115 | state.bufferedRequest = entry;
|
8116 | state.bufferProcessing = false;
|
8117 | }
|
8118 |
|
8119 | Writable.prototype._write = function (chunk, encoding, cb) {
|
8120 | cb(new ERR_METHOD_NOT_IMPLEMENTED('_write()'));
|
8121 | };
|
8122 |
|
8123 | Writable.prototype._writev = null;
|
8124 |
|
8125 | Writable.prototype.end = function (chunk, encoding, cb) {
|
8126 | var state = this._writableState;
|
8127 |
|
8128 | if (typeof chunk === 'function') {
|
8129 | cb = chunk;
|
8130 | chunk = null;
|
8131 | encoding = null;
|
8132 | } else if (typeof encoding === 'function') {
|
8133 | cb = encoding;
|
8134 | encoding = null;
|
8135 | }
|
8136 |
|
8137 | if (chunk !== null && chunk !== undefined) this.write(chunk, encoding);
|
8138 |
|
8139 | if (state.corked) {
|
8140 | state.corked = 1;
|
8141 | this.uncork();
|
8142 | }
|
8143 |
|
8144 |
|
8145 | if (!state.ending) endWritable(this, state, cb);
|
8146 | return this;
|
8147 | };
|
8148 |
|
8149 | Object.defineProperty(Writable.prototype, 'writableLength', {
|
8150 |
|
8151 |
|
8152 |
|
8153 | enumerable: false,
|
8154 | get: function get() {
|
8155 | return this._writableState.length;
|
8156 | }
|
8157 | });
|
8158 |
|
8159 | function needFinish(state) {
|
8160 | return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing;
|
8161 | }
|
8162 |
|
8163 | function callFinal(stream, state) {
|
8164 | stream._final(function (err) {
|
8165 | state.pendingcb--;
|
8166 |
|
8167 | if (err) {
|
8168 | errorOrDestroy(stream, err);
|
8169 | }
|
8170 |
|
8171 | state.prefinished = true;
|
8172 | stream.emit('prefinish');
|
8173 | finishMaybe(stream, state);
|
8174 | });
|
8175 | }
|
8176 |
|
8177 | function prefinish(stream, state) {
|
8178 | if (!state.prefinished && !state.finalCalled) {
|
8179 | if (typeof stream._final === 'function' && !state.destroyed) {
|
8180 | state.pendingcb++;
|
8181 | state.finalCalled = true;
|
8182 | process.nextTick(callFinal, stream, state);
|
8183 | } else {
|
8184 | state.prefinished = true;
|
8185 | stream.emit('prefinish');
|
8186 | }
|
8187 | }
|
8188 | }
|
8189 |
|
8190 | function finishMaybe(stream, state) {
|
8191 | var need = needFinish(state);
|
8192 |
|
8193 | if (need) {
|
8194 | prefinish(stream, state);
|
8195 |
|
8196 | if (state.pendingcb === 0) {
|
8197 | state.finished = true;
|
8198 | stream.emit('finish');
|
8199 |
|
8200 | if (state.autoDestroy) {
|
8201 |
|
8202 |
|
8203 | var rState = stream._readableState;
|
8204 |
|
8205 | if (!rState || rState.autoDestroy && rState.endEmitted) {
|
8206 | stream.destroy();
|
8207 | }
|
8208 | }
|
8209 | }
|
8210 | }
|
8211 |
|
8212 | return need;
|
8213 | }
|
8214 |
|
8215 | function endWritable(stream, state, cb) {
|
8216 | state.ending = true;
|
8217 | finishMaybe(stream, state);
|
8218 |
|
8219 | if (cb) {
|
8220 | if (state.finished) process.nextTick(cb);else stream.once('finish', cb);
|
8221 | }
|
8222 |
|
8223 | state.ended = true;
|
8224 | stream.writable = false;
|
8225 | }
|
8226 |
|
8227 | function onCorkedFinish(corkReq, state, err) {
|
8228 | var entry = corkReq.entry;
|
8229 | corkReq.entry = null;
|
8230 |
|
8231 | while (entry) {
|
8232 | var cb = entry.callback;
|
8233 | state.pendingcb--;
|
8234 | cb(err);
|
8235 | entry = entry.next;
|
8236 | }
|
8237 |
|
8238 |
|
8239 | state.corkedRequestsFree.next = corkReq;
|
8240 | }
|
8241 |
|
8242 | Object.defineProperty(Writable.prototype, 'destroyed', {
|
8243 |
|
8244 |
|
8245 |
|
8246 | enumerable: false,
|
8247 | get: function get() {
|
8248 | if (this._writableState === undefined) {
|
8249 | return false;
|
8250 | }
|
8251 |
|
8252 | return this._writableState.destroyed;
|
8253 | },
|
8254 | set: function set(value) {
|
8255 |
|
8256 |
|
8257 | if (!this._writableState) {
|
8258 | return;
|
8259 | }
|
8260 |
|
8261 |
|
8262 |
|
8263 | this._writableState.destroyed = value;
|
8264 | }
|
8265 | });
|
8266 | Writable.prototype.destroy = destroyImpl.destroy;
|
8267 | Writable.prototype._undestroy = destroyImpl.undestroy;
|
8268 |
|
8269 | Writable.prototype._destroy = function (err, cb) {
|
8270 | cb(err);
|
8271 | };
|
8272 | }).call(this,_dereq_(70),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
8273 | },{"116":116,"18":18,"25":25,"26":26,"33":33,"37":37,"38":38,"70":70,"9":9}],31:[function(_dereq_,module,exports){
|
8274 | (function (process){
|
8275 | 'use strict';
|
8276 |
|
8277 | var _Object$setPrototypeO;
|
8278 |
|
8279 | function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
8280 |
|
8281 | var finished = _dereq_(34);
|
8282 |
|
8283 | var kLastResolve = Symbol('lastResolve');
|
8284 | var kLastReject = Symbol('lastReject');
|
8285 | var kError = Symbol('error');
|
8286 | var kEnded = Symbol('ended');
|
8287 | var kLastPromise = Symbol('lastPromise');
|
8288 | var kHandlePromise = Symbol('handlePromise');
|
8289 | var kStream = Symbol('stream');
|
8290 |
|
8291 | function createIterResult(value, done) {
|
8292 | return {
|
8293 | value: value,
|
8294 | done: done
|
8295 | };
|
8296 | }
|
8297 |
|
8298 | function readAndResolve(iter) {
|
8299 | var resolve = iter[kLastResolve];
|
8300 |
|
8301 | if (resolve !== null) {
|
8302 | var data = iter[kStream].read();
|
8303 |
|
8304 |
|
8305 |
|
8306 | if (data !== null) {
|
8307 | iter[kLastPromise] = null;
|
8308 | iter[kLastResolve] = null;
|
8309 | iter[kLastReject] = null;
|
8310 | resolve(createIterResult(data, false));
|
8311 | }
|
8312 | }
|
8313 | }
|
8314 |
|
8315 | function onReadable(iter) {
|
8316 |
|
8317 |
|
8318 | process.nextTick(readAndResolve, iter);
|
8319 | }
|
8320 |
|
8321 | function wrapForNext(lastPromise, iter) {
|
8322 | return function (resolve, reject) {
|
8323 | lastPromise.then(function () {
|
8324 | if (iter[kEnded]) {
|
8325 | resolve(createIterResult(undefined, true));
|
8326 | return;
|
8327 | }
|
8328 |
|
8329 | iter[kHandlePromise](resolve, reject);
|
8330 | }, reject);
|
8331 | };
|
8332 | }
|
8333 |
|
8334 | var AsyncIteratorPrototype = Object.getPrototypeOf(function () {});
|
8335 | var ReadableStreamAsyncIteratorPrototype = Object.setPrototypeOf((_Object$setPrototypeO = {
|
8336 | get stream() {
|
8337 | return this[kStream];
|
8338 | },
|
8339 |
|
8340 | next: function next() {
|
8341 | var _this = this;
|
8342 |
|
8343 |
|
8344 |
|
8345 | var error = this[kError];
|
8346 |
|
8347 | if (error !== null) {
|
8348 | return Promise.reject(error);
|
8349 | }
|
8350 |
|
8351 | if (this[kEnded]) {
|
8352 | return Promise.resolve(createIterResult(undefined, true));
|
8353 | }
|
8354 |
|
8355 | if (this[kStream].destroyed) {
|
8356 |
|
8357 |
|
8358 |
|
8359 |
|
8360 | return new Promise(function (resolve, reject) {
|
8361 | process.nextTick(function () {
|
8362 | if (_this[kError]) {
|
8363 | reject(_this[kError]);
|
8364 | } else {
|
8365 | resolve(createIterResult(undefined, true));
|
8366 | }
|
8367 | });
|
8368 | });
|
8369 | }
|
8370 |
|
8371 |
|
8372 |
|
8373 |
|
8374 |
|
8375 | var lastPromise = this[kLastPromise];
|
8376 | var promise;
|
8377 |
|
8378 | if (lastPromise) {
|
8379 | promise = new Promise(wrapForNext(lastPromise, this));
|
8380 | } else {
|
8381 |
|
8382 |
|
8383 | var data = this[kStream].read();
|
8384 |
|
8385 | if (data !== null) {
|
8386 | return Promise.resolve(createIterResult(data, false));
|
8387 | }
|
8388 |
|
8389 | promise = new Promise(this[kHandlePromise]);
|
8390 | }
|
8391 |
|
8392 | this[kLastPromise] = promise;
|
8393 | return promise;
|
8394 | }
|
8395 | }, _defineProperty(_Object$setPrototypeO, Symbol.asyncIterator, function () {
|
8396 | return this;
|
8397 | }), _defineProperty(_Object$setPrototypeO, "return", function _return() {
|
8398 | var _this2 = this;
|
8399 |
|
8400 |
|
8401 |
|
8402 |
|
8403 | return new Promise(function (resolve, reject) {
|
8404 | _this2[kStream].destroy(null, function (err) {
|
8405 | if (err) {
|
8406 | reject(err);
|
8407 | return;
|
8408 | }
|
8409 |
|
8410 | resolve(createIterResult(undefined, true));
|
8411 | });
|
8412 | });
|
8413 | }), _Object$setPrototypeO), AsyncIteratorPrototype);
|
8414 |
|
8415 | var createReadableStreamAsyncIterator = function createReadableStreamAsyncIterator(stream) {
|
8416 | var _Object$create;
|
8417 |
|
8418 | var iterator = Object.create(ReadableStreamAsyncIteratorPrototype, (_Object$create = {}, _defineProperty(_Object$create, kStream, {
|
8419 | value: stream,
|
8420 | writable: true
|
8421 | }), _defineProperty(_Object$create, kLastResolve, {
|
8422 | value: null,
|
8423 | writable: true
|
8424 | }), _defineProperty(_Object$create, kLastReject, {
|
8425 | value: null,
|
8426 | writable: true
|
8427 | }), _defineProperty(_Object$create, kError, {
|
8428 | value: null,
|
8429 | writable: true
|
8430 | }), _defineProperty(_Object$create, kEnded, {
|
8431 | value: stream._readableState.endEmitted,
|
8432 | writable: true
|
8433 | }), _defineProperty(_Object$create, kHandlePromise, {
|
8434 | value: function value(resolve, reject) {
|
8435 | var data = iterator[kStream].read();
|
8436 |
|
8437 | if (data) {
|
8438 | iterator[kLastPromise] = null;
|
8439 | iterator[kLastResolve] = null;
|
8440 | iterator[kLastReject] = null;
|
8441 | resolve(createIterResult(data, false));
|
8442 | } else {
|
8443 | iterator[kLastResolve] = resolve;
|
8444 | iterator[kLastReject] = reject;
|
8445 | }
|
8446 | },
|
8447 | writable: true
|
8448 | }), _Object$create));
|
8449 | iterator[kLastPromise] = null;
|
8450 | finished(stream, function (err) {
|
8451 | if (err && err.code !== 'ERR_STREAM_PREMATURE_CLOSE') {
|
8452 | var reject = iterator[kLastReject];
|
8453 |
|
8454 |
|
8455 | if (reject !== null) {
|
8456 | iterator[kLastPromise] = null;
|
8457 | iterator[kLastResolve] = null;
|
8458 | iterator[kLastReject] = null;
|
8459 | reject(err);
|
8460 | }
|
8461 |
|
8462 | iterator[kError] = err;
|
8463 | return;
|
8464 | }
|
8465 |
|
8466 | var resolve = iterator[kLastResolve];
|
8467 |
|
8468 | if (resolve !== null) {
|
8469 | iterator[kLastPromise] = null;
|
8470 | iterator[kLastResolve] = null;
|
8471 | iterator[kLastReject] = null;
|
8472 | resolve(createIterResult(undefined, true));
|
8473 | }
|
8474 |
|
8475 | iterator[kEnded] = true;
|
8476 | });
|
8477 | stream.on('readable', onReadable.bind(null, iterator));
|
8478 | return iterator;
|
8479 | };
|
8480 |
|
8481 | module.exports = createReadableStreamAsyncIterator;
|
8482 | }).call(this,_dereq_(70))
|
8483 | },{"34":34,"70":70}],32:[function(_dereq_,module,exports){
|
8484 | 'use strict';
|
8485 |
|
8486 | function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
8487 |
|
8488 | function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
8489 |
|
8490 | function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
8491 |
|
8492 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
8493 |
|
8494 | function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
8495 |
|
8496 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
8497 |
|
8498 | var _require = _dereq_(9),
|
8499 | Buffer = _require.Buffer;
|
8500 |
|
8501 | var _require2 = _dereq_(7),
|
8502 | inspect = _require2.inspect;
|
8503 |
|
8504 | var custom = inspect && inspect.custom || 'inspect';
|
8505 |
|
8506 | function copyBuffer(src, target, offset) {
|
8507 | Buffer.prototype.copy.call(src, target, offset);
|
8508 | }
|
8509 |
|
8510 | module.exports =
|
8511 |
|
8512 | function () {
|
8513 | function BufferList() {
|
8514 | _classCallCheck(this, BufferList);
|
8515 |
|
8516 | this.head = null;
|
8517 | this.tail = null;
|
8518 | this.length = 0;
|
8519 | }
|
8520 |
|
8521 | _createClass(BufferList, [{
|
8522 | key: "push",
|
8523 | value: function push(v) {
|
8524 | var entry = {
|
8525 | data: v,
|
8526 | next: null
|
8527 | };
|
8528 | if (this.length > 0) this.tail.next = entry;else this.head = entry;
|
8529 | this.tail = entry;
|
8530 | ++this.length;
|
8531 | }
|
8532 | }, {
|
8533 | key: "unshift",
|
8534 | value: function unshift(v) {
|
8535 | var entry = {
|
8536 | data: v,
|
8537 | next: this.head
|
8538 | };
|
8539 | if (this.length === 0) this.tail = entry;
|
8540 | this.head = entry;
|
8541 | ++this.length;
|
8542 | }
|
8543 | }, {
|
8544 | key: "shift",
|
8545 | value: function shift() {
|
8546 | if (this.length === 0) return;
|
8547 | var ret = this.head.data;
|
8548 | if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next;
|
8549 | --this.length;
|
8550 | return ret;
|
8551 | }
|
8552 | }, {
|
8553 | key: "clear",
|
8554 | value: function clear() {
|
8555 | this.head = this.tail = null;
|
8556 | this.length = 0;
|
8557 | }
|
8558 | }, {
|
8559 | key: "join",
|
8560 | value: function join(s) {
|
8561 | if (this.length === 0) return '';
|
8562 | var p = this.head;
|
8563 | var ret = '' + p.data;
|
8564 |
|
8565 | while (p = p.next) {
|
8566 | ret += s + p.data;
|
8567 | }
|
8568 |
|
8569 | return ret;
|
8570 | }
|
8571 | }, {
|
8572 | key: "concat",
|
8573 | value: function concat(n) {
|
8574 | if (this.length === 0) return Buffer.alloc(0);
|
8575 | var ret = Buffer.allocUnsafe(n >>> 0);
|
8576 | var p = this.head;
|
8577 | var i = 0;
|
8578 |
|
8579 | while (p) {
|
8580 | copyBuffer(p.data, ret, i);
|
8581 | i += p.data.length;
|
8582 | p = p.next;
|
8583 | }
|
8584 |
|
8585 | return ret;
|
8586 | }
|
8587 |
|
8588 | }, {
|
8589 | key: "consume",
|
8590 | value: function consume(n, hasStrings) {
|
8591 | var ret;
|
8592 |
|
8593 | if (n < this.head.data.length) {
|
8594 |
|
8595 | ret = this.head.data.slice(0, n);
|
8596 | this.head.data = this.head.data.slice(n);
|
8597 | } else if (n === this.head.data.length) {
|
8598 |
|
8599 | ret = this.shift();
|
8600 | } else {
|
8601 |
|
8602 | ret = hasStrings ? this._getString(n) : this._getBuffer(n);
|
8603 | }
|
8604 |
|
8605 | return ret;
|
8606 | }
|
8607 | }, {
|
8608 | key: "first",
|
8609 | value: function first() {
|
8610 | return this.head.data;
|
8611 | }
|
8612 |
|
8613 | }, {
|
8614 | key: "_getString",
|
8615 | value: function _getString(n) {
|
8616 | var p = this.head;
|
8617 | var c = 1;
|
8618 | var ret = p.data;
|
8619 | n -= ret.length;
|
8620 |
|
8621 | while (p = p.next) {
|
8622 | var str = p.data;
|
8623 | var nb = n > str.length ? str.length : n;
|
8624 | if (nb === str.length) ret += str;else ret += str.slice(0, n);
|
8625 | n -= nb;
|
8626 |
|
8627 | if (n === 0) {
|
8628 | if (nb === str.length) {
|
8629 | ++c;
|
8630 | if (p.next) this.head = p.next;else this.head = this.tail = null;
|
8631 | } else {
|
8632 | this.head = p;
|
8633 | p.data = str.slice(nb);
|
8634 | }
|
8635 |
|
8636 | break;
|
8637 | }
|
8638 |
|
8639 | ++c;
|
8640 | }
|
8641 |
|
8642 | this.length -= c;
|
8643 | return ret;
|
8644 | }
|
8645 |
|
8646 | }, {
|
8647 | key: "_getBuffer",
|
8648 | value: function _getBuffer(n) {
|
8649 | var ret = Buffer.allocUnsafe(n);
|
8650 | var p = this.head;
|
8651 | var c = 1;
|
8652 | p.data.copy(ret);
|
8653 | n -= p.data.length;
|
8654 |
|
8655 | while (p = p.next) {
|
8656 | var buf = p.data;
|
8657 | var nb = n > buf.length ? buf.length : n;
|
8658 | buf.copy(ret, ret.length - n, 0, nb);
|
8659 | n -= nb;
|
8660 |
|
8661 | if (n === 0) {
|
8662 | if (nb === buf.length) {
|
8663 | ++c;
|
8664 | if (p.next) this.head = p.next;else this.head = this.tail = null;
|
8665 | } else {
|
8666 | this.head = p;
|
8667 | p.data = buf.slice(nb);
|
8668 | }
|
8669 |
|
8670 | break;
|
8671 | }
|
8672 |
|
8673 | ++c;
|
8674 | }
|
8675 |
|
8676 | this.length -= c;
|
8677 | return ret;
|
8678 | }
|
8679 |
|
8680 | }, {
|
8681 | key: custom,
|
8682 | value: function value(_, options) {
|
8683 | return inspect(this, _objectSpread({}, options, {
|
8684 |
|
8685 | depth: 0,
|
8686 |
|
8687 | customInspect: false
|
8688 | }));
|
8689 | }
|
8690 | }]);
|
8691 |
|
8692 | return BufferList;
|
8693 | }();
|
8694 | },{"7":7,"9":9}],33:[function(_dereq_,module,exports){
|
8695 | (function (process){
|
8696 | 'use strict';
|
8697 |
|
8698 | function destroy(err, cb) {
|
8699 | var _this = this;
|
8700 |
|
8701 | var readableDestroyed = this._readableState && this._readableState.destroyed;
|
8702 | var writableDestroyed = this._writableState && this._writableState.destroyed;
|
8703 |
|
8704 | if (readableDestroyed || writableDestroyed) {
|
8705 | if (cb) {
|
8706 | cb(err);
|
8707 | } else if (err) {
|
8708 | if (!this._writableState) {
|
8709 | process.nextTick(emitErrorNT, this, err);
|
8710 | } else if (!this._writableState.errorEmitted) {
|
8711 | this._writableState.errorEmitted = true;
|
8712 | process.nextTick(emitErrorNT, this, err);
|
8713 | }
|
8714 | }
|
8715 |
|
8716 | return this;
|
8717 | }
|
8718 |
|
8719 |
|
8720 |
|
8721 | if (this._readableState) {
|
8722 | this._readableState.destroyed = true;
|
8723 | }
|
8724 |
|
8725 |
|
8726 | if (this._writableState) {
|
8727 | this._writableState.destroyed = true;
|
8728 | }
|
8729 |
|
8730 | this._destroy(err || null, function (err) {
|
8731 | if (!cb && err) {
|
8732 | if (!_this._writableState) {
|
8733 | process.nextTick(emitErrorAndCloseNT, _this, err);
|
8734 | } else if (!_this._writableState.errorEmitted) {
|
8735 | _this._writableState.errorEmitted = true;
|
8736 | process.nextTick(emitErrorAndCloseNT, _this, err);
|
8737 | } else {
|
8738 | process.nextTick(emitCloseNT, _this);
|
8739 | }
|
8740 | } else if (cb) {
|
8741 | process.nextTick(emitCloseNT, _this);
|
8742 | cb(err);
|
8743 | } else {
|
8744 | process.nextTick(emitCloseNT, _this);
|
8745 | }
|
8746 | });
|
8747 |
|
8748 | return this;
|
8749 | }
|
8750 |
|
8751 | function emitErrorAndCloseNT(self, err) {
|
8752 | emitErrorNT(self, err);
|
8753 | emitCloseNT(self);
|
8754 | }
|
8755 |
|
8756 | function emitCloseNT(self) {
|
8757 | if (self._writableState && !self._writableState.emitClose) return;
|
8758 | if (self._readableState && !self._readableState.emitClose) return;
|
8759 | self.emit('close');
|
8760 | }
|
8761 |
|
8762 | function undestroy() {
|
8763 | if (this._readableState) {
|
8764 | this._readableState.destroyed = false;
|
8765 | this._readableState.reading = false;
|
8766 | this._readableState.ended = false;
|
8767 | this._readableState.endEmitted = false;
|
8768 | }
|
8769 |
|
8770 | if (this._writableState) {
|
8771 | this._writableState.destroyed = false;
|
8772 | this._writableState.ended = false;
|
8773 | this._writableState.ending = false;
|
8774 | this._writableState.finalCalled = false;
|
8775 | this._writableState.prefinished = false;
|
8776 | this._writableState.finished = false;
|
8777 | this._writableState.errorEmitted = false;
|
8778 | }
|
8779 | }
|
8780 |
|
8781 | function emitErrorNT(self, err) {
|
8782 | self.emit('error', err);
|
8783 | }
|
8784 |
|
8785 | function errorOrDestroy(stream, err) {
|
8786 |
|
8787 |
|
8788 |
|
8789 |
|
8790 |
|
8791 | var rState = stream._readableState;
|
8792 | var wState = stream._writableState;
|
8793 | if (rState && rState.autoDestroy || wState && wState.autoDestroy) stream.destroy(err);else stream.emit('error', err);
|
8794 | }
|
8795 |
|
8796 | module.exports = {
|
8797 | destroy: destroy,
|
8798 | undestroy: undestroy,
|
8799 | errorOrDestroy: errorOrDestroy
|
8800 | };
|
8801 | }).call(this,_dereq_(70))
|
8802 | },{"70":70}],34:[function(_dereq_,module,exports){
|
8803 |
|
8804 |
|
8805 | 'use strict';
|
8806 |
|
8807 | var ERR_STREAM_PREMATURE_CLOSE = _dereq_(25).codes.ERR_STREAM_PREMATURE_CLOSE;
|
8808 |
|
8809 | function once(callback) {
|
8810 | var called = false;
|
8811 | return function () {
|
8812 | if (called) return;
|
8813 | called = true;
|
8814 |
|
8815 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
8816 | args[_key] = arguments[_key];
|
8817 | }
|
8818 |
|
8819 | callback.apply(this, args);
|
8820 | };
|
8821 | }
|
8822 |
|
8823 | function noop() {}
|
8824 |
|
8825 | function isRequest(stream) {
|
8826 | return stream.setHeader && typeof stream.abort === 'function';
|
8827 | }
|
8828 |
|
8829 | function eos(stream, opts, callback) {
|
8830 | if (typeof opts === 'function') return eos(stream, null, opts);
|
8831 | if (!opts) opts = {};
|
8832 | callback = once(callback || noop);
|
8833 | var readable = opts.readable || opts.readable !== false && stream.readable;
|
8834 | var writable = opts.writable || opts.writable !== false && stream.writable;
|
8835 |
|
8836 | var onlegacyfinish = function onlegacyfinish() {
|
8837 | if (!stream.writable) onfinish();
|
8838 | };
|
8839 |
|
8840 | var writableEnded = stream._writableState && stream._writableState.finished;
|
8841 |
|
8842 | var onfinish = function onfinish() {
|
8843 | writable = false;
|
8844 | writableEnded = true;
|
8845 | if (!readable) callback.call(stream);
|
8846 | };
|
8847 |
|
8848 | var readableEnded = stream._readableState && stream._readableState.endEmitted;
|
8849 |
|
8850 | var onend = function onend() {
|
8851 | readable = false;
|
8852 | readableEnded = true;
|
8853 | if (!writable) callback.call(stream);
|
8854 | };
|
8855 |
|
8856 | var onerror = function onerror(err) {
|
8857 | callback.call(stream, err);
|
8858 | };
|
8859 |
|
8860 | var onclose = function onclose() {
|
8861 | var err;
|
8862 |
|
8863 | if (readable && !readableEnded) {
|
8864 | if (!stream._readableState || !stream._readableState.ended) err = new ERR_STREAM_PREMATURE_CLOSE();
|
8865 | return callback.call(stream, err);
|
8866 | }
|
8867 |
|
8868 | if (writable && !writableEnded) {
|
8869 | if (!stream._writableState || !stream._writableState.ended) err = new ERR_STREAM_PREMATURE_CLOSE();
|
8870 | return callback.call(stream, err);
|
8871 | }
|
8872 | };
|
8873 |
|
8874 | var onrequest = function onrequest() {
|
8875 | stream.req.on('finish', onfinish);
|
8876 | };
|
8877 |
|
8878 | if (isRequest(stream)) {
|
8879 | stream.on('complete', onfinish);
|
8880 | stream.on('abort', onclose);
|
8881 | if (stream.req) onrequest();else stream.on('request', onrequest);
|
8882 | } else if (writable && !stream._writableState) {
|
8883 |
|
8884 | stream.on('end', onlegacyfinish);
|
8885 | stream.on('close', onlegacyfinish);
|
8886 | }
|
8887 |
|
8888 | stream.on('end', onend);
|
8889 | stream.on('finish', onfinish);
|
8890 | if (opts.error !== false) stream.on('error', onerror);
|
8891 | stream.on('close', onclose);
|
8892 | return function () {
|
8893 | stream.removeListener('complete', onfinish);
|
8894 | stream.removeListener('abort', onclose);
|
8895 | stream.removeListener('request', onrequest);
|
8896 | if (stream.req) stream.req.removeListener('finish', onfinish);
|
8897 | stream.removeListener('end', onlegacyfinish);
|
8898 | stream.removeListener('close', onlegacyfinish);
|
8899 | stream.removeListener('finish', onfinish);
|
8900 | stream.removeListener('end', onend);
|
8901 | stream.removeListener('error', onerror);
|
8902 | stream.removeListener('close', onclose);
|
8903 | };
|
8904 | }
|
8905 |
|
8906 | module.exports = eos;
|
8907 | },{"25":25}],35:[function(_dereq_,module,exports){
|
8908 | module.exports = function () {
|
8909 | throw new Error('Readable.from is not available in the browser')
|
8910 | };
|
8911 |
|
8912 | },{}],36:[function(_dereq_,module,exports){
|
8913 |
|
8914 |
|
8915 | 'use strict';
|
8916 |
|
8917 | var eos;
|
8918 |
|
8919 | function once(callback) {
|
8920 | var called = false;
|
8921 | return function () {
|
8922 | if (called) return;
|
8923 | called = true;
|
8924 | callback.apply(void 0, arguments);
|
8925 | };
|
8926 | }
|
8927 |
|
8928 | var _require$codes = _dereq_(25).codes,
|
8929 | ERR_MISSING_ARGS = _require$codes.ERR_MISSING_ARGS,
|
8930 | ERR_STREAM_DESTROYED = _require$codes.ERR_STREAM_DESTROYED;
|
8931 |
|
8932 | function noop(err) {
|
8933 |
|
8934 | if (err) throw err;
|
8935 | }
|
8936 |
|
8937 | function isRequest(stream) {
|
8938 | return stream.setHeader && typeof stream.abort === 'function';
|
8939 | }
|
8940 |
|
8941 | function destroyer(stream, reading, writing, callback) {
|
8942 | callback = once(callback);
|
8943 | var closed = false;
|
8944 | stream.on('close', function () {
|
8945 | closed = true;
|
8946 | });
|
8947 | if (eos === undefined) eos = _dereq_(34);
|
8948 | eos(stream, {
|
8949 | readable: reading,
|
8950 | writable: writing
|
8951 | }, function (err) {
|
8952 | if (err) return callback(err);
|
8953 | closed = true;
|
8954 | callback();
|
8955 | });
|
8956 | var destroyed = false;
|
8957 | return function (err) {
|
8958 | if (closed) return;
|
8959 | if (destroyed) return;
|
8960 | destroyed = true;
|
8961 |
|
8962 | if (isRequest(stream)) return stream.abort();
|
8963 | if (typeof stream.destroy === 'function') return stream.destroy();
|
8964 | callback(err || new ERR_STREAM_DESTROYED('pipe'));
|
8965 | };
|
8966 | }
|
8967 |
|
8968 | function call(fn) {
|
8969 | fn();
|
8970 | }
|
8971 |
|
8972 | function pipe(from, to) {
|
8973 | return from.pipe(to);
|
8974 | }
|
8975 |
|
8976 | function popCallback(streams) {
|
8977 | if (!streams.length) return noop;
|
8978 | if (typeof streams[streams.length - 1] !== 'function') return noop;
|
8979 | return streams.pop();
|
8980 | }
|
8981 |
|
8982 | function pipeline() {
|
8983 | for (var _len = arguments.length, streams = new Array(_len), _key = 0; _key < _len; _key++) {
|
8984 | streams[_key] = arguments[_key];
|
8985 | }
|
8986 |
|
8987 | var callback = popCallback(streams);
|
8988 | if (Array.isArray(streams[0])) streams = streams[0];
|
8989 |
|
8990 | if (streams.length < 2) {
|
8991 | throw new ERR_MISSING_ARGS('streams');
|
8992 | }
|
8993 |
|
8994 | var error;
|
8995 | var destroys = streams.map(function (stream, i) {
|
8996 | var reading = i < streams.length - 1;
|
8997 | var writing = i > 0;
|
8998 | return destroyer(stream, reading, writing, function (err) {
|
8999 | if (!error) error = err;
|
9000 | if (err) destroys.forEach(call);
|
9001 | if (reading) return;
|
9002 | destroys.forEach(call);
|
9003 | callback(error);
|
9004 | });
|
9005 | });
|
9006 | return streams.reduce(pipe);
|
9007 | }
|
9008 |
|
9009 | module.exports = pipeline;
|
9010 | },{"25":25,"34":34}],37:[function(_dereq_,module,exports){
|
9011 | 'use strict';
|
9012 |
|
9013 | var ERR_INVALID_OPT_VALUE = _dereq_(25).codes.ERR_INVALID_OPT_VALUE;
|
9014 |
|
9015 | function highWaterMarkFrom(options, isDuplex, duplexKey) {
|
9016 | return options.highWaterMark != null ? options.highWaterMark : isDuplex ? options[duplexKey] : null;
|
9017 | }
|
9018 |
|
9019 | function getHighWaterMark(state, options, duplexKey, isDuplex) {
|
9020 | var hwm = highWaterMarkFrom(options, isDuplex, duplexKey);
|
9021 |
|
9022 | if (hwm != null) {
|
9023 | if (!(isFinite(hwm) && Math.floor(hwm) === hwm) || hwm < 0) {
|
9024 | var name = isDuplex ? duplexKey : 'highWaterMark';
|
9025 | throw new ERR_INVALID_OPT_VALUE(name, hwm);
|
9026 | }
|
9027 |
|
9028 | return Math.floor(hwm);
|
9029 | }
|
9030 |
|
9031 |
|
9032 | return state.objectMode ? 16 : 16 * 1024;
|
9033 | }
|
9034 |
|
9035 | module.exports = {
|
9036 | getHighWaterMark: getHighWaterMark
|
9037 | };
|
9038 | },{"25":25}],38:[function(_dereq_,module,exports){
|
9039 | module.exports = _dereq_(14).EventEmitter;
|
9040 |
|
9041 | },{"14":14}],39:[function(_dereq_,module,exports){
|
9042 | exports = module.exports = _dereq_(28);
|
9043 | exports.Stream = exports;
|
9044 | exports.Readable = exports;
|
9045 | exports.Writable = _dereq_(30);
|
9046 | exports.Duplex = _dereq_(26);
|
9047 | exports.Transform = _dereq_(29);
|
9048 | exports.PassThrough = _dereq_(27);
|
9049 | exports.finished = _dereq_(34);
|
9050 | exports.pipeline = _dereq_(36);
|
9051 |
|
9052 | },{"26":26,"27":27,"28":28,"29":29,"30":30,"34":34,"36":36}],40:[function(_dereq_,module,exports){
|
9053 | module.exports = extend
|
9054 |
|
9055 | var hasOwnProperty = Object.prototype.hasOwnProperty;
|
9056 |
|
9057 | function extend() {
|
9058 | var target = {}
|
9059 |
|
9060 | for (var i = 0; i < arguments.length; i++) {
|
9061 | var source = arguments[i]
|
9062 |
|
9063 | for (var key in source) {
|
9064 | if (hasOwnProperty.call(source, key)) {
|
9065 | target[key] = source[key]
|
9066 | }
|
9067 | }
|
9068 | }
|
9069 |
|
9070 | return target
|
9071 | }
|
9072 |
|
9073 | },{}],41:[function(_dereq_,module,exports){
|
9074 | var WriteError = _dereq_(23).WriteError
|
9075 | var promisify = _dereq_(44)
|
9076 | var getCallback = _dereq_(42).getCallback
|
9077 | var getOptions = _dereq_(42).getOptions
|
9078 |
|
9079 | function Batch (levelup) {
|
9080 | this._levelup = levelup
|
9081 | this.batch = levelup.db.batch()
|
9082 | this.ops = []
|
9083 | this.length = 0
|
9084 | }
|
9085 |
|
9086 | Batch.prototype.put = function (key, value) {
|
9087 | try {
|
9088 | this.batch.put(key, value)
|
9089 | } catch (e) {
|
9090 | throw new WriteError(e)
|
9091 | }
|
9092 |
|
9093 | this.ops.push({ type: 'put', key: key, value: value })
|
9094 | this.length++
|
9095 |
|
9096 | return this
|
9097 | }
|
9098 |
|
9099 | Batch.prototype.del = function (key) {
|
9100 | try {
|
9101 | this.batch.del(key)
|
9102 | } catch (err) {
|
9103 | throw new WriteError(err)
|
9104 | }
|
9105 |
|
9106 | this.ops.push({ type: 'del', key: key })
|
9107 | this.length++
|
9108 |
|
9109 | return this
|
9110 | }
|
9111 |
|
9112 | Batch.prototype.clear = function () {
|
9113 | try {
|
9114 | this.batch.clear()
|
9115 | } catch (err) {
|
9116 | throw new WriteError(err)
|
9117 | }
|
9118 |
|
9119 | this.ops = []
|
9120 | this.length = 0
|
9121 |
|
9122 | return this
|
9123 | }
|
9124 |
|
9125 | Batch.prototype.write = function (options, callback) {
|
9126 | var levelup = this._levelup
|
9127 | var ops = this.ops
|
9128 | var promise
|
9129 |
|
9130 | callback = getCallback(options, callback)
|
9131 |
|
9132 | if (!callback) {
|
9133 | callback = promisify()
|
9134 | promise = callback.promise
|
9135 | }
|
9136 |
|
9137 | options = getOptions(options)
|
9138 |
|
9139 | try {
|
9140 | this.batch.write(options, function (err) {
|
9141 | if (err) { return callback(new WriteError(err)) }
|
9142 | levelup.emit('batch', ops)
|
9143 | callback()
|
9144 | })
|
9145 | } catch (err) {
|
9146 | throw new WriteError(err)
|
9147 | }
|
9148 |
|
9149 | return promise
|
9150 | }
|
9151 |
|
9152 | module.exports = Batch
|
9153 |
|
9154 | },{"23":23,"42":42,"44":44}],42:[function(_dereq_,module,exports){
|
9155 | exports.getCallback = function (options, callback) {
|
9156 | return typeof options === 'function' ? options : callback
|
9157 | }
|
9158 |
|
9159 | exports.getOptions = function (options) {
|
9160 | return typeof options === 'object' && options !== null ? options : {}
|
9161 | }
|
9162 |
|
9163 | },{}],43:[function(_dereq_,module,exports){
|
9164 | (function (process){
|
9165 | var EventEmitter = _dereq_(14).EventEmitter
|
9166 | var inherits = _dereq_(119).inherits
|
9167 | var extend = _dereq_(51)
|
9168 | var DeferredLevelDOWN = _dereq_(50)
|
9169 | var IteratorStream = _dereq_(24)
|
9170 | var Batch = _dereq_(41)
|
9171 | var errors = _dereq_(23)
|
9172 | var assert = _dereq_(2)
|
9173 | var promisify = _dereq_(44)
|
9174 | var getCallback = _dereq_(42).getCallback
|
9175 | var getOptions = _dereq_(42).getOptions
|
9176 |
|
9177 | var WriteError = errors.WriteError
|
9178 | var ReadError = errors.ReadError
|
9179 | var NotFoundError = errors.NotFoundError
|
9180 | var OpenError = errors.OpenError
|
9181 | var InitializationError = errors.InitializationError
|
9182 |
|
9183 |
|
9184 |
|
9185 |
|
9186 |
|
9187 |
|
9188 |
|
9189 |
|
9190 |
|
9191 | function LevelUP (db, options, callback) {
|
9192 | if (!(this instanceof LevelUP)) {
|
9193 | return new LevelUP(db, options, callback)
|
9194 | }
|
9195 |
|
9196 | var error
|
9197 |
|
9198 | EventEmitter.call(this)
|
9199 | this.setMaxListeners(Infinity)
|
9200 |
|
9201 | if (typeof options === 'function') {
|
9202 | callback = options
|
9203 | options = {}
|
9204 | }
|
9205 |
|
9206 | options = options || {}
|
9207 |
|
9208 | if (!db || typeof db !== 'object') {
|
9209 | error = new InitializationError('First argument must be an abstract-leveldown compliant store')
|
9210 | if (typeof callback === 'function') {
|
9211 | return process.nextTick(callback, error)
|
9212 | }
|
9213 | throw error
|
9214 | }
|
9215 |
|
9216 | assert.strictEqual(typeof db.status, 'string', '.status required, old abstract-leveldown')
|
9217 |
|
9218 | this.options = getOptions(options)
|
9219 | this._db = db
|
9220 | this.db = new DeferredLevelDOWN(db)
|
9221 | this.open(callback)
|
9222 | }
|
9223 |
|
9224 | LevelUP.prototype.emit = EventEmitter.prototype.emit
|
9225 | LevelUP.prototype.once = EventEmitter.prototype.once
|
9226 | inherits(LevelUP, EventEmitter)
|
9227 |
|
9228 | LevelUP.prototype.open = function (opts, callback) {
|
9229 | var self = this
|
9230 | var promise
|
9231 |
|
9232 | if (typeof opts === 'function') {
|
9233 | callback = opts
|
9234 | opts = null
|
9235 | }
|
9236 |
|
9237 | if (!callback) {
|
9238 | callback = promisify()
|
9239 | promise = callback.promise
|
9240 | }
|
9241 |
|
9242 | if (!opts) {
|
9243 | opts = this.options
|
9244 | }
|
9245 |
|
9246 | if (this.isOpen()) {
|
9247 | process.nextTick(callback, null, self)
|
9248 | return promise
|
9249 | }
|
9250 |
|
9251 | if (this._isOpening()) {
|
9252 | this.once('open', function () { callback(null, self) })
|
9253 | return promise
|
9254 | }
|
9255 |
|
9256 | this.emit('opening')
|
9257 |
|
9258 | this.db.open(opts, function (err) {
|
9259 | if (err) {
|
9260 | return callback(new OpenError(err))
|
9261 | }
|
9262 | self.db = self._db
|
9263 | callback(null, self)
|
9264 | self.emit('open')
|
9265 | self.emit('ready')
|
9266 | })
|
9267 |
|
9268 | return promise
|
9269 | }
|
9270 |
|
9271 | LevelUP.prototype.close = function (callback) {
|
9272 | var self = this
|
9273 | var promise
|
9274 |
|
9275 | if (!callback) {
|
9276 | callback = promisify()
|
9277 | promise = callback.promise
|
9278 | }
|
9279 |
|
9280 | if (this.isOpen()) {
|
9281 | this.db.close(function () {
|
9282 | self.emit('closed')
|
9283 | callback.apply(null, arguments)
|
9284 | })
|
9285 | this.emit('closing')
|
9286 | this.db = new DeferredLevelDOWN(this._db)
|
9287 | } else if (this.isClosed()) {
|
9288 | process.nextTick(callback)
|
9289 | } else if (this.db.status === 'closing') {
|
9290 | this.once('closed', callback)
|
9291 | } else if (this._isOpening()) {
|
9292 | this.once('open', function () {
|
9293 | self.close(callback)
|
9294 | })
|
9295 | }
|
9296 |
|
9297 | return promise
|
9298 | }
|
9299 |
|
9300 | LevelUP.prototype.isOpen = function () {
|
9301 | return this.db.status === 'open'
|
9302 | }
|
9303 |
|
9304 | LevelUP.prototype._isOpening = function () {
|
9305 | return this.db.status === 'opening'
|
9306 | }
|
9307 |
|
9308 | LevelUP.prototype.isClosed = function () {
|
9309 | return (/^clos|new/).test(this.db.status)
|
9310 | }
|
9311 |
|
9312 | LevelUP.prototype.get = function (key, options, callback) {
|
9313 | if (key === null || key === undefined) {
|
9314 | throw new ReadError('get() requires a key argument')
|
9315 | }
|
9316 |
|
9317 | var promise
|
9318 |
|
9319 | callback = getCallback(options, callback)
|
9320 |
|
9321 | if (!callback) {
|
9322 | callback = promisify()
|
9323 | promise = callback.promise
|
9324 | }
|
9325 |
|
9326 | if (maybeError(this, callback)) { return promise }
|
9327 |
|
9328 | options = getOptions(options)
|
9329 |
|
9330 | this.db.get(key, options, function (err, value) {
|
9331 | if (err) {
|
9332 | if ((/notfound/i).test(err) || err.notFound) {
|
9333 | err = new NotFoundError('Key not found in database [' + key + ']', err)
|
9334 | } else {
|
9335 | err = new ReadError(err)
|
9336 | }
|
9337 | return callback(err)
|
9338 | }
|
9339 | callback(null, value)
|
9340 | })
|
9341 |
|
9342 | return promise
|
9343 | }
|
9344 |
|
9345 | LevelUP.prototype.put = function (key, value, options, callback) {
|
9346 | if (key === null || key === undefined) {
|
9347 | throw new WriteError('put() requires a key argument')
|
9348 | }
|
9349 |
|
9350 | var self = this
|
9351 | var promise
|
9352 |
|
9353 | callback = getCallback(options, callback)
|
9354 |
|
9355 | if (!callback) {
|
9356 | callback = promisify()
|
9357 | promise = callback.promise
|
9358 | }
|
9359 |
|
9360 | if (maybeError(this, callback)) { return promise }
|
9361 |
|
9362 | options = getOptions(options)
|
9363 |
|
9364 | this.db.put(key, value, options, function (err) {
|
9365 | if (err) {
|
9366 | return callback(new WriteError(err))
|
9367 | }
|
9368 | self.emit('put', key, value)
|
9369 | callback()
|
9370 | })
|
9371 |
|
9372 | return promise
|
9373 | }
|
9374 |
|
9375 | LevelUP.prototype.del = function (key, options, callback) {
|
9376 | if (key === null || key === undefined) {
|
9377 | throw new WriteError('del() requires a key argument')
|
9378 | }
|
9379 |
|
9380 | var self = this
|
9381 | var promise
|
9382 |
|
9383 | callback = getCallback(options, callback)
|
9384 |
|
9385 | if (!callback) {
|
9386 | callback = promisify()
|
9387 | promise = callback.promise
|
9388 | }
|
9389 |
|
9390 | if (maybeError(this, callback)) { return promise }
|
9391 |
|
9392 | options = getOptions(options)
|
9393 |
|
9394 | this.db.del(key, options, function (err) {
|
9395 | if (err) {
|
9396 | return callback(new WriteError(err))
|
9397 | }
|
9398 | self.emit('del', key)
|
9399 | callback()
|
9400 | })
|
9401 |
|
9402 | return promise
|
9403 | }
|
9404 |
|
9405 | LevelUP.prototype.batch = function (arr, options, callback) {
|
9406 | if (!arguments.length) {
|
9407 | return new Batch(this)
|
9408 | }
|
9409 |
|
9410 | if (!Array.isArray(arr)) {
|
9411 | throw new WriteError('batch() requires an array argument')
|
9412 | }
|
9413 |
|
9414 | var self = this
|
9415 | var promise
|
9416 |
|
9417 | callback = getCallback(options, callback)
|
9418 |
|
9419 | if (!callback) {
|
9420 | callback = promisify()
|
9421 | promise = callback.promise
|
9422 | }
|
9423 |
|
9424 | if (maybeError(this, callback)) { return promise }
|
9425 |
|
9426 | options = getOptions(options)
|
9427 |
|
9428 | this.db.batch(arr, options, function (err) {
|
9429 | if (err) {
|
9430 | return callback(new WriteError(err))
|
9431 | }
|
9432 | self.emit('batch', arr)
|
9433 | callback()
|
9434 | })
|
9435 |
|
9436 | return promise
|
9437 | }
|
9438 |
|
9439 | LevelUP.prototype.iterator = function (options) {
|
9440 | return this.db.iterator(options)
|
9441 | }
|
9442 |
|
9443 | LevelUP.prototype.readStream =
|
9444 | LevelUP.prototype.createReadStream = function (options) {
|
9445 | options = extend({ keys: true, values: true }, options)
|
9446 | if (typeof options.limit !== 'number') { options.limit = -1 }
|
9447 | return new IteratorStream(this.db.iterator(options), options)
|
9448 | }
|
9449 |
|
9450 | LevelUP.prototype.keyStream =
|
9451 | LevelUP.prototype.createKeyStream = function (options) {
|
9452 | return this.createReadStream(extend(options, { keys: true, values: false }))
|
9453 | }
|
9454 |
|
9455 | LevelUP.prototype.valueStream =
|
9456 | LevelUP.prototype.createValueStream = function (options) {
|
9457 | return this.createReadStream(extend(options, { keys: false, values: true }))
|
9458 | }
|
9459 |
|
9460 | LevelUP.prototype.toString = function () {
|
9461 | return 'LevelUP'
|
9462 | }
|
9463 |
|
9464 | function maybeError (db, callback) {
|
9465 | if (!db._isOpening() && !db.isOpen()) {
|
9466 | process.nextTick(callback, new ReadError('Database is not open'))
|
9467 | return true
|
9468 | }
|
9469 | }
|
9470 |
|
9471 | LevelUP.errors = errors
|
9472 | module.exports = LevelUP.default = LevelUP
|
9473 |
|
9474 | }).call(this,_dereq_(70))
|
9475 | },{"119":119,"14":14,"2":2,"23":23,"24":24,"41":41,"42":42,"44":44,"50":50,"51":51,"70":70}],44:[function(_dereq_,module,exports){
|
9476 | function promisify () {
|
9477 | var callback
|
9478 | var promise = new Promise(function (resolve, reject) {
|
9479 | callback = function callback (err, value) {
|
9480 | if (err) reject(err)
|
9481 | else resolve(value)
|
9482 | }
|
9483 | })
|
9484 | callback.promise = promise
|
9485 | return callback
|
9486 | }
|
9487 |
|
9488 | module.exports = promisify
|
9489 |
|
9490 | },{}],45:[function(_dereq_,module,exports){
|
9491 | function AbstractChainedBatch (db) {
|
9492 | if (typeof db !== 'object' || db === null) {
|
9493 | throw new TypeError('First argument must be an abstract-leveldown compliant store')
|
9494 | }
|
9495 |
|
9496 | this.db = db
|
9497 | this._operations = []
|
9498 | this._written = false
|
9499 | }
|
9500 |
|
9501 | AbstractChainedBatch.prototype._checkWritten = function () {
|
9502 | if (this._written) {
|
9503 | throw new Error('write() already called on this batch')
|
9504 | }
|
9505 | }
|
9506 |
|
9507 | AbstractChainedBatch.prototype.put = function (key, value) {
|
9508 | this._checkWritten()
|
9509 |
|
9510 | var err = this.db._checkKey(key) || this.db._checkValue(value)
|
9511 | if (err) throw err
|
9512 |
|
9513 | key = this.db._serializeKey(key)
|
9514 | value = this.db._serializeValue(value)
|
9515 |
|
9516 | this._put(key, value)
|
9517 |
|
9518 | return this
|
9519 | }
|
9520 |
|
9521 | AbstractChainedBatch.prototype._put = function (key, value) {
|
9522 | this._operations.push({ type: 'put', key: key, value: value })
|
9523 | }
|
9524 |
|
9525 | AbstractChainedBatch.prototype.del = function (key) {
|
9526 | this._checkWritten()
|
9527 |
|
9528 | var err = this.db._checkKey(key)
|
9529 | if (err) throw err
|
9530 |
|
9531 | key = this.db._serializeKey(key)
|
9532 | this._del(key)
|
9533 |
|
9534 | return this
|
9535 | }
|
9536 |
|
9537 | AbstractChainedBatch.prototype._del = function (key) {
|
9538 | this._operations.push({ type: 'del', key: key })
|
9539 | }
|
9540 |
|
9541 | AbstractChainedBatch.prototype.clear = function () {
|
9542 | this._checkWritten()
|
9543 | this._clear()
|
9544 |
|
9545 | return this
|
9546 | }
|
9547 |
|
9548 | AbstractChainedBatch.prototype._clear = function () {
|
9549 | this._operations = []
|
9550 | }
|
9551 |
|
9552 | AbstractChainedBatch.prototype.write = function (options, callback) {
|
9553 | this._checkWritten()
|
9554 |
|
9555 | if (typeof options === 'function') { callback = options }
|
9556 | if (typeof callback !== 'function') {
|
9557 | throw new Error('write() requires a callback argument')
|
9558 | }
|
9559 | if (typeof options !== 'object' || options === null) {
|
9560 | options = {}
|
9561 | }
|
9562 |
|
9563 | this._written = true
|
9564 | this._write(options, callback)
|
9565 | }
|
9566 |
|
9567 | AbstractChainedBatch.prototype._write = function (options, callback) {
|
9568 | this.db._batch(this._operations, options, callback)
|
9569 | }
|
9570 |
|
9571 | module.exports = AbstractChainedBatch
|
9572 |
|
9573 | },{}],46:[function(_dereq_,module,exports){
|
9574 | (function (process){
|
9575 | function AbstractIterator (db) {
|
9576 | if (typeof db !== 'object' || db === null) {
|
9577 | throw new TypeError('First argument must be an abstract-leveldown compliant store')
|
9578 | }
|
9579 |
|
9580 | this.db = db
|
9581 | this._ended = false
|
9582 | this._nexting = false
|
9583 | }
|
9584 |
|
9585 | AbstractIterator.prototype.next = function (callback) {
|
9586 | var self = this
|
9587 |
|
9588 | if (typeof callback !== 'function') {
|
9589 | throw new Error('next() requires a callback argument')
|
9590 | }
|
9591 |
|
9592 | if (self._ended) {
|
9593 | process.nextTick(callback, new Error('cannot call next() after end()'))
|
9594 | return self
|
9595 | }
|
9596 |
|
9597 | if (self._nexting) {
|
9598 | process.nextTick(callback, new Error('cannot call next() before previous next() has completed'))
|
9599 | return self
|
9600 | }
|
9601 |
|
9602 | self._nexting = true
|
9603 | self._next(function () {
|
9604 | self._nexting = false
|
9605 | callback.apply(null, arguments)
|
9606 | })
|
9607 |
|
9608 | return self
|
9609 | }
|
9610 |
|
9611 | AbstractIterator.prototype._next = function (callback) {
|
9612 | process.nextTick(callback)
|
9613 | }
|
9614 |
|
9615 | AbstractIterator.prototype.seek = function (target) {
|
9616 | if (this._ended) {
|
9617 | throw new Error('cannot call seek() after end()')
|
9618 | }
|
9619 | if (this._nexting) {
|
9620 | throw new Error('cannot call seek() before next() has completed')
|
9621 | }
|
9622 |
|
9623 | target = this.db._serializeKey(target)
|
9624 | this._seek(target)
|
9625 | }
|
9626 |
|
9627 | AbstractIterator.prototype._seek = function (target) {}
|
9628 |
|
9629 | AbstractIterator.prototype.end = function (callback) {
|
9630 | if (typeof callback !== 'function') {
|
9631 | throw new Error('end() requires a callback argument')
|
9632 | }
|
9633 |
|
9634 | if (this._ended) {
|
9635 | return process.nextTick(callback, new Error('end() already called on iterator'))
|
9636 | }
|
9637 |
|
9638 | this._ended = true
|
9639 | this._end(callback)
|
9640 | }
|
9641 |
|
9642 | AbstractIterator.prototype._end = function (callback) {
|
9643 | process.nextTick(callback)
|
9644 | }
|
9645 |
|
9646 | module.exports = AbstractIterator
|
9647 |
|
9648 | }).call(this,_dereq_(70))
|
9649 | },{"70":70}],47:[function(_dereq_,module,exports){
|
9650 | (function (Buffer,process){
|
9651 | var xtend = _dereq_(51)
|
9652 | var AbstractIterator = _dereq_(46)
|
9653 | var AbstractChainedBatch = _dereq_(45)
|
9654 | var hasOwnProperty = Object.prototype.hasOwnProperty
|
9655 | var rangeOptions = 'start end gt gte lt lte'.split(' ')
|
9656 |
|
9657 | function AbstractLevelDOWN () {
|
9658 | this.status = 'new'
|
9659 | }
|
9660 |
|
9661 | AbstractLevelDOWN.prototype.open = function (options, callback) {
|
9662 | var self = this
|
9663 | var oldStatus = this.status
|
9664 |
|
9665 | if (typeof options === 'function') callback = options
|
9666 |
|
9667 | if (typeof callback !== 'function') {
|
9668 | throw new Error('open() requires a callback argument')
|
9669 | }
|
9670 |
|
9671 | if (typeof options !== 'object' || options === null) options = {}
|
9672 |
|
9673 | options.createIfMissing = options.createIfMissing !== false
|
9674 | options.errorIfExists = !!options.errorIfExists
|
9675 |
|
9676 | this.status = 'opening'
|
9677 | this._open(options, function (err) {
|
9678 | if (err) {
|
9679 | self.status = oldStatus
|
9680 | return callback(err)
|
9681 | }
|
9682 | self.status = 'open'
|
9683 | callback()
|
9684 | })
|
9685 | }
|
9686 |
|
9687 | AbstractLevelDOWN.prototype._open = function (options, callback) {
|
9688 | process.nextTick(callback)
|
9689 | }
|
9690 |
|
9691 | AbstractLevelDOWN.prototype.close = function (callback) {
|
9692 | var self = this
|
9693 | var oldStatus = this.status
|
9694 |
|
9695 | if (typeof callback !== 'function') {
|
9696 | throw new Error('close() requires a callback argument')
|
9697 | }
|
9698 |
|
9699 | this.status = 'closing'
|
9700 | this._close(function (err) {
|
9701 | if (err) {
|
9702 | self.status = oldStatus
|
9703 | return callback(err)
|
9704 | }
|
9705 | self.status = 'closed'
|
9706 | callback()
|
9707 | })
|
9708 | }
|
9709 |
|
9710 | AbstractLevelDOWN.prototype._close = function (callback) {
|
9711 | process.nextTick(callback)
|
9712 | }
|
9713 |
|
9714 | AbstractLevelDOWN.prototype.get = function (key, options, callback) {
|
9715 | if (typeof options === 'function') callback = options
|
9716 |
|
9717 | if (typeof callback !== 'function') {
|
9718 | throw new Error('get() requires a callback argument')
|
9719 | }
|
9720 |
|
9721 | var err = this._checkKey(key)
|
9722 | if (err) return process.nextTick(callback, err)
|
9723 |
|
9724 | key = this._serializeKey(key)
|
9725 |
|
9726 | if (typeof options !== 'object' || options === null) options = {}
|
9727 |
|
9728 | options.asBuffer = options.asBuffer !== false
|
9729 |
|
9730 | this._get(key, options, callback)
|
9731 | }
|
9732 |
|
9733 | AbstractLevelDOWN.prototype._get = function (key, options, callback) {
|
9734 | process.nextTick(function () { callback(new Error('NotFound')) })
|
9735 | }
|
9736 |
|
9737 | AbstractLevelDOWN.prototype.put = function (key, value, options, callback) {
|
9738 | if (typeof options === 'function') callback = options
|
9739 |
|
9740 | if (typeof callback !== 'function') {
|
9741 | throw new Error('put() requires a callback argument')
|
9742 | }
|
9743 |
|
9744 | var err = this._checkKey(key) || this._checkValue(value)
|
9745 | if (err) return process.nextTick(callback, err)
|
9746 |
|
9747 | key = this._serializeKey(key)
|
9748 | value = this._serializeValue(value)
|
9749 |
|
9750 | if (typeof options !== 'object' || options === null) options = {}
|
9751 |
|
9752 | this._put(key, value, options, callback)
|
9753 | }
|
9754 |
|
9755 | AbstractLevelDOWN.prototype._put = function (key, value, options, callback) {
|
9756 | process.nextTick(callback)
|
9757 | }
|
9758 |
|
9759 | AbstractLevelDOWN.prototype.del = function (key, options, callback) {
|
9760 | if (typeof options === 'function') callback = options
|
9761 |
|
9762 | if (typeof callback !== 'function') {
|
9763 | throw new Error('del() requires a callback argument')
|
9764 | }
|
9765 |
|
9766 | var err = this._checkKey(key)
|
9767 | if (err) return process.nextTick(callback, err)
|
9768 |
|
9769 | key = this._serializeKey(key)
|
9770 |
|
9771 | if (typeof options !== 'object' || options === null) options = {}
|
9772 |
|
9773 | this._del(key, options, callback)
|
9774 | }
|
9775 |
|
9776 | AbstractLevelDOWN.prototype._del = function (key, options, callback) {
|
9777 | process.nextTick(callback)
|
9778 | }
|
9779 |
|
9780 | AbstractLevelDOWN.prototype.batch = function (array, options, callback) {
|
9781 | if (!arguments.length) return this._chainedBatch()
|
9782 |
|
9783 | if (typeof options === 'function') callback = options
|
9784 |
|
9785 | if (typeof array === 'function') callback = array
|
9786 |
|
9787 | if (typeof callback !== 'function') {
|
9788 | throw new Error('batch(array) requires a callback argument')
|
9789 | }
|
9790 |
|
9791 | if (!Array.isArray(array)) {
|
9792 | return process.nextTick(callback, new Error('batch(array) requires an array argument'))
|
9793 | }
|
9794 |
|
9795 | if (array.length === 0) {
|
9796 | return process.nextTick(callback)
|
9797 | }
|
9798 |
|
9799 | if (typeof options !== 'object' || options === null) options = {}
|
9800 |
|
9801 | var serialized = new Array(array.length)
|
9802 |
|
9803 | for (var i = 0; i < array.length; i++) {
|
9804 | if (typeof array[i] !== 'object' || array[i] === null) {
|
9805 | return process.nextTick(callback, new Error('batch(array) element must be an object and not `null`'))
|
9806 | }
|
9807 |
|
9808 | var e = xtend(array[i])
|
9809 |
|
9810 | if (e.type !== 'put' && e.type !== 'del') {
|
9811 | return process.nextTick(callback, new Error("`type` must be 'put' or 'del'"))
|
9812 | }
|
9813 |
|
9814 | var err = this._checkKey(e.key)
|
9815 | if (err) return process.nextTick(callback, err)
|
9816 |
|
9817 | e.key = this._serializeKey(e.key)
|
9818 |
|
9819 | if (e.type === 'put') {
|
9820 | var valueErr = this._checkValue(e.value)
|
9821 | if (valueErr) return process.nextTick(callback, valueErr)
|
9822 |
|
9823 | e.value = this._serializeValue(e.value)
|
9824 | }
|
9825 |
|
9826 | serialized[i] = e
|
9827 | }
|
9828 |
|
9829 | this._batch(serialized, options, callback)
|
9830 | }
|
9831 |
|
9832 | AbstractLevelDOWN.prototype._batch = function (array, options, callback) {
|
9833 | process.nextTick(callback)
|
9834 | }
|
9835 |
|
9836 | AbstractLevelDOWN.prototype._setupIteratorOptions = function (options) {
|
9837 | options = cleanRangeOptions(this, options)
|
9838 |
|
9839 | options.reverse = !!options.reverse
|
9840 | options.keys = options.keys !== false
|
9841 | options.values = options.values !== false
|
9842 | options.limit = 'limit' in options ? options.limit : -1
|
9843 | options.keyAsBuffer = options.keyAsBuffer !== false
|
9844 | options.valueAsBuffer = options.valueAsBuffer !== false
|
9845 |
|
9846 | return options
|
9847 | }
|
9848 |
|
9849 | function cleanRangeOptions (db, options) {
|
9850 | var result = {}
|
9851 |
|
9852 | for (var k in options) {
|
9853 | if (!hasOwnProperty.call(options, k)) continue
|
9854 |
|
9855 | var opt = options[k]
|
9856 |
|
9857 | if (isRangeOption(k)) {
|
9858 |
|
9859 |
|
9860 | opt = db._serializeKey(opt)
|
9861 | }
|
9862 |
|
9863 | result[k] = opt
|
9864 | }
|
9865 |
|
9866 | return result
|
9867 | }
|
9868 |
|
9869 | function isRangeOption (k) {
|
9870 | return rangeOptions.indexOf(k) !== -1
|
9871 | }
|
9872 |
|
9873 | AbstractLevelDOWN.prototype.iterator = function (options) {
|
9874 | if (typeof options !== 'object' || options === null) options = {}
|
9875 | options = this._setupIteratorOptions(options)
|
9876 | return this._iterator(options)
|
9877 | }
|
9878 |
|
9879 | AbstractLevelDOWN.prototype._iterator = function (options) {
|
9880 | return new AbstractIterator(this)
|
9881 | }
|
9882 |
|
9883 | AbstractLevelDOWN.prototype._chainedBatch = function () {
|
9884 | return new AbstractChainedBatch(this)
|
9885 | }
|
9886 |
|
9887 | AbstractLevelDOWN.prototype._serializeKey = function (key) {
|
9888 | return key
|
9889 | }
|
9890 |
|
9891 | AbstractLevelDOWN.prototype._serializeValue = function (value) {
|
9892 | return value
|
9893 | }
|
9894 |
|
9895 | AbstractLevelDOWN.prototype._checkKey = function (key) {
|
9896 | if (key === null || key === undefined) {
|
9897 | return new Error('key cannot be `null` or `undefined`')
|
9898 | } else if (Buffer.isBuffer(key) && key.length === 0) {
|
9899 | return new Error('key cannot be an empty Buffer')
|
9900 | } else if (key === '') {
|
9901 | return new Error('key cannot be an empty String')
|
9902 | } else if (Array.isArray(key) && key.length === 0) {
|
9903 | return new Error('key cannot be an empty Array')
|
9904 | }
|
9905 | }
|
9906 |
|
9907 | AbstractLevelDOWN.prototype._checkValue = function (value) {
|
9908 | if (value === null || value === undefined) {
|
9909 | return new Error('value cannot be `null` or `undefined`')
|
9910 | }
|
9911 | }
|
9912 |
|
9913 | module.exports = AbstractLevelDOWN
|
9914 |
|
9915 | }).call(this,{"isBuffer":_dereq_(19)},_dereq_(70))
|
9916 | },{"19":19,"45":45,"46":46,"51":51,"70":70}],48:[function(_dereq_,module,exports){
|
9917 | exports.AbstractLevelDOWN = _dereq_(47)
|
9918 | exports.AbstractIterator = _dereq_(46)
|
9919 | exports.AbstractChainedBatch = _dereq_(45)
|
9920 |
|
9921 | },{"45":45,"46":46,"47":47}],49:[function(_dereq_,module,exports){
|
9922 | var AbstractIterator = _dereq_(48).AbstractIterator
|
9923 | var inherits = _dereq_(18)
|
9924 |
|
9925 | function DeferredIterator (options) {
|
9926 | AbstractIterator.call(this, options)
|
9927 |
|
9928 | this._options = options
|
9929 | this._iterator = null
|
9930 | this._operations = []
|
9931 | }
|
9932 |
|
9933 | inherits(DeferredIterator, AbstractIterator)
|
9934 |
|
9935 | DeferredIterator.prototype.setDb = function (db) {
|
9936 | var it = this._iterator = db.iterator(this._options)
|
9937 | this._operations.forEach(function (op) {
|
9938 | it[op.method].apply(it, op.args)
|
9939 | })
|
9940 | }
|
9941 |
|
9942 | DeferredIterator.prototype._operation = function (method, args) {
|
9943 | if (this._iterator) return this._iterator[method].apply(this._iterator, args)
|
9944 | this._operations.push({ method: method, args: args })
|
9945 | }
|
9946 |
|
9947 | 'next end'.split(' ').forEach(function (m) {
|
9948 | DeferredIterator.prototype['_' + m] = function () {
|
9949 | this._operation(m, arguments)
|
9950 | }
|
9951 | })
|
9952 |
|
9953 |
|
9954 | DeferredIterator.prototype.seek = function () {
|
9955 | this._operation('seek', arguments)
|
9956 | }
|
9957 |
|
9958 | module.exports = DeferredIterator
|
9959 |
|
9960 | },{"18":18,"48":48}],50:[function(_dereq_,module,exports){
|
9961 | var AbstractLevelDOWN = _dereq_(48).AbstractLevelDOWN
|
9962 | var inherits = _dereq_(18)
|
9963 | var DeferredIterator = _dereq_(49)
|
9964 | var deferrables = 'put get del batch'.split(' ')
|
9965 |
|
9966 | function DeferredLevelDOWN (db) {
|
9967 | AbstractLevelDOWN.call(this, '')
|
9968 | this._db = db
|
9969 | this._operations = []
|
9970 | this._iterators = []
|
9971 | closed(this)
|
9972 | }
|
9973 |
|
9974 | inherits(DeferredLevelDOWN, AbstractLevelDOWN)
|
9975 |
|
9976 | DeferredLevelDOWN.prototype._open = function (options, callback) {
|
9977 | var self = this
|
9978 |
|
9979 | this._db.open(options, function (err) {
|
9980 | if (err) return callback(err)
|
9981 |
|
9982 | self._operations.forEach(function (op) {
|
9983 | self._db[op.method].apply(self._db, op.args)
|
9984 | })
|
9985 | self._operations = []
|
9986 | self._iterators.forEach(function (it) {
|
9987 | it.setDb(self._db)
|
9988 | })
|
9989 | self._iterators = []
|
9990 | open(self)
|
9991 | callback()
|
9992 | })
|
9993 | }
|
9994 |
|
9995 | DeferredLevelDOWN.prototype._close = function (callback) {
|
9996 | var self = this
|
9997 |
|
9998 | this._db.close(function (err) {
|
9999 | if (err) return callback(err)
|
10000 | closed(self)
|
10001 | callback()
|
10002 | })
|
10003 | }
|
10004 |
|
10005 | function open (self) {
|
10006 | deferrables.concat('iterator').forEach(function (m) {
|
10007 | self['_' + m] = function () {
|
10008 | return this._db[m].apply(this._db, arguments)
|
10009 | }
|
10010 | })
|
10011 | if (self._db.approximateSize) {
|
10012 | self.approximateSize = function () {
|
10013 | return this._db.approximateSize.apply(this._db, arguments)
|
10014 | }
|
10015 | }
|
10016 | }
|
10017 |
|
10018 | function closed (self) {
|
10019 | deferrables.forEach(function (m) {
|
10020 | self['_' + m] = function () {
|
10021 | this._operations.push({ method: m, args: arguments })
|
10022 | }
|
10023 | })
|
10024 | if (typeof self._db.approximateSize === 'function') {
|
10025 | self.approximateSize = function () {
|
10026 | this._operations.push({
|
10027 | method: 'approximateSize',
|
10028 | args: arguments
|
10029 | })
|
10030 | }
|
10031 | }
|
10032 | self._iterator = function (options) {
|
10033 | var it = new DeferredIterator(options)
|
10034 | this._iterators.push(it)
|
10035 | return it
|
10036 | }
|
10037 | }
|
10038 |
|
10039 | DeferredLevelDOWN.prototype._serializeKey = function (key) {
|
10040 | return key
|
10041 | }
|
10042 |
|
10043 | DeferredLevelDOWN.prototype._serializeValue = function (value) {
|
10044 | return value
|
10045 | }
|
10046 |
|
10047 | module.exports = DeferredLevelDOWN
|
10048 | module.exports.DeferredIterator = DeferredIterator
|
10049 |
|
10050 | },{"18":18,"48":48,"49":49}],51:[function(_dereq_,module,exports){
|
10051 | arguments[4][40][0].apply(exports,arguments)
|
10052 | },{"40":40}],52:[function(_dereq_,module,exports){
|
10053 | (function (Buffer){
|
10054 |
|
10055 | exports.compare = function (a, b) {
|
10056 |
|
10057 | if(Buffer.isBuffer(a)) {
|
10058 | var l = Math.min(a.length, b.length)
|
10059 | for(var i = 0; i < l; i++) {
|
10060 | var cmp = a[i] - b[i]
|
10061 | if(cmp) return cmp
|
10062 | }
|
10063 | return a.length - b.length
|
10064 | }
|
10065 |
|
10066 | return a < b ? -1 : a > b ? 1 : 0
|
10067 | }
|
10068 |
|
10069 |
|
10070 |
|
10071 |
|
10072 |
|
10073 |
|
10074 | function isDef (val) {
|
10075 | return val !== undefined && val !== ''
|
10076 | }
|
10077 |
|
10078 | function has (range, name) {
|
10079 | return Object.hasOwnProperty.call(range, name)
|
10080 | }
|
10081 |
|
10082 | function hasKey(range, name) {
|
10083 | return Object.hasOwnProperty.call(range, name) && name
|
10084 | }
|
10085 |
|
10086 | var lowerBoundKey = exports.lowerBoundKey = function (range) {
|
10087 | return (
|
10088 | hasKey(range, 'gt')
|
10089 | || hasKey(range, 'gte')
|
10090 | || hasKey(range, 'min')
|
10091 | || (range.reverse ? hasKey(range, 'end') : hasKey(range, 'start'))
|
10092 | || undefined
|
10093 | )
|
10094 | }
|
10095 |
|
10096 | var lowerBound = exports.lowerBound = function (range, def) {
|
10097 | var k = lowerBoundKey(range)
|
10098 | return k ? range[k] : def
|
10099 | }
|
10100 |
|
10101 | var lowerBoundInclusive = exports.lowerBoundInclusive = function (range) {
|
10102 | return has(range, 'gt') ? false : true
|
10103 | }
|
10104 |
|
10105 | var upperBoundInclusive = exports.upperBoundInclusive =
|
10106 | function (range) {
|
10107 | return (has(range, 'lt') ) ? false : true
|
10108 | }
|
10109 |
|
10110 | var lowerBoundExclusive = exports.lowerBoundExclusive =
|
10111 | function (range) {
|
10112 | return !lowerBoundInclusive(range)
|
10113 | }
|
10114 |
|
10115 | var upperBoundExclusive = exports.upperBoundExclusive =
|
10116 | function (range) {
|
10117 | return !upperBoundInclusive(range)
|
10118 | }
|
10119 |
|
10120 | var upperBoundKey = exports.upperBoundKey = function (range) {
|
10121 | return (
|
10122 | hasKey(range, 'lt')
|
10123 | || hasKey(range, 'lte')
|
10124 | || hasKey(range, 'max')
|
10125 | || (range.reverse ? hasKey(range, 'start') : hasKey(range, 'end'))
|
10126 | || undefined
|
10127 | )
|
10128 | }
|
10129 |
|
10130 | var upperBound = exports.upperBound = function (range, def) {
|
10131 | var k = upperBoundKey(range)
|
10132 | return k ? range[k] : def
|
10133 | }
|
10134 |
|
10135 | exports.start = function (range, def) {
|
10136 | return range.reverse ? upperBound(range, def) : lowerBound(range, def)
|
10137 | }
|
10138 | exports.end = function (range, def) {
|
10139 | return range.reverse ? lowerBound(range, def) : upperBound(range, def)
|
10140 | }
|
10141 | exports.startInclusive = function (range) {
|
10142 | return (
|
10143 | range.reverse
|
10144 | ? upperBoundInclusive(range)
|
10145 | : lowerBoundInclusive(range)
|
10146 | )
|
10147 | }
|
10148 | exports.endInclusive = function (range) {
|
10149 | return (
|
10150 | range.reverse
|
10151 | ? lowerBoundInclusive(range)
|
10152 | : upperBoundInclusive(range)
|
10153 | )
|
10154 | }
|
10155 |
|
10156 | function id (e) { return e }
|
10157 |
|
10158 | exports.toLtgt = function (range, _range, map, lower, upper) {
|
10159 | _range = _range || {}
|
10160 | map = map || id
|
10161 | var defaults = arguments.length > 3
|
10162 | var lb = exports.lowerBoundKey(range)
|
10163 | var ub = exports.upperBoundKey(range)
|
10164 | if(lb) {
|
10165 | if(lb === 'gt') _range.gt = map(range.gt, false)
|
10166 | else _range.gte = map(range[lb], false)
|
10167 | }
|
10168 | else if(defaults)
|
10169 | _range.gte = map(lower, false)
|
10170 |
|
10171 | if(ub) {
|
10172 | if(ub === 'lt') _range.lt = map(range.lt, true)
|
10173 | else _range.lte = map(range[ub], true)
|
10174 | }
|
10175 | else if(defaults)
|
10176 | _range.lte = map(upper, true)
|
10177 |
|
10178 | if(range.reverse != null)
|
10179 | _range.reverse = !!range.reverse
|
10180 |
|
10181 |
|
10182 |
|
10183 |
|
10184 | if(has(_range, 'max')) delete _range.max
|
10185 | if(has(_range, 'min')) delete _range.min
|
10186 | if(has(_range, 'start')) delete _range.start
|
10187 | if(has(_range, 'end')) delete _range.end
|
10188 |
|
10189 | return _range
|
10190 | }
|
10191 |
|
10192 | exports.contains = function (range, key, compare) {
|
10193 | compare = compare || exports.compare
|
10194 |
|
10195 | var lb = lowerBound(range)
|
10196 | if(isDef(lb)) {
|
10197 | var cmp = compare(key, lb)
|
10198 | if(cmp < 0 || (cmp === 0 && lowerBoundExclusive(range)))
|
10199 | return false
|
10200 | }
|
10201 |
|
10202 | var ub = upperBound(range)
|
10203 | if(isDef(ub)) {
|
10204 | var cmp = compare(key, ub)
|
10205 | if(cmp > 0 || (cmp === 0) && upperBoundExclusive(range))
|
10206 | return false
|
10207 | }
|
10208 |
|
10209 | return true
|
10210 | }
|
10211 |
|
10212 | exports.filter = function (range, compare) {
|
10213 | return function (key) {
|
10214 | return exports.contains(range, key, compare)
|
10215 | }
|
10216 | }
|
10217 |
|
10218 |
|
10219 |
|
10220 | }).call(this,{"isBuffer":_dereq_(19)})
|
10221 | },{"19":19}],53:[function(_dereq_,module,exports){
|
10222 | module.exports = _dereq_(60)
|
10223 |
|
10224 | },{"60":60}],54:[function(_dereq_,module,exports){
|
10225 | (function (Buffer){
|
10226 | var inherits = _dereq_(18)
|
10227 | , AbstractLevelDOWN = _dereq_(58).AbstractLevelDOWN
|
10228 | , AbstractIterator = _dereq_(58).AbstractIterator
|
10229 | , ltgt = _dereq_(66)
|
10230 | , createRBT = _dereq_(15)
|
10231 | , globalStore = {}
|
10232 |
|
10233 |
|
10234 |
|
10235 | var setImmediate = _dereq_(53)
|
10236 |
|
10237 | function gt(value) {
|
10238 | return ltgt.compare(value, this._end) > 0
|
10239 | }
|
10240 |
|
10241 | function gte(value) {
|
10242 | return ltgt.compare(value, this._end) >= 0
|
10243 | }
|
10244 |
|
10245 | function lt(value) {
|
10246 | return ltgt.compare(value, this._end) < 0
|
10247 | }
|
10248 |
|
10249 | function lte(value) {
|
10250 | return ltgt.compare(value, this._end) <= 0
|
10251 | }
|
10252 |
|
10253 |
|
10254 | function MemIterator (db, options) {
|
10255 | AbstractIterator.call(this, db)
|
10256 | this._limit = options.limit
|
10257 |
|
10258 | if (this._limit === -1)
|
10259 | this._limit = Infinity
|
10260 |
|
10261 | var tree = db._store[db._location]
|
10262 |
|
10263 | this.keyAsBuffer = options.keyAsBuffer !== false
|
10264 | this.valueAsBuffer = options.valueAsBuffer !== false
|
10265 | this._reverse = options.reverse
|
10266 | this._options = options
|
10267 | this._done = 0
|
10268 |
|
10269 | if (!this._reverse) {
|
10270 | this._incr = 'next'
|
10271 | this._start = ltgt.lowerBound(options)
|
10272 | this._end = ltgt.upperBound(options)
|
10273 |
|
10274 | if (typeof this._start === 'undefined')
|
10275 | this._tree = tree.begin
|
10276 | else if (ltgt.lowerBoundInclusive(options))
|
10277 | this._tree = tree.ge(this._start)
|
10278 | else
|
10279 | this._tree = tree.gt(this._start)
|
10280 |
|
10281 | if (this._end) {
|
10282 | if (ltgt.upperBoundInclusive(options))
|
10283 | this._test = lte
|
10284 | else
|
10285 | this._test = lt
|
10286 | }
|
10287 |
|
10288 | } else {
|
10289 | this._incr = 'prev'
|
10290 | this._start = ltgt.upperBound(options)
|
10291 | this._end = ltgt.lowerBound(options)
|
10292 |
|
10293 | if (typeof this._start === 'undefined')
|
10294 | this._tree = tree.end
|
10295 | else if (ltgt.upperBoundInclusive(options))
|
10296 | this._tree = tree.le(this._start)
|
10297 | else
|
10298 | this._tree = tree.lt(this._start)
|
10299 |
|
10300 | if (this._end) {
|
10301 | if (ltgt.lowerBoundInclusive(options))
|
10302 | this._test = gte
|
10303 | else
|
10304 | this._test = gt
|
10305 | }
|
10306 |
|
10307 | }
|
10308 |
|
10309 | }
|
10310 |
|
10311 | inherits(MemIterator, AbstractIterator)
|
10312 |
|
10313 | MemIterator.prototype._next = function (callback) {
|
10314 | var key
|
10315 | , value
|
10316 |
|
10317 | if (this._done++ >= this._limit)
|
10318 | return setImmediate(callback)
|
10319 |
|
10320 | if (!this._tree.valid)
|
10321 | return setImmediate(callback)
|
10322 |
|
10323 | key = this._tree.key
|
10324 | value = this._tree.value
|
10325 |
|
10326 | if (!this._test(key))
|
10327 | return setImmediate(callback)
|
10328 |
|
10329 | if (this.keyAsBuffer)
|
10330 | key = new Buffer(key)
|
10331 |
|
10332 | if (this.valueAsBuffer)
|
10333 | value = new Buffer(value)
|
10334 |
|
10335 | this._tree[this._incr]()
|
10336 |
|
10337 | setImmediate(function callNext() {
|
10338 | callback(null, key, value)
|
10339 | })
|
10340 | }
|
10341 |
|
10342 | MemIterator.prototype._test = function () {return true}
|
10343 |
|
10344 | function MemDOWN (location) {
|
10345 | if (!(this instanceof MemDOWN))
|
10346 | return new MemDOWN(location)
|
10347 |
|
10348 | AbstractLevelDOWN.call(this, typeof location == 'string' ? location : '')
|
10349 |
|
10350 | this._location = this.location ? ('$' + this.location) : '_tree'
|
10351 | this._store = this.location ? globalStore: this
|
10352 | this._store[this._location] = this._store[this._location] || createRBT(ltgt.compare)
|
10353 | }
|
10354 |
|
10355 | MemDOWN.clearGlobalStore = function (strict) {
|
10356 | if (strict) {
|
10357 | Object.keys(globalStore).forEach(function (key) {
|
10358 | delete globalStore[key]
|
10359 | })
|
10360 | } else {
|
10361 | globalStore = {}
|
10362 | }
|
10363 | }
|
10364 |
|
10365 | inherits(MemDOWN, AbstractLevelDOWN)
|
10366 |
|
10367 | MemDOWN.prototype._open = function (options, callback) {
|
10368 | var self = this
|
10369 | setImmediate(function callNext() { callback(null, self) })
|
10370 | }
|
10371 |
|
10372 | MemDOWN.prototype._put = function (key, value, options, callback) {
|
10373 | if (typeof value === 'undefined' || value === null) value = ''
|
10374 |
|
10375 | var iter = this._store[this._location].find(key)
|
10376 |
|
10377 | if (iter.valid) {
|
10378 | this._store[this._location] = iter.update(value)
|
10379 | } else {
|
10380 | this._store[this._location] = this._store[this._location].insert(key, value)
|
10381 | }
|
10382 |
|
10383 | setImmediate(callback)
|
10384 | }
|
10385 |
|
10386 | MemDOWN.prototype._get = function (key, options, callback) {
|
10387 | var value = this._store[this._location].get(key)
|
10388 |
|
10389 | if (typeof value === 'undefined') {
|
10390 |
|
10391 | return setImmediate(function callNext() { callback(new Error('NotFound')) })
|
10392 | }
|
10393 |
|
10394 | if (options.asBuffer !== false && !this._isBuffer(value))
|
10395 | value = new Buffer(String(value))
|
10396 |
|
10397 | setImmediate(function callNext () {
|
10398 | callback(null, value)
|
10399 | })
|
10400 |
|
10401 | }
|
10402 |
|
10403 | MemDOWN.prototype._del = function (key, options, callback) {
|
10404 | this._store[this._location] = this._store[this._location].remove(key)
|
10405 | setImmediate(callback)
|
10406 | }
|
10407 |
|
10408 | MemDOWN.prototype._batch = function (array, options, callback) {
|
10409 | var i = -1
|
10410 | , key
|
10411 | , value
|
10412 | , iter
|
10413 | , len = array.length
|
10414 | , tree = this._store[this._location]
|
10415 |
|
10416 | while (++i < len) {
|
10417 | if (!array[i])
|
10418 | continue
|
10419 |
|
10420 | key = this._isBuffer(array[i].key) ? array[i].key : String(array[i].key)
|
10421 | iter = tree.find(key)
|
10422 |
|
10423 | if (array[i].type === 'put') {
|
10424 | value = this._isBuffer(array[i].value) ? array[i].value : String(array[i].value)
|
10425 | tree = iter.valid ? iter.update(value) : tree.insert(key, value)
|
10426 | } else {
|
10427 | tree = iter.remove()
|
10428 | }
|
10429 | }
|
10430 |
|
10431 | this._store[this._location] = tree
|
10432 |
|
10433 | setImmediate(callback)
|
10434 | }
|
10435 |
|
10436 | MemDOWN.prototype._iterator = function (options) {
|
10437 | return new MemIterator(this, options)
|
10438 | }
|
10439 |
|
10440 | MemDOWN.prototype._isBuffer = function (obj) {
|
10441 | return Buffer.isBuffer(obj)
|
10442 | }
|
10443 |
|
10444 | MemDOWN.destroy = function (name, callback) {
|
10445 | var key = '$' + name
|
10446 |
|
10447 | if (key in globalStore)
|
10448 | delete globalStore[key]
|
10449 |
|
10450 | setImmediate(callback)
|
10451 | }
|
10452 |
|
10453 | module.exports = MemDOWN
|
10454 |
|
10455 | }).call(this,_dereq_(9).Buffer)
|
10456 | },{"15":15,"18":18,"53":53,"58":58,"66":66,"9":9}],55:[function(_dereq_,module,exports){
|
10457 | (function (process){
|
10458 |
|
10459 |
|
10460 | function AbstractChainedBatch (db) {
|
10461 | this._db = db
|
10462 | this._operations = []
|
10463 | this._written = false
|
10464 | }
|
10465 |
|
10466 | AbstractChainedBatch.prototype._checkWritten = function () {
|
10467 | if (this._written)
|
10468 | throw new Error('write() already called on this batch')
|
10469 | }
|
10470 |
|
10471 | AbstractChainedBatch.prototype.put = function (key, value) {
|
10472 | this._checkWritten()
|
10473 |
|
10474 | var err = this._db._checkKey(key, 'key', this._db._isBuffer)
|
10475 | if (err)
|
10476 | throw err
|
10477 |
|
10478 | if (!this._db._isBuffer(key)) key = String(key)
|
10479 | if (!this._db._isBuffer(value)) value = String(value)
|
10480 |
|
10481 | if (typeof this._put == 'function' )
|
10482 | this._put(key, value)
|
10483 | else
|
10484 | this._operations.push({ type: 'put', key: key, value: value })
|
10485 |
|
10486 | return this
|
10487 | }
|
10488 |
|
10489 | AbstractChainedBatch.prototype.del = function (key) {
|
10490 | this._checkWritten()
|
10491 |
|
10492 | var err = this._db._checkKey(key, 'key', this._db._isBuffer)
|
10493 | if (err) throw err
|
10494 |
|
10495 | if (!this._db._isBuffer(key)) key = String(key)
|
10496 |
|
10497 | if (typeof this._del == 'function' )
|
10498 | this._del(key)
|
10499 | else
|
10500 | this._operations.push({ type: 'del', key: key })
|
10501 |
|
10502 | return this
|
10503 | }
|
10504 |
|
10505 | AbstractChainedBatch.prototype.clear = function () {
|
10506 | this._checkWritten()
|
10507 |
|
10508 | this._operations = []
|
10509 |
|
10510 | if (typeof this._clear == 'function' )
|
10511 | this._clear()
|
10512 |
|
10513 | return this
|
10514 | }
|
10515 |
|
10516 | AbstractChainedBatch.prototype.write = function (options, callback) {
|
10517 | this._checkWritten()
|
10518 |
|
10519 | if (typeof options == 'function')
|
10520 | callback = options
|
10521 | if (typeof callback != 'function')
|
10522 | throw new Error('write() requires a callback argument')
|
10523 | if (typeof options != 'object')
|
10524 | options = {}
|
10525 |
|
10526 | this._written = true
|
10527 |
|
10528 | if (typeof this._write == 'function' )
|
10529 | return this._write(callback)
|
10530 |
|
10531 | if (typeof this._db._batch == 'function')
|
10532 | return this._db._batch(this._operations, options, callback)
|
10533 |
|
10534 | process.nextTick(callback)
|
10535 | }
|
10536 |
|
10537 | module.exports = AbstractChainedBatch
|
10538 | }).call(this,_dereq_(70))
|
10539 | },{"70":70}],56:[function(_dereq_,module,exports){
|
10540 | (function (process){
|
10541 |
|
10542 |
|
10543 | function AbstractIterator (db) {
|
10544 | this.db = db
|
10545 | this._ended = false
|
10546 | this._nexting = false
|
10547 | }
|
10548 |
|
10549 | AbstractIterator.prototype.next = function (callback) {
|
10550 | var self = this
|
10551 |
|
10552 | if (typeof callback != 'function')
|
10553 | throw new Error('next() requires a callback argument')
|
10554 |
|
10555 | if (self._ended)
|
10556 | return callback(new Error('cannot call next() after end()'))
|
10557 | if (self._nexting)
|
10558 | return callback(new Error('cannot call next() before previous next() has completed'))
|
10559 |
|
10560 | self._nexting = true
|
10561 | if (typeof self._next == 'function') {
|
10562 | return self._next(function () {
|
10563 | self._nexting = false
|
10564 | callback.apply(null, arguments)
|
10565 | })
|
10566 | }
|
10567 |
|
10568 | process.nextTick(function () {
|
10569 | self._nexting = false
|
10570 | callback()
|
10571 | })
|
10572 | }
|
10573 |
|
10574 | AbstractIterator.prototype.end = function (callback) {
|
10575 | if (typeof callback != 'function')
|
10576 | throw new Error('end() requires a callback argument')
|
10577 |
|
10578 | if (this._ended)
|
10579 | return callback(new Error('end() already called on iterator'))
|
10580 |
|
10581 | this._ended = true
|
10582 |
|
10583 | if (typeof this._end == 'function')
|
10584 | return this._end(callback)
|
10585 |
|
10586 | process.nextTick(callback)
|
10587 | }
|
10588 |
|
10589 | module.exports = AbstractIterator
|
10590 |
|
10591 | }).call(this,_dereq_(70))
|
10592 | },{"70":70}],57:[function(_dereq_,module,exports){
|
10593 | (function (Buffer,process){
|
10594 |
|
10595 |
|
10596 | var xtend = _dereq_(67)
|
10597 | , AbstractIterator = _dereq_(56)
|
10598 | , AbstractChainedBatch = _dereq_(55)
|
10599 |
|
10600 | function AbstractLevelDOWN (location) {
|
10601 | if (!arguments.length || location === undefined)
|
10602 | throw new Error('constructor requires at least a location argument')
|
10603 |
|
10604 | if (typeof location != 'string')
|
10605 | throw new Error('constructor requires a location string argument')
|
10606 |
|
10607 | this.location = location
|
10608 | this.status = 'new'
|
10609 | }
|
10610 |
|
10611 | AbstractLevelDOWN.prototype.open = function (options, callback) {
|
10612 | var self = this
|
10613 | , oldStatus = this.status
|
10614 |
|
10615 | if (typeof options == 'function')
|
10616 | callback = options
|
10617 |
|
10618 | if (typeof callback != 'function')
|
10619 | throw new Error('open() requires a callback argument')
|
10620 |
|
10621 | if (typeof options != 'object')
|
10622 | options = {}
|
10623 |
|
10624 | options.createIfMissing = options.createIfMissing != false
|
10625 | options.errorIfExists = !!options.errorIfExists
|
10626 |
|
10627 | if (typeof this._open == 'function') {
|
10628 | this.status = 'opening'
|
10629 | this._open(options, function (err) {
|
10630 | if (err) {
|
10631 | self.status = oldStatus
|
10632 | return callback(err)
|
10633 | }
|
10634 | self.status = 'open'
|
10635 | callback()
|
10636 | })
|
10637 | } else {
|
10638 | this.status = 'open'
|
10639 | process.nextTick(callback)
|
10640 | }
|
10641 | }
|
10642 |
|
10643 | AbstractLevelDOWN.prototype.close = function (callback) {
|
10644 | var self = this
|
10645 | , oldStatus = this.status
|
10646 |
|
10647 | if (typeof callback != 'function')
|
10648 | throw new Error('close() requires a callback argument')
|
10649 |
|
10650 | if (typeof this._close == 'function') {
|
10651 | this.status = 'closing'
|
10652 | this._close(function (err) {
|
10653 | if (err) {
|
10654 | self.status = oldStatus
|
10655 | return callback(err)
|
10656 | }
|
10657 | self.status = 'closed'
|
10658 | callback()
|
10659 | })
|
10660 | } else {
|
10661 | this.status = 'closed'
|
10662 | process.nextTick(callback)
|
10663 | }
|
10664 | }
|
10665 |
|
10666 | AbstractLevelDOWN.prototype.get = function (key, options, callback) {
|
10667 | var err
|
10668 |
|
10669 | if (typeof options == 'function')
|
10670 | callback = options
|
10671 |
|
10672 | if (typeof callback != 'function')
|
10673 | throw new Error('get() requires a callback argument')
|
10674 |
|
10675 | if (err = this._checkKey(key, 'key', this._isBuffer))
|
10676 | return callback(err)
|
10677 |
|
10678 | if (!this._isBuffer(key))
|
10679 | key = String(key)
|
10680 |
|
10681 | if (typeof options != 'object')
|
10682 | options = {}
|
10683 |
|
10684 | options.asBuffer = options.asBuffer != false
|
10685 |
|
10686 | if (typeof this._get == 'function')
|
10687 | return this._get(key, options, callback)
|
10688 |
|
10689 | process.nextTick(function () { callback(new Error('NotFound')) })
|
10690 | }
|
10691 |
|
10692 | AbstractLevelDOWN.prototype.put = function (key, value, options, callback) {
|
10693 | var err
|
10694 |
|
10695 | if (typeof options == 'function')
|
10696 | callback = options
|
10697 |
|
10698 | if (typeof callback != 'function')
|
10699 | throw new Error('put() requires a callback argument')
|
10700 |
|
10701 | if (err = this._checkKey(key, 'key', this._isBuffer))
|
10702 | return callback(err)
|
10703 |
|
10704 | if (!this._isBuffer(key))
|
10705 | key = String(key)
|
10706 |
|
10707 |
|
10708 |
|
10709 | if (value != null && !this._isBuffer(value) && !process.browser)
|
10710 | value = String(value)
|
10711 |
|
10712 | if (typeof options != 'object')
|
10713 | options = {}
|
10714 |
|
10715 | if (typeof this._put == 'function')
|
10716 | return this._put(key, value, options, callback)
|
10717 |
|
10718 | process.nextTick(callback)
|
10719 | }
|
10720 |
|
10721 | AbstractLevelDOWN.prototype.del = function (key, options, callback) {
|
10722 | var err
|
10723 |
|
10724 | if (typeof options == 'function')
|
10725 | callback = options
|
10726 |
|
10727 | if (typeof callback != 'function')
|
10728 | throw new Error('del() requires a callback argument')
|
10729 |
|
10730 | if (err = this._checkKey(key, 'key', this._isBuffer))
|
10731 | return callback(err)
|
10732 |
|
10733 | if (!this._isBuffer(key))
|
10734 | key = String(key)
|
10735 |
|
10736 | if (typeof options != 'object')
|
10737 | options = {}
|
10738 |
|
10739 | if (typeof this._del == 'function')
|
10740 | return this._del(key, options, callback)
|
10741 |
|
10742 | process.nextTick(callback)
|
10743 | }
|
10744 |
|
10745 | AbstractLevelDOWN.prototype.batch = function (array, options, callback) {
|
10746 | if (!arguments.length)
|
10747 | return this._chainedBatch()
|
10748 |
|
10749 | if (typeof options == 'function')
|
10750 | callback = options
|
10751 |
|
10752 | if (typeof array == 'function')
|
10753 | callback = array
|
10754 |
|
10755 | if (typeof callback != 'function')
|
10756 | throw new Error('batch(array) requires a callback argument')
|
10757 |
|
10758 | if (!Array.isArray(array))
|
10759 | return callback(new Error('batch(array) requires an array argument'))
|
10760 |
|
10761 | if (!options || typeof options != 'object')
|
10762 | options = {}
|
10763 |
|
10764 | var i = 0
|
10765 | , l = array.length
|
10766 | , e
|
10767 | , err
|
10768 |
|
10769 | for (; i < l; i++) {
|
10770 | e = array[i]
|
10771 | if (typeof e != 'object')
|
10772 | continue
|
10773 |
|
10774 | if (err = this._checkKey(e.type, 'type', this._isBuffer))
|
10775 | return callback(err)
|
10776 |
|
10777 | if (err = this._checkKey(e.key, 'key', this._isBuffer))
|
10778 | return callback(err)
|
10779 | }
|
10780 |
|
10781 | if (typeof this._batch == 'function')
|
10782 | return this._batch(array, options, callback)
|
10783 |
|
10784 | process.nextTick(callback)
|
10785 | }
|
10786 |
|
10787 |
|
10788 | AbstractLevelDOWN.prototype.approximateSize = function (start, end, callback) {
|
10789 | if ( start == null
|
10790 | || end == null
|
10791 | || typeof start == 'function'
|
10792 | || typeof end == 'function') {
|
10793 | throw new Error('approximateSize() requires valid `start`, `end` and `callback` arguments')
|
10794 | }
|
10795 |
|
10796 | if (typeof callback != 'function')
|
10797 | throw new Error('approximateSize() requires a callback argument')
|
10798 |
|
10799 | if (!this._isBuffer(start))
|
10800 | start = String(start)
|
10801 |
|
10802 | if (!this._isBuffer(end))
|
10803 | end = String(end)
|
10804 |
|
10805 | if (typeof this._approximateSize == 'function')
|
10806 | return this._approximateSize(start, end, callback)
|
10807 |
|
10808 | process.nextTick(function () {
|
10809 | callback(null, 0)
|
10810 | })
|
10811 | }
|
10812 |
|
10813 | AbstractLevelDOWN.prototype._setupIteratorOptions = function (options) {
|
10814 | var self = this
|
10815 |
|
10816 | options = xtend(options)
|
10817 |
|
10818 | ;[ 'start', 'end', 'gt', 'gte', 'lt', 'lte' ].forEach(function (o) {
|
10819 | if (options[o] && self._isBuffer(options[o]) && options[o].length === 0)
|
10820 | delete options[o]
|
10821 | })
|
10822 |
|
10823 | options.reverse = !!options.reverse
|
10824 | options.keys = options.keys != false
|
10825 | options.values = options.values != false
|
10826 | options.limit = 'limit' in options ? options.limit : -1
|
10827 | options.keyAsBuffer = options.keyAsBuffer != false
|
10828 | options.valueAsBuffer = options.valueAsBuffer != false
|
10829 |
|
10830 | return options
|
10831 | }
|
10832 |
|
10833 | AbstractLevelDOWN.prototype.iterator = function (options) {
|
10834 | if (typeof options != 'object')
|
10835 | options = {}
|
10836 |
|
10837 | options = this._setupIteratorOptions(options)
|
10838 |
|
10839 | if (typeof this._iterator == 'function')
|
10840 | return this._iterator(options)
|
10841 |
|
10842 | return new AbstractIterator(this)
|
10843 | }
|
10844 |
|
10845 | AbstractLevelDOWN.prototype._chainedBatch = function () {
|
10846 | return new AbstractChainedBatch(this)
|
10847 | }
|
10848 |
|
10849 | AbstractLevelDOWN.prototype._isBuffer = function (obj) {
|
10850 | return Buffer.isBuffer(obj)
|
10851 | }
|
10852 |
|
10853 | AbstractLevelDOWN.prototype._checkKey = function (obj, type) {
|
10854 |
|
10855 | if (obj === null || obj === undefined)
|
10856 | return new Error(type + ' cannot be `null` or `undefined`')
|
10857 |
|
10858 | if (this._isBuffer(obj)) {
|
10859 | if (obj.length === 0)
|
10860 | return new Error(type + ' cannot be an empty Buffer')
|
10861 | } else if (String(obj) === '')
|
10862 | return new Error(type + ' cannot be an empty String')
|
10863 | }
|
10864 |
|
10865 | module.exports = AbstractLevelDOWN
|
10866 |
|
10867 | }).call(this,{"isBuffer":_dereq_(19)},_dereq_(70))
|
10868 | },{"19":19,"55":55,"56":56,"67":67,"70":70}],58:[function(_dereq_,module,exports){
|
10869 | exports.AbstractLevelDOWN = _dereq_(57)
|
10870 | exports.AbstractIterator = _dereq_(56)
|
10871 | exports.AbstractChainedBatch = _dereq_(55)
|
10872 | exports.isLevelDOWN = _dereq_(59)
|
10873 |
|
10874 | },{"55":55,"56":56,"57":57,"59":59}],59:[function(_dereq_,module,exports){
|
10875 | var AbstractLevelDOWN = _dereq_(57)
|
10876 |
|
10877 | function isLevelDOWN (db) {
|
10878 | if (!db || typeof db !== 'object')
|
10879 | return false
|
10880 | return Object.keys(AbstractLevelDOWN.prototype).filter(function (name) {
|
10881 |
|
10882 | return name[0] != '_' && name != 'approximateSize'
|
10883 | }).every(function (name) {
|
10884 | return typeof db[name] == 'function'
|
10885 | })
|
10886 | }
|
10887 |
|
10888 | module.exports = isLevelDOWN
|
10889 |
|
10890 | },{"57":57}],60:[function(_dereq_,module,exports){
|
10891 | 'use strict';
|
10892 | var types = [
|
10893 | _dereq_(63),
|
10894 | _dereq_(62),
|
10895 | _dereq_(61),
|
10896 | _dereq_(64),
|
10897 | _dereq_(65)
|
10898 | ];
|
10899 | var draining;
|
10900 | var currentQueue;
|
10901 | var queueIndex = -1;
|
10902 | var queue = [];
|
10903 | var scheduled = false;
|
10904 | function cleanUpNextTick() {
|
10905 | if (!draining || !currentQueue) {
|
10906 | return;
|
10907 | }
|
10908 | draining = false;
|
10909 | if (currentQueue.length) {
|
10910 | queue = currentQueue.concat(queue);
|
10911 | } else {
|
10912 | queueIndex = -1;
|
10913 | }
|
10914 | if (queue.length) {
|
10915 | nextTick();
|
10916 | }
|
10917 | }
|
10918 |
|
10919 |
|
10920 | function nextTick() {
|
10921 | if (draining) {
|
10922 | return;
|
10923 | }
|
10924 | scheduled = false;
|
10925 | draining = true;
|
10926 | var len = queue.length;
|
10927 | var timeout = setTimeout(cleanUpNextTick);
|
10928 | while (len) {
|
10929 | currentQueue = queue;
|
10930 | queue = [];
|
10931 | while (currentQueue && ++queueIndex < len) {
|
10932 | currentQueue[queueIndex].run();
|
10933 | }
|
10934 | queueIndex = -1;
|
10935 | len = queue.length;
|
10936 | }
|
10937 | currentQueue = null;
|
10938 | queueIndex = -1;
|
10939 | draining = false;
|
10940 | clearTimeout(timeout);
|
10941 | }
|
10942 | var scheduleDrain;
|
10943 | var i = -1;
|
10944 | var len = types.length;
|
10945 | while (++i < len) {
|
10946 | if (types[i] && types[i].test && types[i].test()) {
|
10947 | scheduleDrain = types[i].install(nextTick);
|
10948 | break;
|
10949 | }
|
10950 | }
|
10951 |
|
10952 | function Item(fun, array) {
|
10953 | this.fun = fun;
|
10954 | this.array = array;
|
10955 | }
|
10956 | Item.prototype.run = function () {
|
10957 | var fun = this.fun;
|
10958 | var array = this.array;
|
10959 | switch (array.length) {
|
10960 | case 0:
|
10961 | return fun();
|
10962 | case 1:
|
10963 | return fun(array[0]);
|
10964 | case 2:
|
10965 | return fun(array[0], array[1]);
|
10966 | case 3:
|
10967 | return fun(array[0], array[1], array[2]);
|
10968 | default:
|
10969 | return fun.apply(null, array);
|
10970 | }
|
10971 |
|
10972 | };
|
10973 | module.exports = immediate;
|
10974 | function immediate(task) {
|
10975 | var args = new Array(arguments.length - 1);
|
10976 | if (arguments.length > 1) {
|
10977 | for (var i = 1; i < arguments.length; i++) {
|
10978 | args[i - 1] = arguments[i];
|
10979 | }
|
10980 | }
|
10981 | queue.push(new Item(task, args));
|
10982 | if (!scheduled && !draining) {
|
10983 | scheduled = true;
|
10984 | scheduleDrain();
|
10985 | }
|
10986 | }
|
10987 |
|
10988 | },{"61":61,"62":62,"63":63,"64":64,"65":65}],61:[function(_dereq_,module,exports){
|
10989 | (function (global){
|
10990 | 'use strict';
|
10991 |
|
10992 | exports.test = function () {
|
10993 | if (global.setImmediate) {
|
10994 |
|
10995 |
|
10996 | return false;
|
10997 | }
|
10998 | return typeof global.MessageChannel !== 'undefined';
|
10999 | };
|
11000 |
|
11001 | exports.install = function (func) {
|
11002 | var channel = new global.MessageChannel();
|
11003 | channel.port1.onmessage = func;
|
11004 | return function () {
|
11005 | channel.port2.postMessage(0);
|
11006 | };
|
11007 | };
|
11008 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
11009 | },{}],62:[function(_dereq_,module,exports){
|
11010 | (function (global){
|
11011 | 'use strict';
|
11012 |
|
11013 |
|
11014 |
|
11015 |
|
11016 | var Mutation = global.MutationObserver || global.WebKitMutationObserver;
|
11017 |
|
11018 | exports.test = function () {
|
11019 | return Mutation;
|
11020 | };
|
11021 |
|
11022 | exports.install = function (handle) {
|
11023 | var called = 0;
|
11024 | var observer = new Mutation(handle);
|
11025 | var element = global.document.createTextNode('');
|
11026 | observer.observe(element, {
|
11027 | characterData: true
|
11028 | });
|
11029 | return function () {
|
11030 | element.data = (called = ++called % 2);
|
11031 | };
|
11032 | };
|
11033 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
11034 | },{}],63:[function(_dereq_,module,exports){
|
11035 | (function (process){
|
11036 | 'use strict';
|
11037 | exports.test = function () {
|
11038 |
|
11039 | return (typeof process !== 'undefined') && !process.browser;
|
11040 | };
|
11041 |
|
11042 | exports.install = function (func) {
|
11043 | return function () {
|
11044 | process.nextTick(func);
|
11045 | };
|
11046 | };
|
11047 |
|
11048 | }).call(this,_dereq_(70))
|
11049 | },{"70":70}],64:[function(_dereq_,module,exports){
|
11050 | (function (global){
|
11051 | 'use strict';
|
11052 |
|
11053 | exports.test = function () {
|
11054 | return 'document' in global && 'onreadystatechange' in global.document.createElement('script');
|
11055 | };
|
11056 |
|
11057 | exports.install = function (handle) {
|
11058 | return function () {
|
11059 |
|
11060 |
|
11061 |
|
11062 | var scriptEl = global.document.createElement('script');
|
11063 | scriptEl.onreadystatechange = function () {
|
11064 | handle();
|
11065 |
|
11066 | scriptEl.onreadystatechange = null;
|
11067 | scriptEl.parentNode.removeChild(scriptEl);
|
11068 | scriptEl = null;
|
11069 | };
|
11070 | global.document.documentElement.appendChild(scriptEl);
|
11071 |
|
11072 | return handle;
|
11073 | };
|
11074 | };
|
11075 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
11076 | },{}],65:[function(_dereq_,module,exports){
|
11077 | 'use strict';
|
11078 | exports.test = function () {
|
11079 | return true;
|
11080 | };
|
11081 |
|
11082 | exports.install = function (t) {
|
11083 | return function () {
|
11084 | setTimeout(t, 0);
|
11085 | };
|
11086 | };
|
11087 | },{}],66:[function(_dereq_,module,exports){
|
11088 | (function (Buffer){
|
11089 |
|
11090 | exports.compare = function (a, b) {
|
11091 |
|
11092 | if(Buffer.isBuffer(a)) {
|
11093 | var l = Math.min(a.length, b.length)
|
11094 | for(var i = 0; i < l; i++) {
|
11095 | var cmp = a[i] - b[i]
|
11096 | if(cmp) return cmp
|
11097 | }
|
11098 | return a.length - b.length
|
11099 | }
|
11100 |
|
11101 | return a < b ? -1 : a > b ? 1 : 0
|
11102 | }
|
11103 |
|
11104 | function has(obj, key) {
|
11105 | return Object.hasOwnProperty.call(obj, key)
|
11106 | }
|
11107 |
|
11108 |
|
11109 |
|
11110 |
|
11111 |
|
11112 |
|
11113 | function isDef (val) {
|
11114 | return val !== undefined && val !== ''
|
11115 | }
|
11116 |
|
11117 | function has (range, name) {
|
11118 | return Object.hasOwnProperty.call(range, name)
|
11119 | }
|
11120 |
|
11121 | function hasKey(range, name) {
|
11122 | return Object.hasOwnProperty.call(range, name) && name
|
11123 | }
|
11124 |
|
11125 | var lowerBoundKey = exports.lowerBoundKey = function (range) {
|
11126 | return (
|
11127 | hasKey(range, 'gt')
|
11128 | || hasKey(range, 'gte')
|
11129 | || hasKey(range, 'min')
|
11130 | || (range.reverse ? hasKey(range, 'end') : hasKey(range, 'start'))
|
11131 | || undefined
|
11132 | )
|
11133 | }
|
11134 |
|
11135 | var lowerBound = exports.lowerBound = function (range) {
|
11136 | var k = lowerBoundKey(range)
|
11137 | return k && range[k]
|
11138 | }
|
11139 |
|
11140 | var lowerBoundInclusive = exports.lowerBoundInclusive = function (range) {
|
11141 | return has(range, 'gt') ? false : true
|
11142 | }
|
11143 |
|
11144 | var upperBoundInclusive = exports.upperBoundInclusive =
|
11145 | function (range) {
|
11146 | return (has(range, 'lt') ) ? false : true
|
11147 | }
|
11148 |
|
11149 | var lowerBoundExclusive = exports.lowerBoundExclusive =
|
11150 | function (range) {
|
11151 | return !lowerBoundInclusive(range)
|
11152 | }
|
11153 |
|
11154 | var upperBoundExclusive = exports.upperBoundExclusive =
|
11155 | function (range) {
|
11156 | return !upperBoundInclusive(range)
|
11157 | }
|
11158 |
|
11159 | var upperBoundKey = exports.upperBoundKey = function (range) {
|
11160 | return (
|
11161 | hasKey(range, 'lt')
|
11162 | || hasKey(range, 'lte')
|
11163 | || hasKey(range, 'max')
|
11164 | || (range.reverse ? hasKey(range, 'start') : hasKey(range, 'end'))
|
11165 | || undefined
|
11166 | )
|
11167 | }
|
11168 |
|
11169 | var upperBound = exports.upperBound = function (range) {
|
11170 | var k = upperBoundKey(range)
|
11171 | return k && range[k]
|
11172 | }
|
11173 |
|
11174 | function id (e) { return e }
|
11175 |
|
11176 | exports.toLtgt = function (range, _range, map, lower, upper) {
|
11177 | _range = _range || {}
|
11178 | map = map || id
|
11179 | var defaults = arguments.length > 3
|
11180 | var lb = exports.lowerBoundKey(range)
|
11181 | var ub = exports.upperBoundKey(range)
|
11182 | if(lb) {
|
11183 | if(lb === 'gt') _range.gt = map(range.gt, false)
|
11184 | else _range.gte = map(range[lb], false)
|
11185 | }
|
11186 | else if(defaults)
|
11187 | _range.gte = map(lower, false)
|
11188 |
|
11189 | if(ub) {
|
11190 | if(ub === 'lt') _range.lt = map(range.lt, true)
|
11191 | else _range.lte = map(range[ub], true)
|
11192 | }
|
11193 | else if(defaults)
|
11194 | _range.lte = map(upper, true)
|
11195 |
|
11196 | if(range.reverse != null)
|
11197 | _range.reverse = !!range.reverse
|
11198 |
|
11199 |
|
11200 |
|
11201 |
|
11202 | if(has(_range, 'max')) delete _range.max
|
11203 | if(has(_range, 'min')) delete _range.min
|
11204 | if(has(_range, 'start')) delete _range.start
|
11205 | if(has(_range, 'end')) delete _range.end
|
11206 |
|
11207 | return _range
|
11208 | }
|
11209 |
|
11210 | exports.contains = function (range, key, compare) {
|
11211 | compare = compare || exports.compare
|
11212 |
|
11213 | var lb = lowerBound(range)
|
11214 | if(isDef(lb)) {
|
11215 | var cmp = compare(key, lb)
|
11216 | if(cmp < 0 || (cmp === 0 && lowerBoundExclusive(range)))
|
11217 | return false
|
11218 | }
|
11219 |
|
11220 | var ub = upperBound(range)
|
11221 | if(isDef(ub)) {
|
11222 | var cmp = compare(key, ub)
|
11223 | if(cmp > 0 || (cmp === 0) && upperBoundExclusive(range))
|
11224 | return false
|
11225 | }
|
11226 |
|
11227 | return true
|
11228 | }
|
11229 |
|
11230 | exports.filter = function (range, compare) {
|
11231 | return function (key) {
|
11232 | return exports.contains(range, key, compare)
|
11233 | }
|
11234 | }
|
11235 |
|
11236 |
|
11237 |
|
11238 |
|
11239 |
|
11240 |
|
11241 | }).call(this,{"isBuffer":_dereq_(19)})
|
11242 | },{"19":19}],67:[function(_dereq_,module,exports){
|
11243 | arguments[4][40][0].apply(exports,arguments)
|
11244 | },{"40":40}],68:[function(_dereq_,module,exports){
|
11245 |
|
11246 |
|
11247 |
|
11248 |
|
11249 |
|
11250 |
|
11251 | 'use strict';
|
11252 |
|
11253 | var getOwnPropertySymbols = Object.getOwnPropertySymbols;
|
11254 | var hasOwnProperty = Object.prototype.hasOwnProperty;
|
11255 | var propIsEnumerable = Object.prototype.propertyIsEnumerable;
|
11256 |
|
11257 | function toObject(val) {
|
11258 | if (val === null || val === undefined) {
|
11259 | throw new TypeError('Object.assign cannot be called with null or undefined');
|
11260 | }
|
11261 |
|
11262 | return Object(val);
|
11263 | }
|
11264 |
|
11265 | function shouldUseNative() {
|
11266 | try {
|
11267 | if (!Object.assign) {
|
11268 | return false;
|
11269 | }
|
11270 |
|
11271 |
|
11272 |
|
11273 |
|
11274 | var test1 = new String('abc');
|
11275 | test1[5] = 'de';
|
11276 | if (Object.getOwnPropertyNames(test1)[0] === '5') {
|
11277 | return false;
|
11278 | }
|
11279 |
|
11280 |
|
11281 | var test2 = {};
|
11282 | for (var i = 0; i < 10; i++) {
|
11283 | test2['_' + String.fromCharCode(i)] = i;
|
11284 | }
|
11285 | var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
|
11286 | return test2[n];
|
11287 | });
|
11288 | if (order2.join('') !== '0123456789') {
|
11289 | return false;
|
11290 | }
|
11291 |
|
11292 |
|
11293 | var test3 = {};
|
11294 | 'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
|
11295 | test3[letter] = letter;
|
11296 | });
|
11297 | if (Object.keys(Object.assign({}, test3)).join('') !==
|
11298 | 'abcdefghijklmnopqrst') {
|
11299 | return false;
|
11300 | }
|
11301 |
|
11302 | return true;
|
11303 | } catch (err) {
|
11304 |
|
11305 | return false;
|
11306 | }
|
11307 | }
|
11308 |
|
11309 | module.exports = shouldUseNative() ? Object.assign : function (target, source) {
|
11310 | var from;
|
11311 | var to = toObject(target);
|
11312 | var symbols;
|
11313 |
|
11314 | for (var s = 1; s < arguments.length; s++) {
|
11315 | from = Object(arguments[s]);
|
11316 |
|
11317 | for (var key in from) {
|
11318 | if (hasOwnProperty.call(from, key)) {
|
11319 | to[key] = from[key];
|
11320 | }
|
11321 | }
|
11322 |
|
11323 | if (getOwnPropertySymbols) {
|
11324 | symbols = getOwnPropertySymbols(from);
|
11325 | for (var i = 0; i < symbols.length; i++) {
|
11326 | if (propIsEnumerable.call(from, symbols[i])) {
|
11327 | to[symbols[i]] = from[symbols[i]];
|
11328 | }
|
11329 | }
|
11330 | }
|
11331 | }
|
11332 |
|
11333 | return to;
|
11334 | };
|
11335 |
|
11336 | },{}],69:[function(_dereq_,module,exports){
|
11337 | (function (process){
|
11338 | 'use strict';
|
11339 |
|
11340 | if (typeof process === 'undefined' ||
|
11341 | !process.version ||
|
11342 | process.version.indexOf('v0.') === 0 ||
|
11343 | process.version.indexOf('v1.') === 0 && process.version.indexOf('v1.8.') !== 0) {
|
11344 | module.exports = { nextTick: nextTick };
|
11345 | } else {
|
11346 | module.exports = process
|
11347 | }
|
11348 |
|
11349 | function nextTick(fn, arg1, arg2, arg3) {
|
11350 | if (typeof fn !== 'function') {
|
11351 | throw new TypeError('"callback" argument must be a function');
|
11352 | }
|
11353 | var len = arguments.length;
|
11354 | var args, i;
|
11355 | switch (len) {
|
11356 | case 0:
|
11357 | case 1:
|
11358 | return process.nextTick(fn);
|
11359 | case 2:
|
11360 | return process.nextTick(function afterTickOne() {
|
11361 | fn.call(null, arg1);
|
11362 | });
|
11363 | case 3:
|
11364 | return process.nextTick(function afterTickTwo() {
|
11365 | fn.call(null, arg1, arg2);
|
11366 | });
|
11367 | case 4:
|
11368 | return process.nextTick(function afterTickThree() {
|
11369 | fn.call(null, arg1, arg2, arg3);
|
11370 | });
|
11371 | default:
|
11372 | args = new Array(len - 1);
|
11373 | i = 0;
|
11374 | while (i < args.length) {
|
11375 | args[i++] = arguments[i];
|
11376 | }
|
11377 | return process.nextTick(function afterTick() {
|
11378 | fn.apply(null, args);
|
11379 | });
|
11380 | }
|
11381 | }
|
11382 |
|
11383 |
|
11384 | }).call(this,_dereq_(70))
|
11385 | },{"70":70}],70:[function(_dereq_,module,exports){
|
11386 |
|
11387 | var process = module.exports = {};
|
11388 |
|
11389 |
|
11390 |
|
11391 |
|
11392 |
|
11393 |
|
11394 | var cachedSetTimeout;
|
11395 | var cachedClearTimeout;
|
11396 |
|
11397 | function defaultSetTimout() {
|
11398 | throw new Error('setTimeout has not been defined');
|
11399 | }
|
11400 | function defaultClearTimeout () {
|
11401 | throw new Error('clearTimeout has not been defined');
|
11402 | }
|
11403 | (function () {
|
11404 | try {
|
11405 | if (typeof setTimeout === 'function') {
|
11406 | cachedSetTimeout = setTimeout;
|
11407 | } else {
|
11408 | cachedSetTimeout = defaultSetTimout;
|
11409 | }
|
11410 | } catch (e) {
|
11411 | cachedSetTimeout = defaultSetTimout;
|
11412 | }
|
11413 | try {
|
11414 | if (typeof clearTimeout === 'function') {
|
11415 | cachedClearTimeout = clearTimeout;
|
11416 | } else {
|
11417 | cachedClearTimeout = defaultClearTimeout;
|
11418 | }
|
11419 | } catch (e) {
|
11420 | cachedClearTimeout = defaultClearTimeout;
|
11421 | }
|
11422 | } ())
|
11423 | function runTimeout(fun) {
|
11424 | if (cachedSetTimeout === setTimeout) {
|
11425 |
|
11426 | return setTimeout(fun, 0);
|
11427 | }
|
11428 |
|
11429 | if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
|
11430 | cachedSetTimeout = setTimeout;
|
11431 | return setTimeout(fun, 0);
|
11432 | }
|
11433 | try {
|
11434 |
|
11435 | return cachedSetTimeout(fun, 0);
|
11436 | } catch(e){
|
11437 | try {
|
11438 |
|
11439 | return cachedSetTimeout.call(null, fun, 0);
|
11440 | } catch(e){
|
11441 |
|
11442 | return cachedSetTimeout.call(this, fun, 0);
|
11443 | }
|
11444 | }
|
11445 |
|
11446 |
|
11447 | }
|
11448 | function runClearTimeout(marker) {
|
11449 | if (cachedClearTimeout === clearTimeout) {
|
11450 |
|
11451 | return clearTimeout(marker);
|
11452 | }
|
11453 |
|
11454 | if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
|
11455 | cachedClearTimeout = clearTimeout;
|
11456 | return clearTimeout(marker);
|
11457 | }
|
11458 | try {
|
11459 |
|
11460 | return cachedClearTimeout(marker);
|
11461 | } catch (e){
|
11462 | try {
|
11463 |
|
11464 | return cachedClearTimeout.call(null, marker);
|
11465 | } catch (e){
|
11466 |
|
11467 |
|
11468 | return cachedClearTimeout.call(this, marker);
|
11469 | }
|
11470 | }
|
11471 |
|
11472 |
|
11473 |
|
11474 | }
|
11475 | var queue = [];
|
11476 | var draining = false;
|
11477 | var currentQueue;
|
11478 | var queueIndex = -1;
|
11479 |
|
11480 | function cleanUpNextTick() {
|
11481 | if (!draining || !currentQueue) {
|
11482 | return;
|
11483 | }
|
11484 | draining = false;
|
11485 | if (currentQueue.length) {
|
11486 | queue = currentQueue.concat(queue);
|
11487 | } else {
|
11488 | queueIndex = -1;
|
11489 | }
|
11490 | if (queue.length) {
|
11491 | drainQueue();
|
11492 | }
|
11493 | }
|
11494 |
|
11495 | function drainQueue() {
|
11496 | if (draining) {
|
11497 | return;
|
11498 | }
|
11499 | var timeout = runTimeout(cleanUpNextTick);
|
11500 | draining = true;
|
11501 |
|
11502 | var len = queue.length;
|
11503 | while(len) {
|
11504 | currentQueue = queue;
|
11505 | queue = [];
|
11506 | while (++queueIndex < len) {
|
11507 | if (currentQueue) {
|
11508 | currentQueue[queueIndex].run();
|
11509 | }
|
11510 | }
|
11511 | queueIndex = -1;
|
11512 | len = queue.length;
|
11513 | }
|
11514 | currentQueue = null;
|
11515 | draining = false;
|
11516 | runClearTimeout(timeout);
|
11517 | }
|
11518 |
|
11519 | process.nextTick = function (fun) {
|
11520 | var args = new Array(arguments.length - 1);
|
11521 | if (arguments.length > 1) {
|
11522 | for (var i = 1; i < arguments.length; i++) {
|
11523 | args[i - 1] = arguments[i];
|
11524 | }
|
11525 | }
|
11526 | queue.push(new Item(fun, args));
|
11527 | if (queue.length === 1 && !draining) {
|
11528 | runTimeout(drainQueue);
|
11529 | }
|
11530 | };
|
11531 |
|
11532 |
|
11533 | function Item(fun, array) {
|
11534 | this.fun = fun;
|
11535 | this.array = array;
|
11536 | }
|
11537 | Item.prototype.run = function () {
|
11538 | this.fun.apply(null, this.array);
|
11539 | };
|
11540 | process.title = 'browser';
|
11541 | process.browser = true;
|
11542 | process.env = {};
|
11543 | process.argv = [];
|
11544 | process.version = '';
|
11545 | process.versions = {};
|
11546 |
|
11547 | function noop() {}
|
11548 |
|
11549 | process.on = noop;
|
11550 | process.addListener = noop;
|
11551 | process.once = noop;
|
11552 | process.off = noop;
|
11553 | process.removeListener = noop;
|
11554 | process.removeAllListeners = noop;
|
11555 | process.emit = noop;
|
11556 | process.prependListener = noop;
|
11557 | process.prependOnceListener = noop;
|
11558 |
|
11559 | process.listeners = function (name) { return [] }
|
11560 |
|
11561 | process.binding = function (name) {
|
11562 | throw new Error('process.binding is not supported');
|
11563 | };
|
11564 |
|
11565 | process.cwd = function () { return '/' };
|
11566 | process.chdir = function (dir) {
|
11567 | throw new Error('process.chdir is not supported');
|
11568 | };
|
11569 | process.umask = function() { return 0; };
|
11570 |
|
11571 | },{}],71:[function(_dereq_,module,exports){
|
11572 |
|
11573 |
|
11574 |
|
11575 |
|
11576 |
|
11577 |
|
11578 |
|
11579 | (function (name, context, definition) {
|
11580 | if (typeof module != 'undefined' && module.exports)
|
11581 | module.exports = definition()
|
11582 | else
|
11583 | context[name] = definition()
|
11584 | })('prr', this, function() {
|
11585 |
|
11586 | var setProperty = typeof Object.defineProperty == 'function'
|
11587 | ? function (obj, key, options) {
|
11588 | Object.defineProperty(obj, key, options)
|
11589 | return obj
|
11590 | }
|
11591 | : function (obj, key, options) {
|
11592 | obj[key] = options.value
|
11593 | return obj
|
11594 | }
|
11595 |
|
11596 | , makeOptions = function (value, options) {
|
11597 | var oo = typeof options == 'object'
|
11598 | , os = !oo && typeof options == 'string'
|
11599 | , op = function (p) {
|
11600 | return oo
|
11601 | ? !!options[p]
|
11602 | : os
|
11603 | ? options.indexOf(p[0]) > -1
|
11604 | : false
|
11605 | }
|
11606 |
|
11607 | return {
|
11608 | enumerable : op('enumerable')
|
11609 | , configurable : op('configurable')
|
11610 | , writable : op('writable')
|
11611 | , value : value
|
11612 | }
|
11613 | }
|
11614 |
|
11615 | , prr = function (obj, key, value, options) {
|
11616 | var k
|
11617 |
|
11618 | options = makeOptions(value, options)
|
11619 |
|
11620 | if (typeof key == 'object') {
|
11621 | for (k in key) {
|
11622 | if (Object.hasOwnProperty.call(key, k)) {
|
11623 | options.value = key[k]
|
11624 | setProperty(obj, k, options)
|
11625 | }
|
11626 | }
|
11627 | return obj
|
11628 | }
|
11629 |
|
11630 | return setProperty(obj, key, options)
|
11631 | }
|
11632 |
|
11633 | return prr
|
11634 | })
|
11635 | },{}],72:[function(_dereq_,module,exports){
|
11636 | (function (process){
|
11637 |
|
11638 |
|
11639 |
|
11640 |
|
11641 |
|
11642 |
|
11643 |
|
11644 |
|
11645 |
|
11646 |
|
11647 |
|
11648 |
|
11649 |
|
11650 |
|
11651 |
|
11652 |
|
11653 |
|
11654 |
|
11655 |
|
11656 |
|
11657 |
|
11658 |
|
11659 |
|
11660 |
|
11661 |
|
11662 |
|
11663 | module.exports = Duplex;
|
11664 |
|
11665 |
|
11666 | var objectKeys = Object.keys || function (obj) {
|
11667 | var keys = [];
|
11668 | for (var key in obj) keys.push(key);
|
11669 | return keys;
|
11670 | }
|
11671 |
|
11672 |
|
11673 |
|
11674 |
|
11675 | var util = _dereq_(10);
|
11676 | util.inherits = _dereq_(18);
|
11677 |
|
11678 |
|
11679 | var Readable = _dereq_(74);
|
11680 | var Writable = _dereq_(76);
|
11681 |
|
11682 | util.inherits(Duplex, Readable);
|
11683 |
|
11684 | forEach(objectKeys(Writable.prototype), function(method) {
|
11685 | if (!Duplex.prototype[method])
|
11686 | Duplex.prototype[method] = Writable.prototype[method];
|
11687 | });
|
11688 |
|
11689 | function Duplex(options) {
|
11690 | if (!(this instanceof Duplex))
|
11691 | return new Duplex(options);
|
11692 |
|
11693 | Readable.call(this, options);
|
11694 | Writable.call(this, options);
|
11695 |
|
11696 | if (options && options.readable === false)
|
11697 | this.readable = false;
|
11698 |
|
11699 | if (options && options.writable === false)
|
11700 | this.writable = false;
|
11701 |
|
11702 | this.allowHalfOpen = true;
|
11703 | if (options && options.allowHalfOpen === false)
|
11704 | this.allowHalfOpen = false;
|
11705 |
|
11706 | this.once('end', onend);
|
11707 | }
|
11708 |
|
11709 |
|
11710 | function onend() {
|
11711 |
|
11712 |
|
11713 | if (this.allowHalfOpen || this._writableState.ended)
|
11714 | return;
|
11715 |
|
11716 |
|
11717 |
|
11718 | process.nextTick(this.end.bind(this));
|
11719 | }
|
11720 |
|
11721 | function forEach (xs, f) {
|
11722 | for (var i = 0, l = xs.length; i < l; i++) {
|
11723 | f(xs[i], i);
|
11724 | }
|
11725 | }
|
11726 |
|
11727 | }).call(this,_dereq_(70))
|
11728 | },{"10":10,"18":18,"70":70,"74":74,"76":76}],73:[function(_dereq_,module,exports){
|
11729 |
|
11730 |
|
11731 |
|
11732 |
|
11733 |
|
11734 |
|
11735 |
|
11736 |
|
11737 |
|
11738 |
|
11739 |
|
11740 |
|
11741 |
|
11742 |
|
11743 |
|
11744 |
|
11745 |
|
11746 |
|
11747 |
|
11748 |
|
11749 |
|
11750 |
|
11751 |
|
11752 |
|
11753 |
|
11754 | module.exports = PassThrough;
|
11755 |
|
11756 | var Transform = _dereq_(75);
|
11757 |
|
11758 |
|
11759 | var util = _dereq_(10);
|
11760 | util.inherits = _dereq_(18);
|
11761 |
|
11762 |
|
11763 | util.inherits(PassThrough, Transform);
|
11764 |
|
11765 | function PassThrough(options) {
|
11766 | if (!(this instanceof PassThrough))
|
11767 | return new PassThrough(options);
|
11768 |
|
11769 | Transform.call(this, options);
|
11770 | }
|
11771 |
|
11772 | PassThrough.prototype._transform = function(chunk, encoding, cb) {
|
11773 | cb(null, chunk);
|
11774 | };
|
11775 |
|
11776 | },{"10":10,"18":18,"75":75}],74:[function(_dereq_,module,exports){
|
11777 | (function (process){
|
11778 |
|
11779 |
|
11780 |
|
11781 |
|
11782 |
|
11783 |
|
11784 |
|
11785 |
|
11786 |
|
11787 |
|
11788 |
|
11789 |
|
11790 |
|
11791 |
|
11792 |
|
11793 |
|
11794 |
|
11795 |
|
11796 |
|
11797 |
|
11798 |
|
11799 | module.exports = Readable;
|
11800 |
|
11801 |
|
11802 | var isArray = _dereq_(20);
|
11803 |
|
11804 |
|
11805 |
|
11806 |
|
11807 | var Buffer = _dereq_(9).Buffer;
|
11808 |
|
11809 |
|
11810 | Readable.ReadableState = ReadableState;
|
11811 |
|
11812 | var EE = _dereq_(14).EventEmitter;
|
11813 |
|
11814 |
|
11815 | if (!EE.listenerCount) EE.listenerCount = function(emitter, type) {
|
11816 | return emitter.listeners(type).length;
|
11817 | };
|
11818 |
|
11819 |
|
11820 | var Stream = _dereq_(81);
|
11821 |
|
11822 |
|
11823 | var util = _dereq_(10);
|
11824 | util.inherits = _dereq_(18);
|
11825 |
|
11826 |
|
11827 | var StringDecoder;
|
11828 |
|
11829 | util.inherits(Readable, Stream);
|
11830 |
|
11831 | function ReadableState(options, stream) {
|
11832 | options = options || {};
|
11833 |
|
11834 |
|
11835 |
|
11836 | var hwm = options.highWaterMark;
|
11837 | this.highWaterMark = (hwm || hwm === 0) ? hwm : 16 * 1024;
|
11838 |
|
11839 |
|
11840 | this.highWaterMark = ~~this.highWaterMark;
|
11841 |
|
11842 | this.buffer = [];
|
11843 | this.length = 0;
|
11844 | this.pipes = null;
|
11845 | this.pipesCount = 0;
|
11846 | this.flowing = false;
|
11847 | this.ended = false;
|
11848 | this.endEmitted = false;
|
11849 | this.reading = false;
|
11850 |
|
11851 |
|
11852 |
|
11853 |
|
11854 |
|
11855 | this.calledRead = false;
|
11856 |
|
11857 |
|
11858 |
|
11859 |
|
11860 |
|
11861 | this.sync = true;
|
11862 |
|
11863 |
|
11864 |
|
11865 | this.needReadable = false;
|
11866 | this.emittedReadable = false;
|
11867 | this.readableListening = false;
|
11868 |
|
11869 |
|
11870 |
|
11871 |
|
11872 | this.objectMode = !!options.objectMode;
|
11873 |
|
11874 |
|
11875 |
|
11876 |
|
11877 | this.defaultEncoding = options.defaultEncoding || 'utf8';
|
11878 |
|
11879 |
|
11880 |
|
11881 | this.ranOut = false;
|
11882 |
|
11883 |
|
11884 | this.awaitDrain = 0;
|
11885 |
|
11886 |
|
11887 | this.readingMore = false;
|
11888 |
|
11889 | this.decoder = null;
|
11890 | this.encoding = null;
|
11891 | if (options.encoding) {
|
11892 | if (!StringDecoder)
|
11893 | StringDecoder = _dereq_(77).StringDecoder;
|
11894 | this.decoder = new StringDecoder(options.encoding);
|
11895 | this.encoding = options.encoding;
|
11896 | }
|
11897 | }
|
11898 |
|
11899 | function Readable(options) {
|
11900 | if (!(this instanceof Readable))
|
11901 | return new Readable(options);
|
11902 |
|
11903 | this._readableState = new ReadableState(options, this);
|
11904 |
|
11905 |
|
11906 | this.readable = true;
|
11907 |
|
11908 | Stream.call(this);
|
11909 | }
|
11910 |
|
11911 |
|
11912 |
|
11913 |
|
11914 |
|
11915 | Readable.prototype.push = function(chunk, encoding) {
|
11916 | var state = this._readableState;
|
11917 |
|
11918 | if (typeof chunk === 'string' && !state.objectMode) {
|
11919 | encoding = encoding || state.defaultEncoding;
|
11920 | if (encoding !== state.encoding) {
|
11921 | chunk = new Buffer(chunk, encoding);
|
11922 | encoding = '';
|
11923 | }
|
11924 | }
|
11925 |
|
11926 | return readableAddChunk(this, state, chunk, encoding, false);
|
11927 | };
|
11928 |
|
11929 |
|
11930 | Readable.prototype.unshift = function(chunk) {
|
11931 | var state = this._readableState;
|
11932 | return readableAddChunk(this, state, chunk, '', true);
|
11933 | };
|
11934 |
|
11935 | function readableAddChunk(stream, state, chunk, encoding, addToFront) {
|
11936 | var er = chunkInvalid(state, chunk);
|
11937 | if (er) {
|
11938 | stream.emit('error', er);
|
11939 | } else if (chunk === null || chunk === undefined) {
|
11940 | state.reading = false;
|
11941 | if (!state.ended)
|
11942 | onEofChunk(stream, state);
|
11943 | } else if (state.objectMode || chunk && chunk.length > 0) {
|
11944 | if (state.ended && !addToFront) {
|
11945 | var e = new Error('stream.push() after EOF');
|
11946 | stream.emit('error', e);
|
11947 | } else if (state.endEmitted && addToFront) {
|
11948 | var e = new Error('stream.unshift() after end event');
|
11949 | stream.emit('error', e);
|
11950 | } else {
|
11951 | if (state.decoder && !addToFront && !encoding)
|
11952 | chunk = state.decoder.write(chunk);
|
11953 |
|
11954 |
|
11955 | state.length += state.objectMode ? 1 : chunk.length;
|
11956 | if (addToFront) {
|
11957 | state.buffer.unshift(chunk);
|
11958 | } else {
|
11959 | state.reading = false;
|
11960 | state.buffer.push(chunk);
|
11961 | }
|
11962 |
|
11963 | if (state.needReadable)
|
11964 | emitReadable(stream);
|
11965 |
|
11966 | maybeReadMore(stream, state);
|
11967 | }
|
11968 | } else if (!addToFront) {
|
11969 | state.reading = false;
|
11970 | }
|
11971 |
|
11972 | return needMoreData(state);
|
11973 | }
|
11974 |
|
11975 |
|
11976 |
|
11977 |
|
11978 |
|
11979 |
|
11980 |
|
11981 |
|
11982 |
|
11983 |
|
11984 | function needMoreData(state) {
|
11985 | return !state.ended &&
|
11986 | (state.needReadable ||
|
11987 | state.length < state.highWaterMark ||
|
11988 | state.length === 0);
|
11989 | }
|
11990 |
|
11991 |
|
11992 | Readable.prototype.setEncoding = function(enc) {
|
11993 | if (!StringDecoder)
|
11994 | StringDecoder = _dereq_(77).StringDecoder;
|
11995 | this._readableState.decoder = new StringDecoder(enc);
|
11996 | this._readableState.encoding = enc;
|
11997 | };
|
11998 |
|
11999 |
|
12000 | var MAX_HWM = 0x800000;
|
12001 | function roundUpToNextPowerOf2(n) {
|
12002 | if (n >= MAX_HWM) {
|
12003 | n = MAX_HWM;
|
12004 | } else {
|
12005 |
|
12006 | n--;
|
12007 | for (var p = 1; p < 32; p <<= 1) n |= n >> p;
|
12008 | n++;
|
12009 | }
|
12010 | return n;
|
12011 | }
|
12012 |
|
12013 | function howMuchToRead(n, state) {
|
12014 | if (state.length === 0 && state.ended)
|
12015 | return 0;
|
12016 |
|
12017 | if (state.objectMode)
|
12018 | return n === 0 ? 0 : 1;
|
12019 |
|
12020 | if (n === null || isNaN(n)) {
|
12021 |
|
12022 | if (state.flowing && state.buffer.length)
|
12023 | return state.buffer[0].length;
|
12024 | else
|
12025 | return state.length;
|
12026 | }
|
12027 |
|
12028 | if (n <= 0)
|
12029 | return 0;
|
12030 |
|
12031 |
|
12032 |
|
12033 |
|
12034 |
|
12035 | if (n > state.highWaterMark)
|
12036 | state.highWaterMark = roundUpToNextPowerOf2(n);
|
12037 |
|
12038 |
|
12039 | if (n > state.length) {
|
12040 | if (!state.ended) {
|
12041 | state.needReadable = true;
|
12042 | return 0;
|
12043 | } else
|
12044 | return state.length;
|
12045 | }
|
12046 |
|
12047 | return n;
|
12048 | }
|
12049 |
|
12050 |
|
12051 | Readable.prototype.read = function(n) {
|
12052 | var state = this._readableState;
|
12053 | state.calledRead = true;
|
12054 | var nOrig = n;
|
12055 | var ret;
|
12056 |
|
12057 | if (typeof n !== 'number' || n > 0)
|
12058 | state.emittedReadable = false;
|
12059 |
|
12060 |
|
12061 |
|
12062 |
|
12063 | if (n === 0 &&
|
12064 | state.needReadable &&
|
12065 | (state.length >= state.highWaterMark || state.ended)) {
|
12066 | emitReadable(this);
|
12067 | return null;
|
12068 | }
|
12069 |
|
12070 | n = howMuchToRead(n, state);
|
12071 |
|
12072 |
|
12073 | if (n === 0 && state.ended) {
|
12074 | ret = null;
|
12075 |
|
12076 |
|
12077 |
|
12078 |
|
12079 |
|
12080 |
|
12081 |
|
12082 |
|
12083 |
|
12084 |
|
12085 |
|
12086 |
|
12087 | if (state.length > 0 && state.decoder) {
|
12088 | ret = fromList(n, state);
|
12089 | state.length -= ret.length;
|
12090 | }
|
12091 |
|
12092 | if (state.length === 0)
|
12093 | endReadable(this);
|
12094 |
|
12095 | return ret;
|
12096 | }
|
12097 |
|
12098 |
|
12099 |
|
12100 |
|
12101 |
|
12102 |
|
12103 |
|
12104 |
|
12105 |
|
12106 |
|
12107 |
|
12108 |
|
12109 |
|
12110 |
|
12111 |
|
12112 |
|
12113 |
|
12114 |
|
12115 |
|
12116 |
|
12117 |
|
12118 |
|
12119 |
|
12120 |
|
12121 | var doRead = state.needReadable;
|
12122 |
|
12123 |
|
12124 | if (state.length - n <= state.highWaterMark)
|
12125 | doRead = true;
|
12126 |
|
12127 |
|
12128 |
|
12129 | if (state.ended || state.reading)
|
12130 | doRead = false;
|
12131 |
|
12132 | if (doRead) {
|
12133 | state.reading = true;
|
12134 | state.sync = true;
|
12135 |
|
12136 | if (state.length === 0)
|
12137 | state.needReadable = true;
|
12138 |
|
12139 | this._read(state.highWaterMark);
|
12140 | state.sync = false;
|
12141 | }
|
12142 |
|
12143 |
|
12144 |
|
12145 |
|
12146 | if (doRead && !state.reading)
|
12147 | n = howMuchToRead(nOrig, state);
|
12148 |
|
12149 | if (n > 0)
|
12150 | ret = fromList(n, state);
|
12151 | else
|
12152 | ret = null;
|
12153 |
|
12154 | if (ret === null) {
|
12155 | state.needReadable = true;
|
12156 | n = 0;
|
12157 | }
|
12158 |
|
12159 | state.length -= n;
|
12160 |
|
12161 |
|
12162 |
|
12163 | if (state.length === 0 && !state.ended)
|
12164 | state.needReadable = true;
|
12165 |
|
12166 |
|
12167 |
|
12168 |
|
12169 | if (state.ended && !state.endEmitted && state.length === 0)
|
12170 | endReadable(this);
|
12171 |
|
12172 | return ret;
|
12173 | };
|
12174 |
|
12175 | function chunkInvalid(state, chunk) {
|
12176 | var er = null;
|
12177 | if (!Buffer.isBuffer(chunk) &&
|
12178 | 'string' !== typeof chunk &&
|
12179 | chunk !== null &&
|
12180 | chunk !== undefined &&
|
12181 | !state.objectMode) {
|
12182 | er = new TypeError('Invalid non-string/buffer chunk');
|
12183 | }
|
12184 | return er;
|
12185 | }
|
12186 |
|
12187 |
|
12188 | function onEofChunk(stream, state) {
|
12189 | if (state.decoder && !state.ended) {
|
12190 | var chunk = state.decoder.end();
|
12191 | if (chunk && chunk.length) {
|
12192 | state.buffer.push(chunk);
|
12193 | state.length += state.objectMode ? 1 : chunk.length;
|
12194 | }
|
12195 | }
|
12196 | state.ended = true;
|
12197 |
|
12198 |
|
12199 |
|
12200 | if (state.length > 0)
|
12201 | emitReadable(stream);
|
12202 | else
|
12203 | endReadable(stream);
|
12204 | }
|
12205 |
|
12206 |
|
12207 |
|
12208 |
|
12209 | function emitReadable(stream) {
|
12210 | var state = stream._readableState;
|
12211 | state.needReadable = false;
|
12212 | if (state.emittedReadable)
|
12213 | return;
|
12214 |
|
12215 | state.emittedReadable = true;
|
12216 | if (state.sync)
|
12217 | process.nextTick(function() {
|
12218 | emitReadable_(stream);
|
12219 | });
|
12220 | else
|
12221 | emitReadable_(stream);
|
12222 | }
|
12223 |
|
12224 | function emitReadable_(stream) {
|
12225 | stream.emit('readable');
|
12226 | }
|
12227 |
|
12228 |
|
12229 |
|
12230 |
|
12231 |
|
12232 |
|
12233 |
|
12234 |
|
12235 | function maybeReadMore(stream, state) {
|
12236 | if (!state.readingMore) {
|
12237 | state.readingMore = true;
|
12238 | process.nextTick(function() {
|
12239 | maybeReadMore_(stream, state);
|
12240 | });
|
12241 | }
|
12242 | }
|
12243 |
|
12244 | function maybeReadMore_(stream, state) {
|
12245 | var len = state.length;
|
12246 | while (!state.reading && !state.flowing && !state.ended &&
|
12247 | state.length < state.highWaterMark) {
|
12248 | stream.read(0);
|
12249 | if (len === state.length)
|
12250 |
|
12251 | break;
|
12252 | else
|
12253 | len = state.length;
|
12254 | }
|
12255 | state.readingMore = false;
|
12256 | }
|
12257 |
|
12258 |
|
12259 |
|
12260 |
|
12261 |
|
12262 | Readable.prototype._read = function(n) {
|
12263 | this.emit('error', new Error('not implemented'));
|
12264 | };
|
12265 |
|
12266 | Readable.prototype.pipe = function(dest, pipeOpts) {
|
12267 | var src = this;
|
12268 | var state = this._readableState;
|
12269 |
|
12270 | switch (state.pipesCount) {
|
12271 | case 0:
|
12272 | state.pipes = dest;
|
12273 | break;
|
12274 | case 1:
|
12275 | state.pipes = [state.pipes, dest];
|
12276 | break;
|
12277 | default:
|
12278 | state.pipes.push(dest);
|
12279 | break;
|
12280 | }
|
12281 | state.pipesCount += 1;
|
12282 |
|
12283 | var doEnd = (!pipeOpts || pipeOpts.end !== false) &&
|
12284 | dest !== process.stdout &&
|
12285 | dest !== process.stderr;
|
12286 |
|
12287 | var endFn = doEnd ? onend : cleanup;
|
12288 | if (state.endEmitted)
|
12289 | process.nextTick(endFn);
|
12290 | else
|
12291 | src.once('end', endFn);
|
12292 |
|
12293 | dest.on('unpipe', onunpipe);
|
12294 | function onunpipe(readable) {
|
12295 | if (readable !== src) return;
|
12296 | cleanup();
|
12297 | }
|
12298 |
|
12299 | function onend() {
|
12300 | dest.end();
|
12301 | }
|
12302 |
|
12303 |
|
12304 |
|
12305 |
|
12306 |
|
12307 | var ondrain = pipeOnDrain(src);
|
12308 | dest.on('drain', ondrain);
|
12309 |
|
12310 | function cleanup() {
|
12311 |
|
12312 | dest.removeListener('close', onclose);
|
12313 | dest.removeListener('finish', onfinish);
|
12314 | dest.removeListener('drain', ondrain);
|
12315 | dest.removeListener('error', onerror);
|
12316 | dest.removeListener('unpipe', onunpipe);
|
12317 | src.removeListener('end', onend);
|
12318 | src.removeListener('end', cleanup);
|
12319 |
|
12320 |
|
12321 |
|
12322 |
|
12323 |
|
12324 |
|
12325 | if (!dest._writableState || dest._writableState.needDrain)
|
12326 | ondrain();
|
12327 | }
|
12328 |
|
12329 |
|
12330 |
|
12331 | function onerror(er) {
|
12332 | unpipe();
|
12333 | dest.removeListener('error', onerror);
|
12334 | if (EE.listenerCount(dest, 'error') === 0)
|
12335 | dest.emit('error', er);
|
12336 | }
|
12337 |
|
12338 |
|
12339 | if (!dest._events || !dest._events.error)
|
12340 | dest.on('error', onerror);
|
12341 | else if (isArray(dest._events.error))
|
12342 | dest._events.error.unshift(onerror);
|
12343 | else
|
12344 | dest._events.error = [onerror, dest._events.error];
|
12345 |
|
12346 |
|
12347 |
|
12348 |
|
12349 | function onclose() {
|
12350 | dest.removeListener('finish', onfinish);
|
12351 | unpipe();
|
12352 | }
|
12353 | dest.once('close', onclose);
|
12354 | function onfinish() {
|
12355 | dest.removeListener('close', onclose);
|
12356 | unpipe();
|
12357 | }
|
12358 | dest.once('finish', onfinish);
|
12359 |
|
12360 | function unpipe() {
|
12361 | src.unpipe(dest);
|
12362 | }
|
12363 |
|
12364 |
|
12365 | dest.emit('pipe', src);
|
12366 |
|
12367 |
|
12368 | if (!state.flowing) {
|
12369 |
|
12370 |
|
12371 |
|
12372 |
|
12373 | this.on('readable', pipeOnReadable);
|
12374 |
|
12375 | state.flowing = true;
|
12376 | process.nextTick(function() {
|
12377 | flow(src);
|
12378 | });
|
12379 | }
|
12380 |
|
12381 | return dest;
|
12382 | };
|
12383 |
|
12384 | function pipeOnDrain(src) {
|
12385 | return function() {
|
12386 | var dest = this;
|
12387 | var state = src._readableState;
|
12388 | state.awaitDrain--;
|
12389 | if (state.awaitDrain === 0)
|
12390 | flow(src);
|
12391 | };
|
12392 | }
|
12393 |
|
12394 | function flow(src) {
|
12395 | var state = src._readableState;
|
12396 | var chunk;
|
12397 | state.awaitDrain = 0;
|
12398 |
|
12399 | function write(dest, i, list) {
|
12400 | var written = dest.write(chunk);
|
12401 | if (false === written) {
|
12402 | state.awaitDrain++;
|
12403 | }
|
12404 | }
|
12405 |
|
12406 | while (state.pipesCount && null !== (chunk = src.read())) {
|
12407 |
|
12408 | if (state.pipesCount === 1)
|
12409 | write(state.pipes, 0, null);
|
12410 | else
|
12411 | forEach(state.pipes, write);
|
12412 |
|
12413 | src.emit('data', chunk);
|
12414 |
|
12415 |
|
12416 | if (state.awaitDrain > 0)
|
12417 | return;
|
12418 | }
|
12419 |
|
12420 |
|
12421 |
|
12422 |
|
12423 |
|
12424 | if (state.pipesCount === 0) {
|
12425 | state.flowing = false;
|
12426 |
|
12427 |
|
12428 | if (EE.listenerCount(src, 'data') > 0)
|
12429 | emitDataEvents(src);
|
12430 | return;
|
12431 | }
|
12432 |
|
12433 |
|
12434 |
|
12435 | state.ranOut = true;
|
12436 | }
|
12437 |
|
12438 | function pipeOnReadable() {
|
12439 | if (this._readableState.ranOut) {
|
12440 | this._readableState.ranOut = false;
|
12441 | flow(this);
|
12442 | }
|
12443 | }
|
12444 |
|
12445 |
|
12446 | Readable.prototype.unpipe = function(dest) {
|
12447 | var state = this._readableState;
|
12448 |
|
12449 |
|
12450 | if (state.pipesCount === 0)
|
12451 | return this;
|
12452 |
|
12453 |
|
12454 | if (state.pipesCount === 1) {
|
12455 |
|
12456 | if (dest && dest !== state.pipes)
|
12457 | return this;
|
12458 |
|
12459 | if (!dest)
|
12460 | dest = state.pipes;
|
12461 |
|
12462 |
|
12463 | state.pipes = null;
|
12464 | state.pipesCount = 0;
|
12465 | this.removeListener('readable', pipeOnReadable);
|
12466 | state.flowing = false;
|
12467 | if (dest)
|
12468 | dest.emit('unpipe', this);
|
12469 | return this;
|
12470 | }
|
12471 |
|
12472 |
|
12473 |
|
12474 | if (!dest) {
|
12475 |
|
12476 | var dests = state.pipes;
|
12477 | var len = state.pipesCount;
|
12478 | state.pipes = null;
|
12479 | state.pipesCount = 0;
|
12480 | this.removeListener('readable', pipeOnReadable);
|
12481 | state.flowing = false;
|
12482 |
|
12483 | for (var i = 0; i < len; i++)
|
12484 | dests[i].emit('unpipe', this);
|
12485 | return this;
|
12486 | }
|
12487 |
|
12488 |
|
12489 | var i = indexOf(state.pipes, dest);
|
12490 | if (i === -1)
|
12491 | return this;
|
12492 |
|
12493 | state.pipes.splice(i, 1);
|
12494 | state.pipesCount -= 1;
|
12495 | if (state.pipesCount === 1)
|
12496 | state.pipes = state.pipes[0];
|
12497 |
|
12498 | dest.emit('unpipe', this);
|
12499 |
|
12500 | return this;
|
12501 | };
|
12502 |
|
12503 |
|
12504 |
|
12505 | Readable.prototype.on = function(ev, fn) {
|
12506 | var res = Stream.prototype.on.call(this, ev, fn);
|
12507 |
|
12508 | if (ev === 'data' && !this._readableState.flowing)
|
12509 | emitDataEvents(this);
|
12510 |
|
12511 | if (ev === 'readable' && this.readable) {
|
12512 | var state = this._readableState;
|
12513 | if (!state.readableListening) {
|
12514 | state.readableListening = true;
|
12515 | state.emittedReadable = false;
|
12516 | state.needReadable = true;
|
12517 | if (!state.reading) {
|
12518 | this.read(0);
|
12519 | } else if (state.length) {
|
12520 | emitReadable(this, state);
|
12521 | }
|
12522 | }
|
12523 | }
|
12524 |
|
12525 | return res;
|
12526 | };
|
12527 | Readable.prototype.addListener = Readable.prototype.on;
|
12528 |
|
12529 |
|
12530 |
|
12531 | Readable.prototype.resume = function() {
|
12532 | emitDataEvents(this);
|
12533 | this.read(0);
|
12534 | this.emit('resume');
|
12535 | };
|
12536 |
|
12537 | Readable.prototype.pause = function() {
|
12538 | emitDataEvents(this, true);
|
12539 | this.emit('pause');
|
12540 | };
|
12541 |
|
12542 | function emitDataEvents(stream, startPaused) {
|
12543 | var state = stream._readableState;
|
12544 |
|
12545 | if (state.flowing) {
|
12546 |
|
12547 | throw new Error('Cannot switch to old mode now.');
|
12548 | }
|
12549 |
|
12550 | var paused = startPaused || false;
|
12551 | var readable = false;
|
12552 |
|
12553 |
|
12554 | stream.readable = true;
|
12555 | stream.pipe = Stream.prototype.pipe;
|
12556 | stream.on = stream.addListener = Stream.prototype.on;
|
12557 |
|
12558 | stream.on('readable', function() {
|
12559 | readable = true;
|
12560 |
|
12561 | var c;
|
12562 | while (!paused && (null !== (c = stream.read())))
|
12563 | stream.emit('data', c);
|
12564 |
|
12565 | if (c === null) {
|
12566 | readable = false;
|
12567 | stream._readableState.needReadable = true;
|
12568 | }
|
12569 | });
|
12570 |
|
12571 | stream.pause = function() {
|
12572 | paused = true;
|
12573 | this.emit('pause');
|
12574 | };
|
12575 |
|
12576 | stream.resume = function() {
|
12577 | paused = false;
|
12578 | if (readable)
|
12579 | process.nextTick(function() {
|
12580 | stream.emit('readable');
|
12581 | });
|
12582 | else
|
12583 | this.read(0);
|
12584 | this.emit('resume');
|
12585 | };
|
12586 |
|
12587 |
|
12588 | stream.emit('readable');
|
12589 | }
|
12590 |
|
12591 |
|
12592 |
|
12593 |
|
12594 | Readable.prototype.wrap = function(stream) {
|
12595 | var state = this._readableState;
|
12596 | var paused = false;
|
12597 |
|
12598 | var self = this;
|
12599 | stream.on('end', function() {
|
12600 | if (state.decoder && !state.ended) {
|
12601 | var chunk = state.decoder.end();
|
12602 | if (chunk && chunk.length)
|
12603 | self.push(chunk);
|
12604 | }
|
12605 |
|
12606 | self.push(null);
|
12607 | });
|
12608 |
|
12609 | stream.on('data', function(chunk) {
|
12610 | if (state.decoder)
|
12611 | chunk = state.decoder.write(chunk);
|
12612 |
|
12613 |
|
12614 |
|
12615 | if (state.objectMode && (chunk === null || chunk === undefined))
|
12616 | return;
|
12617 | else if (!state.objectMode && (!chunk || !chunk.length))
|
12618 | return;
|
12619 |
|
12620 | var ret = self.push(chunk);
|
12621 | if (!ret) {
|
12622 | paused = true;
|
12623 | stream.pause();
|
12624 | }
|
12625 | });
|
12626 |
|
12627 |
|
12628 |
|
12629 | for (var i in stream) {
|
12630 | if (typeof stream[i] === 'function' &&
|
12631 | typeof this[i] === 'undefined') {
|
12632 | this[i] = function(method) { return function() {
|
12633 | return stream[method].apply(stream, arguments);
|
12634 | }}(i);
|
12635 | }
|
12636 | }
|
12637 |
|
12638 |
|
12639 | var events = ['error', 'close', 'destroy', 'pause', 'resume'];
|
12640 | forEach(events, function(ev) {
|
12641 | stream.on(ev, self.emit.bind(self, ev));
|
12642 | });
|
12643 |
|
12644 |
|
12645 |
|
12646 | self._read = function(n) {
|
12647 | if (paused) {
|
12648 | paused = false;
|
12649 | stream.resume();
|
12650 | }
|
12651 | };
|
12652 |
|
12653 | return self;
|
12654 | };
|
12655 |
|
12656 |
|
12657 |
|
12658 |
|
12659 | Readable._fromList = fromList;
|
12660 |
|
12661 |
|
12662 |
|
12663 | function fromList(n, state) {
|
12664 | var list = state.buffer;
|
12665 | var length = state.length;
|
12666 | var stringMode = !!state.decoder;
|
12667 | var objectMode = !!state.objectMode;
|
12668 | var ret;
|
12669 |
|
12670 |
|
12671 | if (list.length === 0)
|
12672 | return null;
|
12673 |
|
12674 | if (length === 0)
|
12675 | ret = null;
|
12676 | else if (objectMode)
|
12677 | ret = list.shift();
|
12678 | else if (!n || n >= length) {
|
12679 |
|
12680 | if (stringMode)
|
12681 | ret = list.join('');
|
12682 | else
|
12683 | ret = Buffer.concat(list, length);
|
12684 | list.length = 0;
|
12685 | } else {
|
12686 |
|
12687 | if (n < list[0].length) {
|
12688 |
|
12689 |
|
12690 | var buf = list[0];
|
12691 | ret = buf.slice(0, n);
|
12692 | list[0] = buf.slice(n);
|
12693 | } else if (n === list[0].length) {
|
12694 |
|
12695 | ret = list.shift();
|
12696 | } else {
|
12697 |
|
12698 |
|
12699 | if (stringMode)
|
12700 | ret = '';
|
12701 | else
|
12702 | ret = new Buffer(n);
|
12703 |
|
12704 | var c = 0;
|
12705 | for (var i = 0, l = list.length; i < l && c < n; i++) {
|
12706 | var buf = list[0];
|
12707 | var cpy = Math.min(n - c, buf.length);
|
12708 |
|
12709 | if (stringMode)
|
12710 | ret += buf.slice(0, cpy);
|
12711 | else
|
12712 | buf.copy(ret, c, 0, cpy);
|
12713 |
|
12714 | if (cpy < buf.length)
|
12715 | list[0] = buf.slice(cpy);
|
12716 | else
|
12717 | list.shift();
|
12718 |
|
12719 | c += cpy;
|
12720 | }
|
12721 | }
|
12722 | }
|
12723 |
|
12724 | return ret;
|
12725 | }
|
12726 |
|
12727 | function endReadable(stream) {
|
12728 | var state = stream._readableState;
|
12729 |
|
12730 |
|
12731 |
|
12732 | if (state.length > 0)
|
12733 | throw new Error('endReadable called on non-empty stream');
|
12734 |
|
12735 | if (!state.endEmitted && state.calledRead) {
|
12736 | state.ended = true;
|
12737 | process.nextTick(function() {
|
12738 |
|
12739 | if (!state.endEmitted && state.length === 0) {
|
12740 | state.endEmitted = true;
|
12741 | stream.readable = false;
|
12742 | stream.emit('end');
|
12743 | }
|
12744 | });
|
12745 | }
|
12746 | }
|
12747 |
|
12748 | function forEach (xs, f) {
|
12749 | for (var i = 0, l = xs.length; i < l; i++) {
|
12750 | f(xs[i], i);
|
12751 | }
|
12752 | }
|
12753 |
|
12754 | function indexOf (xs, x) {
|
12755 | for (var i = 0, l = xs.length; i < l; i++) {
|
12756 | if (xs[i] === x) return i;
|
12757 | }
|
12758 | return -1;
|
12759 | }
|
12760 |
|
12761 | }).call(this,_dereq_(70))
|
12762 | },{"10":10,"14":14,"18":18,"20":20,"70":70,"77":77,"81":81,"9":9}],75:[function(_dereq_,module,exports){
|
12763 |
|
12764 |
|
12765 |
|
12766 |
|
12767 |
|
12768 |
|
12769 |
|
12770 |
|
12771 |
|
12772 |
|
12773 |
|
12774 |
|
12775 |
|
12776 |
|
12777 |
|
12778 |
|
12779 |
|
12780 |
|
12781 |
|
12782 |
|
12783 |
|
12784 |
|
12785 |
|
12786 |
|
12787 |
|
12788 |
|
12789 |
|
12790 |
|
12791 |
|
12792 |
|
12793 |
|
12794 |
|
12795 |
|
12796 |
|
12797 |
|
12798 |
|
12799 |
|
12800 |
|
12801 |
|
12802 |
|
12803 |
|
12804 |
|
12805 |
|
12806 |
|
12807 |
|
12808 |
|
12809 |
|
12810 |
|
12811 |
|
12812 |
|
12813 |
|
12814 |
|
12815 |
|
12816 |
|
12817 |
|
12818 |
|
12819 |
|
12820 |
|
12821 |
|
12822 |
|
12823 |
|
12824 |
|
12825 |
|
12826 |
|
12827 | module.exports = Transform;
|
12828 |
|
12829 | var Duplex = _dereq_(72);
|
12830 |
|
12831 |
|
12832 | var util = _dereq_(10);
|
12833 | util.inherits = _dereq_(18);
|
12834 |
|
12835 |
|
12836 | util.inherits(Transform, Duplex);
|
12837 |
|
12838 |
|
12839 | function TransformState(options, stream) {
|
12840 | this.afterTransform = function(er, data) {
|
12841 | return afterTransform(stream, er, data);
|
12842 | };
|
12843 |
|
12844 | this.needTransform = false;
|
12845 | this.transforming = false;
|
12846 | this.writecb = null;
|
12847 | this.writechunk = null;
|
12848 | }
|
12849 |
|
12850 | function afterTransform(stream, er, data) {
|
12851 | var ts = stream._transformState;
|
12852 | ts.transforming = false;
|
12853 |
|
12854 | var cb = ts.writecb;
|
12855 |
|
12856 | if (!cb)
|
12857 | return stream.emit('error', new Error('no writecb in Transform class'));
|
12858 |
|
12859 | ts.writechunk = null;
|
12860 | ts.writecb = null;
|
12861 |
|
12862 | if (data !== null && data !== undefined)
|
12863 | stream.push(data);
|
12864 |
|
12865 | if (cb)
|
12866 | cb(er);
|
12867 |
|
12868 | var rs = stream._readableState;
|
12869 | rs.reading = false;
|
12870 | if (rs.needReadable || rs.length < rs.highWaterMark) {
|
12871 | stream._read(rs.highWaterMark);
|
12872 | }
|
12873 | }
|
12874 |
|
12875 |
|
12876 | function Transform(options) {
|
12877 | if (!(this instanceof Transform))
|
12878 | return new Transform(options);
|
12879 |
|
12880 | Duplex.call(this, options);
|
12881 |
|
12882 | var ts = this._transformState = new TransformState(options, this);
|
12883 |
|
12884 |
|
12885 | var stream = this;
|
12886 |
|
12887 |
|
12888 | this._readableState.needReadable = true;
|
12889 |
|
12890 |
|
12891 |
|
12892 |
|
12893 | this._readableState.sync = false;
|
12894 |
|
12895 | this.once('finish', function() {
|
12896 | if ('function' === typeof this._flush)
|
12897 | this._flush(function(er) {
|
12898 | done(stream, er);
|
12899 | });
|
12900 | else
|
12901 | done(stream);
|
12902 | });
|
12903 | }
|
12904 |
|
12905 | Transform.prototype.push = function(chunk, encoding) {
|
12906 | this._transformState.needTransform = false;
|
12907 | return Duplex.prototype.push.call(this, chunk, encoding);
|
12908 | };
|
12909 |
|
12910 |
|
12911 |
|
12912 |
|
12913 |
|
12914 |
|
12915 |
|
12916 |
|
12917 |
|
12918 |
|
12919 |
|
12920 | Transform.prototype._transform = function(chunk, encoding, cb) {
|
12921 | throw new Error('not implemented');
|
12922 | };
|
12923 |
|
12924 | Transform.prototype._write = function(chunk, encoding, cb) {
|
12925 | var ts = this._transformState;
|
12926 | ts.writecb = cb;
|
12927 | ts.writechunk = chunk;
|
12928 | ts.writeencoding = encoding;
|
12929 | if (!ts.transforming) {
|
12930 | var rs = this._readableState;
|
12931 | if (ts.needTransform ||
|
12932 | rs.needReadable ||
|
12933 | rs.length < rs.highWaterMark)
|
12934 | this._read(rs.highWaterMark);
|
12935 | }
|
12936 | };
|
12937 |
|
12938 |
|
12939 |
|
12940 |
|
12941 | Transform.prototype._read = function(n) {
|
12942 | var ts = this._transformState;
|
12943 |
|
12944 | if (ts.writechunk !== null && ts.writecb && !ts.transforming) {
|
12945 | ts.transforming = true;
|
12946 | this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
|
12947 | } else {
|
12948 |
|
12949 |
|
12950 | ts.needTransform = true;
|
12951 | }
|
12952 | };
|
12953 |
|
12954 |
|
12955 | function done(stream, er) {
|
12956 | if (er)
|
12957 | return stream.emit('error', er);
|
12958 |
|
12959 |
|
12960 |
|
12961 | var ws = stream._writableState;
|
12962 | var rs = stream._readableState;
|
12963 | var ts = stream._transformState;
|
12964 |
|
12965 | if (ws.length)
|
12966 | throw new Error('calling transform done when ws.length != 0');
|
12967 |
|
12968 | if (ts.transforming)
|
12969 | throw new Error('calling transform done when still transforming');
|
12970 |
|
12971 | return stream.push(null);
|
12972 | }
|
12973 |
|
12974 | },{"10":10,"18":18,"72":72}],76:[function(_dereq_,module,exports){
|
12975 | (function (process){
|
12976 |
|
12977 |
|
12978 |
|
12979 |
|
12980 |
|
12981 |
|
12982 |
|
12983 |
|
12984 |
|
12985 |
|
12986 |
|
12987 |
|
12988 |
|
12989 |
|
12990 |
|
12991 |
|
12992 |
|
12993 |
|
12994 |
|
12995 |
|
12996 |
|
12997 |
|
12998 |
|
12999 |
|
13000 |
|
13001 | module.exports = Writable;
|
13002 |
|
13003 |
|
13004 | var Buffer = _dereq_(9).Buffer;
|
13005 |
|
13006 |
|
13007 | Writable.WritableState = WritableState;
|
13008 |
|
13009 |
|
13010 |
|
13011 | var util = _dereq_(10);
|
13012 | util.inherits = _dereq_(18);
|
13013 |
|
13014 |
|
13015 | var Stream = _dereq_(81);
|
13016 |
|
13017 | util.inherits(Writable, Stream);
|
13018 |
|
13019 | function WriteReq(chunk, encoding, cb) {
|
13020 | this.chunk = chunk;
|
13021 | this.encoding = encoding;
|
13022 | this.callback = cb;
|
13023 | }
|
13024 |
|
13025 | function WritableState(options, stream) {
|
13026 | options = options || {};
|
13027 |
|
13028 |
|
13029 |
|
13030 |
|
13031 | var hwm = options.highWaterMark;
|
13032 | this.highWaterMark = (hwm || hwm === 0) ? hwm : 16 * 1024;
|
13033 |
|
13034 |
|
13035 |
|
13036 | this.objectMode = !!options.objectMode;
|
13037 |
|
13038 |
|
13039 | this.highWaterMark = ~~this.highWaterMark;
|
13040 |
|
13041 | this.needDrain = false;
|
13042 |
|
13043 | this.ending = false;
|
13044 |
|
13045 | this.ended = false;
|
13046 |
|
13047 | this.finished = false;
|
13048 |
|
13049 |
|
13050 |
|
13051 |
|
13052 | var noDecode = options.decodeStrings === false;
|
13053 | this.decodeStrings = !noDecode;
|
13054 |
|
13055 |
|
13056 |
|
13057 |
|
13058 | this.defaultEncoding = options.defaultEncoding || 'utf8';
|
13059 |
|
13060 |
|
13061 |
|
13062 |
|
13063 | this.length = 0;
|
13064 |
|
13065 |
|
13066 | this.writing = false;
|
13067 |
|
13068 |
|
13069 |
|
13070 |
|
13071 |
|
13072 | this.sync = true;
|
13073 |
|
13074 |
|
13075 |
|
13076 |
|
13077 | this.bufferProcessing = false;
|
13078 |
|
13079 |
|
13080 | this.onwrite = function(er) {
|
13081 | onwrite(stream, er);
|
13082 | };
|
13083 |
|
13084 |
|
13085 | this.writecb = null;
|
13086 |
|
13087 |
|
13088 | this.writelen = 0;
|
13089 |
|
13090 | this.buffer = [];
|
13091 |
|
13092 |
|
13093 | this.errorEmitted = false;
|
13094 | }
|
13095 |
|
13096 | function Writable(options) {
|
13097 | var Duplex = _dereq_(72);
|
13098 |
|
13099 |
|
13100 |
|
13101 | if (!(this instanceof Writable) && !(this instanceof Duplex))
|
13102 | return new Writable(options);
|
13103 |
|
13104 | this._writableState = new WritableState(options, this);
|
13105 |
|
13106 |
|
13107 | this.writable = true;
|
13108 |
|
13109 | Stream.call(this);
|
13110 | }
|
13111 |
|
13112 |
|
13113 | Writable.prototype.pipe = function() {
|
13114 | this.emit('error', new Error('Cannot pipe. Not readable.'));
|
13115 | };
|
13116 |
|
13117 |
|
13118 | function writeAfterEnd(stream, state, cb) {
|
13119 | var er = new Error('write after end');
|
13120 |
|
13121 | stream.emit('error', er);
|
13122 | process.nextTick(function() {
|
13123 | cb(er);
|
13124 | });
|
13125 | }
|
13126 |
|
13127 |
|
13128 |
|
13129 |
|
13130 |
|
13131 |
|
13132 | function validChunk(stream, state, chunk, cb) {
|
13133 | var valid = true;
|
13134 | if (!Buffer.isBuffer(chunk) &&
|
13135 | 'string' !== typeof chunk &&
|
13136 | chunk !== null &&
|
13137 | chunk !== undefined &&
|
13138 | !state.objectMode) {
|
13139 | var er = new TypeError('Invalid non-string/buffer chunk');
|
13140 | stream.emit('error', er);
|
13141 | process.nextTick(function() {
|
13142 | cb(er);
|
13143 | });
|
13144 | valid = false;
|
13145 | }
|
13146 | return valid;
|
13147 | }
|
13148 |
|
13149 | Writable.prototype.write = function(chunk, encoding, cb) {
|
13150 | var state = this._writableState;
|
13151 | var ret = false;
|
13152 |
|
13153 | if (typeof encoding === 'function') {
|
13154 | cb = encoding;
|
13155 | encoding = null;
|
13156 | }
|
13157 |
|
13158 | if (Buffer.isBuffer(chunk))
|
13159 | encoding = 'buffer';
|
13160 | else if (!encoding)
|
13161 | encoding = state.defaultEncoding;
|
13162 |
|
13163 | if (typeof cb !== 'function')
|
13164 | cb = function() {};
|
13165 |
|
13166 | if (state.ended)
|
13167 | writeAfterEnd(this, state, cb);
|
13168 | else if (validChunk(this, state, chunk, cb))
|
13169 | ret = writeOrBuffer(this, state, chunk, encoding, cb);
|
13170 |
|
13171 | return ret;
|
13172 | };
|
13173 |
|
13174 | function decodeChunk(state, chunk, encoding) {
|
13175 | if (!state.objectMode &&
|
13176 | state.decodeStrings !== false &&
|
13177 | typeof chunk === 'string') {
|
13178 | chunk = new Buffer(chunk, encoding);
|
13179 | }
|
13180 | return chunk;
|
13181 | }
|
13182 |
|
13183 |
|
13184 |
|
13185 |
|
13186 | function writeOrBuffer(stream, state, chunk, encoding, cb) {
|
13187 | chunk = decodeChunk(state, chunk, encoding);
|
13188 | if (Buffer.isBuffer(chunk))
|
13189 | encoding = 'buffer';
|
13190 | var len = state.objectMode ? 1 : chunk.length;
|
13191 |
|
13192 | state.length += len;
|
13193 |
|
13194 | var ret = state.length < state.highWaterMark;
|
13195 |
|
13196 | if (!ret)
|
13197 | state.needDrain = true;
|
13198 |
|
13199 | if (state.writing)
|
13200 | state.buffer.push(new WriteReq(chunk, encoding, cb));
|
13201 | else
|
13202 | doWrite(stream, state, len, chunk, encoding, cb);
|
13203 |
|
13204 | return ret;
|
13205 | }
|
13206 |
|
13207 | function doWrite(stream, state, len, chunk, encoding, cb) {
|
13208 | state.writelen = len;
|
13209 | state.writecb = cb;
|
13210 | state.writing = true;
|
13211 | state.sync = true;
|
13212 | stream._write(chunk, encoding, state.onwrite);
|
13213 | state.sync = false;
|
13214 | }
|
13215 |
|
13216 | function onwriteError(stream, state, sync, er, cb) {
|
13217 | if (sync)
|
13218 | process.nextTick(function() {
|
13219 | cb(er);
|
13220 | });
|
13221 | else
|
13222 | cb(er);
|
13223 |
|
13224 | stream._writableState.errorEmitted = true;
|
13225 | stream.emit('error', er);
|
13226 | }
|
13227 |
|
13228 | function onwriteStateUpdate(state) {
|
13229 | state.writing = false;
|
13230 | state.writecb = null;
|
13231 | state.length -= state.writelen;
|
13232 | state.writelen = 0;
|
13233 | }
|
13234 |
|
13235 | function onwrite(stream, er) {
|
13236 | var state = stream._writableState;
|
13237 | var sync = state.sync;
|
13238 | var cb = state.writecb;
|
13239 |
|
13240 | onwriteStateUpdate(state);
|
13241 |
|
13242 | if (er)
|
13243 | onwriteError(stream, state, sync, er, cb);
|
13244 | else {
|
13245 |
|
13246 | var finished = needFinish(stream, state);
|
13247 |
|
13248 | if (!finished && !state.bufferProcessing && state.buffer.length)
|
13249 | clearBuffer(stream, state);
|
13250 |
|
13251 | if (sync) {
|
13252 | process.nextTick(function() {
|
13253 | afterWrite(stream, state, finished, cb);
|
13254 | });
|
13255 | } else {
|
13256 | afterWrite(stream, state, finished, cb);
|
13257 | }
|
13258 | }
|
13259 | }
|
13260 |
|
13261 | function afterWrite(stream, state, finished, cb) {
|
13262 | if (!finished)
|
13263 | onwriteDrain(stream, state);
|
13264 | cb();
|
13265 | if (finished)
|
13266 | finishMaybe(stream, state);
|
13267 | }
|
13268 |
|
13269 |
|
13270 |
|
13271 |
|
13272 | function onwriteDrain(stream, state) {
|
13273 | if (state.length === 0 && state.needDrain) {
|
13274 | state.needDrain = false;
|
13275 | stream.emit('drain');
|
13276 | }
|
13277 | }
|
13278 |
|
13279 |
|
13280 |
|
13281 | function clearBuffer(stream, state) {
|
13282 | state.bufferProcessing = true;
|
13283 |
|
13284 | for (var c = 0; c < state.buffer.length; c++) {
|
13285 | var entry = state.buffer[c];
|
13286 | var chunk = entry.chunk;
|
13287 | var encoding = entry.encoding;
|
13288 | var cb = entry.callback;
|
13289 | var len = state.objectMode ? 1 : chunk.length;
|
13290 |
|
13291 | doWrite(stream, state, len, chunk, encoding, cb);
|
13292 |
|
13293 |
|
13294 |
|
13295 |
|
13296 |
|
13297 | if (state.writing) {
|
13298 | c++;
|
13299 | break;
|
13300 | }
|
13301 | }
|
13302 |
|
13303 | state.bufferProcessing = false;
|
13304 | if (c < state.buffer.length)
|
13305 | state.buffer = state.buffer.slice(c);
|
13306 | else
|
13307 | state.buffer.length = 0;
|
13308 | }
|
13309 |
|
13310 | Writable.prototype._write = function(chunk, encoding, cb) {
|
13311 | cb(new Error('not implemented'));
|
13312 | };
|
13313 |
|
13314 | Writable.prototype.end = function(chunk, encoding, cb) {
|
13315 | var state = this._writableState;
|
13316 |
|
13317 | if (typeof chunk === 'function') {
|
13318 | cb = chunk;
|
13319 | chunk = null;
|
13320 | encoding = null;
|
13321 | } else if (typeof encoding === 'function') {
|
13322 | cb = encoding;
|
13323 | encoding = null;
|
13324 | }
|
13325 |
|
13326 | if (typeof chunk !== 'undefined' && chunk !== null)
|
13327 | this.write(chunk, encoding);
|
13328 |
|
13329 |
|
13330 | if (!state.ending && !state.finished)
|
13331 | endWritable(this, state, cb);
|
13332 | };
|
13333 |
|
13334 |
|
13335 | function needFinish(stream, state) {
|
13336 | return (state.ending &&
|
13337 | state.length === 0 &&
|
13338 | !state.finished &&
|
13339 | !state.writing);
|
13340 | }
|
13341 |
|
13342 | function finishMaybe(stream, state) {
|
13343 | var need = needFinish(stream, state);
|
13344 | if (need) {
|
13345 | state.finished = true;
|
13346 | stream.emit('finish');
|
13347 | }
|
13348 | return need;
|
13349 | }
|
13350 |
|
13351 | function endWritable(stream, state, cb) {
|
13352 | state.ending = true;
|
13353 | finishMaybe(stream, state);
|
13354 | if (cb) {
|
13355 | if (state.finished)
|
13356 | process.nextTick(cb);
|
13357 | else
|
13358 | stream.once('finish', cb);
|
13359 | }
|
13360 | state.ended = true;
|
13361 | }
|
13362 |
|
13363 | }).call(this,_dereq_(70))
|
13364 | },{"10":10,"18":18,"70":70,"72":72,"81":81,"9":9}],77:[function(_dereq_,module,exports){
|
13365 |
|
13366 |
|
13367 |
|
13368 |
|
13369 |
|
13370 |
|
13371 |
|
13372 |
|
13373 |
|
13374 |
|
13375 |
|
13376 |
|
13377 |
|
13378 |
|
13379 |
|
13380 |
|
13381 |
|
13382 |
|
13383 |
|
13384 |
|
13385 |
|
13386 | var Buffer = _dereq_(9).Buffer;
|
13387 |
|
13388 | var isBufferEncoding = Buffer.isEncoding
|
13389 | || function(encoding) {
|
13390 | switch (encoding && encoding.toLowerCase()) {
|
13391 | 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 true;
|
13392 | default: return false;
|
13393 | }
|
13394 | }
|
13395 |
|
13396 |
|
13397 | function assertEncoding(encoding) {
|
13398 | if (encoding && !isBufferEncoding(encoding)) {
|
13399 | throw new Error('Unknown encoding: ' + encoding);
|
13400 | }
|
13401 | }
|
13402 |
|
13403 |
|
13404 |
|
13405 |
|
13406 |
|
13407 |
|
13408 |
|
13409 |
|
13410 |
|
13411 | var StringDecoder = exports.StringDecoder = function(encoding) {
|
13412 | this.encoding = (encoding || 'utf8').toLowerCase().replace(/[-_]/, '');
|
13413 | assertEncoding(encoding);
|
13414 | switch (this.encoding) {
|
13415 | case 'utf8':
|
13416 |
|
13417 | this.surrogateSize = 3;
|
13418 | break;
|
13419 | case 'ucs2':
|
13420 | case 'utf16le':
|
13421 |
|
13422 | this.surrogateSize = 2;
|
13423 | this.detectIncompleteChar = utf16DetectIncompleteChar;
|
13424 | break;
|
13425 | case 'base64':
|
13426 |
|
13427 | this.surrogateSize = 3;
|
13428 | this.detectIncompleteChar = base64DetectIncompleteChar;
|
13429 | break;
|
13430 | default:
|
13431 | this.write = passThroughWrite;
|
13432 | return;
|
13433 | }
|
13434 |
|
13435 |
|
13436 |
|
13437 | this.charBuffer = new Buffer(6);
|
13438 |
|
13439 | this.charReceived = 0;
|
13440 |
|
13441 | this.charLength = 0;
|
13442 | };
|
13443 |
|
13444 |
|
13445 |
|
13446 |
|
13447 |
|
13448 |
|
13449 |
|
13450 |
|
13451 |
|
13452 |
|
13453 |
|
13454 | StringDecoder.prototype.write = function(buffer) {
|
13455 | var charStr = '';
|
13456 |
|
13457 | while (this.charLength) {
|
13458 |
|
13459 | var available = (buffer.length >= this.charLength - this.charReceived) ?
|
13460 | this.charLength - this.charReceived :
|
13461 | buffer.length;
|
13462 |
|
13463 |
|
13464 | buffer.copy(this.charBuffer, this.charReceived, 0, available);
|
13465 | this.charReceived += available;
|
13466 |
|
13467 | if (this.charReceived < this.charLength) {
|
13468 |
|
13469 | return '';
|
13470 | }
|
13471 |
|
13472 |
|
13473 | buffer = buffer.slice(available, buffer.length);
|
13474 |
|
13475 |
|
13476 | charStr = this.charBuffer.slice(0, this.charLength).toString(this.encoding);
|
13477 |
|
13478 |
|
13479 | var charCode = charStr.charCodeAt(charStr.length - 1);
|
13480 | if (charCode >= 0xD800 && charCode <= 0xDBFF) {
|
13481 | this.charLength += this.surrogateSize;
|
13482 | charStr = '';
|
13483 | continue;
|
13484 | }
|
13485 | this.charReceived = this.charLength = 0;
|
13486 |
|
13487 |
|
13488 | if (buffer.length === 0) {
|
13489 | return charStr;
|
13490 | }
|
13491 | break;
|
13492 | }
|
13493 |
|
13494 |
|
13495 | this.detectIncompleteChar(buffer);
|
13496 |
|
13497 | var end = buffer.length;
|
13498 | if (this.charLength) {
|
13499 |
|
13500 | buffer.copy(this.charBuffer, 0, buffer.length - this.charReceived, end);
|
13501 | end -= this.charReceived;
|
13502 | }
|
13503 |
|
13504 | charStr += buffer.toString(this.encoding, 0, end);
|
13505 |
|
13506 | var end = charStr.length - 1;
|
13507 | var charCode = charStr.charCodeAt(end);
|
13508 |
|
13509 | if (charCode >= 0xD800 && charCode <= 0xDBFF) {
|
13510 | var size = this.surrogateSize;
|
13511 | this.charLength += size;
|
13512 | this.charReceived += size;
|
13513 | this.charBuffer.copy(this.charBuffer, size, 0, size);
|
13514 | buffer.copy(this.charBuffer, 0, 0, size);
|
13515 | return charStr.substring(0, end);
|
13516 | }
|
13517 |
|
13518 |
|
13519 | return charStr;
|
13520 | };
|
13521 |
|
13522 |
|
13523 |
|
13524 |
|
13525 |
|
13526 | StringDecoder.prototype.detectIncompleteChar = function(buffer) {
|
13527 |
|
13528 | var i = (buffer.length >= 3) ? 3 : buffer.length;
|
13529 |
|
13530 |
|
13531 |
|
13532 | for (; i > 0; i--) {
|
13533 | var c = buffer[buffer.length - i];
|
13534 |
|
13535 |
|
13536 |
|
13537 |
|
13538 | if (i == 1 && c >> 5 == 0x06) {
|
13539 | this.charLength = 2;
|
13540 | break;
|
13541 | }
|
13542 |
|
13543 |
|
13544 | if (i <= 2 && c >> 4 == 0x0E) {
|
13545 | this.charLength = 3;
|
13546 | break;
|
13547 | }
|
13548 |
|
13549 |
|
13550 | if (i <= 3 && c >> 3 == 0x1E) {
|
13551 | this.charLength = 4;
|
13552 | break;
|
13553 | }
|
13554 | }
|
13555 | this.charReceived = i;
|
13556 | };
|
13557 |
|
13558 | StringDecoder.prototype.end = function(buffer) {
|
13559 | var res = '';
|
13560 | if (buffer && buffer.length)
|
13561 | res = this.write(buffer);
|
13562 |
|
13563 | if (this.charReceived) {
|
13564 | var cr = this.charReceived;
|
13565 | var buf = this.charBuffer;
|
13566 | var enc = this.encoding;
|
13567 | res += buf.slice(0, cr).toString(enc);
|
13568 | }
|
13569 |
|
13570 | return res;
|
13571 | };
|
13572 |
|
13573 | function passThroughWrite(buffer) {
|
13574 | return buffer.toString(this.encoding);
|
13575 | }
|
13576 |
|
13577 | function utf16DetectIncompleteChar(buffer) {
|
13578 | this.charReceived = buffer.length % 2;
|
13579 | this.charLength = this.charReceived ? 2 : 0;
|
13580 | }
|
13581 |
|
13582 | function base64DetectIncompleteChar(buffer) {
|
13583 | this.charReceived = buffer.length % 3;
|
13584 | this.charLength = this.charReceived ? 3 : 0;
|
13585 | }
|
13586 |
|
13587 | },{"9":9}],78:[function(_dereq_,module,exports){
|
13588 | var Stream = _dereq_(81);
|
13589 | exports = module.exports = _dereq_(74);
|
13590 | exports.Stream = Stream;
|
13591 | exports.Readable = exports;
|
13592 | exports.Writable = _dereq_(76);
|
13593 | exports.Duplex = _dereq_(72);
|
13594 | exports.Transform = _dereq_(75);
|
13595 | exports.PassThrough = _dereq_(73);
|
13596 |
|
13597 | },{"72":72,"73":73,"74":74,"75":75,"76":76,"81":81}],79:[function(_dereq_,module,exports){
|
13598 |
|
13599 | var buffer = _dereq_(9)
|
13600 | var Buffer = buffer.Buffer
|
13601 |
|
13602 |
|
13603 | function copyProps (src, dst) {
|
13604 | for (var key in src) {
|
13605 | dst[key] = src[key]
|
13606 | }
|
13607 | }
|
13608 | if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) {
|
13609 | module.exports = buffer
|
13610 | } else {
|
13611 |
|
13612 | copyProps(buffer, exports)
|
13613 | exports.Buffer = SafeBuffer
|
13614 | }
|
13615 |
|
13616 | function SafeBuffer (arg, encodingOrOffset, length) {
|
13617 | return Buffer(arg, encodingOrOffset, length)
|
13618 | }
|
13619 |
|
13620 | SafeBuffer.prototype = Object.create(Buffer.prototype)
|
13621 |
|
13622 |
|
13623 | copyProps(Buffer, SafeBuffer)
|
13624 |
|
13625 | SafeBuffer.from = function (arg, encodingOrOffset, length) {
|
13626 | if (typeof arg === 'number') {
|
13627 | throw new TypeError('Argument must not be a number')
|
13628 | }
|
13629 | return Buffer(arg, encodingOrOffset, length)
|
13630 | }
|
13631 |
|
13632 | SafeBuffer.alloc = function (size, fill, encoding) {
|
13633 | if (typeof size !== 'number') {
|
13634 | throw new TypeError('Argument must be a number')
|
13635 | }
|
13636 | var buf = Buffer(size)
|
13637 | if (fill !== undefined) {
|
13638 | if (typeof encoding === 'string') {
|
13639 | buf.fill(fill, encoding)
|
13640 | } else {
|
13641 | buf.fill(fill)
|
13642 | }
|
13643 | } else {
|
13644 | buf.fill(0)
|
13645 | }
|
13646 | return buf
|
13647 | }
|
13648 |
|
13649 | SafeBuffer.allocUnsafe = function (size) {
|
13650 | if (typeof size !== 'number') {
|
13651 | throw new TypeError('Argument must be a number')
|
13652 | }
|
13653 | return Buffer(size)
|
13654 | }
|
13655 |
|
13656 | SafeBuffer.allocUnsafeSlow = function (size) {
|
13657 | if (typeof size !== 'number') {
|
13658 | throw new TypeError('Argument must be a number')
|
13659 | }
|
13660 | return buffer.SlowBuffer(size)
|
13661 | }
|
13662 |
|
13663 | },{"9":9}],80:[function(_dereq_,module,exports){
|
13664 | (function (factory) {
|
13665 | if (typeof exports === 'object') {
|
13666 |
|
13667 | module.exports = factory();
|
13668 | } else if (typeof define === 'function' && define.amd) {
|
13669 |
|
13670 | define(factory);
|
13671 | } else {
|
13672 |
|
13673 | var glob;
|
13674 |
|
13675 | try {
|
13676 | glob = window;
|
13677 | } catch (e) {
|
13678 | glob = self;
|
13679 | }
|
13680 |
|
13681 | glob.SparkMD5 = factory();
|
13682 | }
|
13683 | }(function (undefined) {
|
13684 |
|
13685 | 'use strict';
|
13686 |
|
13687 | |
13688 |
|
13689 |
|
13690 |
|
13691 |
|
13692 |
|
13693 |
|
13694 |
|
13695 | |
13696 |
|
13697 |
|
13698 |
|
13699 |
|
13700 | var add32 = function (a, b) {
|
13701 | return (a + b) & 0xFFFFFFFF;
|
13702 | },
|
13703 | hex_chr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'];
|
13704 |
|
13705 |
|
13706 | function cmn(q, a, b, x, s, t) {
|
13707 | a = add32(add32(a, q), add32(x, t));
|
13708 | return add32((a << s) | (a >>> (32 - s)), b);
|
13709 | }
|
13710 |
|
13711 | function md5cycle(x, k) {
|
13712 | var a = x[0],
|
13713 | b = x[1],
|
13714 | c = x[2],
|
13715 | d = x[3];
|
13716 |
|
13717 | a += (b & c | ~b & d) + k[0] - 680876936 | 0;
|
13718 | a = (a << 7 | a >>> 25) + b | 0;
|
13719 | d += (a & b | ~a & c) + k[1] - 389564586 | 0;
|
13720 | d = (d << 12 | d >>> 20) + a | 0;
|
13721 | c += (d & a | ~d & b) + k[2] + 606105819 | 0;
|
13722 | c = (c << 17 | c >>> 15) + d | 0;
|
13723 | b += (c & d | ~c & a) + k[3] - 1044525330 | 0;
|
13724 | b = (b << 22 | b >>> 10) + c | 0;
|
13725 | a += (b & c | ~b & d) + k[4] - 176418897 | 0;
|
13726 | a = (a << 7 | a >>> 25) + b | 0;
|
13727 | d += (a & b | ~a & c) + k[5] + 1200080426 | 0;
|
13728 | d = (d << 12 | d >>> 20) + a | 0;
|
13729 | c += (d & a | ~d & b) + k[6] - 1473231341 | 0;
|
13730 | c = (c << 17 | c >>> 15) + d | 0;
|
13731 | b += (c & d | ~c & a) + k[7] - 45705983 | 0;
|
13732 | b = (b << 22 | b >>> 10) + c | 0;
|
13733 | a += (b & c | ~b & d) + k[8] + 1770035416 | 0;
|
13734 | a = (a << 7 | a >>> 25) + b | 0;
|
13735 | d += (a & b | ~a & c) + k[9] - 1958414417 | 0;
|
13736 | d = (d << 12 | d >>> 20) + a | 0;
|
13737 | c += (d & a | ~d & b) + k[10] - 42063 | 0;
|
13738 | c = (c << 17 | c >>> 15) + d | 0;
|
13739 | b += (c & d | ~c & a) + k[11] - 1990404162 | 0;
|
13740 | b = (b << 22 | b >>> 10) + c | 0;
|
13741 | a += (b & c | ~b & d) + k[12] + 1804603682 | 0;
|
13742 | a = (a << 7 | a >>> 25) + b | 0;
|
13743 | d += (a & b | ~a & c) + k[13] - 40341101 | 0;
|
13744 | d = (d << 12 | d >>> 20) + a | 0;
|
13745 | c += (d & a | ~d & b) + k[14] - 1502002290 | 0;
|
13746 | c = (c << 17 | c >>> 15) + d | 0;
|
13747 | b += (c & d | ~c & a) + k[15] + 1236535329 | 0;
|
13748 | b = (b << 22 | b >>> 10) + c | 0;
|
13749 |
|
13750 | a += (b & d | c & ~d) + k[1] - 165796510 | 0;
|
13751 | a = (a << 5 | a >>> 27) + b | 0;
|
13752 | d += (a & c | b & ~c) + k[6] - 1069501632 | 0;
|
13753 | d = (d << 9 | d >>> 23) + a | 0;
|
13754 | c += (d & b | a & ~b) + k[11] + 643717713 | 0;
|
13755 | c = (c << 14 | c >>> 18) + d | 0;
|
13756 | b += (c & a | d & ~a) + k[0] - 373897302 | 0;
|
13757 | b = (b << 20 | b >>> 12) + c | 0;
|
13758 | a += (b & d | c & ~d) + k[5] - 701558691 | 0;
|
13759 | a = (a << 5 | a >>> 27) + b | 0;
|
13760 | d += (a & c | b & ~c) + k[10] + 38016083 | 0;
|
13761 | d = (d << 9 | d >>> 23) + a | 0;
|
13762 | c += (d & b | a & ~b) + k[15] - 660478335 | 0;
|
13763 | c = (c << 14 | c >>> 18) + d | 0;
|
13764 | b += (c & a | d & ~a) + k[4] - 405537848 | 0;
|
13765 | b = (b << 20 | b >>> 12) + c | 0;
|
13766 | a += (b & d | c & ~d) + k[9] + 568446438 | 0;
|
13767 | a = (a << 5 | a >>> 27) + b | 0;
|
13768 | d += (a & c | b & ~c) + k[14] - 1019803690 | 0;
|
13769 | d = (d << 9 | d >>> 23) + a | 0;
|
13770 | c += (d & b | a & ~b) + k[3] - 187363961 | 0;
|
13771 | c = (c << 14 | c >>> 18) + d | 0;
|
13772 | b += (c & a | d & ~a) + k[8] + 1163531501 | 0;
|
13773 | b = (b << 20 | b >>> 12) + c | 0;
|
13774 | a += (b & d | c & ~d) + k[13] - 1444681467 | 0;
|
13775 | a = (a << 5 | a >>> 27) + b | 0;
|
13776 | d += (a & c | b & ~c) + k[2] - 51403784 | 0;
|
13777 | d = (d << 9 | d >>> 23) + a | 0;
|
13778 | c += (d & b | a & ~b) + k[7] + 1735328473 | 0;
|
13779 | c = (c << 14 | c >>> 18) + d | 0;
|
13780 | b += (c & a | d & ~a) + k[12] - 1926607734 | 0;
|
13781 | b = (b << 20 | b >>> 12) + c | 0;
|
13782 |
|
13783 | a += (b ^ c ^ d) + k[5] - 378558 | 0;
|
13784 | a = (a << 4 | a >>> 28) + b | 0;
|
13785 | d += (a ^ b ^ c) + k[8] - 2022574463 | 0;
|
13786 | d = (d << 11 | d >>> 21) + a | 0;
|
13787 | c += (d ^ a ^ b) + k[11] + 1839030562 | 0;
|
13788 | c = (c << 16 | c >>> 16) + d | 0;
|
13789 | b += (c ^ d ^ a) + k[14] - 35309556 | 0;
|
13790 | b = (b << 23 | b >>> 9) + c | 0;
|
13791 | a += (b ^ c ^ d) + k[1] - 1530992060 | 0;
|
13792 | a = (a << 4 | a >>> 28) + b | 0;
|
13793 | d += (a ^ b ^ c) + k[4] + 1272893353 | 0;
|
13794 | d = (d << 11 | d >>> 21) + a | 0;
|
13795 | c += (d ^ a ^ b) + k[7] - 155497632 | 0;
|
13796 | c = (c << 16 | c >>> 16) + d | 0;
|
13797 | b += (c ^ d ^ a) + k[10] - 1094730640 | 0;
|
13798 | b = (b << 23 | b >>> 9) + c | 0;
|
13799 | a += (b ^ c ^ d) + k[13] + 681279174 | 0;
|
13800 | a = (a << 4 | a >>> 28) + b | 0;
|
13801 | d += (a ^ b ^ c) + k[0] - 358537222 | 0;
|
13802 | d = (d << 11 | d >>> 21) + a | 0;
|
13803 | c += (d ^ a ^ b) + k[3] - 722521979 | 0;
|
13804 | c = (c << 16 | c >>> 16) + d | 0;
|
13805 | b += (c ^ d ^ a) + k[6] + 76029189 | 0;
|
13806 | b = (b << 23 | b >>> 9) + c | 0;
|
13807 | a += (b ^ c ^ d) + k[9] - 640364487 | 0;
|
13808 | a = (a << 4 | a >>> 28) + b | 0;
|
13809 | d += (a ^ b ^ c) + k[12] - 421815835 | 0;
|
13810 | d = (d << 11 | d >>> 21) + a | 0;
|
13811 | c += (d ^ a ^ b) + k[15] + 530742520 | 0;
|
13812 | c = (c << 16 | c >>> 16) + d | 0;
|
13813 | b += (c ^ d ^ a) + k[2] - 995338651 | 0;
|
13814 | b = (b << 23 | b >>> 9) + c | 0;
|
13815 |
|
13816 | a += (c ^ (b | ~d)) + k[0] - 198630844 | 0;
|
13817 | a = (a << 6 | a >>> 26) + b | 0;
|
13818 | d += (b ^ (a | ~c)) + k[7] + 1126891415 | 0;
|
13819 | d = (d << 10 | d >>> 22) + a | 0;
|
13820 | c += (a ^ (d | ~b)) + k[14] - 1416354905 | 0;
|
13821 | c = (c << 15 | c >>> 17) + d | 0;
|
13822 | b += (d ^ (c | ~a)) + k[5] - 57434055 | 0;
|
13823 | b = (b << 21 |b >>> 11) + c | 0;
|
13824 | a += (c ^ (b | ~d)) + k[12] + 1700485571 | 0;
|
13825 | a = (a << 6 | a >>> 26) + b | 0;
|
13826 | d += (b ^ (a | ~c)) + k[3] - 1894986606 | 0;
|
13827 | d = (d << 10 | d >>> 22) + a | 0;
|
13828 | c += (a ^ (d | ~b)) + k[10] - 1051523 | 0;
|
13829 | c = (c << 15 | c >>> 17) + d | 0;
|
13830 | b += (d ^ (c | ~a)) + k[1] - 2054922799 | 0;
|
13831 | b = (b << 21 |b >>> 11) + c | 0;
|
13832 | a += (c ^ (b | ~d)) + k[8] + 1873313359 | 0;
|
13833 | a = (a << 6 | a >>> 26) + b | 0;
|
13834 | d += (b ^ (a | ~c)) + k[15] - 30611744 | 0;
|
13835 | d = (d << 10 | d >>> 22) + a | 0;
|
13836 | c += (a ^ (d | ~b)) + k[6] - 1560198380 | 0;
|
13837 | c = (c << 15 | c >>> 17) + d | 0;
|
13838 | b += (d ^ (c | ~a)) + k[13] + 1309151649 | 0;
|
13839 | b = (b << 21 |b >>> 11) + c | 0;
|
13840 | a += (c ^ (b | ~d)) + k[4] - 145523070 | 0;
|
13841 | a = (a << 6 | a >>> 26) + b | 0;
|
13842 | d += (b ^ (a | ~c)) + k[11] - 1120210379 | 0;
|
13843 | d = (d << 10 | d >>> 22) + a | 0;
|
13844 | c += (a ^ (d | ~b)) + k[2] + 718787259 | 0;
|
13845 | c = (c << 15 | c >>> 17) + d | 0;
|
13846 | b += (d ^ (c | ~a)) + k[9] - 343485551 | 0;
|
13847 | b = (b << 21 | b >>> 11) + c | 0;
|
13848 |
|
13849 | x[0] = a + x[0] | 0;
|
13850 | x[1] = b + x[1] | 0;
|
13851 | x[2] = c + x[2] | 0;
|
13852 | x[3] = d + x[3] | 0;
|
13853 | }
|
13854 |
|
13855 | function md5blk(s) {
|
13856 | var md5blks = [],
|
13857 | i;
|
13858 |
|
13859 | for (i = 0; i < 64; i += 4) {
|
13860 | md5blks[i >> 2] = s.charCodeAt(i) + (s.charCodeAt(i + 1) << 8) + (s.charCodeAt(i + 2) << 16) + (s.charCodeAt(i + 3) << 24);
|
13861 | }
|
13862 | return md5blks;
|
13863 | }
|
13864 |
|
13865 | function md5blk_array(a) {
|
13866 | var md5blks = [],
|
13867 | i;
|
13868 |
|
13869 | for (i = 0; i < 64; i += 4) {
|
13870 | md5blks[i >> 2] = a[i] + (a[i + 1] << 8) + (a[i + 2] << 16) + (a[i + 3] << 24);
|
13871 | }
|
13872 | return md5blks;
|
13873 | }
|
13874 |
|
13875 | function md51(s) {
|
13876 | var n = s.length,
|
13877 | state = [1732584193, -271733879, -1732584194, 271733878],
|
13878 | i,
|
13879 | length,
|
13880 | tail,
|
13881 | tmp,
|
13882 | lo,
|
13883 | hi;
|
13884 |
|
13885 | for (i = 64; i <= n; i += 64) {
|
13886 | md5cycle(state, md5blk(s.substring(i - 64, i)));
|
13887 | }
|
13888 | s = s.substring(i - 64);
|
13889 | length = s.length;
|
13890 | tail = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
13891 | for (i = 0; i < length; i += 1) {
|
13892 | tail[i >> 2] |= s.charCodeAt(i) << ((i % 4) << 3);
|
13893 | }
|
13894 | tail[i >> 2] |= 0x80 << ((i % 4) << 3);
|
13895 | if (i > 55) {
|
13896 | md5cycle(state, tail);
|
13897 | for (i = 0; i < 16; i += 1) {
|
13898 | tail[i] = 0;
|
13899 | }
|
13900 | }
|
13901 |
|
13902 |
|
13903 | tmp = n * 8;
|
13904 | tmp = tmp.toString(16).match(/(.*?)(.{0,8})$/);
|
13905 | lo = parseInt(tmp[2], 16);
|
13906 | hi = parseInt(tmp[1], 16) || 0;
|
13907 |
|
13908 | tail[14] = lo;
|
13909 | tail[15] = hi;
|
13910 |
|
13911 | md5cycle(state, tail);
|
13912 | return state;
|
13913 | }
|
13914 |
|
13915 | function md51_array(a) {
|
13916 | var n = a.length,
|
13917 | state = [1732584193, -271733879, -1732584194, 271733878],
|
13918 | i,
|
13919 | length,
|
13920 | tail,
|
13921 | tmp,
|
13922 | lo,
|
13923 | hi;
|
13924 |
|
13925 | for (i = 64; i <= n; i += 64) {
|
13926 | md5cycle(state, md5blk_array(a.subarray(i - 64, i)));
|
13927 | }
|
13928 |
|
13929 |
|
13930 |
|
13931 |
|
13932 |
|
13933 | a = (i - 64) < n ? a.subarray(i - 64) : new Uint8Array(0);
|
13934 |
|
13935 | length = a.length;
|
13936 | tail = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
13937 | for (i = 0; i < length; i += 1) {
|
13938 | tail[i >> 2] |= a[i] << ((i % 4) << 3);
|
13939 | }
|
13940 |
|
13941 | tail[i >> 2] |= 0x80 << ((i % 4) << 3);
|
13942 | if (i > 55) {
|
13943 | md5cycle(state, tail);
|
13944 | for (i = 0; i < 16; i += 1) {
|
13945 | tail[i] = 0;
|
13946 | }
|
13947 | }
|
13948 |
|
13949 |
|
13950 | tmp = n * 8;
|
13951 | tmp = tmp.toString(16).match(/(.*?)(.{0,8})$/);
|
13952 | lo = parseInt(tmp[2], 16);
|
13953 | hi = parseInt(tmp[1], 16) || 0;
|
13954 |
|
13955 | tail[14] = lo;
|
13956 | tail[15] = hi;
|
13957 |
|
13958 | md5cycle(state, tail);
|
13959 |
|
13960 | return state;
|
13961 | }
|
13962 |
|
13963 | function rhex(n) {
|
13964 | var s = '',
|
13965 | j;
|
13966 | for (j = 0; j < 4; j += 1) {
|
13967 | s += hex_chr[(n >> (j * 8 + 4)) & 0x0F] + hex_chr[(n >> (j * 8)) & 0x0F];
|
13968 | }
|
13969 | return s;
|
13970 | }
|
13971 |
|
13972 | function hex(x) {
|
13973 | var i;
|
13974 | for (i = 0; i < x.length; i += 1) {
|
13975 | x[i] = rhex(x[i]);
|
13976 | }
|
13977 | return x.join('');
|
13978 | }
|
13979 |
|
13980 |
|
13981 | if (hex(md51('hello')) !== '5d41402abc4b2a76b9719d911017c592') {
|
13982 | add32 = function (x, y) {
|
13983 | var lsw = (x & 0xFFFF) + (y & 0xFFFF),
|
13984 | msw = (x >> 16) + (y >> 16) + (lsw >> 16);
|
13985 | return (msw << 16) | (lsw & 0xFFFF);
|
13986 | };
|
13987 | }
|
13988 |
|
13989 |
|
13990 |
|
13991 | |
13992 |
|
13993 |
|
13994 |
|
13995 |
|
13996 |
|
13997 | if (typeof ArrayBuffer !== 'undefined' && !ArrayBuffer.prototype.slice) {
|
13998 | (function () {
|
13999 | function clamp(val, length) {
|
14000 | val = (val | 0) || 0;
|
14001 |
|
14002 | if (val < 0) {
|
14003 | return Math.max(val + length, 0);
|
14004 | }
|
14005 |
|
14006 | return Math.min(val, length);
|
14007 | }
|
14008 |
|
14009 | ArrayBuffer.prototype.slice = function (from, to) {
|
14010 | var length = this.byteLength,
|
14011 | begin = clamp(from, length),
|
14012 | end = length,
|
14013 | num,
|
14014 | target,
|
14015 | targetArray,
|
14016 | sourceArray;
|
14017 |
|
14018 | if (to !== undefined) {
|
14019 | end = clamp(to, length);
|
14020 | }
|
14021 |
|
14022 | if (begin > end) {
|
14023 | return new ArrayBuffer(0);
|
14024 | }
|
14025 |
|
14026 | num = end - begin;
|
14027 | target = new ArrayBuffer(num);
|
14028 | targetArray = new Uint8Array(target);
|
14029 |
|
14030 | sourceArray = new Uint8Array(this, begin, num);
|
14031 | targetArray.set(sourceArray);
|
14032 |
|
14033 | return target;
|
14034 | };
|
14035 | })();
|
14036 | }
|
14037 |
|
14038 |
|
14039 |
|
14040 | |
14041 |
|
14042 |
|
14043 |
|
14044 | function toUtf8(str) {
|
14045 | if (/[\u0080-\uFFFF]/.test(str)) {
|
14046 | str = unescape(encodeURIComponent(str));
|
14047 | }
|
14048 |
|
14049 | return str;
|
14050 | }
|
14051 |
|
14052 | function utf8Str2ArrayBuffer(str, returnUInt8Array) {
|
14053 | var length = str.length,
|
14054 | buff = new ArrayBuffer(length),
|
14055 | arr = new Uint8Array(buff),
|
14056 | i;
|
14057 |
|
14058 | for (i = 0; i < length; i += 1) {
|
14059 | arr[i] = str.charCodeAt(i);
|
14060 | }
|
14061 |
|
14062 | return returnUInt8Array ? arr : buff;
|
14063 | }
|
14064 |
|
14065 | function arrayBuffer2Utf8Str(buff) {
|
14066 | return String.fromCharCode.apply(null, new Uint8Array(buff));
|
14067 | }
|
14068 |
|
14069 | function concatenateArrayBuffers(first, second, returnUInt8Array) {
|
14070 | var result = new Uint8Array(first.byteLength + second.byteLength);
|
14071 |
|
14072 | result.set(new Uint8Array(first));
|
14073 | result.set(new Uint8Array(second), first.byteLength);
|
14074 |
|
14075 | return returnUInt8Array ? result : result.buffer;
|
14076 | }
|
14077 |
|
14078 | function hexToBinaryString(hex) {
|
14079 | var bytes = [],
|
14080 | length = hex.length,
|
14081 | x;
|
14082 |
|
14083 | for (x = 0; x < length - 1; x += 2) {
|
14084 | bytes.push(parseInt(hex.substr(x, 2), 16));
|
14085 | }
|
14086 |
|
14087 | return String.fromCharCode.apply(String, bytes);
|
14088 | }
|
14089 |
|
14090 |
|
14091 |
|
14092 | |
14093 |
|
14094 |
|
14095 |
|
14096 |
|
14097 |
|
14098 |
|
14099 | function SparkMD5() {
|
14100 |
|
14101 | this.reset();
|
14102 | }
|
14103 |
|
14104 | |
14105 |
|
14106 |
|
14107 |
|
14108 |
|
14109 |
|
14110 |
|
14111 |
|
14112 | SparkMD5.prototype.append = function (str) {
|
14113 |
|
14114 |
|
14115 | this.appendBinary(toUtf8(str));
|
14116 |
|
14117 | return this;
|
14118 | };
|
14119 |
|
14120 | |
14121 |
|
14122 |
|
14123 |
|
14124 |
|
14125 |
|
14126 |
|
14127 | SparkMD5.prototype.appendBinary = function (contents) {
|
14128 | this._buff += contents;
|
14129 | this._length += contents.length;
|
14130 |
|
14131 | var length = this._buff.length,
|
14132 | i;
|
14133 |
|
14134 | for (i = 64; i <= length; i += 64) {
|
14135 | md5cycle(this._hash, md5blk(this._buff.substring(i - 64, i)));
|
14136 | }
|
14137 |
|
14138 | this._buff = this._buff.substring(i - 64);
|
14139 |
|
14140 | return this;
|
14141 | };
|
14142 |
|
14143 | |
14144 |
|
14145 |
|
14146 |
|
14147 |
|
14148 |
|
14149 |
|
14150 |
|
14151 | SparkMD5.prototype.end = function (raw) {
|
14152 | var buff = this._buff,
|
14153 | length = buff.length,
|
14154 | i,
|
14155 | tail = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
14156 | ret;
|
14157 |
|
14158 | for (i = 0; i < length; i += 1) {
|
14159 | tail[i >> 2] |= buff.charCodeAt(i) << ((i % 4) << 3);
|
14160 | }
|
14161 |
|
14162 | this._finish(tail, length);
|
14163 | ret = hex(this._hash);
|
14164 |
|
14165 | if (raw) {
|
14166 | ret = hexToBinaryString(ret);
|
14167 | }
|
14168 |
|
14169 | this.reset();
|
14170 |
|
14171 | return ret;
|
14172 | };
|
14173 |
|
14174 | |
14175 |
|
14176 |
|
14177 |
|
14178 |
|
14179 | SparkMD5.prototype.reset = function () {
|
14180 | this._buff = '';
|
14181 | this._length = 0;
|
14182 | this._hash = [1732584193, -271733879, -1732584194, 271733878];
|
14183 |
|
14184 | return this;
|
14185 | };
|
14186 |
|
14187 | |
14188 |
|
14189 |
|
14190 |
|
14191 |
|
14192 | SparkMD5.prototype.getState = function () {
|
14193 | return {
|
14194 | buff: this._buff,
|
14195 | length: this._length,
|
14196 | hash: this._hash
|
14197 | };
|
14198 | };
|
14199 |
|
14200 | |
14201 |
|
14202 |
|
14203 |
|
14204 |
|
14205 |
|
14206 |
|
14207 | SparkMD5.prototype.setState = function (state) {
|
14208 | this._buff = state.buff;
|
14209 | this._length = state.length;
|
14210 | this._hash = state.hash;
|
14211 |
|
14212 | return this;
|
14213 | };
|
14214 |
|
14215 | |
14216 |
|
14217 |
|
14218 |
|
14219 | SparkMD5.prototype.destroy = function () {
|
14220 | delete this._hash;
|
14221 | delete this._buff;
|
14222 | delete this._length;
|
14223 | };
|
14224 |
|
14225 | |
14226 |
|
14227 |
|
14228 |
|
14229 |
|
14230 |
|
14231 | SparkMD5.prototype._finish = function (tail, length) {
|
14232 | var i = length,
|
14233 | tmp,
|
14234 | lo,
|
14235 | hi;
|
14236 |
|
14237 | tail[i >> 2] |= 0x80 << ((i % 4) << 3);
|
14238 | if (i > 55) {
|
14239 | md5cycle(this._hash, tail);
|
14240 | for (i = 0; i < 16; i += 1) {
|
14241 | tail[i] = 0;
|
14242 | }
|
14243 | }
|
14244 |
|
14245 |
|
14246 |
|
14247 | tmp = this._length * 8;
|
14248 | tmp = tmp.toString(16).match(/(.*?)(.{0,8})$/);
|
14249 | lo = parseInt(tmp[2], 16);
|
14250 | hi = parseInt(tmp[1], 16) || 0;
|
14251 |
|
14252 | tail[14] = lo;
|
14253 | tail[15] = hi;
|
14254 | md5cycle(this._hash, tail);
|
14255 | };
|
14256 |
|
14257 | |
14258 |
|
14259 |
|
14260 |
|
14261 |
|
14262 |
|
14263 |
|
14264 |
|
14265 |
|
14266 | SparkMD5.hash = function (str, raw) {
|
14267 |
|
14268 |
|
14269 | return SparkMD5.hashBinary(toUtf8(str), raw);
|
14270 | };
|
14271 |
|
14272 | |
14273 |
|
14274 |
|
14275 |
|
14276 |
|
14277 |
|
14278 |
|
14279 |
|
14280 | SparkMD5.hashBinary = function (content, raw) {
|
14281 | var hash = md51(content),
|
14282 | ret = hex(hash);
|
14283 |
|
14284 | return raw ? hexToBinaryString(ret) : ret;
|
14285 | };
|
14286 |
|
14287 |
|
14288 |
|
14289 | |
14290 |
|
14291 |
|
14292 |
|
14293 |
|
14294 | SparkMD5.ArrayBuffer = function () {
|
14295 |
|
14296 | this.reset();
|
14297 | };
|
14298 |
|
14299 | |
14300 |
|
14301 |
|
14302 |
|
14303 |
|
14304 |
|
14305 |
|
14306 | SparkMD5.ArrayBuffer.prototype.append = function (arr) {
|
14307 | var buff = concatenateArrayBuffers(this._buff.buffer, arr, true),
|
14308 | length = buff.length,
|
14309 | i;
|
14310 |
|
14311 | this._length += arr.byteLength;
|
14312 |
|
14313 | for (i = 64; i <= length; i += 64) {
|
14314 | md5cycle(this._hash, md5blk_array(buff.subarray(i - 64, i)));
|
14315 | }
|
14316 |
|
14317 | this._buff = (i - 64) < length ? new Uint8Array(buff.buffer.slice(i - 64)) : new Uint8Array(0);
|
14318 |
|
14319 | return this;
|
14320 | };
|
14321 |
|
14322 | |
14323 |
|
14324 |
|
14325 |
|
14326 |
|
14327 |
|
14328 |
|
14329 |
|
14330 | SparkMD5.ArrayBuffer.prototype.end = function (raw) {
|
14331 | var buff = this._buff,
|
14332 | length = buff.length,
|
14333 | tail = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
14334 | i,
|
14335 | ret;
|
14336 |
|
14337 | for (i = 0; i < length; i += 1) {
|
14338 | tail[i >> 2] |= buff[i] << ((i % 4) << 3);
|
14339 | }
|
14340 |
|
14341 | this._finish(tail, length);
|
14342 | ret = hex(this._hash);
|
14343 |
|
14344 | if (raw) {
|
14345 | ret = hexToBinaryString(ret);
|
14346 | }
|
14347 |
|
14348 | this.reset();
|
14349 |
|
14350 | return ret;
|
14351 | };
|
14352 |
|
14353 | |
14354 |
|
14355 |
|
14356 |
|
14357 |
|
14358 | SparkMD5.ArrayBuffer.prototype.reset = function () {
|
14359 | this._buff = new Uint8Array(0);
|
14360 | this._length = 0;
|
14361 | this._hash = [1732584193, -271733879, -1732584194, 271733878];
|
14362 |
|
14363 | return this;
|
14364 | };
|
14365 |
|
14366 | |
14367 |
|
14368 |
|
14369 |
|
14370 |
|
14371 | SparkMD5.ArrayBuffer.prototype.getState = function () {
|
14372 | var state = SparkMD5.prototype.getState.call(this);
|
14373 |
|
14374 |
|
14375 | state.buff = arrayBuffer2Utf8Str(state.buff);
|
14376 |
|
14377 | return state;
|
14378 | };
|
14379 |
|
14380 | |
14381 |
|
14382 |
|
14383 |
|
14384 |
|
14385 |
|
14386 |
|
14387 | SparkMD5.ArrayBuffer.prototype.setState = function (state) {
|
14388 |
|
14389 | state.buff = utf8Str2ArrayBuffer(state.buff, true);
|
14390 |
|
14391 | return SparkMD5.prototype.setState.call(this, state);
|
14392 | };
|
14393 |
|
14394 | SparkMD5.ArrayBuffer.prototype.destroy = SparkMD5.prototype.destroy;
|
14395 |
|
14396 | SparkMD5.ArrayBuffer.prototype._finish = SparkMD5.prototype._finish;
|
14397 |
|
14398 | |
14399 |
|
14400 |
|
14401 |
|
14402 |
|
14403 |
|
14404 |
|
14405 |
|
14406 | SparkMD5.ArrayBuffer.hash = function (arr, raw) {
|
14407 | var hash = md51_array(new Uint8Array(arr)),
|
14408 | ret = hex(hash);
|
14409 |
|
14410 | return raw ? hexToBinaryString(ret) : ret;
|
14411 | };
|
14412 |
|
14413 | return SparkMD5;
|
14414 | }));
|
14415 |
|
14416 | },{}],81:[function(_dereq_,module,exports){
|
14417 |
|
14418 |
|
14419 |
|
14420 |
|
14421 |
|
14422 |
|
14423 |
|
14424 |
|
14425 |
|
14426 |
|
14427 |
|
14428 |
|
14429 |
|
14430 |
|
14431 |
|
14432 |
|
14433 |
|
14434 |
|
14435 |
|
14436 |
|
14437 |
|
14438 | module.exports = Stream;
|
14439 |
|
14440 | var EE = _dereq_(14).EventEmitter;
|
14441 | var inherits = _dereq_(18);
|
14442 |
|
14443 | inherits(Stream, EE);
|
14444 | Stream.Readable = _dereq_(93);
|
14445 | Stream.Writable = _dereq_(95);
|
14446 | Stream.Duplex = _dereq_(83);
|
14447 | Stream.Transform = _dereq_(94);
|
14448 | Stream.PassThrough = _dereq_(92);
|
14449 |
|
14450 |
|
14451 | Stream.Stream = Stream;
|
14452 |
|
14453 |
|
14454 |
|
14455 |
|
14456 |
|
14457 |
|
14458 | function Stream() {
|
14459 | EE.call(this);
|
14460 | }
|
14461 |
|
14462 | Stream.prototype.pipe = function(dest, options) {
|
14463 | var source = this;
|
14464 |
|
14465 | function ondata(chunk) {
|
14466 | if (dest.writable) {
|
14467 | if (false === dest.write(chunk) && source.pause) {
|
14468 | source.pause();
|
14469 | }
|
14470 | }
|
14471 | }
|
14472 |
|
14473 | source.on('data', ondata);
|
14474 |
|
14475 | function ondrain() {
|
14476 | if (source.readable && source.resume) {
|
14477 | source.resume();
|
14478 | }
|
14479 | }
|
14480 |
|
14481 | dest.on('drain', ondrain);
|
14482 |
|
14483 |
|
14484 |
|
14485 | if (!dest._isStdio && (!options || options.end !== false)) {
|
14486 | source.on('end', onend);
|
14487 | source.on('close', onclose);
|
14488 | }
|
14489 |
|
14490 | var didOnEnd = false;
|
14491 | function onend() {
|
14492 | if (didOnEnd) return;
|
14493 | didOnEnd = true;
|
14494 |
|
14495 | dest.end();
|
14496 | }
|
14497 |
|
14498 |
|
14499 | function onclose() {
|
14500 | if (didOnEnd) return;
|
14501 | didOnEnd = true;
|
14502 |
|
14503 | if (typeof dest.destroy === 'function') dest.destroy();
|
14504 | }
|
14505 |
|
14506 |
|
14507 | function onerror(er) {
|
14508 | cleanup();
|
14509 | if (EE.listenerCount(this, 'error') === 0) {
|
14510 | throw er;
|
14511 | }
|
14512 | }
|
14513 |
|
14514 | source.on('error', onerror);
|
14515 | dest.on('error', onerror);
|
14516 |
|
14517 |
|
14518 | function cleanup() {
|
14519 | source.removeListener('data', ondata);
|
14520 | dest.removeListener('drain', ondrain);
|
14521 |
|
14522 | source.removeListener('end', onend);
|
14523 | source.removeListener('close', onclose);
|
14524 |
|
14525 | source.removeListener('error', onerror);
|
14526 | dest.removeListener('error', onerror);
|
14527 |
|
14528 | source.removeListener('end', cleanup);
|
14529 | source.removeListener('close', cleanup);
|
14530 |
|
14531 | dest.removeListener('close', cleanup);
|
14532 | }
|
14533 |
|
14534 | source.on('end', cleanup);
|
14535 | source.on('close', cleanup);
|
14536 |
|
14537 | dest.on('close', cleanup);
|
14538 |
|
14539 | dest.emit('pipe', source);
|
14540 |
|
14541 |
|
14542 | return dest;
|
14543 | };
|
14544 |
|
14545 | },{"14":14,"18":18,"83":83,"92":92,"93":93,"94":94,"95":95}],82:[function(_dereq_,module,exports){
|
14546 | var toString = {}.toString;
|
14547 |
|
14548 | module.exports = Array.isArray || function (arr) {
|
14549 | return toString.call(arr) == '[object Array]';
|
14550 | };
|
14551 |
|
14552 | },{}],83:[function(_dereq_,module,exports){
|
14553 | module.exports = _dereq_(84);
|
14554 |
|
14555 | },{"84":84}],84:[function(_dereq_,module,exports){
|
14556 |
|
14557 |
|
14558 |
|
14559 |
|
14560 |
|
14561 |
|
14562 |
|
14563 |
|
14564 |
|
14565 |
|
14566 |
|
14567 |
|
14568 |
|
14569 |
|
14570 |
|
14571 |
|
14572 |
|
14573 |
|
14574 |
|
14575 |
|
14576 |
|
14577 |
|
14578 |
|
14579 |
|
14580 |
|
14581 |
|
14582 | 'use strict';
|
14583 |
|
14584 |
|
14585 |
|
14586 | var pna = _dereq_(69);
|
14587 |
|
14588 |
|
14589 |
|
14590 | var objectKeys = Object.keys || function (obj) {
|
14591 | var keys = [];
|
14592 | for (var key in obj) {
|
14593 | keys.push(key);
|
14594 | }return keys;
|
14595 | };
|
14596 |
|
14597 |
|
14598 | module.exports = Duplex;
|
14599 |
|
14600 |
|
14601 | var util = Object.create(_dereq_(10));
|
14602 | util.inherits = _dereq_(18);
|
14603 |
|
14604 |
|
14605 | var Readable = _dereq_(86);
|
14606 | var Writable = _dereq_(88);
|
14607 |
|
14608 | util.inherits(Duplex, Readable);
|
14609 |
|
14610 | {
|
14611 |
|
14612 | var keys = objectKeys(Writable.prototype);
|
14613 | for (var v = 0; v < keys.length; v++) {
|
14614 | var method = keys[v];
|
14615 | if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method];
|
14616 | }
|
14617 | }
|
14618 |
|
14619 | function Duplex(options) {
|
14620 | if (!(this instanceof Duplex)) return new Duplex(options);
|
14621 |
|
14622 | Readable.call(this, options);
|
14623 | Writable.call(this, options);
|
14624 |
|
14625 | if (options && options.readable === false) this.readable = false;
|
14626 |
|
14627 | if (options && options.writable === false) this.writable = false;
|
14628 |
|
14629 | this.allowHalfOpen = true;
|
14630 | if (options && options.allowHalfOpen === false) this.allowHalfOpen = false;
|
14631 |
|
14632 | this.once('end', onend);
|
14633 | }
|
14634 |
|
14635 | Object.defineProperty(Duplex.prototype, 'writableHighWaterMark', {
|
14636 |
|
14637 |
|
14638 |
|
14639 | enumerable: false,
|
14640 | get: function () {
|
14641 | return this._writableState.highWaterMark;
|
14642 | }
|
14643 | });
|
14644 |
|
14645 |
|
14646 | function onend() {
|
14647 |
|
14648 |
|
14649 | if (this.allowHalfOpen || this._writableState.ended) return;
|
14650 |
|
14651 |
|
14652 |
|
14653 | pna.nextTick(onEndNT, this);
|
14654 | }
|
14655 |
|
14656 | function onEndNT(self) {
|
14657 | self.end();
|
14658 | }
|
14659 |
|
14660 | Object.defineProperty(Duplex.prototype, 'destroyed', {
|
14661 | get: function () {
|
14662 | if (this._readableState === undefined || this._writableState === undefined) {
|
14663 | return false;
|
14664 | }
|
14665 | return this._readableState.destroyed && this._writableState.destroyed;
|
14666 | },
|
14667 | set: function (value) {
|
14668 |
|
14669 |
|
14670 | if (this._readableState === undefined || this._writableState === undefined) {
|
14671 | return;
|
14672 | }
|
14673 |
|
14674 |
|
14675 |
|
14676 | this._readableState.destroyed = value;
|
14677 | this._writableState.destroyed = value;
|
14678 | }
|
14679 | });
|
14680 |
|
14681 | Duplex.prototype._destroy = function (err, cb) {
|
14682 | this.push(null);
|
14683 | this.end();
|
14684 |
|
14685 | pna.nextTick(cb, err);
|
14686 | };
|
14687 | },{"10":10,"18":18,"69":69,"86":86,"88":88}],85:[function(_dereq_,module,exports){
|
14688 |
|
14689 |
|
14690 |
|
14691 |
|
14692 |
|
14693 |
|
14694 |
|
14695 |
|
14696 |
|
14697 |
|
14698 |
|
14699 |
|
14700 |
|
14701 |
|
14702 |
|
14703 |
|
14704 |
|
14705 |
|
14706 |
|
14707 |
|
14708 |
|
14709 |
|
14710 |
|
14711 |
|
14712 |
|
14713 | 'use strict';
|
14714 |
|
14715 | module.exports = PassThrough;
|
14716 |
|
14717 | var Transform = _dereq_(87);
|
14718 |
|
14719 |
|
14720 | var util = Object.create(_dereq_(10));
|
14721 | util.inherits = _dereq_(18);
|
14722 |
|
14723 |
|
14724 | util.inherits(PassThrough, Transform);
|
14725 |
|
14726 | function PassThrough(options) {
|
14727 | if (!(this instanceof PassThrough)) return new PassThrough(options);
|
14728 |
|
14729 | Transform.call(this, options);
|
14730 | }
|
14731 |
|
14732 | PassThrough.prototype._transform = function (chunk, encoding, cb) {
|
14733 | cb(null, chunk);
|
14734 | };
|
14735 | },{"10":10,"18":18,"87":87}],86:[function(_dereq_,module,exports){
|
14736 | (function (process,global){
|
14737 |
|
14738 |
|
14739 |
|
14740 |
|
14741 |
|
14742 |
|
14743 |
|
14744 |
|
14745 |
|
14746 |
|
14747 |
|
14748 |
|
14749 |
|
14750 |
|
14751 |
|
14752 |
|
14753 |
|
14754 |
|
14755 |
|
14756 |
|
14757 |
|
14758 | 'use strict';
|
14759 |
|
14760 |
|
14761 |
|
14762 | var pna = _dereq_(69);
|
14763 |
|
14764 |
|
14765 | module.exports = Readable;
|
14766 |
|
14767 |
|
14768 | var isArray = _dereq_(82);
|
14769 |
|
14770 |
|
14771 |
|
14772 | var Duplex;
|
14773 |
|
14774 |
|
14775 | Readable.ReadableState = ReadableState;
|
14776 |
|
14777 |
|
14778 | var EE = _dereq_(14).EventEmitter;
|
14779 |
|
14780 | var EElistenerCount = function (emitter, type) {
|
14781 | return emitter.listeners(type).length;
|
14782 | };
|
14783 |
|
14784 |
|
14785 |
|
14786 | var Stream = _dereq_(91);
|
14787 |
|
14788 |
|
14789 |
|
14790 |
|
14791 | var Buffer = _dereq_(96).Buffer;
|
14792 | var OurUint8Array = global.Uint8Array || function () {};
|
14793 | function _uint8ArrayToBuffer(chunk) {
|
14794 | return Buffer.from(chunk);
|
14795 | }
|
14796 | function _isUint8Array(obj) {
|
14797 | return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
|
14798 | }
|
14799 |
|
14800 |
|
14801 |
|
14802 |
|
14803 | var util = Object.create(_dereq_(10));
|
14804 | util.inherits = _dereq_(18);
|
14805 |
|
14806 |
|
14807 |
|
14808 | var debugUtil = _dereq_(7);
|
14809 | var debug = void 0;
|
14810 | if (debugUtil && debugUtil.debuglog) {
|
14811 | debug = debugUtil.debuglog('stream');
|
14812 | } else {
|
14813 | debug = function () {};
|
14814 | }
|
14815 |
|
14816 |
|
14817 | var BufferList = _dereq_(89);
|
14818 | var destroyImpl = _dereq_(90);
|
14819 | var StringDecoder;
|
14820 |
|
14821 | util.inherits(Readable, Stream);
|
14822 |
|
14823 | var kProxyEvents = ['error', 'close', 'destroy', 'pause', 'resume'];
|
14824 |
|
14825 | function prependListener(emitter, event, fn) {
|
14826 |
|
14827 |
|
14828 | if (typeof emitter.prependListener === 'function') return emitter.prependListener(event, fn);
|
14829 |
|
14830 |
|
14831 |
|
14832 |
|
14833 |
|
14834 | 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]];
|
14835 | }
|
14836 |
|
14837 | function ReadableState(options, stream) {
|
14838 | Duplex = Duplex || _dereq_(84);
|
14839 |
|
14840 | options = options || {};
|
14841 |
|
14842 |
|
14843 |
|
14844 |
|
14845 |
|
14846 |
|
14847 | var isDuplex = stream instanceof Duplex;
|
14848 |
|
14849 |
|
14850 |
|
14851 | this.objectMode = !!options.objectMode;
|
14852 |
|
14853 | if (isDuplex) this.objectMode = this.objectMode || !!options.readableObjectMode;
|
14854 |
|
14855 |
|
14856 |
|
14857 | var hwm = options.highWaterMark;
|
14858 | var readableHwm = options.readableHighWaterMark;
|
14859 | var defaultHwm = this.objectMode ? 16 : 16 * 1024;
|
14860 |
|
14861 | if (hwm || hwm === 0) this.highWaterMark = hwm;else if (isDuplex && (readableHwm || readableHwm === 0)) this.highWaterMark = readableHwm;else this.highWaterMark = defaultHwm;
|
14862 |
|
14863 |
|
14864 | this.highWaterMark = Math.floor(this.highWaterMark);
|
14865 |
|
14866 |
|
14867 |
|
14868 |
|
14869 | this.buffer = new BufferList();
|
14870 | this.length = 0;
|
14871 | this.pipes = null;
|
14872 | this.pipesCount = 0;
|
14873 | this.flowing = null;
|
14874 | this.ended = false;
|
14875 | this.endEmitted = false;
|
14876 | this.reading = false;
|
14877 |
|
14878 |
|
14879 |
|
14880 |
|
14881 |
|
14882 | this.sync = true;
|
14883 |
|
14884 |
|
14885 |
|
14886 | this.needReadable = false;
|
14887 | this.emittedReadable = false;
|
14888 | this.readableListening = false;
|
14889 | this.resumeScheduled = false;
|
14890 |
|
14891 |
|
14892 | this.destroyed = false;
|
14893 |
|
14894 |
|
14895 |
|
14896 |
|
14897 | this.defaultEncoding = options.defaultEncoding || 'utf8';
|
14898 |
|
14899 |
|
14900 | this.awaitDrain = 0;
|
14901 |
|
14902 |
|
14903 | this.readingMore = false;
|
14904 |
|
14905 | this.decoder = null;
|
14906 | this.encoding = null;
|
14907 | if (options.encoding) {
|
14908 | if (!StringDecoder) StringDecoder = _dereq_(97).StringDecoder;
|
14909 | this.decoder = new StringDecoder(options.encoding);
|
14910 | this.encoding = options.encoding;
|
14911 | }
|
14912 | }
|
14913 |
|
14914 | function Readable(options) {
|
14915 | Duplex = Duplex || _dereq_(84);
|
14916 |
|
14917 | if (!(this instanceof Readable)) return new Readable(options);
|
14918 |
|
14919 | this._readableState = new ReadableState(options, this);
|
14920 |
|
14921 |
|
14922 | this.readable = true;
|
14923 |
|
14924 | if (options) {
|
14925 | if (typeof options.read === 'function') this._read = options.read;
|
14926 |
|
14927 | if (typeof options.destroy === 'function') this._destroy = options.destroy;
|
14928 | }
|
14929 |
|
14930 | Stream.call(this);
|
14931 | }
|
14932 |
|
14933 | Object.defineProperty(Readable.prototype, 'destroyed', {
|
14934 | get: function () {
|
14935 | if (this._readableState === undefined) {
|
14936 | return false;
|
14937 | }
|
14938 | return this._readableState.destroyed;
|
14939 | },
|
14940 | set: function (value) {
|
14941 |
|
14942 |
|
14943 | if (!this._readableState) {
|
14944 | return;
|
14945 | }
|
14946 |
|
14947 |
|
14948 |
|
14949 | this._readableState.destroyed = value;
|
14950 | }
|
14951 | });
|
14952 |
|
14953 | Readable.prototype.destroy = destroyImpl.destroy;
|
14954 | Readable.prototype._undestroy = destroyImpl.undestroy;
|
14955 | Readable.prototype._destroy = function (err, cb) {
|
14956 | this.push(null);
|
14957 | cb(err);
|
14958 | };
|
14959 |
|
14960 |
|
14961 |
|
14962 |
|
14963 |
|
14964 | Readable.prototype.push = function (chunk, encoding) {
|
14965 | var state = this._readableState;
|
14966 | var skipChunkCheck;
|
14967 |
|
14968 | if (!state.objectMode) {
|
14969 | if (typeof chunk === 'string') {
|
14970 | encoding = encoding || state.defaultEncoding;
|
14971 | if (encoding !== state.encoding) {
|
14972 | chunk = Buffer.from(chunk, encoding);
|
14973 | encoding = '';
|
14974 | }
|
14975 | skipChunkCheck = true;
|
14976 | }
|
14977 | } else {
|
14978 | skipChunkCheck = true;
|
14979 | }
|
14980 |
|
14981 | return readableAddChunk(this, chunk, encoding, false, skipChunkCheck);
|
14982 | };
|
14983 |
|
14984 |
|
14985 | Readable.prototype.unshift = function (chunk) {
|
14986 | return readableAddChunk(this, chunk, null, true, false);
|
14987 | };
|
14988 |
|
14989 | function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) {
|
14990 | var state = stream._readableState;
|
14991 | if (chunk === null) {
|
14992 | state.reading = false;
|
14993 | onEofChunk(stream, state);
|
14994 | } else {
|
14995 | var er;
|
14996 | if (!skipChunkCheck) er = chunkInvalid(state, chunk);
|
14997 | if (er) {
|
14998 | stream.emit('error', er);
|
14999 | } else if (state.objectMode || chunk && chunk.length > 0) {
|
15000 | if (typeof chunk !== 'string' && !state.objectMode && Object.getPrototypeOf(chunk) !== Buffer.prototype) {
|
15001 | chunk = _uint8ArrayToBuffer(chunk);
|
15002 | }
|
15003 |
|
15004 | if (addToFront) {
|
15005 | if (state.endEmitted) stream.emit('error', new Error('stream.unshift() after end event'));else addChunk(stream, state, chunk, true);
|
15006 | } else if (state.ended) {
|
15007 | stream.emit('error', new Error('stream.push() after EOF'));
|
15008 | } else {
|
15009 | state.reading = false;
|
15010 | if (state.decoder && !encoding) {
|
15011 | chunk = state.decoder.write(chunk);
|
15012 | if (state.objectMode || chunk.length !== 0) addChunk(stream, state, chunk, false);else maybeReadMore(stream, state);
|
15013 | } else {
|
15014 | addChunk(stream, state, chunk, false);
|
15015 | }
|
15016 | }
|
15017 | } else if (!addToFront) {
|
15018 | state.reading = false;
|
15019 | }
|
15020 | }
|
15021 |
|
15022 | return needMoreData(state);
|
15023 | }
|
15024 |
|
15025 | function addChunk(stream, state, chunk, addToFront) {
|
15026 | if (state.flowing && state.length === 0 && !state.sync) {
|
15027 | stream.emit('data', chunk);
|
15028 | stream.read(0);
|
15029 | } else {
|
15030 |
|
15031 | state.length += state.objectMode ? 1 : chunk.length;
|
15032 | if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk);
|
15033 |
|
15034 | if (state.needReadable) emitReadable(stream);
|
15035 | }
|
15036 | maybeReadMore(stream, state);
|
15037 | }
|
15038 |
|
15039 | function chunkInvalid(state, chunk) {
|
15040 | var er;
|
15041 | if (!_isUint8Array(chunk) && typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
|
15042 | er = new TypeError('Invalid non-string/buffer chunk');
|
15043 | }
|
15044 | return er;
|
15045 | }
|
15046 |
|
15047 |
|
15048 |
|
15049 |
|
15050 |
|
15051 |
|
15052 |
|
15053 |
|
15054 | function needMoreData(state) {
|
15055 | return !state.ended && (state.needReadable || state.length < state.highWaterMark || state.length === 0);
|
15056 | }
|
15057 |
|
15058 | Readable.prototype.isPaused = function () {
|
15059 | return this._readableState.flowing === false;
|
15060 | };
|
15061 |
|
15062 |
|
15063 | Readable.prototype.setEncoding = function (enc) {
|
15064 | if (!StringDecoder) StringDecoder = _dereq_(97).StringDecoder;
|
15065 | this._readableState.decoder = new StringDecoder(enc);
|
15066 | this._readableState.encoding = enc;
|
15067 | return this;
|
15068 | };
|
15069 |
|
15070 |
|
15071 | var MAX_HWM = 0x800000;
|
15072 | function computeNewHighWaterMark(n) {
|
15073 | if (n >= MAX_HWM) {
|
15074 | n = MAX_HWM;
|
15075 | } else {
|
15076 |
|
15077 |
|
15078 | n--;
|
15079 | n |= n >>> 1;
|
15080 | n |= n >>> 2;
|
15081 | n |= n >>> 4;
|
15082 | n |= n >>> 8;
|
15083 | n |= n >>> 16;
|
15084 | n++;
|
15085 | }
|
15086 | return n;
|
15087 | }
|
15088 |
|
15089 |
|
15090 |
|
15091 | function howMuchToRead(n, state) {
|
15092 | if (n <= 0 || state.length === 0 && state.ended) return 0;
|
15093 | if (state.objectMode) return 1;
|
15094 | if (n !== n) {
|
15095 |
|
15096 | if (state.flowing && state.length) return state.buffer.head.data.length;else return state.length;
|
15097 | }
|
15098 |
|
15099 | if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n);
|
15100 | if (n <= state.length) return n;
|
15101 |
|
15102 | if (!state.ended) {
|
15103 | state.needReadable = true;
|
15104 | return 0;
|
15105 | }
|
15106 | return state.length;
|
15107 | }
|
15108 |
|
15109 |
|
15110 | Readable.prototype.read = function (n) {
|
15111 | debug('read', n);
|
15112 | n = parseInt(n, 10);
|
15113 | var state = this._readableState;
|
15114 | var nOrig = n;
|
15115 |
|
15116 | if (n !== 0) state.emittedReadable = false;
|
15117 |
|
15118 |
|
15119 |
|
15120 |
|
15121 | if (n === 0 && state.needReadable && (state.length >= state.highWaterMark || state.ended)) {
|
15122 | debug('read: emitReadable', state.length, state.ended);
|
15123 | if (state.length === 0 && state.ended) endReadable(this);else emitReadable(this);
|
15124 | return null;
|
15125 | }
|
15126 |
|
15127 | n = howMuchToRead(n, state);
|
15128 |
|
15129 |
|
15130 | if (n === 0 && state.ended) {
|
15131 | if (state.length === 0) endReadable(this);
|
15132 | return null;
|
15133 | }
|
15134 |
|
15135 |
|
15136 |
|
15137 |
|
15138 |
|
15139 |
|
15140 |
|
15141 |
|
15142 |
|
15143 |
|
15144 |
|
15145 |
|
15146 |
|
15147 |
|
15148 |
|
15149 |
|
15150 |
|
15151 |
|
15152 |
|
15153 |
|
15154 |
|
15155 |
|
15156 |
|
15157 |
|
15158 | var doRead = state.needReadable;
|
15159 | debug('need readable', doRead);
|
15160 |
|
15161 |
|
15162 | if (state.length === 0 || state.length - n < state.highWaterMark) {
|
15163 | doRead = true;
|
15164 | debug('length less than watermark', doRead);
|
15165 | }
|
15166 |
|
15167 |
|
15168 |
|
15169 | if (state.ended || state.reading) {
|
15170 | doRead = false;
|
15171 | debug('reading or ended', doRead);
|
15172 | } else if (doRead) {
|
15173 | debug('do read');
|
15174 | state.reading = true;
|
15175 | state.sync = true;
|
15176 |
|
15177 | if (state.length === 0) state.needReadable = true;
|
15178 |
|
15179 | this._read(state.highWaterMark);
|
15180 | state.sync = false;
|
15181 |
|
15182 |
|
15183 | if (!state.reading) n = howMuchToRead(nOrig, state);
|
15184 | }
|
15185 |
|
15186 | var ret;
|
15187 | if (n > 0) ret = fromList(n, state);else ret = null;
|
15188 |
|
15189 | if (ret === null) {
|
15190 | state.needReadable = true;
|
15191 | n = 0;
|
15192 | } else {
|
15193 | state.length -= n;
|
15194 | }
|
15195 |
|
15196 | if (state.length === 0) {
|
15197 |
|
15198 |
|
15199 | if (!state.ended) state.needReadable = true;
|
15200 |
|
15201 |
|
15202 | if (nOrig !== n && state.ended) endReadable(this);
|
15203 | }
|
15204 |
|
15205 | if (ret !== null) this.emit('data', ret);
|
15206 |
|
15207 | return ret;
|
15208 | };
|
15209 |
|
15210 | function onEofChunk(stream, state) {
|
15211 | if (state.ended) return;
|
15212 | if (state.decoder) {
|
15213 | var chunk = state.decoder.end();
|
15214 | if (chunk && chunk.length) {
|
15215 | state.buffer.push(chunk);
|
15216 | state.length += state.objectMode ? 1 : chunk.length;
|
15217 | }
|
15218 | }
|
15219 | state.ended = true;
|
15220 |
|
15221 |
|
15222 | emitReadable(stream);
|
15223 | }
|
15224 |
|
15225 |
|
15226 |
|
15227 |
|
15228 | function emitReadable(stream) {
|
15229 | var state = stream._readableState;
|
15230 | state.needReadable = false;
|
15231 | if (!state.emittedReadable) {
|
15232 | debug('emitReadable', state.flowing);
|
15233 | state.emittedReadable = true;
|
15234 | if (state.sync) pna.nextTick(emitReadable_, stream);else emitReadable_(stream);
|
15235 | }
|
15236 | }
|
15237 |
|
15238 | function emitReadable_(stream) {
|
15239 | debug('emit readable');
|
15240 | stream.emit('readable');
|
15241 | flow(stream);
|
15242 | }
|
15243 |
|
15244 |
|
15245 |
|
15246 |
|
15247 |
|
15248 |
|
15249 |
|
15250 | function maybeReadMore(stream, state) {
|
15251 | if (!state.readingMore) {
|
15252 | state.readingMore = true;
|
15253 | pna.nextTick(maybeReadMore_, stream, state);
|
15254 | }
|
15255 | }
|
15256 |
|
15257 | function maybeReadMore_(stream, state) {
|
15258 | var len = state.length;
|
15259 | while (!state.reading && !state.flowing && !state.ended && state.length < state.highWaterMark) {
|
15260 | debug('maybeReadMore read 0');
|
15261 | stream.read(0);
|
15262 | if (len === state.length)
|
15263 |
|
15264 | break;else len = state.length;
|
15265 | }
|
15266 | state.readingMore = false;
|
15267 | }
|
15268 |
|
15269 |
|
15270 |
|
15271 |
|
15272 |
|
15273 | Readable.prototype._read = function (n) {
|
15274 | this.emit('error', new Error('_read() is not implemented'));
|
15275 | };
|
15276 |
|
15277 | Readable.prototype.pipe = function (dest, pipeOpts) {
|
15278 | var src = this;
|
15279 | var state = this._readableState;
|
15280 |
|
15281 | switch (state.pipesCount) {
|
15282 | case 0:
|
15283 | state.pipes = dest;
|
15284 | break;
|
15285 | case 1:
|
15286 | state.pipes = [state.pipes, dest];
|
15287 | break;
|
15288 | default:
|
15289 | state.pipes.push(dest);
|
15290 | break;
|
15291 | }
|
15292 | state.pipesCount += 1;
|
15293 | debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts);
|
15294 |
|
15295 | var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr;
|
15296 |
|
15297 | var endFn = doEnd ? onend : unpipe;
|
15298 | if (state.endEmitted) pna.nextTick(endFn);else src.once('end', endFn);
|
15299 |
|
15300 | dest.on('unpipe', onunpipe);
|
15301 | function onunpipe(readable, unpipeInfo) {
|
15302 | debug('onunpipe');
|
15303 | if (readable === src) {
|
15304 | if (unpipeInfo && unpipeInfo.hasUnpiped === false) {
|
15305 | unpipeInfo.hasUnpiped = true;
|
15306 | cleanup();
|
15307 | }
|
15308 | }
|
15309 | }
|
15310 |
|
15311 | function onend() {
|
15312 | debug('onend');
|
15313 | dest.end();
|
15314 | }
|
15315 |
|
15316 |
|
15317 |
|
15318 |
|
15319 |
|
15320 | var ondrain = pipeOnDrain(src);
|
15321 | dest.on('drain', ondrain);
|
15322 |
|
15323 | var cleanedUp = false;
|
15324 | function cleanup() {
|
15325 | debug('cleanup');
|
15326 |
|
15327 | dest.removeListener('close', onclose);
|
15328 | dest.removeListener('finish', onfinish);
|
15329 | dest.removeListener('drain', ondrain);
|
15330 | dest.removeListener('error', onerror);
|
15331 | dest.removeListener('unpipe', onunpipe);
|
15332 | src.removeListener('end', onend);
|
15333 | src.removeListener('end', unpipe);
|
15334 | src.removeListener('data', ondata);
|
15335 |
|
15336 | cleanedUp = true;
|
15337 |
|
15338 |
|
15339 |
|
15340 |
|
15341 |
|
15342 |
|
15343 | if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain();
|
15344 | }
|
15345 |
|
15346 |
|
15347 |
|
15348 |
|
15349 |
|
15350 | var increasedAwaitDrain = false;
|
15351 | src.on('data', ondata);
|
15352 | function ondata(chunk) {
|
15353 | debug('ondata');
|
15354 | increasedAwaitDrain = false;
|
15355 | var ret = dest.write(chunk);
|
15356 | if (false === ret && !increasedAwaitDrain) {
|
15357 |
|
15358 |
|
15359 |
|
15360 |
|
15361 | if ((state.pipesCount === 1 && state.pipes === dest || state.pipesCount > 1 && indexOf(state.pipes, dest) !== -1) && !cleanedUp) {
|
15362 | debug('false write response, pause', src._readableState.awaitDrain);
|
15363 | src._readableState.awaitDrain++;
|
15364 | increasedAwaitDrain = true;
|
15365 | }
|
15366 | src.pause();
|
15367 | }
|
15368 | }
|
15369 |
|
15370 |
|
15371 |
|
15372 | function onerror(er) {
|
15373 | debug('onerror', er);
|
15374 | unpipe();
|
15375 | dest.removeListener('error', onerror);
|
15376 | if (EElistenerCount(dest, 'error') === 0) dest.emit('error', er);
|
15377 | }
|
15378 |
|
15379 |
|
15380 | prependListener(dest, 'error', onerror);
|
15381 |
|
15382 |
|
15383 | function onclose() {
|
15384 | dest.removeListener('finish', onfinish);
|
15385 | unpipe();
|
15386 | }
|
15387 | dest.once('close', onclose);
|
15388 | function onfinish() {
|
15389 | debug('onfinish');
|
15390 | dest.removeListener('close', onclose);
|
15391 | unpipe();
|
15392 | }
|
15393 | dest.once('finish', onfinish);
|
15394 |
|
15395 | function unpipe() {
|
15396 | debug('unpipe');
|
15397 | src.unpipe(dest);
|
15398 | }
|
15399 |
|
15400 |
|
15401 | dest.emit('pipe', src);
|
15402 |
|
15403 |
|
15404 | if (!state.flowing) {
|
15405 | debug('pipe resume');
|
15406 | src.resume();
|
15407 | }
|
15408 |
|
15409 | return dest;
|
15410 | };
|
15411 |
|
15412 | function pipeOnDrain(src) {
|
15413 | return function () {
|
15414 | var state = src._readableState;
|
15415 | debug('pipeOnDrain', state.awaitDrain);
|
15416 | if (state.awaitDrain) state.awaitDrain--;
|
15417 | if (state.awaitDrain === 0 && EElistenerCount(src, 'data')) {
|
15418 | state.flowing = true;
|
15419 | flow(src);
|
15420 | }
|
15421 | };
|
15422 | }
|
15423 |
|
15424 | Readable.prototype.unpipe = function (dest) {
|
15425 | var state = this._readableState;
|
15426 | var unpipeInfo = { hasUnpiped: false };
|
15427 |
|
15428 |
|
15429 | if (state.pipesCount === 0) return this;
|
15430 |
|
15431 |
|
15432 | if (state.pipesCount === 1) {
|
15433 |
|
15434 | if (dest && dest !== state.pipes) return this;
|
15435 |
|
15436 | if (!dest) dest = state.pipes;
|
15437 |
|
15438 |
|
15439 | state.pipes = null;
|
15440 | state.pipesCount = 0;
|
15441 | state.flowing = false;
|
15442 | if (dest) dest.emit('unpipe', this, unpipeInfo);
|
15443 | return this;
|
15444 | }
|
15445 |
|
15446 |
|
15447 |
|
15448 | if (!dest) {
|
15449 |
|
15450 | var dests = state.pipes;
|
15451 | var len = state.pipesCount;
|
15452 | state.pipes = null;
|
15453 | state.pipesCount = 0;
|
15454 | state.flowing = false;
|
15455 |
|
15456 | for (var i = 0; i < len; i++) {
|
15457 | dests[i].emit('unpipe', this, unpipeInfo);
|
15458 | }return this;
|
15459 | }
|
15460 |
|
15461 |
|
15462 | var index = indexOf(state.pipes, dest);
|
15463 | if (index === -1) return this;
|
15464 |
|
15465 | state.pipes.splice(index, 1);
|
15466 | state.pipesCount -= 1;
|
15467 | if (state.pipesCount === 1) state.pipes = state.pipes[0];
|
15468 |
|
15469 | dest.emit('unpipe', this, unpipeInfo);
|
15470 |
|
15471 | return this;
|
15472 | };
|
15473 |
|
15474 |
|
15475 |
|
15476 | Readable.prototype.on = function (ev, fn) {
|
15477 | var res = Stream.prototype.on.call(this, ev, fn);
|
15478 |
|
15479 | if (ev === 'data') {
|
15480 |
|
15481 | if (this._readableState.flowing !== false) this.resume();
|
15482 | } else if (ev === 'readable') {
|
15483 | var state = this._readableState;
|
15484 | if (!state.endEmitted && !state.readableListening) {
|
15485 | state.readableListening = state.needReadable = true;
|
15486 | state.emittedReadable = false;
|
15487 | if (!state.reading) {
|
15488 | pna.nextTick(nReadingNextTick, this);
|
15489 | } else if (state.length) {
|
15490 | emitReadable(this);
|
15491 | }
|
15492 | }
|
15493 | }
|
15494 |
|
15495 | return res;
|
15496 | };
|
15497 | Readable.prototype.addListener = Readable.prototype.on;
|
15498 |
|
15499 | function nReadingNextTick(self) {
|
15500 | debug('readable nexttick read 0');
|
15501 | self.read(0);
|
15502 | }
|
15503 |
|
15504 |
|
15505 |
|
15506 | Readable.prototype.resume = function () {
|
15507 | var state = this._readableState;
|
15508 | if (!state.flowing) {
|
15509 | debug('resume');
|
15510 | state.flowing = true;
|
15511 | resume(this, state);
|
15512 | }
|
15513 | return this;
|
15514 | };
|
15515 |
|
15516 | function resume(stream, state) {
|
15517 | if (!state.resumeScheduled) {
|
15518 | state.resumeScheduled = true;
|
15519 | pna.nextTick(resume_, stream, state);
|
15520 | }
|
15521 | }
|
15522 |
|
15523 | function resume_(stream, state) {
|
15524 | if (!state.reading) {
|
15525 | debug('resume read 0');
|
15526 | stream.read(0);
|
15527 | }
|
15528 |
|
15529 | state.resumeScheduled = false;
|
15530 | state.awaitDrain = 0;
|
15531 | stream.emit('resume');
|
15532 | flow(stream);
|
15533 | if (state.flowing && !state.reading) stream.read(0);
|
15534 | }
|
15535 |
|
15536 | Readable.prototype.pause = function () {
|
15537 | debug('call pause flowing=%j', this._readableState.flowing);
|
15538 | if (false !== this._readableState.flowing) {
|
15539 | debug('pause');
|
15540 | this._readableState.flowing = false;
|
15541 | this.emit('pause');
|
15542 | }
|
15543 | return this;
|
15544 | };
|
15545 |
|
15546 | function flow(stream) {
|
15547 | var state = stream._readableState;
|
15548 | debug('flow', state.flowing);
|
15549 | while (state.flowing && stream.read() !== null) {}
|
15550 | }
|
15551 |
|
15552 |
|
15553 |
|
15554 |
|
15555 | Readable.prototype.wrap = function (stream) {
|
15556 | var _this = this;
|
15557 |
|
15558 | var state = this._readableState;
|
15559 | var paused = false;
|
15560 |
|
15561 | stream.on('end', function () {
|
15562 | debug('wrapped end');
|
15563 | if (state.decoder && !state.ended) {
|
15564 | var chunk = state.decoder.end();
|
15565 | if (chunk && chunk.length) _this.push(chunk);
|
15566 | }
|
15567 |
|
15568 | _this.push(null);
|
15569 | });
|
15570 |
|
15571 | stream.on('data', function (chunk) {
|
15572 | debug('wrapped data');
|
15573 | if (state.decoder) chunk = state.decoder.write(chunk);
|
15574 |
|
15575 |
|
15576 | if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return;
|
15577 |
|
15578 | var ret = _this.push(chunk);
|
15579 | if (!ret) {
|
15580 | paused = true;
|
15581 | stream.pause();
|
15582 | }
|
15583 | });
|
15584 |
|
15585 |
|
15586 |
|
15587 | for (var i in stream) {
|
15588 | if (this[i] === undefined && typeof stream[i] === 'function') {
|
15589 | this[i] = function (method) {
|
15590 | return function () {
|
15591 | return stream[method].apply(stream, arguments);
|
15592 | };
|
15593 | }(i);
|
15594 | }
|
15595 | }
|
15596 |
|
15597 |
|
15598 | for (var n = 0; n < kProxyEvents.length; n++) {
|
15599 | stream.on(kProxyEvents[n], this.emit.bind(this, kProxyEvents[n]));
|
15600 | }
|
15601 |
|
15602 |
|
15603 |
|
15604 | this._read = function (n) {
|
15605 | debug('wrapped _read', n);
|
15606 | if (paused) {
|
15607 | paused = false;
|
15608 | stream.resume();
|
15609 | }
|
15610 | };
|
15611 |
|
15612 | return this;
|
15613 | };
|
15614 |
|
15615 | Object.defineProperty(Readable.prototype, 'readableHighWaterMark', {
|
15616 |
|
15617 |
|
15618 |
|
15619 | enumerable: false,
|
15620 | get: function () {
|
15621 | return this._readableState.highWaterMark;
|
15622 | }
|
15623 | });
|
15624 |
|
15625 |
|
15626 | Readable._fromList = fromList;
|
15627 |
|
15628 |
|
15629 |
|
15630 |
|
15631 |
|
15632 | function fromList(n, state) {
|
15633 |
|
15634 | if (state.length === 0) return null;
|
15635 |
|
15636 | var ret;
|
15637 | if (state.objectMode) ret = state.buffer.shift();else if (!n || n >= state.length) {
|
15638 |
|
15639 | 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);
|
15640 | state.buffer.clear();
|
15641 | } else {
|
15642 |
|
15643 | ret = fromListPartial(n, state.buffer, state.decoder);
|
15644 | }
|
15645 |
|
15646 | return ret;
|
15647 | }
|
15648 |
|
15649 |
|
15650 |
|
15651 |
|
15652 | function fromListPartial(n, list, hasStrings) {
|
15653 | var ret;
|
15654 | if (n < list.head.data.length) {
|
15655 |
|
15656 | ret = list.head.data.slice(0, n);
|
15657 | list.head.data = list.head.data.slice(n);
|
15658 | } else if (n === list.head.data.length) {
|
15659 |
|
15660 | ret = list.shift();
|
15661 | } else {
|
15662 |
|
15663 | ret = hasStrings ? copyFromBufferString(n, list) : copyFromBuffer(n, list);
|
15664 | }
|
15665 | return ret;
|
15666 | }
|
15667 |
|
15668 |
|
15669 |
|
15670 |
|
15671 |
|
15672 | function copyFromBufferString(n, list) {
|
15673 | var p = list.head;
|
15674 | var c = 1;
|
15675 | var ret = p.data;
|
15676 | n -= ret.length;
|
15677 | while (p = p.next) {
|
15678 | var str = p.data;
|
15679 | var nb = n > str.length ? str.length : n;
|
15680 | if (nb === str.length) ret += str;else ret += str.slice(0, n);
|
15681 | n -= nb;
|
15682 | if (n === 0) {
|
15683 | if (nb === str.length) {
|
15684 | ++c;
|
15685 | if (p.next) list.head = p.next;else list.head = list.tail = null;
|
15686 | } else {
|
15687 | list.head = p;
|
15688 | p.data = str.slice(nb);
|
15689 | }
|
15690 | break;
|
15691 | }
|
15692 | ++c;
|
15693 | }
|
15694 | list.length -= c;
|
15695 | return ret;
|
15696 | }
|
15697 |
|
15698 |
|
15699 |
|
15700 |
|
15701 | function copyFromBuffer(n, list) {
|
15702 | var ret = Buffer.allocUnsafe(n);
|
15703 | var p = list.head;
|
15704 | var c = 1;
|
15705 | p.data.copy(ret);
|
15706 | n -= p.data.length;
|
15707 | while (p = p.next) {
|
15708 | var buf = p.data;
|
15709 | var nb = n > buf.length ? buf.length : n;
|
15710 | buf.copy(ret, ret.length - n, 0, nb);
|
15711 | n -= nb;
|
15712 | if (n === 0) {
|
15713 | if (nb === buf.length) {
|
15714 | ++c;
|
15715 | if (p.next) list.head = p.next;else list.head = list.tail = null;
|
15716 | } else {
|
15717 | list.head = p;
|
15718 | p.data = buf.slice(nb);
|
15719 | }
|
15720 | break;
|
15721 | }
|
15722 | ++c;
|
15723 | }
|
15724 | list.length -= c;
|
15725 | return ret;
|
15726 | }
|
15727 |
|
15728 | function endReadable(stream) {
|
15729 | var state = stream._readableState;
|
15730 |
|
15731 |
|
15732 |
|
15733 | if (state.length > 0) throw new Error('"endReadable()" called on non-empty stream');
|
15734 |
|
15735 | if (!state.endEmitted) {
|
15736 | state.ended = true;
|
15737 | pna.nextTick(endReadableNT, state, stream);
|
15738 | }
|
15739 | }
|
15740 |
|
15741 | function endReadableNT(state, stream) {
|
15742 |
|
15743 | if (!state.endEmitted && state.length === 0) {
|
15744 | state.endEmitted = true;
|
15745 | stream.readable = false;
|
15746 | stream.emit('end');
|
15747 | }
|
15748 | }
|
15749 |
|
15750 | function indexOf(xs, x) {
|
15751 | for (var i = 0, l = xs.length; i < l; i++) {
|
15752 | if (xs[i] === x) return i;
|
15753 | }
|
15754 | return -1;
|
15755 | }
|
15756 | }).call(this,_dereq_(70),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
15757 | },{"10":10,"14":14,"18":18,"69":69,"7":7,"70":70,"82":82,"84":84,"89":89,"90":90,"91":91,"96":96,"97":97}],87:[function(_dereq_,module,exports){
|
15758 |
|
15759 |
|
15760 |
|
15761 |
|
15762 |
|
15763 |
|
15764 |
|
15765 |
|
15766 |
|
15767 |
|
15768 |
|
15769 |
|
15770 |
|
15771 |
|
15772 |
|
15773 |
|
15774 |
|
15775 |
|
15776 |
|
15777 |
|
15778 |
|
15779 |
|
15780 |
|
15781 |
|
15782 |
|
15783 |
|
15784 |
|
15785 |
|
15786 |
|
15787 |
|
15788 |
|
15789 |
|
15790 |
|
15791 |
|
15792 |
|
15793 |
|
15794 |
|
15795 |
|
15796 |
|
15797 |
|
15798 |
|
15799 |
|
15800 |
|
15801 |
|
15802 |
|
15803 |
|
15804 |
|
15805 |
|
15806 |
|
15807 |
|
15808 |
|
15809 |
|
15810 |
|
15811 |
|
15812 |
|
15813 |
|
15814 |
|
15815 |
|
15816 |
|
15817 |
|
15818 |
|
15819 |
|
15820 |
|
15821 | 'use strict';
|
15822 |
|
15823 | module.exports = Transform;
|
15824 |
|
15825 | var Duplex = _dereq_(84);
|
15826 |
|
15827 |
|
15828 | var util = Object.create(_dereq_(10));
|
15829 | util.inherits = _dereq_(18);
|
15830 |
|
15831 |
|
15832 | util.inherits(Transform, Duplex);
|
15833 |
|
15834 | function afterTransform(er, data) {
|
15835 | var ts = this._transformState;
|
15836 | ts.transforming = false;
|
15837 |
|
15838 | var cb = ts.writecb;
|
15839 |
|
15840 | if (!cb) {
|
15841 | return this.emit('error', new Error('write callback called multiple times'));
|
15842 | }
|
15843 |
|
15844 | ts.writechunk = null;
|
15845 | ts.writecb = null;
|
15846 |
|
15847 | if (data != null)
|
15848 | this.push(data);
|
15849 |
|
15850 | cb(er);
|
15851 |
|
15852 | var rs = this._readableState;
|
15853 | rs.reading = false;
|
15854 | if (rs.needReadable || rs.length < rs.highWaterMark) {
|
15855 | this._read(rs.highWaterMark);
|
15856 | }
|
15857 | }
|
15858 |
|
15859 | function Transform(options) {
|
15860 | if (!(this instanceof Transform)) return new Transform(options);
|
15861 |
|
15862 | Duplex.call(this, options);
|
15863 |
|
15864 | this._transformState = {
|
15865 | afterTransform: afterTransform.bind(this),
|
15866 | needTransform: false,
|
15867 | transforming: false,
|
15868 | writecb: null,
|
15869 | writechunk: null,
|
15870 | writeencoding: null
|
15871 | };
|
15872 |
|
15873 |
|
15874 | this._readableState.needReadable = true;
|
15875 |
|
15876 |
|
15877 |
|
15878 |
|
15879 | this._readableState.sync = false;
|
15880 |
|
15881 | if (options) {
|
15882 | if (typeof options.transform === 'function') this._transform = options.transform;
|
15883 |
|
15884 | if (typeof options.flush === 'function') this._flush = options.flush;
|
15885 | }
|
15886 |
|
15887 |
|
15888 | this.on('prefinish', prefinish);
|
15889 | }
|
15890 |
|
15891 | function prefinish() {
|
15892 | var _this = this;
|
15893 |
|
15894 | if (typeof this._flush === 'function') {
|
15895 | this._flush(function (er, data) {
|
15896 | done(_this, er, data);
|
15897 | });
|
15898 | } else {
|
15899 | done(this, null, null);
|
15900 | }
|
15901 | }
|
15902 |
|
15903 | Transform.prototype.push = function (chunk, encoding) {
|
15904 | this._transformState.needTransform = false;
|
15905 | return Duplex.prototype.push.call(this, chunk, encoding);
|
15906 | };
|
15907 |
|
15908 |
|
15909 |
|
15910 |
|
15911 |
|
15912 |
|
15913 |
|
15914 |
|
15915 |
|
15916 |
|
15917 |
|
15918 | Transform.prototype._transform = function (chunk, encoding, cb) {
|
15919 | throw new Error('_transform() is not implemented');
|
15920 | };
|
15921 |
|
15922 | Transform.prototype._write = function (chunk, encoding, cb) {
|
15923 | var ts = this._transformState;
|
15924 | ts.writecb = cb;
|
15925 | ts.writechunk = chunk;
|
15926 | ts.writeencoding = encoding;
|
15927 | if (!ts.transforming) {
|
15928 | var rs = this._readableState;
|
15929 | if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) this._read(rs.highWaterMark);
|
15930 | }
|
15931 | };
|
15932 |
|
15933 |
|
15934 |
|
15935 |
|
15936 | Transform.prototype._read = function (n) {
|
15937 | var ts = this._transformState;
|
15938 |
|
15939 | if (ts.writechunk !== null && ts.writecb && !ts.transforming) {
|
15940 | ts.transforming = true;
|
15941 | this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
|
15942 | } else {
|
15943 |
|
15944 |
|
15945 | ts.needTransform = true;
|
15946 | }
|
15947 | };
|
15948 |
|
15949 | Transform.prototype._destroy = function (err, cb) {
|
15950 | var _this2 = this;
|
15951 |
|
15952 | Duplex.prototype._destroy.call(this, err, function (err2) {
|
15953 | cb(err2);
|
15954 | _this2.emit('close');
|
15955 | });
|
15956 | };
|
15957 |
|
15958 | function done(stream, er, data) {
|
15959 | if (er) return stream.emit('error', er);
|
15960 |
|
15961 | if (data != null)
|
15962 | stream.push(data);
|
15963 |
|
15964 |
|
15965 |
|
15966 | if (stream._writableState.length) throw new Error('Calling transform done when ws.length != 0');
|
15967 |
|
15968 | if (stream._transformState.transforming) throw new Error('Calling transform done when still transforming');
|
15969 |
|
15970 | return stream.push(null);
|
15971 | }
|
15972 | },{"10":10,"18":18,"84":84}],88:[function(_dereq_,module,exports){
|
15973 | (function (process,global,setImmediate){
|
15974 |
|
15975 |
|
15976 |
|
15977 |
|
15978 |
|
15979 |
|
15980 |
|
15981 |
|
15982 |
|
15983 |
|
15984 |
|
15985 |
|
15986 |
|
15987 |
|
15988 |
|
15989 |
|
15990 |
|
15991 |
|
15992 |
|
15993 |
|
15994 |
|
15995 |
|
15996 |
|
15997 |
|
15998 |
|
15999 | 'use strict';
|
16000 |
|
16001 |
|
16002 |
|
16003 | var pna = _dereq_(69);
|
16004 |
|
16005 |
|
16006 | module.exports = Writable;
|
16007 |
|
16008 |
|
16009 | function WriteReq(chunk, encoding, cb) {
|
16010 | this.chunk = chunk;
|
16011 | this.encoding = encoding;
|
16012 | this.callback = cb;
|
16013 | this.next = null;
|
16014 | }
|
16015 |
|
16016 |
|
16017 |
|
16018 | function CorkedRequest(state) {
|
16019 | var _this = this;
|
16020 |
|
16021 | this.next = null;
|
16022 | this.entry = null;
|
16023 | this.finish = function () {
|
16024 | onCorkedFinish(_this, state);
|
16025 | };
|
16026 | }
|
16027 |
|
16028 |
|
16029 |
|
16030 | var asyncWrite = !process.browser && ['v0.10', 'v0.9.'].indexOf(process.version.slice(0, 5)) > -1 ? setImmediate : pna.nextTick;
|
16031 |
|
16032 |
|
16033 |
|
16034 | var Duplex;
|
16035 |
|
16036 |
|
16037 | Writable.WritableState = WritableState;
|
16038 |
|
16039 |
|
16040 | var util = Object.create(_dereq_(10));
|
16041 | util.inherits = _dereq_(18);
|
16042 |
|
16043 |
|
16044 |
|
16045 | var internalUtil = {
|
16046 | deprecate: _dereq_(116)
|
16047 | };
|
16048 |
|
16049 |
|
16050 |
|
16051 | var Stream = _dereq_(91);
|
16052 |
|
16053 |
|
16054 |
|
16055 |
|
16056 | var Buffer = _dereq_(96).Buffer;
|
16057 | var OurUint8Array = global.Uint8Array || function () {};
|
16058 | function _uint8ArrayToBuffer(chunk) {
|
16059 | return Buffer.from(chunk);
|
16060 | }
|
16061 | function _isUint8Array(obj) {
|
16062 | return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
|
16063 | }
|
16064 |
|
16065 |
|
16066 |
|
16067 | var destroyImpl = _dereq_(90);
|
16068 |
|
16069 | util.inherits(Writable, Stream);
|
16070 |
|
16071 | function nop() {}
|
16072 |
|
16073 | function WritableState(options, stream) {
|
16074 | Duplex = Duplex || _dereq_(84);
|
16075 |
|
16076 | options = options || {};
|
16077 |
|
16078 |
|
16079 |
|
16080 |
|
16081 |
|
16082 |
|
16083 | var isDuplex = stream instanceof Duplex;
|
16084 |
|
16085 |
|
16086 |
|
16087 | this.objectMode = !!options.objectMode;
|
16088 |
|
16089 | if (isDuplex) this.objectMode = this.objectMode || !!options.writableObjectMode;
|
16090 |
|
16091 |
|
16092 |
|
16093 |
|
16094 | var hwm = options.highWaterMark;
|
16095 | var writableHwm = options.writableHighWaterMark;
|
16096 | var defaultHwm = this.objectMode ? 16 : 16 * 1024;
|
16097 |
|
16098 | if (hwm || hwm === 0) this.highWaterMark = hwm;else if (isDuplex && (writableHwm || writableHwm === 0)) this.highWaterMark = writableHwm;else this.highWaterMark = defaultHwm;
|
16099 |
|
16100 |
|
16101 | this.highWaterMark = Math.floor(this.highWaterMark);
|
16102 |
|
16103 |
|
16104 | this.finalCalled = false;
|
16105 |
|
16106 |
|
16107 | this.needDrain = false;
|
16108 |
|
16109 | this.ending = false;
|
16110 |
|
16111 | this.ended = false;
|
16112 |
|
16113 | this.finished = false;
|
16114 |
|
16115 |
|
16116 | this.destroyed = false;
|
16117 |
|
16118 |
|
16119 |
|
16120 |
|
16121 | var noDecode = options.decodeStrings === false;
|
16122 | this.decodeStrings = !noDecode;
|
16123 |
|
16124 |
|
16125 |
|
16126 |
|
16127 | this.defaultEncoding = options.defaultEncoding || 'utf8';
|
16128 |
|
16129 |
|
16130 |
|
16131 |
|
16132 | this.length = 0;
|
16133 |
|
16134 |
|
16135 | this.writing = false;
|
16136 |
|
16137 |
|
16138 | this.corked = 0;
|
16139 |
|
16140 |
|
16141 |
|
16142 |
|
16143 |
|
16144 | this.sync = true;
|
16145 |
|
16146 |
|
16147 |
|
16148 |
|
16149 | this.bufferProcessing = false;
|
16150 |
|
16151 |
|
16152 | this.onwrite = function (er) {
|
16153 | onwrite(stream, er);
|
16154 | };
|
16155 |
|
16156 |
|
16157 | this.writecb = null;
|
16158 |
|
16159 |
|
16160 | this.writelen = 0;
|
16161 |
|
16162 | this.bufferedRequest = null;
|
16163 | this.lastBufferedRequest = null;
|
16164 |
|
16165 |
|
16166 |
|
16167 | this.pendingcb = 0;
|
16168 |
|
16169 |
|
16170 |
|
16171 | this.prefinished = false;
|
16172 |
|
16173 |
|
16174 | this.errorEmitted = false;
|
16175 |
|
16176 |
|
16177 | this.bufferedRequestCount = 0;
|
16178 |
|
16179 |
|
16180 |
|
16181 | this.corkedRequestsFree = new CorkedRequest(this);
|
16182 | }
|
16183 |
|
16184 | WritableState.prototype.getBuffer = function getBuffer() {
|
16185 | var current = this.bufferedRequest;
|
16186 | var out = [];
|
16187 | while (current) {
|
16188 | out.push(current);
|
16189 | current = current.next;
|
16190 | }
|
16191 | return out;
|
16192 | };
|
16193 |
|
16194 | (function () {
|
16195 | try {
|
16196 | Object.defineProperty(WritableState.prototype, 'buffer', {
|
16197 | get: internalUtil.deprecate(function () {
|
16198 | return this.getBuffer();
|
16199 | }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.', 'DEP0003')
|
16200 | });
|
16201 | } catch (_) {}
|
16202 | })();
|
16203 |
|
16204 |
|
16205 |
|
16206 | var realHasInstance;
|
16207 | if (typeof Symbol === 'function' && Symbol.hasInstance && typeof Function.prototype[Symbol.hasInstance] === 'function') {
|
16208 | realHasInstance = Function.prototype[Symbol.hasInstance];
|
16209 | Object.defineProperty(Writable, Symbol.hasInstance, {
|
16210 | value: function (object) {
|
16211 | if (realHasInstance.call(this, object)) return true;
|
16212 | if (this !== Writable) return false;
|
16213 |
|
16214 | return object && object._writableState instanceof WritableState;
|
16215 | }
|
16216 | });
|
16217 | } else {
|
16218 | realHasInstance = function (object) {
|
16219 | return object instanceof this;
|
16220 | };
|
16221 | }
|
16222 |
|
16223 | function Writable(options) {
|
16224 | Duplex = Duplex || _dereq_(84);
|
16225 |
|
16226 |
|
16227 |
|
16228 |
|
16229 |
|
16230 |
|
16231 |
|
16232 |
|
16233 | if (!realHasInstance.call(Writable, this) && !(this instanceof Duplex)) {
|
16234 | return new Writable(options);
|
16235 | }
|
16236 |
|
16237 | this._writableState = new WritableState(options, this);
|
16238 |
|
16239 |
|
16240 | this.writable = true;
|
16241 |
|
16242 | if (options) {
|
16243 | if (typeof options.write === 'function') this._write = options.write;
|
16244 |
|
16245 | if (typeof options.writev === 'function') this._writev = options.writev;
|
16246 |
|
16247 | if (typeof options.destroy === 'function') this._destroy = options.destroy;
|
16248 |
|
16249 | if (typeof options.final === 'function') this._final = options.final;
|
16250 | }
|
16251 |
|
16252 | Stream.call(this);
|
16253 | }
|
16254 |
|
16255 |
|
16256 | Writable.prototype.pipe = function () {
|
16257 | this.emit('error', new Error('Cannot pipe, not readable'));
|
16258 | };
|
16259 |
|
16260 | function writeAfterEnd(stream, cb) {
|
16261 | var er = new Error('write after end');
|
16262 |
|
16263 | stream.emit('error', er);
|
16264 | pna.nextTick(cb, er);
|
16265 | }
|
16266 |
|
16267 |
|
16268 |
|
16269 |
|
16270 | function validChunk(stream, state, chunk, cb) {
|
16271 | var valid = true;
|
16272 | var er = false;
|
16273 |
|
16274 | if (chunk === null) {
|
16275 | er = new TypeError('May not write null values to stream');
|
16276 | } else if (typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
|
16277 | er = new TypeError('Invalid non-string/buffer chunk');
|
16278 | }
|
16279 | if (er) {
|
16280 | stream.emit('error', er);
|
16281 | pna.nextTick(cb, er);
|
16282 | valid = false;
|
16283 | }
|
16284 | return valid;
|
16285 | }
|
16286 |
|
16287 | Writable.prototype.write = function (chunk, encoding, cb) {
|
16288 | var state = this._writableState;
|
16289 | var ret = false;
|
16290 | var isBuf = !state.objectMode && _isUint8Array(chunk);
|
16291 |
|
16292 | if (isBuf && !Buffer.isBuffer(chunk)) {
|
16293 | chunk = _uint8ArrayToBuffer(chunk);
|
16294 | }
|
16295 |
|
16296 | if (typeof encoding === 'function') {
|
16297 | cb = encoding;
|
16298 | encoding = null;
|
16299 | }
|
16300 |
|
16301 | if (isBuf) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding;
|
16302 |
|
16303 | if (typeof cb !== 'function') cb = nop;
|
16304 |
|
16305 | if (state.ended) writeAfterEnd(this, cb);else if (isBuf || validChunk(this, state, chunk, cb)) {
|
16306 | state.pendingcb++;
|
16307 | ret = writeOrBuffer(this, state, isBuf, chunk, encoding, cb);
|
16308 | }
|
16309 |
|
16310 | return ret;
|
16311 | };
|
16312 |
|
16313 | Writable.prototype.cork = function () {
|
16314 | var state = this._writableState;
|
16315 |
|
16316 | state.corked++;
|
16317 | };
|
16318 |
|
16319 | Writable.prototype.uncork = function () {
|
16320 | var state = this._writableState;
|
16321 |
|
16322 | if (state.corked) {
|
16323 | state.corked--;
|
16324 |
|
16325 | if (!state.writing && !state.corked && !state.finished && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state);
|
16326 | }
|
16327 | };
|
16328 |
|
16329 | Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
|
16330 |
|
16331 | if (typeof encoding === 'string') encoding = encoding.toLowerCase();
|
16332 | if (!(['hex', 'utf8', 'utf-8', 'ascii', 'binary', 'base64', 'ucs2', 'ucs-2', 'utf16le', 'utf-16le', 'raw'].indexOf((encoding + '').toLowerCase()) > -1)) throw new TypeError('Unknown encoding: ' + encoding);
|
16333 | this._writableState.defaultEncoding = encoding;
|
16334 | return this;
|
16335 | };
|
16336 |
|
16337 | function decodeChunk(state, chunk, encoding) {
|
16338 | if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') {
|
16339 | chunk = Buffer.from(chunk, encoding);
|
16340 | }
|
16341 | return chunk;
|
16342 | }
|
16343 |
|
16344 | Object.defineProperty(Writable.prototype, 'writableHighWaterMark', {
|
16345 |
|
16346 |
|
16347 |
|
16348 | enumerable: false,
|
16349 | get: function () {
|
16350 | return this._writableState.highWaterMark;
|
16351 | }
|
16352 | });
|
16353 |
|
16354 |
|
16355 |
|
16356 |
|
16357 | function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) {
|
16358 | if (!isBuf) {
|
16359 | var newChunk = decodeChunk(state, chunk, encoding);
|
16360 | if (chunk !== newChunk) {
|
16361 | isBuf = true;
|
16362 | encoding = 'buffer';
|
16363 | chunk = newChunk;
|
16364 | }
|
16365 | }
|
16366 | var len = state.objectMode ? 1 : chunk.length;
|
16367 |
|
16368 | state.length += len;
|
16369 |
|
16370 | var ret = state.length < state.highWaterMark;
|
16371 |
|
16372 | if (!ret) state.needDrain = true;
|
16373 |
|
16374 | if (state.writing || state.corked) {
|
16375 | var last = state.lastBufferedRequest;
|
16376 | state.lastBufferedRequest = {
|
16377 | chunk: chunk,
|
16378 | encoding: encoding,
|
16379 | isBuf: isBuf,
|
16380 | callback: cb,
|
16381 | next: null
|
16382 | };
|
16383 | if (last) {
|
16384 | last.next = state.lastBufferedRequest;
|
16385 | } else {
|
16386 | state.bufferedRequest = state.lastBufferedRequest;
|
16387 | }
|
16388 | state.bufferedRequestCount += 1;
|
16389 | } else {
|
16390 | doWrite(stream, state, false, len, chunk, encoding, cb);
|
16391 | }
|
16392 |
|
16393 | return ret;
|
16394 | }
|
16395 |
|
16396 | function doWrite(stream, state, writev, len, chunk, encoding, cb) {
|
16397 | state.writelen = len;
|
16398 | state.writecb = cb;
|
16399 | state.writing = true;
|
16400 | state.sync = true;
|
16401 | if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite);
|
16402 | state.sync = false;
|
16403 | }
|
16404 |
|
16405 | function onwriteError(stream, state, sync, er, cb) {
|
16406 | --state.pendingcb;
|
16407 |
|
16408 | if (sync) {
|
16409 |
|
16410 |
|
16411 | pna.nextTick(cb, er);
|
16412 |
|
16413 |
|
16414 | pna.nextTick(finishMaybe, stream, state);
|
16415 | stream._writableState.errorEmitted = true;
|
16416 | stream.emit('error', er);
|
16417 | } else {
|
16418 |
|
16419 |
|
16420 | cb(er);
|
16421 | stream._writableState.errorEmitted = true;
|
16422 | stream.emit('error', er);
|
16423 |
|
16424 |
|
16425 | finishMaybe(stream, state);
|
16426 | }
|
16427 | }
|
16428 |
|
16429 | function onwriteStateUpdate(state) {
|
16430 | state.writing = false;
|
16431 | state.writecb = null;
|
16432 | state.length -= state.writelen;
|
16433 | state.writelen = 0;
|
16434 | }
|
16435 |
|
16436 | function onwrite(stream, er) {
|
16437 | var state = stream._writableState;
|
16438 | var sync = state.sync;
|
16439 | var cb = state.writecb;
|
16440 |
|
16441 | onwriteStateUpdate(state);
|
16442 |
|
16443 | if (er) onwriteError(stream, state, sync, er, cb);else {
|
16444 |
|
16445 | var finished = needFinish(state);
|
16446 |
|
16447 | if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) {
|
16448 | clearBuffer(stream, state);
|
16449 | }
|
16450 |
|
16451 | if (sync) {
|
16452 |
|
16453 | asyncWrite(afterWrite, stream, state, finished, cb);
|
16454 |
|
16455 | } else {
|
16456 | afterWrite(stream, state, finished, cb);
|
16457 | }
|
16458 | }
|
16459 | }
|
16460 |
|
16461 | function afterWrite(stream, state, finished, cb) {
|
16462 | if (!finished) onwriteDrain(stream, state);
|
16463 | state.pendingcb--;
|
16464 | cb();
|
16465 | finishMaybe(stream, state);
|
16466 | }
|
16467 |
|
16468 |
|
16469 |
|
16470 |
|
16471 | function onwriteDrain(stream, state) {
|
16472 | if (state.length === 0 && state.needDrain) {
|
16473 | state.needDrain = false;
|
16474 | stream.emit('drain');
|
16475 | }
|
16476 | }
|
16477 |
|
16478 |
|
16479 | function clearBuffer(stream, state) {
|
16480 | state.bufferProcessing = true;
|
16481 | var entry = state.bufferedRequest;
|
16482 |
|
16483 | if (stream._writev && entry && entry.next) {
|
16484 |
|
16485 | var l = state.bufferedRequestCount;
|
16486 | var buffer = new Array(l);
|
16487 | var holder = state.corkedRequestsFree;
|
16488 | holder.entry = entry;
|
16489 |
|
16490 | var count = 0;
|
16491 | var allBuffers = true;
|
16492 | while (entry) {
|
16493 | buffer[count] = entry;
|
16494 | if (!entry.isBuf) allBuffers = false;
|
16495 | entry = entry.next;
|
16496 | count += 1;
|
16497 | }
|
16498 | buffer.allBuffers = allBuffers;
|
16499 |
|
16500 | doWrite(stream, state, true, state.length, buffer, '', holder.finish);
|
16501 |
|
16502 |
|
16503 |
|
16504 | state.pendingcb++;
|
16505 | state.lastBufferedRequest = null;
|
16506 | if (holder.next) {
|
16507 | state.corkedRequestsFree = holder.next;
|
16508 | holder.next = null;
|
16509 | } else {
|
16510 | state.corkedRequestsFree = new CorkedRequest(state);
|
16511 | }
|
16512 | state.bufferedRequestCount = 0;
|
16513 | } else {
|
16514 |
|
16515 | while (entry) {
|
16516 | var chunk = entry.chunk;
|
16517 | var encoding = entry.encoding;
|
16518 | var cb = entry.callback;
|
16519 | var len = state.objectMode ? 1 : chunk.length;
|
16520 |
|
16521 | doWrite(stream, state, false, len, chunk, encoding, cb);
|
16522 | entry = entry.next;
|
16523 | state.bufferedRequestCount--;
|
16524 |
|
16525 |
|
16526 |
|
16527 |
|
16528 | if (state.writing) {
|
16529 | break;
|
16530 | }
|
16531 | }
|
16532 |
|
16533 | if (entry === null) state.lastBufferedRequest = null;
|
16534 | }
|
16535 |
|
16536 | state.bufferedRequest = entry;
|
16537 | state.bufferProcessing = false;
|
16538 | }
|
16539 |
|
16540 | Writable.prototype._write = function (chunk, encoding, cb) {
|
16541 | cb(new Error('_write() is not implemented'));
|
16542 | };
|
16543 |
|
16544 | Writable.prototype._writev = null;
|
16545 |
|
16546 | Writable.prototype.end = function (chunk, encoding, cb) {
|
16547 | var state = this._writableState;
|
16548 |
|
16549 | if (typeof chunk === 'function') {
|
16550 | cb = chunk;
|
16551 | chunk = null;
|
16552 | encoding = null;
|
16553 | } else if (typeof encoding === 'function') {
|
16554 | cb = encoding;
|
16555 | encoding = null;
|
16556 | }
|
16557 |
|
16558 | if (chunk !== null && chunk !== undefined) this.write(chunk, encoding);
|
16559 |
|
16560 |
|
16561 | if (state.corked) {
|
16562 | state.corked = 1;
|
16563 | this.uncork();
|
16564 | }
|
16565 |
|
16566 |
|
16567 | if (!state.ending && !state.finished) endWritable(this, state, cb);
|
16568 | };
|
16569 |
|
16570 | function needFinish(state) {
|
16571 | return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing;
|
16572 | }
|
16573 | function callFinal(stream, state) {
|
16574 | stream._final(function (err) {
|
16575 | state.pendingcb--;
|
16576 | if (err) {
|
16577 | stream.emit('error', err);
|
16578 | }
|
16579 | state.prefinished = true;
|
16580 | stream.emit('prefinish');
|
16581 | finishMaybe(stream, state);
|
16582 | });
|
16583 | }
|
16584 | function prefinish(stream, state) {
|
16585 | if (!state.prefinished && !state.finalCalled) {
|
16586 | if (typeof stream._final === 'function') {
|
16587 | state.pendingcb++;
|
16588 | state.finalCalled = true;
|
16589 | pna.nextTick(callFinal, stream, state);
|
16590 | } else {
|
16591 | state.prefinished = true;
|
16592 | stream.emit('prefinish');
|
16593 | }
|
16594 | }
|
16595 | }
|
16596 |
|
16597 | function finishMaybe(stream, state) {
|
16598 | var need = needFinish(state);
|
16599 | if (need) {
|
16600 | prefinish(stream, state);
|
16601 | if (state.pendingcb === 0) {
|
16602 | state.finished = true;
|
16603 | stream.emit('finish');
|
16604 | }
|
16605 | }
|
16606 | return need;
|
16607 | }
|
16608 |
|
16609 | function endWritable(stream, state, cb) {
|
16610 | state.ending = true;
|
16611 | finishMaybe(stream, state);
|
16612 | if (cb) {
|
16613 | if (state.finished) pna.nextTick(cb);else stream.once('finish', cb);
|
16614 | }
|
16615 | state.ended = true;
|
16616 | stream.writable = false;
|
16617 | }
|
16618 |
|
16619 | function onCorkedFinish(corkReq, state, err) {
|
16620 | var entry = corkReq.entry;
|
16621 | corkReq.entry = null;
|
16622 | while (entry) {
|
16623 | var cb = entry.callback;
|
16624 | state.pendingcb--;
|
16625 | cb(err);
|
16626 | entry = entry.next;
|
16627 | }
|
16628 | if (state.corkedRequestsFree) {
|
16629 | state.corkedRequestsFree.next = corkReq;
|
16630 | } else {
|
16631 | state.corkedRequestsFree = corkReq;
|
16632 | }
|
16633 | }
|
16634 |
|
16635 | Object.defineProperty(Writable.prototype, 'destroyed', {
|
16636 | get: function () {
|
16637 | if (this._writableState === undefined) {
|
16638 | return false;
|
16639 | }
|
16640 | return this._writableState.destroyed;
|
16641 | },
|
16642 | set: function (value) {
|
16643 |
|
16644 |
|
16645 | if (!this._writableState) {
|
16646 | return;
|
16647 | }
|
16648 |
|
16649 |
|
16650 |
|
16651 | this._writableState.destroyed = value;
|
16652 | }
|
16653 | });
|
16654 |
|
16655 | Writable.prototype.destroy = destroyImpl.destroy;
|
16656 | Writable.prototype._undestroy = destroyImpl.undestroy;
|
16657 | Writable.prototype._destroy = function (err, cb) {
|
16658 | this.end();
|
16659 | cb(err);
|
16660 | };
|
16661 | }).call(this,_dereq_(70),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},_dereq_(115).setImmediate)
|
16662 | },{"10":10,"115":115,"116":116,"18":18,"69":69,"70":70,"84":84,"90":90,"91":91,"96":96}],89:[function(_dereq_,module,exports){
|
16663 | 'use strict';
|
16664 |
|
16665 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
16666 |
|
16667 | var Buffer = _dereq_(96).Buffer;
|
16668 | var util = _dereq_(7);
|
16669 |
|
16670 | function copyBuffer(src, target, offset) {
|
16671 | src.copy(target, offset);
|
16672 | }
|
16673 |
|
16674 | module.exports = function () {
|
16675 | function BufferList() {
|
16676 | _classCallCheck(this, BufferList);
|
16677 |
|
16678 | this.head = null;
|
16679 | this.tail = null;
|
16680 | this.length = 0;
|
16681 | }
|
16682 |
|
16683 | BufferList.prototype.push = function push(v) {
|
16684 | var entry = { data: v, next: null };
|
16685 | if (this.length > 0) this.tail.next = entry;else this.head = entry;
|
16686 | this.tail = entry;
|
16687 | ++this.length;
|
16688 | };
|
16689 |
|
16690 | BufferList.prototype.unshift = function unshift(v) {
|
16691 | var entry = { data: v, next: this.head };
|
16692 | if (this.length === 0) this.tail = entry;
|
16693 | this.head = entry;
|
16694 | ++this.length;
|
16695 | };
|
16696 |
|
16697 | BufferList.prototype.shift = function shift() {
|
16698 | if (this.length === 0) return;
|
16699 | var ret = this.head.data;
|
16700 | if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next;
|
16701 | --this.length;
|
16702 | return ret;
|
16703 | };
|
16704 |
|
16705 | BufferList.prototype.clear = function clear() {
|
16706 | this.head = this.tail = null;
|
16707 | this.length = 0;
|
16708 | };
|
16709 |
|
16710 | BufferList.prototype.join = function join(s) {
|
16711 | if (this.length === 0) return '';
|
16712 | var p = this.head;
|
16713 | var ret = '' + p.data;
|
16714 | while (p = p.next) {
|
16715 | ret += s + p.data;
|
16716 | }return ret;
|
16717 | };
|
16718 |
|
16719 | BufferList.prototype.concat = function concat(n) {
|
16720 | if (this.length === 0) return Buffer.alloc(0);
|
16721 | if (this.length === 1) return this.head.data;
|
16722 | var ret = Buffer.allocUnsafe(n >>> 0);
|
16723 | var p = this.head;
|
16724 | var i = 0;
|
16725 | while (p) {
|
16726 | copyBuffer(p.data, ret, i);
|
16727 | i += p.data.length;
|
16728 | p = p.next;
|
16729 | }
|
16730 | return ret;
|
16731 | };
|
16732 |
|
16733 | return BufferList;
|
16734 | }();
|
16735 |
|
16736 | if (util && util.inspect && util.inspect.custom) {
|
16737 | module.exports.prototype[util.inspect.custom] = function () {
|
16738 | var obj = util.inspect({ length: this.length });
|
16739 | return this.constructor.name + ' ' + obj;
|
16740 | };
|
16741 | }
|
16742 | },{"7":7,"96":96}],90:[function(_dereq_,module,exports){
|
16743 | 'use strict';
|
16744 |
|
16745 |
|
16746 |
|
16747 | var pna = _dereq_(69);
|
16748 |
|
16749 |
|
16750 |
|
16751 | function destroy(err, cb) {
|
16752 | var _this = this;
|
16753 |
|
16754 | var readableDestroyed = this._readableState && this._readableState.destroyed;
|
16755 | var writableDestroyed = this._writableState && this._writableState.destroyed;
|
16756 |
|
16757 | if (readableDestroyed || writableDestroyed) {
|
16758 | if (cb) {
|
16759 | cb(err);
|
16760 | } else if (err && (!this._writableState || !this._writableState.errorEmitted)) {
|
16761 | pna.nextTick(emitErrorNT, this, err);
|
16762 | }
|
16763 | return this;
|
16764 | }
|
16765 |
|
16766 |
|
16767 |
|
16768 |
|
16769 | if (this._readableState) {
|
16770 | this._readableState.destroyed = true;
|
16771 | }
|
16772 |
|
16773 |
|
16774 | if (this._writableState) {
|
16775 | this._writableState.destroyed = true;
|
16776 | }
|
16777 |
|
16778 | this._destroy(err || null, function (err) {
|
16779 | if (!cb && err) {
|
16780 | pna.nextTick(emitErrorNT, _this, err);
|
16781 | if (_this._writableState) {
|
16782 | _this._writableState.errorEmitted = true;
|
16783 | }
|
16784 | } else if (cb) {
|
16785 | cb(err);
|
16786 | }
|
16787 | });
|
16788 |
|
16789 | return this;
|
16790 | }
|
16791 |
|
16792 | function undestroy() {
|
16793 | if (this._readableState) {
|
16794 | this._readableState.destroyed = false;
|
16795 | this._readableState.reading = false;
|
16796 | this._readableState.ended = false;
|
16797 | this._readableState.endEmitted = false;
|
16798 | }
|
16799 |
|
16800 | if (this._writableState) {
|
16801 | this._writableState.destroyed = false;
|
16802 | this._writableState.ended = false;
|
16803 | this._writableState.ending = false;
|
16804 | this._writableState.finished = false;
|
16805 | this._writableState.errorEmitted = false;
|
16806 | }
|
16807 | }
|
16808 |
|
16809 | function emitErrorNT(self, err) {
|
16810 | self.emit('error', err);
|
16811 | }
|
16812 |
|
16813 | module.exports = {
|
16814 | destroy: destroy,
|
16815 | undestroy: undestroy
|
16816 | };
|
16817 | },{"69":69}],91:[function(_dereq_,module,exports){
|
16818 | arguments[4][38][0].apply(exports,arguments)
|
16819 | },{"14":14,"38":38}],92:[function(_dereq_,module,exports){
|
16820 | module.exports = _dereq_(93).PassThrough
|
16821 |
|
16822 | },{"93":93}],93:[function(_dereq_,module,exports){
|
16823 | exports = module.exports = _dereq_(86);
|
16824 | exports.Stream = exports;
|
16825 | exports.Readable = exports;
|
16826 | exports.Writable = _dereq_(88);
|
16827 | exports.Duplex = _dereq_(84);
|
16828 | exports.Transform = _dereq_(87);
|
16829 | exports.PassThrough = _dereq_(85);
|
16830 |
|
16831 | },{"84":84,"85":85,"86":86,"87":87,"88":88}],94:[function(_dereq_,module,exports){
|
16832 | module.exports = _dereq_(93).Transform
|
16833 |
|
16834 | },{"93":93}],95:[function(_dereq_,module,exports){
|
16835 | module.exports = _dereq_(88);
|
16836 |
|
16837 | },{"88":88}],96:[function(_dereq_,module,exports){
|
16838 |
|
16839 | var buffer = _dereq_(9)
|
16840 | var Buffer = buffer.Buffer
|
16841 |
|
16842 |
|
16843 | function copyProps (src, dst) {
|
16844 | for (var key in src) {
|
16845 | dst[key] = src[key]
|
16846 | }
|
16847 | }
|
16848 | if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) {
|
16849 | module.exports = buffer
|
16850 | } else {
|
16851 |
|
16852 | copyProps(buffer, exports)
|
16853 | exports.Buffer = SafeBuffer
|
16854 | }
|
16855 |
|
16856 | function SafeBuffer (arg, encodingOrOffset, length) {
|
16857 | return Buffer(arg, encodingOrOffset, length)
|
16858 | }
|
16859 |
|
16860 |
|
16861 | copyProps(Buffer, SafeBuffer)
|
16862 |
|
16863 | SafeBuffer.from = function (arg, encodingOrOffset, length) {
|
16864 | if (typeof arg === 'number') {
|
16865 | throw new TypeError('Argument must not be a number')
|
16866 | }
|
16867 | return Buffer(arg, encodingOrOffset, length)
|
16868 | }
|
16869 |
|
16870 | SafeBuffer.alloc = function (size, fill, encoding) {
|
16871 | if (typeof size !== 'number') {
|
16872 | throw new TypeError('Argument must be a number')
|
16873 | }
|
16874 | var buf = Buffer(size)
|
16875 | if (fill !== undefined) {
|
16876 | if (typeof encoding === 'string') {
|
16877 | buf.fill(fill, encoding)
|
16878 | } else {
|
16879 | buf.fill(fill)
|
16880 | }
|
16881 | } else {
|
16882 | buf.fill(0)
|
16883 | }
|
16884 | return buf
|
16885 | }
|
16886 |
|
16887 | SafeBuffer.allocUnsafe = function (size) {
|
16888 | if (typeof size !== 'number') {
|
16889 | throw new TypeError('Argument must be a number')
|
16890 | }
|
16891 | return Buffer(size)
|
16892 | }
|
16893 |
|
16894 | SafeBuffer.allocUnsafeSlow = function (size) {
|
16895 | if (typeof size !== 'number') {
|
16896 | throw new TypeError('Argument must be a number')
|
16897 | }
|
16898 | return buffer.SlowBuffer(size)
|
16899 | }
|
16900 |
|
16901 | },{"9":9}],97:[function(_dereq_,module,exports){
|
16902 |
|
16903 |
|
16904 |
|
16905 |
|
16906 |
|
16907 |
|
16908 |
|
16909 |
|
16910 |
|
16911 |
|
16912 |
|
16913 |
|
16914 |
|
16915 |
|
16916 |
|
16917 |
|
16918 |
|
16919 |
|
16920 |
|
16921 |
|
16922 |
|
16923 | 'use strict';
|
16924 |
|
16925 |
|
16926 |
|
16927 | var Buffer = _dereq_(96).Buffer;
|
16928 |
|
16929 |
|
16930 | var isEncoding = Buffer.isEncoding || function (encoding) {
|
16931 | encoding = '' + encoding;
|
16932 | switch (encoding && encoding.toLowerCase()) {
|
16933 | 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':
|
16934 | return true;
|
16935 | default:
|
16936 | return false;
|
16937 | }
|
16938 | };
|
16939 |
|
16940 | function _normalizeEncoding(enc) {
|
16941 | if (!enc) return 'utf8';
|
16942 | var retried;
|
16943 | while (true) {
|
16944 | switch (enc) {
|
16945 | case 'utf8':
|
16946 | case 'utf-8':
|
16947 | return 'utf8';
|
16948 | case 'ucs2':
|
16949 | case 'ucs-2':
|
16950 | case 'utf16le':
|
16951 | case 'utf-16le':
|
16952 | return 'utf16le';
|
16953 | case 'latin1':
|
16954 | case 'binary':
|
16955 | return 'latin1';
|
16956 | case 'base64':
|
16957 | case 'ascii':
|
16958 | case 'hex':
|
16959 | return enc;
|
16960 | default:
|
16961 | if (retried) return;
|
16962 | enc = ('' + enc).toLowerCase();
|
16963 | retried = true;
|
16964 | }
|
16965 | }
|
16966 | };
|
16967 |
|
16968 |
|
16969 |
|
16970 | function normalizeEncoding(enc) {
|
16971 | var nenc = _normalizeEncoding(enc);
|
16972 | if (typeof nenc !== 'string' && (Buffer.isEncoding === isEncoding || !isEncoding(enc))) throw new Error('Unknown encoding: ' + enc);
|
16973 | return nenc || enc;
|
16974 | }
|
16975 |
|
16976 |
|
16977 |
|
16978 |
|
16979 | exports.StringDecoder = StringDecoder;
|
16980 | function StringDecoder(encoding) {
|
16981 | this.encoding = normalizeEncoding(encoding);
|
16982 | var nb;
|
16983 | switch (this.encoding) {
|
16984 | case 'utf16le':
|
16985 | this.text = utf16Text;
|
16986 | this.end = utf16End;
|
16987 | nb = 4;
|
16988 | break;
|
16989 | case 'utf8':
|
16990 | this.fillLast = utf8FillLast;
|
16991 | nb = 4;
|
16992 | break;
|
16993 | case 'base64':
|
16994 | this.text = base64Text;
|
16995 | this.end = base64End;
|
16996 | nb = 3;
|
16997 | break;
|
16998 | default:
|
16999 | this.write = simpleWrite;
|
17000 | this.end = simpleEnd;
|
17001 | return;
|
17002 | }
|
17003 | this.lastNeed = 0;
|
17004 | this.lastTotal = 0;
|
17005 | this.lastChar = Buffer.allocUnsafe(nb);
|
17006 | }
|
17007 |
|
17008 | StringDecoder.prototype.write = function (buf) {
|
17009 | if (buf.length === 0) return '';
|
17010 | var r;
|
17011 | var i;
|
17012 | if (this.lastNeed) {
|
17013 | r = this.fillLast(buf);
|
17014 | if (r === undefined) return '';
|
17015 | i = this.lastNeed;
|
17016 | this.lastNeed = 0;
|
17017 | } else {
|
17018 | i = 0;
|
17019 | }
|
17020 | if (i < buf.length) return r ? r + this.text(buf, i) : this.text(buf, i);
|
17021 | return r || '';
|
17022 | };
|
17023 |
|
17024 | StringDecoder.prototype.end = utf8End;
|
17025 |
|
17026 |
|
17027 | StringDecoder.prototype.text = utf8Text;
|
17028 |
|
17029 |
|
17030 | StringDecoder.prototype.fillLast = function (buf) {
|
17031 | if (this.lastNeed <= buf.length) {
|
17032 | buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, this.lastNeed);
|
17033 | return this.lastChar.toString(this.encoding, 0, this.lastTotal);
|
17034 | }
|
17035 | buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, buf.length);
|
17036 | this.lastNeed -= buf.length;
|
17037 | };
|
17038 |
|
17039 |
|
17040 |
|
17041 | function utf8CheckByte(byte) {
|
17042 | if (byte <= 0x7F) return 0;else if (byte >> 5 === 0x06) return 2;else if (byte >> 4 === 0x0E) return 3;else if (byte >> 3 === 0x1E) return 4;
|
17043 | return byte >> 6 === 0x02 ? -1 : -2;
|
17044 | }
|
17045 |
|
17046 |
|
17047 |
|
17048 |
|
17049 | function utf8CheckIncomplete(self, buf, i) {
|
17050 | var j = buf.length - 1;
|
17051 | if (j < i) return 0;
|
17052 | var nb = utf8CheckByte(buf[j]);
|
17053 | if (nb >= 0) {
|
17054 | if (nb > 0) self.lastNeed = nb - 1;
|
17055 | return nb;
|
17056 | }
|
17057 | if (--j < i || nb === -2) return 0;
|
17058 | nb = utf8CheckByte(buf[j]);
|
17059 | if (nb >= 0) {
|
17060 | if (nb > 0) self.lastNeed = nb - 2;
|
17061 | return nb;
|
17062 | }
|
17063 | if (--j < i || nb === -2) return 0;
|
17064 | nb = utf8CheckByte(buf[j]);
|
17065 | if (nb >= 0) {
|
17066 | if (nb > 0) {
|
17067 | if (nb === 2) nb = 0;else self.lastNeed = nb - 3;
|
17068 | }
|
17069 | return nb;
|
17070 | }
|
17071 | return 0;
|
17072 | }
|
17073 |
|
17074 |
|
17075 |
|
17076 |
|
17077 |
|
17078 |
|
17079 |
|
17080 |
|
17081 |
|
17082 | function utf8CheckExtraBytes(self, buf, p) {
|
17083 | if ((buf[0] & 0xC0) !== 0x80) {
|
17084 | self.lastNeed = 0;
|
17085 | return '\ufffd';
|
17086 | }
|
17087 | if (self.lastNeed > 1 && buf.length > 1) {
|
17088 | if ((buf[1] & 0xC0) !== 0x80) {
|
17089 | self.lastNeed = 1;
|
17090 | return '\ufffd';
|
17091 | }
|
17092 | if (self.lastNeed > 2 && buf.length > 2) {
|
17093 | if ((buf[2] & 0xC0) !== 0x80) {
|
17094 | self.lastNeed = 2;
|
17095 | return '\ufffd';
|
17096 | }
|
17097 | }
|
17098 | }
|
17099 | }
|
17100 |
|
17101 |
|
17102 | function utf8FillLast(buf) {
|
17103 | var p = this.lastTotal - this.lastNeed;
|
17104 | var r = utf8CheckExtraBytes(this, buf, p);
|
17105 | if (r !== undefined) return r;
|
17106 | if (this.lastNeed <= buf.length) {
|
17107 | buf.copy(this.lastChar, p, 0, this.lastNeed);
|
17108 | return this.lastChar.toString(this.encoding, 0, this.lastTotal);
|
17109 | }
|
17110 | buf.copy(this.lastChar, p, 0, buf.length);
|
17111 | this.lastNeed -= buf.length;
|
17112 | }
|
17113 |
|
17114 |
|
17115 |
|
17116 |
|
17117 | function utf8Text(buf, i) {
|
17118 | var total = utf8CheckIncomplete(this, buf, i);
|
17119 | if (!this.lastNeed) return buf.toString('utf8', i);
|
17120 | this.lastTotal = total;
|
17121 | var end = buf.length - (total - this.lastNeed);
|
17122 | buf.copy(this.lastChar, 0, end);
|
17123 | return buf.toString('utf8', i, end);
|
17124 | }
|
17125 |
|
17126 |
|
17127 |
|
17128 | function utf8End(buf) {
|
17129 | var r = buf && buf.length ? this.write(buf) : '';
|
17130 | if (this.lastNeed) return r + '\ufffd';
|
17131 | return r;
|
17132 | }
|
17133 |
|
17134 |
|
17135 |
|
17136 |
|
17137 |
|
17138 | function utf16Text(buf, i) {
|
17139 | if ((buf.length - i) % 2 === 0) {
|
17140 | var r = buf.toString('utf16le', i);
|
17141 | if (r) {
|
17142 | var c = r.charCodeAt(r.length - 1);
|
17143 | if (c >= 0xD800 && c <= 0xDBFF) {
|
17144 | this.lastNeed = 2;
|
17145 | this.lastTotal = 4;
|
17146 | this.lastChar[0] = buf[buf.length - 2];
|
17147 | this.lastChar[1] = buf[buf.length - 1];
|
17148 | return r.slice(0, -1);
|
17149 | }
|
17150 | }
|
17151 | return r;
|
17152 | }
|
17153 | this.lastNeed = 1;
|
17154 | this.lastTotal = 2;
|
17155 | this.lastChar[0] = buf[buf.length - 1];
|
17156 | return buf.toString('utf16le', i, buf.length - 1);
|
17157 | }
|
17158 |
|
17159 |
|
17160 |
|
17161 | function utf16End(buf) {
|
17162 | var r = buf && buf.length ? this.write(buf) : '';
|
17163 | if (this.lastNeed) {
|
17164 | var end = this.lastTotal - this.lastNeed;
|
17165 | return r + this.lastChar.toString('utf16le', 0, end);
|
17166 | }
|
17167 | return r;
|
17168 | }
|
17169 |
|
17170 | function base64Text(buf, i) {
|
17171 | var n = (buf.length - i) % 3;
|
17172 | if (n === 0) return buf.toString('base64', i);
|
17173 | this.lastNeed = 3 - n;
|
17174 | this.lastTotal = 3;
|
17175 | if (n === 1) {
|
17176 | this.lastChar[0] = buf[buf.length - 1];
|
17177 | } else {
|
17178 | this.lastChar[0] = buf[buf.length - 2];
|
17179 | this.lastChar[1] = buf[buf.length - 1];
|
17180 | }
|
17181 | return buf.toString('base64', i, buf.length - n);
|
17182 | }
|
17183 |
|
17184 | function base64End(buf) {
|
17185 | var r = buf && buf.length ? this.write(buf) : '';
|
17186 | if (this.lastNeed) return r + this.lastChar.toString('base64', 0, 3 - this.lastNeed);
|
17187 | return r;
|
17188 | }
|
17189 |
|
17190 |
|
17191 | function simpleWrite(buf) {
|
17192 | return buf.toString(this.encoding);
|
17193 | }
|
17194 |
|
17195 | function simpleEnd(buf) {
|
17196 | return buf && buf.length ? this.write(buf) : '';
|
17197 | }
|
17198 | },{"96":96}],98:[function(_dereq_,module,exports){
|
17199 | arguments[4][97][0].apply(exports,arguments)
|
17200 | },{"79":79,"97":97}],99:[function(_dereq_,module,exports){
|
17201 | arguments[4][25][0].apply(exports,arguments)
|
17202 | },{"25":25}],100:[function(_dereq_,module,exports){
|
17203 | arguments[4][26][0].apply(exports,arguments)
|
17204 | },{"102":102,"104":104,"18":18,"26":26,"70":70}],101:[function(_dereq_,module,exports){
|
17205 | arguments[4][27][0].apply(exports,arguments)
|
17206 | },{"103":103,"18":18,"27":27}],102:[function(_dereq_,module,exports){
|
17207 | arguments[4][28][0].apply(exports,arguments)
|
17208 | },{"100":100,"105":105,"106":106,"107":107,"109":109,"111":111,"112":112,"14":14,"18":18,"28":28,"7":7,"70":70,"9":9,"98":98,"99":99}],103:[function(_dereq_,module,exports){
|
17209 | arguments[4][29][0].apply(exports,arguments)
|
17210 | },{"100":100,"18":18,"29":29,"99":99}],104:[function(_dereq_,module,exports){
|
17211 | arguments[4][30][0].apply(exports,arguments)
|
17212 | },{"100":100,"107":107,"111":111,"112":112,"116":116,"18":18,"30":30,"70":70,"9":9,"99":99}],105:[function(_dereq_,module,exports){
|
17213 | arguments[4][31][0].apply(exports,arguments)
|
17214 | },{"108":108,"31":31,"70":70}],106:[function(_dereq_,module,exports){
|
17215 | arguments[4][32][0].apply(exports,arguments)
|
17216 | },{"32":32,"7":7,"9":9}],107:[function(_dereq_,module,exports){
|
17217 | arguments[4][33][0].apply(exports,arguments)
|
17218 | },{"33":33,"70":70}],108:[function(_dereq_,module,exports){
|
17219 | arguments[4][34][0].apply(exports,arguments)
|
17220 | },{"34":34,"99":99}],109:[function(_dereq_,module,exports){
|
17221 | arguments[4][35][0].apply(exports,arguments)
|
17222 | },{"35":35}],110:[function(_dereq_,module,exports){
|
17223 | arguments[4][36][0].apply(exports,arguments)
|
17224 | },{"108":108,"36":36,"99":99}],111:[function(_dereq_,module,exports){
|
17225 | arguments[4][37][0].apply(exports,arguments)
|
17226 | },{"37":37,"99":99}],112:[function(_dereq_,module,exports){
|
17227 | arguments[4][38][0].apply(exports,arguments)
|
17228 | },{"14":14,"38":38}],113:[function(_dereq_,module,exports){
|
17229 | arguments[4][39][0].apply(exports,arguments)
|
17230 | },{"100":100,"101":101,"102":102,"103":103,"104":104,"108":108,"110":110,"39":39}],114:[function(_dereq_,module,exports){
|
17231 | (function (process){
|
17232 | var Transform = _dereq_(113).Transform
|
17233 | , inherits = _dereq_(119).inherits
|
17234 |
|
17235 | function DestroyableTransform(opts) {
|
17236 | Transform.call(this, opts)
|
17237 | this._destroyed = false
|
17238 | }
|
17239 |
|
17240 | inherits(DestroyableTransform, Transform)
|
17241 |
|
17242 | DestroyableTransform.prototype.destroy = function(err) {
|
17243 | if (this._destroyed) return
|
17244 | this._destroyed = true
|
17245 |
|
17246 | var self = this
|
17247 | process.nextTick(function() {
|
17248 | if (err)
|
17249 | self.emit('error', err)
|
17250 | self.emit('close')
|
17251 | })
|
17252 | }
|
17253 |
|
17254 |
|
17255 | function noop (chunk, enc, callback) {
|
17256 | callback(null, chunk)
|
17257 | }
|
17258 |
|
17259 |
|
17260 |
|
17261 |
|
17262 | function through2 (construct) {
|
17263 | return function (options, transform, flush) {
|
17264 | if (typeof options == 'function') {
|
17265 | flush = transform
|
17266 | transform = options
|
17267 | options = {}
|
17268 | }
|
17269 |
|
17270 | if (typeof transform != 'function')
|
17271 | transform = noop
|
17272 |
|
17273 | if (typeof flush != 'function')
|
17274 | flush = null
|
17275 |
|
17276 | return construct(options, transform, flush)
|
17277 | }
|
17278 | }
|
17279 |
|
17280 |
|
17281 |
|
17282 | module.exports = through2(function (options, transform, flush) {
|
17283 | var t2 = new DestroyableTransform(options)
|
17284 |
|
17285 | t2._transform = transform
|
17286 |
|
17287 | if (flush)
|
17288 | t2._flush = flush
|
17289 |
|
17290 | return t2
|
17291 | })
|
17292 |
|
17293 |
|
17294 |
|
17295 |
|
17296 | module.exports.ctor = through2(function (options, transform, flush) {
|
17297 | function Through2 (override) {
|
17298 | if (!(this instanceof Through2))
|
17299 | return new Through2(override)
|
17300 |
|
17301 | this.options = Object.assign({}, options, override)
|
17302 |
|
17303 | DestroyableTransform.call(this, this.options)
|
17304 | }
|
17305 |
|
17306 | inherits(Through2, DestroyableTransform)
|
17307 |
|
17308 | Through2.prototype._transform = transform
|
17309 |
|
17310 | if (flush)
|
17311 | Through2.prototype._flush = flush
|
17312 |
|
17313 | return Through2
|
17314 | })
|
17315 |
|
17316 |
|
17317 | module.exports.obj = through2(function (options, transform, flush) {
|
17318 | var t2 = new DestroyableTransform(Object.assign({ objectMode: true, highWaterMark: 16 }, options))
|
17319 |
|
17320 | t2._transform = transform
|
17321 |
|
17322 | if (flush)
|
17323 | t2._flush = flush
|
17324 |
|
17325 | return t2
|
17326 | })
|
17327 |
|
17328 | }).call(this,_dereq_(70))
|
17329 | },{"113":113,"119":119,"70":70}],115:[function(_dereq_,module,exports){
|
17330 | (function (setImmediate,clearImmediate){
|
17331 | var nextTick = _dereq_(70).nextTick;
|
17332 | var apply = Function.prototype.apply;
|
17333 | var slice = Array.prototype.slice;
|
17334 | var immediateIds = {};
|
17335 | var nextImmediateId = 0;
|
17336 |
|
17337 |
|
17338 |
|
17339 | exports.setTimeout = function() {
|
17340 | return new Timeout(apply.call(setTimeout, window, arguments), clearTimeout);
|
17341 | };
|
17342 | exports.setInterval = function() {
|
17343 | return new Timeout(apply.call(setInterval, window, arguments), clearInterval);
|
17344 | };
|
17345 | exports.clearTimeout =
|
17346 | exports.clearInterval = function(timeout) { timeout.close(); };
|
17347 |
|
17348 | function Timeout(id, clearFn) {
|
17349 | this._id = id;
|
17350 | this._clearFn = clearFn;
|
17351 | }
|
17352 | Timeout.prototype.unref = Timeout.prototype.ref = function() {};
|
17353 | Timeout.prototype.close = function() {
|
17354 | this._clearFn.call(window, this._id);
|
17355 | };
|
17356 |
|
17357 |
|
17358 | exports.enroll = function(item, msecs) {
|
17359 | clearTimeout(item._idleTimeoutId);
|
17360 | item._idleTimeout = msecs;
|
17361 | };
|
17362 |
|
17363 | exports.unenroll = function(item) {
|
17364 | clearTimeout(item._idleTimeoutId);
|
17365 | item._idleTimeout = -1;
|
17366 | };
|
17367 |
|
17368 | exports._unrefActive = exports.active = function(item) {
|
17369 | clearTimeout(item._idleTimeoutId);
|
17370 |
|
17371 | var msecs = item._idleTimeout;
|
17372 | if (msecs >= 0) {
|
17373 | item._idleTimeoutId = setTimeout(function onTimeout() {
|
17374 | if (item._onTimeout)
|
17375 | item._onTimeout();
|
17376 | }, msecs);
|
17377 | }
|
17378 | };
|
17379 |
|
17380 |
|
17381 | exports.setImmediate = typeof setImmediate === "function" ? setImmediate : function(fn) {
|
17382 | var id = nextImmediateId++;
|
17383 | var args = arguments.length < 2 ? false : slice.call(arguments, 1);
|
17384 |
|
17385 | immediateIds[id] = true;
|
17386 |
|
17387 | nextTick(function onNextTick() {
|
17388 | if (immediateIds[id]) {
|
17389 |
|
17390 |
|
17391 | if (args) {
|
17392 | fn.apply(null, args);
|
17393 | } else {
|
17394 | fn.call(null);
|
17395 | }
|
17396 |
|
17397 | exports.clearImmediate(id);
|
17398 | }
|
17399 | });
|
17400 |
|
17401 | return id;
|
17402 | };
|
17403 |
|
17404 | exports.clearImmediate = typeof clearImmediate === "function" ? clearImmediate : function(id) {
|
17405 | delete immediateIds[id];
|
17406 | };
|
17407 | }).call(this,_dereq_(115).setImmediate,_dereq_(115).clearImmediate)
|
17408 | },{"115":115,"70":70}],116:[function(_dereq_,module,exports){
|
17409 | (function (global){
|
17410 |
|
17411 |
|
17412 |
|
17413 |
|
17414 |
|
17415 | module.exports = deprecate;
|
17416 |
|
17417 |
|
17418 |
|
17419 |
|
17420 |
|
17421 |
|
17422 |
|
17423 |
|
17424 |
|
17425 |
|
17426 |
|
17427 |
|
17428 |
|
17429 |
|
17430 |
|
17431 |
|
17432 |
|
17433 |
|
17434 |
|
17435 | function deprecate (fn, msg) {
|
17436 | if (config('noDeprecation')) {
|
17437 | return fn;
|
17438 | }
|
17439 |
|
17440 | var warned = false;
|
17441 | function deprecated() {
|
17442 | if (!warned) {
|
17443 | if (config('throwDeprecation')) {
|
17444 | throw new Error(msg);
|
17445 | } else if (config('traceDeprecation')) {
|
17446 | console.trace(msg);
|
17447 | } else {
|
17448 | console.warn(msg);
|
17449 | }
|
17450 | warned = true;
|
17451 | }
|
17452 | return fn.apply(this, arguments);
|
17453 | }
|
17454 |
|
17455 | return deprecated;
|
17456 | }
|
17457 |
|
17458 |
|
17459 |
|
17460 |
|
17461 |
|
17462 |
|
17463 |
|
17464 |
|
17465 |
|
17466 | function config (name) {
|
17467 |
|
17468 | try {
|
17469 | if (!global.localStorage) return false;
|
17470 | } catch (_) {
|
17471 | return false;
|
17472 | }
|
17473 | var val = global.localStorage[name];
|
17474 | if (null == val) return false;
|
17475 | return String(val).toLowerCase() === 'true';
|
17476 | }
|
17477 |
|
17478 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
17479 | },{}],117:[function(_dereq_,module,exports){
|
17480 | arguments[4][3][0].apply(exports,arguments)
|
17481 | },{"3":3}],118:[function(_dereq_,module,exports){
|
17482 | arguments[4][4][0].apply(exports,arguments)
|
17483 | },{"4":4}],119:[function(_dereq_,module,exports){
|
17484 | arguments[4][5][0].apply(exports,arguments)
|
17485 | },{"117":117,"118":118,"5":5,"70":70}],120:[function(_dereq_,module,exports){
|
17486 | var v1 = _dereq_(123);
|
17487 | var v4 = _dereq_(124);
|
17488 |
|
17489 | var uuid = v4;
|
17490 | uuid.v1 = v1;
|
17491 | uuid.v4 = v4;
|
17492 |
|
17493 | module.exports = uuid;
|
17494 |
|
17495 | },{"123":123,"124":124}],121:[function(_dereq_,module,exports){
|
17496 |
|
17497 |
|
17498 |
|
17499 |
|
17500 | var byteToHex = [];
|
17501 | for (var i = 0; i < 256; ++i) {
|
17502 | byteToHex[i] = (i + 0x100).toString(16).substr(1);
|
17503 | }
|
17504 |
|
17505 | function bytesToUuid(buf, offset) {
|
17506 | var i = offset || 0;
|
17507 | var bth = byteToHex;
|
17508 |
|
17509 | return ([bth[buf[i++]], bth[buf[i++]],
|
17510 | bth[buf[i++]], bth[buf[i++]], '-',
|
17511 | bth[buf[i++]], bth[buf[i++]], '-',
|
17512 | bth[buf[i++]], bth[buf[i++]], '-',
|
17513 | bth[buf[i++]], bth[buf[i++]], '-',
|
17514 | bth[buf[i++]], bth[buf[i++]],
|
17515 | bth[buf[i++]], bth[buf[i++]],
|
17516 | bth[buf[i++]], bth[buf[i++]]]).join('');
|
17517 | }
|
17518 |
|
17519 | module.exports = bytesToUuid;
|
17520 |
|
17521 | },{}],122:[function(_dereq_,module,exports){
|
17522 |
|
17523 |
|
17524 |
|
17525 |
|
17526 |
|
17527 |
|
17528 |
|
17529 | var getRandomValues = (typeof(crypto) != 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto)) ||
|
17530 | (typeof(msCrypto) != 'undefined' && typeof window.msCrypto.getRandomValues == 'function' && msCrypto.getRandomValues.bind(msCrypto));
|
17531 |
|
17532 | if (getRandomValues) {
|
17533 |
|
17534 | var rnds8 = new Uint8Array(16);
|
17535 |
|
17536 | module.exports = function whatwgRNG() {
|
17537 | getRandomValues(rnds8);
|
17538 | return rnds8;
|
17539 | };
|
17540 | } else {
|
17541 |
|
17542 |
|
17543 |
|
17544 |
|
17545 | var rnds = new Array(16);
|
17546 |
|
17547 | module.exports = function mathRNG() {
|
17548 | for (var i = 0, r; i < 16; i++) {
|
17549 | if ((i & 0x03) === 0) r = Math.random() * 0x100000000;
|
17550 | rnds[i] = r >>> ((i & 0x03) << 3) & 0xff;
|
17551 | }
|
17552 |
|
17553 | return rnds;
|
17554 | };
|
17555 | }
|
17556 |
|
17557 | },{}],123:[function(_dereq_,module,exports){
|
17558 | var rng = _dereq_(122);
|
17559 | var bytesToUuid = _dereq_(121);
|
17560 |
|
17561 |
|
17562 |
|
17563 |
|
17564 |
|
17565 |
|
17566 | var _nodeId;
|
17567 | var _clockseq;
|
17568 |
|
17569 |
|
17570 | var _lastMSecs = 0;
|
17571 | var _lastNSecs = 0;
|
17572 |
|
17573 |
|
17574 | function v1(options, buf, offset) {
|
17575 | var i = buf && offset || 0;
|
17576 | var b = buf || [];
|
17577 |
|
17578 | options = options || {};
|
17579 | var node = options.node || _nodeId;
|
17580 | var clockseq = options.clockseq !== undefined ? options.clockseq : _clockseq;
|
17581 |
|
17582 |
|
17583 |
|
17584 |
|
17585 | if (node == null || clockseq == null) {
|
17586 | var seedBytes = rng();
|
17587 | if (node == null) {
|
17588 |
|
17589 | node = _nodeId = [
|
17590 | seedBytes[0] | 0x01,
|
17591 | seedBytes[1], seedBytes[2], seedBytes[3], seedBytes[4], seedBytes[5]
|
17592 | ];
|
17593 | }
|
17594 | if (clockseq == null) {
|
17595 |
|
17596 | clockseq = _clockseq = (seedBytes[6] << 8 | seedBytes[7]) & 0x3fff;
|
17597 | }
|
17598 | }
|
17599 |
|
17600 |
|
17601 |
|
17602 |
|
17603 |
|
17604 | var msecs = options.msecs !== undefined ? options.msecs : new Date().getTime();
|
17605 |
|
17606 |
|
17607 |
|
17608 | var nsecs = options.nsecs !== undefined ? options.nsecs : _lastNSecs + 1;
|
17609 |
|
17610 |
|
17611 | var dt = (msecs - _lastMSecs) + (nsecs - _lastNSecs)/10000;
|
17612 |
|
17613 |
|
17614 | if (dt < 0 && options.clockseq === undefined) {
|
17615 | clockseq = clockseq + 1 & 0x3fff;
|
17616 | }
|
17617 |
|
17618 |
|
17619 |
|
17620 | if ((dt < 0 || msecs > _lastMSecs) && options.nsecs === undefined) {
|
17621 | nsecs = 0;
|
17622 | }
|
17623 |
|
17624 |
|
17625 | if (nsecs >= 10000) {
|
17626 | throw new Error('uuid.v1(): Can\'t create more than 10M uuids/sec');
|
17627 | }
|
17628 |
|
17629 | _lastMSecs = msecs;
|
17630 | _lastNSecs = nsecs;
|
17631 | _clockseq = clockseq;
|
17632 |
|
17633 |
|
17634 | msecs += 12219292800000;
|
17635 |
|
17636 |
|
17637 | var tl = ((msecs & 0xfffffff) * 10000 + nsecs) % 0x100000000;
|
17638 | b[i++] = tl >>> 24 & 0xff;
|
17639 | b[i++] = tl >>> 16 & 0xff;
|
17640 | b[i++] = tl >>> 8 & 0xff;
|
17641 | b[i++] = tl & 0xff;
|
17642 |
|
17643 |
|
17644 | var tmh = (msecs / 0x100000000 * 10000) & 0xfffffff;
|
17645 | b[i++] = tmh >>> 8 & 0xff;
|
17646 | b[i++] = tmh & 0xff;
|
17647 |
|
17648 |
|
17649 | b[i++] = tmh >>> 24 & 0xf | 0x10;
|
17650 | b[i++] = tmh >>> 16 & 0xff;
|
17651 |
|
17652 |
|
17653 | b[i++] = clockseq >>> 8 | 0x80;
|
17654 |
|
17655 |
|
17656 | b[i++] = clockseq & 0xff;
|
17657 |
|
17658 |
|
17659 | for (var n = 0; n < 6; ++n) {
|
17660 | b[i + n] = node[n];
|
17661 | }
|
17662 |
|
17663 | return buf ? buf : bytesToUuid(b);
|
17664 | }
|
17665 |
|
17666 | module.exports = v1;
|
17667 |
|
17668 | },{"121":121,"122":122}],124:[function(_dereq_,module,exports){
|
17669 | var rng = _dereq_(122);
|
17670 | var bytesToUuid = _dereq_(121);
|
17671 |
|
17672 | function v4(options, buf, offset) {
|
17673 | var i = buf && offset || 0;
|
17674 |
|
17675 | if (typeof(options) == 'string') {
|
17676 | buf = options === 'binary' ? new Array(16) : null;
|
17677 | options = null;
|
17678 | }
|
17679 | options = options || {};
|
17680 |
|
17681 | var rnds = options.random || (options.rng || rng)();
|
17682 |
|
17683 |
|
17684 | rnds[6] = (rnds[6] & 0x0f) | 0x40;
|
17685 | rnds[8] = (rnds[8] & 0x3f) | 0x80;
|
17686 |
|
17687 |
|
17688 | if (buf) {
|
17689 | for (var ii = 0; ii < 16; ++ii) {
|
17690 | buf[i + ii] = rnds[ii];
|
17691 | }
|
17692 | }
|
17693 |
|
17694 | return buf || bytesToUuid(rnds);
|
17695 | }
|
17696 |
|
17697 | module.exports = v4;
|
17698 |
|
17699 | },{"121":121,"122":122}],125:[function(_dereq_,module,exports){
|
17700 | 'use strict';
|
17701 |
|
17702 |
|
17703 |
|
17704 |
|
17705 |
|
17706 |
|
17707 | exports.stringify = function stringify(input) {
|
17708 | var queue = [];
|
17709 | queue.push({obj: input});
|
17710 |
|
17711 | var res = '';
|
17712 | var next, obj, prefix, val, i, arrayPrefix, keys, k, key, value, objPrefix;
|
17713 | while ((next = queue.pop())) {
|
17714 | obj = next.obj;
|
17715 | prefix = next.prefix || '';
|
17716 | val = next.val || '';
|
17717 | res += prefix;
|
17718 | if (val) {
|
17719 | res += val;
|
17720 | } else if (typeof obj !== 'object') {
|
17721 | res += typeof obj === 'undefined' ? null : JSON.stringify(obj);
|
17722 | } else if (obj === null) {
|
17723 | res += 'null';
|
17724 | } else if (Array.isArray(obj)) {
|
17725 | queue.push({val: ']'});
|
17726 | for (i = obj.length - 1; i >= 0; i--) {
|
17727 | arrayPrefix = i === 0 ? '' : ',';
|
17728 | queue.push({obj: obj[i], prefix: arrayPrefix});
|
17729 | }
|
17730 | queue.push({val: '['});
|
17731 | } else {
|
17732 | keys = [];
|
17733 | for (k in obj) {
|
17734 | if (obj.hasOwnProperty(k)) {
|
17735 | keys.push(k);
|
17736 | }
|
17737 | }
|
17738 | queue.push({val: '}'});
|
17739 | for (i = keys.length - 1; i >= 0; i--) {
|
17740 | key = keys[i];
|
17741 | value = obj[key];
|
17742 | objPrefix = (i > 0 ? ',' : '');
|
17743 | objPrefix += JSON.stringify(key) + ':';
|
17744 | queue.push({obj: value, prefix: objPrefix});
|
17745 | }
|
17746 | queue.push({val: '{'});
|
17747 | }
|
17748 | }
|
17749 | return res;
|
17750 | };
|
17751 |
|
17752 |
|
17753 |
|
17754 |
|
17755 | function pop(obj, stack, metaStack) {
|
17756 | var lastMetaElement = metaStack[metaStack.length - 1];
|
17757 | if (obj === lastMetaElement.element) {
|
17758 |
|
17759 | metaStack.pop();
|
17760 | lastMetaElement = metaStack[metaStack.length - 1];
|
17761 | }
|
17762 | var element = lastMetaElement.element;
|
17763 | var lastElementIndex = lastMetaElement.index;
|
17764 | if (Array.isArray(element)) {
|
17765 | element.push(obj);
|
17766 | } else if (lastElementIndex === stack.length - 2) {
|
17767 | var key = stack.pop();
|
17768 | element[key] = obj;
|
17769 | } else {
|
17770 | stack.push(obj);
|
17771 | }
|
17772 | }
|
17773 |
|
17774 | exports.parse = function (str) {
|
17775 | var stack = [];
|
17776 | var metaStack = [];
|
17777 | var i = 0;
|
17778 | var collationIndex,parsedNum,numChar;
|
17779 | var parsedString,lastCh,numConsecutiveSlashes,ch;
|
17780 | var arrayElement, objElement;
|
17781 | while (true) {
|
17782 | collationIndex = str[i++];
|
17783 | if (collationIndex === '}' ||
|
17784 | collationIndex === ']' ||
|
17785 | typeof collationIndex === 'undefined') {
|
17786 | if (stack.length === 1) {
|
17787 | return stack.pop();
|
17788 | } else {
|
17789 | pop(stack.pop(), stack, metaStack);
|
17790 | continue;
|
17791 | }
|
17792 | }
|
17793 | switch (collationIndex) {
|
17794 | case ' ':
|
17795 | case '\t':
|
17796 | case '\n':
|
17797 | case ':':
|
17798 | case ',':
|
17799 | break;
|
17800 | case 'n':
|
17801 | i += 3;
|
17802 | pop(null, stack, metaStack);
|
17803 | break;
|
17804 | case 't':
|
17805 | i += 3;
|
17806 | pop(true, stack, metaStack);
|
17807 | break;
|
17808 | case 'f':
|
17809 | i += 4;
|
17810 | pop(false, stack, metaStack);
|
17811 | break;
|
17812 | case '0':
|
17813 | case '1':
|
17814 | case '2':
|
17815 | case '3':
|
17816 | case '4':
|
17817 | case '5':
|
17818 | case '6':
|
17819 | case '7':
|
17820 | case '8':
|
17821 | case '9':
|
17822 | case '-':
|
17823 | parsedNum = '';
|
17824 | i--;
|
17825 | while (true) {
|
17826 | numChar = str[i++];
|
17827 | if (/[\d\.\-e\+]/.test(numChar)) {
|
17828 | parsedNum += numChar;
|
17829 | } else {
|
17830 | i--;
|
17831 | break;
|
17832 | }
|
17833 | }
|
17834 | pop(parseFloat(parsedNum), stack, metaStack);
|
17835 | break;
|
17836 | case '"':
|
17837 | parsedString = '';
|
17838 | lastCh = void 0;
|
17839 | numConsecutiveSlashes = 0;
|
17840 | while (true) {
|
17841 | ch = str[i++];
|
17842 | if (ch !== '"' || (lastCh === '\\' &&
|
17843 | numConsecutiveSlashes % 2 === 1)) {
|
17844 | parsedString += ch;
|
17845 | lastCh = ch;
|
17846 | if (lastCh === '\\') {
|
17847 | numConsecutiveSlashes++;
|
17848 | } else {
|
17849 | numConsecutiveSlashes = 0;
|
17850 | }
|
17851 | } else {
|
17852 | break;
|
17853 | }
|
17854 | }
|
17855 | pop(JSON.parse('"' + parsedString + '"'), stack, metaStack);
|
17856 | break;
|
17857 | case '[':
|
17858 | arrayElement = { element: [], index: stack.length };
|
17859 | stack.push(arrayElement.element);
|
17860 | metaStack.push(arrayElement);
|
17861 | break;
|
17862 | case '{':
|
17863 | objElement = { element: {}, index: stack.length };
|
17864 | stack.push(objElement.element);
|
17865 | metaStack.push(objElement);
|
17866 | break;
|
17867 | default:
|
17868 | throw new Error(
|
17869 | 'unexpectedly reached end of input: ' + collationIndex);
|
17870 | }
|
17871 | }
|
17872 | };
|
17873 |
|
17874 | },{}],126:[function(_dereq_,module,exports){
|
17875 | (function (global){
|
17876 | 'use strict';
|
17877 |
|
17878 | function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
17879 |
|
17880 | var immediate = _interopDefault(_dereq_(17));
|
17881 | var uuidV4 = _interopDefault(_dereq_(120));
|
17882 | var Md5 = _interopDefault(_dereq_(80));
|
17883 | var levelup = _interopDefault(_dereq_(43));
|
17884 | var ltgt = _interopDefault(_dereq_(52));
|
17885 | var events = _dereq_(14);
|
17886 | var events__default = _interopDefault(events);
|
17887 | var Codec = _interopDefault(_dereq_(21));
|
17888 | var ReadableStreamCore = _interopDefault(_dereq_(78));
|
17889 | var inherits = _interopDefault(_dereq_(18));
|
17890 | var through2 = _dereq_(114);
|
17891 | var getArguments = _interopDefault(_dereq_(1));
|
17892 | var Deque = _interopDefault(_dereq_(11));
|
17893 | var bufferFrom = _interopDefault(_dereq_(8));
|
17894 | var vuvuzela = _interopDefault(_dereq_(125));
|
17895 | var memdown = _interopDefault(_dereq_(54));
|
17896 |
|
17897 | function isBinaryObject(object) {
|
17898 | return (typeof ArrayBuffer !== 'undefined' && object instanceof ArrayBuffer) ||
|
17899 | (typeof Blob !== 'undefined' && object instanceof Blob);
|
17900 | }
|
17901 |
|
17902 | function cloneArrayBuffer(buff) {
|
17903 | if (typeof buff.slice === 'function') {
|
17904 | return buff.slice(0);
|
17905 | }
|
17906 |
|
17907 | var target = new ArrayBuffer(buff.byteLength);
|
17908 | var targetArray = new Uint8Array(target);
|
17909 | var sourceArray = new Uint8Array(buff);
|
17910 | targetArray.set(sourceArray);
|
17911 | return target;
|
17912 | }
|
17913 |
|
17914 | function cloneBinaryObject(object) {
|
17915 | if (object instanceof ArrayBuffer) {
|
17916 | return cloneArrayBuffer(object);
|
17917 | }
|
17918 | var size = object.size;
|
17919 | var type = object.type;
|
17920 |
|
17921 | if (typeof object.slice === 'function') {
|
17922 | return object.slice(0, size, type);
|
17923 | }
|
17924 |
|
17925 | return object.webkitSlice(0, size, type);
|
17926 | }
|
17927 |
|
17928 |
|
17929 |
|
17930 |
|
17931 |
|
17932 | var funcToString = Function.prototype.toString;
|
17933 | var objectCtorString = funcToString.call(Object);
|
17934 |
|
17935 | function isPlainObject(value) {
|
17936 | var proto = Object.getPrototypeOf(value);
|
17937 |
|
17938 | if (proto === null) {
|
17939 | return true;
|
17940 | }
|
17941 | var Ctor = proto.constructor;
|
17942 | return (typeof Ctor == 'function' &&
|
17943 | Ctor instanceof Ctor && funcToString.call(Ctor) == objectCtorString);
|
17944 | }
|
17945 |
|
17946 | function clone(object) {
|
17947 | var newObject;
|
17948 | var i;
|
17949 | var len;
|
17950 |
|
17951 | if (!object || typeof object !== 'object') {
|
17952 | return object;
|
17953 | }
|
17954 |
|
17955 | if (Array.isArray(object)) {
|
17956 | newObject = [];
|
17957 | for (i = 0, len = object.length; i < len; i++) {
|
17958 | newObject[i] = clone(object[i]);
|
17959 | }
|
17960 | return newObject;
|
17961 | }
|
17962 |
|
17963 |
|
17964 |
|
17965 | if (object instanceof Date) {
|
17966 | return object.toISOString();
|
17967 | }
|
17968 |
|
17969 | if (isBinaryObject(object)) {
|
17970 | return cloneBinaryObject(object);
|
17971 | }
|
17972 |
|
17973 | if (!isPlainObject(object)) {
|
17974 | return object;
|
17975 | }
|
17976 |
|
17977 | newObject = {};
|
17978 | for (i in object) {
|
17979 |
|
17980 | if (Object.prototype.hasOwnProperty.call(object, i)) {
|
17981 | var value = clone(object[i]);
|
17982 | if (typeof value !== 'undefined') {
|
17983 | newObject[i] = value;
|
17984 | }
|
17985 | }
|
17986 | }
|
17987 | return newObject;
|
17988 | }
|
17989 |
|
17990 | function mangle(key) {
|
17991 | return '$' + key;
|
17992 | }
|
17993 | function unmangle(key) {
|
17994 | return key.substring(1);
|
17995 | }
|
17996 | function Map$1() {
|
17997 | this._store = {};
|
17998 | }
|
17999 | Map$1.prototype.get = function (key) {
|
18000 | var mangled = mangle(key);
|
18001 | return this._store[mangled];
|
18002 | };
|
18003 | Map$1.prototype.set = function (key, value) {
|
18004 | var mangled = mangle(key);
|
18005 | this._store[mangled] = value;
|
18006 | return true;
|
18007 | };
|
18008 | Map$1.prototype.has = function (key) {
|
18009 | var mangled = mangle(key);
|
18010 | return mangled in this._store;
|
18011 | };
|
18012 | Map$1.prototype["delete"] = function (key) {
|
18013 | var mangled = mangle(key);
|
18014 | var res = mangled in this._store;
|
18015 | delete this._store[mangled];
|
18016 | return res;
|
18017 | };
|
18018 | Map$1.prototype.forEach = function (cb) {
|
18019 | var keys = Object.keys(this._store);
|
18020 | for (var i = 0, len = keys.length; i < len; i++) {
|
18021 | var key = keys[i];
|
18022 | var value = this._store[key];
|
18023 | key = unmangle(key);
|
18024 | cb(value, key);
|
18025 | }
|
18026 | };
|
18027 | Object.defineProperty(Map$1.prototype, 'size', {
|
18028 | get: function () {
|
18029 | return Object.keys(this._store).length;
|
18030 | }
|
18031 | });
|
18032 |
|
18033 | function Set$1(array) {
|
18034 | this._store = new Map$1();
|
18035 |
|
18036 |
|
18037 | if (array && Array.isArray(array)) {
|
18038 | for (var i = 0, len = array.length; i < len; i++) {
|
18039 | this.add(array[i]);
|
18040 | }
|
18041 | }
|
18042 | }
|
18043 | Set$1.prototype.add = function (key) {
|
18044 | return this._store.set(key, true);
|
18045 | };
|
18046 | Set$1.prototype.has = function (key) {
|
18047 | return this._store.has(key);
|
18048 | };
|
18049 | Set$1.prototype.forEach = function (cb) {
|
18050 | this._store.forEach(function (value, key) {
|
18051 | cb(key);
|
18052 | });
|
18053 | };
|
18054 | Object.defineProperty(Set$1.prototype, 'size', {
|
18055 | get: function () {
|
18056 | return this._store.size;
|
18057 | }
|
18058 | });
|
18059 |
|
18060 |
|
18061 |
|
18062 |
|
18063 |
|
18064 | function supportsMapAndSet() {
|
18065 | if (typeof Symbol === 'undefined' || typeof Map === 'undefined' || typeof Set === 'undefined') {
|
18066 | return false;
|
18067 | }
|
18068 | var prop = Object.getOwnPropertyDescriptor(Map, Symbol.species);
|
18069 | return prop && 'get' in prop && Map[Symbol.species] === Map;
|
18070 | }
|
18071 |
|
18072 |
|
18073 |
|
18074 | var ExportedSet;
|
18075 | var ExportedMap;
|
18076 |
|
18077 | {
|
18078 | if (supportsMapAndSet()) {
|
18079 | ExportedSet = Set;
|
18080 | ExportedMap = Map;
|
18081 | } else {
|
18082 | ExportedSet = Set$1;
|
18083 | ExportedMap = Map$1;
|
18084 | }
|
18085 | }
|
18086 |
|
18087 |
|
18088 | function pick(obj, arr) {
|
18089 | var res = {};
|
18090 | for (var i = 0, len = arr.length; i < len; i++) {
|
18091 | var prop = arr[i];
|
18092 | if (prop in obj) {
|
18093 | res[prop] = obj[prop];
|
18094 | }
|
18095 | }
|
18096 | return res;
|
18097 | }
|
18098 |
|
18099 | var hasLocal;
|
18100 |
|
18101 | try {
|
18102 | localStorage.setItem('_pouch_check_localstorage', 1);
|
18103 | hasLocal = !!localStorage.getItem('_pouch_check_localstorage');
|
18104 | } catch (e) {
|
18105 | hasLocal = false;
|
18106 | }
|
18107 |
|
18108 | function hasLocalStorage() {
|
18109 | return hasLocal;
|
18110 | }
|
18111 |
|
18112 |
|
18113 |
|
18114 | inherits(Changes, events.EventEmitter);
|
18115 |
|
18116 |
|
18117 | function attachBrowserEvents(self) {
|
18118 | if (hasLocalStorage()) {
|
18119 | addEventListener("storage", function (e) {
|
18120 | self.emit(e.key);
|
18121 | });
|
18122 | }
|
18123 | }
|
18124 |
|
18125 | function Changes() {
|
18126 | events.EventEmitter.call(this);
|
18127 | this._listeners = {};
|
18128 |
|
18129 | attachBrowserEvents(this);
|
18130 | }
|
18131 | Changes.prototype.addListener = function (dbName, id, db, opts) {
|
18132 |
|
18133 | if (this._listeners[id]) {
|
18134 | return;
|
18135 | }
|
18136 | var self = this;
|
18137 | var inprogress = false;
|
18138 | function eventFunction() {
|
18139 |
|
18140 | if (!self._listeners[id]) {
|
18141 | return;
|
18142 | }
|
18143 | if (inprogress) {
|
18144 | inprogress = 'waiting';
|
18145 | return;
|
18146 | }
|
18147 | inprogress = true;
|
18148 | var changesOpts = pick(opts, [
|
18149 | 'style', 'include_docs', 'attachments', 'conflicts', 'filter',
|
18150 | 'doc_ids', 'view', 'since', 'query_params', 'binary', 'return_docs'
|
18151 | ]);
|
18152 |
|
18153 |
|
18154 | function onError() {
|
18155 | inprogress = false;
|
18156 | }
|
18157 |
|
18158 | db.changes(changesOpts).on('change', function (c) {
|
18159 | if (c.seq > opts.since && !opts.cancelled) {
|
18160 | opts.since = c.seq;
|
18161 | opts.onChange(c);
|
18162 | }
|
18163 | }).on('complete', function () {
|
18164 | if (inprogress === 'waiting') {
|
18165 | immediate(eventFunction);
|
18166 | }
|
18167 | inprogress = false;
|
18168 | }).on('error', onError);
|
18169 | }
|
18170 | this._listeners[id] = eventFunction;
|
18171 | this.on(dbName, eventFunction);
|
18172 | };
|
18173 |
|
18174 | Changes.prototype.removeListener = function (dbName, id) {
|
18175 |
|
18176 | if (!(id in this._listeners)) {
|
18177 | return;
|
18178 | }
|
18179 | events.EventEmitter.prototype.removeListener.call(this, dbName,
|
18180 | this._listeners[id]);
|
18181 | delete this._listeners[id];
|
18182 | };
|
18183 |
|
18184 |
|
18185 |
|
18186 | Changes.prototype.notifyLocalWindows = function (dbName) {
|
18187 |
|
18188 |
|
18189 | if (hasLocalStorage()) {
|
18190 | localStorage[dbName] = (localStorage[dbName] === "a") ? "b" : "a";
|
18191 | }
|
18192 | };
|
18193 |
|
18194 | Changes.prototype.notify = function (dbName) {
|
18195 | this.emit(dbName);
|
18196 | this.notifyLocalWindows(dbName);
|
18197 | };
|
18198 |
|
18199 | function guardedConsole(method) {
|
18200 |
|
18201 | if (typeof console !== 'undefined' && typeof console[method] === 'function') {
|
18202 | var args = Array.prototype.slice.call(arguments, 1);
|
18203 | console[method].apply(console, args);
|
18204 | }
|
18205 | }
|
18206 |
|
18207 | var assign;
|
18208 | {
|
18209 | if (typeof Object.assign === 'function') {
|
18210 | assign = Object.assign;
|
18211 | } else {
|
18212 |
|
18213 |
|
18214 | assign = function (target) {
|
18215 | var to = Object(target);
|
18216 |
|
18217 | for (var index = 1; index < arguments.length; index++) {
|
18218 | var nextSource = arguments[index];
|
18219 |
|
18220 | if (nextSource != null) {
|
18221 | for (var nextKey in nextSource) {
|
18222 |
|
18223 | if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
|
18224 | to[nextKey] = nextSource[nextKey];
|
18225 | }
|
18226 | }
|
18227 | }
|
18228 | }
|
18229 | return to;
|
18230 | };
|
18231 | }
|
18232 | }
|
18233 |
|
18234 | var $inject_Object_assign = assign;
|
18235 |
|
18236 | inherits(PouchError, Error);
|
18237 |
|
18238 | function PouchError(status, error, reason) {
|
18239 | Error.call(this, reason);
|
18240 | this.status = status;
|
18241 | this.name = error;
|
18242 | this.message = reason;
|
18243 | this.error = true;
|
18244 | }
|
18245 |
|
18246 | PouchError.prototype.toString = function () {
|
18247 | return JSON.stringify({
|
18248 | status: this.status,
|
18249 | name: this.name,
|
18250 | message: this.message,
|
18251 | reason: this.reason
|
18252 | });
|
18253 | };
|
18254 |
|
18255 | var UNAUTHORIZED = new PouchError(401, 'unauthorized', "Name or password is incorrect.");
|
18256 | var MISSING_BULK_DOCS = new PouchError(400, 'bad_request', "Missing JSON list of 'docs'");
|
18257 | var MISSING_DOC = new PouchError(404, 'not_found', 'missing');
|
18258 | var REV_CONFLICT = new PouchError(409, 'conflict', 'Document update conflict');
|
18259 | var INVALID_ID = new PouchError(400, 'bad_request', '_id field must contain a string');
|
18260 | var MISSING_ID = new PouchError(412, 'missing_id', '_id is required for puts');
|
18261 | var RESERVED_ID = new PouchError(400, 'bad_request', 'Only reserved document ids may start with underscore.');
|
18262 | var NOT_OPEN = new PouchError(412, 'precondition_failed', 'Database not open');
|
18263 | var UNKNOWN_ERROR = new PouchError(500, 'unknown_error', 'Database encountered an unknown error');
|
18264 | var BAD_ARG = new PouchError(500, 'badarg', 'Some query argument is invalid');
|
18265 | var INVALID_REQUEST = new PouchError(400, 'invalid_request', 'Request was invalid');
|
18266 | var QUERY_PARSE_ERROR = new PouchError(400, 'query_parse_error', 'Some query parameter is invalid');
|
18267 | var DOC_VALIDATION = new PouchError(500, 'doc_validation', 'Bad special document member');
|
18268 | var BAD_REQUEST = new PouchError(400, 'bad_request', 'Something wrong with the request');
|
18269 | var NOT_AN_OBJECT = new PouchError(400, 'bad_request', 'Document must be a JSON object');
|
18270 | var DB_MISSING = new PouchError(404, 'not_found', 'Database not found');
|
18271 | var IDB_ERROR = new PouchError(500, 'indexed_db_went_bad', 'unknown');
|
18272 | var WSQ_ERROR = new PouchError(500, 'web_sql_went_bad', 'unknown');
|
18273 | var LDB_ERROR = new PouchError(500, 'levelDB_went_went_bad', 'unknown');
|
18274 | var FORBIDDEN = new PouchError(403, 'forbidden', 'Forbidden by design doc validate_doc_update function');
|
18275 | var INVALID_REV = new PouchError(400, 'bad_request', 'Invalid rev format');
|
18276 | var FILE_EXISTS = new PouchError(412, 'file_exists', 'The database could not be created, the file already exists.');
|
18277 | var MISSING_STUB = new PouchError(412, 'missing_stub', 'A pre-existing attachment stub wasn\'t found');
|
18278 | var INVALID_URL = new PouchError(413, 'invalid_url', 'Provided URL is invalid');
|
18279 |
|
18280 | function createError(error, reason) {
|
18281 | function CustomPouchError(reason) {
|
18282 |
|
18283 |
|
18284 |
|
18285 | for (var p in error) {
|
18286 | if (typeof error[p] !== 'function') {
|
18287 | this[p] = error[p];
|
18288 | }
|
18289 | }
|
18290 |
|
18291 | if (reason !== undefined) {
|
18292 | this.reason = reason;
|
18293 | }
|
18294 | }
|
18295 | CustomPouchError.prototype = PouchError.prototype;
|
18296 | return new CustomPouchError(reason);
|
18297 | }
|
18298 |
|
18299 | function tryFilter(filter, doc, req) {
|
18300 | try {
|
18301 | return !filter(doc, req);
|
18302 | } catch (err) {
|
18303 | var msg = 'Filter function threw: ' + err.toString();
|
18304 | return createError(BAD_REQUEST, msg);
|
18305 | }
|
18306 | }
|
18307 |
|
18308 | function filterChange(opts) {
|
18309 | var req = {};
|
18310 | var hasFilter = opts.filter && typeof opts.filter === 'function';
|
18311 | req.query = opts.query_params;
|
18312 |
|
18313 | return function filter(change) {
|
18314 | if (!change.doc) {
|
18315 |
|
18316 |
|
18317 | change.doc = {};
|
18318 | }
|
18319 |
|
18320 | var filterReturn = hasFilter && tryFilter(opts.filter, change.doc, req);
|
18321 |
|
18322 | if (typeof filterReturn === 'object') {
|
18323 | return filterReturn;
|
18324 | }
|
18325 |
|
18326 | if (filterReturn) {
|
18327 | return false;
|
18328 | }
|
18329 |
|
18330 | if (!opts.include_docs) {
|
18331 | delete change.doc;
|
18332 | } else if (!opts.attachments) {
|
18333 | for (var att in change.doc._attachments) {
|
18334 |
|
18335 | if (change.doc._attachments.hasOwnProperty(att)) {
|
18336 | change.doc._attachments[att].stub = true;
|
18337 | }
|
18338 | }
|
18339 | }
|
18340 | return true;
|
18341 | };
|
18342 | }
|
18343 |
|
18344 |
|
18345 |
|
18346 |
|
18347 |
|
18348 | function f() {}
|
18349 |
|
18350 | var hasName = f.name;
|
18351 | var res;
|
18352 |
|
18353 |
|
18354 |
|
18355 | if (hasName) {
|
18356 | res = function (fun) {
|
18357 | return fun.name;
|
18358 | };
|
18359 | } else {
|
18360 | res = function (fun) {
|
18361 | var match = fun.toString().match(/^\s*function\s*(?:(\S+)\s*)?\(/);
|
18362 | if (match && match[1]) {
|
18363 | return match[1];
|
18364 | }
|
18365 | else {
|
18366 | return '';
|
18367 | }
|
18368 | };
|
18369 | }
|
18370 |
|
18371 | var functionName = res;
|
18372 |
|
18373 |
|
18374 |
|
18375 |
|
18376 |
|
18377 |
|
18378 | function invalidIdError(id) {
|
18379 | var err;
|
18380 | if (!id) {
|
18381 | err = createError(MISSING_ID);
|
18382 | } else if (typeof id !== 'string') {
|
18383 | err = createError(INVALID_ID);
|
18384 | } else if (/^_/.test(id) && !(/^_(design|local)/).test(id)) {
|
18385 | err = createError(RESERVED_ID);
|
18386 | }
|
18387 | if (err) {
|
18388 | throw err;
|
18389 | }
|
18390 | }
|
18391 |
|
18392 |
|
18393 |
|
18394 |
|
18395 |
|
18396 |
|
18397 |
|
18398 | var thisAtob = function (str) {
|
18399 | return atob(str);
|
18400 | };
|
18401 |
|
18402 | var thisBtoa = function (str) {
|
18403 | return btoa(str);
|
18404 | };
|
18405 |
|
18406 |
|
18407 |
|
18408 |
|
18409 | function createBlob(parts, properties) {
|
18410 |
|
18411 | parts = parts || [];
|
18412 | properties = properties || {};
|
18413 | try {
|
18414 | return new Blob(parts, properties);
|
18415 | } catch (e) {
|
18416 | if (e.name !== "TypeError") {
|
18417 | throw e;
|
18418 | }
|
18419 | var Builder = typeof BlobBuilder !== 'undefined' ? BlobBuilder :
|
18420 | typeof MSBlobBuilder !== 'undefined' ? MSBlobBuilder :
|
18421 | typeof MozBlobBuilder !== 'undefined' ? MozBlobBuilder :
|
18422 | WebKitBlobBuilder;
|
18423 | var builder = new Builder();
|
18424 | for (var i = 0; i < parts.length; i += 1) {
|
18425 | builder.append(parts[i]);
|
18426 | }
|
18427 | return builder.getBlob(properties.type);
|
18428 | }
|
18429 | }
|
18430 |
|
18431 |
|
18432 |
|
18433 | function binaryStringToArrayBuffer(bin) {
|
18434 | var length = bin.length;
|
18435 | var buf = new ArrayBuffer(length);
|
18436 | var arr = new Uint8Array(buf);
|
18437 | for (var i = 0; i < length; i++) {
|
18438 | arr[i] = bin.charCodeAt(i);
|
18439 | }
|
18440 | return buf;
|
18441 | }
|
18442 |
|
18443 | function binStringToBluffer(binString, type) {
|
18444 | return createBlob([binaryStringToArrayBuffer(binString)], {type: type});
|
18445 | }
|
18446 |
|
18447 |
|
18448 |
|
18449 |
|
18450 | function arrayBufferToBinaryString(buffer) {
|
18451 | var binary = '';
|
18452 | var bytes = new Uint8Array(buffer);
|
18453 | var length = bytes.byteLength;
|
18454 | for (var i = 0; i < length; i++) {
|
18455 | binary += String.fromCharCode(bytes[i]);
|
18456 | }
|
18457 | return binary;
|
18458 | }
|
18459 |
|
18460 |
|
18461 | function readAsBinaryString(blob, callback) {
|
18462 | var reader = new FileReader();
|
18463 | var hasBinaryString = typeof reader.readAsBinaryString === 'function';
|
18464 | reader.onloadend = function (e) {
|
18465 | var result = e.target.result || '';
|
18466 | if (hasBinaryString) {
|
18467 | return callback(result);
|
18468 | }
|
18469 | callback(arrayBufferToBinaryString(result));
|
18470 | };
|
18471 | if (hasBinaryString) {
|
18472 | reader.readAsBinaryString(blob);
|
18473 | } else {
|
18474 | reader.readAsArrayBuffer(blob);
|
18475 | }
|
18476 | }
|
18477 |
|
18478 |
|
18479 | function readAsArrayBuffer(blob, callback) {
|
18480 | var reader = new FileReader();
|
18481 | reader.onloadend = function (e) {
|
18482 | var result = e.target.result || new ArrayBuffer(0);
|
18483 | callback(result);
|
18484 | };
|
18485 | reader.readAsArrayBuffer(blob);
|
18486 | }
|
18487 |
|
18488 |
|
18489 |
|
18490 | var setImmediateShim = global.setImmediate || global.setTimeout;
|
18491 | var MD5_CHUNK_SIZE = 32768;
|
18492 |
|
18493 | function rawToBase64(raw) {
|
18494 | return thisBtoa(raw);
|
18495 | }
|
18496 |
|
18497 | function sliceBlob(blob, start, end) {
|
18498 | if (blob.webkitSlice) {
|
18499 | return blob.webkitSlice(start, end);
|
18500 | }
|
18501 | return blob.slice(start, end);
|
18502 | }
|
18503 |
|
18504 | function appendBlob(buffer, blob, start, end, callback) {
|
18505 | if (start > 0 || end < blob.size) {
|
18506 |
|
18507 | blob = sliceBlob(blob, start, end);
|
18508 | }
|
18509 | readAsArrayBuffer(blob, function (arrayBuffer) {
|
18510 | buffer.append(arrayBuffer);
|
18511 | callback();
|
18512 | });
|
18513 | }
|
18514 |
|
18515 | function appendString(buffer, string, start, end, callback) {
|
18516 | if (start > 0 || end < string.length) {
|
18517 |
|
18518 | string = string.substring(start, end);
|
18519 | }
|
18520 | buffer.appendBinary(string);
|
18521 | callback();
|
18522 | }
|
18523 |
|
18524 | function binaryMd5(data, callback) {
|
18525 | var inputIsString = typeof data === 'string';
|
18526 | var len = inputIsString ? data.length : data.size;
|
18527 | var chunkSize = Math.min(MD5_CHUNK_SIZE, len);
|
18528 | var chunks = Math.ceil(len / chunkSize);
|
18529 | var currentChunk = 0;
|
18530 | var buffer = inputIsString ? new Md5() : new Md5.ArrayBuffer();
|
18531 |
|
18532 | var append = inputIsString ? appendString : appendBlob;
|
18533 |
|
18534 | function next() {
|
18535 | setImmediateShim(loadNextChunk);
|
18536 | }
|
18537 |
|
18538 | function done() {
|
18539 | var raw = buffer.end(true);
|
18540 | var base64 = rawToBase64(raw);
|
18541 | callback(base64);
|
18542 | buffer.destroy();
|
18543 | }
|
18544 |
|
18545 | function loadNextChunk() {
|
18546 | var start = currentChunk * chunkSize;
|
18547 | var end = start + chunkSize;
|
18548 | currentChunk++;
|
18549 | if (currentChunk < chunks) {
|
18550 | append(buffer, data, start, end, next);
|
18551 | } else {
|
18552 | append(buffer, data, start, end, done);
|
18553 | }
|
18554 | }
|
18555 | loadNextChunk();
|
18556 | }
|
18557 |
|
18558 | function stringMd5(string) {
|
18559 | return Md5.hash(string);
|
18560 | }
|
18561 |
|
18562 | function rev(doc, deterministic_revs) {
|
18563 | var clonedDoc = clone(doc);
|
18564 | if (!deterministic_revs) {
|
18565 | return uuidV4.v4().replace(/-/g, '').toLowerCase();
|
18566 | }
|
18567 |
|
18568 | delete clonedDoc._rev_tree;
|
18569 | return stringMd5(JSON.stringify(clonedDoc));
|
18570 | }
|
18571 |
|
18572 | var uuid = uuidV4.v4;
|
18573 |
|
18574 | function isFunction(f) {
|
18575 | return 'function' === typeof f;
|
18576 | }
|
18577 |
|
18578 | function getPrefix(db) {
|
18579 | if (isFunction(db.prefix)) {
|
18580 | return db.prefix();
|
18581 | }
|
18582 | return db;
|
18583 | }
|
18584 |
|
18585 | function clone$1(_obj) {
|
18586 | var obj = {};
|
18587 | for (var k in _obj) {
|
18588 | obj[k] = _obj[k];
|
18589 | }
|
18590 | return obj;
|
18591 | }
|
18592 |
|
18593 | function nut(db, precodec, codec) {
|
18594 | function encodePrefix(prefix, key, opts1, opts2) {
|
18595 | return precodec.encode([ prefix, codec.encodeKey(key, opts1, opts2 ) ]);
|
18596 | }
|
18597 |
|
18598 | function addEncodings(op, prefix) {
|
18599 | if (prefix && prefix.options) {
|
18600 | op.keyEncoding =
|
18601 | op.keyEncoding || prefix.options.keyEncoding;
|
18602 | op.valueEncoding =
|
18603 | op.valueEncoding || prefix.options.valueEncoding;
|
18604 | }
|
18605 | return op;
|
18606 | }
|
18607 |
|
18608 | db.open(function () { });
|
18609 |
|
18610 | return {
|
18611 | apply: function (ops, opts, cb) {
|
18612 | opts = opts || {};
|
18613 |
|
18614 | var batch = [];
|
18615 | var i = -1;
|
18616 | var len = ops.length;
|
18617 |
|
18618 | while (++i < len) {
|
18619 | var op = ops[i];
|
18620 | addEncodings(op, op.prefix);
|
18621 | op.prefix = getPrefix(op.prefix);
|
18622 | batch.push({
|
18623 | key: encodePrefix(op.prefix, op.key, opts, op),
|
18624 | value: op.type !== 'del' && codec.encodeValue(op.value, opts, op),
|
18625 | type: op.type
|
18626 | });
|
18627 | }
|
18628 | db.db.batch(batch, opts, cb);
|
18629 | },
|
18630 | get: function (key, prefix, opts, cb) {
|
18631 | opts.asBuffer = codec.valueAsBuffer(opts);
|
18632 | return db.db.get(
|
18633 | encodePrefix(prefix, key, opts),
|
18634 | opts,
|
18635 | function (err, value) {
|
18636 | if (err) {
|
18637 | cb(err);
|
18638 | } else {
|
18639 | cb(null, codec.decodeValue(value, opts));
|
18640 | }
|
18641 | }
|
18642 | );
|
18643 | },
|
18644 | createDecoder: function (opts) {
|
18645 | return function (key, value) {
|
18646 | return {
|
18647 | key: codec.decodeKey(precodec.decode(key)[1], opts),
|
18648 | value: codec.decodeValue(value, opts)
|
18649 | };
|
18650 | };
|
18651 | },
|
18652 | isClosed: function isClosed() {
|
18653 | return db.isClosed();
|
18654 | },
|
18655 | close: function close(cb) {
|
18656 | return db.close(cb);
|
18657 | },
|
18658 | iterator: function (_opts) {
|
18659 | var opts = clone$1(_opts || {});
|
18660 | var prefix = _opts.prefix || [];
|
18661 |
|
18662 | function encodeKey(key) {
|
18663 | return encodePrefix(prefix, key, opts, {});
|
18664 | }
|
18665 |
|
18666 | ltgt.toLtgt(_opts, opts, encodeKey, precodec.lowerBound, precodec.upperBound);
|
18667 |
|
18668 |
|
18669 |
|
18670 | opts.prefix = null;
|
18671 |
|
18672 |
|
18673 |
|
18674 |
|
18675 | opts.keyAsBuffer = opts.valueAsBuffer = false;
|
18676 |
|
18677 |
|
18678 |
|
18679 |
|
18680 |
|
18681 |
|
18682 | if ('number' !== typeof opts.limit) {
|
18683 | opts.limit = -1;
|
18684 | }
|
18685 |
|
18686 | opts.keyAsBuffer = precodec.buffer;
|
18687 | opts.valueAsBuffer = codec.valueAsBuffer(opts);
|
18688 |
|
18689 | function wrapIterator(iterator) {
|
18690 | return {
|
18691 | next: function (cb) {
|
18692 | return iterator.next(cb);
|
18693 | },
|
18694 | end: function (cb) {
|
18695 | iterator.end(cb);
|
18696 | }
|
18697 | };
|
18698 | }
|
18699 |
|
18700 | return wrapIterator(db.db.iterator(opts));
|
18701 | }
|
18702 | };
|
18703 | }
|
18704 |
|
18705 | function NotFoundError() {
|
18706 | Error.call(this);
|
18707 | }
|
18708 |
|
18709 | inherits(NotFoundError, Error);
|
18710 |
|
18711 | NotFoundError.prototype.name = 'NotFoundError';
|
18712 |
|
18713 | var EventEmitter = events__default.EventEmitter;
|
18714 | var version = "6.5.4";
|
18715 |
|
18716 | var NOT_FOUND_ERROR = new NotFoundError();
|
18717 |
|
18718 | var sublevel = function (nut, prefix, createStream, options) {
|
18719 | var emitter = new EventEmitter();
|
18720 | emitter.sublevels = {};
|
18721 | emitter.options = options;
|
18722 |
|
18723 | emitter.version = version;
|
18724 |
|
18725 | emitter.methods = {};
|
18726 | prefix = prefix || [];
|
18727 |
|
18728 | function mergeOpts(opts) {
|
18729 | var o = {};
|
18730 | var k;
|
18731 | if (options) {
|
18732 | for (k in options) {
|
18733 | if (typeof options[k] !== 'undefined') {
|
18734 | o[k] = options[k];
|
18735 | }
|
18736 | }
|
18737 | }
|
18738 | if (opts) {
|
18739 | for (k in opts) {
|
18740 | if (typeof opts[k] !== 'undefined') {
|
18741 | o[k] = opts[k];
|
18742 | }
|
18743 | }
|
18744 | }
|
18745 | return o;
|
18746 | }
|
18747 |
|
18748 | emitter.put = function (key, value, opts, cb) {
|
18749 | if ('function' === typeof opts) {
|
18750 | cb = opts;
|
18751 | opts = {};
|
18752 | }
|
18753 |
|
18754 | nut.apply([{
|
18755 | key: key, value: value,
|
18756 | prefix: prefix.slice(), type: 'put'
|
18757 | }], mergeOpts(opts), function (err) {
|
18758 |
|
18759 | if (err) {
|
18760 | return cb(err);
|
18761 | }
|
18762 | emitter.emit('put', key, value);
|
18763 | cb(null);
|
18764 | });
|
18765 | };
|
18766 |
|
18767 | emitter.prefix = function () {
|
18768 | return prefix.slice();
|
18769 | };
|
18770 |
|
18771 | emitter.batch = function (ops, opts, cb) {
|
18772 | if ('function' === typeof opts) {
|
18773 | cb = opts;
|
18774 | opts = {};
|
18775 | }
|
18776 |
|
18777 | ops = ops.map(function (op) {
|
18778 | return {
|
18779 | key: op.key,
|
18780 | value: op.value,
|
18781 | prefix: op.prefix || prefix,
|
18782 | keyEncoding: op.keyEncoding,
|
18783 | valueEncoding: op.valueEncoding,
|
18784 | type: op.type
|
18785 | };
|
18786 | });
|
18787 |
|
18788 | nut.apply(ops, mergeOpts(opts), function (err) {
|
18789 |
|
18790 | if (err) {
|
18791 | return cb(err);
|
18792 | }
|
18793 | emitter.emit('batch', ops);
|
18794 | cb(null);
|
18795 | });
|
18796 | };
|
18797 |
|
18798 | emitter.get = function (key, opts, cb) {
|
18799 |
|
18800 | if ('function' === typeof opts) {
|
18801 | cb = opts;
|
18802 | opts = {};
|
18803 | }
|
18804 | nut.get(key, prefix, mergeOpts(opts), function (err, value) {
|
18805 | if (err) {
|
18806 | cb(NOT_FOUND_ERROR);
|
18807 | } else {
|
18808 | cb(null, value);
|
18809 | }
|
18810 | });
|
18811 | };
|
18812 |
|
18813 | emitter.sublevel = function (name, opts) {
|
18814 | return emitter.sublevels[name] =
|
18815 | emitter.sublevels[name] || sublevel(nut, prefix.concat(name), createStream, mergeOpts(opts));
|
18816 | };
|
18817 |
|
18818 | emitter.readStream = emitter.createReadStream = function (opts) {
|
18819 | opts = mergeOpts(opts);
|
18820 | opts.prefix = prefix;
|
18821 | var stream;
|
18822 | var it = nut.iterator(opts);
|
18823 |
|
18824 | stream = createStream(opts, nut.createDecoder(opts));
|
18825 | stream.setIterator(it);
|
18826 |
|
18827 | return stream;
|
18828 | };
|
18829 |
|
18830 | emitter.close = function (cb) {
|
18831 | nut.close(cb);
|
18832 | };
|
18833 |
|
18834 | emitter.isOpen = nut.isOpen;
|
18835 | emitter.isClosed = nut.isClosed;
|
18836 |
|
18837 | return emitter;
|
18838 | };
|
18839 |
|
18840 |
|
18841 |
|
18842 |
|
18843 |
|
18844 |
|
18845 | var Readable = ReadableStreamCore.Readable;
|
18846 |
|
18847 | function ReadStream(options, makeData) {
|
18848 | if (!(this instanceof ReadStream)) {
|
18849 | return new ReadStream(options, makeData);
|
18850 | }
|
18851 |
|
18852 | Readable.call(this, { objectMode: true, highWaterMark: options.highWaterMark });
|
18853 |
|
18854 |
|
18855 |
|
18856 | this._waiting = false;
|
18857 | this._options = options;
|
18858 | this._makeData = makeData;
|
18859 | }
|
18860 |
|
18861 | inherits(ReadStream, Readable);
|
18862 |
|
18863 | ReadStream.prototype.setIterator = function (it) {
|
18864 | this._iterator = it;
|
18865 |
|
18866 | if (this._destroyed) {
|
18867 | return it.end(function () {});
|
18868 | }
|
18869 |
|
18870 | if (this._waiting) {
|
18871 | this._waiting = false;
|
18872 | return this._read();
|
18873 | }
|
18874 | return this;
|
18875 | };
|
18876 |
|
18877 | ReadStream.prototype._read = function read() {
|
18878 | var self = this;
|
18879 |
|
18880 | if (self._destroyed) {
|
18881 | return;
|
18882 | }
|
18883 |
|
18884 | if (!self._iterator) {
|
18885 | return this._waiting = true;
|
18886 | }
|
18887 |
|
18888 | self._iterator.next(function (err, key, value) {
|
18889 | if (err || (key === undefined && value === undefined)) {
|
18890 | if (!err && !self._destroyed) {
|
18891 | self.push(null);
|
18892 | }
|
18893 | return self._cleanup(err);
|
18894 | }
|
18895 |
|
18896 |
|
18897 | value = self._makeData(key, value);
|
18898 | if (!self._destroyed) {
|
18899 | self.push(value);
|
18900 | }
|
18901 | });
|
18902 | };
|
18903 |
|
18904 | ReadStream.prototype._cleanup = function (err) {
|
18905 | if (this._destroyed) {
|
18906 | return;
|
18907 | }
|
18908 |
|
18909 | this._destroyed = true;
|
18910 |
|
18911 | var self = this;
|
18912 |
|
18913 | if (err && err.message !== 'iterator has ended') {
|
18914 | self.emit('error', err);
|
18915 | }
|
18916 |
|
18917 |
|
18918 | if (self._iterator) {
|
18919 | self._iterator.end(function () {
|
18920 | self._iterator = null;
|
18921 | self.emit('close');
|
18922 | });
|
18923 | } else {
|
18924 | self.emit('close');
|
18925 | }
|
18926 | };
|
18927 |
|
18928 | ReadStream.prototype.destroy = function () {
|
18929 | this._cleanup();
|
18930 | };
|
18931 |
|
18932 | var precodec = {
|
18933 | encode: function (decodedKey) {
|
18934 | return '\xff' + decodedKey[0] + '\xff' + decodedKey[1];
|
18935 | },
|
18936 | decode: function (encodedKeyAsBuffer) {
|
18937 | var str = encodedKeyAsBuffer.toString();
|
18938 | var idx = str.indexOf('\xff', 1);
|
18939 | return [str.substring(1, idx), str.substring(idx + 1)];
|
18940 | },
|
18941 | lowerBound: '\x00',
|
18942 | upperBound: '\xff'
|
18943 | };
|
18944 |
|
18945 | var codec = new Codec();
|
18946 |
|
18947 | function sublevelPouch(db) {
|
18948 | return sublevel(nut(db, precodec, codec), [], ReadStream, db.options);
|
18949 | }
|
18950 |
|
18951 | function allDocsKeysQuery(api, opts) {
|
18952 | var keys = opts.keys;
|
18953 | var finalResults = {
|
18954 | offset: opts.skip
|
18955 | };
|
18956 | return Promise.all(keys.map(function (key) {
|
18957 | var subOpts = $inject_Object_assign({key: key, deleted: 'ok'}, opts);
|
18958 | ['limit', 'skip', 'keys'].forEach(function (optKey) {
|
18959 | delete subOpts[optKey];
|
18960 | });
|
18961 | return new Promise(function (resolve, reject) {
|
18962 | api._allDocs(subOpts, function (err, res) {
|
18963 |
|
18964 | if (err) {
|
18965 | return reject(err);
|
18966 | }
|
18967 |
|
18968 | if (opts.update_seq && res.update_seq !== undefined) {
|
18969 | finalResults.update_seq = res.update_seq;
|
18970 | }
|
18971 | finalResults.total_rows = res.total_rows;
|
18972 | resolve(res.rows[0] || {key: key, error: 'not_found'});
|
18973 | });
|
18974 | });
|
18975 | })).then(function (results) {
|
18976 | finalResults.rows = results;
|
18977 | return finalResults;
|
18978 | });
|
18979 | }
|
18980 |
|
18981 | function toObject(array) {
|
18982 | return array.reduce(function (obj, item) {
|
18983 | obj[item] = true;
|
18984 | return obj;
|
18985 | }, {});
|
18986 | }
|
18987 |
|
18988 | var reservedWords = toObject([
|
18989 | '_id',
|
18990 | '_rev',
|
18991 | '_attachments',
|
18992 | '_deleted',
|
18993 | '_revisions',
|
18994 | '_revs_info',
|
18995 | '_conflicts',
|
18996 | '_deleted_conflicts',
|
18997 | '_local_seq',
|
18998 | '_rev_tree',
|
18999 |
|
19000 | '_replication_id',
|
19001 | '_replication_state',
|
19002 | '_replication_state_time',
|
19003 | '_replication_state_reason',
|
19004 | '_replication_stats',
|
19005 |
|
19006 | '_removed'
|
19007 | ]);
|
19008 |
|
19009 |
|
19010 | var dataWords = toObject([
|
19011 | '_attachments',
|
19012 |
|
19013 | '_replication_id',
|
19014 | '_replication_state',
|
19015 | '_replication_state_time',
|
19016 | '_replication_state_reason',
|
19017 | '_replication_stats'
|
19018 | ]);
|
19019 |
|
19020 | function parseRevisionInfo(rev$$1) {
|
19021 | if (!/^\d+-/.test(rev$$1)) {
|
19022 | return createError(INVALID_REV);
|
19023 | }
|
19024 | var idx = rev$$1.indexOf('-');
|
19025 | var left = rev$$1.substring(0, idx);
|
19026 | var right = rev$$1.substring(idx + 1);
|
19027 | return {
|
19028 | prefix: parseInt(left, 10),
|
19029 | id: right
|
19030 | };
|
19031 | }
|
19032 |
|
19033 | function makeRevTreeFromRevisions(revisions, opts) {
|
19034 | var pos = revisions.start - revisions.ids.length + 1;
|
19035 |
|
19036 | var revisionIds = revisions.ids;
|
19037 | var ids = [revisionIds[0], opts, []];
|
19038 |
|
19039 | for (var i = 1, len = revisionIds.length; i < len; i++) {
|
19040 | ids = [revisionIds[i], {status: 'missing'}, [ids]];
|
19041 | }
|
19042 |
|
19043 | return [{
|
19044 | pos: pos,
|
19045 | ids: ids
|
19046 | }];
|
19047 | }
|
19048 |
|
19049 |
|
19050 |
|
19051 | function parseDoc(doc, newEdits, dbOpts) {
|
19052 | if (!dbOpts) {
|
19053 | dbOpts = {
|
19054 | deterministic_revs: true
|
19055 | };
|
19056 | }
|
19057 |
|
19058 | var nRevNum;
|
19059 | var newRevId;
|
19060 | var revInfo;
|
19061 | var opts = {status: 'available'};
|
19062 | if (doc._deleted) {
|
19063 | opts.deleted = true;
|
19064 | }
|
19065 |
|
19066 | if (newEdits) {
|
19067 | if (!doc._id) {
|
19068 | doc._id = uuid();
|
19069 | }
|
19070 | newRevId = rev(doc, dbOpts.deterministic_revs);
|
19071 | if (doc._rev) {
|
19072 | revInfo = parseRevisionInfo(doc._rev);
|
19073 | if (revInfo.error) {
|
19074 | return revInfo;
|
19075 | }
|
19076 | doc._rev_tree = [{
|
19077 | pos: revInfo.prefix,
|
19078 | ids: [revInfo.id, {status: 'missing'}, [[newRevId, opts, []]]]
|
19079 | }];
|
19080 | nRevNum = revInfo.prefix + 1;
|
19081 | } else {
|
19082 | doc._rev_tree = [{
|
19083 | pos: 1,
|
19084 | ids : [newRevId, opts, []]
|
19085 | }];
|
19086 | nRevNum = 1;
|
19087 | }
|
19088 | } else {
|
19089 | if (doc._revisions) {
|
19090 | doc._rev_tree = makeRevTreeFromRevisions(doc._revisions, opts);
|
19091 | nRevNum = doc._revisions.start;
|
19092 | newRevId = doc._revisions.ids[0];
|
19093 | }
|
19094 | if (!doc._rev_tree) {
|
19095 | revInfo = parseRevisionInfo(doc._rev);
|
19096 | if (revInfo.error) {
|
19097 | return revInfo;
|
19098 | }
|
19099 | nRevNum = revInfo.prefix;
|
19100 | newRevId = revInfo.id;
|
19101 | doc._rev_tree = [{
|
19102 | pos: nRevNum,
|
19103 | ids: [newRevId, opts, []]
|
19104 | }];
|
19105 | }
|
19106 | }
|
19107 |
|
19108 | invalidIdError(doc._id);
|
19109 |
|
19110 | doc._rev = nRevNum + '-' + newRevId;
|
19111 |
|
19112 | var result = {metadata : {}, data : {}};
|
19113 | for (var key in doc) {
|
19114 |
|
19115 | if (Object.prototype.hasOwnProperty.call(doc, key)) {
|
19116 | var specialKey = key[0] === '_';
|
19117 | if (specialKey && !reservedWords[key]) {
|
19118 | var error = createError(DOC_VALIDATION, key);
|
19119 | error.message = DOC_VALIDATION.message + ': ' + key;
|
19120 | throw error;
|
19121 | } else if (specialKey && !dataWords[key]) {
|
19122 | result.metadata[key.slice(1)] = doc[key];
|
19123 | } else {
|
19124 | result.data[key] = doc[key];
|
19125 | }
|
19126 | }
|
19127 | }
|
19128 | return result;
|
19129 | }
|
19130 |
|
19131 |
|
19132 |
|
19133 |
|
19134 |
|
19135 |
|
19136 | function winningRev(metadata) {
|
19137 | var winningId;
|
19138 | var winningPos;
|
19139 | var winningDeleted;
|
19140 | var toVisit = metadata.rev_tree.slice();
|
19141 | var node;
|
19142 | while ((node = toVisit.pop())) {
|
19143 | var tree = node.ids;
|
19144 | var branches = tree[2];
|
19145 | var pos = node.pos;
|
19146 | if (branches.length) {
|
19147 | for (var i = 0, len = branches.length; i < len; i++) {
|
19148 | toVisit.push({pos: pos + 1, ids: branches[i]});
|
19149 | }
|
19150 | continue;
|
19151 | }
|
19152 | var deleted = !!tree[1].deleted;
|
19153 | var id = tree[0];
|
19154 |
|
19155 | if (!winningId || (winningDeleted !== deleted ? winningDeleted :
|
19156 | winningPos !== pos ? winningPos < pos : winningId < id)) {
|
19157 | winningId = id;
|
19158 | winningPos = pos;
|
19159 | winningDeleted = deleted;
|
19160 | }
|
19161 | }
|
19162 |
|
19163 | return winningPos + '-' + winningId;
|
19164 | }
|
19165 |
|
19166 |
|
19167 |
|
19168 |
|
19169 |
|
19170 | function traverseRevTree(revs, callback) {
|
19171 | var toVisit = revs.slice();
|
19172 |
|
19173 | var node;
|
19174 | while ((node = toVisit.pop())) {
|
19175 | var pos = node.pos;
|
19176 | var tree = node.ids;
|
19177 | var branches = tree[2];
|
19178 | var newCtx =
|
19179 | callback(branches.length === 0, pos, tree[0], node.ctx, tree[1]);
|
19180 | for (var i = 0, len = branches.length; i < len; i++) {
|
19181 | toVisit.push({pos: pos + 1, ids: branches[i], ctx: newCtx});
|
19182 | }
|
19183 | }
|
19184 | }
|
19185 |
|
19186 | function sortByPos(a, b) {
|
19187 | return a.pos - b.pos;
|
19188 | }
|
19189 |
|
19190 | function collectLeaves(revs) {
|
19191 | var leaves = [];
|
19192 | traverseRevTree(revs, function (isLeaf, pos, id, acc, opts) {
|
19193 | if (isLeaf) {
|
19194 | leaves.push({rev: pos + "-" + id, pos: pos, opts: opts});
|
19195 | }
|
19196 | });
|
19197 | leaves.sort(sortByPos).reverse();
|
19198 | for (var i = 0, len = leaves.length; i < len; i++) {
|
19199 | delete leaves[i].pos;
|
19200 | }
|
19201 | return leaves;
|
19202 | }
|
19203 |
|
19204 |
|
19205 |
|
19206 |
|
19207 | function collectConflicts(metadata) {
|
19208 | var win = winningRev(metadata);
|
19209 | var leaves = collectLeaves(metadata.rev_tree);
|
19210 | var conflicts = [];
|
19211 | for (var i = 0, len = leaves.length; i < len; i++) {
|
19212 | var leaf = leaves[i];
|
19213 | if (leaf.rev !== win && !leaf.opts.deleted) {
|
19214 | conflicts.push(leaf.rev);
|
19215 | }
|
19216 | }
|
19217 | return conflicts;
|
19218 | }
|
19219 |
|
19220 |
|
19221 |
|
19222 | function compactTree(metadata) {
|
19223 | var revs = [];
|
19224 | traverseRevTree(metadata.rev_tree, function (isLeaf, pos,
|
19225 | revHash, ctx, opts) {
|
19226 | if (opts.status === 'available' && !isLeaf) {
|
19227 | revs.push(pos + '-' + revHash);
|
19228 | opts.status = 'missing';
|
19229 | }
|
19230 | });
|
19231 | return revs;
|
19232 | }
|
19233 |
|
19234 |
|
19235 | function rootToLeaf(revs) {
|
19236 | var paths = [];
|
19237 | var toVisit = revs.slice();
|
19238 | var node;
|
19239 | while ((node = toVisit.pop())) {
|
19240 | var pos = node.pos;
|
19241 | var tree = node.ids;
|
19242 | var id = tree[0];
|
19243 | var opts = tree[1];
|
19244 | var branches = tree[2];
|
19245 | var isLeaf = branches.length === 0;
|
19246 |
|
19247 | var history = node.history ? node.history.slice() : [];
|
19248 | history.push({id: id, opts: opts});
|
19249 | if (isLeaf) {
|
19250 | paths.push({pos: (pos + 1 - history.length), ids: history});
|
19251 | }
|
19252 | for (var i = 0, len = branches.length; i < len; i++) {
|
19253 | toVisit.push({pos: pos + 1, ids: branches[i], history: history});
|
19254 | }
|
19255 | }
|
19256 | return paths.reverse();
|
19257 | }
|
19258 |
|
19259 |
|
19260 |
|
19261 | function sortByPos$1(a, b) {
|
19262 | return a.pos - b.pos;
|
19263 | }
|
19264 |
|
19265 |
|
19266 | function binarySearch(arr, item, comparator) {
|
19267 | var low = 0;
|
19268 | var high = arr.length;
|
19269 | var mid;
|
19270 | while (low < high) {
|
19271 | mid = (low + high) >>> 1;
|
19272 | if (comparator(arr[mid], item) < 0) {
|
19273 | low = mid + 1;
|
19274 | } else {
|
19275 | high = mid;
|
19276 | }
|
19277 | }
|
19278 | return low;
|
19279 | }
|
19280 |
|
19281 |
|
19282 | function insertSorted(arr, item, comparator) {
|
19283 | var idx = binarySearch(arr, item, comparator);
|
19284 | arr.splice(idx, 0, item);
|
19285 | }
|
19286 |
|
19287 |
|
19288 |
|
19289 |
|
19290 | function pathToTree(path, numStemmed) {
|
19291 | var root;
|
19292 | var leaf;
|
19293 | for (var i = numStemmed, len = path.length; i < len; i++) {
|
19294 | var node = path[i];
|
19295 | var currentLeaf = [node.id, node.opts, []];
|
19296 | if (leaf) {
|
19297 | leaf[2].push(currentLeaf);
|
19298 | leaf = currentLeaf;
|
19299 | } else {
|
19300 | root = leaf = currentLeaf;
|
19301 | }
|
19302 | }
|
19303 | return root;
|
19304 | }
|
19305 |
|
19306 |
|
19307 | function compareTree(a, b) {
|
19308 | return a[0] < b[0] ? -1 : 1;
|
19309 | }
|
19310 |
|
19311 |
|
19312 |
|
19313 | function mergeTree(in_tree1, in_tree2) {
|
19314 | var queue = [{tree1: in_tree1, tree2: in_tree2}];
|
19315 | var conflicts = false;
|
19316 | while (queue.length > 0) {
|
19317 | var item = queue.pop();
|
19318 | var tree1 = item.tree1;
|
19319 | var tree2 = item.tree2;
|
19320 |
|
19321 | if (tree1[1].status || tree2[1].status) {
|
19322 | tree1[1].status =
|
19323 | (tree1[1].status === 'available' ||
|
19324 | tree2[1].status === 'available') ? 'available' : 'missing';
|
19325 | }
|
19326 |
|
19327 | for (var i = 0; i < tree2[2].length; i++) {
|
19328 | if (!tree1[2][0]) {
|
19329 | conflicts = 'new_leaf';
|
19330 | tree1[2][0] = tree2[2][i];
|
19331 | continue;
|
19332 | }
|
19333 |
|
19334 | var merged = false;
|
19335 | for (var j = 0; j < tree1[2].length; j++) {
|
19336 | if (tree1[2][j][0] === tree2[2][i][0]) {
|
19337 | queue.push({tree1: tree1[2][j], tree2: tree2[2][i]});
|
19338 | merged = true;
|
19339 | }
|
19340 | }
|
19341 | if (!merged) {
|
19342 | conflicts = 'new_branch';
|
19343 | insertSorted(tree1[2], tree2[2][i], compareTree);
|
19344 | }
|
19345 | }
|
19346 | }
|
19347 | return {conflicts: conflicts, tree: in_tree1};
|
19348 | }
|
19349 |
|
19350 | function doMerge(tree, path, dontExpand) {
|
19351 | var restree = [];
|
19352 | var conflicts = false;
|
19353 | var merged = false;
|
19354 | var res;
|
19355 |
|
19356 | if (!tree.length) {
|
19357 | return {tree: [path], conflicts: 'new_leaf'};
|
19358 | }
|
19359 |
|
19360 | for (var i = 0, len = tree.length; i < len; i++) {
|
19361 | var branch = tree[i];
|
19362 | if (branch.pos === path.pos && branch.ids[0] === path.ids[0]) {
|
19363 |
|
19364 |
|
19365 | res = mergeTree(branch.ids, path.ids);
|
19366 | restree.push({pos: branch.pos, ids: res.tree});
|
19367 | conflicts = conflicts || res.conflicts;
|
19368 | merged = true;
|
19369 | } else if (dontExpand !== true) {
|
19370 |
|
19371 |
|
19372 |
|
19373 |
|
19374 |
|
19375 | var t1 = branch.pos < path.pos ? branch : path;
|
19376 | var t2 = branch.pos < path.pos ? path : branch;
|
19377 | var diff = t2.pos - t1.pos;
|
19378 |
|
19379 | var candidateParents = [];
|
19380 |
|
19381 | var trees = [];
|
19382 | trees.push({ids: t1.ids, diff: diff, parent: null, parentIdx: null});
|
19383 | while (trees.length > 0) {
|
19384 | var item = trees.pop();
|
19385 | if (item.diff === 0) {
|
19386 | if (item.ids[0] === t2.ids[0]) {
|
19387 | candidateParents.push(item);
|
19388 | }
|
19389 | continue;
|
19390 | }
|
19391 | var elements = item.ids[2];
|
19392 | for (var j = 0, elementsLen = elements.length; j < elementsLen; j++) {
|
19393 | trees.push({
|
19394 | ids: elements[j],
|
19395 | diff: item.diff - 1,
|
19396 | parent: item.ids,
|
19397 | parentIdx: j
|
19398 | });
|
19399 | }
|
19400 | }
|
19401 |
|
19402 | var el = candidateParents[0];
|
19403 |
|
19404 | if (!el) {
|
19405 | restree.push(branch);
|
19406 | } else {
|
19407 | res = mergeTree(el.ids, t2.ids);
|
19408 | el.parent[2][el.parentIdx] = res.tree;
|
19409 | restree.push({pos: t1.pos, ids: t1.ids});
|
19410 | conflicts = conflicts || res.conflicts;
|
19411 | merged = true;
|
19412 | }
|
19413 | } else {
|
19414 | restree.push(branch);
|
19415 | }
|
19416 | }
|
19417 |
|
19418 |
|
19419 | if (!merged) {
|
19420 | restree.push(path);
|
19421 | }
|
19422 |
|
19423 | restree.sort(sortByPos$1);
|
19424 |
|
19425 | return {
|
19426 | tree: restree,
|
19427 | conflicts: conflicts || 'internal_node'
|
19428 | };
|
19429 | }
|
19430 |
|
19431 |
|
19432 | function stem(tree, depth) {
|
19433 |
|
19434 | var paths = rootToLeaf(tree);
|
19435 | var stemmedRevs;
|
19436 |
|
19437 | var result;
|
19438 | for (var i = 0, len = paths.length; i < len; i++) {
|
19439 |
|
19440 |
|
19441 | var path = paths[i];
|
19442 | var stemmed = path.ids;
|
19443 | var node;
|
19444 | if (stemmed.length > depth) {
|
19445 |
|
19446 | if (!stemmedRevs) {
|
19447 | stemmedRevs = {};
|
19448 | }
|
19449 | var numStemmed = stemmed.length - depth;
|
19450 | node = {
|
19451 | pos: path.pos + numStemmed,
|
19452 | ids: pathToTree(stemmed, numStemmed)
|
19453 | };
|
19454 |
|
19455 | for (var s = 0; s < numStemmed; s++) {
|
19456 | var rev = (path.pos + s) + '-' + stemmed[s].id;
|
19457 | stemmedRevs[rev] = true;
|
19458 | }
|
19459 | } else {
|
19460 | node = {
|
19461 | pos: path.pos,
|
19462 | ids: pathToTree(stemmed, 0)
|
19463 | };
|
19464 | }
|
19465 |
|
19466 |
|
19467 |
|
19468 | if (result) {
|
19469 | result = doMerge(result, node, true).tree;
|
19470 | } else {
|
19471 | result = [node];
|
19472 | }
|
19473 | }
|
19474 |
|
19475 |
|
19476 | if (stemmedRevs) {
|
19477 | traverseRevTree(result, function (isLeaf, pos, revHash) {
|
19478 |
|
19479 | delete stemmedRevs[pos + '-' + revHash];
|
19480 | });
|
19481 | }
|
19482 |
|
19483 | return {
|
19484 | tree: result,
|
19485 | revs: stemmedRevs ? Object.keys(stemmedRevs) : []
|
19486 | };
|
19487 | }
|
19488 |
|
19489 | function merge(tree, path, depth) {
|
19490 | var newTree = doMerge(tree, path);
|
19491 | var stemmed = stem(newTree.tree, depth);
|
19492 | return {
|
19493 | tree: stemmed.tree,
|
19494 | stemmedRevs: stemmed.revs,
|
19495 | conflicts: newTree.conflicts
|
19496 | };
|
19497 | }
|
19498 |
|
19499 |
|
19500 | function revExists(revs, rev) {
|
19501 | var toVisit = revs.slice();
|
19502 | var splitRev = rev.split('-');
|
19503 | var targetPos = parseInt(splitRev[0], 10);
|
19504 | var targetId = splitRev[1];
|
19505 |
|
19506 | var node;
|
19507 | while ((node = toVisit.pop())) {
|
19508 | if (node.pos === targetPos && node.ids[0] === targetId) {
|
19509 | return true;
|
19510 | }
|
19511 | var branches = node.ids[2];
|
19512 | for (var i = 0, len = branches.length; i < len; i++) {
|
19513 | toVisit.push({pos: node.pos + 1, ids: branches[i]});
|
19514 | }
|
19515 | }
|
19516 | return false;
|
19517 | }
|
19518 |
|
19519 | function getTrees(node) {
|
19520 | return node.ids;
|
19521 | }
|
19522 |
|
19523 |
|
19524 |
|
19525 |
|
19526 | function isDeleted(metadata, rev) {
|
19527 | if (!rev) {
|
19528 | rev = winningRev(metadata);
|
19529 | }
|
19530 | var id = rev.substring(rev.indexOf('-') + 1);
|
19531 | var toVisit = metadata.rev_tree.map(getTrees);
|
19532 |
|
19533 | var tree;
|
19534 | while ((tree = toVisit.pop())) {
|
19535 | if (tree[0] === id) {
|
19536 | return !!tree[1].deleted;
|
19537 | }
|
19538 | toVisit = toVisit.concat(tree[2]);
|
19539 | }
|
19540 | }
|
19541 |
|
19542 | function isLocalId(id) {
|
19543 | return (/^_local/).test(id);
|
19544 | }
|
19545 |
|
19546 |
|
19547 | function latest(rev, metadata) {
|
19548 | var toVisit = metadata.rev_tree.slice();
|
19549 | var node;
|
19550 | while ((node = toVisit.pop())) {
|
19551 | var pos = node.pos;
|
19552 | var tree = node.ids;
|
19553 | var id = tree[0];
|
19554 | var opts = tree[1];
|
19555 | var branches = tree[2];
|
19556 | var isLeaf = branches.length === 0;
|
19557 |
|
19558 | var history = node.history ? node.history.slice() : [];
|
19559 | history.push({id: id, pos: pos, opts: opts});
|
19560 |
|
19561 | if (isLeaf) {
|
19562 | for (var i = 0, len = history.length; i < len; i++) {
|
19563 | var historyNode = history[i];
|
19564 | var historyRev = historyNode.pos + '-' + historyNode.id;
|
19565 |
|
19566 | if (historyRev === rev) {
|
19567 |
|
19568 | return pos + '-' + id;
|
19569 | }
|
19570 | }
|
19571 | }
|
19572 |
|
19573 | for (var j = 0, l = branches.length; j < l; j++) {
|
19574 | toVisit.push({pos: pos + 1, ids: branches[j], history: history});
|
19575 | }
|
19576 | }
|
19577 |
|
19578 |
|
19579 | throw new Error('Unable to resolve latest revision for id ' + metadata.id + ', rev ' + rev);
|
19580 | }
|
19581 |
|
19582 | function updateDoc(revLimit, prev, docInfo, results,
|
19583 | i, cb, writeDoc, newEdits) {
|
19584 |
|
19585 | if (revExists(prev.rev_tree, docInfo.metadata.rev) && !newEdits) {
|
19586 | results[i] = docInfo;
|
19587 | return cb();
|
19588 | }
|
19589 |
|
19590 |
|
19591 | var previousWinningRev = prev.winningRev || winningRev(prev);
|
19592 | var previouslyDeleted = 'deleted' in prev ? prev.deleted :
|
19593 | isDeleted(prev, previousWinningRev);
|
19594 | var deleted = 'deleted' in docInfo.metadata ? docInfo.metadata.deleted :
|
19595 | isDeleted(docInfo.metadata);
|
19596 | var isRoot = /^1-/.test(docInfo.metadata.rev);
|
19597 |
|
19598 | if (previouslyDeleted && !deleted && newEdits && isRoot) {
|
19599 | var newDoc = docInfo.data;
|
19600 | newDoc._rev = previousWinningRev;
|
19601 | newDoc._id = docInfo.metadata.id;
|
19602 | docInfo = parseDoc(newDoc, newEdits);
|
19603 | }
|
19604 |
|
19605 | var merged = merge(prev.rev_tree, docInfo.metadata.rev_tree[0], revLimit);
|
19606 |
|
19607 | var inConflict = newEdits && ((
|
19608 | (previouslyDeleted && deleted && merged.conflicts !== 'new_leaf') ||
|
19609 | (!previouslyDeleted && merged.conflicts !== 'new_leaf') ||
|
19610 | (previouslyDeleted && !deleted && merged.conflicts === 'new_branch')));
|
19611 |
|
19612 | if (inConflict) {
|
19613 | var err = createError(REV_CONFLICT);
|
19614 | results[i] = err;
|
19615 | return cb();
|
19616 | }
|
19617 |
|
19618 | var newRev = docInfo.metadata.rev;
|
19619 | docInfo.metadata.rev_tree = merged.tree;
|
19620 | docInfo.stemmedRevs = merged.stemmedRevs || [];
|
19621 |
|
19622 | if (prev.rev_map) {
|
19623 | docInfo.metadata.rev_map = prev.rev_map;
|
19624 | }
|
19625 |
|
19626 |
|
19627 | var winningRev$$1 = winningRev(docInfo.metadata);
|
19628 | var winningRevIsDeleted = isDeleted(docInfo.metadata, winningRev$$1);
|
19629 |
|
19630 |
|
19631 |
|
19632 | var delta = (previouslyDeleted === winningRevIsDeleted) ? 0 :
|
19633 | previouslyDeleted < winningRevIsDeleted ? -1 : 1;
|
19634 |
|
19635 | var newRevIsDeleted;
|
19636 | if (newRev === winningRev$$1) {
|
19637 |
|
19638 | newRevIsDeleted = winningRevIsDeleted;
|
19639 | } else {
|
19640 |
|
19641 | newRevIsDeleted = isDeleted(docInfo.metadata, newRev);
|
19642 | }
|
19643 |
|
19644 | writeDoc(docInfo, winningRev$$1, winningRevIsDeleted, newRevIsDeleted,
|
19645 | true, delta, i, cb);
|
19646 | }
|
19647 |
|
19648 | function rootIsMissing(docInfo) {
|
19649 | return docInfo.metadata.rev_tree[0].ids[1].status === 'missing';
|
19650 | }
|
19651 |
|
19652 | function processDocs(revLimit, docInfos, api, fetchedDocs, tx, results,
|
19653 | writeDoc, opts, overallCallback) {
|
19654 |
|
19655 |
|
19656 | revLimit = revLimit || 1000;
|
19657 |
|
19658 | function insertDoc(docInfo, resultsIdx, callback) {
|
19659 |
|
19660 | var winningRev$$1 = winningRev(docInfo.metadata);
|
19661 | var deleted = isDeleted(docInfo.metadata, winningRev$$1);
|
19662 | if ('was_delete' in opts && deleted) {
|
19663 | results[resultsIdx] = createError(MISSING_DOC, 'deleted');
|
19664 | return callback();
|
19665 | }
|
19666 |
|
19667 |
|
19668 | var inConflict = newEdits && rootIsMissing(docInfo);
|
19669 |
|
19670 | if (inConflict) {
|
19671 | var err = createError(REV_CONFLICT);
|
19672 | results[resultsIdx] = err;
|
19673 | return callback();
|
19674 | }
|
19675 |
|
19676 | var delta = deleted ? 0 : 1;
|
19677 |
|
19678 | writeDoc(docInfo, winningRev$$1, deleted, deleted, false,
|
19679 | delta, resultsIdx, callback);
|
19680 | }
|
19681 |
|
19682 | var newEdits = opts.new_edits;
|
19683 | var idsToDocs = new ExportedMap();
|
19684 |
|
19685 | var docsDone = 0;
|
19686 | var docsToDo = docInfos.length;
|
19687 |
|
19688 | function checkAllDocsDone() {
|
19689 | if (++docsDone === docsToDo && overallCallback) {
|
19690 | overallCallback();
|
19691 | }
|
19692 | }
|
19693 |
|
19694 | docInfos.forEach(function (currentDoc, resultsIdx) {
|
19695 |
|
19696 | if (currentDoc._id && isLocalId(currentDoc._id)) {
|
19697 | var fun = currentDoc._deleted ? '_removeLocal' : '_putLocal';
|
19698 | api[fun](currentDoc, {ctx: tx}, function (err, res) {
|
19699 | results[resultsIdx] = err || res;
|
19700 | checkAllDocsDone();
|
19701 | });
|
19702 | return;
|
19703 | }
|
19704 |
|
19705 | var id = currentDoc.metadata.id;
|
19706 | if (idsToDocs.has(id)) {
|
19707 | docsToDo--;
|
19708 | idsToDocs.get(id).push([currentDoc, resultsIdx]);
|
19709 | } else {
|
19710 | idsToDocs.set(id, [[currentDoc, resultsIdx]]);
|
19711 | }
|
19712 | });
|
19713 |
|
19714 |
|
19715 |
|
19716 | idsToDocs.forEach(function (docs, id) {
|
19717 | var numDone = 0;
|
19718 |
|
19719 | function docWritten() {
|
19720 | if (++numDone < docs.length) {
|
19721 | nextDoc();
|
19722 | } else {
|
19723 | checkAllDocsDone();
|
19724 | }
|
19725 | }
|
19726 | function nextDoc() {
|
19727 | var value = docs[numDone];
|
19728 | var currentDoc = value[0];
|
19729 | var resultsIdx = value[1];
|
19730 |
|
19731 | if (fetchedDocs.has(id)) {
|
19732 | updateDoc(revLimit, fetchedDocs.get(id), currentDoc, results,
|
19733 | resultsIdx, docWritten, writeDoc, newEdits);
|
19734 | } else {
|
19735 |
|
19736 | var merged = merge([], currentDoc.metadata.rev_tree[0], revLimit);
|
19737 | currentDoc.metadata.rev_tree = merged.tree;
|
19738 | currentDoc.stemmedRevs = merged.stemmedRevs || [];
|
19739 | insertDoc(currentDoc, resultsIdx, docWritten);
|
19740 | }
|
19741 | }
|
19742 | nextDoc();
|
19743 | });
|
19744 | }
|
19745 |
|
19746 | function safeJsonParse(str) {
|
19747 |
|
19748 |
|
19749 |
|
19750 | try {
|
19751 | return JSON.parse(str);
|
19752 | } catch (e) {
|
19753 |
|
19754 | return vuvuzela.parse(str);
|
19755 | }
|
19756 | }
|
19757 |
|
19758 | function safeJsonStringify(json) {
|
19759 | try {
|
19760 | return JSON.stringify(json);
|
19761 | } catch (e) {
|
19762 |
|
19763 | return vuvuzela.stringify(json);
|
19764 | }
|
19765 | }
|
19766 |
|
19767 | function readAsBlobOrBuffer(storedObject, type) {
|
19768 |
|
19769 |
|
19770 |
|
19771 | var byteArray = new Uint8Array(storedObject);
|
19772 | return createBlob([byteArray], {type: type});
|
19773 | }
|
19774 |
|
19775 |
|
19776 | function prepareAttachmentForStorage(attData, cb) {
|
19777 | readAsBinaryString(attData, cb);
|
19778 | }
|
19779 |
|
19780 | function createEmptyBlobOrBuffer(type) {
|
19781 | return createBlob([''], {type: type});
|
19782 | }
|
19783 |
|
19784 | function getCacheFor(transaction, store) {
|
19785 | var prefix = store.prefix()[0];
|
19786 | var cache = transaction._cache;
|
19787 | var subCache = cache.get(prefix);
|
19788 | if (!subCache) {
|
19789 | subCache = new ExportedMap();
|
19790 | cache.set(prefix, subCache);
|
19791 | }
|
19792 | return subCache;
|
19793 | }
|
19794 |
|
19795 | function LevelTransaction() {
|
19796 | this._batch = [];
|
19797 | this._cache = new ExportedMap();
|
19798 | }
|
19799 |
|
19800 | LevelTransaction.prototype.get = function (store, key, callback) {
|
19801 | var cache = getCacheFor(this, store);
|
19802 | var exists = cache.get(key);
|
19803 | if (exists) {
|
19804 | return immediate(function () {
|
19805 | callback(null, exists);
|
19806 | });
|
19807 | } else if (exists === null) {
|
19808 |
|
19809 | return immediate(function () {
|
19810 | callback({name: 'NotFoundError'});
|
19811 | });
|
19812 | }
|
19813 | store.get(key, function (err, res) {
|
19814 | if (err) {
|
19815 |
|
19816 | if (err.name === 'NotFoundError') {
|
19817 | cache.set(key, null);
|
19818 | }
|
19819 | return callback(err);
|
19820 | }
|
19821 | cache.set(key, res);
|
19822 | callback(null, res);
|
19823 | });
|
19824 | };
|
19825 |
|
19826 | LevelTransaction.prototype.batch = function (batch) {
|
19827 | for (var i = 0, len = batch.length; i < len; i++) {
|
19828 | var operation = batch[i];
|
19829 |
|
19830 | var cache = getCacheFor(this, operation.prefix);
|
19831 |
|
19832 | if (operation.type === 'put') {
|
19833 | cache.set(operation.key, operation.value);
|
19834 | } else {
|
19835 | cache.set(operation.key, null);
|
19836 | }
|
19837 | }
|
19838 | this._batch = this._batch.concat(batch);
|
19839 | };
|
19840 |
|
19841 | LevelTransaction.prototype.execute = function (db, callback) {
|
19842 |
|
19843 | var keys = new ExportedSet();
|
19844 | var uniqBatches = [];
|
19845 |
|
19846 |
|
19847 | for (var i = this._batch.length - 1; i >= 0; i--) {
|
19848 | var operation = this._batch[i];
|
19849 | var lookupKey = operation.prefix.prefix()[0] + '\xff' + operation.key;
|
19850 | if (keys.has(lookupKey)) {
|
19851 | continue;
|
19852 | }
|
19853 | keys.add(lookupKey);
|
19854 | uniqBatches.push(operation);
|
19855 | }
|
19856 |
|
19857 | db.batch(uniqBatches, callback);
|
19858 | };
|
19859 |
|
19860 | var DOC_STORE = 'document-store';
|
19861 | var BY_SEQ_STORE = 'by-sequence';
|
19862 | var ATTACHMENT_STORE = 'attach-store';
|
19863 | var BINARY_STORE = 'attach-binary-store';
|
19864 | var LOCAL_STORE = 'local-store';
|
19865 | var META_STORE = 'meta-store';
|
19866 |
|
19867 |
|
19868 |
|
19869 | var dbStores = new ExportedMap();
|
19870 |
|
19871 |
|
19872 |
|
19873 | var UPDATE_SEQ_KEY = '_local_last_update_seq';
|
19874 | var DOC_COUNT_KEY = '_local_doc_count';
|
19875 | var UUID_KEY = '_local_uuid';
|
19876 |
|
19877 | var MD5_PREFIX = 'md5-';
|
19878 |
|
19879 | var safeJsonEncoding = {
|
19880 | encode: safeJsonStringify,
|
19881 | decode: safeJsonParse,
|
19882 | buffer: false,
|
19883 | type: 'cheap-json'
|
19884 | };
|
19885 |
|
19886 | var levelChanges = new Changes();
|
19887 |
|
19888 |
|
19889 |
|
19890 | function getWinningRev(metadata) {
|
19891 | return 'winningRev' in metadata ?
|
19892 | metadata.winningRev : winningRev(metadata);
|
19893 | }
|
19894 |
|
19895 | function getIsDeleted(metadata, winningRev$$1) {
|
19896 | return 'deleted' in metadata ?
|
19897 | metadata.deleted : isDeleted(metadata, winningRev$$1);
|
19898 | }
|
19899 |
|
19900 | function fetchAttachment(att, stores, opts) {
|
19901 | var type = att.content_type;
|
19902 | return new Promise(function (resolve, reject) {
|
19903 | stores.binaryStore.get(att.digest, function (err, buffer) {
|
19904 | var data;
|
19905 | if (err) {
|
19906 |
|
19907 | if (err.name !== 'NotFoundError') {
|
19908 | return reject(err);
|
19909 | } else {
|
19910 |
|
19911 | if (!opts.binary) {
|
19912 | data = '';
|
19913 | } else {
|
19914 | data = binStringToBluffer('', type);
|
19915 | }
|
19916 | }
|
19917 | } else {
|
19918 | if (opts.binary) {
|
19919 | data = readAsBlobOrBuffer(buffer, type);
|
19920 | } else {
|
19921 | data = buffer.toString('base64');
|
19922 | }
|
19923 | }
|
19924 | delete att.stub;
|
19925 | delete att.length;
|
19926 | att.data = data;
|
19927 | resolve();
|
19928 | });
|
19929 | });
|
19930 | }
|
19931 |
|
19932 | function fetchAttachments(results, stores, opts) {
|
19933 | var atts = [];
|
19934 | results.forEach(function (row) {
|
19935 | if (!(row.doc && row.doc._attachments)) {
|
19936 | return;
|
19937 | }
|
19938 | var attNames = Object.keys(row.doc._attachments);
|
19939 | attNames.forEach(function (attName) {
|
19940 | var att = row.doc._attachments[attName];
|
19941 | if (!('data' in att)) {
|
19942 | atts.push(att);
|
19943 | }
|
19944 | });
|
19945 | });
|
19946 |
|
19947 | return Promise.all(atts.map(function (att) {
|
19948 | return fetchAttachment(att, stores, opts);
|
19949 | }));
|
19950 | }
|
19951 |
|
19952 | function LevelPouch(opts, callback) {
|
19953 | opts = clone(opts);
|
19954 | var api = this;
|
19955 | var instanceId;
|
19956 | var stores = {};
|
19957 | var revLimit = opts.revs_limit;
|
19958 | var db;
|
19959 | var name = opts.name;
|
19960 |
|
19961 |
|
19962 | if (typeof opts.createIfMissing === 'undefined') {
|
19963 | opts.createIfMissing = true;
|
19964 | }
|
19965 |
|
19966 | var leveldown = opts.db;
|
19967 |
|
19968 | var dbStore;
|
19969 | var leveldownName = functionName(leveldown);
|
19970 | if (dbStores.has(leveldownName)) {
|
19971 | dbStore = dbStores.get(leveldownName);
|
19972 | } else {
|
19973 | dbStore = new ExportedMap();
|
19974 | dbStores.set(leveldownName, dbStore);
|
19975 | }
|
19976 | if (dbStore.has(name)) {
|
19977 | db = dbStore.get(name);
|
19978 | afterDBCreated();
|
19979 | } else {
|
19980 | dbStore.set(name, sublevelPouch(levelup(leveldown(name), opts, function (err) {
|
19981 |
|
19982 | if (err) {
|
19983 | dbStore["delete"](name);
|
19984 | return callback(err);
|
19985 | }
|
19986 | db = dbStore.get(name);
|
19987 | db._docCount = -1;
|
19988 | db._queue = new Deque();
|
19989 |
|
19990 | if (typeof opts.migrate === 'object') {
|
19991 | opts.migrate.doMigrationOne(name, db, afterDBCreated);
|
19992 | } else {
|
19993 | afterDBCreated();
|
19994 | }
|
19995 | })));
|
19996 | }
|
19997 |
|
19998 | function afterDBCreated() {
|
19999 | stores.docStore = db.sublevel(DOC_STORE, {valueEncoding: safeJsonEncoding});
|
20000 | stores.bySeqStore = db.sublevel(BY_SEQ_STORE, {valueEncoding: 'json'});
|
20001 | stores.attachmentStore =
|
20002 | db.sublevel(ATTACHMENT_STORE, {valueEncoding: 'json'});
|
20003 | stores.binaryStore = db.sublevel(BINARY_STORE, {valueEncoding: 'binary'});
|
20004 | stores.localStore = db.sublevel(LOCAL_STORE, {valueEncoding: 'json'});
|
20005 | stores.metaStore = db.sublevel(META_STORE, {valueEncoding: 'json'});
|
20006 |
|
20007 | if (typeof opts.migrate === 'object') {
|
20008 | opts.migrate.doMigrationTwo(db, stores, afterLastMigration);
|
20009 | } else {
|
20010 | afterLastMigration();
|
20011 | }
|
20012 | }
|
20013 |
|
20014 | function afterLastMigration() {
|
20015 | stores.metaStore.get(UPDATE_SEQ_KEY, function (err, value) {
|
20016 | if (typeof db._updateSeq === 'undefined') {
|
20017 | db._updateSeq = value || 0;
|
20018 | }
|
20019 | stores.metaStore.get(DOC_COUNT_KEY, function (err, value) {
|
20020 | db._docCount = !err ? value : 0;
|
20021 | stores.metaStore.get(UUID_KEY, function (err, value) {
|
20022 | instanceId = !err ? value : uuid();
|
20023 | stores.metaStore.put(UUID_KEY, instanceId, function () {
|
20024 | immediate(function () {
|
20025 | callback(null, api);
|
20026 | });
|
20027 | });
|
20028 | });
|
20029 | });
|
20030 | });
|
20031 | }
|
20032 |
|
20033 | function countDocs(callback) {
|
20034 |
|
20035 | if (db.isClosed()) {
|
20036 | return callback(new Error('database is closed'));
|
20037 | }
|
20038 | return callback(null, db._docCount);
|
20039 | }
|
20040 |
|
20041 | api._remote = false;
|
20042 |
|
20043 | api.type = function () {
|
20044 | return 'leveldb';
|
20045 | };
|
20046 |
|
20047 | api._id = function (callback) {
|
20048 | callback(null, instanceId);
|
20049 | };
|
20050 |
|
20051 | api._info = function (callback) {
|
20052 | var res = {
|
20053 | doc_count: db._docCount,
|
20054 | update_seq: db._updateSeq,
|
20055 | backend_adapter: functionName(leveldown)
|
20056 | };
|
20057 | return immediate(function () {
|
20058 | callback(null, res);
|
20059 | });
|
20060 | };
|
20061 |
|
20062 | function tryCode(fun, args) {
|
20063 | try {
|
20064 | fun.apply(null, args);
|
20065 | } catch (err) {
|
20066 | args[args.length - 1](err);
|
20067 | }
|
20068 | }
|
20069 |
|
20070 | function executeNext() {
|
20071 | var firstTask = db._queue.peekFront();
|
20072 |
|
20073 | if (firstTask.type === 'read') {
|
20074 | runReadOperation(firstTask);
|
20075 | } else {
|
20076 | runWriteOperation(firstTask);
|
20077 | }
|
20078 | }
|
20079 |
|
20080 | function runReadOperation(firstTask) {
|
20081 |
|
20082 |
|
20083 | var readTasks = [firstTask];
|
20084 | var i = 1;
|
20085 | var nextTask = db._queue.get(i);
|
20086 | while (typeof nextTask !== 'undefined' && nextTask.type === 'read') {
|
20087 | readTasks.push(nextTask);
|
20088 | i++;
|
20089 | nextTask = db._queue.get(i);
|
20090 | }
|
20091 |
|
20092 | var numDone = 0;
|
20093 |
|
20094 | readTasks.forEach(function (readTask) {
|
20095 | var args = readTask.args;
|
20096 | var callback = args[args.length - 1];
|
20097 | args[args.length - 1] = getArguments(function (cbArgs) {
|
20098 | callback.apply(null, cbArgs);
|
20099 | if (++numDone === readTasks.length) {
|
20100 | immediate(function () {
|
20101 |
|
20102 | readTasks.forEach(function () {
|
20103 | db._queue.shift();
|
20104 | });
|
20105 | if (db._queue.length) {
|
20106 | executeNext();
|
20107 | }
|
20108 | });
|
20109 | }
|
20110 | });
|
20111 | tryCode(readTask.fun, args);
|
20112 | });
|
20113 | }
|
20114 |
|
20115 | function runWriteOperation(firstTask) {
|
20116 | var args = firstTask.args;
|
20117 | var callback = args[args.length - 1];
|
20118 | args[args.length - 1] = getArguments(function (cbArgs) {
|
20119 | callback.apply(null, cbArgs);
|
20120 | immediate(function () {
|
20121 | db._queue.shift();
|
20122 | if (db._queue.length) {
|
20123 | executeNext();
|
20124 | }
|
20125 | });
|
20126 | });
|
20127 | tryCode(firstTask.fun, args);
|
20128 | }
|
20129 |
|
20130 |
|
20131 |
|
20132 |
|
20133 |
|
20134 | function writeLock(fun) {
|
20135 | return getArguments(function (args) {
|
20136 | db._queue.push({
|
20137 | fun: fun,
|
20138 | args: args,
|
20139 | type: 'write'
|
20140 | });
|
20141 |
|
20142 | if (db._queue.length === 1) {
|
20143 | immediate(executeNext);
|
20144 | }
|
20145 | });
|
20146 | }
|
20147 |
|
20148 |
|
20149 | function readLock(fun) {
|
20150 | return getArguments(function (args) {
|
20151 | db._queue.push({
|
20152 | fun: fun,
|
20153 | args: args,
|
20154 | type: 'read'
|
20155 | });
|
20156 |
|
20157 | if (db._queue.length === 1) {
|
20158 | immediate(executeNext);
|
20159 | }
|
20160 | });
|
20161 | }
|
20162 |
|
20163 | function formatSeq(n) {
|
20164 | return ('0000000000000000' + n).slice(-16);
|
20165 | }
|
20166 |
|
20167 | function parseSeq(s) {
|
20168 | return parseInt(s, 10);
|
20169 | }
|
20170 |
|
20171 | api._get = readLock(function (id, opts, callback) {
|
20172 | opts = clone(opts);
|
20173 |
|
20174 | stores.docStore.get(id, function (err, metadata) {
|
20175 |
|
20176 | if (err || !metadata) {
|
20177 | return callback(createError(MISSING_DOC, 'missing'));
|
20178 | }
|
20179 |
|
20180 | var rev$$1;
|
20181 | if (!opts.rev) {
|
20182 | rev$$1 = getWinningRev(metadata);
|
20183 | var deleted = getIsDeleted(metadata, rev$$1);
|
20184 | if (deleted) {
|
20185 | return callback(createError(MISSING_DOC, "deleted"));
|
20186 | }
|
20187 | } else {
|
20188 | rev$$1 = opts.latest ? latest(opts.rev, metadata) : opts.rev;
|
20189 | }
|
20190 |
|
20191 | var seq = metadata.rev_map[rev$$1];
|
20192 |
|
20193 | stores.bySeqStore.get(formatSeq(seq), function (err, doc) {
|
20194 | if (!doc) {
|
20195 | return callback(createError(MISSING_DOC));
|
20196 | }
|
20197 |
|
20198 | if ('_id' in doc && doc._id !== metadata.id) {
|
20199 |
|
20200 | return callback(new Error('wrong doc returned'));
|
20201 | }
|
20202 | doc._id = metadata.id;
|
20203 | if ('_rev' in doc) {
|
20204 |
|
20205 | if (doc._rev !== rev$$1) {
|
20206 |
|
20207 | return callback(new Error('wrong doc returned'));
|
20208 | }
|
20209 | } else {
|
20210 |
|
20211 | doc._rev = rev$$1;
|
20212 | }
|
20213 | return callback(null, {doc: doc, metadata: metadata});
|
20214 | });
|
20215 | });
|
20216 | });
|
20217 |
|
20218 |
|
20219 |
|
20220 | api._getAttachment = function (docId, attachId, attachment, opts, callback) {
|
20221 | var digest = attachment.digest;
|
20222 | var type = attachment.content_type;
|
20223 |
|
20224 | stores.binaryStore.get(digest, function (err, attach) {
|
20225 | if (err) {
|
20226 |
|
20227 | if (err.name !== 'NotFoundError') {
|
20228 | return callback(err);
|
20229 | }
|
20230 |
|
20231 | return callback(null, opts.binary ? createEmptyBlobOrBuffer(type) : '');
|
20232 | }
|
20233 |
|
20234 | if (opts.binary) {
|
20235 | callback(null, readAsBlobOrBuffer(attach, type));
|
20236 | } else {
|
20237 | callback(null, attach.toString('base64'));
|
20238 | }
|
20239 | });
|
20240 | };
|
20241 |
|
20242 | api._bulkDocs = writeLock(function (req, opts, callback) {
|
20243 | var newEdits = opts.new_edits;
|
20244 | var results = new Array(req.docs.length);
|
20245 | var fetchedDocs = new ExportedMap();
|
20246 | var stemmedRevs = new ExportedMap();
|
20247 |
|
20248 | var txn = new LevelTransaction();
|
20249 | var docCountDelta = 0;
|
20250 | var newUpdateSeq = db._updateSeq;
|
20251 |
|
20252 |
|
20253 | var userDocs = req.docs;
|
20254 | var docInfos = userDocs.map(function (doc) {
|
20255 | if (doc._id && isLocalId(doc._id)) {
|
20256 | return doc;
|
20257 | }
|
20258 | var newDoc = parseDoc(doc, newEdits, api.__opts);
|
20259 |
|
20260 | if (newDoc.metadata && !newDoc.metadata.rev_map) {
|
20261 | newDoc.metadata.rev_map = {};
|
20262 | }
|
20263 |
|
20264 | return newDoc;
|
20265 | });
|
20266 | var infoErrors = docInfos.filter(function (doc) {
|
20267 | return doc.error;
|
20268 | });
|
20269 |
|
20270 | if (infoErrors.length) {
|
20271 | return callback(infoErrors[0]);
|
20272 | }
|
20273 |
|
20274 |
|
20275 |
|
20276 | function verifyAttachment(digest, callback) {
|
20277 | txn.get(stores.attachmentStore, digest, function (levelErr) {
|
20278 | if (levelErr) {
|
20279 | var err = createError(MISSING_STUB,
|
20280 | 'unknown stub attachment with digest ' +
|
20281 | digest);
|
20282 | callback(err);
|
20283 | } else {
|
20284 | callback();
|
20285 | }
|
20286 | });
|
20287 | }
|
20288 |
|
20289 | function verifyAttachments(finish) {
|
20290 | var digests = [];
|
20291 | userDocs.forEach(function (doc) {
|
20292 | if (doc && doc._attachments) {
|
20293 | Object.keys(doc._attachments).forEach(function (filename) {
|
20294 | var att = doc._attachments[filename];
|
20295 | if (att.stub) {
|
20296 | digests.push(att.digest);
|
20297 | }
|
20298 | });
|
20299 | }
|
20300 | });
|
20301 | if (!digests.length) {
|
20302 | return finish();
|
20303 | }
|
20304 | var numDone = 0;
|
20305 | var err;
|
20306 |
|
20307 | digests.forEach(function (digest) {
|
20308 | verifyAttachment(digest, function (attErr) {
|
20309 | if (attErr && !err) {
|
20310 | err = attErr;
|
20311 | }
|
20312 |
|
20313 | if (++numDone === digests.length) {
|
20314 | finish(err);
|
20315 | }
|
20316 | });
|
20317 | });
|
20318 | }
|
20319 |
|
20320 | function fetchExistingDocs(finish) {
|
20321 | var numDone = 0;
|
20322 | var overallErr;
|
20323 | function checkDone() {
|
20324 | if (++numDone === userDocs.length) {
|
20325 | return finish(overallErr);
|
20326 | }
|
20327 | }
|
20328 |
|
20329 | userDocs.forEach(function (doc) {
|
20330 | if (doc._id && isLocalId(doc._id)) {
|
20331 |
|
20332 | return checkDone();
|
20333 | }
|
20334 | txn.get(stores.docStore, doc._id, function (err, info) {
|
20335 | if (err) {
|
20336 |
|
20337 | if (err.name !== 'NotFoundError') {
|
20338 | overallErr = err;
|
20339 | }
|
20340 | } else {
|
20341 | fetchedDocs.set(doc._id, info);
|
20342 | }
|
20343 | checkDone();
|
20344 | });
|
20345 | });
|
20346 | }
|
20347 |
|
20348 | function compact(revsMap, callback) {
|
20349 | var promise = Promise.resolve();
|
20350 | revsMap.forEach(function (revs, docId) {
|
20351 |
|
20352 |
|
20353 | promise = promise.then(function () {
|
20354 | return new Promise(function (resolve, reject) {
|
20355 | api._doCompactionNoLock(docId, revs, {ctx: txn}, function (err) {
|
20356 |
|
20357 | if (err) {
|
20358 | return reject(err);
|
20359 | }
|
20360 | resolve();
|
20361 | });
|
20362 | });
|
20363 | });
|
20364 | });
|
20365 |
|
20366 | promise.then(function () {
|
20367 | callback();
|
20368 | }, callback);
|
20369 | }
|
20370 |
|
20371 | function autoCompact(callback) {
|
20372 | var revsMap = new ExportedMap();
|
20373 | fetchedDocs.forEach(function (metadata, docId) {
|
20374 | revsMap.set(docId, compactTree(metadata));
|
20375 | });
|
20376 | compact(revsMap, callback);
|
20377 | }
|
20378 |
|
20379 | function finish() {
|
20380 | compact(stemmedRevs, function (error) {
|
20381 |
|
20382 | if (error) {
|
20383 | complete(error);
|
20384 | }
|
20385 | if (api.auto_compaction) {
|
20386 | return autoCompact(complete);
|
20387 | }
|
20388 | complete();
|
20389 | });
|
20390 | }
|
20391 |
|
20392 | function writeDoc(docInfo, winningRev$$1, winningRevIsDeleted, newRevIsDeleted,
|
20393 | isUpdate, delta, resultsIdx, callback2) {
|
20394 | docCountDelta += delta;
|
20395 |
|
20396 | var err = null;
|
20397 | var recv = 0;
|
20398 |
|
20399 | docInfo.metadata.winningRev = winningRev$$1;
|
20400 | docInfo.metadata.deleted = winningRevIsDeleted;
|
20401 |
|
20402 | docInfo.data._id = docInfo.metadata.id;
|
20403 | docInfo.data._rev = docInfo.metadata.rev;
|
20404 |
|
20405 | if (newRevIsDeleted) {
|
20406 | docInfo.data._deleted = true;
|
20407 | }
|
20408 |
|
20409 | if (docInfo.stemmedRevs.length) {
|
20410 | stemmedRevs.set(docInfo.metadata.id, docInfo.stemmedRevs);
|
20411 | }
|
20412 |
|
20413 | var attachments = docInfo.data._attachments ?
|
20414 | Object.keys(docInfo.data._attachments) :
|
20415 | [];
|
20416 |
|
20417 | function attachmentSaved(attachmentErr) {
|
20418 | recv++;
|
20419 | if (!err) {
|
20420 |
|
20421 | if (attachmentErr) {
|
20422 | err = attachmentErr;
|
20423 | callback2(err);
|
20424 | } else if (recv === attachments.length) {
|
20425 | finish();
|
20426 | }
|
20427 | }
|
20428 | }
|
20429 |
|
20430 | function onMD5Load(doc, key, data, attachmentSaved) {
|
20431 | return function (result) {
|
20432 | saveAttachment(doc, MD5_PREFIX + result, key, data, attachmentSaved);
|
20433 | };
|
20434 | }
|
20435 |
|
20436 | function doMD5(doc, key, attachmentSaved) {
|
20437 | return function (data) {
|
20438 | binaryMd5(data, onMD5Load(doc, key, data, attachmentSaved));
|
20439 | };
|
20440 | }
|
20441 |
|
20442 | for (var i = 0; i < attachments.length; i++) {
|
20443 | var key = attachments[i];
|
20444 | var att = docInfo.data._attachments[key];
|
20445 |
|
20446 | if (att.stub) {
|
20447 |
|
20448 | var id = docInfo.data._id;
|
20449 | var rev$$1 = docInfo.data._rev;
|
20450 | saveAttachmentRefs(id, rev$$1, att.digest, attachmentSaved);
|
20451 | continue;
|
20452 | }
|
20453 | var data;
|
20454 | if (typeof att.data === 'string') {
|
20455 |
|
20456 | try {
|
20457 | data = thisAtob(att.data);
|
20458 | } catch (e) {
|
20459 | callback(createError(BAD_ARG,
|
20460 | 'Attachment is not a valid base64 string'));
|
20461 | return;
|
20462 | }
|
20463 | doMD5(docInfo, key, attachmentSaved)(data);
|
20464 | } else {
|
20465 | prepareAttachmentForStorage(att.data,
|
20466 | doMD5(docInfo, key, attachmentSaved));
|
20467 | }
|
20468 | }
|
20469 |
|
20470 | function finish() {
|
20471 | var seq = docInfo.metadata.rev_map[docInfo.metadata.rev];
|
20472 |
|
20473 | if (seq) {
|
20474 |
|
20475 |
|
20476 | return callback2();
|
20477 | }
|
20478 | seq = ++newUpdateSeq;
|
20479 | docInfo.metadata.rev_map[docInfo.metadata.rev] =
|
20480 | docInfo.metadata.seq = seq;
|
20481 | var seqKey = formatSeq(seq);
|
20482 | var batch = [{
|
20483 | key: seqKey,
|
20484 | value: docInfo.data,
|
20485 | prefix: stores.bySeqStore,
|
20486 | type: 'put'
|
20487 | }, {
|
20488 | key: docInfo.metadata.id,
|
20489 | value: docInfo.metadata,
|
20490 | prefix: stores.docStore,
|
20491 | type: 'put'
|
20492 | }];
|
20493 | txn.batch(batch);
|
20494 | results[resultsIdx] = {
|
20495 | ok: true,
|
20496 | id: docInfo.metadata.id,
|
20497 | rev: docInfo.metadata.rev
|
20498 | };
|
20499 | fetchedDocs.set(docInfo.metadata.id, docInfo.metadata);
|
20500 | callback2();
|
20501 | }
|
20502 |
|
20503 | if (!attachments.length) {
|
20504 | finish();
|
20505 | }
|
20506 | }
|
20507 |
|
20508 |
|
20509 |
|
20510 | var attachmentQueues = {};
|
20511 |
|
20512 | function saveAttachmentRefs(id, rev$$1, digest, callback) {
|
20513 |
|
20514 | function fetchAtt() {
|
20515 | return new Promise(function (resolve, reject) {
|
20516 | txn.get(stores.attachmentStore, digest, function (err, oldAtt) {
|
20517 |
|
20518 | if (err && err.name !== 'NotFoundError') {
|
20519 | return reject(err);
|
20520 | }
|
20521 | resolve(oldAtt);
|
20522 | });
|
20523 | });
|
20524 | }
|
20525 |
|
20526 | function saveAtt(oldAtt) {
|
20527 | var ref = [id, rev$$1].join('@');
|
20528 | var newAtt = {};
|
20529 |
|
20530 | if (oldAtt) {
|
20531 | if (oldAtt.refs) {
|
20532 |
|
20533 |
|
20534 |
|
20535 | newAtt.refs = oldAtt.refs;
|
20536 | newAtt.refs[ref] = true;
|
20537 | }
|
20538 | } else {
|
20539 | newAtt.refs = {};
|
20540 | newAtt.refs[ref] = true;
|
20541 | }
|
20542 |
|
20543 | return new Promise(function (resolve) {
|
20544 | txn.batch([{
|
20545 | type: 'put',
|
20546 | prefix: stores.attachmentStore,
|
20547 | key: digest,
|
20548 | value: newAtt
|
20549 | }]);
|
20550 | resolve(!oldAtt);
|
20551 | });
|
20552 | }
|
20553 |
|
20554 |
|
20555 |
|
20556 | var queue = attachmentQueues[digest] || Promise.resolve();
|
20557 | attachmentQueues[digest] = queue.then(function () {
|
20558 | return fetchAtt().then(saveAtt).then(function (isNewAttachment) {
|
20559 | callback(null, isNewAttachment);
|
20560 | }, callback);
|
20561 | });
|
20562 | }
|
20563 |
|
20564 | function saveAttachment(docInfo, digest, key, data, callback) {
|
20565 | var att = docInfo.data._attachments[key];
|
20566 | delete att.data;
|
20567 | att.digest = digest;
|
20568 | att.length = data.length;
|
20569 | var id = docInfo.metadata.id;
|
20570 | var rev$$1 = docInfo.metadata.rev;
|
20571 | att.revpos = parseInt(rev$$1, 10);
|
20572 |
|
20573 | saveAttachmentRefs(id, rev$$1, digest, function (err, isNewAttachment) {
|
20574 |
|
20575 | if (err) {
|
20576 | return callback(err);
|
20577 | }
|
20578 |
|
20579 | if (data.length === 0) {
|
20580 | return callback(err);
|
20581 | }
|
20582 | if (!isNewAttachment) {
|
20583 |
|
20584 | return callback(err);
|
20585 | }
|
20586 | txn.batch([{
|
20587 | type: 'put',
|
20588 | prefix: stores.binaryStore,
|
20589 | key: digest,
|
20590 | value: bufferFrom(data, 'binary')
|
20591 | }]);
|
20592 | callback();
|
20593 | });
|
20594 | }
|
20595 |
|
20596 | function complete(err) {
|
20597 |
|
20598 | if (err) {
|
20599 | return immediate(function () {
|
20600 | callback(err);
|
20601 | });
|
20602 | }
|
20603 | txn.batch([
|
20604 | {
|
20605 | prefix: stores.metaStore,
|
20606 | type: 'put',
|
20607 | key: UPDATE_SEQ_KEY,
|
20608 | value: newUpdateSeq
|
20609 | },
|
20610 | {
|
20611 | prefix: stores.metaStore,
|
20612 | type: 'put',
|
20613 | key: DOC_COUNT_KEY,
|
20614 | value: db._docCount + docCountDelta
|
20615 | }
|
20616 | ]);
|
20617 | txn.execute(db, function (err) {
|
20618 |
|
20619 | if (err) {
|
20620 | return callback(err);
|
20621 | }
|
20622 | db._docCount += docCountDelta;
|
20623 | db._updateSeq = newUpdateSeq;
|
20624 | levelChanges.notify(name);
|
20625 | immediate(function () {
|
20626 | callback(null, results);
|
20627 | });
|
20628 | });
|
20629 | }
|
20630 |
|
20631 | if (!docInfos.length) {
|
20632 | return callback(null, []);
|
20633 | }
|
20634 |
|
20635 | verifyAttachments(function (err) {
|
20636 | if (err) {
|
20637 | return callback(err);
|
20638 | }
|
20639 | fetchExistingDocs(function (err) {
|
20640 |
|
20641 | if (err) {
|
20642 | return callback(err);
|
20643 | }
|
20644 | processDocs(revLimit, docInfos, api, fetchedDocs, txn, results,
|
20645 | writeDoc, opts, finish);
|
20646 | });
|
20647 | });
|
20648 | });
|
20649 | api._allDocs = function (opts, callback) {
|
20650 | if ('keys' in opts) {
|
20651 | return allDocsKeysQuery(this, opts);
|
20652 | }
|
20653 | return readLock(function (opts, callback) {
|
20654 | opts = clone(opts);
|
20655 | countDocs(function (err, docCount) {
|
20656 |
|
20657 | if (err) {
|
20658 | return callback(err);
|
20659 | }
|
20660 | var readstreamOpts = {};
|
20661 | var skip = opts.skip || 0;
|
20662 | if (opts.startkey) {
|
20663 | readstreamOpts.gte = opts.startkey;
|
20664 | }
|
20665 | if (opts.endkey) {
|
20666 | readstreamOpts.lte = opts.endkey;
|
20667 | }
|
20668 | if (opts.key) {
|
20669 | readstreamOpts.gte = readstreamOpts.lte = opts.key;
|
20670 | }
|
20671 | if (opts.descending) {
|
20672 | readstreamOpts.reverse = true;
|
20673 |
|
20674 | var tmp = readstreamOpts.lte;
|
20675 | readstreamOpts.lte = readstreamOpts.gte;
|
20676 | readstreamOpts.gte = tmp;
|
20677 | }
|
20678 | var limit;
|
20679 | if (typeof opts.limit === 'number') {
|
20680 | limit = opts.limit;
|
20681 | }
|
20682 | if (limit === 0 ||
|
20683 | ('gte' in readstreamOpts && 'lte' in readstreamOpts &&
|
20684 | readstreamOpts.gte > readstreamOpts.lte)) {
|
20685 |
|
20686 |
|
20687 |
|
20688 | var returnVal = {
|
20689 | total_rows: docCount,
|
20690 | offset: opts.skip,
|
20691 | rows: []
|
20692 | };
|
20693 |
|
20694 | if (opts.update_seq) {
|
20695 | returnVal.update_seq = db._updateSeq;
|
20696 | }
|
20697 | return callback(null, returnVal);
|
20698 | }
|
20699 | var results = [];
|
20700 | var docstream = stores.docStore.readStream(readstreamOpts);
|
20701 |
|
20702 | var throughStream = through2.obj(function (entry, _, next) {
|
20703 | var metadata = entry.value;
|
20704 |
|
20705 |
|
20706 | var winningRev$$1 = getWinningRev(metadata);
|
20707 | var deleted = getIsDeleted(metadata, winningRev$$1);
|
20708 | if (!deleted) {
|
20709 | if (skip-- > 0) {
|
20710 | next();
|
20711 | return;
|
20712 | } else if (typeof limit === 'number' && limit-- <= 0) {
|
20713 | docstream.unpipe();
|
20714 | docstream.destroy();
|
20715 | next();
|
20716 | return;
|
20717 | }
|
20718 | } else if (opts.deleted !== 'ok') {
|
20719 | next();
|
20720 | return;
|
20721 | }
|
20722 | function allDocsInner(data) {
|
20723 | var doc = {
|
20724 | id: metadata.id,
|
20725 | key: metadata.id,
|
20726 | value: {
|
20727 | rev: winningRev$$1
|
20728 | }
|
20729 | };
|
20730 | if (opts.include_docs) {
|
20731 | doc.doc = data;
|
20732 | doc.doc._rev = doc.value.rev;
|
20733 | if (opts.conflicts) {
|
20734 | var conflicts = collectConflicts(metadata);
|
20735 | if (conflicts.length) {
|
20736 | doc.doc._conflicts = conflicts;
|
20737 | }
|
20738 | }
|
20739 | for (var att in doc.doc._attachments) {
|
20740 | if (doc.doc._attachments.hasOwnProperty(att)) {
|
20741 | doc.doc._attachments[att].stub = true;
|
20742 | }
|
20743 | }
|
20744 | }
|
20745 | if (opts.inclusive_end === false && metadata.id === opts.endkey) {
|
20746 | return next();
|
20747 | } else if (deleted) {
|
20748 | if (opts.deleted === 'ok') {
|
20749 | doc.value.deleted = true;
|
20750 | doc.doc = null;
|
20751 | } else {
|
20752 | /* istanbul ignore next */
|
20753 | return next();
|
20754 | }
|
20755 | }
|
20756 | results.push(doc);
|
20757 | next();
|
20758 | }
|
20759 | if (opts.include_docs) {
|
20760 | var seq = metadata.rev_map[winningRev$$1];
|
20761 | stores.bySeqStore.get(formatSeq(seq), function (err, data) {
|
20762 | allDocsInner(data);
|
20763 | });
|
20764 | }
|
20765 | else {
|
20766 | allDocsInner();
|
20767 | }
|
20768 | }, function (next) {
|
20769 | Promise.resolve().then(function () {
|
20770 | if (opts.include_docs && opts.attachments) {
|
20771 | return fetchAttachments(results, stores, opts);
|
20772 | }
|
20773 | }).then(function () {
|
20774 | var returnVal = {
|
20775 | total_rows: docCount,
|
20776 | offset: opts.skip,
|
20777 | rows: results
|
20778 | };
|
20779 |
|
20780 | /* istanbul ignore if */
|
20781 | if (opts.update_seq) {
|
20782 | returnVal.update_seq = db._updateSeq;
|
20783 | }
|
20784 | callback(null, returnVal);
|
20785 | }, callback);
|
20786 | next();
|
20787 | }).on('unpipe', function () {
|
20788 | throughStream.end();
|
20789 | });
|
20790 |
|
20791 | docstream.on('error', callback);
|
20792 |
|
20793 | docstream.pipe(throughStream);
|
20794 | });
|
20795 | })(opts, callback);
|
20796 | };
|
20797 |
|
20798 | api._changes = function (opts) {
|
20799 | opts = clone(opts);
|
20800 |
|
20801 | if (opts.continuous) {
|
20802 | var id = name + ':' + uuid();
|
20803 | levelChanges.addListener(name, id, api, opts);
|
20804 | levelChanges.notify(name);
|
20805 | return {
|
20806 | cancel: function () {
|
20807 | levelChanges.removeListener(name, id);
|
20808 | }
|
20809 | };
|
20810 | }
|
20811 |
|
20812 | var descending = opts.descending;
|
20813 | var results = [];
|
20814 | var lastSeq = opts.since || 0;
|
20815 | var called = 0;
|
20816 | var streamOpts = {
|
20817 | reverse: descending
|
20818 | };
|
20819 | var limit;
|
20820 | if ('limit' in opts && opts.limit > 0) {
|
20821 | limit = opts.limit;
|
20822 | }
|
20823 | if (!streamOpts.reverse) {
|
20824 | streamOpts.start = formatSeq(opts.since || 0);
|
20825 | }
|
20826 |
|
20827 | var docIds = opts.doc_ids && new ExportedSet(opts.doc_ids);
|
20828 | var filter = filterChange(opts);
|
20829 | var docIdsToMetadata = new ExportedMap();
|
20830 |
|
20831 | function complete() {
|
20832 | opts.done = true;
|
20833 | if (opts.return_docs && opts.limit) {
|
20834 | /* istanbul ignore if */
|
20835 | if (opts.limit < results.length) {
|
20836 | results.length = opts.limit;
|
20837 | }
|
20838 | }
|
20839 | changeStream.unpipe(throughStream);
|
20840 | changeStream.destroy();
|
20841 | if (!opts.continuous && !opts.cancelled) {
|
20842 | if (opts.include_docs && opts.attachments && opts.return_docs) {
|
20843 | fetchAttachments(results, stores, opts).then(function () {
|
20844 | opts.complete(null, {results: results, last_seq: lastSeq});
|
20845 | });
|
20846 | } else {
|
20847 | opts.complete(null, {results: results, last_seq: lastSeq});
|
20848 | }
|
20849 | }
|
20850 | }
|
20851 | var changeStream = stores.bySeqStore.readStream(streamOpts);
|
20852 | var throughStream = through2.obj(function (data, _, next) {
|
20853 | if (limit && called >= limit) {
|
20854 | complete();
|
20855 | return next();
|
20856 | }
|
20857 | if (opts.cancelled || opts.done) {
|
20858 | return next();
|
20859 | }
|
20860 |
|
20861 | var seq = parseSeq(data.key);
|
20862 | var doc = data.value;
|
20863 |
|
20864 | if (seq === opts.since && !descending) {
|
20865 | // couchdb ignores `since` if descending=true
|
20866 | return next();
|
20867 | }
|
20868 |
|
20869 | if (docIds && !docIds.has(doc._id)) {
|
20870 | return next();
|
20871 | }
|
20872 |
|
20873 | var metadata;
|
20874 |
|
20875 | function onGetMetadata(metadata) {
|
20876 | var winningRev$$1 = getWinningRev(metadata);
|
20877 |
|
20878 | function onGetWinningDoc(winningDoc) {
|
20879 |
|
20880 | var change = opts.processChange(winningDoc, metadata, opts);
|
20881 | change.seq = metadata.seq;
|
20882 |
|
20883 | var filtered = filter(change);
|
20884 | if (typeof filtered === 'object') {
|
20885 | return opts.complete(filtered);
|
20886 | }
|
20887 |
|
20888 | if (filtered) {
|
20889 | called++;
|
20890 |
|
20891 | if (opts.attachments && opts.include_docs) {
|
20892 | // fetch attachment immediately for the benefit
|
20893 | // of live listeners
|
20894 | fetchAttachments([change], stores, opts).then(function () {
|
20895 | opts.onChange(change);
|
20896 | });
|
20897 | } else {
|
20898 | opts.onChange(change);
|
20899 | }
|
20900 |
|
20901 | if (opts.return_docs) {
|
20902 | results.push(change);
|
20903 | }
|
20904 | }
|
20905 | next();
|
20906 | }
|
20907 |
|
20908 | if (metadata.seq !== seq) {
|
20909 | // some other seq is later
|
20910 | return next();
|
20911 | }
|
20912 |
|
20913 | lastSeq = seq;
|
20914 |
|
20915 | if (winningRev$$1 === doc._rev) {
|
20916 | return onGetWinningDoc(doc);
|
20917 | }
|
20918 |
|
20919 | // fetch the winner
|
20920 |
|
20921 | var winningSeq = metadata.rev_map[winningRev$$1];
|
20922 |
|
20923 | stores.bySeqStore.get(formatSeq(winningSeq), function (err, doc) {
|
20924 | onGetWinningDoc(doc);
|
20925 | });
|
20926 | }
|
20927 |
|
20928 | metadata = docIdsToMetadata.get(doc._id);
|
20929 | if (metadata) { // cached
|
20930 | return onGetMetadata(metadata);
|
20931 | }
|
20932 | // metadata not cached, have to go fetch it
|
20933 | stores.docStore.get(doc._id, function (err, metadata) {
|
20934 | /* istanbul ignore if */
|
20935 | if (opts.cancelled || opts.done || db.isClosed() ||
|
20936 | isLocalId(metadata.id)) {
|
20937 | return next();
|
20938 | }
|
20939 | docIdsToMetadata.set(doc._id, metadata);
|
20940 | onGetMetadata(metadata);
|
20941 | });
|
20942 | }, function (next) {
|
20943 | if (opts.cancelled) {
|
20944 | return next();
|
20945 | }
|
20946 | if (opts.return_docs && opts.limit) {
|
20947 | /* istanbul ignore if */
|
20948 | if (opts.limit < results.length) {
|
20949 | results.length = opts.limit;
|
20950 | }
|
20951 | }
|
20952 |
|
20953 | next();
|
20954 | }).on('unpipe', function () {
|
20955 | throughStream.end();
|
20956 | complete();
|
20957 | });
|
20958 | changeStream.pipe(throughStream);
|
20959 | return {
|
20960 | cancel: function () {
|
20961 | opts.cancelled = true;
|
20962 | complete();
|
20963 | }
|
20964 | };
|
20965 | };
|
20966 |
|
20967 | api._close = function (callback) {
|
20968 | /* istanbul ignore if */
|
20969 | if (db.isClosed()) {
|
20970 | return callback(createError(NOT_OPEN));
|
20971 | }
|
20972 | db.close(function (err) {
|
20973 | /* istanbul ignore if */
|
20974 | if (err) {
|
20975 | callback(err);
|
20976 | } else {
|
20977 | dbStore["delete"](name);
|
20978 | callback();
|
20979 | }
|
20980 | });
|
20981 | };
|
20982 |
|
20983 | api._getRevisionTree = function (docId, callback) {
|
20984 | stores.docStore.get(docId, function (err, metadata) {
|
20985 | if (err) {
|
20986 | callback(createError(MISSING_DOC));
|
20987 | } else {
|
20988 | callback(null, metadata.rev_tree);
|
20989 | }
|
20990 | });
|
20991 | };
|
20992 |
|
20993 | api._doCompaction = writeLock(function (docId, revs, opts, callback) {
|
20994 | api._doCompactionNoLock(docId, revs, opts, callback);
|
20995 | });
|
20996 |
|
20997 | // the NoLock version is for use by bulkDocs
|
20998 | api._doCompactionNoLock = function (docId, revs, opts, callback) {
|
20999 | if (typeof opts === 'function') {
|
21000 | callback = opts;
|
21001 | opts = {};
|
21002 | }
|
21003 |
|
21004 | if (!revs.length) {
|
21005 | return callback();
|
21006 | }
|
21007 | var txn = opts.ctx || new LevelTransaction();
|
21008 |
|
21009 | txn.get(stores.docStore, docId, function (err, metadata) {
|
21010 | /* istanbul ignore if */
|
21011 | if (err) {
|
21012 | return callback(err);
|
21013 | }
|
21014 | var seqs = revs.map(function (rev$$1) {
|
21015 | var seq = metadata.rev_map[rev$$1];
|
21016 | delete metadata.rev_map[rev$$1];
|
21017 | return seq;
|
21018 | });
|
21019 | traverseRevTree(metadata.rev_tree, function (isLeaf, pos,
|
21020 | revHash, ctx, opts) {
|
21021 | var rev$$1 = pos + '-' + revHash;
|
21022 | if (revs.indexOf(rev$$1) !== -1) {
|
21023 | opts.status = 'missing';
|
21024 | }
|
21025 | });
|
21026 |
|
21027 | var batch = [];
|
21028 | batch.push({
|
21029 | key: metadata.id,
|
21030 | value: metadata,
|
21031 | type: 'put',
|
21032 | prefix: stores.docStore
|
21033 | });
|
21034 |
|
21035 | var digestMap = {};
|
21036 | var numDone = 0;
|
21037 | var overallErr;
|
21038 | function checkDone(err) {
|
21039 | /* istanbul ignore if */
|
21040 | if (err) {
|
21041 | overallErr = err;
|
21042 | }
|
21043 | if (++numDone === revs.length) { // done
|
21044 | /* istanbul ignore if */
|
21045 | if (overallErr) {
|
21046 | return callback(overallErr);
|
21047 | }
|
21048 | deleteOrphanedAttachments();
|
21049 | }
|
21050 | }
|
21051 |
|
21052 | function finish(err) {
|
21053 | /* istanbul ignore if */
|
21054 | if (err) {
|
21055 | return callback(err);
|
21056 | }
|
21057 | txn.batch(batch);
|
21058 | if (opts.ctx) {
|
21059 | // don't execute immediately
|
21060 | return callback();
|
21061 | }
|
21062 | txn.execute(db, callback);
|
21063 | }
|
21064 |
|
21065 | function deleteOrphanedAttachments() {
|
21066 | var possiblyOrphanedAttachments = Object.keys(digestMap);
|
21067 | if (!possiblyOrphanedAttachments.length) {
|
21068 | return finish();
|
21069 | }
|
21070 | var numDone = 0;
|
21071 | var overallErr;
|
21072 | function checkDone(err) {
|
21073 | /* istanbul ignore if */
|
21074 | if (err) {
|
21075 | overallErr = err;
|
21076 | }
|
21077 | if (++numDone === possiblyOrphanedAttachments.length) {
|
21078 | finish(overallErr);
|
21079 | }
|
21080 | }
|
21081 | var refsToDelete = new ExportedMap();
|
21082 | revs.forEach(function (rev$$1) {
|
21083 | refsToDelete.set(docId + '@' + rev$$1, true);
|
21084 | });
|
21085 | possiblyOrphanedAttachments.forEach(function (digest) {
|
21086 | txn.get(stores.attachmentStore, digest, function (err, attData) {
|
21087 | /* istanbul ignore if */
|
21088 | if (err) {
|
21089 | if (err.name === 'NotFoundError') {
|
21090 | return checkDone();
|
21091 | } else {
|
21092 | return checkDone(err);
|
21093 | }
|
21094 | }
|
21095 | var refs = Object.keys(attData.refs || {}).filter(function (ref) {
|
21096 | return !refsToDelete.has(ref);
|
21097 | });
|
21098 | var newRefs = {};
|
21099 | refs.forEach(function (ref) {
|
21100 | newRefs[ref] = true;
|
21101 | });
|
21102 | if (refs.length) { // not orphaned
|
21103 | batch.push({
|
21104 | key: digest,
|
21105 | type: 'put',
|
21106 | value: {refs: newRefs},
|
21107 | prefix: stores.attachmentStore
|
21108 | });
|
21109 | } else { // orphaned, can safely delete
|
21110 | batch = batch.concat([{
|
21111 | key: digest,
|
21112 | type: 'del',
|
21113 | prefix: stores.attachmentStore
|
21114 | }, {
|
21115 | key: digest,
|
21116 | type: 'del',
|
21117 | prefix: stores.binaryStore
|
21118 | }]);
|
21119 | }
|
21120 | checkDone();
|
21121 | });
|
21122 | });
|
21123 | }
|
21124 |
|
21125 | seqs.forEach(function (seq) {
|
21126 | batch.push({
|
21127 | key: formatSeq(seq),
|
21128 | type: 'del',
|
21129 | prefix: stores.bySeqStore
|
21130 | });
|
21131 | txn.get(stores.bySeqStore, formatSeq(seq), function (err, doc) {
|
21132 | /* istanbul ignore if */
|
21133 | if (err) {
|
21134 | if (err.name === 'NotFoundError') {
|
21135 | return checkDone();
|
21136 | } else {
|
21137 | return checkDone(err);
|
21138 | }
|
21139 | }
|
21140 | var atts = Object.keys(doc._attachments || {});
|
21141 | atts.forEach(function (attName) {
|
21142 | var digest = doc._attachments[attName].digest;
|
21143 | digestMap[digest] = true;
|
21144 | });
|
21145 | checkDone();
|
21146 | });
|
21147 | });
|
21148 | });
|
21149 | };
|
21150 |
|
21151 | api._getLocal = function (id, callback) {
|
21152 | stores.localStore.get(id, function (err, doc) {
|
21153 | if (err) {
|
21154 | callback(createError(MISSING_DOC));
|
21155 | } else {
|
21156 | callback(null, doc);
|
21157 | }
|
21158 | });
|
21159 | };
|
21160 |
|
21161 | api._putLocal = function (doc, opts, callback) {
|
21162 | if (typeof opts === 'function') {
|
21163 | callback = opts;
|
21164 | opts = {};
|
21165 | }
|
21166 | if (opts.ctx) {
|
21167 | api._putLocalNoLock(doc, opts, callback);
|
21168 | } else {
|
21169 | api._putLocalWithLock(doc, opts, callback);
|
21170 | }
|
21171 | };
|
21172 |
|
21173 | api._putLocalWithLock = writeLock(function (doc, opts, callback) {
|
21174 | api._putLocalNoLock(doc, opts, callback);
|
21175 | });
|
21176 |
|
21177 | // the NoLock version is for use by bulkDocs
|
21178 | api._putLocalNoLock = function (doc, opts, callback) {
|
21179 | delete doc._revisions; // ignore this, trust the rev
|
21180 | var oldRev = doc._rev;
|
21181 | var id = doc._id;
|
21182 |
|
21183 | var txn = opts.ctx || new LevelTransaction();
|
21184 |
|
21185 | txn.get(stores.localStore, id, function (err, resp) {
|
21186 | if (err && oldRev) {
|
21187 | return callback(createError(REV_CONFLICT));
|
21188 | }
|
21189 | if (resp && resp._rev !== oldRev) {
|
21190 | return callback(createError(REV_CONFLICT));
|
21191 | }
|
21192 | doc._rev =
|
21193 | oldRev ? '0-' + (parseInt(oldRev.split('-')[1], 10) + 1) : '0-1';
|
21194 | var batch = [
|
21195 | {
|
21196 | type: 'put',
|
21197 | prefix: stores.localStore,
|
21198 | key: id,
|
21199 | value: doc
|
21200 | }
|
21201 | ];
|
21202 |
|
21203 | txn.batch(batch);
|
21204 | var ret = {ok: true, id: doc._id, rev: doc._rev};
|
21205 |
|
21206 | if (opts.ctx) {
|
21207 | // don't execute immediately
|
21208 | return callback(null, ret);
|
21209 | }
|
21210 | txn.execute(db, function (err) {
|
21211 | /* istanbul ignore if */
|
21212 | if (err) {
|
21213 | return callback(err);
|
21214 | }
|
21215 | callback(null, ret);
|
21216 | });
|
21217 | });
|
21218 | };
|
21219 |
|
21220 | api._removeLocal = function (doc, opts, callback) {
|
21221 | if (typeof opts === 'function') {
|
21222 | callback = opts;
|
21223 | opts = {};
|
21224 | }
|
21225 | if (opts.ctx) {
|
21226 | api._removeLocalNoLock(doc, opts, callback);
|
21227 | } else {
|
21228 | api._removeLocalWithLock(doc, opts, callback);
|
21229 | }
|
21230 | };
|
21231 |
|
21232 | api._removeLocalWithLock = writeLock(function (doc, opts, callback) {
|
21233 | api._removeLocalNoLock(doc, opts, callback);
|
21234 | });
|
21235 |
|
21236 | // the NoLock version is for use by bulkDocs
|
21237 | api._removeLocalNoLock = function (doc, opts, callback) {
|
21238 | var txn = opts.ctx || new LevelTransaction();
|
21239 | txn.get(stores.localStore, doc._id, function (err, resp) {
|
21240 | if (err) {
|
21241 | /* istanbul ignore if */
|
21242 | if (err.name !== 'NotFoundError') {
|
21243 | return callback(err);
|
21244 | } else {
|
21245 | return callback(createError(MISSING_DOC));
|
21246 | }
|
21247 | }
|
21248 | if (resp._rev !== doc._rev) {
|
21249 | return callback(createError(REV_CONFLICT));
|
21250 | }
|
21251 | txn.batch([{
|
21252 | prefix: stores.localStore,
|
21253 | type: 'del',
|
21254 | key: doc._id
|
21255 | }]);
|
21256 | var ret = {ok: true, id: doc._id, rev: '0-0'};
|
21257 | if (opts.ctx) {
|
21258 | // don't execute immediately
|
21259 | return callback(null, ret);
|
21260 | }
|
21261 | txn.execute(db, function (err) {
|
21262 | /* istanbul ignore if */
|
21263 | if (err) {
|
21264 | return callback(err);
|
21265 | }
|
21266 | callback(null, ret);
|
21267 | });
|
21268 | });
|
21269 | };
|
21270 |
|
21271 | // close and delete open leveldb stores
|
21272 | api._destroy = function (opts, callback) {
|
21273 | var dbStore;
|
21274 | var leveldownName = functionName(leveldown);
|
21275 | /* istanbul ignore else */
|
21276 | if (dbStores.has(leveldownName)) {
|
21277 | dbStore = dbStores.get(leveldownName);
|
21278 | } else {
|
21279 | return callDestroy(name, callback);
|
21280 | }
|
21281 |
|
21282 | /* istanbul ignore else */
|
21283 | if (dbStore.has(name)) {
|
21284 | levelChanges.removeAllListeners(name);
|
21285 |
|
21286 | dbStore.get(name).close(function () {
|
21287 | dbStore["delete"](name);
|
21288 | callDestroy(name, callback);
|
21289 | });
|
21290 | } else {
|
21291 | callDestroy(name, callback);
|
21292 | }
|
21293 | };
|
21294 | function callDestroy(name, cb) {
|
21295 | // May not exist if leveldown is backed by memory adapter
|
21296 | /* istanbul ignore else */
|
21297 | if ('destroy' in leveldown) {
|
21298 | leveldown.destroy(name, cb);
|
21299 | } else {
|
21300 | cb(null);
|
21301 | }
|
21302 | }
|
21303 | }
|
21304 |
|
21305 | function MemDownPouch(opts, callback) {
|
21306 | var _opts = $inject_Object_assign({
|
21307 | db: memdown
|
21308 | }, opts);
|
21309 |
|
21310 | LevelPouch.call(this, _opts, callback);
|
21311 | }
|
21312 |
|
21313 | // overrides for normal LevelDB behavior on Node
|
21314 | MemDownPouch.valid = function () {
|
21315 | return true;
|
21316 | };
|
21317 | MemDownPouch.use_prefix = false;
|
21318 |
|
21319 | function MemoryPouchPlugin (PouchDB) {
|
21320 | PouchDB.adapter('memory', MemDownPouch, true);
|
21321 | }
|
21322 |
|
21323 | /* global PouchDB */
|
21324 |
|
21325 | if (typeof PouchDB === 'undefined') {
|
21326 | guardedConsole('error', 'memory adapter plugin error: ' +
|
21327 | 'Cannot find global "PouchDB" object! ' +
|
21328 | 'Did you remember to include pouchdb.js?');
|
21329 | } else {
|
21330 | PouchDB.plugin(MemoryPouchPlugin);
|
21331 | }
|
21332 |
|
21333 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
21334 | },{"1":1,"11":11,"114":114,"120":120,"125":125,"14":14,"17":17,"18":18,"21":21,"43":43,"52":52,"54":54,"78":78,"8":8,"80":80}]},{},[126]);
|
21335 |
|
\ | No newline at end of file |