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_(60))
|
92 | },{"60":60}],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_(60))
|
145 | },{"60":60}],3:[function(_dereq_,module,exports){
|
146 | (function (Buffer,process){
|
147 |
|
148 |
|
149 | var xtend = _dereq_(110)
|
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_(25)},_dereq_(60))
|
407 | },{"1":1,"110":110,"2":2,"25":25,"60":60}],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_(60),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
1543 | },{"6":6,"60":60,"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_(22)
|
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 | },{"22":22,"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_(25)})
|
3620 | },{"25":25}],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_(61)
|
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 | },{"61":61}],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 |
|
4875 |
|
4876 |
|
4877 |
|
4878 |
|
4879 |
|
4880 |
|
4881 |
|
4882 |
|
4883 |
|
4884 |
|
4885 | function hasLocalStorage() {
|
4886 | try {
|
4887 |
|
4888 |
|
4889 |
|
4890 | if (typeof localStorage === 'undefined') {
|
4891 | return false;
|
4892 | }
|
4893 |
|
4894 |
|
4895 |
|
4896 | localStorage.setItem('Storage-Test', '1');
|
4897 |
|
4898 |
|
4899 | if (localStorage.getItem('Storage-Test') !== '1') {
|
4900 | return false;
|
4901 | }
|
4902 |
|
4903 |
|
4904 | localStorage.removeItem('Storage-Test');
|
4905 | } catch (_error) {
|
4906 |
|
4907 |
|
4908 | return false;
|
4909 | }
|
4910 |
|
4911 |
|
4912 | return true;
|
4913 | }
|
4914 |
|
4915 |
|
4916 | if (typeof exports === 'object') {
|
4917 | module.exports = hasLocalStorage;
|
4918 | }
|
4919 |
|
4920 | },{}],20:[function(_dereq_,module,exports){
|
4921 | (function (global){
|
4922 | var exports = module.exports = {};
|
4923 | var localStorageMemory = _dereq_(57);
|
4924 | exports.hasLocalStorage = _dereq_(19);
|
4925 |
|
4926 |
|
4927 |
|
4928 |
|
4929 |
|
4930 |
|
4931 |
|
4932 |
|
4933 |
|
4934 |
|
4935 | exports.create = function () {
|
4936 | var api;
|
4937 |
|
4938 | if (!exports.hasLocalStorage()) {
|
4939 | api = localStorageMemory;
|
4940 | api.isPersistent = false;
|
4941 | } else {
|
4942 | api = global.localStorage;
|
4943 | api = {
|
4944 | get length() { return global.localStorage.length; },
|
4945 | getItem: global.localStorage.getItem.bind(global.localStorage),
|
4946 | setItem: global.localStorage.setItem.bind(global.localStorage),
|
4947 | removeItem: global.localStorage.removeItem.bind(global.localStorage),
|
4948 | key: global.localStorage.key.bind(global.localStorage),
|
4949 | clear: global.localStorage.clear.bind(global.localStorage),
|
4950 | };
|
4951 |
|
4952 | api.isPersistent = true;
|
4953 | }
|
4954 |
|
4955 | api.getObject = exports.getObject.bind(null, api);
|
4956 | api.setObject = exports.setObject.bind(null, api);
|
4957 |
|
4958 | return api;
|
4959 | };
|
4960 |
|
4961 |
|
4962 |
|
4963 |
|
4964 |
|
4965 |
|
4966 | exports.setObject = function (store, key, object) {
|
4967 | if (typeof object !== 'object') {
|
4968 | return store.setItem(key, object);
|
4969 | }
|
4970 |
|
4971 | return store.setItem(key, JSON.stringify(object));
|
4972 | };
|
4973 |
|
4974 |
|
4975 |
|
4976 |
|
4977 |
|
4978 |
|
4979 | exports.getObject = function (store, key) {
|
4980 | var item = store.getItem(key);
|
4981 |
|
4982 | if (!item) {
|
4983 | return null;
|
4984 | }
|
4985 |
|
4986 | try {
|
4987 | return JSON.parse(item);
|
4988 | } catch (e) {
|
4989 | return item;
|
4990 | }
|
4991 | };
|
4992 |
|
4993 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
4994 | },{"19":19,"57":57}],21:[function(_dereq_,module,exports){
|
4995 | var api = _dereq_(20);
|
4996 | module.exports = api.create();
|
4997 |
|
4998 | },{"20":20}],22:[function(_dereq_,module,exports){
|
4999 | exports.read = function (buffer, offset, isLE, mLen, nBytes) {
|
5000 | var e, m
|
5001 | var eLen = (nBytes * 8) - mLen - 1
|
5002 | var eMax = (1 << eLen) - 1
|
5003 | var eBias = eMax >> 1
|
5004 | var nBits = -7
|
5005 | var i = isLE ? (nBytes - 1) : 0
|
5006 | var d = isLE ? -1 : 1
|
5007 | var s = buffer[offset + i]
|
5008 |
|
5009 | i += d
|
5010 |
|
5011 | e = s & ((1 << (-nBits)) - 1)
|
5012 | s >>= (-nBits)
|
5013 | nBits += eLen
|
5014 | for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {}
|
5015 |
|
5016 | m = e & ((1 << (-nBits)) - 1)
|
5017 | e >>= (-nBits)
|
5018 | nBits += mLen
|
5019 | for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {}
|
5020 |
|
5021 | if (e === 0) {
|
5022 | e = 1 - eBias
|
5023 | } else if (e === eMax) {
|
5024 | return m ? NaN : ((s ? -1 : 1) * Infinity)
|
5025 | } else {
|
5026 | m = m + Math.pow(2, mLen)
|
5027 | e = e - eBias
|
5028 | }
|
5029 | return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
|
5030 | }
|
5031 |
|
5032 | exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
|
5033 | var e, m, c
|
5034 | var eLen = (nBytes * 8) - mLen - 1
|
5035 | var eMax = (1 << eLen) - 1
|
5036 | var eBias = eMax >> 1
|
5037 | var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
|
5038 | var i = isLE ? 0 : (nBytes - 1)
|
5039 | var d = isLE ? 1 : -1
|
5040 | var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
|
5041 |
|
5042 | value = Math.abs(value)
|
5043 |
|
5044 | if (isNaN(value) || value === Infinity) {
|
5045 | m = isNaN(value) ? 1 : 0
|
5046 | e = eMax
|
5047 | } else {
|
5048 | e = Math.floor(Math.log(value) / Math.LN2)
|
5049 | if (value * (c = Math.pow(2, -e)) < 1) {
|
5050 | e--
|
5051 | c *= 2
|
5052 | }
|
5053 | if (e + eBias >= 1) {
|
5054 | value += rt / c
|
5055 | } else {
|
5056 | value += rt * Math.pow(2, 1 - eBias)
|
5057 | }
|
5058 | if (value * c >= 2) {
|
5059 | e++
|
5060 | c /= 2
|
5061 | }
|
5062 |
|
5063 | if (e + eBias >= eMax) {
|
5064 | m = 0
|
5065 | e = eMax
|
5066 | } else if (e + eBias >= 1) {
|
5067 | m = ((value * c) - 1) * Math.pow(2, mLen)
|
5068 | e = e + eBias
|
5069 | } else {
|
5070 | m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
|
5071 | e = 0
|
5072 | }
|
5073 | }
|
5074 |
|
5075 | for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
|
5076 |
|
5077 | e = (e << mLen) | m
|
5078 | eLen += mLen
|
5079 | for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
|
5080 |
|
5081 | buffer[offset + i - d] |= s * 128
|
5082 | }
|
5083 |
|
5084 | },{}],23:[function(_dereq_,module,exports){
|
5085 | (function (global){
|
5086 | 'use strict';
|
5087 | var Mutation = global.MutationObserver || global.WebKitMutationObserver;
|
5088 |
|
5089 | var scheduleDrain;
|
5090 |
|
5091 | {
|
5092 | if (Mutation) {
|
5093 | var called = 0;
|
5094 | var observer = new Mutation(nextTick);
|
5095 | var element = global.document.createTextNode('');
|
5096 | observer.observe(element, {
|
5097 | characterData: true
|
5098 | });
|
5099 | scheduleDrain = function () {
|
5100 | element.data = (called = ++called % 2);
|
5101 | };
|
5102 | } else if (!global.setImmediate && typeof global.MessageChannel !== 'undefined') {
|
5103 | var channel = new global.MessageChannel();
|
5104 | channel.port1.onmessage = nextTick;
|
5105 | scheduleDrain = function () {
|
5106 | channel.port2.postMessage(0);
|
5107 | };
|
5108 | } else if ('document' in global && 'onreadystatechange' in global.document.createElement('script')) {
|
5109 | scheduleDrain = function () {
|
5110 |
|
5111 |
|
5112 |
|
5113 | var scriptEl = global.document.createElement('script');
|
5114 | scriptEl.onreadystatechange = function () {
|
5115 | nextTick();
|
5116 |
|
5117 | scriptEl.onreadystatechange = null;
|
5118 | scriptEl.parentNode.removeChild(scriptEl);
|
5119 | scriptEl = null;
|
5120 | };
|
5121 | global.document.documentElement.appendChild(scriptEl);
|
5122 | };
|
5123 | } else {
|
5124 | scheduleDrain = function () {
|
5125 | setTimeout(nextTick, 0);
|
5126 | };
|
5127 | }
|
5128 | }
|
5129 |
|
5130 | var draining;
|
5131 | var queue = [];
|
5132 |
|
5133 | function nextTick() {
|
5134 | draining = true;
|
5135 | var i, oldQueue;
|
5136 | var len = queue.length;
|
5137 | while (len) {
|
5138 | oldQueue = queue;
|
5139 | queue = [];
|
5140 | i = -1;
|
5141 | while (++i < len) {
|
5142 | oldQueue[i]();
|
5143 | }
|
5144 | len = queue.length;
|
5145 | }
|
5146 | draining = false;
|
5147 | }
|
5148 |
|
5149 | module.exports = immediate;
|
5150 | function immediate(task) {
|
5151 | if (queue.push(task) === 1 && !draining) {
|
5152 | scheduleDrain();
|
5153 | }
|
5154 | }
|
5155 |
|
5156 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
5157 | },{}],24:[function(_dereq_,module,exports){
|
5158 | arguments[4][6][0].apply(exports,arguments)
|
5159 | },{"6":6}],25:[function(_dereq_,module,exports){
|
5160 |
|
5161 |
|
5162 |
|
5163 |
|
5164 |
|
5165 |
|
5166 |
|
5167 |
|
5168 |
|
5169 | module.exports = function (obj) {
|
5170 | return obj != null && (isBuffer(obj) || isSlowBuffer(obj) || !!obj._isBuffer)
|
5171 | }
|
5172 |
|
5173 | function isBuffer (obj) {
|
5174 | return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)
|
5175 | }
|
5176 |
|
5177 |
|
5178 | function isSlowBuffer (obj) {
|
5179 | return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isBuffer(obj.slice(0, 0))
|
5180 | }
|
5181 |
|
5182 | },{}],26:[function(_dereq_,module,exports){
|
5183 | var toString = {}.toString;
|
5184 |
|
5185 | module.exports = Array.isArray || function (arr) {
|
5186 | return toString.call(arr) == '[object Array]';
|
5187 | };
|
5188 |
|
5189 | },{}],27:[function(_dereq_,module,exports){
|
5190 | var encodings = _dereq_(28);
|
5191 |
|
5192 | module.exports = Codec;
|
5193 |
|
5194 | function Codec(opts){
|
5195 | this.opts = opts || {};
|
5196 | this.encodings = encodings;
|
5197 | }
|
5198 |
|
5199 | Codec.prototype._encoding = function(encoding){
|
5200 | if (typeof encoding == 'string') encoding = encodings[encoding];
|
5201 | if (!encoding) encoding = encodings.id;
|
5202 | return encoding;
|
5203 | };
|
5204 |
|
5205 | Codec.prototype._keyEncoding = function(opts, batchOpts){
|
5206 | return this._encoding(batchOpts && batchOpts.keyEncoding
|
5207 | || opts && opts.keyEncoding
|
5208 | || this.opts.keyEncoding);
|
5209 | };
|
5210 |
|
5211 | Codec.prototype._valueEncoding = function(opts, batchOpts){
|
5212 | return this._encoding(
|
5213 | batchOpts && (batchOpts.valueEncoding || batchOpts.encoding)
|
5214 | || opts && (opts.valueEncoding || opts.encoding)
|
5215 | || (this.opts.valueEncoding || this.opts.encoding));
|
5216 | };
|
5217 |
|
5218 | Codec.prototype.encodeKey = function(key, opts, batchOpts){
|
5219 | return this._keyEncoding(opts, batchOpts).encode(key);
|
5220 | };
|
5221 |
|
5222 | Codec.prototype.encodeValue = function(value, opts, batchOpts){
|
5223 | return this._valueEncoding(opts, batchOpts).encode(value);
|
5224 | };
|
5225 |
|
5226 | Codec.prototype.decodeKey = function(key, opts){
|
5227 | return this._keyEncoding(opts).decode(key);
|
5228 | };
|
5229 |
|
5230 | Codec.prototype.decodeValue = function(value, opts){
|
5231 | return this._valueEncoding(opts).decode(value);
|
5232 | };
|
5233 |
|
5234 | Codec.prototype.encodeBatch = function(ops, opts){
|
5235 | var self = this;
|
5236 |
|
5237 | return ops.map(function(_op){
|
5238 | var op = {
|
5239 | type: _op.type,
|
5240 | key: self.encodeKey(_op.key, opts, _op)
|
5241 | };
|
5242 | if (self.keyAsBuffer(opts, _op)) op.keyEncoding = 'binary';
|
5243 | if (_op.prefix) op.prefix = _op.prefix;
|
5244 | if ('value' in _op) {
|
5245 | op.value = self.encodeValue(_op.value, opts, _op);
|
5246 | if (self.valueAsBuffer(opts, _op)) op.valueEncoding = 'binary';
|
5247 | }
|
5248 | return op;
|
5249 | });
|
5250 | };
|
5251 |
|
5252 | var ltgtKeys = ['lt', 'gt', 'lte', 'gte', 'start', 'end'];
|
5253 |
|
5254 | Codec.prototype.encodeLtgt = function(ltgt){
|
5255 | var self = this;
|
5256 | var ret = {};
|
5257 | Object.keys(ltgt).forEach(function(key){
|
5258 | ret[key] = ltgtKeys.indexOf(key) > -1
|
5259 | ? self.encodeKey(ltgt[key], ltgt)
|
5260 | : ltgt[key]
|
5261 | });
|
5262 | return ret;
|
5263 | };
|
5264 |
|
5265 | Codec.prototype.createStreamDecoder = function(opts){
|
5266 | var self = this;
|
5267 |
|
5268 | if (opts.keys && opts.values) {
|
5269 | return function(key, value){
|
5270 | return {
|
5271 | key: self.decodeKey(key, opts),
|
5272 | value: self.decodeValue(value, opts)
|
5273 | };
|
5274 | };
|
5275 | } else if (opts.keys) {
|
5276 | return function(key) {
|
5277 | return self.decodeKey(key, opts);
|
5278 | };
|
5279 | } else if (opts.values) {
|
5280 | return function(_, value){
|
5281 | return self.decodeValue(value, opts);
|
5282 | }
|
5283 | } else {
|
5284 | return function(){};
|
5285 | }
|
5286 | };
|
5287 |
|
5288 | Codec.prototype.keyAsBuffer = function(opts){
|
5289 | return this._keyEncoding(opts).buffer;
|
5290 | };
|
5291 |
|
5292 | Codec.prototype.valueAsBuffer = function(opts){
|
5293 | return this._valueEncoding(opts).buffer;
|
5294 | };
|
5295 |
|
5296 |
|
5297 | },{"28":28}],28:[function(_dereq_,module,exports){
|
5298 | (function (Buffer){
|
5299 | exports.utf8 = exports['utf-8'] = {
|
5300 | encode: function(data){
|
5301 | return isBinary(data)
|
5302 | ? data
|
5303 | : String(data);
|
5304 | },
|
5305 | decode: function(data){
|
5306 | return typeof data === 'string'
|
5307 | ? data
|
5308 | : String(data)
|
5309 | },
|
5310 | buffer: false,
|
5311 | type: 'utf8'
|
5312 | };
|
5313 |
|
5314 | exports.json = {
|
5315 | encode: JSON.stringify,
|
5316 | decode: JSON.parse,
|
5317 | buffer: false,
|
5318 | type: 'json'
|
5319 | };
|
5320 |
|
5321 | exports.binary = {
|
5322 | encode: function(data){
|
5323 | return isBinary(data)
|
5324 | ? data
|
5325 | : new Buffer(data);
|
5326 | },
|
5327 | decode: identity,
|
5328 | buffer: true,
|
5329 | type: 'binary'
|
5330 | };
|
5331 |
|
5332 | exports.none = {
|
5333 | encode: identity,
|
5334 | decode: identity,
|
5335 | buffer: false,
|
5336 | type: 'id'
|
5337 | };
|
5338 |
|
5339 | exports.id = exports.none;
|
5340 |
|
5341 | var bufferEncodings = [
|
5342 | 'hex',
|
5343 | 'ascii',
|
5344 | 'base64',
|
5345 | 'ucs2',
|
5346 | 'ucs-2',
|
5347 | 'utf16le',
|
5348 | 'utf-16le'
|
5349 | ];
|
5350 |
|
5351 | bufferEncodings.forEach(function(type){
|
5352 | exports[type] = {
|
5353 | encode: function(data){
|
5354 | return isBinary(data)
|
5355 | ? data
|
5356 | : new Buffer(data, type);
|
5357 | },
|
5358 | decode: function(buffer){
|
5359 | return buffer.toString(type);
|
5360 | },
|
5361 | buffer: true,
|
5362 | type: type
|
5363 | };
|
5364 | });
|
5365 |
|
5366 | function identity(value){
|
5367 | return value;
|
5368 | }
|
5369 |
|
5370 | function isBinary(data){
|
5371 | return data === undefined
|
5372 | || data === null
|
5373 | || Buffer.isBuffer(data);
|
5374 | }
|
5375 |
|
5376 | }).call(this,_dereq_(12).Buffer)
|
5377 | },{"12":12}],29:[function(_dereq_,module,exports){
|
5378 | var inherits = _dereq_(24)
|
5379 | var Readable = _dereq_(38).Readable
|
5380 | var extend = _dereq_(39)
|
5381 |
|
5382 | module.exports = ReadStream
|
5383 | inherits(ReadStream, Readable)
|
5384 |
|
5385 | function ReadStream (iterator, options) {
|
5386 | if (!(this instanceof ReadStream)) return new ReadStream(iterator, options)
|
5387 | options = options || {}
|
5388 | Readable.call(this, extend(options, {
|
5389 | objectMode: true
|
5390 | }))
|
5391 | this._iterator = iterator
|
5392 | this._destroyed = false
|
5393 | this._options = options
|
5394 | this.on('end', this._cleanup.bind(this))
|
5395 | }
|
5396 |
|
5397 | ReadStream.prototype._read = function () {
|
5398 | var self = this
|
5399 | var options = this._options
|
5400 | if (this._destroyed) return
|
5401 |
|
5402 | this._iterator.next(function (err, key, value) {
|
5403 | if (self._destroyed) return
|
5404 | if (err) return self.emit('error', err)
|
5405 | if (key === undefined && value === undefined) {
|
5406 | self.push(null)
|
5407 | } else if (options.keys !== false && options.values === false) {
|
5408 | self.push(key)
|
5409 | } else if (options.keys === false && options.values !== false) {
|
5410 | self.push(value)
|
5411 | } else {
|
5412 | self.push({ key: key, value: value })
|
5413 | }
|
5414 | })
|
5415 | }
|
5416 |
|
5417 | ReadStream.prototype.destroy =
|
5418 | ReadStream.prototype._cleanup = function () {
|
5419 | var self = this
|
5420 | if (this._destroyed) return
|
5421 | this._destroyed = true
|
5422 |
|
5423 | this._iterator.end(function (err) {
|
5424 | if (err) return self.emit('error', err)
|
5425 | self.emit('close')
|
5426 | })
|
5427 | }
|
5428 |
|
5429 | },{"24":24,"38":38,"39":39}],30:[function(_dereq_,module,exports){
|
5430 |
|
5431 |
|
5432 |
|
5433 |
|
5434 |
|
5435 |
|
5436 |
|
5437 |
|
5438 |
|
5439 |
|
5440 |
|
5441 |
|
5442 |
|
5443 |
|
5444 |
|
5445 |
|
5446 |
|
5447 |
|
5448 |
|
5449 |
|
5450 |
|
5451 |
|
5452 |
|
5453 |
|
5454 |
|
5455 |
|
5456 | 'use strict';
|
5457 |
|
5458 |
|
5459 |
|
5460 | var pna = _dereq_(59);
|
5461 |
|
5462 |
|
5463 |
|
5464 | var objectKeys = Object.keys || function (obj) {
|
5465 | var keys = [];
|
5466 | for (var key in obj) {
|
5467 | keys.push(key);
|
5468 | }return keys;
|
5469 | };
|
5470 |
|
5471 |
|
5472 | module.exports = Duplex;
|
5473 |
|
5474 |
|
5475 | var util = _dereq_(13);
|
5476 | util.inherits = _dereq_(24);
|
5477 |
|
5478 |
|
5479 | var Readable = _dereq_(32);
|
5480 | var Writable = _dereq_(34);
|
5481 |
|
5482 | util.inherits(Duplex, Readable);
|
5483 |
|
5484 | {
|
5485 |
|
5486 | var keys = objectKeys(Writable.prototype);
|
5487 | for (var v = 0; v < keys.length; v++) {
|
5488 | var method = keys[v];
|
5489 | if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method];
|
5490 | }
|
5491 | }
|
5492 |
|
5493 | function Duplex(options) {
|
5494 | if (!(this instanceof Duplex)) return new Duplex(options);
|
5495 |
|
5496 | Readable.call(this, options);
|
5497 | Writable.call(this, options);
|
5498 |
|
5499 | if (options && options.readable === false) this.readable = false;
|
5500 |
|
5501 | if (options && options.writable === false) this.writable = false;
|
5502 |
|
5503 | this.allowHalfOpen = true;
|
5504 | if (options && options.allowHalfOpen === false) this.allowHalfOpen = false;
|
5505 |
|
5506 | this.once('end', onend);
|
5507 | }
|
5508 |
|
5509 | Object.defineProperty(Duplex.prototype, 'writableHighWaterMark', {
|
5510 |
|
5511 |
|
5512 |
|
5513 | enumerable: false,
|
5514 | get: function () {
|
5515 | return this._writableState.highWaterMark;
|
5516 | }
|
5517 | });
|
5518 |
|
5519 |
|
5520 | function onend() {
|
5521 |
|
5522 |
|
5523 | if (this.allowHalfOpen || this._writableState.ended) return;
|
5524 |
|
5525 |
|
5526 |
|
5527 | pna.nextTick(onEndNT, this);
|
5528 | }
|
5529 |
|
5530 | function onEndNT(self) {
|
5531 | self.end();
|
5532 | }
|
5533 |
|
5534 | Object.defineProperty(Duplex.prototype, 'destroyed', {
|
5535 | get: function () {
|
5536 | if (this._readableState === undefined || this._writableState === undefined) {
|
5537 | return false;
|
5538 | }
|
5539 | return this._readableState.destroyed && this._writableState.destroyed;
|
5540 | },
|
5541 | set: function (value) {
|
5542 |
|
5543 |
|
5544 | if (this._readableState === undefined || this._writableState === undefined) {
|
5545 | return;
|
5546 | }
|
5547 |
|
5548 |
|
5549 |
|
5550 | this._readableState.destroyed = value;
|
5551 | this._writableState.destroyed = value;
|
5552 | }
|
5553 | });
|
5554 |
|
5555 | Duplex.prototype._destroy = function (err, cb) {
|
5556 | this.push(null);
|
5557 | this.end();
|
5558 |
|
5559 | pna.nextTick(cb, err);
|
5560 | };
|
5561 | },{"13":13,"24":24,"32":32,"34":34,"59":59}],31:[function(_dereq_,module,exports){
|
5562 |
|
5563 |
|
5564 |
|
5565 |
|
5566 |
|
5567 |
|
5568 |
|
5569 |
|
5570 |
|
5571 |
|
5572 |
|
5573 |
|
5574 |
|
5575 |
|
5576 |
|
5577 |
|
5578 |
|
5579 |
|
5580 |
|
5581 |
|
5582 |
|
5583 |
|
5584 |
|
5585 |
|
5586 |
|
5587 | 'use strict';
|
5588 |
|
5589 | module.exports = PassThrough;
|
5590 |
|
5591 | var Transform = _dereq_(33);
|
5592 |
|
5593 |
|
5594 | var util = _dereq_(13);
|
5595 | util.inherits = _dereq_(24);
|
5596 |
|
5597 |
|
5598 | util.inherits(PassThrough, Transform);
|
5599 |
|
5600 | function PassThrough(options) {
|
5601 | if (!(this instanceof PassThrough)) return new PassThrough(options);
|
5602 |
|
5603 | Transform.call(this, options);
|
5604 | }
|
5605 |
|
5606 | PassThrough.prototype._transform = function (chunk, encoding, cb) {
|
5607 | cb(null, chunk);
|
5608 | };
|
5609 | },{"13":13,"24":24,"33":33}],32:[function(_dereq_,module,exports){
|
5610 | (function (process,global){
|
5611 |
|
5612 |
|
5613 |
|
5614 |
|
5615 |
|
5616 |
|
5617 |
|
5618 |
|
5619 |
|
5620 |
|
5621 |
|
5622 |
|
5623 |
|
5624 |
|
5625 |
|
5626 |
|
5627 |
|
5628 |
|
5629 |
|
5630 |
|
5631 |
|
5632 | 'use strict';
|
5633 |
|
5634 |
|
5635 |
|
5636 | var pna = _dereq_(59);
|
5637 |
|
5638 |
|
5639 | module.exports = Readable;
|
5640 |
|
5641 |
|
5642 | var isArray = _dereq_(26);
|
5643 |
|
5644 |
|
5645 |
|
5646 | var Duplex;
|
5647 |
|
5648 |
|
5649 | Readable.ReadableState = ReadableState;
|
5650 |
|
5651 |
|
5652 | var EE = _dereq_(18).EventEmitter;
|
5653 |
|
5654 | var EElistenerCount = function (emitter, type) {
|
5655 | return emitter.listeners(type).length;
|
5656 | };
|
5657 |
|
5658 |
|
5659 |
|
5660 | var Stream = _dereq_(37);
|
5661 |
|
5662 |
|
5663 |
|
5664 |
|
5665 | var Buffer = _dereq_(70).Buffer;
|
5666 | var OurUint8Array = global.Uint8Array || function () {};
|
5667 | function _uint8ArrayToBuffer(chunk) {
|
5668 | return Buffer.from(chunk);
|
5669 | }
|
5670 | function _isUint8Array(obj) {
|
5671 | return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
|
5672 | }
|
5673 |
|
5674 |
|
5675 |
|
5676 |
|
5677 | var util = _dereq_(13);
|
5678 | util.inherits = _dereq_(24);
|
5679 |
|
5680 |
|
5681 |
|
5682 | var debugUtil = _dereq_(10);
|
5683 | var debug = void 0;
|
5684 | if (debugUtil && debugUtil.debuglog) {
|
5685 | debug = debugUtil.debuglog('stream');
|
5686 | } else {
|
5687 | debug = function () {};
|
5688 | }
|
5689 |
|
5690 |
|
5691 | var BufferList = _dereq_(35);
|
5692 | var destroyImpl = _dereq_(36);
|
5693 | var StringDecoder;
|
5694 |
|
5695 | util.inherits(Readable, Stream);
|
5696 |
|
5697 | var kProxyEvents = ['error', 'close', 'destroy', 'pause', 'resume'];
|
5698 |
|
5699 | function prependListener(emitter, event, fn) {
|
5700 |
|
5701 |
|
5702 | if (typeof emitter.prependListener === 'function') return emitter.prependListener(event, fn);
|
5703 |
|
5704 |
|
5705 |
|
5706 |
|
5707 |
|
5708 | 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]];
|
5709 | }
|
5710 |
|
5711 | function ReadableState(options, stream) {
|
5712 | Duplex = Duplex || _dereq_(30);
|
5713 |
|
5714 | options = options || {};
|
5715 |
|
5716 |
|
5717 |
|
5718 |
|
5719 |
|
5720 |
|
5721 | var isDuplex = stream instanceof Duplex;
|
5722 |
|
5723 |
|
5724 |
|
5725 | this.objectMode = !!options.objectMode;
|
5726 |
|
5727 | if (isDuplex) this.objectMode = this.objectMode || !!options.readableObjectMode;
|
5728 |
|
5729 |
|
5730 |
|
5731 | var hwm = options.highWaterMark;
|
5732 | var readableHwm = options.readableHighWaterMark;
|
5733 | var defaultHwm = this.objectMode ? 16 : 16 * 1024;
|
5734 |
|
5735 | if (hwm || hwm === 0) this.highWaterMark = hwm;else if (isDuplex && (readableHwm || readableHwm === 0)) this.highWaterMark = readableHwm;else this.highWaterMark = defaultHwm;
|
5736 |
|
5737 |
|
5738 | this.highWaterMark = Math.floor(this.highWaterMark);
|
5739 |
|
5740 |
|
5741 |
|
5742 |
|
5743 | this.buffer = new BufferList();
|
5744 | this.length = 0;
|
5745 | this.pipes = null;
|
5746 | this.pipesCount = 0;
|
5747 | this.flowing = null;
|
5748 | this.ended = false;
|
5749 | this.endEmitted = false;
|
5750 | this.reading = false;
|
5751 |
|
5752 |
|
5753 |
|
5754 |
|
5755 |
|
5756 | this.sync = true;
|
5757 |
|
5758 |
|
5759 |
|
5760 | this.needReadable = false;
|
5761 | this.emittedReadable = false;
|
5762 | this.readableListening = false;
|
5763 | this.resumeScheduled = false;
|
5764 |
|
5765 |
|
5766 | this.destroyed = false;
|
5767 |
|
5768 |
|
5769 |
|
5770 |
|
5771 | this.defaultEncoding = options.defaultEncoding || 'utf8';
|
5772 |
|
5773 |
|
5774 | this.awaitDrain = 0;
|
5775 |
|
5776 |
|
5777 | this.readingMore = false;
|
5778 |
|
5779 | this.decoder = null;
|
5780 | this.encoding = null;
|
5781 | if (options.encoding) {
|
5782 | if (!StringDecoder) StringDecoder = _dereq_(86).StringDecoder;
|
5783 | this.decoder = new StringDecoder(options.encoding);
|
5784 | this.encoding = options.encoding;
|
5785 | }
|
5786 | }
|
5787 |
|
5788 | function Readable(options) {
|
5789 | Duplex = Duplex || _dereq_(30);
|
5790 |
|
5791 | if (!(this instanceof Readable)) return new Readable(options);
|
5792 |
|
5793 | this._readableState = new ReadableState(options, this);
|
5794 |
|
5795 |
|
5796 | this.readable = true;
|
5797 |
|
5798 | if (options) {
|
5799 | if (typeof options.read === 'function') this._read = options.read;
|
5800 |
|
5801 | if (typeof options.destroy === 'function') this._destroy = options.destroy;
|
5802 | }
|
5803 |
|
5804 | Stream.call(this);
|
5805 | }
|
5806 |
|
5807 | Object.defineProperty(Readable.prototype, 'destroyed', {
|
5808 | get: function () {
|
5809 | if (this._readableState === undefined) {
|
5810 | return false;
|
5811 | }
|
5812 | return this._readableState.destroyed;
|
5813 | },
|
5814 | set: function (value) {
|
5815 |
|
5816 |
|
5817 | if (!this._readableState) {
|
5818 | return;
|
5819 | }
|
5820 |
|
5821 |
|
5822 |
|
5823 | this._readableState.destroyed = value;
|
5824 | }
|
5825 | });
|
5826 |
|
5827 | Readable.prototype.destroy = destroyImpl.destroy;
|
5828 | Readable.prototype._undestroy = destroyImpl.undestroy;
|
5829 | Readable.prototype._destroy = function (err, cb) {
|
5830 | this.push(null);
|
5831 | cb(err);
|
5832 | };
|
5833 |
|
5834 |
|
5835 |
|
5836 |
|
5837 |
|
5838 | Readable.prototype.push = function (chunk, encoding) {
|
5839 | var state = this._readableState;
|
5840 | var skipChunkCheck;
|
5841 |
|
5842 | if (!state.objectMode) {
|
5843 | if (typeof chunk === 'string') {
|
5844 | encoding = encoding || state.defaultEncoding;
|
5845 | if (encoding !== state.encoding) {
|
5846 | chunk = Buffer.from(chunk, encoding);
|
5847 | encoding = '';
|
5848 | }
|
5849 | skipChunkCheck = true;
|
5850 | }
|
5851 | } else {
|
5852 | skipChunkCheck = true;
|
5853 | }
|
5854 |
|
5855 | return readableAddChunk(this, chunk, encoding, false, skipChunkCheck);
|
5856 | };
|
5857 |
|
5858 |
|
5859 | Readable.prototype.unshift = function (chunk) {
|
5860 | return readableAddChunk(this, chunk, null, true, false);
|
5861 | };
|
5862 |
|
5863 | function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) {
|
5864 | var state = stream._readableState;
|
5865 | if (chunk === null) {
|
5866 | state.reading = false;
|
5867 | onEofChunk(stream, state);
|
5868 | } else {
|
5869 | var er;
|
5870 | if (!skipChunkCheck) er = chunkInvalid(state, chunk);
|
5871 | if (er) {
|
5872 | stream.emit('error', er);
|
5873 | } else if (state.objectMode || chunk && chunk.length > 0) {
|
5874 | if (typeof chunk !== 'string' && !state.objectMode && Object.getPrototypeOf(chunk) !== Buffer.prototype) {
|
5875 | chunk = _uint8ArrayToBuffer(chunk);
|
5876 | }
|
5877 |
|
5878 | if (addToFront) {
|
5879 | if (state.endEmitted) stream.emit('error', new Error('stream.unshift() after end event'));else addChunk(stream, state, chunk, true);
|
5880 | } else if (state.ended) {
|
5881 | stream.emit('error', new Error('stream.push() after EOF'));
|
5882 | } else {
|
5883 | state.reading = false;
|
5884 | if (state.decoder && !encoding) {
|
5885 | chunk = state.decoder.write(chunk);
|
5886 | if (state.objectMode || chunk.length !== 0) addChunk(stream, state, chunk, false);else maybeReadMore(stream, state);
|
5887 | } else {
|
5888 | addChunk(stream, state, chunk, false);
|
5889 | }
|
5890 | }
|
5891 | } else if (!addToFront) {
|
5892 | state.reading = false;
|
5893 | }
|
5894 | }
|
5895 |
|
5896 | return needMoreData(state);
|
5897 | }
|
5898 |
|
5899 | function addChunk(stream, state, chunk, addToFront) {
|
5900 | if (state.flowing && state.length === 0 && !state.sync) {
|
5901 | stream.emit('data', chunk);
|
5902 | stream.read(0);
|
5903 | } else {
|
5904 |
|
5905 | state.length += state.objectMode ? 1 : chunk.length;
|
5906 | if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk);
|
5907 |
|
5908 | if (state.needReadable) emitReadable(stream);
|
5909 | }
|
5910 | maybeReadMore(stream, state);
|
5911 | }
|
5912 |
|
5913 | function chunkInvalid(state, chunk) {
|
5914 | var er;
|
5915 | if (!_isUint8Array(chunk) && typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
|
5916 | er = new TypeError('Invalid non-string/buffer chunk');
|
5917 | }
|
5918 | return er;
|
5919 | }
|
5920 |
|
5921 |
|
5922 |
|
5923 |
|
5924 |
|
5925 |
|
5926 |
|
5927 |
|
5928 | function needMoreData(state) {
|
5929 | return !state.ended && (state.needReadable || state.length < state.highWaterMark || state.length === 0);
|
5930 | }
|
5931 |
|
5932 | Readable.prototype.isPaused = function () {
|
5933 | return this._readableState.flowing === false;
|
5934 | };
|
5935 |
|
5936 |
|
5937 | Readable.prototype.setEncoding = function (enc) {
|
5938 | if (!StringDecoder) StringDecoder = _dereq_(86).StringDecoder;
|
5939 | this._readableState.decoder = new StringDecoder(enc);
|
5940 | this._readableState.encoding = enc;
|
5941 | return this;
|
5942 | };
|
5943 |
|
5944 |
|
5945 | var MAX_HWM = 0x800000;
|
5946 | function computeNewHighWaterMark(n) {
|
5947 | if (n >= MAX_HWM) {
|
5948 | n = MAX_HWM;
|
5949 | } else {
|
5950 |
|
5951 |
|
5952 | n--;
|
5953 | n |= n >>> 1;
|
5954 | n |= n >>> 2;
|
5955 | n |= n >>> 4;
|
5956 | n |= n >>> 8;
|
5957 | n |= n >>> 16;
|
5958 | n++;
|
5959 | }
|
5960 | return n;
|
5961 | }
|
5962 |
|
5963 |
|
5964 |
|
5965 | function howMuchToRead(n, state) {
|
5966 | if (n <= 0 || state.length === 0 && state.ended) return 0;
|
5967 | if (state.objectMode) return 1;
|
5968 | if (n !== n) {
|
5969 |
|
5970 | if (state.flowing && state.length) return state.buffer.head.data.length;else return state.length;
|
5971 | }
|
5972 |
|
5973 | if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n);
|
5974 | if (n <= state.length) return n;
|
5975 |
|
5976 | if (!state.ended) {
|
5977 | state.needReadable = true;
|
5978 | return 0;
|
5979 | }
|
5980 | return state.length;
|
5981 | }
|
5982 |
|
5983 |
|
5984 | Readable.prototype.read = function (n) {
|
5985 | debug('read', n);
|
5986 | n = parseInt(n, 10);
|
5987 | var state = this._readableState;
|
5988 | var nOrig = n;
|
5989 |
|
5990 | if (n !== 0) state.emittedReadable = false;
|
5991 |
|
5992 |
|
5993 |
|
5994 |
|
5995 | if (n === 0 && state.needReadable && (state.length >= state.highWaterMark || state.ended)) {
|
5996 | debug('read: emitReadable', state.length, state.ended);
|
5997 | if (state.length === 0 && state.ended) endReadable(this);else emitReadable(this);
|
5998 | return null;
|
5999 | }
|
6000 |
|
6001 | n = howMuchToRead(n, state);
|
6002 |
|
6003 |
|
6004 | if (n === 0 && state.ended) {
|
6005 | if (state.length === 0) endReadable(this);
|
6006 | return null;
|
6007 | }
|
6008 |
|
6009 |
|
6010 |
|
6011 |
|
6012 |
|
6013 |
|
6014 |
|
6015 |
|
6016 |
|
6017 |
|
6018 |
|
6019 |
|
6020 |
|
6021 |
|
6022 |
|
6023 |
|
6024 |
|
6025 |
|
6026 |
|
6027 |
|
6028 |
|
6029 |
|
6030 |
|
6031 |
|
6032 | var doRead = state.needReadable;
|
6033 | debug('need readable', doRead);
|
6034 |
|
6035 |
|
6036 | if (state.length === 0 || state.length - n < state.highWaterMark) {
|
6037 | doRead = true;
|
6038 | debug('length less than watermark', doRead);
|
6039 | }
|
6040 |
|
6041 |
|
6042 |
|
6043 | if (state.ended || state.reading) {
|
6044 | doRead = false;
|
6045 | debug('reading or ended', doRead);
|
6046 | } else if (doRead) {
|
6047 | debug('do read');
|
6048 | state.reading = true;
|
6049 | state.sync = true;
|
6050 |
|
6051 | if (state.length === 0) state.needReadable = true;
|
6052 |
|
6053 | this._read(state.highWaterMark);
|
6054 | state.sync = false;
|
6055 |
|
6056 |
|
6057 | if (!state.reading) n = howMuchToRead(nOrig, state);
|
6058 | }
|
6059 |
|
6060 | var ret;
|
6061 | if (n > 0) ret = fromList(n, state);else ret = null;
|
6062 |
|
6063 | if (ret === null) {
|
6064 | state.needReadable = true;
|
6065 | n = 0;
|
6066 | } else {
|
6067 | state.length -= n;
|
6068 | }
|
6069 |
|
6070 | if (state.length === 0) {
|
6071 |
|
6072 |
|
6073 | if (!state.ended) state.needReadable = true;
|
6074 |
|
6075 |
|
6076 | if (nOrig !== n && state.ended) endReadable(this);
|
6077 | }
|
6078 |
|
6079 | if (ret !== null) this.emit('data', ret);
|
6080 |
|
6081 | return ret;
|
6082 | };
|
6083 |
|
6084 | function onEofChunk(stream, state) {
|
6085 | if (state.ended) return;
|
6086 | if (state.decoder) {
|
6087 | var chunk = state.decoder.end();
|
6088 | if (chunk && chunk.length) {
|
6089 | state.buffer.push(chunk);
|
6090 | state.length += state.objectMode ? 1 : chunk.length;
|
6091 | }
|
6092 | }
|
6093 | state.ended = true;
|
6094 |
|
6095 |
|
6096 | emitReadable(stream);
|
6097 | }
|
6098 |
|
6099 |
|
6100 |
|
6101 |
|
6102 | function emitReadable(stream) {
|
6103 | var state = stream._readableState;
|
6104 | state.needReadable = false;
|
6105 | if (!state.emittedReadable) {
|
6106 | debug('emitReadable', state.flowing);
|
6107 | state.emittedReadable = true;
|
6108 | if (state.sync) pna.nextTick(emitReadable_, stream);else emitReadable_(stream);
|
6109 | }
|
6110 | }
|
6111 |
|
6112 | function emitReadable_(stream) {
|
6113 | debug('emit readable');
|
6114 | stream.emit('readable');
|
6115 | flow(stream);
|
6116 | }
|
6117 |
|
6118 |
|
6119 |
|
6120 |
|
6121 |
|
6122 |
|
6123 |
|
6124 | function maybeReadMore(stream, state) {
|
6125 | if (!state.readingMore) {
|
6126 | state.readingMore = true;
|
6127 | pna.nextTick(maybeReadMore_, stream, state);
|
6128 | }
|
6129 | }
|
6130 |
|
6131 | function maybeReadMore_(stream, state) {
|
6132 | var len = state.length;
|
6133 | while (!state.reading && !state.flowing && !state.ended && state.length < state.highWaterMark) {
|
6134 | debug('maybeReadMore read 0');
|
6135 | stream.read(0);
|
6136 | if (len === state.length)
|
6137 |
|
6138 | break;else len = state.length;
|
6139 | }
|
6140 | state.readingMore = false;
|
6141 | }
|
6142 |
|
6143 |
|
6144 |
|
6145 |
|
6146 |
|
6147 | Readable.prototype._read = function (n) {
|
6148 | this.emit('error', new Error('_read() is not implemented'));
|
6149 | };
|
6150 |
|
6151 | Readable.prototype.pipe = function (dest, pipeOpts) {
|
6152 | var src = this;
|
6153 | var state = this._readableState;
|
6154 |
|
6155 | switch (state.pipesCount) {
|
6156 | case 0:
|
6157 | state.pipes = dest;
|
6158 | break;
|
6159 | case 1:
|
6160 | state.pipes = [state.pipes, dest];
|
6161 | break;
|
6162 | default:
|
6163 | state.pipes.push(dest);
|
6164 | break;
|
6165 | }
|
6166 | state.pipesCount += 1;
|
6167 | debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts);
|
6168 |
|
6169 | var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr;
|
6170 |
|
6171 | var endFn = doEnd ? onend : unpipe;
|
6172 | if (state.endEmitted) pna.nextTick(endFn);else src.once('end', endFn);
|
6173 |
|
6174 | dest.on('unpipe', onunpipe);
|
6175 | function onunpipe(readable, unpipeInfo) {
|
6176 | debug('onunpipe');
|
6177 | if (readable === src) {
|
6178 | if (unpipeInfo && unpipeInfo.hasUnpiped === false) {
|
6179 | unpipeInfo.hasUnpiped = true;
|
6180 | cleanup();
|
6181 | }
|
6182 | }
|
6183 | }
|
6184 |
|
6185 | function onend() {
|
6186 | debug('onend');
|
6187 | dest.end();
|
6188 | }
|
6189 |
|
6190 |
|
6191 |
|
6192 |
|
6193 |
|
6194 | var ondrain = pipeOnDrain(src);
|
6195 | dest.on('drain', ondrain);
|
6196 |
|
6197 | var cleanedUp = false;
|
6198 | function cleanup() {
|
6199 | debug('cleanup');
|
6200 |
|
6201 | dest.removeListener('close', onclose);
|
6202 | dest.removeListener('finish', onfinish);
|
6203 | dest.removeListener('drain', ondrain);
|
6204 | dest.removeListener('error', onerror);
|
6205 | dest.removeListener('unpipe', onunpipe);
|
6206 | src.removeListener('end', onend);
|
6207 | src.removeListener('end', unpipe);
|
6208 | src.removeListener('data', ondata);
|
6209 |
|
6210 | cleanedUp = true;
|
6211 |
|
6212 |
|
6213 |
|
6214 |
|
6215 |
|
6216 |
|
6217 | if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain();
|
6218 | }
|
6219 |
|
6220 |
|
6221 |
|
6222 |
|
6223 |
|
6224 | var increasedAwaitDrain = false;
|
6225 | src.on('data', ondata);
|
6226 | function ondata(chunk) {
|
6227 | debug('ondata');
|
6228 | increasedAwaitDrain = false;
|
6229 | var ret = dest.write(chunk);
|
6230 | if (false === ret && !increasedAwaitDrain) {
|
6231 |
|
6232 |
|
6233 |
|
6234 |
|
6235 | if ((state.pipesCount === 1 && state.pipes === dest || state.pipesCount > 1 && indexOf(state.pipes, dest) !== -1) && !cleanedUp) {
|
6236 | debug('false write response, pause', src._readableState.awaitDrain);
|
6237 | src._readableState.awaitDrain++;
|
6238 | increasedAwaitDrain = true;
|
6239 | }
|
6240 | src.pause();
|
6241 | }
|
6242 | }
|
6243 |
|
6244 |
|
6245 |
|
6246 | function onerror(er) {
|
6247 | debug('onerror', er);
|
6248 | unpipe();
|
6249 | dest.removeListener('error', onerror);
|
6250 | if (EElistenerCount(dest, 'error') === 0) dest.emit('error', er);
|
6251 | }
|
6252 |
|
6253 |
|
6254 | prependListener(dest, 'error', onerror);
|
6255 |
|
6256 |
|
6257 | function onclose() {
|
6258 | dest.removeListener('finish', onfinish);
|
6259 | unpipe();
|
6260 | }
|
6261 | dest.once('close', onclose);
|
6262 | function onfinish() {
|
6263 | debug('onfinish');
|
6264 | dest.removeListener('close', onclose);
|
6265 | unpipe();
|
6266 | }
|
6267 | dest.once('finish', onfinish);
|
6268 |
|
6269 | function unpipe() {
|
6270 | debug('unpipe');
|
6271 | src.unpipe(dest);
|
6272 | }
|
6273 |
|
6274 |
|
6275 | dest.emit('pipe', src);
|
6276 |
|
6277 |
|
6278 | if (!state.flowing) {
|
6279 | debug('pipe resume');
|
6280 | src.resume();
|
6281 | }
|
6282 |
|
6283 | return dest;
|
6284 | };
|
6285 |
|
6286 | function pipeOnDrain(src) {
|
6287 | return function () {
|
6288 | var state = src._readableState;
|
6289 | debug('pipeOnDrain', state.awaitDrain);
|
6290 | if (state.awaitDrain) state.awaitDrain--;
|
6291 | if (state.awaitDrain === 0 && EElistenerCount(src, 'data')) {
|
6292 | state.flowing = true;
|
6293 | flow(src);
|
6294 | }
|
6295 | };
|
6296 | }
|
6297 |
|
6298 | Readable.prototype.unpipe = function (dest) {
|
6299 | var state = this._readableState;
|
6300 | var unpipeInfo = { hasUnpiped: false };
|
6301 |
|
6302 |
|
6303 | if (state.pipesCount === 0) return this;
|
6304 |
|
6305 |
|
6306 | if (state.pipesCount === 1) {
|
6307 |
|
6308 | if (dest && dest !== state.pipes) return this;
|
6309 |
|
6310 | if (!dest) dest = state.pipes;
|
6311 |
|
6312 |
|
6313 | state.pipes = null;
|
6314 | state.pipesCount = 0;
|
6315 | state.flowing = false;
|
6316 | if (dest) dest.emit('unpipe', this, unpipeInfo);
|
6317 | return this;
|
6318 | }
|
6319 |
|
6320 |
|
6321 |
|
6322 | if (!dest) {
|
6323 |
|
6324 | var dests = state.pipes;
|
6325 | var len = state.pipesCount;
|
6326 | state.pipes = null;
|
6327 | state.pipesCount = 0;
|
6328 | state.flowing = false;
|
6329 |
|
6330 | for (var i = 0; i < len; i++) {
|
6331 | dests[i].emit('unpipe', this, unpipeInfo);
|
6332 | }return this;
|
6333 | }
|
6334 |
|
6335 |
|
6336 | var index = indexOf(state.pipes, dest);
|
6337 | if (index === -1) return this;
|
6338 |
|
6339 | state.pipes.splice(index, 1);
|
6340 | state.pipesCount -= 1;
|
6341 | if (state.pipesCount === 1) state.pipes = state.pipes[0];
|
6342 |
|
6343 | dest.emit('unpipe', this, unpipeInfo);
|
6344 |
|
6345 | return this;
|
6346 | };
|
6347 |
|
6348 |
|
6349 |
|
6350 | Readable.prototype.on = function (ev, fn) {
|
6351 | var res = Stream.prototype.on.call(this, ev, fn);
|
6352 |
|
6353 | if (ev === 'data') {
|
6354 |
|
6355 | if (this._readableState.flowing !== false) this.resume();
|
6356 | } else if (ev === 'readable') {
|
6357 | var state = this._readableState;
|
6358 | if (!state.endEmitted && !state.readableListening) {
|
6359 | state.readableListening = state.needReadable = true;
|
6360 | state.emittedReadable = false;
|
6361 | if (!state.reading) {
|
6362 | pna.nextTick(nReadingNextTick, this);
|
6363 | } else if (state.length) {
|
6364 | emitReadable(this);
|
6365 | }
|
6366 | }
|
6367 | }
|
6368 |
|
6369 | return res;
|
6370 | };
|
6371 | Readable.prototype.addListener = Readable.prototype.on;
|
6372 |
|
6373 | function nReadingNextTick(self) {
|
6374 | debug('readable nexttick read 0');
|
6375 | self.read(0);
|
6376 | }
|
6377 |
|
6378 |
|
6379 |
|
6380 | Readable.prototype.resume = function () {
|
6381 | var state = this._readableState;
|
6382 | if (!state.flowing) {
|
6383 | debug('resume');
|
6384 | state.flowing = true;
|
6385 | resume(this, state);
|
6386 | }
|
6387 | return this;
|
6388 | };
|
6389 |
|
6390 | function resume(stream, state) {
|
6391 | if (!state.resumeScheduled) {
|
6392 | state.resumeScheduled = true;
|
6393 | pna.nextTick(resume_, stream, state);
|
6394 | }
|
6395 | }
|
6396 |
|
6397 | function resume_(stream, state) {
|
6398 | if (!state.reading) {
|
6399 | debug('resume read 0');
|
6400 | stream.read(0);
|
6401 | }
|
6402 |
|
6403 | state.resumeScheduled = false;
|
6404 | state.awaitDrain = 0;
|
6405 | stream.emit('resume');
|
6406 | flow(stream);
|
6407 | if (state.flowing && !state.reading) stream.read(0);
|
6408 | }
|
6409 |
|
6410 | Readable.prototype.pause = function () {
|
6411 | debug('call pause flowing=%j', this._readableState.flowing);
|
6412 | if (false !== this._readableState.flowing) {
|
6413 | debug('pause');
|
6414 | this._readableState.flowing = false;
|
6415 | this.emit('pause');
|
6416 | }
|
6417 | return this;
|
6418 | };
|
6419 |
|
6420 | function flow(stream) {
|
6421 | var state = stream._readableState;
|
6422 | debug('flow', state.flowing);
|
6423 | while (state.flowing && stream.read() !== null) {}
|
6424 | }
|
6425 |
|
6426 |
|
6427 |
|
6428 |
|
6429 | Readable.prototype.wrap = function (stream) {
|
6430 | var _this = this;
|
6431 |
|
6432 | var state = this._readableState;
|
6433 | var paused = false;
|
6434 |
|
6435 | stream.on('end', function () {
|
6436 | debug('wrapped end');
|
6437 | if (state.decoder && !state.ended) {
|
6438 | var chunk = state.decoder.end();
|
6439 | if (chunk && chunk.length) _this.push(chunk);
|
6440 | }
|
6441 |
|
6442 | _this.push(null);
|
6443 | });
|
6444 |
|
6445 | stream.on('data', function (chunk) {
|
6446 | debug('wrapped data');
|
6447 | if (state.decoder) chunk = state.decoder.write(chunk);
|
6448 |
|
6449 |
|
6450 | if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return;
|
6451 |
|
6452 | var ret = _this.push(chunk);
|
6453 | if (!ret) {
|
6454 | paused = true;
|
6455 | stream.pause();
|
6456 | }
|
6457 | });
|
6458 |
|
6459 |
|
6460 |
|
6461 | for (var i in stream) {
|
6462 | if (this[i] === undefined && typeof stream[i] === 'function') {
|
6463 | this[i] = function (method) {
|
6464 | return function () {
|
6465 | return stream[method].apply(stream, arguments);
|
6466 | };
|
6467 | }(i);
|
6468 | }
|
6469 | }
|
6470 |
|
6471 |
|
6472 | for (var n = 0; n < kProxyEvents.length; n++) {
|
6473 | stream.on(kProxyEvents[n], this.emit.bind(this, kProxyEvents[n]));
|
6474 | }
|
6475 |
|
6476 |
|
6477 |
|
6478 | this._read = function (n) {
|
6479 | debug('wrapped _read', n);
|
6480 | if (paused) {
|
6481 | paused = false;
|
6482 | stream.resume();
|
6483 | }
|
6484 | };
|
6485 |
|
6486 | return this;
|
6487 | };
|
6488 |
|
6489 | Object.defineProperty(Readable.prototype, 'readableHighWaterMark', {
|
6490 |
|
6491 |
|
6492 |
|
6493 | enumerable: false,
|
6494 | get: function () {
|
6495 | return this._readableState.highWaterMark;
|
6496 | }
|
6497 | });
|
6498 |
|
6499 |
|
6500 | Readable._fromList = fromList;
|
6501 |
|
6502 |
|
6503 |
|
6504 |
|
6505 |
|
6506 | function fromList(n, state) {
|
6507 |
|
6508 | if (state.length === 0) return null;
|
6509 |
|
6510 | var ret;
|
6511 | if (state.objectMode) ret = state.buffer.shift();else if (!n || n >= state.length) {
|
6512 |
|
6513 | 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);
|
6514 | state.buffer.clear();
|
6515 | } else {
|
6516 |
|
6517 | ret = fromListPartial(n, state.buffer, state.decoder);
|
6518 | }
|
6519 |
|
6520 | return ret;
|
6521 | }
|
6522 |
|
6523 |
|
6524 |
|
6525 |
|
6526 | function fromListPartial(n, list, hasStrings) {
|
6527 | var ret;
|
6528 | if (n < list.head.data.length) {
|
6529 |
|
6530 | ret = list.head.data.slice(0, n);
|
6531 | list.head.data = list.head.data.slice(n);
|
6532 | } else if (n === list.head.data.length) {
|
6533 |
|
6534 | ret = list.shift();
|
6535 | } else {
|
6536 |
|
6537 | ret = hasStrings ? copyFromBufferString(n, list) : copyFromBuffer(n, list);
|
6538 | }
|
6539 | return ret;
|
6540 | }
|
6541 |
|
6542 |
|
6543 |
|
6544 |
|
6545 |
|
6546 | function copyFromBufferString(n, list) {
|
6547 | var p = list.head;
|
6548 | var c = 1;
|
6549 | var ret = p.data;
|
6550 | n -= ret.length;
|
6551 | while (p = p.next) {
|
6552 | var str = p.data;
|
6553 | var nb = n > str.length ? str.length : n;
|
6554 | if (nb === str.length) ret += str;else ret += str.slice(0, n);
|
6555 | n -= nb;
|
6556 | if (n === 0) {
|
6557 | if (nb === str.length) {
|
6558 | ++c;
|
6559 | if (p.next) list.head = p.next;else list.head = list.tail = null;
|
6560 | } else {
|
6561 | list.head = p;
|
6562 | p.data = str.slice(nb);
|
6563 | }
|
6564 | break;
|
6565 | }
|
6566 | ++c;
|
6567 | }
|
6568 | list.length -= c;
|
6569 | return ret;
|
6570 | }
|
6571 |
|
6572 |
|
6573 |
|
6574 |
|
6575 | function copyFromBuffer(n, list) {
|
6576 | var ret = Buffer.allocUnsafe(n);
|
6577 | var p = list.head;
|
6578 | var c = 1;
|
6579 | p.data.copy(ret);
|
6580 | n -= p.data.length;
|
6581 | while (p = p.next) {
|
6582 | var buf = p.data;
|
6583 | var nb = n > buf.length ? buf.length : n;
|
6584 | buf.copy(ret, ret.length - n, 0, nb);
|
6585 | n -= nb;
|
6586 | if (n === 0) {
|
6587 | if (nb === buf.length) {
|
6588 | ++c;
|
6589 | if (p.next) list.head = p.next;else list.head = list.tail = null;
|
6590 | } else {
|
6591 | list.head = p;
|
6592 | p.data = buf.slice(nb);
|
6593 | }
|
6594 | break;
|
6595 | }
|
6596 | ++c;
|
6597 | }
|
6598 | list.length -= c;
|
6599 | return ret;
|
6600 | }
|
6601 |
|
6602 | function endReadable(stream) {
|
6603 | var state = stream._readableState;
|
6604 |
|
6605 |
|
6606 |
|
6607 | if (state.length > 0) throw new Error('"endReadable()" called on non-empty stream');
|
6608 |
|
6609 | if (!state.endEmitted) {
|
6610 | state.ended = true;
|
6611 | pna.nextTick(endReadableNT, state, stream);
|
6612 | }
|
6613 | }
|
6614 |
|
6615 | function endReadableNT(state, stream) {
|
6616 |
|
6617 | if (!state.endEmitted && state.length === 0) {
|
6618 | state.endEmitted = true;
|
6619 | stream.readable = false;
|
6620 | stream.emit('end');
|
6621 | }
|
6622 | }
|
6623 |
|
6624 | function indexOf(xs, x) {
|
6625 | for (var i = 0, l = xs.length; i < l; i++) {
|
6626 | if (xs[i] === x) return i;
|
6627 | }
|
6628 | return -1;
|
6629 | }
|
6630 | }).call(this,_dereq_(60),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
6631 | },{"10":10,"13":13,"18":18,"24":24,"26":26,"30":30,"35":35,"36":36,"37":37,"59":59,"60":60,"70":70,"86":86}],33:[function(_dereq_,module,exports){
|
6632 |
|
6633 |
|
6634 |
|
6635 |
|
6636 |
|
6637 |
|
6638 |
|
6639 |
|
6640 |
|
6641 |
|
6642 |
|
6643 |
|
6644 |
|
6645 |
|
6646 |
|
6647 |
|
6648 |
|
6649 |
|
6650 |
|
6651 |
|
6652 |
|
6653 |
|
6654 |
|
6655 |
|
6656 |
|
6657 |
|
6658 |
|
6659 |
|
6660 |
|
6661 |
|
6662 |
|
6663 |
|
6664 |
|
6665 |
|
6666 |
|
6667 |
|
6668 |
|
6669 |
|
6670 |
|
6671 |
|
6672 |
|
6673 |
|
6674 |
|
6675 |
|
6676 |
|
6677 |
|
6678 |
|
6679 |
|
6680 |
|
6681 |
|
6682 |
|
6683 |
|
6684 |
|
6685 |
|
6686 |
|
6687 |
|
6688 |
|
6689 |
|
6690 |
|
6691 |
|
6692 |
|
6693 |
|
6694 |
|
6695 | 'use strict';
|
6696 |
|
6697 | module.exports = Transform;
|
6698 |
|
6699 | var Duplex = _dereq_(30);
|
6700 |
|
6701 |
|
6702 | var util = _dereq_(13);
|
6703 | util.inherits = _dereq_(24);
|
6704 |
|
6705 |
|
6706 | util.inherits(Transform, Duplex);
|
6707 |
|
6708 | function afterTransform(er, data) {
|
6709 | var ts = this._transformState;
|
6710 | ts.transforming = false;
|
6711 |
|
6712 | var cb = ts.writecb;
|
6713 |
|
6714 | if (!cb) {
|
6715 | return this.emit('error', new Error('write callback called multiple times'));
|
6716 | }
|
6717 |
|
6718 | ts.writechunk = null;
|
6719 | ts.writecb = null;
|
6720 |
|
6721 | if (data != null)
|
6722 | this.push(data);
|
6723 |
|
6724 | cb(er);
|
6725 |
|
6726 | var rs = this._readableState;
|
6727 | rs.reading = false;
|
6728 | if (rs.needReadable || rs.length < rs.highWaterMark) {
|
6729 | this._read(rs.highWaterMark);
|
6730 | }
|
6731 | }
|
6732 |
|
6733 | function Transform(options) {
|
6734 | if (!(this instanceof Transform)) return new Transform(options);
|
6735 |
|
6736 | Duplex.call(this, options);
|
6737 |
|
6738 | this._transformState = {
|
6739 | afterTransform: afterTransform.bind(this),
|
6740 | needTransform: false,
|
6741 | transforming: false,
|
6742 | writecb: null,
|
6743 | writechunk: null,
|
6744 | writeencoding: null
|
6745 | };
|
6746 |
|
6747 |
|
6748 | this._readableState.needReadable = true;
|
6749 |
|
6750 |
|
6751 |
|
6752 |
|
6753 | this._readableState.sync = false;
|
6754 |
|
6755 | if (options) {
|
6756 | if (typeof options.transform === 'function') this._transform = options.transform;
|
6757 |
|
6758 | if (typeof options.flush === 'function') this._flush = options.flush;
|
6759 | }
|
6760 |
|
6761 |
|
6762 | this.on('prefinish', prefinish);
|
6763 | }
|
6764 |
|
6765 | function prefinish() {
|
6766 | var _this = this;
|
6767 |
|
6768 | if (typeof this._flush === 'function') {
|
6769 | this._flush(function (er, data) {
|
6770 | done(_this, er, data);
|
6771 | });
|
6772 | } else {
|
6773 | done(this, null, null);
|
6774 | }
|
6775 | }
|
6776 |
|
6777 | Transform.prototype.push = function (chunk, encoding) {
|
6778 | this._transformState.needTransform = false;
|
6779 | return Duplex.prototype.push.call(this, chunk, encoding);
|
6780 | };
|
6781 |
|
6782 |
|
6783 |
|
6784 |
|
6785 |
|
6786 |
|
6787 |
|
6788 |
|
6789 |
|
6790 |
|
6791 |
|
6792 | Transform.prototype._transform = function (chunk, encoding, cb) {
|
6793 | throw new Error('_transform() is not implemented');
|
6794 | };
|
6795 |
|
6796 | Transform.prototype._write = function (chunk, encoding, cb) {
|
6797 | var ts = this._transformState;
|
6798 | ts.writecb = cb;
|
6799 | ts.writechunk = chunk;
|
6800 | ts.writeencoding = encoding;
|
6801 | if (!ts.transforming) {
|
6802 | var rs = this._readableState;
|
6803 | if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) this._read(rs.highWaterMark);
|
6804 | }
|
6805 | };
|
6806 |
|
6807 |
|
6808 |
|
6809 |
|
6810 | Transform.prototype._read = function (n) {
|
6811 | var ts = this._transformState;
|
6812 |
|
6813 | if (ts.writechunk !== null && ts.writecb && !ts.transforming) {
|
6814 | ts.transforming = true;
|
6815 | this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
|
6816 | } else {
|
6817 |
|
6818 |
|
6819 | ts.needTransform = true;
|
6820 | }
|
6821 | };
|
6822 |
|
6823 | Transform.prototype._destroy = function (err, cb) {
|
6824 | var _this2 = this;
|
6825 |
|
6826 | Duplex.prototype._destroy.call(this, err, function (err2) {
|
6827 | cb(err2);
|
6828 | _this2.emit('close');
|
6829 | });
|
6830 | };
|
6831 |
|
6832 | function done(stream, er, data) {
|
6833 | if (er) return stream.emit('error', er);
|
6834 |
|
6835 | if (data != null)
|
6836 | stream.push(data);
|
6837 |
|
6838 |
|
6839 |
|
6840 | if (stream._writableState.length) throw new Error('Calling transform done when ws.length != 0');
|
6841 |
|
6842 | if (stream._transformState.transforming) throw new Error('Calling transform done when still transforming');
|
6843 |
|
6844 | return stream.push(null);
|
6845 | }
|
6846 | },{"13":13,"24":24,"30":30}],34:[function(_dereq_,module,exports){
|
6847 | (function (process,global,setImmediate){
|
6848 |
|
6849 |
|
6850 |
|
6851 |
|
6852 |
|
6853 |
|
6854 |
|
6855 |
|
6856 |
|
6857 |
|
6858 |
|
6859 |
|
6860 |
|
6861 |
|
6862 |
|
6863 |
|
6864 |
|
6865 |
|
6866 |
|
6867 |
|
6868 |
|
6869 |
|
6870 |
|
6871 |
|
6872 |
|
6873 | 'use strict';
|
6874 |
|
6875 |
|
6876 |
|
6877 | var pna = _dereq_(59);
|
6878 |
|
6879 |
|
6880 | module.exports = Writable;
|
6881 |
|
6882 |
|
6883 | function WriteReq(chunk, encoding, cb) {
|
6884 | this.chunk = chunk;
|
6885 | this.encoding = encoding;
|
6886 | this.callback = cb;
|
6887 | this.next = null;
|
6888 | }
|
6889 |
|
6890 |
|
6891 |
|
6892 | function CorkedRequest(state) {
|
6893 | var _this = this;
|
6894 |
|
6895 | this.next = null;
|
6896 | this.entry = null;
|
6897 | this.finish = function () {
|
6898 | onCorkedFinish(_this, state);
|
6899 | };
|
6900 | }
|
6901 |
|
6902 |
|
6903 |
|
6904 | var asyncWrite = !process.browser && ['v0.10', 'v0.9.'].indexOf(process.version.slice(0, 5)) > -1 ? setImmediate : pna.nextTick;
|
6905 |
|
6906 |
|
6907 |
|
6908 | var Duplex;
|
6909 |
|
6910 |
|
6911 | Writable.WritableState = WritableState;
|
6912 |
|
6913 |
|
6914 | var util = _dereq_(13);
|
6915 | util.inherits = _dereq_(24);
|
6916 |
|
6917 |
|
6918 |
|
6919 | var internalUtil = {
|
6920 | deprecate: _dereq_(101)
|
6921 | };
|
6922 |
|
6923 |
|
6924 |
|
6925 | var Stream = _dereq_(37);
|
6926 |
|
6927 |
|
6928 |
|
6929 |
|
6930 | var Buffer = _dereq_(70).Buffer;
|
6931 | var OurUint8Array = global.Uint8Array || function () {};
|
6932 | function _uint8ArrayToBuffer(chunk) {
|
6933 | return Buffer.from(chunk);
|
6934 | }
|
6935 | function _isUint8Array(obj) {
|
6936 | return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
|
6937 | }
|
6938 |
|
6939 |
|
6940 |
|
6941 | var destroyImpl = _dereq_(36);
|
6942 |
|
6943 | util.inherits(Writable, Stream);
|
6944 |
|
6945 | function nop() {}
|
6946 |
|
6947 | function WritableState(options, stream) {
|
6948 | Duplex = Duplex || _dereq_(30);
|
6949 |
|
6950 | options = options || {};
|
6951 |
|
6952 |
|
6953 |
|
6954 |
|
6955 |
|
6956 |
|
6957 | var isDuplex = stream instanceof Duplex;
|
6958 |
|
6959 |
|
6960 |
|
6961 | this.objectMode = !!options.objectMode;
|
6962 |
|
6963 | if (isDuplex) this.objectMode = this.objectMode || !!options.writableObjectMode;
|
6964 |
|
6965 |
|
6966 |
|
6967 |
|
6968 | var hwm = options.highWaterMark;
|
6969 | var writableHwm = options.writableHighWaterMark;
|
6970 | var defaultHwm = this.objectMode ? 16 : 16 * 1024;
|
6971 |
|
6972 | if (hwm || hwm === 0) this.highWaterMark = hwm;else if (isDuplex && (writableHwm || writableHwm === 0)) this.highWaterMark = writableHwm;else this.highWaterMark = defaultHwm;
|
6973 |
|
6974 |
|
6975 | this.highWaterMark = Math.floor(this.highWaterMark);
|
6976 |
|
6977 |
|
6978 | this.finalCalled = false;
|
6979 |
|
6980 |
|
6981 | this.needDrain = false;
|
6982 |
|
6983 | this.ending = false;
|
6984 |
|
6985 | this.ended = false;
|
6986 |
|
6987 | this.finished = false;
|
6988 |
|
6989 |
|
6990 | this.destroyed = false;
|
6991 |
|
6992 |
|
6993 |
|
6994 |
|
6995 | var noDecode = options.decodeStrings === false;
|
6996 | this.decodeStrings = !noDecode;
|
6997 |
|
6998 |
|
6999 |
|
7000 |
|
7001 | this.defaultEncoding = options.defaultEncoding || 'utf8';
|
7002 |
|
7003 |
|
7004 |
|
7005 |
|
7006 | this.length = 0;
|
7007 |
|
7008 |
|
7009 | this.writing = false;
|
7010 |
|
7011 |
|
7012 | this.corked = 0;
|
7013 |
|
7014 |
|
7015 |
|
7016 |
|
7017 |
|
7018 | this.sync = true;
|
7019 |
|
7020 |
|
7021 |
|
7022 |
|
7023 | this.bufferProcessing = false;
|
7024 |
|
7025 |
|
7026 | this.onwrite = function (er) {
|
7027 | onwrite(stream, er);
|
7028 | };
|
7029 |
|
7030 |
|
7031 | this.writecb = null;
|
7032 |
|
7033 |
|
7034 | this.writelen = 0;
|
7035 |
|
7036 | this.bufferedRequest = null;
|
7037 | this.lastBufferedRequest = null;
|
7038 |
|
7039 |
|
7040 |
|
7041 | this.pendingcb = 0;
|
7042 |
|
7043 |
|
7044 |
|
7045 | this.prefinished = false;
|
7046 |
|
7047 |
|
7048 | this.errorEmitted = false;
|
7049 |
|
7050 |
|
7051 | this.bufferedRequestCount = 0;
|
7052 |
|
7053 |
|
7054 |
|
7055 | this.corkedRequestsFree = new CorkedRequest(this);
|
7056 | }
|
7057 |
|
7058 | WritableState.prototype.getBuffer = function getBuffer() {
|
7059 | var current = this.bufferedRequest;
|
7060 | var out = [];
|
7061 | while (current) {
|
7062 | out.push(current);
|
7063 | current = current.next;
|
7064 | }
|
7065 | return out;
|
7066 | };
|
7067 |
|
7068 | (function () {
|
7069 | try {
|
7070 | Object.defineProperty(WritableState.prototype, 'buffer', {
|
7071 | get: internalUtil.deprecate(function () {
|
7072 | return this.getBuffer();
|
7073 | }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.', 'DEP0003')
|
7074 | });
|
7075 | } catch (_) {}
|
7076 | })();
|
7077 |
|
7078 |
|
7079 |
|
7080 | var realHasInstance;
|
7081 | if (typeof Symbol === 'function' && Symbol.hasInstance && typeof Function.prototype[Symbol.hasInstance] === 'function') {
|
7082 | realHasInstance = Function.prototype[Symbol.hasInstance];
|
7083 | Object.defineProperty(Writable, Symbol.hasInstance, {
|
7084 | value: function (object) {
|
7085 | if (realHasInstance.call(this, object)) return true;
|
7086 | if (this !== Writable) return false;
|
7087 |
|
7088 | return object && object._writableState instanceof WritableState;
|
7089 | }
|
7090 | });
|
7091 | } else {
|
7092 | realHasInstance = function (object) {
|
7093 | return object instanceof this;
|
7094 | };
|
7095 | }
|
7096 |
|
7097 | function Writable(options) {
|
7098 | Duplex = Duplex || _dereq_(30);
|
7099 |
|
7100 |
|
7101 |
|
7102 |
|
7103 |
|
7104 |
|
7105 |
|
7106 |
|
7107 | if (!realHasInstance.call(Writable, this) && !(this instanceof Duplex)) {
|
7108 | return new Writable(options);
|
7109 | }
|
7110 |
|
7111 | this._writableState = new WritableState(options, this);
|
7112 |
|
7113 |
|
7114 | this.writable = true;
|
7115 |
|
7116 | if (options) {
|
7117 | if (typeof options.write === 'function') this._write = options.write;
|
7118 |
|
7119 | if (typeof options.writev === 'function') this._writev = options.writev;
|
7120 |
|
7121 | if (typeof options.destroy === 'function') this._destroy = options.destroy;
|
7122 |
|
7123 | if (typeof options.final === 'function') this._final = options.final;
|
7124 | }
|
7125 |
|
7126 | Stream.call(this);
|
7127 | }
|
7128 |
|
7129 |
|
7130 | Writable.prototype.pipe = function () {
|
7131 | this.emit('error', new Error('Cannot pipe, not readable'));
|
7132 | };
|
7133 |
|
7134 | function writeAfterEnd(stream, cb) {
|
7135 | var er = new Error('write after end');
|
7136 |
|
7137 | stream.emit('error', er);
|
7138 | pna.nextTick(cb, er);
|
7139 | }
|
7140 |
|
7141 |
|
7142 |
|
7143 |
|
7144 | function validChunk(stream, state, chunk, cb) {
|
7145 | var valid = true;
|
7146 | var er = false;
|
7147 |
|
7148 | if (chunk === null) {
|
7149 | er = new TypeError('May not write null values to stream');
|
7150 | } else if (typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
|
7151 | er = new TypeError('Invalid non-string/buffer chunk');
|
7152 | }
|
7153 | if (er) {
|
7154 | stream.emit('error', er);
|
7155 | pna.nextTick(cb, er);
|
7156 | valid = false;
|
7157 | }
|
7158 | return valid;
|
7159 | }
|
7160 |
|
7161 | Writable.prototype.write = function (chunk, encoding, cb) {
|
7162 | var state = this._writableState;
|
7163 | var ret = false;
|
7164 | var isBuf = !state.objectMode && _isUint8Array(chunk);
|
7165 |
|
7166 | if (isBuf && !Buffer.isBuffer(chunk)) {
|
7167 | chunk = _uint8ArrayToBuffer(chunk);
|
7168 | }
|
7169 |
|
7170 | if (typeof encoding === 'function') {
|
7171 | cb = encoding;
|
7172 | encoding = null;
|
7173 | }
|
7174 |
|
7175 | if (isBuf) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding;
|
7176 |
|
7177 | if (typeof cb !== 'function') cb = nop;
|
7178 |
|
7179 | if (state.ended) writeAfterEnd(this, cb);else if (isBuf || validChunk(this, state, chunk, cb)) {
|
7180 | state.pendingcb++;
|
7181 | ret = writeOrBuffer(this, state, isBuf, chunk, encoding, cb);
|
7182 | }
|
7183 |
|
7184 | return ret;
|
7185 | };
|
7186 |
|
7187 | Writable.prototype.cork = function () {
|
7188 | var state = this._writableState;
|
7189 |
|
7190 | state.corked++;
|
7191 | };
|
7192 |
|
7193 | Writable.prototype.uncork = function () {
|
7194 | var state = this._writableState;
|
7195 |
|
7196 | if (state.corked) {
|
7197 | state.corked--;
|
7198 |
|
7199 | if (!state.writing && !state.corked && !state.finished && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state);
|
7200 | }
|
7201 | };
|
7202 |
|
7203 | Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
|
7204 |
|
7205 | if (typeof encoding === 'string') encoding = encoding.toLowerCase();
|
7206 | 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);
|
7207 | this._writableState.defaultEncoding = encoding;
|
7208 | return this;
|
7209 | };
|
7210 |
|
7211 | function decodeChunk(state, chunk, encoding) {
|
7212 | if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') {
|
7213 | chunk = Buffer.from(chunk, encoding);
|
7214 | }
|
7215 | return chunk;
|
7216 | }
|
7217 |
|
7218 | Object.defineProperty(Writable.prototype, 'writableHighWaterMark', {
|
7219 |
|
7220 |
|
7221 |
|
7222 | enumerable: false,
|
7223 | get: function () {
|
7224 | return this._writableState.highWaterMark;
|
7225 | }
|
7226 | });
|
7227 |
|
7228 |
|
7229 |
|
7230 |
|
7231 | function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) {
|
7232 | if (!isBuf) {
|
7233 | var newChunk = decodeChunk(state, chunk, encoding);
|
7234 | if (chunk !== newChunk) {
|
7235 | isBuf = true;
|
7236 | encoding = 'buffer';
|
7237 | chunk = newChunk;
|
7238 | }
|
7239 | }
|
7240 | var len = state.objectMode ? 1 : chunk.length;
|
7241 |
|
7242 | state.length += len;
|
7243 |
|
7244 | var ret = state.length < state.highWaterMark;
|
7245 |
|
7246 | if (!ret) state.needDrain = true;
|
7247 |
|
7248 | if (state.writing || state.corked) {
|
7249 | var last = state.lastBufferedRequest;
|
7250 | state.lastBufferedRequest = {
|
7251 | chunk: chunk,
|
7252 | encoding: encoding,
|
7253 | isBuf: isBuf,
|
7254 | callback: cb,
|
7255 | next: null
|
7256 | };
|
7257 | if (last) {
|
7258 | last.next = state.lastBufferedRequest;
|
7259 | } else {
|
7260 | state.bufferedRequest = state.lastBufferedRequest;
|
7261 | }
|
7262 | state.bufferedRequestCount += 1;
|
7263 | } else {
|
7264 | doWrite(stream, state, false, len, chunk, encoding, cb);
|
7265 | }
|
7266 |
|
7267 | return ret;
|
7268 | }
|
7269 |
|
7270 | function doWrite(stream, state, writev, len, chunk, encoding, cb) {
|
7271 | state.writelen = len;
|
7272 | state.writecb = cb;
|
7273 | state.writing = true;
|
7274 | state.sync = true;
|
7275 | if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite);
|
7276 | state.sync = false;
|
7277 | }
|
7278 |
|
7279 | function onwriteError(stream, state, sync, er, cb) {
|
7280 | --state.pendingcb;
|
7281 |
|
7282 | if (sync) {
|
7283 |
|
7284 |
|
7285 | pna.nextTick(cb, er);
|
7286 |
|
7287 |
|
7288 | pna.nextTick(finishMaybe, stream, state);
|
7289 | stream._writableState.errorEmitted = true;
|
7290 | stream.emit('error', er);
|
7291 | } else {
|
7292 |
|
7293 |
|
7294 | cb(er);
|
7295 | stream._writableState.errorEmitted = true;
|
7296 | stream.emit('error', er);
|
7297 |
|
7298 |
|
7299 | finishMaybe(stream, state);
|
7300 | }
|
7301 | }
|
7302 |
|
7303 | function onwriteStateUpdate(state) {
|
7304 | state.writing = false;
|
7305 | state.writecb = null;
|
7306 | state.length -= state.writelen;
|
7307 | state.writelen = 0;
|
7308 | }
|
7309 |
|
7310 | function onwrite(stream, er) {
|
7311 | var state = stream._writableState;
|
7312 | var sync = state.sync;
|
7313 | var cb = state.writecb;
|
7314 |
|
7315 | onwriteStateUpdate(state);
|
7316 |
|
7317 | if (er) onwriteError(stream, state, sync, er, cb);else {
|
7318 |
|
7319 | var finished = needFinish(state);
|
7320 |
|
7321 | if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) {
|
7322 | clearBuffer(stream, state);
|
7323 | }
|
7324 |
|
7325 | if (sync) {
|
7326 |
|
7327 | asyncWrite(afterWrite, stream, state, finished, cb);
|
7328 |
|
7329 | } else {
|
7330 | afterWrite(stream, state, finished, cb);
|
7331 | }
|
7332 | }
|
7333 | }
|
7334 |
|
7335 | function afterWrite(stream, state, finished, cb) {
|
7336 | if (!finished) onwriteDrain(stream, state);
|
7337 | state.pendingcb--;
|
7338 | cb();
|
7339 | finishMaybe(stream, state);
|
7340 | }
|
7341 |
|
7342 |
|
7343 |
|
7344 |
|
7345 | function onwriteDrain(stream, state) {
|
7346 | if (state.length === 0 && state.needDrain) {
|
7347 | state.needDrain = false;
|
7348 | stream.emit('drain');
|
7349 | }
|
7350 | }
|
7351 |
|
7352 |
|
7353 | function clearBuffer(stream, state) {
|
7354 | state.bufferProcessing = true;
|
7355 | var entry = state.bufferedRequest;
|
7356 |
|
7357 | if (stream._writev && entry && entry.next) {
|
7358 |
|
7359 | var l = state.bufferedRequestCount;
|
7360 | var buffer = new Array(l);
|
7361 | var holder = state.corkedRequestsFree;
|
7362 | holder.entry = entry;
|
7363 |
|
7364 | var count = 0;
|
7365 | var allBuffers = true;
|
7366 | while (entry) {
|
7367 | buffer[count] = entry;
|
7368 | if (!entry.isBuf) allBuffers = false;
|
7369 | entry = entry.next;
|
7370 | count += 1;
|
7371 | }
|
7372 | buffer.allBuffers = allBuffers;
|
7373 |
|
7374 | doWrite(stream, state, true, state.length, buffer, '', holder.finish);
|
7375 |
|
7376 |
|
7377 |
|
7378 | state.pendingcb++;
|
7379 | state.lastBufferedRequest = null;
|
7380 | if (holder.next) {
|
7381 | state.corkedRequestsFree = holder.next;
|
7382 | holder.next = null;
|
7383 | } else {
|
7384 | state.corkedRequestsFree = new CorkedRequest(state);
|
7385 | }
|
7386 | state.bufferedRequestCount = 0;
|
7387 | } else {
|
7388 |
|
7389 | while (entry) {
|
7390 | var chunk = entry.chunk;
|
7391 | var encoding = entry.encoding;
|
7392 | var cb = entry.callback;
|
7393 | var len = state.objectMode ? 1 : chunk.length;
|
7394 |
|
7395 | doWrite(stream, state, false, len, chunk, encoding, cb);
|
7396 | entry = entry.next;
|
7397 | state.bufferedRequestCount--;
|
7398 |
|
7399 |
|
7400 |
|
7401 |
|
7402 | if (state.writing) {
|
7403 | break;
|
7404 | }
|
7405 | }
|
7406 |
|
7407 | if (entry === null) state.lastBufferedRequest = null;
|
7408 | }
|
7409 |
|
7410 | state.bufferedRequest = entry;
|
7411 | state.bufferProcessing = false;
|
7412 | }
|
7413 |
|
7414 | Writable.prototype._write = function (chunk, encoding, cb) {
|
7415 | cb(new Error('_write() is not implemented'));
|
7416 | };
|
7417 |
|
7418 | Writable.prototype._writev = null;
|
7419 |
|
7420 | Writable.prototype.end = function (chunk, encoding, cb) {
|
7421 | var state = this._writableState;
|
7422 |
|
7423 | if (typeof chunk === 'function') {
|
7424 | cb = chunk;
|
7425 | chunk = null;
|
7426 | encoding = null;
|
7427 | } else if (typeof encoding === 'function') {
|
7428 | cb = encoding;
|
7429 | encoding = null;
|
7430 | }
|
7431 |
|
7432 | if (chunk !== null && chunk !== undefined) this.write(chunk, encoding);
|
7433 |
|
7434 |
|
7435 | if (state.corked) {
|
7436 | state.corked = 1;
|
7437 | this.uncork();
|
7438 | }
|
7439 |
|
7440 |
|
7441 | if (!state.ending && !state.finished) endWritable(this, state, cb);
|
7442 | };
|
7443 |
|
7444 | function needFinish(state) {
|
7445 | return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing;
|
7446 | }
|
7447 | function callFinal(stream, state) {
|
7448 | stream._final(function (err) {
|
7449 | state.pendingcb--;
|
7450 | if (err) {
|
7451 | stream.emit('error', err);
|
7452 | }
|
7453 | state.prefinished = true;
|
7454 | stream.emit('prefinish');
|
7455 | finishMaybe(stream, state);
|
7456 | });
|
7457 | }
|
7458 | function prefinish(stream, state) {
|
7459 | if (!state.prefinished && !state.finalCalled) {
|
7460 | if (typeof stream._final === 'function') {
|
7461 | state.pendingcb++;
|
7462 | state.finalCalled = true;
|
7463 | pna.nextTick(callFinal, stream, state);
|
7464 | } else {
|
7465 | state.prefinished = true;
|
7466 | stream.emit('prefinish');
|
7467 | }
|
7468 | }
|
7469 | }
|
7470 |
|
7471 | function finishMaybe(stream, state) {
|
7472 | var need = needFinish(state);
|
7473 | if (need) {
|
7474 | prefinish(stream, state);
|
7475 | if (state.pendingcb === 0) {
|
7476 | state.finished = true;
|
7477 | stream.emit('finish');
|
7478 | }
|
7479 | }
|
7480 | return need;
|
7481 | }
|
7482 |
|
7483 | function endWritable(stream, state, cb) {
|
7484 | state.ending = true;
|
7485 | finishMaybe(stream, state);
|
7486 | if (cb) {
|
7487 | if (state.finished) pna.nextTick(cb);else stream.once('finish', cb);
|
7488 | }
|
7489 | state.ended = true;
|
7490 | stream.writable = false;
|
7491 | }
|
7492 |
|
7493 | function onCorkedFinish(corkReq, state, err) {
|
7494 | var entry = corkReq.entry;
|
7495 | corkReq.entry = null;
|
7496 | while (entry) {
|
7497 | var cb = entry.callback;
|
7498 | state.pendingcb--;
|
7499 | cb(err);
|
7500 | entry = entry.next;
|
7501 | }
|
7502 | if (state.corkedRequestsFree) {
|
7503 | state.corkedRequestsFree.next = corkReq;
|
7504 | } else {
|
7505 | state.corkedRequestsFree = corkReq;
|
7506 | }
|
7507 | }
|
7508 |
|
7509 | Object.defineProperty(Writable.prototype, 'destroyed', {
|
7510 | get: function () {
|
7511 | if (this._writableState === undefined) {
|
7512 | return false;
|
7513 | }
|
7514 | return this._writableState.destroyed;
|
7515 | },
|
7516 | set: function (value) {
|
7517 |
|
7518 |
|
7519 | if (!this._writableState) {
|
7520 | return;
|
7521 | }
|
7522 |
|
7523 |
|
7524 |
|
7525 | this._writableState.destroyed = value;
|
7526 | }
|
7527 | });
|
7528 |
|
7529 | Writable.prototype.destroy = destroyImpl.destroy;
|
7530 | Writable.prototype._undestroy = destroyImpl.undestroy;
|
7531 | Writable.prototype._destroy = function (err, cb) {
|
7532 | this.end();
|
7533 | cb(err);
|
7534 | };
|
7535 | }).call(this,_dereq_(60),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},_dereq_(99).setImmediate)
|
7536 | },{"101":101,"13":13,"24":24,"30":30,"36":36,"37":37,"59":59,"60":60,"70":70,"99":99}],35:[function(_dereq_,module,exports){
|
7537 | 'use strict';
|
7538 |
|
7539 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
7540 |
|
7541 | var Buffer = _dereq_(70).Buffer;
|
7542 | var util = _dereq_(10);
|
7543 |
|
7544 | function copyBuffer(src, target, offset) {
|
7545 | src.copy(target, offset);
|
7546 | }
|
7547 |
|
7548 | module.exports = function () {
|
7549 | function BufferList() {
|
7550 | _classCallCheck(this, BufferList);
|
7551 |
|
7552 | this.head = null;
|
7553 | this.tail = null;
|
7554 | this.length = 0;
|
7555 | }
|
7556 |
|
7557 | BufferList.prototype.push = function push(v) {
|
7558 | var entry = { data: v, next: null };
|
7559 | if (this.length > 0) this.tail.next = entry;else this.head = entry;
|
7560 | this.tail = entry;
|
7561 | ++this.length;
|
7562 | };
|
7563 |
|
7564 | BufferList.prototype.unshift = function unshift(v) {
|
7565 | var entry = { data: v, next: this.head };
|
7566 | if (this.length === 0) this.tail = entry;
|
7567 | this.head = entry;
|
7568 | ++this.length;
|
7569 | };
|
7570 |
|
7571 | BufferList.prototype.shift = function shift() {
|
7572 | if (this.length === 0) return;
|
7573 | var ret = this.head.data;
|
7574 | if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next;
|
7575 | --this.length;
|
7576 | return ret;
|
7577 | };
|
7578 |
|
7579 | BufferList.prototype.clear = function clear() {
|
7580 | this.head = this.tail = null;
|
7581 | this.length = 0;
|
7582 | };
|
7583 |
|
7584 | BufferList.prototype.join = function join(s) {
|
7585 | if (this.length === 0) return '';
|
7586 | var p = this.head;
|
7587 | var ret = '' + p.data;
|
7588 | while (p = p.next) {
|
7589 | ret += s + p.data;
|
7590 | }return ret;
|
7591 | };
|
7592 |
|
7593 | BufferList.prototype.concat = function concat(n) {
|
7594 | if (this.length === 0) return Buffer.alloc(0);
|
7595 | if (this.length === 1) return this.head.data;
|
7596 | var ret = Buffer.allocUnsafe(n >>> 0);
|
7597 | var p = this.head;
|
7598 | var i = 0;
|
7599 | while (p) {
|
7600 | copyBuffer(p.data, ret, i);
|
7601 | i += p.data.length;
|
7602 | p = p.next;
|
7603 | }
|
7604 | return ret;
|
7605 | };
|
7606 |
|
7607 | return BufferList;
|
7608 | }();
|
7609 |
|
7610 | if (util && util.inspect && util.inspect.custom) {
|
7611 | module.exports.prototype[util.inspect.custom] = function () {
|
7612 | var obj = util.inspect({ length: this.length });
|
7613 | return this.constructor.name + ' ' + obj;
|
7614 | };
|
7615 | }
|
7616 | },{"10":10,"70":70}],36:[function(_dereq_,module,exports){
|
7617 | 'use strict';
|
7618 |
|
7619 |
|
7620 |
|
7621 | var pna = _dereq_(59);
|
7622 |
|
7623 |
|
7624 |
|
7625 | function destroy(err, cb) {
|
7626 | var _this = this;
|
7627 |
|
7628 | var readableDestroyed = this._readableState && this._readableState.destroyed;
|
7629 | var writableDestroyed = this._writableState && this._writableState.destroyed;
|
7630 |
|
7631 | if (readableDestroyed || writableDestroyed) {
|
7632 | if (cb) {
|
7633 | cb(err);
|
7634 | } else if (err && (!this._writableState || !this._writableState.errorEmitted)) {
|
7635 | pna.nextTick(emitErrorNT, this, err);
|
7636 | }
|
7637 | return this;
|
7638 | }
|
7639 |
|
7640 |
|
7641 |
|
7642 |
|
7643 | if (this._readableState) {
|
7644 | this._readableState.destroyed = true;
|
7645 | }
|
7646 |
|
7647 |
|
7648 | if (this._writableState) {
|
7649 | this._writableState.destroyed = true;
|
7650 | }
|
7651 |
|
7652 | this._destroy(err || null, function (err) {
|
7653 | if (!cb && err) {
|
7654 | pna.nextTick(emitErrorNT, _this, err);
|
7655 | if (_this._writableState) {
|
7656 | _this._writableState.errorEmitted = true;
|
7657 | }
|
7658 | } else if (cb) {
|
7659 | cb(err);
|
7660 | }
|
7661 | });
|
7662 |
|
7663 | return this;
|
7664 | }
|
7665 |
|
7666 | function undestroy() {
|
7667 | if (this._readableState) {
|
7668 | this._readableState.destroyed = false;
|
7669 | this._readableState.reading = false;
|
7670 | this._readableState.ended = false;
|
7671 | this._readableState.endEmitted = false;
|
7672 | }
|
7673 |
|
7674 | if (this._writableState) {
|
7675 | this._writableState.destroyed = false;
|
7676 | this._writableState.ended = false;
|
7677 | this._writableState.ending = false;
|
7678 | this._writableState.finished = false;
|
7679 | this._writableState.errorEmitted = false;
|
7680 | }
|
7681 | }
|
7682 |
|
7683 | function emitErrorNT(self, err) {
|
7684 | self.emit('error', err);
|
7685 | }
|
7686 |
|
7687 | module.exports = {
|
7688 | destroy: destroy,
|
7689 | undestroy: undestroy
|
7690 | };
|
7691 | },{"59":59}],37:[function(_dereq_,module,exports){
|
7692 | module.exports = _dereq_(18).EventEmitter;
|
7693 |
|
7694 | },{"18":18}],38:[function(_dereq_,module,exports){
|
7695 | exports = module.exports = _dereq_(32);
|
7696 | exports.Stream = exports;
|
7697 | exports.Readable = exports;
|
7698 | exports.Writable = _dereq_(34);
|
7699 | exports.Duplex = _dereq_(30);
|
7700 | exports.Transform = _dereq_(33);
|
7701 | exports.PassThrough = _dereq_(31);
|
7702 |
|
7703 | },{"30":30,"31":31,"32":32,"33":33,"34":34}],39:[function(_dereq_,module,exports){
|
7704 | module.exports = extend
|
7705 |
|
7706 | var hasOwnProperty = Object.prototype.hasOwnProperty;
|
7707 |
|
7708 | function extend() {
|
7709 | var target = {}
|
7710 |
|
7711 | for (var i = 0; i < arguments.length; i++) {
|
7712 | var source = arguments[i]
|
7713 |
|
7714 | for (var key in source) {
|
7715 | if (hasOwnProperty.call(source, key)) {
|
7716 | target[key] = source[key]
|
7717 | }
|
7718 | }
|
7719 | }
|
7720 |
|
7721 | return target
|
7722 | }
|
7723 |
|
7724 | },{}],40:[function(_dereq_,module,exports){
|
7725 |
|
7726 |
|
7727 |
|
7728 |
|
7729 |
|
7730 |
|
7731 | var WriteError = _dereq_(49).WriteError
|
7732 | var promisify = _dereq_(42)
|
7733 |
|
7734 | function Batch (levelup) {
|
7735 | this._levelup = levelup
|
7736 | this.batch = levelup.db.batch()
|
7737 | this.ops = []
|
7738 | this.length = 0
|
7739 | }
|
7740 |
|
7741 | Batch.prototype.put = function (key, value) {
|
7742 | try {
|
7743 | this.batch.put(key, value)
|
7744 | } catch (e) {
|
7745 | throw new WriteError(e)
|
7746 | }
|
7747 |
|
7748 | this.ops.push({ type: 'put', key: key, value: value })
|
7749 | this.length++
|
7750 |
|
7751 | return this
|
7752 | }
|
7753 |
|
7754 | Batch.prototype.del = function (key) {
|
7755 | try {
|
7756 | this.batch.del(key)
|
7757 | } catch (err) {
|
7758 | throw new WriteError(err)
|
7759 | }
|
7760 |
|
7761 | this.ops.push({ type: 'del', key: key })
|
7762 | this.length++
|
7763 |
|
7764 | return this
|
7765 | }
|
7766 |
|
7767 | Batch.prototype.clear = function () {
|
7768 | try {
|
7769 | this.batch.clear()
|
7770 | } catch (err) {
|
7771 | throw new WriteError(err)
|
7772 | }
|
7773 |
|
7774 | this.ops = []
|
7775 | this.length = 0
|
7776 |
|
7777 | return this
|
7778 | }
|
7779 |
|
7780 | Batch.prototype.write = function (callback) {
|
7781 | var levelup = this._levelup
|
7782 | var ops = this.ops
|
7783 | var promise
|
7784 |
|
7785 | if (!callback) {
|
7786 | callback = promisify()
|
7787 | promise = callback.promise
|
7788 | }
|
7789 |
|
7790 | try {
|
7791 | this.batch.write(function (err) {
|
7792 | if (err) { return callback(new WriteError(err)) }
|
7793 | levelup.emit('batch', ops)
|
7794 | callback()
|
7795 | })
|
7796 | } catch (err) {
|
7797 | throw new WriteError(err)
|
7798 | }
|
7799 |
|
7800 | return promise
|
7801 | }
|
7802 |
|
7803 | module.exports = Batch
|
7804 |
|
7805 | },{"42":42,"49":49}],41:[function(_dereq_,module,exports){
|
7806 | (function (process){
|
7807 |
|
7808 |
|
7809 |
|
7810 |
|
7811 |
|
7812 |
|
7813 | var EventEmitter = _dereq_(18).EventEmitter
|
7814 | var inherits = _dereq_(103).inherits
|
7815 | var extend = _dereq_(50)
|
7816 | var DeferredLevelDOWN = _dereq_(48)
|
7817 | var IteratorStream = _dereq_(29)
|
7818 | var Batch = _dereq_(40)
|
7819 | var errors = _dereq_(49)
|
7820 | var assert = _dereq_(5)
|
7821 | var promisify = _dereq_(42)
|
7822 |
|
7823 | var WriteError = errors.WriteError
|
7824 | var ReadError = errors.ReadError
|
7825 | var NotFoundError = errors.NotFoundError
|
7826 | var OpenError = errors.OpenError
|
7827 | var InitializationError = errors.InitializationError
|
7828 |
|
7829 |
|
7830 |
|
7831 |
|
7832 |
|
7833 |
|
7834 |
|
7835 |
|
7836 |
|
7837 | function LevelUP (db, options, callback) {
|
7838 | if (!(this instanceof LevelUP)) {
|
7839 | return new LevelUP(db, options, callback)
|
7840 | }
|
7841 |
|
7842 | var error
|
7843 |
|
7844 | EventEmitter.call(this)
|
7845 | this.setMaxListeners(Infinity)
|
7846 |
|
7847 | if (typeof options === 'function') {
|
7848 | callback = options
|
7849 | options = {}
|
7850 | }
|
7851 |
|
7852 | options = options || {}
|
7853 |
|
7854 | if (!db || typeof db !== 'object') {
|
7855 | error = new InitializationError('First argument must be an abstract-leveldown compliant store')
|
7856 | if (typeof callback === 'function') {
|
7857 | return process.nextTick(callback, error)
|
7858 | }
|
7859 | throw error
|
7860 | }
|
7861 |
|
7862 | assert.equal(typeof db.status, 'string', '.status required, old abstract-leveldown')
|
7863 |
|
7864 | this.options = getOptions(options)
|
7865 | this._db = db
|
7866 | this.db = new DeferredLevelDOWN(db)
|
7867 | this.open(callback)
|
7868 | }
|
7869 |
|
7870 | LevelUP.prototype.emit = EventEmitter.prototype.emit
|
7871 | LevelUP.prototype.once = EventEmitter.prototype.once
|
7872 | inherits(LevelUP, EventEmitter)
|
7873 |
|
7874 | LevelUP.prototype.open = function (callback) {
|
7875 | var self = this
|
7876 | var promise
|
7877 |
|
7878 | if (!callback) {
|
7879 | callback = promisify()
|
7880 | promise = callback.promise
|
7881 | }
|
7882 |
|
7883 | if (this.isOpen()) {
|
7884 | process.nextTick(callback, null, self)
|
7885 | return promise
|
7886 | }
|
7887 |
|
7888 | if (this._isOpening()) {
|
7889 | this.once('open', function () { callback(null, self) })
|
7890 | return promise
|
7891 | }
|
7892 |
|
7893 | this.emit('opening')
|
7894 |
|
7895 | this.db.open(this.options, function (err) {
|
7896 | if (err) {
|
7897 | return callback(new OpenError(err))
|
7898 | }
|
7899 | self.db = self._db
|
7900 | callback(null, self)
|
7901 | self.emit('open')
|
7902 | self.emit('ready')
|
7903 | })
|
7904 |
|
7905 | return promise
|
7906 | }
|
7907 |
|
7908 | LevelUP.prototype.close = function (callback) {
|
7909 | var self = this
|
7910 | var promise
|
7911 |
|
7912 | if (!callback) {
|
7913 | callback = promisify()
|
7914 | promise = callback.promise
|
7915 | }
|
7916 |
|
7917 | if (this.isOpen()) {
|
7918 | this.db.close(function () {
|
7919 | self.emit('closed')
|
7920 | callback.apply(null, arguments)
|
7921 | })
|
7922 | this.emit('closing')
|
7923 | this.db = new DeferredLevelDOWN(this._db)
|
7924 | } else if (this.isClosed()) {
|
7925 | process.nextTick(callback)
|
7926 | } else if (this.db.status === 'closing') {
|
7927 | this.once('closed', callback)
|
7928 | } else if (this._isOpening()) {
|
7929 | this.once('open', function () {
|
7930 | self.close(callback)
|
7931 | })
|
7932 | }
|
7933 |
|
7934 | return promise
|
7935 | }
|
7936 |
|
7937 | LevelUP.prototype.isOpen = function () {
|
7938 | return this.db.status === 'open'
|
7939 | }
|
7940 |
|
7941 | LevelUP.prototype._isOpening = function () {
|
7942 | return this.db.status === 'opening'
|
7943 | }
|
7944 |
|
7945 | LevelUP.prototype.isClosed = function () {
|
7946 | return (/^clos|new/).test(this.db.status)
|
7947 | }
|
7948 |
|
7949 | LevelUP.prototype.get = function (key, options, callback) {
|
7950 | if (key === null || key === undefined) {
|
7951 | throw new ReadError('get() requires a key argument')
|
7952 | }
|
7953 |
|
7954 | var promise
|
7955 |
|
7956 | callback = getCallback(options, callback)
|
7957 |
|
7958 | if (!callback) {
|
7959 | callback = promisify()
|
7960 | promise = callback.promise
|
7961 | }
|
7962 |
|
7963 | if (maybeError(this, callback)) { return promise }
|
7964 |
|
7965 | options = getOptions(options)
|
7966 |
|
7967 | this.db.get(key, options, function (err, value) {
|
7968 | if (err) {
|
7969 | if ((/notfound/i).test(err) || err.notFound) {
|
7970 | err = new NotFoundError('Key not found in database [' + key + ']', err)
|
7971 | } else {
|
7972 | err = new ReadError(err)
|
7973 | }
|
7974 | return callback(err)
|
7975 | }
|
7976 | callback(null, value)
|
7977 | })
|
7978 |
|
7979 | return promise
|
7980 | }
|
7981 |
|
7982 | LevelUP.prototype.put = function (key, value, options, callback) {
|
7983 | if (key === null || key === undefined) {
|
7984 | throw new WriteError('put() requires a key argument')
|
7985 | }
|
7986 |
|
7987 | var self = this
|
7988 | var promise
|
7989 |
|
7990 | callback = getCallback(options, callback)
|
7991 |
|
7992 | if (!callback) {
|
7993 | callback = promisify()
|
7994 | promise = callback.promise
|
7995 | }
|
7996 |
|
7997 | if (maybeError(this, callback)) { return promise }
|
7998 |
|
7999 | options = getOptions(options)
|
8000 |
|
8001 | this.db.put(key, value, options, function (err) {
|
8002 | if (err) {
|
8003 | return callback(new WriteError(err))
|
8004 | }
|
8005 | self.emit('put', key, value)
|
8006 | callback()
|
8007 | })
|
8008 |
|
8009 | return promise
|
8010 | }
|
8011 |
|
8012 | LevelUP.prototype.del = function (key, options, callback) {
|
8013 | if (key === null || key === undefined) {
|
8014 | throw new WriteError('del() requires a key argument')
|
8015 | }
|
8016 |
|
8017 | var self = this
|
8018 | var promise
|
8019 |
|
8020 | callback = getCallback(options, callback)
|
8021 |
|
8022 | if (!callback) {
|
8023 | callback = promisify()
|
8024 | promise = callback.promise
|
8025 | }
|
8026 |
|
8027 | if (maybeError(this, callback)) { return promise }
|
8028 |
|
8029 | options = getOptions(options)
|
8030 |
|
8031 | this.db.del(key, options, function (err) {
|
8032 | if (err) {
|
8033 | return callback(new WriteError(err))
|
8034 | }
|
8035 | self.emit('del', key)
|
8036 | callback()
|
8037 | })
|
8038 |
|
8039 | return promise
|
8040 | }
|
8041 |
|
8042 | LevelUP.prototype.batch = function (arr, options, callback) {
|
8043 | if (!arguments.length) {
|
8044 | return new Batch(this)
|
8045 | }
|
8046 |
|
8047 | if (!Array.isArray(arr)) {
|
8048 | throw new WriteError('batch() requires an array argument')
|
8049 | }
|
8050 |
|
8051 | var self = this
|
8052 | var promise
|
8053 |
|
8054 | callback = getCallback(options, callback)
|
8055 |
|
8056 | if (!callback) {
|
8057 | callback = promisify()
|
8058 | promise = callback.promise
|
8059 | }
|
8060 |
|
8061 | if (maybeError(this, callback)) { return promise }
|
8062 |
|
8063 | options = getOptions(options)
|
8064 |
|
8065 | this.db.batch(arr, options, function (err) {
|
8066 | if (err) {
|
8067 | return callback(new WriteError(err))
|
8068 | }
|
8069 | self.emit('batch', arr)
|
8070 | callback()
|
8071 | })
|
8072 |
|
8073 | return promise
|
8074 | }
|
8075 |
|
8076 | LevelUP.prototype.readStream =
|
8077 | LevelUP.prototype.createReadStream = function (options) {
|
8078 | options = extend({ keys: true, values: true }, options)
|
8079 | if (typeof options.limit !== 'number') { options.limit = -1 }
|
8080 | return new IteratorStream(this.db.iterator(options), options)
|
8081 | }
|
8082 |
|
8083 | LevelUP.prototype.keyStream =
|
8084 | LevelUP.prototype.createKeyStream = function (options) {
|
8085 | return this.createReadStream(extend(options, { keys: true, values: false }))
|
8086 | }
|
8087 |
|
8088 | LevelUP.prototype.valueStream =
|
8089 | LevelUP.prototype.createValueStream = function (options) {
|
8090 | return this.createReadStream(extend(options, { keys: false, values: true }))
|
8091 | }
|
8092 |
|
8093 | LevelUP.prototype.toString = function () {
|
8094 | return 'LevelUP'
|
8095 | }
|
8096 |
|
8097 | function getCallback (options, callback) {
|
8098 | return typeof options === 'function' ? options : callback
|
8099 | }
|
8100 |
|
8101 | function getOptions (options) {
|
8102 | return typeof options === 'object' && options !== null ? options : {}
|
8103 | }
|
8104 |
|
8105 | function maybeError (db, callback) {
|
8106 | if (!db._isOpening() && !db.isOpen()) {
|
8107 | process.nextTick(callback, new ReadError('Database is not open'))
|
8108 | return true
|
8109 | }
|
8110 | }
|
8111 |
|
8112 | LevelUP.errors = errors
|
8113 | module.exports = LevelUP.default = LevelUP
|
8114 |
|
8115 | }).call(this,_dereq_(60))
|
8116 | },{"103":103,"18":18,"29":29,"40":40,"42":42,"48":48,"49":49,"5":5,"50":50,"60":60}],42:[function(_dereq_,module,exports){
|
8117 |
|
8118 |
|
8119 |
|
8120 |
|
8121 |
|
8122 |
|
8123 | function promisify () {
|
8124 | var callback
|
8125 | var promise = new Promise(function (resolve, reject) {
|
8126 | callback = function callback (err, value) {
|
8127 | if (err) reject(err)
|
8128 | else resolve(value)
|
8129 | }
|
8130 | })
|
8131 | callback.promise = promise
|
8132 | return callback
|
8133 | }
|
8134 |
|
8135 | module.exports = promisify
|
8136 |
|
8137 | },{}],43:[function(_dereq_,module,exports){
|
8138 | (function (process){
|
8139 |
|
8140 |
|
8141 | function AbstractChainedBatch (db) {
|
8142 | this._db = db
|
8143 | this._operations = []
|
8144 | this._written = false
|
8145 | }
|
8146 |
|
8147 | AbstractChainedBatch.prototype._serializeKey = function (key) {
|
8148 | return this._db._serializeKey(key)
|
8149 | }
|
8150 |
|
8151 | AbstractChainedBatch.prototype._serializeValue = function (value) {
|
8152 | return this._db._serializeValue(value)
|
8153 | }
|
8154 |
|
8155 | AbstractChainedBatch.prototype._checkWritten = function () {
|
8156 | if (this._written) {
|
8157 | throw new Error('write() already called on this batch')
|
8158 | }
|
8159 | }
|
8160 |
|
8161 | AbstractChainedBatch.prototype.put = function (key, value) {
|
8162 | this._checkWritten()
|
8163 |
|
8164 | var err = this._db._checkKey(key, 'key')
|
8165 | if (err) { throw err }
|
8166 |
|
8167 | key = this._serializeKey(key)
|
8168 | value = this._serializeValue(value)
|
8169 |
|
8170 | this._put(key, value)
|
8171 |
|
8172 | return this
|
8173 | }
|
8174 |
|
8175 | AbstractChainedBatch.prototype._put = function (key, value) {
|
8176 | this._operations.push({ type: 'put', key: key, value: value })
|
8177 | }
|
8178 |
|
8179 | AbstractChainedBatch.prototype.del = function (key) {
|
8180 | this._checkWritten()
|
8181 |
|
8182 | var err = this._db._checkKey(key, 'key')
|
8183 | if (err) { throw err }
|
8184 |
|
8185 | key = this._serializeKey(key)
|
8186 | this._del(key)
|
8187 |
|
8188 | return this
|
8189 | }
|
8190 |
|
8191 | AbstractChainedBatch.prototype._del = function (key) {
|
8192 | this._operations.push({ type: 'del', key: key })
|
8193 | }
|
8194 |
|
8195 | AbstractChainedBatch.prototype.clear = function () {
|
8196 | this._checkWritten()
|
8197 | this._operations = []
|
8198 | this._clear()
|
8199 |
|
8200 | return this
|
8201 | }
|
8202 |
|
8203 | AbstractChainedBatch.prototype._clear = function noop () {}
|
8204 |
|
8205 | AbstractChainedBatch.prototype.write = function (options, callback) {
|
8206 | this._checkWritten()
|
8207 |
|
8208 | if (typeof options === 'function') { callback = options }
|
8209 | if (typeof callback !== 'function') {
|
8210 | throw new Error('write() requires a callback argument')
|
8211 | }
|
8212 | if (typeof options !== 'object') { options = {} }
|
8213 |
|
8214 | this._written = true
|
8215 |
|
8216 |
|
8217 | if (typeof this._write === 'function') { return this._write(callback) }
|
8218 |
|
8219 | if (typeof this._db._batch === 'function') {
|
8220 | return this._db._batch(this._operations, options, callback)
|
8221 | }
|
8222 |
|
8223 | process.nextTick(callback)
|
8224 | }
|
8225 |
|
8226 | module.exports = AbstractChainedBatch
|
8227 |
|
8228 | }).call(this,_dereq_(60))
|
8229 | },{"60":60}],44:[function(_dereq_,module,exports){
|
8230 | (function (process){
|
8231 |
|
8232 |
|
8233 | function AbstractIterator (db) {
|
8234 | this.db = db
|
8235 | this._ended = false
|
8236 | this._nexting = false
|
8237 | }
|
8238 |
|
8239 | AbstractIterator.prototype.next = function (callback) {
|
8240 | var self = this
|
8241 |
|
8242 | if (typeof callback !== 'function') {
|
8243 | throw new Error('next() requires a callback argument')
|
8244 | }
|
8245 |
|
8246 | if (self._ended) {
|
8247 | process.nextTick(callback, new Error('cannot call next() after end()'))
|
8248 | return self
|
8249 | }
|
8250 |
|
8251 | if (self._nexting) {
|
8252 | process.nextTick(callback, new Error('cannot call next() before previous next() has completed'))
|
8253 | return self
|
8254 | }
|
8255 |
|
8256 | self._nexting = true
|
8257 | self._next(function () {
|
8258 | self._nexting = false
|
8259 | callback.apply(null, arguments)
|
8260 | })
|
8261 |
|
8262 | return self
|
8263 | }
|
8264 |
|
8265 | AbstractIterator.prototype._next = function (callback) {
|
8266 | process.nextTick(callback)
|
8267 | }
|
8268 |
|
8269 | AbstractIterator.prototype.end = function (callback) {
|
8270 | if (typeof callback !== 'function') {
|
8271 | throw new Error('end() requires a callback argument')
|
8272 | }
|
8273 |
|
8274 | if (this._ended) {
|
8275 | return process.nextTick(callback, new Error('end() already called on iterator'))
|
8276 | }
|
8277 |
|
8278 | this._ended = true
|
8279 | this._end(callback)
|
8280 | }
|
8281 |
|
8282 | AbstractIterator.prototype._end = function (callback) {
|
8283 | process.nextTick(callback)
|
8284 | }
|
8285 |
|
8286 | module.exports = AbstractIterator
|
8287 |
|
8288 | }).call(this,_dereq_(60))
|
8289 | },{"60":60}],45:[function(_dereq_,module,exports){
|
8290 | (function (Buffer,process){
|
8291 |
|
8292 |
|
8293 | var xtend = _dereq_(50)
|
8294 | var AbstractIterator = _dereq_(44)
|
8295 | var AbstractChainedBatch = _dereq_(43)
|
8296 | var hasOwnProperty = Object.prototype.hasOwnProperty
|
8297 | var rangeOptions = 'start end gt gte lt lte'.split(' ')
|
8298 |
|
8299 | function AbstractLevelDOWN (location) {
|
8300 | if (!arguments.length || location === undefined) {
|
8301 | throw new Error('constructor requires at least a location argument')
|
8302 | }
|
8303 |
|
8304 | if (typeof location !== 'string') {
|
8305 | throw new Error('constructor requires a location string argument')
|
8306 | }
|
8307 |
|
8308 | this.location = location
|
8309 | this.status = 'new'
|
8310 | }
|
8311 |
|
8312 | AbstractLevelDOWN.prototype.open = function (options, callback) {
|
8313 | var self = this
|
8314 | var oldStatus = this.status
|
8315 |
|
8316 | if (typeof options === 'function') { callback = options }
|
8317 |
|
8318 | if (typeof callback !== 'function') {
|
8319 | throw new Error('open() requires a callback argument')
|
8320 | }
|
8321 |
|
8322 | if (typeof options !== 'object') { options = {} }
|
8323 |
|
8324 | options.createIfMissing = options.createIfMissing !== false
|
8325 | options.errorIfExists = !!options.errorIfExists
|
8326 |
|
8327 | this.status = 'opening'
|
8328 | this._open(options, function (err) {
|
8329 | if (err) {
|
8330 | self.status = oldStatus
|
8331 | return callback(err)
|
8332 | }
|
8333 | self.status = 'open'
|
8334 | callback()
|
8335 | })
|
8336 | }
|
8337 |
|
8338 | AbstractLevelDOWN.prototype._open = function (options, callback) {
|
8339 | process.nextTick(callback)
|
8340 | }
|
8341 |
|
8342 | AbstractLevelDOWN.prototype.close = function (callback) {
|
8343 | var self = this
|
8344 | var oldStatus = this.status
|
8345 |
|
8346 | if (typeof callback !== 'function') {
|
8347 | throw new Error('close() requires a callback argument')
|
8348 | }
|
8349 |
|
8350 | this.status = 'closing'
|
8351 | this._close(function (err) {
|
8352 | if (err) {
|
8353 | self.status = oldStatus
|
8354 | return callback(err)
|
8355 | }
|
8356 | self.status = 'closed'
|
8357 | callback()
|
8358 | })
|
8359 | }
|
8360 |
|
8361 | AbstractLevelDOWN.prototype._close = function (callback) {
|
8362 | process.nextTick(callback)
|
8363 | }
|
8364 |
|
8365 | AbstractLevelDOWN.prototype.get = function (key, options, callback) {
|
8366 | if (typeof options === 'function') { callback = options }
|
8367 |
|
8368 | if (typeof callback !== 'function') {
|
8369 | throw new Error('get() requires a callback argument')
|
8370 | }
|
8371 |
|
8372 | var err = this._checkKey(key, 'key')
|
8373 | if (err) return process.nextTick(callback, err)
|
8374 |
|
8375 | key = this._serializeKey(key)
|
8376 |
|
8377 | if (typeof options !== 'object') { options = {} }
|
8378 |
|
8379 | options.asBuffer = options.asBuffer !== false
|
8380 |
|
8381 | this._get(key, options, callback)
|
8382 | }
|
8383 |
|
8384 | AbstractLevelDOWN.prototype._get = function (key, options, callback) {
|
8385 | process.nextTick(function () { callback(new Error('NotFound')) })
|
8386 | }
|
8387 |
|
8388 | AbstractLevelDOWN.prototype.put = function (key, value, options, callback) {
|
8389 | if (typeof options === 'function') { callback = options }
|
8390 |
|
8391 | if (typeof callback !== 'function') {
|
8392 | throw new Error('put() requires a callback argument')
|
8393 | }
|
8394 |
|
8395 | var err = this._checkKey(key, 'key')
|
8396 | if (err) return process.nextTick(callback, err)
|
8397 |
|
8398 | key = this._serializeKey(key)
|
8399 | value = this._serializeValue(value)
|
8400 |
|
8401 | if (typeof options !== 'object') { options = {} }
|
8402 |
|
8403 | this._put(key, value, options, callback)
|
8404 | }
|
8405 |
|
8406 | AbstractLevelDOWN.prototype._put = function (key, value, options, callback) {
|
8407 | process.nextTick(callback)
|
8408 | }
|
8409 |
|
8410 | AbstractLevelDOWN.prototype.del = function (key, options, callback) {
|
8411 | if (typeof options === 'function') { callback = options }
|
8412 |
|
8413 | if (typeof callback !== 'function') {
|
8414 | throw new Error('del() requires a callback argument')
|
8415 | }
|
8416 |
|
8417 | var err = this._checkKey(key, 'key')
|
8418 | if (err) return process.nextTick(callback, err)
|
8419 |
|
8420 | key = this._serializeKey(key)
|
8421 |
|
8422 | if (typeof options !== 'object') { options = {} }
|
8423 |
|
8424 | this._del(key, options, callback)
|
8425 | }
|
8426 |
|
8427 | AbstractLevelDOWN.prototype._del = function (key, options, callback) {
|
8428 | process.nextTick(callback)
|
8429 | }
|
8430 |
|
8431 | AbstractLevelDOWN.prototype.batch = function (array, options, callback) {
|
8432 | if (!arguments.length) { return this._chainedBatch() }
|
8433 |
|
8434 | if (typeof options === 'function') { callback = options }
|
8435 |
|
8436 | if (typeof array === 'function') { callback = array }
|
8437 |
|
8438 | if (typeof callback !== 'function') {
|
8439 | throw new Error('batch(array) requires a callback argument')
|
8440 | }
|
8441 |
|
8442 | if (!Array.isArray(array)) {
|
8443 | return process.nextTick(callback, new Error('batch(array) requires an array argument'))
|
8444 | }
|
8445 |
|
8446 | if (!options || typeof options !== 'object') { options = {} }
|
8447 |
|
8448 | var serialized = new Array(array.length)
|
8449 |
|
8450 | for (var i = 0; i < array.length; i++) {
|
8451 | if (typeof array[i] !== 'object' || array[i] === null) {
|
8452 | return process.nextTick(callback, new Error('batch(array) element must be an object and not `null`'))
|
8453 | }
|
8454 |
|
8455 | var e = xtend(array[i])
|
8456 |
|
8457 | if (e.type !== 'put' && e.type !== 'del') {
|
8458 | return process.nextTick(callback, new Error("`type` must be 'put' or 'del'"))
|
8459 | }
|
8460 |
|
8461 | var err = this._checkKey(e.key, 'key')
|
8462 | if (err) return process.nextTick(callback, err)
|
8463 |
|
8464 | e.key = this._serializeKey(e.key)
|
8465 |
|
8466 | if (e.type === 'put') { e.value = this._serializeValue(e.value) }
|
8467 |
|
8468 | serialized[i] = e
|
8469 | }
|
8470 |
|
8471 | this._batch(serialized, options, callback)
|
8472 | }
|
8473 |
|
8474 | AbstractLevelDOWN.prototype._batch = function (array, options, callback) {
|
8475 | process.nextTick(callback)
|
8476 | }
|
8477 |
|
8478 | AbstractLevelDOWN.prototype._setupIteratorOptions = function (options) {
|
8479 | options = cleanRangeOptions(options)
|
8480 |
|
8481 | options.reverse = !!options.reverse
|
8482 | options.keys = options.keys !== false
|
8483 | options.values = options.values !== false
|
8484 | options.limit = 'limit' in options ? options.limit : -1
|
8485 | options.keyAsBuffer = options.keyAsBuffer !== false
|
8486 | options.valueAsBuffer = options.valueAsBuffer !== false
|
8487 |
|
8488 | return options
|
8489 | }
|
8490 |
|
8491 | function cleanRangeOptions (options) {
|
8492 | var result = {}
|
8493 |
|
8494 | for (var k in options) {
|
8495 | if (!hasOwnProperty.call(options, k)) continue
|
8496 | if (isRangeOption(k) && isEmptyRangeOption(options[k])) continue
|
8497 |
|
8498 | result[k] = options[k]
|
8499 | }
|
8500 |
|
8501 | return result
|
8502 | }
|
8503 |
|
8504 | function isRangeOption (k) {
|
8505 | return rangeOptions.indexOf(k) !== -1
|
8506 | }
|
8507 |
|
8508 | function isEmptyRangeOption (v) {
|
8509 | return v === '' || v == null || isEmptyBuffer(v)
|
8510 | }
|
8511 |
|
8512 | function isEmptyBuffer (v) {
|
8513 | return Buffer.isBuffer(v) && v.length === 0
|
8514 | }
|
8515 |
|
8516 | AbstractLevelDOWN.prototype.iterator = function (options) {
|
8517 | if (typeof options !== 'object') { options = {} }
|
8518 | options = this._setupIteratorOptions(options)
|
8519 | return this._iterator(options)
|
8520 | }
|
8521 |
|
8522 | AbstractLevelDOWN.prototype._iterator = function (options) {
|
8523 | return new AbstractIterator(this)
|
8524 | }
|
8525 |
|
8526 | AbstractLevelDOWN.prototype._chainedBatch = function () {
|
8527 | return new AbstractChainedBatch(this)
|
8528 | }
|
8529 |
|
8530 | AbstractLevelDOWN.prototype._serializeKey = function (key) {
|
8531 | return Buffer.isBuffer(key) ? key : String(key)
|
8532 | }
|
8533 |
|
8534 | AbstractLevelDOWN.prototype._serializeValue = function (value) {
|
8535 | if (value == null) return ''
|
8536 | return Buffer.isBuffer(value) || process.browser ? value : String(value)
|
8537 | }
|
8538 |
|
8539 | AbstractLevelDOWN.prototype._checkKey = function (obj, type) {
|
8540 | if (obj === null || obj === undefined) {
|
8541 | return new Error(type + ' cannot be `null` or `undefined`')
|
8542 | }
|
8543 |
|
8544 | if (Buffer.isBuffer(obj) && obj.length === 0) {
|
8545 | return new Error(type + ' cannot be an empty Buffer')
|
8546 | }
|
8547 |
|
8548 | if (String(obj) === '') {
|
8549 | return new Error(type + ' cannot be an empty String')
|
8550 | }
|
8551 | }
|
8552 |
|
8553 | module.exports = AbstractLevelDOWN
|
8554 |
|
8555 | }).call(this,{"isBuffer":_dereq_(25)},_dereq_(60))
|
8556 | },{"25":25,"43":43,"44":44,"50":50,"60":60}],46:[function(_dereq_,module,exports){
|
8557 | exports.AbstractLevelDOWN = _dereq_(45)
|
8558 | exports.AbstractIterator = _dereq_(44)
|
8559 | exports.AbstractChainedBatch = _dereq_(43)
|
8560 |
|
8561 | },{"43":43,"44":44,"45":45}],47:[function(_dereq_,module,exports){
|
8562 | var AbstractIterator = _dereq_(46).AbstractIterator
|
8563 | var inherits = _dereq_(24)
|
8564 |
|
8565 | function DeferredIterator (options) {
|
8566 | AbstractIterator.call(this, options)
|
8567 |
|
8568 | this._options = options
|
8569 | this._iterator = null
|
8570 | this._operations = []
|
8571 | }
|
8572 |
|
8573 | inherits(DeferredIterator, AbstractIterator)
|
8574 |
|
8575 | DeferredIterator.prototype.setDb = function (db) {
|
8576 | var it = this._iterator = db.iterator(this._options)
|
8577 | this._operations.forEach(function (op) {
|
8578 | it[op.method].apply(it, op.args)
|
8579 | })
|
8580 | }
|
8581 |
|
8582 | DeferredIterator.prototype._operation = function (method, args) {
|
8583 | if (this._iterator) return this._iterator[method].apply(this._iterator, args)
|
8584 | this._operations.push({ method: method, args: args })
|
8585 | }
|
8586 |
|
8587 | 'next end'.split(' ').forEach(function (m) {
|
8588 | DeferredIterator.prototype['_' + m] = function () {
|
8589 | this._operation(m, arguments)
|
8590 | }
|
8591 | })
|
8592 |
|
8593 | module.exports = DeferredIterator
|
8594 |
|
8595 | },{"24":24,"46":46}],48:[function(_dereq_,module,exports){
|
8596 | var AbstractLevelDOWN = _dereq_(46).AbstractLevelDOWN
|
8597 | var inherits = _dereq_(24)
|
8598 | var DeferredIterator = _dereq_(47)
|
8599 | var deferrables = 'put get del batch'.split(' ')
|
8600 |
|
8601 | function DeferredLevelDOWN (db) {
|
8602 | AbstractLevelDOWN.call(this, '')
|
8603 | this._db = db
|
8604 | this._operations = []
|
8605 | this._iterators = []
|
8606 | closed(this)
|
8607 | }
|
8608 |
|
8609 | inherits(DeferredLevelDOWN, AbstractLevelDOWN)
|
8610 |
|
8611 | DeferredLevelDOWN.prototype._open = function (options, callback) {
|
8612 | var self = this
|
8613 |
|
8614 | this._db.open(options, function (err) {
|
8615 | if (err) return callback(err)
|
8616 |
|
8617 | self._operations.forEach(function (op) {
|
8618 | self._db[op.method].apply(self._db, op.args)
|
8619 | })
|
8620 | self._operations = []
|
8621 | self._iterators.forEach(function (it) {
|
8622 | it.setDb(self._db)
|
8623 | })
|
8624 | self._iterators = []
|
8625 | open(self)
|
8626 | callback()
|
8627 | })
|
8628 | }
|
8629 |
|
8630 | DeferredLevelDOWN.prototype._close = function (callback) {
|
8631 | var self = this
|
8632 |
|
8633 | this._db.close(function (err) {
|
8634 | if (err) return callback(err)
|
8635 | closed(self)
|
8636 | callback()
|
8637 | })
|
8638 | }
|
8639 |
|
8640 | function open (self) {
|
8641 | deferrables.concat('iterator').forEach(function (m) {
|
8642 | self['_' + m] = function () {
|
8643 | return this._db[m].apply(this._db, arguments)
|
8644 | }
|
8645 | })
|
8646 | if (self._db.approximateSize) {
|
8647 | self.approximateSize = function () {
|
8648 | return this._db.approximateSize.apply(this._db, arguments)
|
8649 | }
|
8650 | }
|
8651 | }
|
8652 |
|
8653 | function closed (self) {
|
8654 | deferrables.forEach(function (m) {
|
8655 | self['_' + m] = function () {
|
8656 | this._operations.push({ method: m, args: arguments })
|
8657 | }
|
8658 | })
|
8659 | if (typeof self._db.approximateSize === 'function') {
|
8660 | self.approximateSize = function () {
|
8661 | this._operations.push({
|
8662 | method: 'approximateSize',
|
8663 | args: arguments
|
8664 | })
|
8665 | }
|
8666 | }
|
8667 | self._iterator = function (options) {
|
8668 | var it = new DeferredIterator(options)
|
8669 | this._iterators.push(it)
|
8670 | return it
|
8671 | }
|
8672 | }
|
8673 |
|
8674 | DeferredLevelDOWN.prototype._serializeKey = function (key) {
|
8675 | return key
|
8676 | }
|
8677 |
|
8678 | DeferredLevelDOWN.prototype._serializeValue = function (value) {
|
8679 | return value
|
8680 | }
|
8681 |
|
8682 | module.exports = DeferredLevelDOWN
|
8683 | module.exports.DeferredIterator = DeferredIterator
|
8684 |
|
8685 | },{"24":24,"46":46,"47":47}],49:[function(_dereq_,module,exports){
|
8686 |
|
8687 |
|
8688 |
|
8689 |
|
8690 |
|
8691 |
|
8692 | var createError = _dereq_(17).create
|
8693 | var LevelUPError = createError('LevelUPError')
|
8694 | var NotFoundError = createError('NotFoundError', LevelUPError)
|
8695 |
|
8696 | NotFoundError.prototype.notFound = true
|
8697 | NotFoundError.prototype.status = 404
|
8698 |
|
8699 | module.exports = {
|
8700 | LevelUPError: LevelUPError,
|
8701 | InitializationError: createError('InitializationError', LevelUPError),
|
8702 | OpenError: createError('OpenError', LevelUPError),
|
8703 | ReadError: createError('ReadError', LevelUPError),
|
8704 | WriteError: createError('WriteError', LevelUPError),
|
8705 | NotFoundError: NotFoundError,
|
8706 | EncodingError: createError('EncodingError', LevelUPError)
|
8707 | }
|
8708 |
|
8709 | },{"17":17}],50:[function(_dereq_,module,exports){
|
8710 | arguments[4][39][0].apply(exports,arguments)
|
8711 | },{"39":39}],51:[function(_dereq_,module,exports){
|
8712 | (function (Buffer,process,global){
|
8713 | 'use strict';
|
8714 |
|
8715 | var inherits = _dereq_(24);
|
8716 | var bufferFrom = _dereq_(56);
|
8717 | var AbstractLevelDOWN = _dereq_(3).AbstractLevelDOWN;
|
8718 | var AbstractIterator = _dereq_(3).AbstractIterator;
|
8719 |
|
8720 | var LocalStorage = _dereq_(53).LocalStorage;
|
8721 | var LocalStorageCore = _dereq_(52);
|
8722 | var utils = _dereq_(55);
|
8723 |
|
8724 |
|
8725 | var nextTick = global.setImmediate || process.nextTick;
|
8726 |
|
8727 | function LDIterator(db, options) {
|
8728 |
|
8729 | AbstractIterator.call(this, db);
|
8730 |
|
8731 | this._reverse = !!options.reverse;
|
8732 | this._endkey = options.end;
|
8733 | this._startkey = options.start;
|
8734 | this._gt = options.gt;
|
8735 | this._gte = options.gte;
|
8736 | this._lt = options.lt;
|
8737 | this._lte = options.lte;
|
8738 | this._exclusiveStart = options.exclusiveStart;
|
8739 | this._keysOnly = options.values === false;
|
8740 | this._limit = options.limit;
|
8741 | this._count = 0;
|
8742 |
|
8743 | this.onInitCompleteListeners = [];
|
8744 | }
|
8745 |
|
8746 | inherits(LDIterator, AbstractIterator);
|
8747 |
|
8748 | LDIterator.prototype._init = function (callback) {
|
8749 | nextTick(function () {
|
8750 | callback();
|
8751 | });
|
8752 | };
|
8753 |
|
8754 | LDIterator.prototype._next = function (callback) {
|
8755 | var self = this;
|
8756 |
|
8757 | function onInitComplete() {
|
8758 | if (self._pos === self._keys.length || self._pos < 0) {
|
8759 | return callback();
|
8760 | }
|
8761 |
|
8762 | var key = self._keys[self._pos];
|
8763 |
|
8764 | if (!!self._endkey && (self._reverse ? key < self._endkey : key > self._endkey)) {
|
8765 | return callback();
|
8766 | }
|
8767 |
|
8768 | if (!!self._limit && self._limit > 0 && self._count++ >= self._limit) {
|
8769 | return callback();
|
8770 | }
|
8771 |
|
8772 | if ((self._lt && key >= self._lt) ||
|
8773 | (self._lte && key > self._lte) ||
|
8774 | (self._gt && key <= self._gt) ||
|
8775 | (self._gte && key < self._gte)) {
|
8776 | return callback();
|
8777 | }
|
8778 |
|
8779 | self._pos += self._reverse ? -1 : 1;
|
8780 | if (self._keysOnly) {
|
8781 | return callback(null, key);
|
8782 | }
|
8783 |
|
8784 | self.db.container.getItem(key, function (err, value) {
|
8785 | if (err) {
|
8786 | if (err.message === 'NotFound') {
|
8787 | return nextTick(function () {
|
8788 | self._next(callback);
|
8789 | });
|
8790 | }
|
8791 | return callback(err);
|
8792 | }
|
8793 | callback(null, key, value);
|
8794 | });
|
8795 | }
|
8796 | if (!self.initStarted) {
|
8797 | process.nextTick(function () {
|
8798 | self.initStarted = true;
|
8799 | self._init(function (err) {
|
8800 | if (err) {
|
8801 | return callback(err);
|
8802 | }
|
8803 | self.db.container.keys(function (err, keys) {
|
8804 | if (err) {
|
8805 | return callback(err);
|
8806 | }
|
8807 | self._keys = keys;
|
8808 | if (self._startkey) {
|
8809 | var index = utils.sortedIndexOf(self._keys, self._startkey);
|
8810 | var startkey = (index >= self._keys.length || index < 0) ?
|
8811 | undefined : self._keys[index];
|
8812 | self._pos = index;
|
8813 | if (self._reverse) {
|
8814 | if (self._exclusiveStart || startkey !== self._startkey) {
|
8815 | self._pos--;
|
8816 | }
|
8817 | } else if (self._exclusiveStart && startkey === self._startkey) {
|
8818 | self._pos++;
|
8819 | }
|
8820 | } else {
|
8821 | self._pos = self._reverse ? self._keys.length - 1 : 0;
|
8822 | }
|
8823 | onInitComplete();
|
8824 |
|
8825 | self.initCompleted = true;
|
8826 | var i = -1;
|
8827 | while (++i < self.onInitCompleteListeners.length) {
|
8828 | nextTick(self.onInitCompleteListeners[i]);
|
8829 | }
|
8830 | });
|
8831 | });
|
8832 | });
|
8833 | } else if (!self.initCompleted) {
|
8834 | self.onInitCompleteListeners.push(onInitComplete);
|
8835 | } else {
|
8836 | process.nextTick(onInitComplete);
|
8837 | }
|
8838 | };
|
8839 |
|
8840 | function LD(location) {
|
8841 | if (!(this instanceof LD)) {
|
8842 | return new LD(location);
|
8843 | }
|
8844 | AbstractLevelDOWN.call(this, location);
|
8845 | this.container = new LocalStorage(location);
|
8846 | }
|
8847 |
|
8848 | inherits(LD, AbstractLevelDOWN);
|
8849 |
|
8850 | LD.prototype._open = function (options, callback) {
|
8851 | this.container.init(callback);
|
8852 | };
|
8853 |
|
8854 | LD.prototype._put = function (key, value, options, callback) {
|
8855 |
|
8856 | var err = checkKeyValue(key, 'key');
|
8857 |
|
8858 | if (err) {
|
8859 | return nextTick(function () {
|
8860 | callback(err);
|
8861 | });
|
8862 | }
|
8863 |
|
8864 | err = checkKeyValue(value, 'value');
|
8865 |
|
8866 | if (err) {
|
8867 | return nextTick(function () {
|
8868 | callback(err);
|
8869 | });
|
8870 | }
|
8871 |
|
8872 | if (typeof value === 'object' && !Buffer.isBuffer(value) && value.buffer === undefined) {
|
8873 | var obj = {};
|
8874 | obj.storetype = "json";
|
8875 | obj.data = value;
|
8876 | value = JSON.stringify(obj);
|
8877 | }
|
8878 |
|
8879 | this.container.setItem(key, value, callback);
|
8880 | };
|
8881 |
|
8882 | LD.prototype._get = function (key, options, callback) {
|
8883 |
|
8884 | var err = checkKeyValue(key, 'key');
|
8885 |
|
8886 | if (err) {
|
8887 | return nextTick(function () {
|
8888 | callback(err);
|
8889 | });
|
8890 | }
|
8891 |
|
8892 | if (!Buffer.isBuffer(key)) {
|
8893 | key = String(key);
|
8894 | }
|
8895 | this.container.getItem(key, function (err, value) {
|
8896 |
|
8897 | if (err) {
|
8898 | return callback(err);
|
8899 | }
|
8900 |
|
8901 | if (options.asBuffer !== false && !Buffer.isBuffer(value)) {
|
8902 | value = bufferFrom(value);
|
8903 | }
|
8904 |
|
8905 |
|
8906 | if (options.asBuffer === false) {
|
8907 | if (value.indexOf("{\"storetype\":\"json\",\"data\"") > -1) {
|
8908 | var res = JSON.parse(value);
|
8909 | value = res.data;
|
8910 | }
|
8911 | }
|
8912 | callback(null, value);
|
8913 | });
|
8914 | };
|
8915 |
|
8916 | LD.prototype._del = function (key, options, callback) {
|
8917 |
|
8918 | var err = checkKeyValue(key, 'key');
|
8919 |
|
8920 | if (err) {
|
8921 | return nextTick(function () {
|
8922 | callback(err);
|
8923 | });
|
8924 | }
|
8925 | if (!Buffer.isBuffer(key)) {
|
8926 | key = String(key);
|
8927 | }
|
8928 |
|
8929 | this.container.removeItem(key, callback);
|
8930 | };
|
8931 |
|
8932 | LD.prototype._batch = function (array, options, callback) {
|
8933 | var self = this;
|
8934 | nextTick(function () {
|
8935 | var err;
|
8936 | var key;
|
8937 | var value;
|
8938 |
|
8939 | var numDone = 0;
|
8940 | var overallErr;
|
8941 | function checkDone() {
|
8942 | if (++numDone === array.length) {
|
8943 | callback(overallErr);
|
8944 | }
|
8945 | }
|
8946 |
|
8947 | if (Array.isArray(array) && array.length) {
|
8948 | for (var i = 0; i < array.length; i++) {
|
8949 | var task = array[i];
|
8950 | if (task) {
|
8951 | key = Buffer.isBuffer(task.key) ? task.key : String(task.key);
|
8952 | err = checkKeyValue(key, 'key');
|
8953 | if (err) {
|
8954 | overallErr = err;
|
8955 | checkDone();
|
8956 | } else if (task.type === 'del') {
|
8957 | self._del(task.key, options, checkDone);
|
8958 | } else if (task.type === 'put') {
|
8959 | value = Buffer.isBuffer(task.value) ? task.value : String(task.value);
|
8960 | err = checkKeyValue(value, 'value');
|
8961 | if (err) {
|
8962 | overallErr = err;
|
8963 | checkDone();
|
8964 | } else {
|
8965 | self._put(key, value, options, checkDone);
|
8966 | }
|
8967 | }
|
8968 | } else {
|
8969 | checkDone();
|
8970 | }
|
8971 | }
|
8972 | } else {
|
8973 | callback();
|
8974 | }
|
8975 | });
|
8976 | };
|
8977 |
|
8978 | LD.prototype._iterator = function (options) {
|
8979 | return new LDIterator(this, options);
|
8980 | };
|
8981 |
|
8982 | LD.destroy = function (name, callback) {
|
8983 | LocalStorageCore.destroy(name, callback);
|
8984 | };
|
8985 |
|
8986 | function checkKeyValue(obj, type) {
|
8987 | if (obj === null || obj === undefined) {
|
8988 | return new Error(type + ' cannot be `null` or `undefined`');
|
8989 | }
|
8990 | if (obj === null || obj === undefined) {
|
8991 | return new Error(type + ' cannot be `null` or `undefined`');
|
8992 | }
|
8993 |
|
8994 | if (type === 'key') {
|
8995 |
|
8996 | if (obj instanceof Boolean) {
|
8997 | return new Error(type + ' cannot be `null` or `undefined`');
|
8998 | }
|
8999 | if (obj === '') {
|
9000 | return new Error(type + ' cannot be empty');
|
9001 | }
|
9002 | }
|
9003 | if (obj.toString().indexOf("[object ArrayBuffer]") === 0) {
|
9004 | if (obj.byteLength === 0 || obj.byteLength === undefined) {
|
9005 | return new Error(type + ' cannot be an empty Buffer');
|
9006 | }
|
9007 | }
|
9008 |
|
9009 | if (Buffer.isBuffer(obj)) {
|
9010 | if (obj.length === 0) {
|
9011 | return new Error(type + ' cannot be an empty Buffer');
|
9012 | }
|
9013 | } else if (String(obj) === '') {
|
9014 | return new Error(type + ' cannot be an empty String');
|
9015 | }
|
9016 | }
|
9017 |
|
9018 | module.exports = LD;
|
9019 |
|
9020 | }).call(this,{"isBuffer":_dereq_(25)},_dereq_(60),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
9021 | },{"24":24,"25":25,"3":3,"52":52,"53":53,"55":55,"56":56,"60":60}],52:[function(_dereq_,module,exports){
|
9022 | (function (process,global){
|
9023 | 'use strict';
|
9024 |
|
9025 |
|
9026 |
|
9027 |
|
9028 |
|
9029 |
|
9030 |
|
9031 |
|
9032 |
|
9033 |
|
9034 | var nextTick = global.setImmediate || process.nextTick;
|
9035 |
|
9036 |
|
9037 |
|
9038 |
|
9039 | var storage = _dereq_(21);
|
9040 |
|
9041 | function callbackify(callback, fun) {
|
9042 | var val;
|
9043 | var err;
|
9044 | try {
|
9045 | val = fun();
|
9046 | } catch (e) {
|
9047 | err = e;
|
9048 | }
|
9049 | nextTick(function () {
|
9050 | callback(err, val);
|
9051 | });
|
9052 | }
|
9053 |
|
9054 | function createPrefix(dbname) {
|
9055 | return dbname.replace(/!/g, '!!') + '!';
|
9056 | }
|
9057 |
|
9058 | function LocalStorageCore(dbname) {
|
9059 | this._prefix = createPrefix(dbname);
|
9060 | }
|
9061 |
|
9062 | LocalStorageCore.prototype.getKeys = function (callback) {
|
9063 | var self = this;
|
9064 | callbackify(callback, function () {
|
9065 | var keys = [];
|
9066 | var prefixLen = self._prefix.length;
|
9067 | var i = -1;
|
9068 | var len = storage.length;
|
9069 | while (++i < len) {
|
9070 | var fullKey = storage.key(i);
|
9071 | if (fullKey.substring(0, prefixLen) === self._prefix) {
|
9072 | keys.push(fullKey.substring(prefixLen));
|
9073 | }
|
9074 | }
|
9075 | keys.sort();
|
9076 | return keys;
|
9077 | });
|
9078 | };
|
9079 |
|
9080 | LocalStorageCore.prototype.put = function (key, value, callback) {
|
9081 | var self = this;
|
9082 | callbackify(callback, function () {
|
9083 | storage.setItem(self._prefix + key, value);
|
9084 | });
|
9085 | };
|
9086 |
|
9087 | LocalStorageCore.prototype.get = function (key, callback) {
|
9088 | var self = this;
|
9089 | callbackify(callback, function () {
|
9090 | return storage.getItem(self._prefix + key);
|
9091 | });
|
9092 | };
|
9093 |
|
9094 | LocalStorageCore.prototype.remove = function (key, callback) {
|
9095 | var self = this;
|
9096 | callbackify(callback, function () {
|
9097 | storage.removeItem(self._prefix + key);
|
9098 | });
|
9099 | };
|
9100 |
|
9101 | LocalStorageCore.destroy = function (dbname, callback) {
|
9102 | var prefix = createPrefix(dbname);
|
9103 | callbackify(callback, function () {
|
9104 | var keysToDelete = [];
|
9105 | var i = -1;
|
9106 | var len = storage.length;
|
9107 | while (++i < len) {
|
9108 | var key = storage.key(i);
|
9109 | if (key.substring(0, prefix.length) === prefix) {
|
9110 | keysToDelete.push(key);
|
9111 | }
|
9112 | }
|
9113 | keysToDelete.forEach(function (key) {
|
9114 | storage.removeItem(key);
|
9115 | });
|
9116 | });
|
9117 | };
|
9118 |
|
9119 | module.exports = LocalStorageCore;
|
9120 | }).call(this,_dereq_(60),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
9121 | },{"21":21,"60":60}],53:[function(_dereq_,module,exports){
|
9122 | (function (Buffer){
|
9123 | 'use strict';
|
9124 |
|
9125 |
|
9126 |
|
9127 | var arrayBuffPrefix = 'ArrayBuffer:';
|
9128 | var arrayBuffRegex = new RegExp('^' + arrayBuffPrefix);
|
9129 | var uintPrefix = 'Uint8Array:';
|
9130 | var uintRegex = new RegExp('^' + uintPrefix);
|
9131 |
|
9132 |
|
9133 | var bufferPrefix = 'Buff:';
|
9134 | var bufferRegex = new RegExp('^' + bufferPrefix);
|
9135 |
|
9136 | var utils = _dereq_(55);
|
9137 | var LocalStorageCore = _dereq_(52);
|
9138 | var TaskQueue = _dereq_(54);
|
9139 | var d64 = _dereq_(14);
|
9140 |
|
9141 | function LocalStorage(dbname) {
|
9142 | this._store = new LocalStorageCore(dbname);
|
9143 | this._queue = new TaskQueue();
|
9144 | }
|
9145 |
|
9146 | LocalStorage.prototype.sequentialize = function (callback, fun) {
|
9147 | this._queue.add(fun, callback);
|
9148 | };
|
9149 |
|
9150 | LocalStorage.prototype.init = function (callback) {
|
9151 | var self = this;
|
9152 | self.sequentialize(callback, function (callback) {
|
9153 | self._store.getKeys(function (err, keys) {
|
9154 | if (err) {
|
9155 | return callback(err);
|
9156 | }
|
9157 | self._keys = keys;
|
9158 | return callback();
|
9159 | });
|
9160 | });
|
9161 | };
|
9162 |
|
9163 | LocalStorage.prototype.keys = function (callback) {
|
9164 | var self = this;
|
9165 | self.sequentialize(callback, function (callback) {
|
9166 | self._store.getKeys(function (err, keys) {
|
9167 | callback(null, keys.slice());
|
9168 | });
|
9169 | });
|
9170 | };
|
9171 |
|
9172 |
|
9173 | LocalStorage.prototype.setItem = function (key, value, callback) {
|
9174 | var self = this;
|
9175 | self.sequentialize(callback, function (callback) {
|
9176 | if (Buffer.isBuffer(value)) {
|
9177 | value = bufferPrefix + d64.encode(value);
|
9178 | }
|
9179 |
|
9180 | var idx = utils.sortedIndexOf(self._keys, key);
|
9181 | if (self._keys[idx] !== key) {
|
9182 | self._keys.splice(idx, 0, key);
|
9183 | }
|
9184 | self._store.put(key, value, callback);
|
9185 | });
|
9186 | };
|
9187 |
|
9188 |
|
9189 | LocalStorage.prototype.getItem = function (key, callback) {
|
9190 | var self = this;
|
9191 | self.sequentialize(callback, function (callback) {
|
9192 | self._store.get(key, function (err, retval) {
|
9193 | if (err) {
|
9194 | return callback(err);
|
9195 | }
|
9196 | if (typeof retval === 'undefined' || retval === null) {
|
9197 |
|
9198 | return callback(new Error('NotFound'));
|
9199 | }
|
9200 | if (typeof retval !== 'undefined') {
|
9201 | if (bufferRegex.test(retval)) {
|
9202 | retval = d64.decode(retval.substring(bufferPrefix.length));
|
9203 | } else if (arrayBuffRegex.test(retval)) {
|
9204 |
|
9205 |
|
9206 |
|
9207 | retval = retval.substring(arrayBuffPrefix.length);
|
9208 | retval = new ArrayBuffer(atob(retval).split('').map(function (c) {
|
9209 | return c.charCodeAt(0);
|
9210 | }));
|
9211 | } else if (uintRegex.test(retval)) {
|
9212 |
|
9213 | retval = retval.substring(uintPrefix.length);
|
9214 | retval = new Uint8Array(atob(retval).split('').map(function (c) {
|
9215 | return c.charCodeAt(0);
|
9216 | }));
|
9217 | }
|
9218 | }
|
9219 | callback(null, retval);
|
9220 | });
|
9221 | });
|
9222 | };
|
9223 |
|
9224 |
|
9225 | LocalStorage.prototype.removeItem = function (key, callback) {
|
9226 | var self = this;
|
9227 | self.sequentialize(callback, function (callback) {
|
9228 | var idx = utils.sortedIndexOf(self._keys, key);
|
9229 | if (self._keys[idx] === key) {
|
9230 | self._keys.splice(idx, 1);
|
9231 | self._store.remove(key, function (err) {
|
9232 | if (err) {
|
9233 | return callback(err);
|
9234 | }
|
9235 | callback();
|
9236 | });
|
9237 | } else {
|
9238 | callback();
|
9239 | }
|
9240 | });
|
9241 | };
|
9242 |
|
9243 | LocalStorage.prototype.length = function (callback) {
|
9244 | var self = this;
|
9245 | self.sequentialize(callback, function (callback) {
|
9246 | callback(null, self._keys.length);
|
9247 | });
|
9248 | };
|
9249 |
|
9250 | exports.LocalStorage = LocalStorage;
|
9251 |
|
9252 | }).call(this,{"isBuffer":_dereq_(25)})
|
9253 | },{"14":14,"25":25,"52":52,"54":54,"55":55}],54:[function(_dereq_,module,exports){
|
9254 | (function (process,global){
|
9255 | 'use strict';
|
9256 |
|
9257 | var argsarray = _dereq_(4);
|
9258 | var Queue = _dereq_(100);
|
9259 |
|
9260 |
|
9261 | var nextTick = global.setImmediate || process.nextTick;
|
9262 |
|
9263 | function TaskQueue() {
|
9264 | this.queue = new Queue();
|
9265 | this.running = false;
|
9266 | }
|
9267 |
|
9268 | TaskQueue.prototype.add = function (fun, callback) {
|
9269 | this.queue.push({fun: fun, callback: callback});
|
9270 | this.processNext();
|
9271 | };
|
9272 |
|
9273 | TaskQueue.prototype.processNext = function () {
|
9274 | var self = this;
|
9275 | if (self.running || !self.queue.length) {
|
9276 | return;
|
9277 | }
|
9278 | self.running = true;
|
9279 |
|
9280 | var task = self.queue.shift();
|
9281 | nextTick(function () {
|
9282 | task.fun(argsarray(function (args) {
|
9283 | task.callback.apply(null, args);
|
9284 | self.running = false;
|
9285 | self.processNext();
|
9286 | }));
|
9287 | });
|
9288 | };
|
9289 |
|
9290 | module.exports = TaskQueue;
|
9291 |
|
9292 | }).call(this,_dereq_(60),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
9293 | },{"100":100,"4":4,"60":60}],55:[function(_dereq_,module,exports){
|
9294 | 'use strict';
|
9295 |
|
9296 | exports.sortedIndexOf = function(arr, item) {
|
9297 | var low = 0;
|
9298 | var high = arr.length;
|
9299 | var mid;
|
9300 | while (low < high) {
|
9301 | mid = (low + high) >>> 1;
|
9302 | if (arr[mid] < item) {
|
9303 | low = mid + 1;
|
9304 | } else {
|
9305 | high = mid;
|
9306 | }
|
9307 | }
|
9308 | return low;
|
9309 | };
|
9310 |
|
9311 | },{}],56:[function(_dereq_,module,exports){
|
9312 | arguments[4][11][0].apply(exports,arguments)
|
9313 | },{"11":11,"12":12}],57:[function(_dereq_,module,exports){
|
9314 | (function(root) {
|
9315 | var localStorageMemory = {};
|
9316 | var cache = {};
|
9317 |
|
9318 | |
9319 |
|
9320 |
|
9321 | localStorageMemory.length = 0;
|
9322 |
|
9323 | |
9324 |
|
9325 |
|
9326 |
|
9327 |
|
9328 |
|
9329 |
|
9330 | localStorageMemory.getItem = function(key) {
|
9331 | return cache[key] || null;
|
9332 | };
|
9333 |
|
9334 | |
9335 |
|
9336 |
|
9337 |
|
9338 |
|
9339 |
|
9340 |
|
9341 |
|
9342 |
|
9343 | localStorageMemory.setItem = function(key, value) {
|
9344 | if (typeof value === 'undefined') {
|
9345 | localStorageMemory.removeItem(key);
|
9346 | } else {
|
9347 | if (!(cache.hasOwnProperty(key))) {
|
9348 | localStorageMemory.length++;
|
9349 | }
|
9350 |
|
9351 | cache[key] = '' + value;
|
9352 | }
|
9353 | };
|
9354 |
|
9355 | |
9356 |
|
9357 |
|
9358 |
|
9359 |
|
9360 |
|
9361 |
|
9362 | localStorageMemory.removeItem = function(key) {
|
9363 | if (cache.hasOwnProperty(key)) {
|
9364 | delete cache[key];
|
9365 | localStorageMemory.length--;
|
9366 | }
|
9367 | };
|
9368 |
|
9369 | |
9370 |
|
9371 |
|
9372 |
|
9373 |
|
9374 |
|
9375 |
|
9376 | localStorageMemory.key = function(index) {
|
9377 | return Object.keys(cache)[index] || null;
|
9378 | };
|
9379 |
|
9380 | |
9381 |
|
9382 |
|
9383 |
|
9384 |
|
9385 | localStorageMemory.clear = function() {
|
9386 | cache = {};
|
9387 | localStorageMemory.length = 0;
|
9388 | };
|
9389 |
|
9390 | if (typeof exports === 'object') {
|
9391 | module.exports = localStorageMemory;
|
9392 | } else {
|
9393 | root.localStorageMemory = localStorageMemory;
|
9394 | }
|
9395 | })(this);
|
9396 |
|
9397 | },{}],58:[function(_dereq_,module,exports){
|
9398 | (function (Buffer){
|
9399 |
|
9400 | exports.compare = function (a, b) {
|
9401 |
|
9402 | if(Buffer.isBuffer(a)) {
|
9403 | var l = Math.min(a.length, b.length)
|
9404 | for(var i = 0; i < l; i++) {
|
9405 | var cmp = a[i] - b[i]
|
9406 | if(cmp) return cmp
|
9407 | }
|
9408 | return a.length - b.length
|
9409 | }
|
9410 |
|
9411 | return a < b ? -1 : a > b ? 1 : 0
|
9412 | }
|
9413 |
|
9414 |
|
9415 |
|
9416 |
|
9417 |
|
9418 |
|
9419 | function isDef (val) {
|
9420 | return val !== undefined && val !== ''
|
9421 | }
|
9422 |
|
9423 | function has (range, name) {
|
9424 | return Object.hasOwnProperty.call(range, name)
|
9425 | }
|
9426 |
|
9427 | function hasKey(range, name) {
|
9428 | return Object.hasOwnProperty.call(range, name) && name
|
9429 | }
|
9430 |
|
9431 | var lowerBoundKey = exports.lowerBoundKey = function (range) {
|
9432 | return (
|
9433 | hasKey(range, 'gt')
|
9434 | || hasKey(range, 'gte')
|
9435 | || hasKey(range, 'min')
|
9436 | || (range.reverse ? hasKey(range, 'end') : hasKey(range, 'start'))
|
9437 | || undefined
|
9438 | )
|
9439 | }
|
9440 |
|
9441 | var lowerBound = exports.lowerBound = function (range, def) {
|
9442 | var k = lowerBoundKey(range)
|
9443 | return k ? range[k] : def
|
9444 | }
|
9445 |
|
9446 | var lowerBoundInclusive = exports.lowerBoundInclusive = function (range) {
|
9447 | return has(range, 'gt') ? false : true
|
9448 | }
|
9449 |
|
9450 | var upperBoundInclusive = exports.upperBoundInclusive =
|
9451 | function (range) {
|
9452 | return (has(range, 'lt') ) ? false : true
|
9453 | }
|
9454 |
|
9455 | var lowerBoundExclusive = exports.lowerBoundExclusive =
|
9456 | function (range) {
|
9457 | return !lowerBoundInclusive(range)
|
9458 | }
|
9459 |
|
9460 | var upperBoundExclusive = exports.upperBoundExclusive =
|
9461 | function (range) {
|
9462 | return !upperBoundInclusive(range)
|
9463 | }
|
9464 |
|
9465 | var upperBoundKey = exports.upperBoundKey = function (range) {
|
9466 | return (
|
9467 | hasKey(range, 'lt')
|
9468 | || hasKey(range, 'lte')
|
9469 | || hasKey(range, 'max')
|
9470 | || (range.reverse ? hasKey(range, 'start') : hasKey(range, 'end'))
|
9471 | || undefined
|
9472 | )
|
9473 | }
|
9474 |
|
9475 | var upperBound = exports.upperBound = function (range, def) {
|
9476 | var k = upperBoundKey(range)
|
9477 | return k ? range[k] : def
|
9478 | }
|
9479 |
|
9480 | exports.start = function (range, def) {
|
9481 | return range.reverse ? upperBound(range, def) : lowerBound(range, def)
|
9482 | }
|
9483 | exports.end = function (range, def) {
|
9484 | return range.reverse ? lowerBound(range, def) : upperBound(range, def)
|
9485 | }
|
9486 | exports.startInclusive = function (range) {
|
9487 | return (
|
9488 | range.reverse
|
9489 | ? upperBoundInclusive(range)
|
9490 | : lowerBoundInclusive(range)
|
9491 | )
|
9492 | }
|
9493 | exports.endInclusive = function (range) {
|
9494 | return (
|
9495 | range.reverse
|
9496 | ? lowerBoundInclusive(range)
|
9497 | : upperBoundInclusive(range)
|
9498 | )
|
9499 | }
|
9500 |
|
9501 | function id (e) { return e }
|
9502 |
|
9503 | exports.toLtgt = function (range, _range, map, lower, upper) {
|
9504 | _range = _range || {}
|
9505 | map = map || id
|
9506 | var defaults = arguments.length > 3
|
9507 | var lb = exports.lowerBoundKey(range)
|
9508 | var ub = exports.upperBoundKey(range)
|
9509 | if(lb) {
|
9510 | if(lb === 'gt') _range.gt = map(range.gt, false)
|
9511 | else _range.gte = map(range[lb], false)
|
9512 | }
|
9513 | else if(defaults)
|
9514 | _range.gte = map(lower, false)
|
9515 |
|
9516 | if(ub) {
|
9517 | if(ub === 'lt') _range.lt = map(range.lt, true)
|
9518 | else _range.lte = map(range[ub], true)
|
9519 | }
|
9520 | else if(defaults)
|
9521 | _range.lte = map(upper, true)
|
9522 |
|
9523 | if(range.reverse != null)
|
9524 | _range.reverse = !!range.reverse
|
9525 |
|
9526 |
|
9527 |
|
9528 |
|
9529 | if(has(_range, 'max')) delete _range.max
|
9530 | if(has(_range, 'min')) delete _range.min
|
9531 | if(has(_range, 'start')) delete _range.start
|
9532 | if(has(_range, 'end')) delete _range.end
|
9533 |
|
9534 | return _range
|
9535 | }
|
9536 |
|
9537 | exports.contains = function (range, key, compare) {
|
9538 | compare = compare || exports.compare
|
9539 |
|
9540 | var lb = lowerBound(range)
|
9541 | if(isDef(lb)) {
|
9542 | var cmp = compare(key, lb)
|
9543 | if(cmp < 0 || (cmp === 0 && lowerBoundExclusive(range)))
|
9544 | return false
|
9545 | }
|
9546 |
|
9547 | var ub = upperBound(range)
|
9548 | if(isDef(ub)) {
|
9549 | var cmp = compare(key, ub)
|
9550 | if(cmp > 0 || (cmp === 0) && upperBoundExclusive(range))
|
9551 | return false
|
9552 | }
|
9553 |
|
9554 | return true
|
9555 | }
|
9556 |
|
9557 | exports.filter = function (range, compare) {
|
9558 | return function (key) {
|
9559 | return exports.contains(range, key, compare)
|
9560 | }
|
9561 | }
|
9562 |
|
9563 |
|
9564 |
|
9565 | }).call(this,{"isBuffer":_dereq_(25)})
|
9566 | },{"25":25}],59:[function(_dereq_,module,exports){
|
9567 | (function (process){
|
9568 | 'use strict';
|
9569 |
|
9570 | if (!process.version ||
|
9571 | process.version.indexOf('v0.') === 0 ||
|
9572 | process.version.indexOf('v1.') === 0 && process.version.indexOf('v1.8.') !== 0) {
|
9573 | module.exports = { nextTick: nextTick };
|
9574 | } else {
|
9575 | module.exports = process
|
9576 | }
|
9577 |
|
9578 | function nextTick(fn, arg1, arg2, arg3) {
|
9579 | if (typeof fn !== 'function') {
|
9580 | throw new TypeError('"callback" argument must be a function');
|
9581 | }
|
9582 | var len = arguments.length;
|
9583 | var args, i;
|
9584 | switch (len) {
|
9585 | case 0:
|
9586 | case 1:
|
9587 | return process.nextTick(fn);
|
9588 | case 2:
|
9589 | return process.nextTick(function afterTickOne() {
|
9590 | fn.call(null, arg1);
|
9591 | });
|
9592 | case 3:
|
9593 | return process.nextTick(function afterTickTwo() {
|
9594 | fn.call(null, arg1, arg2);
|
9595 | });
|
9596 | case 4:
|
9597 | return process.nextTick(function afterTickThree() {
|
9598 | fn.call(null, arg1, arg2, arg3);
|
9599 | });
|
9600 | default:
|
9601 | args = new Array(len - 1);
|
9602 | i = 0;
|
9603 | while (i < args.length) {
|
9604 | args[i++] = arguments[i];
|
9605 | }
|
9606 | return process.nextTick(function afterTick() {
|
9607 | fn.apply(null, args);
|
9608 | });
|
9609 | }
|
9610 | }
|
9611 |
|
9612 |
|
9613 | }).call(this,_dereq_(60))
|
9614 | },{"60":60}],60:[function(_dereq_,module,exports){
|
9615 |
|
9616 | var process = module.exports = {};
|
9617 |
|
9618 |
|
9619 |
|
9620 |
|
9621 |
|
9622 |
|
9623 | var cachedSetTimeout;
|
9624 | var cachedClearTimeout;
|
9625 |
|
9626 | function defaultSetTimout() {
|
9627 | throw new Error('setTimeout has not been defined');
|
9628 | }
|
9629 | function defaultClearTimeout () {
|
9630 | throw new Error('clearTimeout has not been defined');
|
9631 | }
|
9632 | (function () {
|
9633 | try {
|
9634 | if (typeof setTimeout === 'function') {
|
9635 | cachedSetTimeout = setTimeout;
|
9636 | } else {
|
9637 | cachedSetTimeout = defaultSetTimout;
|
9638 | }
|
9639 | } catch (e) {
|
9640 | cachedSetTimeout = defaultSetTimout;
|
9641 | }
|
9642 | try {
|
9643 | if (typeof clearTimeout === 'function') {
|
9644 | cachedClearTimeout = clearTimeout;
|
9645 | } else {
|
9646 | cachedClearTimeout = defaultClearTimeout;
|
9647 | }
|
9648 | } catch (e) {
|
9649 | cachedClearTimeout = defaultClearTimeout;
|
9650 | }
|
9651 | } ())
|
9652 | function runTimeout(fun) {
|
9653 | if (cachedSetTimeout === setTimeout) {
|
9654 |
|
9655 | return setTimeout(fun, 0);
|
9656 | }
|
9657 |
|
9658 | if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
|
9659 | cachedSetTimeout = setTimeout;
|
9660 | return setTimeout(fun, 0);
|
9661 | }
|
9662 | try {
|
9663 |
|
9664 | return cachedSetTimeout(fun, 0);
|
9665 | } catch(e){
|
9666 | try {
|
9667 |
|
9668 | return cachedSetTimeout.call(null, fun, 0);
|
9669 | } catch(e){
|
9670 |
|
9671 | return cachedSetTimeout.call(this, fun, 0);
|
9672 | }
|
9673 | }
|
9674 |
|
9675 |
|
9676 | }
|
9677 | function runClearTimeout(marker) {
|
9678 | if (cachedClearTimeout === clearTimeout) {
|
9679 |
|
9680 | return clearTimeout(marker);
|
9681 | }
|
9682 |
|
9683 | if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
|
9684 | cachedClearTimeout = clearTimeout;
|
9685 | return clearTimeout(marker);
|
9686 | }
|
9687 | try {
|
9688 |
|
9689 | return cachedClearTimeout(marker);
|
9690 | } catch (e){
|
9691 | try {
|
9692 |
|
9693 | return cachedClearTimeout.call(null, marker);
|
9694 | } catch (e){
|
9695 |
|
9696 |
|
9697 | return cachedClearTimeout.call(this, marker);
|
9698 | }
|
9699 | }
|
9700 |
|
9701 |
|
9702 |
|
9703 | }
|
9704 | var queue = [];
|
9705 | var draining = false;
|
9706 | var currentQueue;
|
9707 | var queueIndex = -1;
|
9708 |
|
9709 | function cleanUpNextTick() {
|
9710 | if (!draining || !currentQueue) {
|
9711 | return;
|
9712 | }
|
9713 | draining = false;
|
9714 | if (currentQueue.length) {
|
9715 | queue = currentQueue.concat(queue);
|
9716 | } else {
|
9717 | queueIndex = -1;
|
9718 | }
|
9719 | if (queue.length) {
|
9720 | drainQueue();
|
9721 | }
|
9722 | }
|
9723 |
|
9724 | function drainQueue() {
|
9725 | if (draining) {
|
9726 | return;
|
9727 | }
|
9728 | var timeout = runTimeout(cleanUpNextTick);
|
9729 | draining = true;
|
9730 |
|
9731 | var len = queue.length;
|
9732 | while(len) {
|
9733 | currentQueue = queue;
|
9734 | queue = [];
|
9735 | while (++queueIndex < len) {
|
9736 | if (currentQueue) {
|
9737 | currentQueue[queueIndex].run();
|
9738 | }
|
9739 | }
|
9740 | queueIndex = -1;
|
9741 | len = queue.length;
|
9742 | }
|
9743 | currentQueue = null;
|
9744 | draining = false;
|
9745 | runClearTimeout(timeout);
|
9746 | }
|
9747 |
|
9748 | process.nextTick = function (fun) {
|
9749 | var args = new Array(arguments.length - 1);
|
9750 | if (arguments.length > 1) {
|
9751 | for (var i = 1; i < arguments.length; i++) {
|
9752 | args[i - 1] = arguments[i];
|
9753 | }
|
9754 | }
|
9755 | queue.push(new Item(fun, args));
|
9756 | if (queue.length === 1 && !draining) {
|
9757 | runTimeout(drainQueue);
|
9758 | }
|
9759 | };
|
9760 |
|
9761 |
|
9762 | function Item(fun, array) {
|
9763 | this.fun = fun;
|
9764 | this.array = array;
|
9765 | }
|
9766 | Item.prototype.run = function () {
|
9767 | this.fun.apply(null, this.array);
|
9768 | };
|
9769 | process.title = 'browser';
|
9770 | process.browser = true;
|
9771 | process.env = {};
|
9772 | process.argv = [];
|
9773 | process.version = '';
|
9774 | process.versions = {};
|
9775 |
|
9776 | function noop() {}
|
9777 |
|
9778 | process.on = noop;
|
9779 | process.addListener = noop;
|
9780 | process.once = noop;
|
9781 | process.off = noop;
|
9782 | process.removeListener = noop;
|
9783 | process.removeAllListeners = noop;
|
9784 | process.emit = noop;
|
9785 | process.prependListener = noop;
|
9786 | process.prependOnceListener = noop;
|
9787 |
|
9788 | process.listeners = function (name) { return [] }
|
9789 |
|
9790 | process.binding = function (name) {
|
9791 | throw new Error('process.binding is not supported');
|
9792 | };
|
9793 |
|
9794 | process.cwd = function () { return '/' };
|
9795 | process.chdir = function (dir) {
|
9796 | throw new Error('process.chdir is not supported');
|
9797 | };
|
9798 | process.umask = function() { return 0; };
|
9799 |
|
9800 | },{}],61:[function(_dereq_,module,exports){
|
9801 |
|
9802 |
|
9803 |
|
9804 |
|
9805 |
|
9806 |
|
9807 |
|
9808 | (function (name, context, definition) {
|
9809 | if (typeof module != 'undefined' && module.exports)
|
9810 | module.exports = definition()
|
9811 | else
|
9812 | context[name] = definition()
|
9813 | })('prr', this, function() {
|
9814 |
|
9815 | var setProperty = typeof Object.defineProperty == 'function'
|
9816 | ? function (obj, key, options) {
|
9817 | Object.defineProperty(obj, key, options)
|
9818 | return obj
|
9819 | }
|
9820 | : function (obj, key, options) {
|
9821 | obj[key] = options.value
|
9822 | return obj
|
9823 | }
|
9824 |
|
9825 | , makeOptions = function (value, options) {
|
9826 | var oo = typeof options == 'object'
|
9827 | , os = !oo && typeof options == 'string'
|
9828 | , op = function (p) {
|
9829 | return oo
|
9830 | ? !!options[p]
|
9831 | : os
|
9832 | ? options.indexOf(p[0]) > -1
|
9833 | : false
|
9834 | }
|
9835 |
|
9836 | return {
|
9837 | enumerable : op('enumerable')
|
9838 | , configurable : op('configurable')
|
9839 | , writable : op('writable')
|
9840 | , value : value
|
9841 | }
|
9842 | }
|
9843 |
|
9844 | , prr = function (obj, key, value, options) {
|
9845 | var k
|
9846 |
|
9847 | options = makeOptions(value, options)
|
9848 |
|
9849 | if (typeof key == 'object') {
|
9850 | for (k in key) {
|
9851 | if (Object.hasOwnProperty.call(key, k)) {
|
9852 | options.value = key[k]
|
9853 | setProperty(obj, k, options)
|
9854 | }
|
9855 | }
|
9856 | return obj
|
9857 | }
|
9858 |
|
9859 | return setProperty(obj, key, options)
|
9860 | }
|
9861 |
|
9862 | return prr
|
9863 | })
|
9864 | },{}],62:[function(_dereq_,module,exports){
|
9865 | (function (process){
|
9866 |
|
9867 |
|
9868 |
|
9869 |
|
9870 |
|
9871 |
|
9872 |
|
9873 |
|
9874 |
|
9875 |
|
9876 |
|
9877 |
|
9878 |
|
9879 |
|
9880 |
|
9881 |
|
9882 |
|
9883 |
|
9884 |
|
9885 |
|
9886 |
|
9887 |
|
9888 |
|
9889 |
|
9890 |
|
9891 |
|
9892 | module.exports = Duplex;
|
9893 |
|
9894 |
|
9895 | var objectKeys = Object.keys || function (obj) {
|
9896 | var keys = [];
|
9897 | for (var key in obj) keys.push(key);
|
9898 | return keys;
|
9899 | }
|
9900 |
|
9901 |
|
9902 |
|
9903 |
|
9904 | var util = _dereq_(13);
|
9905 | util.inherits = _dereq_(24);
|
9906 |
|
9907 |
|
9908 | var Readable = _dereq_(64);
|
9909 | var Writable = _dereq_(66);
|
9910 |
|
9911 | util.inherits(Duplex, Readable);
|
9912 |
|
9913 | forEach(objectKeys(Writable.prototype), function(method) {
|
9914 | if (!Duplex.prototype[method])
|
9915 | Duplex.prototype[method] = Writable.prototype[method];
|
9916 | });
|
9917 |
|
9918 | function Duplex(options) {
|
9919 | if (!(this instanceof Duplex))
|
9920 | return new Duplex(options);
|
9921 |
|
9922 | Readable.call(this, options);
|
9923 | Writable.call(this, options);
|
9924 |
|
9925 | if (options && options.readable === false)
|
9926 | this.readable = false;
|
9927 |
|
9928 | if (options && options.writable === false)
|
9929 | this.writable = false;
|
9930 |
|
9931 | this.allowHalfOpen = true;
|
9932 | if (options && options.allowHalfOpen === false)
|
9933 | this.allowHalfOpen = false;
|
9934 |
|
9935 | this.once('end', onend);
|
9936 | }
|
9937 |
|
9938 |
|
9939 | function onend() {
|
9940 |
|
9941 |
|
9942 | if (this.allowHalfOpen || this._writableState.ended)
|
9943 | return;
|
9944 |
|
9945 |
|
9946 |
|
9947 | process.nextTick(this.end.bind(this));
|
9948 | }
|
9949 |
|
9950 | function forEach (xs, f) {
|
9951 | for (var i = 0, l = xs.length; i < l; i++) {
|
9952 | f(xs[i], i);
|
9953 | }
|
9954 | }
|
9955 |
|
9956 | }).call(this,_dereq_(60))
|
9957 | },{"13":13,"24":24,"60":60,"64":64,"66":66}],63:[function(_dereq_,module,exports){
|
9958 |
|
9959 |
|
9960 |
|
9961 |
|
9962 |
|
9963 |
|
9964 |
|
9965 |
|
9966 |
|
9967 |
|
9968 |
|
9969 |
|
9970 |
|
9971 |
|
9972 |
|
9973 |
|
9974 |
|
9975 |
|
9976 |
|
9977 |
|
9978 |
|
9979 |
|
9980 |
|
9981 |
|
9982 |
|
9983 | module.exports = PassThrough;
|
9984 |
|
9985 | var Transform = _dereq_(65);
|
9986 |
|
9987 |
|
9988 | var util = _dereq_(13);
|
9989 | util.inherits = _dereq_(24);
|
9990 |
|
9991 |
|
9992 | util.inherits(PassThrough, Transform);
|
9993 |
|
9994 | function PassThrough(options) {
|
9995 | if (!(this instanceof PassThrough))
|
9996 | return new PassThrough(options);
|
9997 |
|
9998 | Transform.call(this, options);
|
9999 | }
|
10000 |
|
10001 | PassThrough.prototype._transform = function(chunk, encoding, cb) {
|
10002 | cb(null, chunk);
|
10003 | };
|
10004 |
|
10005 | },{"13":13,"24":24,"65":65}],64:[function(_dereq_,module,exports){
|
10006 | (function (process){
|
10007 |
|
10008 |
|
10009 |
|
10010 |
|
10011 |
|
10012 |
|
10013 |
|
10014 |
|
10015 |
|
10016 |
|
10017 |
|
10018 |
|
10019 |
|
10020 |
|
10021 |
|
10022 |
|
10023 |
|
10024 |
|
10025 |
|
10026 |
|
10027 |
|
10028 | module.exports = Readable;
|
10029 |
|
10030 |
|
10031 | var isArray = _dereq_(67);
|
10032 |
|
10033 |
|
10034 |
|
10035 |
|
10036 | var Buffer = _dereq_(12).Buffer;
|
10037 |
|
10038 |
|
10039 | Readable.ReadableState = ReadableState;
|
10040 |
|
10041 | var EE = _dereq_(18).EventEmitter;
|
10042 |
|
10043 |
|
10044 | if (!EE.listenerCount) EE.listenerCount = function(emitter, type) {
|
10045 | return emitter.listeners(type).length;
|
10046 | };
|
10047 |
|
10048 |
|
10049 | var Stream = _dereq_(72);
|
10050 |
|
10051 |
|
10052 | var util = _dereq_(13);
|
10053 | util.inherits = _dereq_(24);
|
10054 |
|
10055 |
|
10056 | var StringDecoder;
|
10057 |
|
10058 | util.inherits(Readable, Stream);
|
10059 |
|
10060 | function ReadableState(options, stream) {
|
10061 | options = options || {};
|
10062 |
|
10063 |
|
10064 |
|
10065 | var hwm = options.highWaterMark;
|
10066 | this.highWaterMark = (hwm || hwm === 0) ? hwm : 16 * 1024;
|
10067 |
|
10068 |
|
10069 | this.highWaterMark = ~~this.highWaterMark;
|
10070 |
|
10071 | this.buffer = [];
|
10072 | this.length = 0;
|
10073 | this.pipes = null;
|
10074 | this.pipesCount = 0;
|
10075 | this.flowing = false;
|
10076 | this.ended = false;
|
10077 | this.endEmitted = false;
|
10078 | this.reading = false;
|
10079 |
|
10080 |
|
10081 |
|
10082 |
|
10083 |
|
10084 | this.calledRead = false;
|
10085 |
|
10086 |
|
10087 |
|
10088 |
|
10089 |
|
10090 | this.sync = true;
|
10091 |
|
10092 |
|
10093 |
|
10094 | this.needReadable = false;
|
10095 | this.emittedReadable = false;
|
10096 | this.readableListening = false;
|
10097 |
|
10098 |
|
10099 |
|
10100 |
|
10101 | this.objectMode = !!options.objectMode;
|
10102 |
|
10103 |
|
10104 |
|
10105 |
|
10106 | this.defaultEncoding = options.defaultEncoding || 'utf8';
|
10107 |
|
10108 |
|
10109 |
|
10110 | this.ranOut = false;
|
10111 |
|
10112 |
|
10113 | this.awaitDrain = 0;
|
10114 |
|
10115 |
|
10116 | this.readingMore = false;
|
10117 |
|
10118 | this.decoder = null;
|
10119 | this.encoding = null;
|
10120 | if (options.encoding) {
|
10121 | if (!StringDecoder)
|
10122 | StringDecoder = _dereq_(68).StringDecoder;
|
10123 | this.decoder = new StringDecoder(options.encoding);
|
10124 | this.encoding = options.encoding;
|
10125 | }
|
10126 | }
|
10127 |
|
10128 | function Readable(options) {
|
10129 | if (!(this instanceof Readable))
|
10130 | return new Readable(options);
|
10131 |
|
10132 | this._readableState = new ReadableState(options, this);
|
10133 |
|
10134 |
|
10135 | this.readable = true;
|
10136 |
|
10137 | Stream.call(this);
|
10138 | }
|
10139 |
|
10140 |
|
10141 |
|
10142 |
|
10143 |
|
10144 | Readable.prototype.push = function(chunk, encoding) {
|
10145 | var state = this._readableState;
|
10146 |
|
10147 | if (typeof chunk === 'string' && !state.objectMode) {
|
10148 | encoding = encoding || state.defaultEncoding;
|
10149 | if (encoding !== state.encoding) {
|
10150 | chunk = new Buffer(chunk, encoding);
|
10151 | encoding = '';
|
10152 | }
|
10153 | }
|
10154 |
|
10155 | return readableAddChunk(this, state, chunk, encoding, false);
|
10156 | };
|
10157 |
|
10158 |
|
10159 | Readable.prototype.unshift = function(chunk) {
|
10160 | var state = this._readableState;
|
10161 | return readableAddChunk(this, state, chunk, '', true);
|
10162 | };
|
10163 |
|
10164 | function readableAddChunk(stream, state, chunk, encoding, addToFront) {
|
10165 | var er = chunkInvalid(state, chunk);
|
10166 | if (er) {
|
10167 | stream.emit('error', er);
|
10168 | } else if (chunk === null || chunk === undefined) {
|
10169 | state.reading = false;
|
10170 | if (!state.ended)
|
10171 | onEofChunk(stream, state);
|
10172 | } else if (state.objectMode || chunk && chunk.length > 0) {
|
10173 | if (state.ended && !addToFront) {
|
10174 | var e = new Error('stream.push() after EOF');
|
10175 | stream.emit('error', e);
|
10176 | } else if (state.endEmitted && addToFront) {
|
10177 | var e = new Error('stream.unshift() after end event');
|
10178 | stream.emit('error', e);
|
10179 | } else {
|
10180 | if (state.decoder && !addToFront && !encoding)
|
10181 | chunk = state.decoder.write(chunk);
|
10182 |
|
10183 |
|
10184 | state.length += state.objectMode ? 1 : chunk.length;
|
10185 | if (addToFront) {
|
10186 | state.buffer.unshift(chunk);
|
10187 | } else {
|
10188 | state.reading = false;
|
10189 | state.buffer.push(chunk);
|
10190 | }
|
10191 |
|
10192 | if (state.needReadable)
|
10193 | emitReadable(stream);
|
10194 |
|
10195 | maybeReadMore(stream, state);
|
10196 | }
|
10197 | } else if (!addToFront) {
|
10198 | state.reading = false;
|
10199 | }
|
10200 |
|
10201 | return needMoreData(state);
|
10202 | }
|
10203 |
|
10204 |
|
10205 |
|
10206 |
|
10207 |
|
10208 |
|
10209 |
|
10210 |
|
10211 |
|
10212 |
|
10213 | function needMoreData(state) {
|
10214 | return !state.ended &&
|
10215 | (state.needReadable ||
|
10216 | state.length < state.highWaterMark ||
|
10217 | state.length === 0);
|
10218 | }
|
10219 |
|
10220 |
|
10221 | Readable.prototype.setEncoding = function(enc) {
|
10222 | if (!StringDecoder)
|
10223 | StringDecoder = _dereq_(68).StringDecoder;
|
10224 | this._readableState.decoder = new StringDecoder(enc);
|
10225 | this._readableState.encoding = enc;
|
10226 | };
|
10227 |
|
10228 |
|
10229 | var MAX_HWM = 0x800000;
|
10230 | function roundUpToNextPowerOf2(n) {
|
10231 | if (n >= MAX_HWM) {
|
10232 | n = MAX_HWM;
|
10233 | } else {
|
10234 |
|
10235 | n--;
|
10236 | for (var p = 1; p < 32; p <<= 1) n |= n >> p;
|
10237 | n++;
|
10238 | }
|
10239 | return n;
|
10240 | }
|
10241 |
|
10242 | function howMuchToRead(n, state) {
|
10243 | if (state.length === 0 && state.ended)
|
10244 | return 0;
|
10245 |
|
10246 | if (state.objectMode)
|
10247 | return n === 0 ? 0 : 1;
|
10248 |
|
10249 | if (n === null || isNaN(n)) {
|
10250 |
|
10251 | if (state.flowing && state.buffer.length)
|
10252 | return state.buffer[0].length;
|
10253 | else
|
10254 | return state.length;
|
10255 | }
|
10256 |
|
10257 | if (n <= 0)
|
10258 | return 0;
|
10259 |
|
10260 |
|
10261 |
|
10262 |
|
10263 |
|
10264 | if (n > state.highWaterMark)
|
10265 | state.highWaterMark = roundUpToNextPowerOf2(n);
|
10266 |
|
10267 |
|
10268 | if (n > state.length) {
|
10269 | if (!state.ended) {
|
10270 | state.needReadable = true;
|
10271 | return 0;
|
10272 | } else
|
10273 | return state.length;
|
10274 | }
|
10275 |
|
10276 | return n;
|
10277 | }
|
10278 |
|
10279 |
|
10280 | Readable.prototype.read = function(n) {
|
10281 | var state = this._readableState;
|
10282 | state.calledRead = true;
|
10283 | var nOrig = n;
|
10284 | var ret;
|
10285 |
|
10286 | if (typeof n !== 'number' || n > 0)
|
10287 | state.emittedReadable = false;
|
10288 |
|
10289 |
|
10290 |
|
10291 |
|
10292 | if (n === 0 &&
|
10293 | state.needReadable &&
|
10294 | (state.length >= state.highWaterMark || state.ended)) {
|
10295 | emitReadable(this);
|
10296 | return null;
|
10297 | }
|
10298 |
|
10299 | n = howMuchToRead(n, state);
|
10300 |
|
10301 |
|
10302 | if (n === 0 && state.ended) {
|
10303 | ret = null;
|
10304 |
|
10305 |
|
10306 |
|
10307 |
|
10308 |
|
10309 |
|
10310 |
|
10311 |
|
10312 |
|
10313 |
|
10314 |
|
10315 |
|
10316 | if (state.length > 0 && state.decoder) {
|
10317 | ret = fromList(n, state);
|
10318 | state.length -= ret.length;
|
10319 | }
|
10320 |
|
10321 | if (state.length === 0)
|
10322 | endReadable(this);
|
10323 |
|
10324 | return ret;
|
10325 | }
|
10326 |
|
10327 |
|
10328 |
|
10329 |
|
10330 |
|
10331 |
|
10332 |
|
10333 |
|
10334 |
|
10335 |
|
10336 |
|
10337 |
|
10338 |
|
10339 |
|
10340 |
|
10341 |
|
10342 |
|
10343 |
|
10344 |
|
10345 |
|
10346 |
|
10347 |
|
10348 |
|
10349 |
|
10350 | var doRead = state.needReadable;
|
10351 |
|
10352 |
|
10353 | if (state.length - n <= state.highWaterMark)
|
10354 | doRead = true;
|
10355 |
|
10356 |
|
10357 |
|
10358 | if (state.ended || state.reading)
|
10359 | doRead = false;
|
10360 |
|
10361 | if (doRead) {
|
10362 | state.reading = true;
|
10363 | state.sync = true;
|
10364 |
|
10365 | if (state.length === 0)
|
10366 | state.needReadable = true;
|
10367 |
|
10368 | this._read(state.highWaterMark);
|
10369 | state.sync = false;
|
10370 | }
|
10371 |
|
10372 |
|
10373 |
|
10374 |
|
10375 | if (doRead && !state.reading)
|
10376 | n = howMuchToRead(nOrig, state);
|
10377 |
|
10378 | if (n > 0)
|
10379 | ret = fromList(n, state);
|
10380 | else
|
10381 | ret = null;
|
10382 |
|
10383 | if (ret === null) {
|
10384 | state.needReadable = true;
|
10385 | n = 0;
|
10386 | }
|
10387 |
|
10388 | state.length -= n;
|
10389 |
|
10390 |
|
10391 |
|
10392 | if (state.length === 0 && !state.ended)
|
10393 | state.needReadable = true;
|
10394 |
|
10395 |
|
10396 |
|
10397 |
|
10398 | if (state.ended && !state.endEmitted && state.length === 0)
|
10399 | endReadable(this);
|
10400 |
|
10401 | return ret;
|
10402 | };
|
10403 |
|
10404 | function chunkInvalid(state, chunk) {
|
10405 | var er = null;
|
10406 | if (!Buffer.isBuffer(chunk) &&
|
10407 | 'string' !== typeof chunk &&
|
10408 | chunk !== null &&
|
10409 | chunk !== undefined &&
|
10410 | !state.objectMode) {
|
10411 | er = new TypeError('Invalid non-string/buffer chunk');
|
10412 | }
|
10413 | return er;
|
10414 | }
|
10415 |
|
10416 |
|
10417 | function onEofChunk(stream, state) {
|
10418 | if (state.decoder && !state.ended) {
|
10419 | var chunk = state.decoder.end();
|
10420 | if (chunk && chunk.length) {
|
10421 | state.buffer.push(chunk);
|
10422 | state.length += state.objectMode ? 1 : chunk.length;
|
10423 | }
|
10424 | }
|
10425 | state.ended = true;
|
10426 |
|
10427 |
|
10428 |
|
10429 | if (state.length > 0)
|
10430 | emitReadable(stream);
|
10431 | else
|
10432 | endReadable(stream);
|
10433 | }
|
10434 |
|
10435 |
|
10436 |
|
10437 |
|
10438 | function emitReadable(stream) {
|
10439 | var state = stream._readableState;
|
10440 | state.needReadable = false;
|
10441 | if (state.emittedReadable)
|
10442 | return;
|
10443 |
|
10444 | state.emittedReadable = true;
|
10445 | if (state.sync)
|
10446 | process.nextTick(function() {
|
10447 | emitReadable_(stream);
|
10448 | });
|
10449 | else
|
10450 | emitReadable_(stream);
|
10451 | }
|
10452 |
|
10453 | function emitReadable_(stream) {
|
10454 | stream.emit('readable');
|
10455 | }
|
10456 |
|
10457 |
|
10458 |
|
10459 |
|
10460 |
|
10461 |
|
10462 |
|
10463 |
|
10464 | function maybeReadMore(stream, state) {
|
10465 | if (!state.readingMore) {
|
10466 | state.readingMore = true;
|
10467 | process.nextTick(function() {
|
10468 | maybeReadMore_(stream, state);
|
10469 | });
|
10470 | }
|
10471 | }
|
10472 |
|
10473 | function maybeReadMore_(stream, state) {
|
10474 | var len = state.length;
|
10475 | while (!state.reading && !state.flowing && !state.ended &&
|
10476 | state.length < state.highWaterMark) {
|
10477 | stream.read(0);
|
10478 | if (len === state.length)
|
10479 |
|
10480 | break;
|
10481 | else
|
10482 | len = state.length;
|
10483 | }
|
10484 | state.readingMore = false;
|
10485 | }
|
10486 |
|
10487 |
|
10488 |
|
10489 |
|
10490 |
|
10491 | Readable.prototype._read = function(n) {
|
10492 | this.emit('error', new Error('not implemented'));
|
10493 | };
|
10494 |
|
10495 | Readable.prototype.pipe = function(dest, pipeOpts) {
|
10496 | var src = this;
|
10497 | var state = this._readableState;
|
10498 |
|
10499 | switch (state.pipesCount) {
|
10500 | case 0:
|
10501 | state.pipes = dest;
|
10502 | break;
|
10503 | case 1:
|
10504 | state.pipes = [state.pipes, dest];
|
10505 | break;
|
10506 | default:
|
10507 | state.pipes.push(dest);
|
10508 | break;
|
10509 | }
|
10510 | state.pipesCount += 1;
|
10511 |
|
10512 | var doEnd = (!pipeOpts || pipeOpts.end !== false) &&
|
10513 | dest !== process.stdout &&
|
10514 | dest !== process.stderr;
|
10515 |
|
10516 | var endFn = doEnd ? onend : cleanup;
|
10517 | if (state.endEmitted)
|
10518 | process.nextTick(endFn);
|
10519 | else
|
10520 | src.once('end', endFn);
|
10521 |
|
10522 | dest.on('unpipe', onunpipe);
|
10523 | function onunpipe(readable) {
|
10524 | if (readable !== src) return;
|
10525 | cleanup();
|
10526 | }
|
10527 |
|
10528 | function onend() {
|
10529 | dest.end();
|
10530 | }
|
10531 |
|
10532 |
|
10533 |
|
10534 |
|
10535 |
|
10536 | var ondrain = pipeOnDrain(src);
|
10537 | dest.on('drain', ondrain);
|
10538 |
|
10539 | function cleanup() {
|
10540 |
|
10541 | dest.removeListener('close', onclose);
|
10542 | dest.removeListener('finish', onfinish);
|
10543 | dest.removeListener('drain', ondrain);
|
10544 | dest.removeListener('error', onerror);
|
10545 | dest.removeListener('unpipe', onunpipe);
|
10546 | src.removeListener('end', onend);
|
10547 | src.removeListener('end', cleanup);
|
10548 |
|
10549 |
|
10550 |
|
10551 |
|
10552 |
|
10553 |
|
10554 | if (!dest._writableState || dest._writableState.needDrain)
|
10555 | ondrain();
|
10556 | }
|
10557 |
|
10558 |
|
10559 |
|
10560 | function onerror(er) {
|
10561 | unpipe();
|
10562 | dest.removeListener('error', onerror);
|
10563 | if (EE.listenerCount(dest, 'error') === 0)
|
10564 | dest.emit('error', er);
|
10565 | }
|
10566 |
|
10567 |
|
10568 | if (!dest._events || !dest._events.error)
|
10569 | dest.on('error', onerror);
|
10570 | else if (isArray(dest._events.error))
|
10571 | dest._events.error.unshift(onerror);
|
10572 | else
|
10573 | dest._events.error = [onerror, dest._events.error];
|
10574 |
|
10575 |
|
10576 |
|
10577 |
|
10578 | function onclose() {
|
10579 | dest.removeListener('finish', onfinish);
|
10580 | unpipe();
|
10581 | }
|
10582 | dest.once('close', onclose);
|
10583 | function onfinish() {
|
10584 | dest.removeListener('close', onclose);
|
10585 | unpipe();
|
10586 | }
|
10587 | dest.once('finish', onfinish);
|
10588 |
|
10589 | function unpipe() {
|
10590 | src.unpipe(dest);
|
10591 | }
|
10592 |
|
10593 |
|
10594 | dest.emit('pipe', src);
|
10595 |
|
10596 |
|
10597 | if (!state.flowing) {
|
10598 |
|
10599 |
|
10600 |
|
10601 |
|
10602 | this.on('readable', pipeOnReadable);
|
10603 |
|
10604 | state.flowing = true;
|
10605 | process.nextTick(function() {
|
10606 | flow(src);
|
10607 | });
|
10608 | }
|
10609 |
|
10610 | return dest;
|
10611 | };
|
10612 |
|
10613 | function pipeOnDrain(src) {
|
10614 | return function() {
|
10615 | var dest = this;
|
10616 | var state = src._readableState;
|
10617 | state.awaitDrain--;
|
10618 | if (state.awaitDrain === 0)
|
10619 | flow(src);
|
10620 | };
|
10621 | }
|
10622 |
|
10623 | function flow(src) {
|
10624 | var state = src._readableState;
|
10625 | var chunk;
|
10626 | state.awaitDrain = 0;
|
10627 |
|
10628 | function write(dest, i, list) {
|
10629 | var written = dest.write(chunk);
|
10630 | if (false === written) {
|
10631 | state.awaitDrain++;
|
10632 | }
|
10633 | }
|
10634 |
|
10635 | while (state.pipesCount && null !== (chunk = src.read())) {
|
10636 |
|
10637 | if (state.pipesCount === 1)
|
10638 | write(state.pipes, 0, null);
|
10639 | else
|
10640 | forEach(state.pipes, write);
|
10641 |
|
10642 | src.emit('data', chunk);
|
10643 |
|
10644 |
|
10645 | if (state.awaitDrain > 0)
|
10646 | return;
|
10647 | }
|
10648 |
|
10649 |
|
10650 |
|
10651 |
|
10652 |
|
10653 | if (state.pipesCount === 0) {
|
10654 | state.flowing = false;
|
10655 |
|
10656 |
|
10657 | if (EE.listenerCount(src, 'data') > 0)
|
10658 | emitDataEvents(src);
|
10659 | return;
|
10660 | }
|
10661 |
|
10662 |
|
10663 |
|
10664 | state.ranOut = true;
|
10665 | }
|
10666 |
|
10667 | function pipeOnReadable() {
|
10668 | if (this._readableState.ranOut) {
|
10669 | this._readableState.ranOut = false;
|
10670 | flow(this);
|
10671 | }
|
10672 | }
|
10673 |
|
10674 |
|
10675 | Readable.prototype.unpipe = function(dest) {
|
10676 | var state = this._readableState;
|
10677 |
|
10678 |
|
10679 | if (state.pipesCount === 0)
|
10680 | return this;
|
10681 |
|
10682 |
|
10683 | if (state.pipesCount === 1) {
|
10684 |
|
10685 | if (dest && dest !== state.pipes)
|
10686 | return this;
|
10687 |
|
10688 | if (!dest)
|
10689 | dest = state.pipes;
|
10690 |
|
10691 |
|
10692 | state.pipes = null;
|
10693 | state.pipesCount = 0;
|
10694 | this.removeListener('readable', pipeOnReadable);
|
10695 | state.flowing = false;
|
10696 | if (dest)
|
10697 | dest.emit('unpipe', this);
|
10698 | return this;
|
10699 | }
|
10700 |
|
10701 |
|
10702 |
|
10703 | if (!dest) {
|
10704 |
|
10705 | var dests = state.pipes;
|
10706 | var len = state.pipesCount;
|
10707 | state.pipes = null;
|
10708 | state.pipesCount = 0;
|
10709 | this.removeListener('readable', pipeOnReadable);
|
10710 | state.flowing = false;
|
10711 |
|
10712 | for (var i = 0; i < len; i++)
|
10713 | dests[i].emit('unpipe', this);
|
10714 | return this;
|
10715 | }
|
10716 |
|
10717 |
|
10718 | var i = indexOf(state.pipes, dest);
|
10719 | if (i === -1)
|
10720 | return this;
|
10721 |
|
10722 | state.pipes.splice(i, 1);
|
10723 | state.pipesCount -= 1;
|
10724 | if (state.pipesCount === 1)
|
10725 | state.pipes = state.pipes[0];
|
10726 |
|
10727 | dest.emit('unpipe', this);
|
10728 |
|
10729 | return this;
|
10730 | };
|
10731 |
|
10732 |
|
10733 |
|
10734 | Readable.prototype.on = function(ev, fn) {
|
10735 | var res = Stream.prototype.on.call(this, ev, fn);
|
10736 |
|
10737 | if (ev === 'data' && !this._readableState.flowing)
|
10738 | emitDataEvents(this);
|
10739 |
|
10740 | if (ev === 'readable' && this.readable) {
|
10741 | var state = this._readableState;
|
10742 | if (!state.readableListening) {
|
10743 | state.readableListening = true;
|
10744 | state.emittedReadable = false;
|
10745 | state.needReadable = true;
|
10746 | if (!state.reading) {
|
10747 | this.read(0);
|
10748 | } else if (state.length) {
|
10749 | emitReadable(this, state);
|
10750 | }
|
10751 | }
|
10752 | }
|
10753 |
|
10754 | return res;
|
10755 | };
|
10756 | Readable.prototype.addListener = Readable.prototype.on;
|
10757 |
|
10758 |
|
10759 |
|
10760 | Readable.prototype.resume = function() {
|
10761 | emitDataEvents(this);
|
10762 | this.read(0);
|
10763 | this.emit('resume');
|
10764 | };
|
10765 |
|
10766 | Readable.prototype.pause = function() {
|
10767 | emitDataEvents(this, true);
|
10768 | this.emit('pause');
|
10769 | };
|
10770 |
|
10771 | function emitDataEvents(stream, startPaused) {
|
10772 | var state = stream._readableState;
|
10773 |
|
10774 | if (state.flowing) {
|
10775 |
|
10776 | throw new Error('Cannot switch to old mode now.');
|
10777 | }
|
10778 |
|
10779 | var paused = startPaused || false;
|
10780 | var readable = false;
|
10781 |
|
10782 |
|
10783 | stream.readable = true;
|
10784 | stream.pipe = Stream.prototype.pipe;
|
10785 | stream.on = stream.addListener = Stream.prototype.on;
|
10786 |
|
10787 | stream.on('readable', function() {
|
10788 | readable = true;
|
10789 |
|
10790 | var c;
|
10791 | while (!paused && (null !== (c = stream.read())))
|
10792 | stream.emit('data', c);
|
10793 |
|
10794 | if (c === null) {
|
10795 | readable = false;
|
10796 | stream._readableState.needReadable = true;
|
10797 | }
|
10798 | });
|
10799 |
|
10800 | stream.pause = function() {
|
10801 | paused = true;
|
10802 | this.emit('pause');
|
10803 | };
|
10804 |
|
10805 | stream.resume = function() {
|
10806 | paused = false;
|
10807 | if (readable)
|
10808 | process.nextTick(function() {
|
10809 | stream.emit('readable');
|
10810 | });
|
10811 | else
|
10812 | this.read(0);
|
10813 | this.emit('resume');
|
10814 | };
|
10815 |
|
10816 |
|
10817 | stream.emit('readable');
|
10818 | }
|
10819 |
|
10820 |
|
10821 |
|
10822 |
|
10823 | Readable.prototype.wrap = function(stream) {
|
10824 | var state = this._readableState;
|
10825 | var paused = false;
|
10826 |
|
10827 | var self = this;
|
10828 | stream.on('end', function() {
|
10829 | if (state.decoder && !state.ended) {
|
10830 | var chunk = state.decoder.end();
|
10831 | if (chunk && chunk.length)
|
10832 | self.push(chunk);
|
10833 | }
|
10834 |
|
10835 | self.push(null);
|
10836 | });
|
10837 |
|
10838 | stream.on('data', function(chunk) {
|
10839 | if (state.decoder)
|
10840 | chunk = state.decoder.write(chunk);
|
10841 |
|
10842 |
|
10843 |
|
10844 | if (state.objectMode && (chunk === null || chunk === undefined))
|
10845 | return;
|
10846 | else if (!state.objectMode && (!chunk || !chunk.length))
|
10847 | return;
|
10848 |
|
10849 | var ret = self.push(chunk);
|
10850 | if (!ret) {
|
10851 | paused = true;
|
10852 | stream.pause();
|
10853 | }
|
10854 | });
|
10855 |
|
10856 |
|
10857 |
|
10858 | for (var i in stream) {
|
10859 | if (typeof stream[i] === 'function' &&
|
10860 | typeof this[i] === 'undefined') {
|
10861 | this[i] = function(method) { return function() {
|
10862 | return stream[method].apply(stream, arguments);
|
10863 | }}(i);
|
10864 | }
|
10865 | }
|
10866 |
|
10867 |
|
10868 | var events = ['error', 'close', 'destroy', 'pause', 'resume'];
|
10869 | forEach(events, function(ev) {
|
10870 | stream.on(ev, self.emit.bind(self, ev));
|
10871 | });
|
10872 |
|
10873 |
|
10874 |
|
10875 | self._read = function(n) {
|
10876 | if (paused) {
|
10877 | paused = false;
|
10878 | stream.resume();
|
10879 | }
|
10880 | };
|
10881 |
|
10882 | return self;
|
10883 | };
|
10884 |
|
10885 |
|
10886 |
|
10887 |
|
10888 | Readable._fromList = fromList;
|
10889 |
|
10890 |
|
10891 |
|
10892 | function fromList(n, state) {
|
10893 | var list = state.buffer;
|
10894 | var length = state.length;
|
10895 | var stringMode = !!state.decoder;
|
10896 | var objectMode = !!state.objectMode;
|
10897 | var ret;
|
10898 |
|
10899 |
|
10900 | if (list.length === 0)
|
10901 | return null;
|
10902 |
|
10903 | if (length === 0)
|
10904 | ret = null;
|
10905 | else if (objectMode)
|
10906 | ret = list.shift();
|
10907 | else if (!n || n >= length) {
|
10908 |
|
10909 | if (stringMode)
|
10910 | ret = list.join('');
|
10911 | else
|
10912 | ret = Buffer.concat(list, length);
|
10913 | list.length = 0;
|
10914 | } else {
|
10915 |
|
10916 | if (n < list[0].length) {
|
10917 |
|
10918 |
|
10919 | var buf = list[0];
|
10920 | ret = buf.slice(0, n);
|
10921 | list[0] = buf.slice(n);
|
10922 | } else if (n === list[0].length) {
|
10923 |
|
10924 | ret = list.shift();
|
10925 | } else {
|
10926 |
|
10927 |
|
10928 | if (stringMode)
|
10929 | ret = '';
|
10930 | else
|
10931 | ret = new Buffer(n);
|
10932 |
|
10933 | var c = 0;
|
10934 | for (var i = 0, l = list.length; i < l && c < n; i++) {
|
10935 | var buf = list[0];
|
10936 | var cpy = Math.min(n - c, buf.length);
|
10937 |
|
10938 | if (stringMode)
|
10939 | ret += buf.slice(0, cpy);
|
10940 | else
|
10941 | buf.copy(ret, c, 0, cpy);
|
10942 |
|
10943 | if (cpy < buf.length)
|
10944 | list[0] = buf.slice(cpy);
|
10945 | else
|
10946 | list.shift();
|
10947 |
|
10948 | c += cpy;
|
10949 | }
|
10950 | }
|
10951 | }
|
10952 |
|
10953 | return ret;
|
10954 | }
|
10955 |
|
10956 | function endReadable(stream) {
|
10957 | var state = stream._readableState;
|
10958 |
|
10959 |
|
10960 |
|
10961 | if (state.length > 0)
|
10962 | throw new Error('endReadable called on non-empty stream');
|
10963 |
|
10964 | if (!state.endEmitted && state.calledRead) {
|
10965 | state.ended = true;
|
10966 | process.nextTick(function() {
|
10967 |
|
10968 | if (!state.endEmitted && state.length === 0) {
|
10969 | state.endEmitted = true;
|
10970 | stream.readable = false;
|
10971 | stream.emit('end');
|
10972 | }
|
10973 | });
|
10974 | }
|
10975 | }
|
10976 |
|
10977 | function forEach (xs, f) {
|
10978 | for (var i = 0, l = xs.length; i < l; i++) {
|
10979 | f(xs[i], i);
|
10980 | }
|
10981 | }
|
10982 |
|
10983 | function indexOf (xs, x) {
|
10984 | for (var i = 0, l = xs.length; i < l; i++) {
|
10985 | if (xs[i] === x) return i;
|
10986 | }
|
10987 | return -1;
|
10988 | }
|
10989 |
|
10990 | }).call(this,_dereq_(60))
|
10991 | },{"12":12,"13":13,"18":18,"24":24,"60":60,"67":67,"68":68,"72":72}],65:[function(_dereq_,module,exports){
|
10992 |
|
10993 |
|
10994 |
|
10995 |
|
10996 |
|
10997 |
|
10998 |
|
10999 |
|
11000 |
|
11001 |
|
11002 |
|
11003 |
|
11004 |
|
11005 |
|
11006 |
|
11007 |
|
11008 |
|
11009 |
|
11010 |
|
11011 |
|
11012 |
|
11013 |
|
11014 |
|
11015 |
|
11016 |
|
11017 |
|
11018 |
|
11019 |
|
11020 |
|
11021 |
|
11022 |
|
11023 |
|
11024 |
|
11025 |
|
11026 |
|
11027 |
|
11028 |
|
11029 |
|
11030 |
|
11031 |
|
11032 |
|
11033 |
|
11034 |
|
11035 |
|
11036 |
|
11037 |
|
11038 |
|
11039 |
|
11040 |
|
11041 |
|
11042 |
|
11043 |
|
11044 |
|
11045 |
|
11046 |
|
11047 |
|
11048 |
|
11049 |
|
11050 |
|
11051 |
|
11052 |
|
11053 |
|
11054 |
|
11055 |
|
11056 | module.exports = Transform;
|
11057 |
|
11058 | var Duplex = _dereq_(62);
|
11059 |
|
11060 |
|
11061 | var util = _dereq_(13);
|
11062 | util.inherits = _dereq_(24);
|
11063 |
|
11064 |
|
11065 | util.inherits(Transform, Duplex);
|
11066 |
|
11067 |
|
11068 | function TransformState(options, stream) {
|
11069 | this.afterTransform = function(er, data) {
|
11070 | return afterTransform(stream, er, data);
|
11071 | };
|
11072 |
|
11073 | this.needTransform = false;
|
11074 | this.transforming = false;
|
11075 | this.writecb = null;
|
11076 | this.writechunk = null;
|
11077 | }
|
11078 |
|
11079 | function afterTransform(stream, er, data) {
|
11080 | var ts = stream._transformState;
|
11081 | ts.transforming = false;
|
11082 |
|
11083 | var cb = ts.writecb;
|
11084 |
|
11085 | if (!cb)
|
11086 | return stream.emit('error', new Error('no writecb in Transform class'));
|
11087 |
|
11088 | ts.writechunk = null;
|
11089 | ts.writecb = null;
|
11090 |
|
11091 | if (data !== null && data !== undefined)
|
11092 | stream.push(data);
|
11093 |
|
11094 | if (cb)
|
11095 | cb(er);
|
11096 |
|
11097 | var rs = stream._readableState;
|
11098 | rs.reading = false;
|
11099 | if (rs.needReadable || rs.length < rs.highWaterMark) {
|
11100 | stream._read(rs.highWaterMark);
|
11101 | }
|
11102 | }
|
11103 |
|
11104 |
|
11105 | function Transform(options) {
|
11106 | if (!(this instanceof Transform))
|
11107 | return new Transform(options);
|
11108 |
|
11109 | Duplex.call(this, options);
|
11110 |
|
11111 | var ts = this._transformState = new TransformState(options, this);
|
11112 |
|
11113 |
|
11114 | var stream = this;
|
11115 |
|
11116 |
|
11117 | this._readableState.needReadable = true;
|
11118 |
|
11119 |
|
11120 |
|
11121 |
|
11122 | this._readableState.sync = false;
|
11123 |
|
11124 | this.once('finish', function() {
|
11125 | if ('function' === typeof this._flush)
|
11126 | this._flush(function(er) {
|
11127 | done(stream, er);
|
11128 | });
|
11129 | else
|
11130 | done(stream);
|
11131 | });
|
11132 | }
|
11133 |
|
11134 | Transform.prototype.push = function(chunk, encoding) {
|
11135 | this._transformState.needTransform = false;
|
11136 | return Duplex.prototype.push.call(this, chunk, encoding);
|
11137 | };
|
11138 |
|
11139 |
|
11140 |
|
11141 |
|
11142 |
|
11143 |
|
11144 |
|
11145 |
|
11146 |
|
11147 |
|
11148 |
|
11149 | Transform.prototype._transform = function(chunk, encoding, cb) {
|
11150 | throw new Error('not implemented');
|
11151 | };
|
11152 |
|
11153 | Transform.prototype._write = function(chunk, encoding, cb) {
|
11154 | var ts = this._transformState;
|
11155 | ts.writecb = cb;
|
11156 | ts.writechunk = chunk;
|
11157 | ts.writeencoding = encoding;
|
11158 | if (!ts.transforming) {
|
11159 | var rs = this._readableState;
|
11160 | if (ts.needTransform ||
|
11161 | rs.needReadable ||
|
11162 | rs.length < rs.highWaterMark)
|
11163 | this._read(rs.highWaterMark);
|
11164 | }
|
11165 | };
|
11166 |
|
11167 |
|
11168 |
|
11169 |
|
11170 | Transform.prototype._read = function(n) {
|
11171 | var ts = this._transformState;
|
11172 |
|
11173 | if (ts.writechunk !== null && ts.writecb && !ts.transforming) {
|
11174 | ts.transforming = true;
|
11175 | this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
|
11176 | } else {
|
11177 |
|
11178 |
|
11179 | ts.needTransform = true;
|
11180 | }
|
11181 | };
|
11182 |
|
11183 |
|
11184 | function done(stream, er) {
|
11185 | if (er)
|
11186 | return stream.emit('error', er);
|
11187 |
|
11188 |
|
11189 |
|
11190 | var ws = stream._writableState;
|
11191 | var rs = stream._readableState;
|
11192 | var ts = stream._transformState;
|
11193 |
|
11194 | if (ws.length)
|
11195 | throw new Error('calling transform done when ws.length != 0');
|
11196 |
|
11197 | if (ts.transforming)
|
11198 | throw new Error('calling transform done when still transforming');
|
11199 |
|
11200 | return stream.push(null);
|
11201 | }
|
11202 |
|
11203 | },{"13":13,"24":24,"62":62}],66:[function(_dereq_,module,exports){
|
11204 | (function (process){
|
11205 |
|
11206 |
|
11207 |
|
11208 |
|
11209 |
|
11210 |
|
11211 |
|
11212 |
|
11213 |
|
11214 |
|
11215 |
|
11216 |
|
11217 |
|
11218 |
|
11219 |
|
11220 |
|
11221 |
|
11222 |
|
11223 |
|
11224 |
|
11225 |
|
11226 |
|
11227 |
|
11228 |
|
11229 |
|
11230 | module.exports = Writable;
|
11231 |
|
11232 |
|
11233 | var Buffer = _dereq_(12).Buffer;
|
11234 |
|
11235 |
|
11236 | Writable.WritableState = WritableState;
|
11237 |
|
11238 |
|
11239 |
|
11240 | var util = _dereq_(13);
|
11241 | util.inherits = _dereq_(24);
|
11242 |
|
11243 |
|
11244 | var Stream = _dereq_(72);
|
11245 |
|
11246 | util.inherits(Writable, Stream);
|
11247 |
|
11248 | function WriteReq(chunk, encoding, cb) {
|
11249 | this.chunk = chunk;
|
11250 | this.encoding = encoding;
|
11251 | this.callback = cb;
|
11252 | }
|
11253 |
|
11254 | function WritableState(options, stream) {
|
11255 | options = options || {};
|
11256 |
|
11257 |
|
11258 |
|
11259 |
|
11260 | var hwm = options.highWaterMark;
|
11261 | this.highWaterMark = (hwm || hwm === 0) ? hwm : 16 * 1024;
|
11262 |
|
11263 |
|
11264 |
|
11265 | this.objectMode = !!options.objectMode;
|
11266 |
|
11267 |
|
11268 | this.highWaterMark = ~~this.highWaterMark;
|
11269 |
|
11270 | this.needDrain = false;
|
11271 |
|
11272 | this.ending = false;
|
11273 |
|
11274 | this.ended = false;
|
11275 |
|
11276 | this.finished = false;
|
11277 |
|
11278 |
|
11279 |
|
11280 |
|
11281 | var noDecode = options.decodeStrings === false;
|
11282 | this.decodeStrings = !noDecode;
|
11283 |
|
11284 |
|
11285 |
|
11286 |
|
11287 | this.defaultEncoding = options.defaultEncoding || 'utf8';
|
11288 |
|
11289 |
|
11290 |
|
11291 |
|
11292 | this.length = 0;
|
11293 |
|
11294 |
|
11295 | this.writing = false;
|
11296 |
|
11297 |
|
11298 |
|
11299 |
|
11300 |
|
11301 | this.sync = true;
|
11302 |
|
11303 |
|
11304 |
|
11305 |
|
11306 | this.bufferProcessing = false;
|
11307 |
|
11308 |
|
11309 | this.onwrite = function(er) {
|
11310 | onwrite(stream, er);
|
11311 | };
|
11312 |
|
11313 |
|
11314 | this.writecb = null;
|
11315 |
|
11316 |
|
11317 | this.writelen = 0;
|
11318 |
|
11319 | this.buffer = [];
|
11320 |
|
11321 |
|
11322 | this.errorEmitted = false;
|
11323 | }
|
11324 |
|
11325 | function Writable(options) {
|
11326 | var Duplex = _dereq_(62);
|
11327 |
|
11328 |
|
11329 |
|
11330 | if (!(this instanceof Writable) && !(this instanceof Duplex))
|
11331 | return new Writable(options);
|
11332 |
|
11333 | this._writableState = new WritableState(options, this);
|
11334 |
|
11335 |
|
11336 | this.writable = true;
|
11337 |
|
11338 | Stream.call(this);
|
11339 | }
|
11340 |
|
11341 |
|
11342 | Writable.prototype.pipe = function() {
|
11343 | this.emit('error', new Error('Cannot pipe. Not readable.'));
|
11344 | };
|
11345 |
|
11346 |
|
11347 | function writeAfterEnd(stream, state, cb) {
|
11348 | var er = new Error('write after end');
|
11349 |
|
11350 | stream.emit('error', er);
|
11351 | process.nextTick(function() {
|
11352 | cb(er);
|
11353 | });
|
11354 | }
|
11355 |
|
11356 |
|
11357 |
|
11358 |
|
11359 |
|
11360 |
|
11361 | function validChunk(stream, state, chunk, cb) {
|
11362 | var valid = true;
|
11363 | if (!Buffer.isBuffer(chunk) &&
|
11364 | 'string' !== typeof chunk &&
|
11365 | chunk !== null &&
|
11366 | chunk !== undefined &&
|
11367 | !state.objectMode) {
|
11368 | var er = new TypeError('Invalid non-string/buffer chunk');
|
11369 | stream.emit('error', er);
|
11370 | process.nextTick(function() {
|
11371 | cb(er);
|
11372 | });
|
11373 | valid = false;
|
11374 | }
|
11375 | return valid;
|
11376 | }
|
11377 |
|
11378 | Writable.prototype.write = function(chunk, encoding, cb) {
|
11379 | var state = this._writableState;
|
11380 | var ret = false;
|
11381 |
|
11382 | if (typeof encoding === 'function') {
|
11383 | cb = encoding;
|
11384 | encoding = null;
|
11385 | }
|
11386 |
|
11387 | if (Buffer.isBuffer(chunk))
|
11388 | encoding = 'buffer';
|
11389 | else if (!encoding)
|
11390 | encoding = state.defaultEncoding;
|
11391 |
|
11392 | if (typeof cb !== 'function')
|
11393 | cb = function() {};
|
11394 |
|
11395 | if (state.ended)
|
11396 | writeAfterEnd(this, state, cb);
|
11397 | else if (validChunk(this, state, chunk, cb))
|
11398 | ret = writeOrBuffer(this, state, chunk, encoding, cb);
|
11399 |
|
11400 | return ret;
|
11401 | };
|
11402 |
|
11403 | function decodeChunk(state, chunk, encoding) {
|
11404 | if (!state.objectMode &&
|
11405 | state.decodeStrings !== false &&
|
11406 | typeof chunk === 'string') {
|
11407 | chunk = new Buffer(chunk, encoding);
|
11408 | }
|
11409 | return chunk;
|
11410 | }
|
11411 |
|
11412 |
|
11413 |
|
11414 |
|
11415 | function writeOrBuffer(stream, state, chunk, encoding, cb) {
|
11416 | chunk = decodeChunk(state, chunk, encoding);
|
11417 | if (Buffer.isBuffer(chunk))
|
11418 | encoding = 'buffer';
|
11419 | var len = state.objectMode ? 1 : chunk.length;
|
11420 |
|
11421 | state.length += len;
|
11422 |
|
11423 | var ret = state.length < state.highWaterMark;
|
11424 |
|
11425 | if (!ret)
|
11426 | state.needDrain = true;
|
11427 |
|
11428 | if (state.writing)
|
11429 | state.buffer.push(new WriteReq(chunk, encoding, cb));
|
11430 | else
|
11431 | doWrite(stream, state, len, chunk, encoding, cb);
|
11432 |
|
11433 | return ret;
|
11434 | }
|
11435 |
|
11436 | function doWrite(stream, state, len, chunk, encoding, cb) {
|
11437 | state.writelen = len;
|
11438 | state.writecb = cb;
|
11439 | state.writing = true;
|
11440 | state.sync = true;
|
11441 | stream._write(chunk, encoding, state.onwrite);
|
11442 | state.sync = false;
|
11443 | }
|
11444 |
|
11445 | function onwriteError(stream, state, sync, er, cb) {
|
11446 | if (sync)
|
11447 | process.nextTick(function() {
|
11448 | cb(er);
|
11449 | });
|
11450 | else
|
11451 | cb(er);
|
11452 |
|
11453 | stream._writableState.errorEmitted = true;
|
11454 | stream.emit('error', er);
|
11455 | }
|
11456 |
|
11457 | function onwriteStateUpdate(state) {
|
11458 | state.writing = false;
|
11459 | state.writecb = null;
|
11460 | state.length -= state.writelen;
|
11461 | state.writelen = 0;
|
11462 | }
|
11463 |
|
11464 | function onwrite(stream, er) {
|
11465 | var state = stream._writableState;
|
11466 | var sync = state.sync;
|
11467 | var cb = state.writecb;
|
11468 |
|
11469 | onwriteStateUpdate(state);
|
11470 |
|
11471 | if (er)
|
11472 | onwriteError(stream, state, sync, er, cb);
|
11473 | else {
|
11474 |
|
11475 | var finished = needFinish(stream, state);
|
11476 |
|
11477 | if (!finished && !state.bufferProcessing && state.buffer.length)
|
11478 | clearBuffer(stream, state);
|
11479 |
|
11480 | if (sync) {
|
11481 | process.nextTick(function() {
|
11482 | afterWrite(stream, state, finished, cb);
|
11483 | });
|
11484 | } else {
|
11485 | afterWrite(stream, state, finished, cb);
|
11486 | }
|
11487 | }
|
11488 | }
|
11489 |
|
11490 | function afterWrite(stream, state, finished, cb) {
|
11491 | if (!finished)
|
11492 | onwriteDrain(stream, state);
|
11493 | cb();
|
11494 | if (finished)
|
11495 | finishMaybe(stream, state);
|
11496 | }
|
11497 |
|
11498 |
|
11499 |
|
11500 |
|
11501 | function onwriteDrain(stream, state) {
|
11502 | if (state.length === 0 && state.needDrain) {
|
11503 | state.needDrain = false;
|
11504 | stream.emit('drain');
|
11505 | }
|
11506 | }
|
11507 |
|
11508 |
|
11509 |
|
11510 | function clearBuffer(stream, state) {
|
11511 | state.bufferProcessing = true;
|
11512 |
|
11513 | for (var c = 0; c < state.buffer.length; c++) {
|
11514 | var entry = state.buffer[c];
|
11515 | var chunk = entry.chunk;
|
11516 | var encoding = entry.encoding;
|
11517 | var cb = entry.callback;
|
11518 | var len = state.objectMode ? 1 : chunk.length;
|
11519 |
|
11520 | doWrite(stream, state, len, chunk, encoding, cb);
|
11521 |
|
11522 |
|
11523 |
|
11524 |
|
11525 |
|
11526 | if (state.writing) {
|
11527 | c++;
|
11528 | break;
|
11529 | }
|
11530 | }
|
11531 |
|
11532 | state.bufferProcessing = false;
|
11533 | if (c < state.buffer.length)
|
11534 | state.buffer = state.buffer.slice(c);
|
11535 | else
|
11536 | state.buffer.length = 0;
|
11537 | }
|
11538 |
|
11539 | Writable.prototype._write = function(chunk, encoding, cb) {
|
11540 | cb(new Error('not implemented'));
|
11541 | };
|
11542 |
|
11543 | Writable.prototype.end = function(chunk, encoding, cb) {
|
11544 | var state = this._writableState;
|
11545 |
|
11546 | if (typeof chunk === 'function') {
|
11547 | cb = chunk;
|
11548 | chunk = null;
|
11549 | encoding = null;
|
11550 | } else if (typeof encoding === 'function') {
|
11551 | cb = encoding;
|
11552 | encoding = null;
|
11553 | }
|
11554 |
|
11555 | if (typeof chunk !== 'undefined' && chunk !== null)
|
11556 | this.write(chunk, encoding);
|
11557 |
|
11558 |
|
11559 | if (!state.ending && !state.finished)
|
11560 | endWritable(this, state, cb);
|
11561 | };
|
11562 |
|
11563 |
|
11564 | function needFinish(stream, state) {
|
11565 | return (state.ending &&
|
11566 | state.length === 0 &&
|
11567 | !state.finished &&
|
11568 | !state.writing);
|
11569 | }
|
11570 |
|
11571 | function finishMaybe(stream, state) {
|
11572 | var need = needFinish(stream, state);
|
11573 | if (need) {
|
11574 | state.finished = true;
|
11575 | stream.emit('finish');
|
11576 | }
|
11577 | return need;
|
11578 | }
|
11579 |
|
11580 | function endWritable(stream, state, cb) {
|
11581 | state.ending = true;
|
11582 | finishMaybe(stream, state);
|
11583 | if (cb) {
|
11584 | if (state.finished)
|
11585 | process.nextTick(cb);
|
11586 | else
|
11587 | stream.once('finish', cb);
|
11588 | }
|
11589 | state.ended = true;
|
11590 | }
|
11591 |
|
11592 | }).call(this,_dereq_(60))
|
11593 | },{"12":12,"13":13,"24":24,"60":60,"62":62,"72":72}],67:[function(_dereq_,module,exports){
|
11594 | module.exports = Array.isArray || function (arr) {
|
11595 | return Object.prototype.toString.call(arr) == '[object Array]';
|
11596 | };
|
11597 |
|
11598 | },{}],68:[function(_dereq_,module,exports){
|
11599 |
|
11600 |
|
11601 |
|
11602 |
|
11603 |
|
11604 |
|
11605 |
|
11606 |
|
11607 |
|
11608 |
|
11609 |
|
11610 |
|
11611 |
|
11612 |
|
11613 |
|
11614 |
|
11615 |
|
11616 |
|
11617 |
|
11618 |
|
11619 |
|
11620 | var Buffer = _dereq_(12).Buffer;
|
11621 |
|
11622 | var isBufferEncoding = Buffer.isEncoding
|
11623 | || function(encoding) {
|
11624 | switch (encoding && encoding.toLowerCase()) {
|
11625 | 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;
|
11626 | default: return false;
|
11627 | }
|
11628 | }
|
11629 |
|
11630 |
|
11631 | function assertEncoding(encoding) {
|
11632 | if (encoding && !isBufferEncoding(encoding)) {
|
11633 | throw new Error('Unknown encoding: ' + encoding);
|
11634 | }
|
11635 | }
|
11636 |
|
11637 |
|
11638 |
|
11639 |
|
11640 |
|
11641 |
|
11642 |
|
11643 |
|
11644 |
|
11645 | var StringDecoder = exports.StringDecoder = function(encoding) {
|
11646 | this.encoding = (encoding || 'utf8').toLowerCase().replace(/[-_]/, '');
|
11647 | assertEncoding(encoding);
|
11648 | switch (this.encoding) {
|
11649 | case 'utf8':
|
11650 |
|
11651 | this.surrogateSize = 3;
|
11652 | break;
|
11653 | case 'ucs2':
|
11654 | case 'utf16le':
|
11655 |
|
11656 | this.surrogateSize = 2;
|
11657 | this.detectIncompleteChar = utf16DetectIncompleteChar;
|
11658 | break;
|
11659 | case 'base64':
|
11660 |
|
11661 | this.surrogateSize = 3;
|
11662 | this.detectIncompleteChar = base64DetectIncompleteChar;
|
11663 | break;
|
11664 | default:
|
11665 | this.write = passThroughWrite;
|
11666 | return;
|
11667 | }
|
11668 |
|
11669 |
|
11670 |
|
11671 | this.charBuffer = new Buffer(6);
|
11672 |
|
11673 | this.charReceived = 0;
|
11674 |
|
11675 | this.charLength = 0;
|
11676 | };
|
11677 |
|
11678 |
|
11679 |
|
11680 |
|
11681 |
|
11682 |
|
11683 |
|
11684 |
|
11685 |
|
11686 |
|
11687 |
|
11688 | StringDecoder.prototype.write = function(buffer) {
|
11689 | var charStr = '';
|
11690 |
|
11691 | while (this.charLength) {
|
11692 |
|
11693 | var available = (buffer.length >= this.charLength - this.charReceived) ?
|
11694 | this.charLength - this.charReceived :
|
11695 | buffer.length;
|
11696 |
|
11697 |
|
11698 | buffer.copy(this.charBuffer, this.charReceived, 0, available);
|
11699 | this.charReceived += available;
|
11700 |
|
11701 | if (this.charReceived < this.charLength) {
|
11702 |
|
11703 | return '';
|
11704 | }
|
11705 |
|
11706 |
|
11707 | buffer = buffer.slice(available, buffer.length);
|
11708 |
|
11709 |
|
11710 | charStr = this.charBuffer.slice(0, this.charLength).toString(this.encoding);
|
11711 |
|
11712 |
|
11713 | var charCode = charStr.charCodeAt(charStr.length - 1);
|
11714 | if (charCode >= 0xD800 && charCode <= 0xDBFF) {
|
11715 | this.charLength += this.surrogateSize;
|
11716 | charStr = '';
|
11717 | continue;
|
11718 | }
|
11719 | this.charReceived = this.charLength = 0;
|
11720 |
|
11721 |
|
11722 | if (buffer.length === 0) {
|
11723 | return charStr;
|
11724 | }
|
11725 | break;
|
11726 | }
|
11727 |
|
11728 |
|
11729 | this.detectIncompleteChar(buffer);
|
11730 |
|
11731 | var end = buffer.length;
|
11732 | if (this.charLength) {
|
11733 |
|
11734 | buffer.copy(this.charBuffer, 0, buffer.length - this.charReceived, end);
|
11735 | end -= this.charReceived;
|
11736 | }
|
11737 |
|
11738 | charStr += buffer.toString(this.encoding, 0, end);
|
11739 |
|
11740 | var end = charStr.length - 1;
|
11741 | var charCode = charStr.charCodeAt(end);
|
11742 |
|
11743 | if (charCode >= 0xD800 && charCode <= 0xDBFF) {
|
11744 | var size = this.surrogateSize;
|
11745 | this.charLength += size;
|
11746 | this.charReceived += size;
|
11747 | this.charBuffer.copy(this.charBuffer, size, 0, size);
|
11748 | buffer.copy(this.charBuffer, 0, 0, size);
|
11749 | return charStr.substring(0, end);
|
11750 | }
|
11751 |
|
11752 |
|
11753 | return charStr;
|
11754 | };
|
11755 |
|
11756 |
|
11757 |
|
11758 |
|
11759 |
|
11760 | StringDecoder.prototype.detectIncompleteChar = function(buffer) {
|
11761 |
|
11762 | var i = (buffer.length >= 3) ? 3 : buffer.length;
|
11763 |
|
11764 |
|
11765 |
|
11766 | for (; i > 0; i--) {
|
11767 | var c = buffer[buffer.length - i];
|
11768 |
|
11769 |
|
11770 |
|
11771 |
|
11772 | if (i == 1 && c >> 5 == 0x06) {
|
11773 | this.charLength = 2;
|
11774 | break;
|
11775 | }
|
11776 |
|
11777 |
|
11778 | if (i <= 2 && c >> 4 == 0x0E) {
|
11779 | this.charLength = 3;
|
11780 | break;
|
11781 | }
|
11782 |
|
11783 |
|
11784 | if (i <= 3 && c >> 3 == 0x1E) {
|
11785 | this.charLength = 4;
|
11786 | break;
|
11787 | }
|
11788 | }
|
11789 | this.charReceived = i;
|
11790 | };
|
11791 |
|
11792 | StringDecoder.prototype.end = function(buffer) {
|
11793 | var res = '';
|
11794 | if (buffer && buffer.length)
|
11795 | res = this.write(buffer);
|
11796 |
|
11797 | if (this.charReceived) {
|
11798 | var cr = this.charReceived;
|
11799 | var buf = this.charBuffer;
|
11800 | var enc = this.encoding;
|
11801 | res += buf.slice(0, cr).toString(enc);
|
11802 | }
|
11803 |
|
11804 | return res;
|
11805 | };
|
11806 |
|
11807 | function passThroughWrite(buffer) {
|
11808 | return buffer.toString(this.encoding);
|
11809 | }
|
11810 |
|
11811 | function utf16DetectIncompleteChar(buffer) {
|
11812 | this.charReceived = buffer.length % 2;
|
11813 | this.charLength = this.charReceived ? 2 : 0;
|
11814 | }
|
11815 |
|
11816 | function base64DetectIncompleteChar(buffer) {
|
11817 | this.charReceived = buffer.length % 3;
|
11818 | this.charLength = this.charReceived ? 3 : 0;
|
11819 | }
|
11820 |
|
11821 | },{"12":12}],69:[function(_dereq_,module,exports){
|
11822 | var Stream = _dereq_(72);
|
11823 | exports = module.exports = _dereq_(64);
|
11824 | exports.Stream = Stream;
|
11825 | exports.Readable = exports;
|
11826 | exports.Writable = _dereq_(66);
|
11827 | exports.Duplex = _dereq_(62);
|
11828 | exports.Transform = _dereq_(65);
|
11829 | exports.PassThrough = _dereq_(63);
|
11830 |
|
11831 | },{"62":62,"63":63,"64":64,"65":65,"66":66,"72":72}],70:[function(_dereq_,module,exports){
|
11832 |
|
11833 | var buffer = _dereq_(12)
|
11834 | var Buffer = buffer.Buffer
|
11835 |
|
11836 |
|
11837 | function copyProps (src, dst) {
|
11838 | for (var key in src) {
|
11839 | dst[key] = src[key]
|
11840 | }
|
11841 | }
|
11842 | if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) {
|
11843 | module.exports = buffer
|
11844 | } else {
|
11845 |
|
11846 | copyProps(buffer, exports)
|
11847 | exports.Buffer = SafeBuffer
|
11848 | }
|
11849 |
|
11850 | function SafeBuffer (arg, encodingOrOffset, length) {
|
11851 | return Buffer(arg, encodingOrOffset, length)
|
11852 | }
|
11853 |
|
11854 |
|
11855 | copyProps(Buffer, SafeBuffer)
|
11856 |
|
11857 | SafeBuffer.from = function (arg, encodingOrOffset, length) {
|
11858 | if (typeof arg === 'number') {
|
11859 | throw new TypeError('Argument must not be a number')
|
11860 | }
|
11861 | return Buffer(arg, encodingOrOffset, length)
|
11862 | }
|
11863 |
|
11864 | SafeBuffer.alloc = function (size, fill, encoding) {
|
11865 | if (typeof size !== 'number') {
|
11866 | throw new TypeError('Argument must be a number')
|
11867 | }
|
11868 | var buf = Buffer(size)
|
11869 | if (fill !== undefined) {
|
11870 | if (typeof encoding === 'string') {
|
11871 | buf.fill(fill, encoding)
|
11872 | } else {
|
11873 | buf.fill(fill)
|
11874 | }
|
11875 | } else {
|
11876 | buf.fill(0)
|
11877 | }
|
11878 | return buf
|
11879 | }
|
11880 |
|
11881 | SafeBuffer.allocUnsafe = function (size) {
|
11882 | if (typeof size !== 'number') {
|
11883 | throw new TypeError('Argument must be a number')
|
11884 | }
|
11885 | return Buffer(size)
|
11886 | }
|
11887 |
|
11888 | SafeBuffer.allocUnsafeSlow = function (size) {
|
11889 | if (typeof size !== 'number') {
|
11890 | throw new TypeError('Argument must be a number')
|
11891 | }
|
11892 | return buffer.SlowBuffer(size)
|
11893 | }
|
11894 |
|
11895 | },{"12":12}],71:[function(_dereq_,module,exports){
|
11896 | (function (factory) {
|
11897 | if (typeof exports === 'object') {
|
11898 |
|
11899 | module.exports = factory();
|
11900 | } else if (typeof define === 'function' && define.amd) {
|
11901 |
|
11902 | define(factory);
|
11903 | } else {
|
11904 |
|
11905 | var glob;
|
11906 |
|
11907 | try {
|
11908 | glob = window;
|
11909 | } catch (e) {
|
11910 | glob = self;
|
11911 | }
|
11912 |
|
11913 | glob.SparkMD5 = factory();
|
11914 | }
|
11915 | }(function (undefined) {
|
11916 |
|
11917 | 'use strict';
|
11918 |
|
11919 | |
11920 |
|
11921 |
|
11922 |
|
11923 |
|
11924 |
|
11925 |
|
11926 |
|
11927 | |
11928 |
|
11929 |
|
11930 |
|
11931 |
|
11932 | var add32 = function (a, b) {
|
11933 | return (a + b) & 0xFFFFFFFF;
|
11934 | },
|
11935 | hex_chr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'];
|
11936 |
|
11937 |
|
11938 | function cmn(q, a, b, x, s, t) {
|
11939 | a = add32(add32(a, q), add32(x, t));
|
11940 | return add32((a << s) | (a >>> (32 - s)), b);
|
11941 | }
|
11942 |
|
11943 | function md5cycle(x, k) {
|
11944 | var a = x[0],
|
11945 | b = x[1],
|
11946 | c = x[2],
|
11947 | d = x[3];
|
11948 |
|
11949 | a += (b & c | ~b & d) + k[0] - 680876936 | 0;
|
11950 | a = (a << 7 | a >>> 25) + b | 0;
|
11951 | d += (a & b | ~a & c) + k[1] - 389564586 | 0;
|
11952 | d = (d << 12 | d >>> 20) + a | 0;
|
11953 | c += (d & a | ~d & b) + k[2] + 606105819 | 0;
|
11954 | c = (c << 17 | c >>> 15) + d | 0;
|
11955 | b += (c & d | ~c & a) + k[3] - 1044525330 | 0;
|
11956 | b = (b << 22 | b >>> 10) + c | 0;
|
11957 | a += (b & c | ~b & d) + k[4] - 176418897 | 0;
|
11958 | a = (a << 7 | a >>> 25) + b | 0;
|
11959 | d += (a & b | ~a & c) + k[5] + 1200080426 | 0;
|
11960 | d = (d << 12 | d >>> 20) + a | 0;
|
11961 | c += (d & a | ~d & b) + k[6] - 1473231341 | 0;
|
11962 | c = (c << 17 | c >>> 15) + d | 0;
|
11963 | b += (c & d | ~c & a) + k[7] - 45705983 | 0;
|
11964 | b = (b << 22 | b >>> 10) + c | 0;
|
11965 | a += (b & c | ~b & d) + k[8] + 1770035416 | 0;
|
11966 | a = (a << 7 | a >>> 25) + b | 0;
|
11967 | d += (a & b | ~a & c) + k[9] - 1958414417 | 0;
|
11968 | d = (d << 12 | d >>> 20) + a | 0;
|
11969 | c += (d & a | ~d & b) + k[10] - 42063 | 0;
|
11970 | c = (c << 17 | c >>> 15) + d | 0;
|
11971 | b += (c & d | ~c & a) + k[11] - 1990404162 | 0;
|
11972 | b = (b << 22 | b >>> 10) + c | 0;
|
11973 | a += (b & c | ~b & d) + k[12] + 1804603682 | 0;
|
11974 | a = (a << 7 | a >>> 25) + b | 0;
|
11975 | d += (a & b | ~a & c) + k[13] - 40341101 | 0;
|
11976 | d = (d << 12 | d >>> 20) + a | 0;
|
11977 | c += (d & a | ~d & b) + k[14] - 1502002290 | 0;
|
11978 | c = (c << 17 | c >>> 15) + d | 0;
|
11979 | b += (c & d | ~c & a) + k[15] + 1236535329 | 0;
|
11980 | b = (b << 22 | b >>> 10) + c | 0;
|
11981 |
|
11982 | a += (b & d | c & ~d) + k[1] - 165796510 | 0;
|
11983 | a = (a << 5 | a >>> 27) + b | 0;
|
11984 | d += (a & c | b & ~c) + k[6] - 1069501632 | 0;
|
11985 | d = (d << 9 | d >>> 23) + a | 0;
|
11986 | c += (d & b | a & ~b) + k[11] + 643717713 | 0;
|
11987 | c = (c << 14 | c >>> 18) + d | 0;
|
11988 | b += (c & a | d & ~a) + k[0] - 373897302 | 0;
|
11989 | b = (b << 20 | b >>> 12) + c | 0;
|
11990 | a += (b & d | c & ~d) + k[5] - 701558691 | 0;
|
11991 | a = (a << 5 | a >>> 27) + b | 0;
|
11992 | d += (a & c | b & ~c) + k[10] + 38016083 | 0;
|
11993 | d = (d << 9 | d >>> 23) + a | 0;
|
11994 | c += (d & b | a & ~b) + k[15] - 660478335 | 0;
|
11995 | c = (c << 14 | c >>> 18) + d | 0;
|
11996 | b += (c & a | d & ~a) + k[4] - 405537848 | 0;
|
11997 | b = (b << 20 | b >>> 12) + c | 0;
|
11998 | a += (b & d | c & ~d) + k[9] + 568446438 | 0;
|
11999 | a = (a << 5 | a >>> 27) + b | 0;
|
12000 | d += (a & c | b & ~c) + k[14] - 1019803690 | 0;
|
12001 | d = (d << 9 | d >>> 23) + a | 0;
|
12002 | c += (d & b | a & ~b) + k[3] - 187363961 | 0;
|
12003 | c = (c << 14 | c >>> 18) + d | 0;
|
12004 | b += (c & a | d & ~a) + k[8] + 1163531501 | 0;
|
12005 | b = (b << 20 | b >>> 12) + c | 0;
|
12006 | a += (b & d | c & ~d) + k[13] - 1444681467 | 0;
|
12007 | a = (a << 5 | a >>> 27) + b | 0;
|
12008 | d += (a & c | b & ~c) + k[2] - 51403784 | 0;
|
12009 | d = (d << 9 | d >>> 23) + a | 0;
|
12010 | c += (d & b | a & ~b) + k[7] + 1735328473 | 0;
|
12011 | c = (c << 14 | c >>> 18) + d | 0;
|
12012 | b += (c & a | d & ~a) + k[12] - 1926607734 | 0;
|
12013 | b = (b << 20 | b >>> 12) + c | 0;
|
12014 |
|
12015 | a += (b ^ c ^ d) + k[5] - 378558 | 0;
|
12016 | a = (a << 4 | a >>> 28) + b | 0;
|
12017 | d += (a ^ b ^ c) + k[8] - 2022574463 | 0;
|
12018 | d = (d << 11 | d >>> 21) + a | 0;
|
12019 | c += (d ^ a ^ b) + k[11] + 1839030562 | 0;
|
12020 | c = (c << 16 | c >>> 16) + d | 0;
|
12021 | b += (c ^ d ^ a) + k[14] - 35309556 | 0;
|
12022 | b = (b << 23 | b >>> 9) + c | 0;
|
12023 | a += (b ^ c ^ d) + k[1] - 1530992060 | 0;
|
12024 | a = (a << 4 | a >>> 28) + b | 0;
|
12025 | d += (a ^ b ^ c) + k[4] + 1272893353 | 0;
|
12026 | d = (d << 11 | d >>> 21) + a | 0;
|
12027 | c += (d ^ a ^ b) + k[7] - 155497632 | 0;
|
12028 | c = (c << 16 | c >>> 16) + d | 0;
|
12029 | b += (c ^ d ^ a) + k[10] - 1094730640 | 0;
|
12030 | b = (b << 23 | b >>> 9) + c | 0;
|
12031 | a += (b ^ c ^ d) + k[13] + 681279174 | 0;
|
12032 | a = (a << 4 | a >>> 28) + b | 0;
|
12033 | d += (a ^ b ^ c) + k[0] - 358537222 | 0;
|
12034 | d = (d << 11 | d >>> 21) + a | 0;
|
12035 | c += (d ^ a ^ b) + k[3] - 722521979 | 0;
|
12036 | c = (c << 16 | c >>> 16) + d | 0;
|
12037 | b += (c ^ d ^ a) + k[6] + 76029189 | 0;
|
12038 | b = (b << 23 | b >>> 9) + c | 0;
|
12039 | a += (b ^ c ^ d) + k[9] - 640364487 | 0;
|
12040 | a = (a << 4 | a >>> 28) + b | 0;
|
12041 | d += (a ^ b ^ c) + k[12] - 421815835 | 0;
|
12042 | d = (d << 11 | d >>> 21) + a | 0;
|
12043 | c += (d ^ a ^ b) + k[15] + 530742520 | 0;
|
12044 | c = (c << 16 | c >>> 16) + d | 0;
|
12045 | b += (c ^ d ^ a) + k[2] - 995338651 | 0;
|
12046 | b = (b << 23 | b >>> 9) + c | 0;
|
12047 |
|
12048 | a += (c ^ (b | ~d)) + k[0] - 198630844 | 0;
|
12049 | a = (a << 6 | a >>> 26) + b | 0;
|
12050 | d += (b ^ (a | ~c)) + k[7] + 1126891415 | 0;
|
12051 | d = (d << 10 | d >>> 22) + a | 0;
|
12052 | c += (a ^ (d | ~b)) + k[14] - 1416354905 | 0;
|
12053 | c = (c << 15 | c >>> 17) + d | 0;
|
12054 | b += (d ^ (c | ~a)) + k[5] - 57434055 | 0;
|
12055 | b = (b << 21 |b >>> 11) + c | 0;
|
12056 | a += (c ^ (b | ~d)) + k[12] + 1700485571 | 0;
|
12057 | a = (a << 6 | a >>> 26) + b | 0;
|
12058 | d += (b ^ (a | ~c)) + k[3] - 1894986606 | 0;
|
12059 | d = (d << 10 | d >>> 22) + a | 0;
|
12060 | c += (a ^ (d | ~b)) + k[10] - 1051523 | 0;
|
12061 | c = (c << 15 | c >>> 17) + d | 0;
|
12062 | b += (d ^ (c | ~a)) + k[1] - 2054922799 | 0;
|
12063 | b = (b << 21 |b >>> 11) + c | 0;
|
12064 | a += (c ^ (b | ~d)) + k[8] + 1873313359 | 0;
|
12065 | a = (a << 6 | a >>> 26) + b | 0;
|
12066 | d += (b ^ (a | ~c)) + k[15] - 30611744 | 0;
|
12067 | d = (d << 10 | d >>> 22) + a | 0;
|
12068 | c += (a ^ (d | ~b)) + k[6] - 1560198380 | 0;
|
12069 | c = (c << 15 | c >>> 17) + d | 0;
|
12070 | b += (d ^ (c | ~a)) + k[13] + 1309151649 | 0;
|
12071 | b = (b << 21 |b >>> 11) + c | 0;
|
12072 | a += (c ^ (b | ~d)) + k[4] - 145523070 | 0;
|
12073 | a = (a << 6 | a >>> 26) + b | 0;
|
12074 | d += (b ^ (a | ~c)) + k[11] - 1120210379 | 0;
|
12075 | d = (d << 10 | d >>> 22) + a | 0;
|
12076 | c += (a ^ (d | ~b)) + k[2] + 718787259 | 0;
|
12077 | c = (c << 15 | c >>> 17) + d | 0;
|
12078 | b += (d ^ (c | ~a)) + k[9] - 343485551 | 0;
|
12079 | b = (b << 21 | b >>> 11) + c | 0;
|
12080 |
|
12081 | x[0] = a + x[0] | 0;
|
12082 | x[1] = b + x[1] | 0;
|
12083 | x[2] = c + x[2] | 0;
|
12084 | x[3] = d + x[3] | 0;
|
12085 | }
|
12086 |
|
12087 | function md5blk(s) {
|
12088 | var md5blks = [],
|
12089 | i;
|
12090 |
|
12091 | for (i = 0; i < 64; i += 4) {
|
12092 | md5blks[i >> 2] = s.charCodeAt(i) + (s.charCodeAt(i + 1) << 8) + (s.charCodeAt(i + 2) << 16) + (s.charCodeAt(i + 3) << 24);
|
12093 | }
|
12094 | return md5blks;
|
12095 | }
|
12096 |
|
12097 | function md5blk_array(a) {
|
12098 | var md5blks = [],
|
12099 | i;
|
12100 |
|
12101 | for (i = 0; i < 64; i += 4) {
|
12102 | md5blks[i >> 2] = a[i] + (a[i + 1] << 8) + (a[i + 2] << 16) + (a[i + 3] << 24);
|
12103 | }
|
12104 | return md5blks;
|
12105 | }
|
12106 |
|
12107 | function md51(s) {
|
12108 | var n = s.length,
|
12109 | state = [1732584193, -271733879, -1732584194, 271733878],
|
12110 | i,
|
12111 | length,
|
12112 | tail,
|
12113 | tmp,
|
12114 | lo,
|
12115 | hi;
|
12116 |
|
12117 | for (i = 64; i <= n; i += 64) {
|
12118 | md5cycle(state, md5blk(s.substring(i - 64, i)));
|
12119 | }
|
12120 | s = s.substring(i - 64);
|
12121 | length = s.length;
|
12122 | tail = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
12123 | for (i = 0; i < length; i += 1) {
|
12124 | tail[i >> 2] |= s.charCodeAt(i) << ((i % 4) << 3);
|
12125 | }
|
12126 | tail[i >> 2] |= 0x80 << ((i % 4) << 3);
|
12127 | if (i > 55) {
|
12128 | md5cycle(state, tail);
|
12129 | for (i = 0; i < 16; i += 1) {
|
12130 | tail[i] = 0;
|
12131 | }
|
12132 | }
|
12133 |
|
12134 |
|
12135 | tmp = n * 8;
|
12136 | tmp = tmp.toString(16).match(/(.*?)(.{0,8})$/);
|
12137 | lo = parseInt(tmp[2], 16);
|
12138 | hi = parseInt(tmp[1], 16) || 0;
|
12139 |
|
12140 | tail[14] = lo;
|
12141 | tail[15] = hi;
|
12142 |
|
12143 | md5cycle(state, tail);
|
12144 | return state;
|
12145 | }
|
12146 |
|
12147 | function md51_array(a) {
|
12148 | var n = a.length,
|
12149 | state = [1732584193, -271733879, -1732584194, 271733878],
|
12150 | i,
|
12151 | length,
|
12152 | tail,
|
12153 | tmp,
|
12154 | lo,
|
12155 | hi;
|
12156 |
|
12157 | for (i = 64; i <= n; i += 64) {
|
12158 | md5cycle(state, md5blk_array(a.subarray(i - 64, i)));
|
12159 | }
|
12160 |
|
12161 |
|
12162 |
|
12163 |
|
12164 |
|
12165 | a = (i - 64) < n ? a.subarray(i - 64) : new Uint8Array(0);
|
12166 |
|
12167 | length = a.length;
|
12168 | tail = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
12169 | for (i = 0; i < length; i += 1) {
|
12170 | tail[i >> 2] |= a[i] << ((i % 4) << 3);
|
12171 | }
|
12172 |
|
12173 | tail[i >> 2] |= 0x80 << ((i % 4) << 3);
|
12174 | if (i > 55) {
|
12175 | md5cycle(state, tail);
|
12176 | for (i = 0; i < 16; i += 1) {
|
12177 | tail[i] = 0;
|
12178 | }
|
12179 | }
|
12180 |
|
12181 |
|
12182 | tmp = n * 8;
|
12183 | tmp = tmp.toString(16).match(/(.*?)(.{0,8})$/);
|
12184 | lo = parseInt(tmp[2], 16);
|
12185 | hi = parseInt(tmp[1], 16) || 0;
|
12186 |
|
12187 | tail[14] = lo;
|
12188 | tail[15] = hi;
|
12189 |
|
12190 | md5cycle(state, tail);
|
12191 |
|
12192 | return state;
|
12193 | }
|
12194 |
|
12195 | function rhex(n) {
|
12196 | var s = '',
|
12197 | j;
|
12198 | for (j = 0; j < 4; j += 1) {
|
12199 | s += hex_chr[(n >> (j * 8 + 4)) & 0x0F] + hex_chr[(n >> (j * 8)) & 0x0F];
|
12200 | }
|
12201 | return s;
|
12202 | }
|
12203 |
|
12204 | function hex(x) {
|
12205 | var i;
|
12206 | for (i = 0; i < x.length; i += 1) {
|
12207 | x[i] = rhex(x[i]);
|
12208 | }
|
12209 | return x.join('');
|
12210 | }
|
12211 |
|
12212 |
|
12213 | if (hex(md51('hello')) !== '5d41402abc4b2a76b9719d911017c592') {
|
12214 | add32 = function (x, y) {
|
12215 | var lsw = (x & 0xFFFF) + (y & 0xFFFF),
|
12216 | msw = (x >> 16) + (y >> 16) + (lsw >> 16);
|
12217 | return (msw << 16) | (lsw & 0xFFFF);
|
12218 | };
|
12219 | }
|
12220 |
|
12221 |
|
12222 |
|
12223 | |
12224 |
|
12225 |
|
12226 |
|
12227 |
|
12228 |
|
12229 | if (typeof ArrayBuffer !== 'undefined' && !ArrayBuffer.prototype.slice) {
|
12230 | (function () {
|
12231 | function clamp(val, length) {
|
12232 | val = (val | 0) || 0;
|
12233 |
|
12234 | if (val < 0) {
|
12235 | return Math.max(val + length, 0);
|
12236 | }
|
12237 |
|
12238 | return Math.min(val, length);
|
12239 | }
|
12240 |
|
12241 | ArrayBuffer.prototype.slice = function (from, to) {
|
12242 | var length = this.byteLength,
|
12243 | begin = clamp(from, length),
|
12244 | end = length,
|
12245 | num,
|
12246 | target,
|
12247 | targetArray,
|
12248 | sourceArray;
|
12249 |
|
12250 | if (to !== undefined) {
|
12251 | end = clamp(to, length);
|
12252 | }
|
12253 |
|
12254 | if (begin > end) {
|
12255 | return new ArrayBuffer(0);
|
12256 | }
|
12257 |
|
12258 | num = end - begin;
|
12259 | target = new ArrayBuffer(num);
|
12260 | targetArray = new Uint8Array(target);
|
12261 |
|
12262 | sourceArray = new Uint8Array(this, begin, num);
|
12263 | targetArray.set(sourceArray);
|
12264 |
|
12265 | return target;
|
12266 | };
|
12267 | })();
|
12268 | }
|
12269 |
|
12270 |
|
12271 |
|
12272 | |
12273 |
|
12274 |
|
12275 |
|
12276 | function toUtf8(str) {
|
12277 | if (/[\u0080-\uFFFF]/.test(str)) {
|
12278 | str = unescape(encodeURIComponent(str));
|
12279 | }
|
12280 |
|
12281 | return str;
|
12282 | }
|
12283 |
|
12284 | function utf8Str2ArrayBuffer(str, returnUInt8Array) {
|
12285 | var length = str.length,
|
12286 | buff = new ArrayBuffer(length),
|
12287 | arr = new Uint8Array(buff),
|
12288 | i;
|
12289 |
|
12290 | for (i = 0; i < length; i += 1) {
|
12291 | arr[i] = str.charCodeAt(i);
|
12292 | }
|
12293 |
|
12294 | return returnUInt8Array ? arr : buff;
|
12295 | }
|
12296 |
|
12297 | function arrayBuffer2Utf8Str(buff) {
|
12298 | return String.fromCharCode.apply(null, new Uint8Array(buff));
|
12299 | }
|
12300 |
|
12301 | function concatenateArrayBuffers(first, second, returnUInt8Array) {
|
12302 | var result = new Uint8Array(first.byteLength + second.byteLength);
|
12303 |
|
12304 | result.set(new Uint8Array(first));
|
12305 | result.set(new Uint8Array(second), first.byteLength);
|
12306 |
|
12307 | return returnUInt8Array ? result : result.buffer;
|
12308 | }
|
12309 |
|
12310 | function hexToBinaryString(hex) {
|
12311 | var bytes = [],
|
12312 | length = hex.length,
|
12313 | x;
|
12314 |
|
12315 | for (x = 0; x < length - 1; x += 2) {
|
12316 | bytes.push(parseInt(hex.substr(x, 2), 16));
|
12317 | }
|
12318 |
|
12319 | return String.fromCharCode.apply(String, bytes);
|
12320 | }
|
12321 |
|
12322 |
|
12323 |
|
12324 | |
12325 |
|
12326 |
|
12327 |
|
12328 |
|
12329 |
|
12330 |
|
12331 | function SparkMD5() {
|
12332 |
|
12333 | this.reset();
|
12334 | }
|
12335 |
|
12336 | |
12337 |
|
12338 |
|
12339 |
|
12340 |
|
12341 |
|
12342 |
|
12343 |
|
12344 | SparkMD5.prototype.append = function (str) {
|
12345 |
|
12346 |
|
12347 | this.appendBinary(toUtf8(str));
|
12348 |
|
12349 | return this;
|
12350 | };
|
12351 |
|
12352 | |
12353 |
|
12354 |
|
12355 |
|
12356 |
|
12357 |
|
12358 |
|
12359 | SparkMD5.prototype.appendBinary = function (contents) {
|
12360 | this._buff += contents;
|
12361 | this._length += contents.length;
|
12362 |
|
12363 | var length = this._buff.length,
|
12364 | i;
|
12365 |
|
12366 | for (i = 64; i <= length; i += 64) {
|
12367 | md5cycle(this._hash, md5blk(this._buff.substring(i - 64, i)));
|
12368 | }
|
12369 |
|
12370 | this._buff = this._buff.substring(i - 64);
|
12371 |
|
12372 | return this;
|
12373 | };
|
12374 |
|
12375 | |
12376 |
|
12377 |
|
12378 |
|
12379 |
|
12380 |
|
12381 |
|
12382 |
|
12383 | SparkMD5.prototype.end = function (raw) {
|
12384 | var buff = this._buff,
|
12385 | length = buff.length,
|
12386 | i,
|
12387 | tail = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
12388 | ret;
|
12389 |
|
12390 | for (i = 0; i < length; i += 1) {
|
12391 | tail[i >> 2] |= buff.charCodeAt(i) << ((i % 4) << 3);
|
12392 | }
|
12393 |
|
12394 | this._finish(tail, length);
|
12395 | ret = hex(this._hash);
|
12396 |
|
12397 | if (raw) {
|
12398 | ret = hexToBinaryString(ret);
|
12399 | }
|
12400 |
|
12401 | this.reset();
|
12402 |
|
12403 | return ret;
|
12404 | };
|
12405 |
|
12406 | |
12407 |
|
12408 |
|
12409 |
|
12410 |
|
12411 | SparkMD5.prototype.reset = function () {
|
12412 | this._buff = '';
|
12413 | this._length = 0;
|
12414 | this._hash = [1732584193, -271733879, -1732584194, 271733878];
|
12415 |
|
12416 | return this;
|
12417 | };
|
12418 |
|
12419 | |
12420 |
|
12421 |
|
12422 |
|
12423 |
|
12424 | SparkMD5.prototype.getState = function () {
|
12425 | return {
|
12426 | buff: this._buff,
|
12427 | length: this._length,
|
12428 | hash: this._hash
|
12429 | };
|
12430 | };
|
12431 |
|
12432 | |
12433 |
|
12434 |
|
12435 |
|
12436 |
|
12437 |
|
12438 |
|
12439 | SparkMD5.prototype.setState = function (state) {
|
12440 | this._buff = state.buff;
|
12441 | this._length = state.length;
|
12442 | this._hash = state.hash;
|
12443 |
|
12444 | return this;
|
12445 | };
|
12446 |
|
12447 | |
12448 |
|
12449 |
|
12450 |
|
12451 | SparkMD5.prototype.destroy = function () {
|
12452 | delete this._hash;
|
12453 | delete this._buff;
|
12454 | delete this._length;
|
12455 | };
|
12456 |
|
12457 | |
12458 |
|
12459 |
|
12460 |
|
12461 |
|
12462 |
|
12463 | SparkMD5.prototype._finish = function (tail, length) {
|
12464 | var i = length,
|
12465 | tmp,
|
12466 | lo,
|
12467 | hi;
|
12468 |
|
12469 | tail[i >> 2] |= 0x80 << ((i % 4) << 3);
|
12470 | if (i > 55) {
|
12471 | md5cycle(this._hash, tail);
|
12472 | for (i = 0; i < 16; i += 1) {
|
12473 | tail[i] = 0;
|
12474 | }
|
12475 | }
|
12476 |
|
12477 |
|
12478 |
|
12479 | tmp = this._length * 8;
|
12480 | tmp = tmp.toString(16).match(/(.*?)(.{0,8})$/);
|
12481 | lo = parseInt(tmp[2], 16);
|
12482 | hi = parseInt(tmp[1], 16) || 0;
|
12483 |
|
12484 | tail[14] = lo;
|
12485 | tail[15] = hi;
|
12486 | md5cycle(this._hash, tail);
|
12487 | };
|
12488 |
|
12489 | |
12490 |
|
12491 |
|
12492 |
|
12493 |
|
12494 |
|
12495 |
|
12496 |
|
12497 |
|
12498 | SparkMD5.hash = function (str, raw) {
|
12499 |
|
12500 |
|
12501 | return SparkMD5.hashBinary(toUtf8(str), raw);
|
12502 | };
|
12503 |
|
12504 | |
12505 |
|
12506 |
|
12507 |
|
12508 |
|
12509 |
|
12510 |
|
12511 |
|
12512 | SparkMD5.hashBinary = function (content, raw) {
|
12513 | var hash = md51(content),
|
12514 | ret = hex(hash);
|
12515 |
|
12516 | return raw ? hexToBinaryString(ret) : ret;
|
12517 | };
|
12518 |
|
12519 |
|
12520 |
|
12521 | |
12522 |
|
12523 |
|
12524 |
|
12525 |
|
12526 | SparkMD5.ArrayBuffer = function () {
|
12527 |
|
12528 | this.reset();
|
12529 | };
|
12530 |
|
12531 | |
12532 |
|
12533 |
|
12534 |
|
12535 |
|
12536 |
|
12537 |
|
12538 | SparkMD5.ArrayBuffer.prototype.append = function (arr) {
|
12539 | var buff = concatenateArrayBuffers(this._buff.buffer, arr, true),
|
12540 | length = buff.length,
|
12541 | i;
|
12542 |
|
12543 | this._length += arr.byteLength;
|
12544 |
|
12545 | for (i = 64; i <= length; i += 64) {
|
12546 | md5cycle(this._hash, md5blk_array(buff.subarray(i - 64, i)));
|
12547 | }
|
12548 |
|
12549 | this._buff = (i - 64) < length ? new Uint8Array(buff.buffer.slice(i - 64)) : new Uint8Array(0);
|
12550 |
|
12551 | return this;
|
12552 | };
|
12553 |
|
12554 | |
12555 |
|
12556 |
|
12557 |
|
12558 |
|
12559 |
|
12560 |
|
12561 |
|
12562 | SparkMD5.ArrayBuffer.prototype.end = function (raw) {
|
12563 | var buff = this._buff,
|
12564 | length = buff.length,
|
12565 | tail = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
12566 | i,
|
12567 | ret;
|
12568 |
|
12569 | for (i = 0; i < length; i += 1) {
|
12570 | tail[i >> 2] |= buff[i] << ((i % 4) << 3);
|
12571 | }
|
12572 |
|
12573 | this._finish(tail, length);
|
12574 | ret = hex(this._hash);
|
12575 |
|
12576 | if (raw) {
|
12577 | ret = hexToBinaryString(ret);
|
12578 | }
|
12579 |
|
12580 | this.reset();
|
12581 |
|
12582 | return ret;
|
12583 | };
|
12584 |
|
12585 | |
12586 |
|
12587 |
|
12588 |
|
12589 |
|
12590 | SparkMD5.ArrayBuffer.prototype.reset = function () {
|
12591 | this._buff = new Uint8Array(0);
|
12592 | this._length = 0;
|
12593 | this._hash = [1732584193, -271733879, -1732584194, 271733878];
|
12594 |
|
12595 | return this;
|
12596 | };
|
12597 |
|
12598 | |
12599 |
|
12600 |
|
12601 |
|
12602 |
|
12603 | SparkMD5.ArrayBuffer.prototype.getState = function () {
|
12604 | var state = SparkMD5.prototype.getState.call(this);
|
12605 |
|
12606 |
|
12607 | state.buff = arrayBuffer2Utf8Str(state.buff);
|
12608 |
|
12609 | return state;
|
12610 | };
|
12611 |
|
12612 | |
12613 |
|
12614 |
|
12615 |
|
12616 |
|
12617 |
|
12618 |
|
12619 | SparkMD5.ArrayBuffer.prototype.setState = function (state) {
|
12620 |
|
12621 | state.buff = utf8Str2ArrayBuffer(state.buff, true);
|
12622 |
|
12623 | return SparkMD5.prototype.setState.call(this, state);
|
12624 | };
|
12625 |
|
12626 | SparkMD5.ArrayBuffer.prototype.destroy = SparkMD5.prototype.destroy;
|
12627 |
|
12628 | SparkMD5.ArrayBuffer.prototype._finish = SparkMD5.prototype._finish;
|
12629 |
|
12630 | |
12631 |
|
12632 |
|
12633 |
|
12634 |
|
12635 |
|
12636 |
|
12637 |
|
12638 | SparkMD5.ArrayBuffer.hash = function (arr, raw) {
|
12639 | var hash = md51_array(new Uint8Array(arr)),
|
12640 | ret = hex(hash);
|
12641 |
|
12642 | return raw ? hexToBinaryString(ret) : ret;
|
12643 | };
|
12644 |
|
12645 | return SparkMD5;
|
12646 | }));
|
12647 |
|
12648 | },{}],72:[function(_dereq_,module,exports){
|
12649 |
|
12650 |
|
12651 |
|
12652 |
|
12653 |
|
12654 |
|
12655 |
|
12656 |
|
12657 |
|
12658 |
|
12659 |
|
12660 |
|
12661 |
|
12662 |
|
12663 |
|
12664 |
|
12665 |
|
12666 |
|
12667 |
|
12668 |
|
12669 |
|
12670 | module.exports = Stream;
|
12671 |
|
12672 | var EE = _dereq_(18).EventEmitter;
|
12673 | var inherits = _dereq_(24);
|
12674 |
|
12675 | inherits(Stream, EE);
|
12676 | Stream.Readable = _dereq_(83);
|
12677 | Stream.Writable = _dereq_(85);
|
12678 | Stream.Duplex = _dereq_(73);
|
12679 | Stream.Transform = _dereq_(84);
|
12680 | Stream.PassThrough = _dereq_(82);
|
12681 |
|
12682 |
|
12683 | Stream.Stream = Stream;
|
12684 |
|
12685 |
|
12686 |
|
12687 |
|
12688 |
|
12689 |
|
12690 | function Stream() {
|
12691 | EE.call(this);
|
12692 | }
|
12693 |
|
12694 | Stream.prototype.pipe = function(dest, options) {
|
12695 | var source = this;
|
12696 |
|
12697 | function ondata(chunk) {
|
12698 | if (dest.writable) {
|
12699 | if (false === dest.write(chunk) && source.pause) {
|
12700 | source.pause();
|
12701 | }
|
12702 | }
|
12703 | }
|
12704 |
|
12705 | source.on('data', ondata);
|
12706 |
|
12707 | function ondrain() {
|
12708 | if (source.readable && source.resume) {
|
12709 | source.resume();
|
12710 | }
|
12711 | }
|
12712 |
|
12713 | dest.on('drain', ondrain);
|
12714 |
|
12715 |
|
12716 |
|
12717 | if (!dest._isStdio && (!options || options.end !== false)) {
|
12718 | source.on('end', onend);
|
12719 | source.on('close', onclose);
|
12720 | }
|
12721 |
|
12722 | var didOnEnd = false;
|
12723 | function onend() {
|
12724 | if (didOnEnd) return;
|
12725 | didOnEnd = true;
|
12726 |
|
12727 | dest.end();
|
12728 | }
|
12729 |
|
12730 |
|
12731 | function onclose() {
|
12732 | if (didOnEnd) return;
|
12733 | didOnEnd = true;
|
12734 |
|
12735 | if (typeof dest.destroy === 'function') dest.destroy();
|
12736 | }
|
12737 |
|
12738 |
|
12739 | function onerror(er) {
|
12740 | cleanup();
|
12741 | if (EE.listenerCount(this, 'error') === 0) {
|
12742 | throw er;
|
12743 | }
|
12744 | }
|
12745 |
|
12746 | source.on('error', onerror);
|
12747 | dest.on('error', onerror);
|
12748 |
|
12749 |
|
12750 | function cleanup() {
|
12751 | source.removeListener('data', ondata);
|
12752 | dest.removeListener('drain', ondrain);
|
12753 |
|
12754 | source.removeListener('end', onend);
|
12755 | source.removeListener('close', onclose);
|
12756 |
|
12757 | source.removeListener('error', onerror);
|
12758 | dest.removeListener('error', onerror);
|
12759 |
|
12760 | source.removeListener('end', cleanup);
|
12761 | source.removeListener('close', cleanup);
|
12762 |
|
12763 | dest.removeListener('close', cleanup);
|
12764 | }
|
12765 |
|
12766 | source.on('end', cleanup);
|
12767 | source.on('close', cleanup);
|
12768 |
|
12769 | dest.on('close', cleanup);
|
12770 |
|
12771 | dest.emit('pipe', source);
|
12772 |
|
12773 |
|
12774 | return dest;
|
12775 | };
|
12776 |
|
12777 | },{"18":18,"24":24,"73":73,"82":82,"83":83,"84":84,"85":85}],73:[function(_dereq_,module,exports){
|
12778 | module.exports = _dereq_(74);
|
12779 |
|
12780 | },{"74":74}],74:[function(_dereq_,module,exports){
|
12781 | arguments[4][30][0].apply(exports,arguments)
|
12782 | },{"13":13,"24":24,"30":30,"59":59,"76":76,"78":78}],75:[function(_dereq_,module,exports){
|
12783 | arguments[4][31][0].apply(exports,arguments)
|
12784 | },{"13":13,"24":24,"31":31,"77":77}],76:[function(_dereq_,module,exports){
|
12785 | arguments[4][32][0].apply(exports,arguments)
|
12786 | },{"10":10,"13":13,"18":18,"24":24,"26":26,"32":32,"59":59,"60":60,"70":70,"74":74,"79":79,"80":80,"81":81,"86":86}],77:[function(_dereq_,module,exports){
|
12787 | arguments[4][33][0].apply(exports,arguments)
|
12788 | },{"13":13,"24":24,"33":33,"74":74}],78:[function(_dereq_,module,exports){
|
12789 | arguments[4][34][0].apply(exports,arguments)
|
12790 | },{"101":101,"13":13,"24":24,"34":34,"59":59,"60":60,"70":70,"74":74,"80":80,"81":81,"99":99}],79:[function(_dereq_,module,exports){
|
12791 | arguments[4][35][0].apply(exports,arguments)
|
12792 | },{"10":10,"35":35,"70":70}],80:[function(_dereq_,module,exports){
|
12793 | arguments[4][36][0].apply(exports,arguments)
|
12794 | },{"36":36,"59":59}],81:[function(_dereq_,module,exports){
|
12795 | arguments[4][37][0].apply(exports,arguments)
|
12796 | },{"18":18,"37":37}],82:[function(_dereq_,module,exports){
|
12797 | module.exports = _dereq_(83).PassThrough
|
12798 |
|
12799 | },{"83":83}],83:[function(_dereq_,module,exports){
|
12800 | arguments[4][38][0].apply(exports,arguments)
|
12801 | },{"38":38,"74":74,"75":75,"76":76,"77":77,"78":78}],84:[function(_dereq_,module,exports){
|
12802 | module.exports = _dereq_(83).Transform
|
12803 |
|
12804 | },{"83":83}],85:[function(_dereq_,module,exports){
|
12805 | module.exports = _dereq_(78);
|
12806 |
|
12807 | },{"78":78}],86:[function(_dereq_,module,exports){
|
12808 |
|
12809 |
|
12810 |
|
12811 |
|
12812 |
|
12813 |
|
12814 |
|
12815 |
|
12816 |
|
12817 |
|
12818 |
|
12819 |
|
12820 |
|
12821 |
|
12822 |
|
12823 |
|
12824 |
|
12825 |
|
12826 |
|
12827 |
|
12828 |
|
12829 | 'use strict';
|
12830 |
|
12831 |
|
12832 |
|
12833 | var Buffer = _dereq_(70).Buffer;
|
12834 |
|
12835 |
|
12836 | var isEncoding = Buffer.isEncoding || function (encoding) {
|
12837 | encoding = '' + encoding;
|
12838 | switch (encoding && encoding.toLowerCase()) {
|
12839 | 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':
|
12840 | return true;
|
12841 | default:
|
12842 | return false;
|
12843 | }
|
12844 | };
|
12845 |
|
12846 | function _normalizeEncoding(enc) {
|
12847 | if (!enc) return 'utf8';
|
12848 | var retried;
|
12849 | while (true) {
|
12850 | switch (enc) {
|
12851 | case 'utf8':
|
12852 | case 'utf-8':
|
12853 | return 'utf8';
|
12854 | case 'ucs2':
|
12855 | case 'ucs-2':
|
12856 | case 'utf16le':
|
12857 | case 'utf-16le':
|
12858 | return 'utf16le';
|
12859 | case 'latin1':
|
12860 | case 'binary':
|
12861 | return 'latin1';
|
12862 | case 'base64':
|
12863 | case 'ascii':
|
12864 | case 'hex':
|
12865 | return enc;
|
12866 | default:
|
12867 | if (retried) return;
|
12868 | enc = ('' + enc).toLowerCase();
|
12869 | retried = true;
|
12870 | }
|
12871 | }
|
12872 | };
|
12873 |
|
12874 |
|
12875 |
|
12876 | function normalizeEncoding(enc) {
|
12877 | var nenc = _normalizeEncoding(enc);
|
12878 | if (typeof nenc !== 'string' && (Buffer.isEncoding === isEncoding || !isEncoding(enc))) throw new Error('Unknown encoding: ' + enc);
|
12879 | return nenc || enc;
|
12880 | }
|
12881 |
|
12882 |
|
12883 |
|
12884 |
|
12885 | exports.StringDecoder = StringDecoder;
|
12886 | function StringDecoder(encoding) {
|
12887 | this.encoding = normalizeEncoding(encoding);
|
12888 | var nb;
|
12889 | switch (this.encoding) {
|
12890 | case 'utf16le':
|
12891 | this.text = utf16Text;
|
12892 | this.end = utf16End;
|
12893 | nb = 4;
|
12894 | break;
|
12895 | case 'utf8':
|
12896 | this.fillLast = utf8FillLast;
|
12897 | nb = 4;
|
12898 | break;
|
12899 | case 'base64':
|
12900 | this.text = base64Text;
|
12901 | this.end = base64End;
|
12902 | nb = 3;
|
12903 | break;
|
12904 | default:
|
12905 | this.write = simpleWrite;
|
12906 | this.end = simpleEnd;
|
12907 | return;
|
12908 | }
|
12909 | this.lastNeed = 0;
|
12910 | this.lastTotal = 0;
|
12911 | this.lastChar = Buffer.allocUnsafe(nb);
|
12912 | }
|
12913 |
|
12914 | StringDecoder.prototype.write = function (buf) {
|
12915 | if (buf.length === 0) return '';
|
12916 | var r;
|
12917 | var i;
|
12918 | if (this.lastNeed) {
|
12919 | r = this.fillLast(buf);
|
12920 | if (r === undefined) return '';
|
12921 | i = this.lastNeed;
|
12922 | this.lastNeed = 0;
|
12923 | } else {
|
12924 | i = 0;
|
12925 | }
|
12926 | if (i < buf.length) return r ? r + this.text(buf, i) : this.text(buf, i);
|
12927 | return r || '';
|
12928 | };
|
12929 |
|
12930 | StringDecoder.prototype.end = utf8End;
|
12931 |
|
12932 |
|
12933 | StringDecoder.prototype.text = utf8Text;
|
12934 |
|
12935 |
|
12936 | StringDecoder.prototype.fillLast = function (buf) {
|
12937 | if (this.lastNeed <= buf.length) {
|
12938 | buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, this.lastNeed);
|
12939 | return this.lastChar.toString(this.encoding, 0, this.lastTotal);
|
12940 | }
|
12941 | buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, buf.length);
|
12942 | this.lastNeed -= buf.length;
|
12943 | };
|
12944 |
|
12945 |
|
12946 |
|
12947 | function utf8CheckByte(byte) {
|
12948 | 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;
|
12949 | return byte >> 6 === 0x02 ? -1 : -2;
|
12950 | }
|
12951 |
|
12952 |
|
12953 |
|
12954 |
|
12955 | function utf8CheckIncomplete(self, buf, i) {
|
12956 | var j = buf.length - 1;
|
12957 | if (j < i) return 0;
|
12958 | var nb = utf8CheckByte(buf[j]);
|
12959 | if (nb >= 0) {
|
12960 | if (nb > 0) self.lastNeed = nb - 1;
|
12961 | return nb;
|
12962 | }
|
12963 | if (--j < i || nb === -2) return 0;
|
12964 | nb = utf8CheckByte(buf[j]);
|
12965 | if (nb >= 0) {
|
12966 | if (nb > 0) self.lastNeed = nb - 2;
|
12967 | return nb;
|
12968 | }
|
12969 | if (--j < i || nb === -2) return 0;
|
12970 | nb = utf8CheckByte(buf[j]);
|
12971 | if (nb >= 0) {
|
12972 | if (nb > 0) {
|
12973 | if (nb === 2) nb = 0;else self.lastNeed = nb - 3;
|
12974 | }
|
12975 | return nb;
|
12976 | }
|
12977 | return 0;
|
12978 | }
|
12979 |
|
12980 |
|
12981 |
|
12982 |
|
12983 |
|
12984 |
|
12985 |
|
12986 |
|
12987 |
|
12988 | function utf8CheckExtraBytes(self, buf, p) {
|
12989 | if ((buf[0] & 0xC0) !== 0x80) {
|
12990 | self.lastNeed = 0;
|
12991 | return '\ufffd';
|
12992 | }
|
12993 | if (self.lastNeed > 1 && buf.length > 1) {
|
12994 | if ((buf[1] & 0xC0) !== 0x80) {
|
12995 | self.lastNeed = 1;
|
12996 | return '\ufffd';
|
12997 | }
|
12998 | if (self.lastNeed > 2 && buf.length > 2) {
|
12999 | if ((buf[2] & 0xC0) !== 0x80) {
|
13000 | self.lastNeed = 2;
|
13001 | return '\ufffd';
|
13002 | }
|
13003 | }
|
13004 | }
|
13005 | }
|
13006 |
|
13007 |
|
13008 | function utf8FillLast(buf) {
|
13009 | var p = this.lastTotal - this.lastNeed;
|
13010 | var r = utf8CheckExtraBytes(this, buf, p);
|
13011 | if (r !== undefined) return r;
|
13012 | if (this.lastNeed <= buf.length) {
|
13013 | buf.copy(this.lastChar, p, 0, this.lastNeed);
|
13014 | return this.lastChar.toString(this.encoding, 0, this.lastTotal);
|
13015 | }
|
13016 | buf.copy(this.lastChar, p, 0, buf.length);
|
13017 | this.lastNeed -= buf.length;
|
13018 | }
|
13019 |
|
13020 |
|
13021 |
|
13022 |
|
13023 | function utf8Text(buf, i) {
|
13024 | var total = utf8CheckIncomplete(this, buf, i);
|
13025 | if (!this.lastNeed) return buf.toString('utf8', i);
|
13026 | this.lastTotal = total;
|
13027 | var end = buf.length - (total - this.lastNeed);
|
13028 | buf.copy(this.lastChar, 0, end);
|
13029 | return buf.toString('utf8', i, end);
|
13030 | }
|
13031 |
|
13032 |
|
13033 |
|
13034 | function utf8End(buf) {
|
13035 | var r = buf && buf.length ? this.write(buf) : '';
|
13036 | if (this.lastNeed) return r + '\ufffd';
|
13037 | return r;
|
13038 | }
|
13039 |
|
13040 |
|
13041 |
|
13042 |
|
13043 |
|
13044 | function utf16Text(buf, i) {
|
13045 | if ((buf.length - i) % 2 === 0) {
|
13046 | var r = buf.toString('utf16le', i);
|
13047 | if (r) {
|
13048 | var c = r.charCodeAt(r.length - 1);
|
13049 | if (c >= 0xD800 && c <= 0xDBFF) {
|
13050 | this.lastNeed = 2;
|
13051 | this.lastTotal = 4;
|
13052 | this.lastChar[0] = buf[buf.length - 2];
|
13053 | this.lastChar[1] = buf[buf.length - 1];
|
13054 | return r.slice(0, -1);
|
13055 | }
|
13056 | }
|
13057 | return r;
|
13058 | }
|
13059 | this.lastNeed = 1;
|
13060 | this.lastTotal = 2;
|
13061 | this.lastChar[0] = buf[buf.length - 1];
|
13062 | return buf.toString('utf16le', i, buf.length - 1);
|
13063 | }
|
13064 |
|
13065 |
|
13066 |
|
13067 | function utf16End(buf) {
|
13068 | var r = buf && buf.length ? this.write(buf) : '';
|
13069 | if (this.lastNeed) {
|
13070 | var end = this.lastTotal - this.lastNeed;
|
13071 | return r + this.lastChar.toString('utf16le', 0, end);
|
13072 | }
|
13073 | return r;
|
13074 | }
|
13075 |
|
13076 | function base64Text(buf, i) {
|
13077 | var n = (buf.length - i) % 3;
|
13078 | if (n === 0) return buf.toString('base64', i);
|
13079 | this.lastNeed = 3 - n;
|
13080 | this.lastTotal = 3;
|
13081 | if (n === 1) {
|
13082 | this.lastChar[0] = buf[buf.length - 1];
|
13083 | } else {
|
13084 | this.lastChar[0] = buf[buf.length - 2];
|
13085 | this.lastChar[1] = buf[buf.length - 1];
|
13086 | }
|
13087 | return buf.toString('base64', i, buf.length - n);
|
13088 | }
|
13089 |
|
13090 | function base64End(buf) {
|
13091 | var r = buf && buf.length ? this.write(buf) : '';
|
13092 | if (this.lastNeed) return r + this.lastChar.toString('base64', 0, 3 - this.lastNeed);
|
13093 | return r;
|
13094 | }
|
13095 |
|
13096 |
|
13097 | function simpleWrite(buf) {
|
13098 | return buf.toString(this.encoding);
|
13099 | }
|
13100 |
|
13101 | function simpleEnd(buf) {
|
13102 | return buf && buf.length ? this.write(buf) : '';
|
13103 | }
|
13104 | },{"70":70}],87:[function(_dereq_,module,exports){
|
13105 | arguments[4][30][0].apply(exports,arguments)
|
13106 | },{"13":13,"24":24,"30":30,"59":59,"89":89,"91":91}],88:[function(_dereq_,module,exports){
|
13107 | arguments[4][31][0].apply(exports,arguments)
|
13108 | },{"13":13,"24":24,"31":31,"90":90}],89:[function(_dereq_,module,exports){
|
13109 | arguments[4][32][0].apply(exports,arguments)
|
13110 | },{"10":10,"13":13,"18":18,"24":24,"26":26,"32":32,"59":59,"60":60,"70":70,"86":86,"87":87,"92":92,"93":93,"94":94}],90:[function(_dereq_,module,exports){
|
13111 | arguments[4][33][0].apply(exports,arguments)
|
13112 | },{"13":13,"24":24,"33":33,"87":87}],91:[function(_dereq_,module,exports){
|
13113 | arguments[4][34][0].apply(exports,arguments)
|
13114 | },{"101":101,"13":13,"24":24,"34":34,"59":59,"60":60,"70":70,"87":87,"93":93,"94":94,"99":99}],92:[function(_dereq_,module,exports){
|
13115 | arguments[4][35][0].apply(exports,arguments)
|
13116 | },{"10":10,"35":35,"70":70}],93:[function(_dereq_,module,exports){
|
13117 | arguments[4][36][0].apply(exports,arguments)
|
13118 | },{"36":36,"59":59}],94:[function(_dereq_,module,exports){
|
13119 | arguments[4][37][0].apply(exports,arguments)
|
13120 | },{"18":18,"37":37}],95:[function(_dereq_,module,exports){
|
13121 | arguments[4][38][0].apply(exports,arguments)
|
13122 | },{"38":38,"87":87,"88":88,"89":89,"90":90,"91":91}],96:[function(_dereq_,module,exports){
|
13123 | arguments[4][84][0].apply(exports,arguments)
|
13124 | },{"84":84,"95":95}],97:[function(_dereq_,module,exports){
|
13125 | arguments[4][39][0].apply(exports,arguments)
|
13126 | },{"39":39}],98:[function(_dereq_,module,exports){
|
13127 | (function (process){
|
13128 | var Transform = _dereq_(96)
|
13129 | , inherits = _dereq_(103).inherits
|
13130 | , xtend = _dereq_(97)
|
13131 |
|
13132 | function DestroyableTransform(opts) {
|
13133 | Transform.call(this, opts)
|
13134 | this._destroyed = false
|
13135 | }
|
13136 |
|
13137 | inherits(DestroyableTransform, Transform)
|
13138 |
|
13139 | DestroyableTransform.prototype.destroy = function(err) {
|
13140 | if (this._destroyed) return
|
13141 | this._destroyed = true
|
13142 |
|
13143 | var self = this
|
13144 | process.nextTick(function() {
|
13145 | if (err)
|
13146 | self.emit('error', err)
|
13147 | self.emit('close')
|
13148 | })
|
13149 | }
|
13150 |
|
13151 |
|
13152 | function noop (chunk, enc, callback) {
|
13153 | callback(null, chunk)
|
13154 | }
|
13155 |
|
13156 |
|
13157 |
|
13158 |
|
13159 | function through2 (construct) {
|
13160 | return function (options, transform, flush) {
|
13161 | if (typeof options == 'function') {
|
13162 | flush = transform
|
13163 | transform = options
|
13164 | options = {}
|
13165 | }
|
13166 |
|
13167 | if (typeof transform != 'function')
|
13168 | transform = noop
|
13169 |
|
13170 | if (typeof flush != 'function')
|
13171 | flush = null
|
13172 |
|
13173 | return construct(options, transform, flush)
|
13174 | }
|
13175 | }
|
13176 |
|
13177 |
|
13178 |
|
13179 | module.exports = through2(function (options, transform, flush) {
|
13180 | var t2 = new DestroyableTransform(options)
|
13181 |
|
13182 | t2._transform = transform
|
13183 |
|
13184 | if (flush)
|
13185 | t2._flush = flush
|
13186 |
|
13187 | return t2
|
13188 | })
|
13189 |
|
13190 |
|
13191 |
|
13192 |
|
13193 | module.exports.ctor = through2(function (options, transform, flush) {
|
13194 | function Through2 (override) {
|
13195 | if (!(this instanceof Through2))
|
13196 | return new Through2(override)
|
13197 |
|
13198 | this.options = xtend(options, override)
|
13199 |
|
13200 | DestroyableTransform.call(this, this.options)
|
13201 | }
|
13202 |
|
13203 | inherits(Through2, DestroyableTransform)
|
13204 |
|
13205 | Through2.prototype._transform = transform
|
13206 |
|
13207 | if (flush)
|
13208 | Through2.prototype._flush = flush
|
13209 |
|
13210 | return Through2
|
13211 | })
|
13212 |
|
13213 |
|
13214 | module.exports.obj = through2(function (options, transform, flush) {
|
13215 | var t2 = new DestroyableTransform(xtend({ objectMode: true, highWaterMark: 16 }, options))
|
13216 |
|
13217 | t2._transform = transform
|
13218 |
|
13219 | if (flush)
|
13220 | t2._flush = flush
|
13221 |
|
13222 | return t2
|
13223 | })
|
13224 |
|
13225 | }).call(this,_dereq_(60))
|
13226 | },{"103":103,"60":60,"96":96,"97":97}],99:[function(_dereq_,module,exports){
|
13227 | (function (setImmediate,clearImmediate){
|
13228 | var nextTick = _dereq_(60).nextTick;
|
13229 | var apply = Function.prototype.apply;
|
13230 | var slice = Array.prototype.slice;
|
13231 | var immediateIds = {};
|
13232 | var nextImmediateId = 0;
|
13233 |
|
13234 |
|
13235 |
|
13236 | exports.setTimeout = function() {
|
13237 | return new Timeout(apply.call(setTimeout, window, arguments), clearTimeout);
|
13238 | };
|
13239 | exports.setInterval = function() {
|
13240 | return new Timeout(apply.call(setInterval, window, arguments), clearInterval);
|
13241 | };
|
13242 | exports.clearTimeout =
|
13243 | exports.clearInterval = function(timeout) { timeout.close(); };
|
13244 |
|
13245 | function Timeout(id, clearFn) {
|
13246 | this._id = id;
|
13247 | this._clearFn = clearFn;
|
13248 | }
|
13249 | Timeout.prototype.unref = Timeout.prototype.ref = function() {};
|
13250 | Timeout.prototype.close = function() {
|
13251 | this._clearFn.call(window, this._id);
|
13252 | };
|
13253 |
|
13254 |
|
13255 | exports.enroll = function(item, msecs) {
|
13256 | clearTimeout(item._idleTimeoutId);
|
13257 | item._idleTimeout = msecs;
|
13258 | };
|
13259 |
|
13260 | exports.unenroll = function(item) {
|
13261 | clearTimeout(item._idleTimeoutId);
|
13262 | item._idleTimeout = -1;
|
13263 | };
|
13264 |
|
13265 | exports._unrefActive = exports.active = function(item) {
|
13266 | clearTimeout(item._idleTimeoutId);
|
13267 |
|
13268 | var msecs = item._idleTimeout;
|
13269 | if (msecs >= 0) {
|
13270 | item._idleTimeoutId = setTimeout(function onTimeout() {
|
13271 | if (item._onTimeout)
|
13272 | item._onTimeout();
|
13273 | }, msecs);
|
13274 | }
|
13275 | };
|
13276 |
|
13277 |
|
13278 | exports.setImmediate = typeof setImmediate === "function" ? setImmediate : function(fn) {
|
13279 | var id = nextImmediateId++;
|
13280 | var args = arguments.length < 2 ? false : slice.call(arguments, 1);
|
13281 |
|
13282 | immediateIds[id] = true;
|
13283 |
|
13284 | nextTick(function onNextTick() {
|
13285 | if (immediateIds[id]) {
|
13286 |
|
13287 |
|
13288 | if (args) {
|
13289 | fn.apply(null, args);
|
13290 | } else {
|
13291 | fn.call(null);
|
13292 | }
|
13293 |
|
13294 | exports.clearImmediate(id);
|
13295 | }
|
13296 | });
|
13297 |
|
13298 | return id;
|
13299 | };
|
13300 |
|
13301 | exports.clearImmediate = typeof clearImmediate === "function" ? clearImmediate : function(id) {
|
13302 | delete immediateIds[id];
|
13303 | };
|
13304 | }).call(this,_dereq_(99).setImmediate,_dereq_(99).clearImmediate)
|
13305 | },{"60":60,"99":99}],100:[function(_dereq_,module,exports){
|
13306 | 'use strict';
|
13307 |
|
13308 |
|
13309 |
|
13310 |
|
13311 | function Queue() {
|
13312 | this.length = 0;
|
13313 | }
|
13314 |
|
13315 | Queue.prototype.push = function (item) {
|
13316 | var node = {item: item};
|
13317 | if (this.last) {
|
13318 | this.last = this.last.next = node;
|
13319 | } else {
|
13320 | this.last = this.first = node;
|
13321 | }
|
13322 | this.length++;
|
13323 | };
|
13324 |
|
13325 | Queue.prototype.shift = function () {
|
13326 | var node = this.first;
|
13327 | if (node) {
|
13328 | this.first = node.next;
|
13329 | if (!(--this.length)) {
|
13330 | this.last = undefined;
|
13331 | }
|
13332 | return node.item;
|
13333 | }
|
13334 | };
|
13335 |
|
13336 | Queue.prototype.slice = function (start, end) {
|
13337 | start = typeof start === 'undefined' ? 0 : start;
|
13338 | end = typeof end === 'undefined' ? Infinity : end;
|
13339 |
|
13340 | var output = [];
|
13341 |
|
13342 | var i = 0;
|
13343 | for (var node = this.first; node; node = node.next) {
|
13344 | if (--end < 0) {
|
13345 | break;
|
13346 | } else if (++i > start) {
|
13347 | output.push(node.item);
|
13348 | }
|
13349 | }
|
13350 | return output;
|
13351 | }
|
13352 |
|
13353 | module.exports = Queue;
|
13354 |
|
13355 | },{}],101:[function(_dereq_,module,exports){
|
13356 | (function (global){
|
13357 |
|
13358 |
|
13359 |
|
13360 |
|
13361 |
|
13362 | module.exports = deprecate;
|
13363 |
|
13364 |
|
13365 |
|
13366 |
|
13367 |
|
13368 |
|
13369 |
|
13370 |
|
13371 |
|
13372 |
|
13373 |
|
13374 |
|
13375 |
|
13376 |
|
13377 |
|
13378 |
|
13379 |
|
13380 |
|
13381 |
|
13382 | function deprecate (fn, msg) {
|
13383 | if (config('noDeprecation')) {
|
13384 | return fn;
|
13385 | }
|
13386 |
|
13387 | var warned = false;
|
13388 | function deprecated() {
|
13389 | if (!warned) {
|
13390 | if (config('throwDeprecation')) {
|
13391 | throw new Error(msg);
|
13392 | } else if (config('traceDeprecation')) {
|
13393 | console.trace(msg);
|
13394 | } else {
|
13395 | console.warn(msg);
|
13396 | }
|
13397 | warned = true;
|
13398 | }
|
13399 | return fn.apply(this, arguments);
|
13400 | }
|
13401 |
|
13402 | return deprecated;
|
13403 | }
|
13404 |
|
13405 |
|
13406 |
|
13407 |
|
13408 |
|
13409 |
|
13410 |
|
13411 |
|
13412 |
|
13413 | function config (name) {
|
13414 |
|
13415 | try {
|
13416 | if (!global.localStorage) return false;
|
13417 | } catch (_) {
|
13418 | return false;
|
13419 | }
|
13420 | var val = global.localStorage[name];
|
13421 | if (null == val) return false;
|
13422 | return String(val).toLowerCase() === 'true';
|
13423 | }
|
13424 |
|
13425 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
13426 | },{}],102:[function(_dereq_,module,exports){
|
13427 | arguments[4][7][0].apply(exports,arguments)
|
13428 | },{"7":7}],103:[function(_dereq_,module,exports){
|
13429 | arguments[4][8][0].apply(exports,arguments)
|
13430 | },{"102":102,"24":24,"60":60,"8":8}],104:[function(_dereq_,module,exports){
|
13431 | var v1 = _dereq_(107);
|
13432 | var v4 = _dereq_(108);
|
13433 |
|
13434 | var uuid = v4;
|
13435 | uuid.v1 = v1;
|
13436 | uuid.v4 = v4;
|
13437 |
|
13438 | module.exports = uuid;
|
13439 |
|
13440 | },{"107":107,"108":108}],105:[function(_dereq_,module,exports){
|
13441 |
|
13442 |
|
13443 |
|
13444 |
|
13445 | var byteToHex = [];
|
13446 | for (var i = 0; i < 256; ++i) {
|
13447 | byteToHex[i] = (i + 0x100).toString(16).substr(1);
|
13448 | }
|
13449 |
|
13450 | function bytesToUuid(buf, offset) {
|
13451 | var i = offset || 0;
|
13452 | var bth = byteToHex;
|
13453 | return bth[buf[i++]] + bth[buf[i++]] +
|
13454 | bth[buf[i++]] + bth[buf[i++]] + '-' +
|
13455 | bth[buf[i++]] + bth[buf[i++]] + '-' +
|
13456 | bth[buf[i++]] + bth[buf[i++]] + '-' +
|
13457 | bth[buf[i++]] + bth[buf[i++]] + '-' +
|
13458 | bth[buf[i++]] + bth[buf[i++]] +
|
13459 | bth[buf[i++]] + bth[buf[i++]] +
|
13460 | bth[buf[i++]] + bth[buf[i++]];
|
13461 | }
|
13462 |
|
13463 | module.exports = bytesToUuid;
|
13464 |
|
13465 | },{}],106:[function(_dereq_,module,exports){
|
13466 |
|
13467 |
|
13468 |
|
13469 |
|
13470 |
|
13471 |
|
13472 | var getRandomValues = (typeof(crypto) != 'undefined' && crypto.getRandomValues.bind(crypto)) ||
|
13473 | (typeof(msCrypto) != 'undefined' && msCrypto.getRandomValues.bind(msCrypto));
|
13474 | if (getRandomValues) {
|
13475 |
|
13476 | var rnds8 = new Uint8Array(16);
|
13477 |
|
13478 | module.exports = function whatwgRNG() {
|
13479 | getRandomValues(rnds8);
|
13480 | return rnds8;
|
13481 | };
|
13482 | } else {
|
13483 |
|
13484 |
|
13485 |
|
13486 |
|
13487 | var rnds = new Array(16);
|
13488 |
|
13489 | module.exports = function mathRNG() {
|
13490 | for (var i = 0, r; i < 16; i++) {
|
13491 | if ((i & 0x03) === 0) r = Math.random() * 0x100000000;
|
13492 | rnds[i] = r >>> ((i & 0x03) << 3) & 0xff;
|
13493 | }
|
13494 |
|
13495 | return rnds;
|
13496 | };
|
13497 | }
|
13498 |
|
13499 | },{}],107:[function(_dereq_,module,exports){
|
13500 | var rng = _dereq_(106);
|
13501 | var bytesToUuid = _dereq_(105);
|
13502 |
|
13503 |
|
13504 |
|
13505 |
|
13506 |
|
13507 |
|
13508 | var _nodeId;
|
13509 | var _clockseq;
|
13510 |
|
13511 |
|
13512 | var _lastMSecs = 0;
|
13513 | var _lastNSecs = 0;
|
13514 |
|
13515 |
|
13516 | function v1(options, buf, offset) {
|
13517 | var i = buf && offset || 0;
|
13518 | var b = buf || [];
|
13519 |
|
13520 | options = options || {};
|
13521 | var node = options.node || _nodeId;
|
13522 | var clockseq = options.clockseq !== undefined ? options.clockseq : _clockseq;
|
13523 |
|
13524 |
|
13525 |
|
13526 |
|
13527 | if (node == null || clockseq == null) {
|
13528 | var seedBytes = rng();
|
13529 | if (node == null) {
|
13530 |
|
13531 | node = _nodeId = [
|
13532 | seedBytes[0] | 0x01,
|
13533 | seedBytes[1], seedBytes[2], seedBytes[3], seedBytes[4], seedBytes[5]
|
13534 | ];
|
13535 | }
|
13536 | if (clockseq == null) {
|
13537 |
|
13538 | clockseq = _clockseq = (seedBytes[6] << 8 | seedBytes[7]) & 0x3fff;
|
13539 | }
|
13540 | }
|
13541 |
|
13542 |
|
13543 |
|
13544 |
|
13545 |
|
13546 | var msecs = options.msecs !== undefined ? options.msecs : new Date().getTime();
|
13547 |
|
13548 |
|
13549 |
|
13550 | var nsecs = options.nsecs !== undefined ? options.nsecs : _lastNSecs + 1;
|
13551 |
|
13552 |
|
13553 | var dt = (msecs - _lastMSecs) + (nsecs - _lastNSecs)/10000;
|
13554 |
|
13555 |
|
13556 | if (dt < 0 && options.clockseq === undefined) {
|
13557 | clockseq = clockseq + 1 & 0x3fff;
|
13558 | }
|
13559 |
|
13560 |
|
13561 |
|
13562 | if ((dt < 0 || msecs > _lastMSecs) && options.nsecs === undefined) {
|
13563 | nsecs = 0;
|
13564 | }
|
13565 |
|
13566 |
|
13567 | if (nsecs >= 10000) {
|
13568 | throw new Error('uuid.v1(): Can\'t create more than 10M uuids/sec');
|
13569 | }
|
13570 |
|
13571 | _lastMSecs = msecs;
|
13572 | _lastNSecs = nsecs;
|
13573 | _clockseq = clockseq;
|
13574 |
|
13575 |
|
13576 | msecs += 12219292800000;
|
13577 |
|
13578 |
|
13579 | var tl = ((msecs & 0xfffffff) * 10000 + nsecs) % 0x100000000;
|
13580 | b[i++] = tl >>> 24 & 0xff;
|
13581 | b[i++] = tl >>> 16 & 0xff;
|
13582 | b[i++] = tl >>> 8 & 0xff;
|
13583 | b[i++] = tl & 0xff;
|
13584 |
|
13585 |
|
13586 | var tmh = (msecs / 0x100000000 * 10000) & 0xfffffff;
|
13587 | b[i++] = tmh >>> 8 & 0xff;
|
13588 | b[i++] = tmh & 0xff;
|
13589 |
|
13590 |
|
13591 | b[i++] = tmh >>> 24 & 0xf | 0x10;
|
13592 | b[i++] = tmh >>> 16 & 0xff;
|
13593 |
|
13594 |
|
13595 | b[i++] = clockseq >>> 8 | 0x80;
|
13596 |
|
13597 |
|
13598 | b[i++] = clockseq & 0xff;
|
13599 |
|
13600 |
|
13601 | for (var n = 0; n < 6; ++n) {
|
13602 | b[i + n] = node[n];
|
13603 | }
|
13604 |
|
13605 | return buf ? buf : bytesToUuid(b);
|
13606 | }
|
13607 |
|
13608 | module.exports = v1;
|
13609 |
|
13610 | },{"105":105,"106":106}],108:[function(_dereq_,module,exports){
|
13611 | var rng = _dereq_(106);
|
13612 | var bytesToUuid = _dereq_(105);
|
13613 |
|
13614 | function v4(options, buf, offset) {
|
13615 | var i = buf && offset || 0;
|
13616 |
|
13617 | if (typeof(options) == 'string') {
|
13618 | buf = options === 'binary' ? new Array(16) : null;
|
13619 | options = null;
|
13620 | }
|
13621 | options = options || {};
|
13622 |
|
13623 | var rnds = options.random || (options.rng || rng)();
|
13624 |
|
13625 |
|
13626 | rnds[6] = (rnds[6] & 0x0f) | 0x40;
|
13627 | rnds[8] = (rnds[8] & 0x3f) | 0x80;
|
13628 |
|
13629 |
|
13630 | if (buf) {
|
13631 | for (var ii = 0; ii < 16; ++ii) {
|
13632 | buf[i + ii] = rnds[ii];
|
13633 | }
|
13634 | }
|
13635 |
|
13636 | return buf || bytesToUuid(rnds);
|
13637 | }
|
13638 |
|
13639 | module.exports = v4;
|
13640 |
|
13641 | },{"105":105,"106":106}],109:[function(_dereq_,module,exports){
|
13642 | 'use strict';
|
13643 |
|
13644 |
|
13645 |
|
13646 |
|
13647 |
|
13648 |
|
13649 | exports.stringify = function stringify(input) {
|
13650 | var queue = [];
|
13651 | queue.push({obj: input});
|
13652 |
|
13653 | var res = '';
|
13654 | var next, obj, prefix, val, i, arrayPrefix, keys, k, key, value, objPrefix;
|
13655 | while ((next = queue.pop())) {
|
13656 | obj = next.obj;
|
13657 | prefix = next.prefix || '';
|
13658 | val = next.val || '';
|
13659 | res += prefix;
|
13660 | if (val) {
|
13661 | res += val;
|
13662 | } else if (typeof obj !== 'object') {
|
13663 | res += typeof obj === 'undefined' ? null : JSON.stringify(obj);
|
13664 | } else if (obj === null) {
|
13665 | res += 'null';
|
13666 | } else if (Array.isArray(obj)) {
|
13667 | queue.push({val: ']'});
|
13668 | for (i = obj.length - 1; i >= 0; i--) {
|
13669 | arrayPrefix = i === 0 ? '' : ',';
|
13670 | queue.push({obj: obj[i], prefix: arrayPrefix});
|
13671 | }
|
13672 | queue.push({val: '['});
|
13673 | } else {
|
13674 | keys = [];
|
13675 | for (k in obj) {
|
13676 | if (obj.hasOwnProperty(k)) {
|
13677 | keys.push(k);
|
13678 | }
|
13679 | }
|
13680 | queue.push({val: '}'});
|
13681 | for (i = keys.length - 1; i >= 0; i--) {
|
13682 | key = keys[i];
|
13683 | value = obj[key];
|
13684 | objPrefix = (i > 0 ? ',' : '');
|
13685 | objPrefix += JSON.stringify(key) + ':';
|
13686 | queue.push({obj: value, prefix: objPrefix});
|
13687 | }
|
13688 | queue.push({val: '{'});
|
13689 | }
|
13690 | }
|
13691 | return res;
|
13692 | };
|
13693 |
|
13694 |
|
13695 |
|
13696 |
|
13697 | function pop(obj, stack, metaStack) {
|
13698 | var lastMetaElement = metaStack[metaStack.length - 1];
|
13699 | if (obj === lastMetaElement.element) {
|
13700 |
|
13701 | metaStack.pop();
|
13702 | lastMetaElement = metaStack[metaStack.length - 1];
|
13703 | }
|
13704 | var element = lastMetaElement.element;
|
13705 | var lastElementIndex = lastMetaElement.index;
|
13706 | if (Array.isArray(element)) {
|
13707 | element.push(obj);
|
13708 | } else if (lastElementIndex === stack.length - 2) {
|
13709 | var key = stack.pop();
|
13710 | element[key] = obj;
|
13711 | } else {
|
13712 | stack.push(obj);
|
13713 | }
|
13714 | }
|
13715 |
|
13716 | exports.parse = function (str) {
|
13717 | var stack = [];
|
13718 | var metaStack = [];
|
13719 | var i = 0;
|
13720 | var collationIndex,parsedNum,numChar;
|
13721 | var parsedString,lastCh,numConsecutiveSlashes,ch;
|
13722 | var arrayElement, objElement;
|
13723 | while (true) {
|
13724 | collationIndex = str[i++];
|
13725 | if (collationIndex === '}' ||
|
13726 | collationIndex === ']' ||
|
13727 | typeof collationIndex === 'undefined') {
|
13728 | if (stack.length === 1) {
|
13729 | return stack.pop();
|
13730 | } else {
|
13731 | pop(stack.pop(), stack, metaStack);
|
13732 | continue;
|
13733 | }
|
13734 | }
|
13735 | switch (collationIndex) {
|
13736 | case ' ':
|
13737 | case '\t':
|
13738 | case '\n':
|
13739 | case ':':
|
13740 | case ',':
|
13741 | break;
|
13742 | case 'n':
|
13743 | i += 3;
|
13744 | pop(null, stack, metaStack);
|
13745 | break;
|
13746 | case 't':
|
13747 | i += 3;
|
13748 | pop(true, stack, metaStack);
|
13749 | break;
|
13750 | case 'f':
|
13751 | i += 4;
|
13752 | pop(false, stack, metaStack);
|
13753 | break;
|
13754 | case '0':
|
13755 | case '1':
|
13756 | case '2':
|
13757 | case '3':
|
13758 | case '4':
|
13759 | case '5':
|
13760 | case '6':
|
13761 | case '7':
|
13762 | case '8':
|
13763 | case '9':
|
13764 | case '-':
|
13765 | parsedNum = '';
|
13766 | i--;
|
13767 | while (true) {
|
13768 | numChar = str[i++];
|
13769 | if (/[\d\.\-e\+]/.test(numChar)) {
|
13770 | parsedNum += numChar;
|
13771 | } else {
|
13772 | i--;
|
13773 | break;
|
13774 | }
|
13775 | }
|
13776 | pop(parseFloat(parsedNum), stack, metaStack);
|
13777 | break;
|
13778 | case '"':
|
13779 | parsedString = '';
|
13780 | lastCh = void 0;
|
13781 | numConsecutiveSlashes = 0;
|
13782 | while (true) {
|
13783 | ch = str[i++];
|
13784 | if (ch !== '"' || (lastCh === '\\' &&
|
13785 | numConsecutiveSlashes % 2 === 1)) {
|
13786 | parsedString += ch;
|
13787 | lastCh = ch;
|
13788 | if (lastCh === '\\') {
|
13789 | numConsecutiveSlashes++;
|
13790 | } else {
|
13791 | numConsecutiveSlashes = 0;
|
13792 | }
|
13793 | } else {
|
13794 | break;
|
13795 | }
|
13796 | }
|
13797 | pop(JSON.parse('"' + parsedString + '"'), stack, metaStack);
|
13798 | break;
|
13799 | case '[':
|
13800 | arrayElement = { element: [], index: stack.length };
|
13801 | stack.push(arrayElement.element);
|
13802 | metaStack.push(arrayElement);
|
13803 | break;
|
13804 | case '{':
|
13805 | objElement = { element: {}, index: stack.length };
|
13806 | stack.push(objElement.element);
|
13807 | metaStack.push(objElement);
|
13808 | break;
|
13809 | default:
|
13810 | throw new Error(
|
13811 | 'unexpectedly reached end of input: ' + collationIndex);
|
13812 | }
|
13813 | }
|
13814 | };
|
13815 |
|
13816 | },{}],110:[function(_dereq_,module,exports){
|
13817 | module.exports = extend
|
13818 |
|
13819 | function extend() {
|
13820 | var target = {}
|
13821 |
|
13822 | for (var i = 0; i < arguments.length; i++) {
|
13823 | var source = arguments[i]
|
13824 |
|
13825 | for (var key in source) {
|
13826 | if (source.hasOwnProperty(key)) {
|
13827 | target[key] = source[key]
|
13828 | }
|
13829 | }
|
13830 | }
|
13831 |
|
13832 | return target
|
13833 | }
|
13834 |
|
13835 | },{}],111:[function(_dereq_,module,exports){
|
13836 | (function (global){
|
13837 | 'use strict';
|
13838 |
|
13839 | function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
13840 |
|
13841 | var getArguments = _interopDefault(_dereq_(4));
|
13842 | var nextTick = _interopDefault(_dereq_(23));
|
13843 | var events = _dereq_(18);
|
13844 | var events__default = _interopDefault(events);
|
13845 | var inherits = _interopDefault(_dereq_(24));
|
13846 | var Md5 = _interopDefault(_dereq_(71));
|
13847 | var uuidV4 = _interopDefault(_dereq_(104));
|
13848 | var ltgt = _interopDefault(_dereq_(58));
|
13849 | var ReadableStreamCore = _interopDefault(_dereq_(69));
|
13850 | var Codec = _interopDefault(_dereq_(27));
|
13851 | var vuvuzela = _interopDefault(_dereq_(109));
|
13852 | var levelup = _interopDefault(_dereq_(41));
|
13853 | var through2 = _dereq_(98);
|
13854 | var Deque = _interopDefault(_dereq_(15));
|
13855 | var bufferFrom = _interopDefault(_dereq_(11));
|
13856 | var localstoragedown = _interopDefault(_dereq_(51));
|
13857 |
|
13858 | function isBinaryObject(object) {
|
13859 | return (typeof ArrayBuffer !== 'undefined' && object instanceof ArrayBuffer) ||
|
13860 | (typeof Blob !== 'undefined' && object instanceof Blob);
|
13861 | }
|
13862 |
|
13863 | function cloneArrayBuffer(buff) {
|
13864 | if (typeof buff.slice === 'function') {
|
13865 | return buff.slice(0);
|
13866 | }
|
13867 |
|
13868 | var target = new ArrayBuffer(buff.byteLength);
|
13869 | var targetArray = new Uint8Array(target);
|
13870 | var sourceArray = new Uint8Array(buff);
|
13871 | targetArray.set(sourceArray);
|
13872 | return target;
|
13873 | }
|
13874 |
|
13875 | function cloneBinaryObject(object) {
|
13876 | if (object instanceof ArrayBuffer) {
|
13877 | return cloneArrayBuffer(object);
|
13878 | }
|
13879 | var size = object.size;
|
13880 | var type = object.type;
|
13881 |
|
13882 | if (typeof object.slice === 'function') {
|
13883 | return object.slice(0, size, type);
|
13884 | }
|
13885 |
|
13886 | return object.webkitSlice(0, size, type);
|
13887 | }
|
13888 |
|
13889 |
|
13890 |
|
13891 |
|
13892 |
|
13893 | var funcToString = Function.prototype.toString;
|
13894 | var objectCtorString = funcToString.call(Object);
|
13895 |
|
13896 | function isPlainObject(value) {
|
13897 | var proto = Object.getPrototypeOf(value);
|
13898 |
|
13899 | if (proto === null) {
|
13900 | return true;
|
13901 | }
|
13902 | var Ctor = proto.constructor;
|
13903 | return (typeof Ctor == 'function' &&
|
13904 | Ctor instanceof Ctor && funcToString.call(Ctor) == objectCtorString);
|
13905 | }
|
13906 |
|
13907 | function clone(object) {
|
13908 | var newObject;
|
13909 | var i;
|
13910 | var len;
|
13911 |
|
13912 | if (!object || typeof object !== 'object') {
|
13913 | return object;
|
13914 | }
|
13915 |
|
13916 | if (Array.isArray(object)) {
|
13917 | newObject = [];
|
13918 | for (i = 0, len = object.length; i < len; i++) {
|
13919 | newObject[i] = clone(object[i]);
|
13920 | }
|
13921 | return newObject;
|
13922 | }
|
13923 |
|
13924 |
|
13925 |
|
13926 | if (object instanceof Date) {
|
13927 | return object.toISOString();
|
13928 | }
|
13929 |
|
13930 | if (isBinaryObject(object)) {
|
13931 | return cloneBinaryObject(object);
|
13932 | }
|
13933 |
|
13934 | if (!isPlainObject(object)) {
|
13935 | return object;
|
13936 | }
|
13937 |
|
13938 | newObject = {};
|
13939 | for (i in object) {
|
13940 |
|
13941 | if (Object.prototype.hasOwnProperty.call(object, i)) {
|
13942 | var value = clone(object[i]);
|
13943 | if (typeof value !== 'undefined') {
|
13944 | newObject[i] = value;
|
13945 | }
|
13946 | }
|
13947 | }
|
13948 | return newObject;
|
13949 | }
|
13950 |
|
13951 | function mangle(key) {
|
13952 | return '$' + key;
|
13953 | }
|
13954 | function unmangle(key) {
|
13955 | return key.substring(1);
|
13956 | }
|
13957 | function Map$1() {
|
13958 | this._store = {};
|
13959 | }
|
13960 | Map$1.prototype.get = function (key) {
|
13961 | var mangled = mangle(key);
|
13962 | return this._store[mangled];
|
13963 | };
|
13964 | Map$1.prototype.set = function (key, value) {
|
13965 | var mangled = mangle(key);
|
13966 | this._store[mangled] = value;
|
13967 | return true;
|
13968 | };
|
13969 | Map$1.prototype.has = function (key) {
|
13970 | var mangled = mangle(key);
|
13971 | return mangled in this._store;
|
13972 | };
|
13973 | Map$1.prototype["delete"] = function (key) {
|
13974 | var mangled = mangle(key);
|
13975 | var res = mangled in this._store;
|
13976 | delete this._store[mangled];
|
13977 | return res;
|
13978 | };
|
13979 | Map$1.prototype.forEach = function (cb) {
|
13980 | var keys = Object.keys(this._store);
|
13981 | for (var i = 0, len = keys.length; i < len; i++) {
|
13982 | var key = keys[i];
|
13983 | var value = this._store[key];
|
13984 | key = unmangle(key);
|
13985 | cb(value, key);
|
13986 | }
|
13987 | };
|
13988 | Object.defineProperty(Map$1.prototype, 'size', {
|
13989 | get: function () {
|
13990 | return Object.keys(this._store).length;
|
13991 | }
|
13992 | });
|
13993 |
|
13994 | function Set$1(array) {
|
13995 | this._store = new Map$1();
|
13996 |
|
13997 |
|
13998 | if (array && Array.isArray(array)) {
|
13999 | for (var i = 0, len = array.length; i < len; i++) {
|
14000 | this.add(array[i]);
|
14001 | }
|
14002 | }
|
14003 | }
|
14004 | Set$1.prototype.add = function (key) {
|
14005 | return this._store.set(key, true);
|
14006 | };
|
14007 | Set$1.prototype.has = function (key) {
|
14008 | return this._store.has(key);
|
14009 | };
|
14010 | Set$1.prototype.forEach = function (cb) {
|
14011 | this._store.forEach(function (value, key) {
|
14012 | cb(key);
|
14013 | });
|
14014 | };
|
14015 | Object.defineProperty(Set$1.prototype, 'size', {
|
14016 | get: function () {
|
14017 | return this._store.size;
|
14018 | }
|
14019 | });
|
14020 |
|
14021 |
|
14022 |
|
14023 |
|
14024 |
|
14025 | function supportsMapAndSet() {
|
14026 | if (typeof Symbol === 'undefined' || typeof Map === 'undefined' || typeof Set === 'undefined') {
|
14027 | return false;
|
14028 | }
|
14029 | var prop = Object.getOwnPropertyDescriptor(Map, Symbol.species);
|
14030 | return prop && 'get' in prop && Map[Symbol.species] === Map;
|
14031 | }
|
14032 |
|
14033 |
|
14034 |
|
14035 | var ExportedSet;
|
14036 | var ExportedMap;
|
14037 |
|
14038 | {
|
14039 | if (supportsMapAndSet()) {
|
14040 | ExportedSet = Set;
|
14041 | ExportedMap = Map;
|
14042 | } else {
|
14043 | ExportedSet = Set$1;
|
14044 | ExportedMap = Map$1;
|
14045 | }
|
14046 | }
|
14047 |
|
14048 |
|
14049 | function pick(obj, arr) {
|
14050 | var res = {};
|
14051 | for (var i = 0, len = arr.length; i < len; i++) {
|
14052 | var prop = arr[i];
|
14053 | if (prop in obj) {
|
14054 | res[prop] = obj[prop];
|
14055 | }
|
14056 | }
|
14057 | return res;
|
14058 | }
|
14059 |
|
14060 | var hasLocal;
|
14061 |
|
14062 | try {
|
14063 | localStorage.setItem('_pouch_check_localstorage', 1);
|
14064 | hasLocal = !!localStorage.getItem('_pouch_check_localstorage');
|
14065 | } catch (e) {
|
14066 | hasLocal = false;
|
14067 | }
|
14068 |
|
14069 | function hasLocalStorage() {
|
14070 | return hasLocal;
|
14071 | }
|
14072 |
|
14073 |
|
14074 |
|
14075 | inherits(Changes, events.EventEmitter);
|
14076 |
|
14077 |
|
14078 | function attachBrowserEvents(self) {
|
14079 | if (hasLocalStorage()) {
|
14080 | addEventListener("storage", function (e) {
|
14081 | self.emit(e.key);
|
14082 | });
|
14083 | }
|
14084 | }
|
14085 |
|
14086 | function Changes() {
|
14087 | events.EventEmitter.call(this);
|
14088 | this._listeners = {};
|
14089 |
|
14090 | attachBrowserEvents(this);
|
14091 | }
|
14092 | Changes.prototype.addListener = function (dbName, id, db, opts) {
|
14093 |
|
14094 | if (this._listeners[id]) {
|
14095 | return;
|
14096 | }
|
14097 | var self = this;
|
14098 | var inprogress = false;
|
14099 | function eventFunction() {
|
14100 |
|
14101 | if (!self._listeners[id]) {
|
14102 | return;
|
14103 | }
|
14104 | if (inprogress) {
|
14105 | inprogress = 'waiting';
|
14106 | return;
|
14107 | }
|
14108 | inprogress = true;
|
14109 | var changesOpts = pick(opts, [
|
14110 | 'style', 'include_docs', 'attachments', 'conflicts', 'filter',
|
14111 | 'doc_ids', 'view', 'since', 'query_params', 'binary', 'return_docs'
|
14112 | ]);
|
14113 |
|
14114 |
|
14115 | function onError() {
|
14116 | inprogress = false;
|
14117 | }
|
14118 |
|
14119 | db.changes(changesOpts).on('change', function (c) {
|
14120 | if (c.seq > opts.since && !opts.cancelled) {
|
14121 | opts.since = c.seq;
|
14122 | opts.onChange(c);
|
14123 | }
|
14124 | }).on('complete', function () {
|
14125 | if (inprogress === 'waiting') {
|
14126 | nextTick(eventFunction);
|
14127 | }
|
14128 | inprogress = false;
|
14129 | }).on('error', onError);
|
14130 | }
|
14131 | this._listeners[id] = eventFunction;
|
14132 | this.on(dbName, eventFunction);
|
14133 | };
|
14134 |
|
14135 | Changes.prototype.removeListener = function (dbName, id) {
|
14136 |
|
14137 | if (!(id in this._listeners)) {
|
14138 | return;
|
14139 | }
|
14140 | events.EventEmitter.prototype.removeListener.call(this, dbName,
|
14141 | this._listeners[id]);
|
14142 | delete this._listeners[id];
|
14143 | };
|
14144 |
|
14145 |
|
14146 |
|
14147 | Changes.prototype.notifyLocalWindows = function (dbName) {
|
14148 |
|
14149 |
|
14150 | if (hasLocalStorage()) {
|
14151 | localStorage[dbName] = (localStorage[dbName] === "a") ? "b" : "a";
|
14152 | }
|
14153 | };
|
14154 |
|
14155 | Changes.prototype.notify = function (dbName) {
|
14156 | this.emit(dbName);
|
14157 | this.notifyLocalWindows(dbName);
|
14158 | };
|
14159 |
|
14160 | function guardedConsole(method) {
|
14161 |
|
14162 | if (typeof console !== 'undefined' && typeof console[method] === 'function') {
|
14163 | var args = Array.prototype.slice.call(arguments, 1);
|
14164 | console[method].apply(console, args);
|
14165 | }
|
14166 | }
|
14167 |
|
14168 | var assign;
|
14169 | {
|
14170 | if (typeof Object.assign === 'function') {
|
14171 | assign = Object.assign;
|
14172 | } else {
|
14173 |
|
14174 |
|
14175 | assign = function (target) {
|
14176 | var to = Object(target);
|
14177 |
|
14178 | for (var index = 1; index < arguments.length; index++) {
|
14179 | var nextSource = arguments[index];
|
14180 |
|
14181 | if (nextSource != null) {
|
14182 | for (var nextKey in nextSource) {
|
14183 |
|
14184 | if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
|
14185 | to[nextKey] = nextSource[nextKey];
|
14186 | }
|
14187 | }
|
14188 | }
|
14189 | }
|
14190 | return to;
|
14191 | };
|
14192 | }
|
14193 | }
|
14194 |
|
14195 | var $inject_Object_assign = assign;
|
14196 |
|
14197 | inherits(PouchError, Error);
|
14198 |
|
14199 | function PouchError(status, error, reason) {
|
14200 | Error.call(this, reason);
|
14201 | this.status = status;
|
14202 | this.name = error;
|
14203 | this.message = reason;
|
14204 | this.error = true;
|
14205 | }
|
14206 |
|
14207 | PouchError.prototype.toString = function () {
|
14208 | return JSON.stringify({
|
14209 | status: this.status,
|
14210 | name: this.name,
|
14211 | message: this.message,
|
14212 | reason: this.reason
|
14213 | });
|
14214 | };
|
14215 |
|
14216 | var UNAUTHORIZED = new PouchError(401, 'unauthorized', "Name or password is incorrect.");
|
14217 | var MISSING_BULK_DOCS = new PouchError(400, 'bad_request', "Missing JSON list of 'docs'");
|
14218 | var MISSING_DOC = new PouchError(404, 'not_found', 'missing');
|
14219 | var REV_CONFLICT = new PouchError(409, 'conflict', 'Document update conflict');
|
14220 | var INVALID_ID = new PouchError(400, 'bad_request', '_id field must contain a string');
|
14221 | var MISSING_ID = new PouchError(412, 'missing_id', '_id is required for puts');
|
14222 | var RESERVED_ID = new PouchError(400, 'bad_request', 'Only reserved document ids may start with underscore.');
|
14223 | var NOT_OPEN = new PouchError(412, 'precondition_failed', 'Database not open');
|
14224 | var UNKNOWN_ERROR = new PouchError(500, 'unknown_error', 'Database encountered an unknown error');
|
14225 | var BAD_ARG = new PouchError(500, 'badarg', 'Some query argument is invalid');
|
14226 | var INVALID_REQUEST = new PouchError(400, 'invalid_request', 'Request was invalid');
|
14227 | var QUERY_PARSE_ERROR = new PouchError(400, 'query_parse_error', 'Some query parameter is invalid');
|
14228 | var DOC_VALIDATION = new PouchError(500, 'doc_validation', 'Bad special document member');
|
14229 | var BAD_REQUEST = new PouchError(400, 'bad_request', 'Something wrong with the request');
|
14230 | var NOT_AN_OBJECT = new PouchError(400, 'bad_request', 'Document must be a JSON object');
|
14231 | var DB_MISSING = new PouchError(404, 'not_found', 'Database not found');
|
14232 | var IDB_ERROR = new PouchError(500, 'indexed_db_went_bad', 'unknown');
|
14233 | var WSQ_ERROR = new PouchError(500, 'web_sql_went_bad', 'unknown');
|
14234 | var LDB_ERROR = new PouchError(500, 'levelDB_went_went_bad', 'unknown');
|
14235 | var FORBIDDEN = new PouchError(403, 'forbidden', 'Forbidden by design doc validate_doc_update function');
|
14236 | var INVALID_REV = new PouchError(400, 'bad_request', 'Invalid rev format');
|
14237 | var FILE_EXISTS = new PouchError(412, 'file_exists', 'The database could not be created, the file already exists.');
|
14238 | var MISSING_STUB = new PouchError(412, 'missing_stub', 'A pre-existing attachment stub wasn\'t found');
|
14239 | var INVALID_URL = new PouchError(413, 'invalid_url', 'Provided URL is invalid');
|
14240 |
|
14241 | function createError(error, reason) {
|
14242 | function CustomPouchError(reason) {
|
14243 |
|
14244 |
|
14245 |
|
14246 | for (var p in error) {
|
14247 | if (typeof error[p] !== 'function') {
|
14248 | this[p] = error[p];
|
14249 | }
|
14250 | }
|
14251 |
|
14252 | if (reason !== undefined) {
|
14253 | this.reason = reason;
|
14254 | }
|
14255 | }
|
14256 | CustomPouchError.prototype = PouchError.prototype;
|
14257 | return new CustomPouchError(reason);
|
14258 | }
|
14259 |
|
14260 | function tryFilter(filter, doc, req) {
|
14261 | try {
|
14262 | return !filter(doc, req);
|
14263 | } catch (err) {
|
14264 | var msg = 'Filter function threw: ' + err.toString();
|
14265 | return createError(BAD_REQUEST, msg);
|
14266 | }
|
14267 | }
|
14268 |
|
14269 | function filterChange(opts) {
|
14270 | var req = {};
|
14271 | var hasFilter = opts.filter && typeof opts.filter === 'function';
|
14272 | req.query = opts.query_params;
|
14273 |
|
14274 | return function filter(change) {
|
14275 | if (!change.doc) {
|
14276 |
|
14277 |
|
14278 | change.doc = {};
|
14279 | }
|
14280 |
|
14281 | var filterReturn = hasFilter && tryFilter(opts.filter, change.doc, req);
|
14282 |
|
14283 | if (typeof filterReturn === 'object') {
|
14284 | return filterReturn;
|
14285 | }
|
14286 |
|
14287 | if (filterReturn) {
|
14288 | return false;
|
14289 | }
|
14290 |
|
14291 | if (!opts.include_docs) {
|
14292 | delete change.doc;
|
14293 | } else if (!opts.attachments) {
|
14294 | for (var att in change.doc._attachments) {
|
14295 |
|
14296 | if (change.doc._attachments.hasOwnProperty(att)) {
|
14297 | change.doc._attachments[att].stub = true;
|
14298 | }
|
14299 | }
|
14300 | }
|
14301 | return true;
|
14302 | };
|
14303 | }
|
14304 |
|
14305 |
|
14306 |
|
14307 |
|
14308 |
|
14309 | function f() {}
|
14310 |
|
14311 | var hasName = f.name;
|
14312 | var res;
|
14313 |
|
14314 |
|
14315 |
|
14316 | if (hasName) {
|
14317 | res = function (fun) {
|
14318 | return fun.name;
|
14319 | };
|
14320 | } else {
|
14321 | res = function (fun) {
|
14322 | var match = fun.toString().match(/^\s*function\s*(?:(\S+)\s*)?\(/);
|
14323 | if (match && match[1]) {
|
14324 | return match[1];
|
14325 | }
|
14326 | else {
|
14327 | return '';
|
14328 | }
|
14329 | };
|
14330 | }
|
14331 |
|
14332 | var functionName = res;
|
14333 |
|
14334 |
|
14335 |
|
14336 |
|
14337 |
|
14338 |
|
14339 | function invalidIdError(id) {
|
14340 | var err;
|
14341 | if (!id) {
|
14342 | err = createError(MISSING_ID);
|
14343 | } else if (typeof id !== 'string') {
|
14344 | err = createError(INVALID_ID);
|
14345 | } else if (/^_/.test(id) && !(/^_(design|local)/).test(id)) {
|
14346 | err = createError(RESERVED_ID);
|
14347 | }
|
14348 | if (err) {
|
14349 | throw err;
|
14350 | }
|
14351 | }
|
14352 |
|
14353 |
|
14354 |
|
14355 |
|
14356 |
|
14357 |
|
14358 |
|
14359 | var thisAtob = function (str) {
|
14360 | return atob(str);
|
14361 | };
|
14362 |
|
14363 | var thisBtoa = function (str) {
|
14364 | return btoa(str);
|
14365 | };
|
14366 |
|
14367 |
|
14368 |
|
14369 |
|
14370 | function createBlob(parts, properties) {
|
14371 |
|
14372 | parts = parts || [];
|
14373 | properties = properties || {};
|
14374 | try {
|
14375 | return new Blob(parts, properties);
|
14376 | } catch (e) {
|
14377 | if (e.name !== "TypeError") {
|
14378 | throw e;
|
14379 | }
|
14380 | var Builder = typeof BlobBuilder !== 'undefined' ? BlobBuilder :
|
14381 | typeof MSBlobBuilder !== 'undefined' ? MSBlobBuilder :
|
14382 | typeof MozBlobBuilder !== 'undefined' ? MozBlobBuilder :
|
14383 | WebKitBlobBuilder;
|
14384 | var builder = new Builder();
|
14385 | for (var i = 0; i < parts.length; i += 1) {
|
14386 | builder.append(parts[i]);
|
14387 | }
|
14388 | return builder.getBlob(properties.type);
|
14389 | }
|
14390 | }
|
14391 |
|
14392 |
|
14393 |
|
14394 | function binaryStringToArrayBuffer(bin) {
|
14395 | var length = bin.length;
|
14396 | var buf = new ArrayBuffer(length);
|
14397 | var arr = new Uint8Array(buf);
|
14398 | for (var i = 0; i < length; i++) {
|
14399 | arr[i] = bin.charCodeAt(i);
|
14400 | }
|
14401 | return buf;
|
14402 | }
|
14403 |
|
14404 | function binStringToBluffer(binString, type) {
|
14405 | return createBlob([binaryStringToArrayBuffer(binString)], {type: type});
|
14406 | }
|
14407 |
|
14408 |
|
14409 |
|
14410 |
|
14411 | function arrayBufferToBinaryString(buffer) {
|
14412 | var binary = '';
|
14413 | var bytes = new Uint8Array(buffer);
|
14414 | var length = bytes.byteLength;
|
14415 | for (var i = 0; i < length; i++) {
|
14416 | binary += String.fromCharCode(bytes[i]);
|
14417 | }
|
14418 | return binary;
|
14419 | }
|
14420 |
|
14421 |
|
14422 | function readAsBinaryString(blob, callback) {
|
14423 | var reader = new FileReader();
|
14424 | var hasBinaryString = typeof reader.readAsBinaryString === 'function';
|
14425 | reader.onloadend = function (e) {
|
14426 | var result = e.target.result || '';
|
14427 | if (hasBinaryString) {
|
14428 | return callback(result);
|
14429 | }
|
14430 | callback(arrayBufferToBinaryString(result));
|
14431 | };
|
14432 | if (hasBinaryString) {
|
14433 | reader.readAsBinaryString(blob);
|
14434 | } else {
|
14435 | reader.readAsArrayBuffer(blob);
|
14436 | }
|
14437 | }
|
14438 |
|
14439 |
|
14440 | function readAsArrayBuffer(blob, callback) {
|
14441 | var reader = new FileReader();
|
14442 | reader.onloadend = function (e) {
|
14443 | var result = e.target.result || new ArrayBuffer(0);
|
14444 | callback(result);
|
14445 | };
|
14446 | reader.readAsArrayBuffer(blob);
|
14447 | }
|
14448 |
|
14449 |
|
14450 |
|
14451 | var setImmediateShim = global.setImmediate || global.setTimeout;
|
14452 | var MD5_CHUNK_SIZE = 32768;
|
14453 |
|
14454 | function rawToBase64(raw) {
|
14455 | return thisBtoa(raw);
|
14456 | }
|
14457 |
|
14458 | function sliceBlob(blob, start, end) {
|
14459 | if (blob.webkitSlice) {
|
14460 | return blob.webkitSlice(start, end);
|
14461 | }
|
14462 | return blob.slice(start, end);
|
14463 | }
|
14464 |
|
14465 | function appendBlob(buffer, blob, start, end, callback) {
|
14466 | if (start > 0 || end < blob.size) {
|
14467 |
|
14468 | blob = sliceBlob(blob, start, end);
|
14469 | }
|
14470 | readAsArrayBuffer(blob, function (arrayBuffer) {
|
14471 | buffer.append(arrayBuffer);
|
14472 | callback();
|
14473 | });
|
14474 | }
|
14475 |
|
14476 | function appendString(buffer, string, start, end, callback) {
|
14477 | if (start > 0 || end < string.length) {
|
14478 |
|
14479 | string = string.substring(start, end);
|
14480 | }
|
14481 | buffer.appendBinary(string);
|
14482 | callback();
|
14483 | }
|
14484 |
|
14485 | function binaryMd5(data, callback) {
|
14486 | var inputIsString = typeof data === 'string';
|
14487 | var len = inputIsString ? data.length : data.size;
|
14488 | var chunkSize = Math.min(MD5_CHUNK_SIZE, len);
|
14489 | var chunks = Math.ceil(len / chunkSize);
|
14490 | var currentChunk = 0;
|
14491 | var buffer = inputIsString ? new Md5() : new Md5.ArrayBuffer();
|
14492 |
|
14493 | var append = inputIsString ? appendString : appendBlob;
|
14494 |
|
14495 | function next() {
|
14496 | setImmediateShim(loadNextChunk);
|
14497 | }
|
14498 |
|
14499 | function done() {
|
14500 | var raw = buffer.end(true);
|
14501 | var base64 = rawToBase64(raw);
|
14502 | callback(base64);
|
14503 | buffer.destroy();
|
14504 | }
|
14505 |
|
14506 | function loadNextChunk() {
|
14507 | var start = currentChunk * chunkSize;
|
14508 | var end = start + chunkSize;
|
14509 | currentChunk++;
|
14510 | if (currentChunk < chunks) {
|
14511 | append(buffer, data, start, end, next);
|
14512 | } else {
|
14513 | append(buffer, data, start, end, done);
|
14514 | }
|
14515 | }
|
14516 | loadNextChunk();
|
14517 | }
|
14518 |
|
14519 | function stringMd5(string) {
|
14520 | return Md5.hash(string);
|
14521 | }
|
14522 |
|
14523 | function rev$$1(doc, deterministic_revs) {
|
14524 | var clonedDoc = clone(doc);
|
14525 | if (!deterministic_revs) {
|
14526 | return uuidV4.v4().replace(/-/g, '').toLowerCase();
|
14527 | }
|
14528 |
|
14529 | delete clonedDoc._rev_tree;
|
14530 | return stringMd5(JSON.stringify(clonedDoc));
|
14531 | }
|
14532 |
|
14533 | var uuid = uuidV4.v4;
|
14534 |
|
14535 | function isFunction(f) {
|
14536 | return 'function' === typeof f;
|
14537 | }
|
14538 |
|
14539 | function getPrefix(db) {
|
14540 | if (isFunction(db.prefix)) {
|
14541 | return db.prefix();
|
14542 | }
|
14543 | return db;
|
14544 | }
|
14545 |
|
14546 | function clone$1(_obj) {
|
14547 | var obj = {};
|
14548 | for (var k in _obj) {
|
14549 | obj[k] = _obj[k];
|
14550 | }
|
14551 | return obj;
|
14552 | }
|
14553 |
|
14554 | function nut(db, precodec, codec) {
|
14555 | function encodePrefix(prefix, key, opts1, opts2) {
|
14556 | return precodec.encode([ prefix, codec.encodeKey(key, opts1, opts2 ) ]);
|
14557 | }
|
14558 |
|
14559 | function addEncodings(op, prefix) {
|
14560 | if (prefix && prefix.options) {
|
14561 | op.keyEncoding =
|
14562 | op.keyEncoding || prefix.options.keyEncoding;
|
14563 | op.valueEncoding =
|
14564 | op.valueEncoding || prefix.options.valueEncoding;
|
14565 | }
|
14566 | return op;
|
14567 | }
|
14568 |
|
14569 | db.open(function () { });
|
14570 |
|
14571 | return {
|
14572 | apply: function (ops, opts, cb) {
|
14573 | opts = opts || {};
|
14574 |
|
14575 | var batch = [];
|
14576 | var i = -1;
|
14577 | var len = ops.length;
|
14578 |
|
14579 | while (++i < len) {
|
14580 | var op = ops[i];
|
14581 | addEncodings(op, op.prefix);
|
14582 | op.prefix = getPrefix(op.prefix);
|
14583 | batch.push({
|
14584 | key: encodePrefix(op.prefix, op.key, opts, op),
|
14585 | value: op.type !== 'del' && codec.encodeValue(op.value, opts, op),
|
14586 | type: op.type
|
14587 | });
|
14588 | }
|
14589 | db.db.batch(batch, opts, cb);
|
14590 | },
|
14591 | get: function (key, prefix, opts, cb) {
|
14592 | opts.asBuffer = codec.valueAsBuffer(opts);
|
14593 | return db.db.get(
|
14594 | encodePrefix(prefix, key, opts),
|
14595 | opts,
|
14596 | function (err, value) {
|
14597 | if (err) {
|
14598 | cb(err);
|
14599 | } else {
|
14600 | cb(null, codec.decodeValue(value, opts));
|
14601 | }
|
14602 | }
|
14603 | );
|
14604 | },
|
14605 | createDecoder: function (opts) {
|
14606 | return function (key, value) {
|
14607 | return {
|
14608 | key: codec.decodeKey(precodec.decode(key)[1], opts),
|
14609 | value: codec.decodeValue(value, opts)
|
14610 | };
|
14611 | };
|
14612 | },
|
14613 | isClosed: function isClosed() {
|
14614 | return db.isClosed();
|
14615 | },
|
14616 | close: function close(cb) {
|
14617 | return db.close(cb);
|
14618 | },
|
14619 | iterator: function (_opts) {
|
14620 | var opts = clone$1(_opts || {});
|
14621 | var prefix = _opts.prefix || [];
|
14622 |
|
14623 | function encodeKey(key) {
|
14624 | return encodePrefix(prefix, key, opts, {});
|
14625 | }
|
14626 |
|
14627 | ltgt.toLtgt(_opts, opts, encodeKey, precodec.lowerBound, precodec.upperBound);
|
14628 |
|
14629 |
|
14630 |
|
14631 | opts.prefix = null;
|
14632 |
|
14633 |
|
14634 |
|
14635 |
|
14636 | opts.keyAsBuffer = opts.valueAsBuffer = false;
|
14637 |
|
14638 |
|
14639 |
|
14640 |
|
14641 |
|
14642 |
|
14643 | if ('number' !== typeof opts.limit) {
|
14644 | opts.limit = -1;
|
14645 | }
|
14646 |
|
14647 | opts.keyAsBuffer = precodec.buffer;
|
14648 | opts.valueAsBuffer = codec.valueAsBuffer(opts);
|
14649 |
|
14650 | function wrapIterator(iterator) {
|
14651 | return {
|
14652 | next: function (cb) {
|
14653 | return iterator.next(cb);
|
14654 | },
|
14655 | end: function (cb) {
|
14656 | iterator.end(cb);
|
14657 | }
|
14658 | };
|
14659 | }
|
14660 |
|
14661 | return wrapIterator(db.db.iterator(opts));
|
14662 | }
|
14663 | };
|
14664 | }
|
14665 |
|
14666 | function NotFoundError() {
|
14667 | Error.call(this);
|
14668 | }
|
14669 |
|
14670 | inherits(NotFoundError, Error);
|
14671 |
|
14672 | NotFoundError.prototype.name = 'NotFoundError';
|
14673 |
|
14674 | var EventEmitter = events__default.EventEmitter;
|
14675 | var version = "6.5.4";
|
14676 |
|
14677 | var NOT_FOUND_ERROR = new NotFoundError();
|
14678 |
|
14679 | var sublevel = function (nut, prefix, createStream, options) {
|
14680 | var emitter = new EventEmitter();
|
14681 | emitter.sublevels = {};
|
14682 | emitter.options = options;
|
14683 |
|
14684 | emitter.version = version;
|
14685 |
|
14686 | emitter.methods = {};
|
14687 | prefix = prefix || [];
|
14688 |
|
14689 | function mergeOpts(opts) {
|
14690 | var o = {};
|
14691 | var k;
|
14692 | if (options) {
|
14693 | for (k in options) {
|
14694 | if (typeof options[k] !== 'undefined') {
|
14695 | o[k] = options[k];
|
14696 | }
|
14697 | }
|
14698 | }
|
14699 | if (opts) {
|
14700 | for (k in opts) {
|
14701 | if (typeof opts[k] !== 'undefined') {
|
14702 | o[k] = opts[k];
|
14703 | }
|
14704 | }
|
14705 | }
|
14706 | return o;
|
14707 | }
|
14708 |
|
14709 | emitter.put = function (key, value, opts, cb) {
|
14710 | if ('function' === typeof opts) {
|
14711 | cb = opts;
|
14712 | opts = {};
|
14713 | }
|
14714 |
|
14715 | nut.apply([{
|
14716 | key: key, value: value,
|
14717 | prefix: prefix.slice(), type: 'put'
|
14718 | }], mergeOpts(opts), function (err) {
|
14719 |
|
14720 | if (err) {
|
14721 | return cb(err);
|
14722 | }
|
14723 | emitter.emit('put', key, value);
|
14724 | cb(null);
|
14725 | });
|
14726 | };
|
14727 |
|
14728 | emitter.prefix = function () {
|
14729 | return prefix.slice();
|
14730 | };
|
14731 |
|
14732 | emitter.batch = function (ops, opts, cb) {
|
14733 | if ('function' === typeof opts) {
|
14734 | cb = opts;
|
14735 | opts = {};
|
14736 | }
|
14737 |
|
14738 | ops = ops.map(function (op) {
|
14739 | return {
|
14740 | key: op.key,
|
14741 | value: op.value,
|
14742 | prefix: op.prefix || prefix,
|
14743 | keyEncoding: op.keyEncoding,
|
14744 | valueEncoding: op.valueEncoding,
|
14745 | type: op.type
|
14746 | };
|
14747 | });
|
14748 |
|
14749 | nut.apply(ops, mergeOpts(opts), function (err) {
|
14750 |
|
14751 | if (err) {
|
14752 | return cb(err);
|
14753 | }
|
14754 | emitter.emit('batch', ops);
|
14755 | cb(null);
|
14756 | });
|
14757 | };
|
14758 |
|
14759 | emitter.get = function (key, opts, cb) {
|
14760 |
|
14761 | if ('function' === typeof opts) {
|
14762 | cb = opts;
|
14763 | opts = {};
|
14764 | }
|
14765 | nut.get(key, prefix, mergeOpts(opts), function (err, value) {
|
14766 | if (err) {
|
14767 | cb(NOT_FOUND_ERROR);
|
14768 | } else {
|
14769 | cb(null, value);
|
14770 | }
|
14771 | });
|
14772 | };
|
14773 |
|
14774 | emitter.sublevel = function (name, opts) {
|
14775 | return emitter.sublevels[name] =
|
14776 | emitter.sublevels[name] || sublevel(nut, prefix.concat(name), createStream, mergeOpts(opts));
|
14777 | };
|
14778 |
|
14779 | emitter.readStream = emitter.createReadStream = function (opts) {
|
14780 | opts = mergeOpts(opts);
|
14781 | opts.prefix = prefix;
|
14782 | var stream;
|
14783 | var it = nut.iterator(opts);
|
14784 |
|
14785 | stream = createStream(opts, nut.createDecoder(opts));
|
14786 | stream.setIterator(it);
|
14787 |
|
14788 | return stream;
|
14789 | };
|
14790 |
|
14791 | emitter.close = function (cb) {
|
14792 | nut.close(cb);
|
14793 | };
|
14794 |
|
14795 | emitter.isOpen = nut.isOpen;
|
14796 | emitter.isClosed = nut.isClosed;
|
14797 |
|
14798 | return emitter;
|
14799 | };
|
14800 |
|
14801 |
|
14802 |
|
14803 |
|
14804 |
|
14805 |
|
14806 | var Readable = ReadableStreamCore.Readable;
|
14807 |
|
14808 | function ReadStream(options, makeData) {
|
14809 | if (!(this instanceof ReadStream)) {
|
14810 | return new ReadStream(options, makeData);
|
14811 | }
|
14812 |
|
14813 | Readable.call(this, { objectMode: true, highWaterMark: options.highWaterMark });
|
14814 |
|
14815 |
|
14816 |
|
14817 | this._waiting = false;
|
14818 | this._options = options;
|
14819 | this._makeData = makeData;
|
14820 | }
|
14821 |
|
14822 | inherits(ReadStream, Readable);
|
14823 |
|
14824 | ReadStream.prototype.setIterator = function (it) {
|
14825 | this._iterator = it;
|
14826 |
|
14827 | if (this._destroyed) {
|
14828 | return it.end(function () {});
|
14829 | }
|
14830 |
|
14831 | if (this._waiting) {
|
14832 | this._waiting = false;
|
14833 | return this._read();
|
14834 | }
|
14835 | return this;
|
14836 | };
|
14837 |
|
14838 | ReadStream.prototype._read = function read() {
|
14839 | var self = this;
|
14840 |
|
14841 | if (self._destroyed) {
|
14842 | return;
|
14843 | }
|
14844 |
|
14845 | if (!self._iterator) {
|
14846 | return this._waiting = true;
|
14847 | }
|
14848 |
|
14849 | self._iterator.next(function (err, key, value) {
|
14850 | if (err || (key === undefined && value === undefined)) {
|
14851 | if (!err && !self._destroyed) {
|
14852 | self.push(null);
|
14853 | }
|
14854 | return self._cleanup(err);
|
14855 | }
|
14856 |
|
14857 |
|
14858 | value = self._makeData(key, value);
|
14859 | if (!self._destroyed) {
|
14860 | self.push(value);
|
14861 | }
|
14862 | });
|
14863 | };
|
14864 |
|
14865 | ReadStream.prototype._cleanup = function (err) {
|
14866 | if (this._destroyed) {
|
14867 | return;
|
14868 | }
|
14869 |
|
14870 | this._destroyed = true;
|
14871 |
|
14872 | var self = this;
|
14873 |
|
14874 | if (err && err.message !== 'iterator has ended') {
|
14875 | self.emit('error', err);
|
14876 | }
|
14877 |
|
14878 |
|
14879 | if (self._iterator) {
|
14880 | self._iterator.end(function () {
|
14881 | self._iterator = null;
|
14882 | self.emit('close');
|
14883 | });
|
14884 | } else {
|
14885 | self.emit('close');
|
14886 | }
|
14887 | };
|
14888 |
|
14889 | ReadStream.prototype.destroy = function () {
|
14890 | this._cleanup();
|
14891 | };
|
14892 |
|
14893 | var precodec = {
|
14894 | encode: function (decodedKey) {
|
14895 | return '\xff' + decodedKey[0] + '\xff' + decodedKey[1];
|
14896 | },
|
14897 | decode: function (encodedKeyAsBuffer) {
|
14898 | var str = encodedKeyAsBuffer.toString();
|
14899 | var idx = str.indexOf('\xff', 1);
|
14900 | return [str.substring(1, idx), str.substring(idx + 1)];
|
14901 | },
|
14902 | lowerBound: '\x00',
|
14903 | upperBound: '\xff'
|
14904 | };
|
14905 |
|
14906 | var codec = new Codec();
|
14907 |
|
14908 | function sublevelPouch(db) {
|
14909 | return sublevel(nut(db, precodec, codec), [], ReadStream, db.options);
|
14910 | }
|
14911 |
|
14912 | function allDocsKeysQuery(api, opts) {
|
14913 | var keys = opts.keys;
|
14914 | var finalResults = {
|
14915 | offset: opts.skip
|
14916 | };
|
14917 | return Promise.all(keys.map(function (key) {
|
14918 | var subOpts = $inject_Object_assign({key: key, deleted: 'ok'}, opts);
|
14919 | ['limit', 'skip', 'keys'].forEach(function (optKey) {
|
14920 | delete subOpts[optKey];
|
14921 | });
|
14922 | return new Promise(function (resolve, reject) {
|
14923 | api._allDocs(subOpts, function (err, res) {
|
14924 |
|
14925 | if (err) {
|
14926 | return reject(err);
|
14927 | }
|
14928 |
|
14929 | if (opts.update_seq && res.update_seq !== undefined) {
|
14930 | finalResults.update_seq = res.update_seq;
|
14931 | }
|
14932 | finalResults.total_rows = res.total_rows;
|
14933 | resolve(res.rows[0] || {key: key, error: 'not_found'});
|
14934 | });
|
14935 | });
|
14936 | })).then(function (results) {
|
14937 | finalResults.rows = results;
|
14938 | return finalResults;
|
14939 | });
|
14940 | }
|
14941 |
|
14942 | function toObject(array) {
|
14943 | return array.reduce(function (obj, item) {
|
14944 | obj[item] = true;
|
14945 | return obj;
|
14946 | }, {});
|
14947 | }
|
14948 |
|
14949 | var reservedWords = toObject([
|
14950 | '_id',
|
14951 | '_rev',
|
14952 | '_attachments',
|
14953 | '_deleted',
|
14954 | '_revisions',
|
14955 | '_revs_info',
|
14956 | '_conflicts',
|
14957 | '_deleted_conflicts',
|
14958 | '_local_seq',
|
14959 | '_rev_tree',
|
14960 |
|
14961 | '_replication_id',
|
14962 | '_replication_state',
|
14963 | '_replication_state_time',
|
14964 | '_replication_state_reason',
|
14965 | '_replication_stats',
|
14966 |
|
14967 | '_removed'
|
14968 | ]);
|
14969 |
|
14970 |
|
14971 | var dataWords = toObject([
|
14972 | '_attachments',
|
14973 |
|
14974 | '_replication_id',
|
14975 | '_replication_state',
|
14976 | '_replication_state_time',
|
14977 | '_replication_state_reason',
|
14978 | '_replication_stats'
|
14979 | ]);
|
14980 |
|
14981 | function parseRevisionInfo(rev) {
|
14982 | if (!/^\d+-./.test(rev)) {
|
14983 | return createError(INVALID_REV);
|
14984 | }
|
14985 | var idx = rev.indexOf('-');
|
14986 | var left = rev.substring(0, idx);
|
14987 | var right = rev.substring(idx + 1);
|
14988 | return {
|
14989 | prefix: parseInt(left, 10),
|
14990 | id: right
|
14991 | };
|
14992 | }
|
14993 |
|
14994 | function makeRevTreeFromRevisions(revisions, opts) {
|
14995 | var pos = revisions.start - revisions.ids.length + 1;
|
14996 |
|
14997 | var revisionIds = revisions.ids;
|
14998 | var ids = [revisionIds[0], opts, []];
|
14999 |
|
15000 | for (var i = 1, len = revisionIds.length; i < len; i++) {
|
15001 | ids = [revisionIds[i], {status: 'missing'}, [ids]];
|
15002 | }
|
15003 |
|
15004 | return [{
|
15005 | pos: pos,
|
15006 | ids: ids
|
15007 | }];
|
15008 | }
|
15009 |
|
15010 |
|
15011 |
|
15012 | function parseDoc(doc, newEdits, dbOpts) {
|
15013 | if (!dbOpts) {
|
15014 | dbOpts = {
|
15015 | deterministic_revs: true
|
15016 | };
|
15017 | }
|
15018 |
|
15019 | var nRevNum;
|
15020 | var newRevId;
|
15021 | var revInfo;
|
15022 | var opts = {status: 'available'};
|
15023 | if (doc._deleted) {
|
15024 | opts.deleted = true;
|
15025 | }
|
15026 |
|
15027 | if (newEdits) {
|
15028 | if (!doc._id) {
|
15029 | doc._id = uuid();
|
15030 | }
|
15031 | newRevId = rev$$1(doc, dbOpts.deterministic_revs);
|
15032 | if (doc._rev) {
|
15033 | revInfo = parseRevisionInfo(doc._rev);
|
15034 | if (revInfo.error) {
|
15035 | return revInfo;
|
15036 | }
|
15037 | doc._rev_tree = [{
|
15038 | pos: revInfo.prefix,
|
15039 | ids: [revInfo.id, {status: 'missing'}, [[newRevId, opts, []]]]
|
15040 | }];
|
15041 | nRevNum = revInfo.prefix + 1;
|
15042 | } else {
|
15043 | doc._rev_tree = [{
|
15044 | pos: 1,
|
15045 | ids : [newRevId, opts, []]
|
15046 | }];
|
15047 | nRevNum = 1;
|
15048 | }
|
15049 | } else {
|
15050 | if (doc._revisions) {
|
15051 | doc._rev_tree = makeRevTreeFromRevisions(doc._revisions, opts);
|
15052 | nRevNum = doc._revisions.start;
|
15053 | newRevId = doc._revisions.ids[0];
|
15054 | }
|
15055 | if (!doc._rev_tree) {
|
15056 | revInfo = parseRevisionInfo(doc._rev);
|
15057 | if (revInfo.error) {
|
15058 | return revInfo;
|
15059 | }
|
15060 | nRevNum = revInfo.prefix;
|
15061 | newRevId = revInfo.id;
|
15062 | doc._rev_tree = [{
|
15063 | pos: nRevNum,
|
15064 | ids: [newRevId, opts, []]
|
15065 | }];
|
15066 | }
|
15067 | }
|
15068 |
|
15069 | invalidIdError(doc._id);
|
15070 |
|
15071 | doc._rev = nRevNum + '-' + newRevId;
|
15072 |
|
15073 | var result = {metadata : {}, data : {}};
|
15074 | for (var key in doc) {
|
15075 |
|
15076 | if (Object.prototype.hasOwnProperty.call(doc, key)) {
|
15077 | var specialKey = key[0] === '_';
|
15078 | if (specialKey && !reservedWords[key]) {
|
15079 | var error = createError(DOC_VALIDATION, key);
|
15080 | error.message = DOC_VALIDATION.message + ': ' + key;
|
15081 | throw error;
|
15082 | } else if (specialKey && !dataWords[key]) {
|
15083 | result.metadata[key.slice(1)] = doc[key];
|
15084 | } else {
|
15085 | result.data[key] = doc[key];
|
15086 | }
|
15087 | }
|
15088 | }
|
15089 | return result;
|
15090 | }
|
15091 |
|
15092 |
|
15093 |
|
15094 |
|
15095 |
|
15096 |
|
15097 | function winningRev(metadata) {
|
15098 | var winningId;
|
15099 | var winningPos;
|
15100 | var winningDeleted;
|
15101 | var toVisit = metadata.rev_tree.slice();
|
15102 | var node;
|
15103 | while ((node = toVisit.pop())) {
|
15104 | var tree = node.ids;
|
15105 | var branches = tree[2];
|
15106 | var pos = node.pos;
|
15107 | if (branches.length) {
|
15108 | for (var i = 0, len = branches.length; i < len; i++) {
|
15109 | toVisit.push({pos: pos + 1, ids: branches[i]});
|
15110 | }
|
15111 | continue;
|
15112 | }
|
15113 | var deleted = !!tree[1].deleted;
|
15114 | var id = tree[0];
|
15115 |
|
15116 | if (!winningId || (winningDeleted !== deleted ? winningDeleted :
|
15117 | winningPos !== pos ? winningPos < pos : winningId < id)) {
|
15118 | winningId = id;
|
15119 | winningPos = pos;
|
15120 | winningDeleted = deleted;
|
15121 | }
|
15122 | }
|
15123 |
|
15124 | return winningPos + '-' + winningId;
|
15125 | }
|
15126 |
|
15127 |
|
15128 |
|
15129 |
|
15130 |
|
15131 | function traverseRevTree(revs, callback) {
|
15132 | var toVisit = revs.slice();
|
15133 |
|
15134 | var node;
|
15135 | while ((node = toVisit.pop())) {
|
15136 | var pos = node.pos;
|
15137 | var tree = node.ids;
|
15138 | var branches = tree[2];
|
15139 | var newCtx =
|
15140 | callback(branches.length === 0, pos, tree[0], node.ctx, tree[1]);
|
15141 | for (var i = 0, len = branches.length; i < len; i++) {
|
15142 | toVisit.push({pos: pos + 1, ids: branches[i], ctx: newCtx});
|
15143 | }
|
15144 | }
|
15145 | }
|
15146 |
|
15147 | function sortByPos(a, b) {
|
15148 | return a.pos - b.pos;
|
15149 | }
|
15150 |
|
15151 | function collectLeaves(revs) {
|
15152 | var leaves = [];
|
15153 | traverseRevTree(revs, function (isLeaf, pos, id, acc, opts) {
|
15154 | if (isLeaf) {
|
15155 | leaves.push({rev: pos + "-" + id, pos: pos, opts: opts});
|
15156 | }
|
15157 | });
|
15158 | leaves.sort(sortByPos).reverse();
|
15159 | for (var i = 0, len = leaves.length; i < len; i++) {
|
15160 | delete leaves[i].pos;
|
15161 | }
|
15162 | return leaves;
|
15163 | }
|
15164 |
|
15165 |
|
15166 |
|
15167 |
|
15168 | function collectConflicts(metadata) {
|
15169 | var win = winningRev(metadata);
|
15170 | var leaves = collectLeaves(metadata.rev_tree);
|
15171 | var conflicts = [];
|
15172 | for (var i = 0, len = leaves.length; i < len; i++) {
|
15173 | var leaf = leaves[i];
|
15174 | if (leaf.rev !== win && !leaf.opts.deleted) {
|
15175 | conflicts.push(leaf.rev);
|
15176 | }
|
15177 | }
|
15178 | return conflicts;
|
15179 | }
|
15180 |
|
15181 |
|
15182 |
|
15183 | function compactTree(metadata) {
|
15184 | var revs = [];
|
15185 | traverseRevTree(metadata.rev_tree, function (isLeaf, pos,
|
15186 | revHash, ctx, opts) {
|
15187 | if (opts.status === 'available' && !isLeaf) {
|
15188 | revs.push(pos + '-' + revHash);
|
15189 | opts.status = 'missing';
|
15190 | }
|
15191 | });
|
15192 | return revs;
|
15193 | }
|
15194 |
|
15195 |
|
15196 | function rootToLeaf(revs) {
|
15197 | var paths = [];
|
15198 | var toVisit = revs.slice();
|
15199 | var node;
|
15200 | while ((node = toVisit.pop())) {
|
15201 | var pos = node.pos;
|
15202 | var tree = node.ids;
|
15203 | var id = tree[0];
|
15204 | var opts = tree[1];
|
15205 | var branches = tree[2];
|
15206 | var isLeaf = branches.length === 0;
|
15207 |
|
15208 | var history = node.history ? node.history.slice() : [];
|
15209 | history.push({id: id, opts: opts});
|
15210 | if (isLeaf) {
|
15211 | paths.push({pos: (pos + 1 - history.length), ids: history});
|
15212 | }
|
15213 | for (var i = 0, len = branches.length; i < len; i++) {
|
15214 | toVisit.push({pos: pos + 1, ids: branches[i], history: history});
|
15215 | }
|
15216 | }
|
15217 | return paths.reverse();
|
15218 | }
|
15219 |
|
15220 |
|
15221 |
|
15222 | function sortByPos$1(a, b) {
|
15223 | return a.pos - b.pos;
|
15224 | }
|
15225 |
|
15226 |
|
15227 | function binarySearch(arr, item, comparator) {
|
15228 | var low = 0;
|
15229 | var high = arr.length;
|
15230 | var mid;
|
15231 | while (low < high) {
|
15232 | mid = (low + high) >>> 1;
|
15233 | if (comparator(arr[mid], item) < 0) {
|
15234 | low = mid + 1;
|
15235 | } else {
|
15236 | high = mid;
|
15237 | }
|
15238 | }
|
15239 | return low;
|
15240 | }
|
15241 |
|
15242 |
|
15243 | function insertSorted(arr, item, comparator) {
|
15244 | var idx = binarySearch(arr, item, comparator);
|
15245 | arr.splice(idx, 0, item);
|
15246 | }
|
15247 |
|
15248 |
|
15249 |
|
15250 |
|
15251 | function pathToTree(path, numStemmed) {
|
15252 | var root;
|
15253 | var leaf;
|
15254 | for (var i = numStemmed, len = path.length; i < len; i++) {
|
15255 | var node = path[i];
|
15256 | var currentLeaf = [node.id, node.opts, []];
|
15257 | if (leaf) {
|
15258 | leaf[2].push(currentLeaf);
|
15259 | leaf = currentLeaf;
|
15260 | } else {
|
15261 | root = leaf = currentLeaf;
|
15262 | }
|
15263 | }
|
15264 | return root;
|
15265 | }
|
15266 |
|
15267 |
|
15268 | function compareTree(a, b) {
|
15269 | return a[0] < b[0] ? -1 : 1;
|
15270 | }
|
15271 |
|
15272 |
|
15273 |
|
15274 | function mergeTree(in_tree1, in_tree2) {
|
15275 | var queue = [{tree1: in_tree1, tree2: in_tree2}];
|
15276 | var conflicts = false;
|
15277 | while (queue.length > 0) {
|
15278 | var item = queue.pop();
|
15279 | var tree1 = item.tree1;
|
15280 | var tree2 = item.tree2;
|
15281 |
|
15282 | if (tree1[1].status || tree2[1].status) {
|
15283 | tree1[1].status =
|
15284 | (tree1[1].status === 'available' ||
|
15285 | tree2[1].status === 'available') ? 'available' : 'missing';
|
15286 | }
|
15287 |
|
15288 | for (var i = 0; i < tree2[2].length; i++) {
|
15289 | if (!tree1[2][0]) {
|
15290 | conflicts = 'new_leaf';
|
15291 | tree1[2][0] = tree2[2][i];
|
15292 | continue;
|
15293 | }
|
15294 |
|
15295 | var merged = false;
|
15296 | for (var j = 0; j < tree1[2].length; j++) {
|
15297 | if (tree1[2][j][0] === tree2[2][i][0]) {
|
15298 | queue.push({tree1: tree1[2][j], tree2: tree2[2][i]});
|
15299 | merged = true;
|
15300 | }
|
15301 | }
|
15302 | if (!merged) {
|
15303 | conflicts = 'new_branch';
|
15304 | insertSorted(tree1[2], tree2[2][i], compareTree);
|
15305 | }
|
15306 | }
|
15307 | }
|
15308 | return {conflicts: conflicts, tree: in_tree1};
|
15309 | }
|
15310 |
|
15311 | function doMerge(tree, path, dontExpand) {
|
15312 | var restree = [];
|
15313 | var conflicts = false;
|
15314 | var merged = false;
|
15315 | var res;
|
15316 |
|
15317 | if (!tree.length) {
|
15318 | return {tree: [path], conflicts: 'new_leaf'};
|
15319 | }
|
15320 |
|
15321 | for (var i = 0, len = tree.length; i < len; i++) {
|
15322 | var branch = tree[i];
|
15323 | if (branch.pos === path.pos && branch.ids[0] === path.ids[0]) {
|
15324 |
|
15325 |
|
15326 | res = mergeTree(branch.ids, path.ids);
|
15327 | restree.push({pos: branch.pos, ids: res.tree});
|
15328 | conflicts = conflicts || res.conflicts;
|
15329 | merged = true;
|
15330 | } else if (dontExpand !== true) {
|
15331 |
|
15332 |
|
15333 |
|
15334 |
|
15335 |
|
15336 | var t1 = branch.pos < path.pos ? branch : path;
|
15337 | var t2 = branch.pos < path.pos ? path : branch;
|
15338 | var diff = t2.pos - t1.pos;
|
15339 |
|
15340 | var candidateParents = [];
|
15341 |
|
15342 | var trees = [];
|
15343 | trees.push({ids: t1.ids, diff: diff, parent: null, parentIdx: null});
|
15344 | while (trees.length > 0) {
|
15345 | var item = trees.pop();
|
15346 | if (item.diff === 0) {
|
15347 | if (item.ids[0] === t2.ids[0]) {
|
15348 | candidateParents.push(item);
|
15349 | }
|
15350 | continue;
|
15351 | }
|
15352 | var elements = item.ids[2];
|
15353 | for (var j = 0, elementsLen = elements.length; j < elementsLen; j++) {
|
15354 | trees.push({
|
15355 | ids: elements[j],
|
15356 | diff: item.diff - 1,
|
15357 | parent: item.ids,
|
15358 | parentIdx: j
|
15359 | });
|
15360 | }
|
15361 | }
|
15362 |
|
15363 | var el = candidateParents[0];
|
15364 |
|
15365 | if (!el) {
|
15366 | restree.push(branch);
|
15367 | } else {
|
15368 | res = mergeTree(el.ids, t2.ids);
|
15369 | el.parent[2][el.parentIdx] = res.tree;
|
15370 | restree.push({pos: t1.pos, ids: t1.ids});
|
15371 | conflicts = conflicts || res.conflicts;
|
15372 | merged = true;
|
15373 | }
|
15374 | } else {
|
15375 | restree.push(branch);
|
15376 | }
|
15377 | }
|
15378 |
|
15379 |
|
15380 | if (!merged) {
|
15381 | restree.push(path);
|
15382 | }
|
15383 |
|
15384 | restree.sort(sortByPos$1);
|
15385 |
|
15386 | return {
|
15387 | tree: restree,
|
15388 | conflicts: conflicts || 'internal_node'
|
15389 | };
|
15390 | }
|
15391 |
|
15392 |
|
15393 | function stem(tree, depth) {
|
15394 |
|
15395 | var paths = rootToLeaf(tree);
|
15396 | var stemmedRevs;
|
15397 |
|
15398 | var result;
|
15399 | for (var i = 0, len = paths.length; i < len; i++) {
|
15400 |
|
15401 |
|
15402 | var path = paths[i];
|
15403 | var stemmed = path.ids;
|
15404 | var node;
|
15405 | if (stemmed.length > depth) {
|
15406 |
|
15407 | if (!stemmedRevs) {
|
15408 | stemmedRevs = {};
|
15409 | }
|
15410 | var numStemmed = stemmed.length - depth;
|
15411 | node = {
|
15412 | pos: path.pos + numStemmed,
|
15413 | ids: pathToTree(stemmed, numStemmed)
|
15414 | };
|
15415 |
|
15416 | for (var s = 0; s < numStemmed; s++) {
|
15417 | var rev = (path.pos + s) + '-' + stemmed[s].id;
|
15418 | stemmedRevs[rev] = true;
|
15419 | }
|
15420 | } else {
|
15421 | node = {
|
15422 | pos: path.pos,
|
15423 | ids: pathToTree(stemmed, 0)
|
15424 | };
|
15425 | }
|
15426 |
|
15427 |
|
15428 |
|
15429 | if (result) {
|
15430 | result = doMerge(result, node, true).tree;
|
15431 | } else {
|
15432 | result = [node];
|
15433 | }
|
15434 | }
|
15435 |
|
15436 |
|
15437 | if (stemmedRevs) {
|
15438 | traverseRevTree(result, function (isLeaf, pos, revHash) {
|
15439 |
|
15440 | delete stemmedRevs[pos + '-' + revHash];
|
15441 | });
|
15442 | }
|
15443 |
|
15444 | return {
|
15445 | tree: result,
|
15446 | revs: stemmedRevs ? Object.keys(stemmedRevs) : []
|
15447 | };
|
15448 | }
|
15449 |
|
15450 | function merge(tree, path, depth) {
|
15451 | var newTree = doMerge(tree, path);
|
15452 | var stemmed = stem(newTree.tree, depth);
|
15453 | return {
|
15454 | tree: stemmed.tree,
|
15455 | stemmedRevs: stemmed.revs,
|
15456 | conflicts: newTree.conflicts
|
15457 | };
|
15458 | }
|
15459 |
|
15460 |
|
15461 | function revExists(revs, rev) {
|
15462 | var toVisit = revs.slice();
|
15463 | var splitRev = rev.split('-');
|
15464 | var targetPos = parseInt(splitRev[0], 10);
|
15465 | var targetId = splitRev[1];
|
15466 |
|
15467 | var node;
|
15468 | while ((node = toVisit.pop())) {
|
15469 | if (node.pos === targetPos && node.ids[0] === targetId) {
|
15470 | return true;
|
15471 | }
|
15472 | var branches = node.ids[2];
|
15473 | for (var i = 0, len = branches.length; i < len; i++) {
|
15474 | toVisit.push({pos: node.pos + 1, ids: branches[i]});
|
15475 | }
|
15476 | }
|
15477 | return false;
|
15478 | }
|
15479 |
|
15480 | function getTrees(node) {
|
15481 | return node.ids;
|
15482 | }
|
15483 |
|
15484 |
|
15485 |
|
15486 |
|
15487 | function isDeleted(metadata, rev) {
|
15488 | if (!rev) {
|
15489 | rev = winningRev(metadata);
|
15490 | }
|
15491 | var id = rev.substring(rev.indexOf('-') + 1);
|
15492 | var toVisit = metadata.rev_tree.map(getTrees);
|
15493 |
|
15494 | var tree;
|
15495 | while ((tree = toVisit.pop())) {
|
15496 | if (tree[0] === id) {
|
15497 | return !!tree[1].deleted;
|
15498 | }
|
15499 | toVisit = toVisit.concat(tree[2]);
|
15500 | }
|
15501 | }
|
15502 |
|
15503 | function isLocalId(id) {
|
15504 | return (/^_local/).test(id);
|
15505 | }
|
15506 |
|
15507 |
|
15508 | function latest(rev, metadata) {
|
15509 | var toVisit = metadata.rev_tree.slice();
|
15510 | var node;
|
15511 | while ((node = toVisit.pop())) {
|
15512 | var pos = node.pos;
|
15513 | var tree = node.ids;
|
15514 | var id = tree[0];
|
15515 | var opts = tree[1];
|
15516 | var branches = tree[2];
|
15517 | var isLeaf = branches.length === 0;
|
15518 |
|
15519 | var history = node.history ? node.history.slice() : [];
|
15520 | history.push({id: id, pos: pos, opts: opts});
|
15521 |
|
15522 | if (isLeaf) {
|
15523 | for (var i = 0, len = history.length; i < len; i++) {
|
15524 | var historyNode = history[i];
|
15525 | var historyRev = historyNode.pos + '-' + historyNode.id;
|
15526 |
|
15527 | if (historyRev === rev) {
|
15528 |
|
15529 | return pos + '-' + id;
|
15530 | }
|
15531 | }
|
15532 | }
|
15533 |
|
15534 | for (var j = 0, l = branches.length; j < l; j++) {
|
15535 | toVisit.push({pos: pos + 1, ids: branches[j], history: history});
|
15536 | }
|
15537 | }
|
15538 |
|
15539 |
|
15540 | throw new Error('Unable to resolve latest revision for id ' + metadata.id + ', rev ' + rev);
|
15541 | }
|
15542 |
|
15543 | function updateDoc(revLimit, prev, docInfo, results,
|
15544 | i, cb, writeDoc, newEdits) {
|
15545 |
|
15546 | if (revExists(prev.rev_tree, docInfo.metadata.rev) && !newEdits) {
|
15547 | results[i] = docInfo;
|
15548 | return cb();
|
15549 | }
|
15550 |
|
15551 |
|
15552 | var previousWinningRev = prev.winningRev || winningRev(prev);
|
15553 | var previouslyDeleted = 'deleted' in prev ? prev.deleted :
|
15554 | isDeleted(prev, previousWinningRev);
|
15555 | var deleted = 'deleted' in docInfo.metadata ? docInfo.metadata.deleted :
|
15556 | isDeleted(docInfo.metadata);
|
15557 | var isRoot = /^1-/.test(docInfo.metadata.rev);
|
15558 |
|
15559 | if (previouslyDeleted && !deleted && newEdits && isRoot) {
|
15560 | var newDoc = docInfo.data;
|
15561 | newDoc._rev = previousWinningRev;
|
15562 | newDoc._id = docInfo.metadata.id;
|
15563 | docInfo = parseDoc(newDoc, newEdits);
|
15564 | }
|
15565 |
|
15566 | var merged = merge(prev.rev_tree, docInfo.metadata.rev_tree[0], revLimit);
|
15567 |
|
15568 | var inConflict = newEdits && ((
|
15569 | (previouslyDeleted && deleted && merged.conflicts !== 'new_leaf') ||
|
15570 | (!previouslyDeleted && merged.conflicts !== 'new_leaf') ||
|
15571 | (previouslyDeleted && !deleted && merged.conflicts === 'new_branch')));
|
15572 |
|
15573 | if (inConflict) {
|
15574 | var err = createError(REV_CONFLICT);
|
15575 | results[i] = err;
|
15576 | return cb();
|
15577 | }
|
15578 |
|
15579 | var newRev = docInfo.metadata.rev;
|
15580 | docInfo.metadata.rev_tree = merged.tree;
|
15581 | docInfo.stemmedRevs = merged.stemmedRevs || [];
|
15582 |
|
15583 | if (prev.rev_map) {
|
15584 | docInfo.metadata.rev_map = prev.rev_map;
|
15585 | }
|
15586 |
|
15587 |
|
15588 | var winningRev$$1 = winningRev(docInfo.metadata);
|
15589 | var winningRevIsDeleted = isDeleted(docInfo.metadata, winningRev$$1);
|
15590 |
|
15591 |
|
15592 |
|
15593 | var delta = (previouslyDeleted === winningRevIsDeleted) ? 0 :
|
15594 | previouslyDeleted < winningRevIsDeleted ? -1 : 1;
|
15595 |
|
15596 | var newRevIsDeleted;
|
15597 | if (newRev === winningRev$$1) {
|
15598 |
|
15599 | newRevIsDeleted = winningRevIsDeleted;
|
15600 | } else {
|
15601 |
|
15602 | newRevIsDeleted = isDeleted(docInfo.metadata, newRev);
|
15603 | }
|
15604 |
|
15605 | writeDoc(docInfo, winningRev$$1, winningRevIsDeleted, newRevIsDeleted,
|
15606 | true, delta, i, cb);
|
15607 | }
|
15608 |
|
15609 | function rootIsMissing(docInfo) {
|
15610 | return docInfo.metadata.rev_tree[0].ids[1].status === 'missing';
|
15611 | }
|
15612 |
|
15613 | function processDocs(revLimit, docInfos, api, fetchedDocs, tx, results,
|
15614 | writeDoc, opts, overallCallback) {
|
15615 |
|
15616 |
|
15617 | revLimit = revLimit || 1000;
|
15618 |
|
15619 | function insertDoc(docInfo, resultsIdx, callback) {
|
15620 |
|
15621 | var winningRev$$1 = winningRev(docInfo.metadata);
|
15622 | var deleted = isDeleted(docInfo.metadata, winningRev$$1);
|
15623 | if ('was_delete' in opts && deleted) {
|
15624 | results[resultsIdx] = createError(MISSING_DOC, 'deleted');
|
15625 | return callback();
|
15626 | }
|
15627 |
|
15628 |
|
15629 | var inConflict = newEdits && rootIsMissing(docInfo);
|
15630 |
|
15631 | if (inConflict) {
|
15632 | var err = createError(REV_CONFLICT);
|
15633 | results[resultsIdx] = err;
|
15634 | return callback();
|
15635 | }
|
15636 |
|
15637 | var delta = deleted ? 0 : 1;
|
15638 |
|
15639 | writeDoc(docInfo, winningRev$$1, deleted, deleted, false,
|
15640 | delta, resultsIdx, callback);
|
15641 | }
|
15642 |
|
15643 | var newEdits = opts.new_edits;
|
15644 | var idsToDocs = new ExportedMap();
|
15645 |
|
15646 | var docsDone = 0;
|
15647 | var docsToDo = docInfos.length;
|
15648 |
|
15649 | function checkAllDocsDone() {
|
15650 | if (++docsDone === docsToDo && overallCallback) {
|
15651 | overallCallback();
|
15652 | }
|
15653 | }
|
15654 |
|
15655 | docInfos.forEach(function (currentDoc, resultsIdx) {
|
15656 |
|
15657 | if (currentDoc._id && isLocalId(currentDoc._id)) {
|
15658 | var fun = currentDoc._deleted ? '_removeLocal' : '_putLocal';
|
15659 | api[fun](currentDoc, {ctx: tx}, function (err, res) {
|
15660 | results[resultsIdx] = err || res;
|
15661 | checkAllDocsDone();
|
15662 | });
|
15663 | return;
|
15664 | }
|
15665 |
|
15666 | var id = currentDoc.metadata.id;
|
15667 | if (idsToDocs.has(id)) {
|
15668 | docsToDo--;
|
15669 | idsToDocs.get(id).push([currentDoc, resultsIdx]);
|
15670 | } else {
|
15671 | idsToDocs.set(id, [[currentDoc, resultsIdx]]);
|
15672 | }
|
15673 | });
|
15674 |
|
15675 |
|
15676 |
|
15677 | idsToDocs.forEach(function (docs, id) {
|
15678 | var numDone = 0;
|
15679 |
|
15680 | function docWritten() {
|
15681 | if (++numDone < docs.length) {
|
15682 | nextDoc();
|
15683 | } else {
|
15684 | checkAllDocsDone();
|
15685 | }
|
15686 | }
|
15687 | function nextDoc() {
|
15688 | var value = docs[numDone];
|
15689 | var currentDoc = value[0];
|
15690 | var resultsIdx = value[1];
|
15691 |
|
15692 | if (fetchedDocs.has(id)) {
|
15693 | updateDoc(revLimit, fetchedDocs.get(id), currentDoc, results,
|
15694 | resultsIdx, docWritten, writeDoc, newEdits);
|
15695 | } else {
|
15696 |
|
15697 | var merged = merge([], currentDoc.metadata.rev_tree[0], revLimit);
|
15698 | currentDoc.metadata.rev_tree = merged.tree;
|
15699 | currentDoc.stemmedRevs = merged.stemmedRevs || [];
|
15700 | insertDoc(currentDoc, resultsIdx, docWritten);
|
15701 | }
|
15702 | }
|
15703 | nextDoc();
|
15704 | });
|
15705 | }
|
15706 |
|
15707 | function safeJsonParse(str) {
|
15708 |
|
15709 |
|
15710 |
|
15711 | try {
|
15712 | return JSON.parse(str);
|
15713 | } catch (e) {
|
15714 |
|
15715 | return vuvuzela.parse(str);
|
15716 | }
|
15717 | }
|
15718 |
|
15719 | function safeJsonStringify(json) {
|
15720 | try {
|
15721 | return JSON.stringify(json);
|
15722 | } catch (e) {
|
15723 |
|
15724 | return vuvuzela.stringify(json);
|
15725 | }
|
15726 | }
|
15727 |
|
15728 | function readAsBlobOrBuffer(storedObject, type) {
|
15729 |
|
15730 |
|
15731 |
|
15732 | var byteArray = new Uint8Array(storedObject);
|
15733 | return createBlob([byteArray], {type: type});
|
15734 | }
|
15735 |
|
15736 |
|
15737 | function prepareAttachmentForStorage(attData, cb) {
|
15738 | readAsBinaryString(attData, cb);
|
15739 | }
|
15740 |
|
15741 | function createEmptyBlobOrBuffer(type) {
|
15742 | return createBlob([''], {type: type});
|
15743 | }
|
15744 |
|
15745 | function getCacheFor(transaction, store) {
|
15746 | var prefix = store.prefix()[0];
|
15747 | var cache = transaction._cache;
|
15748 | var subCache = cache.get(prefix);
|
15749 | if (!subCache) {
|
15750 | subCache = new ExportedMap();
|
15751 | cache.set(prefix, subCache);
|
15752 | }
|
15753 | return subCache;
|
15754 | }
|
15755 |
|
15756 | function LevelTransaction() {
|
15757 | this._batch = [];
|
15758 | this._cache = new ExportedMap();
|
15759 | }
|
15760 |
|
15761 | LevelTransaction.prototype.get = function (store, key, callback) {
|
15762 | var cache = getCacheFor(this, store);
|
15763 | var exists = cache.get(key);
|
15764 | if (exists) {
|
15765 | return nextTick(function () {
|
15766 | callback(null, exists);
|
15767 | });
|
15768 | } else if (exists === null) {
|
15769 |
|
15770 | return nextTick(function () {
|
15771 | callback({name: 'NotFoundError'});
|
15772 | });
|
15773 | }
|
15774 | store.get(key, function (err, res) {
|
15775 | if (err) {
|
15776 |
|
15777 | if (err.name === 'NotFoundError') {
|
15778 | cache.set(key, null);
|
15779 | }
|
15780 | return callback(err);
|
15781 | }
|
15782 | cache.set(key, res);
|
15783 | callback(null, res);
|
15784 | });
|
15785 | };
|
15786 |
|
15787 | LevelTransaction.prototype.batch = function (batch) {
|
15788 | for (var i = 0, len = batch.length; i < len; i++) {
|
15789 | var operation = batch[i];
|
15790 |
|
15791 | var cache = getCacheFor(this, operation.prefix);
|
15792 |
|
15793 | if (operation.type === 'put') {
|
15794 | cache.set(operation.key, operation.value);
|
15795 | } else {
|
15796 | cache.set(operation.key, null);
|
15797 | }
|
15798 | }
|
15799 | this._batch = this._batch.concat(batch);
|
15800 | };
|
15801 |
|
15802 | LevelTransaction.prototype.execute = function (db, callback) {
|
15803 |
|
15804 | var keys = new ExportedSet();
|
15805 | var uniqBatches = [];
|
15806 |
|
15807 |
|
15808 | for (var i = this._batch.length - 1; i >= 0; i--) {
|
15809 | var operation = this._batch[i];
|
15810 | var lookupKey = operation.prefix.prefix()[0] + '\xff' + operation.key;
|
15811 | if (keys.has(lookupKey)) {
|
15812 | continue;
|
15813 | }
|
15814 | keys.add(lookupKey);
|
15815 | uniqBatches.push(operation);
|
15816 | }
|
15817 |
|
15818 | db.batch(uniqBatches, callback);
|
15819 | };
|
15820 |
|
15821 | var DOC_STORE = 'document-store';
|
15822 | var BY_SEQ_STORE = 'by-sequence';
|
15823 | var ATTACHMENT_STORE = 'attach-store';
|
15824 | var BINARY_STORE = 'attach-binary-store';
|
15825 | var LOCAL_STORE = 'local-store';
|
15826 | var META_STORE = 'meta-store';
|
15827 |
|
15828 |
|
15829 |
|
15830 | var dbStores = new ExportedMap();
|
15831 |
|
15832 |
|
15833 |
|
15834 | var UPDATE_SEQ_KEY = '_local_last_update_seq';
|
15835 | var DOC_COUNT_KEY = '_local_doc_count';
|
15836 | var UUID_KEY = '_local_uuid';
|
15837 |
|
15838 | var MD5_PREFIX = 'md5-';
|
15839 |
|
15840 | var safeJsonEncoding = {
|
15841 | encode: safeJsonStringify,
|
15842 | decode: safeJsonParse,
|
15843 | buffer: false,
|
15844 | type: 'cheap-json'
|
15845 | };
|
15846 |
|
15847 | var levelChanges = new Changes();
|
15848 |
|
15849 |
|
15850 |
|
15851 | function getWinningRev(metadata) {
|
15852 | return 'winningRev' in metadata ?
|
15853 | metadata.winningRev : winningRev(metadata);
|
15854 | }
|
15855 |
|
15856 | function getIsDeleted(metadata, winningRev$$1) {
|
15857 | return 'deleted' in metadata ?
|
15858 | metadata.deleted : isDeleted(metadata, winningRev$$1);
|
15859 | }
|
15860 |
|
15861 | function fetchAttachment(att, stores, opts) {
|
15862 | var type = att.content_type;
|
15863 | return new Promise(function (resolve, reject) {
|
15864 | stores.binaryStore.get(att.digest, function (err, buffer) {
|
15865 | var data;
|
15866 | if (err) {
|
15867 |
|
15868 | if (err.name !== 'NotFoundError') {
|
15869 | return reject(err);
|
15870 | } else {
|
15871 |
|
15872 | if (!opts.binary) {
|
15873 | data = '';
|
15874 | } else {
|
15875 | data = binStringToBluffer('', type);
|
15876 | }
|
15877 | }
|
15878 | } else {
|
15879 | if (opts.binary) {
|
15880 | data = readAsBlobOrBuffer(buffer, type);
|
15881 | } else {
|
15882 | data = buffer.toString('base64');
|
15883 | }
|
15884 | }
|
15885 | delete att.stub;
|
15886 | delete att.length;
|
15887 | att.data = data;
|
15888 | resolve();
|
15889 | });
|
15890 | });
|
15891 | }
|
15892 |
|
15893 | function fetchAttachments(results, stores, opts) {
|
15894 | var atts = [];
|
15895 | results.forEach(function (row) {
|
15896 | if (!(row.doc && row.doc._attachments)) {
|
15897 | return;
|
15898 | }
|
15899 | var attNames = Object.keys(row.doc._attachments);
|
15900 | attNames.forEach(function (attName) {
|
15901 | var att = row.doc._attachments[attName];
|
15902 | if (!('data' in att)) {
|
15903 | atts.push(att);
|
15904 | }
|
15905 | });
|
15906 | });
|
15907 |
|
15908 | return Promise.all(atts.map(function (att) {
|
15909 | return fetchAttachment(att, stores, opts);
|
15910 | }));
|
15911 | }
|
15912 |
|
15913 | function LevelPouch(opts, callback) {
|
15914 | opts = clone(opts);
|
15915 | var api = this;
|
15916 | var instanceId;
|
15917 | var stores = {};
|
15918 | var revLimit = opts.revs_limit;
|
15919 | var db;
|
15920 | var name = opts.name;
|
15921 |
|
15922 |
|
15923 | if (typeof opts.createIfMissing === 'undefined') {
|
15924 | opts.createIfMissing = true;
|
15925 | }
|
15926 |
|
15927 | var leveldown = opts.db;
|
15928 |
|
15929 | var dbStore;
|
15930 | var leveldownName = functionName(leveldown);
|
15931 | if (dbStores.has(leveldownName)) {
|
15932 | dbStore = dbStores.get(leveldownName);
|
15933 | } else {
|
15934 | dbStore = new ExportedMap();
|
15935 | dbStores.set(leveldownName, dbStore);
|
15936 | }
|
15937 | if (dbStore.has(name)) {
|
15938 | db = dbStore.get(name);
|
15939 | afterDBCreated();
|
15940 | } else {
|
15941 | dbStore.set(name, sublevelPouch(levelup(leveldown(name), opts, function (err) {
|
15942 |
|
15943 | if (err) {
|
15944 | dbStore["delete"](name);
|
15945 | return callback(err);
|
15946 | }
|
15947 | db = dbStore.get(name);
|
15948 | db._docCount = -1;
|
15949 | db._queue = new Deque();
|
15950 |
|
15951 | if (typeof opts.migrate === 'object') {
|
15952 | opts.migrate.doMigrationOne(name, db, afterDBCreated);
|
15953 | } else {
|
15954 | afterDBCreated();
|
15955 | }
|
15956 | })));
|
15957 | }
|
15958 |
|
15959 | function afterDBCreated() {
|
15960 | stores.docStore = db.sublevel(DOC_STORE, {valueEncoding: safeJsonEncoding});
|
15961 | stores.bySeqStore = db.sublevel(BY_SEQ_STORE, {valueEncoding: 'json'});
|
15962 | stores.attachmentStore =
|
15963 | db.sublevel(ATTACHMENT_STORE, {valueEncoding: 'json'});
|
15964 | stores.binaryStore = db.sublevel(BINARY_STORE, {valueEncoding: 'binary'});
|
15965 | stores.localStore = db.sublevel(LOCAL_STORE, {valueEncoding: 'json'});
|
15966 | stores.metaStore = db.sublevel(META_STORE, {valueEncoding: 'json'});
|
15967 |
|
15968 | if (typeof opts.migrate === 'object') {
|
15969 | opts.migrate.doMigrationTwo(db, stores, afterLastMigration);
|
15970 | } else {
|
15971 | afterLastMigration();
|
15972 | }
|
15973 | }
|
15974 |
|
15975 | function afterLastMigration() {
|
15976 | stores.metaStore.get(UPDATE_SEQ_KEY, function (err, value) {
|
15977 | if (typeof db._updateSeq === 'undefined') {
|
15978 | db._updateSeq = value || 0;
|
15979 | }
|
15980 | stores.metaStore.get(DOC_COUNT_KEY, function (err, value) {
|
15981 | db._docCount = !err ? value : 0;
|
15982 | stores.metaStore.get(UUID_KEY, function (err, value) {
|
15983 | instanceId = !err ? value : uuid();
|
15984 | stores.metaStore.put(UUID_KEY, instanceId, function () {
|
15985 | nextTick(function () {
|
15986 | callback(null, api);
|
15987 | });
|
15988 | });
|
15989 | });
|
15990 | });
|
15991 | });
|
15992 | }
|
15993 |
|
15994 | function countDocs(callback) {
|
15995 |
|
15996 | if (db.isClosed()) {
|
15997 | return callback(new Error('database is closed'));
|
15998 | }
|
15999 | return callback(null, db._docCount);
|
16000 | }
|
16001 |
|
16002 | api._remote = false;
|
16003 |
|
16004 | api.type = function () {
|
16005 | return 'leveldb';
|
16006 | };
|
16007 |
|
16008 | api._id = function (callback) {
|
16009 | callback(null, instanceId);
|
16010 | };
|
16011 |
|
16012 | api._info = function (callback) {
|
16013 | var res = {
|
16014 | doc_count: db._docCount,
|
16015 | update_seq: db._updateSeq,
|
16016 | backend_adapter: functionName(leveldown)
|
16017 | };
|
16018 | return nextTick(function () {
|
16019 | callback(null, res);
|
16020 | });
|
16021 | };
|
16022 |
|
16023 | function tryCode(fun, args) {
|
16024 | try {
|
16025 | fun.apply(null, args);
|
16026 | } catch (err) {
|
16027 | args[args.length - 1](err);
|
16028 | }
|
16029 | }
|
16030 |
|
16031 | function executeNext() {
|
16032 | var firstTask = db._queue.peekFront();
|
16033 |
|
16034 | if (firstTask.type === 'read') {
|
16035 | runReadOperation(firstTask);
|
16036 | } else {
|
16037 | runWriteOperation(firstTask);
|
16038 | }
|
16039 | }
|
16040 |
|
16041 | function runReadOperation(firstTask) {
|
16042 |
|
16043 |
|
16044 | var readTasks = [firstTask];
|
16045 | var i = 1;
|
16046 | var nextTask = db._queue.get(i);
|
16047 | while (typeof nextTask !== 'undefined' && nextTask.type === 'read') {
|
16048 | readTasks.push(nextTask);
|
16049 | i++;
|
16050 | nextTask = db._queue.get(i);
|
16051 | }
|
16052 |
|
16053 | var numDone = 0;
|
16054 |
|
16055 | readTasks.forEach(function (readTask) {
|
16056 | var args = readTask.args;
|
16057 | var callback = args[args.length - 1];
|
16058 | args[args.length - 1] = getArguments(function (cbArgs) {
|
16059 | callback.apply(null, cbArgs);
|
16060 | if (++numDone === readTasks.length) {
|
16061 | nextTick(function () {
|
16062 |
|
16063 | readTasks.forEach(function () {
|
16064 | db._queue.shift();
|
16065 | });
|
16066 | if (db._queue.length) {
|
16067 | executeNext();
|
16068 | }
|
16069 | });
|
16070 | }
|
16071 | });
|
16072 | tryCode(readTask.fun, args);
|
16073 | });
|
16074 | }
|
16075 |
|
16076 | function runWriteOperation(firstTask) {
|
16077 | var args = firstTask.args;
|
16078 | var callback = args[args.length - 1];
|
16079 | args[args.length - 1] = getArguments(function (cbArgs) {
|
16080 | callback.apply(null, cbArgs);
|
16081 | nextTick(function () {
|
16082 | db._queue.shift();
|
16083 | if (db._queue.length) {
|
16084 | executeNext();
|
16085 | }
|
16086 | });
|
16087 | });
|
16088 | tryCode(firstTask.fun, args);
|
16089 | }
|
16090 |
|
16091 |
|
16092 |
|
16093 |
|
16094 |
|
16095 | function writeLock(fun) {
|
16096 | return getArguments(function (args) {
|
16097 | db._queue.push({
|
16098 | fun: fun,
|
16099 | args: args,
|
16100 | type: 'write'
|
16101 | });
|
16102 |
|
16103 | if (db._queue.length === 1) {
|
16104 | nextTick(executeNext);
|
16105 | }
|
16106 | });
|
16107 | }
|
16108 |
|
16109 |
|
16110 | function readLock(fun) {
|
16111 | return getArguments(function (args) {
|
16112 | db._queue.push({
|
16113 | fun: fun,
|
16114 | args: args,
|
16115 | type: 'read'
|
16116 | });
|
16117 |
|
16118 | if (db._queue.length === 1) {
|
16119 | nextTick(executeNext);
|
16120 | }
|
16121 | });
|
16122 | }
|
16123 |
|
16124 | function formatSeq(n) {
|
16125 | return ('0000000000000000' + n).slice(-16);
|
16126 | }
|
16127 |
|
16128 | function parseSeq(s) {
|
16129 | return parseInt(s, 10);
|
16130 | }
|
16131 |
|
16132 | api._get = readLock(function (id, opts, callback) {
|
16133 | opts = clone(opts);
|
16134 |
|
16135 | stores.docStore.get(id, function (err, metadata) {
|
16136 |
|
16137 | if (err || !metadata) {
|
16138 | return callback(createError(MISSING_DOC, 'missing'));
|
16139 | }
|
16140 |
|
16141 | var rev;
|
16142 | if (!opts.rev) {
|
16143 | rev = getWinningRev(metadata);
|
16144 | var deleted = getIsDeleted(metadata, rev);
|
16145 | if (deleted) {
|
16146 | return callback(createError(MISSING_DOC, "deleted"));
|
16147 | }
|
16148 | } else {
|
16149 | rev = opts.latest ? latest(opts.rev, metadata) : opts.rev;
|
16150 | }
|
16151 |
|
16152 | var seq = metadata.rev_map[rev];
|
16153 |
|
16154 | stores.bySeqStore.get(formatSeq(seq), function (err, doc) {
|
16155 | if (!doc) {
|
16156 | return callback(createError(MISSING_DOC));
|
16157 | }
|
16158 |
|
16159 | if ('_id' in doc && doc._id !== metadata.id) {
|
16160 |
|
16161 | return callback(new Error('wrong doc returned'));
|
16162 | }
|
16163 | doc._id = metadata.id;
|
16164 | if ('_rev' in doc) {
|
16165 |
|
16166 | if (doc._rev !== rev) {
|
16167 |
|
16168 | return callback(new Error('wrong doc returned'));
|
16169 | }
|
16170 | } else {
|
16171 |
|
16172 | doc._rev = rev;
|
16173 | }
|
16174 | return callback(null, {doc: doc, metadata: metadata});
|
16175 | });
|
16176 | });
|
16177 | });
|
16178 |
|
16179 |
|
16180 |
|
16181 | api._getAttachment = function (docId, attachId, attachment, opts, callback) {
|
16182 | var digest = attachment.digest;
|
16183 | var type = attachment.content_type;
|
16184 |
|
16185 | stores.binaryStore.get(digest, function (err, attach) {
|
16186 | if (err) {
|
16187 |
|
16188 | if (err.name !== 'NotFoundError') {
|
16189 | return callback(err);
|
16190 | }
|
16191 |
|
16192 | return callback(null, opts.binary ? createEmptyBlobOrBuffer(type) : '');
|
16193 | }
|
16194 |
|
16195 | if (opts.binary) {
|
16196 | callback(null, readAsBlobOrBuffer(attach, type));
|
16197 | } else {
|
16198 | callback(null, attach.toString('base64'));
|
16199 | }
|
16200 | });
|
16201 | };
|
16202 |
|
16203 | api._bulkDocs = writeLock(function (req, opts, callback) {
|
16204 | var newEdits = opts.new_edits;
|
16205 | var results = new Array(req.docs.length);
|
16206 | var fetchedDocs = new ExportedMap();
|
16207 | var stemmedRevs = new ExportedMap();
|
16208 |
|
16209 | var txn = new LevelTransaction();
|
16210 | var docCountDelta = 0;
|
16211 | var newUpdateSeq = db._updateSeq;
|
16212 |
|
16213 |
|
16214 | var userDocs = req.docs;
|
16215 | var docInfos = userDocs.map(function (doc) {
|
16216 | if (doc._id && isLocalId(doc._id)) {
|
16217 | return doc;
|
16218 | }
|
16219 | var newDoc = parseDoc(doc, newEdits, api.__opts);
|
16220 |
|
16221 | if (newDoc.metadata && !newDoc.metadata.rev_map) {
|
16222 | newDoc.metadata.rev_map = {};
|
16223 | }
|
16224 |
|
16225 | return newDoc;
|
16226 | });
|
16227 | var infoErrors = docInfos.filter(function (doc) {
|
16228 | return doc.error;
|
16229 | });
|
16230 |
|
16231 | if (infoErrors.length) {
|
16232 | return callback(infoErrors[0]);
|
16233 | }
|
16234 |
|
16235 |
|
16236 |
|
16237 | function verifyAttachment(digest, callback) {
|
16238 | txn.get(stores.attachmentStore, digest, function (levelErr) {
|
16239 | if (levelErr) {
|
16240 | var err = createError(MISSING_STUB,
|
16241 | 'unknown stub attachment with digest ' +
|
16242 | digest);
|
16243 | callback(err);
|
16244 | } else {
|
16245 | callback();
|
16246 | }
|
16247 | });
|
16248 | }
|
16249 |
|
16250 | function verifyAttachments(finish) {
|
16251 | var digests = [];
|
16252 | userDocs.forEach(function (doc) {
|
16253 | if (doc && doc._attachments) {
|
16254 | Object.keys(doc._attachments).forEach(function (filename) {
|
16255 | var att = doc._attachments[filename];
|
16256 | if (att.stub) {
|
16257 | digests.push(att.digest);
|
16258 | }
|
16259 | });
|
16260 | }
|
16261 | });
|
16262 | if (!digests.length) {
|
16263 | return finish();
|
16264 | }
|
16265 | var numDone = 0;
|
16266 | var err;
|
16267 |
|
16268 | digests.forEach(function (digest) {
|
16269 | verifyAttachment(digest, function (attErr) {
|
16270 | if (attErr && !err) {
|
16271 | err = attErr;
|
16272 | }
|
16273 |
|
16274 | if (++numDone === digests.length) {
|
16275 | finish(err);
|
16276 | }
|
16277 | });
|
16278 | });
|
16279 | }
|
16280 |
|
16281 | function fetchExistingDocs(finish) {
|
16282 | var numDone = 0;
|
16283 | var overallErr;
|
16284 | function checkDone() {
|
16285 | if (++numDone === userDocs.length) {
|
16286 | return finish(overallErr);
|
16287 | }
|
16288 | }
|
16289 |
|
16290 | userDocs.forEach(function (doc) {
|
16291 | if (doc._id && isLocalId(doc._id)) {
|
16292 |
|
16293 | return checkDone();
|
16294 | }
|
16295 | txn.get(stores.docStore, doc._id, function (err, info) {
|
16296 | if (err) {
|
16297 |
|
16298 | if (err.name !== 'NotFoundError') {
|
16299 | overallErr = err;
|
16300 | }
|
16301 | } else {
|
16302 | fetchedDocs.set(doc._id, info);
|
16303 | }
|
16304 | checkDone();
|
16305 | });
|
16306 | });
|
16307 | }
|
16308 |
|
16309 | function compact(revsMap, callback) {
|
16310 | var promise = Promise.resolve();
|
16311 | revsMap.forEach(function (revs, docId) {
|
16312 |
|
16313 |
|
16314 | promise = promise.then(function () {
|
16315 | return new Promise(function (resolve, reject) {
|
16316 | api._doCompactionNoLock(docId, revs, {ctx: txn}, function (err) {
|
16317 |
|
16318 | if (err) {
|
16319 | return reject(err);
|
16320 | }
|
16321 | resolve();
|
16322 | });
|
16323 | });
|
16324 | });
|
16325 | });
|
16326 |
|
16327 | promise.then(function () {
|
16328 | callback();
|
16329 | }, callback);
|
16330 | }
|
16331 |
|
16332 | function autoCompact(callback) {
|
16333 | var revsMap = new ExportedMap();
|
16334 | fetchedDocs.forEach(function (metadata, docId) {
|
16335 | revsMap.set(docId, compactTree(metadata));
|
16336 | });
|
16337 | compact(revsMap, callback);
|
16338 | }
|
16339 |
|
16340 | function finish() {
|
16341 | compact(stemmedRevs, function (error) {
|
16342 |
|
16343 | if (error) {
|
16344 | complete(error);
|
16345 | }
|
16346 | if (api.auto_compaction) {
|
16347 | return autoCompact(complete);
|
16348 | }
|
16349 | complete();
|
16350 | });
|
16351 | }
|
16352 |
|
16353 | function writeDoc(docInfo, winningRev$$1, winningRevIsDeleted, newRevIsDeleted,
|
16354 | isUpdate, delta, resultsIdx, callback2) {
|
16355 | docCountDelta += delta;
|
16356 |
|
16357 | var err = null;
|
16358 | var recv = 0;
|
16359 |
|
16360 | docInfo.metadata.winningRev = winningRev$$1;
|
16361 | docInfo.metadata.deleted = winningRevIsDeleted;
|
16362 |
|
16363 | docInfo.data._id = docInfo.metadata.id;
|
16364 | docInfo.data._rev = docInfo.metadata.rev;
|
16365 |
|
16366 | if (newRevIsDeleted) {
|
16367 | docInfo.data._deleted = true;
|
16368 | }
|
16369 |
|
16370 | if (docInfo.stemmedRevs.length) {
|
16371 | stemmedRevs.set(docInfo.metadata.id, docInfo.stemmedRevs);
|
16372 | }
|
16373 |
|
16374 | var attachments = docInfo.data._attachments ?
|
16375 | Object.keys(docInfo.data._attachments) :
|
16376 | [];
|
16377 |
|
16378 | function attachmentSaved(attachmentErr) {
|
16379 | recv++;
|
16380 | if (!err) {
|
16381 |
|
16382 | if (attachmentErr) {
|
16383 | err = attachmentErr;
|
16384 | callback2(err);
|
16385 | } else if (recv === attachments.length) {
|
16386 | finish();
|
16387 | }
|
16388 | }
|
16389 | }
|
16390 |
|
16391 | function onMD5Load(doc, key, data, attachmentSaved) {
|
16392 | return function (result) {
|
16393 | saveAttachment(doc, MD5_PREFIX + result, key, data, attachmentSaved);
|
16394 | };
|
16395 | }
|
16396 |
|
16397 | function doMD5(doc, key, attachmentSaved) {
|
16398 | return function (data) {
|
16399 | binaryMd5(data, onMD5Load(doc, key, data, attachmentSaved));
|
16400 | };
|
16401 | }
|
16402 |
|
16403 | for (var i = 0; i < attachments.length; i++) {
|
16404 | var key = attachments[i];
|
16405 | var att = docInfo.data._attachments[key];
|
16406 |
|
16407 | if (att.stub) {
|
16408 |
|
16409 | var id = docInfo.data._id;
|
16410 | var rev = docInfo.data._rev;
|
16411 | saveAttachmentRefs(id, rev, att.digest, attachmentSaved);
|
16412 | continue;
|
16413 | }
|
16414 | var data;
|
16415 | if (typeof att.data === 'string') {
|
16416 |
|
16417 | try {
|
16418 | data = thisAtob(att.data);
|
16419 | } catch (e) {
|
16420 | callback(createError(BAD_ARG,
|
16421 | 'Attachment is not a valid base64 string'));
|
16422 | return;
|
16423 | }
|
16424 | doMD5(docInfo, key, attachmentSaved)(data);
|
16425 | } else {
|
16426 | prepareAttachmentForStorage(att.data,
|
16427 | doMD5(docInfo, key, attachmentSaved));
|
16428 | }
|
16429 | }
|
16430 |
|
16431 | function finish() {
|
16432 | var seq = docInfo.metadata.rev_map[docInfo.metadata.rev];
|
16433 |
|
16434 | if (seq) {
|
16435 |
|
16436 |
|
16437 | return callback2();
|
16438 | }
|
16439 | seq = ++newUpdateSeq;
|
16440 | docInfo.metadata.rev_map[docInfo.metadata.rev] =
|
16441 | docInfo.metadata.seq = seq;
|
16442 | var seqKey = formatSeq(seq);
|
16443 | var batch = [{
|
16444 | key: seqKey,
|
16445 | value: docInfo.data,
|
16446 | prefix: stores.bySeqStore,
|
16447 | type: 'put'
|
16448 | }, {
|
16449 | key: docInfo.metadata.id,
|
16450 | value: docInfo.metadata,
|
16451 | prefix: stores.docStore,
|
16452 | type: 'put'
|
16453 | }];
|
16454 | txn.batch(batch);
|
16455 | results[resultsIdx] = {
|
16456 | ok: true,
|
16457 | id: docInfo.metadata.id,
|
16458 | rev: docInfo.metadata.rev
|
16459 | };
|
16460 | fetchedDocs.set(docInfo.metadata.id, docInfo.metadata);
|
16461 | callback2();
|
16462 | }
|
16463 |
|
16464 | if (!attachments.length) {
|
16465 | finish();
|
16466 | }
|
16467 | }
|
16468 |
|
16469 |
|
16470 |
|
16471 | var attachmentQueues = {};
|
16472 |
|
16473 | function saveAttachmentRefs(id, rev, digest, callback) {
|
16474 |
|
16475 | function fetchAtt() {
|
16476 | return new Promise(function (resolve, reject) {
|
16477 | txn.get(stores.attachmentStore, digest, function (err, oldAtt) {
|
16478 |
|
16479 | if (err && err.name !== 'NotFoundError') {
|
16480 | return reject(err);
|
16481 | }
|
16482 | resolve(oldAtt);
|
16483 | });
|
16484 | });
|
16485 | }
|
16486 |
|
16487 | function saveAtt(oldAtt) {
|
16488 | var ref = [id, rev].join('@');
|
16489 | var newAtt = {};
|
16490 |
|
16491 | if (oldAtt) {
|
16492 | if (oldAtt.refs) {
|
16493 |
|
16494 |
|
16495 |
|
16496 | newAtt.refs = oldAtt.refs;
|
16497 | newAtt.refs[ref] = true;
|
16498 | }
|
16499 | } else {
|
16500 | newAtt.refs = {};
|
16501 | newAtt.refs[ref] = true;
|
16502 | }
|
16503 |
|
16504 | return new Promise(function (resolve) {
|
16505 | txn.batch([{
|
16506 | type: 'put',
|
16507 | prefix: stores.attachmentStore,
|
16508 | key: digest,
|
16509 | value: newAtt
|
16510 | }]);
|
16511 | resolve(!oldAtt);
|
16512 | });
|
16513 | }
|
16514 |
|
16515 |
|
16516 |
|
16517 | var queue = attachmentQueues[digest] || Promise.resolve();
|
16518 | attachmentQueues[digest] = queue.then(function () {
|
16519 | return fetchAtt().then(saveAtt).then(function (isNewAttachment) {
|
16520 | callback(null, isNewAttachment);
|
16521 | }, callback);
|
16522 | });
|
16523 | }
|
16524 |
|
16525 | function saveAttachment(docInfo, digest, key, data, callback) {
|
16526 | var att = docInfo.data._attachments[key];
|
16527 | delete att.data;
|
16528 | att.digest = digest;
|
16529 | att.length = data.length;
|
16530 | var id = docInfo.metadata.id;
|
16531 | var rev = docInfo.metadata.rev;
|
16532 | att.revpos = parseInt(rev, 10);
|
16533 |
|
16534 | saveAttachmentRefs(id, rev, digest, function (err, isNewAttachment) {
|
16535 |
|
16536 | if (err) {
|
16537 | return callback(err);
|
16538 | }
|
16539 |
|
16540 | if (data.length === 0) {
|
16541 | return callback(err);
|
16542 | }
|
16543 | if (!isNewAttachment) {
|
16544 |
|
16545 | return callback(err);
|
16546 | }
|
16547 | txn.batch([{
|
16548 | type: 'put',
|
16549 | prefix: stores.binaryStore,
|
16550 | key: digest,
|
16551 | value: bufferFrom(data, 'binary')
|
16552 | }]);
|
16553 | callback();
|
16554 | });
|
16555 | }
|
16556 |
|
16557 | function complete(err) {
|
16558 |
|
16559 | if (err) {
|
16560 | return nextTick(function () {
|
16561 | callback(err);
|
16562 | });
|
16563 | }
|
16564 | txn.batch([
|
16565 | {
|
16566 | prefix: stores.metaStore,
|
16567 | type: 'put',
|
16568 | key: UPDATE_SEQ_KEY,
|
16569 | value: newUpdateSeq
|
16570 | },
|
16571 | {
|
16572 | prefix: stores.metaStore,
|
16573 | type: 'put',
|
16574 | key: DOC_COUNT_KEY,
|
16575 | value: db._docCount + docCountDelta
|
16576 | }
|
16577 | ]);
|
16578 | txn.execute(db, function (err) {
|
16579 |
|
16580 | if (err) {
|
16581 | return callback(err);
|
16582 | }
|
16583 | db._docCount += docCountDelta;
|
16584 | db._updateSeq = newUpdateSeq;
|
16585 | levelChanges.notify(name);
|
16586 | nextTick(function () {
|
16587 | callback(null, results);
|
16588 | });
|
16589 | });
|
16590 | }
|
16591 |
|
16592 | if (!docInfos.length) {
|
16593 | return callback(null, []);
|
16594 | }
|
16595 |
|
16596 | verifyAttachments(function (err) {
|
16597 | if (err) {
|
16598 | return callback(err);
|
16599 | }
|
16600 | fetchExistingDocs(function (err) {
|
16601 |
|
16602 | if (err) {
|
16603 | return callback(err);
|
16604 | }
|
16605 | processDocs(revLimit, docInfos, api, fetchedDocs, txn, results,
|
16606 | writeDoc, opts, finish);
|
16607 | });
|
16608 | });
|
16609 | });
|
16610 | api._allDocs = function (opts, callback) {
|
16611 | if ('keys' in opts) {
|
16612 | return allDocsKeysQuery(this, opts);
|
16613 | }
|
16614 | return readLock(function (opts, callback) {
|
16615 | opts = clone(opts);
|
16616 | countDocs(function (err, docCount) {
|
16617 |
|
16618 | if (err) {
|
16619 | return callback(err);
|
16620 | }
|
16621 | var readstreamOpts = {};
|
16622 | var skip = opts.skip || 0;
|
16623 | if (opts.startkey) {
|
16624 | readstreamOpts.gte = opts.startkey;
|
16625 | }
|
16626 | if (opts.endkey) {
|
16627 | readstreamOpts.lte = opts.endkey;
|
16628 | }
|
16629 | if (opts.key) {
|
16630 | readstreamOpts.gte = readstreamOpts.lte = opts.key;
|
16631 | }
|
16632 | if (opts.descending) {
|
16633 | readstreamOpts.reverse = true;
|
16634 |
|
16635 | var tmp = readstreamOpts.lte;
|
16636 | readstreamOpts.lte = readstreamOpts.gte;
|
16637 | readstreamOpts.gte = tmp;
|
16638 | }
|
16639 | var limit;
|
16640 | if (typeof opts.limit === 'number') {
|
16641 | limit = opts.limit;
|
16642 | }
|
16643 | if (limit === 0 ||
|
16644 | ('gte' in readstreamOpts && 'lte' in readstreamOpts &&
|
16645 | readstreamOpts.gte > readstreamOpts.lte)) {
|
16646 |
|
16647 |
|
16648 |
|
16649 | var returnVal = {
|
16650 | total_rows: docCount,
|
16651 | offset: opts.skip,
|
16652 | rows: []
|
16653 | };
|
16654 |
|
16655 | if (opts.update_seq) {
|
16656 | returnVal.update_seq = db._updateSeq;
|
16657 | }
|
16658 | return callback(null, returnVal);
|
16659 | }
|
16660 | var results = [];
|
16661 | var docstream = stores.docStore.readStream(readstreamOpts);
|
16662 |
|
16663 | var throughStream = through2.obj(function (entry, _, next) {
|
16664 | var metadata = entry.value;
|
16665 |
|
16666 |
|
16667 | var winningRev$$1 = getWinningRev(metadata);
|
16668 | var deleted = getIsDeleted(metadata, winningRev$$1);
|
16669 | if (!deleted) {
|
16670 | if (skip-- > 0) {
|
16671 | next();
|
16672 | return;
|
16673 | } else if (typeof limit === 'number' && limit-- <= 0) {
|
16674 | docstream.unpipe();
|
16675 | docstream.destroy();
|
16676 | next();
|
16677 | return;
|
16678 | }
|
16679 | } else if (opts.deleted !== 'ok') {
|
16680 | next();
|
16681 | return;
|
16682 | }
|
16683 | function allDocsInner(data) {
|
16684 | var doc = {
|
16685 | id: metadata.id,
|
16686 | key: metadata.id,
|
16687 | value: {
|
16688 | rev: winningRev$$1
|
16689 | }
|
16690 | };
|
16691 | if (opts.include_docs) {
|
16692 | doc.doc = data;
|
16693 | doc.doc._rev = doc.value.rev;
|
16694 | if (opts.conflicts) {
|
16695 | var conflicts = collectConflicts(metadata);
|
16696 | if (conflicts.length) {
|
16697 | doc.doc._conflicts = conflicts;
|
16698 | }
|
16699 | }
|
16700 | for (var att in doc.doc._attachments) {
|
16701 | if (doc.doc._attachments.hasOwnProperty(att)) {
|
16702 | doc.doc._attachments[att].stub = true;
|
16703 | }
|
16704 | }
|
16705 | }
|
16706 | if (opts.inclusive_end === false && metadata.id === opts.endkey) {
|
16707 | return next();
|
16708 | } else if (deleted) {
|
16709 | if (opts.deleted === 'ok') {
|
16710 | doc.value.deleted = true;
|
16711 | doc.doc = null;
|
16712 | } else {
|
16713 | /* istanbul ignore next */
|
16714 | return next();
|
16715 | }
|
16716 | }
|
16717 | results.push(doc);
|
16718 | next();
|
16719 | }
|
16720 | if (opts.include_docs) {
|
16721 | var seq = metadata.rev_map[winningRev$$1];
|
16722 | stores.bySeqStore.get(formatSeq(seq), function (err, data) {
|
16723 | allDocsInner(data);
|
16724 | });
|
16725 | }
|
16726 | else {
|
16727 | allDocsInner();
|
16728 | }
|
16729 | }, function (next) {
|
16730 | Promise.resolve().then(function () {
|
16731 | if (opts.include_docs && opts.attachments) {
|
16732 | return fetchAttachments(results, stores, opts);
|
16733 | }
|
16734 | }).then(function () {
|
16735 | var returnVal = {
|
16736 | total_rows: docCount,
|
16737 | offset: opts.skip,
|
16738 | rows: results
|
16739 | };
|
16740 |
|
16741 | /* istanbul ignore if */
|
16742 | if (opts.update_seq) {
|
16743 | returnVal.update_seq = db._updateSeq;
|
16744 | }
|
16745 | callback(null, returnVal);
|
16746 | }, callback);
|
16747 | next();
|
16748 | }).on('unpipe', function () {
|
16749 | throughStream.end();
|
16750 | });
|
16751 |
|
16752 | docstream.on('error', callback);
|
16753 |
|
16754 | docstream.pipe(throughStream);
|
16755 | });
|
16756 | })(opts, callback);
|
16757 | };
|
16758 |
|
16759 | api._changes = function (opts) {
|
16760 | opts = clone(opts);
|
16761 |
|
16762 | if (opts.continuous) {
|
16763 | var id = name + ':' + uuid();
|
16764 | levelChanges.addListener(name, id, api, opts);
|
16765 | levelChanges.notify(name);
|
16766 | return {
|
16767 | cancel: function () {
|
16768 | levelChanges.removeListener(name, id);
|
16769 | }
|
16770 | };
|
16771 | }
|
16772 |
|
16773 | var descending = opts.descending;
|
16774 | var results = [];
|
16775 | var lastSeq = opts.since || 0;
|
16776 | var called = 0;
|
16777 | var streamOpts = {
|
16778 | reverse: descending
|
16779 | };
|
16780 | var limit;
|
16781 | if ('limit' in opts && opts.limit > 0) {
|
16782 | limit = opts.limit;
|
16783 | }
|
16784 | if (!streamOpts.reverse) {
|
16785 | streamOpts.start = formatSeq(opts.since || 0);
|
16786 | }
|
16787 |
|
16788 | var docIds = opts.doc_ids && new ExportedSet(opts.doc_ids);
|
16789 | var filter = filterChange(opts);
|
16790 | var docIdsToMetadata = new ExportedMap();
|
16791 |
|
16792 | function complete() {
|
16793 | opts.done = true;
|
16794 | if (opts.return_docs && opts.limit) {
|
16795 | /* istanbul ignore if */
|
16796 | if (opts.limit < results.length) {
|
16797 | results.length = opts.limit;
|
16798 | }
|
16799 | }
|
16800 | changeStream.unpipe(throughStream);
|
16801 | changeStream.destroy();
|
16802 | if (!opts.continuous && !opts.cancelled) {
|
16803 | if (opts.include_docs && opts.attachments && opts.return_docs) {
|
16804 | fetchAttachments(results, stores, opts).then(function () {
|
16805 | opts.complete(null, {results: results, last_seq: lastSeq});
|
16806 | });
|
16807 | } else {
|
16808 | opts.complete(null, {results: results, last_seq: lastSeq});
|
16809 | }
|
16810 | }
|
16811 | }
|
16812 | var changeStream = stores.bySeqStore.readStream(streamOpts);
|
16813 | var throughStream = through2.obj(function (data, _, next) {
|
16814 | if (limit && called >= limit) {
|
16815 | complete();
|
16816 | return next();
|
16817 | }
|
16818 | if (opts.cancelled || opts.done) {
|
16819 | return next();
|
16820 | }
|
16821 |
|
16822 | var seq = parseSeq(data.key);
|
16823 | var doc = data.value;
|
16824 |
|
16825 | if (seq === opts.since && !descending) {
|
16826 | // couchdb ignores `since` if descending=true
|
16827 | return next();
|
16828 | }
|
16829 |
|
16830 | if (docIds && !docIds.has(doc._id)) {
|
16831 | return next();
|
16832 | }
|
16833 |
|
16834 | var metadata;
|
16835 |
|
16836 | function onGetMetadata(metadata) {
|
16837 | var winningRev$$1 = getWinningRev(metadata);
|
16838 |
|
16839 | function onGetWinningDoc(winningDoc) {
|
16840 |
|
16841 | var change = opts.processChange(winningDoc, metadata, opts);
|
16842 | change.seq = metadata.seq;
|
16843 |
|
16844 | var filtered = filter(change);
|
16845 | if (typeof filtered === 'object') {
|
16846 | return opts.complete(filtered);
|
16847 | }
|
16848 |
|
16849 | if (filtered) {
|
16850 | called++;
|
16851 |
|
16852 | if (opts.attachments && opts.include_docs) {
|
16853 | // fetch attachment immediately for the benefit
|
16854 | // of live listeners
|
16855 | fetchAttachments([change], stores, opts).then(function () {
|
16856 | opts.onChange(change);
|
16857 | });
|
16858 | } else {
|
16859 | opts.onChange(change);
|
16860 | }
|
16861 |
|
16862 | if (opts.return_docs) {
|
16863 | results.push(change);
|
16864 | }
|
16865 | }
|
16866 | next();
|
16867 | }
|
16868 |
|
16869 | if (metadata.seq !== seq) {
|
16870 | // some other seq is later
|
16871 | return next();
|
16872 | }
|
16873 |
|
16874 | lastSeq = seq;
|
16875 |
|
16876 | if (winningRev$$1 === doc._rev) {
|
16877 | return onGetWinningDoc(doc);
|
16878 | }
|
16879 |
|
16880 | // fetch the winner
|
16881 |
|
16882 | var winningSeq = metadata.rev_map[winningRev$$1];
|
16883 |
|
16884 | stores.bySeqStore.get(formatSeq(winningSeq), function (err, doc) {
|
16885 | onGetWinningDoc(doc);
|
16886 | });
|
16887 | }
|
16888 |
|
16889 | metadata = docIdsToMetadata.get(doc._id);
|
16890 | if (metadata) { // cached
|
16891 | return onGetMetadata(metadata);
|
16892 | }
|
16893 | // metadata not cached, have to go fetch it
|
16894 | stores.docStore.get(doc._id, function (err, metadata) {
|
16895 | /* istanbul ignore if */
|
16896 | if (opts.cancelled || opts.done || db.isClosed() ||
|
16897 | isLocalId(metadata.id)) {
|
16898 | return next();
|
16899 | }
|
16900 | docIdsToMetadata.set(doc._id, metadata);
|
16901 | onGetMetadata(metadata);
|
16902 | });
|
16903 | }, function (next) {
|
16904 | if (opts.cancelled) {
|
16905 | return next();
|
16906 | }
|
16907 | if (opts.return_docs && opts.limit) {
|
16908 | /* istanbul ignore if */
|
16909 | if (opts.limit < results.length) {
|
16910 | results.length = opts.limit;
|
16911 | }
|
16912 | }
|
16913 |
|
16914 | next();
|
16915 | }).on('unpipe', function () {
|
16916 | throughStream.end();
|
16917 | complete();
|
16918 | });
|
16919 | changeStream.pipe(throughStream);
|
16920 | return {
|
16921 | cancel: function () {
|
16922 | opts.cancelled = true;
|
16923 | complete();
|
16924 | }
|
16925 | };
|
16926 | };
|
16927 |
|
16928 | api._close = function (callback) {
|
16929 | /* istanbul ignore if */
|
16930 | if (db.isClosed()) {
|
16931 | return callback(createError(NOT_OPEN));
|
16932 | }
|
16933 | db.close(function (err) {
|
16934 | /* istanbul ignore if */
|
16935 | if (err) {
|
16936 | callback(err);
|
16937 | } else {
|
16938 | dbStore["delete"](name);
|
16939 | callback();
|
16940 | }
|
16941 | });
|
16942 | };
|
16943 |
|
16944 | api._getRevisionTree = function (docId, callback) {
|
16945 | stores.docStore.get(docId, function (err, metadata) {
|
16946 | if (err) {
|
16947 | callback(createError(MISSING_DOC));
|
16948 | } else {
|
16949 | callback(null, metadata.rev_tree);
|
16950 | }
|
16951 | });
|
16952 | };
|
16953 |
|
16954 | api._doCompaction = writeLock(function (docId, revs, opts, callback) {
|
16955 | api._doCompactionNoLock(docId, revs, opts, callback);
|
16956 | });
|
16957 |
|
16958 | // the NoLock version is for use by bulkDocs
|
16959 | api._doCompactionNoLock = function (docId, revs, opts, callback) {
|
16960 | if (typeof opts === 'function') {
|
16961 | callback = opts;
|
16962 | opts = {};
|
16963 | }
|
16964 |
|
16965 | if (!revs.length) {
|
16966 | return callback();
|
16967 | }
|
16968 | var txn = opts.ctx || new LevelTransaction();
|
16969 |
|
16970 | txn.get(stores.docStore, docId, function (err, metadata) {
|
16971 | /* istanbul ignore if */
|
16972 | if (err) {
|
16973 | return callback(err);
|
16974 | }
|
16975 | var seqs = revs.map(function (rev) {
|
16976 | var seq = metadata.rev_map[rev];
|
16977 | delete metadata.rev_map[rev];
|
16978 | return seq;
|
16979 | });
|
16980 | traverseRevTree(metadata.rev_tree, function (isLeaf, pos,
|
16981 | revHash, ctx, opts) {
|
16982 | var rev = pos + '-' + revHash;
|
16983 | if (revs.indexOf(rev) !== -1) {
|
16984 | opts.status = 'missing';
|
16985 | }
|
16986 | });
|
16987 |
|
16988 | var batch = [];
|
16989 | batch.push({
|
16990 | key: metadata.id,
|
16991 | value: metadata,
|
16992 | type: 'put',
|
16993 | prefix: stores.docStore
|
16994 | });
|
16995 |
|
16996 | var digestMap = {};
|
16997 | var numDone = 0;
|
16998 | var overallErr;
|
16999 | function checkDone(err) {
|
17000 | /* istanbul ignore if */
|
17001 | if (err) {
|
17002 | overallErr = err;
|
17003 | }
|
17004 | if (++numDone === revs.length) { // done
|
17005 | /* istanbul ignore if */
|
17006 | if (overallErr) {
|
17007 | return callback(overallErr);
|
17008 | }
|
17009 | deleteOrphanedAttachments();
|
17010 | }
|
17011 | }
|
17012 |
|
17013 | function finish(err) {
|
17014 | /* istanbul ignore if */
|
17015 | if (err) {
|
17016 | return callback(err);
|
17017 | }
|
17018 | txn.batch(batch);
|
17019 | if (opts.ctx) {
|
17020 | // don't execute immediately
|
17021 | return callback();
|
17022 | }
|
17023 | txn.execute(db, callback);
|
17024 | }
|
17025 |
|
17026 | function deleteOrphanedAttachments() {
|
17027 | var possiblyOrphanedAttachments = Object.keys(digestMap);
|
17028 | if (!possiblyOrphanedAttachments.length) {
|
17029 | return finish();
|
17030 | }
|
17031 | var numDone = 0;
|
17032 | var overallErr;
|
17033 | function checkDone(err) {
|
17034 | /* istanbul ignore if */
|
17035 | if (err) {
|
17036 | overallErr = err;
|
17037 | }
|
17038 | if (++numDone === possiblyOrphanedAttachments.length) {
|
17039 | finish(overallErr);
|
17040 | }
|
17041 | }
|
17042 | var refsToDelete = new ExportedMap();
|
17043 | revs.forEach(function (rev) {
|
17044 | refsToDelete.set(docId + '@' + rev, true);
|
17045 | });
|
17046 | possiblyOrphanedAttachments.forEach(function (digest) {
|
17047 | txn.get(stores.attachmentStore, digest, function (err, attData) {
|
17048 | /* istanbul ignore if */
|
17049 | if (err) {
|
17050 | if (err.name === 'NotFoundError') {
|
17051 | return checkDone();
|
17052 | } else {
|
17053 | return checkDone(err);
|
17054 | }
|
17055 | }
|
17056 | var refs = Object.keys(attData.refs || {}).filter(function (ref) {
|
17057 | return !refsToDelete.has(ref);
|
17058 | });
|
17059 | var newRefs = {};
|
17060 | refs.forEach(function (ref) {
|
17061 | newRefs[ref] = true;
|
17062 | });
|
17063 | if (refs.length) { // not orphaned
|
17064 | batch.push({
|
17065 | key: digest,
|
17066 | type: 'put',
|
17067 | value: {refs: newRefs},
|
17068 | prefix: stores.attachmentStore
|
17069 | });
|
17070 | } else { // orphaned, can safely delete
|
17071 | batch = batch.concat([{
|
17072 | key: digest,
|
17073 | type: 'del',
|
17074 | prefix: stores.attachmentStore
|
17075 | }, {
|
17076 | key: digest,
|
17077 | type: 'del',
|
17078 | prefix: stores.binaryStore
|
17079 | }]);
|
17080 | }
|
17081 | checkDone();
|
17082 | });
|
17083 | });
|
17084 | }
|
17085 |
|
17086 | seqs.forEach(function (seq) {
|
17087 | batch.push({
|
17088 | key: formatSeq(seq),
|
17089 | type: 'del',
|
17090 | prefix: stores.bySeqStore
|
17091 | });
|
17092 | txn.get(stores.bySeqStore, formatSeq(seq), function (err, doc) {
|
17093 | /* istanbul ignore if */
|
17094 | if (err) {
|
17095 | if (err.name === 'NotFoundError') {
|
17096 | return checkDone();
|
17097 | } else {
|
17098 | return checkDone(err);
|
17099 | }
|
17100 | }
|
17101 | var atts = Object.keys(doc._attachments || {});
|
17102 | atts.forEach(function (attName) {
|
17103 | var digest = doc._attachments[attName].digest;
|
17104 | digestMap[digest] = true;
|
17105 | });
|
17106 | checkDone();
|
17107 | });
|
17108 | });
|
17109 | });
|
17110 | };
|
17111 |
|
17112 | api._getLocal = function (id, callback) {
|
17113 | stores.localStore.get(id, function (err, doc) {
|
17114 | if (err) {
|
17115 | callback(createError(MISSING_DOC));
|
17116 | } else {
|
17117 | callback(null, doc);
|
17118 | }
|
17119 | });
|
17120 | };
|
17121 |
|
17122 | api._putLocal = function (doc, opts, callback) {
|
17123 | if (typeof opts === 'function') {
|
17124 | callback = opts;
|
17125 | opts = {};
|
17126 | }
|
17127 | if (opts.ctx) {
|
17128 | api._putLocalNoLock(doc, opts, callback);
|
17129 | } else {
|
17130 | api._putLocalWithLock(doc, opts, callback);
|
17131 | }
|
17132 | };
|
17133 |
|
17134 | api._putLocalWithLock = writeLock(function (doc, opts, callback) {
|
17135 | api._putLocalNoLock(doc, opts, callback);
|
17136 | });
|
17137 |
|
17138 | // the NoLock version is for use by bulkDocs
|
17139 | api._putLocalNoLock = function (doc, opts, callback) {
|
17140 | delete doc._revisions; // ignore this, trust the rev
|
17141 | var oldRev = doc._rev;
|
17142 | var id = doc._id;
|
17143 |
|
17144 | var txn = opts.ctx || new LevelTransaction();
|
17145 |
|
17146 | txn.get(stores.localStore, id, function (err, resp) {
|
17147 | if (err && oldRev) {
|
17148 | return callback(createError(REV_CONFLICT));
|
17149 | }
|
17150 | if (resp && resp._rev !== oldRev) {
|
17151 | return callback(createError(REV_CONFLICT));
|
17152 | }
|
17153 | doc._rev =
|
17154 | oldRev ? '0-' + (parseInt(oldRev.split('-')[1], 10) + 1) : '0-1';
|
17155 | var batch = [
|
17156 | {
|
17157 | type: 'put',
|
17158 | prefix: stores.localStore,
|
17159 | key: id,
|
17160 | value: doc
|
17161 | }
|
17162 | ];
|
17163 |
|
17164 | txn.batch(batch);
|
17165 | var ret = {ok: true, id: doc._id, rev: doc._rev};
|
17166 |
|
17167 | if (opts.ctx) {
|
17168 | // don't execute immediately
|
17169 | return callback(null, ret);
|
17170 | }
|
17171 | txn.execute(db, function (err) {
|
17172 | /* istanbul ignore if */
|
17173 | if (err) {
|
17174 | return callback(err);
|
17175 | }
|
17176 | callback(null, ret);
|
17177 | });
|
17178 | });
|
17179 | };
|
17180 |
|
17181 | api._removeLocal = function (doc, opts, callback) {
|
17182 | if (typeof opts === 'function') {
|
17183 | callback = opts;
|
17184 | opts = {};
|
17185 | }
|
17186 | if (opts.ctx) {
|
17187 | api._removeLocalNoLock(doc, opts, callback);
|
17188 | } else {
|
17189 | api._removeLocalWithLock(doc, opts, callback);
|
17190 | }
|
17191 | };
|
17192 |
|
17193 | api._removeLocalWithLock = writeLock(function (doc, opts, callback) {
|
17194 | api._removeLocalNoLock(doc, opts, callback);
|
17195 | });
|
17196 |
|
17197 | // the NoLock version is for use by bulkDocs
|
17198 | api._removeLocalNoLock = function (doc, opts, callback) {
|
17199 | var txn = opts.ctx || new LevelTransaction();
|
17200 | txn.get(stores.localStore, doc._id, function (err, resp) {
|
17201 | if (err) {
|
17202 | /* istanbul ignore if */
|
17203 | if (err.name !== 'NotFoundError') {
|
17204 | return callback(err);
|
17205 | } else {
|
17206 | return callback(createError(MISSING_DOC));
|
17207 | }
|
17208 | }
|
17209 | if (resp._rev !== doc._rev) {
|
17210 | return callback(createError(REV_CONFLICT));
|
17211 | }
|
17212 | txn.batch([{
|
17213 | prefix: stores.localStore,
|
17214 | type: 'del',
|
17215 | key: doc._id
|
17216 | }]);
|
17217 | var ret = {ok: true, id: doc._id, rev: '0-0'};
|
17218 | if (opts.ctx) {
|
17219 | // don't execute immediately
|
17220 | return callback(null, ret);
|
17221 | }
|
17222 | txn.execute(db, function (err) {
|
17223 | /* istanbul ignore if */
|
17224 | if (err) {
|
17225 | return callback(err);
|
17226 | }
|
17227 | callback(null, ret);
|
17228 | });
|
17229 | });
|
17230 | };
|
17231 |
|
17232 | // close and delete open leveldb stores
|
17233 | api._destroy = function (opts, callback) {
|
17234 | var dbStore;
|
17235 | var leveldownName = functionName(leveldown);
|
17236 | /* istanbul ignore else */
|
17237 | if (dbStores.has(leveldownName)) {
|
17238 | dbStore = dbStores.get(leveldownName);
|
17239 | } else {
|
17240 | return callDestroy(name, callback);
|
17241 | }
|
17242 |
|
17243 | /* istanbul ignore else */
|
17244 | if (dbStore.has(name)) {
|
17245 | levelChanges.removeAllListeners(name);
|
17246 |
|
17247 | dbStore.get(name).close(function () {
|
17248 | dbStore["delete"](name);
|
17249 | callDestroy(name, callback);
|
17250 | });
|
17251 | } else {
|
17252 | callDestroy(name, callback);
|
17253 | }
|
17254 | };
|
17255 | function callDestroy(name, cb) {
|
17256 | // May not exist if leveldown is backed by memory adapter
|
17257 | if ('destroy' in leveldown) {
|
17258 | leveldown.destroy(name, cb);
|
17259 | }
|
17260 | }
|
17261 | }
|
17262 |
|
17263 | function LocalStoragePouch(opts, callback) {
|
17264 | var _opts = $inject_Object_assign({
|
17265 | db: localstoragedown
|
17266 | }, opts);
|
17267 |
|
17268 | LevelPouch.call(this, _opts, callback);
|
17269 | }
|
17270 |
|
17271 | // overrides for normal LevelDB behavior on Node
|
17272 | LocalStoragePouch.valid = function () {
|
17273 | return typeof localStorage !== 'undefined';
|
17274 | };
|
17275 | LocalStoragePouch.use_prefix = true;
|
17276 |
|
17277 | function LocalStoragePouchPlugin (PouchDB) {
|
17278 | PouchDB.adapter('localstorage', LocalStoragePouch, true);
|
17279 | }
|
17280 |
|
17281 | /* global PouchDB */
|
17282 |
|
17283 | if (typeof PouchDB === 'undefined') {
|
17284 | guardedConsole('error', 'localstorage adapter plugin error: ' +
|
17285 | 'Cannot find global "PouchDB" object! ' +
|
17286 | 'Did you remember to include pouchdb.js?');
|
17287 | } else {
|
17288 | PouchDB.plugin(LocalStoragePouchPlugin);
|
17289 | }
|
17290 |
|
17291 | }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
17292 | },{"104":104,"109":109,"11":11,"15":15,"18":18,"23":23,"24":24,"27":27,"4":4,"41":41,"51":51,"58":58,"69":69,"71":71,"98":98}]},{},[111]);
|
17293 |
|
\ | No newline at end of file |