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 | (function (process){
|
10 |
|
11 |
|
12 | function AbstractChainedBatch (db) {
|
13 | this._db = db
|
14 | this._operations = []
|
15 | this._written = false
|
16 | }
|
17 |
|
18 | AbstractChainedBatch.prototype._checkWritten = function () {
|
19 | if (this._written)
|
20 | throw new Error('write() already called on this batch')
|
21 | }
|
22 |
|
23 | AbstractChainedBatch.prototype.put = function (key, value) {
|
24 | this._checkWritten()
|
25 |
|
26 | var err = this._db._checkKeyValue(key, 'key', this._db._isBuffer)
|
27 | if (err) throw err
|
28 | err = this._db._checkKeyValue(value, 'value', this._db._isBuffer)
|
29 | if (err) throw err
|
30 |
|
31 | if (!this._db._isBuffer(key)) key = String(key)
|
32 | if (!this._db._isBuffer(value)) value = String(value)
|
33 |
|
34 | if (typeof this._put == 'function' )
|
35 | this._put(key, value)
|
36 | else
|
37 | this._operations.push({ type: 'put', key: key, value: value })
|
38 |
|
39 | return this
|
40 | }
|
41 |
|
42 | AbstractChainedBatch.prototype.del = function (key) {
|
43 | this._checkWritten()
|
44 |
|
45 | var err = this._db._checkKeyValue(key, 'key', this._db._isBuffer)
|
46 | if (err) throw err
|
47 |
|
48 | if (!this._db._isBuffer(key)) key = String(key)
|
49 |
|
50 | if (typeof this._del == 'function' )
|
51 | this._del(key)
|
52 | else
|
53 | this._operations.push({ type: 'del', key: key })
|
54 |
|
55 | return this
|
56 | }
|
57 |
|
58 | AbstractChainedBatch.prototype.clear = function () {
|
59 | this._checkWritten()
|
60 |
|
61 | this._operations = []
|
62 |
|
63 | if (typeof this._clear == 'function' )
|
64 | this._clear()
|
65 |
|
66 | return this
|
67 | }
|
68 |
|
69 | AbstractChainedBatch.prototype.write = function (options, callback) {
|
70 | this._checkWritten()
|
71 |
|
72 | if (typeof options == 'function')
|
73 | callback = options
|
74 | if (typeof callback != 'function')
|
75 | throw new Error('write() requires a callback argument')
|
76 | if (typeof options != 'object')
|
77 | options = {}
|
78 |
|
79 | this._written = true
|
80 |
|
81 | if (typeof this._write == 'function' )
|
82 | return this._write(callback)
|
83 |
|
84 | if (typeof this._db._batch == 'function')
|
85 | return this._db._batch(this._operations, options, callback)
|
86 |
|
87 | process.nextTick(callback)
|
88 | }
|
89 |
|
90 | module.exports = AbstractChainedBatch
|
91 | }).call(this,_dereq_(55))
|
92 | },{"55":55}],2:[function(_dereq_,module,exports){
|
93 | (function (process){
|
94 |
|
95 |
|
96 | function AbstractIterator (db) {
|
97 | this.db = db
|
98 | this._ended = false
|
99 | this._nexting = false
|
100 | }
|
101 |
|
102 | AbstractIterator.prototype.next = function (callback) {
|
103 | var self = this
|
104 |
|
105 | if (typeof callback != 'function')
|
106 | throw new Error('next() requires a callback argument')
|
107 |
|
108 | if (self._ended)
|
109 | return callback(new Error('cannot call next() after end()'))
|
110 | if (self._nexting)
|
111 | return callback(new Error('cannot call next() before previous next() has completed'))
|
112 |
|
113 | self._nexting = true
|
114 | if (typeof self._next == 'function') {
|
115 | return self._next(function () {
|
116 | self._nexting = false
|
117 | callback.apply(null, arguments)
|
118 | })
|
119 | }
|
120 |
|
121 | process.nextTick(function () {
|
122 | self._nexting = false
|
123 | callback()
|
124 | })
|
125 | }
|
126 |
|
127 | AbstractIterator.prototype.end = function (callback) {
|
128 | if (typeof callback != 'function')
|
129 | throw new Error('end() requires a callback argument')
|
130 |
|
131 | if (this._ended)
|
132 | return callback(new Error('end() already called on iterator'))
|
133 |
|
134 | this._ended = true
|
135 |
|
136 | if (typeof this._end == 'function')
|
137 | return this._end(callback)
|
138 |
|
139 | process.nextTick(callback)
|
140 | }
|
141 |
|
142 | module.exports = AbstractIterator
|
143 |
|
144 | }).call(this,_dereq_(55))
|
145 | },{"55":55}],3:[function(_dereq_,module,exports){
|
146 | (function (Buffer,process){
|
147 |
|
148 |
|
149 | var xtend = _dereq_(105)
|
150 | , AbstractIterator = _dereq_(2)
|
151 | , AbstractChainedBatch = _dereq_(1)
|
152 |
|
153 | function AbstractLevelDOWN (location) {
|
154 | if (!arguments.length || location === undefined)
|
155 | throw new Error('constructor requires at least a location argument')
|
156 |
|
157 | if (typeof location != 'string')
|
158 | throw new Error('constructor requires a location string argument')
|
159 |
|
160 | this.location = location
|
161 | }
|
162 |
|
163 | AbstractLevelDOWN.prototype.open = function (options, callback) {
|
164 | if (typeof options == 'function')
|
165 | callback = options
|
166 |
|
167 | if (typeof callback != 'function')
|
168 | throw new Error('open() requires a callback argument')
|
169 |
|
170 | if (typeof options != 'object')
|
171 | options = {}
|
172 |
|
173 | if (typeof this._open == 'function')
|
174 | return this._open(options, callback)
|
175 |
|
176 | process.nextTick(callback)
|
177 | }
|
178 |
|
179 | AbstractLevelDOWN.prototype.close = function (callback) {
|
180 | if (typeof callback != 'function')
|
181 | throw new Error('close() requires a callback argument')
|
182 |
|
183 | if (typeof this._close == 'function')
|
184 | return this._close(callback)
|
185 |
|
186 | process.nextTick(callback)
|
187 | }
|
188 |
|
189 | AbstractLevelDOWN.prototype.get = function (key, options, callback) {
|
190 | var err
|
191 |
|
192 | if (typeof options == 'function')
|
193 | callback = options
|
194 |
|
195 | if (typeof callback != 'function')
|
196 | throw new Error('get() requires a callback argument')
|
197 |
|
198 | if (err = this._checkKeyValue(key, 'key', this._isBuffer))
|
199 | return callback(err)
|
200 |
|
201 | if (!this._isBuffer(key))
|
202 | key = String(key)
|
203 |
|
204 | if (typeof options != 'object')
|
205 | options = {}
|
206 |
|
207 | if (typeof this._get == 'function')
|
208 | return this._get(key, options, callback)
|
209 |
|
210 | process.nextTick(function () { callback(new Error('NotFound')) })
|
211 | }
|
212 |
|
213 | AbstractLevelDOWN.prototype.put = function (key, value, options, callback) {
|
214 | var err
|
215 |
|
216 | if (typeof options == 'function')
|
217 | callback = options
|
218 |
|
219 | if (typeof callback != 'function')
|
220 | throw new Error('put() requires a callback argument')
|
221 |
|
222 | if (err = this._checkKeyValue(key, 'key', this._isBuffer))
|
223 | return callback(err)
|
224 |
|
225 | if (err = this._checkKeyValue(value, 'value', this._isBuffer))
|
226 | return callback(err)
|
227 |
|
228 | if (!this._isBuffer(key))
|
229 | key = String(key)
|
230 |
|
231 |
|
232 |
|
233 | if (!this._isBuffer(value) && !process.browser)
|
234 | value = String(value)
|
235 |
|
236 | if (typeof options != 'object')
|
237 | options = {}
|
238 |
|
239 | if (typeof this._put == 'function')
|
240 | return this._put(key, value, options, callback)
|
241 |
|
242 | process.nextTick(callback)
|
243 | }
|
244 |
|
245 | AbstractLevelDOWN.prototype.del = function (key, options, callback) {
|
246 | var err
|
247 |
|
248 | if (typeof options == 'function')
|
249 | callback = options
|
250 |
|
251 | if (typeof callback != 'function')
|
252 | throw new Error('del() requires a callback argument')
|
253 |
|
254 | if (err = this._checkKeyValue(key, 'key', this._isBuffer))
|
255 | return callback(err)
|
256 |
|
257 | if (!this._isBuffer(key))
|
258 | key = String(key)
|
259 |
|
260 | if (typeof options != 'object')
|
261 | options = {}
|
262 |
|
263 | if (typeof this._del == 'function')
|
264 | return this._del(key, options, callback)
|
265 |
|
266 | process.nextTick(callback)
|
267 | }
|
268 |
|
269 | AbstractLevelDOWN.prototype.batch = function (array, options, callback) {
|
270 | if (!arguments.length)
|
271 | return this._chainedBatch()
|
272 |
|
273 | if (typeof options == 'function')
|
274 | callback = options
|
275 |
|
276 | if (typeof callback != 'function')
|
277 | throw new Error('batch(array) requires a callback argument')
|
278 |
|
279 | if (!Array.isArray(array))
|
280 | return callback(new Error('batch(array) requires an array argument'))
|
281 |
|
282 | if (typeof options != 'object')
|
283 | options = {}
|
284 |
|
285 | var i = 0
|
286 | , l = array.length
|
287 | , e
|
288 | , err
|
289 |
|
290 | for (; i < l; i++) {
|
291 | e = array[i]
|
292 | if (typeof e != 'object')
|
293 | continue
|
294 |
|
295 | if (err = this._checkKeyValue(e.type, 'type', this._isBuffer))
|
296 | return callback(err)
|
297 |
|
298 | if (err = this._checkKeyValue(e.key, 'key', this._isBuffer))
|
299 | return callback(err)
|
300 |
|
301 | if (e.type == 'put') {
|
302 | if (err = this._checkKeyValue(e.value, 'value', this._isBuffer))
|
303 | return callback(err)
|
304 | }
|
305 | }
|
306 |
|
307 | if (typeof this._batch == 'function')
|
308 | return this._batch(array, options, callback)
|
309 |
|
310 | process.nextTick(callback)
|
311 | }
|
312 |
|
313 |
|
314 | AbstractLevelDOWN.prototype.approximateSize = function (start, end, callback) {
|
315 | if ( start == null
|
316 | || end == null
|
317 | || typeof start == 'function'
|
318 | || typeof end == 'function') {
|
319 | throw new Error('approximateSize() requires valid `start`, `end` and `callback` arguments')
|
320 | }
|
321 |
|
322 | if (typeof callback != 'function')
|
323 | throw new Error('approximateSize() requires a callback argument')
|
324 |
|
325 | if (!this._isBuffer(start))
|
326 | start = String(start)
|
327 |
|
328 | if (!this._isBuffer(end))
|
329 | end = String(end)
|
330 |
|
331 | if (typeof this._approximateSize == 'function')
|
332 | return this._approximateSize(start, end, callback)
|
333 |
|
334 | process.nextTick(function () {
|
335 | callback(null, 0)
|
336 | })
|
337 | }
|
338 |
|
339 | AbstractLevelDOWN.prototype._setupIteratorOptions = function (options) {
|
340 | var self = this
|
341 |
|
342 | options = xtend(options)
|
343 |
|
344 | ;[ 'start', 'end', 'gt', 'gte', 'lt', 'lte' ].forEach(function (o) {
|
345 | if (options[o] && self._isBuffer(options[o]) && options[o].length === 0)
|
346 | delete options[o]
|
347 | })
|
348 |
|
349 | options.reverse = !!options.reverse
|
350 |
|
351 |
|
352 | if (options.reverse && options.lt)
|
353 | options.start = options.lt
|
354 | if (options.reverse && options.lte)
|
355 | options.start = options.lte
|
356 | if (!options.reverse && options.gt)
|
357 | options.start = options.gt
|
358 | if (!options.reverse && options.gte)
|
359 | options.start = options.gte
|
360 |
|
361 | if ((options.reverse && options.lt && !options.lte)
|
362 | || (!options.reverse && options.gt && !options.gte))
|
363 | options.exclusiveStart = true
|
364 |
|
365 | return options
|
366 | }
|
367 |
|
368 | AbstractLevelDOWN.prototype.iterator = function (options) {
|
369 | if (typeof options != 'object')
|
370 | options = {}
|
371 |
|
372 | options = this._setupIteratorOptions(options)
|
373 |
|
374 | if (typeof this._iterator == 'function')
|
375 | return this._iterator(options)
|
376 |
|
377 | return new AbstractIterator(this)
|
378 | }
|
379 |
|
380 | AbstractLevelDOWN.prototype._chainedBatch = function () {
|
381 | return new AbstractChainedBatch(this)
|
382 | }
|
383 |
|
384 | AbstractLevelDOWN.prototype._isBuffer = function (obj) {
|
385 | return Buffer.isBuffer(obj)
|
386 | }
|
387 |
|
388 | AbstractLevelDOWN.prototype._checkKeyValue = function (obj, type) {
|
389 | if (obj === null || obj === undefined)
|
390 | return new Error(type + ' cannot be `null` or `undefined`')
|
391 |
|
392 | if (obj === null || obj === undefined)
|
393 | return new Error(type + ' cannot be `null` or `undefined`')
|
394 |
|
395 | if (this._isBuffer(obj)) {
|
396 | if (obj.length === 0)
|
397 | return new Error(type + ' cannot be an empty Buffer')
|
398 | } else if (String(obj) === '')
|
399 | return new Error(type + ' cannot be an empty String')
|
400 | }
|
401 |
|
402 | module.exports.AbstractLevelDOWN = AbstractLevelDOWN
|
403 | module.exports.AbstractIterator = AbstractIterator
|
404 | module.exports.AbstractChainedBatch = AbstractChainedBatch
|
405 |
|
406 | }).call(this,{"isBuffer":_dereq_(27)},_dereq_(55))
|
407 | },{"1":1,"105":105,"2":2,"27":27,"55":55}],4:[function(_dereq_,module,exports){
|
408 | 'use strict';
|
409 |
|
410 | module.exports = argsArray;
|
411 |
|
412 | function argsArray(fun) {
|
413 | return function () {
|
414 | var len = arguments.length;
|
415 | if (len) {
|
416 | var args = [];
|
417 | var i = -1;
|
418 | while (++i < len) {
|
419 | args[i] = arguments[i];
|
420 | }
|
421 | return fun.call(this, args);
|
422 | } else {
|
423 | return fun.call(this, []);
|
424 | }
|
425 | };
|
426 | }
|
427 | },{}],5:[function(_dereq_,module,exports){
|
428 | (function (global){
|
429 | 'use strict';
|
430 |
|
431 |
|
432 |
|
433 |
|
434 |
|
435 |
|
436 |
|
437 |
|
438 |
|
439 |
|
440 | function compare(a, b) {
|
441 | if (a === b) {
|
442 | return 0;
|
443 | }
|
444 |
|
445 | var x = a.length;
|
446 | var y = b.length;
|
447 |
|
448 | for (var i = 0, len = Math.min(x, y); i < len; ++i) {
|
449 | if (a[i] !== b[i]) {
|
450 | x = a[i];
|
451 | y = b[i];
|
452 | break;
|
453 | }
|
454 | }
|
455 |
|
456 | if (x < y) {
|
457 | return -1;
|
458 | }
|
459 | if (y < x) {
|
460 | return 1;
|
461 | }
|
462 | return 0;
|
463 | }
|
464 | function isBuffer(b) {
|
465 | if (global.Buffer && typeof global.Buffer.isBuffer === 'function') {
|
466 | return global.Buffer.isBuffer(b);
|
467 | }
|
468 | return !!(b != null && b._isBuffer);
|
469 | }
|
470 |
|
471 |
|
472 |
|
473 |
|
474 |
|
475 |
|
476 |
|
477 |
|
478 |
|
479 |
|
480 |
|
481 |
|
482 |
|
483 |
|
484 |
|
485 |
|
486 |
|
487 |
|
488 |
|
489 |
|
490 |
|
491 |
|
492 |
|
493 |
|
494 |
|
495 |
|
496 |
|
497 | var util = _dereq_(8);
|
498 | var hasOwn = Object.prototype.hasOwnProperty;
|
499 | var pSlice = Array.prototype.slice;
|
500 | var functionsHaveNames = (function () {
|
501 | return function foo() {}.name === 'foo';
|
502 | }());
|
503 | function pToString (obj) {
|
504 | return Object.prototype.toString.call(obj);
|
505 | }
|
506 | function isView(arrbuf) {
|
507 | if (isBuffer(arrbuf)) {
|
508 | return false;
|
509 | }
|
510 | if (typeof global.ArrayBuffer !== 'function') {
|
511 | return false;
|
512 | }
|
513 | if (typeof ArrayBuffer.isView === 'function') {
|
514 | return ArrayBuffer.isView(arrbuf);
|
515 | }
|
516 | if (!arrbuf) {
|
517 | return false;
|
518 | }
|
519 | if (arrbuf instanceof DataView) {
|
520 | return true;
|
521 | }
|
522 | if (arrbuf.buffer && arrbuf.buffer instanceof ArrayBuffer) {
|
523 | return true;
|
524 | }
|
525 | return false;
|
526 | }
|
527 |
|
528 |
|
529 |
|
530 |
|
531 | var assert = module.exports = ok;
|
532 |
|
533 |
|
534 |
|
535 |
|
536 |
|
537 |
|
538 | var regex = /\s*function\s+([^\(\s]*)\s*/;
|
539 |
|
540 | function getName(func) {
|
541 | if (!util.isFunction(func)) {
|
542 | return;
|
543 | }
|
544 | if (functionsHaveNames) {
|
545 | return func.name;
|
546 | }
|
547 | var str = func.toString();
|
548 | var match = str.match(regex);
|
549 | return match && match[1];
|
550 | }
|
551 | assert.AssertionError = function AssertionError(options) {
|
552 | this.name = 'AssertionError';
|
553 | this.actual = options.actual;
|
554 | this.expected = options.expected;
|
555 | this.operator = options.operator;
|
556 | if (options.message) {
|
557 | this.message = options.message;
|
558 | this.generatedMessage = false;
|
559 | } else {
|
560 | this.message = getMessage(this);
|
561 | this.generatedMessage = true;
|
562 | }
|
563 | var stackStartFunction = options.stackStartFunction || fail;
|
564 | if (Error.captureStackTrace) {
|
565 | Error.captureStackTrace(this, stackStartFunction);
|
566 | } else {
|
567 |
|
568 | var err = new Error();
|
569 | if (err.stack) {
|
570 | var out = err.stack;
|
571 |
|
572 |
|
573 | var fn_name = getName(stackStartFunction);
|
574 | var idx = out.indexOf('\n' + fn_name);
|
575 | if (idx >= 0) {
|
576 |
|
577 |
|
578 | var next_line = out.indexOf('\n', idx + 1);
|
579 | out = out.substring(next_line + 1);
|
580 | }
|
581 |
|
582 | this.stack = out;
|
583 | }
|
584 | }
|
585 | };
|
586 |
|
587 |
|
588 | util.inherits(assert.AssertionError, Error);
|
589 |
|
590 | function truncate(s, n) {
|
591 | if (typeof s === 'string') {
|
592 | return s.length < n ? s : s.slice(0, n);
|
593 | } else {
|
594 | return s;
|
595 | }
|
596 | }
|
597 | function inspect(something) {
|
598 | if (functionsHaveNames || !util.isFunction(something)) {
|
599 | return util.inspect(something);
|
600 | }
|
601 | var rawname = getName(something);
|
602 | var name = rawname ? ': ' + rawname : '';
|
603 | return '[Function' + name + ']';
|
604 | }
|
605 | function getMessage(self) {
|
606 | return truncate(inspect(self.actual), 128) + ' ' +
|
607 | self.operator + ' ' +
|
608 | truncate(inspect(self.expected), 128);
|
609 | }
|
610 |
|
611 |
|
612 |
|
613 |
|
614 |
|
615 |
|
616 |
|
617 |
|
618 |
|
619 |
|
620 |
|
621 |
|
622 | function fail(actual, expected, message, operator, stackStartFunction) {
|
623 | throw new assert.AssertionError({
|
624 | message: message,
|
625 | actual: actual,
|
626 | expected: expected,
|
627 | operator: operator,
|
628 | stackStartFunction: stackStartFunction
|
629 | });
|
630 | }
|
631 |
|
632 |
|
633 | assert.fail = fail;
|
634 |
|
635 |
|
636 |
|
637 |
|
638 |
|
639 |
|
640 |
|
641 |
|
642 | function ok(value, message) {
|
643 | if (!value) fail(value, true, message, '==', assert.ok);
|
644 | }
|
645 | assert.ok = ok;
|
646 |
|
647 |
|
648 |
|
649 |
|
650 |
|
651 | assert.equal = function equal(actual, expected, message) {
|
652 | if (actual != expected) fail(actual, expected, message, '==', assert.equal);
|
653 | };
|
654 |
|
655 |
|
656 |
|
657 |
|
658 | assert.notEqual = function notEqual(actual, expected, message) {
|
659 | if (actual == expected) {
|
660 | fail(actual, expected, message, '!=', assert.notEqual);
|
661 | }
|
662 | };
|
663 |
|
664 |
|
665 |
|
666 |
|
667 | assert.deepEqual = function deepEqual(actual, expected, message) {
|
668 | if (!_deepEqual(actual, expected, false)) {
|
669 | fail(actual, expected, message, 'deepEqual', assert.deepEqual);
|
670 | }
|
671 | };
|
672 |
|
673 | assert.deepStrictEqual = function deepStrictEqual(actual, expected, message) {
|
674 | if (!_deepEqual(actual, expected, true)) {
|
675 | fail(actual, expected, message, 'deepStrictEqual', assert.deepStrictEqual);
|
676 | }
|
677 | };
|
678 |
|
679 | function _deepEqual(actual, expected, strict, memos) {
|
680 |
|
681 | if (actual === expected) {
|
682 | return true;
|
683 | } else if (isBuffer(actual) && isBuffer(expected)) {
|
684 | return compare(actual, expected) === 0;
|
685 |
|
686 |
|
687 |
|
688 | } else if (util.isDate(actual) && util.isDate(expected)) {
|
689 | return actual.getTime() === expected.getTime();
|
690 |
|
691 |
|
692 |
|
693 |
|
694 | } else if (util.isRegExp(actual) && util.isRegExp(expected)) {
|
695 | return actual.source === expected.source &&
|
696 | actual.global === expected.global &&
|
697 | actual.multiline === expected.multiline &&
|
698 | actual.lastIndex === expected.lastIndex &&
|
699 | actual.ignoreCase === expected.ignoreCase;
|
700 |
|
701 |
|
702 |
|
703 | } else if ((actual === null || typeof actual !== 'object') &&
|
704 | (expected === null || typeof expected !== 'object')) {
|
705 | return strict ? actual === expected : actual == expected;
|
706 |
|
707 |
|
708 |
|
709 |
|
710 |
|
711 |
|
712 |
|
713 | } else if (isView(actual) && isView(expected) &&
|
714 | pToString(actual) === pToString(expected) &&
|
715 | !(actual instanceof Float32Array ||
|
716 | actual instanceof Float64Array)) {
|
717 | return compare(new Uint8Array(actual.buffer),
|
718 | new Uint8Array(expected.buffer)) === 0;
|
719 |
|
720 |
|
721 |
|
722 |
|
723 |
|
724 |
|
725 |
|
726 | } else if (isBuffer(actual) !== isBuffer(expected)) {
|
727 | return false;
|
728 | } else {
|
729 | memos = memos || {actual: [], expected: []};
|
730 |
|
731 | var actualIndex = memos.actual.indexOf(actual);
|
732 | if (actualIndex !== -1) {
|
733 | if (actualIndex === memos.expected.indexOf(expected)) {
|
734 | return true;
|
735 | }
|
736 | }
|
737 |
|
738 | memos.actual.push(actual);
|
739 | memos.expected.push(expected);
|
740 |
|
741 | return objEquiv(actual, expected, strict, memos);
|
742 | }
|
743 | }
|
744 |
|
745 | function isArguments(object) {
|
746 | return Object.prototype.toString.call(object) == '[object Arguments]';
|
747 | }
|
748 |
|
749 | function objEquiv(a, b, strict, actualVisitedObjects) {
|
750 | if (a === null || a === undefined || b === null || b === undefined)
|
751 | return false;
|
752 |
|
753 | if (util.isPrimitive(a) || util.isPrimitive(b))
|
754 | return a === b;
|
755 | if (strict && Object.getPrototypeOf(a) !== Object.getPrototypeOf(b))
|
756 | return false;
|
757 | var aIsArgs = isArguments(a);
|
758 | var bIsArgs = isArguments(b);
|
759 | if ((aIsArgs && !bIsArgs) || (!aIsArgs && bIsArgs))
|
760 | return false;
|
761 | if (aIsArgs) {
|
762 | a = pSlice.call(a);
|
763 | b = pSlice.call(b);
|
764 | return _deepEqual(a, b, strict);
|
765 | }
|
766 | var ka = objectKeys(a);
|
767 | var kb = objectKeys(b);
|
768 | var key, i;
|
769 |
|
770 |
|
771 | if (ka.length !== kb.length)
|
772 | return false;
|
773 |
|
774 | ka.sort();
|
775 | kb.sort();
|
776 |
|
777 | for (i = ka.length - 1; i >= 0; i--) {
|
778 | if (ka[i] !== kb[i])
|
779 | return false;
|
780 | }
|
781 |
|
782 |
|
783 | for (i = ka.length - 1; i >= 0; i--) {
|
784 | key = ka[i];
|
785 | if (!_deepEqual(a[key], b[key], strict, actualVisitedObjects))
|
786 | return false;
|
787 | }
|
788 | return true;
|
789 | }
|
790 |
|
791 |
|
792 |
|
793 |
|
794 | assert.notDeepEqual = function notDeepEqual(actual, expected, message) {
|
795 | if (_deepEqual(actual, expected, false)) {
|
796 | fail(actual, expected, message, 'notDeepEqual', assert.notDeepEqual);
|
797 | }
|
798 | };
|
799 |
|
800 | assert.notDeepStrictEqual = notDeepStrictEqual;
|
801 | function notDeepStrictEqual(actual, expected, message) {
|
802 | if (_deepEqual(actual, expected, true)) {
|
803 | fail(actual, expected, message, 'notDeepStrictEqual', notDeepStrictEqual);
|
804 | }
|
805 | }
|
806 |
|
807 |
|
808 |
|
809 |
|
810 |
|
811 | assert.strictEqual = function strictEqual(actual, expected, message) {
|
812 | if (actual !== expected) {
|
813 | fail(actual, expected, message, '===', assert.strictEqual);
|
814 | }
|
815 | };
|
816 |
|
817 |
|
818 |
|
819 |
|
820 | assert.notStrictEqual = function notStrictEqual(actual, expected, message) {
|
821 | if (actual === expected) {
|
822 | fail(actual, expected, message, '!==', assert.notStrictEqual);
|
823 | }
|
824 | };
|
825 |
|
826 | function expectedException(actual, expected) {
|
827 | if (!actual || !expected) {
|
828 | return false;
|
829 | }
|
830 |
|
831 | if (Object.prototype.toString.call(expected) == '[object RegExp]') {
|
832 | return expected.test(actual);
|
833 | }
|
834 |
|
835 | try {
|
836 | if (actual instanceof expected) {
|
837 | return true;
|
838 | }
|
839 | } catch (e) {
|
840 |
|
841 | }
|
842 |
|
843 | if (Error.isPrototypeOf(expected)) {
|
844 | return false;
|
845 | }
|
846 |
|
847 | return expected.call({}, actual) === true;
|
848 | }
|
849 |
|
850 | function _tryBlock(block) {
|
851 | var error;
|
852 | try {
|
853 | block();
|
854 | } catch (e) {
|
855 | error = e;
|
856 | }
|
857 | return error;
|
858 | }
|
859 |
|
860 | function _throws(shouldThrow, block, expected, message) {
|
861 | var actual;
|
862 |
|
863 | if (typeof block !== 'function') {
|
864 | throw new TypeError('"block" argument must be a function');
|
865 | }
|
866 |
|
867 | if (typeof expected === 'string') {
|
868 | message = expected;
|
869 | expected = null;
|
870 | }
|
871 |
|
872 | actual = _tryBlock(block);
|
873 |
|
874 | message = (expected && expected.name ? ' (' + expected.name + ').' : '.') +
|
875 | (message ? ' ' + message : '.');
|
876 |
|
877 | if (shouldThrow && !actual) {
|
878 | fail(actual, expected, 'Missing expected exception' + message);
|
879 | }
|
880 |
|
881 | var userProvidedMessage = typeof message === 'string';
|
882 | var isUnwantedException = !shouldThrow && util.isError(actual);
|
883 | var isUnexpectedException = !shouldThrow && actual && !expected;
|
884 |
|
885 | if ((isUnwantedException &&
|
886 | userProvidedMessage &&
|
887 | expectedException(actual, expected)) ||
|
888 | isUnexpectedException) {
|
889 | fail(actual, expected, 'Got unwanted exception' + message);
|
890 | }
|
891 |
|
892 | if ((shouldThrow && actual && expected &&
|
893 | !expectedException(actual, expected)) || (!shouldThrow && actual)) {
|
894 | throw actual;
|
895 | }
|
896 | }
|
897 |
|
898 |
|
899 |
|
900 |
|
901 | assert.throws = function(block, /*optional*/error, /*optional*/message) {
|
902 | _throws(true, block, error, message);
|
903 | };
|
904 |
|
905 |
|
906 | assert.doesNotThrow = function(block, /*optional*/error, /*optional*/message) {
|
907 | _throws(false, block, error, message);
|
908 | };
|
909 |
|
910 | assert.ifError = function(err) { if (err) throw err; };
|
911 |
|
912 | var objectKeys = Object.keys || function (obj) {
|
913 | var keys = [];
|
914 | for (var key in obj) {
|
915 | if (hasOwn.call(obj, key)) keys.push(key);
|
916 | }
|
917 | return keys;
|
918 | };
|
919 |
|
920 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
921 | },{"8":8}],6:[function(_dereq_,module,exports){
|
922 | if (typeof Object.create === 'function') {
|
923 |
|
924 | module.exports = function inherits(ctor, superCtor) {
|
925 | ctor.super_ = superCtor
|
926 | ctor.prototype = Object.create(superCtor.prototype, {
|
927 | constructor: {
|
928 | value: ctor,
|
929 | enumerable: false,
|
930 | writable: true,
|
931 | configurable: true
|
932 | }
|
933 | });
|
934 | };
|
935 | } else {
|
936 |
|
937 | module.exports = function inherits(ctor, superCtor) {
|
938 | ctor.super_ = superCtor
|
939 | var TempCtor = function () {}
|
940 | TempCtor.prototype = superCtor.prototype
|
941 | ctor.prototype = new TempCtor()
|
942 | ctor.prototype.constructor = ctor
|
943 | }
|
944 | }
|
945 |
|
946 | },{}],7:[function(_dereq_,module,exports){
|
947 | module.exports = function isBuffer(arg) {
|
948 | return arg && typeof arg === 'object'
|
949 | && typeof arg.copy === 'function'
|
950 | && typeof arg.fill === 'function'
|
951 | && typeof arg.readUInt8 === 'function';
|
952 | }
|
953 | },{}],8:[function(_dereq_,module,exports){
|
954 | (function (process,global){
|
955 |
|
956 |
|
957 |
|
958 |
|
959 |
|
960 |
|
961 |
|
962 |
|
963 |
|
964 |
|
965 |
|
966 |
|
967 |
|
968 |
|
969 |
|
970 |
|
971 |
|
972 |
|
973 |
|
974 |
|
975 |
|
976 | var formatRegExp = /%[sdj%]/g;
|
977 | exports.format = function(f) {
|
978 | if (!isString(f)) {
|
979 | var objects = [];
|
980 | for (var i = 0; i < arguments.length; i++) {
|
981 | objects.push(inspect(arguments[i]));
|
982 | }
|
983 | return objects.join(' ');
|
984 | }
|
985 |
|
986 | var i = 1;
|
987 | var args = arguments;
|
988 | var len = args.length;
|
989 | var str = String(f).replace(formatRegExp, function(x) {
|
990 | if (x === '%%') return '%';
|
991 | if (i >= len) return x;
|
992 | switch (x) {
|
993 | case '%s': return String(args[i++]);
|
994 | case '%d': return Number(args[i++]);
|
995 | case '%j':
|
996 | try {
|
997 | return JSON.stringify(args[i++]);
|
998 | } catch (_) {
|
999 | return '[Circular]';
|
1000 | }
|
1001 | default:
|
1002 | return x;
|
1003 | }
|
1004 | });
|
1005 | for (var x = args[i]; i < len; x = args[++i]) {
|
1006 | if (isNull(x) || !isObject(x)) {
|
1007 | str += ' ' + x;
|
1008 | } else {
|
1009 | str += ' ' + inspect(x);
|
1010 | }
|
1011 | }
|
1012 | return str;
|
1013 | };
|
1014 |
|
1015 |
|
1016 |
|
1017 |
|
1018 |
|
1019 | exports.deprecate = function(fn, msg) {
|
1020 |
|
1021 | if (isUndefined(global.process)) {
|
1022 | return function() {
|
1023 | return exports.deprecate(fn, msg).apply(this, arguments);
|
1024 | };
|
1025 | }
|
1026 |
|
1027 | if (process.noDeprecation === true) {
|
1028 | return fn;
|
1029 | }
|
1030 |
|
1031 | var warned = false;
|
1032 | function deprecated() {
|
1033 | if (!warned) {
|
1034 | if (process.throwDeprecation) {
|
1035 | throw new Error(msg);
|
1036 | } else if (process.traceDeprecation) {
|
1037 | console.trace(msg);
|
1038 | } else {
|
1039 | console.error(msg);
|
1040 | }
|
1041 | warned = true;
|
1042 | }
|
1043 | return fn.apply(this, arguments);
|
1044 | }
|
1045 |
|
1046 | return deprecated;
|
1047 | };
|
1048 |
|
1049 |
|
1050 | var debugs = {};
|
1051 | var debugEnviron;
|
1052 | exports.debuglog = function(set) {
|
1053 | if (isUndefined(debugEnviron))
|
1054 | debugEnviron = process.env.NODE_DEBUG || '';
|
1055 | set = set.toUpperCase();
|
1056 | if (!debugs[set]) {
|
1057 | if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
|
1058 | var pid = process.pid;
|
1059 | debugs[set] = function() {
|
1060 | var msg = exports.format.apply(exports, arguments);
|
1061 | console.error('%s %d: %s', set, pid, msg);
|
1062 | };
|
1063 | } else {
|
1064 | debugs[set] = function() {};
|
1065 | }
|
1066 | }
|
1067 | return debugs[set];
|
1068 | };
|
1069 |
|
1070 |
|
1071 | /**
|
1072 | * Echos the value of a value. Trys to print the value out
|
1073 | * in the best way possible given the different types.
|
1074 | *
|
1075 | * @param {Object} obj The object to print out.
|
1076 | * @param {Object} opts Optional options object that alters the output.
|
1077 | */
|
1078 |
|
1079 | function inspect(obj, opts) {
|
1080 |
|
1081 | var ctx = {
|
1082 | seen: [],
|
1083 | stylize: stylizeNoColor
|
1084 | };
|
1085 |
|
1086 | if (arguments.length >= 3) ctx.depth = arguments[2];
|
1087 | if (arguments.length >= 4) ctx.colors = arguments[3];
|
1088 | if (isBoolean(opts)) {
|
1089 |
|
1090 | ctx.showHidden = opts;
|
1091 | } else if (opts) {
|
1092 |
|
1093 | exports._extend(ctx, opts);
|
1094 | }
|
1095 |
|
1096 | if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
|
1097 | if (isUndefined(ctx.depth)) ctx.depth = 2;
|
1098 | if (isUndefined(ctx.colors)) ctx.colors = false;
|
1099 | if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
|
1100 | if (ctx.colors) ctx.stylize = stylizeWithColor;
|
1101 | return formatValue(ctx, obj, ctx.depth);
|
1102 | }
|
1103 | exports.inspect = inspect;
|
1104 |
|
1105 |
|
1106 |
|
1107 | inspect.colors = {
|
1108 | 'bold' : [1, 22],
|
1109 | 'italic' : [3, 23],
|
1110 | 'underline' : [4, 24],
|
1111 | 'inverse' : [7, 27],
|
1112 | 'white' : [37, 39],
|
1113 | 'grey' : [90, 39],
|
1114 | 'black' : [30, 39],
|
1115 | 'blue' : [34, 39],
|
1116 | 'cyan' : [36, 39],
|
1117 | 'green' : [32, 39],
|
1118 | 'magenta' : [35, 39],
|
1119 | 'red' : [31, 39],
|
1120 | 'yellow' : [33, 39]
|
1121 | };
|
1122 |
|
1123 |
|
1124 | inspect.styles = {
|
1125 | 'special': 'cyan',
|
1126 | 'number': 'yellow',
|
1127 | 'boolean': 'yellow',
|
1128 | 'undefined': 'grey',
|
1129 | 'null': 'bold',
|
1130 | 'string': 'green',
|
1131 | 'date': 'magenta',
|
1132 |
|
1133 | 'regexp': 'red'
|
1134 | };
|
1135 |
|
1136 |
|
1137 | function stylizeWithColor(str, styleType) {
|
1138 | var style = inspect.styles[styleType];
|
1139 |
|
1140 | if (style) {
|
1141 | return '\u001b[' + inspect.colors[style][0] + 'm' + str +
|
1142 | '\u001b[' + inspect.colors[style][1] + 'm';
|
1143 | } else {
|
1144 | return str;
|
1145 | }
|
1146 | }
|
1147 |
|
1148 |
|
1149 | function stylizeNoColor(str, styleType) {
|
1150 | return str;
|
1151 | }
|
1152 |
|
1153 |
|
1154 | function arrayToHash(array) {
|
1155 | var hash = {};
|
1156 |
|
1157 | array.forEach(function(val, idx) {
|
1158 | hash[val] = true;
|
1159 | });
|
1160 |
|
1161 | return hash;
|
1162 | }
|
1163 |
|
1164 |
|
1165 | function formatValue(ctx, value, recurseTimes) {
|
1166 |
|
1167 |
|
1168 | if (ctx.customInspect &&
|
1169 | value &&
|
1170 | isFunction(value.inspect) &&
|
1171 |
|
1172 | value.inspect !== exports.inspect &&
|
1173 |
|
1174 | !(value.constructor && value.constructor.prototype === value)) {
|
1175 | var ret = value.inspect(recurseTimes, ctx);
|
1176 | if (!isString(ret)) {
|
1177 | ret = formatValue(ctx, ret, recurseTimes);
|
1178 | }
|
1179 | return ret;
|
1180 | }
|
1181 |
|
1182 |
|
1183 | var primitive = formatPrimitive(ctx, value);
|
1184 | if (primitive) {
|
1185 | return primitive;
|
1186 | }
|
1187 |
|
1188 |
|
1189 | var keys = Object.keys(value);
|
1190 | var visibleKeys = arrayToHash(keys);
|
1191 |
|
1192 | if (ctx.showHidden) {
|
1193 | keys = Object.getOwnPropertyNames(value);
|
1194 | }
|
1195 |
|
1196 |
|
1197 |
|
1198 | if (isError(value)
|
1199 | && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
|
1200 | return formatError(value);
|
1201 | }
|
1202 |
|
1203 |
|
1204 | if (keys.length === 0) {
|
1205 | if (isFunction(value)) {
|
1206 | var name = value.name ? ': ' + value.name : '';
|
1207 | return ctx.stylize('[Function' + name + ']', 'special');
|
1208 | }
|
1209 | if (isRegExp(value)) {
|
1210 | return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
|
1211 | }
|
1212 | if (isDate(value)) {
|
1213 | return ctx.stylize(Date.prototype.toString.call(value), 'date');
|
1214 | }
|
1215 | if (isError(value)) {
|
1216 | return formatError(value);
|
1217 | }
|
1218 | }
|
1219 |
|
1220 | var base = '', array = false, braces = ['{', '}'];
|
1221 |
|
1222 |
|
1223 | if (isArray(value)) {
|
1224 | array = true;
|
1225 | braces = ['[', ']'];
|
1226 | }
|
1227 |
|
1228 |
|
1229 | if (isFunction(value)) {
|
1230 | var n = value.name ? ': ' + value.name : '';
|
1231 | base = ' [Function' + n + ']';
|
1232 | }
|
1233 |
|
1234 |
|
1235 | if (isRegExp(value)) {
|
1236 | base = ' ' + RegExp.prototype.toString.call(value);
|
1237 | }
|
1238 |
|
1239 |
|
1240 | if (isDate(value)) {
|
1241 | base = ' ' + Date.prototype.toUTCString.call(value);
|
1242 | }
|
1243 |
|
1244 |
|
1245 | if (isError(value)) {
|
1246 | base = ' ' + formatError(value);
|
1247 | }
|
1248 |
|
1249 | if (keys.length === 0 && (!array || value.length == 0)) {
|
1250 | return braces[0] + base + braces[1];
|
1251 | }
|
1252 |
|
1253 | if (recurseTimes < 0) {
|
1254 | if (isRegExp(value)) {
|
1255 | return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
|
1256 | } else {
|
1257 | return ctx.stylize('[Object]', 'special');
|
1258 | }
|
1259 | }
|
1260 |
|
1261 | ctx.seen.push(value);
|
1262 |
|
1263 | var output;
|
1264 | if (array) {
|
1265 | output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
|
1266 | } else {
|
1267 | output = keys.map(function(key) {
|
1268 | return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
|
1269 | });
|
1270 | }
|
1271 |
|
1272 | ctx.seen.pop();
|
1273 |
|
1274 | return reduceToSingleString(output, base, braces);
|
1275 | }
|
1276 |
|
1277 |
|
1278 | function formatPrimitive(ctx, value) {
|
1279 | if (isUndefined(value))
|
1280 | return ctx.stylize('undefined', 'undefined');
|
1281 | if (isString(value)) {
|
1282 | var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
|
1283 | .replace(/'/g, "\\'")
|
1284 | .replace(/\\"/g, '"') + '\'';
|
1285 | return ctx.stylize(simple, 'string');
|
1286 | }
|
1287 | if (isNumber(value))
|
1288 | return ctx.stylize('' + value, 'number');
|
1289 | if (isBoolean(value))
|
1290 | return ctx.stylize('' + value, 'boolean');
|
1291 |
|
1292 | if (isNull(value))
|
1293 | return ctx.stylize('null', 'null');
|
1294 | }
|
1295 |
|
1296 |
|
1297 | function formatError(value) {
|
1298 | return '[' + Error.prototype.toString.call(value) + ']';
|
1299 | }
|
1300 |
|
1301 |
|
1302 | function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
|
1303 | var output = [];
|
1304 | for (var i = 0, l = value.length; i < l; ++i) {
|
1305 | if (hasOwnProperty(value, String(i))) {
|
1306 | output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
|
1307 | String(i), true));
|
1308 | } else {
|
1309 | output.push('');
|
1310 | }
|
1311 | }
|
1312 | keys.forEach(function(key) {
|
1313 | if (!key.match(/^\d+$/)) {
|
1314 | output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
|
1315 | key, true));
|
1316 | }
|
1317 | });
|
1318 | return output;
|
1319 | }
|
1320 |
|
1321 |
|
1322 | function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
|
1323 | var name, str, desc;
|
1324 | desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
|
1325 | if (desc.get) {
|
1326 | if (desc.set) {
|
1327 | str = ctx.stylize('[Getter/Setter]', 'special');
|
1328 | } else {
|
1329 | str = ctx.stylize('[Getter]', 'special');
|
1330 | }
|
1331 | } else {
|
1332 | if (desc.set) {
|
1333 | str = ctx.stylize('[Setter]', 'special');
|
1334 | }
|
1335 | }
|
1336 | if (!hasOwnProperty(visibleKeys, key)) {
|
1337 | name = '[' + key + ']';
|
1338 | }
|
1339 | if (!str) {
|
1340 | if (ctx.seen.indexOf(desc.value) < 0) {
|
1341 | if (isNull(recurseTimes)) {
|
1342 | str = formatValue(ctx, desc.value, null);
|
1343 | } else {
|
1344 | str = formatValue(ctx, desc.value, recurseTimes - 1);
|
1345 | }
|
1346 | if (str.indexOf('\n') > -1) {
|
1347 | if (array) {
|
1348 | str = str.split('\n').map(function(line) {
|
1349 | return ' ' + line;
|
1350 | }).join('\n').substr(2);
|
1351 | } else {
|
1352 | str = '\n' + str.split('\n').map(function(line) {
|
1353 | return ' ' + line;
|
1354 | }).join('\n');
|
1355 | }
|
1356 | }
|
1357 | } else {
|
1358 | str = ctx.stylize('[Circular]', 'special');
|
1359 | }
|
1360 | }
|
1361 | if (isUndefined(name)) {
|
1362 | if (array && key.match(/^\d+$/)) {
|
1363 | return str;
|
1364 | }
|
1365 | name = JSON.stringify('' + key);
|
1366 | if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
|
1367 | name = name.substr(1, name.length - 2);
|
1368 | name = ctx.stylize(name, 'name');
|
1369 | } else {
|
1370 | name = name.replace(/'/g, "\\'")
|
1371 | .replace(/\\"/g, '"')
|
1372 | .replace(/(^"|"$)/g, "'");
|
1373 | name = ctx.stylize(name, 'string');
|
1374 | }
|
1375 | }
|
1376 |
|
1377 | return name + ': ' + str;
|
1378 | }
|
1379 |
|
1380 |
|
1381 | function reduceToSingleString(output, base, braces) {
|
1382 | var numLinesEst = 0;
|
1383 | var length = output.reduce(function(prev, cur) {
|
1384 | numLinesEst++;
|
1385 | if (cur.indexOf('\n') >= 0) numLinesEst++;
|
1386 | return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
|
1387 | }, 0);
|
1388 |
|
1389 | if (length > 60) {
|
1390 | return braces[0] +
|
1391 | (base === '' ? '' : base + '\n ') +
|
1392 | ' ' +
|
1393 | output.join(',\n ') +
|
1394 | ' ' +
|
1395 | braces[1];
|
1396 | }
|
1397 |
|
1398 | return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
|
1399 | }
|
1400 |
|
1401 |
|
1402 |
|
1403 |
|
1404 | function isArray(ar) {
|
1405 | return Array.isArray(ar);
|
1406 | }
|
1407 | exports.isArray = isArray;
|
1408 |
|
1409 | function isBoolean(arg) {
|
1410 | return typeof arg === 'boolean';
|
1411 | }
|
1412 | exports.isBoolean = isBoolean;
|
1413 |
|
1414 | function isNull(arg) {
|
1415 | return arg === null;
|
1416 | }
|
1417 | exports.isNull = isNull;
|
1418 |
|
1419 | function isNullOrUndefined(arg) {
|
1420 | return arg == null;
|
1421 | }
|
1422 | exports.isNullOrUndefined = isNullOrUndefined;
|
1423 |
|
1424 | function isNumber(arg) {
|
1425 | return typeof arg === 'number';
|
1426 | }
|
1427 | exports.isNumber = isNumber;
|
1428 |
|
1429 | function isString(arg) {
|
1430 | return typeof arg === 'string';
|
1431 | }
|
1432 | exports.isString = isString;
|
1433 |
|
1434 | function isSymbol(arg) {
|
1435 | return typeof arg === 'symbol';
|
1436 | }
|
1437 | exports.isSymbol = isSymbol;
|
1438 |
|
1439 | function isUndefined(arg) {
|
1440 | return arg === void 0;
|
1441 | }
|
1442 | exports.isUndefined = isUndefined;
|
1443 |
|
1444 | function isRegExp(re) {
|
1445 | return isObject(re) && objectToString(re) === '[object RegExp]';
|
1446 | }
|
1447 | exports.isRegExp = isRegExp;
|
1448 |
|
1449 | function isObject(arg) {
|
1450 | return typeof arg === 'object' && arg !== null;
|
1451 | }
|
1452 | exports.isObject = isObject;
|
1453 |
|
1454 | function isDate(d) {
|
1455 | return isObject(d) && objectToString(d) === '[object Date]';
|
1456 | }
|
1457 | exports.isDate = isDate;
|
1458 |
|
1459 | function isError(e) {
|
1460 | return isObject(e) &&
|
1461 | (objectToString(e) === '[object Error]' || e instanceof Error);
|
1462 | }
|
1463 | exports.isError = isError;
|
1464 |
|
1465 | function isFunction(arg) {
|
1466 | return typeof arg === 'function';
|
1467 | }
|
1468 | exports.isFunction = isFunction;
|
1469 |
|
1470 | function isPrimitive(arg) {
|
1471 | return arg === null ||
|
1472 | typeof arg === 'boolean' ||
|
1473 | typeof arg === 'number' ||
|
1474 | typeof arg === 'string' ||
|
1475 | typeof arg === 'symbol' ||
|
1476 | typeof arg === 'undefined';
|
1477 | }
|
1478 | exports.isPrimitive = isPrimitive;
|
1479 |
|
1480 | exports.isBuffer = _dereq_(7);
|
1481 |
|
1482 | function objectToString(o) {
|
1483 | return Object.prototype.toString.call(o);
|
1484 | }
|
1485 |
|
1486 |
|
1487 | function pad(n) {
|
1488 | return n < 10 ? '0' + n.toString(10) : n.toString(10);
|
1489 | }
|
1490 |
|
1491 |
|
1492 | var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
|
1493 | 'Oct', 'Nov', 'Dec'];
|
1494 |
|
1495 |
|
1496 | function timestamp() {
|
1497 | var d = new Date();
|
1498 | var time = [pad(d.getHours()),
|
1499 | pad(d.getMinutes()),
|
1500 | pad(d.getSeconds())].join(':');
|
1501 | return [d.getDate(), months[d.getMonth()], time].join(' ');
|
1502 | }
|
1503 |
|
1504 |
|
1505 |
|
1506 | exports.log = function() {
|
1507 | console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments));
|
1508 | };
|
1509 |
|
1510 |
|
1511 |
|
1512 |
|
1513 |
|
1514 |
|
1515 |
|
1516 |
|
1517 |
|
1518 |
|
1519 |
|
1520 |
|
1521 |
|
1522 |
|
1523 |
|
1524 | exports.inherits = _dereq_(6);
|
1525 |
|
1526 | exports._extend = function(origin, add) {
|
1527 |
|
1528 | if (!add || !isObject(add)) return origin;
|
1529 |
|
1530 | var keys = Object.keys(add);
|
1531 | var i = keys.length;
|
1532 | while (i--) {
|
1533 | origin[keys[i]] = add[keys[i]];
|
1534 | }
|
1535 | return origin;
|
1536 | };
|
1537 |
|
1538 | function hasOwnProperty(obj, prop) {
|
1539 | return Object.prototype.hasOwnProperty.call(obj, prop);
|
1540 | }
|
1541 |
|
1542 | }).call(this,_dereq_(55),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
1543 | },{"55":55,"6":6,"7":7}],9:[function(_dereq_,module,exports){
|
1544 | 'use strict'
|
1545 |
|
1546 | exports.byteLength = byteLength
|
1547 | exports.toByteArray = toByteArray
|
1548 | exports.fromByteArray = fromByteArray
|
1549 |
|
1550 | var lookup = []
|
1551 | var revLookup = []
|
1552 | var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array
|
1553 |
|
1554 | var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
|
1555 | for (var i = 0, len = code.length; i < len; ++i) {
|
1556 | lookup[i] = code[i]
|
1557 | revLookup[code.charCodeAt(i)] = i
|
1558 | }
|
1559 |
|
1560 |
|
1561 |
|
1562 | revLookup['-'.charCodeAt(0)] = 62
|
1563 | revLookup['_'.charCodeAt(0)] = 63
|
1564 |
|
1565 | function getLens (b64) {
|
1566 | var len = b64.length
|
1567 |
|
1568 | if (len % 4 > 0) {
|
1569 | throw new Error('Invalid string. Length must be a multiple of 4')
|
1570 | }
|
1571 |
|
1572 |
|
1573 |
|
1574 | var validLen = b64.indexOf('=')
|
1575 | if (validLen === -1) validLen = len
|
1576 |
|
1577 | var placeHoldersLen = validLen === len
|
1578 | ? 0
|
1579 | : 4 - (validLen % 4)
|
1580 |
|
1581 | return [validLen, placeHoldersLen]
|
1582 | }
|
1583 |
|
1584 |
|
1585 | function byteLength (b64) {
|
1586 | var lens = getLens(b64)
|
1587 | var validLen = lens[0]
|
1588 | var placeHoldersLen = lens[1]
|
1589 | return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
|
1590 | }
|
1591 |
|
1592 | function _byteLength (b64, validLen, placeHoldersLen) {
|
1593 | return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
|
1594 | }
|
1595 |
|
1596 | function toByteArray (b64) {
|
1597 | var tmp
|
1598 | var lens = getLens(b64)
|
1599 | var validLen = lens[0]
|
1600 | var placeHoldersLen = lens[1]
|
1601 |
|
1602 | var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen))
|
1603 |
|
1604 | var curByte = 0
|
1605 |
|
1606 |
|
1607 | var len = placeHoldersLen > 0
|
1608 | ? validLen - 4
|
1609 | : validLen
|
1610 |
|
1611 | for (var i = 0; i < len; i += 4) {
|
1612 | tmp =
|
1613 | (revLookup[b64.charCodeAt(i)] << 18) |
|
1614 | (revLookup[b64.charCodeAt(i + 1)] << 12) |
|
1615 | (revLookup[b64.charCodeAt(i + 2)] << 6) |
|
1616 | revLookup[b64.charCodeAt(i + 3)]
|
1617 | arr[curByte++] = (tmp >> 16) & 0xFF
|
1618 | arr[curByte++] = (tmp >> 8) & 0xFF
|
1619 | arr[curByte++] = tmp & 0xFF
|
1620 | }
|
1621 |
|
1622 | if (placeHoldersLen === 2) {
|
1623 | tmp =
|
1624 | (revLookup[b64.charCodeAt(i)] << 2) |
|
1625 | (revLookup[b64.charCodeAt(i + 1)] >> 4)
|
1626 | arr[curByte++] = tmp & 0xFF
|
1627 | }
|
1628 |
|
1629 | if (placeHoldersLen === 1) {
|
1630 | tmp =
|
1631 | (revLookup[b64.charCodeAt(i)] << 10) |
|
1632 | (revLookup[b64.charCodeAt(i + 1)] << 4) |
|
1633 | (revLookup[b64.charCodeAt(i + 2)] >> 2)
|
1634 | arr[curByte++] = (tmp >> 8) & 0xFF
|
1635 | arr[curByte++] = tmp & 0xFF
|
1636 | }
|
1637 |
|
1638 | return arr
|
1639 | }
|
1640 |
|
1641 | function tripletToBase64 (num) {
|
1642 | return lookup[num >> 18 & 0x3F] +
|
1643 | lookup[num >> 12 & 0x3F] +
|
1644 | lookup[num >> 6 & 0x3F] +
|
1645 | lookup[num & 0x3F]
|
1646 | }
|
1647 |
|
1648 | function encodeChunk (uint8, start, end) {
|
1649 | var tmp
|
1650 | var output = []
|
1651 | for (var i = start; i < end; i += 3) {
|
1652 | tmp =
|
1653 | ((uint8[i] << 16) & 0xFF0000) +
|
1654 | ((uint8[i + 1] << 8) & 0xFF00) +
|
1655 | (uint8[i + 2] & 0xFF)
|
1656 | output.push(tripletToBase64(tmp))
|
1657 | }
|
1658 | return output.join('')
|
1659 | }
|
1660 |
|
1661 | function fromByteArray (uint8) {
|
1662 | var tmp
|
1663 | var len = uint8.length
|
1664 | var extraBytes = len % 3
|
1665 | var parts = []
|
1666 | var maxChunkLength = 16383
|
1667 |
|
1668 |
|
1669 | for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
|
1670 | parts.push(encodeChunk(
|
1671 | uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)
|
1672 | ))
|
1673 | }
|
1674 |
|
1675 |
|
1676 | if (extraBytes === 1) {
|
1677 | tmp = uint8[len - 1]
|
1678 | parts.push(
|
1679 | lookup[tmp >> 2] +
|
1680 | lookup[(tmp << 4) & 0x3F] +
|
1681 | '=='
|
1682 | )
|
1683 | } else if (extraBytes === 2) {
|
1684 | tmp = (uint8[len - 2] << 8) + uint8[len - 1]
|
1685 | parts.push(
|
1686 | lookup[tmp >> 10] +
|
1687 | lookup[(tmp >> 4) & 0x3F] +
|
1688 | lookup[(tmp << 2) & 0x3F] +
|
1689 | '='
|
1690 | )
|
1691 | }
|
1692 |
|
1693 | return parts.join('')
|
1694 | }
|
1695 |
|
1696 | },{}],10:[function(_dereq_,module,exports){
|
1697 |
|
1698 | },{}],11:[function(_dereq_,module,exports){
|
1699 | (function (Buffer){
|
1700 | var toString = Object.prototype.toString
|
1701 |
|
1702 | var isModern = (
|
1703 | typeof Buffer.alloc === 'function' &&
|
1704 | typeof Buffer.allocUnsafe === 'function' &&
|
1705 | typeof Buffer.from === 'function'
|
1706 | )
|
1707 |
|
1708 | function isArrayBuffer (input) {
|
1709 | return toString.call(input).slice(8, -1) === 'ArrayBuffer'
|
1710 | }
|
1711 |
|
1712 | function fromArrayBuffer (obj, byteOffset, length) {
|
1713 | byteOffset >>>= 0
|
1714 |
|
1715 | var maxLength = obj.byteLength - byteOffset
|
1716 |
|
1717 | if (maxLength < 0) {
|
1718 | throw new RangeError("'offset' is out of bounds")
|
1719 | }
|
1720 |
|
1721 | if (length === undefined) {
|
1722 | length = maxLength
|
1723 | } else {
|
1724 | length >>>= 0
|
1725 |
|
1726 | if (length > maxLength) {
|
1727 | throw new RangeError("'length' is out of bounds")
|
1728 | }
|
1729 | }
|
1730 |
|
1731 | return isModern
|
1732 | ? Buffer.from(obj.slice(byteOffset, byteOffset + length))
|
1733 | : new Buffer(new Uint8Array(obj.slice(byteOffset, byteOffset + length)))
|
1734 | }
|
1735 |
|
1736 | function fromString (string, encoding) {
|
1737 | if (typeof encoding !== 'string' || encoding === '') {
|
1738 | encoding = 'utf8'
|
1739 | }
|
1740 |
|
1741 | if (!Buffer.isEncoding(encoding)) {
|
1742 | throw new TypeError('"encoding" must be a valid string encoding')
|
1743 | }
|
1744 |
|
1745 | return isModern
|
1746 | ? Buffer.from(string, encoding)
|
1747 | : new Buffer(string, encoding)
|
1748 | }
|
1749 |
|
1750 | function bufferFrom (value, encodingOrOffset, length) {
|
1751 | if (typeof value === 'number') {
|
1752 | throw new TypeError('"value" argument must not be a number')
|
1753 | }
|
1754 |
|
1755 | if (isArrayBuffer(value)) {
|
1756 | return fromArrayBuffer(value, encodingOrOffset, length)
|
1757 | }
|
1758 |
|
1759 | if (typeof value === 'string') {
|
1760 | return fromString(value, encodingOrOffset)
|
1761 | }
|
1762 |
|
1763 | return isModern
|
1764 | ? Buffer.from(value)
|
1765 | : new Buffer(value)
|
1766 | }
|
1767 |
|
1768 | module.exports = bufferFrom
|
1769 |
|
1770 | }).call(this,_dereq_(12).Buffer)
|
1771 | },{"12":12}],12:[function(_dereq_,module,exports){
|
1772 |
|
1773 |
|
1774 |
|
1775 |
|
1776 |
|
1777 |
|
1778 |
|
1779 |
|
1780 | 'use strict'
|
1781 |
|
1782 | var base64 = _dereq_(9)
|
1783 | var ieee754 = _dereq_(24)
|
1784 |
|
1785 | exports.Buffer = Buffer
|
1786 | exports.SlowBuffer = SlowBuffer
|
1787 | exports.INSPECT_MAX_BYTES = 50
|
1788 |
|
1789 | var K_MAX_LENGTH = 0x7fffffff
|
1790 | exports.kMaxLength = K_MAX_LENGTH
|
1791 |
|
1792 |
|
1793 |
|
1794 |
|
1795 |
|
1796 |
|
1797 |
|
1798 |
|
1799 |
|
1800 |
|
1801 |
|
1802 |
|
1803 |
|
1804 |
|
1805 |
|
1806 | Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport()
|
1807 |
|
1808 | if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' &&
|
1809 | typeof console.error === 'function') {
|
1810 | console.error(
|
1811 | 'This browser lacks typed array (Uint8Array) support which is required by ' +
|
1812 | '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.'
|
1813 | )
|
1814 | }
|
1815 |
|
1816 | function typedArraySupport () {
|
1817 |
|
1818 | try {
|
1819 | var arr = new Uint8Array(1)
|
1820 | arr.__proto__ = {__proto__: Uint8Array.prototype, foo: function () { return 42 }}
|
1821 | return arr.foo() === 42
|
1822 | } catch (e) {
|
1823 | return false
|
1824 | }
|
1825 | }
|
1826 |
|
1827 | Object.defineProperty(Buffer.prototype, 'parent', {
|
1828 | get: function () {
|
1829 | if (!(this instanceof Buffer)) {
|
1830 | return undefined
|
1831 | }
|
1832 | return this.buffer
|
1833 | }
|
1834 | })
|
1835 |
|
1836 | Object.defineProperty(Buffer.prototype, 'offset', {
|
1837 | get: function () {
|
1838 | if (!(this instanceof Buffer)) {
|
1839 | return undefined
|
1840 | }
|
1841 | return this.byteOffset
|
1842 | }
|
1843 | })
|
1844 |
|
1845 | function createBuffer (length) {
|
1846 | if (length > K_MAX_LENGTH) {
|
1847 | throw new RangeError('Invalid typed array length')
|
1848 | }
|
1849 |
|
1850 | var buf = new Uint8Array(length)
|
1851 | buf.__proto__ = Buffer.prototype
|
1852 | return buf
|
1853 | }
|
1854 |
|
1855 |
|
1856 |
|
1857 |
|
1858 |
|
1859 |
|
1860 |
|
1861 |
|
1862 |
|
1863 |
|
1864 |
|
1865 | function Buffer (arg, encodingOrOffset, length) {
|
1866 |
|
1867 | if (typeof arg === 'number') {
|
1868 | if (typeof encodingOrOffset === 'string') {
|
1869 | throw new Error(
|
1870 | 'If encoding is specified then the first argument must be a string'
|
1871 | )
|
1872 | }
|
1873 | return allocUnsafe(arg)
|
1874 | }
|
1875 | return from(arg, encodingOrOffset, length)
|
1876 | }
|
1877 |
|
1878 |
|
1879 | if (typeof Symbol !== 'undefined' && Symbol.species &&
|
1880 | Buffer[Symbol.species] === Buffer) {
|
1881 | Object.defineProperty(Buffer, Symbol.species, {
|
1882 | value: null,
|
1883 | configurable: true,
|
1884 | enumerable: false,
|
1885 | writable: false
|
1886 | })
|
1887 | }
|
1888 |
|
1889 | Buffer.poolSize = 8192
|
1890 |
|
1891 | function from (value, encodingOrOffset, length) {
|
1892 | if (typeof value === 'number') {
|
1893 | throw new TypeError('"value" argument must not be a number')
|
1894 | }
|
1895 |
|
1896 | if (isArrayBuffer(value) || (value && isArrayBuffer(value.buffer))) {
|
1897 | return fromArrayBuffer(value, encodingOrOffset, length)
|
1898 | }
|
1899 |
|
1900 | if (typeof value === 'string') {
|
1901 | return fromString(value, encodingOrOffset)
|
1902 | }
|
1903 |
|
1904 | return fromObject(value)
|
1905 | }
|
1906 |
|
1907 |
|
1908 |
|
1909 |
|
1910 |
|
1911 |
|
1912 |
|
1913 |
|
1914 |
|
1915 | Buffer.from = function (value, encodingOrOffset, length) {
|
1916 | return from(value, encodingOrOffset, length)
|
1917 | }
|
1918 |
|
1919 |
|
1920 |
|
1921 | Buffer.prototype.__proto__ = Uint8Array.prototype
|
1922 | Buffer.__proto__ = Uint8Array
|
1923 |
|
1924 | function assertSize (size) {
|
1925 | if (typeof size !== 'number') {
|
1926 | throw new TypeError('"size" argument must be of type number')
|
1927 | } else if (size < 0) {
|
1928 | throw new RangeError('"size" argument must not be negative')
|
1929 | }
|
1930 | }
|
1931 |
|
1932 | function alloc (size, fill, encoding) {
|
1933 | assertSize(size)
|
1934 | if (size <= 0) {
|
1935 | return createBuffer(size)
|
1936 | }
|
1937 | if (fill !== undefined) {
|
1938 |
|
1939 |
|
1940 |
|
1941 | return typeof encoding === 'string'
|
1942 | ? createBuffer(size).fill(fill, encoding)
|
1943 | : createBuffer(size).fill(fill)
|
1944 | }
|
1945 | return createBuffer(size)
|
1946 | }
|
1947 |
|
1948 |
|
1949 |
|
1950 |
|
1951 |
|
1952 | Buffer.alloc = function (size, fill, encoding) {
|
1953 | return alloc(size, fill, encoding)
|
1954 | }
|
1955 |
|
1956 | function allocUnsafe (size) {
|
1957 | assertSize(size)
|
1958 | return createBuffer(size < 0 ? 0 : checked(size) | 0)
|
1959 | }
|
1960 |
|
1961 |
|
1962 |
|
1963 |
|
1964 | Buffer.allocUnsafe = function (size) {
|
1965 | return allocUnsafe(size)
|
1966 | }
|
1967 |
|
1968 |
|
1969 |
|
1970 | Buffer.allocUnsafeSlow = function (size) {
|
1971 | return allocUnsafe(size)
|
1972 | }
|
1973 |
|
1974 | function fromString (string, encoding) {
|
1975 | if (typeof encoding !== 'string' || encoding === '') {
|
1976 | encoding = 'utf8'
|
1977 | }
|
1978 |
|
1979 | if (!Buffer.isEncoding(encoding)) {
|
1980 | throw new TypeError('Unknown encoding: ' + encoding)
|
1981 | }
|
1982 |
|
1983 | var length = byteLength(string, encoding) | 0
|
1984 | var buf = createBuffer(length)
|
1985 |
|
1986 | var actual = buf.write(string, encoding)
|
1987 |
|
1988 | if (actual !== length) {
|
1989 |
|
1990 |
|
1991 |
|
1992 | buf = buf.slice(0, actual)
|
1993 | }
|
1994 |
|
1995 | return buf
|
1996 | }
|
1997 |
|
1998 | function fromArrayLike (array) {
|
1999 | var length = array.length < 0 ? 0 : checked(array.length) | 0
|
2000 | var buf = createBuffer(length)
|
2001 | for (var i = 0; i < length; i += 1) {
|
2002 | buf[i] = array[i] & 255
|
2003 | }
|
2004 | return buf
|
2005 | }
|
2006 |
|
2007 | function fromArrayBuffer (array, byteOffset, length) {
|
2008 | if (byteOffset < 0 || array.byteLength < byteOffset) {
|
2009 | throw new RangeError('"offset" is outside of buffer bounds')
|
2010 | }
|
2011 |
|
2012 | if (array.byteLength < byteOffset + (length || 0)) {
|
2013 | throw new RangeError('"length" is outside of buffer bounds')
|
2014 | }
|
2015 |
|
2016 | var buf
|
2017 | if (byteOffset === undefined && length === undefined) {
|
2018 | buf = new Uint8Array(array)
|
2019 | } else if (length === undefined) {
|
2020 | buf = new Uint8Array(array, byteOffset)
|
2021 | } else {
|
2022 | buf = new Uint8Array(array, byteOffset, length)
|
2023 | }
|
2024 |
|
2025 |
|
2026 | buf.__proto__ = Buffer.prototype
|
2027 | return buf
|
2028 | }
|
2029 |
|
2030 | function fromObject (obj) {
|
2031 | if (Buffer.isBuffer(obj)) {
|
2032 | var len = checked(obj.length) | 0
|
2033 | var buf = createBuffer(len)
|
2034 |
|
2035 | if (buf.length === 0) {
|
2036 | return buf
|
2037 | }
|
2038 |
|
2039 | obj.copy(buf, 0, 0, len)
|
2040 | return buf
|
2041 | }
|
2042 |
|
2043 | if (obj) {
|
2044 | if (ArrayBuffer.isView(obj) || 'length' in obj) {
|
2045 | if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
|
2046 | return createBuffer(0)
|
2047 | }
|
2048 | return fromArrayLike(obj)
|
2049 | }
|
2050 |
|
2051 | if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
|
2052 | return fromArrayLike(obj.data)
|
2053 | }
|
2054 | }
|
2055 |
|
2056 | throw new TypeError('The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object.')
|
2057 | }
|
2058 |
|
2059 | function checked (length) {
|
2060 |
|
2061 |
|
2062 | if (length >= K_MAX_LENGTH) {
|
2063 | throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
|
2064 | 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes')
|
2065 | }
|
2066 | return length | 0
|
2067 | }
|
2068 |
|
2069 | function SlowBuffer (length) {
|
2070 | if (+length != length) {
|
2071 | length = 0
|
2072 | }
|
2073 | return Buffer.alloc(+length)
|
2074 | }
|
2075 |
|
2076 | Buffer.isBuffer = function isBuffer (b) {
|
2077 | return b != null && b._isBuffer === true
|
2078 | }
|
2079 |
|
2080 | Buffer.compare = function compare (a, b) {
|
2081 | if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
|
2082 | throw new TypeError('Arguments must be Buffers')
|
2083 | }
|
2084 |
|
2085 | if (a === b) return 0
|
2086 |
|
2087 | var x = a.length
|
2088 | var y = b.length
|
2089 |
|
2090 | for (var i = 0, len = Math.min(x, y); i < len; ++i) {
|
2091 | if (a[i] !== b[i]) {
|
2092 | x = a[i]
|
2093 | y = b[i]
|
2094 | break
|
2095 | }
|
2096 | }
|
2097 |
|
2098 | if (x < y) return -1
|
2099 | if (y < x) return 1
|
2100 | return 0
|
2101 | }
|
2102 |
|
2103 | Buffer.isEncoding = function isEncoding (encoding) {
|
2104 | switch (String(encoding).toLowerCase()) {
|
2105 | case 'hex':
|
2106 | case 'utf8':
|
2107 | case 'utf-8':
|
2108 | case 'ascii':
|
2109 | case 'latin1':
|
2110 | case 'binary':
|
2111 | case 'base64':
|
2112 | case 'ucs2':
|
2113 | case 'ucs-2':
|
2114 | case 'utf16le':
|
2115 | case 'utf-16le':
|
2116 | return true
|
2117 | default:
|
2118 | return false
|
2119 | }
|
2120 | }
|
2121 |
|
2122 | Buffer.concat = function concat (list, length) {
|
2123 | if (!Array.isArray(list)) {
|
2124 | throw new TypeError('"list" argument must be an Array of Buffers')
|
2125 | }
|
2126 |
|
2127 | if (list.length === 0) {
|
2128 | return Buffer.alloc(0)
|
2129 | }
|
2130 |
|
2131 | var i
|
2132 | if (length === undefined) {
|
2133 | length = 0
|
2134 | for (i = 0; i < list.length; ++i) {
|
2135 | length += list[i].length
|
2136 | }
|
2137 | }
|
2138 |
|
2139 | var buffer = Buffer.allocUnsafe(length)
|
2140 | var pos = 0
|
2141 | for (i = 0; i < list.length; ++i) {
|
2142 | var buf = list[i]
|
2143 | if (ArrayBuffer.isView(buf)) {
|
2144 | buf = Buffer.from(buf)
|
2145 | }
|
2146 | if (!Buffer.isBuffer(buf)) {
|
2147 | throw new TypeError('"list" argument must be an Array of Buffers')
|
2148 | }
|
2149 | buf.copy(buffer, pos)
|
2150 | pos += buf.length
|
2151 | }
|
2152 | return buffer
|
2153 | }
|
2154 |
|
2155 | function byteLength (string, encoding) {
|
2156 | if (Buffer.isBuffer(string)) {
|
2157 | return string.length
|
2158 | }
|
2159 | if (ArrayBuffer.isView(string) || isArrayBuffer(string)) {
|
2160 | return string.byteLength
|
2161 | }
|
2162 | if (typeof string !== 'string') {
|
2163 | string = '' + string
|
2164 | }
|
2165 |
|
2166 | var len = string.length
|
2167 | if (len === 0) return 0
|
2168 |
|
2169 |
|
2170 | var loweredCase = false
|
2171 | for (;;) {
|
2172 | switch (encoding) {
|
2173 | case 'ascii':
|
2174 | case 'latin1':
|
2175 | case 'binary':
|
2176 | return len
|
2177 | case 'utf8':
|
2178 | case 'utf-8':
|
2179 | case undefined:
|
2180 | return utf8ToBytes(string).length
|
2181 | case 'ucs2':
|
2182 | case 'ucs-2':
|
2183 | case 'utf16le':
|
2184 | case 'utf-16le':
|
2185 | return len * 2
|
2186 | case 'hex':
|
2187 | return len >>> 1
|
2188 | case 'base64':
|
2189 | return base64ToBytes(string).length
|
2190 | default:
|
2191 | if (loweredCase) return utf8ToBytes(string).length
|
2192 | encoding = ('' + encoding).toLowerCase()
|
2193 | loweredCase = true
|
2194 | }
|
2195 | }
|
2196 | }
|
2197 | Buffer.byteLength = byteLength
|
2198 |
|
2199 | function slowToString (encoding, start, end) {
|
2200 | var loweredCase = false
|
2201 |
|
2202 |
|
2203 |
|
2204 |
|
2205 |
|
2206 |
|
2207 |
|
2208 |
|
2209 | if (start === undefined || start < 0) {
|
2210 | start = 0
|
2211 | }
|
2212 |
|
2213 |
|
2214 | if (start > this.length) {
|
2215 | return ''
|
2216 | }
|
2217 |
|
2218 | if (end === undefined || end > this.length) {
|
2219 | end = this.length
|
2220 | }
|
2221 |
|
2222 | if (end <= 0) {
|
2223 | return ''
|
2224 | }
|
2225 |
|
2226 |
|
2227 | end >>>= 0
|
2228 | start >>>= 0
|
2229 |
|
2230 | if (end <= start) {
|
2231 | return ''
|
2232 | }
|
2233 |
|
2234 | if (!encoding) encoding = 'utf8'
|
2235 |
|
2236 | while (true) {
|
2237 | switch (encoding) {
|
2238 | case 'hex':
|
2239 | return hexSlice(this, start, end)
|
2240 |
|
2241 | case 'utf8':
|
2242 | case 'utf-8':
|
2243 | return utf8Slice(this, start, end)
|
2244 |
|
2245 | case 'ascii':
|
2246 | return asciiSlice(this, start, end)
|
2247 |
|
2248 | case 'latin1':
|
2249 | case 'binary':
|
2250 | return latin1Slice(this, start, end)
|
2251 |
|
2252 | case 'base64':
|
2253 | return base64Slice(this, start, end)
|
2254 |
|
2255 | case 'ucs2':
|
2256 | case 'ucs-2':
|
2257 | case 'utf16le':
|
2258 | case 'utf-16le':
|
2259 | return utf16leSlice(this, start, end)
|
2260 |
|
2261 | default:
|
2262 | if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
|
2263 | encoding = (encoding + '').toLowerCase()
|
2264 | loweredCase = true
|
2265 | }
|
2266 | }
|
2267 | }
|
2268 |
|
2269 |
|
2270 |
|
2271 |
|
2272 |
|
2273 |
|
2274 |
|
2275 | Buffer.prototype._isBuffer = true
|
2276 |
|
2277 | function swap (b, n, m) {
|
2278 | var i = b[n]
|
2279 | b[n] = b[m]
|
2280 | b[m] = i
|
2281 | }
|
2282 |
|
2283 | Buffer.prototype.swap16 = function swap16 () {
|
2284 | var len = this.length
|
2285 | if (len % 2 !== 0) {
|
2286 | throw new RangeError('Buffer size must be a multiple of 16-bits')
|
2287 | }
|
2288 | for (var i = 0; i < len; i += 2) {
|
2289 | swap(this, i, i + 1)
|
2290 | }
|
2291 | return this
|
2292 | }
|
2293 |
|
2294 | Buffer.prototype.swap32 = function swap32 () {
|
2295 | var len = this.length
|
2296 | if (len % 4 !== 0) {
|
2297 | throw new RangeError('Buffer size must be a multiple of 32-bits')
|
2298 | }
|
2299 | for (var i = 0; i < len; i += 4) {
|
2300 | swap(this, i, i + 3)
|
2301 | swap(this, i + 1, i + 2)
|
2302 | }
|
2303 | return this
|
2304 | }
|
2305 |
|
2306 | Buffer.prototype.swap64 = function swap64 () {
|
2307 | var len = this.length
|
2308 | if (len % 8 !== 0) {
|
2309 | throw new RangeError('Buffer size must be a multiple of 64-bits')
|
2310 | }
|
2311 | for (var i = 0; i < len; i += 8) {
|
2312 | swap(this, i, i + 7)
|
2313 | swap(this, i + 1, i + 6)
|
2314 | swap(this, i + 2, i + 5)
|
2315 | swap(this, i + 3, i + 4)
|
2316 | }
|
2317 | return this
|
2318 | }
|
2319 |
|
2320 | Buffer.prototype.toString = function toString () {
|
2321 | var length = this.length
|
2322 | if (length === 0) return ''
|
2323 | if (arguments.length === 0) return utf8Slice(this, 0, length)
|
2324 | return slowToString.apply(this, arguments)
|
2325 | }
|
2326 |
|
2327 | Buffer.prototype.toLocaleString = Buffer.prototype.toString
|
2328 |
|
2329 | Buffer.prototype.equals = function equals (b) {
|
2330 | if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
|
2331 | if (this === b) return true
|
2332 | return Buffer.compare(this, b) === 0
|
2333 | }
|
2334 |
|
2335 | Buffer.prototype.inspect = function inspect () {
|
2336 | var str = ''
|
2337 | var max = exports.INSPECT_MAX_BYTES
|
2338 | if (this.length > 0) {
|
2339 | str = this.toString('hex', 0, max).match(/.{2}/g).join(' ')
|
2340 | if (this.length > max) str += ' ... '
|
2341 | }
|
2342 | return '<Buffer ' + str + '>'
|
2343 | }
|
2344 |
|
2345 | Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
|
2346 | if (!Buffer.isBuffer(target)) {
|
2347 | throw new TypeError('Argument must be a Buffer')
|
2348 | }
|
2349 |
|
2350 | if (start === undefined) {
|
2351 | start = 0
|
2352 | }
|
2353 | if (end === undefined) {
|
2354 | end = target ? target.length : 0
|
2355 | }
|
2356 | if (thisStart === undefined) {
|
2357 | thisStart = 0
|
2358 | }
|
2359 | if (thisEnd === undefined) {
|
2360 | thisEnd = this.length
|
2361 | }
|
2362 |
|
2363 | if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
|
2364 | throw new RangeError('out of range index')
|
2365 | }
|
2366 |
|
2367 | if (thisStart >= thisEnd && start >= end) {
|
2368 | return 0
|
2369 | }
|
2370 | if (thisStart >= thisEnd) {
|
2371 | return -1
|
2372 | }
|
2373 | if (start >= end) {
|
2374 | return 1
|
2375 | }
|
2376 |
|
2377 | start >>>= 0
|
2378 | end >>>= 0
|
2379 | thisStart >>>= 0
|
2380 | thisEnd >>>= 0
|
2381 |
|
2382 | if (this === target) return 0
|
2383 |
|
2384 | var x = thisEnd - thisStart
|
2385 | var y = end - start
|
2386 | var len = Math.min(x, y)
|
2387 |
|
2388 | var thisCopy = this.slice(thisStart, thisEnd)
|
2389 | var targetCopy = target.slice(start, end)
|
2390 |
|
2391 | for (var i = 0; i < len; ++i) {
|
2392 | if (thisCopy[i] !== targetCopy[i]) {
|
2393 | x = thisCopy[i]
|
2394 | y = targetCopy[i]
|
2395 | break
|
2396 | }
|
2397 | }
|
2398 |
|
2399 | if (x < y) return -1
|
2400 | if (y < x) return 1
|
2401 | return 0
|
2402 | }
|
2403 |
|
2404 |
|
2405 |
|
2406 |
|
2407 |
|
2408 |
|
2409 |
|
2410 |
|
2411 |
|
2412 |
|
2413 | function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
|
2414 |
|
2415 | if (buffer.length === 0) return -1
|
2416 |
|
2417 |
|
2418 | if (typeof byteOffset === 'string') {
|
2419 | encoding = byteOffset
|
2420 | byteOffset = 0
|
2421 | } else if (byteOffset > 0x7fffffff) {
|
2422 | byteOffset = 0x7fffffff
|
2423 | } else if (byteOffset < -0x80000000) {
|
2424 | byteOffset = -0x80000000
|
2425 | }
|
2426 | byteOffset = +byteOffset
|
2427 | if (numberIsNaN(byteOffset)) {
|
2428 |
|
2429 | byteOffset = dir ? 0 : (buffer.length - 1)
|
2430 | }
|
2431 |
|
2432 |
|
2433 | if (byteOffset < 0) byteOffset = buffer.length + byteOffset
|
2434 | if (byteOffset >= buffer.length) {
|
2435 | if (dir) return -1
|
2436 | else byteOffset = buffer.length - 1
|
2437 | } else if (byteOffset < 0) {
|
2438 | if (dir) byteOffset = 0
|
2439 | else return -1
|
2440 | }
|
2441 |
|
2442 |
|
2443 | if (typeof val === 'string') {
|
2444 | val = Buffer.from(val, encoding)
|
2445 | }
|
2446 |
|
2447 |
|
2448 | if (Buffer.isBuffer(val)) {
|
2449 |
|
2450 | if (val.length === 0) {
|
2451 | return -1
|
2452 | }
|
2453 | return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
|
2454 | } else if (typeof val === 'number') {
|
2455 | val = val & 0xFF
|
2456 | if (typeof Uint8Array.prototype.indexOf === 'function') {
|
2457 | if (dir) {
|
2458 | return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
|
2459 | } else {
|
2460 | return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
|
2461 | }
|
2462 | }
|
2463 | return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir)
|
2464 | }
|
2465 |
|
2466 | throw new TypeError('val must be string, number or Buffer')
|
2467 | }
|
2468 |
|
2469 | function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
|
2470 | var indexSize = 1
|
2471 | var arrLength = arr.length
|
2472 | var valLength = val.length
|
2473 |
|
2474 | if (encoding !== undefined) {
|
2475 | encoding = String(encoding).toLowerCase()
|
2476 | if (encoding === 'ucs2' || encoding === 'ucs-2' ||
|
2477 | encoding === 'utf16le' || encoding === 'utf-16le') {
|
2478 | if (arr.length < 2 || val.length < 2) {
|
2479 | return -1
|
2480 | }
|
2481 | indexSize = 2
|
2482 | arrLength /= 2
|
2483 | valLength /= 2
|
2484 | byteOffset /= 2
|
2485 | }
|
2486 | }
|
2487 |
|
2488 | function read (buf, i) {
|
2489 | if (indexSize === 1) {
|
2490 | return buf[i]
|
2491 | } else {
|
2492 | return buf.readUInt16BE(i * indexSize)
|
2493 | }
|
2494 | }
|
2495 |
|
2496 | var i
|
2497 | if (dir) {
|
2498 | var foundIndex = -1
|
2499 | for (i = byteOffset; i < arrLength; i++) {
|
2500 | if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
|
2501 | if (foundIndex === -1) foundIndex = i
|
2502 | if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
|
2503 | } else {
|
2504 | if (foundIndex !== -1) i -= i - foundIndex
|
2505 | foundIndex = -1
|
2506 | }
|
2507 | }
|
2508 | } else {
|
2509 | if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength
|
2510 | for (i = byteOffset; i >= 0; i--) {
|
2511 | var found = true
|
2512 | for (var j = 0; j < valLength; j++) {
|
2513 | if (read(arr, i + j) !== read(val, j)) {
|
2514 | found = false
|
2515 | break
|
2516 | }
|
2517 | }
|
2518 | if (found) return i
|
2519 | }
|
2520 | }
|
2521 |
|
2522 | return -1
|
2523 | }
|
2524 |
|
2525 | Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
|
2526 | return this.indexOf(val, byteOffset, encoding) !== -1
|
2527 | }
|
2528 |
|
2529 | Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
|
2530 | return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
|
2531 | }
|
2532 |
|
2533 | Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
|
2534 | return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
|
2535 | }
|
2536 |
|
2537 | function hexWrite (buf, string, offset, length) {
|
2538 | offset = Number(offset) || 0
|
2539 | var remaining = buf.length - offset
|
2540 | if (!length) {
|
2541 | length = remaining
|
2542 | } else {
|
2543 | length = Number(length)
|
2544 | if (length > remaining) {
|
2545 | length = remaining
|
2546 | }
|
2547 | }
|
2548 |
|
2549 | var strLen = string.length
|
2550 |
|
2551 | if (length > strLen / 2) {
|
2552 | length = strLen / 2
|
2553 | }
|
2554 | for (var i = 0; i < length; ++i) {
|
2555 | var parsed = parseInt(string.substr(i * 2, 2), 16)
|
2556 | if (numberIsNaN(parsed)) return i
|
2557 | buf[offset + i] = parsed
|
2558 | }
|
2559 | return i
|
2560 | }
|
2561 |
|
2562 | function utf8Write (buf, string, offset, length) {
|
2563 | return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
|
2564 | }
|
2565 |
|
2566 | function asciiWrite (buf, string, offset, length) {
|
2567 | return blitBuffer(asciiToBytes(string), buf, offset, length)
|
2568 | }
|
2569 |
|
2570 | function latin1Write (buf, string, offset, length) {
|
2571 | return asciiWrite(buf, string, offset, length)
|
2572 | }
|
2573 |
|
2574 | function base64Write (buf, string, offset, length) {
|
2575 | return blitBuffer(base64ToBytes(string), buf, offset, length)
|
2576 | }
|
2577 |
|
2578 | function ucs2Write (buf, string, offset, length) {
|
2579 | return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
|
2580 | }
|
2581 |
|
2582 | Buffer.prototype.write = function write (string, offset, length, encoding) {
|
2583 |
|
2584 | if (offset === undefined) {
|
2585 | encoding = 'utf8'
|
2586 | length = this.length
|
2587 | offset = 0
|
2588 |
|
2589 | } else if (length === undefined && typeof offset === 'string') {
|
2590 | encoding = offset
|
2591 | length = this.length
|
2592 | offset = 0
|
2593 |
|
2594 | } else if (isFinite(offset)) {
|
2595 | offset = offset >>> 0
|
2596 | if (isFinite(length)) {
|
2597 | length = length >>> 0
|
2598 | if (encoding === undefined) encoding = 'utf8'
|
2599 | } else {
|
2600 | encoding = length
|
2601 | length = undefined
|
2602 | }
|
2603 | } else {
|
2604 | throw new Error(
|
2605 | 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
|
2606 | )
|
2607 | }
|
2608 |
|
2609 | var remaining = this.length - offset
|
2610 | if (length === undefined || length > remaining) length = remaining
|
2611 |
|
2612 | if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
|
2613 | throw new RangeError('Attempt to write outside buffer bounds')
|
2614 | }
|
2615 |
|
2616 | if (!encoding) encoding = 'utf8'
|
2617 |
|
2618 | var loweredCase = false
|
2619 | for (;;) {
|
2620 | switch (encoding) {
|
2621 | case 'hex':
|
2622 | return hexWrite(this, string, offset, length)
|
2623 |
|
2624 | case 'utf8':
|
2625 | case 'utf-8':
|
2626 | return utf8Write(this, string, offset, length)
|
2627 |
|
2628 | case 'ascii':
|
2629 | return asciiWrite(this, string, offset, length)
|
2630 |
|
2631 | case 'latin1':
|
2632 | case 'binary':
|
2633 | return latin1Write(this, string, offset, length)
|
2634 |
|
2635 | case 'base64':
|
2636 |
|
2637 | return base64Write(this, string, offset, length)
|
2638 |
|
2639 | case 'ucs2':
|
2640 | case 'ucs-2':
|
2641 | case 'utf16le':
|
2642 | case 'utf-16le':
|
2643 | return ucs2Write(this, string, offset, length)
|
2644 |
|
2645 | default:
|
2646 | if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
|
2647 | encoding = ('' + encoding).toLowerCase()
|
2648 | loweredCase = true
|
2649 | }
|
2650 | }
|
2651 | }
|
2652 |
|
2653 | Buffer.prototype.toJSON = function toJSON () {
|
2654 | return {
|
2655 | type: 'Buffer',
|
2656 | data: Array.prototype.slice.call(this._arr || this, 0)
|
2657 | }
|
2658 | }
|
2659 |
|
2660 | function base64Slice (buf, start, end) {
|
2661 | if (start === 0 && end === buf.length) {
|
2662 | return base64.fromByteArray(buf)
|
2663 | } else {
|
2664 | return base64.fromByteArray(buf.slice(start, end))
|
2665 | }
|
2666 | }
|
2667 |
|
2668 | function utf8Slice (buf, start, end) {
|
2669 | end = Math.min(buf.length, end)
|
2670 | var res = []
|
2671 |
|
2672 | var i = start
|
2673 | while (i < end) {
|
2674 | var firstByte = buf[i]
|
2675 | var codePoint = null
|
2676 | var bytesPerSequence = (firstByte > 0xEF) ? 4
|
2677 | : (firstByte > 0xDF) ? 3
|
2678 | : (firstByte > 0xBF) ? 2
|
2679 | : 1
|
2680 |
|
2681 | if (i + bytesPerSequence <= end) {
|
2682 | var secondByte, thirdByte, fourthByte, tempCodePoint
|
2683 |
|
2684 | switch (bytesPerSequence) {
|
2685 | case 1:
|
2686 | if (firstByte < 0x80) {
|
2687 | codePoint = firstByte
|
2688 | }
|
2689 | break
|
2690 | case 2:
|
2691 | secondByte = buf[i + 1]
|
2692 | if ((secondByte & 0xC0) === 0x80) {
|
2693 | tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F)
|
2694 | if (tempCodePoint > 0x7F) {
|
2695 | codePoint = tempCodePoint
|
2696 | }
|
2697 | }
|
2698 | break
|
2699 | case 3:
|
2700 | secondByte = buf[i + 1]
|
2701 | thirdByte = buf[i + 2]
|
2702 | if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
|
2703 | tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F)
|
2704 | if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
|
2705 | codePoint = tempCodePoint
|
2706 | }
|
2707 | }
|
2708 | break
|
2709 | case 4:
|
2710 | secondByte = buf[i + 1]
|
2711 | thirdByte = buf[i + 2]
|
2712 | fourthByte = buf[i + 3]
|
2713 | if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
|
2714 | tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F)
|
2715 | if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
|
2716 | codePoint = tempCodePoint
|
2717 | }
|
2718 | }
|
2719 | }
|
2720 | }
|
2721 |
|
2722 | if (codePoint === null) {
|
2723 |
|
2724 |
|
2725 | codePoint = 0xFFFD
|
2726 | bytesPerSequence = 1
|
2727 | } else if (codePoint > 0xFFFF) {
|
2728 |
|
2729 | codePoint -= 0x10000
|
2730 | res.push(codePoint >>> 10 & 0x3FF | 0xD800)
|
2731 | codePoint = 0xDC00 | codePoint & 0x3FF
|
2732 | }
|
2733 |
|
2734 | res.push(codePoint)
|
2735 | i += bytesPerSequence
|
2736 | }
|
2737 |
|
2738 | return decodeCodePointsArray(res)
|
2739 | }
|
2740 |
|
2741 |
|
2742 |
|
2743 |
|
2744 | var MAX_ARGUMENTS_LENGTH = 0x1000
|
2745 |
|
2746 | function decodeCodePointsArray (codePoints) {
|
2747 | var len = codePoints.length
|
2748 | if (len <= MAX_ARGUMENTS_LENGTH) {
|
2749 | return String.fromCharCode.apply(String, codePoints)
|
2750 | }
|
2751 |
|
2752 |
|
2753 | var res = ''
|
2754 | var i = 0
|
2755 | while (i < len) {
|
2756 | res += String.fromCharCode.apply(
|
2757 | String,
|
2758 | codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
|
2759 | )
|
2760 | }
|
2761 | return res
|
2762 | }
|
2763 |
|
2764 | function asciiSlice (buf, start, end) {
|
2765 | var ret = ''
|
2766 | end = Math.min(buf.length, end)
|
2767 |
|
2768 | for (var i = start; i < end; ++i) {
|
2769 | ret += String.fromCharCode(buf[i] & 0x7F)
|
2770 | }
|
2771 | return ret
|
2772 | }
|
2773 |
|
2774 | function latin1Slice (buf, start, end) {
|
2775 | var ret = ''
|
2776 | end = Math.min(buf.length, end)
|
2777 |
|
2778 | for (var i = start; i < end; ++i) {
|
2779 | ret += String.fromCharCode(buf[i])
|
2780 | }
|
2781 | return ret
|
2782 | }
|
2783 |
|
2784 | function hexSlice (buf, start, end) {
|
2785 | var len = buf.length
|
2786 |
|
2787 | if (!start || start < 0) start = 0
|
2788 | if (!end || end < 0 || end > len) end = len
|
2789 |
|
2790 | var out = ''
|
2791 | for (var i = start; i < end; ++i) {
|
2792 | out += toHex(buf[i])
|
2793 | }
|
2794 | return out
|
2795 | }
|
2796 |
|
2797 | function utf16leSlice (buf, start, end) {
|
2798 | var bytes = buf.slice(start, end)
|
2799 | var res = ''
|
2800 | for (var i = 0; i < bytes.length; i += 2) {
|
2801 | res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256))
|
2802 | }
|
2803 | return res
|
2804 | }
|
2805 |
|
2806 | Buffer.prototype.slice = function slice (start, end) {
|
2807 | var len = this.length
|
2808 | start = ~~start
|
2809 | end = end === undefined ? len : ~~end
|
2810 |
|
2811 | if (start < 0) {
|
2812 | start += len
|
2813 | if (start < 0) start = 0
|
2814 | } else if (start > len) {
|
2815 | start = len
|
2816 | }
|
2817 |
|
2818 | if (end < 0) {
|
2819 | end += len
|
2820 | if (end < 0) end = 0
|
2821 | } else if (end > len) {
|
2822 | end = len
|
2823 | }
|
2824 |
|
2825 | if (end < start) end = start
|
2826 |
|
2827 | var newBuf = this.subarray(start, end)
|
2828 |
|
2829 | newBuf.__proto__ = Buffer.prototype
|
2830 | return newBuf
|
2831 | }
|
2832 |
|
2833 |
|
2834 |
|
2835 |
|
2836 | function checkOffset (offset, ext, length) {
|
2837 | if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
|
2838 | if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
|
2839 | }
|
2840 |
|
2841 | Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
|
2842 | offset = offset >>> 0
|
2843 | byteLength = byteLength >>> 0
|
2844 | if (!noAssert) checkOffset(offset, byteLength, this.length)
|
2845 |
|
2846 | var val = this[offset]
|
2847 | var mul = 1
|
2848 | var i = 0
|
2849 | while (++i < byteLength && (mul *= 0x100)) {
|
2850 | val += this[offset + i] * mul
|
2851 | }
|
2852 |
|
2853 | return val
|
2854 | }
|
2855 |
|
2856 | Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
|
2857 | offset = offset >>> 0
|
2858 | byteLength = byteLength >>> 0
|
2859 | if (!noAssert) {
|
2860 | checkOffset(offset, byteLength, this.length)
|
2861 | }
|
2862 |
|
2863 | var val = this[offset + --byteLength]
|
2864 | var mul = 1
|
2865 | while (byteLength > 0 && (mul *= 0x100)) {
|
2866 | val += this[offset + --byteLength] * mul
|
2867 | }
|
2868 |
|
2869 | return val
|
2870 | }
|
2871 |
|
2872 | Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
|
2873 | offset = offset >>> 0
|
2874 | if (!noAssert) checkOffset(offset, 1, this.length)
|
2875 | return this[offset]
|
2876 | }
|
2877 |
|
2878 | Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
|
2879 | offset = offset >>> 0
|
2880 | if (!noAssert) checkOffset(offset, 2, this.length)
|
2881 | return this[offset] | (this[offset + 1] << 8)
|
2882 | }
|
2883 |
|
2884 | Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
|
2885 | offset = offset >>> 0
|
2886 | if (!noAssert) checkOffset(offset, 2, this.length)
|
2887 | return (this[offset] << 8) | this[offset + 1]
|
2888 | }
|
2889 |
|
2890 | Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
|
2891 | offset = offset >>> 0
|
2892 | if (!noAssert) checkOffset(offset, 4, this.length)
|
2893 |
|
2894 | return ((this[offset]) |
|
2895 | (this[offset + 1] << 8) |
|
2896 | (this[offset + 2] << 16)) +
|
2897 | (this[offset + 3] * 0x1000000)
|
2898 | }
|
2899 |
|
2900 | Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
|
2901 | offset = offset >>> 0
|
2902 | if (!noAssert) checkOffset(offset, 4, this.length)
|
2903 |
|
2904 | return (this[offset] * 0x1000000) +
|
2905 | ((this[offset + 1] << 16) |
|
2906 | (this[offset + 2] << 8) |
|
2907 | this[offset + 3])
|
2908 | }
|
2909 |
|
2910 | Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
|
2911 | offset = offset >>> 0
|
2912 | byteLength = byteLength >>> 0
|
2913 | if (!noAssert) checkOffset(offset, byteLength, this.length)
|
2914 |
|
2915 | var val = this[offset]
|
2916 | var mul = 1
|
2917 | var i = 0
|
2918 | while (++i < byteLength && (mul *= 0x100)) {
|
2919 | val += this[offset + i] * mul
|
2920 | }
|
2921 | mul *= 0x80
|
2922 |
|
2923 | if (val >= mul) val -= Math.pow(2, 8 * byteLength)
|
2924 |
|
2925 | return val
|
2926 | }
|
2927 |
|
2928 | Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
|
2929 | offset = offset >>> 0
|
2930 | byteLength = byteLength >>> 0
|
2931 | if (!noAssert) checkOffset(offset, byteLength, this.length)
|
2932 |
|
2933 | var i = byteLength
|
2934 | var mul = 1
|
2935 | var val = this[offset + --i]
|
2936 | while (i > 0 && (mul *= 0x100)) {
|
2937 | val += this[offset + --i] * mul
|
2938 | }
|
2939 | mul *= 0x80
|
2940 |
|
2941 | if (val >= mul) val -= Math.pow(2, 8 * byteLength)
|
2942 |
|
2943 | return val
|
2944 | }
|
2945 |
|
2946 | Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
|
2947 | offset = offset >>> 0
|
2948 | if (!noAssert) checkOffset(offset, 1, this.length)
|
2949 | if (!(this[offset] & 0x80)) return (this[offset])
|
2950 | return ((0xff - this[offset] + 1) * -1)
|
2951 | }
|
2952 |
|
2953 | Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
|
2954 | offset = offset >>> 0
|
2955 | if (!noAssert) checkOffset(offset, 2, this.length)
|
2956 | var val = this[offset] | (this[offset + 1] << 8)
|
2957 | return (val & 0x8000) ? val | 0xFFFF0000 : val
|
2958 | }
|
2959 |
|
2960 | Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
|
2961 | offset = offset >>> 0
|
2962 | if (!noAssert) checkOffset(offset, 2, this.length)
|
2963 | var val = this[offset + 1] | (this[offset] << 8)
|
2964 | return (val & 0x8000) ? val | 0xFFFF0000 : val
|
2965 | }
|
2966 |
|
2967 | Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
|
2968 | offset = offset >>> 0
|
2969 | if (!noAssert) checkOffset(offset, 4, this.length)
|
2970 |
|
2971 | return (this[offset]) |
|
2972 | (this[offset + 1] << 8) |
|
2973 | (this[offset + 2] << 16) |
|
2974 | (this[offset + 3] << 24)
|
2975 | }
|
2976 |
|
2977 | Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
|
2978 | offset = offset >>> 0
|
2979 | if (!noAssert) checkOffset(offset, 4, this.length)
|
2980 |
|
2981 | return (this[offset] << 24) |
|
2982 | (this[offset + 1] << 16) |
|
2983 | (this[offset + 2] << 8) |
|
2984 | (this[offset + 3])
|
2985 | }
|
2986 |
|
2987 | Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
|
2988 | offset = offset >>> 0
|
2989 | if (!noAssert) checkOffset(offset, 4, this.length)
|
2990 | return ieee754.read(this, offset, true, 23, 4)
|
2991 | }
|
2992 |
|
2993 | Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
|
2994 | offset = offset >>> 0
|
2995 | if (!noAssert) checkOffset(offset, 4, this.length)
|
2996 | return ieee754.read(this, offset, false, 23, 4)
|
2997 | }
|
2998 |
|
2999 | Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
|
3000 | offset = offset >>> 0
|
3001 | if (!noAssert) checkOffset(offset, 8, this.length)
|
3002 | return ieee754.read(this, offset, true, 52, 8)
|
3003 | }
|
3004 |
|
3005 | Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
|
3006 | offset = offset >>> 0
|
3007 | if (!noAssert) checkOffset(offset, 8, this.length)
|
3008 | return ieee754.read(this, offset, false, 52, 8)
|
3009 | }
|
3010 |
|
3011 | function checkInt (buf, value, offset, ext, max, min) {
|
3012 | if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
|
3013 | if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
|
3014 | if (offset + ext > buf.length) throw new RangeError('Index out of range')
|
3015 | }
|
3016 |
|
3017 | Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
|
3018 | value = +value
|
3019 | offset = offset >>> 0
|
3020 | byteLength = byteLength >>> 0
|
3021 | if (!noAssert) {
|
3022 | var maxBytes = Math.pow(2, 8 * byteLength) - 1
|
3023 | checkInt(this, value, offset, byteLength, maxBytes, 0)
|
3024 | }
|
3025 |
|
3026 | var mul = 1
|
3027 | var i = 0
|
3028 | this[offset] = value & 0xFF
|
3029 | while (++i < byteLength && (mul *= 0x100)) {
|
3030 | this[offset + i] = (value / mul) & 0xFF
|
3031 | }
|
3032 |
|
3033 | return offset + byteLength
|
3034 | }
|
3035 |
|
3036 | Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
|
3037 | value = +value
|
3038 | offset = offset >>> 0
|
3039 | byteLength = byteLength >>> 0
|
3040 | if (!noAssert) {
|
3041 | var maxBytes = Math.pow(2, 8 * byteLength) - 1
|
3042 | checkInt(this, value, offset, byteLength, maxBytes, 0)
|
3043 | }
|
3044 |
|
3045 | var i = byteLength - 1
|
3046 | var mul = 1
|
3047 | this[offset + i] = value & 0xFF
|
3048 | while (--i >= 0 && (mul *= 0x100)) {
|
3049 | this[offset + i] = (value / mul) & 0xFF
|
3050 | }
|
3051 |
|
3052 | return offset + byteLength
|
3053 | }
|
3054 |
|
3055 | Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
|
3056 | value = +value
|
3057 | offset = offset >>> 0
|
3058 | if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)
|
3059 | this[offset] = (value & 0xff)
|
3060 | return offset + 1
|
3061 | }
|
3062 |
|
3063 | Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
|
3064 | value = +value
|
3065 | offset = offset >>> 0
|
3066 | if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
|
3067 | this[offset] = (value & 0xff)
|
3068 | this[offset + 1] = (value >>> 8)
|
3069 | return offset + 2
|
3070 | }
|
3071 |
|
3072 | Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
|
3073 | value = +value
|
3074 | offset = offset >>> 0
|
3075 | if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
|
3076 | this[offset] = (value >>> 8)
|
3077 | this[offset + 1] = (value & 0xff)
|
3078 | return offset + 2
|
3079 | }
|
3080 |
|
3081 | Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
|
3082 | value = +value
|
3083 | offset = offset >>> 0
|
3084 | if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
|
3085 | this[offset + 3] = (value >>> 24)
|
3086 | this[offset + 2] = (value >>> 16)
|
3087 | this[offset + 1] = (value >>> 8)
|
3088 | this[offset] = (value & 0xff)
|
3089 | return offset + 4
|
3090 | }
|
3091 |
|
3092 | Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
|
3093 | value = +value
|
3094 | offset = offset >>> 0
|
3095 | if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
|
3096 | this[offset] = (value >>> 24)
|
3097 | this[offset + 1] = (value >>> 16)
|
3098 | this[offset + 2] = (value >>> 8)
|
3099 | this[offset + 3] = (value & 0xff)
|
3100 | return offset + 4
|
3101 | }
|
3102 |
|
3103 | Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
|
3104 | value = +value
|
3105 | offset = offset >>> 0
|
3106 | if (!noAssert) {
|
3107 | var limit = Math.pow(2, (8 * byteLength) - 1)
|
3108 |
|
3109 | checkInt(this, value, offset, byteLength, limit - 1, -limit)
|
3110 | }
|
3111 |
|
3112 | var i = 0
|
3113 | var mul = 1
|
3114 | var sub = 0
|
3115 | this[offset] = value & 0xFF
|
3116 | while (++i < byteLength && (mul *= 0x100)) {
|
3117 | if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
|
3118 | sub = 1
|
3119 | }
|
3120 | this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
|
3121 | }
|
3122 |
|
3123 | return offset + byteLength
|
3124 | }
|
3125 |
|
3126 | Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
|
3127 | value = +value
|
3128 | offset = offset >>> 0
|
3129 | if (!noAssert) {
|
3130 | var limit = Math.pow(2, (8 * byteLength) - 1)
|
3131 |
|
3132 | checkInt(this, value, offset, byteLength, limit - 1, -limit)
|
3133 | }
|
3134 |
|
3135 | var i = byteLength - 1
|
3136 | var mul = 1
|
3137 | var sub = 0
|
3138 | this[offset + i] = value & 0xFF
|
3139 | while (--i >= 0 && (mul *= 0x100)) {
|
3140 | if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
|
3141 | sub = 1
|
3142 | }
|
3143 | this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
|
3144 | }
|
3145 |
|
3146 | return offset + byteLength
|
3147 | }
|
3148 |
|
3149 | Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
|
3150 | value = +value
|
3151 | offset = offset >>> 0
|
3152 | if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80)
|
3153 | if (value < 0) value = 0xff + value + 1
|
3154 | this[offset] = (value & 0xff)
|
3155 | return offset + 1
|
3156 | }
|
3157 |
|
3158 | Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
|
3159 | value = +value
|
3160 | offset = offset >>> 0
|
3161 | if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
|
3162 | this[offset] = (value & 0xff)
|
3163 | this[offset + 1] = (value >>> 8)
|
3164 | return offset + 2
|
3165 | }
|
3166 |
|
3167 | Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
|
3168 | value = +value
|
3169 | offset = offset >>> 0
|
3170 | if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
|
3171 | this[offset] = (value >>> 8)
|
3172 | this[offset + 1] = (value & 0xff)
|
3173 | return offset + 2
|
3174 | }
|
3175 |
|
3176 | Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
|
3177 | value = +value
|
3178 | offset = offset >>> 0
|
3179 | if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
|
3180 | this[offset] = (value & 0xff)
|
3181 | this[offset + 1] = (value >>> 8)
|
3182 | this[offset + 2] = (value >>> 16)
|
3183 | this[offset + 3] = (value >>> 24)
|
3184 | return offset + 4
|
3185 | }
|
3186 |
|
3187 | Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
|
3188 | value = +value
|
3189 | offset = offset >>> 0
|
3190 | if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
|
3191 | if (value < 0) value = 0xffffffff + value + 1
|
3192 | this[offset] = (value >>> 24)
|
3193 | this[offset + 1] = (value >>> 16)
|
3194 | this[offset + 2] = (value >>> 8)
|
3195 | this[offset + 3] = (value & 0xff)
|
3196 | return offset + 4
|
3197 | }
|
3198 |
|
3199 | function checkIEEE754 (buf, value, offset, ext, max, min) {
|
3200 | if (offset + ext > buf.length) throw new RangeError('Index out of range')
|
3201 | if (offset < 0) throw new RangeError('Index out of range')
|
3202 | }
|
3203 |
|
3204 | function writeFloat (buf, value, offset, littleEndian, noAssert) {
|
3205 | value = +value
|
3206 | offset = offset >>> 0
|
3207 | if (!noAssert) {
|
3208 | checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
|
3209 | }
|
3210 | ieee754.write(buf, value, offset, littleEndian, 23, 4)
|
3211 | return offset + 4
|
3212 | }
|
3213 |
|
3214 | Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
|
3215 | return writeFloat(this, value, offset, true, noAssert)
|
3216 | }
|
3217 |
|
3218 | Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
|
3219 | return writeFloat(this, value, offset, false, noAssert)
|
3220 | }
|
3221 |
|
3222 | function writeDouble (buf, value, offset, littleEndian, noAssert) {
|
3223 | value = +value
|
3224 | offset = offset >>> 0
|
3225 | if (!noAssert) {
|
3226 | checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
|
3227 | }
|
3228 | ieee754.write(buf, value, offset, littleEndian, 52, 8)
|
3229 | return offset + 8
|
3230 | }
|
3231 |
|
3232 | Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
|
3233 | return writeDouble(this, value, offset, true, noAssert)
|
3234 | }
|
3235 |
|
3236 | Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
|
3237 | return writeDouble(this, value, offset, false, noAssert)
|
3238 | }
|
3239 |
|
3240 |
|
3241 | Buffer.prototype.copy = function copy (target, targetStart, start, end) {
|
3242 | if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer')
|
3243 | if (!start) start = 0
|
3244 | if (!end && end !== 0) end = this.length
|
3245 | if (targetStart >= target.length) targetStart = target.length
|
3246 | if (!targetStart) targetStart = 0
|
3247 | if (end > 0 && end < start) end = start
|
3248 |
|
3249 |
|
3250 | if (end === start) return 0
|
3251 | if (target.length === 0 || this.length === 0) return 0
|
3252 |
|
3253 |
|
3254 | if (targetStart < 0) {
|
3255 | throw new RangeError('targetStart out of bounds')
|
3256 | }
|
3257 | if (start < 0 || start >= this.length) throw new RangeError('Index out of range')
|
3258 | if (end < 0) throw new RangeError('sourceEnd out of bounds')
|
3259 |
|
3260 |
|
3261 | if (end > this.length) end = this.length
|
3262 | if (target.length - targetStart < end - start) {
|
3263 | end = target.length - targetStart + start
|
3264 | }
|
3265 |
|
3266 | var len = end - start
|
3267 |
|
3268 | if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {
|
3269 |
|
3270 | this.copyWithin(targetStart, start, end)
|
3271 | } else if (this === target && start < targetStart && targetStart < end) {
|
3272 |
|
3273 | for (var i = len - 1; i >= 0; --i) {
|
3274 | target[i + targetStart] = this[i + start]
|
3275 | }
|
3276 | } else {
|
3277 | Uint8Array.prototype.set.call(
|
3278 | target,
|
3279 | this.subarray(start, end),
|
3280 | targetStart
|
3281 | )
|
3282 | }
|
3283 |
|
3284 | return len
|
3285 | }
|
3286 |
|
3287 |
|
3288 |
|
3289 |
|
3290 |
|
3291 | Buffer.prototype.fill = function fill (val, start, end, encoding) {
|
3292 |
|
3293 | if (typeof val === 'string') {
|
3294 | if (typeof start === 'string') {
|
3295 | encoding = start
|
3296 | start = 0
|
3297 | end = this.length
|
3298 | } else if (typeof end === 'string') {
|
3299 | encoding = end
|
3300 | end = this.length
|
3301 | }
|
3302 | if (encoding !== undefined && typeof encoding !== 'string') {
|
3303 | throw new TypeError('encoding must be a string')
|
3304 | }
|
3305 | if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
|
3306 | throw new TypeError('Unknown encoding: ' + encoding)
|
3307 | }
|
3308 | if (val.length === 1) {
|
3309 | var code = val.charCodeAt(0)
|
3310 | if ((encoding === 'utf8' && code < 128) ||
|
3311 | encoding === 'latin1') {
|
3312 |
|
3313 | val = code
|
3314 | }
|
3315 | }
|
3316 | } else if (typeof val === 'number') {
|
3317 | val = val & 255
|
3318 | }
|
3319 |
|
3320 |
|
3321 | if (start < 0 || this.length < start || this.length < end) {
|
3322 | throw new RangeError('Out of range index')
|
3323 | }
|
3324 |
|
3325 | if (end <= start) {
|
3326 | return this
|
3327 | }
|
3328 |
|
3329 | start = start >>> 0
|
3330 | end = end === undefined ? this.length : end >>> 0
|
3331 |
|
3332 | if (!val) val = 0
|
3333 |
|
3334 | var i
|
3335 | if (typeof val === 'number') {
|
3336 | for (i = start; i < end; ++i) {
|
3337 | this[i] = val
|
3338 | }
|
3339 | } else {
|
3340 | var bytes = Buffer.isBuffer(val)
|
3341 | ? val
|
3342 | : new Buffer(val, encoding)
|
3343 | var len = bytes.length
|
3344 | if (len === 0) {
|
3345 | throw new TypeError('The value "' + val +
|
3346 | '" is invalid for argument "value"')
|
3347 | }
|
3348 | for (i = 0; i < end - start; ++i) {
|
3349 | this[i + start] = bytes[i % len]
|
3350 | }
|
3351 | }
|
3352 |
|
3353 | return this
|
3354 | }
|
3355 |
|
3356 |
|
3357 |
|
3358 |
|
3359 | var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g
|
3360 |
|
3361 | function base64clean (str) {
|
3362 |
|
3363 | str = str.split('=')[0]
|
3364 |
|
3365 | str = str.trim().replace(INVALID_BASE64_RE, '')
|
3366 |
|
3367 | if (str.length < 2) return ''
|
3368 |
|
3369 | while (str.length % 4 !== 0) {
|
3370 | str = str + '='
|
3371 | }
|
3372 | return str
|
3373 | }
|
3374 |
|
3375 | function toHex (n) {
|
3376 | if (n < 16) return '0' + n.toString(16)
|
3377 | return n.toString(16)
|
3378 | }
|
3379 |
|
3380 | function utf8ToBytes (string, units) {
|
3381 | units = units || Infinity
|
3382 | var codePoint
|
3383 | var length = string.length
|
3384 | var leadSurrogate = null
|
3385 | var bytes = []
|
3386 |
|
3387 | for (var i = 0; i < length; ++i) {
|
3388 | codePoint = string.charCodeAt(i)
|
3389 |
|
3390 |
|
3391 | if (codePoint > 0xD7FF && codePoint < 0xE000) {
|
3392 |
|
3393 | if (!leadSurrogate) {
|
3394 |
|
3395 | if (codePoint > 0xDBFF) {
|
3396 |
|
3397 | if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
|
3398 | continue
|
3399 | } else if (i + 1 === length) {
|
3400 |
|
3401 | if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
|
3402 | continue
|
3403 | }
|
3404 |
|
3405 |
|
3406 | leadSurrogate = codePoint
|
3407 |
|
3408 | continue
|
3409 | }
|
3410 |
|
3411 |
|
3412 | if (codePoint < 0xDC00) {
|
3413 | if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
|
3414 | leadSurrogate = codePoint
|
3415 | continue
|
3416 | }
|
3417 |
|
3418 |
|
3419 | codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000
|
3420 | } else if (leadSurrogate) {
|
3421 |
|
3422 | if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
|
3423 | }
|
3424 |
|
3425 | leadSurrogate = null
|
3426 |
|
3427 |
|
3428 | if (codePoint < 0x80) {
|
3429 | if ((units -= 1) < 0) break
|
3430 | bytes.push(codePoint)
|
3431 | } else if (codePoint < 0x800) {
|
3432 | if ((units -= 2) < 0) break
|
3433 | bytes.push(
|
3434 | codePoint >> 0x6 | 0xC0,
|
3435 | codePoint & 0x3F | 0x80
|
3436 | )
|
3437 | } else if (codePoint < 0x10000) {
|
3438 | if ((units -= 3) < 0) break
|
3439 | bytes.push(
|
3440 | codePoint >> 0xC | 0xE0,
|
3441 | codePoint >> 0x6 & 0x3F | 0x80,
|
3442 | codePoint & 0x3F | 0x80
|
3443 | )
|
3444 | } else if (codePoint < 0x110000) {
|
3445 | if ((units -= 4) < 0) break
|
3446 | bytes.push(
|
3447 | codePoint >> 0x12 | 0xF0,
|
3448 | codePoint >> 0xC & 0x3F | 0x80,
|
3449 | codePoint >> 0x6 & 0x3F | 0x80,
|
3450 | codePoint & 0x3F | 0x80
|
3451 | )
|
3452 | } else {
|
3453 | throw new Error('Invalid code point')
|
3454 | }
|
3455 | }
|
3456 |
|
3457 | return bytes
|
3458 | }
|
3459 |
|
3460 | function asciiToBytes (str) {
|
3461 | var byteArray = []
|
3462 | for (var i = 0; i < str.length; ++i) {
|
3463 |
|
3464 | byteArray.push(str.charCodeAt(i) & 0xFF)
|
3465 | }
|
3466 | return byteArray
|
3467 | }
|
3468 |
|
3469 | function utf16leToBytes (str, units) {
|
3470 | var c, hi, lo
|
3471 | var byteArray = []
|
3472 | for (var i = 0; i < str.length; ++i) {
|
3473 | if ((units -= 2) < 0) break
|
3474 |
|
3475 | c = str.charCodeAt(i)
|
3476 | hi = c >> 8
|
3477 | lo = c % 256
|
3478 | byteArray.push(lo)
|
3479 | byteArray.push(hi)
|
3480 | }
|
3481 |
|
3482 | return byteArray
|
3483 | }
|
3484 |
|
3485 | function base64ToBytes (str) {
|
3486 | return base64.toByteArray(base64clean(str))
|
3487 | }
|
3488 |
|
3489 | function blitBuffer (src, dst, offset, length) {
|
3490 | for (var i = 0; i < length; ++i) {
|
3491 | if ((i + offset >= dst.length) || (i >= src.length)) break
|
3492 | dst[i + offset] = src[i]
|
3493 | }
|
3494 | return i
|
3495 | }
|
3496 |
|
3497 |
|
3498 |
|
3499 | function isArrayBuffer (obj) {
|
3500 | return obj instanceof ArrayBuffer ||
|
3501 | (obj != null && obj.constructor != null && obj.constructor.name === 'ArrayBuffer' &&
|
3502 | typeof obj.byteLength === 'number')
|
3503 | }
|
3504 |
|
3505 | function numberIsNaN (obj) {
|
3506 | return obj !== obj
|
3507 | }
|
3508 |
|
3509 | },{"24":24,"9":9}],13:[function(_dereq_,module,exports){
|
3510 | (function (Buffer){
|
3511 |
|
3512 |
|
3513 |
|
3514 |
|
3515 |
|
3516 |
|
3517 |
|
3518 |
|
3519 |
|
3520 |
|
3521 |
|
3522 |
|
3523 |
|
3524 |
|
3525 |
|
3526 |
|
3527 |
|
3528 |
|
3529 |
|
3530 |
|
3531 |
|
3532 |
|
3533 |
|
3534 |
|
3535 | function isArray(arg) {
|
3536 | if (Array.isArray) {
|
3537 | return Array.isArray(arg);
|
3538 | }
|
3539 | return objectToString(arg) === '[object Array]';
|
3540 | }
|
3541 | exports.isArray = isArray;
|
3542 |
|
3543 | function isBoolean(arg) {
|
3544 | return typeof arg === 'boolean';
|
3545 | }
|
3546 | exports.isBoolean = isBoolean;
|
3547 |
|
3548 | function isNull(arg) {
|
3549 | return arg === null;
|
3550 | }
|
3551 | exports.isNull = isNull;
|
3552 |
|
3553 | function isNullOrUndefined(arg) {
|
3554 | return arg == null;
|
3555 | }
|
3556 | exports.isNullOrUndefined = isNullOrUndefined;
|
3557 |
|
3558 | function isNumber(arg) {
|
3559 | return typeof arg === 'number';
|
3560 | }
|
3561 | exports.isNumber = isNumber;
|
3562 |
|
3563 | function isString(arg) {
|
3564 | return typeof arg === 'string';
|
3565 | }
|
3566 | exports.isString = isString;
|
3567 |
|
3568 | function isSymbol(arg) {
|
3569 | return typeof arg === 'symbol';
|
3570 | }
|
3571 | exports.isSymbol = isSymbol;
|
3572 |
|
3573 | function isUndefined(arg) {
|
3574 | return arg === void 0;
|
3575 | }
|
3576 | exports.isUndefined = isUndefined;
|
3577 |
|
3578 | function isRegExp(re) {
|
3579 | return objectToString(re) === '[object RegExp]';
|
3580 | }
|
3581 | exports.isRegExp = isRegExp;
|
3582 |
|
3583 | function isObject(arg) {
|
3584 | return typeof arg === 'object' && arg !== null;
|
3585 | }
|
3586 | exports.isObject = isObject;
|
3587 |
|
3588 | function isDate(d) {
|
3589 | return objectToString(d) === '[object Date]';
|
3590 | }
|
3591 | exports.isDate = isDate;
|
3592 |
|
3593 | function isError(e) {
|
3594 | return (objectToString(e) === '[object Error]' || e instanceof Error);
|
3595 | }
|
3596 | exports.isError = isError;
|
3597 |
|
3598 | function isFunction(arg) {
|
3599 | return typeof arg === 'function';
|
3600 | }
|
3601 | exports.isFunction = isFunction;
|
3602 |
|
3603 | function isPrimitive(arg) {
|
3604 | return arg === null ||
|
3605 | typeof arg === 'boolean' ||
|
3606 | typeof arg === 'number' ||
|
3607 | typeof arg === 'string' ||
|
3608 | typeof arg === 'symbol' ||
|
3609 | typeof arg === 'undefined';
|
3610 | }
|
3611 | exports.isPrimitive = isPrimitive;
|
3612 |
|
3613 | exports.isBuffer = Buffer.isBuffer;
|
3614 |
|
3615 | function objectToString(o) {
|
3616 | return Object.prototype.toString.call(o);
|
3617 | }
|
3618 |
|
3619 | }).call(this,{"isBuffer":_dereq_(27)})
|
3620 | },{"27":27}],14:[function(_dereq_,module,exports){
|
3621 | var Buffer = _dereq_(12).Buffer
|
3622 |
|
3623 | var CHARS = '.PYFGCRLAOEUIDHTNSQJKXBMWVZ_pyfgcrlaoeuidhtnsqjkxbmwvz1234567890'
|
3624 | .split('').sort().join('')
|
3625 |
|
3626 | module.exports = function (chars, exports) {
|
3627 | chars = chars || CHARS
|
3628 | exports = exports || {}
|
3629 | if(chars.length !== 64) throw new Error('a base 64 encoding requires 64 chars')
|
3630 |
|
3631 | var codeToIndex = new Buffer(128)
|
3632 | codeToIndex.fill()
|
3633 |
|
3634 | for(var i = 0; i < 64; i++) {
|
3635 | var code = chars.charCodeAt(i)
|
3636 | codeToIndex[code] = i
|
3637 | }
|
3638 |
|
3639 | exports.encode = function (data) {
|
3640 | var s = '', l = data.length, hang = 0
|
3641 | for(var i = 0; i < l; i++) {
|
3642 | var v = data[i]
|
3643 |
|
3644 | switch (i % 3) {
|
3645 | case 0:
|
3646 | s += chars[v >> 2]
|
3647 | hang = (v & 3) << 4
|
3648 | break;
|
3649 | case 1:
|
3650 | s += chars[hang | v >> 4]
|
3651 | hang = (v & 0xf) << 2
|
3652 | break;
|
3653 | case 2:
|
3654 | s += chars[hang | v >> 6]
|
3655 | s += chars[v & 0x3f]
|
3656 | hang = 0
|
3657 | break;
|
3658 | }
|
3659 |
|
3660 | }
|
3661 | if(l%3) s += chars[hang]
|
3662 | return s
|
3663 | }
|
3664 | exports.decode = function (str) {
|
3665 | var l = str.length, j = 0
|
3666 | var b = new Buffer(~~((l/4)*3)), hang = 0
|
3667 |
|
3668 | for(var i = 0; i < l; i++) {
|
3669 | var v = codeToIndex[str.charCodeAt(i)]
|
3670 |
|
3671 | switch (i % 4) {
|
3672 | case 0:
|
3673 | hang = v << 2;
|
3674 | break;
|
3675 | case 1:
|
3676 | b[j++] = hang | v >> 4
|
3677 | hang = (v << 4) & 0xff
|
3678 | break;
|
3679 | case 2:
|
3680 | b[j++] = hang | v >> 2
|
3681 | hang = (v << 6) & 0xff
|
3682 | break;
|
3683 | case 3:
|
3684 | b[j++] = hang | v
|
3685 | break;
|
3686 | }
|
3687 |
|
3688 | }
|
3689 | return b
|
3690 | }
|
3691 | return exports
|
3692 | }
|
3693 |
|
3694 | module.exports(CHARS, module.exports)
|
3695 |
|
3696 |
|
3697 | },{"12":12}],15:[function(_dereq_,module,exports){
|
3698 |
|
3699 |
|
3700 |
|
3701 |
|
3702 |
|
3703 |
|
3704 |
|
3705 |
|
3706 |
|
3707 |
|
3708 |
|
3709 |
|
3710 |
|
3711 |
|
3712 |
|
3713 |
|
3714 |
|
3715 |
|
3716 |
|
3717 |
|
3718 |
|
3719 | "use strict";
|
3720 | function Deque(capacity) {
|
3721 | this._capacity = getCapacity(capacity);
|
3722 | this._length = 0;
|
3723 | this._front = 0;
|
3724 | if (isArray(capacity)) {
|
3725 | var len = capacity.length;
|
3726 | for (var i = 0; i < len; ++i) {
|
3727 | this[i] = capacity[i];
|
3728 | }
|
3729 | this._length = len;
|
3730 | }
|
3731 | }
|
3732 |
|
3733 | Deque.prototype.toArray = function Deque$toArray() {
|
3734 | var len = this._length;
|
3735 | var ret = new Array(len);
|
3736 | var front = this._front;
|
3737 | var capacity = this._capacity;
|
3738 | for (var j = 0; j < len; ++j) {
|
3739 | ret[j] = this[(front + j) & (capacity - 1)];
|
3740 | }
|
3741 | return ret;
|
3742 | };
|
3743 |
|
3744 | Deque.prototype.push = function Deque$push(item) {
|
3745 | var argsLength = arguments.length;
|
3746 | var length = this._length;
|
3747 | if (argsLength > 1) {
|
3748 | var capacity = this._capacity;
|
3749 | if (length + argsLength > capacity) {
|
3750 | for (var i = 0; i < argsLength; ++i) {
|
3751 | this._checkCapacity(length + 1);
|
3752 | var j = (this._front + length) & (this._capacity - 1);
|
3753 | this[j] = arguments[i];
|
3754 | length++;
|
3755 | this._length = length;
|
3756 | }
|
3757 | return length;
|
3758 | }
|
3759 | else {
|
3760 | var j = this._front;
|
3761 | for (var i = 0; i < argsLength; ++i) {
|
3762 | this[(j + length) & (capacity - 1)] = arguments[i];
|
3763 | j++;
|
3764 | }
|
3765 | this._length = length + argsLength;
|
3766 | return length + argsLength;
|
3767 | }
|
3768 |
|
3769 | }
|
3770 |
|
3771 | if (argsLength === 0) return length;
|
3772 |
|
3773 | this._checkCapacity(length + 1);
|
3774 | var i = (this._front + length) & (this._capacity - 1);
|
3775 | this[i] = item;
|
3776 | this._length = length + 1;
|
3777 | return length + 1;
|
3778 | };
|
3779 |
|
3780 | Deque.prototype.pop = function Deque$pop() {
|
3781 | var length = this._length;
|
3782 | if (length === 0) {
|
3783 | return void 0;
|
3784 | }
|
3785 | var i = (this._front + length - 1) & (this._capacity - 1);
|
3786 | var ret = this[i];
|
3787 | this[i] = void 0;
|
3788 | this._length = length - 1;
|
3789 | return ret;
|
3790 | };
|
3791 |
|
3792 | Deque.prototype.shift = function Deque$shift() {
|
3793 | var length = this._length;
|
3794 | if (length === 0) {
|
3795 | return void 0;
|
3796 | }
|
3797 | var front = this._front;
|
3798 | var ret = this[front];
|
3799 | this[front] = void 0;
|
3800 | this._front = (front + 1) & (this._capacity - 1);
|
3801 | this._length = length - 1;
|
3802 | return ret;
|
3803 | };
|
3804 |
|
3805 | Deque.prototype.unshift = function Deque$unshift(item) {
|
3806 | var length = this._length;
|
3807 | var argsLength = arguments.length;
|
3808 |
|
3809 |
|
3810 | if (argsLength > 1) {
|
3811 | var capacity = this._capacity;
|
3812 | if (length + argsLength > capacity) {
|
3813 | for (var i = argsLength - 1; i >= 0; i--) {
|
3814 | this._checkCapacity(length + 1);
|
3815 | var capacity = this._capacity;
|
3816 | var j = (((( this._front - 1 ) &
|
3817 | ( capacity - 1) ) ^ capacity ) - capacity );
|
3818 | this[j] = arguments[i];
|
3819 | length++;
|
3820 | this._length = length;
|
3821 | this._front = j;
|
3822 | }
|
3823 | return length;
|
3824 | }
|
3825 | else {
|
3826 | var front = this._front;
|
3827 | for (var i = argsLength - 1; i >= 0; i--) {
|
3828 | var j = (((( front - 1 ) &
|
3829 | ( capacity - 1) ) ^ capacity ) - capacity );
|
3830 | this[j] = arguments[i];
|
3831 | front = j;
|
3832 | }
|
3833 | this._front = front;
|
3834 | this._length = length + argsLength;
|
3835 | return length + argsLength;
|
3836 | }
|
3837 | }
|
3838 |
|
3839 | if (argsLength === 0) return length;
|
3840 |
|
3841 | this._checkCapacity(length + 1);
|
3842 | var capacity = this._capacity;
|
3843 | var i = (((( this._front - 1 ) &
|
3844 | ( capacity - 1) ) ^ capacity ) - capacity );
|
3845 | this[i] = item;
|
3846 | this._length = length + 1;
|
3847 | this._front = i;
|
3848 | return length + 1;
|
3849 | };
|
3850 |
|
3851 | Deque.prototype.peekBack = function Deque$peekBack() {
|
3852 | var length = this._length;
|
3853 | if (length === 0) {
|
3854 | return void 0;
|
3855 | }
|
3856 | var index = (this._front + length - 1) & (this._capacity - 1);
|
3857 | return this[index];
|
3858 | };
|
3859 |
|
3860 | Deque.prototype.peekFront = function Deque$peekFront() {
|
3861 | if (this._length === 0) {
|
3862 | return void 0;
|
3863 | }
|
3864 | return this[this._front];
|
3865 | };
|
3866 |
|
3867 | Deque.prototype.get = function Deque$get(index) {
|
3868 | var i = index;
|
3869 | if ((i !== (i | 0))) {
|
3870 | return void 0;
|
3871 | }
|
3872 | var len = this._length;
|
3873 | if (i < 0) {
|
3874 | i = i + len;
|
3875 | }
|
3876 | if (i < 0 || i >= len) {
|
3877 | return void 0;
|
3878 | }
|
3879 | return this[(this._front + i) & (this._capacity - 1)];
|
3880 | };
|
3881 |
|
3882 | Deque.prototype.isEmpty = function Deque$isEmpty() {
|
3883 | return this._length === 0;
|
3884 | };
|
3885 |
|
3886 | Deque.prototype.clear = function Deque$clear() {
|
3887 | var len = this._length;
|
3888 | var front = this._front;
|
3889 | var capacity = this._capacity;
|
3890 | for (var j = 0; j < len; ++j) {
|
3891 | this[(front + j) & (capacity - 1)] = void 0;
|
3892 | }
|
3893 | this._length = 0;
|
3894 | this._front = 0;
|
3895 | };
|
3896 |
|
3897 | Deque.prototype.toString = function Deque$toString() {
|
3898 | return this.toArray().toString();
|
3899 | };
|
3900 |
|
3901 | Deque.prototype.valueOf = Deque.prototype.toString;
|
3902 | Deque.prototype.removeFront = Deque.prototype.shift;
|
3903 | Deque.prototype.removeBack = Deque.prototype.pop;
|
3904 | Deque.prototype.insertFront = Deque.prototype.unshift;
|
3905 | Deque.prototype.insertBack = Deque.prototype.push;
|
3906 | Deque.prototype.enqueue = Deque.prototype.push;
|
3907 | Deque.prototype.dequeue = Deque.prototype.shift;
|
3908 | Deque.prototype.toJSON = Deque.prototype.toArray;
|
3909 |
|
3910 | Object.defineProperty(Deque.prototype, "length", {
|
3911 | get: function() {
|
3912 | return this._length;
|
3913 | },
|
3914 | set: function() {
|
3915 | throw new RangeError("");
|
3916 | }
|
3917 | });
|
3918 |
|
3919 | Deque.prototype._checkCapacity = function Deque$_checkCapacity(size) {
|
3920 | if (this._capacity < size) {
|
3921 | this._resizeTo(getCapacity(this._capacity * 1.5 + 16));
|
3922 | }
|
3923 | };
|
3924 |
|
3925 | Deque.prototype._resizeTo = function Deque$_resizeTo(capacity) {
|
3926 | var oldCapacity = this._capacity;
|
3927 | this._capacity = capacity;
|
3928 | var front = this._front;
|
3929 | var length = this._length;
|
3930 | if (front + length > oldCapacity) {
|
3931 | var moveItemsCount = (front + length) & (oldCapacity - 1);
|
3932 | arrayMove(this, 0, this, oldCapacity, moveItemsCount);
|
3933 | }
|
3934 | };
|
3935 |
|
3936 |
|
3937 | var isArray = Array.isArray;
|
3938 |
|
3939 | function arrayMove(src, srcIndex, dst, dstIndex, len) {
|
3940 | for (var j = 0; j < len; ++j) {
|
3941 | dst[j + dstIndex] = src[j + srcIndex];
|
3942 | src[j + srcIndex] = void 0;
|
3943 | }
|
3944 | }
|
3945 |
|
3946 | function pow2AtLeast(n) {
|
3947 | n = n >>> 0;
|
3948 | n = n - 1;
|
3949 | n = n | (n >> 1);
|
3950 | n = n | (n >> 2);
|
3951 | n = n | (n >> 4);
|
3952 | n = n | (n >> 8);
|
3953 | n = n | (n >> 16);
|
3954 | return n + 1;
|
3955 | }
|
3956 |
|
3957 | function getCapacity(capacity) {
|
3958 | if (typeof capacity !== "number") {
|
3959 | if (isArray(capacity)) {
|
3960 | capacity = capacity.length;
|
3961 | }
|
3962 | else {
|
3963 | return 16;
|
3964 | }
|
3965 | }
|
3966 | return pow2AtLeast(
|
3967 | Math.min(
|
3968 | Math.max(16, capacity), 1073741824)
|
3969 | );
|
3970 | }
|
3971 |
|
3972 | module.exports = Deque;
|
3973 |
|
3974 | },{}],16:[function(_dereq_,module,exports){
|
3975 | var prr = _dereq_(56)
|
3976 |
|
3977 | function init (type, message, cause) {
|
3978 | if (!!message && typeof message != 'string') {
|
3979 | message = message.message || message.name
|
3980 | }
|
3981 | prr(this, {
|
3982 | type : type
|
3983 | , name : type
|
3984 |
|
3985 | , cause : typeof message != 'string' ? message : cause
|
3986 | , message : message
|
3987 | }, 'ewr')
|
3988 | }
|
3989 |
|
3990 |
|
3991 | function CustomError (message, cause) {
|
3992 | Error.call(this)
|
3993 | if (Error.captureStackTrace)
|
3994 | Error.captureStackTrace(this, this.constructor)
|
3995 | init.call(this, 'CustomError', message, cause)
|
3996 | }
|
3997 |
|
3998 | CustomError.prototype = new Error()
|
3999 |
|
4000 | function createError (errno, type, proto) {
|
4001 | var err = function (message, cause) {
|
4002 | init.call(this, type, message, cause)
|
4003 |
|
4004 | if (type == 'FilesystemError') {
|
4005 | this.code = this.cause.code
|
4006 | this.path = this.cause.path
|
4007 | this.errno = this.cause.errno
|
4008 | this.message =
|
4009 | (errno.errno[this.cause.errno]
|
4010 | ? errno.errno[this.cause.errno].description
|
4011 | : this.cause.message)
|
4012 | + (this.cause.path ? ' [' + this.cause.path + ']' : '')
|
4013 | }
|
4014 | Error.call(this)
|
4015 | if (Error.captureStackTrace)
|
4016 | Error.captureStackTrace(this, err)
|
4017 | }
|
4018 | err.prototype = !!proto ? new proto() : new CustomError()
|
4019 | return err
|
4020 | }
|
4021 |
|
4022 | module.exports = function (errno) {
|
4023 | var ce = function (type, proto) {
|
4024 | return createError(errno, type, proto)
|
4025 | }
|
4026 | return {
|
4027 | CustomError : CustomError
|
4028 | , FilesystemError : ce('FilesystemError')
|
4029 | , createError : ce
|
4030 | }
|
4031 | }
|
4032 |
|
4033 | },{"56":56}],17:[function(_dereq_,module,exports){
|
4034 | var all = module.exports.all = [
|
4035 | {
|
4036 | errno: -2,
|
4037 | code: 'ENOENT',
|
4038 | description: 'no such file or directory'
|
4039 | },
|
4040 | {
|
4041 | errno: -1,
|
4042 | code: 'UNKNOWN',
|
4043 | description: 'unknown error'
|
4044 | },
|
4045 | {
|
4046 | errno: 0,
|
4047 | code: 'OK',
|
4048 | description: 'success'
|
4049 | },
|
4050 | {
|
4051 | errno: 1,
|
4052 | code: 'EOF',
|
4053 | description: 'end of file'
|
4054 | },
|
4055 | {
|
4056 | errno: 2,
|
4057 | code: 'EADDRINFO',
|
4058 | description: 'getaddrinfo error'
|
4059 | },
|
4060 | {
|
4061 | errno: 3,
|
4062 | code: 'EACCES',
|
4063 | description: 'permission denied'
|
4064 | },
|
4065 | {
|
4066 | errno: 4,
|
4067 | code: 'EAGAIN',
|
4068 | description: 'resource temporarily unavailable'
|
4069 | },
|
4070 | {
|
4071 | errno: 5,
|
4072 | code: 'EADDRINUSE',
|
4073 | description: 'address already in use'
|
4074 | },
|
4075 | {
|
4076 | errno: 6,
|
4077 | code: 'EADDRNOTAVAIL',
|
4078 | description: 'address not available'
|
4079 | },
|
4080 | {
|
4081 | errno: 7,
|
4082 | code: 'EAFNOSUPPORT',
|
4083 | description: 'address family not supported'
|
4084 | },
|
4085 | {
|
4086 | errno: 8,
|
4087 | code: 'EALREADY',
|
4088 | description: 'connection already in progress'
|
4089 | },
|
4090 | {
|
4091 | errno: 9,
|
4092 | code: 'EBADF',
|
4093 | description: 'bad file descriptor'
|
4094 | },
|
4095 | {
|
4096 | errno: 10,
|
4097 | code: 'EBUSY',
|
4098 | description: 'resource busy or locked'
|
4099 | },
|
4100 | {
|
4101 | errno: 11,
|
4102 | code: 'ECONNABORTED',
|
4103 | description: 'software caused connection abort'
|
4104 | },
|
4105 | {
|
4106 | errno: 12,
|
4107 | code: 'ECONNREFUSED',
|
4108 | description: 'connection refused'
|
4109 | },
|
4110 | {
|
4111 | errno: 13,
|
4112 | code: 'ECONNRESET',
|
4113 | description: 'connection reset by peer'
|
4114 | },
|
4115 | {
|
4116 | errno: 14,
|
4117 | code: 'EDESTADDRREQ',
|
4118 | description: 'destination address required'
|
4119 | },
|
4120 | {
|
4121 | errno: 15,
|
4122 | code: 'EFAULT',
|
4123 | description: 'bad address in system call argument'
|
4124 | },
|
4125 | {
|
4126 | errno: 16,
|
4127 | code: 'EHOSTUNREACH',
|
4128 | description: 'host is unreachable'
|
4129 | },
|
4130 | {
|
4131 | errno: 17,
|
4132 | code: 'EINTR',
|
4133 | description: 'interrupted system call'
|
4134 | },
|
4135 | {
|
4136 | errno: 18,
|
4137 | code: 'EINVAL',
|
4138 | description: 'invalid argument'
|
4139 | },
|
4140 | {
|
4141 | errno: 19,
|
4142 | code: 'EISCONN',
|
4143 | description: 'socket is already connected'
|
4144 | },
|
4145 | {
|
4146 | errno: 20,
|
4147 | code: 'EMFILE',
|
4148 | description: 'too many open files'
|
4149 | },
|
4150 | {
|
4151 | errno: 21,
|
4152 | code: 'EMSGSIZE',
|
4153 | description: 'message too long'
|
4154 | },
|
4155 | {
|
4156 | errno: 22,
|
4157 | code: 'ENETDOWN',
|
4158 | description: 'network is down'
|
4159 | },
|
4160 | {
|
4161 | errno: 23,
|
4162 | code: 'ENETUNREACH',
|
4163 | description: 'network is unreachable'
|
4164 | },
|
4165 | {
|
4166 | errno: 24,
|
4167 | code: 'ENFILE',
|
4168 | description: 'file table overflow'
|
4169 | },
|
4170 | {
|
4171 | errno: 25,
|
4172 | code: 'ENOBUFS',
|
4173 | description: 'no buffer space available'
|
4174 | },
|
4175 | {
|
4176 | errno: 26,
|
4177 | code: 'ENOMEM',
|
4178 | description: 'not enough memory'
|
4179 | },
|
4180 | {
|
4181 | errno: 27,
|
4182 | code: 'ENOTDIR',
|
4183 | description: 'not a directory'
|
4184 | },
|
4185 | {
|
4186 | errno: 28,
|
4187 | code: 'EISDIR',
|
4188 | description: 'illegal operation on a directory'
|
4189 | },
|
4190 | {
|
4191 | errno: 29,
|
4192 | code: 'ENONET',
|
4193 | description: 'machine is not on the network'
|
4194 | },
|
4195 | {
|
4196 | errno: 31,
|
4197 | code: 'ENOTCONN',
|
4198 | description: 'socket is not connected'
|
4199 | },
|
4200 | {
|
4201 | errno: 32,
|
4202 | code: 'ENOTSOCK',
|
4203 | description: 'socket operation on non-socket'
|
4204 | },
|
4205 | {
|
4206 | errno: 33,
|
4207 | code: 'ENOTSUP',
|
4208 | description: 'operation not supported on socket'
|
4209 | },
|
4210 | {
|
4211 | errno: 34,
|
4212 | code: 'ENOENT',
|
4213 | description: 'no such file or directory'
|
4214 | },
|
4215 | {
|
4216 | errno: 35,
|
4217 | code: 'ENOSYS',
|
4218 | description: 'function not implemented'
|
4219 | },
|
4220 | {
|
4221 | errno: 36,
|
4222 | code: 'EPIPE',
|
4223 | description: 'broken pipe'
|
4224 | },
|
4225 | {
|
4226 | errno: 37,
|
4227 | code: 'EPROTO',
|
4228 | description: 'protocol error'
|
4229 | },
|
4230 | {
|
4231 | errno: 38,
|
4232 | code: 'EPROTONOSUPPORT',
|
4233 | description: 'protocol not supported'
|
4234 | },
|
4235 | {
|
4236 | errno: 39,
|
4237 | code: 'EPROTOTYPE',
|
4238 | description: 'protocol wrong type for socket'
|
4239 | },
|
4240 | {
|
4241 | errno: 40,
|
4242 | code: 'ETIMEDOUT',
|
4243 | description: 'connection timed out'
|
4244 | },
|
4245 | {
|
4246 | errno: 41,
|
4247 | code: 'ECHARSET',
|
4248 | description: 'invalid Unicode character'
|
4249 | },
|
4250 | {
|
4251 | errno: 42,
|
4252 | code: 'EAIFAMNOSUPPORT',
|
4253 | description: 'address family for hostname not supported'
|
4254 | },
|
4255 | {
|
4256 | errno: 44,
|
4257 | code: 'EAISERVICE',
|
4258 | description: 'servname not supported for ai_socktype'
|
4259 | },
|
4260 | {
|
4261 | errno: 45,
|
4262 | code: 'EAISOCKTYPE',
|
4263 | description: 'ai_socktype not supported'
|
4264 | },
|
4265 | {
|
4266 | errno: 46,
|
4267 | code: 'ESHUTDOWN',
|
4268 | description: 'cannot send after transport endpoint shutdown'
|
4269 | },
|
4270 | {
|
4271 | errno: 47,
|
4272 | code: 'EEXIST',
|
4273 | description: 'file already exists'
|
4274 | },
|
4275 | {
|
4276 | errno: 48,
|
4277 | code: 'ESRCH',
|
4278 | description: 'no such process'
|
4279 | },
|
4280 | {
|
4281 | errno: 49,
|
4282 | code: 'ENAMETOOLONG',
|
4283 | description: 'name too long'
|
4284 | },
|
4285 | {
|
4286 | errno: 50,
|
4287 | code: 'EPERM',
|
4288 | description: 'operation not permitted'
|
4289 | },
|
4290 | {
|
4291 | errno: 51,
|
4292 | code: 'ELOOP',
|
4293 | description: 'too many symbolic links encountered'
|
4294 | },
|
4295 | {
|
4296 | errno: 52,
|
4297 | code: 'EXDEV',
|
4298 | description: 'cross-device link not permitted'
|
4299 | },
|
4300 | {
|
4301 | errno: 53,
|
4302 | code: 'ENOTEMPTY',
|
4303 | description: 'directory not empty'
|
4304 | },
|
4305 | {
|
4306 | errno: 54,
|
4307 | code: 'ENOSPC',
|
4308 | description: 'no space left on device'
|
4309 | },
|
4310 | {
|
4311 | errno: 55,
|
4312 | code: 'EIO',
|
4313 | description: 'i/o error'
|
4314 | },
|
4315 | {
|
4316 | errno: 56,
|
4317 | code: 'EROFS',
|
4318 | description: 'read-only file system'
|
4319 | },
|
4320 | {
|
4321 | errno: 57,
|
4322 | code: 'ENODEV',
|
4323 | description: 'no such device'
|
4324 | },
|
4325 | {
|
4326 | errno: 58,
|
4327 | code: 'ESPIPE',
|
4328 | description: 'invalid seek'
|
4329 | },
|
4330 | {
|
4331 | errno: 59,
|
4332 | code: 'ECANCELED',
|
4333 | description: 'operation canceled'
|
4334 | }
|
4335 | ]
|
4336 |
|
4337 | module.exports.errno = {}
|
4338 | module.exports.code = {}
|
4339 |
|
4340 | all.forEach(function (error) {
|
4341 | module.exports.errno[error.errno] = error
|
4342 | module.exports.code[error.code] = error
|
4343 | })
|
4344 |
|
4345 | module.exports.custom = _dereq_(16)(module.exports)
|
4346 | module.exports.create = module.exports.custom.createError
|
4347 |
|
4348 | },{"16":16}],18:[function(_dereq_,module,exports){
|
4349 |
|
4350 |
|
4351 |
|
4352 |
|
4353 |
|
4354 |
|
4355 |
|
4356 |
|
4357 |
|
4358 |
|
4359 |
|
4360 |
|
4361 |
|
4362 |
|
4363 |
|
4364 |
|
4365 |
|
4366 |
|
4367 |
|
4368 |
|
4369 |
|
4370 | var objectCreate = Object.create || objectCreatePolyfill
|
4371 | var objectKeys = Object.keys || objectKeysPolyfill
|
4372 | var bind = Function.prototype.bind || functionBindPolyfill
|
4373 |
|
4374 | function EventEmitter() {
|
4375 | if (!this._events || !Object.prototype.hasOwnProperty.call(this, '_events')) {
|
4376 | this._events = objectCreate(null);
|
4377 | this._eventsCount = 0;
|
4378 | }
|
4379 |
|
4380 | this._maxListeners = this._maxListeners || undefined;
|
4381 | }
|
4382 | module.exports = EventEmitter;
|
4383 |
|
4384 |
|
4385 | EventEmitter.EventEmitter = EventEmitter;
|
4386 |
|
4387 | EventEmitter.prototype._events = undefined;
|
4388 | EventEmitter.prototype._maxListeners = undefined;
|
4389 |
|
4390 |
|
4391 |
|
4392 | var defaultMaxListeners = 10;
|
4393 |
|
4394 | var hasDefineProperty;
|
4395 | try {
|
4396 | var o = {};
|
4397 | if (Object.defineProperty) Object.defineProperty(o, 'x', { value: 0 });
|
4398 | hasDefineProperty = o.x === 0;
|
4399 | } catch (err) { hasDefineProperty = false }
|
4400 | if (hasDefineProperty) {
|
4401 | Object.defineProperty(EventEmitter, 'defaultMaxListeners', {
|
4402 | enumerable: true,
|
4403 | get: function() {
|
4404 | return defaultMaxListeners;
|
4405 | },
|
4406 | set: function(arg) {
|
4407 |
|
4408 |
|
4409 | if (typeof arg !== 'number' || arg < 0 || arg !== arg)
|
4410 | throw new TypeError('"defaultMaxListeners" must be a positive number');
|
4411 | defaultMaxListeners = arg;
|
4412 | }
|
4413 | });
|
4414 | } else {
|
4415 | EventEmitter.defaultMaxListeners = defaultMaxListeners;
|
4416 | }
|
4417 |
|
4418 |
|
4419 |
|
4420 | EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
|
4421 | if (typeof n !== 'number' || n < 0 || isNaN(n))
|
4422 | throw new TypeError('"n" argument must be a positive number');
|
4423 | this._maxListeners = n;
|
4424 | return this;
|
4425 | };
|
4426 |
|
4427 | function $getMaxListeners(that) {
|
4428 | if (that._maxListeners === undefined)
|
4429 | return EventEmitter.defaultMaxListeners;
|
4430 | return that._maxListeners;
|
4431 | }
|
4432 |
|
4433 | EventEmitter.prototype.getMaxListeners = function getMaxListeners() {
|
4434 | return $getMaxListeners(this);
|
4435 | };
|
4436 |
|
4437 |
|
4438 |
|
4439 |
|
4440 |
|
4441 |
|
4442 | function emitNone(handler, isFn, self) {
|
4443 | if (isFn)
|
4444 | handler.call(self);
|
4445 | else {
|
4446 | var len = handler.length;
|
4447 | var listeners = arrayClone(handler, len);
|
4448 | for (var i = 0; i < len; ++i)
|
4449 | listeners[i].call(self);
|
4450 | }
|
4451 | }
|
4452 | function emitOne(handler, isFn, self, arg1) {
|
4453 | if (isFn)
|
4454 | handler.call(self, arg1);
|
4455 | else {
|
4456 | var len = handler.length;
|
4457 | var listeners = arrayClone(handler, len);
|
4458 | for (var i = 0; i < len; ++i)
|
4459 | listeners[i].call(self, arg1);
|
4460 | }
|
4461 | }
|
4462 | function emitTwo(handler, isFn, self, arg1, arg2) {
|
4463 | if (isFn)
|
4464 | handler.call(self, arg1, arg2);
|
4465 | else {
|
4466 | var len = handler.length;
|
4467 | var listeners = arrayClone(handler, len);
|
4468 | for (var i = 0; i < len; ++i)
|
4469 | listeners[i].call(self, arg1, arg2);
|
4470 | }
|
4471 | }
|
4472 | function emitThree(handler, isFn, self, arg1, arg2, arg3) {
|
4473 | if (isFn)
|
4474 | handler.call(self, arg1, arg2, arg3);
|
4475 | else {
|
4476 | var len = handler.length;
|
4477 | var listeners = arrayClone(handler, len);
|
4478 | for (var i = 0; i < len; ++i)
|
4479 | listeners[i].call(self, arg1, arg2, arg3);
|
4480 | }
|
4481 | }
|
4482 |
|
4483 | function emitMany(handler, isFn, self, args) {
|
4484 | if (isFn)
|
4485 | handler.apply(self, args);
|
4486 | else {
|
4487 | var len = handler.length;
|
4488 | var listeners = arrayClone(handler, len);
|
4489 | for (var i = 0; i < len; ++i)
|
4490 | listeners[i].apply(self, args);
|
4491 | }
|
4492 | }
|
4493 |
|
4494 | EventEmitter.prototype.emit = function emit(type) {
|
4495 | var er, handler, len, args, i, events;
|
4496 | var doError = (type === 'error');
|
4497 |
|
4498 | events = this._events;
|
4499 | if (events)
|
4500 | doError = (doError && events.error == null);
|
4501 | else if (!doError)
|
4502 | return false;
|
4503 |
|
4504 |
|
4505 | if (doError) {
|
4506 | if (arguments.length > 1)
|
4507 | er = arguments[1];
|
4508 | if (er instanceof Error) {
|
4509 | throw er;
|
4510 | } else {
|
4511 |
|
4512 | var err = new Error('Unhandled "error" event. (' + er + ')');
|
4513 | err.context = er;
|
4514 | throw err;
|
4515 | }
|
4516 | return false;
|
4517 | }
|
4518 |
|
4519 | handler = events[type];
|
4520 |
|
4521 | if (!handler)
|
4522 | return false;
|
4523 |
|
4524 | var isFn = typeof handler === 'function';
|
4525 | len = arguments.length;
|
4526 | switch (len) {
|
4527 |
|
4528 | case 1:
|
4529 | emitNone(handler, isFn, this);
|
4530 | break;
|
4531 | case 2:
|
4532 | emitOne(handler, isFn, this, arguments[1]);
|
4533 | break;
|
4534 | case 3:
|
4535 | emitTwo(handler, isFn, this, arguments[1], arguments[2]);
|
4536 | break;
|
4537 | case 4:
|
4538 | emitThree(handler, isFn, this, arguments[1], arguments[2], arguments[3]);
|
4539 | break;
|
4540 |
|
4541 | default:
|
4542 | args = new Array(len - 1);
|
4543 | for (i = 1; i < len; i++)
|
4544 | args[i - 1] = arguments[i];
|
4545 | emitMany(handler, isFn, this, args);
|
4546 | }
|
4547 |
|
4548 | return true;
|
4549 | };
|
4550 |
|
4551 | function _addListener(target, type, listener, prepend) {
|
4552 | var m;
|
4553 | var events;
|
4554 | var existing;
|
4555 |
|
4556 | if (typeof listener !== 'function')
|
4557 | throw new TypeError('"listener" argument must be a function');
|
4558 |
|
4559 | events = target._events;
|
4560 | if (!events) {
|
4561 | events = target._events = objectCreate(null);
|
4562 | target._eventsCount = 0;
|
4563 | } else {
|
4564 |
|
4565 |
|
4566 | if (events.newListener) {
|
4567 | target.emit('newListener', type,
|
4568 | listener.listener ? listener.listener : listener);
|
4569 |
|
4570 |
|
4571 |
|
4572 | events = target._events;
|
4573 | }
|
4574 | existing = events[type];
|
4575 | }
|
4576 |
|
4577 | if (!existing) {
|
4578 |
|
4579 | existing = events[type] = listener;
|
4580 | ++target._eventsCount;
|
4581 | } else {
|
4582 | if (typeof existing === 'function') {
|
4583 |
|
4584 | existing = events[type] =
|
4585 | prepend ? [listener, existing] : [existing, listener];
|
4586 | } else {
|
4587 |
|
4588 | if (prepend) {
|
4589 | existing.unshift(listener);
|
4590 | } else {
|
4591 | existing.push(listener);
|
4592 | }
|
4593 | }
|
4594 |
|
4595 |
|
4596 | if (!existing.warned) {
|
4597 | m = $getMaxListeners(target);
|
4598 | if (m && m > 0 && existing.length > m) {
|
4599 | existing.warned = true;
|
4600 | var w = new Error('Possible EventEmitter memory leak detected. ' +
|
4601 | existing.length + ' "' + String(type) + '" listeners ' +
|
4602 | 'added. Use emitter.setMaxListeners() to ' +
|
4603 | 'increase limit.');
|
4604 | w.name = 'MaxListenersExceededWarning';
|
4605 | w.emitter = target;
|
4606 | w.type = type;
|
4607 | w.count = existing.length;
|
4608 | if (typeof console === 'object' && console.warn) {
|
4609 | console.warn('%s: %s', w.name, w.message);
|
4610 | }
|
4611 | }
|
4612 | }
|
4613 | }
|
4614 |
|
4615 | return target;
|
4616 | }
|
4617 |
|
4618 | EventEmitter.prototype.addListener = function addListener(type, listener) {
|
4619 | return _addListener(this, type, listener, false);
|
4620 | };
|
4621 |
|
4622 | EventEmitter.prototype.on = EventEmitter.prototype.addListener;
|
4623 |
|
4624 | EventEmitter.prototype.prependListener =
|
4625 | function prependListener(type, listener) {
|
4626 | return _addListener(this, type, listener, true);
|
4627 | };
|
4628 |
|
4629 | function onceWrapper() {
|
4630 | if (!this.fired) {
|
4631 | this.target.removeListener(this.type, this.wrapFn);
|
4632 | this.fired = true;
|
4633 | switch (arguments.length) {
|
4634 | case 0:
|
4635 | return this.listener.call(this.target);
|
4636 | case 1:
|
4637 | return this.listener.call(this.target, arguments[0]);
|
4638 | case 2:
|
4639 | return this.listener.call(this.target, arguments[0], arguments[1]);
|
4640 | case 3:
|
4641 | return this.listener.call(this.target, arguments[0], arguments[1],
|
4642 | arguments[2]);
|
4643 | default:
|
4644 | var args = new Array(arguments.length);
|
4645 | for (var i = 0; i < args.length; ++i)
|
4646 | args[i] = arguments[i];
|
4647 | this.listener.apply(this.target, args);
|
4648 | }
|
4649 | }
|
4650 | }
|
4651 |
|
4652 | function _onceWrap(target, type, listener) {
|
4653 | var state = { fired: false, wrapFn: undefined, target: target, type: type, listener: listener };
|
4654 | var wrapped = bind.call(onceWrapper, state);
|
4655 | wrapped.listener = listener;
|
4656 | state.wrapFn = wrapped;
|
4657 | return wrapped;
|
4658 | }
|
4659 |
|
4660 | EventEmitter.prototype.once = function once(type, listener) {
|
4661 | if (typeof listener !== 'function')
|
4662 | throw new TypeError('"listener" argument must be a function');
|
4663 | this.on(type, _onceWrap(this, type, listener));
|
4664 | return this;
|
4665 | };
|
4666 |
|
4667 | EventEmitter.prototype.prependOnceListener =
|
4668 | function prependOnceListener(type, listener) {
|
4669 | if (typeof listener !== 'function')
|
4670 | throw new TypeError('"listener" argument must be a function');
|
4671 | this.prependListener(type, _onceWrap(this, type, listener));
|
4672 | return this;
|
4673 | };
|
4674 |
|
4675 |
|
4676 | EventEmitter.prototype.removeListener =
|
4677 | function removeListener(type, listener) {
|
4678 | var list, events, position, i, originalListener;
|
4679 |
|
4680 | if (typeof listener !== 'function')
|
4681 | throw new TypeError('"listener" argument must be a function');
|
4682 |
|
4683 | events = this._events;
|
4684 | if (!events)
|
4685 | return this;
|
4686 |
|
4687 | list = events[type];
|
4688 | if (!list)
|
4689 | return this;
|
4690 |
|
4691 | if (list === listener || list.listener === listener) {
|
4692 | if (--this._eventsCount === 0)
|
4693 | this._events = objectCreate(null);
|
4694 | else {
|
4695 | delete events[type];
|
4696 | if (events.removeListener)
|
4697 | this.emit('removeListener', type, list.listener || listener);
|
4698 | }
|
4699 | } else if (typeof list !== 'function') {
|
4700 | position = -1;
|
4701 |
|
4702 | for (i = list.length - 1; i >= 0; i--) {
|
4703 | if (list[i] === listener || list[i].listener === listener) {
|
4704 | originalListener = list[i].listener;
|
4705 | position = i;
|
4706 | break;
|
4707 | }
|
4708 | }
|
4709 |
|
4710 | if (position < 0)
|
4711 | return this;
|
4712 |
|
4713 | if (position === 0)
|
4714 | list.shift();
|
4715 | else
|
4716 | spliceOne(list, position);
|
4717 |
|
4718 | if (list.length === 1)
|
4719 | events[type] = list[0];
|
4720 |
|
4721 | if (events.removeListener)
|
4722 | this.emit('removeListener', type, originalListener || listener);
|
4723 | }
|
4724 |
|
4725 | return this;
|
4726 | };
|
4727 |
|
4728 | EventEmitter.prototype.removeAllListeners =
|
4729 | function removeAllListeners(type) {
|
4730 | var listeners, events, i;
|
4731 |
|
4732 | events = this._events;
|
4733 | if (!events)
|
4734 | return this;
|
4735 |
|
4736 |
|
4737 | if (!events.removeListener) {
|
4738 | if (arguments.length === 0) {
|
4739 | this._events = objectCreate(null);
|
4740 | this._eventsCount = 0;
|
4741 | } else if (events[type]) {
|
4742 | if (--this._eventsCount === 0)
|
4743 | this._events = objectCreate(null);
|
4744 | else
|
4745 | delete events[type];
|
4746 | }
|
4747 | return this;
|
4748 | }
|
4749 |
|
4750 |
|
4751 | if (arguments.length === 0) {
|
4752 | var keys = objectKeys(events);
|
4753 | var key;
|
4754 | for (i = 0; i < keys.length; ++i) {
|
4755 | key = keys[i];
|
4756 | if (key === 'removeListener') continue;
|
4757 | this.removeAllListeners(key);
|
4758 | }
|
4759 | this.removeAllListeners('removeListener');
|
4760 | this._events = objectCreate(null);
|
4761 | this._eventsCount = 0;
|
4762 | return this;
|
4763 | }
|
4764 |
|
4765 | listeners = events[type];
|
4766 |
|
4767 | if (typeof listeners === 'function') {
|
4768 | this.removeListener(type, listeners);
|
4769 | } else if (listeners) {
|
4770 |
|
4771 | for (i = listeners.length - 1; i >= 0; i--) {
|
4772 | this.removeListener(type, listeners[i]);
|
4773 | }
|
4774 | }
|
4775 |
|
4776 | return this;
|
4777 | };
|
4778 |
|
4779 | function _listeners(target, type, unwrap) {
|
4780 | var events = target._events;
|
4781 |
|
4782 | if (!events)
|
4783 | return [];
|
4784 |
|
4785 | var evlistener = events[type];
|
4786 | if (!evlistener)
|
4787 | return [];
|
4788 |
|
4789 | if (typeof evlistener === 'function')
|
4790 | return unwrap ? [evlistener.listener || evlistener] : [evlistener];
|
4791 |
|
4792 | return unwrap ? unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length);
|
4793 | }
|
4794 |
|
4795 | EventEmitter.prototype.listeners = function listeners(type) {
|
4796 | return _listeners(this, type, true);
|
4797 | };
|
4798 |
|
4799 | EventEmitter.prototype.rawListeners = function rawListeners(type) {
|
4800 | return _listeners(this, type, false);
|
4801 | };
|
4802 |
|
4803 | EventEmitter.listenerCount = function(emitter, type) {
|
4804 | if (typeof emitter.listenerCount === 'function') {
|
4805 | return emitter.listenerCount(type);
|
4806 | } else {
|
4807 | return listenerCount.call(emitter, type);
|
4808 | }
|
4809 | };
|
4810 |
|
4811 | EventEmitter.prototype.listenerCount = listenerCount;
|
4812 | function listenerCount(type) {
|
4813 | var events = this._events;
|
4814 |
|
4815 | if (events) {
|
4816 | var evlistener = events[type];
|
4817 |
|
4818 | if (typeof evlistener === 'function') {
|
4819 | return 1;
|
4820 | } else if (evlistener) {
|
4821 | return evlistener.length;
|
4822 | }
|
4823 | }
|
4824 |
|
4825 | return 0;
|
4826 | }
|
4827 |
|
4828 | EventEmitter.prototype.eventNames = function eventNames() {
|
4829 | return this._eventsCount > 0 ? Reflect.ownKeys(this._events) : [];
|
4830 | };
|
4831 |
|
4832 |
|
4833 | function spliceOne(list, index) {
|
4834 | for (var i = index, k = i + 1, n = list.length; k < n; i += 1, k += 1)
|
4835 | list[i] = list[k];
|
4836 | list.pop();
|
4837 | }
|
4838 |
|
4839 | function arrayClone(arr, n) {
|
4840 | var copy = new Array(n);
|
4841 | for (var i = 0; i < n; ++i)
|
4842 | copy[i] = arr[i];
|
4843 | return copy;
|
4844 | }
|
4845 |
|
4846 | function unwrapListeners(arr) {
|
4847 | var ret = new Array(arr.length);
|
4848 | for (var i = 0; i < ret.length; ++i) {
|
4849 | ret[i] = arr[i].listener || arr[i];
|
4850 | }
|
4851 | return ret;
|
4852 | }
|
4853 |
|
4854 | function objectCreatePolyfill(proto) {
|
4855 | var F = function() {};
|
4856 | F.prototype = proto;
|
4857 | return new F;
|
4858 | }
|
4859 | function objectKeysPolyfill(obj) {
|
4860 | var keys = [];
|
4861 | for (var k in obj) if (Object.prototype.hasOwnProperty.call(obj, k)) {
|
4862 | keys.push(k);
|
4863 | }
|
4864 | return k;
|
4865 | }
|
4866 | function functionBindPolyfill(context) {
|
4867 | var fn = this;
|
4868 | return function () {
|
4869 | return fn.apply(context, arguments);
|
4870 | };
|
4871 | }
|
4872 |
|
4873 | },{}],19:[function(_dereq_,module,exports){
|
4874 | (function (process,global){
|
4875 | 'use strict';
|
4876 |
|
4877 |
|
4878 |
|
4879 |
|
4880 |
|
4881 |
|
4882 |
|
4883 |
|
4884 | var STORE = 'fruitdown';
|
4885 |
|
4886 |
|
4887 | var nextTick = global.setImmediate || process.nextTick;
|
4888 |
|
4889 |
|
4890 |
|
4891 | var cachedDBs = {};
|
4892 | var openReqList = {};
|
4893 |
|
4894 | function StorageCore(dbName) {
|
4895 | this._dbName = dbName;
|
4896 | }
|
4897 |
|
4898 | function getDatabase(dbName, callback) {
|
4899 | if (cachedDBs[dbName]) {
|
4900 | return nextTick(function () {
|
4901 | callback(null, cachedDBs[dbName]);
|
4902 | });
|
4903 | }
|
4904 |
|
4905 | var req = indexedDB.open(dbName, 1);
|
4906 |
|
4907 | openReqList[dbName] = req;
|
4908 |
|
4909 | req.onupgradeneeded = function (e) {
|
4910 | var db = e.target.result;
|
4911 |
|
4912 |
|
4913 |
|
4914 | if (e.oldVersion === 1) {
|
4915 | return;
|
4916 | }
|
4917 |
|
4918 |
|
4919 |
|
4920 |
|
4921 |
|
4922 | db.createObjectStore(STORE).createIndex('fakeKey', 'fakeKey');
|
4923 |
|
4924 | };
|
4925 |
|
4926 | req.onsuccess = function (e) {
|
4927 | var db = cachedDBs[dbName] = e.target.result;
|
4928 | callback(null, db);
|
4929 | };
|
4930 |
|
4931 | req.onerror = function(e) {
|
4932 | var msg = 'Failed to open indexedDB, are you in private browsing mode?';
|
4933 | console.error(msg);
|
4934 | callback(e);
|
4935 | };
|
4936 | }
|
4937 |
|
4938 | function openTransactionSafely(db, mode) {
|
4939 | try {
|
4940 | return {
|
4941 | txn: db.transaction(STORE, mode)
|
4942 | };
|
4943 | } catch (err) {
|
4944 | return {
|
4945 | error: err
|
4946 | };
|
4947 | }
|
4948 | }
|
4949 |
|
4950 | StorageCore.prototype.getKeys = function (callback) {
|
4951 | getDatabase(this._dbName, function (err, db) {
|
4952 | if (err) {
|
4953 | return callback(err);
|
4954 | }
|
4955 | var txnRes = openTransactionSafely(db, 'readonly');
|
4956 | if (txnRes.error) {
|
4957 | return callback(txnRes.error);
|
4958 | }
|
4959 | var txn = txnRes.txn;
|
4960 | var store = txn.objectStore(STORE);
|
4961 |
|
4962 | txn.onerror = callback;
|
4963 |
|
4964 | var keys = [];
|
4965 | txn.oncomplete = function () {
|
4966 |
|
4967 |
|
4968 |
|
4969 | callback(null, keys.sort());
|
4970 | };
|
4971 |
|
4972 |
|
4973 |
|
4974 | var req = store.index('fakeKey').openKeyCursor();
|
4975 |
|
4976 | req.onsuccess = function (e) {
|
4977 | var cursor = e.target.result;
|
4978 | if (!cursor) {
|
4979 | return;
|
4980 | }
|
4981 | keys.push(cursor.primaryKey);
|
4982 | cursor.continue();
|
4983 | };
|
4984 | });
|
4985 | };
|
4986 |
|
4987 | StorageCore.prototype.put = function (key, value, callback) {
|
4988 | getDatabase(this._dbName, function (err, db) {
|
4989 | if (err) {
|
4990 | return callback(err);
|
4991 | }
|
4992 | var txnRes = openTransactionSafely(db, 'readwrite');
|
4993 | if (txnRes.error) {
|
4994 | return callback(txnRes.error);
|
4995 | }
|
4996 | var txn = txnRes.txn;
|
4997 | var store = txn.objectStore(STORE);
|
4998 |
|
4999 | var valueToStore = typeof value === 'string' ? value : value.toString();
|
5000 |
|
5001 | txn.onerror = callback;
|
5002 | txn.oncomplete = function () {
|
5003 | callback();
|
5004 | };
|
5005 |
|
5006 | store.put({value: valueToStore, fakeKey: 0}, key);
|
5007 | });
|
5008 | };
|
5009 |
|
5010 | StorageCore.prototype.get = function (key, callback) {
|
5011 | getDatabase(this._dbName, function (err, db) {
|
5012 | if (err) {
|
5013 | return callback(err);
|
5014 | }
|
5015 | var txnRes = openTransactionSafely(db, 'readonly');
|
5016 | if (txnRes.error) {
|
5017 | return callback(txnRes.error);
|
5018 | }
|
5019 | var txn = txnRes.txn;
|
5020 | var store = txn.objectStore(STORE);
|
5021 |
|
5022 | var gotten;
|
5023 | var req = store.get(key);
|
5024 | req.onsuccess = function (e) {
|
5025 | if (e.target.result) {
|
5026 | gotten = e.target.result.value;
|
5027 | }
|
5028 | };
|
5029 |
|
5030 | txn.onerror = callback;
|
5031 | txn.oncomplete = function () {
|
5032 | callback(null, gotten);
|
5033 | };
|
5034 | });
|
5035 | };
|
5036 |
|
5037 | StorageCore.prototype.remove = function (key, callback) {
|
5038 | getDatabase(this._dbName, function (err, db) {
|
5039 | if (err) {
|
5040 | return callback(err);
|
5041 | }
|
5042 | var txnRes = openTransactionSafely(db, 'readwrite');
|
5043 | if (txnRes.error) {
|
5044 | return callback(txnRes.error);
|
5045 | }
|
5046 | var txn = txnRes.txn;
|
5047 | var store = txn.objectStore(STORE);
|
5048 |
|
5049 | store.delete(key);
|
5050 |
|
5051 | txn.onerror = callback;
|
5052 | txn.oncomplete = function () {
|
5053 | callback();
|
5054 | };
|
5055 | });
|
5056 | };
|
5057 |
|
5058 | StorageCore.destroy = function (dbName, callback) {
|
5059 | nextTick(function () {
|
5060 |
|
5061 | if (openReqList[dbName] && openReqList[dbName].result) {
|
5062 | openReqList[dbName].result.close();
|
5063 | delete cachedDBs[dbName];
|
5064 | }
|
5065 | var req = indexedDB.deleteDatabase(dbName);
|
5066 |
|
5067 | req.onsuccess = function () {
|
5068 |
|
5069 | if (openReqList[dbName]) {
|
5070 | openReqList[dbName] = null;
|
5071 | }
|
5072 | callback(null);
|
5073 | };
|
5074 |
|
5075 | req.onerror = callback;
|
5076 | });
|
5077 | };
|
5078 |
|
5079 | module.exports = StorageCore;
|
5080 |
|
5081 | }).call(this,_dereq_(55),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
5082 | },{"55":55}],20:[function(_dereq_,module,exports){
|
5083 | (function (Buffer){
|
5084 | 'use strict';
|
5085 |
|
5086 |
|
5087 |
|
5088 | var arrayBuffPrefix = 'ArrayBuffer:';
|
5089 | var arrayBuffRegex = new RegExp('^' + arrayBuffPrefix);
|
5090 | var uintPrefix = 'Uint8Array:';
|
5091 | var uintRegex = new RegExp('^' + uintPrefix);
|
5092 |
|
5093 |
|
5094 | var bufferPrefix = 'Buff:';
|
5095 | var bufferRegex = new RegExp('^' + bufferPrefix);
|
5096 |
|
5097 | var utils = _dereq_(23);
|
5098 | var DatabaseCore = _dereq_(19);
|
5099 | var TaskQueue = _dereq_(22);
|
5100 | var d64 = _dereq_(14);
|
5101 |
|
5102 | function Database(dbname) {
|
5103 | this._store = new DatabaseCore(dbname);
|
5104 | this._queue = new TaskQueue();
|
5105 | }
|
5106 |
|
5107 | Database.prototype.sequentialize = function (callback, fun) {
|
5108 | this._queue.add(fun, callback);
|
5109 | };
|
5110 |
|
5111 | Database.prototype.init = function (callback) {
|
5112 | var self = this;
|
5113 | self.sequentialize(callback, function (callback) {
|
5114 | self._store.getKeys(function (err, keys) {
|
5115 | if (err) {
|
5116 | return callback(err);
|
5117 | }
|
5118 | self._keys = keys;
|
5119 | return callback();
|
5120 | });
|
5121 | });
|
5122 | };
|
5123 |
|
5124 | Database.prototype.keys = function (callback) {
|
5125 | var self = this;
|
5126 | self.sequentialize(callback, function (callback) {
|
5127 | callback(null, self._keys.slice());
|
5128 | });
|
5129 | };
|
5130 |
|
5131 |
|
5132 | Database.prototype.setItem = function (key, value, callback) {
|
5133 | var self = this;
|
5134 | self.sequentialize(callback, function (callback) {
|
5135 | if (Buffer.isBuffer(value)) {
|
5136 | value = bufferPrefix + d64.encode(value);
|
5137 | }
|
5138 |
|
5139 | var idx = utils.sortedIndexOf(self._keys, key);
|
5140 | if (self._keys[idx] !== key) {
|
5141 | self._keys.splice(idx, 0, key);
|
5142 | }
|
5143 | self._store.put(key, value, callback);
|
5144 | });
|
5145 | };
|
5146 |
|
5147 |
|
5148 | Database.prototype.getItem = function (key, callback) {
|
5149 | var self = this;
|
5150 | self.sequentialize(callback, function (callback) {
|
5151 | self._store.get(key, function (err, retval) {
|
5152 | if (err) {
|
5153 | return callback(err);
|
5154 | }
|
5155 | if (typeof retval === 'undefined' || retval === null) {
|
5156 |
|
5157 | return callback(new Error('NotFound'));
|
5158 | }
|
5159 | if (typeof retval !== 'undefined') {
|
5160 | if (bufferRegex.test(retval)) {
|
5161 | retval = d64.decode(retval.substring(bufferPrefix.length));
|
5162 | } else if (arrayBuffRegex.test(retval)) {
|
5163 |
|
5164 |
|
5165 |
|
5166 | retval = retval.substring(arrayBuffPrefix.length);
|
5167 | retval = new ArrayBuffer(atob(retval).split('').map(function (c) {
|
5168 | return c.charCodeAt(0);
|
5169 | }));
|
5170 | } else if (uintRegex.test(retval)) {
|
5171 |
|
5172 | retval = retval.substring(uintPrefix.length);
|
5173 | retval = new Uint8Array(atob(retval).split('').map(function (c) {
|
5174 | return c.charCodeAt(0);
|
5175 | }));
|
5176 | }
|
5177 | }
|
5178 | callback(null, retval);
|
5179 | });
|
5180 | });
|
5181 | };
|
5182 |
|
5183 |
|
5184 | Database.prototype.removeItem = function (key, callback) {
|
5185 | var self = this;
|
5186 | self.sequentialize(callback, function (callback) {
|
5187 | var idx = utils.sortedIndexOf(self._keys, key);
|
5188 | if (self._keys[idx] === key) {
|
5189 | self._keys.splice(idx, 1);
|
5190 | self._store.remove(key, function (err) {
|
5191 | if (err) {
|
5192 | return callback(err);
|
5193 | }
|
5194 | callback();
|
5195 | });
|
5196 | } else {
|
5197 | callback();
|
5198 | }
|
5199 | });
|
5200 | };
|
5201 |
|
5202 | Database.prototype.length = function (callback) {
|
5203 | var self = this;
|
5204 | self.sequentialize(callback, function (callback) {
|
5205 | callback(null, self._keys.length);
|
5206 | });
|
5207 | };
|
5208 |
|
5209 | module.exports = Database;
|
5210 |
|
5211 | }).call(this,{"isBuffer":_dereq_(27)})
|
5212 | },{"14":14,"19":19,"22":22,"23":23,"27":27}],21:[function(_dereq_,module,exports){
|
5213 | (function (process,global,Buffer){
|
5214 | 'use strict';
|
5215 |
|
5216 | var inherits = _dereq_(26);
|
5217 | var AbstractLevelDOWN = _dereq_(3).AbstractLevelDOWN;
|
5218 | var AbstractIterator = _dereq_(3).AbstractIterator;
|
5219 |
|
5220 | var Database = _dereq_(20);
|
5221 | var DatabaseCore = _dereq_(19);
|
5222 | var utils = _dereq_(23);
|
5223 |
|
5224 |
|
5225 | var nextTick = global.setImmediate || process.nextTick;
|
5226 |
|
5227 | function DatabaseIterator(db, options) {
|
5228 |
|
5229 | AbstractIterator.call(this, db);
|
5230 |
|
5231 | this._reverse = !!options.reverse;
|
5232 | this._endkey = options.end;
|
5233 | this._startkey = options.start;
|
5234 | this._gt = options.gt;
|
5235 | this._gte = options.gte;
|
5236 | this._lt = options.lt;
|
5237 | this._lte = options.lte;
|
5238 | this._exclusiveStart = options.exclusiveStart;
|
5239 | this._limit = options.limit;
|
5240 | this._count = 0;
|
5241 |
|
5242 | this.onInitCompleteListeners = [];
|
5243 | }
|
5244 |
|
5245 | inherits(DatabaseIterator, AbstractIterator);
|
5246 |
|
5247 | DatabaseIterator.prototype._init = function (callback) {
|
5248 | nextTick(function () {
|
5249 | callback();
|
5250 | });
|
5251 | };
|
5252 |
|
5253 | DatabaseIterator.prototype._next = function (callback) {
|
5254 | var self = this;
|
5255 |
|
5256 | function onInitComplete() {
|
5257 | if (self._pos === self._keys.length || self._pos < 0) {
|
5258 | return callback();
|
5259 | }
|
5260 |
|
5261 | var key = self._keys[self._pos];
|
5262 |
|
5263 | if (!!self._endkey && (self._reverse ? key < self._endkey : key > self._endkey)) {
|
5264 | return callback();
|
5265 | }
|
5266 |
|
5267 | if (!!self._limit && self._limit > 0 && self._count++ >= self._limit) {
|
5268 | return callback();
|
5269 | }
|
5270 |
|
5271 | if ((self._lt && key >= self._lt) ||
|
5272 | (self._lte && key > self._lte) ||
|
5273 | (self._gt && key <= self._gt) ||
|
5274 | (self._gte && key < self._gte)) {
|
5275 | return callback();
|
5276 | }
|
5277 |
|
5278 | self._pos += self._reverse ? -1 : 1;
|
5279 | self.db.container.getItem(key, function (err, value) {
|
5280 | if (err) {
|
5281 | if (err.message === 'NotFound') {
|
5282 | return nextTick(function () {
|
5283 | self._next(callback);
|
5284 | });
|
5285 | }
|
5286 | return callback(err);
|
5287 | }
|
5288 | callback(null, key, value);
|
5289 | });
|
5290 | }
|
5291 | if (!self.initStarted) {
|
5292 | self.initStarted = true;
|
5293 | self._init(function (err) {
|
5294 | if (err) {
|
5295 | return callback(err);
|
5296 | }
|
5297 | self.db.container.keys(function (err, keys) {
|
5298 | if (err) {
|
5299 | return callback(err);
|
5300 | }
|
5301 | self._keys = keys;
|
5302 | if (self._startkey) {
|
5303 | var index = utils.sortedIndexOf(self._keys, self._startkey);
|
5304 | var startkey = (index >= self._keys.length || index < 0) ?
|
5305 | undefined : self._keys[index];
|
5306 | self._pos = index;
|
5307 | if (self._reverse) {
|
5308 | if (self._exclusiveStart || startkey !== self._startkey) {
|
5309 | self._pos--;
|
5310 | }
|
5311 | } else if (self._exclusiveStart && startkey === self._startkey) {
|
5312 | self._pos++;
|
5313 | }
|
5314 | } else {
|
5315 | self._pos = self._reverse ? self._keys.length - 1 : 0;
|
5316 | }
|
5317 | onInitComplete();
|
5318 |
|
5319 | self.initCompleted = true;
|
5320 | var i = -1;
|
5321 | while (++i < self.onInitCompleteListeners) {
|
5322 | nextTick(self.onInitCompleteListeners[i]);
|
5323 | }
|
5324 | });
|
5325 | });
|
5326 | } else if (!self.initCompleted) {
|
5327 | self.onInitCompleteListeners.push(onInitComplete);
|
5328 | } else {
|
5329 | onInitComplete();
|
5330 | }
|
5331 | };
|
5332 |
|
5333 | function FruitDown(location) {
|
5334 | if (!(this instanceof FruitDown)) {
|
5335 | return new FruitDown(location);
|
5336 | }
|
5337 | AbstractLevelDOWN.call(this, location);
|
5338 | this.container = new Database(location);
|
5339 | }
|
5340 |
|
5341 | inherits(FruitDown, AbstractLevelDOWN);
|
5342 |
|
5343 | FruitDown.prototype._open = function (options, callback) {
|
5344 | this.container.init(callback);
|
5345 | };
|
5346 |
|
5347 | FruitDown.prototype._put = function (key, value, options, callback) {
|
5348 |
|
5349 | var err = checkKeyValue(key, 'key');
|
5350 |
|
5351 | if (err) {
|
5352 | return nextTick(function () {
|
5353 | callback(err);
|
5354 | });
|
5355 | }
|
5356 |
|
5357 | err = checkKeyValue(value, 'value');
|
5358 |
|
5359 | if (err) {
|
5360 | return nextTick(function () {
|
5361 | callback(err);
|
5362 | });
|
5363 | }
|
5364 |
|
5365 | if (typeof value === 'object' && !Buffer.isBuffer(value) && value.buffer === undefined) {
|
5366 | var obj = {};
|
5367 | obj.storetype = "json";
|
5368 | obj.data = value;
|
5369 | value = JSON.stringify(obj);
|
5370 | }
|
5371 |
|
5372 | this.container.setItem(key, value, callback);
|
5373 | };
|
5374 |
|
5375 | FruitDown.prototype._get = function (key, options, callback) {
|
5376 |
|
5377 | var err = checkKeyValue(key, 'key');
|
5378 |
|
5379 | if (err) {
|
5380 | return nextTick(function () {
|
5381 | callback(err);
|
5382 | });
|
5383 | }
|
5384 |
|
5385 | if (!Buffer.isBuffer(key)) {
|
5386 | key = String(key);
|
5387 | }
|
5388 | this.container.getItem(key, function (err, value) {
|
5389 |
|
5390 | if (err) {
|
5391 | return callback(err);
|
5392 | }
|
5393 |
|
5394 | if (options.asBuffer !== false && !Buffer.isBuffer(value)) {
|
5395 | value = new Buffer(value);
|
5396 | }
|
5397 |
|
5398 |
|
5399 | if (options.asBuffer === false) {
|
5400 | if (value.indexOf("{\"storetype\":\"json\",\"data\"") > -1) {
|
5401 | var res = JSON.parse(value);
|
5402 | value = res.data;
|
5403 | }
|
5404 | }
|
5405 | callback(null, value);
|
5406 | });
|
5407 | };
|
5408 |
|
5409 | FruitDown.prototype._del = function (key, options, callback) {
|
5410 |
|
5411 | var err = checkKeyValue(key, 'key');
|
5412 |
|
5413 | if (err) {
|
5414 | return nextTick(function () {
|
5415 | callback(err);
|
5416 | });
|
5417 | }
|
5418 | if (!Buffer.isBuffer(key)) {
|
5419 | key = String(key);
|
5420 | }
|
5421 |
|
5422 | this.container.removeItem(key, callback);
|
5423 | };
|
5424 |
|
5425 | FruitDown.prototype._batch = function (array, options, callback) {
|
5426 | var self = this;
|
5427 | nextTick(function () {
|
5428 | var err;
|
5429 | var key;
|
5430 | var value;
|
5431 |
|
5432 | var numDone = 0;
|
5433 | var overallErr;
|
5434 | function checkDone() {
|
5435 | if (++numDone === array.length) {
|
5436 | callback(overallErr);
|
5437 | }
|
5438 | }
|
5439 |
|
5440 | if (Array.isArray(array) && array.length) {
|
5441 | for (var i = 0; i < array.length; i++) {
|
5442 | var task = array[i];
|
5443 | if (task) {
|
5444 | key = Buffer.isBuffer(task.key) ? task.key : String(task.key);
|
5445 | err = checkKeyValue(key, 'key');
|
5446 | if (err) {
|
5447 | overallErr = err;
|
5448 | checkDone();
|
5449 | } else if (task.type === 'del') {
|
5450 | self._del(task.key, options, checkDone);
|
5451 | } else if (task.type === 'put') {
|
5452 | value = Buffer.isBuffer(task.value) ? task.value : String(task.value);
|
5453 | err = checkKeyValue(value, 'value');
|
5454 | if (err) {
|
5455 | overallErr = err;
|
5456 | checkDone();
|
5457 | } else {
|
5458 | self._put(key, value, options, checkDone);
|
5459 | }
|
5460 | }
|
5461 | } else {
|
5462 | checkDone();
|
5463 | }
|
5464 | }
|
5465 | } else {
|
5466 | callback();
|
5467 | }
|
5468 | });
|
5469 | };
|
5470 |
|
5471 | FruitDown.prototype._iterator = function (options) {
|
5472 | return new DatabaseIterator(this, options);
|
5473 | };
|
5474 |
|
5475 | FruitDown.destroy = function (name, callback) {
|
5476 | DatabaseCore.destroy(name, callback);
|
5477 | };
|
5478 |
|
5479 | function checkKeyValue(obj, type) {
|
5480 | if (obj === null || obj === undefined) {
|
5481 | return new Error(type + ' cannot be `null` or `undefined`');
|
5482 | }
|
5483 | if (obj === null || obj === undefined) {
|
5484 | return new Error(type + ' cannot be `null` or `undefined`');
|
5485 | }
|
5486 |
|
5487 | if (type === 'key') {
|
5488 |
|
5489 | if (obj instanceof Boolean) {
|
5490 | return new Error(type + ' cannot be `null` or `undefined`');
|
5491 | }
|
5492 | if (obj === '') {
|
5493 | return new Error(type + ' cannot be empty');
|
5494 | }
|
5495 | }
|
5496 | if (obj.toString().indexOf("[object ArrayBuffer]") === 0) {
|
5497 | if (obj.byteLength === 0 || obj.byteLength === undefined) {
|
5498 | return new Error(type + ' cannot be an empty Buffer');
|
5499 | }
|
5500 | }
|
5501 |
|
5502 | if (Buffer.isBuffer(obj)) {
|
5503 | if (obj.length === 0) {
|
5504 | return new Error(type + ' cannot be an empty Buffer');
|
5505 | }
|
5506 | } else if (String(obj) === '') {
|
5507 | return new Error(type + ' cannot be an empty String');
|
5508 | }
|
5509 | }
|
5510 |
|
5511 | module.exports = FruitDown;
|
5512 |
|
5513 | }).call(this,_dereq_(55),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},_dereq_(12).Buffer)
|
5514 | },{"12":12,"19":19,"20":20,"23":23,"26":26,"3":3,"55":55}],22:[function(_dereq_,module,exports){
|
5515 | (function (process,global){
|
5516 | 'use strict';
|
5517 |
|
5518 | var argsarray = _dereq_(4);
|
5519 | var Queue = _dereq_(95);
|
5520 |
|
5521 |
|
5522 | var nextTick = global.setImmediate || process.nextTick;
|
5523 |
|
5524 | function TaskQueue() {
|
5525 | this.queue = new Queue();
|
5526 | this.running = false;
|
5527 | }
|
5528 |
|
5529 | TaskQueue.prototype.add = function (fun, callback) {
|
5530 | this.queue.push({fun: fun, callback: callback});
|
5531 | this.processNext();
|
5532 | };
|
5533 |
|
5534 | TaskQueue.prototype.processNext = function () {
|
5535 | var self = this;
|
5536 | if (self.running || !self.queue.length) {
|
5537 | return;
|
5538 | }
|
5539 | self.running = true;
|
5540 |
|
5541 | var task = self.queue.shift();
|
5542 | nextTick(function () {
|
5543 | task.fun(argsarray(function (args) {
|
5544 | task.callback.apply(null, args);
|
5545 | self.running = false;
|
5546 | self.processNext();
|
5547 | }));
|
5548 | });
|
5549 | };
|
5550 |
|
5551 | module.exports = TaskQueue;
|
5552 |
|
5553 | }).call(this,_dereq_(55),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
5554 | },{"4":4,"55":55,"95":95}],23:[function(_dereq_,module,exports){
|
5555 | 'use strict';
|
5556 |
|
5557 | exports.sortedIndexOf = function(arr, item) {
|
5558 | var low = 0;
|
5559 | var high = arr.length;
|
5560 | var mid;
|
5561 | while (low < high) {
|
5562 | mid = (low + high) >>> 1;
|
5563 | if (arr[mid] < item) {
|
5564 | low = mid + 1;
|
5565 | } else {
|
5566 | high = mid;
|
5567 | }
|
5568 | }
|
5569 | return low;
|
5570 | };
|
5571 |
|
5572 | },{}],24:[function(_dereq_,module,exports){
|
5573 | exports.read = function (buffer, offset, isLE, mLen, nBytes) {
|
5574 | var e, m
|
5575 | var eLen = (nBytes * 8) - mLen - 1
|
5576 | var eMax = (1 << eLen) - 1
|
5577 | var eBias = eMax >> 1
|
5578 | var nBits = -7
|
5579 | var i = isLE ? (nBytes - 1) : 0
|
5580 | var d = isLE ? -1 : 1
|
5581 | var s = buffer[offset + i]
|
5582 |
|
5583 | i += d
|
5584 |
|
5585 | e = s & ((1 << (-nBits)) - 1)
|
5586 | s >>= (-nBits)
|
5587 | nBits += eLen
|
5588 | for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {}
|
5589 |
|
5590 | m = e & ((1 << (-nBits)) - 1)
|
5591 | e >>= (-nBits)
|
5592 | nBits += mLen
|
5593 | for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {}
|
5594 |
|
5595 | if (e === 0) {
|
5596 | e = 1 - eBias
|
5597 | } else if (e === eMax) {
|
5598 | return m ? NaN : ((s ? -1 : 1) * Infinity)
|
5599 | } else {
|
5600 | m = m + Math.pow(2, mLen)
|
5601 | e = e - eBias
|
5602 | }
|
5603 | return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
|
5604 | }
|
5605 |
|
5606 | exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
|
5607 | var e, m, c
|
5608 | var eLen = (nBytes * 8) - mLen - 1
|
5609 | var eMax = (1 << eLen) - 1
|
5610 | var eBias = eMax >> 1
|
5611 | var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
|
5612 | var i = isLE ? 0 : (nBytes - 1)
|
5613 | var d = isLE ? 1 : -1
|
5614 | var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
|
5615 |
|
5616 | value = Math.abs(value)
|
5617 |
|
5618 | if (isNaN(value) || value === Infinity) {
|
5619 | m = isNaN(value) ? 1 : 0
|
5620 | e = eMax
|
5621 | } else {
|
5622 | e = Math.floor(Math.log(value) / Math.LN2)
|
5623 | if (value * (c = Math.pow(2, -e)) < 1) {
|
5624 | e--
|
5625 | c *= 2
|
5626 | }
|
5627 | if (e + eBias >= 1) {
|
5628 | value += rt / c
|
5629 | } else {
|
5630 | value += rt * Math.pow(2, 1 - eBias)
|
5631 | }
|
5632 | if (value * c >= 2) {
|
5633 | e++
|
5634 | c /= 2
|
5635 | }
|
5636 |
|
5637 | if (e + eBias >= eMax) {
|
5638 | m = 0
|
5639 | e = eMax
|
5640 | } else if (e + eBias >= 1) {
|
5641 | m = ((value * c) - 1) * Math.pow(2, mLen)
|
5642 | e = e + eBias
|
5643 | } else {
|
5644 | m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
|
5645 | e = 0
|
5646 | }
|
5647 | }
|
5648 |
|
5649 | for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
|
5650 |
|
5651 | e = (e << mLen) | m
|
5652 | eLen += mLen
|
5653 | for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
|
5654 |
|
5655 | buffer[offset + i - d] |= s * 128
|
5656 | }
|
5657 |
|
5658 | },{}],25:[function(_dereq_,module,exports){
|
5659 | (function (global){
|
5660 | 'use strict';
|
5661 | var Mutation = global.MutationObserver || global.WebKitMutationObserver;
|
5662 |
|
5663 | var scheduleDrain;
|
5664 |
|
5665 | {
|
5666 | if (Mutation) {
|
5667 | var called = 0;
|
5668 | var observer = new Mutation(nextTick);
|
5669 | var element = global.document.createTextNode('');
|
5670 | observer.observe(element, {
|
5671 | characterData: true
|
5672 | });
|
5673 | scheduleDrain = function () {
|
5674 | element.data = (called = ++called % 2);
|
5675 | };
|
5676 | } else if (!global.setImmediate && typeof global.MessageChannel !== 'undefined') {
|
5677 | var channel = new global.MessageChannel();
|
5678 | channel.port1.onmessage = nextTick;
|
5679 | scheduleDrain = function () {
|
5680 | channel.port2.postMessage(0);
|
5681 | };
|
5682 | } else if ('document' in global && 'onreadystatechange' in global.document.createElement('script')) {
|
5683 | scheduleDrain = function () {
|
5684 |
|
5685 |
|
5686 |
|
5687 | var scriptEl = global.document.createElement('script');
|
5688 | scriptEl.onreadystatechange = function () {
|
5689 | nextTick();
|
5690 |
|
5691 | scriptEl.onreadystatechange = null;
|
5692 | scriptEl.parentNode.removeChild(scriptEl);
|
5693 | scriptEl = null;
|
5694 | };
|
5695 | global.document.documentElement.appendChild(scriptEl);
|
5696 | };
|
5697 | } else {
|
5698 | scheduleDrain = function () {
|
5699 | setTimeout(nextTick, 0);
|
5700 | };
|
5701 | }
|
5702 | }
|
5703 |
|
5704 | var draining;
|
5705 | var queue = [];
|
5706 |
|
5707 | function nextTick() {
|
5708 | draining = true;
|
5709 | var i, oldQueue;
|
5710 | var len = queue.length;
|
5711 | while (len) {
|
5712 | oldQueue = queue;
|
5713 | queue = [];
|
5714 | i = -1;
|
5715 | while (++i < len) {
|
5716 | oldQueue[i]();
|
5717 | }
|
5718 | len = queue.length;
|
5719 | }
|
5720 | draining = false;
|
5721 | }
|
5722 |
|
5723 | module.exports = immediate;
|
5724 | function immediate(task) {
|
5725 | if (queue.push(task) === 1 && !draining) {
|
5726 | scheduleDrain();
|
5727 | }
|
5728 | }
|
5729 |
|
5730 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
5731 | },{}],26:[function(_dereq_,module,exports){
|
5732 | arguments[4][6][0].apply(exports,arguments)
|
5733 | },{"6":6}],27:[function(_dereq_,module,exports){
|
5734 |
|
5735 |
|
5736 |
|
5737 |
|
5738 |
|
5739 |
|
5740 |
|
5741 |
|
5742 |
|
5743 | module.exports = function (obj) {
|
5744 | return obj != null && (isBuffer(obj) || isSlowBuffer(obj) || !!obj._isBuffer)
|
5745 | }
|
5746 |
|
5747 | function isBuffer (obj) {
|
5748 | return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)
|
5749 | }
|
5750 |
|
5751 |
|
5752 | function isSlowBuffer (obj) {
|
5753 | return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isBuffer(obj.slice(0, 0))
|
5754 | }
|
5755 |
|
5756 | },{}],28:[function(_dereq_,module,exports){
|
5757 | var toString = {}.toString;
|
5758 |
|
5759 | module.exports = Array.isArray || function (arr) {
|
5760 | return toString.call(arr) == '[object Array]';
|
5761 | };
|
5762 |
|
5763 | },{}],29:[function(_dereq_,module,exports){
|
5764 | var encodings = _dereq_(30);
|
5765 |
|
5766 | module.exports = Codec;
|
5767 |
|
5768 | function Codec(opts){
|
5769 | this.opts = opts || {};
|
5770 | this.encodings = encodings;
|
5771 | }
|
5772 |
|
5773 | Codec.prototype._encoding = function(encoding){
|
5774 | if (typeof encoding == 'string') encoding = encodings[encoding];
|
5775 | if (!encoding) encoding = encodings.id;
|
5776 | return encoding;
|
5777 | };
|
5778 |
|
5779 | Codec.prototype._keyEncoding = function(opts, batchOpts){
|
5780 | return this._encoding(batchOpts && batchOpts.keyEncoding
|
5781 | || opts && opts.keyEncoding
|
5782 | || this.opts.keyEncoding);
|
5783 | };
|
5784 |
|
5785 | Codec.prototype._valueEncoding = function(opts, batchOpts){
|
5786 | return this._encoding(
|
5787 | batchOpts && (batchOpts.valueEncoding || batchOpts.encoding)
|
5788 | || opts && (opts.valueEncoding || opts.encoding)
|
5789 | || (this.opts.valueEncoding || this.opts.encoding));
|
5790 | };
|
5791 |
|
5792 | Codec.prototype.encodeKey = function(key, opts, batchOpts){
|
5793 | return this._keyEncoding(opts, batchOpts).encode(key);
|
5794 | };
|
5795 |
|
5796 | Codec.prototype.encodeValue = function(value, opts, batchOpts){
|
5797 | return this._valueEncoding(opts, batchOpts).encode(value);
|
5798 | };
|
5799 |
|
5800 | Codec.prototype.decodeKey = function(key, opts){
|
5801 | return this._keyEncoding(opts).decode(key);
|
5802 | };
|
5803 |
|
5804 | Codec.prototype.decodeValue = function(value, opts){
|
5805 | return this._valueEncoding(opts).decode(value);
|
5806 | };
|
5807 |
|
5808 | Codec.prototype.encodeBatch = function(ops, opts){
|
5809 | var self = this;
|
5810 |
|
5811 | return ops.map(function(_op){
|
5812 | var op = {
|
5813 | type: _op.type,
|
5814 | key: self.encodeKey(_op.key, opts, _op)
|
5815 | };
|
5816 | if (self.keyAsBuffer(opts, _op)) op.keyEncoding = 'binary';
|
5817 | if (_op.prefix) op.prefix = _op.prefix;
|
5818 | if ('value' in _op) {
|
5819 | op.value = self.encodeValue(_op.value, opts, _op);
|
5820 | if (self.valueAsBuffer(opts, _op)) op.valueEncoding = 'binary';
|
5821 | }
|
5822 | return op;
|
5823 | });
|
5824 | };
|
5825 |
|
5826 | var ltgtKeys = ['lt', 'gt', 'lte', 'gte', 'start', 'end'];
|
5827 |
|
5828 | Codec.prototype.encodeLtgt = function(ltgt){
|
5829 | var self = this;
|
5830 | var ret = {};
|
5831 | Object.keys(ltgt).forEach(function(key){
|
5832 | ret[key] = ltgtKeys.indexOf(key) > -1
|
5833 | ? self.encodeKey(ltgt[key], ltgt)
|
5834 | : ltgt[key]
|
5835 | });
|
5836 | return ret;
|
5837 | };
|
5838 |
|
5839 | Codec.prototype.createStreamDecoder = function(opts){
|
5840 | var self = this;
|
5841 |
|
5842 | if (opts.keys && opts.values) {
|
5843 | return function(key, value){
|
5844 | return {
|
5845 | key: self.decodeKey(key, opts),
|
5846 | value: self.decodeValue(value, opts)
|
5847 | };
|
5848 | };
|
5849 | } else if (opts.keys) {
|
5850 | return function(key) {
|
5851 | return self.decodeKey(key, opts);
|
5852 | };
|
5853 | } else if (opts.values) {
|
5854 | return function(_, value){
|
5855 | return self.decodeValue(value, opts);
|
5856 | }
|
5857 | } else {
|
5858 | return function(){};
|
5859 | }
|
5860 | };
|
5861 |
|
5862 | Codec.prototype.keyAsBuffer = function(opts){
|
5863 | return this._keyEncoding(opts).buffer;
|
5864 | };
|
5865 |
|
5866 | Codec.prototype.valueAsBuffer = function(opts){
|
5867 | return this._valueEncoding(opts).buffer;
|
5868 | };
|
5869 |
|
5870 |
|
5871 | },{"30":30}],30:[function(_dereq_,module,exports){
|
5872 | (function (Buffer){
|
5873 | exports.utf8 = exports['utf-8'] = {
|
5874 | encode: function(data){
|
5875 | return isBinary(data)
|
5876 | ? data
|
5877 | : String(data);
|
5878 | },
|
5879 | decode: function(data){
|
5880 | return typeof data === 'string'
|
5881 | ? data
|
5882 | : String(data)
|
5883 | },
|
5884 | buffer: false,
|
5885 | type: 'utf8'
|
5886 | };
|
5887 |
|
5888 | exports.json = {
|
5889 | encode: JSON.stringify,
|
5890 | decode: JSON.parse,
|
5891 | buffer: false,
|
5892 | type: 'json'
|
5893 | };
|
5894 |
|
5895 | exports.binary = {
|
5896 | encode: function(data){
|
5897 | return isBinary(data)
|
5898 | ? data
|
5899 | : new Buffer(data);
|
5900 | },
|
5901 | decode: identity,
|
5902 | buffer: true,
|
5903 | type: 'binary'
|
5904 | };
|
5905 |
|
5906 | exports.none = {
|
5907 | encode: identity,
|
5908 | decode: identity,
|
5909 | buffer: false,
|
5910 | type: 'id'
|
5911 | };
|
5912 |
|
5913 | exports.id = exports.none;
|
5914 |
|
5915 | var bufferEncodings = [
|
5916 | 'hex',
|
5917 | 'ascii',
|
5918 | 'base64',
|
5919 | 'ucs2',
|
5920 | 'ucs-2',
|
5921 | 'utf16le',
|
5922 | 'utf-16le'
|
5923 | ];
|
5924 |
|
5925 | bufferEncodings.forEach(function(type){
|
5926 | exports[type] = {
|
5927 | encode: function(data){
|
5928 | return isBinary(data)
|
5929 | ? data
|
5930 | : new Buffer(data, type);
|
5931 | },
|
5932 | decode: function(buffer){
|
5933 | return buffer.toString(type);
|
5934 | },
|
5935 | buffer: true,
|
5936 | type: type
|
5937 | };
|
5938 | });
|
5939 |
|
5940 | function identity(value){
|
5941 | return value;
|
5942 | }
|
5943 |
|
5944 | function isBinary(data){
|
5945 | return data === undefined
|
5946 | || data === null
|
5947 | || Buffer.isBuffer(data);
|
5948 | }
|
5949 |
|
5950 | }).call(this,_dereq_(12).Buffer)
|
5951 | },{"12":12}],31:[function(_dereq_,module,exports){
|
5952 | var inherits = _dereq_(26)
|
5953 | var Readable = _dereq_(40).Readable
|
5954 | var extend = _dereq_(41)
|
5955 |
|
5956 | module.exports = ReadStream
|
5957 | inherits(ReadStream, Readable)
|
5958 |
|
5959 | function ReadStream (iterator, options) {
|
5960 | if (!(this instanceof ReadStream)) return new ReadStream(iterator, options)
|
5961 | options = options || {}
|
5962 | Readable.call(this, extend(options, {
|
5963 | objectMode: true
|
5964 | }))
|
5965 | this._iterator = iterator
|
5966 | this._destroyed = false
|
5967 | this._options = options
|
5968 | this.on('end', this._cleanup.bind(this))
|
5969 | }
|
5970 |
|
5971 | ReadStream.prototype._read = function () {
|
5972 | var self = this
|
5973 | var options = this._options
|
5974 | if (this._destroyed) return
|
5975 |
|
5976 | this._iterator.next(function (err, key, value) {
|
5977 | if (self._destroyed) return
|
5978 | if (err) return self.emit('error', err)
|
5979 | if (key === undefined && value === undefined) {
|
5980 | self.push(null)
|
5981 | } else if (options.keys !== false && options.values === false) {
|
5982 | self.push(key)
|
5983 | } else if (options.keys === false && options.values !== false) {
|
5984 | self.push(value)
|
5985 | } else {
|
5986 | self.push({ key: key, value: value })
|
5987 | }
|
5988 | })
|
5989 | }
|
5990 |
|
5991 | ReadStream.prototype.destroy =
|
5992 | ReadStream.prototype._cleanup = function () {
|
5993 | var self = this
|
5994 | if (this._destroyed) return
|
5995 | this._destroyed = true
|
5996 |
|
5997 | this._iterator.end(function (err) {
|
5998 | if (err) return self.emit('error', err)
|
5999 | self.emit('close')
|
6000 | })
|
6001 | }
|
6002 |
|
6003 | },{"26":26,"40":40,"41":41}],32:[function(_dereq_,module,exports){
|
6004 |
|
6005 |
|
6006 |
|
6007 |
|
6008 |
|
6009 |
|
6010 |
|
6011 |
|
6012 |
|
6013 |
|
6014 |
|
6015 |
|
6016 |
|
6017 |
|
6018 |
|
6019 |
|
6020 |
|
6021 |
|
6022 |
|
6023 |
|
6024 |
|
6025 |
|
6026 |
|
6027 |
|
6028 |
|
6029 |
|
6030 | 'use strict';
|
6031 |
|
6032 |
|
6033 |
|
6034 | var pna = _dereq_(54);
|
6035 |
|
6036 |
|
6037 |
|
6038 | var objectKeys = Object.keys || function (obj) {
|
6039 | var keys = [];
|
6040 | for (var key in obj) {
|
6041 | keys.push(key);
|
6042 | }return keys;
|
6043 | };
|
6044 |
|
6045 |
|
6046 | module.exports = Duplex;
|
6047 |
|
6048 |
|
6049 | var util = _dereq_(13);
|
6050 | util.inherits = _dereq_(26);
|
6051 |
|
6052 |
|
6053 | var Readable = _dereq_(34);
|
6054 | var Writable = _dereq_(36);
|
6055 |
|
6056 | util.inherits(Duplex, Readable);
|
6057 |
|
6058 | {
|
6059 |
|
6060 | var keys = objectKeys(Writable.prototype);
|
6061 | for (var v = 0; v < keys.length; v++) {
|
6062 | var method = keys[v];
|
6063 | if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method];
|
6064 | }
|
6065 | }
|
6066 |
|
6067 | function Duplex(options) {
|
6068 | if (!(this instanceof Duplex)) return new Duplex(options);
|
6069 |
|
6070 | Readable.call(this, options);
|
6071 | Writable.call(this, options);
|
6072 |
|
6073 | if (options && options.readable === false) this.readable = false;
|
6074 |
|
6075 | if (options && options.writable === false) this.writable = false;
|
6076 |
|
6077 | this.allowHalfOpen = true;
|
6078 | if (options && options.allowHalfOpen === false) this.allowHalfOpen = false;
|
6079 |
|
6080 | this.once('end', onend);
|
6081 | }
|
6082 |
|
6083 | Object.defineProperty(Duplex.prototype, 'writableHighWaterMark', {
|
6084 |
|
6085 |
|
6086 |
|
6087 | enumerable: false,
|
6088 | get: function () {
|
6089 | return this._writableState.highWaterMark;
|
6090 | }
|
6091 | });
|
6092 |
|
6093 |
|
6094 | function onend() {
|
6095 |
|
6096 |
|
6097 | if (this.allowHalfOpen || this._writableState.ended) return;
|
6098 |
|
6099 |
|
6100 |
|
6101 | pna.nextTick(onEndNT, this);
|
6102 | }
|
6103 |
|
6104 | function onEndNT(self) {
|
6105 | self.end();
|
6106 | }
|
6107 |
|
6108 | Object.defineProperty(Duplex.prototype, 'destroyed', {
|
6109 | get: function () {
|
6110 | if (this._readableState === undefined || this._writableState === undefined) {
|
6111 | return false;
|
6112 | }
|
6113 | return this._readableState.destroyed && this._writableState.destroyed;
|
6114 | },
|
6115 | set: function (value) {
|
6116 |
|
6117 |
|
6118 | if (this._readableState === undefined || this._writableState === undefined) {
|
6119 | return;
|
6120 | }
|
6121 |
|
6122 |
|
6123 |
|
6124 | this._readableState.destroyed = value;
|
6125 | this._writableState.destroyed = value;
|
6126 | }
|
6127 | });
|
6128 |
|
6129 | Duplex.prototype._destroy = function (err, cb) {
|
6130 | this.push(null);
|
6131 | this.end();
|
6132 |
|
6133 | pna.nextTick(cb, err);
|
6134 | };
|
6135 | },{"13":13,"26":26,"34":34,"36":36,"54":54}],33:[function(_dereq_,module,exports){
|
6136 |
|
6137 |
|
6138 |
|
6139 |
|
6140 |
|
6141 |
|
6142 |
|
6143 |
|
6144 |
|
6145 |
|
6146 |
|
6147 |
|
6148 |
|
6149 |
|
6150 |
|
6151 |
|
6152 |
|
6153 |
|
6154 |
|
6155 |
|
6156 |
|
6157 |
|
6158 |
|
6159 |
|
6160 |
|
6161 | 'use strict';
|
6162 |
|
6163 | module.exports = PassThrough;
|
6164 |
|
6165 | var Transform = _dereq_(35);
|
6166 |
|
6167 |
|
6168 | var util = _dereq_(13);
|
6169 | util.inherits = _dereq_(26);
|
6170 |
|
6171 |
|
6172 | util.inherits(PassThrough, Transform);
|
6173 |
|
6174 | function PassThrough(options) {
|
6175 | if (!(this instanceof PassThrough)) return new PassThrough(options);
|
6176 |
|
6177 | Transform.call(this, options);
|
6178 | }
|
6179 |
|
6180 | PassThrough.prototype._transform = function (chunk, encoding, cb) {
|
6181 | cb(null, chunk);
|
6182 | };
|
6183 | },{"13":13,"26":26,"35":35}],34:[function(_dereq_,module,exports){
|
6184 | (function (process,global){
|
6185 |
|
6186 |
|
6187 |
|
6188 |
|
6189 |
|
6190 |
|
6191 |
|
6192 |
|
6193 |
|
6194 |
|
6195 |
|
6196 |
|
6197 |
|
6198 |
|
6199 |
|
6200 |
|
6201 |
|
6202 |
|
6203 |
|
6204 |
|
6205 |
|
6206 | 'use strict';
|
6207 |
|
6208 |
|
6209 |
|
6210 | var pna = _dereq_(54);
|
6211 |
|
6212 |
|
6213 | module.exports = Readable;
|
6214 |
|
6215 |
|
6216 | var isArray = _dereq_(28);
|
6217 |
|
6218 |
|
6219 |
|
6220 | var Duplex;
|
6221 |
|
6222 |
|
6223 | Readable.ReadableState = ReadableState;
|
6224 |
|
6225 |
|
6226 | var EE = _dereq_(18).EventEmitter;
|
6227 |
|
6228 | var EElistenerCount = function (emitter, type) {
|
6229 | return emitter.listeners(type).length;
|
6230 | };
|
6231 |
|
6232 |
|
6233 |
|
6234 | var Stream = _dereq_(39);
|
6235 |
|
6236 |
|
6237 |
|
6238 |
|
6239 | var Buffer = _dereq_(65).Buffer;
|
6240 | var OurUint8Array = global.Uint8Array || function () {};
|
6241 | function _uint8ArrayToBuffer(chunk) {
|
6242 | return Buffer.from(chunk);
|
6243 | }
|
6244 | function _isUint8Array(obj) {
|
6245 | return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
|
6246 | }
|
6247 |
|
6248 |
|
6249 |
|
6250 |
|
6251 | var util = _dereq_(13);
|
6252 | util.inherits = _dereq_(26);
|
6253 |
|
6254 |
|
6255 |
|
6256 | var debugUtil = _dereq_(10);
|
6257 | var debug = void 0;
|
6258 | if (debugUtil && debugUtil.debuglog) {
|
6259 | debug = debugUtil.debuglog('stream');
|
6260 | } else {
|
6261 | debug = function () {};
|
6262 | }
|
6263 |
|
6264 |
|
6265 | var BufferList = _dereq_(37);
|
6266 | var destroyImpl = _dereq_(38);
|
6267 | var StringDecoder;
|
6268 |
|
6269 | util.inherits(Readable, Stream);
|
6270 |
|
6271 | var kProxyEvents = ['error', 'close', 'destroy', 'pause', 'resume'];
|
6272 |
|
6273 | function prependListener(emitter, event, fn) {
|
6274 |
|
6275 |
|
6276 | if (typeof emitter.prependListener === 'function') return emitter.prependListener(event, fn);
|
6277 |
|
6278 |
|
6279 |
|
6280 |
|
6281 |
|
6282 | 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]];
|
6283 | }
|
6284 |
|
6285 | function ReadableState(options, stream) {
|
6286 | Duplex = Duplex || _dereq_(32);
|
6287 |
|
6288 | options = options || {};
|
6289 |
|
6290 |
|
6291 |
|
6292 |
|
6293 |
|
6294 |
|
6295 | var isDuplex = stream instanceof Duplex;
|
6296 |
|
6297 |
|
6298 |
|
6299 | this.objectMode = !!options.objectMode;
|
6300 |
|
6301 | if (isDuplex) this.objectMode = this.objectMode || !!options.readableObjectMode;
|
6302 |
|
6303 |
|
6304 |
|
6305 | var hwm = options.highWaterMark;
|
6306 | var readableHwm = options.readableHighWaterMark;
|
6307 | var defaultHwm = this.objectMode ? 16 : 16 * 1024;
|
6308 |
|
6309 | if (hwm || hwm === 0) this.highWaterMark = hwm;else if (isDuplex && (readableHwm || readableHwm === 0)) this.highWaterMark = readableHwm;else this.highWaterMark = defaultHwm;
|
6310 |
|
6311 |
|
6312 | this.highWaterMark = Math.floor(this.highWaterMark);
|
6313 |
|
6314 |
|
6315 |
|
6316 |
|
6317 | this.buffer = new BufferList();
|
6318 | this.length = 0;
|
6319 | this.pipes = null;
|
6320 | this.pipesCount = 0;
|
6321 | this.flowing = null;
|
6322 | this.ended = false;
|
6323 | this.endEmitted = false;
|
6324 | this.reading = false;
|
6325 |
|
6326 |
|
6327 |
|
6328 |
|
6329 |
|
6330 | this.sync = true;
|
6331 |
|
6332 |
|
6333 |
|
6334 | this.needReadable = false;
|
6335 | this.emittedReadable = false;
|
6336 | this.readableListening = false;
|
6337 | this.resumeScheduled = false;
|
6338 |
|
6339 |
|
6340 | this.destroyed = false;
|
6341 |
|
6342 |
|
6343 |
|
6344 |
|
6345 | this.defaultEncoding = options.defaultEncoding || 'utf8';
|
6346 |
|
6347 |
|
6348 | this.awaitDrain = 0;
|
6349 |
|
6350 |
|
6351 | this.readingMore = false;
|
6352 |
|
6353 | this.decoder = null;
|
6354 | this.encoding = null;
|
6355 | if (options.encoding) {
|
6356 | if (!StringDecoder) StringDecoder = _dereq_(81).StringDecoder;
|
6357 | this.decoder = new StringDecoder(options.encoding);
|
6358 | this.encoding = options.encoding;
|
6359 | }
|
6360 | }
|
6361 |
|
6362 | function Readable(options) {
|
6363 | Duplex = Duplex || _dereq_(32);
|
6364 |
|
6365 | if (!(this instanceof Readable)) return new Readable(options);
|
6366 |
|
6367 | this._readableState = new ReadableState(options, this);
|
6368 |
|
6369 |
|
6370 | this.readable = true;
|
6371 |
|
6372 | if (options) {
|
6373 | if (typeof options.read === 'function') this._read = options.read;
|
6374 |
|
6375 | if (typeof options.destroy === 'function') this._destroy = options.destroy;
|
6376 | }
|
6377 |
|
6378 | Stream.call(this);
|
6379 | }
|
6380 |
|
6381 | Object.defineProperty(Readable.prototype, 'destroyed', {
|
6382 | get: function () {
|
6383 | if (this._readableState === undefined) {
|
6384 | return false;
|
6385 | }
|
6386 | return this._readableState.destroyed;
|
6387 | },
|
6388 | set: function (value) {
|
6389 |
|
6390 |
|
6391 | if (!this._readableState) {
|
6392 | return;
|
6393 | }
|
6394 |
|
6395 |
|
6396 |
|
6397 | this._readableState.destroyed = value;
|
6398 | }
|
6399 | });
|
6400 |
|
6401 | Readable.prototype.destroy = destroyImpl.destroy;
|
6402 | Readable.prototype._undestroy = destroyImpl.undestroy;
|
6403 | Readable.prototype._destroy = function (err, cb) {
|
6404 | this.push(null);
|
6405 | cb(err);
|
6406 | };
|
6407 |
|
6408 |
|
6409 |
|
6410 |
|
6411 |
|
6412 | Readable.prototype.push = function (chunk, encoding) {
|
6413 | var state = this._readableState;
|
6414 | var skipChunkCheck;
|
6415 |
|
6416 | if (!state.objectMode) {
|
6417 | if (typeof chunk === 'string') {
|
6418 | encoding = encoding || state.defaultEncoding;
|
6419 | if (encoding !== state.encoding) {
|
6420 | chunk = Buffer.from(chunk, encoding);
|
6421 | encoding = '';
|
6422 | }
|
6423 | skipChunkCheck = true;
|
6424 | }
|
6425 | } else {
|
6426 | skipChunkCheck = true;
|
6427 | }
|
6428 |
|
6429 | return readableAddChunk(this, chunk, encoding, false, skipChunkCheck);
|
6430 | };
|
6431 |
|
6432 |
|
6433 | Readable.prototype.unshift = function (chunk) {
|
6434 | return readableAddChunk(this, chunk, null, true, false);
|
6435 | };
|
6436 |
|
6437 | function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) {
|
6438 | var state = stream._readableState;
|
6439 | if (chunk === null) {
|
6440 | state.reading = false;
|
6441 | onEofChunk(stream, state);
|
6442 | } else {
|
6443 | var er;
|
6444 | if (!skipChunkCheck) er = chunkInvalid(state, chunk);
|
6445 | if (er) {
|
6446 | stream.emit('error', er);
|
6447 | } else if (state.objectMode || chunk && chunk.length > 0) {
|
6448 | if (typeof chunk !== 'string' && !state.objectMode && Object.getPrototypeOf(chunk) !== Buffer.prototype) {
|
6449 | chunk = _uint8ArrayToBuffer(chunk);
|
6450 | }
|
6451 |
|
6452 | if (addToFront) {
|
6453 | if (state.endEmitted) stream.emit('error', new Error('stream.unshift() after end event'));else addChunk(stream, state, chunk, true);
|
6454 | } else if (state.ended) {
|
6455 | stream.emit('error', new Error('stream.push() after EOF'));
|
6456 | } else {
|
6457 | state.reading = false;
|
6458 | if (state.decoder && !encoding) {
|
6459 | chunk = state.decoder.write(chunk);
|
6460 | if (state.objectMode || chunk.length !== 0) addChunk(stream, state, chunk, false);else maybeReadMore(stream, state);
|
6461 | } else {
|
6462 | addChunk(stream, state, chunk, false);
|
6463 | }
|
6464 | }
|
6465 | } else if (!addToFront) {
|
6466 | state.reading = false;
|
6467 | }
|
6468 | }
|
6469 |
|
6470 | return needMoreData(state);
|
6471 | }
|
6472 |
|
6473 | function addChunk(stream, state, chunk, addToFront) {
|
6474 | if (state.flowing && state.length === 0 && !state.sync) {
|
6475 | stream.emit('data', chunk);
|
6476 | stream.read(0);
|
6477 | } else {
|
6478 |
|
6479 | state.length += state.objectMode ? 1 : chunk.length;
|
6480 | if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk);
|
6481 |
|
6482 | if (state.needReadable) emitReadable(stream);
|
6483 | }
|
6484 | maybeReadMore(stream, state);
|
6485 | }
|
6486 |
|
6487 | function chunkInvalid(state, chunk) {
|
6488 | var er;
|
6489 | if (!_isUint8Array(chunk) && typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
|
6490 | er = new TypeError('Invalid non-string/buffer chunk');
|
6491 | }
|
6492 | return er;
|
6493 | }
|
6494 |
|
6495 |
|
6496 |
|
6497 |
|
6498 |
|
6499 |
|
6500 |
|
6501 |
|
6502 | function needMoreData(state) {
|
6503 | return !state.ended && (state.needReadable || state.length < state.highWaterMark || state.length === 0);
|
6504 | }
|
6505 |
|
6506 | Readable.prototype.isPaused = function () {
|
6507 | return this._readableState.flowing === false;
|
6508 | };
|
6509 |
|
6510 |
|
6511 | Readable.prototype.setEncoding = function (enc) {
|
6512 | if (!StringDecoder) StringDecoder = _dereq_(81).StringDecoder;
|
6513 | this._readableState.decoder = new StringDecoder(enc);
|
6514 | this._readableState.encoding = enc;
|
6515 | return this;
|
6516 | };
|
6517 |
|
6518 |
|
6519 | var MAX_HWM = 0x800000;
|
6520 | function computeNewHighWaterMark(n) {
|
6521 | if (n >= MAX_HWM) {
|
6522 | n = MAX_HWM;
|
6523 | } else {
|
6524 |
|
6525 |
|
6526 | n--;
|
6527 | n |= n >>> 1;
|
6528 | n |= n >>> 2;
|
6529 | n |= n >>> 4;
|
6530 | n |= n >>> 8;
|
6531 | n |= n >>> 16;
|
6532 | n++;
|
6533 | }
|
6534 | return n;
|
6535 | }
|
6536 |
|
6537 |
|
6538 |
|
6539 | function howMuchToRead(n, state) {
|
6540 | if (n <= 0 || state.length === 0 && state.ended) return 0;
|
6541 | if (state.objectMode) return 1;
|
6542 | if (n !== n) {
|
6543 |
|
6544 | if (state.flowing && state.length) return state.buffer.head.data.length;else return state.length;
|
6545 | }
|
6546 |
|
6547 | if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n);
|
6548 | if (n <= state.length) return n;
|
6549 |
|
6550 | if (!state.ended) {
|
6551 | state.needReadable = true;
|
6552 | return 0;
|
6553 | }
|
6554 | return state.length;
|
6555 | }
|
6556 |
|
6557 |
|
6558 | Readable.prototype.read = function (n) {
|
6559 | debug('read', n);
|
6560 | n = parseInt(n, 10);
|
6561 | var state = this._readableState;
|
6562 | var nOrig = n;
|
6563 |
|
6564 | if (n !== 0) state.emittedReadable = false;
|
6565 |
|
6566 |
|
6567 |
|
6568 |
|
6569 | if (n === 0 && state.needReadable && (state.length >= state.highWaterMark || state.ended)) {
|
6570 | debug('read: emitReadable', state.length, state.ended);
|
6571 | if (state.length === 0 && state.ended) endReadable(this);else emitReadable(this);
|
6572 | return null;
|
6573 | }
|
6574 |
|
6575 | n = howMuchToRead(n, state);
|
6576 |
|
6577 |
|
6578 | if (n === 0 && state.ended) {
|
6579 | if (state.length === 0) endReadable(this);
|
6580 | return null;
|
6581 | }
|
6582 |
|
6583 |
|
6584 |
|
6585 |
|
6586 |
|
6587 |
|
6588 |
|
6589 |
|
6590 |
|
6591 |
|
6592 |
|
6593 |
|
6594 |
|
6595 |
|
6596 |
|
6597 |
|
6598 |
|
6599 |
|
6600 |
|
6601 |
|
6602 |
|
6603 |
|
6604 |
|
6605 |
|
6606 | var doRead = state.needReadable;
|
6607 | debug('need readable', doRead);
|
6608 |
|
6609 |
|
6610 | if (state.length === 0 || state.length - n < state.highWaterMark) {
|
6611 | doRead = true;
|
6612 | debug('length less than watermark', doRead);
|
6613 | }
|
6614 |
|
6615 |
|
6616 |
|
6617 | if (state.ended || state.reading) {
|
6618 | doRead = false;
|
6619 | debug('reading or ended', doRead);
|
6620 | } else if (doRead) {
|
6621 | debug('do read');
|
6622 | state.reading = true;
|
6623 | state.sync = true;
|
6624 |
|
6625 | if (state.length === 0) state.needReadable = true;
|
6626 |
|
6627 | this._read(state.highWaterMark);
|
6628 | state.sync = false;
|
6629 |
|
6630 |
|
6631 | if (!state.reading) n = howMuchToRead(nOrig, state);
|
6632 | }
|
6633 |
|
6634 | var ret;
|
6635 | if (n > 0) ret = fromList(n, state);else ret = null;
|
6636 |
|
6637 | if (ret === null) {
|
6638 | state.needReadable = true;
|
6639 | n = 0;
|
6640 | } else {
|
6641 | state.length -= n;
|
6642 | }
|
6643 |
|
6644 | if (state.length === 0) {
|
6645 |
|
6646 |
|
6647 | if (!state.ended) state.needReadable = true;
|
6648 |
|
6649 |
|
6650 | if (nOrig !== n && state.ended) endReadable(this);
|
6651 | }
|
6652 |
|
6653 | if (ret !== null) this.emit('data', ret);
|
6654 |
|
6655 | return ret;
|
6656 | };
|
6657 |
|
6658 | function onEofChunk(stream, state) {
|
6659 | if (state.ended) return;
|
6660 | if (state.decoder) {
|
6661 | var chunk = state.decoder.end();
|
6662 | if (chunk && chunk.length) {
|
6663 | state.buffer.push(chunk);
|
6664 | state.length += state.objectMode ? 1 : chunk.length;
|
6665 | }
|
6666 | }
|
6667 | state.ended = true;
|
6668 |
|
6669 |
|
6670 | emitReadable(stream);
|
6671 | }
|
6672 |
|
6673 |
|
6674 |
|
6675 |
|
6676 | function emitReadable(stream) {
|
6677 | var state = stream._readableState;
|
6678 | state.needReadable = false;
|
6679 | if (!state.emittedReadable) {
|
6680 | debug('emitReadable', state.flowing);
|
6681 | state.emittedReadable = true;
|
6682 | if (state.sync) pna.nextTick(emitReadable_, stream);else emitReadable_(stream);
|
6683 | }
|
6684 | }
|
6685 |
|
6686 | function emitReadable_(stream) {
|
6687 | debug('emit readable');
|
6688 | stream.emit('readable');
|
6689 | flow(stream);
|
6690 | }
|
6691 |
|
6692 |
|
6693 |
|
6694 |
|
6695 |
|
6696 |
|
6697 |
|
6698 | function maybeReadMore(stream, state) {
|
6699 | if (!state.readingMore) {
|
6700 | state.readingMore = true;
|
6701 | pna.nextTick(maybeReadMore_, stream, state);
|
6702 | }
|
6703 | }
|
6704 |
|
6705 | function maybeReadMore_(stream, state) {
|
6706 | var len = state.length;
|
6707 | while (!state.reading && !state.flowing && !state.ended && state.length < state.highWaterMark) {
|
6708 | debug('maybeReadMore read 0');
|
6709 | stream.read(0);
|
6710 | if (len === state.length)
|
6711 |
|
6712 | break;else len = state.length;
|
6713 | }
|
6714 | state.readingMore = false;
|
6715 | }
|
6716 |
|
6717 |
|
6718 |
|
6719 |
|
6720 |
|
6721 | Readable.prototype._read = function (n) {
|
6722 | this.emit('error', new Error('_read() is not implemented'));
|
6723 | };
|
6724 |
|
6725 | Readable.prototype.pipe = function (dest, pipeOpts) {
|
6726 | var src = this;
|
6727 | var state = this._readableState;
|
6728 |
|
6729 | switch (state.pipesCount) {
|
6730 | case 0:
|
6731 | state.pipes = dest;
|
6732 | break;
|
6733 | case 1:
|
6734 | state.pipes = [state.pipes, dest];
|
6735 | break;
|
6736 | default:
|
6737 | state.pipes.push(dest);
|
6738 | break;
|
6739 | }
|
6740 | state.pipesCount += 1;
|
6741 | debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts);
|
6742 |
|
6743 | var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr;
|
6744 |
|
6745 | var endFn = doEnd ? onend : unpipe;
|
6746 | if (state.endEmitted) pna.nextTick(endFn);else src.once('end', endFn);
|
6747 |
|
6748 | dest.on('unpipe', onunpipe);
|
6749 | function onunpipe(readable, unpipeInfo) {
|
6750 | debug('onunpipe');
|
6751 | if (readable === src) {
|
6752 | if (unpipeInfo && unpipeInfo.hasUnpiped === false) {
|
6753 | unpipeInfo.hasUnpiped = true;
|
6754 | cleanup();
|
6755 | }
|
6756 | }
|
6757 | }
|
6758 |
|
6759 | function onend() {
|
6760 | debug('onend');
|
6761 | dest.end();
|
6762 | }
|
6763 |
|
6764 |
|
6765 |
|
6766 |
|
6767 |
|
6768 | var ondrain = pipeOnDrain(src);
|
6769 | dest.on('drain', ondrain);
|
6770 |
|
6771 | var cleanedUp = false;
|
6772 | function cleanup() {
|
6773 | debug('cleanup');
|
6774 |
|
6775 | dest.removeListener('close', onclose);
|
6776 | dest.removeListener('finish', onfinish);
|
6777 | dest.removeListener('drain', ondrain);
|
6778 | dest.removeListener('error', onerror);
|
6779 | dest.removeListener('unpipe', onunpipe);
|
6780 | src.removeListener('end', onend);
|
6781 | src.removeListener('end', unpipe);
|
6782 | src.removeListener('data', ondata);
|
6783 |
|
6784 | cleanedUp = true;
|
6785 |
|
6786 |
|
6787 |
|
6788 |
|
6789 |
|
6790 |
|
6791 | if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain();
|
6792 | }
|
6793 |
|
6794 |
|
6795 |
|
6796 |
|
6797 |
|
6798 | var increasedAwaitDrain = false;
|
6799 | src.on('data', ondata);
|
6800 | function ondata(chunk) {
|
6801 | debug('ondata');
|
6802 | increasedAwaitDrain = false;
|
6803 | var ret = dest.write(chunk);
|
6804 | if (false === ret && !increasedAwaitDrain) {
|
6805 |
|
6806 |
|
6807 |
|
6808 |
|
6809 | if ((state.pipesCount === 1 && state.pipes === dest || state.pipesCount > 1 && indexOf(state.pipes, dest) !== -1) && !cleanedUp) {
|
6810 | debug('false write response, pause', src._readableState.awaitDrain);
|
6811 | src._readableState.awaitDrain++;
|
6812 | increasedAwaitDrain = true;
|
6813 | }
|
6814 | src.pause();
|
6815 | }
|
6816 | }
|
6817 |
|
6818 |
|
6819 |
|
6820 | function onerror(er) {
|
6821 | debug('onerror', er);
|
6822 | unpipe();
|
6823 | dest.removeListener('error', onerror);
|
6824 | if (EElistenerCount(dest, 'error') === 0) dest.emit('error', er);
|
6825 | }
|
6826 |
|
6827 |
|
6828 | prependListener(dest, 'error', onerror);
|
6829 |
|
6830 |
|
6831 | function onclose() {
|
6832 | dest.removeListener('finish', onfinish);
|
6833 | unpipe();
|
6834 | }
|
6835 | dest.once('close', onclose);
|
6836 | function onfinish() {
|
6837 | debug('onfinish');
|
6838 | dest.removeListener('close', onclose);
|
6839 | unpipe();
|
6840 | }
|
6841 | dest.once('finish', onfinish);
|
6842 |
|
6843 | function unpipe() {
|
6844 | debug('unpipe');
|
6845 | src.unpipe(dest);
|
6846 | }
|
6847 |
|
6848 |
|
6849 | dest.emit('pipe', src);
|
6850 |
|
6851 |
|
6852 | if (!state.flowing) {
|
6853 | debug('pipe resume');
|
6854 | src.resume();
|
6855 | }
|
6856 |
|
6857 | return dest;
|
6858 | };
|
6859 |
|
6860 | function pipeOnDrain(src) {
|
6861 | return function () {
|
6862 | var state = src._readableState;
|
6863 | debug('pipeOnDrain', state.awaitDrain);
|
6864 | if (state.awaitDrain) state.awaitDrain--;
|
6865 | if (state.awaitDrain === 0 && EElistenerCount(src, 'data')) {
|
6866 | state.flowing = true;
|
6867 | flow(src);
|
6868 | }
|
6869 | };
|
6870 | }
|
6871 |
|
6872 | Readable.prototype.unpipe = function (dest) {
|
6873 | var state = this._readableState;
|
6874 | var unpipeInfo = { hasUnpiped: false };
|
6875 |
|
6876 |
|
6877 | if (state.pipesCount === 0) return this;
|
6878 |
|
6879 |
|
6880 | if (state.pipesCount === 1) {
|
6881 |
|
6882 | if (dest && dest !== state.pipes) return this;
|
6883 |
|
6884 | if (!dest) dest = state.pipes;
|
6885 |
|
6886 |
|
6887 | state.pipes = null;
|
6888 | state.pipesCount = 0;
|
6889 | state.flowing = false;
|
6890 | if (dest) dest.emit('unpipe', this, unpipeInfo);
|
6891 | return this;
|
6892 | }
|
6893 |
|
6894 |
|
6895 |
|
6896 | if (!dest) {
|
6897 |
|
6898 | var dests = state.pipes;
|
6899 | var len = state.pipesCount;
|
6900 | state.pipes = null;
|
6901 | state.pipesCount = 0;
|
6902 | state.flowing = false;
|
6903 |
|
6904 | for (var i = 0; i < len; i++) {
|
6905 | dests[i].emit('unpipe', this, unpipeInfo);
|
6906 | }return this;
|
6907 | }
|
6908 |
|
6909 |
|
6910 | var index = indexOf(state.pipes, dest);
|
6911 | if (index === -1) return this;
|
6912 |
|
6913 | state.pipes.splice(index, 1);
|
6914 | state.pipesCount -= 1;
|
6915 | if (state.pipesCount === 1) state.pipes = state.pipes[0];
|
6916 |
|
6917 | dest.emit('unpipe', this, unpipeInfo);
|
6918 |
|
6919 | return this;
|
6920 | };
|
6921 |
|
6922 |
|
6923 |
|
6924 | Readable.prototype.on = function (ev, fn) {
|
6925 | var res = Stream.prototype.on.call(this, ev, fn);
|
6926 |
|
6927 | if (ev === 'data') {
|
6928 |
|
6929 | if (this._readableState.flowing !== false) this.resume();
|
6930 | } else if (ev === 'readable') {
|
6931 | var state = this._readableState;
|
6932 | if (!state.endEmitted && !state.readableListening) {
|
6933 | state.readableListening = state.needReadable = true;
|
6934 | state.emittedReadable = false;
|
6935 | if (!state.reading) {
|
6936 | pna.nextTick(nReadingNextTick, this);
|
6937 | } else if (state.length) {
|
6938 | emitReadable(this);
|
6939 | }
|
6940 | }
|
6941 | }
|
6942 |
|
6943 | return res;
|
6944 | };
|
6945 | Readable.prototype.addListener = Readable.prototype.on;
|
6946 |
|
6947 | function nReadingNextTick(self) {
|
6948 | debug('readable nexttick read 0');
|
6949 | self.read(0);
|
6950 | }
|
6951 |
|
6952 |
|
6953 |
|
6954 | Readable.prototype.resume = function () {
|
6955 | var state = this._readableState;
|
6956 | if (!state.flowing) {
|
6957 | debug('resume');
|
6958 | state.flowing = true;
|
6959 | resume(this, state);
|
6960 | }
|
6961 | return this;
|
6962 | };
|
6963 |
|
6964 | function resume(stream, state) {
|
6965 | if (!state.resumeScheduled) {
|
6966 | state.resumeScheduled = true;
|
6967 | pna.nextTick(resume_, stream, state);
|
6968 | }
|
6969 | }
|
6970 |
|
6971 | function resume_(stream, state) {
|
6972 | if (!state.reading) {
|
6973 | debug('resume read 0');
|
6974 | stream.read(0);
|
6975 | }
|
6976 |
|
6977 | state.resumeScheduled = false;
|
6978 | state.awaitDrain = 0;
|
6979 | stream.emit('resume');
|
6980 | flow(stream);
|
6981 | if (state.flowing && !state.reading) stream.read(0);
|
6982 | }
|
6983 |
|
6984 | Readable.prototype.pause = function () {
|
6985 | debug('call pause flowing=%j', this._readableState.flowing);
|
6986 | if (false !== this._readableState.flowing) {
|
6987 | debug('pause');
|
6988 | this._readableState.flowing = false;
|
6989 | this.emit('pause');
|
6990 | }
|
6991 | return this;
|
6992 | };
|
6993 |
|
6994 | function flow(stream) {
|
6995 | var state = stream._readableState;
|
6996 | debug('flow', state.flowing);
|
6997 | while (state.flowing && stream.read() !== null) {}
|
6998 | }
|
6999 |
|
7000 |
|
7001 |
|
7002 |
|
7003 | Readable.prototype.wrap = function (stream) {
|
7004 | var _this = this;
|
7005 |
|
7006 | var state = this._readableState;
|
7007 | var paused = false;
|
7008 |
|
7009 | stream.on('end', function () {
|
7010 | debug('wrapped end');
|
7011 | if (state.decoder && !state.ended) {
|
7012 | var chunk = state.decoder.end();
|
7013 | if (chunk && chunk.length) _this.push(chunk);
|
7014 | }
|
7015 |
|
7016 | _this.push(null);
|
7017 | });
|
7018 |
|
7019 | stream.on('data', function (chunk) {
|
7020 | debug('wrapped data');
|
7021 | if (state.decoder) chunk = state.decoder.write(chunk);
|
7022 |
|
7023 |
|
7024 | if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return;
|
7025 |
|
7026 | var ret = _this.push(chunk);
|
7027 | if (!ret) {
|
7028 | paused = true;
|
7029 | stream.pause();
|
7030 | }
|
7031 | });
|
7032 |
|
7033 |
|
7034 |
|
7035 | for (var i in stream) {
|
7036 | if (this[i] === undefined && typeof stream[i] === 'function') {
|
7037 | this[i] = function (method) {
|
7038 | return function () {
|
7039 | return stream[method].apply(stream, arguments);
|
7040 | };
|
7041 | }(i);
|
7042 | }
|
7043 | }
|
7044 |
|
7045 |
|
7046 | for (var n = 0; n < kProxyEvents.length; n++) {
|
7047 | stream.on(kProxyEvents[n], this.emit.bind(this, kProxyEvents[n]));
|
7048 | }
|
7049 |
|
7050 |
|
7051 |
|
7052 | this._read = function (n) {
|
7053 | debug('wrapped _read', n);
|
7054 | if (paused) {
|
7055 | paused = false;
|
7056 | stream.resume();
|
7057 | }
|
7058 | };
|
7059 |
|
7060 | return this;
|
7061 | };
|
7062 |
|
7063 | Object.defineProperty(Readable.prototype, 'readableHighWaterMark', {
|
7064 |
|
7065 |
|
7066 |
|
7067 | enumerable: false,
|
7068 | get: function () {
|
7069 | return this._readableState.highWaterMark;
|
7070 | }
|
7071 | });
|
7072 |
|
7073 |
|
7074 | Readable._fromList = fromList;
|
7075 |
|
7076 |
|
7077 |
|
7078 |
|
7079 |
|
7080 | function fromList(n, state) {
|
7081 |
|
7082 | if (state.length === 0) return null;
|
7083 |
|
7084 | var ret;
|
7085 | if (state.objectMode) ret = state.buffer.shift();else if (!n || n >= state.length) {
|
7086 |
|
7087 | 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);
|
7088 | state.buffer.clear();
|
7089 | } else {
|
7090 |
|
7091 | ret = fromListPartial(n, state.buffer, state.decoder);
|
7092 | }
|
7093 |
|
7094 | return ret;
|
7095 | }
|
7096 |
|
7097 |
|
7098 |
|
7099 |
|
7100 | function fromListPartial(n, list, hasStrings) {
|
7101 | var ret;
|
7102 | if (n < list.head.data.length) {
|
7103 |
|
7104 | ret = list.head.data.slice(0, n);
|
7105 | list.head.data = list.head.data.slice(n);
|
7106 | } else if (n === list.head.data.length) {
|
7107 |
|
7108 | ret = list.shift();
|
7109 | } else {
|
7110 |
|
7111 | ret = hasStrings ? copyFromBufferString(n, list) : copyFromBuffer(n, list);
|
7112 | }
|
7113 | return ret;
|
7114 | }
|
7115 |
|
7116 |
|
7117 |
|
7118 |
|
7119 |
|
7120 | function copyFromBufferString(n, list) {
|
7121 | var p = list.head;
|
7122 | var c = 1;
|
7123 | var ret = p.data;
|
7124 | n -= ret.length;
|
7125 | while (p = p.next) {
|
7126 | var str = p.data;
|
7127 | var nb = n > str.length ? str.length : n;
|
7128 | if (nb === str.length) ret += str;else ret += str.slice(0, n);
|
7129 | n -= nb;
|
7130 | if (n === 0) {
|
7131 | if (nb === str.length) {
|
7132 | ++c;
|
7133 | if (p.next) list.head = p.next;else list.head = list.tail = null;
|
7134 | } else {
|
7135 | list.head = p;
|
7136 | p.data = str.slice(nb);
|
7137 | }
|
7138 | break;
|
7139 | }
|
7140 | ++c;
|
7141 | }
|
7142 | list.length -= c;
|
7143 | return ret;
|
7144 | }
|
7145 |
|
7146 |
|
7147 |
|
7148 |
|
7149 | function copyFromBuffer(n, list) {
|
7150 | var ret = Buffer.allocUnsafe(n);
|
7151 | var p = list.head;
|
7152 | var c = 1;
|
7153 | p.data.copy(ret);
|
7154 | n -= p.data.length;
|
7155 | while (p = p.next) {
|
7156 | var buf = p.data;
|
7157 | var nb = n > buf.length ? buf.length : n;
|
7158 | buf.copy(ret, ret.length - n, 0, nb);
|
7159 | n -= nb;
|
7160 | if (n === 0) {
|
7161 | if (nb === buf.length) {
|
7162 | ++c;
|
7163 | if (p.next) list.head = p.next;else list.head = list.tail = null;
|
7164 | } else {
|
7165 | list.head = p;
|
7166 | p.data = buf.slice(nb);
|
7167 | }
|
7168 | break;
|
7169 | }
|
7170 | ++c;
|
7171 | }
|
7172 | list.length -= c;
|
7173 | return ret;
|
7174 | }
|
7175 |
|
7176 | function endReadable(stream) {
|
7177 | var state = stream._readableState;
|
7178 |
|
7179 |
|
7180 |
|
7181 | if (state.length > 0) throw new Error('"endReadable()" called on non-empty stream');
|
7182 |
|
7183 | if (!state.endEmitted) {
|
7184 | state.ended = true;
|
7185 | pna.nextTick(endReadableNT, state, stream);
|
7186 | }
|
7187 | }
|
7188 |
|
7189 | function endReadableNT(state, stream) {
|
7190 |
|
7191 | if (!state.endEmitted && state.length === 0) {
|
7192 | state.endEmitted = true;
|
7193 | stream.readable = false;
|
7194 | stream.emit('end');
|
7195 | }
|
7196 | }
|
7197 |
|
7198 | function indexOf(xs, x) {
|
7199 | for (var i = 0, l = xs.length; i < l; i++) {
|
7200 | if (xs[i] === x) return i;
|
7201 | }
|
7202 | return -1;
|
7203 | }
|
7204 | }).call(this,_dereq_(55),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
7205 | },{"10":10,"13":13,"18":18,"26":26,"28":28,"32":32,"37":37,"38":38,"39":39,"54":54,"55":55,"65":65,"81":81}],35:[function(_dereq_,module,exports){
|
7206 |
|
7207 |
|
7208 |
|
7209 |
|
7210 |
|
7211 |
|
7212 |
|
7213 |
|
7214 |
|
7215 |
|
7216 |
|
7217 |
|
7218 |
|
7219 |
|
7220 |
|
7221 |
|
7222 |
|
7223 |
|
7224 |
|
7225 |
|
7226 |
|
7227 |
|
7228 |
|
7229 |
|
7230 |
|
7231 |
|
7232 |
|
7233 |
|
7234 |
|
7235 |
|
7236 |
|
7237 |
|
7238 |
|
7239 |
|
7240 |
|
7241 |
|
7242 |
|
7243 |
|
7244 |
|
7245 |
|
7246 |
|
7247 |
|
7248 |
|
7249 |
|
7250 |
|
7251 |
|
7252 |
|
7253 |
|
7254 |
|
7255 |
|
7256 |
|
7257 |
|
7258 |
|
7259 |
|
7260 |
|
7261 |
|
7262 |
|
7263 |
|
7264 |
|
7265 |
|
7266 |
|
7267 |
|
7268 |
|
7269 | 'use strict';
|
7270 |
|
7271 | module.exports = Transform;
|
7272 |
|
7273 | var Duplex = _dereq_(32);
|
7274 |
|
7275 |
|
7276 | var util = _dereq_(13);
|
7277 | util.inherits = _dereq_(26);
|
7278 |
|
7279 |
|
7280 | util.inherits(Transform, Duplex);
|
7281 |
|
7282 | function afterTransform(er, data) {
|
7283 | var ts = this._transformState;
|
7284 | ts.transforming = false;
|
7285 |
|
7286 | var cb = ts.writecb;
|
7287 |
|
7288 | if (!cb) {
|
7289 | return this.emit('error', new Error('write callback called multiple times'));
|
7290 | }
|
7291 |
|
7292 | ts.writechunk = null;
|
7293 | ts.writecb = null;
|
7294 |
|
7295 | if (data != null)
|
7296 | this.push(data);
|
7297 |
|
7298 | cb(er);
|
7299 |
|
7300 | var rs = this._readableState;
|
7301 | rs.reading = false;
|
7302 | if (rs.needReadable || rs.length < rs.highWaterMark) {
|
7303 | this._read(rs.highWaterMark);
|
7304 | }
|
7305 | }
|
7306 |
|
7307 | function Transform(options) {
|
7308 | if (!(this instanceof Transform)) return new Transform(options);
|
7309 |
|
7310 | Duplex.call(this, options);
|
7311 |
|
7312 | this._transformState = {
|
7313 | afterTransform: afterTransform.bind(this),
|
7314 | needTransform: false,
|
7315 | transforming: false,
|
7316 | writecb: null,
|
7317 | writechunk: null,
|
7318 | writeencoding: null
|
7319 | };
|
7320 |
|
7321 |
|
7322 | this._readableState.needReadable = true;
|
7323 |
|
7324 |
|
7325 |
|
7326 |
|
7327 | this._readableState.sync = false;
|
7328 |
|
7329 | if (options) {
|
7330 | if (typeof options.transform === 'function') this._transform = options.transform;
|
7331 |
|
7332 | if (typeof options.flush === 'function') this._flush = options.flush;
|
7333 | }
|
7334 |
|
7335 |
|
7336 | this.on('prefinish', prefinish);
|
7337 | }
|
7338 |
|
7339 | function prefinish() {
|
7340 | var _this = this;
|
7341 |
|
7342 | if (typeof this._flush === 'function') {
|
7343 | this._flush(function (er, data) {
|
7344 | done(_this, er, data);
|
7345 | });
|
7346 | } else {
|
7347 | done(this, null, null);
|
7348 | }
|
7349 | }
|
7350 |
|
7351 | Transform.prototype.push = function (chunk, encoding) {
|
7352 | this._transformState.needTransform = false;
|
7353 | return Duplex.prototype.push.call(this, chunk, encoding);
|
7354 | };
|
7355 |
|
7356 |
|
7357 |
|
7358 |
|
7359 |
|
7360 |
|
7361 |
|
7362 |
|
7363 |
|
7364 |
|
7365 |
|
7366 | Transform.prototype._transform = function (chunk, encoding, cb) {
|
7367 | throw new Error('_transform() is not implemented');
|
7368 | };
|
7369 |
|
7370 | Transform.prototype._write = function (chunk, encoding, cb) {
|
7371 | var ts = this._transformState;
|
7372 | ts.writecb = cb;
|
7373 | ts.writechunk = chunk;
|
7374 | ts.writeencoding = encoding;
|
7375 | if (!ts.transforming) {
|
7376 | var rs = this._readableState;
|
7377 | if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) this._read(rs.highWaterMark);
|
7378 | }
|
7379 | };
|
7380 |
|
7381 |
|
7382 |
|
7383 |
|
7384 | Transform.prototype._read = function (n) {
|
7385 | var ts = this._transformState;
|
7386 |
|
7387 | if (ts.writechunk !== null && ts.writecb && !ts.transforming) {
|
7388 | ts.transforming = true;
|
7389 | this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
|
7390 | } else {
|
7391 |
|
7392 |
|
7393 | ts.needTransform = true;
|
7394 | }
|
7395 | };
|
7396 |
|
7397 | Transform.prototype._destroy = function (err, cb) {
|
7398 | var _this2 = this;
|
7399 |
|
7400 | Duplex.prototype._destroy.call(this, err, function (err2) {
|
7401 | cb(err2);
|
7402 | _this2.emit('close');
|
7403 | });
|
7404 | };
|
7405 |
|
7406 | function done(stream, er, data) {
|
7407 | if (er) return stream.emit('error', er);
|
7408 |
|
7409 | if (data != null)
|
7410 | stream.push(data);
|
7411 |
|
7412 |
|
7413 |
|
7414 | if (stream._writableState.length) throw new Error('Calling transform done when ws.length != 0');
|
7415 |
|
7416 | if (stream._transformState.transforming) throw new Error('Calling transform done when still transforming');
|
7417 |
|
7418 | return stream.push(null);
|
7419 | }
|
7420 | },{"13":13,"26":26,"32":32}],36:[function(_dereq_,module,exports){
|
7421 | (function (process,global,setImmediate){
|
7422 |
|
7423 |
|
7424 |
|
7425 |
|
7426 |
|
7427 |
|
7428 |
|
7429 |
|
7430 |
|
7431 |
|
7432 |
|
7433 |
|
7434 |
|
7435 |
|
7436 |
|
7437 |
|
7438 |
|
7439 |
|
7440 |
|
7441 |
|
7442 |
|
7443 |
|
7444 |
|
7445 |
|
7446 |
|
7447 | 'use strict';
|
7448 |
|
7449 |
|
7450 |
|
7451 | var pna = _dereq_(54);
|
7452 |
|
7453 |
|
7454 | module.exports = Writable;
|
7455 |
|
7456 |
|
7457 | function WriteReq(chunk, encoding, cb) {
|
7458 | this.chunk = chunk;
|
7459 | this.encoding = encoding;
|
7460 | this.callback = cb;
|
7461 | this.next = null;
|
7462 | }
|
7463 |
|
7464 |
|
7465 |
|
7466 | function CorkedRequest(state) {
|
7467 | var _this = this;
|
7468 |
|
7469 | this.next = null;
|
7470 | this.entry = null;
|
7471 | this.finish = function () {
|
7472 | onCorkedFinish(_this, state);
|
7473 | };
|
7474 | }
|
7475 |
|
7476 |
|
7477 |
|
7478 | var asyncWrite = !process.browser && ['v0.10', 'v0.9.'].indexOf(process.version.slice(0, 5)) > -1 ? setImmediate : pna.nextTick;
|
7479 |
|
7480 |
|
7481 |
|
7482 | var Duplex;
|
7483 |
|
7484 |
|
7485 | Writable.WritableState = WritableState;
|
7486 |
|
7487 |
|
7488 | var util = _dereq_(13);
|
7489 | util.inherits = _dereq_(26);
|
7490 |
|
7491 |
|
7492 |
|
7493 | var internalUtil = {
|
7494 | deprecate: _dereq_(96)
|
7495 | };
|
7496 |
|
7497 |
|
7498 |
|
7499 | var Stream = _dereq_(39);
|
7500 |
|
7501 |
|
7502 |
|
7503 |
|
7504 | var Buffer = _dereq_(65).Buffer;
|
7505 | var OurUint8Array = global.Uint8Array || function () {};
|
7506 | function _uint8ArrayToBuffer(chunk) {
|
7507 | return Buffer.from(chunk);
|
7508 | }
|
7509 | function _isUint8Array(obj) {
|
7510 | return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
|
7511 | }
|
7512 |
|
7513 |
|
7514 |
|
7515 | var destroyImpl = _dereq_(38);
|
7516 |
|
7517 | util.inherits(Writable, Stream);
|
7518 |
|
7519 | function nop() {}
|
7520 |
|
7521 | function WritableState(options, stream) {
|
7522 | Duplex = Duplex || _dereq_(32);
|
7523 |
|
7524 | options = options || {};
|
7525 |
|
7526 |
|
7527 |
|
7528 |
|
7529 |
|
7530 |
|
7531 | var isDuplex = stream instanceof Duplex;
|
7532 |
|
7533 |
|
7534 |
|
7535 | this.objectMode = !!options.objectMode;
|
7536 |
|
7537 | if (isDuplex) this.objectMode = this.objectMode || !!options.writableObjectMode;
|
7538 |
|
7539 |
|
7540 |
|
7541 |
|
7542 | var hwm = options.highWaterMark;
|
7543 | var writableHwm = options.writableHighWaterMark;
|
7544 | var defaultHwm = this.objectMode ? 16 : 16 * 1024;
|
7545 |
|
7546 | if (hwm || hwm === 0) this.highWaterMark = hwm;else if (isDuplex && (writableHwm || writableHwm === 0)) this.highWaterMark = writableHwm;else this.highWaterMark = defaultHwm;
|
7547 |
|
7548 |
|
7549 | this.highWaterMark = Math.floor(this.highWaterMark);
|
7550 |
|
7551 |
|
7552 | this.finalCalled = false;
|
7553 |
|
7554 |
|
7555 | this.needDrain = false;
|
7556 |
|
7557 | this.ending = false;
|
7558 |
|
7559 | this.ended = false;
|
7560 |
|
7561 | this.finished = false;
|
7562 |
|
7563 |
|
7564 | this.destroyed = false;
|
7565 |
|
7566 |
|
7567 |
|
7568 |
|
7569 | var noDecode = options.decodeStrings === false;
|
7570 | this.decodeStrings = !noDecode;
|
7571 |
|
7572 |
|
7573 |
|
7574 |
|
7575 | this.defaultEncoding = options.defaultEncoding || 'utf8';
|
7576 |
|
7577 |
|
7578 |
|
7579 |
|
7580 | this.length = 0;
|
7581 |
|
7582 |
|
7583 | this.writing = false;
|
7584 |
|
7585 |
|
7586 | this.corked = 0;
|
7587 |
|
7588 |
|
7589 |
|
7590 |
|
7591 |
|
7592 | this.sync = true;
|
7593 |
|
7594 |
|
7595 |
|
7596 |
|
7597 | this.bufferProcessing = false;
|
7598 |
|
7599 |
|
7600 | this.onwrite = function (er) {
|
7601 | onwrite(stream, er);
|
7602 | };
|
7603 |
|
7604 |
|
7605 | this.writecb = null;
|
7606 |
|
7607 |
|
7608 | this.writelen = 0;
|
7609 |
|
7610 | this.bufferedRequest = null;
|
7611 | this.lastBufferedRequest = null;
|
7612 |
|
7613 |
|
7614 |
|
7615 | this.pendingcb = 0;
|
7616 |
|
7617 |
|
7618 |
|
7619 | this.prefinished = false;
|
7620 |
|
7621 |
|
7622 | this.errorEmitted = false;
|
7623 |
|
7624 |
|
7625 | this.bufferedRequestCount = 0;
|
7626 |
|
7627 |
|
7628 |
|
7629 | this.corkedRequestsFree = new CorkedRequest(this);
|
7630 | }
|
7631 |
|
7632 | WritableState.prototype.getBuffer = function getBuffer() {
|
7633 | var current = this.bufferedRequest;
|
7634 | var out = [];
|
7635 | while (current) {
|
7636 | out.push(current);
|
7637 | current = current.next;
|
7638 | }
|
7639 | return out;
|
7640 | };
|
7641 |
|
7642 | (function () {
|
7643 | try {
|
7644 | Object.defineProperty(WritableState.prototype, 'buffer', {
|
7645 | get: internalUtil.deprecate(function () {
|
7646 | return this.getBuffer();
|
7647 | }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.', 'DEP0003')
|
7648 | });
|
7649 | } catch (_) {}
|
7650 | })();
|
7651 |
|
7652 |
|
7653 |
|
7654 | var realHasInstance;
|
7655 | if (typeof Symbol === 'function' && Symbol.hasInstance && typeof Function.prototype[Symbol.hasInstance] === 'function') {
|
7656 | realHasInstance = Function.prototype[Symbol.hasInstance];
|
7657 | Object.defineProperty(Writable, Symbol.hasInstance, {
|
7658 | value: function (object) {
|
7659 | if (realHasInstance.call(this, object)) return true;
|
7660 | if (this !== Writable) return false;
|
7661 |
|
7662 | return object && object._writableState instanceof WritableState;
|
7663 | }
|
7664 | });
|
7665 | } else {
|
7666 | realHasInstance = function (object) {
|
7667 | return object instanceof this;
|
7668 | };
|
7669 | }
|
7670 |
|
7671 | function Writable(options) {
|
7672 | Duplex = Duplex || _dereq_(32);
|
7673 |
|
7674 |
|
7675 |
|
7676 |
|
7677 |
|
7678 |
|
7679 |
|
7680 |
|
7681 | if (!realHasInstance.call(Writable, this) && !(this instanceof Duplex)) {
|
7682 | return new Writable(options);
|
7683 | }
|
7684 |
|
7685 | this._writableState = new WritableState(options, this);
|
7686 |
|
7687 |
|
7688 | this.writable = true;
|
7689 |
|
7690 | if (options) {
|
7691 | if (typeof options.write === 'function') this._write = options.write;
|
7692 |
|
7693 | if (typeof options.writev === 'function') this._writev = options.writev;
|
7694 |
|
7695 | if (typeof options.destroy === 'function') this._destroy = options.destroy;
|
7696 |
|
7697 | if (typeof options.final === 'function') this._final = options.final;
|
7698 | }
|
7699 |
|
7700 | Stream.call(this);
|
7701 | }
|
7702 |
|
7703 |
|
7704 | Writable.prototype.pipe = function () {
|
7705 | this.emit('error', new Error('Cannot pipe, not readable'));
|
7706 | };
|
7707 |
|
7708 | function writeAfterEnd(stream, cb) {
|
7709 | var er = new Error('write after end');
|
7710 |
|
7711 | stream.emit('error', er);
|
7712 | pna.nextTick(cb, er);
|
7713 | }
|
7714 |
|
7715 |
|
7716 |
|
7717 |
|
7718 | function validChunk(stream, state, chunk, cb) {
|
7719 | var valid = true;
|
7720 | var er = false;
|
7721 |
|
7722 | if (chunk === null) {
|
7723 | er = new TypeError('May not write null values to stream');
|
7724 | } else if (typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
|
7725 | er = new TypeError('Invalid non-string/buffer chunk');
|
7726 | }
|
7727 | if (er) {
|
7728 | stream.emit('error', er);
|
7729 | pna.nextTick(cb, er);
|
7730 | valid = false;
|
7731 | }
|
7732 | return valid;
|
7733 | }
|
7734 |
|
7735 | Writable.prototype.write = function (chunk, encoding, cb) {
|
7736 | var state = this._writableState;
|
7737 | var ret = false;
|
7738 | var isBuf = !state.objectMode && _isUint8Array(chunk);
|
7739 |
|
7740 | if (isBuf && !Buffer.isBuffer(chunk)) {
|
7741 | chunk = _uint8ArrayToBuffer(chunk);
|
7742 | }
|
7743 |
|
7744 | if (typeof encoding === 'function') {
|
7745 | cb = encoding;
|
7746 | encoding = null;
|
7747 | }
|
7748 |
|
7749 | if (isBuf) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding;
|
7750 |
|
7751 | if (typeof cb !== 'function') cb = nop;
|
7752 |
|
7753 | if (state.ended) writeAfterEnd(this, cb);else if (isBuf || validChunk(this, state, chunk, cb)) {
|
7754 | state.pendingcb++;
|
7755 | ret = writeOrBuffer(this, state, isBuf, chunk, encoding, cb);
|
7756 | }
|
7757 |
|
7758 | return ret;
|
7759 | };
|
7760 |
|
7761 | Writable.prototype.cork = function () {
|
7762 | var state = this._writableState;
|
7763 |
|
7764 | state.corked++;
|
7765 | };
|
7766 |
|
7767 | Writable.prototype.uncork = function () {
|
7768 | var state = this._writableState;
|
7769 |
|
7770 | if (state.corked) {
|
7771 | state.corked--;
|
7772 |
|
7773 | if (!state.writing && !state.corked && !state.finished && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state);
|
7774 | }
|
7775 | };
|
7776 |
|
7777 | Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
|
7778 |
|
7779 | if (typeof encoding === 'string') encoding = encoding.toLowerCase();
|
7780 | 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);
|
7781 | this._writableState.defaultEncoding = encoding;
|
7782 | return this;
|
7783 | };
|
7784 |
|
7785 | function decodeChunk(state, chunk, encoding) {
|
7786 | if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') {
|
7787 | chunk = Buffer.from(chunk, encoding);
|
7788 | }
|
7789 | return chunk;
|
7790 | }
|
7791 |
|
7792 | Object.defineProperty(Writable.prototype, 'writableHighWaterMark', {
|
7793 |
|
7794 |
|
7795 |
|
7796 | enumerable: false,
|
7797 | get: function () {
|
7798 | return this._writableState.highWaterMark;
|
7799 | }
|
7800 | });
|
7801 |
|
7802 |
|
7803 |
|
7804 |
|
7805 | function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) {
|
7806 | if (!isBuf) {
|
7807 | var newChunk = decodeChunk(state, chunk, encoding);
|
7808 | if (chunk !== newChunk) {
|
7809 | isBuf = true;
|
7810 | encoding = 'buffer';
|
7811 | chunk = newChunk;
|
7812 | }
|
7813 | }
|
7814 | var len = state.objectMode ? 1 : chunk.length;
|
7815 |
|
7816 | state.length += len;
|
7817 |
|
7818 | var ret = state.length < state.highWaterMark;
|
7819 |
|
7820 | if (!ret) state.needDrain = true;
|
7821 |
|
7822 | if (state.writing || state.corked) {
|
7823 | var last = state.lastBufferedRequest;
|
7824 | state.lastBufferedRequest = {
|
7825 | chunk: chunk,
|
7826 | encoding: encoding,
|
7827 | isBuf: isBuf,
|
7828 | callback: cb,
|
7829 | next: null
|
7830 | };
|
7831 | if (last) {
|
7832 | last.next = state.lastBufferedRequest;
|
7833 | } else {
|
7834 | state.bufferedRequest = state.lastBufferedRequest;
|
7835 | }
|
7836 | state.bufferedRequestCount += 1;
|
7837 | } else {
|
7838 | doWrite(stream, state, false, len, chunk, encoding, cb);
|
7839 | }
|
7840 |
|
7841 | return ret;
|
7842 | }
|
7843 |
|
7844 | function doWrite(stream, state, writev, len, chunk, encoding, cb) {
|
7845 | state.writelen = len;
|
7846 | state.writecb = cb;
|
7847 | state.writing = true;
|
7848 | state.sync = true;
|
7849 | if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite);
|
7850 | state.sync = false;
|
7851 | }
|
7852 |
|
7853 | function onwriteError(stream, state, sync, er, cb) {
|
7854 | --state.pendingcb;
|
7855 |
|
7856 | if (sync) {
|
7857 |
|
7858 |
|
7859 | pna.nextTick(cb, er);
|
7860 |
|
7861 |
|
7862 | pna.nextTick(finishMaybe, stream, state);
|
7863 | stream._writableState.errorEmitted = true;
|
7864 | stream.emit('error', er);
|
7865 | } else {
|
7866 |
|
7867 |
|
7868 | cb(er);
|
7869 | stream._writableState.errorEmitted = true;
|
7870 | stream.emit('error', er);
|
7871 |
|
7872 |
|
7873 | finishMaybe(stream, state);
|
7874 | }
|
7875 | }
|
7876 |
|
7877 | function onwriteStateUpdate(state) {
|
7878 | state.writing = false;
|
7879 | state.writecb = null;
|
7880 | state.length -= state.writelen;
|
7881 | state.writelen = 0;
|
7882 | }
|
7883 |
|
7884 | function onwrite(stream, er) {
|
7885 | var state = stream._writableState;
|
7886 | var sync = state.sync;
|
7887 | var cb = state.writecb;
|
7888 |
|
7889 | onwriteStateUpdate(state);
|
7890 |
|
7891 | if (er) onwriteError(stream, state, sync, er, cb);else {
|
7892 |
|
7893 | var finished = needFinish(state);
|
7894 |
|
7895 | if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) {
|
7896 | clearBuffer(stream, state);
|
7897 | }
|
7898 |
|
7899 | if (sync) {
|
7900 |
|
7901 | asyncWrite(afterWrite, stream, state, finished, cb);
|
7902 |
|
7903 | } else {
|
7904 | afterWrite(stream, state, finished, cb);
|
7905 | }
|
7906 | }
|
7907 | }
|
7908 |
|
7909 | function afterWrite(stream, state, finished, cb) {
|
7910 | if (!finished) onwriteDrain(stream, state);
|
7911 | state.pendingcb--;
|
7912 | cb();
|
7913 | finishMaybe(stream, state);
|
7914 | }
|
7915 |
|
7916 |
|
7917 |
|
7918 |
|
7919 | function onwriteDrain(stream, state) {
|
7920 | if (state.length === 0 && state.needDrain) {
|
7921 | state.needDrain = false;
|
7922 | stream.emit('drain');
|
7923 | }
|
7924 | }
|
7925 |
|
7926 |
|
7927 | function clearBuffer(stream, state) {
|
7928 | state.bufferProcessing = true;
|
7929 | var entry = state.bufferedRequest;
|
7930 |
|
7931 | if (stream._writev && entry && entry.next) {
|
7932 |
|
7933 | var l = state.bufferedRequestCount;
|
7934 | var buffer = new Array(l);
|
7935 | var holder = state.corkedRequestsFree;
|
7936 | holder.entry = entry;
|
7937 |
|
7938 | var count = 0;
|
7939 | var allBuffers = true;
|
7940 | while (entry) {
|
7941 | buffer[count] = entry;
|
7942 | if (!entry.isBuf) allBuffers = false;
|
7943 | entry = entry.next;
|
7944 | count += 1;
|
7945 | }
|
7946 | buffer.allBuffers = allBuffers;
|
7947 |
|
7948 | doWrite(stream, state, true, state.length, buffer, '', holder.finish);
|
7949 |
|
7950 |
|
7951 |
|
7952 | state.pendingcb++;
|
7953 | state.lastBufferedRequest = null;
|
7954 | if (holder.next) {
|
7955 | state.corkedRequestsFree = holder.next;
|
7956 | holder.next = null;
|
7957 | } else {
|
7958 | state.corkedRequestsFree = new CorkedRequest(state);
|
7959 | }
|
7960 | state.bufferedRequestCount = 0;
|
7961 | } else {
|
7962 |
|
7963 | while (entry) {
|
7964 | var chunk = entry.chunk;
|
7965 | var encoding = entry.encoding;
|
7966 | var cb = entry.callback;
|
7967 | var len = state.objectMode ? 1 : chunk.length;
|
7968 |
|
7969 | doWrite(stream, state, false, len, chunk, encoding, cb);
|
7970 | entry = entry.next;
|
7971 | state.bufferedRequestCount--;
|
7972 |
|
7973 |
|
7974 |
|
7975 |
|
7976 | if (state.writing) {
|
7977 | break;
|
7978 | }
|
7979 | }
|
7980 |
|
7981 | if (entry === null) state.lastBufferedRequest = null;
|
7982 | }
|
7983 |
|
7984 | state.bufferedRequest = entry;
|
7985 | state.bufferProcessing = false;
|
7986 | }
|
7987 |
|
7988 | Writable.prototype._write = function (chunk, encoding, cb) {
|
7989 | cb(new Error('_write() is not implemented'));
|
7990 | };
|
7991 |
|
7992 | Writable.prototype._writev = null;
|
7993 |
|
7994 | Writable.prototype.end = function (chunk, encoding, cb) {
|
7995 | var state = this._writableState;
|
7996 |
|
7997 | if (typeof chunk === 'function') {
|
7998 | cb = chunk;
|
7999 | chunk = null;
|
8000 | encoding = null;
|
8001 | } else if (typeof encoding === 'function') {
|
8002 | cb = encoding;
|
8003 | encoding = null;
|
8004 | }
|
8005 |
|
8006 | if (chunk !== null && chunk !== undefined) this.write(chunk, encoding);
|
8007 |
|
8008 |
|
8009 | if (state.corked) {
|
8010 | state.corked = 1;
|
8011 | this.uncork();
|
8012 | }
|
8013 |
|
8014 |
|
8015 | if (!state.ending && !state.finished) endWritable(this, state, cb);
|
8016 | };
|
8017 |
|
8018 | function needFinish(state) {
|
8019 | return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing;
|
8020 | }
|
8021 | function callFinal(stream, state) {
|
8022 | stream._final(function (err) {
|
8023 | state.pendingcb--;
|
8024 | if (err) {
|
8025 | stream.emit('error', err);
|
8026 | }
|
8027 | state.prefinished = true;
|
8028 | stream.emit('prefinish');
|
8029 | finishMaybe(stream, state);
|
8030 | });
|
8031 | }
|
8032 | function prefinish(stream, state) {
|
8033 | if (!state.prefinished && !state.finalCalled) {
|
8034 | if (typeof stream._final === 'function') {
|
8035 | state.pendingcb++;
|
8036 | state.finalCalled = true;
|
8037 | pna.nextTick(callFinal, stream, state);
|
8038 | } else {
|
8039 | state.prefinished = true;
|
8040 | stream.emit('prefinish');
|
8041 | }
|
8042 | }
|
8043 | }
|
8044 |
|
8045 | function finishMaybe(stream, state) {
|
8046 | var need = needFinish(state);
|
8047 | if (need) {
|
8048 | prefinish(stream, state);
|
8049 | if (state.pendingcb === 0) {
|
8050 | state.finished = true;
|
8051 | stream.emit('finish');
|
8052 | }
|
8053 | }
|
8054 | return need;
|
8055 | }
|
8056 |
|
8057 | function endWritable(stream, state, cb) {
|
8058 | state.ending = true;
|
8059 | finishMaybe(stream, state);
|
8060 | if (cb) {
|
8061 | if (state.finished) pna.nextTick(cb);else stream.once('finish', cb);
|
8062 | }
|
8063 | state.ended = true;
|
8064 | stream.writable = false;
|
8065 | }
|
8066 |
|
8067 | function onCorkedFinish(corkReq, state, err) {
|
8068 | var entry = corkReq.entry;
|
8069 | corkReq.entry = null;
|
8070 | while (entry) {
|
8071 | var cb = entry.callback;
|
8072 | state.pendingcb--;
|
8073 | cb(err);
|
8074 | entry = entry.next;
|
8075 | }
|
8076 | if (state.corkedRequestsFree) {
|
8077 | state.corkedRequestsFree.next = corkReq;
|
8078 | } else {
|
8079 | state.corkedRequestsFree = corkReq;
|
8080 | }
|
8081 | }
|
8082 |
|
8083 | Object.defineProperty(Writable.prototype, 'destroyed', {
|
8084 | get: function () {
|
8085 | if (this._writableState === undefined) {
|
8086 | return false;
|
8087 | }
|
8088 | return this._writableState.destroyed;
|
8089 | },
|
8090 | set: function (value) {
|
8091 |
|
8092 |
|
8093 | if (!this._writableState) {
|
8094 | return;
|
8095 | }
|
8096 |
|
8097 |
|
8098 |
|
8099 | this._writableState.destroyed = value;
|
8100 | }
|
8101 | });
|
8102 |
|
8103 | Writable.prototype.destroy = destroyImpl.destroy;
|
8104 | Writable.prototype._undestroy = destroyImpl.undestroy;
|
8105 | Writable.prototype._destroy = function (err, cb) {
|
8106 | this.end();
|
8107 | cb(err);
|
8108 | };
|
8109 | }).call(this,_dereq_(55),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},_dereq_(94).setImmediate)
|
8110 | },{"13":13,"26":26,"32":32,"38":38,"39":39,"54":54,"55":55,"65":65,"94":94,"96":96}],37:[function(_dereq_,module,exports){
|
8111 | 'use strict';
|
8112 |
|
8113 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
8114 |
|
8115 | var Buffer = _dereq_(65).Buffer;
|
8116 | var util = _dereq_(10);
|
8117 |
|
8118 | function copyBuffer(src, target, offset) {
|
8119 | src.copy(target, offset);
|
8120 | }
|
8121 |
|
8122 | module.exports = function () {
|
8123 | function BufferList() {
|
8124 | _classCallCheck(this, BufferList);
|
8125 |
|
8126 | this.head = null;
|
8127 | this.tail = null;
|
8128 | this.length = 0;
|
8129 | }
|
8130 |
|
8131 | BufferList.prototype.push = function push(v) {
|
8132 | var entry = { data: v, next: null };
|
8133 | if (this.length > 0) this.tail.next = entry;else this.head = entry;
|
8134 | this.tail = entry;
|
8135 | ++this.length;
|
8136 | };
|
8137 |
|
8138 | BufferList.prototype.unshift = function unshift(v) {
|
8139 | var entry = { data: v, next: this.head };
|
8140 | if (this.length === 0) this.tail = entry;
|
8141 | this.head = entry;
|
8142 | ++this.length;
|
8143 | };
|
8144 |
|
8145 | BufferList.prototype.shift = function shift() {
|
8146 | if (this.length === 0) return;
|
8147 | var ret = this.head.data;
|
8148 | if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next;
|
8149 | --this.length;
|
8150 | return ret;
|
8151 | };
|
8152 |
|
8153 | BufferList.prototype.clear = function clear() {
|
8154 | this.head = this.tail = null;
|
8155 | this.length = 0;
|
8156 | };
|
8157 |
|
8158 | BufferList.prototype.join = function join(s) {
|
8159 | if (this.length === 0) return '';
|
8160 | var p = this.head;
|
8161 | var ret = '' + p.data;
|
8162 | while (p = p.next) {
|
8163 | ret += s + p.data;
|
8164 | }return ret;
|
8165 | };
|
8166 |
|
8167 | BufferList.prototype.concat = function concat(n) {
|
8168 | if (this.length === 0) return Buffer.alloc(0);
|
8169 | if (this.length === 1) return this.head.data;
|
8170 | var ret = Buffer.allocUnsafe(n >>> 0);
|
8171 | var p = this.head;
|
8172 | var i = 0;
|
8173 | while (p) {
|
8174 | copyBuffer(p.data, ret, i);
|
8175 | i += p.data.length;
|
8176 | p = p.next;
|
8177 | }
|
8178 | return ret;
|
8179 | };
|
8180 |
|
8181 | return BufferList;
|
8182 | }();
|
8183 |
|
8184 | if (util && util.inspect && util.inspect.custom) {
|
8185 | module.exports.prototype[util.inspect.custom] = function () {
|
8186 | var obj = util.inspect({ length: this.length });
|
8187 | return this.constructor.name + ' ' + obj;
|
8188 | };
|
8189 | }
|
8190 | },{"10":10,"65":65}],38:[function(_dereq_,module,exports){
|
8191 | 'use strict';
|
8192 |
|
8193 |
|
8194 |
|
8195 | var pna = _dereq_(54);
|
8196 |
|
8197 |
|
8198 |
|
8199 | function destroy(err, cb) {
|
8200 | var _this = this;
|
8201 |
|
8202 | var readableDestroyed = this._readableState && this._readableState.destroyed;
|
8203 | var writableDestroyed = this._writableState && this._writableState.destroyed;
|
8204 |
|
8205 | if (readableDestroyed || writableDestroyed) {
|
8206 | if (cb) {
|
8207 | cb(err);
|
8208 | } else if (err && (!this._writableState || !this._writableState.errorEmitted)) {
|
8209 | pna.nextTick(emitErrorNT, this, err);
|
8210 | }
|
8211 | return this;
|
8212 | }
|
8213 |
|
8214 |
|
8215 |
|
8216 |
|
8217 | if (this._readableState) {
|
8218 | this._readableState.destroyed = true;
|
8219 | }
|
8220 |
|
8221 |
|
8222 | if (this._writableState) {
|
8223 | this._writableState.destroyed = true;
|
8224 | }
|
8225 |
|
8226 | this._destroy(err || null, function (err) {
|
8227 | if (!cb && err) {
|
8228 | pna.nextTick(emitErrorNT, _this, err);
|
8229 | if (_this._writableState) {
|
8230 | _this._writableState.errorEmitted = true;
|
8231 | }
|
8232 | } else if (cb) {
|
8233 | cb(err);
|
8234 | }
|
8235 | });
|
8236 |
|
8237 | return this;
|
8238 | }
|
8239 |
|
8240 | function undestroy() {
|
8241 | if (this._readableState) {
|
8242 | this._readableState.destroyed = false;
|
8243 | this._readableState.reading = false;
|
8244 | this._readableState.ended = false;
|
8245 | this._readableState.endEmitted = false;
|
8246 | }
|
8247 |
|
8248 | if (this._writableState) {
|
8249 | this._writableState.destroyed = false;
|
8250 | this._writableState.ended = false;
|
8251 | this._writableState.ending = false;
|
8252 | this._writableState.finished = false;
|
8253 | this._writableState.errorEmitted = false;
|
8254 | }
|
8255 | }
|
8256 |
|
8257 | function emitErrorNT(self, err) {
|
8258 | self.emit('error', err);
|
8259 | }
|
8260 |
|
8261 | module.exports = {
|
8262 | destroy: destroy,
|
8263 | undestroy: undestroy
|
8264 | };
|
8265 | },{"54":54}],39:[function(_dereq_,module,exports){
|
8266 | module.exports = _dereq_(18).EventEmitter;
|
8267 |
|
8268 | },{"18":18}],40:[function(_dereq_,module,exports){
|
8269 | exports = module.exports = _dereq_(34);
|
8270 | exports.Stream = exports;
|
8271 | exports.Readable = exports;
|
8272 | exports.Writable = _dereq_(36);
|
8273 | exports.Duplex = _dereq_(32);
|
8274 | exports.Transform = _dereq_(35);
|
8275 | exports.PassThrough = _dereq_(33);
|
8276 |
|
8277 | },{"32":32,"33":33,"34":34,"35":35,"36":36}],41:[function(_dereq_,module,exports){
|
8278 | module.exports = extend
|
8279 |
|
8280 | var hasOwnProperty = Object.prototype.hasOwnProperty;
|
8281 |
|
8282 | function extend() {
|
8283 | var target = {}
|
8284 |
|
8285 | for (var i = 0; i < arguments.length; i++) {
|
8286 | var source = arguments[i]
|
8287 |
|
8288 | for (var key in source) {
|
8289 | if (hasOwnProperty.call(source, key)) {
|
8290 | target[key] = source[key]
|
8291 | }
|
8292 | }
|
8293 | }
|
8294 |
|
8295 | return target
|
8296 | }
|
8297 |
|
8298 | },{}],42:[function(_dereq_,module,exports){
|
8299 |
|
8300 |
|
8301 |
|
8302 |
|
8303 |
|
8304 |
|
8305 | var WriteError = _dereq_(51).WriteError
|
8306 | var promisify = _dereq_(44)
|
8307 |
|
8308 | function Batch (levelup) {
|
8309 | this._levelup = levelup
|
8310 | this.batch = levelup.db.batch()
|
8311 | this.ops = []
|
8312 | this.length = 0
|
8313 | }
|
8314 |
|
8315 | Batch.prototype.put = function (key, value) {
|
8316 | try {
|
8317 | this.batch.put(key, value)
|
8318 | } catch (e) {
|
8319 | throw new WriteError(e)
|
8320 | }
|
8321 |
|
8322 | this.ops.push({ type: 'put', key: key, value: value })
|
8323 | this.length++
|
8324 |
|
8325 | return this
|
8326 | }
|
8327 |
|
8328 | Batch.prototype.del = function (key) {
|
8329 | try {
|
8330 | this.batch.del(key)
|
8331 | } catch (err) {
|
8332 | throw new WriteError(err)
|
8333 | }
|
8334 |
|
8335 | this.ops.push({ type: 'del', key: key })
|
8336 | this.length++
|
8337 |
|
8338 | return this
|
8339 | }
|
8340 |
|
8341 | Batch.prototype.clear = function () {
|
8342 | try {
|
8343 | this.batch.clear()
|
8344 | } catch (err) {
|
8345 | throw new WriteError(err)
|
8346 | }
|
8347 |
|
8348 | this.ops = []
|
8349 | this.length = 0
|
8350 |
|
8351 | return this
|
8352 | }
|
8353 |
|
8354 | Batch.prototype.write = function (callback) {
|
8355 | var levelup = this._levelup
|
8356 | var ops = this.ops
|
8357 | var promise
|
8358 |
|
8359 | if (!callback) {
|
8360 | callback = promisify()
|
8361 | promise = callback.promise
|
8362 | }
|
8363 |
|
8364 | try {
|
8365 | this.batch.write(function (err) {
|
8366 | if (err) { return callback(new WriteError(err)) }
|
8367 | levelup.emit('batch', ops)
|
8368 | callback()
|
8369 | })
|
8370 | } catch (err) {
|
8371 | throw new WriteError(err)
|
8372 | }
|
8373 |
|
8374 | return promise
|
8375 | }
|
8376 |
|
8377 | module.exports = Batch
|
8378 |
|
8379 | },{"44":44,"51":51}],43:[function(_dereq_,module,exports){
|
8380 | (function (process){
|
8381 |
|
8382 |
|
8383 |
|
8384 |
|
8385 |
|
8386 |
|
8387 | var EventEmitter = _dereq_(18).EventEmitter
|
8388 | var inherits = _dereq_(98).inherits
|
8389 | var extend = _dereq_(52)
|
8390 | var DeferredLevelDOWN = _dereq_(50)
|
8391 | var IteratorStream = _dereq_(31)
|
8392 | var Batch = _dereq_(42)
|
8393 | var errors = _dereq_(51)
|
8394 | var assert = _dereq_(5)
|
8395 | var promisify = _dereq_(44)
|
8396 |
|
8397 | var WriteError = errors.WriteError
|
8398 | var ReadError = errors.ReadError
|
8399 | var NotFoundError = errors.NotFoundError
|
8400 | var OpenError = errors.OpenError
|
8401 | var InitializationError = errors.InitializationError
|
8402 |
|
8403 |
|
8404 |
|
8405 |
|
8406 |
|
8407 |
|
8408 |
|
8409 |
|
8410 |
|
8411 | function LevelUP (db, options, callback) {
|
8412 | if (!(this instanceof LevelUP)) {
|
8413 | return new LevelUP(db, options, callback)
|
8414 | }
|
8415 |
|
8416 | var error
|
8417 |
|
8418 | EventEmitter.call(this)
|
8419 | this.setMaxListeners(Infinity)
|
8420 |
|
8421 | if (typeof options === 'function') {
|
8422 | callback = options
|
8423 | options = {}
|
8424 | }
|
8425 |
|
8426 | options = options || {}
|
8427 |
|
8428 | if (!db || typeof db !== 'object') {
|
8429 | error = new InitializationError('First argument must be an abstract-leveldown compliant store')
|
8430 | if (typeof callback === 'function') {
|
8431 | return process.nextTick(callback, error)
|
8432 | }
|
8433 | throw error
|
8434 | }
|
8435 |
|
8436 | assert.equal(typeof db.status, 'string', '.status required, old abstract-leveldown')
|
8437 |
|
8438 | this.options = getOptions(options)
|
8439 | this._db = db
|
8440 | this.db = new DeferredLevelDOWN(db)
|
8441 | this.open(callback)
|
8442 | }
|
8443 |
|
8444 | LevelUP.prototype.emit = EventEmitter.prototype.emit
|
8445 | LevelUP.prototype.once = EventEmitter.prototype.once
|
8446 | inherits(LevelUP, EventEmitter)
|
8447 |
|
8448 | LevelUP.prototype.open = function (callback) {
|
8449 | var self = this
|
8450 | var promise
|
8451 |
|
8452 | if (!callback) {
|
8453 | callback = promisify()
|
8454 | promise = callback.promise
|
8455 | }
|
8456 |
|
8457 | if (this.isOpen()) {
|
8458 | process.nextTick(callback, null, self)
|
8459 | return promise
|
8460 | }
|
8461 |
|
8462 | if (this._isOpening()) {
|
8463 | this.once('open', function () { callback(null, self) })
|
8464 | return promise
|
8465 | }
|
8466 |
|
8467 | this.emit('opening')
|
8468 |
|
8469 | this.db.open(this.options, function (err) {
|
8470 | if (err) {
|
8471 | return callback(new OpenError(err))
|
8472 | }
|
8473 | self.db = self._db
|
8474 | callback(null, self)
|
8475 | self.emit('open')
|
8476 | self.emit('ready')
|
8477 | })
|
8478 |
|
8479 | return promise
|
8480 | }
|
8481 |
|
8482 | LevelUP.prototype.close = function (callback) {
|
8483 | var self = this
|
8484 | var promise
|
8485 |
|
8486 | if (!callback) {
|
8487 | callback = promisify()
|
8488 | promise = callback.promise
|
8489 | }
|
8490 |
|
8491 | if (this.isOpen()) {
|
8492 | this.db.close(function () {
|
8493 | self.emit('closed')
|
8494 | callback.apply(null, arguments)
|
8495 | })
|
8496 | this.emit('closing')
|
8497 | this.db = new DeferredLevelDOWN(this._db)
|
8498 | } else if (this.isClosed()) {
|
8499 | process.nextTick(callback)
|
8500 | } else if (this.db.status === 'closing') {
|
8501 | this.once('closed', callback)
|
8502 | } else if (this._isOpening()) {
|
8503 | this.once('open', function () {
|
8504 | self.close(callback)
|
8505 | })
|
8506 | }
|
8507 |
|
8508 | return promise
|
8509 | }
|
8510 |
|
8511 | LevelUP.prototype.isOpen = function () {
|
8512 | return this.db.status === 'open'
|
8513 | }
|
8514 |
|
8515 | LevelUP.prototype._isOpening = function () {
|
8516 | return this.db.status === 'opening'
|
8517 | }
|
8518 |
|
8519 | LevelUP.prototype.isClosed = function () {
|
8520 | return (/^clos|new/).test(this.db.status)
|
8521 | }
|
8522 |
|
8523 | LevelUP.prototype.get = function (key, options, callback) {
|
8524 | if (key === null || key === undefined) {
|
8525 | throw new ReadError('get() requires a key argument')
|
8526 | }
|
8527 |
|
8528 | var promise
|
8529 |
|
8530 | callback = getCallback(options, callback)
|
8531 |
|
8532 | if (!callback) {
|
8533 | callback = promisify()
|
8534 | promise = callback.promise
|
8535 | }
|
8536 |
|
8537 | if (maybeError(this, callback)) { return promise }
|
8538 |
|
8539 | options = getOptions(options)
|
8540 |
|
8541 | this.db.get(key, options, function (err, value) {
|
8542 | if (err) {
|
8543 | if ((/notfound/i).test(err) || err.notFound) {
|
8544 | err = new NotFoundError('Key not found in database [' + key + ']', err)
|
8545 | } else {
|
8546 | err = new ReadError(err)
|
8547 | }
|
8548 | return callback(err)
|
8549 | }
|
8550 | callback(null, value)
|
8551 | })
|
8552 |
|
8553 | return promise
|
8554 | }
|
8555 |
|
8556 | LevelUP.prototype.put = function (key, value, options, callback) {
|
8557 | if (key === null || key === undefined) {
|
8558 | throw new WriteError('put() requires a key argument')
|
8559 | }
|
8560 |
|
8561 | var self = this
|
8562 | var promise
|
8563 |
|
8564 | callback = getCallback(options, callback)
|
8565 |
|
8566 | if (!callback) {
|
8567 | callback = promisify()
|
8568 | promise = callback.promise
|
8569 | }
|
8570 |
|
8571 | if (maybeError(this, callback)) { return promise }
|
8572 |
|
8573 | options = getOptions(options)
|
8574 |
|
8575 | this.db.put(key, value, options, function (err) {
|
8576 | if (err) {
|
8577 | return callback(new WriteError(err))
|
8578 | }
|
8579 | self.emit('put', key, value)
|
8580 | callback()
|
8581 | })
|
8582 |
|
8583 | return promise
|
8584 | }
|
8585 |
|
8586 | LevelUP.prototype.del = function (key, options, callback) {
|
8587 | if (key === null || key === undefined) {
|
8588 | throw new WriteError('del() requires a key argument')
|
8589 | }
|
8590 |
|
8591 | var self = this
|
8592 | var promise
|
8593 |
|
8594 | callback = getCallback(options, callback)
|
8595 |
|
8596 | if (!callback) {
|
8597 | callback = promisify()
|
8598 | promise = callback.promise
|
8599 | }
|
8600 |
|
8601 | if (maybeError(this, callback)) { return promise }
|
8602 |
|
8603 | options = getOptions(options)
|
8604 |
|
8605 | this.db.del(key, options, function (err) {
|
8606 | if (err) {
|
8607 | return callback(new WriteError(err))
|
8608 | }
|
8609 | self.emit('del', key)
|
8610 | callback()
|
8611 | })
|
8612 |
|
8613 | return promise
|
8614 | }
|
8615 |
|
8616 | LevelUP.prototype.batch = function (arr, options, callback) {
|
8617 | if (!arguments.length) {
|
8618 | return new Batch(this)
|
8619 | }
|
8620 |
|
8621 | if (!Array.isArray(arr)) {
|
8622 | throw new WriteError('batch() requires an array argument')
|
8623 | }
|
8624 |
|
8625 | var self = this
|
8626 | var promise
|
8627 |
|
8628 | callback = getCallback(options, callback)
|
8629 |
|
8630 | if (!callback) {
|
8631 | callback = promisify()
|
8632 | promise = callback.promise
|
8633 | }
|
8634 |
|
8635 | if (maybeError(this, callback)) { return promise }
|
8636 |
|
8637 | options = getOptions(options)
|
8638 |
|
8639 | this.db.batch(arr, options, function (err) {
|
8640 | if (err) {
|
8641 | return callback(new WriteError(err))
|
8642 | }
|
8643 | self.emit('batch', arr)
|
8644 | callback()
|
8645 | })
|
8646 |
|
8647 | return promise
|
8648 | }
|
8649 |
|
8650 | LevelUP.prototype.readStream =
|
8651 | LevelUP.prototype.createReadStream = function (options) {
|
8652 | options = extend({ keys: true, values: true }, options)
|
8653 | if (typeof options.limit !== 'number') { options.limit = -1 }
|
8654 | return new IteratorStream(this.db.iterator(options), options)
|
8655 | }
|
8656 |
|
8657 | LevelUP.prototype.keyStream =
|
8658 | LevelUP.prototype.createKeyStream = function (options) {
|
8659 | return this.createReadStream(extend(options, { keys: true, values: false }))
|
8660 | }
|
8661 |
|
8662 | LevelUP.prototype.valueStream =
|
8663 | LevelUP.prototype.createValueStream = function (options) {
|
8664 | return this.createReadStream(extend(options, { keys: false, values: true }))
|
8665 | }
|
8666 |
|
8667 | LevelUP.prototype.toString = function () {
|
8668 | return 'LevelUP'
|
8669 | }
|
8670 |
|
8671 | function getCallback (options, callback) {
|
8672 | return typeof options === 'function' ? options : callback
|
8673 | }
|
8674 |
|
8675 | function getOptions (options) {
|
8676 | return typeof options === 'object' && options !== null ? options : {}
|
8677 | }
|
8678 |
|
8679 | function maybeError (db, callback) {
|
8680 | if (!db._isOpening() && !db.isOpen()) {
|
8681 | process.nextTick(callback, new ReadError('Database is not open'))
|
8682 | return true
|
8683 | }
|
8684 | }
|
8685 |
|
8686 | LevelUP.errors = errors
|
8687 | module.exports = LevelUP.default = LevelUP
|
8688 |
|
8689 | }).call(this,_dereq_(55))
|
8690 | },{"18":18,"31":31,"42":42,"44":44,"5":5,"50":50,"51":51,"52":52,"55":55,"98":98}],44:[function(_dereq_,module,exports){
|
8691 |
|
8692 |
|
8693 |
|
8694 |
|
8695 |
|
8696 |
|
8697 | function promisify () {
|
8698 | var callback
|
8699 | var promise = new Promise(function (resolve, reject) {
|
8700 | callback = function callback (err, value) {
|
8701 | if (err) reject(err)
|
8702 | else resolve(value)
|
8703 | }
|
8704 | })
|
8705 | callback.promise = promise
|
8706 | return callback
|
8707 | }
|
8708 |
|
8709 | module.exports = promisify
|
8710 |
|
8711 | },{}],45:[function(_dereq_,module,exports){
|
8712 | (function (process){
|
8713 |
|
8714 |
|
8715 | function AbstractChainedBatch (db) {
|
8716 | this._db = db
|
8717 | this._operations = []
|
8718 | this._written = false
|
8719 | }
|
8720 |
|
8721 | AbstractChainedBatch.prototype._serializeKey = function (key) {
|
8722 | return this._db._serializeKey(key)
|
8723 | }
|
8724 |
|
8725 | AbstractChainedBatch.prototype._serializeValue = function (value) {
|
8726 | return this._db._serializeValue(value)
|
8727 | }
|
8728 |
|
8729 | AbstractChainedBatch.prototype._checkWritten = function () {
|
8730 | if (this._written) {
|
8731 | throw new Error('write() already called on this batch')
|
8732 | }
|
8733 | }
|
8734 |
|
8735 | AbstractChainedBatch.prototype.put = function (key, value) {
|
8736 | this._checkWritten()
|
8737 |
|
8738 | var err = this._db._checkKey(key, 'key')
|
8739 | if (err) { throw err }
|
8740 |
|
8741 | key = this._serializeKey(key)
|
8742 | value = this._serializeValue(value)
|
8743 |
|
8744 | this._put(key, value)
|
8745 |
|
8746 | return this
|
8747 | }
|
8748 |
|
8749 | AbstractChainedBatch.prototype._put = function (key, value) {
|
8750 | this._operations.push({ type: 'put', key: key, value: value })
|
8751 | }
|
8752 |
|
8753 | AbstractChainedBatch.prototype.del = function (key) {
|
8754 | this._checkWritten()
|
8755 |
|
8756 | var err = this._db._checkKey(key, 'key')
|
8757 | if (err) { throw err }
|
8758 |
|
8759 | key = this._serializeKey(key)
|
8760 | this._del(key)
|
8761 |
|
8762 | return this
|
8763 | }
|
8764 |
|
8765 | AbstractChainedBatch.prototype._del = function (key) {
|
8766 | this._operations.push({ type: 'del', key: key })
|
8767 | }
|
8768 |
|
8769 | AbstractChainedBatch.prototype.clear = function () {
|
8770 | this._checkWritten()
|
8771 | this._operations = []
|
8772 | this._clear()
|
8773 |
|
8774 | return this
|
8775 | }
|
8776 |
|
8777 | AbstractChainedBatch.prototype._clear = function noop () {}
|
8778 |
|
8779 | AbstractChainedBatch.prototype.write = function (options, callback) {
|
8780 | this._checkWritten()
|
8781 |
|
8782 | if (typeof options === 'function') { callback = options }
|
8783 | if (typeof callback !== 'function') {
|
8784 | throw new Error('write() requires a callback argument')
|
8785 | }
|
8786 | if (typeof options !== 'object') { options = {} }
|
8787 |
|
8788 | this._written = true
|
8789 |
|
8790 |
|
8791 | if (typeof this._write === 'function') { return this._write(callback) }
|
8792 |
|
8793 | if (typeof this._db._batch === 'function') {
|
8794 | return this._db._batch(this._operations, options, callback)
|
8795 | }
|
8796 |
|
8797 | process.nextTick(callback)
|
8798 | }
|
8799 |
|
8800 | module.exports = AbstractChainedBatch
|
8801 |
|
8802 | }).call(this,_dereq_(55))
|
8803 | },{"55":55}],46:[function(_dereq_,module,exports){
|
8804 | (function (process){
|
8805 |
|
8806 |
|
8807 | function AbstractIterator (db) {
|
8808 | this.db = db
|
8809 | this._ended = false
|
8810 | this._nexting = false
|
8811 | }
|
8812 |
|
8813 | AbstractIterator.prototype.next = function (callback) {
|
8814 | var self = this
|
8815 |
|
8816 | if (typeof callback !== 'function') {
|
8817 | throw new Error('next() requires a callback argument')
|
8818 | }
|
8819 |
|
8820 | if (self._ended) {
|
8821 | process.nextTick(callback, new Error('cannot call next() after end()'))
|
8822 | return self
|
8823 | }
|
8824 |
|
8825 | if (self._nexting) {
|
8826 | process.nextTick(callback, new Error('cannot call next() before previous next() has completed'))
|
8827 | return self
|
8828 | }
|
8829 |
|
8830 | self._nexting = true
|
8831 | self._next(function () {
|
8832 | self._nexting = false
|
8833 | callback.apply(null, arguments)
|
8834 | })
|
8835 |
|
8836 | return self
|
8837 | }
|
8838 |
|
8839 | AbstractIterator.prototype._next = function (callback) {
|
8840 | process.nextTick(callback)
|
8841 | }
|
8842 |
|
8843 | AbstractIterator.prototype.end = function (callback) {
|
8844 | if (typeof callback !== 'function') {
|
8845 | throw new Error('end() requires a callback argument')
|
8846 | }
|
8847 |
|
8848 | if (this._ended) {
|
8849 | return process.nextTick(callback, new Error('end() already called on iterator'))
|
8850 | }
|
8851 |
|
8852 | this._ended = true
|
8853 | this._end(callback)
|
8854 | }
|
8855 |
|
8856 | AbstractIterator.prototype._end = function (callback) {
|
8857 | process.nextTick(callback)
|
8858 | }
|
8859 |
|
8860 | module.exports = AbstractIterator
|
8861 |
|
8862 | }).call(this,_dereq_(55))
|
8863 | },{"55":55}],47:[function(_dereq_,module,exports){
|
8864 | (function (Buffer,process){
|
8865 |
|
8866 |
|
8867 | var xtend = _dereq_(52)
|
8868 | var AbstractIterator = _dereq_(46)
|
8869 | var AbstractChainedBatch = _dereq_(45)
|
8870 | var hasOwnProperty = Object.prototype.hasOwnProperty
|
8871 | var rangeOptions = 'start end gt gte lt lte'.split(' ')
|
8872 |
|
8873 | function AbstractLevelDOWN (location) {
|
8874 | if (!arguments.length || location === undefined) {
|
8875 | throw new Error('constructor requires at least a location argument')
|
8876 | }
|
8877 |
|
8878 | if (typeof location !== 'string') {
|
8879 | throw new Error('constructor requires a location string argument')
|
8880 | }
|
8881 |
|
8882 | this.location = location
|
8883 | this.status = 'new'
|
8884 | }
|
8885 |
|
8886 | AbstractLevelDOWN.prototype.open = function (options, callback) {
|
8887 | var self = this
|
8888 | var oldStatus = this.status
|
8889 |
|
8890 | if (typeof options === 'function') { callback = options }
|
8891 |
|
8892 | if (typeof callback !== 'function') {
|
8893 | throw new Error('open() requires a callback argument')
|
8894 | }
|
8895 |
|
8896 | if (typeof options !== 'object') { options = {} }
|
8897 |
|
8898 | options.createIfMissing = options.createIfMissing !== false
|
8899 | options.errorIfExists = !!options.errorIfExists
|
8900 |
|
8901 | this.status = 'opening'
|
8902 | this._open(options, function (err) {
|
8903 | if (err) {
|
8904 | self.status = oldStatus
|
8905 | return callback(err)
|
8906 | }
|
8907 | self.status = 'open'
|
8908 | callback()
|
8909 | })
|
8910 | }
|
8911 |
|
8912 | AbstractLevelDOWN.prototype._open = function (options, callback) {
|
8913 | process.nextTick(callback)
|
8914 | }
|
8915 |
|
8916 | AbstractLevelDOWN.prototype.close = function (callback) {
|
8917 | var self = this
|
8918 | var oldStatus = this.status
|
8919 |
|
8920 | if (typeof callback !== 'function') {
|
8921 | throw new Error('close() requires a callback argument')
|
8922 | }
|
8923 |
|
8924 | this.status = 'closing'
|
8925 | this._close(function (err) {
|
8926 | if (err) {
|
8927 | self.status = oldStatus
|
8928 | return callback(err)
|
8929 | }
|
8930 | self.status = 'closed'
|
8931 | callback()
|
8932 | })
|
8933 | }
|
8934 |
|
8935 | AbstractLevelDOWN.prototype._close = function (callback) {
|
8936 | process.nextTick(callback)
|
8937 | }
|
8938 |
|
8939 | AbstractLevelDOWN.prototype.get = function (key, options, callback) {
|
8940 | if (typeof options === 'function') { callback = options }
|
8941 |
|
8942 | if (typeof callback !== 'function') {
|
8943 | throw new Error('get() requires a callback argument')
|
8944 | }
|
8945 |
|
8946 | var err = this._checkKey(key, 'key')
|
8947 | if (err) return process.nextTick(callback, err)
|
8948 |
|
8949 | key = this._serializeKey(key)
|
8950 |
|
8951 | if (typeof options !== 'object') { options = {} }
|
8952 |
|
8953 | options.asBuffer = options.asBuffer !== false
|
8954 |
|
8955 | this._get(key, options, callback)
|
8956 | }
|
8957 |
|
8958 | AbstractLevelDOWN.prototype._get = function (key, options, callback) {
|
8959 | process.nextTick(function () { callback(new Error('NotFound')) })
|
8960 | }
|
8961 |
|
8962 | AbstractLevelDOWN.prototype.put = function (key, value, options, callback) {
|
8963 | if (typeof options === 'function') { callback = options }
|
8964 |
|
8965 | if (typeof callback !== 'function') {
|
8966 | throw new Error('put() requires a callback argument')
|
8967 | }
|
8968 |
|
8969 | var err = this._checkKey(key, 'key')
|
8970 | if (err) return process.nextTick(callback, err)
|
8971 |
|
8972 | key = this._serializeKey(key)
|
8973 | value = this._serializeValue(value)
|
8974 |
|
8975 | if (typeof options !== 'object') { options = {} }
|
8976 |
|
8977 | this._put(key, value, options, callback)
|
8978 | }
|
8979 |
|
8980 | AbstractLevelDOWN.prototype._put = function (key, value, options, callback) {
|
8981 | process.nextTick(callback)
|
8982 | }
|
8983 |
|
8984 | AbstractLevelDOWN.prototype.del = function (key, options, callback) {
|
8985 | if (typeof options === 'function') { callback = options }
|
8986 |
|
8987 | if (typeof callback !== 'function') {
|
8988 | throw new Error('del() requires a callback argument')
|
8989 | }
|
8990 |
|
8991 | var err = this._checkKey(key, 'key')
|
8992 | if (err) return process.nextTick(callback, err)
|
8993 |
|
8994 | key = this._serializeKey(key)
|
8995 |
|
8996 | if (typeof options !== 'object') { options = {} }
|
8997 |
|
8998 | this._del(key, options, callback)
|
8999 | }
|
9000 |
|
9001 | AbstractLevelDOWN.prototype._del = function (key, options, callback) {
|
9002 | process.nextTick(callback)
|
9003 | }
|
9004 |
|
9005 | AbstractLevelDOWN.prototype.batch = function (array, options, callback) {
|
9006 | if (!arguments.length) { return this._chainedBatch() }
|
9007 |
|
9008 | if (typeof options === 'function') { callback = options }
|
9009 |
|
9010 | if (typeof array === 'function') { callback = array }
|
9011 |
|
9012 | if (typeof callback !== 'function') {
|
9013 | throw new Error('batch(array) requires a callback argument')
|
9014 | }
|
9015 |
|
9016 | if (!Array.isArray(array)) {
|
9017 | return process.nextTick(callback, new Error('batch(array) requires an array argument'))
|
9018 | }
|
9019 |
|
9020 | if (!options || typeof options !== 'object') { options = {} }
|
9021 |
|
9022 | var serialized = new Array(array.length)
|
9023 |
|
9024 | for (var i = 0; i < array.length; i++) {
|
9025 | if (typeof array[i] !== 'object' || array[i] === null) {
|
9026 | return process.nextTick(callback, new Error('batch(array) element must be an object and not `null`'))
|
9027 | }
|
9028 |
|
9029 | var e = xtend(array[i])
|
9030 |
|
9031 | if (e.type !== 'put' && e.type !== 'del') {
|
9032 | return process.nextTick(callback, new Error("`type` must be 'put' or 'del'"))
|
9033 | }
|
9034 |
|
9035 | var err = this._checkKey(e.key, 'key')
|
9036 | if (err) return process.nextTick(callback, err)
|
9037 |
|
9038 | e.key = this._serializeKey(e.key)
|
9039 |
|
9040 | if (e.type === 'put') { e.value = this._serializeValue(e.value) }
|
9041 |
|
9042 | serialized[i] = e
|
9043 | }
|
9044 |
|
9045 | this._batch(serialized, options, callback)
|
9046 | }
|
9047 |
|
9048 | AbstractLevelDOWN.prototype._batch = function (array, options, callback) {
|
9049 | process.nextTick(callback)
|
9050 | }
|
9051 |
|
9052 | AbstractLevelDOWN.prototype._setupIteratorOptions = function (options) {
|
9053 | options = cleanRangeOptions(options)
|
9054 |
|
9055 | options.reverse = !!options.reverse
|
9056 | options.keys = options.keys !== false
|
9057 | options.values = options.values !== false
|
9058 | options.limit = 'limit' in options ? options.limit : -1
|
9059 | options.keyAsBuffer = options.keyAsBuffer !== false
|
9060 | options.valueAsBuffer = options.valueAsBuffer !== false
|
9061 |
|
9062 | return options
|
9063 | }
|
9064 |
|
9065 | function cleanRangeOptions (options) {
|
9066 | var result = {}
|
9067 |
|
9068 | for (var k in options) {
|
9069 | if (!hasOwnProperty.call(options, k)) continue
|
9070 | if (isRangeOption(k) && isEmptyRangeOption(options[k])) continue
|
9071 |
|
9072 | result[k] = options[k]
|
9073 | }
|
9074 |
|
9075 | return result
|
9076 | }
|
9077 |
|
9078 | function isRangeOption (k) {
|
9079 | return rangeOptions.indexOf(k) !== -1
|
9080 | }
|
9081 |
|
9082 | function isEmptyRangeOption (v) {
|
9083 | return v === '' || v == null || isEmptyBuffer(v)
|
9084 | }
|
9085 |
|
9086 | function isEmptyBuffer (v) {
|
9087 | return Buffer.isBuffer(v) && v.length === 0
|
9088 | }
|
9089 |
|
9090 | AbstractLevelDOWN.prototype.iterator = function (options) {
|
9091 | if (typeof options !== 'object') { options = {} }
|
9092 | options = this._setupIteratorOptions(options)
|
9093 | return this._iterator(options)
|
9094 | }
|
9095 |
|
9096 | AbstractLevelDOWN.prototype._iterator = function (options) {
|
9097 | return new AbstractIterator(this)
|
9098 | }
|
9099 |
|
9100 | AbstractLevelDOWN.prototype._chainedBatch = function () {
|
9101 | return new AbstractChainedBatch(this)
|
9102 | }
|
9103 |
|
9104 | AbstractLevelDOWN.prototype._serializeKey = function (key) {
|
9105 | return Buffer.isBuffer(key) ? key : String(key)
|
9106 | }
|
9107 |
|
9108 | AbstractLevelDOWN.prototype._serializeValue = function (value) {
|
9109 | if (value == null) return ''
|
9110 | return Buffer.isBuffer(value) || process.browser ? value : String(value)
|
9111 | }
|
9112 |
|
9113 | AbstractLevelDOWN.prototype._checkKey = function (obj, type) {
|
9114 | if (obj === null || obj === undefined) {
|
9115 | return new Error(type + ' cannot be `null` or `undefined`')
|
9116 | }
|
9117 |
|
9118 | if (Buffer.isBuffer(obj) && obj.length === 0) {
|
9119 | return new Error(type + ' cannot be an empty Buffer')
|
9120 | }
|
9121 |
|
9122 | if (String(obj) === '') {
|
9123 | return new Error(type + ' cannot be an empty String')
|
9124 | }
|
9125 | }
|
9126 |
|
9127 | module.exports = AbstractLevelDOWN
|
9128 |
|
9129 | }).call(this,{"isBuffer":_dereq_(27)},_dereq_(55))
|
9130 | },{"27":27,"45":45,"46":46,"52":52,"55":55}],48:[function(_dereq_,module,exports){
|
9131 | exports.AbstractLevelDOWN = _dereq_(47)
|
9132 | exports.AbstractIterator = _dereq_(46)
|
9133 | exports.AbstractChainedBatch = _dereq_(45)
|
9134 |
|
9135 | },{"45":45,"46":46,"47":47}],49:[function(_dereq_,module,exports){
|
9136 | var AbstractIterator = _dereq_(48).AbstractIterator
|
9137 | var inherits = _dereq_(26)
|
9138 |
|
9139 | function DeferredIterator (options) {
|
9140 | AbstractIterator.call(this, options)
|
9141 |
|
9142 | this._options = options
|
9143 | this._iterator = null
|
9144 | this._operations = []
|
9145 | }
|
9146 |
|
9147 | inherits(DeferredIterator, AbstractIterator)
|
9148 |
|
9149 | DeferredIterator.prototype.setDb = function (db) {
|
9150 | var it = this._iterator = db.iterator(this._options)
|
9151 | this._operations.forEach(function (op) {
|
9152 | it[op.method].apply(it, op.args)
|
9153 | })
|
9154 | }
|
9155 |
|
9156 | DeferredIterator.prototype._operation = function (method, args) {
|
9157 | if (this._iterator) return this._iterator[method].apply(this._iterator, args)
|
9158 | this._operations.push({ method: method, args: args })
|
9159 | }
|
9160 |
|
9161 | 'next end'.split(' ').forEach(function (m) {
|
9162 | DeferredIterator.prototype['_' + m] = function () {
|
9163 | this._operation(m, arguments)
|
9164 | }
|
9165 | })
|
9166 |
|
9167 | module.exports = DeferredIterator
|
9168 |
|
9169 | },{"26":26,"48":48}],50:[function(_dereq_,module,exports){
|
9170 | var AbstractLevelDOWN = _dereq_(48).AbstractLevelDOWN
|
9171 | var inherits = _dereq_(26)
|
9172 | var DeferredIterator = _dereq_(49)
|
9173 | var deferrables = 'put get del batch'.split(' ')
|
9174 |
|
9175 | function DeferredLevelDOWN (db) {
|
9176 | AbstractLevelDOWN.call(this, '')
|
9177 | this._db = db
|
9178 | this._operations = []
|
9179 | this._iterators = []
|
9180 | closed(this)
|
9181 | }
|
9182 |
|
9183 | inherits(DeferredLevelDOWN, AbstractLevelDOWN)
|
9184 |
|
9185 | DeferredLevelDOWN.prototype._open = function (options, callback) {
|
9186 | var self = this
|
9187 |
|
9188 | this._db.open(options, function (err) {
|
9189 | if (err) return callback(err)
|
9190 |
|
9191 | self._operations.forEach(function (op) {
|
9192 | self._db[op.method].apply(self._db, op.args)
|
9193 | })
|
9194 | self._operations = []
|
9195 | self._iterators.forEach(function (it) {
|
9196 | it.setDb(self._db)
|
9197 | })
|
9198 | self._iterators = []
|
9199 | open(self)
|
9200 | callback()
|
9201 | })
|
9202 | }
|
9203 |
|
9204 | DeferredLevelDOWN.prototype._close = function (callback) {
|
9205 | var self = this
|
9206 |
|
9207 | this._db.close(function (err) {
|
9208 | if (err) return callback(err)
|
9209 | closed(self)
|
9210 | callback()
|
9211 | })
|
9212 | }
|
9213 |
|
9214 | function open (self) {
|
9215 | deferrables.concat('iterator').forEach(function (m) {
|
9216 | self['_' + m] = function () {
|
9217 | return this._db[m].apply(this._db, arguments)
|
9218 | }
|
9219 | })
|
9220 | if (self._db.approximateSize) {
|
9221 | self.approximateSize = function () {
|
9222 | return this._db.approximateSize.apply(this._db, arguments)
|
9223 | }
|
9224 | }
|
9225 | }
|
9226 |
|
9227 | function closed (self) {
|
9228 | deferrables.forEach(function (m) {
|
9229 | self['_' + m] = function () {
|
9230 | this._operations.push({ method: m, args: arguments })
|
9231 | }
|
9232 | })
|
9233 | if (typeof self._db.approximateSize === 'function') {
|
9234 | self.approximateSize = function () {
|
9235 | this._operations.push({
|
9236 | method: 'approximateSize',
|
9237 | args: arguments
|
9238 | })
|
9239 | }
|
9240 | }
|
9241 | self._iterator = function (options) {
|
9242 | var it = new DeferredIterator(options)
|
9243 | this._iterators.push(it)
|
9244 | return it
|
9245 | }
|
9246 | }
|
9247 |
|
9248 | DeferredLevelDOWN.prototype._serializeKey = function (key) {
|
9249 | return key
|
9250 | }
|
9251 |
|
9252 | DeferredLevelDOWN.prototype._serializeValue = function (value) {
|
9253 | return value
|
9254 | }
|
9255 |
|
9256 | module.exports = DeferredLevelDOWN
|
9257 | module.exports.DeferredIterator = DeferredIterator
|
9258 |
|
9259 | },{"26":26,"48":48,"49":49}],51:[function(_dereq_,module,exports){
|
9260 |
|
9261 |
|
9262 |
|
9263 |
|
9264 |
|
9265 |
|
9266 | var createError = _dereq_(17).create
|
9267 | var LevelUPError = createError('LevelUPError')
|
9268 | var NotFoundError = createError('NotFoundError', LevelUPError)
|
9269 |
|
9270 | NotFoundError.prototype.notFound = true
|
9271 | NotFoundError.prototype.status = 404
|
9272 |
|
9273 | module.exports = {
|
9274 | LevelUPError: LevelUPError,
|
9275 | InitializationError: createError('InitializationError', LevelUPError),
|
9276 | OpenError: createError('OpenError', LevelUPError),
|
9277 | ReadError: createError('ReadError', LevelUPError),
|
9278 | WriteError: createError('WriteError', LevelUPError),
|
9279 | NotFoundError: NotFoundError,
|
9280 | EncodingError: createError('EncodingError', LevelUPError)
|
9281 | }
|
9282 |
|
9283 | },{"17":17}],52:[function(_dereq_,module,exports){
|
9284 | arguments[4][41][0].apply(exports,arguments)
|
9285 | },{"41":41}],53:[function(_dereq_,module,exports){
|
9286 | (function (Buffer){
|
9287 |
|
9288 | exports.compare = function (a, b) {
|
9289 |
|
9290 | if(Buffer.isBuffer(a)) {
|
9291 | var l = Math.min(a.length, b.length)
|
9292 | for(var i = 0; i < l; i++) {
|
9293 | var cmp = a[i] - b[i]
|
9294 | if(cmp) return cmp
|
9295 | }
|
9296 | return a.length - b.length
|
9297 | }
|
9298 |
|
9299 | return a < b ? -1 : a > b ? 1 : 0
|
9300 | }
|
9301 |
|
9302 |
|
9303 |
|
9304 |
|
9305 |
|
9306 |
|
9307 | function isDef (val) {
|
9308 | return val !== undefined && val !== ''
|
9309 | }
|
9310 |
|
9311 | function has (range, name) {
|
9312 | return Object.hasOwnProperty.call(range, name)
|
9313 | }
|
9314 |
|
9315 | function hasKey(range, name) {
|
9316 | return Object.hasOwnProperty.call(range, name) && name
|
9317 | }
|
9318 |
|
9319 | var lowerBoundKey = exports.lowerBoundKey = function (range) {
|
9320 | return (
|
9321 | hasKey(range, 'gt')
|
9322 | || hasKey(range, 'gte')
|
9323 | || hasKey(range, 'min')
|
9324 | || (range.reverse ? hasKey(range, 'end') : hasKey(range, 'start'))
|
9325 | || undefined
|
9326 | )
|
9327 | }
|
9328 |
|
9329 | var lowerBound = exports.lowerBound = function (range, def) {
|
9330 | var k = lowerBoundKey(range)
|
9331 | return k ? range[k] : def
|
9332 | }
|
9333 |
|
9334 | var lowerBoundInclusive = exports.lowerBoundInclusive = function (range) {
|
9335 | return has(range, 'gt') ? false : true
|
9336 | }
|
9337 |
|
9338 | var upperBoundInclusive = exports.upperBoundInclusive =
|
9339 | function (range) {
|
9340 | return (has(range, 'lt') ) ? false : true
|
9341 | }
|
9342 |
|
9343 | var lowerBoundExclusive = exports.lowerBoundExclusive =
|
9344 | function (range) {
|
9345 | return !lowerBoundInclusive(range)
|
9346 | }
|
9347 |
|
9348 | var upperBoundExclusive = exports.upperBoundExclusive =
|
9349 | function (range) {
|
9350 | return !upperBoundInclusive(range)
|
9351 | }
|
9352 |
|
9353 | var upperBoundKey = exports.upperBoundKey = function (range) {
|
9354 | return (
|
9355 | hasKey(range, 'lt')
|
9356 | || hasKey(range, 'lte')
|
9357 | || hasKey(range, 'max')
|
9358 | || (range.reverse ? hasKey(range, 'start') : hasKey(range, 'end'))
|
9359 | || undefined
|
9360 | )
|
9361 | }
|
9362 |
|
9363 | var upperBound = exports.upperBound = function (range, def) {
|
9364 | var k = upperBoundKey(range)
|
9365 | return k ? range[k] : def
|
9366 | }
|
9367 |
|
9368 | exports.start = function (range, def) {
|
9369 | return range.reverse ? upperBound(range, def) : lowerBound(range, def)
|
9370 | }
|
9371 | exports.end = function (range, def) {
|
9372 | return range.reverse ? lowerBound(range, def) : upperBound(range, def)
|
9373 | }
|
9374 | exports.startInclusive = function (range) {
|
9375 | return (
|
9376 | range.reverse
|
9377 | ? upperBoundInclusive(range)
|
9378 | : lowerBoundInclusive(range)
|
9379 | )
|
9380 | }
|
9381 | exports.endInclusive = function (range) {
|
9382 | return (
|
9383 | range.reverse
|
9384 | ? lowerBoundInclusive(range)
|
9385 | : upperBoundInclusive(range)
|
9386 | )
|
9387 | }
|
9388 |
|
9389 | function id (e) { return e }
|
9390 |
|
9391 | exports.toLtgt = function (range, _range, map, lower, upper) {
|
9392 | _range = _range || {}
|
9393 | map = map || id
|
9394 | var defaults = arguments.length > 3
|
9395 | var lb = exports.lowerBoundKey(range)
|
9396 | var ub = exports.upperBoundKey(range)
|
9397 | if(lb) {
|
9398 | if(lb === 'gt') _range.gt = map(range.gt, false)
|
9399 | else _range.gte = map(range[lb], false)
|
9400 | }
|
9401 | else if(defaults)
|
9402 | _range.gte = map(lower, false)
|
9403 |
|
9404 | if(ub) {
|
9405 | if(ub === 'lt') _range.lt = map(range.lt, true)
|
9406 | else _range.lte = map(range[ub], true)
|
9407 | }
|
9408 | else if(defaults)
|
9409 | _range.lte = map(upper, true)
|
9410 |
|
9411 | if(range.reverse != null)
|
9412 | _range.reverse = !!range.reverse
|
9413 |
|
9414 |
|
9415 |
|
9416 |
|
9417 | if(has(_range, 'max')) delete _range.max
|
9418 | if(has(_range, 'min')) delete _range.min
|
9419 | if(has(_range, 'start')) delete _range.start
|
9420 | if(has(_range, 'end')) delete _range.end
|
9421 |
|
9422 | return _range
|
9423 | }
|
9424 |
|
9425 | exports.contains = function (range, key, compare) {
|
9426 | compare = compare || exports.compare
|
9427 |
|
9428 | var lb = lowerBound(range)
|
9429 | if(isDef(lb)) {
|
9430 | var cmp = compare(key, lb)
|
9431 | if(cmp < 0 || (cmp === 0 && lowerBoundExclusive(range)))
|
9432 | return false
|
9433 | }
|
9434 |
|
9435 | var ub = upperBound(range)
|
9436 | if(isDef(ub)) {
|
9437 | var cmp = compare(key, ub)
|
9438 | if(cmp > 0 || (cmp === 0) && upperBoundExclusive(range))
|
9439 | return false
|
9440 | }
|
9441 |
|
9442 | return true
|
9443 | }
|
9444 |
|
9445 | exports.filter = function (range, compare) {
|
9446 | return function (key) {
|
9447 | return exports.contains(range, key, compare)
|
9448 | }
|
9449 | }
|
9450 |
|
9451 |
|
9452 |
|
9453 | }).call(this,{"isBuffer":_dereq_(27)})
|
9454 | },{"27":27}],54:[function(_dereq_,module,exports){
|
9455 | (function (process){
|
9456 | 'use strict';
|
9457 |
|
9458 | if (!process.version ||
|
9459 | process.version.indexOf('v0.') === 0 ||
|
9460 | process.version.indexOf('v1.') === 0 && process.version.indexOf('v1.8.') !== 0) {
|
9461 | module.exports = { nextTick: nextTick };
|
9462 | } else {
|
9463 | module.exports = process
|
9464 | }
|
9465 |
|
9466 | function nextTick(fn, arg1, arg2, arg3) {
|
9467 | if (typeof fn !== 'function') {
|
9468 | throw new TypeError('"callback" argument must be a function');
|
9469 | }
|
9470 | var len = arguments.length;
|
9471 | var args, i;
|
9472 | switch (len) {
|
9473 | case 0:
|
9474 | case 1:
|
9475 | return process.nextTick(fn);
|
9476 | case 2:
|
9477 | return process.nextTick(function afterTickOne() {
|
9478 | fn.call(null, arg1);
|
9479 | });
|
9480 | case 3:
|
9481 | return process.nextTick(function afterTickTwo() {
|
9482 | fn.call(null, arg1, arg2);
|
9483 | });
|
9484 | case 4:
|
9485 | return process.nextTick(function afterTickThree() {
|
9486 | fn.call(null, arg1, arg2, arg3);
|
9487 | });
|
9488 | default:
|
9489 | args = new Array(len - 1);
|
9490 | i = 0;
|
9491 | while (i < args.length) {
|
9492 | args[i++] = arguments[i];
|
9493 | }
|
9494 | return process.nextTick(function afterTick() {
|
9495 | fn.apply(null, args);
|
9496 | });
|
9497 | }
|
9498 | }
|
9499 |
|
9500 |
|
9501 | }).call(this,_dereq_(55))
|
9502 | },{"55":55}],55:[function(_dereq_,module,exports){
|
9503 |
|
9504 | var process = module.exports = {};
|
9505 |
|
9506 |
|
9507 |
|
9508 |
|
9509 |
|
9510 |
|
9511 | var cachedSetTimeout;
|
9512 | var cachedClearTimeout;
|
9513 |
|
9514 | function defaultSetTimout() {
|
9515 | throw new Error('setTimeout has not been defined');
|
9516 | }
|
9517 | function defaultClearTimeout () {
|
9518 | throw new Error('clearTimeout has not been defined');
|
9519 | }
|
9520 | (function () {
|
9521 | try {
|
9522 | if (typeof setTimeout === 'function') {
|
9523 | cachedSetTimeout = setTimeout;
|
9524 | } else {
|
9525 | cachedSetTimeout = defaultSetTimout;
|
9526 | }
|
9527 | } catch (e) {
|
9528 | cachedSetTimeout = defaultSetTimout;
|
9529 | }
|
9530 | try {
|
9531 | if (typeof clearTimeout === 'function') {
|
9532 | cachedClearTimeout = clearTimeout;
|
9533 | } else {
|
9534 | cachedClearTimeout = defaultClearTimeout;
|
9535 | }
|
9536 | } catch (e) {
|
9537 | cachedClearTimeout = defaultClearTimeout;
|
9538 | }
|
9539 | } ())
|
9540 | function runTimeout(fun) {
|
9541 | if (cachedSetTimeout === setTimeout) {
|
9542 |
|
9543 | return setTimeout(fun, 0);
|
9544 | }
|
9545 |
|
9546 | if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
|
9547 | cachedSetTimeout = setTimeout;
|
9548 | return setTimeout(fun, 0);
|
9549 | }
|
9550 | try {
|
9551 |
|
9552 | return cachedSetTimeout(fun, 0);
|
9553 | } catch(e){
|
9554 | try {
|
9555 |
|
9556 | return cachedSetTimeout.call(null, fun, 0);
|
9557 | } catch(e){
|
9558 |
|
9559 | return cachedSetTimeout.call(this, fun, 0);
|
9560 | }
|
9561 | }
|
9562 |
|
9563 |
|
9564 | }
|
9565 | function runClearTimeout(marker) {
|
9566 | if (cachedClearTimeout === clearTimeout) {
|
9567 |
|
9568 | return clearTimeout(marker);
|
9569 | }
|
9570 |
|
9571 | if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
|
9572 | cachedClearTimeout = clearTimeout;
|
9573 | return clearTimeout(marker);
|
9574 | }
|
9575 | try {
|
9576 |
|
9577 | return cachedClearTimeout(marker);
|
9578 | } catch (e){
|
9579 | try {
|
9580 |
|
9581 | return cachedClearTimeout.call(null, marker);
|
9582 | } catch (e){
|
9583 |
|
9584 |
|
9585 | return cachedClearTimeout.call(this, marker);
|
9586 | }
|
9587 | }
|
9588 |
|
9589 |
|
9590 |
|
9591 | }
|
9592 | var queue = [];
|
9593 | var draining = false;
|
9594 | var currentQueue;
|
9595 | var queueIndex = -1;
|
9596 |
|
9597 | function cleanUpNextTick() {
|
9598 | if (!draining || !currentQueue) {
|
9599 | return;
|
9600 | }
|
9601 | draining = false;
|
9602 | if (currentQueue.length) {
|
9603 | queue = currentQueue.concat(queue);
|
9604 | } else {
|
9605 | queueIndex = -1;
|
9606 | }
|
9607 | if (queue.length) {
|
9608 | drainQueue();
|
9609 | }
|
9610 | }
|
9611 |
|
9612 | function drainQueue() {
|
9613 | if (draining) {
|
9614 | return;
|
9615 | }
|
9616 | var timeout = runTimeout(cleanUpNextTick);
|
9617 | draining = true;
|
9618 |
|
9619 | var len = queue.length;
|
9620 | while(len) {
|
9621 | currentQueue = queue;
|
9622 | queue = [];
|
9623 | while (++queueIndex < len) {
|
9624 | if (currentQueue) {
|
9625 | currentQueue[queueIndex].run();
|
9626 | }
|
9627 | }
|
9628 | queueIndex = -1;
|
9629 | len = queue.length;
|
9630 | }
|
9631 | currentQueue = null;
|
9632 | draining = false;
|
9633 | runClearTimeout(timeout);
|
9634 | }
|
9635 |
|
9636 | process.nextTick = function (fun) {
|
9637 | var args = new Array(arguments.length - 1);
|
9638 | if (arguments.length > 1) {
|
9639 | for (var i = 1; i < arguments.length; i++) {
|
9640 | args[i - 1] = arguments[i];
|
9641 | }
|
9642 | }
|
9643 | queue.push(new Item(fun, args));
|
9644 | if (queue.length === 1 && !draining) {
|
9645 | runTimeout(drainQueue);
|
9646 | }
|
9647 | };
|
9648 |
|
9649 |
|
9650 | function Item(fun, array) {
|
9651 | this.fun = fun;
|
9652 | this.array = array;
|
9653 | }
|
9654 | Item.prototype.run = function () {
|
9655 | this.fun.apply(null, this.array);
|
9656 | };
|
9657 | process.title = 'browser';
|
9658 | process.browser = true;
|
9659 | process.env = {};
|
9660 | process.argv = [];
|
9661 | process.version = '';
|
9662 | process.versions = {};
|
9663 |
|
9664 | function noop() {}
|
9665 |
|
9666 | process.on = noop;
|
9667 | process.addListener = noop;
|
9668 | process.once = noop;
|
9669 | process.off = noop;
|
9670 | process.removeListener = noop;
|
9671 | process.removeAllListeners = noop;
|
9672 | process.emit = noop;
|
9673 | process.prependListener = noop;
|
9674 | process.prependOnceListener = noop;
|
9675 |
|
9676 | process.listeners = function (name) { return [] }
|
9677 |
|
9678 | process.binding = function (name) {
|
9679 | throw new Error('process.binding is not supported');
|
9680 | };
|
9681 |
|
9682 | process.cwd = function () { return '/' };
|
9683 | process.chdir = function (dir) {
|
9684 | throw new Error('process.chdir is not supported');
|
9685 | };
|
9686 | process.umask = function() { return 0; };
|
9687 |
|
9688 | },{}],56:[function(_dereq_,module,exports){
|
9689 |
|
9690 |
|
9691 |
|
9692 |
|
9693 |
|
9694 |
|
9695 |
|
9696 | (function (name, context, definition) {
|
9697 | if (typeof module != 'undefined' && module.exports)
|
9698 | module.exports = definition()
|
9699 | else
|
9700 | context[name] = definition()
|
9701 | })('prr', this, function() {
|
9702 |
|
9703 | var setProperty = typeof Object.defineProperty == 'function'
|
9704 | ? function (obj, key, options) {
|
9705 | Object.defineProperty(obj, key, options)
|
9706 | return obj
|
9707 | }
|
9708 | : function (obj, key, options) {
|
9709 | obj[key] = options.value
|
9710 | return obj
|
9711 | }
|
9712 |
|
9713 | , makeOptions = function (value, options) {
|
9714 | var oo = typeof options == 'object'
|
9715 | , os = !oo && typeof options == 'string'
|
9716 | , op = function (p) {
|
9717 | return oo
|
9718 | ? !!options[p]
|
9719 | : os
|
9720 | ? options.indexOf(p[0]) > -1
|
9721 | : false
|
9722 | }
|
9723 |
|
9724 | return {
|
9725 | enumerable : op('enumerable')
|
9726 | , configurable : op('configurable')
|
9727 | , writable : op('writable')
|
9728 | , value : value
|
9729 | }
|
9730 | }
|
9731 |
|
9732 | , prr = function (obj, key, value, options) {
|
9733 | var k
|
9734 |
|
9735 | options = makeOptions(value, options)
|
9736 |
|
9737 | if (typeof key == 'object') {
|
9738 | for (k in key) {
|
9739 | if (Object.hasOwnProperty.call(key, k)) {
|
9740 | options.value = key[k]
|
9741 | setProperty(obj, k, options)
|
9742 | }
|
9743 | }
|
9744 | return obj
|
9745 | }
|
9746 |
|
9747 | return setProperty(obj, key, options)
|
9748 | }
|
9749 |
|
9750 | return prr
|
9751 | })
|
9752 | },{}],57:[function(_dereq_,module,exports){
|
9753 | (function (process){
|
9754 |
|
9755 |
|
9756 |
|
9757 |
|
9758 |
|
9759 |
|
9760 |
|
9761 |
|
9762 |
|
9763 |
|
9764 |
|
9765 |
|
9766 |
|
9767 |
|
9768 |
|
9769 |
|
9770 |
|
9771 |
|
9772 |
|
9773 |
|
9774 |
|
9775 |
|
9776 |
|
9777 |
|
9778 |
|
9779 |
|
9780 | module.exports = Duplex;
|
9781 |
|
9782 |
|
9783 | var objectKeys = Object.keys || function (obj) {
|
9784 | var keys = [];
|
9785 | for (var key in obj) keys.push(key);
|
9786 | return keys;
|
9787 | }
|
9788 |
|
9789 |
|
9790 |
|
9791 |
|
9792 | var util = _dereq_(13);
|
9793 | util.inherits = _dereq_(26);
|
9794 |
|
9795 |
|
9796 | var Readable = _dereq_(59);
|
9797 | var Writable = _dereq_(61);
|
9798 |
|
9799 | util.inherits(Duplex, Readable);
|
9800 |
|
9801 | forEach(objectKeys(Writable.prototype), function(method) {
|
9802 | if (!Duplex.prototype[method])
|
9803 | Duplex.prototype[method] = Writable.prototype[method];
|
9804 | });
|
9805 |
|
9806 | function Duplex(options) {
|
9807 | if (!(this instanceof Duplex))
|
9808 | return new Duplex(options);
|
9809 |
|
9810 | Readable.call(this, options);
|
9811 | Writable.call(this, options);
|
9812 |
|
9813 | if (options && options.readable === false)
|
9814 | this.readable = false;
|
9815 |
|
9816 | if (options && options.writable === false)
|
9817 | this.writable = false;
|
9818 |
|
9819 | this.allowHalfOpen = true;
|
9820 | if (options && options.allowHalfOpen === false)
|
9821 | this.allowHalfOpen = false;
|
9822 |
|
9823 | this.once('end', onend);
|
9824 | }
|
9825 |
|
9826 |
|
9827 | function onend() {
|
9828 |
|
9829 |
|
9830 | if (this.allowHalfOpen || this._writableState.ended)
|
9831 | return;
|
9832 |
|
9833 |
|
9834 |
|
9835 | process.nextTick(this.end.bind(this));
|
9836 | }
|
9837 |
|
9838 | function forEach (xs, f) {
|
9839 | for (var i = 0, l = xs.length; i < l; i++) {
|
9840 | f(xs[i], i);
|
9841 | }
|
9842 | }
|
9843 |
|
9844 | }).call(this,_dereq_(55))
|
9845 | },{"13":13,"26":26,"55":55,"59":59,"61":61}],58:[function(_dereq_,module,exports){
|
9846 |
|
9847 |
|
9848 |
|
9849 |
|
9850 |
|
9851 |
|
9852 |
|
9853 |
|
9854 |
|
9855 |
|
9856 |
|
9857 |
|
9858 |
|
9859 |
|
9860 |
|
9861 |
|
9862 |
|
9863 |
|
9864 |
|
9865 |
|
9866 |
|
9867 |
|
9868 |
|
9869 |
|
9870 |
|
9871 | module.exports = PassThrough;
|
9872 |
|
9873 | var Transform = _dereq_(60);
|
9874 |
|
9875 |
|
9876 | var util = _dereq_(13);
|
9877 | util.inherits = _dereq_(26);
|
9878 |
|
9879 |
|
9880 | util.inherits(PassThrough, Transform);
|
9881 |
|
9882 | function PassThrough(options) {
|
9883 | if (!(this instanceof PassThrough))
|
9884 | return new PassThrough(options);
|
9885 |
|
9886 | Transform.call(this, options);
|
9887 | }
|
9888 |
|
9889 | PassThrough.prototype._transform = function(chunk, encoding, cb) {
|
9890 | cb(null, chunk);
|
9891 | };
|
9892 |
|
9893 | },{"13":13,"26":26,"60":60}],59:[function(_dereq_,module,exports){
|
9894 | (function (process){
|
9895 |
|
9896 |
|
9897 |
|
9898 |
|
9899 |
|
9900 |
|
9901 |
|
9902 |
|
9903 |
|
9904 |
|
9905 |
|
9906 |
|
9907 |
|
9908 |
|
9909 |
|
9910 |
|
9911 |
|
9912 |
|
9913 |
|
9914 |
|
9915 |
|
9916 | module.exports = Readable;
|
9917 |
|
9918 |
|
9919 | var isArray = _dereq_(62);
|
9920 |
|
9921 |
|
9922 |
|
9923 |
|
9924 | var Buffer = _dereq_(12).Buffer;
|
9925 |
|
9926 |
|
9927 | Readable.ReadableState = ReadableState;
|
9928 |
|
9929 | var EE = _dereq_(18).EventEmitter;
|
9930 |
|
9931 |
|
9932 | if (!EE.listenerCount) EE.listenerCount = function(emitter, type) {
|
9933 | return emitter.listeners(type).length;
|
9934 | };
|
9935 |
|
9936 |
|
9937 | var Stream = _dereq_(67);
|
9938 |
|
9939 |
|
9940 | var util = _dereq_(13);
|
9941 | util.inherits = _dereq_(26);
|
9942 |
|
9943 |
|
9944 | var StringDecoder;
|
9945 |
|
9946 | util.inherits(Readable, Stream);
|
9947 |
|
9948 | function ReadableState(options, stream) {
|
9949 | options = options || {};
|
9950 |
|
9951 |
|
9952 |
|
9953 | var hwm = options.highWaterMark;
|
9954 | this.highWaterMark = (hwm || hwm === 0) ? hwm : 16 * 1024;
|
9955 |
|
9956 |
|
9957 | this.highWaterMark = ~~this.highWaterMark;
|
9958 |
|
9959 | this.buffer = [];
|
9960 | this.length = 0;
|
9961 | this.pipes = null;
|
9962 | this.pipesCount = 0;
|
9963 | this.flowing = false;
|
9964 | this.ended = false;
|
9965 | this.endEmitted = false;
|
9966 | this.reading = false;
|
9967 |
|
9968 |
|
9969 |
|
9970 |
|
9971 |
|
9972 | this.calledRead = false;
|
9973 |
|
9974 |
|
9975 |
|
9976 |
|
9977 |
|
9978 | this.sync = true;
|
9979 |
|
9980 |
|
9981 |
|
9982 | this.needReadable = false;
|
9983 | this.emittedReadable = false;
|
9984 | this.readableListening = false;
|
9985 |
|
9986 |
|
9987 |
|
9988 |
|
9989 | this.objectMode = !!options.objectMode;
|
9990 |
|
9991 |
|
9992 |
|
9993 |
|
9994 | this.defaultEncoding = options.defaultEncoding || 'utf8';
|
9995 |
|
9996 |
|
9997 |
|
9998 | this.ranOut = false;
|
9999 |
|
10000 |
|
10001 | this.awaitDrain = 0;
|
10002 |
|
10003 |
|
10004 | this.readingMore = false;
|
10005 |
|
10006 | this.decoder = null;
|
10007 | this.encoding = null;
|
10008 | if (options.encoding) {
|
10009 | if (!StringDecoder)
|
10010 | StringDecoder = _dereq_(63).StringDecoder;
|
10011 | this.decoder = new StringDecoder(options.encoding);
|
10012 | this.encoding = options.encoding;
|
10013 | }
|
10014 | }
|
10015 |
|
10016 | function Readable(options) {
|
10017 | if (!(this instanceof Readable))
|
10018 | return new Readable(options);
|
10019 |
|
10020 | this._readableState = new ReadableState(options, this);
|
10021 |
|
10022 |
|
10023 | this.readable = true;
|
10024 |
|
10025 | Stream.call(this);
|
10026 | }
|
10027 |
|
10028 |
|
10029 |
|
10030 |
|
10031 |
|
10032 | Readable.prototype.push = function(chunk, encoding) {
|
10033 | var state = this._readableState;
|
10034 |
|
10035 | if (typeof chunk === 'string' && !state.objectMode) {
|
10036 | encoding = encoding || state.defaultEncoding;
|
10037 | if (encoding !== state.encoding) {
|
10038 | chunk = new Buffer(chunk, encoding);
|
10039 | encoding = '';
|
10040 | }
|
10041 | }
|
10042 |
|
10043 | return readableAddChunk(this, state, chunk, encoding, false);
|
10044 | };
|
10045 |
|
10046 |
|
10047 | Readable.prototype.unshift = function(chunk) {
|
10048 | var state = this._readableState;
|
10049 | return readableAddChunk(this, state, chunk, '', true);
|
10050 | };
|
10051 |
|
10052 | function readableAddChunk(stream, state, chunk, encoding, addToFront) {
|
10053 | var er = chunkInvalid(state, chunk);
|
10054 | if (er) {
|
10055 | stream.emit('error', er);
|
10056 | } else if (chunk === null || chunk === undefined) {
|
10057 | state.reading = false;
|
10058 | if (!state.ended)
|
10059 | onEofChunk(stream, state);
|
10060 | } else if (state.objectMode || chunk && chunk.length > 0) {
|
10061 | if (state.ended && !addToFront) {
|
10062 | var e = new Error('stream.push() after EOF');
|
10063 | stream.emit('error', e);
|
10064 | } else if (state.endEmitted && addToFront) {
|
10065 | var e = new Error('stream.unshift() after end event');
|
10066 | stream.emit('error', e);
|
10067 | } else {
|
10068 | if (state.decoder && !addToFront && !encoding)
|
10069 | chunk = state.decoder.write(chunk);
|
10070 |
|
10071 |
|
10072 | state.length += state.objectMode ? 1 : chunk.length;
|
10073 | if (addToFront) {
|
10074 | state.buffer.unshift(chunk);
|
10075 | } else {
|
10076 | state.reading = false;
|
10077 | state.buffer.push(chunk);
|
10078 | }
|
10079 |
|
10080 | if (state.needReadable)
|
10081 | emitReadable(stream);
|
10082 |
|
10083 | maybeReadMore(stream, state);
|
10084 | }
|
10085 | } else if (!addToFront) {
|
10086 | state.reading = false;
|
10087 | }
|
10088 |
|
10089 | return needMoreData(state);
|
10090 | }
|
10091 |
|
10092 |
|
10093 |
|
10094 |
|
10095 |
|
10096 |
|
10097 |
|
10098 |
|
10099 |
|
10100 |
|
10101 | function needMoreData(state) {
|
10102 | return !state.ended &&
|
10103 | (state.needReadable ||
|
10104 | state.length < state.highWaterMark ||
|
10105 | state.length === 0);
|
10106 | }
|
10107 |
|
10108 |
|
10109 | Readable.prototype.setEncoding = function(enc) {
|
10110 | if (!StringDecoder)
|
10111 | StringDecoder = _dereq_(63).StringDecoder;
|
10112 | this._readableState.decoder = new StringDecoder(enc);
|
10113 | this._readableState.encoding = enc;
|
10114 | };
|
10115 |
|
10116 |
|
10117 | var MAX_HWM = 0x800000;
|
10118 | function roundUpToNextPowerOf2(n) {
|
10119 | if (n >= MAX_HWM) {
|
10120 | n = MAX_HWM;
|
10121 | } else {
|
10122 |
|
10123 | n--;
|
10124 | for (var p = 1; p < 32; p <<= 1) n |= n >> p;
|
10125 | n++;
|
10126 | }
|
10127 | return n;
|
10128 | }
|
10129 |
|
10130 | function howMuchToRead(n, state) {
|
10131 | if (state.length === 0 && state.ended)
|
10132 | return 0;
|
10133 |
|
10134 | if (state.objectMode)
|
10135 | return n === 0 ? 0 : 1;
|
10136 |
|
10137 | if (n === null || isNaN(n)) {
|
10138 |
|
10139 | if (state.flowing && state.buffer.length)
|
10140 | return state.buffer[0].length;
|
10141 | else
|
10142 | return state.length;
|
10143 | }
|
10144 |
|
10145 | if (n <= 0)
|
10146 | return 0;
|
10147 |
|
10148 |
|
10149 |
|
10150 |
|
10151 |
|
10152 | if (n > state.highWaterMark)
|
10153 | state.highWaterMark = roundUpToNextPowerOf2(n);
|
10154 |
|
10155 |
|
10156 | if (n > state.length) {
|
10157 | if (!state.ended) {
|
10158 | state.needReadable = true;
|
10159 | return 0;
|
10160 | } else
|
10161 | return state.length;
|
10162 | }
|
10163 |
|
10164 | return n;
|
10165 | }
|
10166 |
|
10167 |
|
10168 | Readable.prototype.read = function(n) {
|
10169 | var state = this._readableState;
|
10170 | state.calledRead = true;
|
10171 | var nOrig = n;
|
10172 | var ret;
|
10173 |
|
10174 | if (typeof n !== 'number' || n > 0)
|
10175 | state.emittedReadable = false;
|
10176 |
|
10177 |
|
10178 |
|
10179 |
|
10180 | if (n === 0 &&
|
10181 | state.needReadable &&
|
10182 | (state.length >= state.highWaterMark || state.ended)) {
|
10183 | emitReadable(this);
|
10184 | return null;
|
10185 | }
|
10186 |
|
10187 | n = howMuchToRead(n, state);
|
10188 |
|
10189 |
|
10190 | if (n === 0 && state.ended) {
|
10191 | ret = null;
|
10192 |
|
10193 |
|
10194 |
|
10195 |
|
10196 |
|
10197 |
|
10198 |
|
10199 |
|
10200 |
|
10201 |
|
10202 |
|
10203 |
|
10204 | if (state.length > 0 && state.decoder) {
|
10205 | ret = fromList(n, state);
|
10206 | state.length -= ret.length;
|
10207 | }
|
10208 |
|
10209 | if (state.length === 0)
|
10210 | endReadable(this);
|
10211 |
|
10212 | return ret;
|
10213 | }
|
10214 |
|
10215 |
|
10216 |
|
10217 |
|
10218 |
|
10219 |
|
10220 |
|
10221 |
|
10222 |
|
10223 |
|
10224 |
|
10225 |
|
10226 |
|
10227 |
|
10228 |
|
10229 |
|
10230 |
|
10231 |
|
10232 |
|
10233 |
|
10234 |
|
10235 |
|
10236 |
|
10237 |
|
10238 | var doRead = state.needReadable;
|
10239 |
|
10240 |
|
10241 | if (state.length - n <= state.highWaterMark)
|
10242 | doRead = true;
|
10243 |
|
10244 |
|
10245 |
|
10246 | if (state.ended || state.reading)
|
10247 | doRead = false;
|
10248 |
|
10249 | if (doRead) {
|
10250 | state.reading = true;
|
10251 | state.sync = true;
|
10252 |
|
10253 | if (state.length === 0)
|
10254 | state.needReadable = true;
|
10255 |
|
10256 | this._read(state.highWaterMark);
|
10257 | state.sync = false;
|
10258 | }
|
10259 |
|
10260 |
|
10261 |
|
10262 |
|
10263 | if (doRead && !state.reading)
|
10264 | n = howMuchToRead(nOrig, state);
|
10265 |
|
10266 | if (n > 0)
|
10267 | ret = fromList(n, state);
|
10268 | else
|
10269 | ret = null;
|
10270 |
|
10271 | if (ret === null) {
|
10272 | state.needReadable = true;
|
10273 | n = 0;
|
10274 | }
|
10275 |
|
10276 | state.length -= n;
|
10277 |
|
10278 |
|
10279 |
|
10280 | if (state.length === 0 && !state.ended)
|
10281 | state.needReadable = true;
|
10282 |
|
10283 |
|
10284 |
|
10285 |
|
10286 | if (state.ended && !state.endEmitted && state.length === 0)
|
10287 | endReadable(this);
|
10288 |
|
10289 | return ret;
|
10290 | };
|
10291 |
|
10292 | function chunkInvalid(state, chunk) {
|
10293 | var er = null;
|
10294 | if (!Buffer.isBuffer(chunk) &&
|
10295 | 'string' !== typeof chunk &&
|
10296 | chunk !== null &&
|
10297 | chunk !== undefined &&
|
10298 | !state.objectMode) {
|
10299 | er = new TypeError('Invalid non-string/buffer chunk');
|
10300 | }
|
10301 | return er;
|
10302 | }
|
10303 |
|
10304 |
|
10305 | function onEofChunk(stream, state) {
|
10306 | if (state.decoder && !state.ended) {
|
10307 | var chunk = state.decoder.end();
|
10308 | if (chunk && chunk.length) {
|
10309 | state.buffer.push(chunk);
|
10310 | state.length += state.objectMode ? 1 : chunk.length;
|
10311 | }
|
10312 | }
|
10313 | state.ended = true;
|
10314 |
|
10315 |
|
10316 |
|
10317 | if (state.length > 0)
|
10318 | emitReadable(stream);
|
10319 | else
|
10320 | endReadable(stream);
|
10321 | }
|
10322 |
|
10323 |
|
10324 |
|
10325 |
|
10326 | function emitReadable(stream) {
|
10327 | var state = stream._readableState;
|
10328 | state.needReadable = false;
|
10329 | if (state.emittedReadable)
|
10330 | return;
|
10331 |
|
10332 | state.emittedReadable = true;
|
10333 | if (state.sync)
|
10334 | process.nextTick(function() {
|
10335 | emitReadable_(stream);
|
10336 | });
|
10337 | else
|
10338 | emitReadable_(stream);
|
10339 | }
|
10340 |
|
10341 | function emitReadable_(stream) {
|
10342 | stream.emit('readable');
|
10343 | }
|
10344 |
|
10345 |
|
10346 |
|
10347 |
|
10348 |
|
10349 |
|
10350 |
|
10351 |
|
10352 | function maybeReadMore(stream, state) {
|
10353 | if (!state.readingMore) {
|
10354 | state.readingMore = true;
|
10355 | process.nextTick(function() {
|
10356 | maybeReadMore_(stream, state);
|
10357 | });
|
10358 | }
|
10359 | }
|
10360 |
|
10361 | function maybeReadMore_(stream, state) {
|
10362 | var len = state.length;
|
10363 | while (!state.reading && !state.flowing && !state.ended &&
|
10364 | state.length < state.highWaterMark) {
|
10365 | stream.read(0);
|
10366 | if (len === state.length)
|
10367 |
|
10368 | break;
|
10369 | else
|
10370 | len = state.length;
|
10371 | }
|
10372 | state.readingMore = false;
|
10373 | }
|
10374 |
|
10375 |
|
10376 |
|
10377 |
|
10378 |
|
10379 | Readable.prototype._read = function(n) {
|
10380 | this.emit('error', new Error('not implemented'));
|
10381 | };
|
10382 |
|
10383 | Readable.prototype.pipe = function(dest, pipeOpts) {
|
10384 | var src = this;
|
10385 | var state = this._readableState;
|
10386 |
|
10387 | switch (state.pipesCount) {
|
10388 | case 0:
|
10389 | state.pipes = dest;
|
10390 | break;
|
10391 | case 1:
|
10392 | state.pipes = [state.pipes, dest];
|
10393 | break;
|
10394 | default:
|
10395 | state.pipes.push(dest);
|
10396 | break;
|
10397 | }
|
10398 | state.pipesCount += 1;
|
10399 |
|
10400 | var doEnd = (!pipeOpts || pipeOpts.end !== false) &&
|
10401 | dest !== process.stdout &&
|
10402 | dest !== process.stderr;
|
10403 |
|
10404 | var endFn = doEnd ? onend : cleanup;
|
10405 | if (state.endEmitted)
|
10406 | process.nextTick(endFn);
|
10407 | else
|
10408 | src.once('end', endFn);
|
10409 |
|
10410 | dest.on('unpipe', onunpipe);
|
10411 | function onunpipe(readable) {
|
10412 | if (readable !== src) return;
|
10413 | cleanup();
|
10414 | }
|
10415 |
|
10416 | function onend() {
|
10417 | dest.end();
|
10418 | }
|
10419 |
|
10420 |
|
10421 |
|
10422 |
|
10423 |
|
10424 | var ondrain = pipeOnDrain(src);
|
10425 | dest.on('drain', ondrain);
|
10426 |
|
10427 | function cleanup() {
|
10428 |
|
10429 | dest.removeListener('close', onclose);
|
10430 | dest.removeListener('finish', onfinish);
|
10431 | dest.removeListener('drain', ondrain);
|
10432 | dest.removeListener('error', onerror);
|
10433 | dest.removeListener('unpipe', onunpipe);
|
10434 | src.removeListener('end', onend);
|
10435 | src.removeListener('end', cleanup);
|
10436 |
|
10437 |
|
10438 |
|
10439 |
|
10440 |
|
10441 |
|
10442 | if (!dest._writableState || dest._writableState.needDrain)
|
10443 | ondrain();
|
10444 | }
|
10445 |
|
10446 |
|
10447 |
|
10448 | function onerror(er) {
|
10449 | unpipe();
|
10450 | dest.removeListener('error', onerror);
|
10451 | if (EE.listenerCount(dest, 'error') === 0)
|
10452 | dest.emit('error', er);
|
10453 | }
|
10454 |
|
10455 |
|
10456 | if (!dest._events || !dest._events.error)
|
10457 | dest.on('error', onerror);
|
10458 | else if (isArray(dest._events.error))
|
10459 | dest._events.error.unshift(onerror);
|
10460 | else
|
10461 | dest._events.error = [onerror, dest._events.error];
|
10462 |
|
10463 |
|
10464 |
|
10465 |
|
10466 | function onclose() {
|
10467 | dest.removeListener('finish', onfinish);
|
10468 | unpipe();
|
10469 | }
|
10470 | dest.once('close', onclose);
|
10471 | function onfinish() {
|
10472 | dest.removeListener('close', onclose);
|
10473 | unpipe();
|
10474 | }
|
10475 | dest.once('finish', onfinish);
|
10476 |
|
10477 | function unpipe() {
|
10478 | src.unpipe(dest);
|
10479 | }
|
10480 |
|
10481 |
|
10482 | dest.emit('pipe', src);
|
10483 |
|
10484 |
|
10485 | if (!state.flowing) {
|
10486 |
|
10487 |
|
10488 |
|
10489 |
|
10490 | this.on('readable', pipeOnReadable);
|
10491 |
|
10492 | state.flowing = true;
|
10493 | process.nextTick(function() {
|
10494 | flow(src);
|
10495 | });
|
10496 | }
|
10497 |
|
10498 | return dest;
|
10499 | };
|
10500 |
|
10501 | function pipeOnDrain(src) {
|
10502 | return function() {
|
10503 | var dest = this;
|
10504 | var state = src._readableState;
|
10505 | state.awaitDrain--;
|
10506 | if (state.awaitDrain === 0)
|
10507 | flow(src);
|
10508 | };
|
10509 | }
|
10510 |
|
10511 | function flow(src) {
|
10512 | var state = src._readableState;
|
10513 | var chunk;
|
10514 | state.awaitDrain = 0;
|
10515 |
|
10516 | function write(dest, i, list) {
|
10517 | var written = dest.write(chunk);
|
10518 | if (false === written) {
|
10519 | state.awaitDrain++;
|
10520 | }
|
10521 | }
|
10522 |
|
10523 | while (state.pipesCount && null !== (chunk = src.read())) {
|
10524 |
|
10525 | if (state.pipesCount === 1)
|
10526 | write(state.pipes, 0, null);
|
10527 | else
|
10528 | forEach(state.pipes, write);
|
10529 |
|
10530 | src.emit('data', chunk);
|
10531 |
|
10532 |
|
10533 | if (state.awaitDrain > 0)
|
10534 | return;
|
10535 | }
|
10536 |
|
10537 |
|
10538 |
|
10539 |
|
10540 |
|
10541 | if (state.pipesCount === 0) {
|
10542 | state.flowing = false;
|
10543 |
|
10544 |
|
10545 | if (EE.listenerCount(src, 'data') > 0)
|
10546 | emitDataEvents(src);
|
10547 | return;
|
10548 | }
|
10549 |
|
10550 |
|
10551 |
|
10552 | state.ranOut = true;
|
10553 | }
|
10554 |
|
10555 | function pipeOnReadable() {
|
10556 | if (this._readableState.ranOut) {
|
10557 | this._readableState.ranOut = false;
|
10558 | flow(this);
|
10559 | }
|
10560 | }
|
10561 |
|
10562 |
|
10563 | Readable.prototype.unpipe = function(dest) {
|
10564 | var state = this._readableState;
|
10565 |
|
10566 |
|
10567 | if (state.pipesCount === 0)
|
10568 | return this;
|
10569 |
|
10570 |
|
10571 | if (state.pipesCount === 1) {
|
10572 |
|
10573 | if (dest && dest !== state.pipes)
|
10574 | return this;
|
10575 |
|
10576 | if (!dest)
|
10577 | dest = state.pipes;
|
10578 |
|
10579 |
|
10580 | state.pipes = null;
|
10581 | state.pipesCount = 0;
|
10582 | this.removeListener('readable', pipeOnReadable);
|
10583 | state.flowing = false;
|
10584 | if (dest)
|
10585 | dest.emit('unpipe', this);
|
10586 | return this;
|
10587 | }
|
10588 |
|
10589 |
|
10590 |
|
10591 | if (!dest) {
|
10592 |
|
10593 | var dests = state.pipes;
|
10594 | var len = state.pipesCount;
|
10595 | state.pipes = null;
|
10596 | state.pipesCount = 0;
|
10597 | this.removeListener('readable', pipeOnReadable);
|
10598 | state.flowing = false;
|
10599 |
|
10600 | for (var i = 0; i < len; i++)
|
10601 | dests[i].emit('unpipe', this);
|
10602 | return this;
|
10603 | }
|
10604 |
|
10605 |
|
10606 | var i = indexOf(state.pipes, dest);
|
10607 | if (i === -1)
|
10608 | return this;
|
10609 |
|
10610 | state.pipes.splice(i, 1);
|
10611 | state.pipesCount -= 1;
|
10612 | if (state.pipesCount === 1)
|
10613 | state.pipes = state.pipes[0];
|
10614 |
|
10615 | dest.emit('unpipe', this);
|
10616 |
|
10617 | return this;
|
10618 | };
|
10619 |
|
10620 |
|
10621 |
|
10622 | Readable.prototype.on = function(ev, fn) {
|
10623 | var res = Stream.prototype.on.call(this, ev, fn);
|
10624 |
|
10625 | if (ev === 'data' && !this._readableState.flowing)
|
10626 | emitDataEvents(this);
|
10627 |
|
10628 | if (ev === 'readable' && this.readable) {
|
10629 | var state = this._readableState;
|
10630 | if (!state.readableListening) {
|
10631 | state.readableListening = true;
|
10632 | state.emittedReadable = false;
|
10633 | state.needReadable = true;
|
10634 | if (!state.reading) {
|
10635 | this.read(0);
|
10636 | } else if (state.length) {
|
10637 | emitReadable(this, state);
|
10638 | }
|
10639 | }
|
10640 | }
|
10641 |
|
10642 | return res;
|
10643 | };
|
10644 | Readable.prototype.addListener = Readable.prototype.on;
|
10645 |
|
10646 |
|
10647 |
|
10648 | Readable.prototype.resume = function() {
|
10649 | emitDataEvents(this);
|
10650 | this.read(0);
|
10651 | this.emit('resume');
|
10652 | };
|
10653 |
|
10654 | Readable.prototype.pause = function() {
|
10655 | emitDataEvents(this, true);
|
10656 | this.emit('pause');
|
10657 | };
|
10658 |
|
10659 | function emitDataEvents(stream, startPaused) {
|
10660 | var state = stream._readableState;
|
10661 |
|
10662 | if (state.flowing) {
|
10663 |
|
10664 | throw new Error('Cannot switch to old mode now.');
|
10665 | }
|
10666 |
|
10667 | var paused = startPaused || false;
|
10668 | var readable = false;
|
10669 |
|
10670 |
|
10671 | stream.readable = true;
|
10672 | stream.pipe = Stream.prototype.pipe;
|
10673 | stream.on = stream.addListener = Stream.prototype.on;
|
10674 |
|
10675 | stream.on('readable', function() {
|
10676 | readable = true;
|
10677 |
|
10678 | var c;
|
10679 | while (!paused && (null !== (c = stream.read())))
|
10680 | stream.emit('data', c);
|
10681 |
|
10682 | if (c === null) {
|
10683 | readable = false;
|
10684 | stream._readableState.needReadable = true;
|
10685 | }
|
10686 | });
|
10687 |
|
10688 | stream.pause = function() {
|
10689 | paused = true;
|
10690 | this.emit('pause');
|
10691 | };
|
10692 |
|
10693 | stream.resume = function() {
|
10694 | paused = false;
|
10695 | if (readable)
|
10696 | process.nextTick(function() {
|
10697 | stream.emit('readable');
|
10698 | });
|
10699 | else
|
10700 | this.read(0);
|
10701 | this.emit('resume');
|
10702 | };
|
10703 |
|
10704 |
|
10705 | stream.emit('readable');
|
10706 | }
|
10707 |
|
10708 |
|
10709 |
|
10710 |
|
10711 | Readable.prototype.wrap = function(stream) {
|
10712 | var state = this._readableState;
|
10713 | var paused = false;
|
10714 |
|
10715 | var self = this;
|
10716 | stream.on('end', function() {
|
10717 | if (state.decoder && !state.ended) {
|
10718 | var chunk = state.decoder.end();
|
10719 | if (chunk && chunk.length)
|
10720 | self.push(chunk);
|
10721 | }
|
10722 |
|
10723 | self.push(null);
|
10724 | });
|
10725 |
|
10726 | stream.on('data', function(chunk) {
|
10727 | if (state.decoder)
|
10728 | chunk = state.decoder.write(chunk);
|
10729 |
|
10730 |
|
10731 |
|
10732 | if (state.objectMode && (chunk === null || chunk === undefined))
|
10733 | return;
|
10734 | else if (!state.objectMode && (!chunk || !chunk.length))
|
10735 | return;
|
10736 |
|
10737 | var ret = self.push(chunk);
|
10738 | if (!ret) {
|
10739 | paused = true;
|
10740 | stream.pause();
|
10741 | }
|
10742 | });
|
10743 |
|
10744 |
|
10745 |
|
10746 | for (var i in stream) {
|
10747 | if (typeof stream[i] === 'function' &&
|
10748 | typeof this[i] === 'undefined') {
|
10749 | this[i] = function(method) { return function() {
|
10750 | return stream[method].apply(stream, arguments);
|
10751 | }}(i);
|
10752 | }
|
10753 | }
|
10754 |
|
10755 |
|
10756 | var events = ['error', 'close', 'destroy', 'pause', 'resume'];
|
10757 | forEach(events, function(ev) {
|
10758 | stream.on(ev, self.emit.bind(self, ev));
|
10759 | });
|
10760 |
|
10761 |
|
10762 |
|
10763 | self._read = function(n) {
|
10764 | if (paused) {
|
10765 | paused = false;
|
10766 | stream.resume();
|
10767 | }
|
10768 | };
|
10769 |
|
10770 | return self;
|
10771 | };
|
10772 |
|
10773 |
|
10774 |
|
10775 |
|
10776 | Readable._fromList = fromList;
|
10777 |
|
10778 |
|
10779 |
|
10780 | function fromList(n, state) {
|
10781 | var list = state.buffer;
|
10782 | var length = state.length;
|
10783 | var stringMode = !!state.decoder;
|
10784 | var objectMode = !!state.objectMode;
|
10785 | var ret;
|
10786 |
|
10787 |
|
10788 | if (list.length === 0)
|
10789 | return null;
|
10790 |
|
10791 | if (length === 0)
|
10792 | ret = null;
|
10793 | else if (objectMode)
|
10794 | ret = list.shift();
|
10795 | else if (!n || n >= length) {
|
10796 |
|
10797 | if (stringMode)
|
10798 | ret = list.join('');
|
10799 | else
|
10800 | ret = Buffer.concat(list, length);
|
10801 | list.length = 0;
|
10802 | } else {
|
10803 |
|
10804 | if (n < list[0].length) {
|
10805 |
|
10806 |
|
10807 | var buf = list[0];
|
10808 | ret = buf.slice(0, n);
|
10809 | list[0] = buf.slice(n);
|
10810 | } else if (n === list[0].length) {
|
10811 |
|
10812 | ret = list.shift();
|
10813 | } else {
|
10814 |
|
10815 |
|
10816 | if (stringMode)
|
10817 | ret = '';
|
10818 | else
|
10819 | ret = new Buffer(n);
|
10820 |
|
10821 | var c = 0;
|
10822 | for (var i = 0, l = list.length; i < l && c < n; i++) {
|
10823 | var buf = list[0];
|
10824 | var cpy = Math.min(n - c, buf.length);
|
10825 |
|
10826 | if (stringMode)
|
10827 | ret += buf.slice(0, cpy);
|
10828 | else
|
10829 | buf.copy(ret, c, 0, cpy);
|
10830 |
|
10831 | if (cpy < buf.length)
|
10832 | list[0] = buf.slice(cpy);
|
10833 | else
|
10834 | list.shift();
|
10835 |
|
10836 | c += cpy;
|
10837 | }
|
10838 | }
|
10839 | }
|
10840 |
|
10841 | return ret;
|
10842 | }
|
10843 |
|
10844 | function endReadable(stream) {
|
10845 | var state = stream._readableState;
|
10846 |
|
10847 |
|
10848 |
|
10849 | if (state.length > 0)
|
10850 | throw new Error('endReadable called on non-empty stream');
|
10851 |
|
10852 | if (!state.endEmitted && state.calledRead) {
|
10853 | state.ended = true;
|
10854 | process.nextTick(function() {
|
10855 |
|
10856 | if (!state.endEmitted && state.length === 0) {
|
10857 | state.endEmitted = true;
|
10858 | stream.readable = false;
|
10859 | stream.emit('end');
|
10860 | }
|
10861 | });
|
10862 | }
|
10863 | }
|
10864 |
|
10865 | function forEach (xs, f) {
|
10866 | for (var i = 0, l = xs.length; i < l; i++) {
|
10867 | f(xs[i], i);
|
10868 | }
|
10869 | }
|
10870 |
|
10871 | function indexOf (xs, x) {
|
10872 | for (var i = 0, l = xs.length; i < l; i++) {
|
10873 | if (xs[i] === x) return i;
|
10874 | }
|
10875 | return -1;
|
10876 | }
|
10877 |
|
10878 | }).call(this,_dereq_(55))
|
10879 | },{"12":12,"13":13,"18":18,"26":26,"55":55,"62":62,"63":63,"67":67}],60:[function(_dereq_,module,exports){
|
10880 |
|
10881 |
|
10882 |
|
10883 |
|
10884 |
|
10885 |
|
10886 |
|
10887 |
|
10888 |
|
10889 |
|
10890 |
|
10891 |
|
10892 |
|
10893 |
|
10894 |
|
10895 |
|
10896 |
|
10897 |
|
10898 |
|
10899 |
|
10900 |
|
10901 |
|
10902 |
|
10903 |
|
10904 |
|
10905 |
|
10906 |
|
10907 |
|
10908 |
|
10909 |
|
10910 |
|
10911 |
|
10912 |
|
10913 |
|
10914 |
|
10915 |
|
10916 |
|
10917 |
|
10918 |
|
10919 |
|
10920 |
|
10921 |
|
10922 |
|
10923 |
|
10924 |
|
10925 |
|
10926 |
|
10927 |
|
10928 |
|
10929 |
|
10930 |
|
10931 |
|
10932 |
|
10933 |
|
10934 |
|
10935 |
|
10936 |
|
10937 |
|
10938 |
|
10939 |
|
10940 |
|
10941 |
|
10942 |
|
10943 |
|
10944 | module.exports = Transform;
|
10945 |
|
10946 | var Duplex = _dereq_(57);
|
10947 |
|
10948 |
|
10949 | var util = _dereq_(13);
|
10950 | util.inherits = _dereq_(26);
|
10951 |
|
10952 |
|
10953 | util.inherits(Transform, Duplex);
|
10954 |
|
10955 |
|
10956 | function TransformState(options, stream) {
|
10957 | this.afterTransform = function(er, data) {
|
10958 | return afterTransform(stream, er, data);
|
10959 | };
|
10960 |
|
10961 | this.needTransform = false;
|
10962 | this.transforming = false;
|
10963 | this.writecb = null;
|
10964 | this.writechunk = null;
|
10965 | }
|
10966 |
|
10967 | function afterTransform(stream, er, data) {
|
10968 | var ts = stream._transformState;
|
10969 | ts.transforming = false;
|
10970 |
|
10971 | var cb = ts.writecb;
|
10972 |
|
10973 | if (!cb)
|
10974 | return stream.emit('error', new Error('no writecb in Transform class'));
|
10975 |
|
10976 | ts.writechunk = null;
|
10977 | ts.writecb = null;
|
10978 |
|
10979 | if (data !== null && data !== undefined)
|
10980 | stream.push(data);
|
10981 |
|
10982 | if (cb)
|
10983 | cb(er);
|
10984 |
|
10985 | var rs = stream._readableState;
|
10986 | rs.reading = false;
|
10987 | if (rs.needReadable || rs.length < rs.highWaterMark) {
|
10988 | stream._read(rs.highWaterMark);
|
10989 | }
|
10990 | }
|
10991 |
|
10992 |
|
10993 | function Transform(options) {
|
10994 | if (!(this instanceof Transform))
|
10995 | return new Transform(options);
|
10996 |
|
10997 | Duplex.call(this, options);
|
10998 |
|
10999 | var ts = this._transformState = new TransformState(options, this);
|
11000 |
|
11001 |
|
11002 | var stream = this;
|
11003 |
|
11004 |
|
11005 | this._readableState.needReadable = true;
|
11006 |
|
11007 |
|
11008 |
|
11009 |
|
11010 | this._readableState.sync = false;
|
11011 |
|
11012 | this.once('finish', function() {
|
11013 | if ('function' === typeof this._flush)
|
11014 | this._flush(function(er) {
|
11015 | done(stream, er);
|
11016 | });
|
11017 | else
|
11018 | done(stream);
|
11019 | });
|
11020 | }
|
11021 |
|
11022 | Transform.prototype.push = function(chunk, encoding) {
|
11023 | this._transformState.needTransform = false;
|
11024 | return Duplex.prototype.push.call(this, chunk, encoding);
|
11025 | };
|
11026 |
|
11027 |
|
11028 |
|
11029 |
|
11030 |
|
11031 |
|
11032 |
|
11033 |
|
11034 |
|
11035 |
|
11036 |
|
11037 | Transform.prototype._transform = function(chunk, encoding, cb) {
|
11038 | throw new Error('not implemented');
|
11039 | };
|
11040 |
|
11041 | Transform.prototype._write = function(chunk, encoding, cb) {
|
11042 | var ts = this._transformState;
|
11043 | ts.writecb = cb;
|
11044 | ts.writechunk = chunk;
|
11045 | ts.writeencoding = encoding;
|
11046 | if (!ts.transforming) {
|
11047 | var rs = this._readableState;
|
11048 | if (ts.needTransform ||
|
11049 | rs.needReadable ||
|
11050 | rs.length < rs.highWaterMark)
|
11051 | this._read(rs.highWaterMark);
|
11052 | }
|
11053 | };
|
11054 |
|
11055 |
|
11056 |
|
11057 |
|
11058 | Transform.prototype._read = function(n) {
|
11059 | var ts = this._transformState;
|
11060 |
|
11061 | if (ts.writechunk !== null && ts.writecb && !ts.transforming) {
|
11062 | ts.transforming = true;
|
11063 | this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
|
11064 | } else {
|
11065 |
|
11066 |
|
11067 | ts.needTransform = true;
|
11068 | }
|
11069 | };
|
11070 |
|
11071 |
|
11072 | function done(stream, er) {
|
11073 | if (er)
|
11074 | return stream.emit('error', er);
|
11075 |
|
11076 |
|
11077 |
|
11078 | var ws = stream._writableState;
|
11079 | var rs = stream._readableState;
|
11080 | var ts = stream._transformState;
|
11081 |
|
11082 | if (ws.length)
|
11083 | throw new Error('calling transform done when ws.length != 0');
|
11084 |
|
11085 | if (ts.transforming)
|
11086 | throw new Error('calling transform done when still transforming');
|
11087 |
|
11088 | return stream.push(null);
|
11089 | }
|
11090 |
|
11091 | },{"13":13,"26":26,"57":57}],61:[function(_dereq_,module,exports){
|
11092 | (function (process){
|
11093 |
|
11094 |
|
11095 |
|
11096 |
|
11097 |
|
11098 |
|
11099 |
|
11100 |
|
11101 |
|
11102 |
|
11103 |
|
11104 |
|
11105 |
|
11106 |
|
11107 |
|
11108 |
|
11109 |
|
11110 |
|
11111 |
|
11112 |
|
11113 |
|
11114 |
|
11115 |
|
11116 |
|
11117 |
|
11118 | module.exports = Writable;
|
11119 |
|
11120 |
|
11121 | var Buffer = _dereq_(12).Buffer;
|
11122 |
|
11123 |
|
11124 | Writable.WritableState = WritableState;
|
11125 |
|
11126 |
|
11127 |
|
11128 | var util = _dereq_(13);
|
11129 | util.inherits = _dereq_(26);
|
11130 |
|
11131 |
|
11132 | var Stream = _dereq_(67);
|
11133 |
|
11134 | util.inherits(Writable, Stream);
|
11135 |
|
11136 | function WriteReq(chunk, encoding, cb) {
|
11137 | this.chunk = chunk;
|
11138 | this.encoding = encoding;
|
11139 | this.callback = cb;
|
11140 | }
|
11141 |
|
11142 | function WritableState(options, stream) {
|
11143 | options = options || {};
|
11144 |
|
11145 |
|
11146 |
|
11147 |
|
11148 | var hwm = options.highWaterMark;
|
11149 | this.highWaterMark = (hwm || hwm === 0) ? hwm : 16 * 1024;
|
11150 |
|
11151 |
|
11152 |
|
11153 | this.objectMode = !!options.objectMode;
|
11154 |
|
11155 |
|
11156 | this.highWaterMark = ~~this.highWaterMark;
|
11157 |
|
11158 | this.needDrain = false;
|
11159 |
|
11160 | this.ending = false;
|
11161 |
|
11162 | this.ended = false;
|
11163 |
|
11164 | this.finished = false;
|
11165 |
|
11166 |
|
11167 |
|
11168 |
|
11169 | var noDecode = options.decodeStrings === false;
|
11170 | this.decodeStrings = !noDecode;
|
11171 |
|
11172 |
|
11173 |
|
11174 |
|
11175 | this.defaultEncoding = options.defaultEncoding || 'utf8';
|
11176 |
|
11177 |
|
11178 |
|
11179 |
|
11180 | this.length = 0;
|
11181 |
|
11182 |
|
11183 | this.writing = false;
|
11184 |
|
11185 |
|
11186 |
|
11187 |
|
11188 |
|
11189 | this.sync = true;
|
11190 |
|
11191 |
|
11192 |
|
11193 |
|
11194 | this.bufferProcessing = false;
|
11195 |
|
11196 |
|
11197 | this.onwrite = function(er) {
|
11198 | onwrite(stream, er);
|
11199 | };
|
11200 |
|
11201 |
|
11202 | this.writecb = null;
|
11203 |
|
11204 |
|
11205 | this.writelen = 0;
|
11206 |
|
11207 | this.buffer = [];
|
11208 |
|
11209 |
|
11210 | this.errorEmitted = false;
|
11211 | }
|
11212 |
|
11213 | function Writable(options) {
|
11214 | var Duplex = _dereq_(57);
|
11215 |
|
11216 |
|
11217 |
|
11218 | if (!(this instanceof Writable) && !(this instanceof Duplex))
|
11219 | return new Writable(options);
|
11220 |
|
11221 | this._writableState = new WritableState(options, this);
|
11222 |
|
11223 |
|
11224 | this.writable = true;
|
11225 |
|
11226 | Stream.call(this);
|
11227 | }
|
11228 |
|
11229 |
|
11230 | Writable.prototype.pipe = function() {
|
11231 | this.emit('error', new Error('Cannot pipe. Not readable.'));
|
11232 | };
|
11233 |
|
11234 |
|
11235 | function writeAfterEnd(stream, state, cb) {
|
11236 | var er = new Error('write after end');
|
11237 |
|
11238 | stream.emit('error', er);
|
11239 | process.nextTick(function() {
|
11240 | cb(er);
|
11241 | });
|
11242 | }
|
11243 |
|
11244 |
|
11245 |
|
11246 |
|
11247 |
|
11248 |
|
11249 | function validChunk(stream, state, chunk, cb) {
|
11250 | var valid = true;
|
11251 | if (!Buffer.isBuffer(chunk) &&
|
11252 | 'string' !== typeof chunk &&
|
11253 | chunk !== null &&
|
11254 | chunk !== undefined &&
|
11255 | !state.objectMode) {
|
11256 | var er = new TypeError('Invalid non-string/buffer chunk');
|
11257 | stream.emit('error', er);
|
11258 | process.nextTick(function() {
|
11259 | cb(er);
|
11260 | });
|
11261 | valid = false;
|
11262 | }
|
11263 | return valid;
|
11264 | }
|
11265 |
|
11266 | Writable.prototype.write = function(chunk, encoding, cb) {
|
11267 | var state = this._writableState;
|
11268 | var ret = false;
|
11269 |
|
11270 | if (typeof encoding === 'function') {
|
11271 | cb = encoding;
|
11272 | encoding = null;
|
11273 | }
|
11274 |
|
11275 | if (Buffer.isBuffer(chunk))
|
11276 | encoding = 'buffer';
|
11277 | else if (!encoding)
|
11278 | encoding = state.defaultEncoding;
|
11279 |
|
11280 | if (typeof cb !== 'function')
|
11281 | cb = function() {};
|
11282 |
|
11283 | if (state.ended)
|
11284 | writeAfterEnd(this, state, cb);
|
11285 | else if (validChunk(this, state, chunk, cb))
|
11286 | ret = writeOrBuffer(this, state, chunk, encoding, cb);
|
11287 |
|
11288 | return ret;
|
11289 | };
|
11290 |
|
11291 | function decodeChunk(state, chunk, encoding) {
|
11292 | if (!state.objectMode &&
|
11293 | state.decodeStrings !== false &&
|
11294 | typeof chunk === 'string') {
|
11295 | chunk = new Buffer(chunk, encoding);
|
11296 | }
|
11297 | return chunk;
|
11298 | }
|
11299 |
|
11300 |
|
11301 |
|
11302 |
|
11303 | function writeOrBuffer(stream, state, chunk, encoding, cb) {
|
11304 | chunk = decodeChunk(state, chunk, encoding);
|
11305 | if (Buffer.isBuffer(chunk))
|
11306 | encoding = 'buffer';
|
11307 | var len = state.objectMode ? 1 : chunk.length;
|
11308 |
|
11309 | state.length += len;
|
11310 |
|
11311 | var ret = state.length < state.highWaterMark;
|
11312 |
|
11313 | if (!ret)
|
11314 | state.needDrain = true;
|
11315 |
|
11316 | if (state.writing)
|
11317 | state.buffer.push(new WriteReq(chunk, encoding, cb));
|
11318 | else
|
11319 | doWrite(stream, state, len, chunk, encoding, cb);
|
11320 |
|
11321 | return ret;
|
11322 | }
|
11323 |
|
11324 | function doWrite(stream, state, len, chunk, encoding, cb) {
|
11325 | state.writelen = len;
|
11326 | state.writecb = cb;
|
11327 | state.writing = true;
|
11328 | state.sync = true;
|
11329 | stream._write(chunk, encoding, state.onwrite);
|
11330 | state.sync = false;
|
11331 | }
|
11332 |
|
11333 | function onwriteError(stream, state, sync, er, cb) {
|
11334 | if (sync)
|
11335 | process.nextTick(function() {
|
11336 | cb(er);
|
11337 | });
|
11338 | else
|
11339 | cb(er);
|
11340 |
|
11341 | stream._writableState.errorEmitted = true;
|
11342 | stream.emit('error', er);
|
11343 | }
|
11344 |
|
11345 | function onwriteStateUpdate(state) {
|
11346 | state.writing = false;
|
11347 | state.writecb = null;
|
11348 | state.length -= state.writelen;
|
11349 | state.writelen = 0;
|
11350 | }
|
11351 |
|
11352 | function onwrite(stream, er) {
|
11353 | var state = stream._writableState;
|
11354 | var sync = state.sync;
|
11355 | var cb = state.writecb;
|
11356 |
|
11357 | onwriteStateUpdate(state);
|
11358 |
|
11359 | if (er)
|
11360 | onwriteError(stream, state, sync, er, cb);
|
11361 | else {
|
11362 |
|
11363 | var finished = needFinish(stream, state);
|
11364 |
|
11365 | if (!finished && !state.bufferProcessing && state.buffer.length)
|
11366 | clearBuffer(stream, state);
|
11367 |
|
11368 | if (sync) {
|
11369 | process.nextTick(function() {
|
11370 | afterWrite(stream, state, finished, cb);
|
11371 | });
|
11372 | } else {
|
11373 | afterWrite(stream, state, finished, cb);
|
11374 | }
|
11375 | }
|
11376 | }
|
11377 |
|
11378 | function afterWrite(stream, state, finished, cb) {
|
11379 | if (!finished)
|
11380 | onwriteDrain(stream, state);
|
11381 | cb();
|
11382 | if (finished)
|
11383 | finishMaybe(stream, state);
|
11384 | }
|
11385 |
|
11386 |
|
11387 |
|
11388 |
|
11389 | function onwriteDrain(stream, state) {
|
11390 | if (state.length === 0 && state.needDrain) {
|
11391 | state.needDrain = false;
|
11392 | stream.emit('drain');
|
11393 | }
|
11394 | }
|
11395 |
|
11396 |
|
11397 |
|
11398 | function clearBuffer(stream, state) {
|
11399 | state.bufferProcessing = true;
|
11400 |
|
11401 | for (var c = 0; c < state.buffer.length; c++) {
|
11402 | var entry = state.buffer[c];
|
11403 | var chunk = entry.chunk;
|
11404 | var encoding = entry.encoding;
|
11405 | var cb = entry.callback;
|
11406 | var len = state.objectMode ? 1 : chunk.length;
|
11407 |
|
11408 | doWrite(stream, state, len, chunk, encoding, cb);
|
11409 |
|
11410 |
|
11411 |
|
11412 |
|
11413 |
|
11414 | if (state.writing) {
|
11415 | c++;
|
11416 | break;
|
11417 | }
|
11418 | }
|
11419 |
|
11420 | state.bufferProcessing = false;
|
11421 | if (c < state.buffer.length)
|
11422 | state.buffer = state.buffer.slice(c);
|
11423 | else
|
11424 | state.buffer.length = 0;
|
11425 | }
|
11426 |
|
11427 | Writable.prototype._write = function(chunk, encoding, cb) {
|
11428 | cb(new Error('not implemented'));
|
11429 | };
|
11430 |
|
11431 | Writable.prototype.end = function(chunk, encoding, cb) {
|
11432 | var state = this._writableState;
|
11433 |
|
11434 | if (typeof chunk === 'function') {
|
11435 | cb = chunk;
|
11436 | chunk = null;
|
11437 | encoding = null;
|
11438 | } else if (typeof encoding === 'function') {
|
11439 | cb = encoding;
|
11440 | encoding = null;
|
11441 | }
|
11442 |
|
11443 | if (typeof chunk !== 'undefined' && chunk !== null)
|
11444 | this.write(chunk, encoding);
|
11445 |
|
11446 |
|
11447 | if (!state.ending && !state.finished)
|
11448 | endWritable(this, state, cb);
|
11449 | };
|
11450 |
|
11451 |
|
11452 | function needFinish(stream, state) {
|
11453 | return (state.ending &&
|
11454 | state.length === 0 &&
|
11455 | !state.finished &&
|
11456 | !state.writing);
|
11457 | }
|
11458 |
|
11459 | function finishMaybe(stream, state) {
|
11460 | var need = needFinish(stream, state);
|
11461 | if (need) {
|
11462 | state.finished = true;
|
11463 | stream.emit('finish');
|
11464 | }
|
11465 | return need;
|
11466 | }
|
11467 |
|
11468 | function endWritable(stream, state, cb) {
|
11469 | state.ending = true;
|
11470 | finishMaybe(stream, state);
|
11471 | if (cb) {
|
11472 | if (state.finished)
|
11473 | process.nextTick(cb);
|
11474 | else
|
11475 | stream.once('finish', cb);
|
11476 | }
|
11477 | state.ended = true;
|
11478 | }
|
11479 |
|
11480 | }).call(this,_dereq_(55))
|
11481 | },{"12":12,"13":13,"26":26,"55":55,"57":57,"67":67}],62:[function(_dereq_,module,exports){
|
11482 | module.exports = Array.isArray || function (arr) {
|
11483 | return Object.prototype.toString.call(arr) == '[object Array]';
|
11484 | };
|
11485 |
|
11486 | },{}],63:[function(_dereq_,module,exports){
|
11487 |
|
11488 |
|
11489 |
|
11490 |
|
11491 |
|
11492 |
|
11493 |
|
11494 |
|
11495 |
|
11496 |
|
11497 |
|
11498 |
|
11499 |
|
11500 |
|
11501 |
|
11502 |
|
11503 |
|
11504 |
|
11505 |
|
11506 |
|
11507 |
|
11508 | var Buffer = _dereq_(12).Buffer;
|
11509 |
|
11510 | var isBufferEncoding = Buffer.isEncoding
|
11511 | || function(encoding) {
|
11512 | switch (encoding && encoding.toLowerCase()) {
|
11513 | 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;
|
11514 | default: return false;
|
11515 | }
|
11516 | }
|
11517 |
|
11518 |
|
11519 | function assertEncoding(encoding) {
|
11520 | if (encoding && !isBufferEncoding(encoding)) {
|
11521 | throw new Error('Unknown encoding: ' + encoding);
|
11522 | }
|
11523 | }
|
11524 |
|
11525 |
|
11526 |
|
11527 |
|
11528 |
|
11529 |
|
11530 |
|
11531 |
|
11532 |
|
11533 | var StringDecoder = exports.StringDecoder = function(encoding) {
|
11534 | this.encoding = (encoding || 'utf8').toLowerCase().replace(/[-_]/, '');
|
11535 | assertEncoding(encoding);
|
11536 | switch (this.encoding) {
|
11537 | case 'utf8':
|
11538 |
|
11539 | this.surrogateSize = 3;
|
11540 | break;
|
11541 | case 'ucs2':
|
11542 | case 'utf16le':
|
11543 |
|
11544 | this.surrogateSize = 2;
|
11545 | this.detectIncompleteChar = utf16DetectIncompleteChar;
|
11546 | break;
|
11547 | case 'base64':
|
11548 |
|
11549 | this.surrogateSize = 3;
|
11550 | this.detectIncompleteChar = base64DetectIncompleteChar;
|
11551 | break;
|
11552 | default:
|
11553 | this.write = passThroughWrite;
|
11554 | return;
|
11555 | }
|
11556 |
|
11557 |
|
11558 |
|
11559 | this.charBuffer = new Buffer(6);
|
11560 |
|
11561 | this.charReceived = 0;
|
11562 |
|
11563 | this.charLength = 0;
|
11564 | };
|
11565 |
|
11566 |
|
11567 |
|
11568 |
|
11569 |
|
11570 |
|
11571 |
|
11572 |
|
11573 |
|
11574 |
|
11575 |
|
11576 | StringDecoder.prototype.write = function(buffer) {
|
11577 | var charStr = '';
|
11578 |
|
11579 | while (this.charLength) {
|
11580 |
|
11581 | var available = (buffer.length >= this.charLength - this.charReceived) ?
|
11582 | this.charLength - this.charReceived :
|
11583 | buffer.length;
|
11584 |
|
11585 |
|
11586 | buffer.copy(this.charBuffer, this.charReceived, 0, available);
|
11587 | this.charReceived += available;
|
11588 |
|
11589 | if (this.charReceived < this.charLength) {
|
11590 |
|
11591 | return '';
|
11592 | }
|
11593 |
|
11594 |
|
11595 | buffer = buffer.slice(available, buffer.length);
|
11596 |
|
11597 |
|
11598 | charStr = this.charBuffer.slice(0, this.charLength).toString(this.encoding);
|
11599 |
|
11600 |
|
11601 | var charCode = charStr.charCodeAt(charStr.length - 1);
|
11602 | if (charCode >= 0xD800 && charCode <= 0xDBFF) {
|
11603 | this.charLength += this.surrogateSize;
|
11604 | charStr = '';
|
11605 | continue;
|
11606 | }
|
11607 | this.charReceived = this.charLength = 0;
|
11608 |
|
11609 |
|
11610 | if (buffer.length === 0) {
|
11611 | return charStr;
|
11612 | }
|
11613 | break;
|
11614 | }
|
11615 |
|
11616 |
|
11617 | this.detectIncompleteChar(buffer);
|
11618 |
|
11619 | var end = buffer.length;
|
11620 | if (this.charLength) {
|
11621 |
|
11622 | buffer.copy(this.charBuffer, 0, buffer.length - this.charReceived, end);
|
11623 | end -= this.charReceived;
|
11624 | }
|
11625 |
|
11626 | charStr += buffer.toString(this.encoding, 0, end);
|
11627 |
|
11628 | var end = charStr.length - 1;
|
11629 | var charCode = charStr.charCodeAt(end);
|
11630 |
|
11631 | if (charCode >= 0xD800 && charCode <= 0xDBFF) {
|
11632 | var size = this.surrogateSize;
|
11633 | this.charLength += size;
|
11634 | this.charReceived += size;
|
11635 | this.charBuffer.copy(this.charBuffer, size, 0, size);
|
11636 | buffer.copy(this.charBuffer, 0, 0, size);
|
11637 | return charStr.substring(0, end);
|
11638 | }
|
11639 |
|
11640 |
|
11641 | return charStr;
|
11642 | };
|
11643 |
|
11644 |
|
11645 |
|
11646 |
|
11647 |
|
11648 | StringDecoder.prototype.detectIncompleteChar = function(buffer) {
|
11649 |
|
11650 | var i = (buffer.length >= 3) ? 3 : buffer.length;
|
11651 |
|
11652 |
|
11653 |
|
11654 | for (; i > 0; i--) {
|
11655 | var c = buffer[buffer.length - i];
|
11656 |
|
11657 |
|
11658 |
|
11659 |
|
11660 | if (i == 1 && c >> 5 == 0x06) {
|
11661 | this.charLength = 2;
|
11662 | break;
|
11663 | }
|
11664 |
|
11665 |
|
11666 | if (i <= 2 && c >> 4 == 0x0E) {
|
11667 | this.charLength = 3;
|
11668 | break;
|
11669 | }
|
11670 |
|
11671 |
|
11672 | if (i <= 3 && c >> 3 == 0x1E) {
|
11673 | this.charLength = 4;
|
11674 | break;
|
11675 | }
|
11676 | }
|
11677 | this.charReceived = i;
|
11678 | };
|
11679 |
|
11680 | StringDecoder.prototype.end = function(buffer) {
|
11681 | var res = '';
|
11682 | if (buffer && buffer.length)
|
11683 | res = this.write(buffer);
|
11684 |
|
11685 | if (this.charReceived) {
|
11686 | var cr = this.charReceived;
|
11687 | var buf = this.charBuffer;
|
11688 | var enc = this.encoding;
|
11689 | res += buf.slice(0, cr).toString(enc);
|
11690 | }
|
11691 |
|
11692 | return res;
|
11693 | };
|
11694 |
|
11695 | function passThroughWrite(buffer) {
|
11696 | return buffer.toString(this.encoding);
|
11697 | }
|
11698 |
|
11699 | function utf16DetectIncompleteChar(buffer) {
|
11700 | this.charReceived = buffer.length % 2;
|
11701 | this.charLength = this.charReceived ? 2 : 0;
|
11702 | }
|
11703 |
|
11704 | function base64DetectIncompleteChar(buffer) {
|
11705 | this.charReceived = buffer.length % 3;
|
11706 | this.charLength = this.charReceived ? 3 : 0;
|
11707 | }
|
11708 |
|
11709 | },{"12":12}],64:[function(_dereq_,module,exports){
|
11710 | var Stream = _dereq_(67);
|
11711 | exports = module.exports = _dereq_(59);
|
11712 | exports.Stream = Stream;
|
11713 | exports.Readable = exports;
|
11714 | exports.Writable = _dereq_(61);
|
11715 | exports.Duplex = _dereq_(57);
|
11716 | exports.Transform = _dereq_(60);
|
11717 | exports.PassThrough = _dereq_(58);
|
11718 |
|
11719 | },{"57":57,"58":58,"59":59,"60":60,"61":61,"67":67}],65:[function(_dereq_,module,exports){
|
11720 |
|
11721 | var buffer = _dereq_(12)
|
11722 | var Buffer = buffer.Buffer
|
11723 |
|
11724 |
|
11725 | function copyProps (src, dst) {
|
11726 | for (var key in src) {
|
11727 | dst[key] = src[key]
|
11728 | }
|
11729 | }
|
11730 | if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) {
|
11731 | module.exports = buffer
|
11732 | } else {
|
11733 |
|
11734 | copyProps(buffer, exports)
|
11735 | exports.Buffer = SafeBuffer
|
11736 | }
|
11737 |
|
11738 | function SafeBuffer (arg, encodingOrOffset, length) {
|
11739 | return Buffer(arg, encodingOrOffset, length)
|
11740 | }
|
11741 |
|
11742 |
|
11743 | copyProps(Buffer, SafeBuffer)
|
11744 |
|
11745 | SafeBuffer.from = function (arg, encodingOrOffset, length) {
|
11746 | if (typeof arg === 'number') {
|
11747 | throw new TypeError('Argument must not be a number')
|
11748 | }
|
11749 | return Buffer(arg, encodingOrOffset, length)
|
11750 | }
|
11751 |
|
11752 | SafeBuffer.alloc = function (size, fill, encoding) {
|
11753 | if (typeof size !== 'number') {
|
11754 | throw new TypeError('Argument must be a number')
|
11755 | }
|
11756 | var buf = Buffer(size)
|
11757 | if (fill !== undefined) {
|
11758 | if (typeof encoding === 'string') {
|
11759 | buf.fill(fill, encoding)
|
11760 | } else {
|
11761 | buf.fill(fill)
|
11762 | }
|
11763 | } else {
|
11764 | buf.fill(0)
|
11765 | }
|
11766 | return buf
|
11767 | }
|
11768 |
|
11769 | SafeBuffer.allocUnsafe = function (size) {
|
11770 | if (typeof size !== 'number') {
|
11771 | throw new TypeError('Argument must be a number')
|
11772 | }
|
11773 | return Buffer(size)
|
11774 | }
|
11775 |
|
11776 | SafeBuffer.allocUnsafeSlow = function (size) {
|
11777 | if (typeof size !== 'number') {
|
11778 | throw new TypeError('Argument must be a number')
|
11779 | }
|
11780 | return buffer.SlowBuffer(size)
|
11781 | }
|
11782 |
|
11783 | },{"12":12}],66:[function(_dereq_,module,exports){
|
11784 | (function (factory) {
|
11785 | if (typeof exports === 'object') {
|
11786 |
|
11787 | module.exports = factory();
|
11788 | } else if (typeof define === 'function' && define.amd) {
|
11789 |
|
11790 | define(factory);
|
11791 | } else {
|
11792 |
|
11793 | var glob;
|
11794 |
|
11795 | try {
|
11796 | glob = window;
|
11797 | } catch (e) {
|
11798 | glob = self;
|
11799 | }
|
11800 |
|
11801 | glob.SparkMD5 = factory();
|
11802 | }
|
11803 | }(function (undefined) {
|
11804 |
|
11805 | 'use strict';
|
11806 |
|
11807 | |
11808 |
|
11809 |
|
11810 |
|
11811 |
|
11812 |
|
11813 |
|
11814 |
|
11815 | |
11816 |
|
11817 |
|
11818 |
|
11819 |
|
11820 | var add32 = function (a, b) {
|
11821 | return (a + b) & 0xFFFFFFFF;
|
11822 | },
|
11823 | hex_chr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'];
|
11824 |
|
11825 |
|
11826 | function cmn(q, a, b, x, s, t) {
|
11827 | a = add32(add32(a, q), add32(x, t));
|
11828 | return add32((a << s) | (a >>> (32 - s)), b);
|
11829 | }
|
11830 |
|
11831 | function md5cycle(x, k) {
|
11832 | var a = x[0],
|
11833 | b = x[1],
|
11834 | c = x[2],
|
11835 | d = x[3];
|
11836 |
|
11837 | a += (b & c | ~b & d) + k[0] - 680876936 | 0;
|
11838 | a = (a << 7 | a >>> 25) + b | 0;
|
11839 | d += (a & b | ~a & c) + k[1] - 389564586 | 0;
|
11840 | d = (d << 12 | d >>> 20) + a | 0;
|
11841 | c += (d & a | ~d & b) + k[2] + 606105819 | 0;
|
11842 | c = (c << 17 | c >>> 15) + d | 0;
|
11843 | b += (c & d | ~c & a) + k[3] - 1044525330 | 0;
|
11844 | b = (b << 22 | b >>> 10) + c | 0;
|
11845 | a += (b & c | ~b & d) + k[4] - 176418897 | 0;
|
11846 | a = (a << 7 | a >>> 25) + b | 0;
|
11847 | d += (a & b | ~a & c) + k[5] + 1200080426 | 0;
|
11848 | d = (d << 12 | d >>> 20) + a | 0;
|
11849 | c += (d & a | ~d & b) + k[6] - 1473231341 | 0;
|
11850 | c = (c << 17 | c >>> 15) + d | 0;
|
11851 | b += (c & d | ~c & a) + k[7] - 45705983 | 0;
|
11852 | b = (b << 22 | b >>> 10) + c | 0;
|
11853 | a += (b & c | ~b & d) + k[8] + 1770035416 | 0;
|
11854 | a = (a << 7 | a >>> 25) + b | 0;
|
11855 | d += (a & b | ~a & c) + k[9] - 1958414417 | 0;
|
11856 | d = (d << 12 | d >>> 20) + a | 0;
|
11857 | c += (d & a | ~d & b) + k[10] - 42063 | 0;
|
11858 | c = (c << 17 | c >>> 15) + d | 0;
|
11859 | b += (c & d | ~c & a) + k[11] - 1990404162 | 0;
|
11860 | b = (b << 22 | b >>> 10) + c | 0;
|
11861 | a += (b & c | ~b & d) + k[12] + 1804603682 | 0;
|
11862 | a = (a << 7 | a >>> 25) + b | 0;
|
11863 | d += (a & b | ~a & c) + k[13] - 40341101 | 0;
|
11864 | d = (d << 12 | d >>> 20) + a | 0;
|
11865 | c += (d & a | ~d & b) + k[14] - 1502002290 | 0;
|
11866 | c = (c << 17 | c >>> 15) + d | 0;
|
11867 | b += (c & d | ~c & a) + k[15] + 1236535329 | 0;
|
11868 | b = (b << 22 | b >>> 10) + c | 0;
|
11869 |
|
11870 | a += (b & d | c & ~d) + k[1] - 165796510 | 0;
|
11871 | a = (a << 5 | a >>> 27) + b | 0;
|
11872 | d += (a & c | b & ~c) + k[6] - 1069501632 | 0;
|
11873 | d = (d << 9 | d >>> 23) + a | 0;
|
11874 | c += (d & b | a & ~b) + k[11] + 643717713 | 0;
|
11875 | c = (c << 14 | c >>> 18) + d | 0;
|
11876 | b += (c & a | d & ~a) + k[0] - 373897302 | 0;
|
11877 | b = (b << 20 | b >>> 12) + c | 0;
|
11878 | a += (b & d | c & ~d) + k[5] - 701558691 | 0;
|
11879 | a = (a << 5 | a >>> 27) + b | 0;
|
11880 | d += (a & c | b & ~c) + k[10] + 38016083 | 0;
|
11881 | d = (d << 9 | d >>> 23) + a | 0;
|
11882 | c += (d & b | a & ~b) + k[15] - 660478335 | 0;
|
11883 | c = (c << 14 | c >>> 18) + d | 0;
|
11884 | b += (c & a | d & ~a) + k[4] - 405537848 | 0;
|
11885 | b = (b << 20 | b >>> 12) + c | 0;
|
11886 | a += (b & d | c & ~d) + k[9] + 568446438 | 0;
|
11887 | a = (a << 5 | a >>> 27) + b | 0;
|
11888 | d += (a & c | b & ~c) + k[14] - 1019803690 | 0;
|
11889 | d = (d << 9 | d >>> 23) + a | 0;
|
11890 | c += (d & b | a & ~b) + k[3] - 187363961 | 0;
|
11891 | c = (c << 14 | c >>> 18) + d | 0;
|
11892 | b += (c & a | d & ~a) + k[8] + 1163531501 | 0;
|
11893 | b = (b << 20 | b >>> 12) + c | 0;
|
11894 | a += (b & d | c & ~d) + k[13] - 1444681467 | 0;
|
11895 | a = (a << 5 | a >>> 27) + b | 0;
|
11896 | d += (a & c | b & ~c) + k[2] - 51403784 | 0;
|
11897 | d = (d << 9 | d >>> 23) + a | 0;
|
11898 | c += (d & b | a & ~b) + k[7] + 1735328473 | 0;
|
11899 | c = (c << 14 | c >>> 18) + d | 0;
|
11900 | b += (c & a | d & ~a) + k[12] - 1926607734 | 0;
|
11901 | b = (b << 20 | b >>> 12) + c | 0;
|
11902 |
|
11903 | a += (b ^ c ^ d) + k[5] - 378558 | 0;
|
11904 | a = (a << 4 | a >>> 28) + b | 0;
|
11905 | d += (a ^ b ^ c) + k[8] - 2022574463 | 0;
|
11906 | d = (d << 11 | d >>> 21) + a | 0;
|
11907 | c += (d ^ a ^ b) + k[11] + 1839030562 | 0;
|
11908 | c = (c << 16 | c >>> 16) + d | 0;
|
11909 | b += (c ^ d ^ a) + k[14] - 35309556 | 0;
|
11910 | b = (b << 23 | b >>> 9) + c | 0;
|
11911 | a += (b ^ c ^ d) + k[1] - 1530992060 | 0;
|
11912 | a = (a << 4 | a >>> 28) + b | 0;
|
11913 | d += (a ^ b ^ c) + k[4] + 1272893353 | 0;
|
11914 | d = (d << 11 | d >>> 21) + a | 0;
|
11915 | c += (d ^ a ^ b) + k[7] - 155497632 | 0;
|
11916 | c = (c << 16 | c >>> 16) + d | 0;
|
11917 | b += (c ^ d ^ a) + k[10] - 1094730640 | 0;
|
11918 | b = (b << 23 | b >>> 9) + c | 0;
|
11919 | a += (b ^ c ^ d) + k[13] + 681279174 | 0;
|
11920 | a = (a << 4 | a >>> 28) + b | 0;
|
11921 | d += (a ^ b ^ c) + k[0] - 358537222 | 0;
|
11922 | d = (d << 11 | d >>> 21) + a | 0;
|
11923 | c += (d ^ a ^ b) + k[3] - 722521979 | 0;
|
11924 | c = (c << 16 | c >>> 16) + d | 0;
|
11925 | b += (c ^ d ^ a) + k[6] + 76029189 | 0;
|
11926 | b = (b << 23 | b >>> 9) + c | 0;
|
11927 | a += (b ^ c ^ d) + k[9] - 640364487 | 0;
|
11928 | a = (a << 4 | a >>> 28) + b | 0;
|
11929 | d += (a ^ b ^ c) + k[12] - 421815835 | 0;
|
11930 | d = (d << 11 | d >>> 21) + a | 0;
|
11931 | c += (d ^ a ^ b) + k[15] + 530742520 | 0;
|
11932 | c = (c << 16 | c >>> 16) + d | 0;
|
11933 | b += (c ^ d ^ a) + k[2] - 995338651 | 0;
|
11934 | b = (b << 23 | b >>> 9) + c | 0;
|
11935 |
|
11936 | a += (c ^ (b | ~d)) + k[0] - 198630844 | 0;
|
11937 | a = (a << 6 | a >>> 26) + b | 0;
|
11938 | d += (b ^ (a | ~c)) + k[7] + 1126891415 | 0;
|
11939 | d = (d << 10 | d >>> 22) + a | 0;
|
11940 | c += (a ^ (d | ~b)) + k[14] - 1416354905 | 0;
|
11941 | c = (c << 15 | c >>> 17) + d | 0;
|
11942 | b += (d ^ (c | ~a)) + k[5] - 57434055 | 0;
|
11943 | b = (b << 21 |b >>> 11) + c | 0;
|
11944 | a += (c ^ (b | ~d)) + k[12] + 1700485571 | 0;
|
11945 | a = (a << 6 | a >>> 26) + b | 0;
|
11946 | d += (b ^ (a | ~c)) + k[3] - 1894986606 | 0;
|
11947 | d = (d << 10 | d >>> 22) + a | 0;
|
11948 | c += (a ^ (d | ~b)) + k[10] - 1051523 | 0;
|
11949 | c = (c << 15 | c >>> 17) + d | 0;
|
11950 | b += (d ^ (c | ~a)) + k[1] - 2054922799 | 0;
|
11951 | b = (b << 21 |b >>> 11) + c | 0;
|
11952 | a += (c ^ (b | ~d)) + k[8] + 1873313359 | 0;
|
11953 | a = (a << 6 | a >>> 26) + b | 0;
|
11954 | d += (b ^ (a | ~c)) + k[15] - 30611744 | 0;
|
11955 | d = (d << 10 | d >>> 22) + a | 0;
|
11956 | c += (a ^ (d | ~b)) + k[6] - 1560198380 | 0;
|
11957 | c = (c << 15 | c >>> 17) + d | 0;
|
11958 | b += (d ^ (c | ~a)) + k[13] + 1309151649 | 0;
|
11959 | b = (b << 21 |b >>> 11) + c | 0;
|
11960 | a += (c ^ (b | ~d)) + k[4] - 145523070 | 0;
|
11961 | a = (a << 6 | a >>> 26) + b | 0;
|
11962 | d += (b ^ (a | ~c)) + k[11] - 1120210379 | 0;
|
11963 | d = (d << 10 | d >>> 22) + a | 0;
|
11964 | c += (a ^ (d | ~b)) + k[2] + 718787259 | 0;
|
11965 | c = (c << 15 | c >>> 17) + d | 0;
|
11966 | b += (d ^ (c | ~a)) + k[9] - 343485551 | 0;
|
11967 | b = (b << 21 | b >>> 11) + c | 0;
|
11968 |
|
11969 | x[0] = a + x[0] | 0;
|
11970 | x[1] = b + x[1] | 0;
|
11971 | x[2] = c + x[2] | 0;
|
11972 | x[3] = d + x[3] | 0;
|
11973 | }
|
11974 |
|
11975 | function md5blk(s) {
|
11976 | var md5blks = [],
|
11977 | i;
|
11978 |
|
11979 | for (i = 0; i < 64; i += 4) {
|
11980 | md5blks[i >> 2] = s.charCodeAt(i) + (s.charCodeAt(i + 1) << 8) + (s.charCodeAt(i + 2) << 16) + (s.charCodeAt(i + 3) << 24);
|
11981 | }
|
11982 | return md5blks;
|
11983 | }
|
11984 |
|
11985 | function md5blk_array(a) {
|
11986 | var md5blks = [],
|
11987 | i;
|
11988 |
|
11989 | for (i = 0; i < 64; i += 4) {
|
11990 | md5blks[i >> 2] = a[i] + (a[i + 1] << 8) + (a[i + 2] << 16) + (a[i + 3] << 24);
|
11991 | }
|
11992 | return md5blks;
|
11993 | }
|
11994 |
|
11995 | function md51(s) {
|
11996 | var n = s.length,
|
11997 | state = [1732584193, -271733879, -1732584194, 271733878],
|
11998 | i,
|
11999 | length,
|
12000 | tail,
|
12001 | tmp,
|
12002 | lo,
|
12003 | hi;
|
12004 |
|
12005 | for (i = 64; i <= n; i += 64) {
|
12006 | md5cycle(state, md5blk(s.substring(i - 64, i)));
|
12007 | }
|
12008 | s = s.substring(i - 64);
|
12009 | length = s.length;
|
12010 | tail = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
12011 | for (i = 0; i < length; i += 1) {
|
12012 | tail[i >> 2] |= s.charCodeAt(i) << ((i % 4) << 3);
|
12013 | }
|
12014 | tail[i >> 2] |= 0x80 << ((i % 4) << 3);
|
12015 | if (i > 55) {
|
12016 | md5cycle(state, tail);
|
12017 | for (i = 0; i < 16; i += 1) {
|
12018 | tail[i] = 0;
|
12019 | }
|
12020 | }
|
12021 |
|
12022 |
|
12023 | tmp = n * 8;
|
12024 | tmp = tmp.toString(16).match(/(.*?)(.{0,8})$/);
|
12025 | lo = parseInt(tmp[2], 16);
|
12026 | hi = parseInt(tmp[1], 16) || 0;
|
12027 |
|
12028 | tail[14] = lo;
|
12029 | tail[15] = hi;
|
12030 |
|
12031 | md5cycle(state, tail);
|
12032 | return state;
|
12033 | }
|
12034 |
|
12035 | function md51_array(a) {
|
12036 | var n = a.length,
|
12037 | state = [1732584193, -271733879, -1732584194, 271733878],
|
12038 | i,
|
12039 | length,
|
12040 | tail,
|
12041 | tmp,
|
12042 | lo,
|
12043 | hi;
|
12044 |
|
12045 | for (i = 64; i <= n; i += 64) {
|
12046 | md5cycle(state, md5blk_array(a.subarray(i - 64, i)));
|
12047 | }
|
12048 |
|
12049 |
|
12050 |
|
12051 |
|
12052 |
|
12053 | a = (i - 64) < n ? a.subarray(i - 64) : new Uint8Array(0);
|
12054 |
|
12055 | length = a.length;
|
12056 | tail = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
12057 | for (i = 0; i < length; i += 1) {
|
12058 | tail[i >> 2] |= a[i] << ((i % 4) << 3);
|
12059 | }
|
12060 |
|
12061 | tail[i >> 2] |= 0x80 << ((i % 4) << 3);
|
12062 | if (i > 55) {
|
12063 | md5cycle(state, tail);
|
12064 | for (i = 0; i < 16; i += 1) {
|
12065 | tail[i] = 0;
|
12066 | }
|
12067 | }
|
12068 |
|
12069 |
|
12070 | tmp = n * 8;
|
12071 | tmp = tmp.toString(16).match(/(.*?)(.{0,8})$/);
|
12072 | lo = parseInt(tmp[2], 16);
|
12073 | hi = parseInt(tmp[1], 16) || 0;
|
12074 |
|
12075 | tail[14] = lo;
|
12076 | tail[15] = hi;
|
12077 |
|
12078 | md5cycle(state, tail);
|
12079 |
|
12080 | return state;
|
12081 | }
|
12082 |
|
12083 | function rhex(n) {
|
12084 | var s = '',
|
12085 | j;
|
12086 | for (j = 0; j < 4; j += 1) {
|
12087 | s += hex_chr[(n >> (j * 8 + 4)) & 0x0F] + hex_chr[(n >> (j * 8)) & 0x0F];
|
12088 | }
|
12089 | return s;
|
12090 | }
|
12091 |
|
12092 | function hex(x) {
|
12093 | var i;
|
12094 | for (i = 0; i < x.length; i += 1) {
|
12095 | x[i] = rhex(x[i]);
|
12096 | }
|
12097 | return x.join('');
|
12098 | }
|
12099 |
|
12100 |
|
12101 | if (hex(md51('hello')) !== '5d41402abc4b2a76b9719d911017c592') {
|
12102 | add32 = function (x, y) {
|
12103 | var lsw = (x & 0xFFFF) + (y & 0xFFFF),
|
12104 | msw = (x >> 16) + (y >> 16) + (lsw >> 16);
|
12105 | return (msw << 16) | (lsw & 0xFFFF);
|
12106 | };
|
12107 | }
|
12108 |
|
12109 |
|
12110 |
|
12111 | |
12112 |
|
12113 |
|
12114 |
|
12115 |
|
12116 |
|
12117 | if (typeof ArrayBuffer !== 'undefined' && !ArrayBuffer.prototype.slice) {
|
12118 | (function () {
|
12119 | function clamp(val, length) {
|
12120 | val = (val | 0) || 0;
|
12121 |
|
12122 | if (val < 0) {
|
12123 | return Math.max(val + length, 0);
|
12124 | }
|
12125 |
|
12126 | return Math.min(val, length);
|
12127 | }
|
12128 |
|
12129 | ArrayBuffer.prototype.slice = function (from, to) {
|
12130 | var length = this.byteLength,
|
12131 | begin = clamp(from, length),
|
12132 | end = length,
|
12133 | num,
|
12134 | target,
|
12135 | targetArray,
|
12136 | sourceArray;
|
12137 |
|
12138 | if (to !== undefined) {
|
12139 | end = clamp(to, length);
|
12140 | }
|
12141 |
|
12142 | if (begin > end) {
|
12143 | return new ArrayBuffer(0);
|
12144 | }
|
12145 |
|
12146 | num = end - begin;
|
12147 | target = new ArrayBuffer(num);
|
12148 | targetArray = new Uint8Array(target);
|
12149 |
|
12150 | sourceArray = new Uint8Array(this, begin, num);
|
12151 | targetArray.set(sourceArray);
|
12152 |
|
12153 | return target;
|
12154 | };
|
12155 | })();
|
12156 | }
|
12157 |
|
12158 |
|
12159 |
|
12160 | |
12161 |
|
12162 |
|
12163 |
|
12164 | function toUtf8(str) {
|
12165 | if (/[\u0080-\uFFFF]/.test(str)) {
|
12166 | str = unescape(encodeURIComponent(str));
|
12167 | }
|
12168 |
|
12169 | return str;
|
12170 | }
|
12171 |
|
12172 | function utf8Str2ArrayBuffer(str, returnUInt8Array) {
|
12173 | var length = str.length,
|
12174 | buff = new ArrayBuffer(length),
|
12175 | arr = new Uint8Array(buff),
|
12176 | i;
|
12177 |
|
12178 | for (i = 0; i < length; i += 1) {
|
12179 | arr[i] = str.charCodeAt(i);
|
12180 | }
|
12181 |
|
12182 | return returnUInt8Array ? arr : buff;
|
12183 | }
|
12184 |
|
12185 | function arrayBuffer2Utf8Str(buff) {
|
12186 | return String.fromCharCode.apply(null, new Uint8Array(buff));
|
12187 | }
|
12188 |
|
12189 | function concatenateArrayBuffers(first, second, returnUInt8Array) {
|
12190 | var result = new Uint8Array(first.byteLength + second.byteLength);
|
12191 |
|
12192 | result.set(new Uint8Array(first));
|
12193 | result.set(new Uint8Array(second), first.byteLength);
|
12194 |
|
12195 | return returnUInt8Array ? result : result.buffer;
|
12196 | }
|
12197 |
|
12198 | function hexToBinaryString(hex) {
|
12199 | var bytes = [],
|
12200 | length = hex.length,
|
12201 | x;
|
12202 |
|
12203 | for (x = 0; x < length - 1; x += 2) {
|
12204 | bytes.push(parseInt(hex.substr(x, 2), 16));
|
12205 | }
|
12206 |
|
12207 | return String.fromCharCode.apply(String, bytes);
|
12208 | }
|
12209 |
|
12210 |
|
12211 |
|
12212 | |
12213 |
|
12214 |
|
12215 |
|
12216 |
|
12217 |
|
12218 |
|
12219 | function SparkMD5() {
|
12220 |
|
12221 | this.reset();
|
12222 | }
|
12223 |
|
12224 | |
12225 |
|
12226 |
|
12227 |
|
12228 |
|
12229 |
|
12230 |
|
12231 |
|
12232 | SparkMD5.prototype.append = function (str) {
|
12233 |
|
12234 |
|
12235 | this.appendBinary(toUtf8(str));
|
12236 |
|
12237 | return this;
|
12238 | };
|
12239 |
|
12240 | |
12241 |
|
12242 |
|
12243 |
|
12244 |
|
12245 |
|
12246 |
|
12247 | SparkMD5.prototype.appendBinary = function (contents) {
|
12248 | this._buff += contents;
|
12249 | this._length += contents.length;
|
12250 |
|
12251 | var length = this._buff.length,
|
12252 | i;
|
12253 |
|
12254 | for (i = 64; i <= length; i += 64) {
|
12255 | md5cycle(this._hash, md5blk(this._buff.substring(i - 64, i)));
|
12256 | }
|
12257 |
|
12258 | this._buff = this._buff.substring(i - 64);
|
12259 |
|
12260 | return this;
|
12261 | };
|
12262 |
|
12263 | |
12264 |
|
12265 |
|
12266 |
|
12267 |
|
12268 |
|
12269 |
|
12270 |
|
12271 | SparkMD5.prototype.end = function (raw) {
|
12272 | var buff = this._buff,
|
12273 | length = buff.length,
|
12274 | i,
|
12275 | tail = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
12276 | ret;
|
12277 |
|
12278 | for (i = 0; i < length; i += 1) {
|
12279 | tail[i >> 2] |= buff.charCodeAt(i) << ((i % 4) << 3);
|
12280 | }
|
12281 |
|
12282 | this._finish(tail, length);
|
12283 | ret = hex(this._hash);
|
12284 |
|
12285 | if (raw) {
|
12286 | ret = hexToBinaryString(ret);
|
12287 | }
|
12288 |
|
12289 | this.reset();
|
12290 |
|
12291 | return ret;
|
12292 | };
|
12293 |
|
12294 | |
12295 |
|
12296 |
|
12297 |
|
12298 |
|
12299 | SparkMD5.prototype.reset = function () {
|
12300 | this._buff = '';
|
12301 | this._length = 0;
|
12302 | this._hash = [1732584193, -271733879, -1732584194, 271733878];
|
12303 |
|
12304 | return this;
|
12305 | };
|
12306 |
|
12307 | |
12308 |
|
12309 |
|
12310 |
|
12311 |
|
12312 | SparkMD5.prototype.getState = function () {
|
12313 | return {
|
12314 | buff: this._buff,
|
12315 | length: this._length,
|
12316 | hash: this._hash
|
12317 | };
|
12318 | };
|
12319 |
|
12320 | |
12321 |
|
12322 |
|
12323 |
|
12324 |
|
12325 |
|
12326 |
|
12327 | SparkMD5.prototype.setState = function (state) {
|
12328 | this._buff = state.buff;
|
12329 | this._length = state.length;
|
12330 | this._hash = state.hash;
|
12331 |
|
12332 | return this;
|
12333 | };
|
12334 |
|
12335 | |
12336 |
|
12337 |
|
12338 |
|
12339 | SparkMD5.prototype.destroy = function () {
|
12340 | delete this._hash;
|
12341 | delete this._buff;
|
12342 | delete this._length;
|
12343 | };
|
12344 |
|
12345 | |
12346 |
|
12347 |
|
12348 |
|
12349 |
|
12350 |
|
12351 | SparkMD5.prototype._finish = function (tail, length) {
|
12352 | var i = length,
|
12353 | tmp,
|
12354 | lo,
|
12355 | hi;
|
12356 |
|
12357 | tail[i >> 2] |= 0x80 << ((i % 4) << 3);
|
12358 | if (i > 55) {
|
12359 | md5cycle(this._hash, tail);
|
12360 | for (i = 0; i < 16; i += 1) {
|
12361 | tail[i] = 0;
|
12362 | }
|
12363 | }
|
12364 |
|
12365 |
|
12366 |
|
12367 | tmp = this._length * 8;
|
12368 | tmp = tmp.toString(16).match(/(.*?)(.{0,8})$/);
|
12369 | lo = parseInt(tmp[2], 16);
|
12370 | hi = parseInt(tmp[1], 16) || 0;
|
12371 |
|
12372 | tail[14] = lo;
|
12373 | tail[15] = hi;
|
12374 | md5cycle(this._hash, tail);
|
12375 | };
|
12376 |
|
12377 | |
12378 |
|
12379 |
|
12380 |
|
12381 |
|
12382 |
|
12383 |
|
12384 |
|
12385 |
|
12386 | SparkMD5.hash = function (str, raw) {
|
12387 |
|
12388 |
|
12389 | return SparkMD5.hashBinary(toUtf8(str), raw);
|
12390 | };
|
12391 |
|
12392 | |
12393 |
|
12394 |
|
12395 |
|
12396 |
|
12397 |
|
12398 |
|
12399 |
|
12400 | SparkMD5.hashBinary = function (content, raw) {
|
12401 | var hash = md51(content),
|
12402 | ret = hex(hash);
|
12403 |
|
12404 | return raw ? hexToBinaryString(ret) : ret;
|
12405 | };
|
12406 |
|
12407 |
|
12408 |
|
12409 | |
12410 |
|
12411 |
|
12412 |
|
12413 |
|
12414 | SparkMD5.ArrayBuffer = function () {
|
12415 |
|
12416 | this.reset();
|
12417 | };
|
12418 |
|
12419 | |
12420 |
|
12421 |
|
12422 |
|
12423 |
|
12424 |
|
12425 |
|
12426 | SparkMD5.ArrayBuffer.prototype.append = function (arr) {
|
12427 | var buff = concatenateArrayBuffers(this._buff.buffer, arr, true),
|
12428 | length = buff.length,
|
12429 | i;
|
12430 |
|
12431 | this._length += arr.byteLength;
|
12432 |
|
12433 | for (i = 64; i <= length; i += 64) {
|
12434 | md5cycle(this._hash, md5blk_array(buff.subarray(i - 64, i)));
|
12435 | }
|
12436 |
|
12437 | this._buff = (i - 64) < length ? new Uint8Array(buff.buffer.slice(i - 64)) : new Uint8Array(0);
|
12438 |
|
12439 | return this;
|
12440 | };
|
12441 |
|
12442 | |
12443 |
|
12444 |
|
12445 |
|
12446 |
|
12447 |
|
12448 |
|
12449 |
|
12450 | SparkMD5.ArrayBuffer.prototype.end = function (raw) {
|
12451 | var buff = this._buff,
|
12452 | length = buff.length,
|
12453 | tail = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
12454 | i,
|
12455 | ret;
|
12456 |
|
12457 | for (i = 0; i < length; i += 1) {
|
12458 | tail[i >> 2] |= buff[i] << ((i % 4) << 3);
|
12459 | }
|
12460 |
|
12461 | this._finish(tail, length);
|
12462 | ret = hex(this._hash);
|
12463 |
|
12464 | if (raw) {
|
12465 | ret = hexToBinaryString(ret);
|
12466 | }
|
12467 |
|
12468 | this.reset();
|
12469 |
|
12470 | return ret;
|
12471 | };
|
12472 |
|
12473 | |
12474 |
|
12475 |
|
12476 |
|
12477 |
|
12478 | SparkMD5.ArrayBuffer.prototype.reset = function () {
|
12479 | this._buff = new Uint8Array(0);
|
12480 | this._length = 0;
|
12481 | this._hash = [1732584193, -271733879, -1732584194, 271733878];
|
12482 |
|
12483 | return this;
|
12484 | };
|
12485 |
|
12486 | |
12487 |
|
12488 |
|
12489 |
|
12490 |
|
12491 | SparkMD5.ArrayBuffer.prototype.getState = function () {
|
12492 | var state = SparkMD5.prototype.getState.call(this);
|
12493 |
|
12494 |
|
12495 | state.buff = arrayBuffer2Utf8Str(state.buff);
|
12496 |
|
12497 | return state;
|
12498 | };
|
12499 |
|
12500 | |
12501 |
|
12502 |
|
12503 |
|
12504 |
|
12505 |
|
12506 |
|
12507 | SparkMD5.ArrayBuffer.prototype.setState = function (state) {
|
12508 |
|
12509 | state.buff = utf8Str2ArrayBuffer(state.buff, true);
|
12510 |
|
12511 | return SparkMD5.prototype.setState.call(this, state);
|
12512 | };
|
12513 |
|
12514 | SparkMD5.ArrayBuffer.prototype.destroy = SparkMD5.prototype.destroy;
|
12515 |
|
12516 | SparkMD5.ArrayBuffer.prototype._finish = SparkMD5.prototype._finish;
|
12517 |
|
12518 | |
12519 |
|
12520 |
|
12521 |
|
12522 |
|
12523 |
|
12524 |
|
12525 |
|
12526 | SparkMD5.ArrayBuffer.hash = function (arr, raw) {
|
12527 | var hash = md51_array(new Uint8Array(arr)),
|
12528 | ret = hex(hash);
|
12529 |
|
12530 | return raw ? hexToBinaryString(ret) : ret;
|
12531 | };
|
12532 |
|
12533 | return SparkMD5;
|
12534 | }));
|
12535 |
|
12536 | },{}],67:[function(_dereq_,module,exports){
|
12537 |
|
12538 |
|
12539 |
|
12540 |
|
12541 |
|
12542 |
|
12543 |
|
12544 |
|
12545 |
|
12546 |
|
12547 |
|
12548 |
|
12549 |
|
12550 |
|
12551 |
|
12552 |
|
12553 |
|
12554 |
|
12555 |
|
12556 |
|
12557 |
|
12558 | module.exports = Stream;
|
12559 |
|
12560 | var EE = _dereq_(18).EventEmitter;
|
12561 | var inherits = _dereq_(26);
|
12562 |
|
12563 | inherits(Stream, EE);
|
12564 | Stream.Readable = _dereq_(78);
|
12565 | Stream.Writable = _dereq_(80);
|
12566 | Stream.Duplex = _dereq_(68);
|
12567 | Stream.Transform = _dereq_(79);
|
12568 | Stream.PassThrough = _dereq_(77);
|
12569 |
|
12570 |
|
12571 | Stream.Stream = Stream;
|
12572 |
|
12573 |
|
12574 |
|
12575 |
|
12576 |
|
12577 |
|
12578 | function Stream() {
|
12579 | EE.call(this);
|
12580 | }
|
12581 |
|
12582 | Stream.prototype.pipe = function(dest, options) {
|
12583 | var source = this;
|
12584 |
|
12585 | function ondata(chunk) {
|
12586 | if (dest.writable) {
|
12587 | if (false === dest.write(chunk) && source.pause) {
|
12588 | source.pause();
|
12589 | }
|
12590 | }
|
12591 | }
|
12592 |
|
12593 | source.on('data', ondata);
|
12594 |
|
12595 | function ondrain() {
|
12596 | if (source.readable && source.resume) {
|
12597 | source.resume();
|
12598 | }
|
12599 | }
|
12600 |
|
12601 | dest.on('drain', ondrain);
|
12602 |
|
12603 |
|
12604 |
|
12605 | if (!dest._isStdio && (!options || options.end !== false)) {
|
12606 | source.on('end', onend);
|
12607 | source.on('close', onclose);
|
12608 | }
|
12609 |
|
12610 | var didOnEnd = false;
|
12611 | function onend() {
|
12612 | if (didOnEnd) return;
|
12613 | didOnEnd = true;
|
12614 |
|
12615 | dest.end();
|
12616 | }
|
12617 |
|
12618 |
|
12619 | function onclose() {
|
12620 | if (didOnEnd) return;
|
12621 | didOnEnd = true;
|
12622 |
|
12623 | if (typeof dest.destroy === 'function') dest.destroy();
|
12624 | }
|
12625 |
|
12626 |
|
12627 | function onerror(er) {
|
12628 | cleanup();
|
12629 | if (EE.listenerCount(this, 'error') === 0) {
|
12630 | throw er;
|
12631 | }
|
12632 | }
|
12633 |
|
12634 | source.on('error', onerror);
|
12635 | dest.on('error', onerror);
|
12636 |
|
12637 |
|
12638 | function cleanup() {
|
12639 | source.removeListener('data', ondata);
|
12640 | dest.removeListener('drain', ondrain);
|
12641 |
|
12642 | source.removeListener('end', onend);
|
12643 | source.removeListener('close', onclose);
|
12644 |
|
12645 | source.removeListener('error', onerror);
|
12646 | dest.removeListener('error', onerror);
|
12647 |
|
12648 | source.removeListener('end', cleanup);
|
12649 | source.removeListener('close', cleanup);
|
12650 |
|
12651 | dest.removeListener('close', cleanup);
|
12652 | }
|
12653 |
|
12654 | source.on('end', cleanup);
|
12655 | source.on('close', cleanup);
|
12656 |
|
12657 | dest.on('close', cleanup);
|
12658 |
|
12659 | dest.emit('pipe', source);
|
12660 |
|
12661 |
|
12662 | return dest;
|
12663 | };
|
12664 |
|
12665 | },{"18":18,"26":26,"68":68,"77":77,"78":78,"79":79,"80":80}],68:[function(_dereq_,module,exports){
|
12666 | module.exports = _dereq_(69);
|
12667 |
|
12668 | },{"69":69}],69:[function(_dereq_,module,exports){
|
12669 | arguments[4][32][0].apply(exports,arguments)
|
12670 | },{"13":13,"26":26,"32":32,"54":54,"71":71,"73":73}],70:[function(_dereq_,module,exports){
|
12671 | arguments[4][33][0].apply(exports,arguments)
|
12672 | },{"13":13,"26":26,"33":33,"72":72}],71:[function(_dereq_,module,exports){
|
12673 | arguments[4][34][0].apply(exports,arguments)
|
12674 | },{"10":10,"13":13,"18":18,"26":26,"28":28,"34":34,"54":54,"55":55,"65":65,"69":69,"74":74,"75":75,"76":76,"81":81}],72:[function(_dereq_,module,exports){
|
12675 | arguments[4][35][0].apply(exports,arguments)
|
12676 | },{"13":13,"26":26,"35":35,"69":69}],73:[function(_dereq_,module,exports){
|
12677 | arguments[4][36][0].apply(exports,arguments)
|
12678 | },{"13":13,"26":26,"36":36,"54":54,"55":55,"65":65,"69":69,"75":75,"76":76,"94":94,"96":96}],74:[function(_dereq_,module,exports){
|
12679 | arguments[4][37][0].apply(exports,arguments)
|
12680 | },{"10":10,"37":37,"65":65}],75:[function(_dereq_,module,exports){
|
12681 | arguments[4][38][0].apply(exports,arguments)
|
12682 | },{"38":38,"54":54}],76:[function(_dereq_,module,exports){
|
12683 | arguments[4][39][0].apply(exports,arguments)
|
12684 | },{"18":18,"39":39}],77:[function(_dereq_,module,exports){
|
12685 | module.exports = _dereq_(78).PassThrough
|
12686 |
|
12687 | },{"78":78}],78:[function(_dereq_,module,exports){
|
12688 | arguments[4][40][0].apply(exports,arguments)
|
12689 | },{"40":40,"69":69,"70":70,"71":71,"72":72,"73":73}],79:[function(_dereq_,module,exports){
|
12690 | module.exports = _dereq_(78).Transform
|
12691 |
|
12692 | },{"78":78}],80:[function(_dereq_,module,exports){
|
12693 | module.exports = _dereq_(73);
|
12694 |
|
12695 | },{"73":73}],81:[function(_dereq_,module,exports){
|
12696 |
|
12697 |
|
12698 |
|
12699 |
|
12700 |
|
12701 |
|
12702 |
|
12703 |
|
12704 |
|
12705 |
|
12706 |
|
12707 |
|
12708 |
|
12709 |
|
12710 |
|
12711 |
|
12712 |
|
12713 |
|
12714 |
|
12715 |
|
12716 |
|
12717 | 'use strict';
|
12718 |
|
12719 |
|
12720 |
|
12721 | var Buffer = _dereq_(65).Buffer;
|
12722 |
|
12723 |
|
12724 | var isEncoding = Buffer.isEncoding || function (encoding) {
|
12725 | encoding = '' + encoding;
|
12726 | switch (encoding && encoding.toLowerCase()) {
|
12727 | 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':
|
12728 | return true;
|
12729 | default:
|
12730 | return false;
|
12731 | }
|
12732 | };
|
12733 |
|
12734 | function _normalizeEncoding(enc) {
|
12735 | if (!enc) return 'utf8';
|
12736 | var retried;
|
12737 | while (true) {
|
12738 | switch (enc) {
|
12739 | case 'utf8':
|
12740 | case 'utf-8':
|
12741 | return 'utf8';
|
12742 | case 'ucs2':
|
12743 | case 'ucs-2':
|
12744 | case 'utf16le':
|
12745 | case 'utf-16le':
|
12746 | return 'utf16le';
|
12747 | case 'latin1':
|
12748 | case 'binary':
|
12749 | return 'latin1';
|
12750 | case 'base64':
|
12751 | case 'ascii':
|
12752 | case 'hex':
|
12753 | return enc;
|
12754 | default:
|
12755 | if (retried) return;
|
12756 | enc = ('' + enc).toLowerCase();
|
12757 | retried = true;
|
12758 | }
|
12759 | }
|
12760 | };
|
12761 |
|
12762 |
|
12763 |
|
12764 | function normalizeEncoding(enc) {
|
12765 | var nenc = _normalizeEncoding(enc);
|
12766 | if (typeof nenc !== 'string' && (Buffer.isEncoding === isEncoding || !isEncoding(enc))) throw new Error('Unknown encoding: ' + enc);
|
12767 | return nenc || enc;
|
12768 | }
|
12769 |
|
12770 |
|
12771 |
|
12772 |
|
12773 | exports.StringDecoder = StringDecoder;
|
12774 | function StringDecoder(encoding) {
|
12775 | this.encoding = normalizeEncoding(encoding);
|
12776 | var nb;
|
12777 | switch (this.encoding) {
|
12778 | case 'utf16le':
|
12779 | this.text = utf16Text;
|
12780 | this.end = utf16End;
|
12781 | nb = 4;
|
12782 | break;
|
12783 | case 'utf8':
|
12784 | this.fillLast = utf8FillLast;
|
12785 | nb = 4;
|
12786 | break;
|
12787 | case 'base64':
|
12788 | this.text = base64Text;
|
12789 | this.end = base64End;
|
12790 | nb = 3;
|
12791 | break;
|
12792 | default:
|
12793 | this.write = simpleWrite;
|
12794 | this.end = simpleEnd;
|
12795 | return;
|
12796 | }
|
12797 | this.lastNeed = 0;
|
12798 | this.lastTotal = 0;
|
12799 | this.lastChar = Buffer.allocUnsafe(nb);
|
12800 | }
|
12801 |
|
12802 | StringDecoder.prototype.write = function (buf) {
|
12803 | if (buf.length === 0) return '';
|
12804 | var r;
|
12805 | var i;
|
12806 | if (this.lastNeed) {
|
12807 | r = this.fillLast(buf);
|
12808 | if (r === undefined) return '';
|
12809 | i = this.lastNeed;
|
12810 | this.lastNeed = 0;
|
12811 | } else {
|
12812 | i = 0;
|
12813 | }
|
12814 | if (i < buf.length) return r ? r + this.text(buf, i) : this.text(buf, i);
|
12815 | return r || '';
|
12816 | };
|
12817 |
|
12818 | StringDecoder.prototype.end = utf8End;
|
12819 |
|
12820 |
|
12821 | StringDecoder.prototype.text = utf8Text;
|
12822 |
|
12823 |
|
12824 | StringDecoder.prototype.fillLast = function (buf) {
|
12825 | if (this.lastNeed <= buf.length) {
|
12826 | buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, this.lastNeed);
|
12827 | return this.lastChar.toString(this.encoding, 0, this.lastTotal);
|
12828 | }
|
12829 | buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, buf.length);
|
12830 | this.lastNeed -= buf.length;
|
12831 | };
|
12832 |
|
12833 |
|
12834 |
|
12835 | function utf8CheckByte(byte) {
|
12836 | 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;
|
12837 | return byte >> 6 === 0x02 ? -1 : -2;
|
12838 | }
|
12839 |
|
12840 |
|
12841 |
|
12842 |
|
12843 | function utf8CheckIncomplete(self, buf, i) {
|
12844 | var j = buf.length - 1;
|
12845 | if (j < i) return 0;
|
12846 | var nb = utf8CheckByte(buf[j]);
|
12847 | if (nb >= 0) {
|
12848 | if (nb > 0) self.lastNeed = nb - 1;
|
12849 | return nb;
|
12850 | }
|
12851 | if (--j < i || nb === -2) return 0;
|
12852 | nb = utf8CheckByte(buf[j]);
|
12853 | if (nb >= 0) {
|
12854 | if (nb > 0) self.lastNeed = nb - 2;
|
12855 | return nb;
|
12856 | }
|
12857 | if (--j < i || nb === -2) return 0;
|
12858 | nb = utf8CheckByte(buf[j]);
|
12859 | if (nb >= 0) {
|
12860 | if (nb > 0) {
|
12861 | if (nb === 2) nb = 0;else self.lastNeed = nb - 3;
|
12862 | }
|
12863 | return nb;
|
12864 | }
|
12865 | return 0;
|
12866 | }
|
12867 |
|
12868 |
|
12869 |
|
12870 |
|
12871 |
|
12872 |
|
12873 |
|
12874 |
|
12875 |
|
12876 | function utf8CheckExtraBytes(self, buf, p) {
|
12877 | if ((buf[0] & 0xC0) !== 0x80) {
|
12878 | self.lastNeed = 0;
|
12879 | return '\ufffd';
|
12880 | }
|
12881 | if (self.lastNeed > 1 && buf.length > 1) {
|
12882 | if ((buf[1] & 0xC0) !== 0x80) {
|
12883 | self.lastNeed = 1;
|
12884 | return '\ufffd';
|
12885 | }
|
12886 | if (self.lastNeed > 2 && buf.length > 2) {
|
12887 | if ((buf[2] & 0xC0) !== 0x80) {
|
12888 | self.lastNeed = 2;
|
12889 | return '\ufffd';
|
12890 | }
|
12891 | }
|
12892 | }
|
12893 | }
|
12894 |
|
12895 |
|
12896 | function utf8FillLast(buf) {
|
12897 | var p = this.lastTotal - this.lastNeed;
|
12898 | var r = utf8CheckExtraBytes(this, buf, p);
|
12899 | if (r !== undefined) return r;
|
12900 | if (this.lastNeed <= buf.length) {
|
12901 | buf.copy(this.lastChar, p, 0, this.lastNeed);
|
12902 | return this.lastChar.toString(this.encoding, 0, this.lastTotal);
|
12903 | }
|
12904 | buf.copy(this.lastChar, p, 0, buf.length);
|
12905 | this.lastNeed -= buf.length;
|
12906 | }
|
12907 |
|
12908 |
|
12909 |
|
12910 |
|
12911 | function utf8Text(buf, i) {
|
12912 | var total = utf8CheckIncomplete(this, buf, i);
|
12913 | if (!this.lastNeed) return buf.toString('utf8', i);
|
12914 | this.lastTotal = total;
|
12915 | var end = buf.length - (total - this.lastNeed);
|
12916 | buf.copy(this.lastChar, 0, end);
|
12917 | return buf.toString('utf8', i, end);
|
12918 | }
|
12919 |
|
12920 |
|
12921 |
|
12922 | function utf8End(buf) {
|
12923 | var r = buf && buf.length ? this.write(buf) : '';
|
12924 | if (this.lastNeed) return r + '\ufffd';
|
12925 | return r;
|
12926 | }
|
12927 |
|
12928 |
|
12929 |
|
12930 |
|
12931 |
|
12932 | function utf16Text(buf, i) {
|
12933 | if ((buf.length - i) % 2 === 0) {
|
12934 | var r = buf.toString('utf16le', i);
|
12935 | if (r) {
|
12936 | var c = r.charCodeAt(r.length - 1);
|
12937 | if (c >= 0xD800 && c <= 0xDBFF) {
|
12938 | this.lastNeed = 2;
|
12939 | this.lastTotal = 4;
|
12940 | this.lastChar[0] = buf[buf.length - 2];
|
12941 | this.lastChar[1] = buf[buf.length - 1];
|
12942 | return r.slice(0, -1);
|
12943 | }
|
12944 | }
|
12945 | return r;
|
12946 | }
|
12947 | this.lastNeed = 1;
|
12948 | this.lastTotal = 2;
|
12949 | this.lastChar[0] = buf[buf.length - 1];
|
12950 | return buf.toString('utf16le', i, buf.length - 1);
|
12951 | }
|
12952 |
|
12953 |
|
12954 |
|
12955 | function utf16End(buf) {
|
12956 | var r = buf && buf.length ? this.write(buf) : '';
|
12957 | if (this.lastNeed) {
|
12958 | var end = this.lastTotal - this.lastNeed;
|
12959 | return r + this.lastChar.toString('utf16le', 0, end);
|
12960 | }
|
12961 | return r;
|
12962 | }
|
12963 |
|
12964 | function base64Text(buf, i) {
|
12965 | var n = (buf.length - i) % 3;
|
12966 | if (n === 0) return buf.toString('base64', i);
|
12967 | this.lastNeed = 3 - n;
|
12968 | this.lastTotal = 3;
|
12969 | if (n === 1) {
|
12970 | this.lastChar[0] = buf[buf.length - 1];
|
12971 | } else {
|
12972 | this.lastChar[0] = buf[buf.length - 2];
|
12973 | this.lastChar[1] = buf[buf.length - 1];
|
12974 | }
|
12975 | return buf.toString('base64', i, buf.length - n);
|
12976 | }
|
12977 |
|
12978 | function base64End(buf) {
|
12979 | var r = buf && buf.length ? this.write(buf) : '';
|
12980 | if (this.lastNeed) return r + this.lastChar.toString('base64', 0, 3 - this.lastNeed);
|
12981 | return r;
|
12982 | }
|
12983 |
|
12984 |
|
12985 | function simpleWrite(buf) {
|
12986 | return buf.toString(this.encoding);
|
12987 | }
|
12988 |
|
12989 | function simpleEnd(buf) {
|
12990 | return buf && buf.length ? this.write(buf) : '';
|
12991 | }
|
12992 | },{"65":65}],82:[function(_dereq_,module,exports){
|
12993 | arguments[4][32][0].apply(exports,arguments)
|
12994 | },{"13":13,"26":26,"32":32,"54":54,"84":84,"86":86}],83:[function(_dereq_,module,exports){
|
12995 | arguments[4][33][0].apply(exports,arguments)
|
12996 | },{"13":13,"26":26,"33":33,"85":85}],84:[function(_dereq_,module,exports){
|
12997 | arguments[4][34][0].apply(exports,arguments)
|
12998 | },{"10":10,"13":13,"18":18,"26":26,"28":28,"34":34,"54":54,"55":55,"65":65,"81":81,"82":82,"87":87,"88":88,"89":89}],85:[function(_dereq_,module,exports){
|
12999 | arguments[4][35][0].apply(exports,arguments)
|
13000 | },{"13":13,"26":26,"35":35,"82":82}],86:[function(_dereq_,module,exports){
|
13001 | arguments[4][36][0].apply(exports,arguments)
|
13002 | },{"13":13,"26":26,"36":36,"54":54,"55":55,"65":65,"82":82,"88":88,"89":89,"94":94,"96":96}],87:[function(_dereq_,module,exports){
|
13003 | arguments[4][37][0].apply(exports,arguments)
|
13004 | },{"10":10,"37":37,"65":65}],88:[function(_dereq_,module,exports){
|
13005 | arguments[4][38][0].apply(exports,arguments)
|
13006 | },{"38":38,"54":54}],89:[function(_dereq_,module,exports){
|
13007 | arguments[4][39][0].apply(exports,arguments)
|
13008 | },{"18":18,"39":39}],90:[function(_dereq_,module,exports){
|
13009 | arguments[4][40][0].apply(exports,arguments)
|
13010 | },{"40":40,"82":82,"83":83,"84":84,"85":85,"86":86}],91:[function(_dereq_,module,exports){
|
13011 | arguments[4][79][0].apply(exports,arguments)
|
13012 | },{"79":79,"90":90}],92:[function(_dereq_,module,exports){
|
13013 | arguments[4][41][0].apply(exports,arguments)
|
13014 | },{"41":41}],93:[function(_dereq_,module,exports){
|
13015 | (function (process){
|
13016 | var Transform = _dereq_(91)
|
13017 | , inherits = _dereq_(98).inherits
|
13018 | , xtend = _dereq_(92)
|
13019 |
|
13020 | function DestroyableTransform(opts) {
|
13021 | Transform.call(this, opts)
|
13022 | this._destroyed = false
|
13023 | }
|
13024 |
|
13025 | inherits(DestroyableTransform, Transform)
|
13026 |
|
13027 | DestroyableTransform.prototype.destroy = function(err) {
|
13028 | if (this._destroyed) return
|
13029 | this._destroyed = true
|
13030 |
|
13031 | var self = this
|
13032 | process.nextTick(function() {
|
13033 | if (err)
|
13034 | self.emit('error', err)
|
13035 | self.emit('close')
|
13036 | })
|
13037 | }
|
13038 |
|
13039 |
|
13040 | function noop (chunk, enc, callback) {
|
13041 | callback(null, chunk)
|
13042 | }
|
13043 |
|
13044 |
|
13045 |
|
13046 |
|
13047 | function through2 (construct) {
|
13048 | return function (options, transform, flush) {
|
13049 | if (typeof options == 'function') {
|
13050 | flush = transform
|
13051 | transform = options
|
13052 | options = {}
|
13053 | }
|
13054 |
|
13055 | if (typeof transform != 'function')
|
13056 | transform = noop
|
13057 |
|
13058 | if (typeof flush != 'function')
|
13059 | flush = null
|
13060 |
|
13061 | return construct(options, transform, flush)
|
13062 | }
|
13063 | }
|
13064 |
|
13065 |
|
13066 |
|
13067 | module.exports = through2(function (options, transform, flush) {
|
13068 | var t2 = new DestroyableTransform(options)
|
13069 |
|
13070 | t2._transform = transform
|
13071 |
|
13072 | if (flush)
|
13073 | t2._flush = flush
|
13074 |
|
13075 | return t2
|
13076 | })
|
13077 |
|
13078 |
|
13079 |
|
13080 |
|
13081 | module.exports.ctor = through2(function (options, transform, flush) {
|
13082 | function Through2 (override) {
|
13083 | if (!(this instanceof Through2))
|
13084 | return new Through2(override)
|
13085 |
|
13086 | this.options = xtend(options, override)
|
13087 |
|
13088 | DestroyableTransform.call(this, this.options)
|
13089 | }
|
13090 |
|
13091 | inherits(Through2, DestroyableTransform)
|
13092 |
|
13093 | Through2.prototype._transform = transform
|
13094 |
|
13095 | if (flush)
|
13096 | Through2.prototype._flush = flush
|
13097 |
|
13098 | return Through2
|
13099 | })
|
13100 |
|
13101 |
|
13102 | module.exports.obj = through2(function (options, transform, flush) {
|
13103 | var t2 = new DestroyableTransform(xtend({ objectMode: true, highWaterMark: 16 }, options))
|
13104 |
|
13105 | t2._transform = transform
|
13106 |
|
13107 | if (flush)
|
13108 | t2._flush = flush
|
13109 |
|
13110 | return t2
|
13111 | })
|
13112 |
|
13113 | }).call(this,_dereq_(55))
|
13114 | },{"55":55,"91":91,"92":92,"98":98}],94:[function(_dereq_,module,exports){
|
13115 | (function (setImmediate,clearImmediate){
|
13116 | var nextTick = _dereq_(55).nextTick;
|
13117 | var apply = Function.prototype.apply;
|
13118 | var slice = Array.prototype.slice;
|
13119 | var immediateIds = {};
|
13120 | var nextImmediateId = 0;
|
13121 |
|
13122 |
|
13123 |
|
13124 | exports.setTimeout = function() {
|
13125 | return new Timeout(apply.call(setTimeout, window, arguments), clearTimeout);
|
13126 | };
|
13127 | exports.setInterval = function() {
|
13128 | return new Timeout(apply.call(setInterval, window, arguments), clearInterval);
|
13129 | };
|
13130 | exports.clearTimeout =
|
13131 | exports.clearInterval = function(timeout) { timeout.close(); };
|
13132 |
|
13133 | function Timeout(id, clearFn) {
|
13134 | this._id = id;
|
13135 | this._clearFn = clearFn;
|
13136 | }
|
13137 | Timeout.prototype.unref = Timeout.prototype.ref = function() {};
|
13138 | Timeout.prototype.close = function() {
|
13139 | this._clearFn.call(window, this._id);
|
13140 | };
|
13141 |
|
13142 |
|
13143 | exports.enroll = function(item, msecs) {
|
13144 | clearTimeout(item._idleTimeoutId);
|
13145 | item._idleTimeout = msecs;
|
13146 | };
|
13147 |
|
13148 | exports.unenroll = function(item) {
|
13149 | clearTimeout(item._idleTimeoutId);
|
13150 | item._idleTimeout = -1;
|
13151 | };
|
13152 |
|
13153 | exports._unrefActive = exports.active = function(item) {
|
13154 | clearTimeout(item._idleTimeoutId);
|
13155 |
|
13156 | var msecs = item._idleTimeout;
|
13157 | if (msecs >= 0) {
|
13158 | item._idleTimeoutId = setTimeout(function onTimeout() {
|
13159 | if (item._onTimeout)
|
13160 | item._onTimeout();
|
13161 | }, msecs);
|
13162 | }
|
13163 | };
|
13164 |
|
13165 |
|
13166 | exports.setImmediate = typeof setImmediate === "function" ? setImmediate : function(fn) {
|
13167 | var id = nextImmediateId++;
|
13168 | var args = arguments.length < 2 ? false : slice.call(arguments, 1);
|
13169 |
|
13170 | immediateIds[id] = true;
|
13171 |
|
13172 | nextTick(function onNextTick() {
|
13173 | if (immediateIds[id]) {
|
13174 |
|
13175 |
|
13176 | if (args) {
|
13177 | fn.apply(null, args);
|
13178 | } else {
|
13179 | fn.call(null);
|
13180 | }
|
13181 |
|
13182 | exports.clearImmediate(id);
|
13183 | }
|
13184 | });
|
13185 |
|
13186 | return id;
|
13187 | };
|
13188 |
|
13189 | exports.clearImmediate = typeof clearImmediate === "function" ? clearImmediate : function(id) {
|
13190 | delete immediateIds[id];
|
13191 | };
|
13192 | }).call(this,_dereq_(94).setImmediate,_dereq_(94).clearImmediate)
|
13193 | },{"55":55,"94":94}],95:[function(_dereq_,module,exports){
|
13194 | 'use strict';
|
13195 |
|
13196 |
|
13197 |
|
13198 |
|
13199 | function Queue() {
|
13200 | this.length = 0;
|
13201 | }
|
13202 |
|
13203 | Queue.prototype.push = function (item) {
|
13204 | var node = {item: item};
|
13205 | if (this.last) {
|
13206 | this.last = this.last.next = node;
|
13207 | } else {
|
13208 | this.last = this.first = node;
|
13209 | }
|
13210 | this.length++;
|
13211 | };
|
13212 |
|
13213 | Queue.prototype.shift = function () {
|
13214 | var node = this.first;
|
13215 | if (node) {
|
13216 | this.first = node.next;
|
13217 | if (!(--this.length)) {
|
13218 | this.last = undefined;
|
13219 | }
|
13220 | return node.item;
|
13221 | }
|
13222 | };
|
13223 |
|
13224 | Queue.prototype.slice = function (start, end) {
|
13225 | start = typeof start === 'undefined' ? 0 : start;
|
13226 | end = typeof end === 'undefined' ? Infinity : end;
|
13227 |
|
13228 | var output = [];
|
13229 |
|
13230 | var i = 0;
|
13231 | for (var node = this.first; node; node = node.next) {
|
13232 | if (--end < 0) {
|
13233 | break;
|
13234 | } else if (++i > start) {
|
13235 | output.push(node.item);
|
13236 | }
|
13237 | }
|
13238 | return output;
|
13239 | }
|
13240 |
|
13241 | module.exports = Queue;
|
13242 |
|
13243 | },{}],96:[function(_dereq_,module,exports){
|
13244 | (function (global){
|
13245 |
|
13246 |
|
13247 |
|
13248 |
|
13249 |
|
13250 | module.exports = deprecate;
|
13251 |
|
13252 |
|
13253 |
|
13254 |
|
13255 |
|
13256 |
|
13257 |
|
13258 |
|
13259 |
|
13260 |
|
13261 |
|
13262 |
|
13263 |
|
13264 |
|
13265 |
|
13266 |
|
13267 |
|
13268 |
|
13269 |
|
13270 | function deprecate (fn, msg) {
|
13271 | if (config('noDeprecation')) {
|
13272 | return fn;
|
13273 | }
|
13274 |
|
13275 | var warned = false;
|
13276 | function deprecated() {
|
13277 | if (!warned) {
|
13278 | if (config('throwDeprecation')) {
|
13279 | throw new Error(msg);
|
13280 | } else if (config('traceDeprecation')) {
|
13281 | console.trace(msg);
|
13282 | } else {
|
13283 | console.warn(msg);
|
13284 | }
|
13285 | warned = true;
|
13286 | }
|
13287 | return fn.apply(this, arguments);
|
13288 | }
|
13289 |
|
13290 | return deprecated;
|
13291 | }
|
13292 |
|
13293 |
|
13294 |
|
13295 |
|
13296 |
|
13297 |
|
13298 |
|
13299 |
|
13300 |
|
13301 | function config (name) {
|
13302 |
|
13303 | try {
|
13304 | if (!global.localStorage) return false;
|
13305 | } catch (_) {
|
13306 | return false;
|
13307 | }
|
13308 | var val = global.localStorage[name];
|
13309 | if (null == val) return false;
|
13310 | return String(val).toLowerCase() === 'true';
|
13311 | }
|
13312 |
|
13313 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
13314 | },{}],97:[function(_dereq_,module,exports){
|
13315 | arguments[4][7][0].apply(exports,arguments)
|
13316 | },{"7":7}],98:[function(_dereq_,module,exports){
|
13317 | arguments[4][8][0].apply(exports,arguments)
|
13318 | },{"26":26,"55":55,"8":8,"97":97}],99:[function(_dereq_,module,exports){
|
13319 | var v1 = _dereq_(102);
|
13320 | var v4 = _dereq_(103);
|
13321 |
|
13322 | var uuid = v4;
|
13323 | uuid.v1 = v1;
|
13324 | uuid.v4 = v4;
|
13325 |
|
13326 | module.exports = uuid;
|
13327 |
|
13328 | },{"102":102,"103":103}],100:[function(_dereq_,module,exports){
|
13329 |
|
13330 |
|
13331 |
|
13332 |
|
13333 | var byteToHex = [];
|
13334 | for (var i = 0; i < 256; ++i) {
|
13335 | byteToHex[i] = (i + 0x100).toString(16).substr(1);
|
13336 | }
|
13337 |
|
13338 | function bytesToUuid(buf, offset) {
|
13339 | var i = offset || 0;
|
13340 | var bth = byteToHex;
|
13341 | return bth[buf[i++]] + bth[buf[i++]] +
|
13342 | bth[buf[i++]] + bth[buf[i++]] + '-' +
|
13343 | bth[buf[i++]] + bth[buf[i++]] + '-' +
|
13344 | bth[buf[i++]] + bth[buf[i++]] + '-' +
|
13345 | bth[buf[i++]] + bth[buf[i++]] + '-' +
|
13346 | bth[buf[i++]] + bth[buf[i++]] +
|
13347 | bth[buf[i++]] + bth[buf[i++]] +
|
13348 | bth[buf[i++]] + bth[buf[i++]];
|
13349 | }
|
13350 |
|
13351 | module.exports = bytesToUuid;
|
13352 |
|
13353 | },{}],101:[function(_dereq_,module,exports){
|
13354 |
|
13355 |
|
13356 |
|
13357 |
|
13358 |
|
13359 |
|
13360 | var getRandomValues = (typeof(crypto) != 'undefined' && crypto.getRandomValues.bind(crypto)) ||
|
13361 | (typeof(msCrypto) != 'undefined' && msCrypto.getRandomValues.bind(msCrypto));
|
13362 | if (getRandomValues) {
|
13363 |
|
13364 | var rnds8 = new Uint8Array(16);
|
13365 |
|
13366 | module.exports = function whatwgRNG() {
|
13367 | getRandomValues(rnds8);
|
13368 | return rnds8;
|
13369 | };
|
13370 | } else {
|
13371 |
|
13372 |
|
13373 |
|
13374 |
|
13375 | var rnds = new Array(16);
|
13376 |
|
13377 | module.exports = function mathRNG() {
|
13378 | for (var i = 0, r; i < 16; i++) {
|
13379 | if ((i & 0x03) === 0) r = Math.random() * 0x100000000;
|
13380 | rnds[i] = r >>> ((i & 0x03) << 3) & 0xff;
|
13381 | }
|
13382 |
|
13383 | return rnds;
|
13384 | };
|
13385 | }
|
13386 |
|
13387 | },{}],102:[function(_dereq_,module,exports){
|
13388 | var rng = _dereq_(101);
|
13389 | var bytesToUuid = _dereq_(100);
|
13390 |
|
13391 |
|
13392 |
|
13393 |
|
13394 |
|
13395 |
|
13396 | var _nodeId;
|
13397 | var _clockseq;
|
13398 |
|
13399 |
|
13400 | var _lastMSecs = 0;
|
13401 | var _lastNSecs = 0;
|
13402 |
|
13403 |
|
13404 | function v1(options, buf, offset) {
|
13405 | var i = buf && offset || 0;
|
13406 | var b = buf || [];
|
13407 |
|
13408 | options = options || {};
|
13409 | var node = options.node || _nodeId;
|
13410 | var clockseq = options.clockseq !== undefined ? options.clockseq : _clockseq;
|
13411 |
|
13412 |
|
13413 |
|
13414 |
|
13415 | if (node == null || clockseq == null) {
|
13416 | var seedBytes = rng();
|
13417 | if (node == null) {
|
13418 |
|
13419 | node = _nodeId = [
|
13420 | seedBytes[0] | 0x01,
|
13421 | seedBytes[1], seedBytes[2], seedBytes[3], seedBytes[4], seedBytes[5]
|
13422 | ];
|
13423 | }
|
13424 | if (clockseq == null) {
|
13425 |
|
13426 | clockseq = _clockseq = (seedBytes[6] << 8 | seedBytes[7]) & 0x3fff;
|
13427 | }
|
13428 | }
|
13429 |
|
13430 |
|
13431 |
|
13432 |
|
13433 |
|
13434 | var msecs = options.msecs !== undefined ? options.msecs : new Date().getTime();
|
13435 |
|
13436 |
|
13437 |
|
13438 | var nsecs = options.nsecs !== undefined ? options.nsecs : _lastNSecs + 1;
|
13439 |
|
13440 |
|
13441 | var dt = (msecs - _lastMSecs) + (nsecs - _lastNSecs)/10000;
|
13442 |
|
13443 |
|
13444 | if (dt < 0 && options.clockseq === undefined) {
|
13445 | clockseq = clockseq + 1 & 0x3fff;
|
13446 | }
|
13447 |
|
13448 |
|
13449 |
|
13450 | if ((dt < 0 || msecs > _lastMSecs) && options.nsecs === undefined) {
|
13451 | nsecs = 0;
|
13452 | }
|
13453 |
|
13454 |
|
13455 | if (nsecs >= 10000) {
|
13456 | throw new Error('uuid.v1(): Can\'t create more than 10M uuids/sec');
|
13457 | }
|
13458 |
|
13459 | _lastMSecs = msecs;
|
13460 | _lastNSecs = nsecs;
|
13461 | _clockseq = clockseq;
|
13462 |
|
13463 |
|
13464 | msecs += 12219292800000;
|
13465 |
|
13466 |
|
13467 | var tl = ((msecs & 0xfffffff) * 10000 + nsecs) % 0x100000000;
|
13468 | b[i++] = tl >>> 24 & 0xff;
|
13469 | b[i++] = tl >>> 16 & 0xff;
|
13470 | b[i++] = tl >>> 8 & 0xff;
|
13471 | b[i++] = tl & 0xff;
|
13472 |
|
13473 |
|
13474 | var tmh = (msecs / 0x100000000 * 10000) & 0xfffffff;
|
13475 | b[i++] = tmh >>> 8 & 0xff;
|
13476 | b[i++] = tmh & 0xff;
|
13477 |
|
13478 |
|
13479 | b[i++] = tmh >>> 24 & 0xf | 0x10;
|
13480 | b[i++] = tmh >>> 16 & 0xff;
|
13481 |
|
13482 |
|
13483 | b[i++] = clockseq >>> 8 | 0x80;
|
13484 |
|
13485 |
|
13486 | b[i++] = clockseq & 0xff;
|
13487 |
|
13488 |
|
13489 | for (var n = 0; n < 6; ++n) {
|
13490 | b[i + n] = node[n];
|
13491 | }
|
13492 |
|
13493 | return buf ? buf : bytesToUuid(b);
|
13494 | }
|
13495 |
|
13496 | module.exports = v1;
|
13497 |
|
13498 | },{"100":100,"101":101}],103:[function(_dereq_,module,exports){
|
13499 | var rng = _dereq_(101);
|
13500 | var bytesToUuid = _dereq_(100);
|
13501 |
|
13502 | function v4(options, buf, offset) {
|
13503 | var i = buf && offset || 0;
|
13504 |
|
13505 | if (typeof(options) == 'string') {
|
13506 | buf = options === 'binary' ? new Array(16) : null;
|
13507 | options = null;
|
13508 | }
|
13509 | options = options || {};
|
13510 |
|
13511 | var rnds = options.random || (options.rng || rng)();
|
13512 |
|
13513 |
|
13514 | rnds[6] = (rnds[6] & 0x0f) | 0x40;
|
13515 | rnds[8] = (rnds[8] & 0x3f) | 0x80;
|
13516 |
|
13517 |
|
13518 | if (buf) {
|
13519 | for (var ii = 0; ii < 16; ++ii) {
|
13520 | buf[i + ii] = rnds[ii];
|
13521 | }
|
13522 | }
|
13523 |
|
13524 | return buf || bytesToUuid(rnds);
|
13525 | }
|
13526 |
|
13527 | module.exports = v4;
|
13528 |
|
13529 | },{"100":100,"101":101}],104:[function(_dereq_,module,exports){
|
13530 | 'use strict';
|
13531 |
|
13532 |
|
13533 |
|
13534 |
|
13535 |
|
13536 |
|
13537 | exports.stringify = function stringify(input) {
|
13538 | var queue = [];
|
13539 | queue.push({obj: input});
|
13540 |
|
13541 | var res = '';
|
13542 | var next, obj, prefix, val, i, arrayPrefix, keys, k, key, value, objPrefix;
|
13543 | while ((next = queue.pop())) {
|
13544 | obj = next.obj;
|
13545 | prefix = next.prefix || '';
|
13546 | val = next.val || '';
|
13547 | res += prefix;
|
13548 | if (val) {
|
13549 | res += val;
|
13550 | } else if (typeof obj !== 'object') {
|
13551 | res += typeof obj === 'undefined' ? null : JSON.stringify(obj);
|
13552 | } else if (obj === null) {
|
13553 | res += 'null';
|
13554 | } else if (Array.isArray(obj)) {
|
13555 | queue.push({val: ']'});
|
13556 | for (i = obj.length - 1; i >= 0; i--) {
|
13557 | arrayPrefix = i === 0 ? '' : ',';
|
13558 | queue.push({obj: obj[i], prefix: arrayPrefix});
|
13559 | }
|
13560 | queue.push({val: '['});
|
13561 | } else {
|
13562 | keys = [];
|
13563 | for (k in obj) {
|
13564 | if (obj.hasOwnProperty(k)) {
|
13565 | keys.push(k);
|
13566 | }
|
13567 | }
|
13568 | queue.push({val: '}'});
|
13569 | for (i = keys.length - 1; i >= 0; i--) {
|
13570 | key = keys[i];
|
13571 | value = obj[key];
|
13572 | objPrefix = (i > 0 ? ',' : '');
|
13573 | objPrefix += JSON.stringify(key) + ':';
|
13574 | queue.push({obj: value, prefix: objPrefix});
|
13575 | }
|
13576 | queue.push({val: '{'});
|
13577 | }
|
13578 | }
|
13579 | return res;
|
13580 | };
|
13581 |
|
13582 |
|
13583 |
|
13584 |
|
13585 | function pop(obj, stack, metaStack) {
|
13586 | var lastMetaElement = metaStack[metaStack.length - 1];
|
13587 | if (obj === lastMetaElement.element) {
|
13588 |
|
13589 | metaStack.pop();
|
13590 | lastMetaElement = metaStack[metaStack.length - 1];
|
13591 | }
|
13592 | var element = lastMetaElement.element;
|
13593 | var lastElementIndex = lastMetaElement.index;
|
13594 | if (Array.isArray(element)) {
|
13595 | element.push(obj);
|
13596 | } else if (lastElementIndex === stack.length - 2) {
|
13597 | var key = stack.pop();
|
13598 | element[key] = obj;
|
13599 | } else {
|
13600 | stack.push(obj);
|
13601 | }
|
13602 | }
|
13603 |
|
13604 | exports.parse = function (str) {
|
13605 | var stack = [];
|
13606 | var metaStack = [];
|
13607 | var i = 0;
|
13608 | var collationIndex,parsedNum,numChar;
|
13609 | var parsedString,lastCh,numConsecutiveSlashes,ch;
|
13610 | var arrayElement, objElement;
|
13611 | while (true) {
|
13612 | collationIndex = str[i++];
|
13613 | if (collationIndex === '}' ||
|
13614 | collationIndex === ']' ||
|
13615 | typeof collationIndex === 'undefined') {
|
13616 | if (stack.length === 1) {
|
13617 | return stack.pop();
|
13618 | } else {
|
13619 | pop(stack.pop(), stack, metaStack);
|
13620 | continue;
|
13621 | }
|
13622 | }
|
13623 | switch (collationIndex) {
|
13624 | case ' ':
|
13625 | case '\t':
|
13626 | case '\n':
|
13627 | case ':':
|
13628 | case ',':
|
13629 | break;
|
13630 | case 'n':
|
13631 | i += 3;
|
13632 | pop(null, stack, metaStack);
|
13633 | break;
|
13634 | case 't':
|
13635 | i += 3;
|
13636 | pop(true, stack, metaStack);
|
13637 | break;
|
13638 | case 'f':
|
13639 | i += 4;
|
13640 | pop(false, stack, metaStack);
|
13641 | break;
|
13642 | case '0':
|
13643 | case '1':
|
13644 | case '2':
|
13645 | case '3':
|
13646 | case '4':
|
13647 | case '5':
|
13648 | case '6':
|
13649 | case '7':
|
13650 | case '8':
|
13651 | case '9':
|
13652 | case '-':
|
13653 | parsedNum = '';
|
13654 | i--;
|
13655 | while (true) {
|
13656 | numChar = str[i++];
|
13657 | if (/[\d\.\-e\+]/.test(numChar)) {
|
13658 | parsedNum += numChar;
|
13659 | } else {
|
13660 | i--;
|
13661 | break;
|
13662 | }
|
13663 | }
|
13664 | pop(parseFloat(parsedNum), stack, metaStack);
|
13665 | break;
|
13666 | case '"':
|
13667 | parsedString = '';
|
13668 | lastCh = void 0;
|
13669 | numConsecutiveSlashes = 0;
|
13670 | while (true) {
|
13671 | ch = str[i++];
|
13672 | if (ch !== '"' || (lastCh === '\\' &&
|
13673 | numConsecutiveSlashes % 2 === 1)) {
|
13674 | parsedString += ch;
|
13675 | lastCh = ch;
|
13676 | if (lastCh === '\\') {
|
13677 | numConsecutiveSlashes++;
|
13678 | } else {
|
13679 | numConsecutiveSlashes = 0;
|
13680 | }
|
13681 | } else {
|
13682 | break;
|
13683 | }
|
13684 | }
|
13685 | pop(JSON.parse('"' + parsedString + '"'), stack, metaStack);
|
13686 | break;
|
13687 | case '[':
|
13688 | arrayElement = { element: [], index: stack.length };
|
13689 | stack.push(arrayElement.element);
|
13690 | metaStack.push(arrayElement);
|
13691 | break;
|
13692 | case '{':
|
13693 | objElement = { element: {}, index: stack.length };
|
13694 | stack.push(objElement.element);
|
13695 | metaStack.push(objElement);
|
13696 | break;
|
13697 | default:
|
13698 | throw new Error(
|
13699 | 'unexpectedly reached end of input: ' + collationIndex);
|
13700 | }
|
13701 | }
|
13702 | };
|
13703 |
|
13704 | },{}],105:[function(_dereq_,module,exports){
|
13705 | module.exports = extend
|
13706 |
|
13707 | function extend() {
|
13708 | var target = {}
|
13709 |
|
13710 | for (var i = 0; i < arguments.length; i++) {
|
13711 | var source = arguments[i]
|
13712 |
|
13713 | for (var key in source) {
|
13714 | if (source.hasOwnProperty(key)) {
|
13715 | target[key] = source[key]
|
13716 | }
|
13717 | }
|
13718 | }
|
13719 |
|
13720 | return target
|
13721 | }
|
13722 |
|
13723 | },{}],106:[function(_dereq_,module,exports){
|
13724 | (function (global){
|
13725 | 'use strict';
|
13726 |
|
13727 | function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
13728 |
|
13729 | var getArguments = _interopDefault(_dereq_(4));
|
13730 | var nextTick = _interopDefault(_dereq_(25));
|
13731 | var events = _dereq_(18);
|
13732 | var events__default = _interopDefault(events);
|
13733 | var inherits = _interopDefault(_dereq_(26));
|
13734 | var Md5 = _interopDefault(_dereq_(66));
|
13735 | var uuidV4 = _interopDefault(_dereq_(99));
|
13736 | var ltgt = _interopDefault(_dereq_(53));
|
13737 | var ReadableStreamCore = _interopDefault(_dereq_(64));
|
13738 | var Codec = _interopDefault(_dereq_(29));
|
13739 | var vuvuzela = _interopDefault(_dereq_(104));
|
13740 | var levelup = _interopDefault(_dereq_(43));
|
13741 | var through2 = _dereq_(93);
|
13742 | var Deque = _interopDefault(_dereq_(15));
|
13743 | var bufferFrom = _interopDefault(_dereq_(11));
|
13744 | var fruitdown = _interopDefault(_dereq_(21));
|
13745 |
|
13746 | function isBinaryObject(object) {
|
13747 | return (typeof ArrayBuffer !== 'undefined' && object instanceof ArrayBuffer) ||
|
13748 | (typeof Blob !== 'undefined' && object instanceof Blob);
|
13749 | }
|
13750 |
|
13751 | function cloneArrayBuffer(buff) {
|
13752 | if (typeof buff.slice === 'function') {
|
13753 | return buff.slice(0);
|
13754 | }
|
13755 |
|
13756 | var target = new ArrayBuffer(buff.byteLength);
|
13757 | var targetArray = new Uint8Array(target);
|
13758 | var sourceArray = new Uint8Array(buff);
|
13759 | targetArray.set(sourceArray);
|
13760 | return target;
|
13761 | }
|
13762 |
|
13763 | function cloneBinaryObject(object) {
|
13764 | if (object instanceof ArrayBuffer) {
|
13765 | return cloneArrayBuffer(object);
|
13766 | }
|
13767 | var size = object.size;
|
13768 | var type = object.type;
|
13769 |
|
13770 | if (typeof object.slice === 'function') {
|
13771 | return object.slice(0, size, type);
|
13772 | }
|
13773 |
|
13774 | return object.webkitSlice(0, size, type);
|
13775 | }
|
13776 |
|
13777 |
|
13778 |
|
13779 |
|
13780 |
|
13781 | var funcToString = Function.prototype.toString;
|
13782 | var objectCtorString = funcToString.call(Object);
|
13783 |
|
13784 | function isPlainObject(value) {
|
13785 | var proto = Object.getPrototypeOf(value);
|
13786 |
|
13787 | if (proto === null) {
|
13788 | return true;
|
13789 | }
|
13790 | var Ctor = proto.constructor;
|
13791 | return (typeof Ctor == 'function' &&
|
13792 | Ctor instanceof Ctor && funcToString.call(Ctor) == objectCtorString);
|
13793 | }
|
13794 |
|
13795 | function clone(object) {
|
13796 | var newObject;
|
13797 | var i;
|
13798 | var len;
|
13799 |
|
13800 | if (!object || typeof object !== 'object') {
|
13801 | return object;
|
13802 | }
|
13803 |
|
13804 | if (Array.isArray(object)) {
|
13805 | newObject = [];
|
13806 | for (i = 0, len = object.length; i < len; i++) {
|
13807 | newObject[i] = clone(object[i]);
|
13808 | }
|
13809 | return newObject;
|
13810 | }
|
13811 |
|
13812 |
|
13813 |
|
13814 | if (object instanceof Date) {
|
13815 | return object.toISOString();
|
13816 | }
|
13817 |
|
13818 | if (isBinaryObject(object)) {
|
13819 | return cloneBinaryObject(object);
|
13820 | }
|
13821 |
|
13822 | if (!isPlainObject(object)) {
|
13823 | return object;
|
13824 | }
|
13825 |
|
13826 | newObject = {};
|
13827 | for (i in object) {
|
13828 |
|
13829 | if (Object.prototype.hasOwnProperty.call(object, i)) {
|
13830 | var value = clone(object[i]);
|
13831 | if (typeof value !== 'undefined') {
|
13832 | newObject[i] = value;
|
13833 | }
|
13834 | }
|
13835 | }
|
13836 | return newObject;
|
13837 | }
|
13838 |
|
13839 | function mangle(key) {
|
13840 | return '$' + key;
|
13841 | }
|
13842 | function unmangle(key) {
|
13843 | return key.substring(1);
|
13844 | }
|
13845 | function Map$1() {
|
13846 | this._store = {};
|
13847 | }
|
13848 | Map$1.prototype.get = function (key) {
|
13849 | var mangled = mangle(key);
|
13850 | return this._store[mangled];
|
13851 | };
|
13852 | Map$1.prototype.set = function (key, value) {
|
13853 | var mangled = mangle(key);
|
13854 | this._store[mangled] = value;
|
13855 | return true;
|
13856 | };
|
13857 | Map$1.prototype.has = function (key) {
|
13858 | var mangled = mangle(key);
|
13859 | return mangled in this._store;
|
13860 | };
|
13861 | Map$1.prototype["delete"] = function (key) {
|
13862 | var mangled = mangle(key);
|
13863 | var res = mangled in this._store;
|
13864 | delete this._store[mangled];
|
13865 | return res;
|
13866 | };
|
13867 | Map$1.prototype.forEach = function (cb) {
|
13868 | var keys = Object.keys(this._store);
|
13869 | for (var i = 0, len = keys.length; i < len; i++) {
|
13870 | var key = keys[i];
|
13871 | var value = this._store[key];
|
13872 | key = unmangle(key);
|
13873 | cb(value, key);
|
13874 | }
|
13875 | };
|
13876 | Object.defineProperty(Map$1.prototype, 'size', {
|
13877 | get: function () {
|
13878 | return Object.keys(this._store).length;
|
13879 | }
|
13880 | });
|
13881 |
|
13882 | function Set$1(array) {
|
13883 | this._store = new Map$1();
|
13884 |
|
13885 |
|
13886 | if (array && Array.isArray(array)) {
|
13887 | for (var i = 0, len = array.length; i < len; i++) {
|
13888 | this.add(array[i]);
|
13889 | }
|
13890 | }
|
13891 | }
|
13892 | Set$1.prototype.add = function (key) {
|
13893 | return this._store.set(key, true);
|
13894 | };
|
13895 | Set$1.prototype.has = function (key) {
|
13896 | return this._store.has(key);
|
13897 | };
|
13898 | Set$1.prototype.forEach = function (cb) {
|
13899 | this._store.forEach(function (value, key) {
|
13900 | cb(key);
|
13901 | });
|
13902 | };
|
13903 | Object.defineProperty(Set$1.prototype, 'size', {
|
13904 | get: function () {
|
13905 | return this._store.size;
|
13906 | }
|
13907 | });
|
13908 |
|
13909 |
|
13910 |
|
13911 |
|
13912 |
|
13913 | function supportsMapAndSet() {
|
13914 | if (typeof Symbol === 'undefined' || typeof Map === 'undefined' || typeof Set === 'undefined') {
|
13915 | return false;
|
13916 | }
|
13917 | var prop = Object.getOwnPropertyDescriptor(Map, Symbol.species);
|
13918 | return prop && 'get' in prop && Map[Symbol.species] === Map;
|
13919 | }
|
13920 |
|
13921 |
|
13922 |
|
13923 | var ExportedSet;
|
13924 | var ExportedMap;
|
13925 |
|
13926 | {
|
13927 | if (supportsMapAndSet()) {
|
13928 | ExportedSet = Set;
|
13929 | ExportedMap = Map;
|
13930 | } else {
|
13931 | ExportedSet = Set$1;
|
13932 | ExportedMap = Map$1;
|
13933 | }
|
13934 | }
|
13935 |
|
13936 |
|
13937 | function pick(obj, arr) {
|
13938 | var res = {};
|
13939 | for (var i = 0, len = arr.length; i < len; i++) {
|
13940 | var prop = arr[i];
|
13941 | if (prop in obj) {
|
13942 | res[prop] = obj[prop];
|
13943 | }
|
13944 | }
|
13945 | return res;
|
13946 | }
|
13947 |
|
13948 | var hasLocal;
|
13949 |
|
13950 | try {
|
13951 | localStorage.setItem('_pouch_check_localstorage', 1);
|
13952 | hasLocal = !!localStorage.getItem('_pouch_check_localstorage');
|
13953 | } catch (e) {
|
13954 | hasLocal = false;
|
13955 | }
|
13956 |
|
13957 | function hasLocalStorage() {
|
13958 | return hasLocal;
|
13959 | }
|
13960 |
|
13961 |
|
13962 |
|
13963 | inherits(Changes, events.EventEmitter);
|
13964 |
|
13965 |
|
13966 | function attachBrowserEvents(self) {
|
13967 | if (hasLocalStorage()) {
|
13968 | addEventListener("storage", function (e) {
|
13969 | self.emit(e.key);
|
13970 | });
|
13971 | }
|
13972 | }
|
13973 |
|
13974 | function Changes() {
|
13975 | events.EventEmitter.call(this);
|
13976 | this._listeners = {};
|
13977 |
|
13978 | attachBrowserEvents(this);
|
13979 | }
|
13980 | Changes.prototype.addListener = function (dbName, id, db, opts) {
|
13981 |
|
13982 | if (this._listeners[id]) {
|
13983 | return;
|
13984 | }
|
13985 | var self = this;
|
13986 | var inprogress = false;
|
13987 | function eventFunction() {
|
13988 |
|
13989 | if (!self._listeners[id]) {
|
13990 | return;
|
13991 | }
|
13992 | if (inprogress) {
|
13993 | inprogress = 'waiting';
|
13994 | return;
|
13995 | }
|
13996 | inprogress = true;
|
13997 | var changesOpts = pick(opts, [
|
13998 | 'style', 'include_docs', 'attachments', 'conflicts', 'filter',
|
13999 | 'doc_ids', 'view', 'since', 'query_params', 'binary', 'return_docs'
|
14000 | ]);
|
14001 |
|
14002 |
|
14003 | function onError() {
|
14004 | inprogress = false;
|
14005 | }
|
14006 |
|
14007 | db.changes(changesOpts).on('change', function (c) {
|
14008 | if (c.seq > opts.since && !opts.cancelled) {
|
14009 | opts.since = c.seq;
|
14010 | opts.onChange(c);
|
14011 | }
|
14012 | }).on('complete', function () {
|
14013 | if (inprogress === 'waiting') {
|
14014 | nextTick(eventFunction);
|
14015 | }
|
14016 | inprogress = false;
|
14017 | }).on('error', onError);
|
14018 | }
|
14019 | this._listeners[id] = eventFunction;
|
14020 | this.on(dbName, eventFunction);
|
14021 | };
|
14022 |
|
14023 | Changes.prototype.removeListener = function (dbName, id) {
|
14024 |
|
14025 | if (!(id in this._listeners)) {
|
14026 | return;
|
14027 | }
|
14028 | events.EventEmitter.prototype.removeListener.call(this, dbName,
|
14029 | this._listeners[id]);
|
14030 | delete this._listeners[id];
|
14031 | };
|
14032 |
|
14033 |
|
14034 |
|
14035 | Changes.prototype.notifyLocalWindows = function (dbName) {
|
14036 |
|
14037 |
|
14038 | if (hasLocalStorage()) {
|
14039 | localStorage[dbName] = (localStorage[dbName] === "a") ? "b" : "a";
|
14040 | }
|
14041 | };
|
14042 |
|
14043 | Changes.prototype.notify = function (dbName) {
|
14044 | this.emit(dbName);
|
14045 | this.notifyLocalWindows(dbName);
|
14046 | };
|
14047 |
|
14048 | function guardedConsole(method) {
|
14049 |
|
14050 | if (typeof console !== 'undefined' && typeof console[method] === 'function') {
|
14051 | var args = Array.prototype.slice.call(arguments, 1);
|
14052 | console[method].apply(console, args);
|
14053 | }
|
14054 | }
|
14055 |
|
14056 | var assign;
|
14057 | {
|
14058 | if (typeof Object.assign === 'function') {
|
14059 | assign = Object.assign;
|
14060 | } else {
|
14061 |
|
14062 |
|
14063 | assign = function (target) {
|
14064 | var to = Object(target);
|
14065 |
|
14066 | for (var index = 1; index < arguments.length; index++) {
|
14067 | var nextSource = arguments[index];
|
14068 |
|
14069 | if (nextSource != null) {
|
14070 | for (var nextKey in nextSource) {
|
14071 |
|
14072 | if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
|
14073 | to[nextKey] = nextSource[nextKey];
|
14074 | }
|
14075 | }
|
14076 | }
|
14077 | }
|
14078 | return to;
|
14079 | };
|
14080 | }
|
14081 | }
|
14082 |
|
14083 | var $inject_Object_assign = assign;
|
14084 |
|
14085 | inherits(PouchError, Error);
|
14086 |
|
14087 | function PouchError(status, error, reason) {
|
14088 | Error.call(this, reason);
|
14089 | this.status = status;
|
14090 | this.name = error;
|
14091 | this.message = reason;
|
14092 | this.error = true;
|
14093 | }
|
14094 |
|
14095 | PouchError.prototype.toString = function () {
|
14096 | return JSON.stringify({
|
14097 | status: this.status,
|
14098 | name: this.name,
|
14099 | message: this.message,
|
14100 | reason: this.reason
|
14101 | });
|
14102 | };
|
14103 |
|
14104 | var UNAUTHORIZED = new PouchError(401, 'unauthorized', "Name or password is incorrect.");
|
14105 | var MISSING_BULK_DOCS = new PouchError(400, 'bad_request', "Missing JSON list of 'docs'");
|
14106 | var MISSING_DOC = new PouchError(404, 'not_found', 'missing');
|
14107 | var REV_CONFLICT = new PouchError(409, 'conflict', 'Document update conflict');
|
14108 | var INVALID_ID = new PouchError(400, 'bad_request', '_id field must contain a string');
|
14109 | var MISSING_ID = new PouchError(412, 'missing_id', '_id is required for puts');
|
14110 | var RESERVED_ID = new PouchError(400, 'bad_request', 'Only reserved document ids may start with underscore.');
|
14111 | var NOT_OPEN = new PouchError(412, 'precondition_failed', 'Database not open');
|
14112 | var UNKNOWN_ERROR = new PouchError(500, 'unknown_error', 'Database encountered an unknown error');
|
14113 | var BAD_ARG = new PouchError(500, 'badarg', 'Some query argument is invalid');
|
14114 | var INVALID_REQUEST = new PouchError(400, 'invalid_request', 'Request was invalid');
|
14115 | var QUERY_PARSE_ERROR = new PouchError(400, 'query_parse_error', 'Some query parameter is invalid');
|
14116 | var DOC_VALIDATION = new PouchError(500, 'doc_validation', 'Bad special document member');
|
14117 | var BAD_REQUEST = new PouchError(400, 'bad_request', 'Something wrong with the request');
|
14118 | var NOT_AN_OBJECT = new PouchError(400, 'bad_request', 'Document must be a JSON object');
|
14119 | var DB_MISSING = new PouchError(404, 'not_found', 'Database not found');
|
14120 | var IDB_ERROR = new PouchError(500, 'indexed_db_went_bad', 'unknown');
|
14121 | var WSQ_ERROR = new PouchError(500, 'web_sql_went_bad', 'unknown');
|
14122 | var LDB_ERROR = new PouchError(500, 'levelDB_went_went_bad', 'unknown');
|
14123 | var FORBIDDEN = new PouchError(403, 'forbidden', 'Forbidden by design doc validate_doc_update function');
|
14124 | var INVALID_REV = new PouchError(400, 'bad_request', 'Invalid rev format');
|
14125 | var FILE_EXISTS = new PouchError(412, 'file_exists', 'The database could not be created, the file already exists.');
|
14126 | var MISSING_STUB = new PouchError(412, 'missing_stub', 'A pre-existing attachment stub wasn\'t found');
|
14127 | var INVALID_URL = new PouchError(413, 'invalid_url', 'Provided URL is invalid');
|
14128 |
|
14129 | function createError(error, reason) {
|
14130 | function CustomPouchError(reason) {
|
14131 |
|
14132 |
|
14133 |
|
14134 | for (var p in error) {
|
14135 | if (typeof error[p] !== 'function') {
|
14136 | this[p] = error[p];
|
14137 | }
|
14138 | }
|
14139 |
|
14140 | if (reason !== undefined) {
|
14141 | this.reason = reason;
|
14142 | }
|
14143 | }
|
14144 | CustomPouchError.prototype = PouchError.prototype;
|
14145 | return new CustomPouchError(reason);
|
14146 | }
|
14147 |
|
14148 | function tryFilter(filter, doc, req) {
|
14149 | try {
|
14150 | return !filter(doc, req);
|
14151 | } catch (err) {
|
14152 | var msg = 'Filter function threw: ' + err.toString();
|
14153 | return createError(BAD_REQUEST, msg);
|
14154 | }
|
14155 | }
|
14156 |
|
14157 | function filterChange(opts) {
|
14158 | var req = {};
|
14159 | var hasFilter = opts.filter && typeof opts.filter === 'function';
|
14160 | req.query = opts.query_params;
|
14161 |
|
14162 | return function filter(change) {
|
14163 | if (!change.doc) {
|
14164 |
|
14165 |
|
14166 | change.doc = {};
|
14167 | }
|
14168 |
|
14169 | var filterReturn = hasFilter && tryFilter(opts.filter, change.doc, req);
|
14170 |
|
14171 | if (typeof filterReturn === 'object') {
|
14172 | return filterReturn;
|
14173 | }
|
14174 |
|
14175 | if (filterReturn) {
|
14176 | return false;
|
14177 | }
|
14178 |
|
14179 | if (!opts.include_docs) {
|
14180 | delete change.doc;
|
14181 | } else if (!opts.attachments) {
|
14182 | for (var att in change.doc._attachments) {
|
14183 |
|
14184 | if (change.doc._attachments.hasOwnProperty(att)) {
|
14185 | change.doc._attachments[att].stub = true;
|
14186 | }
|
14187 | }
|
14188 | }
|
14189 | return true;
|
14190 | };
|
14191 | }
|
14192 |
|
14193 |
|
14194 |
|
14195 |
|
14196 |
|
14197 | function f() {}
|
14198 |
|
14199 | var hasName = f.name;
|
14200 | var res;
|
14201 |
|
14202 |
|
14203 |
|
14204 | if (hasName) {
|
14205 | res = function (fun) {
|
14206 | return fun.name;
|
14207 | };
|
14208 | } else {
|
14209 | res = function (fun) {
|
14210 | var match = fun.toString().match(/^\s*function\s*(?:(\S+)\s*)?\(/);
|
14211 | if (match && match[1]) {
|
14212 | return match[1];
|
14213 | }
|
14214 | else {
|
14215 | return '';
|
14216 | }
|
14217 | };
|
14218 | }
|
14219 |
|
14220 | var functionName = res;
|
14221 |
|
14222 |
|
14223 |
|
14224 |
|
14225 |
|
14226 |
|
14227 | function invalidIdError(id) {
|
14228 | var err;
|
14229 | if (!id) {
|
14230 | err = createError(MISSING_ID);
|
14231 | } else if (typeof id !== 'string') {
|
14232 | err = createError(INVALID_ID);
|
14233 | } else if (/^_/.test(id) && !(/^_(design|local)/).test(id)) {
|
14234 | err = createError(RESERVED_ID);
|
14235 | }
|
14236 | if (err) {
|
14237 | throw err;
|
14238 | }
|
14239 | }
|
14240 |
|
14241 |
|
14242 |
|
14243 |
|
14244 |
|
14245 |
|
14246 |
|
14247 | var thisAtob = function (str) {
|
14248 | return atob(str);
|
14249 | };
|
14250 |
|
14251 | var thisBtoa = function (str) {
|
14252 | return btoa(str);
|
14253 | };
|
14254 |
|
14255 |
|
14256 |
|
14257 |
|
14258 | function createBlob(parts, properties) {
|
14259 |
|
14260 | parts = parts || [];
|
14261 | properties = properties || {};
|
14262 | try {
|
14263 | return new Blob(parts, properties);
|
14264 | } catch (e) {
|
14265 | if (e.name !== "TypeError") {
|
14266 | throw e;
|
14267 | }
|
14268 | var Builder = typeof BlobBuilder !== 'undefined' ? BlobBuilder :
|
14269 | typeof MSBlobBuilder !== 'undefined' ? MSBlobBuilder :
|
14270 | typeof MozBlobBuilder !== 'undefined' ? MozBlobBuilder :
|
14271 | WebKitBlobBuilder;
|
14272 | var builder = new Builder();
|
14273 | for (var i = 0; i < parts.length; i += 1) {
|
14274 | builder.append(parts[i]);
|
14275 | }
|
14276 | return builder.getBlob(properties.type);
|
14277 | }
|
14278 | }
|
14279 |
|
14280 |
|
14281 |
|
14282 | function binaryStringToArrayBuffer(bin) {
|
14283 | var length = bin.length;
|
14284 | var buf = new ArrayBuffer(length);
|
14285 | var arr = new Uint8Array(buf);
|
14286 | for (var i = 0; i < length; i++) {
|
14287 | arr[i] = bin.charCodeAt(i);
|
14288 | }
|
14289 | return buf;
|
14290 | }
|
14291 |
|
14292 | function binStringToBluffer(binString, type) {
|
14293 | return createBlob([binaryStringToArrayBuffer(binString)], {type: type});
|
14294 | }
|
14295 |
|
14296 |
|
14297 |
|
14298 |
|
14299 | function arrayBufferToBinaryString(buffer) {
|
14300 | var binary = '';
|
14301 | var bytes = new Uint8Array(buffer);
|
14302 | var length = bytes.byteLength;
|
14303 | for (var i = 0; i < length; i++) {
|
14304 | binary += String.fromCharCode(bytes[i]);
|
14305 | }
|
14306 | return binary;
|
14307 | }
|
14308 |
|
14309 |
|
14310 | function readAsBinaryString(blob, callback) {
|
14311 | var reader = new FileReader();
|
14312 | var hasBinaryString = typeof reader.readAsBinaryString === 'function';
|
14313 | reader.onloadend = function (e) {
|
14314 | var result = e.target.result || '';
|
14315 | if (hasBinaryString) {
|
14316 | return callback(result);
|
14317 | }
|
14318 | callback(arrayBufferToBinaryString(result));
|
14319 | };
|
14320 | if (hasBinaryString) {
|
14321 | reader.readAsBinaryString(blob);
|
14322 | } else {
|
14323 | reader.readAsArrayBuffer(blob);
|
14324 | }
|
14325 | }
|
14326 |
|
14327 |
|
14328 | function readAsArrayBuffer(blob, callback) {
|
14329 | var reader = new FileReader();
|
14330 | reader.onloadend = function (e) {
|
14331 | var result = e.target.result || new ArrayBuffer(0);
|
14332 | callback(result);
|
14333 | };
|
14334 | reader.readAsArrayBuffer(blob);
|
14335 | }
|
14336 |
|
14337 |
|
14338 |
|
14339 | var setImmediateShim = global.setImmediate || global.setTimeout;
|
14340 | var MD5_CHUNK_SIZE = 32768;
|
14341 |
|
14342 | function rawToBase64(raw) {
|
14343 | return thisBtoa(raw);
|
14344 | }
|
14345 |
|
14346 | function sliceBlob(blob, start, end) {
|
14347 | if (blob.webkitSlice) {
|
14348 | return blob.webkitSlice(start, end);
|
14349 | }
|
14350 | return blob.slice(start, end);
|
14351 | }
|
14352 |
|
14353 | function appendBlob(buffer, blob, start, end, callback) {
|
14354 | if (start > 0 || end < blob.size) {
|
14355 |
|
14356 | blob = sliceBlob(blob, start, end);
|
14357 | }
|
14358 | readAsArrayBuffer(blob, function (arrayBuffer) {
|
14359 | buffer.append(arrayBuffer);
|
14360 | callback();
|
14361 | });
|
14362 | }
|
14363 |
|
14364 | function appendString(buffer, string, start, end, callback) {
|
14365 | if (start > 0 || end < string.length) {
|
14366 |
|
14367 | string = string.substring(start, end);
|
14368 | }
|
14369 | buffer.appendBinary(string);
|
14370 | callback();
|
14371 | }
|
14372 |
|
14373 | function binaryMd5(data, callback) {
|
14374 | var inputIsString = typeof data === 'string';
|
14375 | var len = inputIsString ? data.length : data.size;
|
14376 | var chunkSize = Math.min(MD5_CHUNK_SIZE, len);
|
14377 | var chunks = Math.ceil(len / chunkSize);
|
14378 | var currentChunk = 0;
|
14379 | var buffer = inputIsString ? new Md5() : new Md5.ArrayBuffer();
|
14380 |
|
14381 | var append = inputIsString ? appendString : appendBlob;
|
14382 |
|
14383 | function next() {
|
14384 | setImmediateShim(loadNextChunk);
|
14385 | }
|
14386 |
|
14387 | function done() {
|
14388 | var raw = buffer.end(true);
|
14389 | var base64 = rawToBase64(raw);
|
14390 | callback(base64);
|
14391 | buffer.destroy();
|
14392 | }
|
14393 |
|
14394 | function loadNextChunk() {
|
14395 | var start = currentChunk * chunkSize;
|
14396 | var end = start + chunkSize;
|
14397 | currentChunk++;
|
14398 | if (currentChunk < chunks) {
|
14399 | append(buffer, data, start, end, next);
|
14400 | } else {
|
14401 | append(buffer, data, start, end, done);
|
14402 | }
|
14403 | }
|
14404 | loadNextChunk();
|
14405 | }
|
14406 |
|
14407 | function stringMd5(string) {
|
14408 | return Md5.hash(string);
|
14409 | }
|
14410 |
|
14411 | function rev$$1(doc, deterministic_revs) {
|
14412 | var clonedDoc = clone(doc);
|
14413 | if (!deterministic_revs) {
|
14414 | return uuidV4.v4().replace(/-/g, '').toLowerCase();
|
14415 | }
|
14416 |
|
14417 | delete clonedDoc._rev_tree;
|
14418 | return stringMd5(JSON.stringify(clonedDoc));
|
14419 | }
|
14420 |
|
14421 | var uuid = uuidV4.v4;
|
14422 |
|
14423 | function isFunction(f) {
|
14424 | return 'function' === typeof f;
|
14425 | }
|
14426 |
|
14427 | function getPrefix(db) {
|
14428 | if (isFunction(db.prefix)) {
|
14429 | return db.prefix();
|
14430 | }
|
14431 | return db;
|
14432 | }
|
14433 |
|
14434 | function clone$1(_obj) {
|
14435 | var obj = {};
|
14436 | for (var k in _obj) {
|
14437 | obj[k] = _obj[k];
|
14438 | }
|
14439 | return obj;
|
14440 | }
|
14441 |
|
14442 | function nut(db, precodec, codec) {
|
14443 | function encodePrefix(prefix, key, opts1, opts2) {
|
14444 | return precodec.encode([ prefix, codec.encodeKey(key, opts1, opts2 ) ]);
|
14445 | }
|
14446 |
|
14447 | function addEncodings(op, prefix) {
|
14448 | if (prefix && prefix.options) {
|
14449 | op.keyEncoding =
|
14450 | op.keyEncoding || prefix.options.keyEncoding;
|
14451 | op.valueEncoding =
|
14452 | op.valueEncoding || prefix.options.valueEncoding;
|
14453 | }
|
14454 | return op;
|
14455 | }
|
14456 |
|
14457 | db.open(function () { });
|
14458 |
|
14459 | return {
|
14460 | apply: function (ops, opts, cb) {
|
14461 | opts = opts || {};
|
14462 |
|
14463 | var batch = [];
|
14464 | var i = -1;
|
14465 | var len = ops.length;
|
14466 |
|
14467 | while (++i < len) {
|
14468 | var op = ops[i];
|
14469 | addEncodings(op, op.prefix);
|
14470 | op.prefix = getPrefix(op.prefix);
|
14471 | batch.push({
|
14472 | key: encodePrefix(op.prefix, op.key, opts, op),
|
14473 | value: op.type !== 'del' && codec.encodeValue(op.value, opts, op),
|
14474 | type: op.type
|
14475 | });
|
14476 | }
|
14477 | db.db.batch(batch, opts, cb);
|
14478 | },
|
14479 | get: function (key, prefix, opts, cb) {
|
14480 | opts.asBuffer = codec.valueAsBuffer(opts);
|
14481 | return db.db.get(
|
14482 | encodePrefix(prefix, key, opts),
|
14483 | opts,
|
14484 | function (err, value) {
|
14485 | if (err) {
|
14486 | cb(err);
|
14487 | } else {
|
14488 | cb(null, codec.decodeValue(value, opts));
|
14489 | }
|
14490 | }
|
14491 | );
|
14492 | },
|
14493 | createDecoder: function (opts) {
|
14494 | return function (key, value) {
|
14495 | return {
|
14496 | key: codec.decodeKey(precodec.decode(key)[1], opts),
|
14497 | value: codec.decodeValue(value, opts)
|
14498 | };
|
14499 | };
|
14500 | },
|
14501 | isClosed: function isClosed() {
|
14502 | return db.isClosed();
|
14503 | },
|
14504 | close: function close(cb) {
|
14505 | return db.close(cb);
|
14506 | },
|
14507 | iterator: function (_opts) {
|
14508 | var opts = clone$1(_opts || {});
|
14509 | var prefix = _opts.prefix || [];
|
14510 |
|
14511 | function encodeKey(key) {
|
14512 | return encodePrefix(prefix, key, opts, {});
|
14513 | }
|
14514 |
|
14515 | ltgt.toLtgt(_opts, opts, encodeKey, precodec.lowerBound, precodec.upperBound);
|
14516 |
|
14517 |
|
14518 |
|
14519 | opts.prefix = null;
|
14520 |
|
14521 |
|
14522 |
|
14523 |
|
14524 | opts.keyAsBuffer = opts.valueAsBuffer = false;
|
14525 |
|
14526 |
|
14527 |
|
14528 |
|
14529 |
|
14530 |
|
14531 | if ('number' !== typeof opts.limit) {
|
14532 | opts.limit = -1;
|
14533 | }
|
14534 |
|
14535 | opts.keyAsBuffer = precodec.buffer;
|
14536 | opts.valueAsBuffer = codec.valueAsBuffer(opts);
|
14537 |
|
14538 | function wrapIterator(iterator) {
|
14539 | return {
|
14540 | next: function (cb) {
|
14541 | return iterator.next(cb);
|
14542 | },
|
14543 | end: function (cb) {
|
14544 | iterator.end(cb);
|
14545 | }
|
14546 | };
|
14547 | }
|
14548 |
|
14549 | return wrapIterator(db.db.iterator(opts));
|
14550 | }
|
14551 | };
|
14552 | }
|
14553 |
|
14554 | function NotFoundError() {
|
14555 | Error.call(this);
|
14556 | }
|
14557 |
|
14558 | inherits(NotFoundError, Error);
|
14559 |
|
14560 | NotFoundError.prototype.name = 'NotFoundError';
|
14561 |
|
14562 | var EventEmitter = events__default.EventEmitter;
|
14563 | var version = "6.5.4";
|
14564 |
|
14565 | var NOT_FOUND_ERROR = new NotFoundError();
|
14566 |
|
14567 | var sublevel = function (nut, prefix, createStream, options) {
|
14568 | var emitter = new EventEmitter();
|
14569 | emitter.sublevels = {};
|
14570 | emitter.options = options;
|
14571 |
|
14572 | emitter.version = version;
|
14573 |
|
14574 | emitter.methods = {};
|
14575 | prefix = prefix || [];
|
14576 |
|
14577 | function mergeOpts(opts) {
|
14578 | var o = {};
|
14579 | var k;
|
14580 | if (options) {
|
14581 | for (k in options) {
|
14582 | if (typeof options[k] !== 'undefined') {
|
14583 | o[k] = options[k];
|
14584 | }
|
14585 | }
|
14586 | }
|
14587 | if (opts) {
|
14588 | for (k in opts) {
|
14589 | if (typeof opts[k] !== 'undefined') {
|
14590 | o[k] = opts[k];
|
14591 | }
|
14592 | }
|
14593 | }
|
14594 | return o;
|
14595 | }
|
14596 |
|
14597 | emitter.put = function (key, value, opts, cb) {
|
14598 | if ('function' === typeof opts) {
|
14599 | cb = opts;
|
14600 | opts = {};
|
14601 | }
|
14602 |
|
14603 | nut.apply([{
|
14604 | key: key, value: value,
|
14605 | prefix: prefix.slice(), type: 'put'
|
14606 | }], mergeOpts(opts), function (err) {
|
14607 |
|
14608 | if (err) {
|
14609 | return cb(err);
|
14610 | }
|
14611 | emitter.emit('put', key, value);
|
14612 | cb(null);
|
14613 | });
|
14614 | };
|
14615 |
|
14616 | emitter.prefix = function () {
|
14617 | return prefix.slice();
|
14618 | };
|
14619 |
|
14620 | emitter.batch = function (ops, opts, cb) {
|
14621 | if ('function' === typeof opts) {
|
14622 | cb = opts;
|
14623 | opts = {};
|
14624 | }
|
14625 |
|
14626 | ops = ops.map(function (op) {
|
14627 | return {
|
14628 | key: op.key,
|
14629 | value: op.value,
|
14630 | prefix: op.prefix || prefix,
|
14631 | keyEncoding: op.keyEncoding,
|
14632 | valueEncoding: op.valueEncoding,
|
14633 | type: op.type
|
14634 | };
|
14635 | });
|
14636 |
|
14637 | nut.apply(ops, mergeOpts(opts), function (err) {
|
14638 |
|
14639 | if (err) {
|
14640 | return cb(err);
|
14641 | }
|
14642 | emitter.emit('batch', ops);
|
14643 | cb(null);
|
14644 | });
|
14645 | };
|
14646 |
|
14647 | emitter.get = function (key, opts, cb) {
|
14648 |
|
14649 | if ('function' === typeof opts) {
|
14650 | cb = opts;
|
14651 | opts = {};
|
14652 | }
|
14653 | nut.get(key, prefix, mergeOpts(opts), function (err, value) {
|
14654 | if (err) {
|
14655 | cb(NOT_FOUND_ERROR);
|
14656 | } else {
|
14657 | cb(null, value);
|
14658 | }
|
14659 | });
|
14660 | };
|
14661 |
|
14662 | emitter.sublevel = function (name, opts) {
|
14663 | return emitter.sublevels[name] =
|
14664 | emitter.sublevels[name] || sublevel(nut, prefix.concat(name), createStream, mergeOpts(opts));
|
14665 | };
|
14666 |
|
14667 | emitter.readStream = emitter.createReadStream = function (opts) {
|
14668 | opts = mergeOpts(opts);
|
14669 | opts.prefix = prefix;
|
14670 | var stream;
|
14671 | var it = nut.iterator(opts);
|
14672 |
|
14673 | stream = createStream(opts, nut.createDecoder(opts));
|
14674 | stream.setIterator(it);
|
14675 |
|
14676 | return stream;
|
14677 | };
|
14678 |
|
14679 | emitter.close = function (cb) {
|
14680 | nut.close(cb);
|
14681 | };
|
14682 |
|
14683 | emitter.isOpen = nut.isOpen;
|
14684 | emitter.isClosed = nut.isClosed;
|
14685 |
|
14686 | return emitter;
|
14687 | };
|
14688 |
|
14689 |
|
14690 |
|
14691 |
|
14692 |
|
14693 |
|
14694 | var Readable = ReadableStreamCore.Readable;
|
14695 |
|
14696 | function ReadStream(options, makeData) {
|
14697 | if (!(this instanceof ReadStream)) {
|
14698 | return new ReadStream(options, makeData);
|
14699 | }
|
14700 |
|
14701 | Readable.call(this, { objectMode: true, highWaterMark: options.highWaterMark });
|
14702 |
|
14703 |
|
14704 |
|
14705 | this._waiting = false;
|
14706 | this._options = options;
|
14707 | this._makeData = makeData;
|
14708 | }
|
14709 |
|
14710 | inherits(ReadStream, Readable);
|
14711 |
|
14712 | ReadStream.prototype.setIterator = function (it) {
|
14713 | this._iterator = it;
|
14714 |
|
14715 | if (this._destroyed) {
|
14716 | return it.end(function () {});
|
14717 | }
|
14718 |
|
14719 | if (this._waiting) {
|
14720 | this._waiting = false;
|
14721 | return this._read();
|
14722 | }
|
14723 | return this;
|
14724 | };
|
14725 |
|
14726 | ReadStream.prototype._read = function read() {
|
14727 | var self = this;
|
14728 |
|
14729 | if (self._destroyed) {
|
14730 | return;
|
14731 | }
|
14732 |
|
14733 | if (!self._iterator) {
|
14734 | return this._waiting = true;
|
14735 | }
|
14736 |
|
14737 | self._iterator.next(function (err, key, value) {
|
14738 | if (err || (key === undefined && value === undefined)) {
|
14739 | if (!err && !self._destroyed) {
|
14740 | self.push(null);
|
14741 | }
|
14742 | return self._cleanup(err);
|
14743 | }
|
14744 |
|
14745 |
|
14746 | value = self._makeData(key, value);
|
14747 | if (!self._destroyed) {
|
14748 | self.push(value);
|
14749 | }
|
14750 | });
|
14751 | };
|
14752 |
|
14753 | ReadStream.prototype._cleanup = function (err) {
|
14754 | if (this._destroyed) {
|
14755 | return;
|
14756 | }
|
14757 |
|
14758 | this._destroyed = true;
|
14759 |
|
14760 | var self = this;
|
14761 |
|
14762 | if (err && err.message !== 'iterator has ended') {
|
14763 | self.emit('error', err);
|
14764 | }
|
14765 |
|
14766 |
|
14767 | if (self._iterator) {
|
14768 | self._iterator.end(function () {
|
14769 | self._iterator = null;
|
14770 | self.emit('close');
|
14771 | });
|
14772 | } else {
|
14773 | self.emit('close');
|
14774 | }
|
14775 | };
|
14776 |
|
14777 | ReadStream.prototype.destroy = function () {
|
14778 | this._cleanup();
|
14779 | };
|
14780 |
|
14781 | var precodec = {
|
14782 | encode: function (decodedKey) {
|
14783 | return '\xff' + decodedKey[0] + '\xff' + decodedKey[1];
|
14784 | },
|
14785 | decode: function (encodedKeyAsBuffer) {
|
14786 | var str = encodedKeyAsBuffer.toString();
|
14787 | var idx = str.indexOf('\xff', 1);
|
14788 | return [str.substring(1, idx), str.substring(idx + 1)];
|
14789 | },
|
14790 | lowerBound: '\x00',
|
14791 | upperBound: '\xff'
|
14792 | };
|
14793 |
|
14794 | var codec = new Codec();
|
14795 |
|
14796 | function sublevelPouch(db) {
|
14797 | return sublevel(nut(db, precodec, codec), [], ReadStream, db.options);
|
14798 | }
|
14799 |
|
14800 | function allDocsKeysQuery(api, opts) {
|
14801 | var keys = opts.keys;
|
14802 | var finalResults = {
|
14803 | offset: opts.skip
|
14804 | };
|
14805 | return Promise.all(keys.map(function (key) {
|
14806 | var subOpts = $inject_Object_assign({key: key, deleted: 'ok'}, opts);
|
14807 | ['limit', 'skip', 'keys'].forEach(function (optKey) {
|
14808 | delete subOpts[optKey];
|
14809 | });
|
14810 | return new Promise(function (resolve, reject) {
|
14811 | api._allDocs(subOpts, function (err, res) {
|
14812 |
|
14813 | if (err) {
|
14814 | return reject(err);
|
14815 | }
|
14816 |
|
14817 | if (opts.update_seq && res.update_seq !== undefined) {
|
14818 | finalResults.update_seq = res.update_seq;
|
14819 | }
|
14820 | finalResults.total_rows = res.total_rows;
|
14821 | resolve(res.rows[0] || {key: key, error: 'not_found'});
|
14822 | });
|
14823 | });
|
14824 | })).then(function (results) {
|
14825 | finalResults.rows = results;
|
14826 | return finalResults;
|
14827 | });
|
14828 | }
|
14829 |
|
14830 | function toObject(array) {
|
14831 | return array.reduce(function (obj, item) {
|
14832 | obj[item] = true;
|
14833 | return obj;
|
14834 | }, {});
|
14835 | }
|
14836 |
|
14837 | var reservedWords = toObject([
|
14838 | '_id',
|
14839 | '_rev',
|
14840 | '_attachments',
|
14841 | '_deleted',
|
14842 | '_revisions',
|
14843 | '_revs_info',
|
14844 | '_conflicts',
|
14845 | '_deleted_conflicts',
|
14846 | '_local_seq',
|
14847 | '_rev_tree',
|
14848 |
|
14849 | '_replication_id',
|
14850 | '_replication_state',
|
14851 | '_replication_state_time',
|
14852 | '_replication_state_reason',
|
14853 | '_replication_stats',
|
14854 |
|
14855 | '_removed'
|
14856 | ]);
|
14857 |
|
14858 |
|
14859 | var dataWords = toObject([
|
14860 | '_attachments',
|
14861 |
|
14862 | '_replication_id',
|
14863 | '_replication_state',
|
14864 | '_replication_state_time',
|
14865 | '_replication_state_reason',
|
14866 | '_replication_stats'
|
14867 | ]);
|
14868 |
|
14869 | function parseRevisionInfo(rev) {
|
14870 | if (!/^\d+-./.test(rev)) {
|
14871 | return createError(INVALID_REV);
|
14872 | }
|
14873 | var idx = rev.indexOf('-');
|
14874 | var left = rev.substring(0, idx);
|
14875 | var right = rev.substring(idx + 1);
|
14876 | return {
|
14877 | prefix: parseInt(left, 10),
|
14878 | id: right
|
14879 | };
|
14880 | }
|
14881 |
|
14882 | function makeRevTreeFromRevisions(revisions, opts) {
|
14883 | var pos = revisions.start - revisions.ids.length + 1;
|
14884 |
|
14885 | var revisionIds = revisions.ids;
|
14886 | var ids = [revisionIds[0], opts, []];
|
14887 |
|
14888 | for (var i = 1, len = revisionIds.length; i < len; i++) {
|
14889 | ids = [revisionIds[i], {status: 'missing'}, [ids]];
|
14890 | }
|
14891 |
|
14892 | return [{
|
14893 | pos: pos,
|
14894 | ids: ids
|
14895 | }];
|
14896 | }
|
14897 |
|
14898 |
|
14899 |
|
14900 | function parseDoc(doc, newEdits, dbOpts) {
|
14901 | if (!dbOpts) {
|
14902 | dbOpts = {
|
14903 | deterministic_revs: true
|
14904 | };
|
14905 | }
|
14906 |
|
14907 | var nRevNum;
|
14908 | var newRevId;
|
14909 | var revInfo;
|
14910 | var opts = {status: 'available'};
|
14911 | if (doc._deleted) {
|
14912 | opts.deleted = true;
|
14913 | }
|
14914 |
|
14915 | if (newEdits) {
|
14916 | if (!doc._id) {
|
14917 | doc._id = uuid();
|
14918 | }
|
14919 | newRevId = rev$$1(doc, dbOpts.deterministic_revs);
|
14920 | if (doc._rev) {
|
14921 | revInfo = parseRevisionInfo(doc._rev);
|
14922 | if (revInfo.error) {
|
14923 | return revInfo;
|
14924 | }
|
14925 | doc._rev_tree = [{
|
14926 | pos: revInfo.prefix,
|
14927 | ids: [revInfo.id, {status: 'missing'}, [[newRevId, opts, []]]]
|
14928 | }];
|
14929 | nRevNum = revInfo.prefix + 1;
|
14930 | } else {
|
14931 | doc._rev_tree = [{
|
14932 | pos: 1,
|
14933 | ids : [newRevId, opts, []]
|
14934 | }];
|
14935 | nRevNum = 1;
|
14936 | }
|
14937 | } else {
|
14938 | if (doc._revisions) {
|
14939 | doc._rev_tree = makeRevTreeFromRevisions(doc._revisions, opts);
|
14940 | nRevNum = doc._revisions.start;
|
14941 | newRevId = doc._revisions.ids[0];
|
14942 | }
|
14943 | if (!doc._rev_tree) {
|
14944 | revInfo = parseRevisionInfo(doc._rev);
|
14945 | if (revInfo.error) {
|
14946 | return revInfo;
|
14947 | }
|
14948 | nRevNum = revInfo.prefix;
|
14949 | newRevId = revInfo.id;
|
14950 | doc._rev_tree = [{
|
14951 | pos: nRevNum,
|
14952 | ids: [newRevId, opts, []]
|
14953 | }];
|
14954 | }
|
14955 | }
|
14956 |
|
14957 | invalidIdError(doc._id);
|
14958 |
|
14959 | doc._rev = nRevNum + '-' + newRevId;
|
14960 |
|
14961 | var result = {metadata : {}, data : {}};
|
14962 | for (var key in doc) {
|
14963 |
|
14964 | if (Object.prototype.hasOwnProperty.call(doc, key)) {
|
14965 | var specialKey = key[0] === '_';
|
14966 | if (specialKey && !reservedWords[key]) {
|
14967 | var error = createError(DOC_VALIDATION, key);
|
14968 | error.message = DOC_VALIDATION.message + ': ' + key;
|
14969 | throw error;
|
14970 | } else if (specialKey && !dataWords[key]) {
|
14971 | result.metadata[key.slice(1)] = doc[key];
|
14972 | } else {
|
14973 | result.data[key] = doc[key];
|
14974 | }
|
14975 | }
|
14976 | }
|
14977 | return result;
|
14978 | }
|
14979 |
|
14980 |
|
14981 |
|
14982 |
|
14983 |
|
14984 |
|
14985 | function winningRev(metadata) {
|
14986 | var winningId;
|
14987 | var winningPos;
|
14988 | var winningDeleted;
|
14989 | var toVisit = metadata.rev_tree.slice();
|
14990 | var node;
|
14991 | while ((node = toVisit.pop())) {
|
14992 | var tree = node.ids;
|
14993 | var branches = tree[2];
|
14994 | var pos = node.pos;
|
14995 | if (branches.length) {
|
14996 | for (var i = 0, len = branches.length; i < len; i++) {
|
14997 | toVisit.push({pos: pos + 1, ids: branches[i]});
|
14998 | }
|
14999 | continue;
|
15000 | }
|
15001 | var deleted = !!tree[1].deleted;
|
15002 | var id = tree[0];
|
15003 |
|
15004 | if (!winningId || (winningDeleted !== deleted ? winningDeleted :
|
15005 | winningPos !== pos ? winningPos < pos : winningId < id)) {
|
15006 | winningId = id;
|
15007 | winningPos = pos;
|
15008 | winningDeleted = deleted;
|
15009 | }
|
15010 | }
|
15011 |
|
15012 | return winningPos + '-' + winningId;
|
15013 | }
|
15014 |
|
15015 |
|
15016 |
|
15017 |
|
15018 |
|
15019 | function traverseRevTree(revs, callback) {
|
15020 | var toVisit = revs.slice();
|
15021 |
|
15022 | var node;
|
15023 | while ((node = toVisit.pop())) {
|
15024 | var pos = node.pos;
|
15025 | var tree = node.ids;
|
15026 | var branches = tree[2];
|
15027 | var newCtx =
|
15028 | callback(branches.length === 0, pos, tree[0], node.ctx, tree[1]);
|
15029 | for (var i = 0, len = branches.length; i < len; i++) {
|
15030 | toVisit.push({pos: pos + 1, ids: branches[i], ctx: newCtx});
|
15031 | }
|
15032 | }
|
15033 | }
|
15034 |
|
15035 | function sortByPos(a, b) {
|
15036 | return a.pos - b.pos;
|
15037 | }
|
15038 |
|
15039 | function collectLeaves(revs) {
|
15040 | var leaves = [];
|
15041 | traverseRevTree(revs, function (isLeaf, pos, id, acc, opts) {
|
15042 | if (isLeaf) {
|
15043 | leaves.push({rev: pos + "-" + id, pos: pos, opts: opts});
|
15044 | }
|
15045 | });
|
15046 | leaves.sort(sortByPos).reverse();
|
15047 | for (var i = 0, len = leaves.length; i < len; i++) {
|
15048 | delete leaves[i].pos;
|
15049 | }
|
15050 | return leaves;
|
15051 | }
|
15052 |
|
15053 |
|
15054 |
|
15055 |
|
15056 | function collectConflicts(metadata) {
|
15057 | var win = winningRev(metadata);
|
15058 | var leaves = collectLeaves(metadata.rev_tree);
|
15059 | var conflicts = [];
|
15060 | for (var i = 0, len = leaves.length; i < len; i++) {
|
15061 | var leaf = leaves[i];
|
15062 | if (leaf.rev !== win && !leaf.opts.deleted) {
|
15063 | conflicts.push(leaf.rev);
|
15064 | }
|
15065 | }
|
15066 | return conflicts;
|
15067 | }
|
15068 |
|
15069 |
|
15070 |
|
15071 | function compactTree(metadata) {
|
15072 | var revs = [];
|
15073 | traverseRevTree(metadata.rev_tree, function (isLeaf, pos,
|
15074 | revHash, ctx, opts) {
|
15075 | if (opts.status === 'available' && !isLeaf) {
|
15076 | revs.push(pos + '-' + revHash);
|
15077 | opts.status = 'missing';
|
15078 | }
|
15079 | });
|
15080 | return revs;
|
15081 | }
|
15082 |
|
15083 |
|
15084 | function rootToLeaf(revs) {
|
15085 | var paths = [];
|
15086 | var toVisit = revs.slice();
|
15087 | var node;
|
15088 | while ((node = toVisit.pop())) {
|
15089 | var pos = node.pos;
|
15090 | var tree = node.ids;
|
15091 | var id = tree[0];
|
15092 | var opts = tree[1];
|
15093 | var branches = tree[2];
|
15094 | var isLeaf = branches.length === 0;
|
15095 |
|
15096 | var history = node.history ? node.history.slice() : [];
|
15097 | history.push({id: id, opts: opts});
|
15098 | if (isLeaf) {
|
15099 | paths.push({pos: (pos + 1 - history.length), ids: history});
|
15100 | }
|
15101 | for (var i = 0, len = branches.length; i < len; i++) {
|
15102 | toVisit.push({pos: pos + 1, ids: branches[i], history: history});
|
15103 | }
|
15104 | }
|
15105 | return paths.reverse();
|
15106 | }
|
15107 |
|
15108 |
|
15109 |
|
15110 | function sortByPos$1(a, b) {
|
15111 | return a.pos - b.pos;
|
15112 | }
|
15113 |
|
15114 |
|
15115 | function binarySearch(arr, item, comparator) {
|
15116 | var low = 0;
|
15117 | var high = arr.length;
|
15118 | var mid;
|
15119 | while (low < high) {
|
15120 | mid = (low + high) >>> 1;
|
15121 | if (comparator(arr[mid], item) < 0) {
|
15122 | low = mid + 1;
|
15123 | } else {
|
15124 | high = mid;
|
15125 | }
|
15126 | }
|
15127 | return low;
|
15128 | }
|
15129 |
|
15130 |
|
15131 | function insertSorted(arr, item, comparator) {
|
15132 | var idx = binarySearch(arr, item, comparator);
|
15133 | arr.splice(idx, 0, item);
|
15134 | }
|
15135 |
|
15136 |
|
15137 |
|
15138 |
|
15139 | function pathToTree(path, numStemmed) {
|
15140 | var root;
|
15141 | var leaf;
|
15142 | for (var i = numStemmed, len = path.length; i < len; i++) {
|
15143 | var node = path[i];
|
15144 | var currentLeaf = [node.id, node.opts, []];
|
15145 | if (leaf) {
|
15146 | leaf[2].push(currentLeaf);
|
15147 | leaf = currentLeaf;
|
15148 | } else {
|
15149 | root = leaf = currentLeaf;
|
15150 | }
|
15151 | }
|
15152 | return root;
|
15153 | }
|
15154 |
|
15155 |
|
15156 | function compareTree(a, b) {
|
15157 | return a[0] < b[0] ? -1 : 1;
|
15158 | }
|
15159 |
|
15160 |
|
15161 |
|
15162 | function mergeTree(in_tree1, in_tree2) {
|
15163 | var queue = [{tree1: in_tree1, tree2: in_tree2}];
|
15164 | var conflicts = false;
|
15165 | while (queue.length > 0) {
|
15166 | var item = queue.pop();
|
15167 | var tree1 = item.tree1;
|
15168 | var tree2 = item.tree2;
|
15169 |
|
15170 | if (tree1[1].status || tree2[1].status) {
|
15171 | tree1[1].status =
|
15172 | (tree1[1].status === 'available' ||
|
15173 | tree2[1].status === 'available') ? 'available' : 'missing';
|
15174 | }
|
15175 |
|
15176 | for (var i = 0; i < tree2[2].length; i++) {
|
15177 | if (!tree1[2][0]) {
|
15178 | conflicts = 'new_leaf';
|
15179 | tree1[2][0] = tree2[2][i];
|
15180 | continue;
|
15181 | }
|
15182 |
|
15183 | var merged = false;
|
15184 | for (var j = 0; j < tree1[2].length; j++) {
|
15185 | if (tree1[2][j][0] === tree2[2][i][0]) {
|
15186 | queue.push({tree1: tree1[2][j], tree2: tree2[2][i]});
|
15187 | merged = true;
|
15188 | }
|
15189 | }
|
15190 | if (!merged) {
|
15191 | conflicts = 'new_branch';
|
15192 | insertSorted(tree1[2], tree2[2][i], compareTree);
|
15193 | }
|
15194 | }
|
15195 | }
|
15196 | return {conflicts: conflicts, tree: in_tree1};
|
15197 | }
|
15198 |
|
15199 | function doMerge(tree, path, dontExpand) {
|
15200 | var restree = [];
|
15201 | var conflicts = false;
|
15202 | var merged = false;
|
15203 | var res;
|
15204 |
|
15205 | if (!tree.length) {
|
15206 | return {tree: [path], conflicts: 'new_leaf'};
|
15207 | }
|
15208 |
|
15209 | for (var i = 0, len = tree.length; i < len; i++) {
|
15210 | var branch = tree[i];
|
15211 | if (branch.pos === path.pos && branch.ids[0] === path.ids[0]) {
|
15212 |
|
15213 |
|
15214 | res = mergeTree(branch.ids, path.ids);
|
15215 | restree.push({pos: branch.pos, ids: res.tree});
|
15216 | conflicts = conflicts || res.conflicts;
|
15217 | merged = true;
|
15218 | } else if (dontExpand !== true) {
|
15219 |
|
15220 |
|
15221 |
|
15222 |
|
15223 |
|
15224 | var t1 = branch.pos < path.pos ? branch : path;
|
15225 | var t2 = branch.pos < path.pos ? path : branch;
|
15226 | var diff = t2.pos - t1.pos;
|
15227 |
|
15228 | var candidateParents = [];
|
15229 |
|
15230 | var trees = [];
|
15231 | trees.push({ids: t1.ids, diff: diff, parent: null, parentIdx: null});
|
15232 | while (trees.length > 0) {
|
15233 | var item = trees.pop();
|
15234 | if (item.diff === 0) {
|
15235 | if (item.ids[0] === t2.ids[0]) {
|
15236 | candidateParents.push(item);
|
15237 | }
|
15238 | continue;
|
15239 | }
|
15240 | var elements = item.ids[2];
|
15241 | for (var j = 0, elementsLen = elements.length; j < elementsLen; j++) {
|
15242 | trees.push({
|
15243 | ids: elements[j],
|
15244 | diff: item.diff - 1,
|
15245 | parent: item.ids,
|
15246 | parentIdx: j
|
15247 | });
|
15248 | }
|
15249 | }
|
15250 |
|
15251 | var el = candidateParents[0];
|
15252 |
|
15253 | if (!el) {
|
15254 | restree.push(branch);
|
15255 | } else {
|
15256 | res = mergeTree(el.ids, t2.ids);
|
15257 | el.parent[2][el.parentIdx] = res.tree;
|
15258 | restree.push({pos: t1.pos, ids: t1.ids});
|
15259 | conflicts = conflicts || res.conflicts;
|
15260 | merged = true;
|
15261 | }
|
15262 | } else {
|
15263 | restree.push(branch);
|
15264 | }
|
15265 | }
|
15266 |
|
15267 |
|
15268 | if (!merged) {
|
15269 | restree.push(path);
|
15270 | }
|
15271 |
|
15272 | restree.sort(sortByPos$1);
|
15273 |
|
15274 | return {
|
15275 | tree: restree,
|
15276 | conflicts: conflicts || 'internal_node'
|
15277 | };
|
15278 | }
|
15279 |
|
15280 |
|
15281 | function stem(tree, depth) {
|
15282 |
|
15283 | var paths = rootToLeaf(tree);
|
15284 | var stemmedRevs;
|
15285 |
|
15286 | var result;
|
15287 | for (var i = 0, len = paths.length; i < len; i++) {
|
15288 |
|
15289 |
|
15290 | var path = paths[i];
|
15291 | var stemmed = path.ids;
|
15292 | var node;
|
15293 | if (stemmed.length > depth) {
|
15294 |
|
15295 | if (!stemmedRevs) {
|
15296 | stemmedRevs = {};
|
15297 | }
|
15298 | var numStemmed = stemmed.length - depth;
|
15299 | node = {
|
15300 | pos: path.pos + numStemmed,
|
15301 | ids: pathToTree(stemmed, numStemmed)
|
15302 | };
|
15303 |
|
15304 | for (var s = 0; s < numStemmed; s++) {
|
15305 | var rev = (path.pos + s) + '-' + stemmed[s].id;
|
15306 | stemmedRevs[rev] = true;
|
15307 | }
|
15308 | } else {
|
15309 | node = {
|
15310 | pos: path.pos,
|
15311 | ids: pathToTree(stemmed, 0)
|
15312 | };
|
15313 | }
|
15314 |
|
15315 |
|
15316 |
|
15317 | if (result) {
|
15318 | result = doMerge(result, node, true).tree;
|
15319 | } else {
|
15320 | result = [node];
|
15321 | }
|
15322 | }
|
15323 |
|
15324 |
|
15325 | if (stemmedRevs) {
|
15326 | traverseRevTree(result, function (isLeaf, pos, revHash) {
|
15327 |
|
15328 | delete stemmedRevs[pos + '-' + revHash];
|
15329 | });
|
15330 | }
|
15331 |
|
15332 | return {
|
15333 | tree: result,
|
15334 | revs: stemmedRevs ? Object.keys(stemmedRevs) : []
|
15335 | };
|
15336 | }
|
15337 |
|
15338 | function merge(tree, path, depth) {
|
15339 | var newTree = doMerge(tree, path);
|
15340 | var stemmed = stem(newTree.tree, depth);
|
15341 | return {
|
15342 | tree: stemmed.tree,
|
15343 | stemmedRevs: stemmed.revs,
|
15344 | conflicts: newTree.conflicts
|
15345 | };
|
15346 | }
|
15347 |
|
15348 |
|
15349 | function revExists(revs, rev) {
|
15350 | var toVisit = revs.slice();
|
15351 | var splitRev = rev.split('-');
|
15352 | var targetPos = parseInt(splitRev[0], 10);
|
15353 | var targetId = splitRev[1];
|
15354 |
|
15355 | var node;
|
15356 | while ((node = toVisit.pop())) {
|
15357 | if (node.pos === targetPos && node.ids[0] === targetId) {
|
15358 | return true;
|
15359 | }
|
15360 | var branches = node.ids[2];
|
15361 | for (var i = 0, len = branches.length; i < len; i++) {
|
15362 | toVisit.push({pos: node.pos + 1, ids: branches[i]});
|
15363 | }
|
15364 | }
|
15365 | return false;
|
15366 | }
|
15367 |
|
15368 | function getTrees(node) {
|
15369 | return node.ids;
|
15370 | }
|
15371 |
|
15372 |
|
15373 |
|
15374 |
|
15375 | function isDeleted(metadata, rev) {
|
15376 | if (!rev) {
|
15377 | rev = winningRev(metadata);
|
15378 | }
|
15379 | var id = rev.substring(rev.indexOf('-') + 1);
|
15380 | var toVisit = metadata.rev_tree.map(getTrees);
|
15381 |
|
15382 | var tree;
|
15383 | while ((tree = toVisit.pop())) {
|
15384 | if (tree[0] === id) {
|
15385 | return !!tree[1].deleted;
|
15386 | }
|
15387 | toVisit = toVisit.concat(tree[2]);
|
15388 | }
|
15389 | }
|
15390 |
|
15391 | function isLocalId(id) {
|
15392 | return (/^_local/).test(id);
|
15393 | }
|
15394 |
|
15395 |
|
15396 | function latest(rev, metadata) {
|
15397 | var toVisit = metadata.rev_tree.slice();
|
15398 | var node;
|
15399 | while ((node = toVisit.pop())) {
|
15400 | var pos = node.pos;
|
15401 | var tree = node.ids;
|
15402 | var id = tree[0];
|
15403 | var opts = tree[1];
|
15404 | var branches = tree[2];
|
15405 | var isLeaf = branches.length === 0;
|
15406 |
|
15407 | var history = node.history ? node.history.slice() : [];
|
15408 | history.push({id: id, pos: pos, opts: opts});
|
15409 |
|
15410 | if (isLeaf) {
|
15411 | for (var i = 0, len = history.length; i < len; i++) {
|
15412 | var historyNode = history[i];
|
15413 | var historyRev = historyNode.pos + '-' + historyNode.id;
|
15414 |
|
15415 | if (historyRev === rev) {
|
15416 |
|
15417 | return pos + '-' + id;
|
15418 | }
|
15419 | }
|
15420 | }
|
15421 |
|
15422 | for (var j = 0, l = branches.length; j < l; j++) {
|
15423 | toVisit.push({pos: pos + 1, ids: branches[j], history: history});
|
15424 | }
|
15425 | }
|
15426 |
|
15427 |
|
15428 | throw new Error('Unable to resolve latest revision for id ' + metadata.id + ', rev ' + rev);
|
15429 | }
|
15430 |
|
15431 | function updateDoc(revLimit, prev, docInfo, results,
|
15432 | i, cb, writeDoc, newEdits) {
|
15433 |
|
15434 | if (revExists(prev.rev_tree, docInfo.metadata.rev) && !newEdits) {
|
15435 | results[i] = docInfo;
|
15436 | return cb();
|
15437 | }
|
15438 |
|
15439 |
|
15440 | var previousWinningRev = prev.winningRev || winningRev(prev);
|
15441 | var previouslyDeleted = 'deleted' in prev ? prev.deleted :
|
15442 | isDeleted(prev, previousWinningRev);
|
15443 | var deleted = 'deleted' in docInfo.metadata ? docInfo.metadata.deleted :
|
15444 | isDeleted(docInfo.metadata);
|
15445 | var isRoot = /^1-/.test(docInfo.metadata.rev);
|
15446 |
|
15447 | if (previouslyDeleted && !deleted && newEdits && isRoot) {
|
15448 | var newDoc = docInfo.data;
|
15449 | newDoc._rev = previousWinningRev;
|
15450 | newDoc._id = docInfo.metadata.id;
|
15451 | docInfo = parseDoc(newDoc, newEdits);
|
15452 | }
|
15453 |
|
15454 | var merged = merge(prev.rev_tree, docInfo.metadata.rev_tree[0], revLimit);
|
15455 |
|
15456 | var inConflict = newEdits && ((
|
15457 | (previouslyDeleted && deleted && merged.conflicts !== 'new_leaf') ||
|
15458 | (!previouslyDeleted && merged.conflicts !== 'new_leaf') ||
|
15459 | (previouslyDeleted && !deleted && merged.conflicts === 'new_branch')));
|
15460 |
|
15461 | if (inConflict) {
|
15462 | var err = createError(REV_CONFLICT);
|
15463 | results[i] = err;
|
15464 | return cb();
|
15465 | }
|
15466 |
|
15467 | var newRev = docInfo.metadata.rev;
|
15468 | docInfo.metadata.rev_tree = merged.tree;
|
15469 | docInfo.stemmedRevs = merged.stemmedRevs || [];
|
15470 |
|
15471 | if (prev.rev_map) {
|
15472 | docInfo.metadata.rev_map = prev.rev_map;
|
15473 | }
|
15474 |
|
15475 |
|
15476 | var winningRev$$1 = winningRev(docInfo.metadata);
|
15477 | var winningRevIsDeleted = isDeleted(docInfo.metadata, winningRev$$1);
|
15478 |
|
15479 |
|
15480 |
|
15481 | var delta = (previouslyDeleted === winningRevIsDeleted) ? 0 :
|
15482 | previouslyDeleted < winningRevIsDeleted ? -1 : 1;
|
15483 |
|
15484 | var newRevIsDeleted;
|
15485 | if (newRev === winningRev$$1) {
|
15486 |
|
15487 | newRevIsDeleted = winningRevIsDeleted;
|
15488 | } else {
|
15489 |
|
15490 | newRevIsDeleted = isDeleted(docInfo.metadata, newRev);
|
15491 | }
|
15492 |
|
15493 | writeDoc(docInfo, winningRev$$1, winningRevIsDeleted, newRevIsDeleted,
|
15494 | true, delta, i, cb);
|
15495 | }
|
15496 |
|
15497 | function rootIsMissing(docInfo) {
|
15498 | return docInfo.metadata.rev_tree[0].ids[1].status === 'missing';
|
15499 | }
|
15500 |
|
15501 | function processDocs(revLimit, docInfos, api, fetchedDocs, tx, results,
|
15502 | writeDoc, opts, overallCallback) {
|
15503 |
|
15504 |
|
15505 | revLimit = revLimit || 1000;
|
15506 |
|
15507 | function insertDoc(docInfo, resultsIdx, callback) {
|
15508 |
|
15509 | var winningRev$$1 = winningRev(docInfo.metadata);
|
15510 | var deleted = isDeleted(docInfo.metadata, winningRev$$1);
|
15511 | if ('was_delete' in opts && deleted) {
|
15512 | results[resultsIdx] = createError(MISSING_DOC, 'deleted');
|
15513 | return callback();
|
15514 | }
|
15515 |
|
15516 |
|
15517 | var inConflict = newEdits && rootIsMissing(docInfo);
|
15518 |
|
15519 | if (inConflict) {
|
15520 | var err = createError(REV_CONFLICT);
|
15521 | results[resultsIdx] = err;
|
15522 | return callback();
|
15523 | }
|
15524 |
|
15525 | var delta = deleted ? 0 : 1;
|
15526 |
|
15527 | writeDoc(docInfo, winningRev$$1, deleted, deleted, false,
|
15528 | delta, resultsIdx, callback);
|
15529 | }
|
15530 |
|
15531 | var newEdits = opts.new_edits;
|
15532 | var idsToDocs = new ExportedMap();
|
15533 |
|
15534 | var docsDone = 0;
|
15535 | var docsToDo = docInfos.length;
|
15536 |
|
15537 | function checkAllDocsDone() {
|
15538 | if (++docsDone === docsToDo && overallCallback) {
|
15539 | overallCallback();
|
15540 | }
|
15541 | }
|
15542 |
|
15543 | docInfos.forEach(function (currentDoc, resultsIdx) {
|
15544 |
|
15545 | if (currentDoc._id && isLocalId(currentDoc._id)) {
|
15546 | var fun = currentDoc._deleted ? '_removeLocal' : '_putLocal';
|
15547 | api[fun](currentDoc, {ctx: tx}, function (err, res) {
|
15548 | results[resultsIdx] = err || res;
|
15549 | checkAllDocsDone();
|
15550 | });
|
15551 | return;
|
15552 | }
|
15553 |
|
15554 | var id = currentDoc.metadata.id;
|
15555 | if (idsToDocs.has(id)) {
|
15556 | docsToDo--;
|
15557 | idsToDocs.get(id).push([currentDoc, resultsIdx]);
|
15558 | } else {
|
15559 | idsToDocs.set(id, [[currentDoc, resultsIdx]]);
|
15560 | }
|
15561 | });
|
15562 |
|
15563 |
|
15564 |
|
15565 | idsToDocs.forEach(function (docs, id) {
|
15566 | var numDone = 0;
|
15567 |
|
15568 | function docWritten() {
|
15569 | if (++numDone < docs.length) {
|
15570 | nextDoc();
|
15571 | } else {
|
15572 | checkAllDocsDone();
|
15573 | }
|
15574 | }
|
15575 | function nextDoc() {
|
15576 | var value = docs[numDone];
|
15577 | var currentDoc = value[0];
|
15578 | var resultsIdx = value[1];
|
15579 |
|
15580 | if (fetchedDocs.has(id)) {
|
15581 | updateDoc(revLimit, fetchedDocs.get(id), currentDoc, results,
|
15582 | resultsIdx, docWritten, writeDoc, newEdits);
|
15583 | } else {
|
15584 |
|
15585 | var merged = merge([], currentDoc.metadata.rev_tree[0], revLimit);
|
15586 | currentDoc.metadata.rev_tree = merged.tree;
|
15587 | currentDoc.stemmedRevs = merged.stemmedRevs || [];
|
15588 | insertDoc(currentDoc, resultsIdx, docWritten);
|
15589 | }
|
15590 | }
|
15591 | nextDoc();
|
15592 | });
|
15593 | }
|
15594 |
|
15595 | function safeJsonParse(str) {
|
15596 |
|
15597 |
|
15598 |
|
15599 | try {
|
15600 | return JSON.parse(str);
|
15601 | } catch (e) {
|
15602 |
|
15603 | return vuvuzela.parse(str);
|
15604 | }
|
15605 | }
|
15606 |
|
15607 | function safeJsonStringify(json) {
|
15608 | try {
|
15609 | return JSON.stringify(json);
|
15610 | } catch (e) {
|
15611 |
|
15612 | return vuvuzela.stringify(json);
|
15613 | }
|
15614 | }
|
15615 |
|
15616 | function readAsBlobOrBuffer(storedObject, type) {
|
15617 |
|
15618 |
|
15619 |
|
15620 | var byteArray = new Uint8Array(storedObject);
|
15621 | return createBlob([byteArray], {type: type});
|
15622 | }
|
15623 |
|
15624 |
|
15625 | function prepareAttachmentForStorage(attData, cb) {
|
15626 | readAsBinaryString(attData, cb);
|
15627 | }
|
15628 |
|
15629 | function createEmptyBlobOrBuffer(type) {
|
15630 | return createBlob([''], {type: type});
|
15631 | }
|
15632 |
|
15633 | function getCacheFor(transaction, store) {
|
15634 | var prefix = store.prefix()[0];
|
15635 | var cache = transaction._cache;
|
15636 | var subCache = cache.get(prefix);
|
15637 | if (!subCache) {
|
15638 | subCache = new ExportedMap();
|
15639 | cache.set(prefix, subCache);
|
15640 | }
|
15641 | return subCache;
|
15642 | }
|
15643 |
|
15644 | function LevelTransaction() {
|
15645 | this._batch = [];
|
15646 | this._cache = new ExportedMap();
|
15647 | }
|
15648 |
|
15649 | LevelTransaction.prototype.get = function (store, key, callback) {
|
15650 | var cache = getCacheFor(this, store);
|
15651 | var exists = cache.get(key);
|
15652 | if (exists) {
|
15653 | return nextTick(function () {
|
15654 | callback(null, exists);
|
15655 | });
|
15656 | } else if (exists === null) {
|
15657 |
|
15658 | return nextTick(function () {
|
15659 | callback({name: 'NotFoundError'});
|
15660 | });
|
15661 | }
|
15662 | store.get(key, function (err, res) {
|
15663 | if (err) {
|
15664 |
|
15665 | if (err.name === 'NotFoundError') {
|
15666 | cache.set(key, null);
|
15667 | }
|
15668 | return callback(err);
|
15669 | }
|
15670 | cache.set(key, res);
|
15671 | callback(null, res);
|
15672 | });
|
15673 | };
|
15674 |
|
15675 | LevelTransaction.prototype.batch = function (batch) {
|
15676 | for (var i = 0, len = batch.length; i < len; i++) {
|
15677 | var operation = batch[i];
|
15678 |
|
15679 | var cache = getCacheFor(this, operation.prefix);
|
15680 |
|
15681 | if (operation.type === 'put') {
|
15682 | cache.set(operation.key, operation.value);
|
15683 | } else {
|
15684 | cache.set(operation.key, null);
|
15685 | }
|
15686 | }
|
15687 | this._batch = this._batch.concat(batch);
|
15688 | };
|
15689 |
|
15690 | LevelTransaction.prototype.execute = function (db, callback) {
|
15691 |
|
15692 | var keys = new ExportedSet();
|
15693 | var uniqBatches = [];
|
15694 |
|
15695 |
|
15696 | for (var i = this._batch.length - 1; i >= 0; i--) {
|
15697 | var operation = this._batch[i];
|
15698 | var lookupKey = operation.prefix.prefix()[0] + '\xff' + operation.key;
|
15699 | if (keys.has(lookupKey)) {
|
15700 | continue;
|
15701 | }
|
15702 | keys.add(lookupKey);
|
15703 | uniqBatches.push(operation);
|
15704 | }
|
15705 |
|
15706 | db.batch(uniqBatches, callback);
|
15707 | };
|
15708 |
|
15709 | var DOC_STORE = 'document-store';
|
15710 | var BY_SEQ_STORE = 'by-sequence';
|
15711 | var ATTACHMENT_STORE = 'attach-store';
|
15712 | var BINARY_STORE = 'attach-binary-store';
|
15713 | var LOCAL_STORE = 'local-store';
|
15714 | var META_STORE = 'meta-store';
|
15715 |
|
15716 |
|
15717 |
|
15718 | var dbStores = new ExportedMap();
|
15719 |
|
15720 |
|
15721 |
|
15722 | var UPDATE_SEQ_KEY = '_local_last_update_seq';
|
15723 | var DOC_COUNT_KEY = '_local_doc_count';
|
15724 | var UUID_KEY = '_local_uuid';
|
15725 |
|
15726 | var MD5_PREFIX = 'md5-';
|
15727 |
|
15728 | var safeJsonEncoding = {
|
15729 | encode: safeJsonStringify,
|
15730 | decode: safeJsonParse,
|
15731 | buffer: false,
|
15732 | type: 'cheap-json'
|
15733 | };
|
15734 |
|
15735 | var levelChanges = new Changes();
|
15736 |
|
15737 |
|
15738 |
|
15739 | function getWinningRev(metadata) {
|
15740 | return 'winningRev' in metadata ?
|
15741 | metadata.winningRev : winningRev(metadata);
|
15742 | }
|
15743 |
|
15744 | function getIsDeleted(metadata, winningRev$$1) {
|
15745 | return 'deleted' in metadata ?
|
15746 | metadata.deleted : isDeleted(metadata, winningRev$$1);
|
15747 | }
|
15748 |
|
15749 | function fetchAttachment(att, stores, opts) {
|
15750 | var type = att.content_type;
|
15751 | return new Promise(function (resolve, reject) {
|
15752 | stores.binaryStore.get(att.digest, function (err, buffer) {
|
15753 | var data;
|
15754 | if (err) {
|
15755 |
|
15756 | if (err.name !== 'NotFoundError') {
|
15757 | return reject(err);
|
15758 | } else {
|
15759 |
|
15760 | if (!opts.binary) {
|
15761 | data = '';
|
15762 | } else {
|
15763 | data = binStringToBluffer('', type);
|
15764 | }
|
15765 | }
|
15766 | } else {
|
15767 | if (opts.binary) {
|
15768 | data = readAsBlobOrBuffer(buffer, type);
|
15769 | } else {
|
15770 | data = buffer.toString('base64');
|
15771 | }
|
15772 | }
|
15773 | delete att.stub;
|
15774 | delete att.length;
|
15775 | att.data = data;
|
15776 | resolve();
|
15777 | });
|
15778 | });
|
15779 | }
|
15780 |
|
15781 | function fetchAttachments(results, stores, opts) {
|
15782 | var atts = [];
|
15783 | results.forEach(function (row) {
|
15784 | if (!(row.doc && row.doc._attachments)) {
|
15785 | return;
|
15786 | }
|
15787 | var attNames = Object.keys(row.doc._attachments);
|
15788 | attNames.forEach(function (attName) {
|
15789 | var att = row.doc._attachments[attName];
|
15790 | if (!('data' in att)) {
|
15791 | atts.push(att);
|
15792 | }
|
15793 | });
|
15794 | });
|
15795 |
|
15796 | return Promise.all(atts.map(function (att) {
|
15797 | return fetchAttachment(att, stores, opts);
|
15798 | }));
|
15799 | }
|
15800 |
|
15801 | function LevelPouch(opts, callback) {
|
15802 | opts = clone(opts);
|
15803 | var api = this;
|
15804 | var instanceId;
|
15805 | var stores = {};
|
15806 | var revLimit = opts.revs_limit;
|
15807 | var db;
|
15808 | var name = opts.name;
|
15809 |
|
15810 |
|
15811 | if (typeof opts.createIfMissing === 'undefined') {
|
15812 | opts.createIfMissing = true;
|
15813 | }
|
15814 |
|
15815 | var leveldown = opts.db;
|
15816 |
|
15817 | var dbStore;
|
15818 | var leveldownName = functionName(leveldown);
|
15819 | if (dbStores.has(leveldownName)) {
|
15820 | dbStore = dbStores.get(leveldownName);
|
15821 | } else {
|
15822 | dbStore = new ExportedMap();
|
15823 | dbStores.set(leveldownName, dbStore);
|
15824 | }
|
15825 | if (dbStore.has(name)) {
|
15826 | db = dbStore.get(name);
|
15827 | afterDBCreated();
|
15828 | } else {
|
15829 | dbStore.set(name, sublevelPouch(levelup(leveldown(name), opts, function (err) {
|
15830 |
|
15831 | if (err) {
|
15832 | dbStore["delete"](name);
|
15833 | return callback(err);
|
15834 | }
|
15835 | db = dbStore.get(name);
|
15836 | db._docCount = -1;
|
15837 | db._queue = new Deque();
|
15838 |
|
15839 | if (typeof opts.migrate === 'object') {
|
15840 | opts.migrate.doMigrationOne(name, db, afterDBCreated);
|
15841 | } else {
|
15842 | afterDBCreated();
|
15843 | }
|
15844 | })));
|
15845 | }
|
15846 |
|
15847 | function afterDBCreated() {
|
15848 | stores.docStore = db.sublevel(DOC_STORE, {valueEncoding: safeJsonEncoding});
|
15849 | stores.bySeqStore = db.sublevel(BY_SEQ_STORE, {valueEncoding: 'json'});
|
15850 | stores.attachmentStore =
|
15851 | db.sublevel(ATTACHMENT_STORE, {valueEncoding: 'json'});
|
15852 | stores.binaryStore = db.sublevel(BINARY_STORE, {valueEncoding: 'binary'});
|
15853 | stores.localStore = db.sublevel(LOCAL_STORE, {valueEncoding: 'json'});
|
15854 | stores.metaStore = db.sublevel(META_STORE, {valueEncoding: 'json'});
|
15855 |
|
15856 | if (typeof opts.migrate === 'object') {
|
15857 | opts.migrate.doMigrationTwo(db, stores, afterLastMigration);
|
15858 | } else {
|
15859 | afterLastMigration();
|
15860 | }
|
15861 | }
|
15862 |
|
15863 | function afterLastMigration() {
|
15864 | stores.metaStore.get(UPDATE_SEQ_KEY, function (err, value) {
|
15865 | if (typeof db._updateSeq === 'undefined') {
|
15866 | db._updateSeq = value || 0;
|
15867 | }
|
15868 | stores.metaStore.get(DOC_COUNT_KEY, function (err, value) {
|
15869 | db._docCount = !err ? value : 0;
|
15870 | stores.metaStore.get(UUID_KEY, function (err, value) {
|
15871 | instanceId = !err ? value : uuid();
|
15872 | stores.metaStore.put(UUID_KEY, instanceId, function () {
|
15873 | nextTick(function () {
|
15874 | callback(null, api);
|
15875 | });
|
15876 | });
|
15877 | });
|
15878 | });
|
15879 | });
|
15880 | }
|
15881 |
|
15882 | function countDocs(callback) {
|
15883 |
|
15884 | if (db.isClosed()) {
|
15885 | return callback(new Error('database is closed'));
|
15886 | }
|
15887 | return callback(null, db._docCount);
|
15888 | }
|
15889 |
|
15890 | api._remote = false;
|
15891 |
|
15892 | api.type = function () {
|
15893 | return 'leveldb';
|
15894 | };
|
15895 |
|
15896 | api._id = function (callback) {
|
15897 | callback(null, instanceId);
|
15898 | };
|
15899 |
|
15900 | api._info = function (callback) {
|
15901 | var res = {
|
15902 | doc_count: db._docCount,
|
15903 | update_seq: db._updateSeq,
|
15904 | backend_adapter: functionName(leveldown)
|
15905 | };
|
15906 | return nextTick(function () {
|
15907 | callback(null, res);
|
15908 | });
|
15909 | };
|
15910 |
|
15911 | function tryCode(fun, args) {
|
15912 | try {
|
15913 | fun.apply(null, args);
|
15914 | } catch (err) {
|
15915 | args[args.length - 1](err);
|
15916 | }
|
15917 | }
|
15918 |
|
15919 | function executeNext() {
|
15920 | var firstTask = db._queue.peekFront();
|
15921 |
|
15922 | if (firstTask.type === 'read') {
|
15923 | runReadOperation(firstTask);
|
15924 | } else {
|
15925 | runWriteOperation(firstTask);
|
15926 | }
|
15927 | }
|
15928 |
|
15929 | function runReadOperation(firstTask) {
|
15930 |
|
15931 |
|
15932 | var readTasks = [firstTask];
|
15933 | var i = 1;
|
15934 | var nextTask = db._queue.get(i);
|
15935 | while (typeof nextTask !== 'undefined' && nextTask.type === 'read') {
|
15936 | readTasks.push(nextTask);
|
15937 | i++;
|
15938 | nextTask = db._queue.get(i);
|
15939 | }
|
15940 |
|
15941 | var numDone = 0;
|
15942 |
|
15943 | readTasks.forEach(function (readTask) {
|
15944 | var args = readTask.args;
|
15945 | var callback = args[args.length - 1];
|
15946 | args[args.length - 1] = getArguments(function (cbArgs) {
|
15947 | callback.apply(null, cbArgs);
|
15948 | if (++numDone === readTasks.length) {
|
15949 | nextTick(function () {
|
15950 |
|
15951 | readTasks.forEach(function () {
|
15952 | db._queue.shift();
|
15953 | });
|
15954 | if (db._queue.length) {
|
15955 | executeNext();
|
15956 | }
|
15957 | });
|
15958 | }
|
15959 | });
|
15960 | tryCode(readTask.fun, args);
|
15961 | });
|
15962 | }
|
15963 |
|
15964 | function runWriteOperation(firstTask) {
|
15965 | var args = firstTask.args;
|
15966 | var callback = args[args.length - 1];
|
15967 | args[args.length - 1] = getArguments(function (cbArgs) {
|
15968 | callback.apply(null, cbArgs);
|
15969 | nextTick(function () {
|
15970 | db._queue.shift();
|
15971 | if (db._queue.length) {
|
15972 | executeNext();
|
15973 | }
|
15974 | });
|
15975 | });
|
15976 | tryCode(firstTask.fun, args);
|
15977 | }
|
15978 |
|
15979 |
|
15980 |
|
15981 |
|
15982 |
|
15983 | function writeLock(fun) {
|
15984 | return getArguments(function (args) {
|
15985 | db._queue.push({
|
15986 | fun: fun,
|
15987 | args: args,
|
15988 | type: 'write'
|
15989 | });
|
15990 |
|
15991 | if (db._queue.length === 1) {
|
15992 | nextTick(executeNext);
|
15993 | }
|
15994 | });
|
15995 | }
|
15996 |
|
15997 |
|
15998 | function readLock(fun) {
|
15999 | return getArguments(function (args) {
|
16000 | db._queue.push({
|
16001 | fun: fun,
|
16002 | args: args,
|
16003 | type: 'read'
|
16004 | });
|
16005 |
|
16006 | if (db._queue.length === 1) {
|
16007 | nextTick(executeNext);
|
16008 | }
|
16009 | });
|
16010 | }
|
16011 |
|
16012 | function formatSeq(n) {
|
16013 | return ('0000000000000000' + n).slice(-16);
|
16014 | }
|
16015 |
|
16016 | function parseSeq(s) {
|
16017 | return parseInt(s, 10);
|
16018 | }
|
16019 |
|
16020 | api._get = readLock(function (id, opts, callback) {
|
16021 | opts = clone(opts);
|
16022 |
|
16023 | stores.docStore.get(id, function (err, metadata) {
|
16024 |
|
16025 | if (err || !metadata) {
|
16026 | return callback(createError(MISSING_DOC, 'missing'));
|
16027 | }
|
16028 |
|
16029 | var rev;
|
16030 | if (!opts.rev) {
|
16031 | rev = getWinningRev(metadata);
|
16032 | var deleted = getIsDeleted(metadata, rev);
|
16033 | if (deleted) {
|
16034 | return callback(createError(MISSING_DOC, "deleted"));
|
16035 | }
|
16036 | } else {
|
16037 | rev = opts.latest ? latest(opts.rev, metadata) : opts.rev;
|
16038 | }
|
16039 |
|
16040 | var seq = metadata.rev_map[rev];
|
16041 |
|
16042 | stores.bySeqStore.get(formatSeq(seq), function (err, doc) {
|
16043 | if (!doc) {
|
16044 | return callback(createError(MISSING_DOC));
|
16045 | }
|
16046 |
|
16047 | if ('_id' in doc && doc._id !== metadata.id) {
|
16048 |
|
16049 | return callback(new Error('wrong doc returned'));
|
16050 | }
|
16051 | doc._id = metadata.id;
|
16052 | if ('_rev' in doc) {
|
16053 |
|
16054 | if (doc._rev !== rev) {
|
16055 |
|
16056 | return callback(new Error('wrong doc returned'));
|
16057 | }
|
16058 | } else {
|
16059 |
|
16060 | doc._rev = rev;
|
16061 | }
|
16062 | return callback(null, {doc: doc, metadata: metadata});
|
16063 | });
|
16064 | });
|
16065 | });
|
16066 |
|
16067 |
|
16068 |
|
16069 | api._getAttachment = function (docId, attachId, attachment, opts, callback) {
|
16070 | var digest = attachment.digest;
|
16071 | var type = attachment.content_type;
|
16072 |
|
16073 | stores.binaryStore.get(digest, function (err, attach) {
|
16074 | if (err) {
|
16075 |
|
16076 | if (err.name !== 'NotFoundError') {
|
16077 | return callback(err);
|
16078 | }
|
16079 |
|
16080 | return callback(null, opts.binary ? createEmptyBlobOrBuffer(type) : '');
|
16081 | }
|
16082 |
|
16083 | if (opts.binary) {
|
16084 | callback(null, readAsBlobOrBuffer(attach, type));
|
16085 | } else {
|
16086 | callback(null, attach.toString('base64'));
|
16087 | }
|
16088 | });
|
16089 | };
|
16090 |
|
16091 | api._bulkDocs = writeLock(function (req, opts, callback) {
|
16092 | var newEdits = opts.new_edits;
|
16093 | var results = new Array(req.docs.length);
|
16094 | var fetchedDocs = new ExportedMap();
|
16095 | var stemmedRevs = new ExportedMap();
|
16096 |
|
16097 | var txn = new LevelTransaction();
|
16098 | var docCountDelta = 0;
|
16099 | var newUpdateSeq = db._updateSeq;
|
16100 |
|
16101 |
|
16102 | var userDocs = req.docs;
|
16103 | var docInfos = userDocs.map(function (doc) {
|
16104 | if (doc._id && isLocalId(doc._id)) {
|
16105 | return doc;
|
16106 | }
|
16107 | var newDoc = parseDoc(doc, newEdits, api.__opts);
|
16108 |
|
16109 | if (newDoc.metadata && !newDoc.metadata.rev_map) {
|
16110 | newDoc.metadata.rev_map = {};
|
16111 | }
|
16112 |
|
16113 | return newDoc;
|
16114 | });
|
16115 | var infoErrors = docInfos.filter(function (doc) {
|
16116 | return doc.error;
|
16117 | });
|
16118 |
|
16119 | if (infoErrors.length) {
|
16120 | return callback(infoErrors[0]);
|
16121 | }
|
16122 |
|
16123 |
|
16124 |
|
16125 | function verifyAttachment(digest, callback) {
|
16126 | txn.get(stores.attachmentStore, digest, function (levelErr) {
|
16127 | if (levelErr) {
|
16128 | var err = createError(MISSING_STUB,
|
16129 | 'unknown stub attachment with digest ' +
|
16130 | digest);
|
16131 | callback(err);
|
16132 | } else {
|
16133 | callback();
|
16134 | }
|
16135 | });
|
16136 | }
|
16137 |
|
16138 | function verifyAttachments(finish) {
|
16139 | var digests = [];
|
16140 | userDocs.forEach(function (doc) {
|
16141 | if (doc && doc._attachments) {
|
16142 | Object.keys(doc._attachments).forEach(function (filename) {
|
16143 | var att = doc._attachments[filename];
|
16144 | if (att.stub) {
|
16145 | digests.push(att.digest);
|
16146 | }
|
16147 | });
|
16148 | }
|
16149 | });
|
16150 | if (!digests.length) {
|
16151 | return finish();
|
16152 | }
|
16153 | var numDone = 0;
|
16154 | var err;
|
16155 |
|
16156 | digests.forEach(function (digest) {
|
16157 | verifyAttachment(digest, function (attErr) {
|
16158 | if (attErr && !err) {
|
16159 | err = attErr;
|
16160 | }
|
16161 |
|
16162 | if (++numDone === digests.length) {
|
16163 | finish(err);
|
16164 | }
|
16165 | });
|
16166 | });
|
16167 | }
|
16168 |
|
16169 | function fetchExistingDocs(finish) {
|
16170 | var numDone = 0;
|
16171 | var overallErr;
|
16172 | function checkDone() {
|
16173 | if (++numDone === userDocs.length) {
|
16174 | return finish(overallErr);
|
16175 | }
|
16176 | }
|
16177 |
|
16178 | userDocs.forEach(function (doc) {
|
16179 | if (doc._id && isLocalId(doc._id)) {
|
16180 |
|
16181 | return checkDone();
|
16182 | }
|
16183 | txn.get(stores.docStore, doc._id, function (err, info) {
|
16184 | if (err) {
|
16185 |
|
16186 | if (err.name !== 'NotFoundError') {
|
16187 | overallErr = err;
|
16188 | }
|
16189 | } else {
|
16190 | fetchedDocs.set(doc._id, info);
|
16191 | }
|
16192 | checkDone();
|
16193 | });
|
16194 | });
|
16195 | }
|
16196 |
|
16197 | function compact(revsMap, callback) {
|
16198 | var promise = Promise.resolve();
|
16199 | revsMap.forEach(function (revs, docId) {
|
16200 |
|
16201 |
|
16202 | promise = promise.then(function () {
|
16203 | return new Promise(function (resolve, reject) {
|
16204 | api._doCompactionNoLock(docId, revs, {ctx: txn}, function (err) {
|
16205 |
|
16206 | if (err) {
|
16207 | return reject(err);
|
16208 | }
|
16209 | resolve();
|
16210 | });
|
16211 | });
|
16212 | });
|
16213 | });
|
16214 |
|
16215 | promise.then(function () {
|
16216 | callback();
|
16217 | }, callback);
|
16218 | }
|
16219 |
|
16220 | function autoCompact(callback) {
|
16221 | var revsMap = new ExportedMap();
|
16222 | fetchedDocs.forEach(function (metadata, docId) {
|
16223 | revsMap.set(docId, compactTree(metadata));
|
16224 | });
|
16225 | compact(revsMap, callback);
|
16226 | }
|
16227 |
|
16228 | function finish() {
|
16229 | compact(stemmedRevs, function (error) {
|
16230 |
|
16231 | if (error) {
|
16232 | complete(error);
|
16233 | }
|
16234 | if (api.auto_compaction) {
|
16235 | return autoCompact(complete);
|
16236 | }
|
16237 | complete();
|
16238 | });
|
16239 | }
|
16240 |
|
16241 | function writeDoc(docInfo, winningRev$$1, winningRevIsDeleted, newRevIsDeleted,
|
16242 | isUpdate, delta, resultsIdx, callback2) {
|
16243 | docCountDelta += delta;
|
16244 |
|
16245 | var err = null;
|
16246 | var recv = 0;
|
16247 |
|
16248 | docInfo.metadata.winningRev = winningRev$$1;
|
16249 | docInfo.metadata.deleted = winningRevIsDeleted;
|
16250 |
|
16251 | docInfo.data._id = docInfo.metadata.id;
|
16252 | docInfo.data._rev = docInfo.metadata.rev;
|
16253 |
|
16254 | if (newRevIsDeleted) {
|
16255 | docInfo.data._deleted = true;
|
16256 | }
|
16257 |
|
16258 | if (docInfo.stemmedRevs.length) {
|
16259 | stemmedRevs.set(docInfo.metadata.id, docInfo.stemmedRevs);
|
16260 | }
|
16261 |
|
16262 | var attachments = docInfo.data._attachments ?
|
16263 | Object.keys(docInfo.data._attachments) :
|
16264 | [];
|
16265 |
|
16266 | function attachmentSaved(attachmentErr) {
|
16267 | recv++;
|
16268 | if (!err) {
|
16269 |
|
16270 | if (attachmentErr) {
|
16271 | err = attachmentErr;
|
16272 | callback2(err);
|
16273 | } else if (recv === attachments.length) {
|
16274 | finish();
|
16275 | }
|
16276 | }
|
16277 | }
|
16278 |
|
16279 | function onMD5Load(doc, key, data, attachmentSaved) {
|
16280 | return function (result) {
|
16281 | saveAttachment(doc, MD5_PREFIX + result, key, data, attachmentSaved);
|
16282 | };
|
16283 | }
|
16284 |
|
16285 | function doMD5(doc, key, attachmentSaved) {
|
16286 | return function (data) {
|
16287 | binaryMd5(data, onMD5Load(doc, key, data, attachmentSaved));
|
16288 | };
|
16289 | }
|
16290 |
|
16291 | for (var i = 0; i < attachments.length; i++) {
|
16292 | var key = attachments[i];
|
16293 | var att = docInfo.data._attachments[key];
|
16294 |
|
16295 | if (att.stub) {
|
16296 |
|
16297 | var id = docInfo.data._id;
|
16298 | var rev = docInfo.data._rev;
|
16299 | saveAttachmentRefs(id, rev, att.digest, attachmentSaved);
|
16300 | continue;
|
16301 | }
|
16302 | var data;
|
16303 | if (typeof att.data === 'string') {
|
16304 |
|
16305 | try {
|
16306 | data = thisAtob(att.data);
|
16307 | } catch (e) {
|
16308 | callback(createError(BAD_ARG,
|
16309 | 'Attachment is not a valid base64 string'));
|
16310 | return;
|
16311 | }
|
16312 | doMD5(docInfo, key, attachmentSaved)(data);
|
16313 | } else {
|
16314 | prepareAttachmentForStorage(att.data,
|
16315 | doMD5(docInfo, key, attachmentSaved));
|
16316 | }
|
16317 | }
|
16318 |
|
16319 | function finish() {
|
16320 | var seq = docInfo.metadata.rev_map[docInfo.metadata.rev];
|
16321 |
|
16322 | if (seq) {
|
16323 |
|
16324 |
|
16325 | return callback2();
|
16326 | }
|
16327 | seq = ++newUpdateSeq;
|
16328 | docInfo.metadata.rev_map[docInfo.metadata.rev] =
|
16329 | docInfo.metadata.seq = seq;
|
16330 | var seqKey = formatSeq(seq);
|
16331 | var batch = [{
|
16332 | key: seqKey,
|
16333 | value: docInfo.data,
|
16334 | prefix: stores.bySeqStore,
|
16335 | type: 'put'
|
16336 | }, {
|
16337 | key: docInfo.metadata.id,
|
16338 | value: docInfo.metadata,
|
16339 | prefix: stores.docStore,
|
16340 | type: 'put'
|
16341 | }];
|
16342 | txn.batch(batch);
|
16343 | results[resultsIdx] = {
|
16344 | ok: true,
|
16345 | id: docInfo.metadata.id,
|
16346 | rev: docInfo.metadata.rev
|
16347 | };
|
16348 | fetchedDocs.set(docInfo.metadata.id, docInfo.metadata);
|
16349 | callback2();
|
16350 | }
|
16351 |
|
16352 | if (!attachments.length) {
|
16353 | finish();
|
16354 | }
|
16355 | }
|
16356 |
|
16357 |
|
16358 |
|
16359 | var attachmentQueues = {};
|
16360 |
|
16361 | function saveAttachmentRefs(id, rev, digest, callback) {
|
16362 |
|
16363 | function fetchAtt() {
|
16364 | return new Promise(function (resolve, reject) {
|
16365 | txn.get(stores.attachmentStore, digest, function (err, oldAtt) {
|
16366 |
|
16367 | if (err && err.name !== 'NotFoundError') {
|
16368 | return reject(err);
|
16369 | }
|
16370 | resolve(oldAtt);
|
16371 | });
|
16372 | });
|
16373 | }
|
16374 |
|
16375 | function saveAtt(oldAtt) {
|
16376 | var ref = [id, rev].join('@');
|
16377 | var newAtt = {};
|
16378 |
|
16379 | if (oldAtt) {
|
16380 | if (oldAtt.refs) {
|
16381 |
|
16382 |
|
16383 |
|
16384 | newAtt.refs = oldAtt.refs;
|
16385 | newAtt.refs[ref] = true;
|
16386 | }
|
16387 | } else {
|
16388 | newAtt.refs = {};
|
16389 | newAtt.refs[ref] = true;
|
16390 | }
|
16391 |
|
16392 | return new Promise(function (resolve) {
|
16393 | txn.batch([{
|
16394 | type: 'put',
|
16395 | prefix: stores.attachmentStore,
|
16396 | key: digest,
|
16397 | value: newAtt
|
16398 | }]);
|
16399 | resolve(!oldAtt);
|
16400 | });
|
16401 | }
|
16402 |
|
16403 |
|
16404 |
|
16405 | var queue = attachmentQueues[digest] || Promise.resolve();
|
16406 | attachmentQueues[digest] = queue.then(function () {
|
16407 | return fetchAtt().then(saveAtt).then(function (isNewAttachment) {
|
16408 | callback(null, isNewAttachment);
|
16409 | }, callback);
|
16410 | });
|
16411 | }
|
16412 |
|
16413 | function saveAttachment(docInfo, digest, key, data, callback) {
|
16414 | var att = docInfo.data._attachments[key];
|
16415 | delete att.data;
|
16416 | att.digest = digest;
|
16417 | att.length = data.length;
|
16418 | var id = docInfo.metadata.id;
|
16419 | var rev = docInfo.metadata.rev;
|
16420 | att.revpos = parseInt(rev, 10);
|
16421 |
|
16422 | saveAttachmentRefs(id, rev, digest, function (err, isNewAttachment) {
|
16423 |
|
16424 | if (err) {
|
16425 | return callback(err);
|
16426 | }
|
16427 |
|
16428 | if (data.length === 0) {
|
16429 | return callback(err);
|
16430 | }
|
16431 | if (!isNewAttachment) {
|
16432 |
|
16433 | return callback(err);
|
16434 | }
|
16435 | txn.batch([{
|
16436 | type: 'put',
|
16437 | prefix: stores.binaryStore,
|
16438 | key: digest,
|
16439 | value: bufferFrom(data, 'binary')
|
16440 | }]);
|
16441 | callback();
|
16442 | });
|
16443 | }
|
16444 |
|
16445 | function complete(err) {
|
16446 |
|
16447 | if (err) {
|
16448 | return nextTick(function () {
|
16449 | callback(err);
|
16450 | });
|
16451 | }
|
16452 | txn.batch([
|
16453 | {
|
16454 | prefix: stores.metaStore,
|
16455 | type: 'put',
|
16456 | key: UPDATE_SEQ_KEY,
|
16457 | value: newUpdateSeq
|
16458 | },
|
16459 | {
|
16460 | prefix: stores.metaStore,
|
16461 | type: 'put',
|
16462 | key: DOC_COUNT_KEY,
|
16463 | value: db._docCount + docCountDelta
|
16464 | }
|
16465 | ]);
|
16466 | txn.execute(db, function (err) {
|
16467 |
|
16468 | if (err) {
|
16469 | return callback(err);
|
16470 | }
|
16471 | db._docCount += docCountDelta;
|
16472 | db._updateSeq = newUpdateSeq;
|
16473 | levelChanges.notify(name);
|
16474 | nextTick(function () {
|
16475 | callback(null, results);
|
16476 | });
|
16477 | });
|
16478 | }
|
16479 |
|
16480 | if (!docInfos.length) {
|
16481 | return callback(null, []);
|
16482 | }
|
16483 |
|
16484 | verifyAttachments(function (err) {
|
16485 | if (err) {
|
16486 | return callback(err);
|
16487 | }
|
16488 | fetchExistingDocs(function (err) {
|
16489 |
|
16490 | if (err) {
|
16491 | return callback(err);
|
16492 | }
|
16493 | processDocs(revLimit, docInfos, api, fetchedDocs, txn, results,
|
16494 | writeDoc, opts, finish);
|
16495 | });
|
16496 | });
|
16497 | });
|
16498 | api._allDocs = function (opts, callback) {
|
16499 | if ('keys' in opts) {
|
16500 | return allDocsKeysQuery(this, opts);
|
16501 | }
|
16502 | return readLock(function (opts, callback) {
|
16503 | opts = clone(opts);
|
16504 | countDocs(function (err, docCount) {
|
16505 |
|
16506 | if (err) {
|
16507 | return callback(err);
|
16508 | }
|
16509 | var readstreamOpts = {};
|
16510 | var skip = opts.skip || 0;
|
16511 | if (opts.startkey) {
|
16512 | readstreamOpts.gte = opts.startkey;
|
16513 | }
|
16514 | if (opts.endkey) {
|
16515 | readstreamOpts.lte = opts.endkey;
|
16516 | }
|
16517 | if (opts.key) {
|
16518 | readstreamOpts.gte = readstreamOpts.lte = opts.key;
|
16519 | }
|
16520 | if (opts.descending) {
|
16521 | readstreamOpts.reverse = true;
|
16522 |
|
16523 | var tmp = readstreamOpts.lte;
|
16524 | readstreamOpts.lte = readstreamOpts.gte;
|
16525 | readstreamOpts.gte = tmp;
|
16526 | }
|
16527 | var limit;
|
16528 | if (typeof opts.limit === 'number') {
|
16529 | limit = opts.limit;
|
16530 | }
|
16531 | if (limit === 0 ||
|
16532 | ('gte' in readstreamOpts && 'lte' in readstreamOpts &&
|
16533 | readstreamOpts.gte > readstreamOpts.lte)) {
|
16534 |
|
16535 |
|
16536 |
|
16537 | var returnVal = {
|
16538 | total_rows: docCount,
|
16539 | offset: opts.skip,
|
16540 | rows: []
|
16541 | };
|
16542 |
|
16543 | if (opts.update_seq) {
|
16544 | returnVal.update_seq = db._updateSeq;
|
16545 | }
|
16546 | return callback(null, returnVal);
|
16547 | }
|
16548 | var results = [];
|
16549 | var docstream = stores.docStore.readStream(readstreamOpts);
|
16550 |
|
16551 | var throughStream = through2.obj(function (entry, _, next) {
|
16552 | var metadata = entry.value;
|
16553 |
|
16554 |
|
16555 | var winningRev$$1 = getWinningRev(metadata);
|
16556 | var deleted = getIsDeleted(metadata, winningRev$$1);
|
16557 | if (!deleted) {
|
16558 | if (skip-- > 0) {
|
16559 | next();
|
16560 | return;
|
16561 | } else if (typeof limit === 'number' && limit-- <= 0) {
|
16562 | docstream.unpipe();
|
16563 | docstream.destroy();
|
16564 | next();
|
16565 | return;
|
16566 | }
|
16567 | } else if (opts.deleted !== 'ok') {
|
16568 | next();
|
16569 | return;
|
16570 | }
|
16571 | function allDocsInner(data) {
|
16572 | var doc = {
|
16573 | id: metadata.id,
|
16574 | key: metadata.id,
|
16575 | value: {
|
16576 | rev: winningRev$$1
|
16577 | }
|
16578 | };
|
16579 | if (opts.include_docs) {
|
16580 | doc.doc = data;
|
16581 | doc.doc._rev = doc.value.rev;
|
16582 | if (opts.conflicts) {
|
16583 | var conflicts = collectConflicts(metadata);
|
16584 | if (conflicts.length) {
|
16585 | doc.doc._conflicts = conflicts;
|
16586 | }
|
16587 | }
|
16588 | for (var att in doc.doc._attachments) {
|
16589 | if (doc.doc._attachments.hasOwnProperty(att)) {
|
16590 | doc.doc._attachments[att].stub = true;
|
16591 | }
|
16592 | }
|
16593 | }
|
16594 | if (opts.inclusive_end === false && metadata.id === opts.endkey) {
|
16595 | return next();
|
16596 | } else if (deleted) {
|
16597 | if (opts.deleted === 'ok') {
|
16598 | doc.value.deleted = true;
|
16599 | doc.doc = null;
|
16600 | } else {
|
16601 | /* istanbul ignore next */
|
16602 | return next();
|
16603 | }
|
16604 | }
|
16605 | results.push(doc);
|
16606 | next();
|
16607 | }
|
16608 | if (opts.include_docs) {
|
16609 | var seq = metadata.rev_map[winningRev$$1];
|
16610 | stores.bySeqStore.get(formatSeq(seq), function (err, data) {
|
16611 | allDocsInner(data);
|
16612 | });
|
16613 | }
|
16614 | else {
|
16615 | allDocsInner();
|
16616 | }
|
16617 | }, function (next) {
|
16618 | Promise.resolve().then(function () {
|
16619 | if (opts.include_docs && opts.attachments) {
|
16620 | return fetchAttachments(results, stores, opts);
|
16621 | }
|
16622 | }).then(function () {
|
16623 | var returnVal = {
|
16624 | total_rows: docCount,
|
16625 | offset: opts.skip,
|
16626 | rows: results
|
16627 | };
|
16628 |
|
16629 | /* istanbul ignore if */
|
16630 | if (opts.update_seq) {
|
16631 | returnVal.update_seq = db._updateSeq;
|
16632 | }
|
16633 | callback(null, returnVal);
|
16634 | }, callback);
|
16635 | next();
|
16636 | }).on('unpipe', function () {
|
16637 | throughStream.end();
|
16638 | });
|
16639 |
|
16640 | docstream.on('error', callback);
|
16641 |
|
16642 | docstream.pipe(throughStream);
|
16643 | });
|
16644 | })(opts, callback);
|
16645 | };
|
16646 |
|
16647 | api._changes = function (opts) {
|
16648 | opts = clone(opts);
|
16649 |
|
16650 | if (opts.continuous) {
|
16651 | var id = name + ':' + uuid();
|
16652 | levelChanges.addListener(name, id, api, opts);
|
16653 | levelChanges.notify(name);
|
16654 | return {
|
16655 | cancel: function () {
|
16656 | levelChanges.removeListener(name, id);
|
16657 | }
|
16658 | };
|
16659 | }
|
16660 |
|
16661 | var descending = opts.descending;
|
16662 | var results = [];
|
16663 | var lastSeq = opts.since || 0;
|
16664 | var called = 0;
|
16665 | var streamOpts = {
|
16666 | reverse: descending
|
16667 | };
|
16668 | var limit;
|
16669 | if ('limit' in opts && opts.limit > 0) {
|
16670 | limit = opts.limit;
|
16671 | }
|
16672 | if (!streamOpts.reverse) {
|
16673 | streamOpts.start = formatSeq(opts.since || 0);
|
16674 | }
|
16675 |
|
16676 | var docIds = opts.doc_ids && new ExportedSet(opts.doc_ids);
|
16677 | var filter = filterChange(opts);
|
16678 | var docIdsToMetadata = new ExportedMap();
|
16679 |
|
16680 | function complete() {
|
16681 | opts.done = true;
|
16682 | if (opts.return_docs && opts.limit) {
|
16683 | /* istanbul ignore if */
|
16684 | if (opts.limit < results.length) {
|
16685 | results.length = opts.limit;
|
16686 | }
|
16687 | }
|
16688 | changeStream.unpipe(throughStream);
|
16689 | changeStream.destroy();
|
16690 | if (!opts.continuous && !opts.cancelled) {
|
16691 | if (opts.include_docs && opts.attachments && opts.return_docs) {
|
16692 | fetchAttachments(results, stores, opts).then(function () {
|
16693 | opts.complete(null, {results: results, last_seq: lastSeq});
|
16694 | });
|
16695 | } else {
|
16696 | opts.complete(null, {results: results, last_seq: lastSeq});
|
16697 | }
|
16698 | }
|
16699 | }
|
16700 | var changeStream = stores.bySeqStore.readStream(streamOpts);
|
16701 | var throughStream = through2.obj(function (data, _, next) {
|
16702 | if (limit && called >= limit) {
|
16703 | complete();
|
16704 | return next();
|
16705 | }
|
16706 | if (opts.cancelled || opts.done) {
|
16707 | return next();
|
16708 | }
|
16709 |
|
16710 | var seq = parseSeq(data.key);
|
16711 | var doc = data.value;
|
16712 |
|
16713 | if (seq === opts.since && !descending) {
|
16714 | // couchdb ignores `since` if descending=true
|
16715 | return next();
|
16716 | }
|
16717 |
|
16718 | if (docIds && !docIds.has(doc._id)) {
|
16719 | return next();
|
16720 | }
|
16721 |
|
16722 | var metadata;
|
16723 |
|
16724 | function onGetMetadata(metadata) {
|
16725 | var winningRev$$1 = getWinningRev(metadata);
|
16726 |
|
16727 | function onGetWinningDoc(winningDoc) {
|
16728 |
|
16729 | var change = opts.processChange(winningDoc, metadata, opts);
|
16730 | change.seq = metadata.seq;
|
16731 |
|
16732 | var filtered = filter(change);
|
16733 | if (typeof filtered === 'object') {
|
16734 | return opts.complete(filtered);
|
16735 | }
|
16736 |
|
16737 | if (filtered) {
|
16738 | called++;
|
16739 |
|
16740 | if (opts.attachments && opts.include_docs) {
|
16741 | // fetch attachment immediately for the benefit
|
16742 | // of live listeners
|
16743 | fetchAttachments([change], stores, opts).then(function () {
|
16744 | opts.onChange(change);
|
16745 | });
|
16746 | } else {
|
16747 | opts.onChange(change);
|
16748 | }
|
16749 |
|
16750 | if (opts.return_docs) {
|
16751 | results.push(change);
|
16752 | }
|
16753 | }
|
16754 | next();
|
16755 | }
|
16756 |
|
16757 | if (metadata.seq !== seq) {
|
16758 | // some other seq is later
|
16759 | return next();
|
16760 | }
|
16761 |
|
16762 | lastSeq = seq;
|
16763 |
|
16764 | if (winningRev$$1 === doc._rev) {
|
16765 | return onGetWinningDoc(doc);
|
16766 | }
|
16767 |
|
16768 | // fetch the winner
|
16769 |
|
16770 | var winningSeq = metadata.rev_map[winningRev$$1];
|
16771 |
|
16772 | stores.bySeqStore.get(formatSeq(winningSeq), function (err, doc) {
|
16773 | onGetWinningDoc(doc);
|
16774 | });
|
16775 | }
|
16776 |
|
16777 | metadata = docIdsToMetadata.get(doc._id);
|
16778 | if (metadata) { // cached
|
16779 | return onGetMetadata(metadata);
|
16780 | }
|
16781 | // metadata not cached, have to go fetch it
|
16782 | stores.docStore.get(doc._id, function (err, metadata) {
|
16783 | /* istanbul ignore if */
|
16784 | if (opts.cancelled || opts.done || db.isClosed() ||
|
16785 | isLocalId(metadata.id)) {
|
16786 | return next();
|
16787 | }
|
16788 | docIdsToMetadata.set(doc._id, metadata);
|
16789 | onGetMetadata(metadata);
|
16790 | });
|
16791 | }, function (next) {
|
16792 | if (opts.cancelled) {
|
16793 | return next();
|
16794 | }
|
16795 | if (opts.return_docs && opts.limit) {
|
16796 | /* istanbul ignore if */
|
16797 | if (opts.limit < results.length) {
|
16798 | results.length = opts.limit;
|
16799 | }
|
16800 | }
|
16801 |
|
16802 | next();
|
16803 | }).on('unpipe', function () {
|
16804 | throughStream.end();
|
16805 | complete();
|
16806 | });
|
16807 | changeStream.pipe(throughStream);
|
16808 | return {
|
16809 | cancel: function () {
|
16810 | opts.cancelled = true;
|
16811 | complete();
|
16812 | }
|
16813 | };
|
16814 | };
|
16815 |
|
16816 | api._close = function (callback) {
|
16817 | /* istanbul ignore if */
|
16818 | if (db.isClosed()) {
|
16819 | return callback(createError(NOT_OPEN));
|
16820 | }
|
16821 | db.close(function (err) {
|
16822 | /* istanbul ignore if */
|
16823 | if (err) {
|
16824 | callback(err);
|
16825 | } else {
|
16826 | dbStore["delete"](name);
|
16827 | callback();
|
16828 | }
|
16829 | });
|
16830 | };
|
16831 |
|
16832 | api._getRevisionTree = function (docId, callback) {
|
16833 | stores.docStore.get(docId, function (err, metadata) {
|
16834 | if (err) {
|
16835 | callback(createError(MISSING_DOC));
|
16836 | } else {
|
16837 | callback(null, metadata.rev_tree);
|
16838 | }
|
16839 | });
|
16840 | };
|
16841 |
|
16842 | api._doCompaction = writeLock(function (docId, revs, opts, callback) {
|
16843 | api._doCompactionNoLock(docId, revs, opts, callback);
|
16844 | });
|
16845 |
|
16846 | // the NoLock version is for use by bulkDocs
|
16847 | api._doCompactionNoLock = function (docId, revs, opts, callback) {
|
16848 | if (typeof opts === 'function') {
|
16849 | callback = opts;
|
16850 | opts = {};
|
16851 | }
|
16852 |
|
16853 | if (!revs.length) {
|
16854 | return callback();
|
16855 | }
|
16856 | var txn = opts.ctx || new LevelTransaction();
|
16857 |
|
16858 | txn.get(stores.docStore, docId, function (err, metadata) {
|
16859 | /* istanbul ignore if */
|
16860 | if (err) {
|
16861 | return callback(err);
|
16862 | }
|
16863 | var seqs = revs.map(function (rev) {
|
16864 | var seq = metadata.rev_map[rev];
|
16865 | delete metadata.rev_map[rev];
|
16866 | return seq;
|
16867 | });
|
16868 | traverseRevTree(metadata.rev_tree, function (isLeaf, pos,
|
16869 | revHash, ctx, opts) {
|
16870 | var rev = pos + '-' + revHash;
|
16871 | if (revs.indexOf(rev) !== -1) {
|
16872 | opts.status = 'missing';
|
16873 | }
|
16874 | });
|
16875 |
|
16876 | var batch = [];
|
16877 | batch.push({
|
16878 | key: metadata.id,
|
16879 | value: metadata,
|
16880 | type: 'put',
|
16881 | prefix: stores.docStore
|
16882 | });
|
16883 |
|
16884 | var digestMap = {};
|
16885 | var numDone = 0;
|
16886 | var overallErr;
|
16887 | function checkDone(err) {
|
16888 | /* istanbul ignore if */
|
16889 | if (err) {
|
16890 | overallErr = err;
|
16891 | }
|
16892 | if (++numDone === revs.length) { // done
|
16893 | /* istanbul ignore if */
|
16894 | if (overallErr) {
|
16895 | return callback(overallErr);
|
16896 | }
|
16897 | deleteOrphanedAttachments();
|
16898 | }
|
16899 | }
|
16900 |
|
16901 | function finish(err) {
|
16902 | /* istanbul ignore if */
|
16903 | if (err) {
|
16904 | return callback(err);
|
16905 | }
|
16906 | txn.batch(batch);
|
16907 | if (opts.ctx) {
|
16908 | // don't execute immediately
|
16909 | return callback();
|
16910 | }
|
16911 | txn.execute(db, callback);
|
16912 | }
|
16913 |
|
16914 | function deleteOrphanedAttachments() {
|
16915 | var possiblyOrphanedAttachments = Object.keys(digestMap);
|
16916 | if (!possiblyOrphanedAttachments.length) {
|
16917 | return finish();
|
16918 | }
|
16919 | var numDone = 0;
|
16920 | var overallErr;
|
16921 | function checkDone(err) {
|
16922 | /* istanbul ignore if */
|
16923 | if (err) {
|
16924 | overallErr = err;
|
16925 | }
|
16926 | if (++numDone === possiblyOrphanedAttachments.length) {
|
16927 | finish(overallErr);
|
16928 | }
|
16929 | }
|
16930 | var refsToDelete = new ExportedMap();
|
16931 | revs.forEach(function (rev) {
|
16932 | refsToDelete.set(docId + '@' + rev, true);
|
16933 | });
|
16934 | possiblyOrphanedAttachments.forEach(function (digest) {
|
16935 | txn.get(stores.attachmentStore, digest, function (err, attData) {
|
16936 | /* istanbul ignore if */
|
16937 | if (err) {
|
16938 | if (err.name === 'NotFoundError') {
|
16939 | return checkDone();
|
16940 | } else {
|
16941 | return checkDone(err);
|
16942 | }
|
16943 | }
|
16944 | var refs = Object.keys(attData.refs || {}).filter(function (ref) {
|
16945 | return !refsToDelete.has(ref);
|
16946 | });
|
16947 | var newRefs = {};
|
16948 | refs.forEach(function (ref) {
|
16949 | newRefs[ref] = true;
|
16950 | });
|
16951 | if (refs.length) { // not orphaned
|
16952 | batch.push({
|
16953 | key: digest,
|
16954 | type: 'put',
|
16955 | value: {refs: newRefs},
|
16956 | prefix: stores.attachmentStore
|
16957 | });
|
16958 | } else { // orphaned, can safely delete
|
16959 | batch = batch.concat([{
|
16960 | key: digest,
|
16961 | type: 'del',
|
16962 | prefix: stores.attachmentStore
|
16963 | }, {
|
16964 | key: digest,
|
16965 | type: 'del',
|
16966 | prefix: stores.binaryStore
|
16967 | }]);
|
16968 | }
|
16969 | checkDone();
|
16970 | });
|
16971 | });
|
16972 | }
|
16973 |
|
16974 | seqs.forEach(function (seq) {
|
16975 | batch.push({
|
16976 | key: formatSeq(seq),
|
16977 | type: 'del',
|
16978 | prefix: stores.bySeqStore
|
16979 | });
|
16980 | txn.get(stores.bySeqStore, formatSeq(seq), function (err, doc) {
|
16981 | /* istanbul ignore if */
|
16982 | if (err) {
|
16983 | if (err.name === 'NotFoundError') {
|
16984 | return checkDone();
|
16985 | } else {
|
16986 | return checkDone(err);
|
16987 | }
|
16988 | }
|
16989 | var atts = Object.keys(doc._attachments || {});
|
16990 | atts.forEach(function (attName) {
|
16991 | var digest = doc._attachments[attName].digest;
|
16992 | digestMap[digest] = true;
|
16993 | });
|
16994 | checkDone();
|
16995 | });
|
16996 | });
|
16997 | });
|
16998 | };
|
16999 |
|
17000 | api._getLocal = function (id, callback) {
|
17001 | stores.localStore.get(id, function (err, doc) {
|
17002 | if (err) {
|
17003 | callback(createError(MISSING_DOC));
|
17004 | } else {
|
17005 | callback(null, doc);
|
17006 | }
|
17007 | });
|
17008 | };
|
17009 |
|
17010 | api._putLocal = function (doc, opts, callback) {
|
17011 | if (typeof opts === 'function') {
|
17012 | callback = opts;
|
17013 | opts = {};
|
17014 | }
|
17015 | if (opts.ctx) {
|
17016 | api._putLocalNoLock(doc, opts, callback);
|
17017 | } else {
|
17018 | api._putLocalWithLock(doc, opts, callback);
|
17019 | }
|
17020 | };
|
17021 |
|
17022 | api._putLocalWithLock = writeLock(function (doc, opts, callback) {
|
17023 | api._putLocalNoLock(doc, opts, callback);
|
17024 | });
|
17025 |
|
17026 | // the NoLock version is for use by bulkDocs
|
17027 | api._putLocalNoLock = function (doc, opts, callback) {
|
17028 | delete doc._revisions; // ignore this, trust the rev
|
17029 | var oldRev = doc._rev;
|
17030 | var id = doc._id;
|
17031 |
|
17032 | var txn = opts.ctx || new LevelTransaction();
|
17033 |
|
17034 | txn.get(stores.localStore, id, function (err, resp) {
|
17035 | if (err && oldRev) {
|
17036 | return callback(createError(REV_CONFLICT));
|
17037 | }
|
17038 | if (resp && resp._rev !== oldRev) {
|
17039 | return callback(createError(REV_CONFLICT));
|
17040 | }
|
17041 | doc._rev =
|
17042 | oldRev ? '0-' + (parseInt(oldRev.split('-')[1], 10) + 1) : '0-1';
|
17043 | var batch = [
|
17044 | {
|
17045 | type: 'put',
|
17046 | prefix: stores.localStore,
|
17047 | key: id,
|
17048 | value: doc
|
17049 | }
|
17050 | ];
|
17051 |
|
17052 | txn.batch(batch);
|
17053 | var ret = {ok: true, id: doc._id, rev: doc._rev};
|
17054 |
|
17055 | if (opts.ctx) {
|
17056 | // don't execute immediately
|
17057 | return callback(null, ret);
|
17058 | }
|
17059 | txn.execute(db, function (err) {
|
17060 | /* istanbul ignore if */
|
17061 | if (err) {
|
17062 | return callback(err);
|
17063 | }
|
17064 | callback(null, ret);
|
17065 | });
|
17066 | });
|
17067 | };
|
17068 |
|
17069 | api._removeLocal = function (doc, opts, callback) {
|
17070 | if (typeof opts === 'function') {
|
17071 | callback = opts;
|
17072 | opts = {};
|
17073 | }
|
17074 | if (opts.ctx) {
|
17075 | api._removeLocalNoLock(doc, opts, callback);
|
17076 | } else {
|
17077 | api._removeLocalWithLock(doc, opts, callback);
|
17078 | }
|
17079 | };
|
17080 |
|
17081 | api._removeLocalWithLock = writeLock(function (doc, opts, callback) {
|
17082 | api._removeLocalNoLock(doc, opts, callback);
|
17083 | });
|
17084 |
|
17085 | // the NoLock version is for use by bulkDocs
|
17086 | api._removeLocalNoLock = function (doc, opts, callback) {
|
17087 | var txn = opts.ctx || new LevelTransaction();
|
17088 | txn.get(stores.localStore, doc._id, function (err, resp) {
|
17089 | if (err) {
|
17090 | /* istanbul ignore if */
|
17091 | if (err.name !== 'NotFoundError') {
|
17092 | return callback(err);
|
17093 | } else {
|
17094 | return callback(createError(MISSING_DOC));
|
17095 | }
|
17096 | }
|
17097 | if (resp._rev !== doc._rev) {
|
17098 | return callback(createError(REV_CONFLICT));
|
17099 | }
|
17100 | txn.batch([{
|
17101 | prefix: stores.localStore,
|
17102 | type: 'del',
|
17103 | key: doc._id
|
17104 | }]);
|
17105 | var ret = {ok: true, id: doc._id, rev: '0-0'};
|
17106 | if (opts.ctx) {
|
17107 | // don't execute immediately
|
17108 | return callback(null, ret);
|
17109 | }
|
17110 | txn.execute(db, function (err) {
|
17111 | /* istanbul ignore if */
|
17112 | if (err) {
|
17113 | return callback(err);
|
17114 | }
|
17115 | callback(null, ret);
|
17116 | });
|
17117 | });
|
17118 | };
|
17119 |
|
17120 | // close and delete open leveldb stores
|
17121 | api._destroy = function (opts, callback) {
|
17122 | var dbStore;
|
17123 | var leveldownName = functionName(leveldown);
|
17124 | /* istanbul ignore else */
|
17125 | if (dbStores.has(leveldownName)) {
|
17126 | dbStore = dbStores.get(leveldownName);
|
17127 | } else {
|
17128 | return callDestroy(name, callback);
|
17129 | }
|
17130 |
|
17131 | /* istanbul ignore else */
|
17132 | if (dbStore.has(name)) {
|
17133 | levelChanges.removeAllListeners(name);
|
17134 |
|
17135 | dbStore.get(name).close(function () {
|
17136 | dbStore["delete"](name);
|
17137 | callDestroy(name, callback);
|
17138 | });
|
17139 | } else {
|
17140 | callDestroy(name, callback);
|
17141 | }
|
17142 | };
|
17143 | function callDestroy(name, cb) {
|
17144 | // May not exist if leveldown is backed by memory adapter
|
17145 | if ('destroy' in leveldown) {
|
17146 | leveldown.destroy(name, cb);
|
17147 | }
|
17148 | }
|
17149 | }
|
17150 |
|
17151 | function FruitDownPouch(opts, callback) {
|
17152 | var _opts = $inject_Object_assign({
|
17153 | db: fruitdown
|
17154 | }, opts);
|
17155 |
|
17156 | LevelPouch.call(this, _opts, callback);
|
17157 | }
|
17158 |
|
17159 | // overrides for normal LevelDB behavior on Node
|
17160 | FruitDownPouch.valid = function () {
|
17161 | return !!global.indexedDB;
|
17162 | };
|
17163 | FruitDownPouch.use_prefix = true;
|
17164 |
|
17165 | function FruitdownPouchPlugin (PouchDB) {
|
17166 | PouchDB.adapter('fruitdown', FruitDownPouch, true);
|
17167 | }
|
17168 |
|
17169 | /* global PouchDB */
|
17170 |
|
17171 | if (typeof PouchDB === 'undefined') {
|
17172 | guardedConsole('error', 'fruitdown adapter plugin error: ' +
|
17173 | 'Cannot find global "PouchDB" object! ' +
|
17174 | 'Did you remember to include pouchdb.js?');
|
17175 | } else {
|
17176 | PouchDB.plugin(FruitdownPouchPlugin);
|
17177 | }
|
17178 |
|
17179 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
17180 | },{"104":104,"11":11,"15":15,"18":18,"21":21,"25":25,"26":26,"29":29,"4":4,"43":43,"53":53,"64":64,"66":66,"93":93,"99":99}]},{},[106]);
|
17181 |
|
\ | No newline at end of file |