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){
3 * The buffer module from node.js, for the browser.
5 * Author: Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
11 var base64 = require('base64-js')
12 var ieee754 = require('ieee754')
14 exports.Buffer = Buffer
15 exports.SlowBuffer = Buffer
16 exports.INSPECT_MAX_BYTES = 50
17 Buffer.poolSize = 8192
20 * If `Buffer._useTypedArrays`:
21 * === true Use Uint8Array implementation (fastest)
22 * === false Use Object implementation (compatible down to IE6)
24 Buffer._useTypedArrays = (function () {
25 // Detect if browser supports Typed Arrays. Supported browsers are IE 10+,
26 // Firefox 4+, Chrome 7+, Safari 5.1+, Opera 11.6+, iOS 4.2+.
27 if (typeof Uint8Array === 'undefined' || typeof ArrayBuffer === 'undefined')
30 // Does the browser support adding properties to `Uint8Array` instances? If
31 // not, then that's the same as no `Uint8Array` support. We need to be able to
32 // add all the node Buffer API methods.
33 // Relevant Firefox bug: https://bugzilla.mozilla.org/show_bug.cgi?id=695438
35 var arr = new Uint8Array(0)
36 arr.foo = function () { return 42 }
37 return 42 === arr.foo() &&
38 typeof arr.subarray === 'function' // Chrome 9-10 lack `subarray`
48 * The Buffer constructor returns instances of `Uint8Array` that are augmented
49 * with function properties for all the node `Buffer` API functions. We use
50 * `Uint8Array` so that square bracket notation works as expected -- it returns
53 * By augmenting the instances, we can avoid modifying the `Uint8Array`
56 function Buffer (subject, encoding, noZero) {
57 if (!(this instanceof Buffer))
58 return new Buffer(subject, encoding, noZero)
60 var type = typeof subject
62 // Workaround: node's base64 implementation allows for non-padded strings
63 // while base64-js does not.
64 if (encoding === 'base64' && type === 'string') {
65 subject = stringtrim(subject)
66 while (subject.length % 4 !== 0) {
67 subject = subject + '='
73 if (type === 'number')
74 length = coerce(subject)
75 else if (type === 'string')
76 length = Buffer.byteLength(subject, encoding)
77 else if (type === 'object')
78 length = coerce(subject.length) // Assume object is an array
80 throw new Error('First argument needs to be a number, array or string.')
83 if (Buffer._useTypedArrays) {
84 // Preferred: Return an augmented `Uint8Array` instance for best performance
85 buf = augment(new Uint8Array(length))
87 // Fallback: Return THIS instance of Buffer (created by `new`)
94 if (Buffer._useTypedArrays && typeof Uint8Array === 'function' &&
95 subject instanceof Uint8Array) {
96 // Speed optimization -- use set if we're copying from a Uint8Array
98 } else if (isArrayish(subject)) {
99 // Treat array-ish objects as a byte array
100 for (i = 0; i < length; i++) {
101 if (Buffer.isBuffer(subject))
102 buf[i] = subject.readUInt8(i)
106 } else if (type === 'string') {
107 buf.write(subject, 0, encoding)
108 } else if (type === 'number' && !Buffer._useTypedArrays && !noZero) {
109 for (i = 0; i < length; i++) {
120 Buffer.isEncoding = function (encoding) {
121 switch (String(encoding).toLowerCase()) {
139 Buffer.isBuffer = function (b) {
140 return !!(b !== null && b !== undefined && b._isBuffer)
143 Buffer.byteLength = function (str, encoding) {
146 switch (encoding || 'utf8') {
152 ret = utf8ToBytes(str).length
160 ret = base64ToBytes(str).length
169 throw new Error('Unknown encoding')
174 Buffer.concat = function (list, totalLength) {
175 assert(isArray(list), 'Usage: Buffer.concat(list, [totalLength])\n' +
176 'list should be an Array.')
178 if (list.length === 0) {
180 } else if (list.length === 1) {
185 if (typeof totalLength !== 'number') {
187 for (i = 0; i < list.length; i++) {
188 totalLength += list[i].length
192 var buf = new Buffer(totalLength)
194 for (i = 0; i < list.length; i++) {
202 // BUFFER INSTANCE METHODS
203 // =======================
205 function _hexWrite (buf, string, offset, length) {
206 offset = Number(offset) || 0
207 var remaining = buf.length - offset
211 length = Number(length)
212 if (length > remaining) {
217 // must be an even number of digits
218 var strLen = string.length
219 assert(strLen % 2 === 0, 'Invalid hex string')
221 if (length > strLen / 2) {
224 for (var i = 0; i < length; i++) {
225 var byte = parseInt(string.substr(i * 2, 2), 16)
226 assert(!isNaN(byte), 'Invalid hex string')
227 buf[offset + i] = byte
229 Buffer._charsWritten = i * 2
233 function _utf8Write (buf, string, offset, length) {
234 var charsWritten = Buffer._charsWritten =
235 blitBuffer(utf8ToBytes(string), buf, offset, length)
239 function _asciiWrite (buf, string, offset, length) {
240 var charsWritten = Buffer._charsWritten =
241 blitBuffer(asciiToBytes(string), buf, offset, length)
245 function _binaryWrite (buf, string, offset, length) {
246 return _asciiWrite(buf, string, offset, length)
249 function _base64Write (buf, string, offset, length) {
250 var charsWritten = Buffer._charsWritten =
251 blitBuffer(base64ToBytes(string), buf, offset, length)
255 function _utf16leWrite (buf, string, offset, length) {
256 var charsWritten = Buffer._charsWritten =
257 blitBuffer(utf16leToBytes(string), buf, offset, length)
261 Buffer.prototype.write = function (string, offset, length, encoding) {
262 // Support both (string, offset, length, encoding)
263 // and the legacy (string, encoding, offset, length)
264 if (isFinite(offset)) {
265 if (!isFinite(length)) {
276 offset = Number(offset) || 0
277 var remaining = this.length - offset
281 length = Number(length)
282 if (length > remaining) {
286 encoding = String(encoding || 'utf8').toLowerCase()
291 ret = _hexWrite(this, string, offset, length)
295 ret = _utf8Write(this, string, offset, length)
298 ret = _asciiWrite(this, string, offset, length)
301 ret = _binaryWrite(this, string, offset, length)
304 ret = _base64Write(this, string, offset, length)
310 ret = _utf16leWrite(this, string, offset, length)
313 throw new Error('Unknown encoding')
318 Buffer.prototype.toString = function (encoding, start, end) {
321 encoding = String(encoding || 'utf8').toLowerCase()
322 start = Number(start) || 0
323 end = (end !== undefined)
327 // Fastpath empty strings
334 ret = _hexSlice(self, start, end)
338 ret = _utf8Slice(self, start, end)
341 ret = _asciiSlice(self, start, end)
344 ret = _binarySlice(self, start, end)
347 ret = _base64Slice(self, start, end)
353 ret = _utf16leSlice(self, start, end)
356 throw new Error('Unknown encoding')
361 Buffer.prototype.toJSON = function () {
364 data: Array.prototype.slice.call(this._arr || this, 0)
368 // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
369 Buffer.prototype.copy = function (target, target_start, start, end) {
372 if (!start) start = 0
373 if (!end && end !== 0) end = this.length
374 if (!target_start) target_start = 0
376 // Copy 0 bytes; we're done
377 if (end === start) return
378 if (target.length === 0 || source.length === 0) return
380 // Fatal error conditions
381 assert(end >= start, 'sourceEnd < sourceStart')
382 assert(target_start >= 0 && target_start < target.length,
383 'targetStart out of bounds')
384 assert(start >= 0 && start < source.length, 'sourceStart out of bounds')
385 assert(end >= 0 && end <= source.length, 'sourceEnd out of bounds')
388 if (end > this.length)
390 if (target.length - target_start < end - start)
391 end = target.length - target_start + start
394 for (var i = 0; i < end - start; i++)
395 target[i + target_start] = this[i + start]
398 function _base64Slice (buf, start, end) {
399 if (start === 0 && end === buf.length) {
400 return base64.fromByteArray(buf)
402 return base64.fromByteArray(buf.slice(start, end))
406 function _utf8Slice (buf, start, end) {
409 end = Math.min(buf.length, end)
411 for (var i = start; i < end; i++) {
412 if (buf[i] <= 0x7F) {
413 res += decodeUtf8Char(tmp) + String.fromCharCode(buf[i])
416 tmp += '%' + buf[i].toString(16)
420 return res + decodeUtf8Char(tmp)
423 function _asciiSlice (buf, start, end) {
425 end = Math.min(buf.length, end)
427 for (var i = start; i < end; i++)
428 ret += String.fromCharCode(buf[i])
432 function _binarySlice (buf, start, end) {
433 return _asciiSlice(buf, start, end)
436 function _hexSlice (buf, start, end) {
439 if (!start || start < 0) start = 0
440 if (!end || end < 0 || end > len) end = len
443 for (var i = start; i < end; i++) {
449 function _utf16leSlice (buf, start, end) {
450 var bytes = buf.slice(start, end)
452 for (var i = 0; i < bytes.length; i += 2) {
453 res += String.fromCharCode(bytes[i] + bytes[i+1] * 256)
458 Buffer.prototype.slice = function (start, end) {
459 var len = this.length
460 start = clamp(start, len, 0)
461 end = clamp(end, len, len)
463 if (Buffer._useTypedArrays) {
464 return augment(this.subarray(start, end))
466 var sliceLen = end - start
467 var newBuf = new Buffer(sliceLen, undefined, true)
468 for (var i = 0; i < sliceLen; i++) {
469 newBuf[i] = this[i + start]
475 // `get` will be removed in Node 0.13+
476 Buffer.prototype.get = function (offset) {
477 console.log('.get() is deprecated. Access using array indexes instead.')
478 return this.readUInt8(offset)
481 // `set` will be removed in Node 0.13+
482 Buffer.prototype.set = function (v, offset) {
483 console.log('.set() is deprecated. Access using array indexes instead.')
484 return this.writeUInt8(v, offset)
487 Buffer.prototype.readUInt8 = function (offset, noAssert) {
489 assert(offset !== undefined && offset !== null, 'missing offset')
490 assert(offset < this.length, 'Trying to read beyond buffer length')
493 if (offset >= this.length)
499 function _readUInt16 (buf, offset, littleEndian, noAssert) {
501 assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
502 assert(offset !== undefined && offset !== null, 'missing offset')
503 assert(offset + 1 < buf.length, 'Trying to read beyond buffer length')
513 if (offset + 1 < len)
514 val |= buf[offset + 1] << 8
516 val = buf[offset] << 8
517 if (offset + 1 < len)
518 val |= buf[offset + 1]
523 Buffer.prototype.readUInt16LE = function (offset, noAssert) {
524 return _readUInt16(this, offset, true, noAssert)
527 Buffer.prototype.readUInt16BE = function (offset, noAssert) {
528 return _readUInt16(this, offset, false, noAssert)
531 function _readUInt32 (buf, offset, littleEndian, noAssert) {
533 assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
534 assert(offset !== undefined && offset !== null, 'missing offset')
535 assert(offset + 3 < buf.length, 'Trying to read beyond buffer length')
544 if (offset + 2 < len)
545 val = buf[offset + 2] << 16
546 if (offset + 1 < len)
547 val |= buf[offset + 1] << 8
549 if (offset + 3 < len)
550 val = val + (buf[offset + 3] << 24 >>> 0)
552 if (offset + 1 < len)
553 val = buf[offset + 1] << 16
554 if (offset + 2 < len)
555 val |= buf[offset + 2] << 8
556 if (offset + 3 < len)
557 val |= buf[offset + 3]
558 val = val + (buf[offset] << 24 >>> 0)
563 Buffer.prototype.readUInt32LE = function (offset, noAssert) {
564 return _readUInt32(this, offset, true, noAssert)
567 Buffer.prototype.readUInt32BE = function (offset, noAssert) {
568 return _readUInt32(this, offset, false, noAssert)
571 Buffer.prototype.readInt8 = function (offset, noAssert) {
573 assert(offset !== undefined && offset !== null,
575 assert(offset < this.length, 'Trying to read beyond buffer length')
578 if (offset >= this.length)
581 var neg = this[offset] & 0x80
583 return (0xff - this[offset] + 1) * -1
588 function _readInt16 (buf, offset, littleEndian, noAssert) {
590 assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
591 assert(offset !== undefined && offset !== null, 'missing offset')
592 assert(offset + 1 < buf.length, 'Trying to read beyond buffer length')
599 var val = _readUInt16(buf, offset, littleEndian, true)
600 var neg = val & 0x8000
602 return (0xffff - val + 1) * -1
607 Buffer.prototype.readInt16LE = function (offset, noAssert) {
608 return _readInt16(this, offset, true, noAssert)
611 Buffer.prototype.readInt16BE = function (offset, noAssert) {
612 return _readInt16(this, offset, false, noAssert)
615 function _readInt32 (buf, offset, littleEndian, noAssert) {
617 assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
618 assert(offset !== undefined && offset !== null, 'missing offset')
619 assert(offset + 3 < buf.length, 'Trying to read beyond buffer length')
626 var val = _readUInt32(buf, offset, littleEndian, true)
627 var neg = val & 0x80000000
629 return (0xffffffff - val + 1) * -1
634 Buffer.prototype.readInt32LE = function (offset, noAssert) {
635 return _readInt32(this, offset, true, noAssert)
638 Buffer.prototype.readInt32BE = function (offset, noAssert) {
639 return _readInt32(this, offset, false, noAssert)
642 function _readFloat (buf, offset, littleEndian, noAssert) {
644 assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
645 assert(offset + 3 < buf.length, 'Trying to read beyond buffer length')
648 return ieee754.read(buf, offset, littleEndian, 23, 4)
651 Buffer.prototype.readFloatLE = function (offset, noAssert) {
652 return _readFloat(this, offset, true, noAssert)
655 Buffer.prototype.readFloatBE = function (offset, noAssert) {
656 return _readFloat(this, offset, false, noAssert)
659 function _readDouble (buf, offset, littleEndian, noAssert) {
661 assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
662 assert(offset + 7 < buf.length, 'Trying to read beyond buffer length')
665 return ieee754.read(buf, offset, littleEndian, 52, 8)
668 Buffer.prototype.readDoubleLE = function (offset, noAssert) {
669 return _readDouble(this, offset, true, noAssert)
672 Buffer.prototype.readDoubleBE = function (offset, noAssert) {
673 return _readDouble(this, offset, false, noAssert)
676 Buffer.prototype.writeUInt8 = function (value, offset, noAssert) {
678 assert(value !== undefined && value !== null, 'missing value')
679 assert(offset !== undefined && offset !== null, 'missing offset')
680 assert(offset < this.length, 'trying to write beyond buffer length')
681 verifuint(value, 0xff)
684 if (offset >= this.length) return
689 function _writeUInt16 (buf, value, offset, littleEndian, noAssert) {
691 assert(value !== undefined && value !== null, 'missing value')
692 assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
693 assert(offset !== undefined && offset !== null, 'missing offset')
694 assert(offset + 1 < buf.length, 'trying to write beyond buffer length')
695 verifuint(value, 0xffff)
702 for (var i = 0, j = Math.min(len - offset, 2); i < j; i++) {
704 (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
705 (littleEndian ? i : 1 - i) * 8
709 Buffer.prototype.writeUInt16LE = function (value, offset, noAssert) {
710 _writeUInt16(this, value, offset, true, noAssert)
713 Buffer.prototype.writeUInt16BE = function (value, offset, noAssert) {
714 _writeUInt16(this, value, offset, false, noAssert)
717 function _writeUInt32 (buf, value, offset, littleEndian, noAssert) {
719 assert(value !== undefined && value !== null, 'missing value')
720 assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
721 assert(offset !== undefined && offset !== null, 'missing offset')
722 assert(offset + 3 < buf.length, 'trying to write beyond buffer length')
723 verifuint(value, 0xffffffff)
730 for (var i = 0, j = Math.min(len - offset, 4); i < j; i++) {
732 (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff
736 Buffer.prototype.writeUInt32LE = function (value, offset, noAssert) {
737 _writeUInt32(this, value, offset, true, noAssert)
740 Buffer.prototype.writeUInt32BE = function (value, offset, noAssert) {
741 _writeUInt32(this, value, offset, false, noAssert)
744 Buffer.prototype.writeInt8 = function (value, offset, noAssert) {
746 assert(value !== undefined && value !== null, 'missing value')
747 assert(offset !== undefined && offset !== null, 'missing offset')
748 assert(offset < this.length, 'Trying to write beyond buffer length')
749 verifsint(value, 0x7f, -0x80)
752 if (offset >= this.length)
756 this.writeUInt8(value, offset, noAssert)
758 this.writeUInt8(0xff + value + 1, offset, noAssert)
761 function _writeInt16 (buf, value, offset, littleEndian, noAssert) {
763 assert(value !== undefined && value !== null, 'missing value')
764 assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
765 assert(offset !== undefined && offset !== null, 'missing offset')
766 assert(offset + 1 < buf.length, 'Trying to write beyond buffer length')
767 verifsint(value, 0x7fff, -0x8000)
775 _writeUInt16(buf, value, offset, littleEndian, noAssert)
777 _writeUInt16(buf, 0xffff + value + 1, offset, littleEndian, noAssert)
780 Buffer.prototype.writeInt16LE = function (value, offset, noAssert) {
781 _writeInt16(this, value, offset, true, noAssert)
784 Buffer.prototype.writeInt16BE = function (value, offset, noAssert) {
785 _writeInt16(this, value, offset, false, noAssert)
788 function _writeInt32 (buf, value, offset, littleEndian, noAssert) {
790 assert(value !== undefined && value !== null, 'missing value')
791 assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
792 assert(offset !== undefined && offset !== null, 'missing offset')
793 assert(offset + 3 < buf.length, 'Trying to write beyond buffer length')
794 verifsint(value, 0x7fffffff, -0x80000000)
802 _writeUInt32(buf, value, offset, littleEndian, noAssert)
804 _writeUInt32(buf, 0xffffffff + value + 1, offset, littleEndian, noAssert)
807 Buffer.prototype.writeInt32LE = function (value, offset, noAssert) {
808 _writeInt32(this, value, offset, true, noAssert)
811 Buffer.prototype.writeInt32BE = function (value, offset, noAssert) {
812 _writeInt32(this, value, offset, false, noAssert)
815 function _writeFloat (buf, value, offset, littleEndian, noAssert) {
817 assert(value !== undefined && value !== null, 'missing value')
818 assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
819 assert(offset !== undefined && offset !== null, 'missing offset')
820 assert(offset + 3 < buf.length, 'Trying to write beyond buffer length')
821 verifIEEE754(value, 3.4028234663852886e+38, -3.4028234663852886e+38)
828 ieee754.write(buf, value, offset, littleEndian, 23, 4)
831 Buffer.prototype.writeFloatLE = function (value, offset, noAssert) {
832 _writeFloat(this, value, offset, true, noAssert)
835 Buffer.prototype.writeFloatBE = function (value, offset, noAssert) {
836 _writeFloat(this, value, offset, false, noAssert)
839 function _writeDouble (buf, value, offset, littleEndian, noAssert) {
841 assert(value !== undefined && value !== null, 'missing value')
842 assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
843 assert(offset !== undefined && offset !== null, 'missing offset')
844 assert(offset + 7 < buf.length,
845 'Trying to write beyond buffer length')
846 verifIEEE754(value, 1.7976931348623157E+308, -1.7976931348623157E+308)
853 ieee754.write(buf, value, offset, littleEndian, 52, 8)
856 Buffer.prototype.writeDoubleLE = function (value, offset, noAssert) {
857 _writeDouble(this, value, offset, true, noAssert)
860 Buffer.prototype.writeDoubleBE = function (value, offset, noAssert) {
861 _writeDouble(this, value, offset, false, noAssert)
864 // fill(value, start=0, end=buffer.length)
865 Buffer.prototype.fill = function (value, start, end) {
866 if (!value) value = 0
867 if (!start) start = 0
868 if (!end) end = this.length
870 if (typeof value === 'string') {
871 value = value.charCodeAt(0)
874 assert(typeof value === 'number' && !isNaN(value), 'value is not a number')
875 assert(end >= start, 'end < start')
877 // Fill 0 bytes; we're done
878 if (end === start) return
879 if (this.length === 0) return
881 assert(start >= 0 && start < this.length, 'start out of bounds')
882 assert(end >= 0 && end <= this.length, 'end out of bounds')
884 for (var i = start; i < end; i++) {
889 Buffer.prototype.inspect = function () {
891 var len = this.length
892 for (var i = 0; i < len; i++) {
893 out[i] = toHex(this[i])
894 if (i === exports.INSPECT_MAX_BYTES) {
899 return '<Buffer ' + out.join(' ') + '>'
903 * Creates a new `ArrayBuffer` with the *copied* memory of the buffer instance.
904 * Added in Node 0.12. Only available in browsers that support ArrayBuffer.
906 Buffer.prototype.toArrayBuffer = function () {
907 if (typeof Uint8Array === 'function') {
908 if (Buffer._useTypedArrays) {
909 return (new Buffer(this)).buffer
911 var buf = new Uint8Array(this.length)
912 for (var i = 0, len = buf.length; i < len; i += 1)
917 throw new Error('Buffer.toArrayBuffer not supported in this browser')
924 function stringtrim (str) {
925 if (str.trim) return str.trim()
926 return str.replace(/^\s+|\s+$/g, '')
929 var BP = Buffer.prototype
932 * Augment the Uint8Array *instance* (not the class!) with Buffer methods
934 function augment (arr) {
937 // save reference to original Uint8Array get/set methods before overwriting
941 // deprecated, will be removed in node 0.13+
946 arr.toString = BP.toString
947 arr.toLocaleString = BP.toString
948 arr.toJSON = BP.toJSON
951 arr.readUInt8 = BP.readUInt8
952 arr.readUInt16LE = BP.readUInt16LE
953 arr.readUInt16BE = BP.readUInt16BE
954 arr.readUInt32LE = BP.readUInt32LE
955 arr.readUInt32BE = BP.readUInt32BE
956 arr.readInt8 = BP.readInt8
957 arr.readInt16LE = BP.readInt16LE
958 arr.readInt16BE = BP.readInt16BE
959 arr.readInt32LE = BP.readInt32LE
960 arr.readInt32BE = BP.readInt32BE
961 arr.readFloatLE = BP.readFloatLE
962 arr.readFloatBE = BP.readFloatBE
963 arr.readDoubleLE = BP.readDoubleLE
964 arr.readDoubleBE = BP.readDoubleBE
965 arr.writeUInt8 = BP.writeUInt8
966 arr.writeUInt16LE = BP.writeUInt16LE
967 arr.writeUInt16BE = BP.writeUInt16BE
968 arr.writeUInt32LE = BP.writeUInt32LE
969 arr.writeUInt32BE = BP.writeUInt32BE
970 arr.writeInt8 = BP.writeInt8
971 arr.writeInt16LE = BP.writeInt16LE
972 arr.writeInt16BE = BP.writeInt16BE
973 arr.writeInt32LE = BP.writeInt32LE
974 arr.writeInt32BE = BP.writeInt32BE
975 arr.writeFloatLE = BP.writeFloatLE
976 arr.writeFloatBE = BP.writeFloatBE
977 arr.writeDoubleLE = BP.writeDoubleLE
978 arr.writeDoubleBE = BP.writeDoubleBE
980 arr.inspect = BP.inspect
981 arr.toArrayBuffer = BP.toArrayBuffer
987 function clamp (index, len, defaultValue) {
988 if (typeof index !== 'number') return defaultValue
989 index = ~~index; // Coerce to integer.
990 if (index >= len) return len
991 if (index >= 0) return index
993 if (index >= 0) return index
997 function coerce (length) {
998 // Coerce length to a number (possibly NaN), round up
999 // in case it's fractional (e.g. 123.456) then do a
1000 // double negate to coerce a NaN to 0. Easy, right?
1001 length = ~~Math.ceil(+length)
1002 return length < 0 ? 0 : length
1005 function isArray (subject) {
1006 return (Array.isArray || function (subject) {
1007 return Object.prototype.toString.call(subject) === '[object Array]'
1011 function isArrayish (subject) {
1012 return isArray(subject) || Buffer.isBuffer(subject) ||
1013 subject && typeof subject === 'object' &&
1014 typeof subject.length === 'number'
1017 function toHex (n) {
1018 if (n < 16) return '0' + n.toString(16)
1019 return n.toString(16)
1022 function utf8ToBytes (str) {
1024 for (var i = 0; i < str.length; i++) {
1025 var b = str.charCodeAt(i)
1027 byteArray.push(str.charCodeAt(i))
1030 if (b >= 0xD800 && b <= 0xDFFF) i++
1031 var h = encodeURIComponent(str.slice(start, i+1)).substr(1).split('%')
1032 for (var j = 0; j < h.length; j++)
1033 byteArray.push(parseInt(h[j], 16))
1039 function asciiToBytes (str) {
1041 for (var i = 0; i < str.length; i++) {
1042 // Node's code seems to be doing this and not & 0x7F..
1043 byteArray.push(str.charCodeAt(i) & 0xFF)
1048 function utf16leToBytes (str) {
1051 for (var i = 0; i < str.length; i++) {
1052 c = str.charCodeAt(i)
1062 function base64ToBytes (str) {
1063 return base64.toByteArray(str)
1066 function blitBuffer (src, dst, offset, length) {
1068 for (var i = 0; i < length; i++) {
1069 if ((i + offset >= dst.length) || (i >= src.length))
1071 dst[i + offset] = src[i]
1076 function decodeUtf8Char (str) {
1078 return decodeURIComponent(str)
1080 return String.fromCharCode(0xFFFD) // UTF 8 invalid char
1085 * We have to make sure that the value is a valid integer. This means that it
1086 * is non-negative. It has no fractional component and that it does not
1087 * exceed the maximum allowed value.
1089 function verifuint (value, max) {
1090 assert(typeof value === 'number', 'cannot write a non-number as a number')
1092 'specified a negative value for writing an unsigned value')
1093 assert(value <= max, 'value is larger than maximum value for type')
1094 assert(Math.floor(value) === value, 'value has a fractional component')
1097 function verifsint (value, max, min) {
1098 assert(typeof value === 'number', 'cannot write a non-number as a number')
1099 assert(value <= max, 'value larger than maximum allowed value')
1100 assert(value >= min, 'value smaller than minimum allowed value')
1101 assert(Math.floor(value) === value, 'value has a fractional component')
1104 function verifIEEE754 (value, max, min) {
1105 assert(typeof value === 'number', 'cannot write a non-number as a number')
1106 assert(value <= max, 'value larger than maximum allowed value')
1107 assert(value >= min, 'value smaller than minimum allowed value')
1110 function assert (test, message) {
1111 if (!test) throw new Error(message || 'Failed assertion')
1114 },{"base64-js":2,"ieee754":3}],2:[function(require,module,exports){
1115 var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
1117 ;(function (exports) {
1120 var Arr = (typeof Uint8Array !== 'undefined')
1124 var ZERO = '0'.charCodeAt(0)
1125 var PLUS = '+'.charCodeAt(0)
1126 var SLASH = '/'.charCodeAt(0)
1127 var NUMBER = '0'.charCodeAt(0)
1128 var LOWER = 'a'.charCodeAt(0)
1129 var UPPER = 'A'.charCodeAt(0)
1131 function decode (elt) {
1132 var code = elt.charCodeAt(0)
1138 return -1 //no match
1139 if (code < NUMBER + 10)
1140 return code - NUMBER + 26 + 26
1141 if (code < UPPER + 26)
1143 if (code < LOWER + 26)
1144 return code - LOWER + 26
1147 function b64ToByteArray (b64) {
1148 var i, j, l, tmp, placeHolders, arr
1150 if (b64.length % 4 > 0) {
1151 throw new Error('Invalid string. Length must be a multiple of 4')
1154 // the number of equal signs (place holders)
1155 // if there are two placeholders, than the two characters before it
1156 // represent one byte
1157 // if there is only one, then the three characters before it represent 2 bytes
1158 // this is just a cheap hack to not do indexOf twice
1159 var len = b64.length
1160 placeHolders = '=' === b64.charAt(len - 2) ? 2 : '=' === b64.charAt(len - 1) ? 1 : 0
1162 // base64 is 4/3 + up to two characters of the original data
1163 arr = new Arr(b64.length * 3 / 4 - placeHolders)
1165 // if there are placeholders, only get up to the last complete 4 chars
1166 l = placeHolders > 0 ? b64.length - 4 : b64.length
1174 for (i = 0, j = 0; i < l; i += 4, j += 3) {
1175 tmp = (decode(b64.charAt(i)) << 18) | (decode(b64.charAt(i + 1)) << 12) | (decode(b64.charAt(i + 2)) << 6) | decode(b64.charAt(i + 3))
1176 push((tmp & 0xFF0000) >> 16)
1177 push((tmp & 0xFF00) >> 8)
1181 if (placeHolders === 2) {
1182 tmp = (decode(b64.charAt(i)) << 2) | (decode(b64.charAt(i + 1)) >> 4)
1184 } else if (placeHolders === 1) {
1185 tmp = (decode(b64.charAt(i)) << 10) | (decode(b64.charAt(i + 1)) << 4) | (decode(b64.charAt(i + 2)) >> 2)
1186 push((tmp >> 8) & 0xFF)
1193 function uint8ToBase64 (uint8) {
1195 extraBytes = uint8.length % 3, // if we have 1 byte left, pad 2 bytes
1199 function encode (num) {
1200 return lookup.charAt(num)
1203 function tripletToBase64 (num) {
1204 return encode(num >> 18 & 0x3F) + encode(num >> 12 & 0x3F) + encode(num >> 6 & 0x3F) + encode(num & 0x3F)
1207 // go through the array every three bytes, we'll deal with trailing stuff later
1208 for (i = 0, length = uint8.length - extraBytes; i < length; i += 3) {
1209 temp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2])
1210 output += tripletToBase64(temp)
1213 // pad the end with zeros, but make sure to not forget the extra bytes
1214 switch (extraBytes) {
1216 temp = uint8[uint8.length - 1]
1217 output += encode(temp >> 2)
1218 output += encode((temp << 4) & 0x3F)
1222 temp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1])
1223 output += encode(temp >> 10)
1224 output += encode((temp >> 4) & 0x3F)
1225 output += encode((temp << 2) & 0x3F)
1233 module.exports.toByteArray = b64ToByteArray
1234 module.exports.fromByteArray = uint8ToBase64
1237 },{}],3:[function(require,module,exports){
1238 exports.read = function(buffer, offset, isLE, mLen, nBytes) {
1240 eLen = nBytes * 8 - mLen - 1,
1241 eMax = (1 << eLen) - 1,
1244 i = isLE ? (nBytes - 1) : 0,
1246 s = buffer[offset + i];
1250 e = s & ((1 << (-nBits)) - 1);
1253 for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8);
1255 m = e & ((1 << (-nBits)) - 1);
1258 for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8);
1262 } else if (e === eMax) {
1263 return m ? NaN : ((s ? -1 : 1) * Infinity);
1265 m = m + Math.pow(2, mLen);
1268 return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
1271 exports.write = function(buffer, value, offset, isLE, mLen, nBytes) {
1273 eLen = nBytes * 8 - mLen - 1,
1274 eMax = (1 << eLen) - 1,
1276 rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0),
1277 i = isLE ? 0 : (nBytes - 1),
1279 s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
1281 value = Math.abs(value);
1283 if (isNaN(value) || value === Infinity) {
1284 m = isNaN(value) ? 1 : 0;
1287 e = Math.floor(Math.log(value) / Math.LN2);
1288 if (value * (c = Math.pow(2, -e)) < 1) {
1292 if (e + eBias >= 1) {
1295 value += rt * Math.pow(2, 1 - eBias);
1297 if (value * c >= 2) {
1302 if (e + eBias >= eMax) {
1305 } else if (e + eBias >= 1) {
1306 m = (value * c - 1) * Math.pow(2, mLen);
1309 m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
1314 for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8);
1316 e = (e << mLen) | m;
1318 for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8);
1320 buffer[offset + i - d] |= s * 128;
1323 },{}],4:[function(require,module,exports){
1324 // Copyright Joyent, Inc. and other Node contributors.
1326 // Permission is hereby granted, free of charge, to any person obtaining a
1327 // copy of this software and associated documentation files (the
1328 // "Software"), to deal in the Software without restriction, including
1329 // without limitation the rights to use, copy, modify, merge, publish,
1330 // distribute, sublicense, and/or sell copies of the Software, and to permit
1331 // persons to whom the Software is furnished to do so, subject to the
1332 // following conditions:
1334 // The above copyright notice and this permission notice shall be included
1335 // in all copies or substantial portions of the Software.
1337 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
1338 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1339 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
1340 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
1341 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
1342 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
1343 // USE OR OTHER DEALINGS IN THE SOFTWARE.
1345 function EventEmitter() {
1346 this._events = this._events || {};
1347 this._maxListeners = this._maxListeners || undefined;
1349 module.exports = EventEmitter;
1351 // Backwards-compat with node 0.10.x
1352 EventEmitter.EventEmitter = EventEmitter;
1354 EventEmitter.prototype._events = undefined;
1355 EventEmitter.prototype._maxListeners = undefined;
1357 // By default EventEmitters will print a warning if more than 10 listeners are
1358 // added to it. This is a useful default which helps finding memory leaks.
1359 EventEmitter.defaultMaxListeners = 10;
1361 // Obviously not all Emitters should be limited to 10. This function allows
1362 // that to be increased. Set to zero for unlimited.
1363 EventEmitter.prototype.setMaxListeners = function(n) {
1364 if (!isNumber(n) || n < 0 || isNaN(n))
1365 throw TypeError('n must be a positive number');
1366 this._maxListeners = n;
1370 EventEmitter.prototype.emit = function(type) {
1371 var er, handler, len, args, i, listeners;
1376 // If there is no 'error' event listener then throw.
1377 if (type === 'error') {
1378 if (!this._events.error ||
1379 (isObject(this._events.error) && !this._events.error.length)) {
1381 if (er instanceof Error) {
1382 throw er; // Unhandled 'error' event
1384 throw TypeError('Uncaught, unspecified "error" event.');
1390 handler = this._events[type];
1392 if (isUndefined(handler))
1395 if (isFunction(handler)) {
1396 switch (arguments.length) {
1402 handler.call(this, arguments[1]);
1405 handler.call(this, arguments[1], arguments[2]);
1409 len = arguments.length;
1410 args = new Array(len - 1);
1411 for (i = 1; i < len; i++)
1412 args[i - 1] = arguments[i];
1413 handler.apply(this, args);
1415 } else if (isObject(handler)) {
1416 len = arguments.length;
1417 args = new Array(len - 1);
1418 for (i = 1; i < len; i++)
1419 args[i - 1] = arguments[i];
1421 listeners = handler.slice();
1422 len = listeners.length;
1423 for (i = 0; i < len; i++)
1424 listeners[i].apply(this, args);
1430 EventEmitter.prototype.addListener = function(type, listener) {
1433 if (!isFunction(listener))
1434 throw TypeError('listener must be a function');
1439 // To avoid recursion in the case that type === "newListener"! Before
1440 // adding it to the listeners, first emit "newListener".
1441 if (this._events.newListener)
1442 this.emit('newListener', type,
1443 isFunction(listener.listener) ?
1444 listener.listener : listener);
1446 if (!this._events[type])
1447 // Optimize the case of one listener. Don't need the extra array object.
1448 this._events[type] = listener;
1449 else if (isObject(this._events[type]))
1450 // If we've already got an array, just append.
1451 this._events[type].push(listener);
1453 // Adding the second element, need to change to array.
1454 this._events[type] = [this._events[type], listener];
1456 // Check for listener leak
1457 if (isObject(this._events[type]) && !this._events[type].warned) {
1459 if (!isUndefined(this._maxListeners)) {
1460 m = this._maxListeners;
1462 m = EventEmitter.defaultMaxListeners;
1465 if (m && m > 0 && this._events[type].length > m) {
1466 this._events[type].warned = true;
1467 console.error('(node) warning: possible EventEmitter memory ' +
1468 'leak detected. %d listeners added. ' +
1469 'Use emitter.setMaxListeners() to increase limit.',
1470 this._events[type].length);
1478 EventEmitter.prototype.on = EventEmitter.prototype.addListener;
1480 EventEmitter.prototype.once = function(type, listener) {
1481 if (!isFunction(listener))
1482 throw TypeError('listener must be a function');
1487 this.removeListener(type, g);
1491 listener.apply(this, arguments);
1495 g.listener = listener;
1501 // emits a 'removeListener' event iff the listener was removed
1502 EventEmitter.prototype.removeListener = function(type, listener) {
1503 var list, position, length, i;
1505 if (!isFunction(listener))
1506 throw TypeError('listener must be a function');
1508 if (!this._events || !this._events[type])
1511 list = this._events[type];
1512 length = list.length;
1515 if (list === listener ||
1516 (isFunction(list.listener) && list.listener === listener)) {
1517 delete this._events[type];
1518 if (this._events.removeListener)
1519 this.emit('removeListener', type, listener);
1521 } else if (isObject(list)) {
1522 for (i = length; i-- > 0;) {
1523 if (list[i] === listener ||
1524 (list[i].listener && list[i].listener === listener)) {
1533 if (list.length === 1) {
1535 delete this._events[type];
1537 list.splice(position, 1);
1540 if (this._events.removeListener)
1541 this.emit('removeListener', type, listener);
1547 EventEmitter.prototype.removeAllListeners = function(type) {
1553 // not listening for removeListener, no need to emit
1554 if (!this._events.removeListener) {
1555 if (arguments.length === 0)
1557 else if (this._events[type])
1558 delete this._events[type];
1562 // emit removeListener for all listeners on all events
1563 if (arguments.length === 0) {
1564 for (key in this._events) {
1565 if (key === 'removeListener') continue;
1566 this.removeAllListeners(key);
1568 this.removeAllListeners('removeListener');
1573 listeners = this._events[type];
1575 if (isFunction(listeners)) {
1576 this.removeListener(type, listeners);
1579 while (listeners.length)
1580 this.removeListener(type, listeners[listeners.length - 1]);
1582 delete this._events[type];
1587 EventEmitter.prototype.listeners = function(type) {
1589 if (!this._events || !this._events[type])
1591 else if (isFunction(this._events[type]))
1592 ret = [this._events[type]];
1594 ret = this._events[type].slice();
1598 EventEmitter.listenerCount = function(emitter, type) {
1600 if (!emitter._events || !emitter._events[type])
1602 else if (isFunction(emitter._events[type]))
1605 ret = emitter._events[type].length;
1609 function isFunction(arg) {
1610 return typeof arg === 'function';
1613 function isNumber(arg) {
1614 return typeof arg === 'number';
1617 function isObject(arg) {
1618 return typeof arg === 'object' && arg !== null;
1621 function isUndefined(arg) {
1622 return arg === void 0;
1625 },{}],5:[function(require,module,exports){
1626 if (typeof Object.create === 'function') {
1627 // implementation from standard node.js 'util' module
1628 module.exports = function inherits(ctor, superCtor) {
1629 ctor.super_ = superCtor
1630 ctor.prototype = Object.create(superCtor.prototype, {
1640 // old school shim for old browsers
1641 module.exports = function inherits(ctor, superCtor) {
1642 ctor.super_ = superCtor
1643 var TempCtor = function () {}
1644 TempCtor.prototype = superCtor.prototype
1645 ctor.prototype = new TempCtor()
1646 ctor.prototype.constructor = ctor
1650 },{}],6:[function(require,module,exports){
1651 // shim for using process in browser
1653 var process = module.exports = {};
1655 process.nextTick = (function () {
1656 var canSetImmediate = typeof window !== 'undefined'
1657 && window.setImmediate;
1658 var canPost = typeof window !== 'undefined'
1659 && window.postMessage && window.addEventListener
1662 if (canSetImmediate) {
1663 return function (f) { return window.setImmediate(f) };
1668 window.addEventListener('message', function (ev) {
1669 var source = ev.source;
1670 if ((source === window || source === null) && ev.data === 'process-tick') {
1671 ev.stopPropagation();
1672 if (queue.length > 0) {
1673 var fn = queue.shift();
1679 return function nextTick(fn) {
1681 window.postMessage('process-tick', '*');
1685 return function nextTick(fn) {
1690 process.title = 'browser';
1691 process.browser = true;
1695 process.binding = function (name) {
1696 throw new Error('process.binding is not supported');
1700 process.cwd = function () { return '/' };
1701 process.chdir = function (dir) {
1702 throw new Error('process.chdir is not supported');
1705 },{}],7:[function(require,module,exports){
1706 (function (process){
1707 // Copyright Joyent, Inc. and other Node contributors.
1709 // Permission is hereby granted, free of charge, to any person obtaining a
1710 // copy of this software and associated documentation files (the
1711 // "Software"), to deal in the Software without restriction, including
1712 // without limitation the rights to use, copy, modify, merge, publish,
1713 // distribute, sublicense, and/or sell copies of the Software, and to permit
1714 // persons to whom the Software is furnished to do so, subject to the
1715 // following conditions:
1717 // The above copyright notice and this permission notice shall be included
1718 // in all copies or substantial portions of the Software.
1720 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
1721 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1722 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
1723 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
1724 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
1725 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
1726 // USE OR OTHER DEALINGS IN THE SOFTWARE.
1728 // resolves . and .. elements in a path array with directory names there
1729 // must be no slashes, empty elements, or device names (c:\) in the array
1730 // (so also no leading and trailing slashes - it does not distinguish
1731 // relative and absolute paths)
1732 function normalizeArray(parts, allowAboveRoot) {
1733 // if the path tries to go above the root, `up` ends up > 0
1735 for (var i = parts.length - 1; i >= 0; i--) {
1736 var last = parts[i];
1739 } else if (last === '..') {
1748 // if the path is allowed to go above the root, restore leading ..s
1749 if (allowAboveRoot) {
1751 parts.unshift('..');
1758 // Split a filename into [root, dir, basename, ext], unix version
1759 // 'root' is just a slash, or nothing.
1761 /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
1762 var splitPath = function(filename) {
1763 return splitPathRe.exec(filename).slice(1);
1766 // path.resolve([from ...], to)
1768 exports.resolve = function() {
1769 var resolvedPath = '',
1770 resolvedAbsolute = false;
1772 for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
1773 var path = (i >= 0) ? arguments[i] : process.cwd();
1775 // Skip empty and invalid entries
1776 if (typeof path !== 'string') {
1777 throw new TypeError('Arguments to path.resolve must be strings');
1782 resolvedPath = path + '/' + resolvedPath;
1783 resolvedAbsolute = path.charAt(0) === '/';
1786 // At this point the path should be resolved to a full absolute path, but
1787 // handle relative paths to be safe (might happen when process.cwd() fails)
1789 // Normalize the path
1790 resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {
1792 }), !resolvedAbsolute).join('/');
1794 return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
1797 // path.normalize(path)
1799 exports.normalize = function(path) {
1800 var isAbsolute = exports.isAbsolute(path),
1801 trailingSlash = substr(path, -1) === '/';
1803 // Normalize the path
1804 path = normalizeArray(filter(path.split('/'), function(p) {
1806 }), !isAbsolute).join('/');
1808 if (!path && !isAbsolute) {
1811 if (path && trailingSlash) {
1815 return (isAbsolute ? '/' : '') + path;
1819 exports.isAbsolute = function(path) {
1820 return path.charAt(0) === '/';
1824 exports.join = function() {
1825 var paths = Array.prototype.slice.call(arguments, 0);
1826 return exports.normalize(filter(paths, function(p, index) {
1827 if (typeof p !== 'string') {
1828 throw new TypeError('Arguments to path.join must be strings');
1835 // path.relative(from, to)
1837 exports.relative = function(from, to) {
1838 from = exports.resolve(from).substr(1);
1839 to = exports.resolve(to).substr(1);
1841 function trim(arr) {
1843 for (; start < arr.length; start++) {
1844 if (arr[start] !== '') break;
1847 var end = arr.length - 1;
1848 for (; end >= 0; end--) {
1849 if (arr[end] !== '') break;
1852 if (start > end) return [];
1853 return arr.slice(start, end - start + 1);
1856 var fromParts = trim(from.split('/'));
1857 var toParts = trim(to.split('/'));
1859 var length = Math.min(fromParts.length, toParts.length);
1860 var samePartsLength = length;
1861 for (var i = 0; i < length; i++) {
1862 if (fromParts[i] !== toParts[i]) {
1863 samePartsLength = i;
1868 var outputParts = [];
1869 for (var i = samePartsLength; i < fromParts.length; i++) {
1870 outputParts.push('..');
1873 outputParts = outputParts.concat(toParts.slice(samePartsLength));
1875 return outputParts.join('/');
1879 exports.delimiter = ':';
1881 exports.dirname = function(path) {
1882 var result = splitPath(path),
1886 if (!root && !dir) {
1887 // No dirname whatsoever
1892 // It has a dirname, strip trailing slash
1893 dir = dir.substr(0, dir.length - 1);
1900 exports.basename = function(path, ext) {
1901 var f = splitPath(path)[2];
1902 // TODO: make this comparison case-insensitive on windows?
1903 if (ext && f.substr(-1 * ext.length) === ext) {
1904 f = f.substr(0, f.length - ext.length);
1910 exports.extname = function(path) {
1911 return splitPath(path)[3];
1914 function filter (xs, f) {
1915 if (xs.filter) return xs.filter(f);
1917 for (var i = 0; i < xs.length; i++) {
1918 if (f(xs[i], i, xs)) res.push(xs[i]);
1923 // String.prototype.substr - negative index don't work in IE8
1924 var substr = 'ab'.substr(-1) === 'b'
1925 ? function (str, start, len) { return str.substr(start, len) }
1926 : function (str, start, len) {
1927 if (start < 0) start = str.length + start;
1928 return str.substr(start, len);
1932 }).call(this,require("/Users/stephen/.nvm/v0.10.24/lib/node_modules/testling/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js"))
1933 },{"/Users/stephen/.nvm/v0.10.24/lib/node_modules/testling/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js":6}],8:[function(require,module,exports){
1934 // Copyright Joyent, Inc. and other Node contributors.
1936 // Permission is hereby granted, free of charge, to any person obtaining a
1937 // copy of this software and associated documentation files (the
1938 // "Software"), to deal in the Software without restriction, including
1939 // without limitation the rights to use, copy, modify, merge, publish,
1940 // distribute, sublicense, and/or sell copies of the Software, and to permit
1941 // persons to whom the Software is furnished to do so, subject to the
1942 // following conditions:
1944 // The above copyright notice and this permission notice shall be included
1945 // in all copies or substantial portions of the Software.
1947 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
1948 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1949 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
1950 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
1951 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
1952 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
1953 // USE OR OTHER DEALINGS IN THE SOFTWARE.
1955 // a duplex stream is just a stream that is both readable and writable.
1956 // Since JS doesn't have multiple prototypal inheritance, this class
1957 // prototypally inherits from Readable, and then parasitically from
1960 module.exports = Duplex;
1961 var inherits = require('inherits');
1962 var setImmediate = require('process/browser.js').nextTick;
1963 var Readable = require('./readable.js');
1964 var Writable = require('./writable.js');
1966 inherits(Duplex, Readable);
1968 Duplex.prototype.write = Writable.prototype.write;
1969 Duplex.prototype.end = Writable.prototype.end;
1970 Duplex.prototype._write = Writable.prototype._write;
1972 function Duplex(options) {
1973 if (!(this instanceof Duplex))
1974 return new Duplex(options);
1976 Readable.call(this, options);
1977 Writable.call(this, options);
1979 if (options && options.readable === false)
1980 this.readable = false;
1982 if (options && options.writable === false)
1983 this.writable = false;
1985 this.allowHalfOpen = true;
1986 if (options && options.allowHalfOpen === false)
1987 this.allowHalfOpen = false;
1989 this.once('end', onend);
1992 // the no-half-open enforcer
1994 // if we allow half-open state, or if the writable side ended,
1996 if (this.allowHalfOpen || this._writableState.ended)
1999 // no more data can be written.
2000 // But allow more writes to happen in this tick.
2002 setImmediate(function () {
2007 },{"./readable.js":12,"./writable.js":14,"inherits":5,"process/browser.js":10}],9:[function(require,module,exports){
2008 // Copyright Joyent, Inc. and other Node contributors.
2010 // Permission is hereby granted, free of charge, to any person obtaining a
2011 // copy of this software and associated documentation files (the
2012 // "Software"), to deal in the Software without restriction, including
2013 // without limitation the rights to use, copy, modify, merge, publish,
2014 // distribute, sublicense, and/or sell copies of the Software, and to permit
2015 // persons to whom the Software is furnished to do so, subject to the
2016 // following conditions:
2018 // The above copyright notice and this permission notice shall be included
2019 // in all copies or substantial portions of the Software.
2021 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
2022 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2023 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
2024 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
2025 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
2026 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
2027 // USE OR OTHER DEALINGS IN THE SOFTWARE.
2029 module.exports = Stream;
2031 var EE = require('events').EventEmitter;
2032 var inherits = require('inherits');
2034 inherits(Stream, EE);
2035 Stream.Readable = require('./readable.js');
2036 Stream.Writable = require('./writable.js');
2037 Stream.Duplex = require('./duplex.js');
2038 Stream.Transform = require('./transform.js');
2039 Stream.PassThrough = require('./passthrough.js');
2041 // Backwards-compat with node 0.4.x
2042 Stream.Stream = Stream;
2046 // old-style streams. Note that the pipe method (the only relevant
2047 // part of this class) is overridden in the Readable class.
2053 Stream.prototype.pipe = function(dest, options) {
2056 function ondata(chunk) {
2057 if (dest.writable) {
2058 if (false === dest.write(chunk) && source.pause) {
2064 source.on('data', ondata);
2066 function ondrain() {
2067 if (source.readable && source.resume) {
2072 dest.on('drain', ondrain);
2074 // If the 'end' option is not supplied, dest.end() will be called when
2075 // source gets the 'end' or 'close' events. Only dest.end() once.
2076 if (!dest._isStdio && (!options || options.end !== false)) {
2077 source.on('end', onend);
2078 source.on('close', onclose);
2081 var didOnEnd = false;
2083 if (didOnEnd) return;
2090 function onclose() {
2091 if (didOnEnd) return;
2094 if (typeof dest.destroy === 'function') dest.destroy();
2097 // don't leave dangling pipes when there are errors.
2098 function onerror(er) {
2100 if (EE.listenerCount(this, 'error') === 0) {
2101 throw er; // Unhandled stream error in pipe.
2105 source.on('error', onerror);
2106 dest.on('error', onerror);
2108 // remove all the event listeners that were added.
2109 function cleanup() {
2110 source.removeListener('data', ondata);
2111 dest.removeListener('drain', ondrain);
2113 source.removeListener('end', onend);
2114 source.removeListener('close', onclose);
2116 source.removeListener('error', onerror);
2117 dest.removeListener('error', onerror);
2119 source.removeListener('end', cleanup);
2120 source.removeListener('close', cleanup);
2122 dest.removeListener('close', cleanup);
2125 source.on('end', cleanup);
2126 source.on('close', cleanup);
2128 dest.on('close', cleanup);
2130 dest.emit('pipe', source);
2132 // Allow for unix-like usage: A.pipe(B).pipe(C)
2136 },{"./duplex.js":8,"./passthrough.js":11,"./readable.js":12,"./transform.js":13,"./writable.js":14,"events":4,"inherits":5}],10:[function(require,module,exports){
2137 module.exports=require(6)
2138 },{}],11:[function(require,module,exports){
2139 // Copyright Joyent, Inc. and other Node contributors.
2141 // Permission is hereby granted, free of charge, to any person obtaining a
2142 // copy of this software and associated documentation files (the
2143 // "Software"), to deal in the Software without restriction, including
2144 // without limitation the rights to use, copy, modify, merge, publish,
2145 // distribute, sublicense, and/or sell copies of the Software, and to permit
2146 // persons to whom the Software is furnished to do so, subject to the
2147 // following conditions:
2149 // The above copyright notice and this permission notice shall be included
2150 // in all copies or substantial portions of the Software.
2152 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
2153 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2154 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
2155 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
2156 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
2157 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
2158 // USE OR OTHER DEALINGS IN THE SOFTWARE.
2160 // a passthrough stream.
2161 // basically just the most minimal sort of Transform stream.
2162 // Every written chunk gets output as-is.
2164 module.exports = PassThrough;
2166 var Transform = require('./transform.js');
2167 var inherits = require('inherits');
2168 inherits(PassThrough, Transform);
2170 function PassThrough(options) {
2171 if (!(this instanceof PassThrough))
2172 return new PassThrough(options);
2174 Transform.call(this, options);
2177 PassThrough.prototype._transform = function(chunk, encoding, cb) {
2181 },{"./transform.js":13,"inherits":5}],12:[function(require,module,exports){
2182 (function (process){
2183 // Copyright Joyent, Inc. and other Node contributors.
2185 // Permission is hereby granted, free of charge, to any person obtaining a
2186 // copy of this software and associated documentation files (the
2187 // "Software"), to deal in the Software without restriction, including
2188 // without limitation the rights to use, copy, modify, merge, publish,
2189 // distribute, sublicense, and/or sell copies of the Software, and to permit
2190 // persons to whom the Software is furnished to do so, subject to the
2191 // following conditions:
2193 // The above copyright notice and this permission notice shall be included
2194 // in all copies or substantial portions of the Software.
2196 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
2197 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2198 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
2199 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
2200 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
2201 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
2202 // USE OR OTHER DEALINGS IN THE SOFTWARE.
2204 module.exports = Readable;
2205 Readable.ReadableState = ReadableState;
2207 var EE = require('events').EventEmitter;
2208 var Stream = require('./index.js');
2209 var Buffer = require('buffer').Buffer;
2210 var setImmediate = require('process/browser.js').nextTick;
2213 var inherits = require('inherits');
2214 inherits(Readable, Stream);
2216 function ReadableState(options, stream) {
2217 options = options || {};
2219 // the point at which it stops calling _read() to fill the buffer
2220 // Note: 0 is a valid value, means "don't call _read preemptively ever"
2221 var hwm = options.highWaterMark;
2222 this.highWaterMark = (hwm || hwm === 0) ? hwm : 16 * 1024;
2225 this.highWaterMark = ~~this.highWaterMark;
2230 this.pipesCount = 0;
2231 this.flowing = false;
2233 this.endEmitted = false;
2234 this.reading = false;
2236 // In streams that never have any data, and do push(null) right away,
2237 // the consumer can miss the 'end' event if they do some I/O before
2238 // consuming the stream. So, we don't emit('end') until some reading
2240 this.calledRead = false;
2242 // a flag to be able to tell if the onwrite cb is called immediately,
2243 // or on a later tick. We set this to true at first, becuase any
2244 // actions that shouldn't happen until "later" should generally also
2245 // not happen before the first write call.
2248 // whenever we return null, then we set a flag to say
2249 // that we're awaiting a 'readable' event emission.
2250 this.needReadable = false;
2251 this.emittedReadable = false;
2252 this.readableListening = false;
2255 // object stream flag. Used to make read(n) ignore n and to
2256 // make all the buffer merging and length checks go away
2257 this.objectMode = !!options.objectMode;
2259 // Crypto is kind of old and crusty. Historically, its default string
2260 // encoding is 'binary' so we have to make this configurable.
2261 // Everything else in the universe uses 'utf8', though.
2262 this.defaultEncoding = options.defaultEncoding || 'utf8';
2264 // when piping, we only care about 'readable' events that happen
2265 // after read()ing all the bytes and not getting any pushback.
2266 this.ranOut = false;
2268 // the number of writers that are awaiting a drain event in .pipe()s
2269 this.awaitDrain = 0;
2271 // if true, a maybeReadMore has been scheduled
2272 this.readingMore = false;
2274 this.decoder = null;
2275 this.encoding = null;
2276 if (options.encoding) {
2278 StringDecoder = require('string_decoder').StringDecoder;
2279 this.decoder = new StringDecoder(options.encoding);
2280 this.encoding = options.encoding;
2284 function Readable(options) {
2285 if (!(this instanceof Readable))
2286 return new Readable(options);
2288 this._readableState = new ReadableState(options, this);
2291 this.readable = true;
2296 // Manually shove something into the read() buffer.
2297 // This returns true if the highWaterMark has not been hit yet,
2298 // similar to how Writable.write() returns true if you should
2299 // write() some more.
2300 Readable.prototype.push = function(chunk, encoding) {
2301 var state = this._readableState;
2303 if (typeof chunk === 'string' && !state.objectMode) {
2304 encoding = encoding || state.defaultEncoding;
2305 if (encoding !== state.encoding) {
2306 chunk = new Buffer(chunk, encoding);
2311 return readableAddChunk(this, state, chunk, encoding, false);
2314 // Unshift should *always* be something directly out of read()
2315 Readable.prototype.unshift = function(chunk) {
2316 var state = this._readableState;
2317 return readableAddChunk(this, state, chunk, '', true);
2320 function readableAddChunk(stream, state, chunk, encoding, addToFront) {
2321 var er = chunkInvalid(state, chunk);
2323 stream.emit('error', er);
2324 } else if (chunk === null || chunk === undefined) {
2325 state.reading = false;
2327 onEofChunk(stream, state);
2328 } else if (state.objectMode || chunk && chunk.length > 0) {
2329 if (state.ended && !addToFront) {
2330 var e = new Error('stream.push() after EOF');
2331 stream.emit('error', e);
2332 } else if (state.endEmitted && addToFront) {
2333 var e = new Error('stream.unshift() after end event');
2334 stream.emit('error', e);
2336 if (state.decoder && !addToFront && !encoding)
2337 chunk = state.decoder.write(chunk);
2339 // update the buffer info.
2340 state.length += state.objectMode ? 1 : chunk.length;
2342 state.buffer.unshift(chunk);
2344 state.reading = false;
2345 state.buffer.push(chunk);
2348 if (state.needReadable)
2349 emitReadable(stream);
2351 maybeReadMore(stream, state);
2353 } else if (!addToFront) {
2354 state.reading = false;
2357 return needMoreData(state);
2362 // if it's past the high water mark, we can push in some more.
2363 // Also, if we have no data yet, we can stand some
2364 // more bytes. This is to work around cases where hwm=0,
2365 // such as the repl. Also, if the push() triggered a
2366 // readable event, and the user called read(largeNumber) such that
2367 // needReadable was set, then we ought to push more, so that another
2368 // 'readable' event will be triggered.
2369 function needMoreData(state) {
2370 return !state.ended &&
2371 (state.needReadable ||
2372 state.length < state.highWaterMark ||
2373 state.length === 0);
2376 // backwards compatibility.
2377 Readable.prototype.setEncoding = function(enc) {
2379 StringDecoder = require('string_decoder').StringDecoder;
2380 this._readableState.decoder = new StringDecoder(enc);
2381 this._readableState.encoding = enc;
2384 // Don't raise the hwm > 128MB
2385 var MAX_HWM = 0x800000;
2386 function roundUpToNextPowerOf2(n) {
2390 // Get the next highest power of 2
2392 for (var p = 1; p < 32; p <<= 1) n |= n >> p;
2398 function howMuchToRead(n, state) {
2399 if (state.length === 0 && state.ended)
2402 if (state.objectMode)
2403 return n === 0 ? 0 : 1;
2405 if (isNaN(n) || n === null) {
2406 // only flow one buffer at a time
2407 if (state.flowing && state.buffer.length)
2408 return state.buffer[0].length;
2410 return state.length;
2416 // If we're asking for more than the target buffer level,
2417 // then raise the water mark. Bump up to the next highest
2418 // power of 2, to prevent increasing it excessively in tiny
2420 if (n > state.highWaterMark)
2421 state.highWaterMark = roundUpToNextPowerOf2(n);
2423 // don't have that much. return null, unless we've ended.
2424 if (n > state.length) {
2426 state.needReadable = true;
2429 return state.length;
2435 // you can override either this method, or the async _read(n) below.
2436 Readable.prototype.read = function(n) {
2437 var state = this._readableState;
2438 state.calledRead = true;
2441 if (typeof n !== 'number' || n > 0)
2442 state.emittedReadable = false;
2444 // if we're doing read(0) to trigger a readable event, but we
2445 // already have a bunch of data in the buffer, then just trigger
2446 // the 'readable' event and move on.
2448 state.needReadable &&
2449 (state.length >= state.highWaterMark || state.ended)) {
2454 n = howMuchToRead(n, state);
2456 // if we've ended, and we're now clear, then finish it up.
2457 if (n === 0 && state.ended) {
2458 if (state.length === 0)
2463 // All the actual chunk generation logic needs to be
2464 // *below* the call to _read. The reason is that in certain
2465 // synthetic stream cases, such as passthrough streams, _read
2466 // may be a completely synchronous operation which may change
2467 // the state of the read buffer, providing enough data when
2468 // before there was *not* enough.
2470 // So, the steps are:
2471 // 1. Figure out what the state of things will be after we do
2472 // a read from the buffer.
2474 // 2. If that resulting state will trigger a _read, then call _read.
2475 // Note that this may be asynchronous, or synchronous. Yes, it is
2476 // deeply ugly to write APIs this way, but that still doesn't mean
2477 // that the Readable class should behave improperly, as streams are
2478 // designed to be sync/async agnostic.
2479 // Take note if the _read call is sync or async (ie, if the read call
2480 // has returned yet), so that we know whether or not it's safe to emit
2483 // 3. Actually pull the requested chunks out of the buffer and return.
2485 // if we need a readable event, then we need to do some reading.
2486 var doRead = state.needReadable;
2488 // if we currently have less than the highWaterMark, then also read some
2489 if (state.length - n <= state.highWaterMark)
2492 // however, if we've ended, then there's no point, and if we're already
2493 // reading, then it's unnecessary.
2494 if (state.ended || state.reading)
2498 state.reading = true;
2500 // if the length is currently zero, then we *need* a readable event.
2501 if (state.length === 0)
2502 state.needReadable = true;
2503 // call internal read method
2504 this._read(state.highWaterMark);
2508 // If _read called its callback synchronously, then `reading`
2509 // will be false, and we need to re-evaluate how much data we
2510 // can return to the user.
2511 if (doRead && !state.reading)
2512 n = howMuchToRead(nOrig, state);
2516 ret = fromList(n, state);
2521 state.needReadable = true;
2527 // If we have nothing in the buffer, then we want to know
2528 // as soon as we *do* get something into the buffer.
2529 if (state.length === 0 && !state.ended)
2530 state.needReadable = true;
2532 // If we happened to read() exactly the remaining amount in the
2533 // buffer, and the EOF has been seen at this point, then make sure
2534 // that we emit 'end' on the very next tick.
2535 if (state.ended && !state.endEmitted && state.length === 0)
2541 function chunkInvalid(state, chunk) {
2543 if (!Buffer.isBuffer(chunk) &&
2544 'string' !== typeof chunk &&
2546 chunk !== undefined &&
2547 !state.objectMode &&
2549 er = new TypeError('Invalid non-string/buffer chunk');
2555 function onEofChunk(stream, state) {
2556 if (state.decoder && !state.ended) {
2557 var chunk = state.decoder.end();
2558 if (chunk && chunk.length) {
2559 state.buffer.push(chunk);
2560 state.length += state.objectMode ? 1 : chunk.length;
2565 // if we've ended and we have some data left, then emit
2566 // 'readable' now to make sure it gets picked up.
2567 if (state.length > 0)
2568 emitReadable(stream);
2570 endReadable(stream);
2573 // Don't emit readable right away in sync mode, because this can trigger
2574 // another read() call => stack overflow. This way, it might trigger
2575 // a nextTick recursion warning, but that's not so bad.
2576 function emitReadable(stream) {
2577 var state = stream._readableState;
2578 state.needReadable = false;
2579 if (state.emittedReadable)
2582 state.emittedReadable = true;
2584 setImmediate(function() {
2585 emitReadable_(stream);
2588 emitReadable_(stream);
2591 function emitReadable_(stream) {
2592 stream.emit('readable');
2596 // at this point, the user has presumably seen the 'readable' event,
2597 // and called read() to consume some data. that may have triggered
2598 // in turn another _read(n) call, in which case reading = true if
2599 // it's in progress.
2600 // However, if we're not ended, or reading, and the length < hwm,
2601 // then go ahead and try to read some more preemptively.
2602 function maybeReadMore(stream, state) {
2603 if (!state.readingMore) {
2604 state.readingMore = true;
2605 setImmediate(function() {
2606 maybeReadMore_(stream, state);
2611 function maybeReadMore_(stream, state) {
2612 var len = state.length;
2613 while (!state.reading && !state.flowing && !state.ended &&
2614 state.length < state.highWaterMark) {
2616 if (len === state.length)
2617 // didn't get any data, stop spinning.
2622 state.readingMore = false;
2625 // abstract method. to be overridden in specific implementation classes.
2626 // call cb(er, data) where data is <= n in length.
2627 // for virtual (non-string, non-buffer) streams, "length" is somewhat
2628 // arbitrary, and perhaps not very meaningful.
2629 Readable.prototype._read = function(n) {
2630 this.emit('error', new Error('not implemented'));
2633 Readable.prototype.pipe = function(dest, pipeOpts) {
2635 var state = this._readableState;
2637 switch (state.pipesCount) {
2642 state.pipes = [state.pipes, dest];
2645 state.pipes.push(dest);
2648 state.pipesCount += 1;
2650 var doEnd = (!pipeOpts || pipeOpts.end !== false) &&
2651 dest !== process.stdout &&
2652 dest !== process.stderr;
2654 var endFn = doEnd ? onend : cleanup;
2655 if (state.endEmitted)
2656 setImmediate(endFn);
2658 src.once('end', endFn);
2660 dest.on('unpipe', onunpipe);
2661 function onunpipe(readable) {
2662 if (readable !== src) return;
2670 // when the dest drains, it reduces the awaitDrain counter
2671 // on the source. This would be more elegant with a .once()
2672 // handler in flow(), but adding and removing repeatedly is
2674 var ondrain = pipeOnDrain(src);
2675 dest.on('drain', ondrain);
2677 function cleanup() {
2678 // cleanup event handlers once the pipe is broken
2679 dest.removeListener('close', onclose);
2680 dest.removeListener('finish', onfinish);
2681 dest.removeListener('drain', ondrain);
2682 dest.removeListener('error', onerror);
2683 dest.removeListener('unpipe', onunpipe);
2684 src.removeListener('end', onend);
2685 src.removeListener('end', cleanup);
2687 // if the reader is waiting for a drain event from this
2688 // specific writer, then it would cause it to never start
2690 // So, if this is awaiting a drain, then we just call it now.
2691 // If we don't know, then assume that we are waiting for one.
2692 if (!dest._writableState || dest._writableState.needDrain)
2696 // if the dest has an error, then stop piping into it.
2697 // however, don't suppress the throwing behavior for this.
2698 // check for listeners before emit removes one-time listeners.
2699 var errListeners = EE.listenerCount(dest, 'error');
2700 function onerror(er) {
2702 if (errListeners === 0 && EE.listenerCount(dest, 'error') === 0)
2703 dest.emit('error', er);
2705 dest.once('error', onerror);
2707 // Both close and finish should trigger unpipe, but only once.
2708 function onclose() {
2709 dest.removeListener('finish', onfinish);
2712 dest.once('close', onclose);
2713 function onfinish() {
2714 dest.removeListener('close', onclose);
2717 dest.once('finish', onfinish);
2723 // tell the dest that it's being piped to
2724 dest.emit('pipe', src);
2726 // start the flow if it hasn't been started already.
2727 if (!state.flowing) {
2728 // the handler that waits for readable events after all
2729 // the data gets sucked out in flow.
2730 // This would be easier to follow with a .once() handler
2731 // in flow(), but that is too slow.
2732 this.on('readable', pipeOnReadable);
2734 state.flowing = true;
2735 setImmediate(function() {
2743 function pipeOnDrain(src) {
2746 var state = src._readableState;
2748 if (state.awaitDrain === 0)
2753 function flow(src) {
2754 var state = src._readableState;
2756 state.awaitDrain = 0;
2758 function write(dest, i, list) {
2759 var written = dest.write(chunk);
2760 if (false === written) {
2765 while (state.pipesCount && null !== (chunk = src.read())) {
2767 if (state.pipesCount === 1)
2768 write(state.pipes, 0, null);
2770 forEach(state.pipes, write);
2772 src.emit('data', chunk);
2774 // if anyone needs a drain, then we have to wait for that.
2775 if (state.awaitDrain > 0)
2779 // if every destination was unpiped, either before entering this
2780 // function, or in the while loop, then stop flowing.
2782 // NB: This is a pretty rare edge case.
2783 if (state.pipesCount === 0) {
2784 state.flowing = false;
2786 // if there were data event listeners added, then switch to old mode.
2787 if (EE.listenerCount(src, 'data') > 0)
2788 emitDataEvents(src);
2792 // at this point, no one needed a drain, so we just ran out of data
2793 // on the next readable event, start it over again.
2794 state.ranOut = true;
2797 function pipeOnReadable() {
2798 if (this._readableState.ranOut) {
2799 this._readableState.ranOut = false;
2805 Readable.prototype.unpipe = function(dest) {
2806 var state = this._readableState;
2808 // if we're not piping anywhere, then do nothing.
2809 if (state.pipesCount === 0)
2812 // just one destination. most common case.
2813 if (state.pipesCount === 1) {
2814 // passed in one, but it's not the right one.
2815 if (dest && dest !== state.pipes)
2823 state.pipesCount = 0;
2824 this.removeListener('readable', pipeOnReadable);
2825 state.flowing = false;
2827 dest.emit('unpipe', this);
2831 // slow case. multiple pipe destinations.
2835 var dests = state.pipes;
2836 var len = state.pipesCount;
2838 state.pipesCount = 0;
2839 this.removeListener('readable', pipeOnReadable);
2840 state.flowing = false;
2842 for (var i = 0; i < len; i++)
2843 dests[i].emit('unpipe', this);
2847 // try to find the right one.
2848 var i = indexOf(state.pipes, dest);
2852 state.pipes.splice(i, 1);
2853 state.pipesCount -= 1;
2854 if (state.pipesCount === 1)
2855 state.pipes = state.pipes[0];
2857 dest.emit('unpipe', this);
2862 // set up data events if they are asked for
2863 // Ensure readable listeners eventually get something
2864 Readable.prototype.on = function(ev, fn) {
2865 var res = Stream.prototype.on.call(this, ev, fn);
2867 if (ev === 'data' && !this._readableState.flowing)
2868 emitDataEvents(this);
2870 if (ev === 'readable' && this.readable) {
2871 var state = this._readableState;
2872 if (!state.readableListening) {
2873 state.readableListening = true;
2874 state.emittedReadable = false;
2875 state.needReadable = true;
2876 if (!state.reading) {
2878 } else if (state.length) {
2879 emitReadable(this, state);
2886 Readable.prototype.addListener = Readable.prototype.on;
2888 // pause() and resume() are remnants of the legacy readable stream API
2889 // If the user uses them, then switch into old mode.
2890 Readable.prototype.resume = function() {
2891 emitDataEvents(this);
2893 this.emit('resume');
2896 Readable.prototype.pause = function() {
2897 emitDataEvents(this, true);
2901 function emitDataEvents(stream, startPaused) {
2902 var state = stream._readableState;
2904 if (state.flowing) {
2905 // https://github.com/isaacs/readable-stream/issues/16
2906 throw new Error('Cannot switch to old mode now.');
2909 var paused = startPaused || false;
2910 var readable = false;
2912 // convert to an old-style stream.
2913 stream.readable = true;
2914 stream.pipe = Stream.prototype.pipe;
2915 stream.on = stream.addListener = Stream.prototype.on;
2917 stream.on('readable', function() {
2921 while (!paused && (null !== (c = stream.read())))
2922 stream.emit('data', c);
2926 stream._readableState.needReadable = true;
2930 stream.pause = function() {
2935 stream.resume = function() {
2938 setImmediate(function() {
2939 stream.emit('readable');
2943 this.emit('resume');
2946 // now make it start, just in case it hadn't already.
2947 stream.emit('readable');
2950 // wrap an old-style stream as the async data source.
2951 // This is *not* part of the readable stream interface.
2952 // It is an ugly unfortunate mess of history.
2953 Readable.prototype.wrap = function(stream) {
2954 var state = this._readableState;
2958 stream.on('end', function() {
2959 if (state.decoder && !state.ended) {
2960 var chunk = state.decoder.end();
2961 if (chunk && chunk.length)
2968 stream.on('data', function(chunk) {
2970 chunk = state.decoder.write(chunk);
2971 if (!chunk || !state.objectMode && !chunk.length)
2974 var ret = self.push(chunk);
2981 // proxy all the other methods.
2982 // important when wrapping filters and duplexes.
2983 for (var i in stream) {
2984 if (typeof stream[i] === 'function' &&
2985 typeof this[i] === 'undefined') {
2986 this[i] = function(method) { return function() {
2987 return stream[method].apply(stream, arguments);
2992 // proxy certain important events.
2993 var events = ['error', 'close', 'destroy', 'pause', 'resume'];
2994 forEach(events, function(ev) {
2995 stream.on(ev, function (x) {
2996 return self.emit.apply(self, ev, x);
3000 // when we try to consume some more bytes, simply unpause the
3001 // underlying stream.
3002 self._read = function(n) {
3014 // exposed for testing purposes only.
3015 Readable._fromList = fromList;
3017 // Pluck off n bytes from an array of buffers.
3018 // Length is the combined lengths of all the buffers in the list.
3019 function fromList(n, state) {
3020 var list = state.buffer;
3021 var length = state.length;
3022 var stringMode = !!state.decoder;
3023 var objectMode = !!state.objectMode;
3026 // nothing in the list, definitely empty.
3027 if (list.length === 0)
3032 else if (objectMode)
3034 else if (!n || n >= length) {
3035 // read it all, truncate the array.
3037 ret = list.join('');
3039 ret = Buffer.concat(list, length);
3042 // read just some of it.
3043 if (n < list[0].length) {
3044 // just take a part of the first list item.
3045 // slice is the same for buffers and strings.
3047 ret = buf.slice(0, n);
3048 list[0] = buf.slice(n);
3049 } else if (n === list[0].length) {
3050 // first list is a perfect match
3054 // we have enough to cover it, but it spans past the first buffer.
3058 ret = new Buffer(n);
3061 for (var i = 0, l = list.length; i < l && c < n; i++) {
3063 var cpy = Math.min(n - c, buf.length);
3066 ret += buf.slice(0, cpy);
3068 buf.copy(ret, c, 0, cpy);
3070 if (cpy < buf.length)
3071 list[0] = buf.slice(cpy);
3083 function endReadable(stream) {
3084 var state = stream._readableState;
3086 // If we get here before consuming all the bytes, then that is a
3087 // bug in node. Should never happen.
3088 if (state.length > 0)
3089 throw new Error('endReadable called on non-empty stream');
3091 if (!state.endEmitted && state.calledRead) {
3093 setImmediate(function() {
3094 // Check that we didn't get one last unshift.
3095 if (!state.endEmitted && state.length === 0) {
3096 state.endEmitted = true;
3097 stream.readable = false;
3104 function forEach (xs, f) {
3105 for (var i = 0, l = xs.length; i < l; i++) {
3110 function indexOf (xs, x) {
3111 for (var i = 0, l = xs.length; i < l; i++) {
3112 if (xs[i] === x) return i;
3117 }).call(this,require("/Users/stephen/.nvm/v0.10.24/lib/node_modules/testling/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js"))
3118 },{"./index.js":9,"/Users/stephen/.nvm/v0.10.24/lib/node_modules/testling/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js":6,"buffer":1,"events":4,"inherits":5,"process/browser.js":10,"string_decoder":15}],13:[function(require,module,exports){
3119 // Copyright Joyent, Inc. and other Node contributors.
3121 // Permission is hereby granted, free of charge, to any person obtaining a
3122 // copy of this software and associated documentation files (the
3123 // "Software"), to deal in the Software without restriction, including
3124 // without limitation the rights to use, copy, modify, merge, publish,
3125 // distribute, sublicense, and/or sell copies of the Software, and to permit
3126 // persons to whom the Software is furnished to do so, subject to the
3127 // following conditions:
3129 // The above copyright notice and this permission notice shall be included
3130 // in all copies or substantial portions of the Software.
3132 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
3133 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
3134 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
3135 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
3136 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
3137 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
3138 // USE OR OTHER DEALINGS IN THE SOFTWARE.
3140 // a transform stream is a readable/writable stream where you do
3141 // something with the data. Sometimes it's called a "filter",
3142 // but that's not a great name for it, since that implies a thing where
3143 // some bits pass through, and others are simply ignored. (That would
3144 // be a valid example of a transform, of course.)
3146 // While the output is causally related to the input, it's not a
3147 // necessarily symmetric or synchronous transformation. For example,
3148 // a zlib stream might take multiple plain-text writes(), and then
3149 // emit a single compressed chunk some time in the future.
3151 // Here's how this works:
3153 // The Transform stream has all the aspects of the readable and writable
3154 // stream classes. When you write(chunk), that calls _write(chunk,cb)
3155 // internally, and returns false if there's a lot of pending writes
3156 // buffered up. When you call read(), that calls _read(n) until
3157 // there's enough pending readable data buffered up.
3159 // In a transform stream, the written data is placed in a buffer. When
3160 // _read(n) is called, it transforms the queued up data, calling the
3161 // buffered _write cb's as it consumes chunks. If consuming a single
3162 // written chunk would result in multiple output chunks, then the first
3163 // outputted bit calls the readcb, and subsequent chunks just go into
3164 // the read buffer, and will cause it to emit 'readable' if necessary.
3166 // This way, back-pressure is actually determined by the reading side,
3167 // since _read has to be called to start processing a new chunk. However,
3168 // a pathological inflate type of transform can cause excessive buffering
3169 // here. For example, imagine a stream where every byte of input is
3170 // interpreted as an integer from 0-255, and then results in that many
3171 // bytes of output. Writing the 4 bytes {ff,ff,ff,ff} would result in
3172 // 1kb of data being output. In this case, you could write a very small
3173 // amount of input, and end up with a very large amount of output. In
3174 // such a pathological inflating mechanism, there'd be no way to tell
3175 // the system to stop doing the transform. A single 4MB write could
3176 // cause the system to run out of memory.
3178 // However, even in such a pathological case, only a single written chunk
3179 // would be consumed, and then the rest would wait (un-transformed) until
3180 // the results of the previous transformed chunk were consumed.
3182 module.exports = Transform;
3184 var Duplex = require('./duplex.js');
3185 var inherits = require('inherits');
3186 inherits(Transform, Duplex);
3189 function TransformState(options, stream) {
3190 this.afterTransform = function(er, data) {
3191 return afterTransform(stream, er, data);
3194 this.needTransform = false;
3195 this.transforming = false;
3196 this.writecb = null;
3197 this.writechunk = null;
3200 function afterTransform(stream, er, data) {
3201 var ts = stream._transformState;
3202 ts.transforming = false;
3204 var cb = ts.writecb;
3207 return stream.emit('error', new Error('no writecb in Transform class'));
3209 ts.writechunk = null;
3212 if (data !== null && data !== undefined)
3218 var rs = stream._readableState;
3220 if (rs.needReadable || rs.length < rs.highWaterMark) {
3221 stream._read(rs.highWaterMark);
3226 function Transform(options) {
3227 if (!(this instanceof Transform))
3228 return new Transform(options);
3230 Duplex.call(this, options);
3232 var ts = this._transformState = new TransformState(options, this);
3234 // when the writable side finishes, then flush out anything remaining.
3237 // start out asking for a readable event once data is transformed.
3238 this._readableState.needReadable = true;
3240 // we have implemented the _read method, and done the other things
3241 // that Readable wants before the first _read call, so unset the
3243 this._readableState.sync = false;
3245 this.once('finish', function() {
3246 if ('function' === typeof this._flush)
3247 this._flush(function(er) {
3255 Transform.prototype.push = function(chunk, encoding) {
3256 this._transformState.needTransform = false;
3257 return Duplex.prototype.push.call(this, chunk, encoding);
3260 // This is the part where you do stuff!
3261 // override this function in implementation classes.
3262 // 'chunk' is an input chunk.
3264 // Call `push(newChunk)` to pass along transformed output
3265 // to the readable side. You may call 'push' zero or more times.
3267 // Call `cb(err)` when you are done with this chunk. If you pass
3268 // an error, then that'll put the hurt on the whole operation. If you
3269 // never call cb(), then you'll never get another chunk.
3270 Transform.prototype._transform = function(chunk, encoding, cb) {
3271 throw new Error('not implemented');
3274 Transform.prototype._write = function(chunk, encoding, cb) {
3275 var ts = this._transformState;
3277 ts.writechunk = chunk;
3278 ts.writeencoding = encoding;
3279 if (!ts.transforming) {
3280 var rs = this._readableState;
3281 if (ts.needTransform ||
3283 rs.length < rs.highWaterMark)
3284 this._read(rs.highWaterMark);
3288 // Doesn't matter what the args are here.
3289 // _transform does all the work.
3290 // That we got here means that the readable side wants more data.
3291 Transform.prototype._read = function(n) {
3292 var ts = this._transformState;
3294 if (ts.writechunk && ts.writecb && !ts.transforming) {
3295 ts.transforming = true;
3296 this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
3298 // mark that we need a transform, so that any data that comes in
3299 // will get processed, now that we've asked for it.
3300 ts.needTransform = true;
3305 function done(stream, er) {
3307 return stream.emit('error', er);
3309 // if there's nothing in the write buffer, then that means
3310 // that nothing more will ever be provided
3311 var ws = stream._writableState;
3312 var rs = stream._readableState;
3313 var ts = stream._transformState;
3316 throw new Error('calling transform done when ws.length != 0');
3318 if (ts.transforming)
3319 throw new Error('calling transform done when still transforming');
3321 return stream.push(null);
3324 },{"./duplex.js":8,"inherits":5}],14:[function(require,module,exports){
3325 // Copyright Joyent, Inc. and other Node contributors.
3327 // Permission is hereby granted, free of charge, to any person obtaining a
3328 // copy of this software and associated documentation files (the
3329 // "Software"), to deal in the Software without restriction, including
3330 // without limitation the rights to use, copy, modify, merge, publish,
3331 // distribute, sublicense, and/or sell copies of the Software, and to permit
3332 // persons to whom the Software is furnished to do so, subject to the
3333 // following conditions:
3335 // The above copyright notice and this permission notice shall be included
3336 // in all copies or substantial portions of the Software.
3338 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
3339 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
3340 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
3341 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
3342 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
3343 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
3344 // USE OR OTHER DEALINGS IN THE SOFTWARE.
3346 // A bit simpler than readable streams.
3347 // Implement an async ._write(chunk, cb), and it'll handle all
3348 // the drain event emission and buffering.
3350 module.exports = Writable;
3351 Writable.WritableState = WritableState;
3353 var isUint8Array = typeof Uint8Array !== 'undefined'
3354 ? function (x) { return x instanceof Uint8Array }
3356 return x && x.constructor && x.constructor.name === 'Uint8Array'
3359 var isArrayBuffer = typeof ArrayBuffer !== 'undefined'
3360 ? function (x) { return x instanceof ArrayBuffer }
3362 return x && x.constructor && x.constructor.name === 'ArrayBuffer'
3366 var inherits = require('inherits');
3367 var Stream = require('./index.js');
3368 var setImmediate = require('process/browser.js').nextTick;
3369 var Buffer = require('buffer').Buffer;
3371 inherits(Writable, Stream);
3373 function WriteReq(chunk, encoding, cb) {
3375 this.encoding = encoding;
3379 function WritableState(options, stream) {
3380 options = options || {};
3382 // the point at which write() starts returning false
3383 // Note: 0 is a valid value, means that we always return false if
3384 // the entire buffer is not flushed immediately on write()
3385 var hwm = options.highWaterMark;
3386 this.highWaterMark = (hwm || hwm === 0) ? hwm : 16 * 1024;
3388 // object stream flag to indicate whether or not this stream
3389 // contains buffers or objects.
3390 this.objectMode = !!options.objectMode;
3393 this.highWaterMark = ~~this.highWaterMark;
3395 this.needDrain = false;
3396 // at the start of calling end()
3397 this.ending = false;
3398 // when end() has been called, and returned
3400 // when 'finish' is emitted
3401 this.finished = false;
3403 // should we decode strings into buffers before passing to _write?
3404 // this is here so that some node-core streams can optimize string
3405 // handling at a lower level.
3406 var noDecode = options.decodeStrings === false;
3407 this.decodeStrings = !noDecode;
3409 // Crypto is kind of old and crusty. Historically, its default string
3410 // encoding is 'binary' so we have to make this configurable.
3411 // Everything else in the universe uses 'utf8', though.
3412 this.defaultEncoding = options.defaultEncoding || 'utf8';
3414 // not an actual buffer we keep track of, but a measurement
3415 // of how much we're waiting to get pushed to some underlying
3419 // a flag to see when we're in the middle of a write.
3420 this.writing = false;
3422 // a flag to be able to tell if the onwrite cb is called immediately,
3423 // or on a later tick. We set this to true at first, becuase any
3424 // actions that shouldn't happen until "later" should generally also
3425 // not happen before the first write call.
3428 // a flag to know if we're processing previously buffered items, which
3429 // may call the _write() callback in the same tick, so that we don't
3430 // end up in an overlapped onwrite situation.
3431 this.bufferProcessing = false;
3433 // the callback that's passed to _write(chunk,cb)
3434 this.onwrite = function(er) {
3435 onwrite(stream, er);
3438 // the callback that the user supplies to write(chunk,encoding,cb)
3439 this.writecb = null;
3441 // the amount that is being written when _write is called.
3447 function Writable(options) {
3448 // Writable ctor is applied to Duplexes, though they're not
3449 // instanceof Writable, they're instanceof Readable.
3450 if (!(this instanceof Writable) && !(this instanceof Stream.Duplex))
3451 return new Writable(options);
3453 this._writableState = new WritableState(options, this);
3456 this.writable = true;
3461 // Otherwise people can pipe Writable streams, which is just wrong.
3462 Writable.prototype.pipe = function() {
3463 this.emit('error', new Error('Cannot pipe. Not readable.'));
3467 function writeAfterEnd(stream, state, cb) {
3468 var er = new Error('write after end');
3469 // TODO: defer error events consistently everywhere, not just the cb
3470 stream.emit('error', er);
3471 setImmediate(function() {
3476 // If we get something that is not a buffer, string, null, or undefined,
3477 // and we're not in objectMode, then that's an error.
3478 // Otherwise stream chunks are all considered to be of length=1, and the
3479 // watermarks determine how many objects to keep in the buffer, rather than
3480 // how many bytes or characters.
3481 function validChunk(stream, state, chunk, cb) {
3483 if (!Buffer.isBuffer(chunk) &&
3484 'string' !== typeof chunk &&
3486 chunk !== undefined &&
3487 !state.objectMode) {
3488 var er = new TypeError('Invalid non-string/buffer chunk');
3489 stream.emit('error', er);
3490 setImmediate(function() {
3498 Writable.prototype.write = function(chunk, encoding, cb) {
3499 var state = this._writableState;
3502 if (typeof encoding === 'function') {
3507 if (!Buffer.isBuffer(chunk) && isUint8Array(chunk))
3508 chunk = new Buffer(chunk);
3509 if (isArrayBuffer(chunk) && typeof Uint8Array !== 'undefined')
3510 chunk = new Buffer(new Uint8Array(chunk));
3512 if (Buffer.isBuffer(chunk))
3513 encoding = 'buffer';
3515 encoding = state.defaultEncoding;
3517 if (typeof cb !== 'function')
3521 writeAfterEnd(this, state, cb);
3522 else if (validChunk(this, state, chunk, cb))
3523 ret = writeOrBuffer(this, state, chunk, encoding, cb);
3528 function decodeChunk(state, chunk, encoding) {
3529 if (!state.objectMode &&
3530 state.decodeStrings !== false &&
3531 typeof chunk === 'string') {
3532 chunk = new Buffer(chunk, encoding);
3537 // if we're already writing something, then just put this
3538 // in the queue, and wait our turn. Otherwise, call _write
3539 // If we return false, then we need a drain event, so set that flag.
3540 function writeOrBuffer(stream, state, chunk, encoding, cb) {
3541 chunk = decodeChunk(state, chunk, encoding);
3542 var len = state.objectMode ? 1 : chunk.length;
3544 state.length += len;
3546 var ret = state.length < state.highWaterMark;
3547 state.needDrain = !ret;
3550 state.buffer.push(new WriteReq(chunk, encoding, cb));
3552 doWrite(stream, state, len, chunk, encoding, cb);
3557 function doWrite(stream, state, len, chunk, encoding, cb) {
3558 state.writelen = len;
3560 state.writing = true;
3562 stream._write(chunk, encoding, state.onwrite);
3566 function onwriteError(stream, state, sync, er, cb) {
3568 setImmediate(function() {
3574 stream.emit('error', er);
3577 function onwriteStateUpdate(state) {
3578 state.writing = false;
3579 state.writecb = null;
3580 state.length -= state.writelen;
3584 function onwrite(stream, er) {
3585 var state = stream._writableState;
3586 var sync = state.sync;
3587 var cb = state.writecb;
3589 onwriteStateUpdate(state);
3592 onwriteError(stream, state, sync, er, cb);
3594 // Check if we're actually ready to finish, but don't emit yet
3595 var finished = needFinish(stream, state);
3597 if (!finished && !state.bufferProcessing && state.buffer.length)
3598 clearBuffer(stream, state);
3601 setImmediate(function() {
3602 afterWrite(stream, state, finished, cb);
3605 afterWrite(stream, state, finished, cb);
3610 function afterWrite(stream, state, finished, cb) {
3612 onwriteDrain(stream, state);
3615 finishMaybe(stream, state);
3618 // Must force callback to be called on nextTick, so that we don't
3619 // emit 'drain' before the write() consumer gets the 'false' return
3620 // value, and has a chance to attach a 'drain' listener.
3621 function onwriteDrain(stream, state) {
3622 if (state.length === 0 && state.needDrain) {
3623 state.needDrain = false;
3624 stream.emit('drain');
3629 // if there's something in the buffer waiting, then process it
3630 function clearBuffer(stream, state) {
3631 state.bufferProcessing = true;
3633 for (var c = 0; c < state.buffer.length; c++) {
3634 var entry = state.buffer[c];
3635 var chunk = entry.chunk;
3636 var encoding = entry.encoding;
3637 var cb = entry.callback;
3638 var len = state.objectMode ? 1 : chunk.length;
3640 doWrite(stream, state, len, chunk, encoding, cb);
3642 // if we didn't call the onwrite immediately, then
3643 // it means that we need to wait until it does.
3644 // also, that means that the chunk and cb are currently
3645 // being processed, so move the buffer counter past them.
3646 if (state.writing) {
3652 state.bufferProcessing = false;
3653 if (c < state.buffer.length)
3654 state.buffer = state.buffer.slice(c);
3656 state.buffer.length = 0;
3659 Writable.prototype._write = function(chunk, encoding, cb) {
3660 cb(new Error('not implemented'));
3663 Writable.prototype.end = function(chunk, encoding, cb) {
3664 var state = this._writableState;
3666 if (typeof chunk === 'function') {
3670 } else if (typeof encoding === 'function') {
3675 if (typeof chunk !== 'undefined' && chunk !== null)
3676 this.write(chunk, encoding);
3678 // ignore unnecessary end() calls.
3679 if (!state.ending && !state.finished)
3680 endWritable(this, state, cb);
3684 function needFinish(stream, state) {
3685 return (state.ending &&
3686 state.length === 0 &&
3691 function finishMaybe(stream, state) {
3692 var need = needFinish(stream, state);
3694 state.finished = true;
3695 stream.emit('finish');
3700 function endWritable(stream, state, cb) {
3701 state.ending = true;
3702 finishMaybe(stream, state);
3707 stream.once('finish', cb);
3712 },{"./index.js":9,"buffer":1,"inherits":5,"process/browser.js":10}],15:[function(require,module,exports){
3713 // Copyright Joyent, Inc. and other Node contributors.
3715 // Permission is hereby granted, free of charge, to any person obtaining a
3716 // copy of this software and associated documentation files (the
3717 // "Software"), to deal in the Software without restriction, including
3718 // without limitation the rights to use, copy, modify, merge, publish,
3719 // distribute, sublicense, and/or sell copies of the Software, and to permit
3720 // persons to whom the Software is furnished to do so, subject to the
3721 // following conditions:
3723 // The above copyright notice and this permission notice shall be included
3724 // in all copies or substantial portions of the Software.
3726 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
3727 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
3728 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
3729 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
3730 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
3731 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
3732 // USE OR OTHER DEALINGS IN THE SOFTWARE.
3734 var Buffer = require('buffer').Buffer;
3736 function assertEncoding(encoding) {
3737 if (encoding && !Buffer.isEncoding(encoding)) {
3738 throw new Error('Unknown encoding: ' + encoding);
3742 var StringDecoder = exports.StringDecoder = function(encoding) {
3743 this.encoding = (encoding || 'utf8').toLowerCase().replace(/[-_]/, '');
3744 assertEncoding(encoding);
3745 switch (this.encoding) {
3747 // CESU-8 represents each of Surrogate Pair by 3-bytes
3748 this.surrogateSize = 3;
3752 // UTF-16 represents each of Surrogate Pair by 2-bytes
3753 this.surrogateSize = 2;
3754 this.detectIncompleteChar = utf16DetectIncompleteChar;
3757 // Base-64 stores 3 bytes in 4 chars, and pads the remainder.
3758 this.surrogateSize = 3;
3759 this.detectIncompleteChar = base64DetectIncompleteChar;
3762 this.write = passThroughWrite;
3766 this.charBuffer = new Buffer(6);
3767 this.charReceived = 0;
3768 this.charLength = 0;
3772 StringDecoder.prototype.write = function(buffer) {
3776 // if our last write ended with an incomplete multibyte character
3777 while (this.charLength) {
3778 // determine how many remaining bytes this buffer has to offer for this char
3779 var i = (buffer.length >= this.charLength - this.charReceived) ?
3780 this.charLength - this.charReceived :
3783 // add the new bytes to the char buffer
3784 buffer.copy(this.charBuffer, this.charReceived, offset, i);
3785 this.charReceived += (i - offset);
3788 if (this.charReceived < this.charLength) {
3789 // still not enough chars in this buffer? wait for more ...
3793 // get the character that was split
3794 charStr = this.charBuffer.slice(0, this.charLength).toString(this.encoding);
3796 // lead surrogate (D800-DBFF) is also the incomplete character
3797 var charCode = charStr.charCodeAt(charStr.length - 1);
3798 if (charCode >= 0xD800 && charCode <= 0xDBFF) {
3799 this.charLength += this.surrogateSize;
3803 this.charReceived = this.charLength = 0;
3805 // if there are no more bytes in this buffer, just emit our char
3806 if (i == buffer.length) return charStr;
3808 // otherwise cut off the characters end from the beginning of this buffer
3809 buffer = buffer.slice(i, buffer.length);
3813 var lenIncomplete = this.detectIncompleteChar(buffer);
3815 var end = buffer.length;
3816 if (this.charLength) {
3817 // buffer the incomplete character bytes we got
3818 buffer.copy(this.charBuffer, 0, buffer.length - lenIncomplete, end);
3819 this.charReceived = lenIncomplete;
3820 end -= lenIncomplete;
3823 charStr += buffer.toString(this.encoding, 0, end);
3825 var end = charStr.length - 1;
3826 var charCode = charStr.charCodeAt(end);
3827 // lead surrogate (D800-DBFF) is also the incomplete character
3828 if (charCode >= 0xD800 && charCode <= 0xDBFF) {
3829 var size = this.surrogateSize;
3830 this.charLength += size;
3831 this.charReceived += size;
3832 this.charBuffer.copy(this.charBuffer, size, 0, size);
3833 this.charBuffer.write(charStr.charAt(charStr.length - 1), this.encoding);
3834 return charStr.substring(0, end);
3837 // or just emit the charStr
3841 StringDecoder.prototype.detectIncompleteChar = function(buffer) {
3842 // determine how many bytes we have to check at the end of this buffer
3843 var i = (buffer.length >= 3) ? 3 : buffer.length;
3845 // Figure out if one of the last i bytes of our buffer announces an
3847 for (; i > 0; i--) {
3848 var c = buffer[buffer.length - i];
3850 // See http://en.wikipedia.org/wiki/UTF-8#Description
3853 if (i == 1 && c >> 5 == 0x06) {
3854 this.charLength = 2;
3859 if (i <= 2 && c >> 4 == 0x0E) {
3860 this.charLength = 3;
3865 if (i <= 3 && c >> 3 == 0x1E) {
3866 this.charLength = 4;
3874 StringDecoder.prototype.end = function(buffer) {
3876 if (buffer && buffer.length)
3877 res = this.write(buffer);
3879 if (this.charReceived) {
3880 var cr = this.charReceived;
3881 var buf = this.charBuffer;
3882 var enc = this.encoding;
3883 res += buf.slice(0, cr).toString(enc);
3889 function passThroughWrite(buffer) {
3890 return buffer.toString(this.encoding);
3893 function utf16DetectIncompleteChar(buffer) {
3894 var incomplete = this.charReceived = buffer.length % 2;
3895 this.charLength = incomplete ? 2 : 0;
3899 function base64DetectIncompleteChar(buffer) {
3900 var incomplete = this.charReceived = buffer.length % 3;
3901 this.charLength = incomplete ? 3 : 0;
3905 },{"buffer":1}],16:[function(require,module,exports){
3906 module.exports = function isBuffer(arg) {
3907 return arg && typeof arg === 'object'
3908 && typeof arg.copy === 'function'
3909 && typeof arg.fill === 'function'
3910 && typeof arg.readUInt8 === 'function';
3912 },{}],17:[function(require,module,exports){
3913 (function (process,global){
3914 // Copyright Joyent, Inc. and other Node contributors.
3916 // Permission is hereby granted, free of charge, to any person obtaining a
3917 // copy of this software and associated documentation files (the
3918 // "Software"), to deal in the Software without restriction, including
3919 // without limitation the rights to use, copy, modify, merge, publish,
3920 // distribute, sublicense, and/or sell copies of the Software, and to permit
3921 // persons to whom the Software is furnished to do so, subject to the
3922 // following conditions:
3924 // The above copyright notice and this permission notice shall be included
3925 // in all copies or substantial portions of the Software.
3927 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
3928 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
3929 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
3930 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
3931 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
3932 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
3933 // USE OR OTHER DEALINGS IN THE SOFTWARE.
3935 var formatRegExp = /%[sdj%]/g;
3936 exports.format = function(f) {
3939 for (var i = 0; i < arguments.length; i++) {
3940 objects.push(inspect(arguments[i]));
3942 return objects.join(' ');
3946 var args = arguments;
3947 var len = args.length;
3948 var str = String(f).replace(formatRegExp, function(x) {
3949 if (x === '%%') return '%';
3950 if (i >= len) return x;
3952 case '%s': return String(args[i++]);
3953 case '%d': return Number(args[i++]);
3956 return JSON.stringify(args[i++]);
3958 return '[Circular]';
3964 for (var x = args[i]; i < len; x = args[++i]) {
3965 if (isNull(x) || !isObject(x)) {
3968 str += ' ' + inspect(x);
3975 // Mark that a method should not be used.
3976 // Returns a modified function which warns once by default.
3977 // If --no-deprecation is set, then it is a no-op.
3978 exports.deprecate = function(fn, msg) {
3979 // Allow for deprecating things in the process of starting up.
3980 if (isUndefined(global.process)) {
3982 return exports.deprecate(fn, msg).apply(this, arguments);
3986 if (process.noDeprecation === true) {
3991 function deprecated() {
3993 if (process.throwDeprecation) {
3994 throw new Error(msg);
3995 } else if (process.traceDeprecation) {
4002 return fn.apply(this, arguments);
4011 exports.debuglog = function(set) {
4012 if (isUndefined(debugEnviron))
4013 debugEnviron = process.env.NODE_DEBUG || '';
4014 set = set.toUpperCase();
4016 if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
4017 var pid = process.pid;
4018 debugs[set] = function() {
4019 var msg = exports.format.apply(exports, arguments);
4020 console.error('%s %d: %s', set, pid, msg);
4023 debugs[set] = function() {};
4031 * Echos the value of a value. Trys to print the value out
4032 * in the best way possible given the different types.
4034 * @param {Object} obj The object to print out.
4035 * @param {Object} opts Optional options object that alters the output.
4037 /* legacy: obj, showHidden, depth, colors*/
4038 function inspect(obj, opts) {
4042 stylize: stylizeNoColor
4045 if (arguments.length >= 3) ctx.depth = arguments[2];
4046 if (arguments.length >= 4) ctx.colors = arguments[3];
4047 if (isBoolean(opts)) {
4049 ctx.showHidden = opts;
4051 // got an "options" object
4052 exports._extend(ctx, opts);
4054 // set default options
4055 if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
4056 if (isUndefined(ctx.depth)) ctx.depth = 2;
4057 if (isUndefined(ctx.colors)) ctx.colors = false;
4058 if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
4059 if (ctx.colors) ctx.stylize = stylizeWithColor;
4060 return formatValue(ctx, obj, ctx.depth);
4062 exports.inspect = inspect;
4065 // http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
4069 'underline' : [4, 24],
4070 'inverse' : [7, 27],
4077 'magenta' : [35, 39],
4082 // Don't use 'blue' not visible on cmd.exe
4086 'boolean': 'yellow',
4087 'undefined': 'grey',
4091 // "name": intentionally not styling
4096 function stylizeWithColor(str, styleType) {
4097 var style = inspect.styles[styleType];
4100 return '\u001b[' + inspect.colors[style][0] + 'm' + str +
4101 '\u001b[' + inspect.colors[style][1] + 'm';
4108 function stylizeNoColor(str, styleType) {
4113 function arrayToHash(array) {
4116 array.forEach(function(val, idx) {
4124 function formatValue(ctx, value, recurseTimes) {
4125 // Provide a hook for user-specified inspect functions.
4126 // Check that value is an object with an inspect function on it
4127 if (ctx.customInspect &&
4129 isFunction(value.inspect) &&
4130 // Filter out the util module, it's inspect function is special
4131 value.inspect !== exports.inspect &&
4132 // Also filter out any prototype objects using the circular check.
4133 !(value.constructor && value.constructor.prototype === value)) {
4134 var ret = value.inspect(recurseTimes, ctx);
4135 if (!isString(ret)) {
4136 ret = formatValue(ctx, ret, recurseTimes);
4141 // Primitive types cannot have properties
4142 var primitive = formatPrimitive(ctx, value);
4147 // Look up the keys of the object.
4148 var keys = Object.keys(value);
4149 var visibleKeys = arrayToHash(keys);
4151 if (ctx.showHidden) {
4152 keys = Object.getOwnPropertyNames(value);
4155 // IE doesn't make error fields non-enumerable
4156 // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx
4158 && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
4159 return formatError(value);
4162 // Some type of object without properties can be shortcutted.
4163 if (keys.length === 0) {
4164 if (isFunction(value)) {
4165 var name = value.name ? ': ' + value.name : '';
4166 return ctx.stylize('[Function' + name + ']', 'special');
4168 if (isRegExp(value)) {
4169 return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
4171 if (isDate(value)) {
4172 return ctx.stylize(Date.prototype.toString.call(value), 'date');
4174 if (isError(value)) {
4175 return formatError(value);
4179 var base = '', array = false, braces = ['{', '}'];
4181 // Make Array say that they are Array
4182 if (isArray(value)) {
4184 braces = ['[', ']'];
4187 // Make functions say that they are functions
4188 if (isFunction(value)) {
4189 var n = value.name ? ': ' + value.name : '';
4190 base = ' [Function' + n + ']';
4193 // Make RegExps say that they are RegExps
4194 if (isRegExp(value)) {
4195 base = ' ' + RegExp.prototype.toString.call(value);
4198 // Make dates with properties first say the date
4199 if (isDate(value)) {
4200 base = ' ' + Date.prototype.toUTCString.call(value);
4203 // Make error with message first say the error
4204 if (isError(value)) {
4205 base = ' ' + formatError(value);
4208 if (keys.length === 0 && (!array || value.length == 0)) {
4209 return braces[0] + base + braces[1];
4212 if (recurseTimes < 0) {
4213 if (isRegExp(value)) {
4214 return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
4216 return ctx.stylize('[Object]', 'special');
4220 ctx.seen.push(value);
4224 output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
4226 output = keys.map(function(key) {
4227 return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
4233 return reduceToSingleString(output, base, braces);
4237 function formatPrimitive(ctx, value) {
4238 if (isUndefined(value))
4239 return ctx.stylize('undefined', 'undefined');
4240 if (isString(value)) {
4241 var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
4242 .replace(/'/g, "\\'")
4243 .replace(/\\"/g, '"') + '\'';
4244 return ctx.stylize(simple, 'string');
4246 if (isNumber(value))
4247 return ctx.stylize('' + value, 'number');
4248 if (isBoolean(value))
4249 return ctx.stylize('' + value, 'boolean');
4250 // For some reason typeof null is "object", so special case here.
4252 return ctx.stylize('null', 'null');
4256 function formatError(value) {
4257 return '[' + Error.prototype.toString.call(value) + ']';
4261 function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
4263 for (var i = 0, l = value.length; i < l; ++i) {
4264 if (hasOwnProperty(value, String(i))) {
4265 output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
4271 keys.forEach(function(key) {
4272 if (!key.match(/^\d+$/)) {
4273 output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
4281 function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
4282 var name, str, desc;
4283 desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
4286 str = ctx.stylize('[Getter/Setter]', 'special');
4288 str = ctx.stylize('[Getter]', 'special');
4292 str = ctx.stylize('[Setter]', 'special');
4295 if (!hasOwnProperty(visibleKeys, key)) {
4296 name = '[' + key + ']';
4299 if (ctx.seen.indexOf(desc.value) < 0) {
4300 if (isNull(recurseTimes)) {
4301 str = formatValue(ctx, desc.value, null);
4303 str = formatValue(ctx, desc.value, recurseTimes - 1);
4305 if (str.indexOf('\n') > -1) {
4307 str = str.split('\n').map(function(line) {
4309 }).join('\n').substr(2);
4311 str = '\n' + str.split('\n').map(function(line) {
4317 str = ctx.stylize('[Circular]', 'special');
4320 if (isUndefined(name)) {
4321 if (array && key.match(/^\d+$/)) {
4324 name = JSON.stringify('' + key);
4325 if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
4326 name = name.substr(1, name.length - 2);
4327 name = ctx.stylize(name, 'name');
4329 name = name.replace(/'/g, "\\'")
4330 .replace(/\\"/g, '"')
4331 .replace(/(^"|"$)/g, "'");
4332 name = ctx.stylize(name, 'string');
4336 return name + ': ' + str;
4340 function reduceToSingleString(output, base, braces) {
4341 var numLinesEst = 0;
4342 var length = output.reduce(function(prev, cur) {
4344 if (cur.indexOf('\n') >= 0) numLinesEst++;
4345 return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
4350 (base === '' ? '' : base + '\n ') +
4352 output.join(',\n ') +
4357 return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
4361 // NOTE: These type checking functions intentionally don't use `instanceof`
4362 // because it is fragile and can be easily faked with `Object.create()`.
4363 function isArray(ar) {
4364 return Array.isArray(ar);
4366 exports.isArray = isArray;
4368 function isBoolean(arg) {
4369 return typeof arg === 'boolean';
4371 exports.isBoolean = isBoolean;
4373 function isNull(arg) {
4374 return arg === null;
4376 exports.isNull = isNull;
4378 function isNullOrUndefined(arg) {
4381 exports.isNullOrUndefined = isNullOrUndefined;
4383 function isNumber(arg) {
4384 return typeof arg === 'number';
4386 exports.isNumber = isNumber;
4388 function isString(arg) {
4389 return typeof arg === 'string';
4391 exports.isString = isString;
4393 function isSymbol(arg) {
4394 return typeof arg === 'symbol';
4396 exports.isSymbol = isSymbol;
4398 function isUndefined(arg) {
4399 return arg === void 0;
4401 exports.isUndefined = isUndefined;
4403 function isRegExp(re) {
4404 return isObject(re) && objectToString(re) === '[object RegExp]';
4406 exports.isRegExp = isRegExp;
4408 function isObject(arg) {
4409 return typeof arg === 'object' && arg !== null;
4411 exports.isObject = isObject;
4413 function isDate(d) {
4414 return isObject(d) && objectToString(d) === '[object Date]';
4416 exports.isDate = isDate;
4418 function isError(e) {
4419 return isObject(e) &&
4420 (objectToString(e) === '[object Error]' || e instanceof Error);
4422 exports.isError = isError;
4424 function isFunction(arg) {
4425 return typeof arg === 'function';
4427 exports.isFunction = isFunction;
4429 function isPrimitive(arg) {
4430 return arg === null ||
4431 typeof arg === 'boolean' ||
4432 typeof arg === 'number' ||
4433 typeof arg === 'string' ||
4434 typeof arg === 'symbol' || // ES6 symbol
4435 typeof arg === 'undefined';
4437 exports.isPrimitive = isPrimitive;
4439 exports.isBuffer = require('./support/isBuffer');
4441 function objectToString(o) {
4442 return Object.prototype.toString.call(o);
4447 return n < 10 ? '0' + n.toString(10) : n.toString(10);
4451 var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
4452 'Oct', 'Nov', 'Dec'];
4455 function timestamp() {
4457 var time = [pad(d.getHours()),
4458 pad(d.getMinutes()),
4459 pad(d.getSeconds())].join(':');
4460 return [d.getDate(), months[d.getMonth()], time].join(' ');
4464 // log is just a thin wrapper to console.log that prepends a timestamp
4465 exports.log = function() {
4466 console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments));
4471 * Inherit the prototype methods from one constructor into another.
4473 * The Function.prototype.inherits from lang.js rewritten as a standalone
4474 * function (not on Function.prototype). NOTE: If this file is to be loaded
4475 * during bootstrapping this function needs to be rewritten using some native
4476 * functions as prototype setup using normal JavaScript does not work as
4477 * expected during bootstrapping (see mirror.js in r114903).
4479 * @param {function} ctor Constructor function which needs to inherit the
4481 * @param {function} superCtor Constructor function to inherit prototype from.
4483 exports.inherits = require('inherits');
4485 exports._extend = function(origin, add) {
4486 // Don't do anything if add isn't an object
4487 if (!add || !isObject(add)) return origin;
4489 var keys = Object.keys(add);
4490 var i = keys.length;
4492 origin[keys[i]] = add[keys[i]];
4497 function hasOwnProperty(obj, prop) {
4498 return Object.prototype.hasOwnProperty.call(obj, prop);
4501 }).call(this,require("/Users/stephen/.nvm/v0.10.24/lib/node_modules/testling/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
4502 },{"./support/isBuffer":16,"/Users/stephen/.nvm/v0.10.24/lib/node_modules/testling/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js":6,"inherits":5}],18:[function(require,module,exports){
4503 module.exports = isFunction
4505 var toString = Object.prototype.toString
4507 function isFunction (fn) {
4508 var string = toString.call(fn)
4509 return string === '[object Function]' ||
4510 (typeof fn === 'function' && string !== '[object RegExp]') ||
4511 (typeof window !== 'undefined' &&
4513 (fn === window.setTimeout ||
4514 fn === window.alert ||
4515 fn === window.confirm ||
4516 fn === window.prompt))
4519 },{}],19:[function(require,module,exports){
4520 (function (process){
4521 var defined = require('defined');
4522 var createDefaultStream = require('./lib/default_stream');
4523 var Test = require('./lib/test');
4524 var createResult = require('./lib/results');
4526 var canEmitExit = typeof process !== 'undefined' && process
4527 && typeof process.on === 'function'
4529 var canExit = typeof process !== 'undefined' && process
4530 && typeof process.exit === 'function'
4533 var nextTick = typeof setImmediate !== 'undefined'
4538 exports = module.exports = (function () {
4540 var lazyLoad = function () {
4541 if (!harness) harness = createExitHarness({
4542 autoclose: !canEmitExit
4545 return harness.apply(this, arguments);
4548 lazyLoad.only = function () {
4549 if (!harness) harness = createExitHarness({
4550 autoclose: !canEmitExit
4553 return harness.only.apply(this, arguments);
4559 function createExitHarness (conf) {
4560 if (!conf) conf = {};
4561 var harness = createHarness({
4562 autoclose: defined(conf.autoclose, false)
4565 var stream = harness.createStream();
4566 var es = stream.pipe(createDefaultStream());
4568 es.on('error', function (err) { harness._exitCode = 1 });
4572 stream.on('end', function () { ended = true });
4574 if (conf.exit === false) return harness;
4575 if (!canEmitExit || !canExit) return harness;
4579 process.on('uncaughtException', function (err) {
4580 if (err && err.code === 'EPIPE' && err.errno === 'EPIPE'
4581 && err.syscall === 'write') return;
4588 process.on('exit', function (code) {
4594 for (var i = 0; i < harness._tests.length; i++) {
4595 var t = harness._tests[i];
4600 process.exit(code || harness._exitCode);
4606 exports.createHarness = createHarness;
4607 exports.Test = Test;
4608 exports.test = exports; // tap compat
4612 function createHarness (conf_) {
4613 if (!conf_) conf_ = {};
4614 var results = createResult();
4615 if (conf_.autoclose !== false) {
4616 results.once('done', function () { results.close() });
4619 var test = function (name, conf, cb) {
4620 var t = new Test(name, conf, cb);
4621 test._tests.push(t);
4623 (function inspectCode (st) {
4624 st.on('test', function sub (st_) {
4627 st.on('result', function (r) {
4628 if (!r.ok) test._exitCode = 1
4638 test.createStream = function () {
4639 return results.createStream();
4643 test.only = function (name) {
4644 if (only) throw new Error('there can only be one only test');
4647 return test.apply(null, arguments);
4651 test.close = function () { results.close() };
4656 }).call(this,require("/Users/stephen/.nvm/v0.10.24/lib/node_modules/testling/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js"))
4657 },{"./lib/default_stream":20,"./lib/results":21,"./lib/test":22,"/Users/stephen/.nvm/v0.10.24/lib/node_modules/testling/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js":6,"defined":26}],20:[function(require,module,exports){
4658 var through = require('through');
4660 module.exports = function () {
4662 var stream = through(write, flush);
4665 function write (buf) {
4666 for (var i = 0; i < buf.length; i++) {
4667 var c = typeof buf === 'string'
4669 : String.fromCharCode(buf[i])
4671 if (c === '\n') flush();
4677 try { console.log(line); }
4678 catch (e) { stream.emit('error', e) }
4683 },{"through":32}],21:[function(require,module,exports){
4684 (function (process){
4685 var Stream = require('stream');
4686 var EventEmitter = require('events').EventEmitter;
4687 var inherits = require('inherits');
4688 var json = typeof JSON === 'object' ? JSON : require('jsonify');
4689 var through = require('through');
4690 var resumer = require('resumer');
4691 var nextTick = typeof setImmediate !== 'undefined'
4696 module.exports = Results;
4697 inherits(Results, EventEmitter);
4699 function Results () {
4700 if (!(this instanceof Results)) return new Results;
4704 this._stream = through();
4708 Results.prototype.createStream = function () {
4710 var output = resumer();
4711 output.queue('TAP version 13\n');
4713 nextTick(function () {
4714 var t = getNextTest(self);
4716 else self.emit('done')
4718 self._stream.pipe(output);
4723 Results.prototype.push = function (t) {
4727 t.once('end', function () {
4728 var nt = getNextTest(self);
4730 else self.emit('done')
4734 Results.prototype.only = function (name) {
4738 write('not ok ' + self.count + ' already called .only()\n');
4743 Results.prototype._watch = function (t) {
4745 var write = function (s) { self._stream.queue(s) };
4746 t.once('prerun', function () {
4747 write('# ' + t.name + '\n');
4750 t.on('result', function (res) {
4751 if (typeof res === 'string') {
4752 write('# ' + res + '\n');
4755 write(encodeResult(res, self.count + 1));
4758 if (res.ok) self.pass ++
4762 t.on('test', function (st) { self._watch(st) });
4765 Results.prototype.close = function () {
4767 if (self.closed) self._stream.emit('error', new Error('ALREADY CLOSED'));
4769 var write = function (s) { self._stream.queue(s) };
4771 write('\n1..' + self.count + '\n');
4772 write('# tests ' + self.count + '\n');
4773 write('# pass ' + self.pass + '\n');
4774 if (self.fail) write('# fail ' + self.fail + '\n')
4775 else write('\n# ok\n')
4777 self._stream.queue(null);
4780 function encodeResult (res, count) {
4782 output += (res.ok ? 'ok ' : 'not ok ') + count;
4783 output += res.name ? ' ' + res.name.toString().replace(/\s+/g, ' ') : '';
4785 if (res.skip) output += ' # SKIP';
4786 else if (res.todo) output += ' # TODO';
4789 if (res.ok) return output;
4792 var inner = outer + ' ';
4793 output += outer + '---\n';
4794 output += inner + 'operator: ' + res.operator + '\n';
4796 var ex = json.stringify(res.expected, getSerialize()) || '';
4797 var ac = json.stringify(res.actual, getSerialize()) || '';
4799 if (Math.max(ex.length, ac.length) > 65) {
4800 output += inner + 'expected:\n' + inner + ' ' + ex + '\n';
4801 output += inner + 'actual:\n' + inner + ' ' + ac + '\n';
4804 output += inner + 'expected: ' + ex + '\n';
4805 output += inner + 'actual: ' + ac + '\n';
4808 output += inner + 'at: ' + res.at + '\n';
4810 if (res.operator === 'error' && res.actual && res.actual.stack) {
4811 var lines = String(res.actual.stack).split('\n');
4812 output += inner + 'stack:\n';
4813 output += inner + ' ' + lines[0] + '\n';
4814 for (var i = 1; i < lines.length; i++) {
4815 output += inner + lines[i] + '\n';
4819 output += outer + '...\n';
4823 function getSerialize () {
4826 return function (key, value) {
4828 if (typeof value === 'object' && value) {
4830 for (var i = 0; i < seen.length; i++) {
4831 if (seen[i] === value) {
4837 if (found) ret = '[Circular]'
4838 else seen.push(value)
4844 function getNextTest(results) {
4845 if (!results._only) {
4846 return results.tests.shift();
4850 var t = results.tests.shift();
4854 if (results._only === t.name) {
4857 } while (results.tests.length !== 0)
4860 }).call(this,require("/Users/stephen/.nvm/v0.10.24/lib/node_modules/testling/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js"))
4861 },{"/Users/stephen/.nvm/v0.10.24/lib/node_modules/testling/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js":6,"events":4,"inherits":27,"jsonify":28,"resumer":31,"stream":9,"through":32}],22:[function(require,module,exports){
4862 (function (process,__dirname){
4863 var Stream = require('stream');
4864 var deepEqual = require('deep-equal');
4865 var defined = require('defined');
4866 var path = require('path');
4867 var inherits = require('util').inherits;
4868 var EventEmitter = require('events').EventEmitter;
4870 module.exports = Test;
4872 var nextTick = typeof setImmediate !== 'undefined'
4877 inherits(Test, EventEmitter);
4879 function Test (name_, opts_, cb_) {
4881 var name = '(anonymous)';
4885 for (var i = 0; i < arguments.length; i++) {
4886 switch (typeof arguments[i]) {
4888 name = arguments[i];
4891 opts = arguments[i] || opts;
4898 this.readable = true;
4899 this.name = name || '(anonymous)';
4900 this.assertCount = 0;
4901 this.pendingCount = 0;
4902 this._skip = opts.skip || false;
4903 this._plan = undefined;
4909 Test.prototype.run = function () {
4913 this.emit('prerun');
4925 Test.prototype.test = function (name, opts, cb) {
4927 var t = new Test(name, opts, cb);
4928 this._progeny.push(t);
4929 this.pendingCount++;
4930 this.emit('test', t);
4931 t.on('prerun', function () {
4935 if (!self._pendingAsserts()) {
4936 nextTick(function () {
4941 nextTick(function() {
4942 if (!self._plan && self.pendingCount == self._progeny.length) {
4948 Test.prototype.comment = function (msg) {
4949 this.emit('result', msg.trim().replace(/^#\s*/, ''));
4952 Test.prototype.plan = function (n) {
4954 this.emit('plan', n);
4957 Test.prototype.end = function () {
4960 if (this._progeny.length) {
4961 var t = this._progeny.shift();
4962 t.on('end', function () {
4969 if (!this.ended) this.emit('end');
4970 var pendingAsserts = this._pendingAsserts();
4971 if (!this._planError && this._plan !== undefined && pendingAsserts) {
4972 this._planError = true;
4973 this.fail('plan != count', {
4974 expected : this._plan,
4975 actual : this.assertCount
4981 Test.prototype._exit = function () {
4982 if (this._plan !== undefined &&
4983 !this._planError && this.assertCount !== this._plan) {
4984 this._planError = true;
4985 this.fail('plan != count', {
4986 expected : this._plan,
4987 actual : this.assertCount,
4991 else if (!this.ended) {
4992 this.fail('test exited without ending', {
4998 Test.prototype._pendingAsserts = function () {
4999 if (this._plan === undefined) {
5003 (this._progeny.length + this.assertCount);
5007 Test.prototype._assert = function assert (ok, opts) {
5009 var extra = opts.extra || {};
5012 id : self.assertCount ++,
5014 skip : defined(extra.skip, opts.skip),
5015 name : defined(extra.message, opts.message, '(unnamed assert)'),
5016 operator : defined(extra.operator, opts.operator),
5017 actual : defined(extra.actual, opts.actual),
5018 expected : defined(extra.expected, opts.expected)
5020 this._ok = Boolean(this._ok && ok);
5023 res.error = defined(extra.error, opts.error, new Error(res.name));
5026 var e = new Error('exception');
5027 var err = (e.stack || '').split('\n');
5028 var dir = path.dirname(__dirname) + '/';
5030 for (var i = 0; i < err.length; i++) {
5031 var m = /^\s*\bat\s+(.+)/.exec(err[i]);
5034 var s = m[1].split(/\s+/);
5035 var filem = /(\/[^:\s]+:(\d+)(?::(\d+))?)/.exec(s[1]);
5037 filem = /(\/[^:\s]+:(\d+)(?::(\d+))?)/.exec(s[3]);
5039 if (!filem) continue;
5042 if (filem[1].slice(0, dir.length) === dir) continue;
5044 res.functionName = s[0];
5045 res.file = filem[1];
5046 res.line = Number(filem[2]);
5047 if (filem[3]) res.column = filem[3];
5053 self.emit('result', res);
5055 var pendingAsserts = self._pendingAsserts();
5056 if (!pendingAsserts) {
5057 if (extra.exiting) {
5060 nextTick(function () {
5066 if (!self._planError && pendingAsserts < 0) {
5067 self._planError = true;
5068 self.fail('plan != count', {
5069 expected : self._plan,
5070 actual : self._plan - pendingAsserts
5075 Test.prototype.fail = function (msg, extra) {
5076 this._assert(false, {
5083 Test.prototype.pass = function (msg, extra) {
5084 this._assert(true, {
5091 Test.prototype.skip = function (msg, extra) {
5092 this._assert(true, {
5101 = Test.prototype['true']
5102 = Test.prototype.assert
5103 = function (value, msg, extra) {
5104 this._assert(value, {
5113 Test.prototype.notOk
5114 = Test.prototype['false']
5115 = Test.prototype.notok
5116 = function (value, msg, extra) {
5117 this._assert(!value, {
5126 Test.prototype.error
5127 = Test.prototype.ifError
5128 = Test.prototype.ifErr
5129 = Test.prototype.iferror
5130 = function (err, msg, extra) {
5131 this._assert(!err, {
5132 message : defined(msg, String(err)),
5139 Test.prototype.equal
5140 = Test.prototype.equals
5141 = Test.prototype.isEqual
5143 = Test.prototype.strictEqual
5144 = Test.prototype.strictEquals
5145 = function (a, b, msg, extra) {
5146 this._assert(a === b, {
5147 message : defined(msg, 'should be equal'),
5155 Test.prototype.notEqual
5156 = Test.prototype.notEquals
5157 = Test.prototype.notStrictEqual
5158 = Test.prototype.notStrictEquals
5159 = Test.prototype.isNotEqual
5160 = Test.prototype.isNot
5161 = Test.prototype.not
5162 = Test.prototype.doesNotEqual
5163 = Test.prototype.isInequal
5164 = function (a, b, msg, extra) {
5165 this._assert(a !== b, {
5166 message : defined(msg, 'should not be equal'),
5167 operator : 'notEqual',
5174 Test.prototype.deepEqual
5175 = Test.prototype.deepEquals
5176 = Test.prototype.isEquivalent
5177 = Test.prototype.same
5178 = function (a, b, msg, extra) {
5179 this._assert(deepEqual(a, b, { strict: true }), {
5180 message : defined(msg, 'should be equivalent'),
5181 operator : 'deepEqual',
5188 Test.prototype.deepLooseEqual
5189 = Test.prototype.looseEqual
5190 = Test.prototype.looseEquals
5191 = function (a, b, msg, extra) {
5192 this._assert(deepEqual(a, b), {
5193 message : defined(msg, 'should be equivalent'),
5194 operator : 'deepLooseEqual',
5201 Test.prototype.notDeepEqual
5202 = Test.prototype.notEquivalent
5203 = Test.prototype.notDeeply
5204 = Test.prototype.notSame
5205 = Test.prototype.isNotDeepEqual
5206 = Test.prototype.isNotDeeply
5207 = Test.prototype.isNotEquivalent
5208 = Test.prototype.isInequivalent
5209 = function (a, b, msg, extra) {
5210 this._assert(!deepEqual(a, b, { strict: true }), {
5211 message : defined(msg, 'should not be equivalent'),
5212 operator : 'notDeepEqual',
5219 Test.prototype.notDeepLooseEqual
5220 = Test.prototype.notLooseEqual
5221 = Test.prototype.notLooseEquals
5222 = function (a, b, msg, extra) {
5223 this._assert(deepEqual(a, b), {
5224 message : defined(msg, 'should be equivalent'),
5225 operator : 'notDeepLooseEqual',
5232 Test.prototype['throws'] = function (fn, expected, msg, extra) {
5233 if (typeof expected === 'string') {
5235 expected = undefined;
5237 var caught = undefined;
5242 caught = { error : err };
5243 var message = err.message;
5245 err.message = message;
5248 var passed = caught;
5250 if (expected instanceof RegExp) {
5251 passed = expected.test(caught && caught.error);
5252 expected = String(expected);
5255 this._assert(passed, {
5256 message : defined(msg, 'should throw'),
5257 operator : 'throws',
5258 actual : caught && caught.error,
5259 expected : expected,
5260 error: !passed && caught && caught.error,
5265 Test.prototype.doesNotThrow = function (fn, expected, msg, extra) {
5266 if (typeof expected === 'string') {
5268 expected = undefined;
5270 var caught = undefined;
5275 caught = { error : err };
5277 this._assert(!caught, {
5278 message : defined(msg, 'should throw'),
5279 operator : 'throws',
5280 actual : caught && caught.error,
5281 expected : expected,
5282 error : caught && caught.error,
5287 // vim: set softtabstop=4 shiftwidth=4:
5289 }).call(this,require("/Users/stephen/.nvm/v0.10.24/lib/node_modules/testling/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js"),"/node_modules/tape/lib")
5290 },{"/Users/stephen/.nvm/v0.10.24/lib/node_modules/testling/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js":6,"deep-equal":23,"defined":26,"events":4,"path":7,"stream":9,"util":17}],23:[function(require,module,exports){
5291 var pSlice = Array.prototype.slice;
5292 var objectKeys = require('./lib/keys.js');
5293 var isArguments = require('./lib/is_arguments.js');
5295 var deepEqual = module.exports = function (actual, expected, opts) {
5296 if (!opts) opts = {};
5297 // 7.1. All identical values are equivalent, as determined by ===.
5298 if (actual === expected) {
5301 } else if (actual instanceof Date && expected instanceof Date) {
5302 return actual.getTime() === expected.getTime();
5304 // 7.3. Other pairs that do not both pass typeof value == 'object',
5305 // equivalence is determined by ==.
5306 } else if (typeof actual != 'object' && typeof expected != 'object') {
5307 return opts.strict ? actual === expected : actual == expected;
5309 // 7.4. For all other Object pairs, including Array objects, equivalence is
5310 // determined by having the same number of owned properties (as verified
5311 // with Object.prototype.hasOwnProperty.call), the same set of keys
5312 // (although not necessarily the same order), equivalent values for every
5313 // corresponding key, and an identical 'prototype' property. Note: this
5314 // accounts for both named and indexed properties on Arrays.
5316 return objEquiv(actual, expected, opts);
5320 function isUndefinedOrNull(value) {
5321 return value === null || value === undefined;
5324 function objEquiv(a, b, opts) {
5325 if (isUndefinedOrNull(a) || isUndefinedOrNull(b))
5327 // an identical 'prototype' property.
5328 if (a.prototype !== b.prototype) return false;
5329 //~~~I've managed to break Object.keys through screwy arguments passing.
5330 // Converting to array solves the problem.
5331 if (isArguments(a)) {
5332 if (!isArguments(b)) {
5337 return deepEqual(a, b, opts);
5340 var ka = objectKeys(a),
5343 } catch (e) {//happens when one is a string literal and the other isn't
5346 // having the same number of owned properties (keys incorporates
5348 if (ka.length != kb.length)
5350 //the same set of keys (although not necessarily the same order),
5354 for (i = ka.length - 1; i >= 0; i--) {
5358 //equivalent values for every corresponding key, and
5359 //~~~possibly expensive deep test
5360 for (i = ka.length - 1; i >= 0; i--) {
5362 if (!deepEqual(a[key], b[key], opts)) return false;
5367 },{"./lib/is_arguments.js":24,"./lib/keys.js":25}],24:[function(require,module,exports){
5368 var supportsArgumentsClass = (function(){
5369 return Object.prototype.toString.call(arguments)
5370 })() == '[object Arguments]';
5372 exports = module.exports = supportsArgumentsClass ? supported : unsupported;
5374 exports.supported = supported;
5375 function supported(object) {
5376 return Object.prototype.toString.call(object) == '[object Arguments]';
5379 exports.unsupported = unsupported;
5380 function unsupported(object){
5382 typeof object == 'object' &&
5383 typeof object.length == 'number' &&
5384 Object.prototype.hasOwnProperty.call(object, 'callee') &&
5385 !Object.prototype.propertyIsEnumerable.call(object, 'callee') ||
5389 },{}],25:[function(require,module,exports){
5390 exports = module.exports = typeof Object.keys === 'function'
5391 ? Object.keys : shim;
5393 exports.shim = shim;
5394 function shim (obj) {
5396 for (var key in obj) keys.push(key);
5400 },{}],26:[function(require,module,exports){
5401 module.exports = function () {
5402 for (var i = 0; i < arguments.length; i++) {
5403 if (arguments[i] !== undefined) return arguments[i];
5407 },{}],27:[function(require,module,exports){
5408 module.exports=require(5)
5409 },{}],28:[function(require,module,exports){
5410 exports.parse = require('./lib/parse');
5411 exports.stringify = require('./lib/stringify');
5413 },{"./lib/parse":29,"./lib/stringify":30}],29:[function(require,module,exports){
5414 var at, // The index of the current character
5415 ch, // The current character
5428 error = function (m) {
5429 // Call error when something is wrong.
5431 name: 'SyntaxError',
5438 next = function (c) {
5439 // If a c parameter is provided, verify that it matches the current character.
5440 if (c && c !== ch) {
5441 error("Expected '" + c + "' instead of '" + ch + "'");
5444 // Get the next character. When there are no more characters,
5445 // return the empty string.
5447 ch = text.charAt(at);
5452 number = function () {
5453 // Parse a number value.
5461 while (ch >= '0' && ch <= '9') {
5467 while (next() && ch >= '0' && ch <= '9') {
5471 if (ch === 'e' || ch === 'E') {
5474 if (ch === '-' || ch === '+') {
5478 while (ch >= '0' && ch <= '9') {
5484 if (!isFinite(number)) {
5485 error("Bad number");
5491 string = function () {
5492 // Parse a string value.
5498 // When parsing for string values, we must look for " and \ characters.
5504 } else if (ch === '\\') {
5508 for (i = 0; i < 4; i += 1) {
5509 hex = parseInt(next(), 16);
5510 if (!isFinite(hex)) {
5513 uffff = uffff * 16 + hex;
5515 string += String.fromCharCode(uffff);
5516 } else if (typeof escapee[ch] === 'string') {
5517 string += escapee[ch];
5526 error("Bad string");
5529 white = function () {
5533 while (ch && ch <= ' ') {
5538 word = function () {
5540 // true, false, or null.
5563 error("Unexpected '" + ch + "'");
5566 value, // Place holder for the value function.
5568 array = function () {
5570 // Parse an array value.
5579 return array; // empty array
5582 array.push(value());
5595 object = function () {
5597 // Parse an object value.
5607 return object; // empty object
5613 if (Object.hasOwnProperty.call(object, key)) {
5614 error('Duplicate key "' + key + '"');
5616 object[key] = value();
5626 error("Bad object");
5629 value = function () {
5631 // Parse a JSON value. It could be an object, an array, a string, a number,
5645 return ch >= '0' && ch <= '9' ? number() : word();
5649 // Return the json_parse function. It will have access to all of the above
5650 // functions and variables.
5652 module.exports = function (source, reviver) {
5661 error("Syntax error");
5664 // If there is a reviver function, we recursively walk the new structure,
5665 // passing each name/value pair to the reviver function for possible
5666 // transformation, starting with a temporary root object that holds the result
5667 // in an empty key. If there is not a reviver function, we simply return the
5670 return typeof reviver === 'function' ? (function walk(holder, key) {
5671 var k, v, value = holder[key];
5672 if (value && typeof value === 'object') {
5674 if (Object.prototype.hasOwnProperty.call(value, k)) {
5676 if (v !== undefined) {
5684 return reviver.call(holder, key, value);
5685 }({'': result}, '')) : result;
5688 },{}],30:[function(require,module,exports){
5689 var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
5690 escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
5693 meta = { // table of character substitutions
5704 function quote(string) {
5705 // If the string contains no control characters, no quote characters, and no
5706 // backslash characters, then we can safely slap some quotes around it.
5707 // Otherwise we must also replace the offending characters with safe escape
5710 escapable.lastIndex = 0;
5711 return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
5713 return typeof c === 'string' ? c :
5714 '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
5715 }) + '"' : '"' + string + '"';
5718 function str(key, holder) {
5719 // Produce a string from holder[key].
5720 var i, // The loop counter.
5721 k, // The member key.
5722 v, // The member value.
5726 value = holder[key];
5728 // If the value has a toJSON method, call it to obtain a replacement value.
5729 if (value && typeof value === 'object' &&
5730 typeof value.toJSON === 'function') {
5731 value = value.toJSON(key);
5734 // If we were called with a replacer function, then call the replacer to
5735 // obtain a replacement value.
5736 if (typeof rep === 'function') {
5737 value = rep.call(holder, key, value);
5740 // What happens next depends on the value's type.
5741 switch (typeof value) {
5743 return quote(value);
5746 // JSON numbers must be finite. Encode non-finite numbers as null.
5747 return isFinite(value) ? String(value) : 'null';
5751 // If the value is a boolean or null, convert it to a string. Note:
5752 // typeof null does not produce 'null'. The case is included here in
5753 // the remote chance that this gets fixed someday.
5754 return String(value);
5757 if (!value) return 'null';
5762 if (Object.prototype.toString.apply(value) === '[object Array]') {
5763 length = value.length;
5764 for (i = 0; i < length; i += 1) {
5765 partial[i] = str(i, value) || 'null';
5768 // Join all of the elements together, separated with commas, and
5769 // wrap them in brackets.
5770 v = partial.length === 0 ? '[]' : gap ?
5771 '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' :
5772 '[' + partial.join(',') + ']';
5777 // If the replacer is an array, use it to select the members to be
5779 if (rep && typeof rep === 'object') {
5780 length = rep.length;
5781 for (i = 0; i < length; i += 1) {
5783 if (typeof k === 'string') {
5786 partial.push(quote(k) + (gap ? ': ' : ':') + v);
5792 // Otherwise, iterate through all of the keys in the object.
5794 if (Object.prototype.hasOwnProperty.call(value, k)) {
5797 partial.push(quote(k) + (gap ? ': ' : ':') + v);
5803 // Join all of the member texts together, separated with commas,
5804 // and wrap them in braces.
5806 v = partial.length === 0 ? '{}' : gap ?
5807 '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' :
5808 '{' + partial.join(',') + '}';
5814 module.exports = function (value, replacer, space) {
5819 // If the space parameter is a number, make an indent string containing that
5821 if (typeof space === 'number') {
5822 for (i = 0; i < space; i += 1) {
5826 // If the space parameter is a string, it will be used as the indent string.
5827 else if (typeof space === 'string') {
5831 // If there is a replacer, it must be a function or an array.
5832 // Otherwise, throw an error.
5834 if (replacer && typeof replacer !== 'function'
5835 && (typeof replacer !== 'object' || typeof replacer.length !== 'number')) {
5836 throw new Error('JSON.stringify');
5839 // Make a fake root object containing our value under the key of ''.
5840 // Return the result of stringifying the value.
5841 return str('', {'': value});
5844 },{}],31:[function(require,module,exports){
5845 (function (process){
5846 var through = require('through');
5847 var nextTick = typeof setImmediate !== 'undefined'
5852 module.exports = function (write, end) {
5853 var tr = through(write, end);
5855 var resume = tr.resume;
5856 var pause = tr.pause;
5859 tr.pause = function () {
5861 return pause.apply(this, arguments);
5864 tr.resume = function () {
5866 return resume.apply(this, arguments);
5869 nextTick(function () {
5870 if (!paused) tr.resume();
5876 }).call(this,require("/Users/stephen/.nvm/v0.10.24/lib/node_modules/testling/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js"))
5877 },{"/Users/stephen/.nvm/v0.10.24/lib/node_modules/testling/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js":6,"through":32}],32:[function(require,module,exports){
5878 (function (process){
5879 var Stream = require('stream')
5883 // a stream that does nothing but re-emit the input.
5884 // useful for aggregating a series of changing but not ending streams into one stream)
5886 exports = module.exports = through
5887 through.through = through
5889 //create a readable writable stream.
5891 function through (write, end, opts) {
5892 write = write || function (data) { this.queue(data) }
5893 end = end || function () { this.queue(null) }
5895 var ended = false, destroyed = false, buffer = [], _ended = false
5896 var stream = new Stream()
5897 stream.readable = stream.writable = true
5898 stream.paused = false
5900 // stream.autoPause = !(opts && opts.autoPause === false)
5901 stream.autoDestroy = !(opts && opts.autoDestroy === false)
5903 stream.write = function (data) {
5904 write.call(this, data)
5905 return !stream.paused
5909 while(buffer.length && !stream.paused) {
5910 var data = buffer.shift()
5912 return stream.emit('end')
5914 stream.emit('data', data)
5918 stream.queue = stream.push = function (data) {
5919 // console.error(ended)
5920 if(_ended) return stream
5921 if(data == null) _ended = true
5927 //this will be registered as the first 'end' listener
5928 //must call destroy next tick, to make sure we're after any
5929 //stream piped from here.
5930 //this is only a problem if end is not emitted synchronously.
5931 //a nicer way to do this is to make sure this is the last listener for 'end'
5933 stream.on('end', function () {
5934 stream.readable = false
5935 if(!stream.writable && stream.autoDestroy)
5936 process.nextTick(function () {
5942 stream.writable = false
5944 if(!stream.readable && stream.autoDestroy)
5948 stream.end = function (data) {
5951 if(arguments.length) stream.write(data)
5952 _end() // will emit or queue
5956 stream.destroy = function () {
5957 if(destroyed) return
5961 stream.writable = stream.readable = false
5962 stream.emit('close')
5966 stream.pause = function () {
5967 if(stream.paused) return
5968 stream.paused = true
5972 stream.resume = function () {
5974 stream.paused = false
5975 stream.emit('resume')
5978 //may have become paused again,
5979 //as drain emits 'data'.
5981 stream.emit('drain')
5988 }).call(this,require("/Users/stephen/.nvm/v0.10.24/lib/node_modules/testling/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js"))
5989 },{"/Users/stephen/.nvm/v0.10.24/lib/node_modules/testling/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js":6,"stream":9}],33:[function(require,module,exports){
5990 var test = require('tape')
5991 var isFunction = require('./index.js')
5993 test('isFunction', function (t) {
5994 t.ok(!isFunction(), 'undefined is not a function')
5995 t.ok(!isFunction(null), 'null is not a function')
5996 t.ok(!isFunction(''), 'string is not a function')
5997 t.ok(!isFunction(/a/), 'regex is not a function')
5998 t.ok(!isFunction(true), 'true is not a function')
5999 t.ok(!isFunction(false), 'false is not a function')
6000 t.ok(!isFunction(NaN), 'NaN is not a function')
6001 t.ok(!isFunction(42), '42 is not a function')
6002 t.ok(isFunction(function () {}), 'function is a function')
6003 t.ok(isFunction(setTimeout), 'setTimeout is a function')
6007 if (typeof window !== 'undefined') {
6008 test('browser quirks', function (t) {
6011 t.ok(isFunction(window.alert), 'alert is a function')
6013 window.testRegExpFromIframe = function (regexp) {
6014 t.ok(!isFunction(regexp))
6017 var iframe = document.createElement('iframe')
6018 document.body.appendChild(iframe)
6020 iframe.contentWindow.document.write([
6021 "<html><body><script type=\"text/javascript\">",
6022 "parent.testRegExpFromIframe(/a/)",
6023 "</script></body></html>"
6028 },{"./index.js":18,"tape":19}]},{},[33])