UNPKG

192 kBJavaScriptView Raw
1(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
2'use strict';
3
4require('./lib/polyfills');
5var crypto = require('crypto');
6
7/**
8 * Exported function
9 *
10 * Options:
11 *
12 * - `algorithm` hash algo to be used by this instance: *'sha1', 'md5'
13 * - `excludeValues` {true|*false} hash object keys, values ignored
14 * - `encoding` hash encoding, supports 'buffer', '*hex', 'binary', 'base64'
15 * * = default
16 *
17 * @param {object} value to hash
18 * @param {options} hashing options
19 * @return {hash value}
20 * @api public
21 */
22exports = module.exports = objectHash;
23
24function objectHash(object, options){
25 options = options || {};
26 options.algorithm = options.algorithm || 'sha1';
27 options.encoding = options.encoding || 'hex';
28 options.excludeValues = options.excludeValues ? true : false;
29 options.algorithm = options.algorithm.toLowerCase();
30 options.encoding = options.encoding.toLowerCase();
31
32 validate(object, options);
33
34 return hash(object, options);
35}
36
37/**
38 * Exported sugar methods
39 *
40 * @param {object} value to hash
41 * @return {hash value}
42 * @api public
43 */
44exports.sha1 = function(object){
45 return objectHash(object);
46};
47exports.keys = function(object){
48 return objectHash(object, {excludeValues: true, algorithm: 'sha1', encoding: 'hex'});
49};
50exports.MD5 = function(object){
51 return objectHash(object, {algorithm: 'md5', encoding: 'hex'});
52};
53exports.keysMD5 = function(object){
54 return objectHash(object, {algorithm: 'md5', encoding: 'hex', excludeValues: true});
55};
56
57/**
58 * Expose HashTable constructor
59 *
60 */
61exports.HashTable = require('./lib/hashTable');
62
63
64// Internals
65function validate(object, options){
66 var hashes = crypto.getHashes ? crypto.getHashes() : ['sha1', 'md5'];
67 var encodings = ['buffer', 'hex', 'binary', 'base64'];
68
69 if(typeof object === 'undefined') {
70 throw new Error('Object argument required.');
71 }
72
73 if(hashes.indexOf(options.algorithm) === -1){
74 throw new Error('Algorithm "' + options.algorithm + '" not supported. ' +
75 'supported values: ' + hashes.join(', '));
76 }
77
78 if(encodings.indexOf(options.encoding) === -1){
79 throw new Error('Encoding "' + options.encoding + '" not supported. ' +
80 'supported values: ' + encodings.join(', '));
81 }
82}
83
84function hash(object, options){
85 var hashFn = crypto.createHash(options.algorithm);
86
87 typeHasher(hashFn, options).dispatch(object);
88
89 return (options.encoding === 'buffer') ? hashFn.digest() :
90 hashFn.digest(options.encoding);
91}
92
93function typeHasher(hashFn, options){
94 return {
95 dispatch: function(value){
96 var type = typeof value;
97 var func = this['_' + type];
98 return (value === null) ? this._null() : func(value);
99 },
100 _object: function(object) {
101 var pattern = (/\[object (.*)\]/i);
102 var objString = Object.prototype.toString.call(object);
103 var objType = pattern.exec(objString)[1] || 'null';
104 objType = objType.toLowerCase();
105
106 if(objType !== 'object') {
107 if(typeHasher(hashFn, options)['_' + objType]) {
108 typeHasher(hashFn, options)['_' + objType](object);
109 }else{
110 throw new Error('Unknown object type "' + objType + '"');
111 }
112 }else{
113 // TODO, add option for enumerating, for key in obj includePrototypeChain
114 var keys = Object.keys(object).sort();
115 return keys.forEach(function(key){
116 hashFn.update(key);
117 if(!options.excludeValues) {
118 typeHasher(hashFn, options).dispatch(object[key]);
119 }
120 });
121 }
122 },
123 _array: function(arr){
124 return arr.forEach(function(el){
125 typeHasher(hashFn, options).dispatch(el);
126 });
127 },
128 _date: function(date){
129 return hashFn.update(date.toString());
130 },
131 _boolean: function(bool){
132 return hashFn.update(bool.toString());
133 },
134 _string: function(string){
135 return hashFn.update(string);
136 },
137 _function: function(fn){
138 return hashFn.update(fn.toString());
139 },
140 _number: function(number){
141 return hashFn.update(number.toString());
142 },
143 _xml: function(xml){
144 return hashFn.update(xml.toString());
145 },
146 _null: function(){
147 return hashFn.update('Null');
148 },
149 _undefined: function(){
150 return hashFn.update('Undefined');
151 },
152 _regexp: function(regex){
153 return hashFn.update(regex.toString());
154 },
155 _domwindow: function(){
156 return hashFn.update('domwindow');
157 }
158 };
159}
160
161},{"./lib/hashTable":2,"./lib/polyfills":3,"crypto":8}],2:[function(require,module,exports){
162'use strict';
163var hasher = require('../index');
164require('./polyfills');
165
166/**
167 * Setup a HashTable instance with options
168 * Options:
169 *
170 * - `algorithm` hash algo to be used by this instance: *'sha1', 'md5'
171 * - `excludeValues` {true|*false} hash object keys, values ignored
172 * - `encoding` hash encoding, supports 'buffer', '*hex', 'binary', 'base64'
173 * * = default
174 *
175 * @param options
176 * @api public
177 */
178exports = module.exports = HashTable;
179
180function HashTable(options){
181 options = options || {};
182 this.options = options;
183 this._table = {};
184}
185
186HashTable.prototype.add = function(/* values to be added */){
187 var self = this;
188 var args = Array.prototype.slice.call(arguments, 0);
189 args.forEach(function(obj){
190 if(Object.prototype.toString.call(obj) === '[object Array]'){
191 obj.forEach(function(val){
192 self._addObject(val);
193 });
194 }else{
195 self._addObject(obj);
196 }
197 });
198
199 return this;
200};
201
202HashTable.prototype._addObject = function(object){
203 var hash = hasher(object, this.options);
204
205 if(this._table[hash]){
206 this._table[hash].count++;
207 if(this.options.excludeValues){
208 this._table[hash].value.push(object);
209 }
210 }else{
211 this._table[hash] = {
212 value: this.options.excludeValues ? [object] : object,
213 count: 1
214 };
215 }
216}
217
218HashTable.prototype.hasKey = function(key){
219 return !!(this._table[key]);
220};
221
222HashTable.prototype.getValue = function(key){
223 return this._table[key] ? this._table[key].value : undefined;
224};
225
226HashTable.prototype.getCount = function(key){
227 return this._table[key] ? this._table[key].count : 0;
228};
229
230HashTable.prototype.table = function(){
231 return this._table;
232};
233
234HashTable.prototype.toArray = function(){
235 var keys = Object.keys(this._table);
236 var arr = [];
237 for(var i = 0;i < keys.length;i++){
238 arr.push({
239 value: this._table[keys[i]].value,
240 count: this._table[keys[i]].count,
241 hash: keys[i]
242 });
243 }
244 return arr;
245};
246
247HashTable.prototype.reset = function(){
248 this._table = {};
249 return this;
250}
251},{"../index":1,"./polyfills":3}],3:[function(require,module,exports){
252// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys
253if (!Object.keys) {
254 Object.keys = (function () {
255 'use strict';
256 var hasOwnProperty = Object.prototype.hasOwnProperty,
257 hasDontEnumBug = !({toString: null}).propertyIsEnumerable('toString'),
258 dontEnums = [
259 'toString',
260 'toLocaleString',
261 'valueOf',
262 'hasOwnProperty',
263 'isPrototypeOf',
264 'propertyIsEnumerable',
265 'constructor'
266 ],
267 dontEnumsLength = dontEnums.length;
268
269 return function (obj) {
270 if (typeof obj !== 'object' && (typeof obj !== 'function' || obj === null)) {
271 throw new TypeError('Object.keys called on non-object');
272 }
273
274 var result = [], prop, i;
275
276 for (prop in obj) {
277 if (hasOwnProperty.call(obj, prop)) {
278 result.push(prop);
279 }
280 }
281
282 if (hasDontEnumBug) {
283 for (i = 0; i < dontEnumsLength; i++) {
284 if (hasOwnProperty.call(obj, dontEnums[i])) {
285 result.push(dontEnums[i]);
286 }
287 }
288 }
289 return result;
290 };
291 }());
292}
293
294// indexOf polyfill from MDN
295if (!Array.prototype.indexOf) {
296 Array.prototype.indexOf = function (searchElement, fromIndex) {
297 if ( this === undefined || this === null ) {
298 throw new TypeError( '"this" is null or not defined' );
299 }
300
301 var length = this.length >>> 0; // Hack to convert object.length to a UInt32
302
303 fromIndex = +fromIndex || 0;
304
305 if (Math.abs(fromIndex) === Infinity) {
306 fromIndex = 0;
307 }
308
309 if (fromIndex < 0) {
310 fromIndex += length;
311 if (fromIndex < 0) {
312 fromIndex = 0;
313 }
314 }
315
316 for (;fromIndex < length; fromIndex++) {
317 if (this[fromIndex] === searchElement) {
318 return fromIndex;
319 }
320 }
321
322 return -1;
323 };
324 }
325// forEach https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach
326if (!Array.prototype.forEach)
327{
328 Array.prototype.forEach = function(fun /*, thisArg */)
329 {
330 "use strict";
331
332 if (this === void 0 || this === null) {
333 throw new TypeError();
334 }
335
336 var t = Object(this);
337 var len = t.length >>> 0;
338 if (typeof fun !== "function") {
339 throw new TypeError();
340 }
341
342 var thisArg = arguments.length >= 2 ? arguments[1] : void 0;
343 for (var i = 0; i < len; i++)
344 {
345 if (i in t) {
346 fun.call(thisArg, t[i], i, t);
347 }
348 }
349 };
350}
351
352(function () {
353 'use strict';
354 var _slice = Array.prototype.slice;
355
356 try {
357 // Can't be used with DOM elements in IE < 9
358 _slice.call(document.documentElement);
359 }
360 catch (e) { // Fails in IE < 9
361 Array.prototype.slice = function (begin, end) {
362 var i, arrl = this.length, a = [];
363 // Although IE < 9 does not fail when applying Array.prototype.slice
364 // to strings, here we do have to duck-type to avoid failing
365 // with IE < 9's lack of support for string indexes
366 if (this.charAt) {
367 for (i = 0; i < arrl; i++) {
368 a.push(this.charAt(i));
369 }
370 }
371 // This will work for genuine arrays, array-like objects,
372 // NamedNodeMap (attributes, entities, notations),
373 // NodeList (e.g., getElementsByTagName), HTMLCollection (e.g., childNodes),
374 // and will not fail on other DOM objects (as do DOM elements in IE < 9)
375 else {
376 // IE < 9 (at least IE < 9 mode in IE 10) does not work with
377 // node.attributes (NamedNodeMap) without a dynamically checked length here
378 for (i = 0; i < this.length; i++) {
379 a.push(this[i]);
380 }
381 }
382 // IE < 9 gives errors here if end is allowed as undefined
383 // (as opposed to just missing) so we default ourselves
384 return _slice.call(a, begin, end || a.length);
385 };
386 }
387}());
388
389},{}],4:[function(require,module,exports){
390/**
391 * The buffer module from node.js, for the browser.
392 *
393 * Author: Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
394 * License: MIT
395 *
396 * `npm install buffer`
397 */
398
399var base64 = require('base64-js')
400var ieee754 = require('ieee754')
401
402exports.Buffer = Buffer
403exports.SlowBuffer = Buffer
404exports.INSPECT_MAX_BYTES = 50
405Buffer.poolSize = 8192
406
407/**
408 * If `Buffer._useTypedArrays`:
409 * === true Use Uint8Array implementation (fastest)
410 * === false Use Object implementation (compatible down to IE6)
411 */
412Buffer._useTypedArrays = (function () {
413 // Detect if browser supports Typed Arrays. Supported browsers are IE 10+,
414 // Firefox 4+, Chrome 7+, Safari 5.1+, Opera 11.6+, iOS 4.2+.
415 if (typeof Uint8Array !== 'function' || typeof ArrayBuffer !== 'function')
416 return false
417
418 // Does the browser support adding properties to `Uint8Array` instances? If
419 // not, then that's the same as no `Uint8Array` support. We need to be able to
420 // add all the node Buffer API methods.
421 // Bug in Firefox 4-29, now fixed: https://bugzilla.mozilla.org/show_bug.cgi?id=695438
422 try {
423 var arr = new Uint8Array(0)
424 arr.foo = function () { return 42 }
425 return 42 === arr.foo() &&
426 typeof arr.subarray === 'function' // Chrome 9-10 lack `subarray`
427 } catch (e) {
428 return false
429 }
430})()
431
432/**
433 * Class: Buffer
434 * =============
435 *
436 * The Buffer constructor returns instances of `Uint8Array` that are augmented
437 * with function properties for all the node `Buffer` API functions. We use
438 * `Uint8Array` so that square bracket notation works as expected -- it returns
439 * a single octet.
440 *
441 * By augmenting the instances, we can avoid modifying the `Uint8Array`
442 * prototype.
443 */
444function Buffer (subject, encoding, noZero) {
445 if (!(this instanceof Buffer))
446 return new Buffer(subject, encoding, noZero)
447
448 var type = typeof subject
449
450 // Workaround: node's base64 implementation allows for non-padded strings
451 // while base64-js does not.
452 if (encoding === 'base64' && type === 'string') {
453 subject = stringtrim(subject)
454 while (subject.length % 4 !== 0) {
455 subject = subject + '='
456 }
457 }
458
459 // Find the length
460 var length
461 if (type === 'number')
462 length = coerce(subject)
463 else if (type === 'string')
464 length = Buffer.byteLength(subject, encoding)
465 else if (type === 'object')
466 length = coerce(subject.length) // Assume object is an array
467 else
468 throw new Error('First argument needs to be a number, array or string.')
469
470 var buf
471 if (Buffer._useTypedArrays) {
472 // Preferred: Return an augmented `Uint8Array` instance for best performance
473 buf = augment(new Uint8Array(length))
474 } else {
475 // Fallback: Return THIS instance of Buffer (created by `new`)
476 buf = this
477 buf.length = length
478 buf._isBuffer = true
479 }
480
481 var i
482 if (Buffer._useTypedArrays && typeof Uint8Array === 'function' &&
483 subject instanceof Uint8Array) {
484 // Speed optimization -- use set if we're copying from a Uint8Array
485 buf._set(subject)
486 } else if (isArrayish(subject)) {
487 // Treat array-ish objects as a byte array
488 for (i = 0; i < length; i++) {
489 if (Buffer.isBuffer(subject))
490 buf[i] = subject.readUInt8(i)
491 else
492 buf[i] = subject[i]
493 }
494 } else if (type === 'string') {
495 buf.write(subject, 0, encoding)
496 } else if (type === 'number' && !Buffer._useTypedArrays && !noZero) {
497 for (i = 0; i < length; i++) {
498 buf[i] = 0
499 }
500 }
501
502 return buf
503}
504
505// STATIC METHODS
506// ==============
507
508Buffer.isEncoding = function (encoding) {
509 switch (String(encoding).toLowerCase()) {
510 case 'hex':
511 case 'utf8':
512 case 'utf-8':
513 case 'ascii':
514 case 'binary':
515 case 'base64':
516 case 'raw':
517 case 'ucs2':
518 case 'ucs-2':
519 case 'utf16le':
520 case 'utf-16le':
521 return true
522 default:
523 return false
524 }
525}
526
527Buffer.isBuffer = function (b) {
528 return !!(b !== null && b !== undefined && b._isBuffer)
529}
530
531Buffer.byteLength = function (str, encoding) {
532 var ret
533 str = str + ''
534 switch (encoding || 'utf8') {
535 case 'hex':
536 ret = str.length / 2
537 break
538 case 'utf8':
539 case 'utf-8':
540 ret = utf8ToBytes(str).length
541 break
542 case 'ascii':
543 case 'binary':
544 case 'raw':
545 ret = str.length
546 break
547 case 'base64':
548 ret = base64ToBytes(str).length
549 break
550 case 'ucs2':
551 case 'ucs-2':
552 case 'utf16le':
553 case 'utf-16le':
554 ret = str.length * 2
555 break
556 default:
557 throw new Error('Unknown encoding')
558 }
559 return ret
560}
561
562Buffer.concat = function (list, totalLength) {
563 assert(isArray(list), 'Usage: Buffer.concat(list, [totalLength])\n' +
564 'list should be an Array.')
565
566 if (list.length === 0) {
567 return new Buffer(0)
568 } else if (list.length === 1) {
569 return list[0]
570 }
571
572 var i
573 if (typeof totalLength !== 'number') {
574 totalLength = 0
575 for (i = 0; i < list.length; i++) {
576 totalLength += list[i].length
577 }
578 }
579
580 var buf = new Buffer(totalLength)
581 var pos = 0
582 for (i = 0; i < list.length; i++) {
583 var item = list[i]
584 item.copy(buf, pos)
585 pos += item.length
586 }
587 return buf
588}
589
590// BUFFER INSTANCE METHODS
591// =======================
592
593function _hexWrite (buf, string, offset, length) {
594 offset = Number(offset) || 0
595 var remaining = buf.length - offset
596 if (!length) {
597 length = remaining
598 } else {
599 length = Number(length)
600 if (length > remaining) {
601 length = remaining
602 }
603 }
604
605 // must be an even number of digits
606 var strLen = string.length
607 assert(strLen % 2 === 0, 'Invalid hex string')
608
609 if (length > strLen / 2) {
610 length = strLen / 2
611 }
612 for (var i = 0; i < length; i++) {
613 var byte = parseInt(string.substr(i * 2, 2), 16)
614 assert(!isNaN(byte), 'Invalid hex string')
615 buf[offset + i] = byte
616 }
617 Buffer._charsWritten = i * 2
618 return i
619}
620
621function _utf8Write (buf, string, offset, length) {
622 var charsWritten = Buffer._charsWritten =
623 blitBuffer(utf8ToBytes(string), buf, offset, length)
624 return charsWritten
625}
626
627function _asciiWrite (buf, string, offset, length) {
628 var charsWritten = Buffer._charsWritten =
629 blitBuffer(asciiToBytes(string), buf, offset, length)
630 return charsWritten
631}
632
633function _binaryWrite (buf, string, offset, length) {
634 return _asciiWrite(buf, string, offset, length)
635}
636
637function _base64Write (buf, string, offset, length) {
638 var charsWritten = Buffer._charsWritten =
639 blitBuffer(base64ToBytes(string), buf, offset, length)
640 return charsWritten
641}
642
643function _utf16leWrite (buf, string, offset, length) {
644 var charsWritten = Buffer._charsWritten =
645 blitBuffer(utf16leToBytes(string), buf, offset, length)
646 return charsWritten
647}
648
649Buffer.prototype.write = function (string, offset, length, encoding) {
650 // Support both (string, offset, length, encoding)
651 // and the legacy (string, encoding, offset, length)
652 if (isFinite(offset)) {
653 if (!isFinite(length)) {
654 encoding = length
655 length = undefined
656 }
657 } else { // legacy
658 var swap = encoding
659 encoding = offset
660 offset = length
661 length = swap
662 }
663
664 offset = Number(offset) || 0
665 var remaining = this.length - offset
666 if (!length) {
667 length = remaining
668 } else {
669 length = Number(length)
670 if (length > remaining) {
671 length = remaining
672 }
673 }
674 encoding = String(encoding || 'utf8').toLowerCase()
675
676 var ret
677 switch (encoding) {
678 case 'hex':
679 ret = _hexWrite(this, string, offset, length)
680 break
681 case 'utf8':
682 case 'utf-8':
683 ret = _utf8Write(this, string, offset, length)
684 break
685 case 'ascii':
686 ret = _asciiWrite(this, string, offset, length)
687 break
688 case 'binary':
689 ret = _binaryWrite(this, string, offset, length)
690 break
691 case 'base64':
692 ret = _base64Write(this, string, offset, length)
693 break
694 case 'ucs2':
695 case 'ucs-2':
696 case 'utf16le':
697 case 'utf-16le':
698 ret = _utf16leWrite(this, string, offset, length)
699 break
700 default:
701 throw new Error('Unknown encoding')
702 }
703 return ret
704}
705
706Buffer.prototype.toString = function (encoding, start, end) {
707 var self = this
708
709 encoding = String(encoding || 'utf8').toLowerCase()
710 start = Number(start) || 0
711 end = (end !== undefined)
712 ? Number(end)
713 : end = self.length
714
715 // Fastpath empty strings
716 if (end === start)
717 return ''
718
719 var ret
720 switch (encoding) {
721 case 'hex':
722 ret = _hexSlice(self, start, end)
723 break
724 case 'utf8':
725 case 'utf-8':
726 ret = _utf8Slice(self, start, end)
727 break
728 case 'ascii':
729 ret = _asciiSlice(self, start, end)
730 break
731 case 'binary':
732 ret = _binarySlice(self, start, end)
733 break
734 case 'base64':
735 ret = _base64Slice(self, start, end)
736 break
737 case 'ucs2':
738 case 'ucs-2':
739 case 'utf16le':
740 case 'utf-16le':
741 ret = _utf16leSlice(self, start, end)
742 break
743 default:
744 throw new Error('Unknown encoding')
745 }
746 return ret
747}
748
749Buffer.prototype.toJSON = function () {
750 return {
751 type: 'Buffer',
752 data: Array.prototype.slice.call(this._arr || this, 0)
753 }
754}
755
756// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
757Buffer.prototype.copy = function (target, target_start, start, end) {
758 var source = this
759
760 if (!start) start = 0
761 if (!end && end !== 0) end = this.length
762 if (!target_start) target_start = 0
763
764 // Copy 0 bytes; we're done
765 if (end === start) return
766 if (target.length === 0 || source.length === 0) return
767
768 // Fatal error conditions
769 assert(end >= start, 'sourceEnd < sourceStart')
770 assert(target_start >= 0 && target_start < target.length,
771 'targetStart out of bounds')
772 assert(start >= 0 && start < source.length, 'sourceStart out of bounds')
773 assert(end >= 0 && end <= source.length, 'sourceEnd out of bounds')
774
775 // Are we oob?
776 if (end > this.length)
777 end = this.length
778 if (target.length - target_start < end - start)
779 end = target.length - target_start + start
780
781 // copy!
782 for (var i = 0; i < end - start; i++)
783 target[i + target_start] = this[i + start]
784}
785
786function _base64Slice (buf, start, end) {
787 if (start === 0 && end === buf.length) {
788 return base64.fromByteArray(buf)
789 } else {
790 return base64.fromByteArray(buf.slice(start, end))
791 }
792}
793
794function _utf8Slice (buf, start, end) {
795 var res = ''
796 var tmp = ''
797 end = Math.min(buf.length, end)
798
799 for (var i = start; i < end; i++) {
800 if (buf[i] <= 0x7F) {
801 res += decodeUtf8Char(tmp) + String.fromCharCode(buf[i])
802 tmp = ''
803 } else {
804 tmp += '%' + buf[i].toString(16)
805 }
806 }
807
808 return res + decodeUtf8Char(tmp)
809}
810
811function _asciiSlice (buf, start, end) {
812 var ret = ''
813 end = Math.min(buf.length, end)
814
815 for (var i = start; i < end; i++)
816 ret += String.fromCharCode(buf[i])
817 return ret
818}
819
820function _binarySlice (buf, start, end) {
821 return _asciiSlice(buf, start, end)
822}
823
824function _hexSlice (buf, start, end) {
825 var len = buf.length
826
827 if (!start || start < 0) start = 0
828 if (!end || end < 0 || end > len) end = len
829
830 var out = ''
831 for (var i = start; i < end; i++) {
832 out += toHex(buf[i])
833 }
834 return out
835}
836
837function _utf16leSlice (buf, start, end) {
838 var bytes = buf.slice(start, end)
839 var res = ''
840 for (var i = 0; i < bytes.length; i += 2) {
841 res += String.fromCharCode(bytes[i] + bytes[i+1] * 256)
842 }
843 return res
844}
845
846Buffer.prototype.slice = function (start, end) {
847 var len = this.length
848 start = clamp(start, len, 0)
849 end = clamp(end, len, len)
850
851 if (Buffer._useTypedArrays) {
852 return augment(this.subarray(start, end))
853 } else {
854 var sliceLen = end - start
855 var newBuf = new Buffer(sliceLen, undefined, true)
856 for (var i = 0; i < sliceLen; i++) {
857 newBuf[i] = this[i + start]
858 }
859 return newBuf
860 }
861}
862
863// `get` will be removed in Node 0.13+
864Buffer.prototype.get = function (offset) {
865 console.log('.get() is deprecated. Access using array indexes instead.')
866 return this.readUInt8(offset)
867}
868
869// `set` will be removed in Node 0.13+
870Buffer.prototype.set = function (v, offset) {
871 console.log('.set() is deprecated. Access using array indexes instead.')
872 return this.writeUInt8(v, offset)
873}
874
875Buffer.prototype.readUInt8 = function (offset, noAssert) {
876 if (!noAssert) {
877 assert(offset !== undefined && offset !== null, 'missing offset')
878 assert(offset < this.length, 'Trying to read beyond buffer length')
879 }
880
881 if (offset >= this.length)
882 return
883
884 return this[offset]
885}
886
887function _readUInt16 (buf, offset, littleEndian, noAssert) {
888 if (!noAssert) {
889 assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
890 assert(offset !== undefined && offset !== null, 'missing offset')
891 assert(offset + 1 < buf.length, 'Trying to read beyond buffer length')
892 }
893
894 var len = buf.length
895 if (offset >= len)
896 return
897
898 var val
899 if (littleEndian) {
900 val = buf[offset]
901 if (offset + 1 < len)
902 val |= buf[offset + 1] << 8
903 } else {
904 val = buf[offset] << 8
905 if (offset + 1 < len)
906 val |= buf[offset + 1]
907 }
908 return val
909}
910
911Buffer.prototype.readUInt16LE = function (offset, noAssert) {
912 return _readUInt16(this, offset, true, noAssert)
913}
914
915Buffer.prototype.readUInt16BE = function (offset, noAssert) {
916 return _readUInt16(this, offset, false, noAssert)
917}
918
919function _readUInt32 (buf, offset, littleEndian, noAssert) {
920 if (!noAssert) {
921 assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
922 assert(offset !== undefined && offset !== null, 'missing offset')
923 assert(offset + 3 < buf.length, 'Trying to read beyond buffer length')
924 }
925
926 var len = buf.length
927 if (offset >= len)
928 return
929
930 var val
931 if (littleEndian) {
932 if (offset + 2 < len)
933 val = buf[offset + 2] << 16
934 if (offset + 1 < len)
935 val |= buf[offset + 1] << 8
936 val |= buf[offset]
937 if (offset + 3 < len)
938 val = val + (buf[offset + 3] << 24 >>> 0)
939 } else {
940 if (offset + 1 < len)
941 val = buf[offset + 1] << 16
942 if (offset + 2 < len)
943 val |= buf[offset + 2] << 8
944 if (offset + 3 < len)
945 val |= buf[offset + 3]
946 val = val + (buf[offset] << 24 >>> 0)
947 }
948 return val
949}
950
951Buffer.prototype.readUInt32LE = function (offset, noAssert) {
952 return _readUInt32(this, offset, true, noAssert)
953}
954
955Buffer.prototype.readUInt32BE = function (offset, noAssert) {
956 return _readUInt32(this, offset, false, noAssert)
957}
958
959Buffer.prototype.readInt8 = function (offset, noAssert) {
960 if (!noAssert) {
961 assert(offset !== undefined && offset !== null,
962 'missing offset')
963 assert(offset < this.length, 'Trying to read beyond buffer length')
964 }
965
966 if (offset >= this.length)
967 return
968
969 var neg = this[offset] & 0x80
970 if (neg)
971 return (0xff - this[offset] + 1) * -1
972 else
973 return this[offset]
974}
975
976function _readInt16 (buf, offset, littleEndian, noAssert) {
977 if (!noAssert) {
978 assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
979 assert(offset !== undefined && offset !== null, 'missing offset')
980 assert(offset + 1 < buf.length, 'Trying to read beyond buffer length')
981 }
982
983 var len = buf.length
984 if (offset >= len)
985 return
986
987 var val = _readUInt16(buf, offset, littleEndian, true)
988 var neg = val & 0x8000
989 if (neg)
990 return (0xffff - val + 1) * -1
991 else
992 return val
993}
994
995Buffer.prototype.readInt16LE = function (offset, noAssert) {
996 return _readInt16(this, offset, true, noAssert)
997}
998
999Buffer.prototype.readInt16BE = function (offset, noAssert) {
1000 return _readInt16(this, offset, false, noAssert)
1001}
1002
1003function _readInt32 (buf, offset, littleEndian, noAssert) {
1004 if (!noAssert) {
1005 assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
1006 assert(offset !== undefined && offset !== null, 'missing offset')
1007 assert(offset + 3 < buf.length, 'Trying to read beyond buffer length')
1008 }
1009
1010 var len = buf.length
1011 if (offset >= len)
1012 return
1013
1014 var val = _readUInt32(buf, offset, littleEndian, true)
1015 var neg = val & 0x80000000
1016 if (neg)
1017 return (0xffffffff - val + 1) * -1
1018 else
1019 return val
1020}
1021
1022Buffer.prototype.readInt32LE = function (offset, noAssert) {
1023 return _readInt32(this, offset, true, noAssert)
1024}
1025
1026Buffer.prototype.readInt32BE = function (offset, noAssert) {
1027 return _readInt32(this, offset, false, noAssert)
1028}
1029
1030function _readFloat (buf, offset, littleEndian, noAssert) {
1031 if (!noAssert) {
1032 assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
1033 assert(offset + 3 < buf.length, 'Trying to read beyond buffer length')
1034 }
1035
1036 return ieee754.read(buf, offset, littleEndian, 23, 4)
1037}
1038
1039Buffer.prototype.readFloatLE = function (offset, noAssert) {
1040 return _readFloat(this, offset, true, noAssert)
1041}
1042
1043Buffer.prototype.readFloatBE = function (offset, noAssert) {
1044 return _readFloat(this, offset, false, noAssert)
1045}
1046
1047function _readDouble (buf, offset, littleEndian, noAssert) {
1048 if (!noAssert) {
1049 assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
1050 assert(offset + 7 < buf.length, 'Trying to read beyond buffer length')
1051 }
1052
1053 return ieee754.read(buf, offset, littleEndian, 52, 8)
1054}
1055
1056Buffer.prototype.readDoubleLE = function (offset, noAssert) {
1057 return _readDouble(this, offset, true, noAssert)
1058}
1059
1060Buffer.prototype.readDoubleBE = function (offset, noAssert) {
1061 return _readDouble(this, offset, false, noAssert)
1062}
1063
1064Buffer.prototype.writeUInt8 = function (value, offset, noAssert) {
1065 if (!noAssert) {
1066 assert(value !== undefined && value !== null, 'missing value')
1067 assert(offset !== undefined && offset !== null, 'missing offset')
1068 assert(offset < this.length, 'trying to write beyond buffer length')
1069 verifuint(value, 0xff)
1070 }
1071
1072 if (offset >= this.length) return
1073
1074 this[offset] = value
1075}
1076
1077function _writeUInt16 (buf, value, offset, littleEndian, noAssert) {
1078 if (!noAssert) {
1079 assert(value !== undefined && value !== null, 'missing value')
1080 assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
1081 assert(offset !== undefined && offset !== null, 'missing offset')
1082 assert(offset + 1 < buf.length, 'trying to write beyond buffer length')
1083 verifuint(value, 0xffff)
1084 }
1085
1086 var len = buf.length
1087 if (offset >= len)
1088 return
1089
1090 for (var i = 0, j = Math.min(len - offset, 2); i < j; i++) {
1091 buf[offset + i] =
1092 (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
1093 (littleEndian ? i : 1 - i) * 8
1094 }
1095}
1096
1097Buffer.prototype.writeUInt16LE = function (value, offset, noAssert) {
1098 _writeUInt16(this, value, offset, true, noAssert)
1099}
1100
1101Buffer.prototype.writeUInt16BE = function (value, offset, noAssert) {
1102 _writeUInt16(this, value, offset, false, noAssert)
1103}
1104
1105function _writeUInt32 (buf, value, offset, littleEndian, noAssert) {
1106 if (!noAssert) {
1107 assert(value !== undefined && value !== null, 'missing value')
1108 assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
1109 assert(offset !== undefined && offset !== null, 'missing offset')
1110 assert(offset + 3 < buf.length, 'trying to write beyond buffer length')
1111 verifuint(value, 0xffffffff)
1112 }
1113
1114 var len = buf.length
1115 if (offset >= len)
1116 return
1117
1118 for (var i = 0, j = Math.min(len - offset, 4); i < j; i++) {
1119 buf[offset + i] =
1120 (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff
1121 }
1122}
1123
1124Buffer.prototype.writeUInt32LE = function (value, offset, noAssert) {
1125 _writeUInt32(this, value, offset, true, noAssert)
1126}
1127
1128Buffer.prototype.writeUInt32BE = function (value, offset, noAssert) {
1129 _writeUInt32(this, value, offset, false, noAssert)
1130}
1131
1132Buffer.prototype.writeInt8 = function (value, offset, noAssert) {
1133 if (!noAssert) {
1134 assert(value !== undefined && value !== null, 'missing value')
1135 assert(offset !== undefined && offset !== null, 'missing offset')
1136 assert(offset < this.length, 'Trying to write beyond buffer length')
1137 verifsint(value, 0x7f, -0x80)
1138 }
1139
1140 if (offset >= this.length)
1141 return
1142
1143 if (value >= 0)
1144 this.writeUInt8(value, offset, noAssert)
1145 else
1146 this.writeUInt8(0xff + value + 1, offset, noAssert)
1147}
1148
1149function _writeInt16 (buf, value, offset, littleEndian, noAssert) {
1150 if (!noAssert) {
1151 assert(value !== undefined && value !== null, 'missing value')
1152 assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
1153 assert(offset !== undefined && offset !== null, 'missing offset')
1154 assert(offset + 1 < buf.length, 'Trying to write beyond buffer length')
1155 verifsint(value, 0x7fff, -0x8000)
1156 }
1157
1158 var len = buf.length
1159 if (offset >= len)
1160 return
1161
1162 if (value >= 0)
1163 _writeUInt16(buf, value, offset, littleEndian, noAssert)
1164 else
1165 _writeUInt16(buf, 0xffff + value + 1, offset, littleEndian, noAssert)
1166}
1167
1168Buffer.prototype.writeInt16LE = function (value, offset, noAssert) {
1169 _writeInt16(this, value, offset, true, noAssert)
1170}
1171
1172Buffer.prototype.writeInt16BE = function (value, offset, noAssert) {
1173 _writeInt16(this, value, offset, false, noAssert)
1174}
1175
1176function _writeInt32 (buf, value, offset, littleEndian, noAssert) {
1177 if (!noAssert) {
1178 assert(value !== undefined && value !== null, 'missing value')
1179 assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
1180 assert(offset !== undefined && offset !== null, 'missing offset')
1181 assert(offset + 3 < buf.length, 'Trying to write beyond buffer length')
1182 verifsint(value, 0x7fffffff, -0x80000000)
1183 }
1184
1185 var len = buf.length
1186 if (offset >= len)
1187 return
1188
1189 if (value >= 0)
1190 _writeUInt32(buf, value, offset, littleEndian, noAssert)
1191 else
1192 _writeUInt32(buf, 0xffffffff + value + 1, offset, littleEndian, noAssert)
1193}
1194
1195Buffer.prototype.writeInt32LE = function (value, offset, noAssert) {
1196 _writeInt32(this, value, offset, true, noAssert)
1197}
1198
1199Buffer.prototype.writeInt32BE = function (value, offset, noAssert) {
1200 _writeInt32(this, value, offset, false, noAssert)
1201}
1202
1203function _writeFloat (buf, value, offset, littleEndian, noAssert) {
1204 if (!noAssert) {
1205 assert(value !== undefined && value !== null, 'missing value')
1206 assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
1207 assert(offset !== undefined && offset !== null, 'missing offset')
1208 assert(offset + 3 < buf.length, 'Trying to write beyond buffer length')
1209 verifIEEE754(value, 3.4028234663852886e+38, -3.4028234663852886e+38)
1210 }
1211
1212 var len = buf.length
1213 if (offset >= len)
1214 return
1215
1216 ieee754.write(buf, value, offset, littleEndian, 23, 4)
1217}
1218
1219Buffer.prototype.writeFloatLE = function (value, offset, noAssert) {
1220 _writeFloat(this, value, offset, true, noAssert)
1221}
1222
1223Buffer.prototype.writeFloatBE = function (value, offset, noAssert) {
1224 _writeFloat(this, value, offset, false, noAssert)
1225}
1226
1227function _writeDouble (buf, value, offset, littleEndian, noAssert) {
1228 if (!noAssert) {
1229 assert(value !== undefined && value !== null, 'missing value')
1230 assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
1231 assert(offset !== undefined && offset !== null, 'missing offset')
1232 assert(offset + 7 < buf.length,
1233 'Trying to write beyond buffer length')
1234 verifIEEE754(value, 1.7976931348623157E+308, -1.7976931348623157E+308)
1235 }
1236
1237 var len = buf.length
1238 if (offset >= len)
1239 return
1240
1241 ieee754.write(buf, value, offset, littleEndian, 52, 8)
1242}
1243
1244Buffer.prototype.writeDoubleLE = function (value, offset, noAssert) {
1245 _writeDouble(this, value, offset, true, noAssert)
1246}
1247
1248Buffer.prototype.writeDoubleBE = function (value, offset, noAssert) {
1249 _writeDouble(this, value, offset, false, noAssert)
1250}
1251
1252// fill(value, start=0, end=buffer.length)
1253Buffer.prototype.fill = function (value, start, end) {
1254 if (!value) value = 0
1255 if (!start) start = 0
1256 if (!end) end = this.length
1257
1258 if (typeof value === 'string') {
1259 value = value.charCodeAt(0)
1260 }
1261
1262 assert(typeof value === 'number' && !isNaN(value), 'value is not a number')
1263 assert(end >= start, 'end < start')
1264
1265 // Fill 0 bytes; we're done
1266 if (end === start) return
1267 if (this.length === 0) return
1268
1269 assert(start >= 0 && start < this.length, 'start out of bounds')
1270 assert(end >= 0 && end <= this.length, 'end out of bounds')
1271
1272 for (var i = start; i < end; i++) {
1273 this[i] = value
1274 }
1275}
1276
1277Buffer.prototype.inspect = function () {
1278 var out = []
1279 var len = this.length
1280 for (var i = 0; i < len; i++) {
1281 out[i] = toHex(this[i])
1282 if (i === exports.INSPECT_MAX_BYTES) {
1283 out[i + 1] = '...'
1284 break
1285 }
1286 }
1287 return '<Buffer ' + out.join(' ') + '>'
1288}
1289
1290/**
1291 * Creates a new `ArrayBuffer` with the *copied* memory of the buffer instance.
1292 * Added in Node 0.12. Only available in browsers that support ArrayBuffer.
1293 */
1294Buffer.prototype.toArrayBuffer = function () {
1295 if (typeof Uint8Array === 'function') {
1296 if (Buffer._useTypedArrays) {
1297 return (new Buffer(this)).buffer
1298 } else {
1299 var buf = new Uint8Array(this.length)
1300 for (var i = 0, len = buf.length; i < len; i += 1)
1301 buf[i] = this[i]
1302 return buf.buffer
1303 }
1304 } else {
1305 throw new Error('Buffer.toArrayBuffer not supported in this browser')
1306 }
1307}
1308
1309// HELPER FUNCTIONS
1310// ================
1311
1312function stringtrim (str) {
1313 if (str.trim) return str.trim()
1314 return str.replace(/^\s+|\s+$/g, '')
1315}
1316
1317var BP = Buffer.prototype
1318
1319/**
1320 * Augment the Uint8Array *instance* (not the class!) with Buffer methods
1321 */
1322function augment (arr) {
1323 arr._isBuffer = true
1324
1325 // save reference to original Uint8Array get/set methods before overwriting
1326 arr._get = arr.get
1327 arr._set = arr.set
1328
1329 // deprecated, will be removed in node 0.13+
1330 arr.get = BP.get
1331 arr.set = BP.set
1332
1333 arr.write = BP.write
1334 arr.toString = BP.toString
1335 arr.toLocaleString = BP.toString
1336 arr.toJSON = BP.toJSON
1337 arr.copy = BP.copy
1338 arr.slice = BP.slice
1339 arr.readUInt8 = BP.readUInt8
1340 arr.readUInt16LE = BP.readUInt16LE
1341 arr.readUInt16BE = BP.readUInt16BE
1342 arr.readUInt32LE = BP.readUInt32LE
1343 arr.readUInt32BE = BP.readUInt32BE
1344 arr.readInt8 = BP.readInt8
1345 arr.readInt16LE = BP.readInt16LE
1346 arr.readInt16BE = BP.readInt16BE
1347 arr.readInt32LE = BP.readInt32LE
1348 arr.readInt32BE = BP.readInt32BE
1349 arr.readFloatLE = BP.readFloatLE
1350 arr.readFloatBE = BP.readFloatBE
1351 arr.readDoubleLE = BP.readDoubleLE
1352 arr.readDoubleBE = BP.readDoubleBE
1353 arr.writeUInt8 = BP.writeUInt8
1354 arr.writeUInt16LE = BP.writeUInt16LE
1355 arr.writeUInt16BE = BP.writeUInt16BE
1356 arr.writeUInt32LE = BP.writeUInt32LE
1357 arr.writeUInt32BE = BP.writeUInt32BE
1358 arr.writeInt8 = BP.writeInt8
1359 arr.writeInt16LE = BP.writeInt16LE
1360 arr.writeInt16BE = BP.writeInt16BE
1361 arr.writeInt32LE = BP.writeInt32LE
1362 arr.writeInt32BE = BP.writeInt32BE
1363 arr.writeFloatLE = BP.writeFloatLE
1364 arr.writeFloatBE = BP.writeFloatBE
1365 arr.writeDoubleLE = BP.writeDoubleLE
1366 arr.writeDoubleBE = BP.writeDoubleBE
1367 arr.fill = BP.fill
1368 arr.inspect = BP.inspect
1369 arr.toArrayBuffer = BP.toArrayBuffer
1370
1371 return arr
1372}
1373
1374// slice(start, end)
1375function clamp (index, len, defaultValue) {
1376 if (typeof index !== 'number') return defaultValue
1377 index = ~~index; // Coerce to integer.
1378 if (index >= len) return len
1379 if (index >= 0) return index
1380 index += len
1381 if (index >= 0) return index
1382 return 0
1383}
1384
1385function coerce (length) {
1386 // Coerce length to a number (possibly NaN), round up
1387 // in case it's fractional (e.g. 123.456) then do a
1388 // double negate to coerce a NaN to 0. Easy, right?
1389 length = ~~Math.ceil(+length)
1390 return length < 0 ? 0 : length
1391}
1392
1393function isArray (subject) {
1394 return (Array.isArray || function (subject) {
1395 return Object.prototype.toString.call(subject) === '[object Array]'
1396 })(subject)
1397}
1398
1399function isArrayish (subject) {
1400 return isArray(subject) || Buffer.isBuffer(subject) ||
1401 subject && typeof subject === 'object' &&
1402 typeof subject.length === 'number'
1403}
1404
1405function toHex (n) {
1406 if (n < 16) return '0' + n.toString(16)
1407 return n.toString(16)
1408}
1409
1410function utf8ToBytes (str) {
1411 var byteArray = []
1412 for (var i = 0; i < str.length; i++) {
1413 var b = str.charCodeAt(i)
1414 if (b <= 0x7F)
1415 byteArray.push(str.charCodeAt(i))
1416 else {
1417 var start = i
1418 if (b >= 0xD800 && b <= 0xDFFF) i++
1419 var h = encodeURIComponent(str.slice(start, i+1)).substr(1).split('%')
1420 for (var j = 0; j < h.length; j++)
1421 byteArray.push(parseInt(h[j], 16))
1422 }
1423 }
1424 return byteArray
1425}
1426
1427function asciiToBytes (str) {
1428 var byteArray = []
1429 for (var i = 0; i < str.length; i++) {
1430 // Node's code seems to be doing this and not & 0x7F..
1431 byteArray.push(str.charCodeAt(i) & 0xFF)
1432 }
1433 return byteArray
1434}
1435
1436function utf16leToBytes (str) {
1437 var c, hi, lo
1438 var byteArray = []
1439 for (var i = 0; i < str.length; i++) {
1440 c = str.charCodeAt(i)
1441 hi = c >> 8
1442 lo = c % 256
1443 byteArray.push(lo)
1444 byteArray.push(hi)
1445 }
1446
1447 return byteArray
1448}
1449
1450function base64ToBytes (str) {
1451 return base64.toByteArray(str)
1452}
1453
1454function blitBuffer (src, dst, offset, length) {
1455 var pos
1456 for (var i = 0; i < length; i++) {
1457 if ((i + offset >= dst.length) || (i >= src.length))
1458 break
1459 dst[i + offset] = src[i]
1460 }
1461 return i
1462}
1463
1464function decodeUtf8Char (str) {
1465 try {
1466 return decodeURIComponent(str)
1467 } catch (err) {
1468 return String.fromCharCode(0xFFFD) // UTF 8 invalid char
1469 }
1470}
1471
1472/*
1473 * We have to make sure that the value is a valid integer. This means that it
1474 * is non-negative. It has no fractional component and that it does not
1475 * exceed the maximum allowed value.
1476 */
1477function verifuint (value, max) {
1478 assert(typeof value === 'number', 'cannot write a non-number as a number')
1479 assert(value >= 0, 'specified a negative value for writing an unsigned value')
1480 assert(value <= max, 'value is larger than maximum value for type')
1481 assert(Math.floor(value) === value, 'value has a fractional component')
1482}
1483
1484function verifsint (value, max, min) {
1485 assert(typeof value === 'number', 'cannot write a non-number as a number')
1486 assert(value <= max, 'value larger than maximum allowed value')
1487 assert(value >= min, 'value smaller than minimum allowed value')
1488 assert(Math.floor(value) === value, 'value has a fractional component')
1489}
1490
1491function verifIEEE754 (value, max, min) {
1492 assert(typeof value === 'number', 'cannot write a non-number as a number')
1493 assert(value <= max, 'value larger than maximum allowed value')
1494 assert(value >= min, 'value smaller than minimum allowed value')
1495}
1496
1497function assert (test, message) {
1498 if (!test) throw new Error(message || 'Failed assertion')
1499}
1500
1501},{"base64-js":5,"ieee754":6}],5:[function(require,module,exports){
1502var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
1503
1504;(function (exports) {
1505 'use strict';
1506
1507 var Arr = (typeof Uint8Array !== 'undefined')
1508 ? Uint8Array
1509 : Array
1510
1511 var ZERO = '0'.charCodeAt(0)
1512 var PLUS = '+'.charCodeAt(0)
1513 var SLASH = '/'.charCodeAt(0)
1514 var NUMBER = '0'.charCodeAt(0)
1515 var LOWER = 'a'.charCodeAt(0)
1516 var UPPER = 'A'.charCodeAt(0)
1517
1518 function decode (elt) {
1519 var code = elt.charCodeAt(0)
1520 if (code === PLUS)
1521 return 62 // '+'
1522 if (code === SLASH)
1523 return 63 // '/'
1524 if (code < NUMBER)
1525 return -1 //no match
1526 if (code < NUMBER + 10)
1527 return code - NUMBER + 26 + 26
1528 if (code < UPPER + 26)
1529 return code - UPPER
1530 if (code < LOWER + 26)
1531 return code - LOWER + 26
1532 }
1533
1534 function b64ToByteArray (b64) {
1535 var i, j, l, tmp, placeHolders, arr
1536
1537 if (b64.length % 4 > 0) {
1538 throw new Error('Invalid string. Length must be a multiple of 4')
1539 }
1540
1541 // the number of equal signs (place holders)
1542 // if there are two placeholders, than the two characters before it
1543 // represent one byte
1544 // if there is only one, then the three characters before it represent 2 bytes
1545 // this is just a cheap hack to not do indexOf twice
1546 var len = b64.length
1547 placeHolders = '=' === b64.charAt(len - 2) ? 2 : '=' === b64.charAt(len - 1) ? 1 : 0
1548
1549 // base64 is 4/3 + up to two characters of the original data
1550 arr = new Arr(b64.length * 3 / 4 - placeHolders)
1551
1552 // if there are placeholders, only get up to the last complete 4 chars
1553 l = placeHolders > 0 ? b64.length - 4 : b64.length
1554
1555 var L = 0
1556
1557 function push (v) {
1558 arr[L++] = v
1559 }
1560
1561 for (i = 0, j = 0; i < l; i += 4, j += 3) {
1562 tmp = (decode(b64.charAt(i)) << 18) | (decode(b64.charAt(i + 1)) << 12) | (decode(b64.charAt(i + 2)) << 6) | decode(b64.charAt(i + 3))
1563 push((tmp & 0xFF0000) >> 16)
1564 push((tmp & 0xFF00) >> 8)
1565 push(tmp & 0xFF)
1566 }
1567
1568 if (placeHolders === 2) {
1569 tmp = (decode(b64.charAt(i)) << 2) | (decode(b64.charAt(i + 1)) >> 4)
1570 push(tmp & 0xFF)
1571 } else if (placeHolders === 1) {
1572 tmp = (decode(b64.charAt(i)) << 10) | (decode(b64.charAt(i + 1)) << 4) | (decode(b64.charAt(i + 2)) >> 2)
1573 push((tmp >> 8) & 0xFF)
1574 push(tmp & 0xFF)
1575 }
1576
1577 return arr
1578 }
1579
1580 function uint8ToBase64 (uint8) {
1581 var i,
1582 extraBytes = uint8.length % 3, // if we have 1 byte left, pad 2 bytes
1583 output = "",
1584 temp, length
1585
1586 function encode (num) {
1587 return lookup.charAt(num)
1588 }
1589
1590 function tripletToBase64 (num) {
1591 return encode(num >> 18 & 0x3F) + encode(num >> 12 & 0x3F) + encode(num >> 6 & 0x3F) + encode(num & 0x3F)
1592 }
1593
1594 // go through the array every three bytes, we'll deal with trailing stuff later
1595 for (i = 0, length = uint8.length - extraBytes; i < length; i += 3) {
1596 temp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2])
1597 output += tripletToBase64(temp)
1598 }
1599
1600 // pad the end with zeros, but make sure to not forget the extra bytes
1601 switch (extraBytes) {
1602 case 1:
1603 temp = uint8[uint8.length - 1]
1604 output += encode(temp >> 2)
1605 output += encode((temp << 4) & 0x3F)
1606 output += '=='
1607 break
1608 case 2:
1609 temp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1])
1610 output += encode(temp >> 10)
1611 output += encode((temp >> 4) & 0x3F)
1612 output += encode((temp << 2) & 0x3F)
1613 output += '='
1614 break
1615 }
1616
1617 return output
1618 }
1619
1620 module.exports.toByteArray = b64ToByteArray
1621 module.exports.fromByteArray = uint8ToBase64
1622}())
1623
1624},{}],6:[function(require,module,exports){
1625exports.read = function(buffer, offset, isLE, mLen, nBytes) {
1626 var e, m,
1627 eLen = nBytes * 8 - mLen - 1,
1628 eMax = (1 << eLen) - 1,
1629 eBias = eMax >> 1,
1630 nBits = -7,
1631 i = isLE ? (nBytes - 1) : 0,
1632 d = isLE ? -1 : 1,
1633 s = buffer[offset + i];
1634
1635 i += d;
1636
1637 e = s & ((1 << (-nBits)) - 1);
1638 s >>= (-nBits);
1639 nBits += eLen;
1640 for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8);
1641
1642 m = e & ((1 << (-nBits)) - 1);
1643 e >>= (-nBits);
1644 nBits += mLen;
1645 for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8);
1646
1647 if (e === 0) {
1648 e = 1 - eBias;
1649 } else if (e === eMax) {
1650 return m ? NaN : ((s ? -1 : 1) * Infinity);
1651 } else {
1652 m = m + Math.pow(2, mLen);
1653 e = e - eBias;
1654 }
1655 return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
1656};
1657
1658exports.write = function(buffer, value, offset, isLE, mLen, nBytes) {
1659 var e, m, c,
1660 eLen = nBytes * 8 - mLen - 1,
1661 eMax = (1 << eLen) - 1,
1662 eBias = eMax >> 1,
1663 rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0),
1664 i = isLE ? 0 : (nBytes - 1),
1665 d = isLE ? 1 : -1,
1666 s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
1667
1668 value = Math.abs(value);
1669
1670 if (isNaN(value) || value === Infinity) {
1671 m = isNaN(value) ? 1 : 0;
1672 e = eMax;
1673 } else {
1674 e = Math.floor(Math.log(value) / Math.LN2);
1675 if (value * (c = Math.pow(2, -e)) < 1) {
1676 e--;
1677 c *= 2;
1678 }
1679 if (e + eBias >= 1) {
1680 value += rt / c;
1681 } else {
1682 value += rt * Math.pow(2, 1 - eBias);
1683 }
1684 if (value * c >= 2) {
1685 e++;
1686 c /= 2;
1687 }
1688
1689 if (e + eBias >= eMax) {
1690 m = 0;
1691 e = eMax;
1692 } else if (e + eBias >= 1) {
1693 m = (value * c - 1) * Math.pow(2, mLen);
1694 e = e + eBias;
1695 } else {
1696 m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
1697 e = 0;
1698 }
1699 }
1700
1701 for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8);
1702
1703 e = (e << mLen) | m;
1704 eLen += mLen;
1705 for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8);
1706
1707 buffer[offset + i - d] |= s * 128;
1708};
1709
1710},{}],7:[function(require,module,exports){
1711var Buffer = require('buffer').Buffer;
1712var intSize = 4;
1713var zeroBuffer = new Buffer(intSize); zeroBuffer.fill(0);
1714var chrsz = 8;
1715
1716function toArray(buf, bigEndian) {
1717 if ((buf.length % intSize) !== 0) {
1718 var len = buf.length + (intSize - (buf.length % intSize));
1719 buf = Buffer.concat([buf, zeroBuffer], len);
1720 }
1721
1722 var arr = [];
1723 var fn = bigEndian ? buf.readInt32BE : buf.readInt32LE;
1724 for (var i = 0; i < buf.length; i += intSize) {
1725 arr.push(fn.call(buf, i));
1726 }
1727 return arr;
1728}
1729
1730function toBuffer(arr, size, bigEndian) {
1731 var buf = new Buffer(size);
1732 var fn = bigEndian ? buf.writeInt32BE : buf.writeInt32LE;
1733 for (var i = 0; i < arr.length; i++) {
1734 fn.call(buf, arr[i], i * 4, true);
1735 }
1736 return buf;
1737}
1738
1739function hash(buf, fn, hashSize, bigEndian) {
1740 if (!Buffer.isBuffer(buf)) buf = new Buffer(buf);
1741 var arr = fn(toArray(buf, bigEndian), buf.length * chrsz);
1742 return toBuffer(arr, hashSize, bigEndian);
1743}
1744
1745module.exports = { hash: hash };
1746
1747},{"buffer":4}],8:[function(require,module,exports){
1748var Buffer = require('buffer').Buffer
1749var sha = require('./sha')
1750var sha256 = require('./sha256')
1751var rng = require('./rng')
1752var md5 = require('./md5')
1753
1754var algorithms = {
1755 sha1: sha,
1756 sha256: sha256,
1757 md5: md5
1758}
1759
1760var blocksize = 64
1761var zeroBuffer = new Buffer(blocksize); zeroBuffer.fill(0)
1762function hmac(fn, key, data) {
1763 if(!Buffer.isBuffer(key)) key = new Buffer(key)
1764 if(!Buffer.isBuffer(data)) data = new Buffer(data)
1765
1766 if(key.length > blocksize) {
1767 key = fn(key)
1768 } else if(key.length < blocksize) {
1769 key = Buffer.concat([key, zeroBuffer], blocksize)
1770 }
1771
1772 var ipad = new Buffer(blocksize), opad = new Buffer(blocksize)
1773 for(var i = 0; i < blocksize; i++) {
1774 ipad[i] = key[i] ^ 0x36
1775 opad[i] = key[i] ^ 0x5C
1776 }
1777
1778 var hash = fn(Buffer.concat([ipad, data]))
1779 return fn(Buffer.concat([opad, hash]))
1780}
1781
1782function hash(alg, key) {
1783 alg = alg || 'sha1'
1784 var fn = algorithms[alg]
1785 var bufs = []
1786 var length = 0
1787 if(!fn) error('algorithm:', alg, 'is not yet supported')
1788 return {
1789 update: function (data) {
1790 if(!Buffer.isBuffer(data)) data = new Buffer(data)
1791
1792 bufs.push(data)
1793 length += data.length
1794 return this
1795 },
1796 digest: function (enc) {
1797 var buf = Buffer.concat(bufs)
1798 var r = key ? hmac(fn, key, buf) : fn(buf)
1799 bufs = null
1800 return enc ? r.toString(enc) : r
1801 }
1802 }
1803}
1804
1805function error () {
1806 var m = [].slice.call(arguments).join(' ')
1807 throw new Error([
1808 m,
1809 'we accept pull requests',
1810 'http://github.com/dominictarr/crypto-browserify'
1811 ].join('\n'))
1812}
1813
1814exports.createHash = function (alg) { return hash(alg) }
1815exports.createHmac = function (alg, key) { return hash(alg, key) }
1816exports.randomBytes = function(size, callback) {
1817 if (callback && callback.call) {
1818 try {
1819 callback.call(this, undefined, new Buffer(rng(size)))
1820 } catch (err) { callback(err) }
1821 } else {
1822 return new Buffer(rng(size))
1823 }
1824}
1825
1826function each(a, f) {
1827 for(var i in a)
1828 f(a[i], i)
1829}
1830
1831// the least I can do is make error messages for the rest of the node.js/crypto api.
1832each(['createCredentials'
1833, 'createCipher'
1834, 'createCipheriv'
1835, 'createDecipher'
1836, 'createDecipheriv'
1837, 'createSign'
1838, 'createVerify'
1839, 'createDiffieHellman'
1840, 'pbkdf2'], function (name) {
1841 exports[name] = function () {
1842 error('sorry,', name, 'is not implemented yet')
1843 }
1844})
1845
1846},{"./md5":9,"./rng":10,"./sha":11,"./sha256":12,"buffer":4}],9:[function(require,module,exports){
1847/*
1848 * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
1849 * Digest Algorithm, as defined in RFC 1321.
1850 * Version 2.1 Copyright (C) Paul Johnston 1999 - 2002.
1851 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
1852 * Distributed under the BSD License
1853 * See http://pajhome.org.uk/crypt/md5 for more info.
1854 */
1855
1856var helpers = require('./helpers');
1857
1858/*
1859 * Perform a simple self-test to see if the VM is working
1860 */
1861function md5_vm_test()
1862{
1863 return hex_md5("abc") == "900150983cd24fb0d6963f7d28e17f72";
1864}
1865
1866/*
1867 * Calculate the MD5 of an array of little-endian words, and a bit length
1868 */
1869function core_md5(x, len)
1870{
1871 /* append padding */
1872 x[len >> 5] |= 0x80 << ((len) % 32);
1873 x[(((len + 64) >>> 9) << 4) + 14] = len;
1874
1875 var a = 1732584193;
1876 var b = -271733879;
1877 var c = -1732584194;
1878 var d = 271733878;
1879
1880 for(var i = 0; i < x.length; i += 16)
1881 {
1882 var olda = a;
1883 var oldb = b;
1884 var oldc = c;
1885 var oldd = d;
1886
1887 a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);
1888 d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);
1889 c = md5_ff(c, d, a, b, x[i+ 2], 17, 606105819);
1890 b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);
1891 a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);
1892 d = md5_ff(d, a, b, c, x[i+ 5], 12, 1200080426);
1893 c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341);
1894 b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983);
1895 a = md5_ff(a, b, c, d, x[i+ 8], 7 , 1770035416);
1896 d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417);
1897 c = md5_ff(c, d, a, b, x[i+10], 17, -42063);
1898 b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);
1899 a = md5_ff(a, b, c, d, x[i+12], 7 , 1804603682);
1900 d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);
1901 c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);
1902 b = md5_ff(b, c, d, a, x[i+15], 22, 1236535329);
1903
1904 a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);
1905 d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
1906 c = md5_gg(c, d, a, b, x[i+11], 14, 643717713);
1907 b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);
1908 a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);
1909 d = md5_gg(d, a, b, c, x[i+10], 9 , 38016083);
1910 c = md5_gg(c, d, a, b, x[i+15], 14, -660478335);
1911 b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848);
1912 a = md5_gg(a, b, c, d, x[i+ 9], 5 , 568446438);
1913 d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690);
1914 c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961);
1915 b = md5_gg(b, c, d, a, x[i+ 8], 20, 1163531501);
1916 a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);
1917 d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);
1918 c = md5_gg(c, d, a, b, x[i+ 7], 14, 1735328473);
1919 b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);
1920
1921 a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);
1922 d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);
1923 c = md5_hh(c, d, a, b, x[i+11], 16, 1839030562);
1924 b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);
1925 a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
1926 d = md5_hh(d, a, b, c, x[i+ 4], 11, 1272893353);
1927 c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632);
1928 b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640);
1929 a = md5_hh(a, b, c, d, x[i+13], 4 , 681279174);
1930 d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222);
1931 c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979);
1932 b = md5_hh(b, c, d, a, x[i+ 6], 23, 76029189);
1933 a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);
1934 d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);
1935 c = md5_hh(c, d, a, b, x[i+15], 16, 530742520);
1936 b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);
1937
1938 a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);
1939 d = md5_ii(d, a, b, c, x[i+ 7], 10, 1126891415);
1940 c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);
1941 b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);
1942 a = md5_ii(a, b, c, d, x[i+12], 6 , 1700485571);
1943 d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606);
1944 c = md5_ii(c, d, a, b, x[i+10], 15, -1051523);
1945 b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799);
1946 a = md5_ii(a, b, c, d, x[i+ 8], 6 , 1873313359);
1947 d = md5_ii(d, a, b, c, x[i+15], 10, -30611744);
1948 c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380);
1949 b = md5_ii(b, c, d, a, x[i+13], 21, 1309151649);
1950 a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);
1951 d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);
1952 c = md5_ii(c, d, a, b, x[i+ 2], 15, 718787259);
1953 b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);
1954
1955 a = safe_add(a, olda);
1956 b = safe_add(b, oldb);
1957 c = safe_add(c, oldc);
1958 d = safe_add(d, oldd);
1959 }
1960 return Array(a, b, c, d);
1961
1962}
1963
1964/*
1965 * These functions implement the four basic operations the algorithm uses.
1966 */
1967function md5_cmn(q, a, b, x, s, t)
1968{
1969 return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b);
1970}
1971function md5_ff(a, b, c, d, x, s, t)
1972{
1973 return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
1974}
1975function md5_gg(a, b, c, d, x, s, t)
1976{
1977 return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
1978}
1979function md5_hh(a, b, c, d, x, s, t)
1980{
1981 return md5_cmn(b ^ c ^ d, a, b, x, s, t);
1982}
1983function md5_ii(a, b, c, d, x, s, t)
1984{
1985 return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
1986}
1987
1988/*
1989 * Add integers, wrapping at 2^32. This uses 16-bit operations internally
1990 * to work around bugs in some JS interpreters.
1991 */
1992function safe_add(x, y)
1993{
1994 var lsw = (x & 0xFFFF) + (y & 0xFFFF);
1995 var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
1996 return (msw << 16) | (lsw & 0xFFFF);
1997}
1998
1999/*
2000 * Bitwise rotate a 32-bit number to the left.
2001 */
2002function bit_rol(num, cnt)
2003{
2004 return (num << cnt) | (num >>> (32 - cnt));
2005}
2006
2007module.exports = function md5(buf) {
2008 return helpers.hash(buf, core_md5, 16);
2009};
2010
2011},{"./helpers":7}],10:[function(require,module,exports){
2012// Original code adapted from Robert Kieffer.
2013// details at https://github.com/broofa/node-uuid
2014(function() {
2015 var _global = this;
2016
2017 var mathRNG, whatwgRNG;
2018
2019 // NOTE: Math.random() does not guarantee "cryptographic quality"
2020 mathRNG = function(size) {
2021 var bytes = new Array(size);
2022 var r;
2023
2024 for (var i = 0, r; i < size; i++) {
2025 if ((i & 0x03) == 0) r = Math.random() * 0x100000000;
2026 bytes[i] = r >>> ((i & 0x03) << 3) & 0xff;
2027 }
2028
2029 return bytes;
2030 }
2031
2032 if (_global.crypto && crypto.getRandomValues) {
2033 whatwgRNG = function(size) {
2034 var bytes = new Uint8Array(size);
2035 crypto.getRandomValues(bytes);
2036 return bytes;
2037 }
2038 }
2039
2040 module.exports = whatwgRNG || mathRNG;
2041
2042}())
2043
2044},{}],11:[function(require,module,exports){
2045/*
2046 * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
2047 * in FIPS PUB 180-1
2048 * Version 2.1a Copyright Paul Johnston 2000 - 2002.
2049 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
2050 * Distributed under the BSD License
2051 * See http://pajhome.org.uk/crypt/md5 for details.
2052 */
2053
2054var helpers = require('./helpers');
2055
2056/*
2057 * Calculate the SHA-1 of an array of big-endian words, and a bit length
2058 */
2059function core_sha1(x, len)
2060{
2061 /* append padding */
2062 x[len >> 5] |= 0x80 << (24 - len % 32);
2063 x[((len + 64 >> 9) << 4) + 15] = len;
2064
2065 var w = Array(80);
2066 var a = 1732584193;
2067 var b = -271733879;
2068 var c = -1732584194;
2069 var d = 271733878;
2070 var e = -1009589776;
2071
2072 for(var i = 0; i < x.length; i += 16)
2073 {
2074 var olda = a;
2075 var oldb = b;
2076 var oldc = c;
2077 var oldd = d;
2078 var olde = e;
2079
2080 for(var j = 0; j < 80; j++)
2081 {
2082 if(j < 16) w[j] = x[i + j];
2083 else w[j] = rol(w[j-3] ^ w[j-8] ^ w[j-14] ^ w[j-16], 1);
2084 var t = safe_add(safe_add(rol(a, 5), sha1_ft(j, b, c, d)),
2085 safe_add(safe_add(e, w[j]), sha1_kt(j)));
2086 e = d;
2087 d = c;
2088 c = rol(b, 30);
2089 b = a;
2090 a = t;
2091 }
2092
2093 a = safe_add(a, olda);
2094 b = safe_add(b, oldb);
2095 c = safe_add(c, oldc);
2096 d = safe_add(d, oldd);
2097 e = safe_add(e, olde);
2098 }
2099 return Array(a, b, c, d, e);
2100
2101}
2102
2103/*
2104 * Perform the appropriate triplet combination function for the current
2105 * iteration
2106 */
2107function sha1_ft(t, b, c, d)
2108{
2109 if(t < 20) return (b & c) | ((~b) & d);
2110 if(t < 40) return b ^ c ^ d;
2111 if(t < 60) return (b & c) | (b & d) | (c & d);
2112 return b ^ c ^ d;
2113}
2114
2115/*
2116 * Determine the appropriate additive constant for the current iteration
2117 */
2118function sha1_kt(t)
2119{
2120 return (t < 20) ? 1518500249 : (t < 40) ? 1859775393 :
2121 (t < 60) ? -1894007588 : -899497514;
2122}
2123
2124/*
2125 * Add integers, wrapping at 2^32. This uses 16-bit operations internally
2126 * to work around bugs in some JS interpreters.
2127 */
2128function safe_add(x, y)
2129{
2130 var lsw = (x & 0xFFFF) + (y & 0xFFFF);
2131 var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
2132 return (msw << 16) | (lsw & 0xFFFF);
2133}
2134
2135/*
2136 * Bitwise rotate a 32-bit number to the left.
2137 */
2138function rol(num, cnt)
2139{
2140 return (num << cnt) | (num >>> (32 - cnt));
2141}
2142
2143module.exports = function sha1(buf) {
2144 return helpers.hash(buf, core_sha1, 20, true);
2145};
2146
2147},{"./helpers":7}],12:[function(require,module,exports){
2148
2149/**
2150 * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined
2151 * in FIPS 180-2
2152 * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009.
2153 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
2154 *
2155 */
2156
2157var helpers = require('./helpers');
2158
2159var safe_add = function(x, y) {
2160 var lsw = (x & 0xFFFF) + (y & 0xFFFF);
2161 var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
2162 return (msw << 16) | (lsw & 0xFFFF);
2163};
2164
2165var S = function(X, n) {
2166 return (X >>> n) | (X << (32 - n));
2167};
2168
2169var R = function(X, n) {
2170 return (X >>> n);
2171};
2172
2173var Ch = function(x, y, z) {
2174 return ((x & y) ^ ((~x) & z));
2175};
2176
2177var Maj = function(x, y, z) {
2178 return ((x & y) ^ (x & z) ^ (y & z));
2179};
2180
2181var Sigma0256 = function(x) {
2182 return (S(x, 2) ^ S(x, 13) ^ S(x, 22));
2183};
2184
2185var Sigma1256 = function(x) {
2186 return (S(x, 6) ^ S(x, 11) ^ S(x, 25));
2187};
2188
2189var Gamma0256 = function(x) {
2190 return (S(x, 7) ^ S(x, 18) ^ R(x, 3));
2191};
2192
2193var Gamma1256 = function(x) {
2194 return (S(x, 17) ^ S(x, 19) ^ R(x, 10));
2195};
2196
2197var core_sha256 = function(m, l) {
2198 var K = new Array(0x428A2F98,0x71374491,0xB5C0FBCF,0xE9B5DBA5,0x3956C25B,0x59F111F1,0x923F82A4,0xAB1C5ED5,0xD807AA98,0x12835B01,0x243185BE,0x550C7DC3,0x72BE5D74,0x80DEB1FE,0x9BDC06A7,0xC19BF174,0xE49B69C1,0xEFBE4786,0xFC19DC6,0x240CA1CC,0x2DE92C6F,0x4A7484AA,0x5CB0A9DC,0x76F988DA,0x983E5152,0xA831C66D,0xB00327C8,0xBF597FC7,0xC6E00BF3,0xD5A79147,0x6CA6351,0x14292967,0x27B70A85,0x2E1B2138,0x4D2C6DFC,0x53380D13,0x650A7354,0x766A0ABB,0x81C2C92E,0x92722C85,0xA2BFE8A1,0xA81A664B,0xC24B8B70,0xC76C51A3,0xD192E819,0xD6990624,0xF40E3585,0x106AA070,0x19A4C116,0x1E376C08,0x2748774C,0x34B0BCB5,0x391C0CB3,0x4ED8AA4A,0x5B9CCA4F,0x682E6FF3,0x748F82EE,0x78A5636F,0x84C87814,0x8CC70208,0x90BEFFFA,0xA4506CEB,0xBEF9A3F7,0xC67178F2);
2199 var HASH = new Array(0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A, 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19);
2200 var W = new Array(64);
2201 var a, b, c, d, e, f, g, h, i, j;
2202 var T1, T2;
2203 /* append padding */
2204 m[l >> 5] |= 0x80 << (24 - l % 32);
2205 m[((l + 64 >> 9) << 4) + 15] = l;
2206 for (var i = 0; i < m.length; i += 16) {
2207 a = HASH[0]; b = HASH[1]; c = HASH[2]; d = HASH[3]; e = HASH[4]; f = HASH[5]; g = HASH[6]; h = HASH[7];
2208 for (var j = 0; j < 64; j++) {
2209 if (j < 16) {
2210 W[j] = m[j + i];
2211 } else {
2212 W[j] = safe_add(safe_add(safe_add(Gamma1256(W[j - 2]), W[j - 7]), Gamma0256(W[j - 15])), W[j - 16]);
2213 }
2214 T1 = safe_add(safe_add(safe_add(safe_add(h, Sigma1256(e)), Ch(e, f, g)), K[j]), W[j]);
2215 T2 = safe_add(Sigma0256(a), Maj(a, b, c));
2216 h = g; g = f; f = e; e = safe_add(d, T1); d = c; c = b; b = a; a = safe_add(T1, T2);
2217 }
2218 HASH[0] = safe_add(a, HASH[0]); HASH[1] = safe_add(b, HASH[1]); HASH[2] = safe_add(c, HASH[2]); HASH[3] = safe_add(d, HASH[3]);
2219 HASH[4] = safe_add(e, HASH[4]); HASH[5] = safe_add(f, HASH[5]); HASH[6] = safe_add(g, HASH[6]); HASH[7] = safe_add(h, HASH[7]);
2220 }
2221 return HASH;
2222};
2223
2224module.exports = function sha256(buf) {
2225 return helpers.hash(buf, core_sha256, 32, true);
2226};
2227
2228},{"./helpers":7}],13:[function(require,module,exports){
2229// Copyright Joyent, Inc. and other Node contributors.
2230//
2231// Permission is hereby granted, free of charge, to any person obtaining a
2232// copy of this software and associated documentation files (the
2233// "Software"), to deal in the Software without restriction, including
2234// without limitation the rights to use, copy, modify, merge, publish,
2235// distribute, sublicense, and/or sell copies of the Software, and to permit
2236// persons to whom the Software is furnished to do so, subject to the
2237// following conditions:
2238//
2239// The above copyright notice and this permission notice shall be included
2240// in all copies or substantial portions of the Software.
2241//
2242// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
2243// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2244// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
2245// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
2246// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
2247// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
2248// USE OR OTHER DEALINGS IN THE SOFTWARE.
2249
2250function EventEmitter() {
2251 this._events = this._events || {};
2252 this._maxListeners = this._maxListeners || undefined;
2253}
2254module.exports = EventEmitter;
2255
2256// Backwards-compat with node 0.10.x
2257EventEmitter.EventEmitter = EventEmitter;
2258
2259EventEmitter.prototype._events = undefined;
2260EventEmitter.prototype._maxListeners = undefined;
2261
2262// By default EventEmitters will print a warning if more than 10 listeners are
2263// added to it. This is a useful default which helps finding memory leaks.
2264EventEmitter.defaultMaxListeners = 10;
2265
2266// Obviously not all Emitters should be limited to 10. This function allows
2267// that to be increased. Set to zero for unlimited.
2268EventEmitter.prototype.setMaxListeners = function(n) {
2269 if (!isNumber(n) || n < 0 || isNaN(n))
2270 throw TypeError('n must be a positive number');
2271 this._maxListeners = n;
2272 return this;
2273};
2274
2275EventEmitter.prototype.emit = function(type) {
2276 var er, handler, len, args, i, listeners;
2277
2278 if (!this._events)
2279 this._events = {};
2280
2281 // If there is no 'error' event listener then throw.
2282 if (type === 'error') {
2283 if (!this._events.error ||
2284 (isObject(this._events.error) && !this._events.error.length)) {
2285 er = arguments[1];
2286 if (er instanceof Error) {
2287 throw er; // Unhandled 'error' event
2288 } else {
2289 throw TypeError('Uncaught, unspecified "error" event.');
2290 }
2291 return false;
2292 }
2293 }
2294
2295 handler = this._events[type];
2296
2297 if (isUndefined(handler))
2298 return false;
2299
2300 if (isFunction(handler)) {
2301 switch (arguments.length) {
2302 // fast cases
2303 case 1:
2304 handler.call(this);
2305 break;
2306 case 2:
2307 handler.call(this, arguments[1]);
2308 break;
2309 case 3:
2310 handler.call(this, arguments[1], arguments[2]);
2311 break;
2312 // slower
2313 default:
2314 len = arguments.length;
2315 args = new Array(len - 1);
2316 for (i = 1; i < len; i++)
2317 args[i - 1] = arguments[i];
2318 handler.apply(this, args);
2319 }
2320 } else if (isObject(handler)) {
2321 len = arguments.length;
2322 args = new Array(len - 1);
2323 for (i = 1; i < len; i++)
2324 args[i - 1] = arguments[i];
2325
2326 listeners = handler.slice();
2327 len = listeners.length;
2328 for (i = 0; i < len; i++)
2329 listeners[i].apply(this, args);
2330 }
2331
2332 return true;
2333};
2334
2335EventEmitter.prototype.addListener = function(type, listener) {
2336 var m;
2337
2338 if (!isFunction(listener))
2339 throw TypeError('listener must be a function');
2340
2341 if (!this._events)
2342 this._events = {};
2343
2344 // To avoid recursion in the case that type === "newListener"! Before
2345 // adding it to the listeners, first emit "newListener".
2346 if (this._events.newListener)
2347 this.emit('newListener', type,
2348 isFunction(listener.listener) ?
2349 listener.listener : listener);
2350
2351 if (!this._events[type])
2352 // Optimize the case of one listener. Don't need the extra array object.
2353 this._events[type] = listener;
2354 else if (isObject(this._events[type]))
2355 // If we've already got an array, just append.
2356 this._events[type].push(listener);
2357 else
2358 // Adding the second element, need to change to array.
2359 this._events[type] = [this._events[type], listener];
2360
2361 // Check for listener leak
2362 if (isObject(this._events[type]) && !this._events[type].warned) {
2363 var m;
2364 if (!isUndefined(this._maxListeners)) {
2365 m = this._maxListeners;
2366 } else {
2367 m = EventEmitter.defaultMaxListeners;
2368 }
2369
2370 if (m && m > 0 && this._events[type].length > m) {
2371 this._events[type].warned = true;
2372 console.error('(node) warning: possible EventEmitter memory ' +
2373 'leak detected. %d listeners added. ' +
2374 'Use emitter.setMaxListeners() to increase limit.',
2375 this._events[type].length);
2376 console.trace();
2377 }
2378 }
2379
2380 return this;
2381};
2382
2383EventEmitter.prototype.on = EventEmitter.prototype.addListener;
2384
2385EventEmitter.prototype.once = function(type, listener) {
2386 if (!isFunction(listener))
2387 throw TypeError('listener must be a function');
2388
2389 var fired = false;
2390
2391 function g() {
2392 this.removeListener(type, g);
2393
2394 if (!fired) {
2395 fired = true;
2396 listener.apply(this, arguments);
2397 }
2398 }
2399
2400 g.listener = listener;
2401 this.on(type, g);
2402
2403 return this;
2404};
2405
2406// emits a 'removeListener' event iff the listener was removed
2407EventEmitter.prototype.removeListener = function(type, listener) {
2408 var list, position, length, i;
2409
2410 if (!isFunction(listener))
2411 throw TypeError('listener must be a function');
2412
2413 if (!this._events || !this._events[type])
2414 return this;
2415
2416 list = this._events[type];
2417 length = list.length;
2418 position = -1;
2419
2420 if (list === listener ||
2421 (isFunction(list.listener) && list.listener === listener)) {
2422 delete this._events[type];
2423 if (this._events.removeListener)
2424 this.emit('removeListener', type, listener);
2425
2426 } else if (isObject(list)) {
2427 for (i = length; i-- > 0;) {
2428 if (list[i] === listener ||
2429 (list[i].listener && list[i].listener === listener)) {
2430 position = i;
2431 break;
2432 }
2433 }
2434
2435 if (position < 0)
2436 return this;
2437
2438 if (list.length === 1) {
2439 list.length = 0;
2440 delete this._events[type];
2441 } else {
2442 list.splice(position, 1);
2443 }
2444
2445 if (this._events.removeListener)
2446 this.emit('removeListener', type, listener);
2447 }
2448
2449 return this;
2450};
2451
2452EventEmitter.prototype.removeAllListeners = function(type) {
2453 var key, listeners;
2454
2455 if (!this._events)
2456 return this;
2457
2458 // not listening for removeListener, no need to emit
2459 if (!this._events.removeListener) {
2460 if (arguments.length === 0)
2461 this._events = {};
2462 else if (this._events[type])
2463 delete this._events[type];
2464 return this;
2465 }
2466
2467 // emit removeListener for all listeners on all events
2468 if (arguments.length === 0) {
2469 for (key in this._events) {
2470 if (key === 'removeListener') continue;
2471 this.removeAllListeners(key);
2472 }
2473 this.removeAllListeners('removeListener');
2474 this._events = {};
2475 return this;
2476 }
2477
2478 listeners = this._events[type];
2479
2480 if (isFunction(listeners)) {
2481 this.removeListener(type, listeners);
2482 } else {
2483 // LIFO order
2484 while (listeners.length)
2485 this.removeListener(type, listeners[listeners.length - 1]);
2486 }
2487 delete this._events[type];
2488
2489 return this;
2490};
2491
2492EventEmitter.prototype.listeners = function(type) {
2493 var ret;
2494 if (!this._events || !this._events[type])
2495 ret = [];
2496 else if (isFunction(this._events[type]))
2497 ret = [this._events[type]];
2498 else
2499 ret = this._events[type].slice();
2500 return ret;
2501};
2502
2503EventEmitter.listenerCount = function(emitter, type) {
2504 var ret;
2505 if (!emitter._events || !emitter._events[type])
2506 ret = 0;
2507 else if (isFunction(emitter._events[type]))
2508 ret = 1;
2509 else
2510 ret = emitter._events[type].length;
2511 return ret;
2512};
2513
2514function isFunction(arg) {
2515 return typeof arg === 'function';
2516}
2517
2518function isNumber(arg) {
2519 return typeof arg === 'number';
2520}
2521
2522function isObject(arg) {
2523 return typeof arg === 'object' && arg !== null;
2524}
2525
2526function isUndefined(arg) {
2527 return arg === void 0;
2528}
2529
2530},{}],14:[function(require,module,exports){
2531if (typeof Object.create === 'function') {
2532 // implementation from standard node.js 'util' module
2533 module.exports = function inherits(ctor, superCtor) {
2534 ctor.super_ = superCtor
2535 ctor.prototype = Object.create(superCtor.prototype, {
2536 constructor: {
2537 value: ctor,
2538 enumerable: false,
2539 writable: true,
2540 configurable: true
2541 }
2542 });
2543 };
2544} else {
2545 // old school shim for old browsers
2546 module.exports = function inherits(ctor, superCtor) {
2547 ctor.super_ = superCtor
2548 var TempCtor = function () {}
2549 TempCtor.prototype = superCtor.prototype
2550 ctor.prototype = new TempCtor()
2551 ctor.prototype.constructor = ctor
2552 }
2553}
2554
2555},{}],15:[function(require,module,exports){
2556// shim for using process in browser
2557
2558var process = module.exports = {};
2559
2560process.nextTick = (function () {
2561 var canSetImmediate = typeof window !== 'undefined'
2562 && window.setImmediate;
2563 var canPost = typeof window !== 'undefined'
2564 && window.postMessage && window.addEventListener
2565 ;
2566
2567 if (canSetImmediate) {
2568 return function (f) { return window.setImmediate(f) };
2569 }
2570
2571 if (canPost) {
2572 var queue = [];
2573 window.addEventListener('message', function (ev) {
2574 var source = ev.source;
2575 if ((source === window || source === null) && ev.data === 'process-tick') {
2576 ev.stopPropagation();
2577 if (queue.length > 0) {
2578 var fn = queue.shift();
2579 fn();
2580 }
2581 }
2582 }, true);
2583
2584 return function nextTick(fn) {
2585 queue.push(fn);
2586 window.postMessage('process-tick', '*');
2587 };
2588 }
2589
2590 return function nextTick(fn) {
2591 setTimeout(fn, 0);
2592 };
2593})();
2594
2595process.title = 'browser';
2596process.browser = true;
2597process.env = {};
2598process.argv = [];
2599
2600process.binding = function (name) {
2601 throw new Error('process.binding is not supported');
2602}
2603
2604// TODO(shtylman)
2605process.cwd = function () { return '/' };
2606process.chdir = function (dir) {
2607 throw new Error('process.chdir is not supported');
2608};
2609
2610},{}],16:[function(require,module,exports){
2611(function (process){
2612// Copyright Joyent, Inc. and other Node contributors.
2613//
2614// Permission is hereby granted, free of charge, to any person obtaining a
2615// copy of this software and associated documentation files (the
2616// "Software"), to deal in the Software without restriction, including
2617// without limitation the rights to use, copy, modify, merge, publish,
2618// distribute, sublicense, and/or sell copies of the Software, and to permit
2619// persons to whom the Software is furnished to do so, subject to the
2620// following conditions:
2621//
2622// The above copyright notice and this permission notice shall be included
2623// in all copies or substantial portions of the Software.
2624//
2625// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
2626// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2627// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
2628// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
2629// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
2630// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
2631// USE OR OTHER DEALINGS IN THE SOFTWARE.
2632
2633// resolves . and .. elements in a path array with directory names there
2634// must be no slashes, empty elements, or device names (c:\) in the array
2635// (so also no leading and trailing slashes - it does not distinguish
2636// relative and absolute paths)
2637function normalizeArray(parts, allowAboveRoot) {
2638 // if the path tries to go above the root, `up` ends up > 0
2639 var up = 0;
2640 for (var i = parts.length - 1; i >= 0; i--) {
2641 var last = parts[i];
2642 if (last === '.') {
2643 parts.splice(i, 1);
2644 } else if (last === '..') {
2645 parts.splice(i, 1);
2646 up++;
2647 } else if (up) {
2648 parts.splice(i, 1);
2649 up--;
2650 }
2651 }
2652
2653 // if the path is allowed to go above the root, restore leading ..s
2654 if (allowAboveRoot) {
2655 for (; up--; up) {
2656 parts.unshift('..');
2657 }
2658 }
2659
2660 return parts;
2661}
2662
2663// Split a filename into [root, dir, basename, ext], unix version
2664// 'root' is just a slash, or nothing.
2665var splitPathRe =
2666 /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
2667var splitPath = function(filename) {
2668 return splitPathRe.exec(filename).slice(1);
2669};
2670
2671// path.resolve([from ...], to)
2672// posix version
2673exports.resolve = function() {
2674 var resolvedPath = '',
2675 resolvedAbsolute = false;
2676
2677 for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
2678 var path = (i >= 0) ? arguments[i] : process.cwd();
2679
2680 // Skip empty and invalid entries
2681 if (typeof path !== 'string') {
2682 throw new TypeError('Arguments to path.resolve must be strings');
2683 } else if (!path) {
2684 continue;
2685 }
2686
2687 resolvedPath = path + '/' + resolvedPath;
2688 resolvedAbsolute = path.charAt(0) === '/';
2689 }
2690
2691 // At this point the path should be resolved to a full absolute path, but
2692 // handle relative paths to be safe (might happen when process.cwd() fails)
2693
2694 // Normalize the path
2695 resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {
2696 return !!p;
2697 }), !resolvedAbsolute).join('/');
2698
2699 return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
2700};
2701
2702// path.normalize(path)
2703// posix version
2704exports.normalize = function(path) {
2705 var isAbsolute = exports.isAbsolute(path),
2706 trailingSlash = substr(path, -1) === '/';
2707
2708 // Normalize the path
2709 path = normalizeArray(filter(path.split('/'), function(p) {
2710 return !!p;
2711 }), !isAbsolute).join('/');
2712
2713 if (!path && !isAbsolute) {
2714 path = '.';
2715 }
2716 if (path && trailingSlash) {
2717 path += '/';
2718 }
2719
2720 return (isAbsolute ? '/' : '') + path;
2721};
2722
2723// posix version
2724exports.isAbsolute = function(path) {
2725 return path.charAt(0) === '/';
2726};
2727
2728// posix version
2729exports.join = function() {
2730 var paths = Array.prototype.slice.call(arguments, 0);
2731 return exports.normalize(filter(paths, function(p, index) {
2732 if (typeof p !== 'string') {
2733 throw new TypeError('Arguments to path.join must be strings');
2734 }
2735 return p;
2736 }).join('/'));
2737};
2738
2739
2740// path.relative(from, to)
2741// posix version
2742exports.relative = function(from, to) {
2743 from = exports.resolve(from).substr(1);
2744 to = exports.resolve(to).substr(1);
2745
2746 function trim(arr) {
2747 var start = 0;
2748 for (; start < arr.length; start++) {
2749 if (arr[start] !== '') break;
2750 }
2751
2752 var end = arr.length - 1;
2753 for (; end >= 0; end--) {
2754 if (arr[end] !== '') break;
2755 }
2756
2757 if (start > end) return [];
2758 return arr.slice(start, end - start + 1);
2759 }
2760
2761 var fromParts = trim(from.split('/'));
2762 var toParts = trim(to.split('/'));
2763
2764 var length = Math.min(fromParts.length, toParts.length);
2765 var samePartsLength = length;
2766 for (var i = 0; i < length; i++) {
2767 if (fromParts[i] !== toParts[i]) {
2768 samePartsLength = i;
2769 break;
2770 }
2771 }
2772
2773 var outputParts = [];
2774 for (var i = samePartsLength; i < fromParts.length; i++) {
2775 outputParts.push('..');
2776 }
2777
2778 outputParts = outputParts.concat(toParts.slice(samePartsLength));
2779
2780 return outputParts.join('/');
2781};
2782
2783exports.sep = '/';
2784exports.delimiter = ':';
2785
2786exports.dirname = function(path) {
2787 var result = splitPath(path),
2788 root = result[0],
2789 dir = result[1];
2790
2791 if (!root && !dir) {
2792 // No dirname whatsoever
2793 return '.';
2794 }
2795
2796 if (dir) {
2797 // It has a dirname, strip trailing slash
2798 dir = dir.substr(0, dir.length - 1);
2799 }
2800
2801 return root + dir;
2802};
2803
2804
2805exports.basename = function(path, ext) {
2806 var f = splitPath(path)[2];
2807 // TODO: make this comparison case-insensitive on windows?
2808 if (ext && f.substr(-1 * ext.length) === ext) {
2809 f = f.substr(0, f.length - ext.length);
2810 }
2811 return f;
2812};
2813
2814
2815exports.extname = function(path) {
2816 return splitPath(path)[3];
2817};
2818
2819function filter (xs, f) {
2820 if (xs.filter) return xs.filter(f);
2821 var res = [];
2822 for (var i = 0; i < xs.length; i++) {
2823 if (f(xs[i], i, xs)) res.push(xs[i]);
2824 }
2825 return res;
2826}
2827
2828// String.prototype.substr - negative index don't work in IE8
2829var substr = 'ab'.substr(-1) === 'b'
2830 ? function (str, start, len) { return str.substr(start, len) }
2831 : function (str, start, len) {
2832 if (start < 0) start = str.length + start;
2833 return str.substr(start, len);
2834 }
2835;
2836
2837}).call(this,require("/Users/scott/Code/object-hash/node_modules/gulp-browserify/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js"))
2838},{"/Users/scott/Code/object-hash/node_modules/gulp-browserify/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js":15}],17:[function(require,module,exports){
2839// Copyright Joyent, Inc. and other Node contributors.
2840//
2841// Permission is hereby granted, free of charge, to any person obtaining a
2842// copy of this software and associated documentation files (the
2843// "Software"), to deal in the Software without restriction, including
2844// without limitation the rights to use, copy, modify, merge, publish,
2845// distribute, sublicense, and/or sell copies of the Software, and to permit
2846// persons to whom the Software is furnished to do so, subject to the
2847// following conditions:
2848//
2849// The above copyright notice and this permission notice shall be included
2850// in all copies or substantial portions of the Software.
2851//
2852// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
2853// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2854// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
2855// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
2856// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
2857// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
2858// USE OR OTHER DEALINGS IN THE SOFTWARE.
2859
2860// a duplex stream is just a stream that is both readable and writable.
2861// Since JS doesn't have multiple prototypal inheritance, this class
2862// prototypally inherits from Readable, and then parasitically from
2863// Writable.
2864
2865module.exports = Duplex;
2866var inherits = require('inherits');
2867var setImmediate = require('process/browser.js').nextTick;
2868var Readable = require('./readable.js');
2869var Writable = require('./writable.js');
2870
2871inherits(Duplex, Readable);
2872
2873Duplex.prototype.write = Writable.prototype.write;
2874Duplex.prototype.end = Writable.prototype.end;
2875Duplex.prototype._write = Writable.prototype._write;
2876
2877function Duplex(options) {
2878 if (!(this instanceof Duplex))
2879 return new Duplex(options);
2880
2881 Readable.call(this, options);
2882 Writable.call(this, options);
2883
2884 if (options && options.readable === false)
2885 this.readable = false;
2886
2887 if (options && options.writable === false)
2888 this.writable = false;
2889
2890 this.allowHalfOpen = true;
2891 if (options && options.allowHalfOpen === false)
2892 this.allowHalfOpen = false;
2893
2894 this.once('end', onend);
2895}
2896
2897// the no-half-open enforcer
2898function onend() {
2899 // if we allow half-open state, or if the writable side ended,
2900 // then we're ok.
2901 if (this.allowHalfOpen || this._writableState.ended)
2902 return;
2903
2904 // no more data can be written.
2905 // But allow more writes to happen in this tick.
2906 var self = this;
2907 setImmediate(function () {
2908 self.end();
2909 });
2910}
2911
2912},{"./readable.js":21,"./writable.js":23,"inherits":14,"process/browser.js":19}],18:[function(require,module,exports){
2913// Copyright Joyent, Inc. and other Node contributors.
2914//
2915// Permission is hereby granted, free of charge, to any person obtaining a
2916// copy of this software and associated documentation files (the
2917// "Software"), to deal in the Software without restriction, including
2918// without limitation the rights to use, copy, modify, merge, publish,
2919// distribute, sublicense, and/or sell copies of the Software, and to permit
2920// persons to whom the Software is furnished to do so, subject to the
2921// following conditions:
2922//
2923// The above copyright notice and this permission notice shall be included
2924// in all copies or substantial portions of the Software.
2925//
2926// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
2927// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2928// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
2929// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
2930// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
2931// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
2932// USE OR OTHER DEALINGS IN THE SOFTWARE.
2933
2934module.exports = Stream;
2935
2936var EE = require('events').EventEmitter;
2937var inherits = require('inherits');
2938
2939inherits(Stream, EE);
2940Stream.Readable = require('./readable.js');
2941Stream.Writable = require('./writable.js');
2942Stream.Duplex = require('./duplex.js');
2943Stream.Transform = require('./transform.js');
2944Stream.PassThrough = require('./passthrough.js');
2945
2946// Backwards-compat with node 0.4.x
2947Stream.Stream = Stream;
2948
2949
2950
2951// old-style streams. Note that the pipe method (the only relevant
2952// part of this class) is overridden in the Readable class.
2953
2954function Stream() {
2955 EE.call(this);
2956}
2957
2958Stream.prototype.pipe = function(dest, options) {
2959 var source = this;
2960
2961 function ondata(chunk) {
2962 if (dest.writable) {
2963 if (false === dest.write(chunk) && source.pause) {
2964 source.pause();
2965 }
2966 }
2967 }
2968
2969 source.on('data', ondata);
2970
2971 function ondrain() {
2972 if (source.readable && source.resume) {
2973 source.resume();
2974 }
2975 }
2976
2977 dest.on('drain', ondrain);
2978
2979 // If the 'end' option is not supplied, dest.end() will be called when
2980 // source gets the 'end' or 'close' events. Only dest.end() once.
2981 if (!dest._isStdio && (!options || options.end !== false)) {
2982 source.on('end', onend);
2983 source.on('close', onclose);
2984 }
2985
2986 var didOnEnd = false;
2987 function onend() {
2988 if (didOnEnd) return;
2989 didOnEnd = true;
2990
2991 dest.end();
2992 }
2993
2994
2995 function onclose() {
2996 if (didOnEnd) return;
2997 didOnEnd = true;
2998
2999 if (typeof dest.destroy === 'function') dest.destroy();
3000 }
3001
3002 // don't leave dangling pipes when there are errors.
3003 function onerror(er) {
3004 cleanup();
3005 if (EE.listenerCount(this, 'error') === 0) {
3006 throw er; // Unhandled stream error in pipe.
3007 }
3008 }
3009
3010 source.on('error', onerror);
3011 dest.on('error', onerror);
3012
3013 // remove all the event listeners that were added.
3014 function cleanup() {
3015 source.removeListener('data', ondata);
3016 dest.removeListener('drain', ondrain);
3017
3018 source.removeListener('end', onend);
3019 source.removeListener('close', onclose);
3020
3021 source.removeListener('error', onerror);
3022 dest.removeListener('error', onerror);
3023
3024 source.removeListener('end', cleanup);
3025 source.removeListener('close', cleanup);
3026
3027 dest.removeListener('close', cleanup);
3028 }
3029
3030 source.on('end', cleanup);
3031 source.on('close', cleanup);
3032
3033 dest.on('close', cleanup);
3034
3035 dest.emit('pipe', source);
3036
3037 // Allow for unix-like usage: A.pipe(B).pipe(C)
3038 return dest;
3039};
3040
3041},{"./duplex.js":17,"./passthrough.js":20,"./readable.js":21,"./transform.js":22,"./writable.js":23,"events":13,"inherits":14}],19:[function(require,module,exports){
3042module.exports=require(15)
3043},{}],20:[function(require,module,exports){
3044// Copyright Joyent, Inc. and other Node contributors.
3045//
3046// Permission is hereby granted, free of charge, to any person obtaining a
3047// copy of this software and associated documentation files (the
3048// "Software"), to deal in the Software without restriction, including
3049// without limitation the rights to use, copy, modify, merge, publish,
3050// distribute, sublicense, and/or sell copies of the Software, and to permit
3051// persons to whom the Software is furnished to do so, subject to the
3052// following conditions:
3053//
3054// The above copyright notice and this permission notice shall be included
3055// in all copies or substantial portions of the Software.
3056//
3057// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
3058// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
3059// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
3060// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
3061// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
3062// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
3063// USE OR OTHER DEALINGS IN THE SOFTWARE.
3064
3065// a passthrough stream.
3066// basically just the most minimal sort of Transform stream.
3067// Every written chunk gets output as-is.
3068
3069module.exports = PassThrough;
3070
3071var Transform = require('./transform.js');
3072var inherits = require('inherits');
3073inherits(PassThrough, Transform);
3074
3075function PassThrough(options) {
3076 if (!(this instanceof PassThrough))
3077 return new PassThrough(options);
3078
3079 Transform.call(this, options);
3080}
3081
3082PassThrough.prototype._transform = function(chunk, encoding, cb) {
3083 cb(null, chunk);
3084};
3085
3086},{"./transform.js":22,"inherits":14}],21:[function(require,module,exports){
3087(function (process){
3088// Copyright Joyent, Inc. and other Node contributors.
3089//
3090// Permission is hereby granted, free of charge, to any person obtaining a
3091// copy of this software and associated documentation files (the
3092// "Software"), to deal in the Software without restriction, including
3093// without limitation the rights to use, copy, modify, merge, publish,
3094// distribute, sublicense, and/or sell copies of the Software, and to permit
3095// persons to whom the Software is furnished to do so, subject to the
3096// following conditions:
3097//
3098// The above copyright notice and this permission notice shall be included
3099// in all copies or substantial portions of the Software.
3100//
3101// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
3102// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
3103// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
3104// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
3105// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
3106// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
3107// USE OR OTHER DEALINGS IN THE SOFTWARE.
3108
3109module.exports = Readable;
3110Readable.ReadableState = ReadableState;
3111
3112var EE = require('events').EventEmitter;
3113var Stream = require('./index.js');
3114var Buffer = require('buffer').Buffer;
3115var setImmediate = require('process/browser.js').nextTick;
3116var StringDecoder;
3117
3118var inherits = require('inherits');
3119inherits(Readable, Stream);
3120
3121function ReadableState(options, stream) {
3122 options = options || {};
3123
3124 // the point at which it stops calling _read() to fill the buffer
3125 // Note: 0 is a valid value, means "don't call _read preemptively ever"
3126 var hwm = options.highWaterMark;
3127 this.highWaterMark = (hwm || hwm === 0) ? hwm : 16 * 1024;
3128
3129 // cast to ints.
3130 this.highWaterMark = ~~this.highWaterMark;
3131
3132 this.buffer = [];
3133 this.length = 0;
3134 this.pipes = null;
3135 this.pipesCount = 0;
3136 this.flowing = false;
3137 this.ended = false;
3138 this.endEmitted = false;
3139 this.reading = false;
3140
3141 // In streams that never have any data, and do push(null) right away,
3142 // the consumer can miss the 'end' event if they do some I/O before
3143 // consuming the stream. So, we don't emit('end') until some reading
3144 // happens.
3145 this.calledRead = false;
3146
3147 // a flag to be able to tell if the onwrite cb is called immediately,
3148 // or on a later tick. We set this to true at first, becuase any
3149 // actions that shouldn't happen until "later" should generally also
3150 // not happen before the first write call.
3151 this.sync = true;
3152
3153 // whenever we return null, then we set a flag to say
3154 // that we're awaiting a 'readable' event emission.
3155 this.needReadable = false;
3156 this.emittedReadable = false;
3157 this.readableListening = false;
3158
3159
3160 // object stream flag. Used to make read(n) ignore n and to
3161 // make all the buffer merging and length checks go away
3162 this.objectMode = !!options.objectMode;
3163
3164 // Crypto is kind of old and crusty. Historically, its default string
3165 // encoding is 'binary' so we have to make this configurable.
3166 // Everything else in the universe uses 'utf8', though.
3167 this.defaultEncoding = options.defaultEncoding || 'utf8';
3168
3169 // when piping, we only care about 'readable' events that happen
3170 // after read()ing all the bytes and not getting any pushback.
3171 this.ranOut = false;
3172
3173 // the number of writers that are awaiting a drain event in .pipe()s
3174 this.awaitDrain = 0;
3175
3176 // if true, a maybeReadMore has been scheduled
3177 this.readingMore = false;
3178
3179 this.decoder = null;
3180 this.encoding = null;
3181 if (options.encoding) {
3182 if (!StringDecoder)
3183 StringDecoder = require('string_decoder').StringDecoder;
3184 this.decoder = new StringDecoder(options.encoding);
3185 this.encoding = options.encoding;
3186 }
3187}
3188
3189function Readable(options) {
3190 if (!(this instanceof Readable))
3191 return new Readable(options);
3192
3193 this._readableState = new ReadableState(options, this);
3194
3195 // legacy
3196 this.readable = true;
3197
3198 Stream.call(this);
3199}
3200
3201// Manually shove something into the read() buffer.
3202// This returns true if the highWaterMark has not been hit yet,
3203// similar to how Writable.write() returns true if you should
3204// write() some more.
3205Readable.prototype.push = function(chunk, encoding) {
3206 var state = this._readableState;
3207
3208 if (typeof chunk === 'string' && !state.objectMode) {
3209 encoding = encoding || state.defaultEncoding;
3210 if (encoding !== state.encoding) {
3211 chunk = new Buffer(chunk, encoding);
3212 encoding = '';
3213 }
3214 }
3215
3216 return readableAddChunk(this, state, chunk, encoding, false);
3217};
3218
3219// Unshift should *always* be something directly out of read()
3220Readable.prototype.unshift = function(chunk) {
3221 var state = this._readableState;
3222 return readableAddChunk(this, state, chunk, '', true);
3223};
3224
3225function readableAddChunk(stream, state, chunk, encoding, addToFront) {
3226 var er = chunkInvalid(state, chunk);
3227 if (er) {
3228 stream.emit('error', er);
3229 } else if (chunk === null || chunk === undefined) {
3230 state.reading = false;
3231 if (!state.ended)
3232 onEofChunk(stream, state);
3233 } else if (state.objectMode || chunk && chunk.length > 0) {
3234 if (state.ended && !addToFront) {
3235 var e = new Error('stream.push() after EOF');
3236 stream.emit('error', e);
3237 } else if (state.endEmitted && addToFront) {
3238 var e = new Error('stream.unshift() after end event');
3239 stream.emit('error', e);
3240 } else {
3241 if (state.decoder && !addToFront && !encoding)
3242 chunk = state.decoder.write(chunk);
3243
3244 // update the buffer info.
3245 state.length += state.objectMode ? 1 : chunk.length;
3246 if (addToFront) {
3247 state.buffer.unshift(chunk);
3248 } else {
3249 state.reading = false;
3250 state.buffer.push(chunk);
3251 }
3252
3253 if (state.needReadable)
3254 emitReadable(stream);
3255
3256 maybeReadMore(stream, state);
3257 }
3258 } else if (!addToFront) {
3259 state.reading = false;
3260 }
3261
3262 return needMoreData(state);
3263}
3264
3265
3266
3267// if it's past the high water mark, we can push in some more.
3268// Also, if we have no data yet, we can stand some
3269// more bytes. This is to work around cases where hwm=0,
3270// such as the repl. Also, if the push() triggered a
3271// readable event, and the user called read(largeNumber) such that
3272// needReadable was set, then we ought to push more, so that another
3273// 'readable' event will be triggered.
3274function needMoreData(state) {
3275 return !state.ended &&
3276 (state.needReadable ||
3277 state.length < state.highWaterMark ||
3278 state.length === 0);
3279}
3280
3281// backwards compatibility.
3282Readable.prototype.setEncoding = function(enc) {
3283 if (!StringDecoder)
3284 StringDecoder = require('string_decoder').StringDecoder;
3285 this._readableState.decoder = new StringDecoder(enc);
3286 this._readableState.encoding = enc;
3287};
3288
3289// Don't raise the hwm > 128MB
3290var MAX_HWM = 0x800000;
3291function roundUpToNextPowerOf2(n) {
3292 if (n >= MAX_HWM) {
3293 n = MAX_HWM;
3294 } else {
3295 // Get the next highest power of 2
3296 n--;
3297 for (var p = 1; p < 32; p <<= 1) n |= n >> p;
3298 n++;
3299 }
3300 return n;
3301}
3302
3303function howMuchToRead(n, state) {
3304 if (state.length === 0 && state.ended)
3305 return 0;
3306
3307 if (state.objectMode)
3308 return n === 0 ? 0 : 1;
3309
3310 if (isNaN(n) || n === null) {
3311 // only flow one buffer at a time
3312 if (state.flowing && state.buffer.length)
3313 return state.buffer[0].length;
3314 else
3315 return state.length;
3316 }
3317
3318 if (n <= 0)
3319 return 0;
3320
3321 // If we're asking for more than the target buffer level,
3322 // then raise the water mark. Bump up to the next highest
3323 // power of 2, to prevent increasing it excessively in tiny
3324 // amounts.
3325 if (n > state.highWaterMark)
3326 state.highWaterMark = roundUpToNextPowerOf2(n);
3327
3328 // don't have that much. return null, unless we've ended.
3329 if (n > state.length) {
3330 if (!state.ended) {
3331 state.needReadable = true;
3332 return 0;
3333 } else
3334 return state.length;
3335 }
3336
3337 return n;
3338}
3339
3340// you can override either this method, or the async _read(n) below.
3341Readable.prototype.read = function(n) {
3342 var state = this._readableState;
3343 state.calledRead = true;
3344 var nOrig = n;
3345
3346 if (typeof n !== 'number' || n > 0)
3347 state.emittedReadable = false;
3348
3349 // if we're doing read(0) to trigger a readable event, but we
3350 // already have a bunch of data in the buffer, then just trigger
3351 // the 'readable' event and move on.
3352 if (n === 0 &&
3353 state.needReadable &&
3354 (state.length >= state.highWaterMark || state.ended)) {
3355 emitReadable(this);
3356 return null;
3357 }
3358
3359 n = howMuchToRead(n, state);
3360
3361 // if we've ended, and we're now clear, then finish it up.
3362 if (n === 0 && state.ended) {
3363 if (state.length === 0)
3364 endReadable(this);
3365 return null;
3366 }
3367
3368 // All the actual chunk generation logic needs to be
3369 // *below* the call to _read. The reason is that in certain
3370 // synthetic stream cases, such as passthrough streams, _read
3371 // may be a completely synchronous operation which may change
3372 // the state of the read buffer, providing enough data when
3373 // before there was *not* enough.
3374 //
3375 // So, the steps are:
3376 // 1. Figure out what the state of things will be after we do
3377 // a read from the buffer.
3378 //
3379 // 2. If that resulting state will trigger a _read, then call _read.
3380 // Note that this may be asynchronous, or synchronous. Yes, it is
3381 // deeply ugly to write APIs this way, but that still doesn't mean
3382 // that the Readable class should behave improperly, as streams are
3383 // designed to be sync/async agnostic.
3384 // Take note if the _read call is sync or async (ie, if the read call
3385 // has returned yet), so that we know whether or not it's safe to emit
3386 // 'readable' etc.
3387 //
3388 // 3. Actually pull the requested chunks out of the buffer and return.
3389
3390 // if we need a readable event, then we need to do some reading.
3391 var doRead = state.needReadable;
3392
3393 // if we currently have less than the highWaterMark, then also read some
3394 if (state.length - n <= state.highWaterMark)
3395 doRead = true;
3396
3397 // however, if we've ended, then there's no point, and if we're already
3398 // reading, then it's unnecessary.
3399 if (state.ended || state.reading)
3400 doRead = false;
3401
3402 if (doRead) {
3403 state.reading = true;
3404 state.sync = true;
3405 // if the length is currently zero, then we *need* a readable event.
3406 if (state.length === 0)
3407 state.needReadable = true;
3408 // call internal read method
3409 this._read(state.highWaterMark);
3410 state.sync = false;
3411 }
3412
3413 // If _read called its callback synchronously, then `reading`
3414 // will be false, and we need to re-evaluate how much data we
3415 // can return to the user.
3416 if (doRead && !state.reading)
3417 n = howMuchToRead(nOrig, state);
3418
3419 var ret;
3420 if (n > 0)
3421 ret = fromList(n, state);
3422 else
3423 ret = null;
3424
3425 if (ret === null) {
3426 state.needReadable = true;
3427 n = 0;
3428 }
3429
3430 state.length -= n;
3431
3432 // If we have nothing in the buffer, then we want to know
3433 // as soon as we *do* get something into the buffer.
3434 if (state.length === 0 && !state.ended)
3435 state.needReadable = true;
3436
3437 // If we happened to read() exactly the remaining amount in the
3438 // buffer, and the EOF has been seen at this point, then make sure
3439 // that we emit 'end' on the very next tick.
3440 if (state.ended && !state.endEmitted && state.length === 0)
3441 endReadable(this);
3442
3443 return ret;
3444};
3445
3446function chunkInvalid(state, chunk) {
3447 var er = null;
3448 if (!Buffer.isBuffer(chunk) &&
3449 'string' !== typeof chunk &&
3450 chunk !== null &&
3451 chunk !== undefined &&
3452 !state.objectMode &&
3453 !er) {
3454 er = new TypeError('Invalid non-string/buffer chunk');
3455 }
3456 return er;
3457}
3458
3459
3460function onEofChunk(stream, state) {
3461 if (state.decoder && !state.ended) {
3462 var chunk = state.decoder.end();
3463 if (chunk && chunk.length) {
3464 state.buffer.push(chunk);
3465 state.length += state.objectMode ? 1 : chunk.length;
3466 }
3467 }
3468 state.ended = true;
3469
3470 // if we've ended and we have some data left, then emit
3471 // 'readable' now to make sure it gets picked up.
3472 if (state.length > 0)
3473 emitReadable(stream);
3474 else
3475 endReadable(stream);
3476}
3477
3478// Don't emit readable right away in sync mode, because this can trigger
3479// another read() call => stack overflow. This way, it might trigger
3480// a nextTick recursion warning, but that's not so bad.
3481function emitReadable(stream) {
3482 var state = stream._readableState;
3483 state.needReadable = false;
3484 if (state.emittedReadable)
3485 return;
3486
3487 state.emittedReadable = true;
3488 if (state.sync)
3489 setImmediate(function() {
3490 emitReadable_(stream);
3491 });
3492 else
3493 emitReadable_(stream);
3494}
3495
3496function emitReadable_(stream) {
3497 stream.emit('readable');
3498}
3499
3500
3501// at this point, the user has presumably seen the 'readable' event,
3502// and called read() to consume some data. that may have triggered
3503// in turn another _read(n) call, in which case reading = true if
3504// it's in progress.
3505// However, if we're not ended, or reading, and the length < hwm,
3506// then go ahead and try to read some more preemptively.
3507function maybeReadMore(stream, state) {
3508 if (!state.readingMore) {
3509 state.readingMore = true;
3510 setImmediate(function() {
3511 maybeReadMore_(stream, state);
3512 });
3513 }
3514}
3515
3516function maybeReadMore_(stream, state) {
3517 var len = state.length;
3518 while (!state.reading && !state.flowing && !state.ended &&
3519 state.length < state.highWaterMark) {
3520 stream.read(0);
3521 if (len === state.length)
3522 // didn't get any data, stop spinning.
3523 break;
3524 else
3525 len = state.length;
3526 }
3527 state.readingMore = false;
3528}
3529
3530// abstract method. to be overridden in specific implementation classes.
3531// call cb(er, data) where data is <= n in length.
3532// for virtual (non-string, non-buffer) streams, "length" is somewhat
3533// arbitrary, and perhaps not very meaningful.
3534Readable.prototype._read = function(n) {
3535 this.emit('error', new Error('not implemented'));
3536};
3537
3538Readable.prototype.pipe = function(dest, pipeOpts) {
3539 var src = this;
3540 var state = this._readableState;
3541
3542 switch (state.pipesCount) {
3543 case 0:
3544 state.pipes = dest;
3545 break;
3546 case 1:
3547 state.pipes = [state.pipes, dest];
3548 break;
3549 default:
3550 state.pipes.push(dest);
3551 break;
3552 }
3553 state.pipesCount += 1;
3554
3555 var doEnd = (!pipeOpts || pipeOpts.end !== false) &&
3556 dest !== process.stdout &&
3557 dest !== process.stderr;
3558
3559 var endFn = doEnd ? onend : cleanup;
3560 if (state.endEmitted)
3561 setImmediate(endFn);
3562 else
3563 src.once('end', endFn);
3564
3565 dest.on('unpipe', onunpipe);
3566 function onunpipe(readable) {
3567 if (readable !== src) return;
3568 cleanup();
3569 }
3570
3571 function onend() {
3572 dest.end();
3573 }
3574
3575 // when the dest drains, it reduces the awaitDrain counter
3576 // on the source. This would be more elegant with a .once()
3577 // handler in flow(), but adding and removing repeatedly is
3578 // too slow.
3579 var ondrain = pipeOnDrain(src);
3580 dest.on('drain', ondrain);
3581
3582 function cleanup() {
3583 // cleanup event handlers once the pipe is broken
3584 dest.removeListener('close', onclose);
3585 dest.removeListener('finish', onfinish);
3586 dest.removeListener('drain', ondrain);
3587 dest.removeListener('error', onerror);
3588 dest.removeListener('unpipe', onunpipe);
3589 src.removeListener('end', onend);
3590 src.removeListener('end', cleanup);
3591
3592 // if the reader is waiting for a drain event from this
3593 // specific writer, then it would cause it to never start
3594 // flowing again.
3595 // So, if this is awaiting a drain, then we just call it now.
3596 // If we don't know, then assume that we are waiting for one.
3597 if (!dest._writableState || dest._writableState.needDrain)
3598 ondrain();
3599 }
3600
3601 // if the dest has an error, then stop piping into it.
3602 // however, don't suppress the throwing behavior for this.
3603 // check for listeners before emit removes one-time listeners.
3604 var errListeners = EE.listenerCount(dest, 'error');
3605 function onerror(er) {
3606 unpipe();
3607 if (errListeners === 0 && EE.listenerCount(dest, 'error') === 0)
3608 dest.emit('error', er);
3609 }
3610 dest.once('error', onerror);
3611
3612 // Both close and finish should trigger unpipe, but only once.
3613 function onclose() {
3614 dest.removeListener('finish', onfinish);
3615 unpipe();
3616 }
3617 dest.once('close', onclose);
3618 function onfinish() {
3619 dest.removeListener('close', onclose);
3620 unpipe();
3621 }
3622 dest.once('finish', onfinish);
3623
3624 function unpipe() {
3625 src.unpipe(dest);
3626 }
3627
3628 // tell the dest that it's being piped to
3629 dest.emit('pipe', src);
3630
3631 // start the flow if it hasn't been started already.
3632 if (!state.flowing) {
3633 // the handler that waits for readable events after all
3634 // the data gets sucked out in flow.
3635 // This would be easier to follow with a .once() handler
3636 // in flow(), but that is too slow.
3637 this.on('readable', pipeOnReadable);
3638
3639 state.flowing = true;
3640 setImmediate(function() {
3641 flow(src);
3642 });
3643 }
3644
3645 return dest;
3646};
3647
3648function pipeOnDrain(src) {
3649 return function() {
3650 var dest = this;
3651 var state = src._readableState;
3652 state.awaitDrain--;
3653 if (state.awaitDrain === 0)
3654 flow(src);
3655 };
3656}
3657
3658function flow(src) {
3659 var state = src._readableState;
3660 var chunk;
3661 state.awaitDrain = 0;
3662
3663 function write(dest, i, list) {
3664 var written = dest.write(chunk);
3665 if (false === written) {
3666 state.awaitDrain++;
3667 }
3668 }
3669
3670 while (state.pipesCount && null !== (chunk = src.read())) {
3671
3672 if (state.pipesCount === 1)
3673 write(state.pipes, 0, null);
3674 else
3675 forEach(state.pipes, write);
3676
3677 src.emit('data', chunk);
3678
3679 // if anyone needs a drain, then we have to wait for that.
3680 if (state.awaitDrain > 0)
3681 return;
3682 }
3683
3684 // if every destination was unpiped, either before entering this
3685 // function, or in the while loop, then stop flowing.
3686 //
3687 // NB: This is a pretty rare edge case.
3688 if (state.pipesCount === 0) {
3689 state.flowing = false;
3690
3691 // if there were data event listeners added, then switch to old mode.
3692 if (EE.listenerCount(src, 'data') > 0)
3693 emitDataEvents(src);
3694 return;
3695 }
3696
3697 // at this point, no one needed a drain, so we just ran out of data
3698 // on the next readable event, start it over again.
3699 state.ranOut = true;
3700}
3701
3702function pipeOnReadable() {
3703 if (this._readableState.ranOut) {
3704 this._readableState.ranOut = false;
3705 flow(this);
3706 }
3707}
3708
3709
3710Readable.prototype.unpipe = function(dest) {
3711 var state = this._readableState;
3712
3713 // if we're not piping anywhere, then do nothing.
3714 if (state.pipesCount === 0)
3715 return this;
3716
3717 // just one destination. most common case.
3718 if (state.pipesCount === 1) {
3719 // passed in one, but it's not the right one.
3720 if (dest && dest !== state.pipes)
3721 return this;
3722
3723 if (!dest)
3724 dest = state.pipes;
3725
3726 // got a match.
3727 state.pipes = null;
3728 state.pipesCount = 0;
3729 this.removeListener('readable', pipeOnReadable);
3730 state.flowing = false;
3731 if (dest)
3732 dest.emit('unpipe', this);
3733 return this;
3734 }
3735
3736 // slow case. multiple pipe destinations.
3737
3738 if (!dest) {
3739 // remove all.
3740 var dests = state.pipes;
3741 var len = state.pipesCount;
3742 state.pipes = null;
3743 state.pipesCount = 0;
3744 this.removeListener('readable', pipeOnReadable);
3745 state.flowing = false;
3746
3747 for (var i = 0; i < len; i++)
3748 dests[i].emit('unpipe', this);
3749 return this;
3750 }
3751
3752 // try to find the right one.
3753 var i = indexOf(state.pipes, dest);
3754 if (i === -1)
3755 return this;
3756
3757 state.pipes.splice(i, 1);
3758 state.pipesCount -= 1;
3759 if (state.pipesCount === 1)
3760 state.pipes = state.pipes[0];
3761
3762 dest.emit('unpipe', this);
3763
3764 return this;
3765};
3766
3767// set up data events if they are asked for
3768// Ensure readable listeners eventually get something
3769Readable.prototype.on = function(ev, fn) {
3770 var res = Stream.prototype.on.call(this, ev, fn);
3771
3772 if (ev === 'data' && !this._readableState.flowing)
3773 emitDataEvents(this);
3774
3775 if (ev === 'readable' && this.readable) {
3776 var state = this._readableState;
3777 if (!state.readableListening) {
3778 state.readableListening = true;
3779 state.emittedReadable = false;
3780 state.needReadable = true;
3781 if (!state.reading) {
3782 this.read(0);
3783 } else if (state.length) {
3784 emitReadable(this, state);
3785 }
3786 }
3787 }
3788
3789 return res;
3790};
3791Readable.prototype.addListener = Readable.prototype.on;
3792
3793// pause() and resume() are remnants of the legacy readable stream API
3794// If the user uses them, then switch into old mode.
3795Readable.prototype.resume = function() {
3796 emitDataEvents(this);
3797 this.read(0);
3798 this.emit('resume');
3799};
3800
3801Readable.prototype.pause = function() {
3802 emitDataEvents(this, true);
3803 this.emit('pause');
3804};
3805
3806function emitDataEvents(stream, startPaused) {
3807 var state = stream._readableState;
3808
3809 if (state.flowing) {
3810 // https://github.com/isaacs/readable-stream/issues/16
3811 throw new Error('Cannot switch to old mode now.');
3812 }
3813
3814 var paused = startPaused || false;
3815 var readable = false;
3816
3817 // convert to an old-style stream.
3818 stream.readable = true;
3819 stream.pipe = Stream.prototype.pipe;
3820 stream.on = stream.addListener = Stream.prototype.on;
3821
3822 stream.on('readable', function() {
3823 readable = true;
3824
3825 var c;
3826 while (!paused && (null !== (c = stream.read())))
3827 stream.emit('data', c);
3828
3829 if (c === null) {
3830 readable = false;
3831 stream._readableState.needReadable = true;
3832 }
3833 });
3834
3835 stream.pause = function() {
3836 paused = true;
3837 this.emit('pause');
3838 };
3839
3840 stream.resume = function() {
3841 paused = false;
3842 if (readable)
3843 setImmediate(function() {
3844 stream.emit('readable');
3845 });
3846 else
3847 this.read(0);
3848 this.emit('resume');
3849 };
3850
3851 // now make it start, just in case it hadn't already.
3852 stream.emit('readable');
3853}
3854
3855// wrap an old-style stream as the async data source.
3856// This is *not* part of the readable stream interface.
3857// It is an ugly unfortunate mess of history.
3858Readable.prototype.wrap = function(stream) {
3859 var state = this._readableState;
3860 var paused = false;
3861
3862 var self = this;
3863 stream.on('end', function() {
3864 if (state.decoder && !state.ended) {
3865 var chunk = state.decoder.end();
3866 if (chunk && chunk.length)
3867 self.push(chunk);
3868 }
3869
3870 self.push(null);
3871 });
3872
3873 stream.on('data', function(chunk) {
3874 if (state.decoder)
3875 chunk = state.decoder.write(chunk);
3876 if (!chunk || !state.objectMode && !chunk.length)
3877 return;
3878
3879 var ret = self.push(chunk);
3880 if (!ret) {
3881 paused = true;
3882 stream.pause();
3883 }
3884 });
3885
3886 // proxy all the other methods.
3887 // important when wrapping filters and duplexes.
3888 for (var i in stream) {
3889 if (typeof stream[i] === 'function' &&
3890 typeof this[i] === 'undefined') {
3891 this[i] = function(method) { return function() {
3892 return stream[method].apply(stream, arguments);
3893 }}(i);
3894 }
3895 }
3896
3897 // proxy certain important events.
3898 var events = ['error', 'close', 'destroy', 'pause', 'resume'];
3899 forEach(events, function(ev) {
3900 stream.on(ev, function (x) {
3901 return self.emit.apply(self, ev, x);
3902 });
3903 });
3904
3905 // when we try to consume some more bytes, simply unpause the
3906 // underlying stream.
3907 self._read = function(n) {
3908 if (paused) {
3909 paused = false;
3910 stream.resume();
3911 }
3912 };
3913
3914 return self;
3915};
3916
3917
3918
3919// exposed for testing purposes only.
3920Readable._fromList = fromList;
3921
3922// Pluck off n bytes from an array of buffers.
3923// Length is the combined lengths of all the buffers in the list.
3924function fromList(n, state) {
3925 var list = state.buffer;
3926 var length = state.length;
3927 var stringMode = !!state.decoder;
3928 var objectMode = !!state.objectMode;
3929 var ret;
3930
3931 // nothing in the list, definitely empty.
3932 if (list.length === 0)
3933 return null;
3934
3935 if (length === 0)
3936 ret = null;
3937 else if (objectMode)
3938 ret = list.shift();
3939 else if (!n || n >= length) {
3940 // read it all, truncate the array.
3941 if (stringMode)
3942 ret = list.join('');
3943 else
3944 ret = Buffer.concat(list, length);
3945 list.length = 0;
3946 } else {
3947 // read just some of it.
3948 if (n < list[0].length) {
3949 // just take a part of the first list item.
3950 // slice is the same for buffers and strings.
3951 var buf = list[0];
3952 ret = buf.slice(0, n);
3953 list[0] = buf.slice(n);
3954 } else if (n === list[0].length) {
3955 // first list is a perfect match
3956 ret = list.shift();
3957 } else {
3958 // complex case.
3959 // we have enough to cover it, but it spans past the first buffer.
3960 if (stringMode)
3961 ret = '';
3962 else
3963 ret = new Buffer(n);
3964
3965 var c = 0;
3966 for (var i = 0, l = list.length; i < l && c < n; i++) {
3967 var buf = list[0];
3968 var cpy = Math.min(n - c, buf.length);
3969
3970 if (stringMode)
3971 ret += buf.slice(0, cpy);
3972 else
3973 buf.copy(ret, c, 0, cpy);
3974
3975 if (cpy < buf.length)
3976 list[0] = buf.slice(cpy);
3977 else
3978 list.shift();
3979
3980 c += cpy;
3981 }
3982 }
3983 }
3984
3985 return ret;
3986}
3987
3988function endReadable(stream) {
3989 var state = stream._readableState;
3990
3991 // If we get here before consuming all the bytes, then that is a
3992 // bug in node. Should never happen.
3993 if (state.length > 0)
3994 throw new Error('endReadable called on non-empty stream');
3995
3996 if (!state.endEmitted && state.calledRead) {
3997 state.ended = true;
3998 setImmediate(function() {
3999 // Check that we didn't get one last unshift.
4000 if (!state.endEmitted && state.length === 0) {
4001 state.endEmitted = true;
4002 stream.readable = false;
4003 stream.emit('end');
4004 }
4005 });
4006 }
4007}
4008
4009function forEach (xs, f) {
4010 for (var i = 0, l = xs.length; i < l; i++) {
4011 f(xs[i], i);
4012 }
4013}
4014
4015function indexOf (xs, x) {
4016 for (var i = 0, l = xs.length; i < l; i++) {
4017 if (xs[i] === x) return i;
4018 }
4019 return -1;
4020}
4021
4022}).call(this,require("/Users/scott/Code/object-hash/node_modules/gulp-browserify/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js"))
4023},{"./index.js":18,"/Users/scott/Code/object-hash/node_modules/gulp-browserify/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js":15,"buffer":4,"events":13,"inherits":14,"process/browser.js":19,"string_decoder":24}],22:[function(require,module,exports){
4024// Copyright Joyent, Inc. and other Node contributors.
4025//
4026// Permission is hereby granted, free of charge, to any person obtaining a
4027// copy of this software and associated documentation files (the
4028// "Software"), to deal in the Software without restriction, including
4029// without limitation the rights to use, copy, modify, merge, publish,
4030// distribute, sublicense, and/or sell copies of the Software, and to permit
4031// persons to whom the Software is furnished to do so, subject to the
4032// following conditions:
4033//
4034// The above copyright notice and this permission notice shall be included
4035// in all copies or substantial portions of the Software.
4036//
4037// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
4038// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
4039// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
4040// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
4041// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
4042// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
4043// USE OR OTHER DEALINGS IN THE SOFTWARE.
4044
4045// a transform stream is a readable/writable stream where you do
4046// something with the data. Sometimes it's called a "filter",
4047// but that's not a great name for it, since that implies a thing where
4048// some bits pass through, and others are simply ignored. (That would
4049// be a valid example of a transform, of course.)
4050//
4051// While the output is causally related to the input, it's not a
4052// necessarily symmetric or synchronous transformation. For example,
4053// a zlib stream might take multiple plain-text writes(), and then
4054// emit a single compressed chunk some time in the future.
4055//
4056// Here's how this works:
4057//
4058// The Transform stream has all the aspects of the readable and writable
4059// stream classes. When you write(chunk), that calls _write(chunk,cb)
4060// internally, and returns false if there's a lot of pending writes
4061// buffered up. When you call read(), that calls _read(n) until
4062// there's enough pending readable data buffered up.
4063//
4064// In a transform stream, the written data is placed in a buffer. When
4065// _read(n) is called, it transforms the queued up data, calling the
4066// buffered _write cb's as it consumes chunks. If consuming a single
4067// written chunk would result in multiple output chunks, then the first
4068// outputted bit calls the readcb, and subsequent chunks just go into
4069// the read buffer, and will cause it to emit 'readable' if necessary.
4070//
4071// This way, back-pressure is actually determined by the reading side,
4072// since _read has to be called to start processing a new chunk. However,
4073// a pathological inflate type of transform can cause excessive buffering
4074// here. For example, imagine a stream where every byte of input is
4075// interpreted as an integer from 0-255, and then results in that many
4076// bytes of output. Writing the 4 bytes {ff,ff,ff,ff} would result in
4077// 1kb of data being output. In this case, you could write a very small
4078// amount of input, and end up with a very large amount of output. In
4079// such a pathological inflating mechanism, there'd be no way to tell
4080// the system to stop doing the transform. A single 4MB write could
4081// cause the system to run out of memory.
4082//
4083// However, even in such a pathological case, only a single written chunk
4084// would be consumed, and then the rest would wait (un-transformed) until
4085// the results of the previous transformed chunk were consumed.
4086
4087module.exports = Transform;
4088
4089var Duplex = require('./duplex.js');
4090var inherits = require('inherits');
4091inherits(Transform, Duplex);
4092
4093
4094function TransformState(options, stream) {
4095 this.afterTransform = function(er, data) {
4096 return afterTransform(stream, er, data);
4097 };
4098
4099 this.needTransform = false;
4100 this.transforming = false;
4101 this.writecb = null;
4102 this.writechunk = null;
4103}
4104
4105function afterTransform(stream, er, data) {
4106 var ts = stream._transformState;
4107 ts.transforming = false;
4108
4109 var cb = ts.writecb;
4110
4111 if (!cb)
4112 return stream.emit('error', new Error('no writecb in Transform class'));
4113
4114 ts.writechunk = null;
4115 ts.writecb = null;
4116
4117 if (data !== null && data !== undefined)
4118 stream.push(data);
4119
4120 if (cb)
4121 cb(er);
4122
4123 var rs = stream._readableState;
4124 rs.reading = false;
4125 if (rs.needReadable || rs.length < rs.highWaterMark) {
4126 stream._read(rs.highWaterMark);
4127 }
4128}
4129
4130
4131function Transform(options) {
4132 if (!(this instanceof Transform))
4133 return new Transform(options);
4134
4135 Duplex.call(this, options);
4136
4137 var ts = this._transformState = new TransformState(options, this);
4138
4139 // when the writable side finishes, then flush out anything remaining.
4140 var stream = this;
4141
4142 // start out asking for a readable event once data is transformed.
4143 this._readableState.needReadable = true;
4144
4145 // we have implemented the _read method, and done the other things
4146 // that Readable wants before the first _read call, so unset the
4147 // sync guard flag.
4148 this._readableState.sync = false;
4149
4150 this.once('finish', function() {
4151 if ('function' === typeof this._flush)
4152 this._flush(function(er) {
4153 done(stream, er);
4154 });
4155 else
4156 done(stream);
4157 });
4158}
4159
4160Transform.prototype.push = function(chunk, encoding) {
4161 this._transformState.needTransform = false;
4162 return Duplex.prototype.push.call(this, chunk, encoding);
4163};
4164
4165// This is the part where you do stuff!
4166// override this function in implementation classes.
4167// 'chunk' is an input chunk.
4168//
4169// Call `push(newChunk)` to pass along transformed output
4170// to the readable side. You may call 'push' zero or more times.
4171//
4172// Call `cb(err)` when you are done with this chunk. If you pass
4173// an error, then that'll put the hurt on the whole operation. If you
4174// never call cb(), then you'll never get another chunk.
4175Transform.prototype._transform = function(chunk, encoding, cb) {
4176 throw new Error('not implemented');
4177};
4178
4179Transform.prototype._write = function(chunk, encoding, cb) {
4180 var ts = this._transformState;
4181 ts.writecb = cb;
4182 ts.writechunk = chunk;
4183 ts.writeencoding = encoding;
4184 if (!ts.transforming) {
4185 var rs = this._readableState;
4186 if (ts.needTransform ||
4187 rs.needReadable ||
4188 rs.length < rs.highWaterMark)
4189 this._read(rs.highWaterMark);
4190 }
4191};
4192
4193// Doesn't matter what the args are here.
4194// _transform does all the work.
4195// That we got here means that the readable side wants more data.
4196Transform.prototype._read = function(n) {
4197 var ts = this._transformState;
4198
4199 if (ts.writechunk && ts.writecb && !ts.transforming) {
4200 ts.transforming = true;
4201 this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
4202 } else {
4203 // mark that we need a transform, so that any data that comes in
4204 // will get processed, now that we've asked for it.
4205 ts.needTransform = true;
4206 }
4207};
4208
4209
4210function done(stream, er) {
4211 if (er)
4212 return stream.emit('error', er);
4213
4214 // if there's nothing in the write buffer, then that means
4215 // that nothing more will ever be provided
4216 var ws = stream._writableState;
4217 var rs = stream._readableState;
4218 var ts = stream._transformState;
4219
4220 if (ws.length)
4221 throw new Error('calling transform done when ws.length != 0');
4222
4223 if (ts.transforming)
4224 throw new Error('calling transform done when still transforming');
4225
4226 return stream.push(null);
4227}
4228
4229},{"./duplex.js":17,"inherits":14}],23:[function(require,module,exports){
4230// Copyright Joyent, Inc. and other Node contributors.
4231//
4232// Permission is hereby granted, free of charge, to any person obtaining a
4233// copy of this software and associated documentation files (the
4234// "Software"), to deal in the Software without restriction, including
4235// without limitation the rights to use, copy, modify, merge, publish,
4236// distribute, sublicense, and/or sell copies of the Software, and to permit
4237// persons to whom the Software is furnished to do so, subject to the
4238// following conditions:
4239//
4240// The above copyright notice and this permission notice shall be included
4241// in all copies or substantial portions of the Software.
4242//
4243// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
4244// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
4245// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
4246// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
4247// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
4248// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
4249// USE OR OTHER DEALINGS IN THE SOFTWARE.
4250
4251// A bit simpler than readable streams.
4252// Implement an async ._write(chunk, cb), and it'll handle all
4253// the drain event emission and buffering.
4254
4255module.exports = Writable;
4256Writable.WritableState = WritableState;
4257
4258var isUint8Array = typeof Uint8Array !== 'undefined'
4259 ? function (x) { return x instanceof Uint8Array }
4260 : function (x) {
4261 return x && x.constructor && x.constructor.name === 'Uint8Array'
4262 }
4263;
4264var isArrayBuffer = typeof ArrayBuffer !== 'undefined'
4265 ? function (x) { return x instanceof ArrayBuffer }
4266 : function (x) {
4267 return x && x.constructor && x.constructor.name === 'ArrayBuffer'
4268 }
4269;
4270
4271var inherits = require('inherits');
4272var Stream = require('./index.js');
4273var setImmediate = require('process/browser.js').nextTick;
4274var Buffer = require('buffer').Buffer;
4275
4276inherits(Writable, Stream);
4277
4278function WriteReq(chunk, encoding, cb) {
4279 this.chunk = chunk;
4280 this.encoding = encoding;
4281 this.callback = cb;
4282}
4283
4284function WritableState(options, stream) {
4285 options = options || {};
4286
4287 // the point at which write() starts returning false
4288 // Note: 0 is a valid value, means that we always return false if
4289 // the entire buffer is not flushed immediately on write()
4290 var hwm = options.highWaterMark;
4291 this.highWaterMark = (hwm || hwm === 0) ? hwm : 16 * 1024;
4292
4293 // object stream flag to indicate whether or not this stream
4294 // contains buffers or objects.
4295 this.objectMode = !!options.objectMode;
4296
4297 // cast to ints.
4298 this.highWaterMark = ~~this.highWaterMark;
4299
4300 this.needDrain = false;
4301 // at the start of calling end()
4302 this.ending = false;
4303 // when end() has been called, and returned
4304 this.ended = false;
4305 // when 'finish' is emitted
4306 this.finished = false;
4307
4308 // should we decode strings into buffers before passing to _write?
4309 // this is here so that some node-core streams can optimize string
4310 // handling at a lower level.
4311 var noDecode = options.decodeStrings === false;
4312 this.decodeStrings = !noDecode;
4313
4314 // Crypto is kind of old and crusty. Historically, its default string
4315 // encoding is 'binary' so we have to make this configurable.
4316 // Everything else in the universe uses 'utf8', though.
4317 this.defaultEncoding = options.defaultEncoding || 'utf8';
4318
4319 // not an actual buffer we keep track of, but a measurement
4320 // of how much we're waiting to get pushed to some underlying
4321 // socket or file.
4322 this.length = 0;
4323
4324 // a flag to see when we're in the middle of a write.
4325 this.writing = false;
4326
4327 // a flag to be able to tell if the onwrite cb is called immediately,
4328 // or on a later tick. We set this to true at first, becuase any
4329 // actions that shouldn't happen until "later" should generally also
4330 // not happen before the first write call.
4331 this.sync = true;
4332
4333 // a flag to know if we're processing previously buffered items, which
4334 // may call the _write() callback in the same tick, so that we don't
4335 // end up in an overlapped onwrite situation.
4336 this.bufferProcessing = false;
4337
4338 // the callback that's passed to _write(chunk,cb)
4339 this.onwrite = function(er) {
4340 onwrite(stream, er);
4341 };
4342
4343 // the callback that the user supplies to write(chunk,encoding,cb)
4344 this.writecb = null;
4345
4346 // the amount that is being written when _write is called.
4347 this.writelen = 0;
4348
4349 this.buffer = [];
4350}
4351
4352function Writable(options) {
4353 // Writable ctor is applied to Duplexes, though they're not
4354 // instanceof Writable, they're instanceof Readable.
4355 if (!(this instanceof Writable) && !(this instanceof Stream.Duplex))
4356 return new Writable(options);
4357
4358 this._writableState = new WritableState(options, this);
4359
4360 // legacy.
4361 this.writable = true;
4362
4363 Stream.call(this);
4364}
4365
4366// Otherwise people can pipe Writable streams, which is just wrong.
4367Writable.prototype.pipe = function() {
4368 this.emit('error', new Error('Cannot pipe. Not readable.'));
4369};
4370
4371
4372function writeAfterEnd(stream, state, cb) {
4373 var er = new Error('write after end');
4374 // TODO: defer error events consistently everywhere, not just the cb
4375 stream.emit('error', er);
4376 setImmediate(function() {
4377 cb(er);
4378 });
4379}
4380
4381// If we get something that is not a buffer, string, null, or undefined,
4382// and we're not in objectMode, then that's an error.
4383// Otherwise stream chunks are all considered to be of length=1, and the
4384// watermarks determine how many objects to keep in the buffer, rather than
4385// how many bytes or characters.
4386function validChunk(stream, state, chunk, cb) {
4387 var valid = true;
4388 if (!Buffer.isBuffer(chunk) &&
4389 'string' !== typeof chunk &&
4390 chunk !== null &&
4391 chunk !== undefined &&
4392 !state.objectMode) {
4393 var er = new TypeError('Invalid non-string/buffer chunk');
4394 stream.emit('error', er);
4395 setImmediate(function() {
4396 cb(er);
4397 });
4398 valid = false;
4399 }
4400 return valid;
4401}
4402
4403Writable.prototype.write = function(chunk, encoding, cb) {
4404 var state = this._writableState;
4405 var ret = false;
4406
4407 if (typeof encoding === 'function') {
4408 cb = encoding;
4409 encoding = null;
4410 }
4411
4412 if (!Buffer.isBuffer(chunk) && isUint8Array(chunk))
4413 chunk = new Buffer(chunk);
4414 if (isArrayBuffer(chunk) && typeof Uint8Array !== 'undefined')
4415 chunk = new Buffer(new Uint8Array(chunk));
4416
4417 if (Buffer.isBuffer(chunk))
4418 encoding = 'buffer';
4419 else if (!encoding)
4420 encoding = state.defaultEncoding;
4421
4422 if (typeof cb !== 'function')
4423 cb = function() {};
4424
4425 if (state.ended)
4426 writeAfterEnd(this, state, cb);
4427 else if (validChunk(this, state, chunk, cb))
4428 ret = writeOrBuffer(this, state, chunk, encoding, cb);
4429
4430 return ret;
4431};
4432
4433function decodeChunk(state, chunk, encoding) {
4434 if (!state.objectMode &&
4435 state.decodeStrings !== false &&
4436 typeof chunk === 'string') {
4437 chunk = new Buffer(chunk, encoding);
4438 }
4439 return chunk;
4440}
4441
4442// if we're already writing something, then just put this
4443// in the queue, and wait our turn. Otherwise, call _write
4444// If we return false, then we need a drain event, so set that flag.
4445function writeOrBuffer(stream, state, chunk, encoding, cb) {
4446 chunk = decodeChunk(state, chunk, encoding);
4447 var len = state.objectMode ? 1 : chunk.length;
4448
4449 state.length += len;
4450
4451 var ret = state.length < state.highWaterMark;
4452 state.needDrain = !ret;
4453
4454 if (state.writing)
4455 state.buffer.push(new WriteReq(chunk, encoding, cb));
4456 else
4457 doWrite(stream, state, len, chunk, encoding, cb);
4458
4459 return ret;
4460}
4461
4462function doWrite(stream, state, len, chunk, encoding, cb) {
4463 state.writelen = len;
4464 state.writecb = cb;
4465 state.writing = true;
4466 state.sync = true;
4467 stream._write(chunk, encoding, state.onwrite);
4468 state.sync = false;
4469}
4470
4471function onwriteError(stream, state, sync, er, cb) {
4472 if (sync)
4473 setImmediate(function() {
4474 cb(er);
4475 });
4476 else
4477 cb(er);
4478
4479 stream.emit('error', er);
4480}
4481
4482function onwriteStateUpdate(state) {
4483 state.writing = false;
4484 state.writecb = null;
4485 state.length -= state.writelen;
4486 state.writelen = 0;
4487}
4488
4489function onwrite(stream, er) {
4490 var state = stream._writableState;
4491 var sync = state.sync;
4492 var cb = state.writecb;
4493
4494 onwriteStateUpdate(state);
4495
4496 if (er)
4497 onwriteError(stream, state, sync, er, cb);
4498 else {
4499 // Check if we're actually ready to finish, but don't emit yet
4500 var finished = needFinish(stream, state);
4501
4502 if (!finished && !state.bufferProcessing && state.buffer.length)
4503 clearBuffer(stream, state);
4504
4505 if (sync) {
4506 setImmediate(function() {
4507 afterWrite(stream, state, finished, cb);
4508 });
4509 } else {
4510 afterWrite(stream, state, finished, cb);
4511 }
4512 }
4513}
4514
4515function afterWrite(stream, state, finished, cb) {
4516 if (!finished)
4517 onwriteDrain(stream, state);
4518 cb();
4519 if (finished)
4520 finishMaybe(stream, state);
4521}
4522
4523// Must force callback to be called on nextTick, so that we don't
4524// emit 'drain' before the write() consumer gets the 'false' return
4525// value, and has a chance to attach a 'drain' listener.
4526function onwriteDrain(stream, state) {
4527 if (state.length === 0 && state.needDrain) {
4528 state.needDrain = false;
4529 stream.emit('drain');
4530 }
4531}
4532
4533
4534// if there's something in the buffer waiting, then process it
4535function clearBuffer(stream, state) {
4536 state.bufferProcessing = true;
4537
4538 for (var c = 0; c < state.buffer.length; c++) {
4539 var entry = state.buffer[c];
4540 var chunk = entry.chunk;
4541 var encoding = entry.encoding;
4542 var cb = entry.callback;
4543 var len = state.objectMode ? 1 : chunk.length;
4544
4545 doWrite(stream, state, len, chunk, encoding, cb);
4546
4547 // if we didn't call the onwrite immediately, then
4548 // it means that we need to wait until it does.
4549 // also, that means that the chunk and cb are currently
4550 // being processed, so move the buffer counter past them.
4551 if (state.writing) {
4552 c++;
4553 break;
4554 }
4555 }
4556
4557 state.bufferProcessing = false;
4558 if (c < state.buffer.length)
4559 state.buffer = state.buffer.slice(c);
4560 else
4561 state.buffer.length = 0;
4562}
4563
4564Writable.prototype._write = function(chunk, encoding, cb) {
4565 cb(new Error('not implemented'));
4566};
4567
4568Writable.prototype.end = function(chunk, encoding, cb) {
4569 var state = this._writableState;
4570
4571 if (typeof chunk === 'function') {
4572 cb = chunk;
4573 chunk = null;
4574 encoding = null;
4575 } else if (typeof encoding === 'function') {
4576 cb = encoding;
4577 encoding = null;
4578 }
4579
4580 if (typeof chunk !== 'undefined' && chunk !== null)
4581 this.write(chunk, encoding);
4582
4583 // ignore unnecessary end() calls.
4584 if (!state.ending && !state.finished)
4585 endWritable(this, state, cb);
4586};
4587
4588
4589function needFinish(stream, state) {
4590 return (state.ending &&
4591 state.length === 0 &&
4592 !state.finished &&
4593 !state.writing);
4594}
4595
4596function finishMaybe(stream, state) {
4597 var need = needFinish(stream, state);
4598 if (need) {
4599 state.finished = true;
4600 stream.emit('finish');
4601 }
4602 return need;
4603}
4604
4605function endWritable(stream, state, cb) {
4606 state.ending = true;
4607 finishMaybe(stream, state);
4608 if (cb) {
4609 if (state.finished)
4610 setImmediate(cb);
4611 else
4612 stream.once('finish', cb);
4613 }
4614 state.ended = true;
4615}
4616
4617},{"./index.js":18,"buffer":4,"inherits":14,"process/browser.js":19}],24:[function(require,module,exports){
4618// Copyright Joyent, Inc. and other Node contributors.
4619//
4620// Permission is hereby granted, free of charge, to any person obtaining a
4621// copy of this software and associated documentation files (the
4622// "Software"), to deal in the Software without restriction, including
4623// without limitation the rights to use, copy, modify, merge, publish,
4624// distribute, sublicense, and/or sell copies of the Software, and to permit
4625// persons to whom the Software is furnished to do so, subject to the
4626// following conditions:
4627//
4628// The above copyright notice and this permission notice shall be included
4629// in all copies or substantial portions of the Software.
4630//
4631// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
4632// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
4633// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
4634// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
4635// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
4636// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
4637// USE OR OTHER DEALINGS IN THE SOFTWARE.
4638
4639var Buffer = require('buffer').Buffer;
4640
4641function assertEncoding(encoding) {
4642 if (encoding && !Buffer.isEncoding(encoding)) {
4643 throw new Error('Unknown encoding: ' + encoding);
4644 }
4645}
4646
4647var StringDecoder = exports.StringDecoder = function(encoding) {
4648 this.encoding = (encoding || 'utf8').toLowerCase().replace(/[-_]/, '');
4649 assertEncoding(encoding);
4650 switch (this.encoding) {
4651 case 'utf8':
4652 // CESU-8 represents each of Surrogate Pair by 3-bytes
4653 this.surrogateSize = 3;
4654 break;
4655 case 'ucs2':
4656 case 'utf16le':
4657 // UTF-16 represents each of Surrogate Pair by 2-bytes
4658 this.surrogateSize = 2;
4659 this.detectIncompleteChar = utf16DetectIncompleteChar;
4660 break;
4661 case 'base64':
4662 // Base-64 stores 3 bytes in 4 chars, and pads the remainder.
4663 this.surrogateSize = 3;
4664 this.detectIncompleteChar = base64DetectIncompleteChar;
4665 break;
4666 default:
4667 this.write = passThroughWrite;
4668 return;
4669 }
4670
4671 this.charBuffer = new Buffer(6);
4672 this.charReceived = 0;
4673 this.charLength = 0;
4674};
4675
4676
4677StringDecoder.prototype.write = function(buffer) {
4678 var charStr = '';
4679 var offset = 0;
4680
4681 // if our last write ended with an incomplete multibyte character
4682 while (this.charLength) {
4683 // determine how many remaining bytes this buffer has to offer for this char
4684 var i = (buffer.length >= this.charLength - this.charReceived) ?
4685 this.charLength - this.charReceived :
4686 buffer.length;
4687
4688 // add the new bytes to the char buffer
4689 buffer.copy(this.charBuffer, this.charReceived, offset, i);
4690 this.charReceived += (i - offset);
4691 offset = i;
4692
4693 if (this.charReceived < this.charLength) {
4694 // still not enough chars in this buffer? wait for more ...
4695 return '';
4696 }
4697
4698 // get the character that was split
4699 charStr = this.charBuffer.slice(0, this.charLength).toString(this.encoding);
4700
4701 // lead surrogate (D800-DBFF) is also the incomplete character
4702 var charCode = charStr.charCodeAt(charStr.length - 1);
4703 if (charCode >= 0xD800 && charCode <= 0xDBFF) {
4704 this.charLength += this.surrogateSize;
4705 charStr = '';
4706 continue;
4707 }
4708 this.charReceived = this.charLength = 0;
4709
4710 // if there are no more bytes in this buffer, just emit our char
4711 if (i == buffer.length) return charStr;
4712
4713 // otherwise cut off the characters end from the beginning of this buffer
4714 buffer = buffer.slice(i, buffer.length);
4715 break;
4716 }
4717
4718 var lenIncomplete = this.detectIncompleteChar(buffer);
4719
4720 var end = buffer.length;
4721 if (this.charLength) {
4722 // buffer the incomplete character bytes we got
4723 buffer.copy(this.charBuffer, 0, buffer.length - lenIncomplete, end);
4724 this.charReceived = lenIncomplete;
4725 end -= lenIncomplete;
4726 }
4727
4728 charStr += buffer.toString(this.encoding, 0, end);
4729
4730 var end = charStr.length - 1;
4731 var charCode = charStr.charCodeAt(end);
4732 // lead surrogate (D800-DBFF) is also the incomplete character
4733 if (charCode >= 0xD800 && charCode <= 0xDBFF) {
4734 var size = this.surrogateSize;
4735 this.charLength += size;
4736 this.charReceived += size;
4737 this.charBuffer.copy(this.charBuffer, size, 0, size);
4738 this.charBuffer.write(charStr.charAt(charStr.length - 1), this.encoding);
4739 return charStr.substring(0, end);
4740 }
4741
4742 // or just emit the charStr
4743 return charStr;
4744};
4745
4746StringDecoder.prototype.detectIncompleteChar = function(buffer) {
4747 // determine how many bytes we have to check at the end of this buffer
4748 var i = (buffer.length >= 3) ? 3 : buffer.length;
4749
4750 // Figure out if one of the last i bytes of our buffer announces an
4751 // incomplete char.
4752 for (; i > 0; i--) {
4753 var c = buffer[buffer.length - i];
4754
4755 // See http://en.wikipedia.org/wiki/UTF-8#Description
4756
4757 // 110XXXXX
4758 if (i == 1 && c >> 5 == 0x06) {
4759 this.charLength = 2;
4760 break;
4761 }
4762
4763 // 1110XXXX
4764 if (i <= 2 && c >> 4 == 0x0E) {
4765 this.charLength = 3;
4766 break;
4767 }
4768
4769 // 11110XXX
4770 if (i <= 3 && c >> 3 == 0x1E) {
4771 this.charLength = 4;
4772 break;
4773 }
4774 }
4775
4776 return i;
4777};
4778
4779StringDecoder.prototype.end = function(buffer) {
4780 var res = '';
4781 if (buffer && buffer.length)
4782 res = this.write(buffer);
4783
4784 if (this.charReceived) {
4785 var cr = this.charReceived;
4786 var buf = this.charBuffer;
4787 var enc = this.encoding;
4788 res += buf.slice(0, cr).toString(enc);
4789 }
4790
4791 return res;
4792};
4793
4794function passThroughWrite(buffer) {
4795 return buffer.toString(this.encoding);
4796}
4797
4798function utf16DetectIncompleteChar(buffer) {
4799 var incomplete = this.charReceived = buffer.length % 2;
4800 this.charLength = incomplete ? 2 : 0;
4801 return incomplete;
4802}
4803
4804function base64DetectIncompleteChar(buffer) {
4805 var incomplete = this.charReceived = buffer.length % 3;
4806 this.charLength = incomplete ? 3 : 0;
4807 return incomplete;
4808}
4809
4810},{"buffer":4}],25:[function(require,module,exports){
4811module.exports = function isBuffer(arg) {
4812 return arg && typeof arg === 'object'
4813 && typeof arg.copy === 'function'
4814 && typeof arg.fill === 'function'
4815 && typeof arg.readUInt8 === 'function';
4816}
4817},{}],26:[function(require,module,exports){
4818(function (process,global){
4819// Copyright Joyent, Inc. and other Node contributors.
4820//
4821// Permission is hereby granted, free of charge, to any person obtaining a
4822// copy of this software and associated documentation files (the
4823// "Software"), to deal in the Software without restriction, including
4824// without limitation the rights to use, copy, modify, merge, publish,
4825// distribute, sublicense, and/or sell copies of the Software, and to permit
4826// persons to whom the Software is furnished to do so, subject to the
4827// following conditions:
4828//
4829// The above copyright notice and this permission notice shall be included
4830// in all copies or substantial portions of the Software.
4831//
4832// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
4833// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
4834// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
4835// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
4836// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
4837// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
4838// USE OR OTHER DEALINGS IN THE SOFTWARE.
4839
4840var formatRegExp = /%[sdj%]/g;
4841exports.format = function(f) {
4842 if (!isString(f)) {
4843 var objects = [];
4844 for (var i = 0; i < arguments.length; i++) {
4845 objects.push(inspect(arguments[i]));
4846 }
4847 return objects.join(' ');
4848 }
4849
4850 var i = 1;
4851 var args = arguments;
4852 var len = args.length;
4853 var str = String(f).replace(formatRegExp, function(x) {
4854 if (x === '%%') return '%';
4855 if (i >= len) return x;
4856 switch (x) {
4857 case '%s': return String(args[i++]);
4858 case '%d': return Number(args[i++]);
4859 case '%j':
4860 try {
4861 return JSON.stringify(args[i++]);
4862 } catch (_) {
4863 return '[Circular]';
4864 }
4865 default:
4866 return x;
4867 }
4868 });
4869 for (var x = args[i]; i < len; x = args[++i]) {
4870 if (isNull(x) || !isObject(x)) {
4871 str += ' ' + x;
4872 } else {
4873 str += ' ' + inspect(x);
4874 }
4875 }
4876 return str;
4877};
4878
4879
4880// Mark that a method should not be used.
4881// Returns a modified function which warns once by default.
4882// If --no-deprecation is set, then it is a no-op.
4883exports.deprecate = function(fn, msg) {
4884 // Allow for deprecating things in the process of starting up.
4885 if (isUndefined(global.process)) {
4886 return function() {
4887 return exports.deprecate(fn, msg).apply(this, arguments);
4888 };
4889 }
4890
4891 if (process.noDeprecation === true) {
4892 return fn;
4893 }
4894
4895 var warned = false;
4896 function deprecated() {
4897 if (!warned) {
4898 if (process.throwDeprecation) {
4899 throw new Error(msg);
4900 } else if (process.traceDeprecation) {
4901 console.trace(msg);
4902 } else {
4903 console.error(msg);
4904 }
4905 warned = true;
4906 }
4907 return fn.apply(this, arguments);
4908 }
4909
4910 return deprecated;
4911};
4912
4913
4914var debugs = {};
4915var debugEnviron;
4916exports.debuglog = function(set) {
4917 if (isUndefined(debugEnviron))
4918 debugEnviron = process.env.NODE_DEBUG || '';
4919 set = set.toUpperCase();
4920 if (!debugs[set]) {
4921 if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
4922 var pid = process.pid;
4923 debugs[set] = function() {
4924 var msg = exports.format.apply(exports, arguments);
4925 console.error('%s %d: %s', set, pid, msg);
4926 };
4927 } else {
4928 debugs[set] = function() {};
4929 }
4930 }
4931 return debugs[set];
4932};
4933
4934
4935/**
4936 * Echos the value of a value. Trys to print the value out
4937 * in the best way possible given the different types.
4938 *
4939 * @param {Object} obj The object to print out.
4940 * @param {Object} opts Optional options object that alters the output.
4941 */
4942/* legacy: obj, showHidden, depth, colors*/
4943function inspect(obj, opts) {
4944 // default options
4945 var ctx = {
4946 seen: [],
4947 stylize: stylizeNoColor
4948 };
4949 // legacy...
4950 if (arguments.length >= 3) ctx.depth = arguments[2];
4951 if (arguments.length >= 4) ctx.colors = arguments[3];
4952 if (isBoolean(opts)) {
4953 // legacy...
4954 ctx.showHidden = opts;
4955 } else if (opts) {
4956 // got an "options" object
4957 exports._extend(ctx, opts);
4958 }
4959 // set default options
4960 if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
4961 if (isUndefined(ctx.depth)) ctx.depth = 2;
4962 if (isUndefined(ctx.colors)) ctx.colors = false;
4963 if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
4964 if (ctx.colors) ctx.stylize = stylizeWithColor;
4965 return formatValue(ctx, obj, ctx.depth);
4966}
4967exports.inspect = inspect;
4968
4969
4970// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
4971inspect.colors = {
4972 'bold' : [1, 22],
4973 'italic' : [3, 23],
4974 'underline' : [4, 24],
4975 'inverse' : [7, 27],
4976 'white' : [37, 39],
4977 'grey' : [90, 39],
4978 'black' : [30, 39],
4979 'blue' : [34, 39],
4980 'cyan' : [36, 39],
4981 'green' : [32, 39],
4982 'magenta' : [35, 39],
4983 'red' : [31, 39],
4984 'yellow' : [33, 39]
4985};
4986
4987// Don't use 'blue' not visible on cmd.exe
4988inspect.styles = {
4989 'special': 'cyan',
4990 'number': 'yellow',
4991 'boolean': 'yellow',
4992 'undefined': 'grey',
4993 'null': 'bold',
4994 'string': 'green',
4995 'date': 'magenta',
4996 // "name": intentionally not styling
4997 'regexp': 'red'
4998};
4999
5000
5001function stylizeWithColor(str, styleType) {
5002 var style = inspect.styles[styleType];
5003
5004 if (style) {
5005 return '\u001b[' + inspect.colors[style][0] + 'm' + str +
5006 '\u001b[' + inspect.colors[style][1] + 'm';
5007 } else {
5008 return str;
5009 }
5010}
5011
5012
5013function stylizeNoColor(str, styleType) {
5014 return str;
5015}
5016
5017
5018function arrayToHash(array) {
5019 var hash = {};
5020
5021 array.forEach(function(val, idx) {
5022 hash[val] = true;
5023 });
5024
5025 return hash;
5026}
5027
5028
5029function formatValue(ctx, value, recurseTimes) {
5030 // Provide a hook for user-specified inspect functions.
5031 // Check that value is an object with an inspect function on it
5032 if (ctx.customInspect &&
5033 value &&
5034 isFunction(value.inspect) &&
5035 // Filter out the util module, it's inspect function is special
5036 value.inspect !== exports.inspect &&
5037 // Also filter out any prototype objects using the circular check.
5038 !(value.constructor && value.constructor.prototype === value)) {
5039 var ret = value.inspect(recurseTimes, ctx);
5040 if (!isString(ret)) {
5041 ret = formatValue(ctx, ret, recurseTimes);
5042 }
5043 return ret;
5044 }
5045
5046 // Primitive types cannot have properties
5047 var primitive = formatPrimitive(ctx, value);
5048 if (primitive) {
5049 return primitive;
5050 }
5051
5052 // Look up the keys of the object.
5053 var keys = Object.keys(value);
5054 var visibleKeys = arrayToHash(keys);
5055
5056 if (ctx.showHidden) {
5057 keys = Object.getOwnPropertyNames(value);
5058 }
5059
5060 // IE doesn't make error fields non-enumerable
5061 // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx
5062 if (isError(value)
5063 && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
5064 return formatError(value);
5065 }
5066
5067 // Some type of object without properties can be shortcutted.
5068 if (keys.length === 0) {
5069 if (isFunction(value)) {
5070 var name = value.name ? ': ' + value.name : '';
5071 return ctx.stylize('[Function' + name + ']', 'special');
5072 }
5073 if (isRegExp(value)) {
5074 return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
5075 }
5076 if (isDate(value)) {
5077 return ctx.stylize(Date.prototype.toString.call(value), 'date');
5078 }
5079 if (isError(value)) {
5080 return formatError(value);
5081 }
5082 }
5083
5084 var base = '', array = false, braces = ['{', '}'];
5085
5086 // Make Array say that they are Array
5087 if (isArray(value)) {
5088 array = true;
5089 braces = ['[', ']'];
5090 }
5091
5092 // Make functions say that they are functions
5093 if (isFunction(value)) {
5094 var n = value.name ? ': ' + value.name : '';
5095 base = ' [Function' + n + ']';
5096 }
5097
5098 // Make RegExps say that they are RegExps
5099 if (isRegExp(value)) {
5100 base = ' ' + RegExp.prototype.toString.call(value);
5101 }
5102
5103 // Make dates with properties first say the date
5104 if (isDate(value)) {
5105 base = ' ' + Date.prototype.toUTCString.call(value);
5106 }
5107
5108 // Make error with message first say the error
5109 if (isError(value)) {
5110 base = ' ' + formatError(value);
5111 }
5112
5113 if (keys.length === 0 && (!array || value.length == 0)) {
5114 return braces[0] + base + braces[1];
5115 }
5116
5117 if (recurseTimes < 0) {
5118 if (isRegExp(value)) {
5119 return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
5120 } else {
5121 return ctx.stylize('[Object]', 'special');
5122 }
5123 }
5124
5125 ctx.seen.push(value);
5126
5127 var output;
5128 if (array) {
5129 output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
5130 } else {
5131 output = keys.map(function(key) {
5132 return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
5133 });
5134 }
5135
5136 ctx.seen.pop();
5137
5138 return reduceToSingleString(output, base, braces);
5139}
5140
5141
5142function formatPrimitive(ctx, value) {
5143 if (isUndefined(value))
5144 return ctx.stylize('undefined', 'undefined');
5145 if (isString(value)) {
5146 var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
5147 .replace(/'/g, "\\'")
5148 .replace(/\\"/g, '"') + '\'';
5149 return ctx.stylize(simple, 'string');
5150 }
5151 if (isNumber(value))
5152 return ctx.stylize('' + value, 'number');
5153 if (isBoolean(value))
5154 return ctx.stylize('' + value, 'boolean');
5155 // For some reason typeof null is "object", so special case here.
5156 if (isNull(value))
5157 return ctx.stylize('null', 'null');
5158}
5159
5160
5161function formatError(value) {
5162 return '[' + Error.prototype.toString.call(value) + ']';
5163}
5164
5165
5166function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
5167 var output = [];
5168 for (var i = 0, l = value.length; i < l; ++i) {
5169 if (hasOwnProperty(value, String(i))) {
5170 output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
5171 String(i), true));
5172 } else {
5173 output.push('');
5174 }
5175 }
5176 keys.forEach(function(key) {
5177 if (!key.match(/^\d+$/)) {
5178 output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
5179 key, true));
5180 }
5181 });
5182 return output;
5183}
5184
5185
5186function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
5187 var name, str, desc;
5188 desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
5189 if (desc.get) {
5190 if (desc.set) {
5191 str = ctx.stylize('[Getter/Setter]', 'special');
5192 } else {
5193 str = ctx.stylize('[Getter]', 'special');
5194 }
5195 } else {
5196 if (desc.set) {
5197 str = ctx.stylize('[Setter]', 'special');
5198 }
5199 }
5200 if (!hasOwnProperty(visibleKeys, key)) {
5201 name = '[' + key + ']';
5202 }
5203 if (!str) {
5204 if (ctx.seen.indexOf(desc.value) < 0) {
5205 if (isNull(recurseTimes)) {
5206 str = formatValue(ctx, desc.value, null);
5207 } else {
5208 str = formatValue(ctx, desc.value, recurseTimes - 1);
5209 }
5210 if (str.indexOf('\n') > -1) {
5211 if (array) {
5212 str = str.split('\n').map(function(line) {
5213 return ' ' + line;
5214 }).join('\n').substr(2);
5215 } else {
5216 str = '\n' + str.split('\n').map(function(line) {
5217 return ' ' + line;
5218 }).join('\n');
5219 }
5220 }
5221 } else {
5222 str = ctx.stylize('[Circular]', 'special');
5223 }
5224 }
5225 if (isUndefined(name)) {
5226 if (array && key.match(/^\d+$/)) {
5227 return str;
5228 }
5229 name = JSON.stringify('' + key);
5230 if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
5231 name = name.substr(1, name.length - 2);
5232 name = ctx.stylize(name, 'name');
5233 } else {
5234 name = name.replace(/'/g, "\\'")
5235 .replace(/\\"/g, '"')
5236 .replace(/(^"|"$)/g, "'");
5237 name = ctx.stylize(name, 'string');
5238 }
5239 }
5240
5241 return name + ': ' + str;
5242}
5243
5244
5245function reduceToSingleString(output, base, braces) {
5246 var numLinesEst = 0;
5247 var length = output.reduce(function(prev, cur) {
5248 numLinesEst++;
5249 if (cur.indexOf('\n') >= 0) numLinesEst++;
5250 return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
5251 }, 0);
5252
5253 if (length > 60) {
5254 return braces[0] +
5255 (base === '' ? '' : base + '\n ') +
5256 ' ' +
5257 output.join(',\n ') +
5258 ' ' +
5259 braces[1];
5260 }
5261
5262 return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
5263}
5264
5265
5266// NOTE: These type checking functions intentionally don't use `instanceof`
5267// because it is fragile and can be easily faked with `Object.create()`.
5268function isArray(ar) {
5269 return Array.isArray(ar);
5270}
5271exports.isArray = isArray;
5272
5273function isBoolean(arg) {
5274 return typeof arg === 'boolean';
5275}
5276exports.isBoolean = isBoolean;
5277
5278function isNull(arg) {
5279 return arg === null;
5280}
5281exports.isNull = isNull;
5282
5283function isNullOrUndefined(arg) {
5284 return arg == null;
5285}
5286exports.isNullOrUndefined = isNullOrUndefined;
5287
5288function isNumber(arg) {
5289 return typeof arg === 'number';
5290}
5291exports.isNumber = isNumber;
5292
5293function isString(arg) {
5294 return typeof arg === 'string';
5295}
5296exports.isString = isString;
5297
5298function isSymbol(arg) {
5299 return typeof arg === 'symbol';
5300}
5301exports.isSymbol = isSymbol;
5302
5303function isUndefined(arg) {
5304 return arg === void 0;
5305}
5306exports.isUndefined = isUndefined;
5307
5308function isRegExp(re) {
5309 return isObject(re) && objectToString(re) === '[object RegExp]';
5310}
5311exports.isRegExp = isRegExp;
5312
5313function isObject(arg) {
5314 return typeof arg === 'object' && arg !== null;
5315}
5316exports.isObject = isObject;
5317
5318function isDate(d) {
5319 return isObject(d) && objectToString(d) === '[object Date]';
5320}
5321exports.isDate = isDate;
5322
5323function isError(e) {
5324 return isObject(e) &&
5325 (objectToString(e) === '[object Error]' || e instanceof Error);
5326}
5327exports.isError = isError;
5328
5329function isFunction(arg) {
5330 return typeof arg === 'function';
5331}
5332exports.isFunction = isFunction;
5333
5334function isPrimitive(arg) {
5335 return arg === null ||
5336 typeof arg === 'boolean' ||
5337 typeof arg === 'number' ||
5338 typeof arg === 'string' ||
5339 typeof arg === 'symbol' || // ES6 symbol
5340 typeof arg === 'undefined';
5341}
5342exports.isPrimitive = isPrimitive;
5343
5344exports.isBuffer = require('./support/isBuffer');
5345
5346function objectToString(o) {
5347 return Object.prototype.toString.call(o);
5348}
5349
5350
5351function pad(n) {
5352 return n < 10 ? '0' + n.toString(10) : n.toString(10);
5353}
5354
5355
5356var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
5357 'Oct', 'Nov', 'Dec'];
5358
5359// 26 Feb 16:19:34
5360function timestamp() {
5361 var d = new Date();
5362 var time = [pad(d.getHours()),
5363 pad(d.getMinutes()),
5364 pad(d.getSeconds())].join(':');
5365 return [d.getDate(), months[d.getMonth()], time].join(' ');
5366}
5367
5368
5369// log is just a thin wrapper to console.log that prepends a timestamp
5370exports.log = function() {
5371 console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments));
5372};
5373
5374
5375/**
5376 * Inherit the prototype methods from one constructor into another.
5377 *
5378 * The Function.prototype.inherits from lang.js rewritten as a standalone
5379 * function (not on Function.prototype). NOTE: If this file is to be loaded
5380 * during bootstrapping this function needs to be rewritten using some native
5381 * functions as prototype setup using normal JavaScript does not work as
5382 * expected during bootstrapping (see mirror.js in r114903).
5383 *
5384 * @param {function} ctor Constructor function which needs to inherit the
5385 * prototype.
5386 * @param {function} superCtor Constructor function to inherit prototype from.
5387 */
5388exports.inherits = require('inherits');
5389
5390exports._extend = function(origin, add) {
5391 // Don't do anything if add isn't an object
5392 if (!add || !isObject(add)) return origin;
5393
5394 var keys = Object.keys(add);
5395 var i = keys.length;
5396 while (i--) {
5397 origin[keys[i]] = add[keys[i]];
5398 }
5399 return origin;
5400};
5401
5402function hasOwnProperty(obj, prop) {
5403 return Object.prototype.hasOwnProperty.call(obj, prop);
5404}
5405
5406}).call(this,require("/Users/scott/Code/object-hash/node_modules/gulp-browserify/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
5407},{"./support/isBuffer":25,"/Users/scott/Code/object-hash/node_modules/gulp-browserify/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js":15,"inherits":14}],27:[function(require,module,exports){
5408(function (process){
5409var defined = require('defined');
5410var createDefaultStream = require('./lib/default_stream');
5411var Test = require('./lib/test');
5412var createResult = require('./lib/results');
5413var through = require('through');
5414
5415var canEmitExit = typeof process !== 'undefined' && process
5416 && typeof process.on === 'function'
5417;
5418var canExit = typeof process !== 'undefined' && process
5419 && typeof process.exit === 'function'
5420;
5421
5422var nextTick = typeof setImmediate !== 'undefined'
5423 ? setImmediate
5424 : process.nextTick
5425;
5426
5427exports = module.exports = (function () {
5428 var harness;
5429 var lazyLoad = function () {
5430 return getHarness().apply(this, arguments);
5431 };
5432
5433 lazyLoad.only = function () {
5434 return getHarness().only.apply(this, arguments);
5435 };
5436
5437 lazyLoad.createStream = function (opts) {
5438 if (!opts) opts = {};
5439 if (!harness) {
5440 var output = through();
5441 getHarness({ stream: output, objectMode: opts.objectMode });
5442 return output;
5443 }
5444 return harness.createStream(opts);
5445 };
5446
5447 return lazyLoad
5448
5449 function getHarness (opts) {
5450 if (!opts) opts = {};
5451 opts.autoclose = !canEmitExit;
5452 if (!harness) harness = createExitHarness(opts);
5453 return harness;
5454 }
5455})();
5456
5457function createExitHarness (conf) {
5458 if (!conf) conf = {};
5459 var harness = createHarness({
5460 autoclose: defined(conf.autoclose, false)
5461 });
5462
5463 var stream = harness.createStream({ objectMode: conf.objectMode });
5464 var es = stream.pipe(conf.stream || createDefaultStream());
5465 if (canEmitExit) {
5466 es.on('error', function (err) { harness._exitCode = 1 });
5467 }
5468
5469 var ended = false;
5470 stream.on('end', function () { ended = true });
5471
5472 if (conf.exit === false) return harness;
5473 if (!canEmitExit || !canExit) return harness;
5474
5475 var _error;
5476
5477 process.on('uncaughtException', function (err) {
5478 if (err && err.code === 'EPIPE' && err.errno === 'EPIPE'
5479 && err.syscall === 'write') return;
5480
5481 _error = err
5482
5483 throw err
5484 })
5485
5486 process.on('exit', function (code) {
5487 if (_error) {
5488 return
5489 }
5490
5491 if (!ended) {
5492 var only = harness._results._only;
5493 for (var i = 0; i < harness._tests.length; i++) {
5494 var t = harness._tests[i];
5495 if (only && t.name !== only) continue;
5496 t._exit();
5497 }
5498 }
5499 harness.close();
5500 process.exit(code || harness._exitCode);
5501 });
5502
5503 return harness;
5504}
5505
5506exports.createHarness = createHarness;
5507exports.Test = Test;
5508exports.test = exports; // tap compat
5509
5510var exitInterval;
5511
5512function createHarness (conf_) {
5513 if (!conf_) conf_ = {};
5514 var results = createResult();
5515 if (conf_.autoclose !== false) {
5516 results.once('done', function () { results.close() });
5517 }
5518
5519 var test = function (name, conf, cb) {
5520 var t = new Test(name, conf, cb);
5521 test._tests.push(t);
5522
5523 (function inspectCode (st) {
5524 st.on('test', function sub (st_) {
5525 inspectCode(st_);
5526 });
5527 st.on('result', function (r) {
5528 if (!r.ok) test._exitCode = 1
5529 });
5530 })(t);
5531
5532 results.push(t);
5533 return t;
5534 };
5535 test._results = results;
5536
5537 test._tests = [];
5538
5539 test.createStream = function (opts) {
5540 return results.createStream(opts);
5541 };
5542
5543 var only = false;
5544 test.only = function (name) {
5545 if (only) throw new Error('there can only be one only test');
5546 results.only(name);
5547 only = true;
5548 return test.apply(null, arguments);
5549 };
5550 test._exitCode = 0;
5551
5552 test.close = function () { results.close() };
5553
5554 return test;
5555}
5556
5557}).call(this,require("/Users/scott/Code/object-hash/node_modules/gulp-browserify/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js"))
5558},{"./lib/default_stream":28,"./lib/results":29,"./lib/test":30,"/Users/scott/Code/object-hash/node_modules/gulp-browserify/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js":15,"defined":34,"through":38}],28:[function(require,module,exports){
5559var through = require('through');
5560
5561module.exports = function () {
5562 var line = '';
5563 var stream = through(write, flush);
5564 return stream;
5565
5566 function write (buf) {
5567 for (var i = 0; i < buf.length; i++) {
5568 var c = typeof buf === 'string'
5569 ? buf.charAt(i)
5570 : String.fromCharCode(buf[i])
5571 ;
5572 if (c === '\n') flush();
5573 else line += c;
5574 }
5575 }
5576
5577 function flush () {
5578 try { console.log(line); }
5579 catch (e) { stream.emit('error', e) }
5580 line = '';
5581 }
5582};
5583
5584},{"through":38}],29:[function(require,module,exports){
5585(function (process){
5586var EventEmitter = require('events').EventEmitter;
5587var inherits = require('inherits');
5588var through = require('through');
5589var resumer = require('resumer');
5590var inspect = require('object-inspect');
5591var nextTick = typeof setImmediate !== 'undefined'
5592 ? setImmediate
5593 : process.nextTick
5594;
5595
5596module.exports = Results;
5597inherits(Results, EventEmitter);
5598
5599function Results () {
5600 if (!(this instanceof Results)) return new Results;
5601 this.count = 0;
5602 this.fail = 0;
5603 this.pass = 0;
5604 this._stream = through();
5605 this.tests = [];
5606}
5607
5608Results.prototype.createStream = function (opts) {
5609 if (!opts) opts = {};
5610 var self = this;
5611 var output, testId = 0;
5612 if (opts.objectMode) {
5613 output = through();
5614 self.on('_push', function ontest (t, extra) {
5615 if (!extra) extra = {};
5616 var id = testId++;
5617 t.once('prerun', function () {
5618 var row = {
5619 type: 'test',
5620 name: t.name,
5621 id: id
5622 };
5623 if (extra.parent) {
5624 row.parent = extra.parent;
5625 }
5626 output.queue(row);
5627 });
5628 t.on('test', function (st) {
5629 ontest(st, { parent: id });
5630 });
5631 t.on('result', function (res) {
5632 res.test = id;
5633 res.type = 'assert';
5634 output.queue(res);
5635 });
5636 t.on('end', function () {
5637 output.queue({ type: 'end', test: id });
5638 });
5639 });
5640 self.on('done', function () { output.queue(null) });
5641 }
5642 else {
5643 output = resumer();
5644 output.queue('TAP version 13\n');
5645 self._stream.pipe(output);
5646 }
5647
5648 nextTick(function next() {
5649 var t;
5650 while (t = getNextTest(self)) {
5651 t.run();
5652 if (!t.ended) return t.once('end', function(){ nextTick(next); });
5653 }
5654 self.emit('done');
5655 });
5656
5657 return output;
5658};
5659
5660Results.prototype.push = function (t) {
5661 var self = this;
5662 self.tests.push(t);
5663 self._watch(t);
5664 self.emit('_push', t);
5665};
5666
5667Results.prototype.only = function (name) {
5668 if (this._only) {
5669 self.count ++;
5670 self.fail ++;
5671 write('not ok ' + self.count + ' already called .only()\n');
5672 }
5673 this._only = name;
5674};
5675
5676Results.prototype._watch = function (t) {
5677 var self = this;
5678 var write = function (s) { self._stream.queue(s) };
5679 t.once('prerun', function () {
5680 write('# ' + t.name + '\n');
5681 });
5682
5683 t.on('result', function (res) {
5684 if (typeof res === 'string') {
5685 write('# ' + res + '\n');
5686 return;
5687 }
5688 write(encodeResult(res, self.count + 1));
5689 self.count ++;
5690
5691 if (res.ok) self.pass ++
5692 else self.fail ++
5693 });
5694
5695 t.on('test', function (st) { self._watch(st) });
5696};
5697
5698Results.prototype.close = function () {
5699 var self = this;
5700 if (self.closed) self._stream.emit('error', new Error('ALREADY CLOSED'));
5701 self.closed = true;
5702 var write = function (s) { self._stream.queue(s) };
5703
5704 write('\n1..' + self.count + '\n');
5705 write('# tests ' + self.count + '\n');
5706 write('# pass ' + self.pass + '\n');
5707 if (self.fail) write('# fail ' + self.fail + '\n')
5708 else write('\n# ok\n')
5709
5710 self._stream.queue(null);
5711};
5712
5713function encodeResult (res, count) {
5714 var output = '';
5715 output += (res.ok ? 'ok ' : 'not ok ') + count;
5716 output += res.name ? ' ' + res.name.toString().replace(/\s+/g, ' ') : '';
5717
5718 if (res.skip) output += ' # SKIP';
5719 else if (res.todo) output += ' # TODO';
5720
5721 output += '\n';
5722 if (res.ok) return output;
5723
5724 var outer = ' ';
5725 var inner = outer + ' ';
5726 output += outer + '---\n';
5727 output += inner + 'operator: ' + res.operator + '\n';
5728
5729 if (has(res, 'expected') || has(res, 'actual')) {
5730 var ex = inspect(res.expected);
5731 var ac = inspect(res.actual);
5732
5733 if (Math.max(ex.length, ac.length) > 65) {
5734 output += inner + 'expected:\n' + inner + ' ' + ex + '\n';
5735 output += inner + 'actual:\n' + inner + ' ' + ac + '\n';
5736 }
5737 else {
5738 output += inner + 'expected: ' + ex + '\n';
5739 output += inner + 'actual: ' + ac + '\n';
5740 }
5741 }
5742 if (res.at) {
5743 output += inner + 'at: ' + res.at + '\n';
5744 }
5745 if (res.operator === 'error' && res.actual && res.actual.stack) {
5746 var lines = String(res.actual.stack).split('\n');
5747 output += inner + 'stack:\n';
5748 output += inner + ' ' + lines[0] + '\n';
5749 for (var i = 1; i < lines.length; i++) {
5750 output += inner + lines[i] + '\n';
5751 }
5752 }
5753
5754 output += outer + '...\n';
5755 return output;
5756}
5757
5758function getNextTest (results) {
5759 if (!results._only) {
5760 return results.tests.shift();
5761 }
5762
5763 do {
5764 var t = results.tests.shift();
5765 if (!t) continue;
5766 if (results._only === t.name) {
5767 return t;
5768 }
5769 } while (results.tests.length !== 0)
5770}
5771
5772function has (obj, prop) {
5773 return Object.prototype.hasOwnProperty.call(obj, prop);
5774}
5775
5776}).call(this,require("/Users/scott/Code/object-hash/node_modules/gulp-browserify/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js"))
5777},{"/Users/scott/Code/object-hash/node_modules/gulp-browserify/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js":15,"events":13,"inherits":35,"object-inspect":36,"resumer":37,"through":38}],30:[function(require,module,exports){
5778(function (process,__dirname){
5779var Stream = require('stream');
5780var deepEqual = require('deep-equal');
5781var defined = require('defined');
5782var path = require('path');
5783var inherits = require('util').inherits;
5784var EventEmitter = require('events').EventEmitter;
5785
5786module.exports = Test;
5787
5788var nextTick = typeof setImmediate !== 'undefined'
5789 ? setImmediate
5790 : process.nextTick
5791;
5792
5793inherits(Test, EventEmitter);
5794
5795function Test (name_, opts_, cb_) {
5796 var self = this;
5797 var name = '(anonymous)';
5798 var opts = {};
5799 var cb;
5800
5801 for (var i = 0; i < arguments.length; i++) {
5802 switch (typeof arguments[i]) {
5803 case 'string':
5804 name = arguments[i];
5805 break;
5806 case 'object':
5807 opts = arguments[i] || opts;
5808 break;
5809 case 'function':
5810 cb = arguments[i];
5811 }
5812 }
5813
5814 this.readable = true;
5815 this.name = name || '(anonymous)';
5816 this.assertCount = 0;
5817 this.pendingCount = 0;
5818 this._skip = opts.skip || false;
5819 this._plan = undefined;
5820 this._cb = cb;
5821 this._progeny = [];
5822 this._ok = true;
5823 this.end = function () {
5824 return Test.prototype.end.apply(self, arguments);
5825 };
5826}
5827
5828Test.prototype.run = function () {
5829 if (!this._cb || this._skip) {
5830 return this._end();
5831 }
5832 this.emit('prerun');
5833 try {
5834 this._cb(this);
5835 }
5836 catch (err) {
5837 this.error(err);
5838 this._end();
5839 return;
5840 }
5841 this.emit('run');
5842};
5843
5844Test.prototype.test = function (name, opts, cb) {
5845 var self = this;
5846 var t = new Test(name, opts, cb);
5847 this._progeny.push(t);
5848 this.pendingCount++;
5849 this.emit('test', t);
5850 t.on('prerun', function () {
5851 self.assertCount++;
5852 })
5853
5854 if (!self._pendingAsserts()) {
5855 nextTick(function () {
5856 self._end();
5857 });
5858 }
5859
5860 nextTick(function() {
5861 if (!self._plan && self.pendingCount == self._progeny.length) {
5862 self._end();
5863 }
5864 });
5865};
5866
5867Test.prototype.comment = function (msg) {
5868 this.emit('result', msg.trim().replace(/^#\s*/, ''));
5869};
5870
5871Test.prototype.plan = function (n) {
5872 this._plan = n;
5873 this.emit('plan', n);
5874};
5875
5876Test.prototype.end = function (err) {
5877 var self = this;
5878 if (arguments.length >= 1) {
5879 this.ifError(err);
5880 }
5881
5882 if (this.calledEnd) {
5883 this.fail('.end() called twice');
5884 }
5885 this.calledEnd = true;
5886 this._end();
5887};
5888
5889Test.prototype._end = function (err) {
5890 var self = this;
5891 if (this._progeny.length) {
5892 var t = this._progeny.shift();
5893 t.on('end', function () { self._end() });
5894 t.run();
5895 return;
5896 }
5897
5898 if (!this.ended) this.emit('end');
5899 var pendingAsserts = this._pendingAsserts();
5900 if (!this._planError && this._plan !== undefined && pendingAsserts) {
5901 this._planError = true;
5902 this.fail('plan != count', {
5903 expected : this._plan,
5904 actual : this.assertCount
5905 });
5906 }
5907 this.ended = true;
5908};
5909
5910Test.prototype._exit = function () {
5911 if (this._plan !== undefined &&
5912 !this._planError && this.assertCount !== this._plan) {
5913 this._planError = true;
5914 this.fail('plan != count', {
5915 expected : this._plan,
5916 actual : this.assertCount,
5917 exiting : true
5918 });
5919 }
5920 else if (!this.ended) {
5921 this.fail('test exited without ending', {
5922 exiting: true
5923 });
5924 }
5925};
5926
5927Test.prototype._pendingAsserts = function () {
5928 if (this._plan === undefined) {
5929 return 1;
5930 }
5931 else {
5932 return this._plan - (this._progeny.length + this.assertCount);
5933 }
5934};
5935
5936Test.prototype._assert = function assert (ok, opts) {
5937 var self = this;
5938 var extra = opts.extra || {};
5939
5940 var res = {
5941 id : self.assertCount ++,
5942 ok : Boolean(ok),
5943 skip : defined(extra.skip, opts.skip),
5944 name : defined(extra.message, opts.message, '(unnamed assert)'),
5945 operator : defined(extra.operator, opts.operator)
5946 };
5947 if (has(opts, 'actual') || has(extra, 'actual')) {
5948 res.actual = defined(extra.actual, opts.actual);
5949 }
5950 if (has(opts, 'expected') || has(extra, 'expected')) {
5951 res.expected = defined(extra.expected, opts.expected);
5952 }
5953 this._ok = Boolean(this._ok && ok);
5954
5955 if (!ok) {
5956 res.error = defined(extra.error, opts.error, new Error(res.name));
5957 }
5958
5959 var e = new Error('exception');
5960 var err = (e.stack || '').split('\n');
5961 var dir = path.dirname(__dirname) + '/';
5962
5963 for (var i = 0; i < err.length; i++) {
5964 var m = /^\s*\bat\s+(.+)/.exec(err[i]);
5965 if (!m) continue;
5966
5967 var s = m[1].split(/\s+/);
5968 var filem = /(\/[^:\s]+:(\d+)(?::(\d+))?)/.exec(s[1]);
5969 if (!filem) {
5970 filem = /(\/[^:\s]+:(\d+)(?::(\d+))?)/.exec(s[3]);
5971
5972 if (!filem) continue;
5973 }
5974
5975 if (filem[1].slice(0, dir.length) === dir) continue;
5976
5977 res.functionName = s[0];
5978 res.file = filem[1];
5979 res.line = Number(filem[2]);
5980 if (filem[3]) res.column = filem[3];
5981
5982 res.at = m[1];
5983 break;
5984 }
5985
5986 self.emit('result', res);
5987
5988 var pendingAsserts = self._pendingAsserts();
5989 if (!pendingAsserts) {
5990 if (extra.exiting) {
5991 self._end();
5992 } else {
5993 nextTick(function () {
5994 self._end();
5995 });
5996 }
5997 }
5998
5999 if (!self._planError && pendingAsserts < 0) {
6000 self._planError = true;
6001 self.fail('plan != count', {
6002 expected : self._plan,
6003 actual : self._plan - pendingAsserts
6004 });
6005 }
6006};
6007
6008Test.prototype.fail = function (msg, extra) {
6009 this._assert(false, {
6010 message : msg,
6011 operator : 'fail',
6012 extra : extra
6013 });
6014};
6015
6016Test.prototype.pass = function (msg, extra) {
6017 this._assert(true, {
6018 message : msg,
6019 operator : 'pass',
6020 extra : extra
6021 });
6022};
6023
6024Test.prototype.skip = function (msg, extra) {
6025 this._assert(true, {
6026 message : msg,
6027 operator : 'skip',
6028 skip : true,
6029 extra : extra
6030 });
6031};
6032
6033Test.prototype.ok
6034= Test.prototype['true']
6035= Test.prototype.assert
6036= function (value, msg, extra) {
6037 this._assert(value, {
6038 message : msg,
6039 operator : 'ok',
6040 expected : true,
6041 actual : value,
6042 extra : extra
6043 });
6044};
6045
6046Test.prototype.notOk
6047= Test.prototype['false']
6048= Test.prototype.notok
6049= function (value, msg, extra) {
6050 this._assert(!value, {
6051 message : msg,
6052 operator : 'notOk',
6053 expected : false,
6054 actual : value,
6055 extra : extra
6056 });
6057};
6058
6059Test.prototype.error
6060= Test.prototype.ifError
6061= Test.prototype.ifErr
6062= Test.prototype.iferror
6063= function (err, msg, extra) {
6064 this._assert(!err, {
6065 message : defined(msg, String(err)),
6066 operator : 'error',
6067 actual : err,
6068 extra : extra
6069 });
6070};
6071
6072Test.prototype.equal
6073= Test.prototype.equals
6074= Test.prototype.isEqual
6075= Test.prototype.is
6076= Test.prototype.strictEqual
6077= Test.prototype.strictEquals
6078= function (a, b, msg, extra) {
6079 this._assert(a === b, {
6080 message : defined(msg, 'should be equal'),
6081 operator : 'equal',
6082 actual : a,
6083 expected : b,
6084 extra : extra
6085 });
6086};
6087
6088Test.prototype.notEqual
6089= Test.prototype.notEquals
6090= Test.prototype.notStrictEqual
6091= Test.prototype.notStrictEquals
6092= Test.prototype.isNotEqual
6093= Test.prototype.isNot
6094= Test.prototype.not
6095= Test.prototype.doesNotEqual
6096= Test.prototype.isInequal
6097= function (a, b, msg, extra) {
6098 this._assert(a !== b, {
6099 message : defined(msg, 'should not be equal'),
6100 operator : 'notEqual',
6101 actual : a,
6102 notExpected : b,
6103 extra : extra
6104 });
6105};
6106
6107Test.prototype.deepEqual
6108= Test.prototype.deepEquals
6109= Test.prototype.isEquivalent
6110= Test.prototype.same
6111= function (a, b, msg, extra) {
6112 this._assert(deepEqual(a, b, { strict: true }), {
6113 message : defined(msg, 'should be equivalent'),
6114 operator : 'deepEqual',
6115 actual : a,
6116 expected : b,
6117 extra : extra
6118 });
6119};
6120
6121Test.prototype.deepLooseEqual
6122= Test.prototype.looseEqual
6123= Test.prototype.looseEquals
6124= function (a, b, msg, extra) {
6125 this._assert(deepEqual(a, b), {
6126 message : defined(msg, 'should be equivalent'),
6127 operator : 'deepLooseEqual',
6128 actual : a,
6129 expected : b,
6130 extra : extra
6131 });
6132};
6133
6134Test.prototype.notDeepEqual
6135= Test.prototype.notEquivalent
6136= Test.prototype.notDeeply
6137= Test.prototype.notSame
6138= Test.prototype.isNotDeepEqual
6139= Test.prototype.isNotDeeply
6140= Test.prototype.isNotEquivalent
6141= Test.prototype.isInequivalent
6142= function (a, b, msg, extra) {
6143 this._assert(!deepEqual(a, b, { strict: true }), {
6144 message : defined(msg, 'should not be equivalent'),
6145 operator : 'notDeepEqual',
6146 actual : a,
6147 notExpected : b,
6148 extra : extra
6149 });
6150};
6151
6152Test.prototype.notDeepLooseEqual
6153= Test.prototype.notLooseEqual
6154= Test.prototype.notLooseEquals
6155= function (a, b, msg, extra) {
6156 this._assert(deepEqual(a, b), {
6157 message : defined(msg, 'should be equivalent'),
6158 operator : 'notDeepLooseEqual',
6159 actual : a,
6160 expected : b,
6161 extra : extra
6162 });
6163};
6164
6165Test.prototype['throws'] = function (fn, expected, msg, extra) {
6166 if (typeof expected === 'string') {
6167 msg = expected;
6168 expected = undefined;
6169 }
6170 var caught = undefined;
6171 try {
6172 fn();
6173 }
6174 catch (err) {
6175 caught = { error : err };
6176 var message = err.message;
6177 delete err.message;
6178 err.message = message;
6179 }
6180
6181 var passed = caught;
6182
6183 if (expected instanceof RegExp) {
6184 passed = expected.test(caught && caught.error);
6185 expected = String(expected);
6186 }
6187
6188 this._assert(passed, {
6189 message : defined(msg, 'should throw'),
6190 operator : 'throws',
6191 actual : caught && caught.error,
6192 expected : expected,
6193 error: !passed && caught && caught.error,
6194 extra : extra
6195 });
6196};
6197
6198Test.prototype.doesNotThrow = function (fn, expected, msg, extra) {
6199 if (typeof expected === 'string') {
6200 msg = expected;
6201 expected = undefined;
6202 }
6203 var caught = undefined;
6204 try {
6205 fn();
6206 }
6207 catch (err) {
6208 caught = { error : err };
6209 }
6210 this._assert(!caught, {
6211 message : defined(msg, 'should not throw'),
6212 operator : 'throws',
6213 actual : caught && caught.error,
6214 expected : expected,
6215 error : caught && caught.error,
6216 extra : extra
6217 });
6218};
6219
6220function has (obj, prop) {
6221 return Object.prototype.hasOwnProperty.call(obj, prop);
6222}
6223
6224// vim: set softtabstop=4 shiftwidth=4:
6225
6226}).call(this,require("/Users/scott/Code/object-hash/node_modules/gulp-browserify/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js"),"/../node_modules/tape/lib")
6227},{"/Users/scott/Code/object-hash/node_modules/gulp-browserify/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js":15,"deep-equal":31,"defined":34,"events":13,"path":16,"stream":18,"util":26}],31:[function(require,module,exports){
6228var pSlice = Array.prototype.slice;
6229var objectKeys = require('./lib/keys.js');
6230var isArguments = require('./lib/is_arguments.js');
6231
6232var deepEqual = module.exports = function (actual, expected, opts) {
6233 if (!opts) opts = {};
6234 // 7.1. All identical values are equivalent, as determined by ===.
6235 if (actual === expected) {
6236 return true;
6237
6238 } else if (actual instanceof Date && expected instanceof Date) {
6239 return actual.getTime() === expected.getTime();
6240
6241 // 7.3. Other pairs that do not both pass typeof value == 'object',
6242 // equivalence is determined by ==.
6243 } else if (typeof actual != 'object' && typeof expected != 'object') {
6244 return opts.strict ? actual === expected : actual == expected;
6245
6246 // 7.4. For all other Object pairs, including Array objects, equivalence is
6247 // determined by having the same number of owned properties (as verified
6248 // with Object.prototype.hasOwnProperty.call), the same set of keys
6249 // (although not necessarily the same order), equivalent values for every
6250 // corresponding key, and an identical 'prototype' property. Note: this
6251 // accounts for both named and indexed properties on Arrays.
6252 } else {
6253 return objEquiv(actual, expected, opts);
6254 }
6255}
6256
6257function isUndefinedOrNull(value) {
6258 return value === null || value === undefined;
6259}
6260
6261function isBuffer (x) {
6262 if (!x || typeof x !== 'object' || typeof x.length !== 'number') return false;
6263 if (typeof x.copy !== 'function' || typeof x.slice !== 'function') {
6264 return false;
6265 }
6266 if (x.length > 0 && typeof x[0] !== 'number') return false;
6267 return true;
6268}
6269
6270function objEquiv(a, b, opts) {
6271 var i, key;
6272 if (isUndefinedOrNull(a) || isUndefinedOrNull(b))
6273 return false;
6274 // an identical 'prototype' property.
6275 if (a.prototype !== b.prototype) return false;
6276 //~~~I've managed to break Object.keys through screwy arguments passing.
6277 // Converting to array solves the problem.
6278 if (isArguments(a)) {
6279 if (!isArguments(b)) {
6280 return false;
6281 }
6282 a = pSlice.call(a);
6283 b = pSlice.call(b);
6284 return deepEqual(a, b, opts);
6285 }
6286 if (isBuffer(a)) {
6287 if (!isBuffer(b)) {
6288 return false;
6289 }
6290 if (a.length !== b.length) return false;
6291 for (i = 0; i < a.length; i++) {
6292 if (a[i] !== b[i]) return false;
6293 }
6294 return true;
6295 }
6296 try {
6297 var ka = objectKeys(a),
6298 kb = objectKeys(b);
6299 } catch (e) {//happens when one is a string literal and the other isn't
6300 return false;
6301 }
6302 // having the same number of owned properties (keys incorporates
6303 // hasOwnProperty)
6304 if (ka.length != kb.length)
6305 return false;
6306 //the same set of keys (although not necessarily the same order),
6307 ka.sort();
6308 kb.sort();
6309 //~~~cheap key test
6310 for (i = ka.length - 1; i >= 0; i--) {
6311 if (ka[i] != kb[i])
6312 return false;
6313 }
6314 //equivalent values for every corresponding key, and
6315 //~~~possibly expensive deep test
6316 for (i = ka.length - 1; i >= 0; i--) {
6317 key = ka[i];
6318 if (!deepEqual(a[key], b[key], opts)) return false;
6319 }
6320 return true;
6321}
6322
6323},{"./lib/is_arguments.js":32,"./lib/keys.js":33}],32:[function(require,module,exports){
6324var supportsArgumentsClass = (function(){
6325 return Object.prototype.toString.call(arguments)
6326})() == '[object Arguments]';
6327
6328exports = module.exports = supportsArgumentsClass ? supported : unsupported;
6329
6330exports.supported = supported;
6331function supported(object) {
6332 return Object.prototype.toString.call(object) == '[object Arguments]';
6333};
6334
6335exports.unsupported = unsupported;
6336function unsupported(object){
6337 return object &&
6338 typeof object == 'object' &&
6339 typeof object.length == 'number' &&
6340 Object.prototype.hasOwnProperty.call(object, 'callee') &&
6341 !Object.prototype.propertyIsEnumerable.call(object, 'callee') ||
6342 false;
6343};
6344
6345},{}],33:[function(require,module,exports){
6346exports = module.exports = typeof Object.keys === 'function'
6347 ? Object.keys : shim;
6348
6349exports.shim = shim;
6350function shim (obj) {
6351 var keys = [];
6352 for (var key in obj) keys.push(key);
6353 return keys;
6354}
6355
6356},{}],34:[function(require,module,exports){
6357module.exports = function () {
6358 for (var i = 0; i < arguments.length; i++) {
6359 if (arguments[i] !== undefined) return arguments[i];
6360 }
6361};
6362
6363},{}],35:[function(require,module,exports){
6364module.exports=require(14)
6365},{}],36:[function(require,module,exports){
6366module.exports = function inspect_ (obj, opts, depth, seen) {
6367 if (!opts) opts = {};
6368
6369 var maxDepth = opts.depth === undefined ? 5 : opts.depth;
6370 if (depth === undefined) depth = 0;
6371 if (depth > maxDepth && maxDepth > 0) return '...';
6372
6373 if (seen === undefined) seen = [];
6374 else if (indexOf(seen, obj) >= 0) {
6375 return '[Circular]';
6376 }
6377
6378 function inspect (value, from) {
6379 if (from) {
6380 seen = seen.slice();
6381 seen.push(from);
6382 }
6383 return inspect_(value, opts, depth + 1, seen);
6384 }
6385
6386 if (typeof obj === 'string') {
6387 return "'" + obj.replace(/(['\\])/g, '\\$1') + "'";
6388 }
6389 else if (typeof obj === 'function') {
6390 var name = nameOf(obj);
6391 return '[Function' + (name ? ': ' + name : '') + ']';
6392 }
6393 else if (obj === null) {
6394 return 'null';
6395 }
6396 else if (isElement(obj)) {
6397 var s = '<' + String(obj.nodeName).toLowerCase();
6398 var attrs = obj.attributes || [];
6399 for (var i = 0; i < attrs.length; i++) {
6400 s += ' ' + attrs[i].name + '="' + quote(attrs[i].value) + '"';
6401 }
6402 s += '>';
6403 if (obj.childNodes && obj.childNodes.length) s += '...';
6404 s += '</' + String(obj.tagName).toLowerCase() + '>';
6405 return s;
6406 }
6407 else if (isArray(obj)) {
6408 if (obj.length === 0) return '[]';
6409 var xs = Array(obj.length);
6410 for (var i = 0; i < obj.length; i++) {
6411 xs[i] = has(obj, i) ? inspect(obj[i], obj) : '';
6412 }
6413 return '[ ' + xs.join(', ') + ' ]';
6414 }
6415 else if (typeof obj === 'object' && typeof obj.inspect === 'function') {
6416 return obj.inspect();
6417 }
6418 else if (typeof obj === 'object' && !isDate(obj) && !isRegExp(obj)) {
6419 var xs = [], keys = [];
6420 for (var key in obj) {
6421 if (has(obj, key)) keys.push(key);
6422 }
6423 keys.sort();
6424 for (var i = 0; i < keys.length; i++) {
6425 var key = keys[i];
6426 if (/[^\w$]/.test(key)) {
6427 xs.push(inspect(key) + ': ' + inspect(obj[key], obj));
6428 }
6429 else xs.push(key + ': ' + inspect(obj[key], obj));
6430 }
6431 if (xs.length === 0) return '{}';
6432 return '{ ' + xs.join(', ') + ' }';
6433 }
6434 else return String(obj);
6435};
6436
6437function quote (s) {
6438 return String(s).replace(/"/g, '&quot;');
6439}
6440
6441function isArray (obj) {
6442 return {}.toString.call(obj) === '[object Array]';
6443}
6444
6445function isDate (obj) {
6446 return {}.toString.call(obj) === '[object Date]';
6447}
6448
6449function isRegExp (obj) {
6450 return {}.toString.call(obj) === '[object RegExp]';
6451}
6452
6453function has (obj, key) {
6454 if (!{}.hasOwnProperty) return key in obj;
6455 return {}.hasOwnProperty.call(obj, key);
6456}
6457
6458function nameOf (f) {
6459 if (f.name) return f.name;
6460 var m = f.toString().match(/^function\s*([\w$]+)/);
6461 if (m) return m[1];
6462}
6463
6464function indexOf (xs, x) {
6465 if (xs.indexOf) return xs.indexOf(x);
6466 for (var i = 0, l = xs.length; i < l; i++) {
6467 if (xs[i] === x) return i;
6468 }
6469 return -1;
6470}
6471
6472function isElement (x) {
6473 if (!x || typeof x !== 'object') return false;
6474 if (typeof HTMLElement !== 'undefined') {
6475 return x instanceof HTMLElement;
6476 }
6477 else return typeof x.nodeName === 'string'
6478 && typeof x.getAttribute === 'function'
6479 ;
6480}
6481
6482},{}],37:[function(require,module,exports){
6483(function (process){
6484var through = require('through');
6485var nextTick = typeof setImmediate !== 'undefined'
6486 ? setImmediate
6487 : process.nextTick
6488;
6489
6490module.exports = function (write, end) {
6491 var tr = through(write, end);
6492 tr.pause();
6493 var resume = tr.resume;
6494 var pause = tr.pause;
6495 var paused = false;
6496
6497 tr.pause = function () {
6498 paused = true;
6499 return pause.apply(this, arguments);
6500 };
6501
6502 tr.resume = function () {
6503 paused = false;
6504 return resume.apply(this, arguments);
6505 };
6506
6507 nextTick(function () {
6508 if (!paused) tr.resume();
6509 });
6510
6511 return tr;
6512};
6513
6514}).call(this,require("/Users/scott/Code/object-hash/node_modules/gulp-browserify/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js"))
6515},{"/Users/scott/Code/object-hash/node_modules/gulp-browserify/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js":15,"through":38}],38:[function(require,module,exports){
6516(function (process){
6517var Stream = require('stream')
6518
6519// through
6520//
6521// a stream that does nothing but re-emit the input.
6522// useful for aggregating a series of changing but not ending streams into one stream)
6523
6524exports = module.exports = through
6525through.through = through
6526
6527//create a readable writable stream.
6528
6529function through (write, end, opts) {
6530 write = write || function (data) { this.queue(data) }
6531 end = end || function () { this.queue(null) }
6532
6533 var ended = false, destroyed = false, buffer = [], _ended = false
6534 var stream = new Stream()
6535 stream.readable = stream.writable = true
6536 stream.paused = false
6537
6538// stream.autoPause = !(opts && opts.autoPause === false)
6539 stream.autoDestroy = !(opts && opts.autoDestroy === false)
6540
6541 stream.write = function (data) {
6542 write.call(this, data)
6543 return !stream.paused
6544 }
6545
6546 function drain() {
6547 while(buffer.length && !stream.paused) {
6548 var data = buffer.shift()
6549 if(null === data)
6550 return stream.emit('end')
6551 else
6552 stream.emit('data', data)
6553 }
6554 }
6555
6556 stream.queue = stream.push = function (data) {
6557// console.error(ended)
6558 if(_ended) return stream
6559 if(data == null) _ended = true
6560 buffer.push(data)
6561 drain()
6562 return stream
6563 }
6564
6565 //this will be registered as the first 'end' listener
6566 //must call destroy next tick, to make sure we're after any
6567 //stream piped from here.
6568 //this is only a problem if end is not emitted synchronously.
6569 //a nicer way to do this is to make sure this is the last listener for 'end'
6570
6571 stream.on('end', function () {
6572 stream.readable = false
6573 if(!stream.writable && stream.autoDestroy)
6574 process.nextTick(function () {
6575 stream.destroy()
6576 })
6577 })
6578
6579 function _end () {
6580 stream.writable = false
6581 end.call(stream)
6582 if(!stream.readable && stream.autoDestroy)
6583 stream.destroy()
6584 }
6585
6586 stream.end = function (data) {
6587 if(ended) return
6588 ended = true
6589 if(arguments.length) stream.write(data)
6590 _end() // will emit or queue
6591 return stream
6592 }
6593
6594 stream.destroy = function () {
6595 if(destroyed) return
6596 destroyed = true
6597 ended = true
6598 buffer.length = 0
6599 stream.writable = stream.readable = false
6600 stream.emit('close')
6601 return stream
6602 }
6603
6604 stream.pause = function () {
6605 if(stream.paused) return
6606 stream.paused = true
6607 return stream
6608 }
6609
6610 stream.resume = function () {
6611 if(stream.paused) {
6612 stream.paused = false
6613 stream.emit('resume')
6614 }
6615 drain()
6616 //may have become paused again,
6617 //as drain emits 'data'.
6618 if(!stream.paused)
6619 stream.emit('drain')
6620 return stream
6621 }
6622 return stream
6623}
6624
6625
6626}).call(this,require("/Users/scott/Code/object-hash/node_modules/gulp-browserify/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js"))
6627},{"/Users/scott/Code/object-hash/node_modules/gulp-browserify/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js":15,"stream":18}],39:[function(require,module,exports){
6628var test = require('tape');
6629var hash = require('../index');
6630var validSha1 = /^[0-9a-f]{40}$/i;
6631
6632test('throws when nothing to hash', function (assert) {
6633 assert.plan(2);
6634 assert.throws(hash, 'no arguments');
6635 assert.throws(function(){
6636 hash(undefined, {algorithm: 'md5'});
6637 }, 'undefined');
6638});
6639
6640test('throws when passed an invalid options', function(assert){
6641 assert.plan(2);
6642 assert.throws(function(){
6643 hash({foo: 'bar'}, {algorithm: 'shalala'});
6644 }, 'bad algorithm');
6645 assert.throws(function(){
6646 hash({foo: 'bar'}, {encoding: 'base16'});
6647 }, 'bad encoding');
6648});
6649
6650test('hashes non-object types', function(assert){
6651 assert.plan(4);
6652 var func = function(a){ return a + 1; };
6653 assert.ok(validSha1.test(hash('Shazbot!')), 'hash string');
6654 assert.ok(validSha1.test(hash(42)), 'hash number');
6655 assert.ok(validSha1.test(hash(true)), 'hash bool');
6656 assert.ok(validSha1.test(hash(func)), 'hash function');
6657});
6658
6659test('hashes special object types', function(assert){
6660 assert.plan(8);
6661 var dt = new Date();
6662 dt.setDate(dt.getDate() + 1);
6663
6664 assert.ok(validSha1.test(hash([1,2,3,4])), 'hash array');
6665 assert.notEqual(hash([1,2,3,4]), hash([4,3,2,1]), 'different arrays not equal');
6666 assert.ok(validSha1.test(hash(new Date())), 'hash date');
6667 assert.notEqual(hash(new Date()), hash(dt), 'different dates not equal');
6668 assert.ok(validSha1.test(hash(null)), 'hash Null');
6669 assert.ok(validSha1.test(hash(Number.NaN)), 'hash NaN');
6670 assert.ok(validSha1.test(hash({ foo: undefined })), 'hash Undefined value');
6671 assert.ok(validSha1.test(hash(new RegExp())), 'hash regex');
6672});
6673
6674test('hashes a simple object', function(assert){
6675 assert.plan(1);
6676 assert.ok(validSha1.test(hash({foo: 'bar', bar: 'baz'})), 'hash object');
6677});
6678
6679test('hashes identical objects with different key ordering', function(assert){
6680 assert.plan(2);
6681 var hash1 = hash({foo: 'bar', bar: 'baz'});
6682 var hash2 = hash({bar: 'baz', foo: 'bar'});
6683 var hash3 = hash({bar: 'foo', foo: 'baz'});
6684 assert.equal(hash1, hash2, 'hashes are equal');
6685 assert.notEqual(hash1, hash3, 'different objects not equal');
6686});
6687
6688test('only hashes object keys when excludeValues option is set', function(assert){
6689 assert.plan(2);
6690 var hash1 = hash({foo: false, bar: 'OK'}, { excludeValues: true });
6691 var hash2 = hash({foo: true, bar: 'NO'}, { excludeValues: true });
6692 var hash3 = hash({foo: true, bar: 'OK', baz: false}, { excludeValues: true });
6693 assert.equal(hash1, hash2, 'values not in hash digest');
6694 assert.notEqual(hash1, hash3, 'different keys not equal');
6695});
6696
6697test('array values are hashed', function(assert){
6698 assert.plan(1);
6699 var hash1 = hash({foo: ['bar', 'baz'], bax: true });
6700 var hash2 = hash({foo: ['baz', 'bar'], bax: true });
6701 assert.notEqual(hash1, hash2, 'different array orders are unique');
6702});
6703
6704test('nested object values are hashed', function(assert){
6705 assert.plan(2);
6706 var hash1 = hash({foo: {bar: true, bax: 1}});
6707 var hash2 = hash({foo: {bar: true, bax: 1}});
6708 var hash3 = hash({foo: {bar: false, bax: 1}});
6709 assert.equal(hash1, hash2, 'hashes are equal');
6710 assert.notEqual(hash1, hash3, 'different objects not equal');
6711});
6712
6713test('sugar methods should be equivalent', function(assert){
6714 assert.plan(3);
6715 var obj = {foo: 'bar', baz: true};
6716 assert.equal(hash.keys(obj), hash(obj, {excludeValues: true}), 'keys');
6717 assert.equal(hash.MD5(obj), hash(obj, {algorithm: 'md5'}), 'md5');
6718 assert.equal(hash.keysMD5(obj),
6719 hash(obj, {algorithm: 'md5', excludeValues: true}), 'keys md5');
6720});
6721
6722
6723test('array of nested object values are hashed', function(assert){
6724 assert.plan(2);
6725 var hash1 = hash({foo: [ {bar: true, bax: 1}, {bar: false, bax: 2} ] });
6726 var hash2 = hash({foo: [ {bar: true, bax: 1}, {bar: false, bax: 2} ] });
6727 var hash3 = hash({foo: [ {bar: false, bax: 2} ] });
6728 assert.equal(hash1, hash2, 'hashes are equal');
6729 assert.notEqual(hash1, hash3, 'different objects not equal');
6730});
6731
6732},{"../index":1,"tape":27}]},{},[39])
\No newline at end of file