UNPKG

171 kBJavaScriptView Raw
1(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
2(function (global){
3!function(e){if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else{var t;"undefined"!=typeof window?t=window:"undefined"!=typeof global?t=global:"undefined"!=typeof self&&(t=self),t.objectHash=e()}}(function(){return function o(i,u,a){function f(n,e){if(!u[n]){if(!i[n]){var t="function"==typeof require&&require;if(!e&&t)return t(n,!0);if(s)return s(n,!0);throw new Error("Cannot find module '"+n+"'")}var r=u[n]={exports:{}};i[n][0].call(r.exports,function(e){var t=i[n][1][e];return f(t||e)},r,r.exports,o,i,u,a)}return u[n].exports}for(var s="function"==typeof require&&require,e=0;e<a.length;e++)f(a[e]);return f}({1:[function(w,b,m){(function(e,t,s,n,r,o,i,u,a){"use strict";var f=w("crypto");function c(e,t){return function(e,t){var n;n="passthrough"!==t.algorithm?f.createHash(t.algorithm):new y;void 0===n.write&&(n.write=n.update,n.end=n.update);g(t,n).dispatch(e),n.update||n.end("");if(n.digest)return n.digest("buffer"===t.encoding?void 0:t.encoding);var r=n.read();return"buffer"!==t.encoding?r.toString(t.encoding):r}(e,t=h(e,t))}(m=b.exports=c).sha1=function(e){return c(e)},m.keys=function(e){return c(e,{excludeValues:!0,algorithm:"sha1",encoding:"hex"})},m.MD5=function(e){return c(e,{algorithm:"md5",encoding:"hex"})},m.keysMD5=function(e){return c(e,{algorithm:"md5",encoding:"hex",excludeValues:!0})};var l=f.getHashes?f.getHashes().slice():["sha1","md5"];l.push("passthrough");var d=["buffer","hex","binary","base64"];function h(e,t){t=t||{};var n={};if(n.algorithm=t.algorithm||"sha1",n.encoding=t.encoding||"hex",n.excludeValues=!!t.excludeValues,n.algorithm=n.algorithm.toLowerCase(),n.encoding=n.encoding.toLowerCase(),n.ignoreUnknown=!0===t.ignoreUnknown,n.respectType=!1!==t.respectType,n.respectFunctionNames=!1!==t.respectFunctionNames,n.respectFunctionProperties=!1!==t.respectFunctionProperties,n.unorderedArrays=!0===t.unorderedArrays,n.unorderedSets=!1!==t.unorderedSets,n.unorderedObjects=!1!==t.unorderedObjects,n.replacer=t.replacer||void 0,n.excludeKeys=t.excludeKeys||void 0,void 0===e)throw new Error("Object argument required.");for(var r=0;r<l.length;++r)l[r].toLowerCase()===n.algorithm.toLowerCase()&&(n.algorithm=l[r]);if(-1===l.indexOf(n.algorithm))throw new Error('Algorithm "'+n.algorithm+'" not supported. supported values: '+l.join(", "));if(-1===d.indexOf(n.encoding)&&"passthrough"!==n.algorithm)throw new Error('Encoding "'+n.encoding+'" not supported. supported values: '+d.join(", "));return n}function p(e){if("function"!=typeof e)return!1;return null!=/^function\s+\w*\s*\(\s*\)\s*{\s+\[native code\]\s+}$/i.exec(Function.prototype.toString.call(e))}function g(u,t,a){a=a||[];function f(e){return t.update?t.update(e,"utf8"):t.write(e,"utf8")}return{dispatch:function(e){u.replacer&&(e=u.replacer(e));var t=typeof e;return null===e&&(t="null"),this["_"+t](e)},_object:function(t){var e=Object.prototype.toString.call(t),n=/\[object (.*)\]/i.exec(e);n=(n=n?n[1]:"unknown:["+e+"]").toLowerCase();var r;if(0<=(r=a.indexOf(t)))return this.dispatch("[CIRCULAR:"+r+"]");if(a.push(t),void 0!==s&&s.isBuffer&&s.isBuffer(t))return f("buffer:"),f(t);if("object"===n||"function"===n||"asyncfunction"===n){var o=Object.keys(t);u.unorderedObjects&&(o=o.sort()),!1===u.respectType||p(t)||o.splice(0,0,"prototype","__proto__","constructor"),u.excludeKeys&&(o=o.filter(function(e){return!u.excludeKeys(e)})),f("object:"+o.length+":");var i=this;return o.forEach(function(e){i.dispatch(e),f(":"),u.excludeValues||i.dispatch(t[e]),f(",")})}if(!this["_"+n]){if(u.ignoreUnknown)return f("["+n+"]");throw new Error('Unknown object type "'+n+'"')}this["_"+n](t)},_array:function(e,t){t=void 0!==t?t:!1!==u.unorderedArrays;var n=this;if(f("array:"+e.length+":"),!t||e.length<=1)return e.forEach(function(e){return n.dispatch(e)});var r=[],o=e.map(function(e){var t=new y,n=a.slice();return g(u,t,n).dispatch(e),r=r.concat(n.slice(a.length)),t.read().toString()});return a=a.concat(r),o.sort(),this._array(o,!1)},_date:function(e){return f("date:"+e.toJSON())},_symbol:function(e){return f("symbol:"+e.toString())},_error:function(e){return f("error:"+e.toString())},_boolean:function(e){return f("bool:"+e.toString())},_string:function(e){f("string:"+e.length+":"),f(e.toString())},_function:function(e){f("fn:"),p(e)?this.dispatch("[native]"):this.dispatch(e.toString()),!1!==u.respectFunctionNames&&this.dispatch("function-name:"+String(e.name)),u.respectFunctionProperties&&this._object(e)},_number:function(e){return f("number:"+e.toString())},_xml:function(e){return f("xml:"+e.toString())},_null:function(){return f("Null")},_undefined:function(){return f("Undefined")},_regexp:function(e){return f("regex:"+e.toString())},_uint8array:function(e){return f("uint8array:"),this.dispatch(Array.prototype.slice.call(e))},_uint8clampedarray:function(e){return f("uint8clampedarray:"),this.dispatch(Array.prototype.slice.call(e))},_int8array:function(e){return f("uint8array:"),this.dispatch(Array.prototype.slice.call(e))},_uint16array:function(e){return f("uint16array:"),this.dispatch(Array.prototype.slice.call(e))},_int16array:function(e){return f("uint16array:"),this.dispatch(Array.prototype.slice.call(e))},_uint32array:function(e){return f("uint32array:"),this.dispatch(Array.prototype.slice.call(e))},_int32array:function(e){return f("uint32array:"),this.dispatch(Array.prototype.slice.call(e))},_float32array:function(e){return f("float32array:"),this.dispatch(Array.prototype.slice.call(e))},_float64array:function(e){return f("float64array:"),this.dispatch(Array.prototype.slice.call(e))},_arraybuffer:function(e){return f("arraybuffer:"),this.dispatch(new Uint8Array(e))},_url:function(e){return f("url:"+e.toString())},_map:function(e){f("map:");var t=Array.from(e);return this._array(t,!1!==u.unorderedSets)},_set:function(e){f("set:");var t=Array.from(e);return this._array(t,!1!==u.unorderedSets)},_blob:function(){if(u.ignoreUnknown)return f("[blob]");throw Error('Hashing Blob objects is currently not supported\n(see https://github.com/puleos/object-hash/issues/26)\nUse "options.replacer" or "options.ignoreUnknown"\n')},_domwindow:function(){return f("domwindow")},_process:function(){return f("process")},_timer:function(){return f("timer")},_pipe:function(){return f("pipe")},_tcp:function(){return f("tcp")},_udp:function(){return f("udp")},_tty:function(){return f("tty")},_statwatcher:function(){return f("statwatcher")},_securecontext:function(){return f("securecontext")},_connection:function(){return f("connection")},_zlib:function(){return f("zlib")},_context:function(){return f("context")},_nodescript:function(){return f("nodescript")},_httpparser:function(){return f("httpparser")},_dataview:function(){return f("dataview")},_signal:function(){return f("signal")},_fsevent:function(){return f("fsevent")},_tlswrap:function(){return f("tlswrap")}}}function y(){return{buf:"",write:function(e){this.buf+=e},end:function(e){this.buf+=e},read:function(){return this.buf}}}m.writeToStream=function(e,t,n){return void 0===n&&(n=t,t={}),g(t=h(e,t),n).dispatch(e)}}).call(this,w("lYpoI2"),"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},w("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/fake_274613e1.js","/")},{buffer:3,crypto:5,lYpoI2:10}],2:[function(e,t,s){(function(e,t,n,r,o,i,u,a,f){!function(e){"use strict";var s="undefined"!=typeof Uint8Array?Uint8Array:Array,n="+".charCodeAt(0),r="/".charCodeAt(0),o="0".charCodeAt(0),i="a".charCodeAt(0),u="A".charCodeAt(0),a="-".charCodeAt(0),f="_".charCodeAt(0);function c(e){var t=e.charCodeAt(0);return t===n||t===a?62:t===r||t===f?63:t<o?-1:t<o+10?t-o+26+26:t<u+26?t-u:t<i+26?t-i+26:void 0}e.toByteArray=function(e){var t,n,r,o,i;if(0<e.length%4)throw new Error("Invalid string. Length must be a multiple of 4");var u=e.length;o="="===e.charAt(u-2)?2:"="===e.charAt(u-1)?1:0,i=new s(3*e.length/4-o),n=0<o?e.length-4:e.length;var a=0;function f(e){i[a++]=e}for(t=0;t<n;t+=4,3)f((16711680&(r=c(e.charAt(t))<<18|c(e.charAt(t+1))<<12|c(e.charAt(t+2))<<6|c(e.charAt(t+3))))>>16),f((65280&r)>>8),f(255&r);return 2==o?f(255&(r=c(e.charAt(t))<<2|c(e.charAt(t+1))>>4)):1==o&&(f((r=c(e.charAt(t))<<10|c(e.charAt(t+1))<<4|c(e.charAt(t+2))>>2)>>8&255),f(255&r)),i},e.fromByteArray=function(e){var t,n,r,o,i=e.length%3,u="";function a(e){return"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(e)}for(t=0,r=e.length-i;t<r;t+=3)n=(e[t]<<16)+(e[t+1]<<8)+e[t+2],u+=a((o=n)>>18&63)+a(o>>12&63)+a(o>>6&63)+a(63&o);switch(i){case 1:u+=a((n=e[e.length-1])>>2),u+=a(n<<4&63),u+="==";break;case 2:u+=a((n=(e[e.length-2]<<8)+e[e.length-1])>>10),u+=a(n>>4&63),u+=a(n<<2&63),u+="="}return u}}(void 0===s?this.base64js={}:s)}).call(this,e("lYpoI2"),"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},e("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/node_modules/gulp-browserify/node_modules/base64-js/lib/b64.js","/node_modules/gulp-browserify/node_modules/base64-js/lib")},{buffer:3,lYpoI2:10}],3:[function(D,e,O){(function(e,t,f,n,r,o,i,u,a){var s=D("base64-js"),c=D("ieee754");function f(e,t,n){if(!(this instanceof f))return new f(e,t,n);var r,o,i,u=typeof e;if("base64"===t&&"string"==u)for(e=function(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}(e);e.length%4!=0;)e+="=";if("number"==u)r=U(e);else if("string"==u)r=f.byteLength(e,t);else{if("object"!=u)throw new Error("First argument needs to be a number, array or string.");r=U(e.length)}if(f._useTypedArrays?o=f._augment(new Uint8Array(r)):((o=this).length=r,o._isBuffer=!0),f._useTypedArrays&&"number"==typeof e.byteLength)o._set(e);else if(function(e){return x(e)||f.isBuffer(e)||e&&"object"==typeof e&&"number"==typeof e.length}(e))for(i=0;i<r;i++)f.isBuffer(e)?o[i]=e.readUInt8(i):o[i]=e[i];else if("string"==u)o.write(e,0,t);else if("number"==u&&!f._useTypedArrays&&!n)for(i=0;i<r;i++)o[i]=0;return o}function l(e,t,n,r){return f._charsWritten=k(function(e){for(var t=[],n=0;n<e.length;n++)t.push(255&e.charCodeAt(n));return t}(t),e,n,r)}function d(e,t,n){var r="";n=Math.min(e.length,n);for(var o=t;o<n;o++)r+=String.fromCharCode(e[o]);return r}function h(e,t,n,r){r||(F("boolean"==typeof n,"missing or invalid endian"),F(null!=t,"missing offset"),F(t+1<e.length,"Trying to read beyond buffer length"));var o,i=e.length;if(!(i<=t))return n?(o=e[t],t+1<i&&(o|=e[t+1]<<8)):(o=e[t]<<8,t+1<i&&(o|=e[t+1])),o}function p(e,t,n,r){r||(F("boolean"==typeof n,"missing or invalid endian"),F(null!=t,"missing offset"),F(t+3<e.length,"Trying to read beyond buffer length"));var o,i=e.length;if(!(i<=t))return n?(t+2<i&&(o=e[t+2]<<16),t+1<i&&(o|=e[t+1]<<8),o|=e[t],t+3<i&&(o+=e[t+3]<<24>>>0)):(t+1<i&&(o=e[t+1]<<16),t+2<i&&(o|=e[t+2]<<8),t+3<i&&(o|=e[t+3]),o+=e[t]<<24>>>0),o}function g(e,t,n,r){if(r||(F("boolean"==typeof n,"missing or invalid endian"),F(null!=t,"missing offset"),F(t+1<e.length,"Trying to read beyond buffer length")),!(e.length<=t)){var o=h(e,t,n,!0);return 32768&o?-1*(65535-o+1):o}}function y(e,t,n,r){if(r||(F("boolean"==typeof n,"missing or invalid endian"),F(null!=t,"missing offset"),F(t+3<e.length,"Trying to read beyond buffer length")),!(e.length<=t)){var o=p(e,t,n,!0);return 2147483648&o?-1*(4294967295-o+1):o}}function w(e,t,n,r){return r||(F("boolean"==typeof n,"missing or invalid endian"),F(t+3<e.length,"Trying to read beyond buffer length")),c.read(e,t,n,23,4)}function b(e,t,n,r){return r||(F("boolean"==typeof n,"missing or invalid endian"),F(t+7<e.length,"Trying to read beyond buffer length")),c.read(e,t,n,52,8)}function m(e,t,n,r,o){o||(F(null!=t,"missing value"),F("boolean"==typeof r,"missing or invalid endian"),F(null!=n,"missing offset"),F(n+1<e.length,"trying to write beyond buffer length"),M(t,65535));var i=e.length;if(!(i<=n))for(var u=0,a=Math.min(i-n,2);u<a;u++)e[n+u]=(t&255<<8*(r?u:1-u))>>>8*(r?u:1-u)}function v(e,t,n,r,o){o||(F(null!=t,"missing value"),F("boolean"==typeof r,"missing or invalid endian"),F(null!=n,"missing offset"),F(n+3<e.length,"trying to write beyond buffer length"),M(t,4294967295));var i=e.length;if(!(i<=n))for(var u=0,a=Math.min(i-n,4);u<a;u++)e[n+u]=t>>>8*(r?u:3-u)&255}function _(e,t,n,r,o){o||(F(null!=t,"missing value"),F("boolean"==typeof r,"missing or invalid endian"),F(null!=n,"missing offset"),F(n+1<e.length,"Trying to write beyond buffer length"),N(t,32767,-32768)),e.length<=n||m(e,0<=t?t:65535+t+1,n,r,o)}function E(e,t,n,r,o){o||(F(null!=t,"missing value"),F("boolean"==typeof r,"missing or invalid endian"),F(null!=n,"missing offset"),F(n+3<e.length,"Trying to write beyond buffer length"),N(t,2147483647,-2147483648)),e.length<=n||v(e,0<=t?t:4294967295+t+1,n,r,o)}function I(e,t,n,r,o){o||(F(null!=t,"missing value"),F("boolean"==typeof r,"missing or invalid endian"),F(null!=n,"missing offset"),F(n+3<e.length,"Trying to write beyond buffer length"),Y(t,34028234663852886e22,-34028234663852886e22)),e.length<=n||c.write(e,t,n,r,23,4)}function A(e,t,n,r,o){o||(F(null!=t,"missing value"),F("boolean"==typeof r,"missing or invalid endian"),F(null!=n,"missing offset"),F(n+7<e.length,"Trying to write beyond buffer length"),Y(t,17976931348623157e292,-17976931348623157e292)),e.length<=n||c.write(e,t,n,r,52,8)}O.Buffer=f,O.SlowBuffer=f,O.INSPECT_MAX_BYTES=50,f.poolSize=8192,f._useTypedArrays=function(){try{var e=new ArrayBuffer(0),t=new Uint8Array(e);return t.foo=function(){return 42},42===t.foo()&&"function"==typeof t.subarray}catch(e){return!1}}(),f.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"raw":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},f.isBuffer=function(e){return!(null==e||!e._isBuffer)},f.byteLength=function(e,t){var n;switch(e+="",t||"utf8"){case"hex":n=e.length/2;break;case"utf8":case"utf-8":n=j(e).length;break;case"ascii":case"binary":case"raw":n=e.length;break;case"base64":n=C(e).length;break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":n=2*e.length;break;default:throw new Error("Unknown encoding")}return n},f.concat=function(e,t){if(F(x(e),"Usage: Buffer.concat(list, [totalLength])\nlist should be an Array."),0===e.length)return new f(0);if(1===e.length)return e[0];var n;if("number"!=typeof t)for(n=t=0;n<e.length;n++)t+=e[n].length;var r=new f(t),o=0;for(n=0;n<e.length;n++){var i=e[n];i.copy(r,o),o+=i.length}return r},f.prototype.write=function(e,t,n,r){if(isFinite(t))isFinite(n)||(r=n,n=void 0);else{var o=r;r=t,t=n,n=o}t=Number(t)||0;var i,u=this.length-t;switch(n?u<(n=Number(n))&&(n=u):n=u,r=String(r||"utf8").toLowerCase()){case"hex":i=function(e,t,n,r){n=Number(n)||0;var o=e.length-n;r?o<(r=Number(r))&&(r=o):r=o;var i=t.length;F(i%2==0,"Invalid hex string"),i/2<r&&(r=i/2);for(var u=0;u<r;u++){var a=parseInt(t.substr(2*u,2),16);F(!isNaN(a),"Invalid hex string"),e[n+u]=a}return f._charsWritten=2*u,u}(this,e,t,n);break;case"utf8":case"utf-8":i=function(e,t,n,r){return f._charsWritten=k(j(t),e,n,r)}(this,e,t,n);break;case"ascii":i=l(this,e,t,n);break;case"binary":i=function(e,t,n,r){return l(e,t,n,r)}(this,e,t,n);break;case"base64":i=function(e,t,n,r){return f._charsWritten=k(C(t),e,n,r)}(this,e,t,n);break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":i=function(e,t,n,r){return f._charsWritten=k(function(e){for(var t,n,r,o=[],i=0;i<e.length;i++)t=e.charCodeAt(i),n=t>>8,r=t%256,o.push(r),o.push(n);return o}(t),e,n,r)}(this,e,t,n);break;default:throw new Error("Unknown encoding")}return i},f.prototype.toString=function(e,t,n){var r,o=this;if(e=String(e||"utf8").toLowerCase(),t=Number(t)||0,(n=void 0!==n?Number(n):n=o.length)===t)return"";switch(e){case"hex":r=function(e,t,n){var r=e.length;(!t||t<0)&&(t=0);(!n||n<0||r<n)&&(n=r);for(var o="",i=t;i<n;i++)o+=S(e[i]);return o}(o,t,n);break;case"utf8":case"utf-8":r=function(e,t,n){var r="",o="";n=Math.min(e.length,n);for(var i=t;i<n;i++)e[i]<=127?(r+=T(o)+String.fromCharCode(e[i]),o=""):o+="%"+e[i].toString(16);return r+T(o)}(o,t,n);break;case"ascii":r=d(o,t,n);break;case"binary":r=function(e,t,n){return d(e,t,n)}(o,t,n);break;case"base64":r=function(e,t,n){return 0===t&&n===e.length?s.fromByteArray(e):s.fromByteArray(e.slice(t,n))}(o,t,n);break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":r=function(e,t,n){for(var r=e.slice(t,n),o="",i=0;i<r.length;i+=2)o+=String.fromCharCode(r[i]+256*r[i+1]);return o}(o,t,n);break;default:throw new Error("Unknown encoding")}return r},f.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}},f.prototype.copy=function(e,t,n,r){if(n=n||0,r||0===r||(r=this.length),t=t||0,r!==n&&0!==e.length&&0!==this.length){F(n<=r,"sourceEnd < sourceStart"),F(0<=t&&t<e.length,"targetStart out of bounds"),F(0<=n&&n<this.length,"sourceStart out of bounds"),F(0<=r&&r<=this.length,"sourceEnd out of bounds"),r>this.length&&(r=this.length),e.length-t<r-n&&(r=e.length-t+n);var o=r-n;if(o<100||!f._useTypedArrays)for(var i=0;i<o;i++)e[i+t]=this[i+n];else e._set(this.subarray(n,n+o),t)}},f.prototype.slice=function(e,t){var n=this.length;if(e=L(e,n,0),t=L(t,n,n),f._useTypedArrays)return f._augment(this.subarray(e,t));for(var r=t-e,o=new f(r,void 0,!0),i=0;i<r;i++)o[i]=this[i+e];return o},f.prototype.get=function(e){return console.log(".get() is deprecated. Access using array indexes instead."),this.readUInt8(e)},f.prototype.set=function(e,t){return console.log(".set() is deprecated. Access using array indexes instead."),this.writeUInt8(e,t)},f.prototype.readUInt8=function(e,t){if(t||(F(null!=e,"missing offset"),F(e<this.length,"Trying to read beyond buffer length")),!(e>=this.length))return this[e]},f.prototype.readUInt16LE=function(e,t){return h(this,e,!0,t)},f.prototype.readUInt16BE=function(e,t){return h(this,e,!1,t)},f.prototype.readUInt32LE=function(e,t){return p(this,e,!0,t)},f.prototype.readUInt32BE=function(e,t){return p(this,e,!1,t)},f.prototype.readInt8=function(e,t){if(t||(F(null!=e,"missing offset"),F(e<this.length,"Trying to read beyond buffer length")),!(e>=this.length))return 128&this[e]?-1*(255-this[e]+1):this[e]},f.prototype.readInt16LE=function(e,t){return g(this,e,!0,t)},f.prototype.readInt16BE=function(e,t){return g(this,e,!1,t)},f.prototype.readInt32LE=function(e,t){return y(this,e,!0,t)},f.prototype.readInt32BE=function(e,t){return y(this,e,!1,t)},f.prototype.readFloatLE=function(e,t){return w(this,e,!0,t)},f.prototype.readFloatBE=function(e,t){return w(this,e,!1,t)},f.prototype.readDoubleLE=function(e,t){return b(this,e,!0,t)},f.prototype.readDoubleBE=function(e,t){return b(this,e,!1,t)},f.prototype.writeUInt8=function(e,t,n){n||(F(null!=e,"missing value"),F(null!=t,"missing offset"),F(t<this.length,"trying to write beyond buffer length"),M(e,255)),t>=this.length||(this[t]=e)},f.prototype.writeUInt16LE=function(e,t,n){m(this,e,t,!0,n)},f.prototype.writeUInt16BE=function(e,t,n){m(this,e,t,!1,n)},f.prototype.writeUInt32LE=function(e,t,n){v(this,e,t,!0,n)},f.prototype.writeUInt32BE=function(e,t,n){v(this,e,t,!1,n)},f.prototype.writeInt8=function(e,t,n){n||(F(null!=e,"missing value"),F(null!=t,"missing offset"),F(t<this.length,"Trying to write beyond buffer length"),N(e,127,-128)),t>=this.length||(0<=e?this.writeUInt8(e,t,n):this.writeUInt8(255+e+1,t,n))},f.prototype.writeInt16LE=function(e,t,n){_(this,e,t,!0,n)},f.prototype.writeInt16BE=function(e,t,n){_(this,e,t,!1,n)},f.prototype.writeInt32LE=function(e,t,n){E(this,e,t,!0,n)},f.prototype.writeInt32BE=function(e,t,n){E(this,e,t,!1,n)},f.prototype.writeFloatLE=function(e,t,n){I(this,e,t,!0,n)},f.prototype.writeFloatBE=function(e,t,n){I(this,e,t,!1,n)},f.prototype.writeDoubleLE=function(e,t,n){A(this,e,t,!0,n)},f.prototype.writeDoubleBE=function(e,t,n){A(this,e,t,!1,n)},f.prototype.fill=function(e,t,n){if(e=e||0,t=t||0,n=n||this.length,"string"==typeof e&&(e=e.charCodeAt(0)),F("number"==typeof e&&!isNaN(e),"value is not a number"),F(t<=n,"end < start"),n!==t&&0!==this.length){F(0<=t&&t<this.length,"start out of bounds"),F(0<=n&&n<=this.length,"end out of bounds");for(var r=t;r<n;r++)this[r]=e}},f.prototype.inspect=function(){for(var e=[],t=this.length,n=0;n<t;n++)if(e[n]=S(this[n]),n===O.INSPECT_MAX_BYTES){e[n+1]="...";break}return"<Buffer "+e.join(" ")+">"},f.prototype.toArrayBuffer=function(){if("undefined"==typeof Uint8Array)throw new Error("Buffer.toArrayBuffer not supported in this browser");if(f._useTypedArrays)return new f(this).buffer;for(var e=new Uint8Array(this.length),t=0,n=e.length;t<n;t+=1)e[t]=this[t];return e.buffer};var B=f.prototype;function L(e,t,n){return"number"!=typeof e?n:t<=(e=~~e)?t:0<=e?e:0<=(e+=t)?e:0}function U(e){return(e=~~Math.ceil(+e))<0?0:e}function x(e){return(Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)})(e)}function S(e){return e<16?"0"+e.toString(16):e.toString(16)}function j(e){for(var t=[],n=0;n<e.length;n++){var r=e.charCodeAt(n);if(r<=127)t.push(e.charCodeAt(n));else{var o=n;55296<=r&&r<=57343&&n++;for(var i=encodeURIComponent(e.slice(o,n+1)).substr(1).split("%"),u=0;u<i.length;u++)t.push(parseInt(i[u],16))}}return t}function C(e){return s.toByteArray(e)}function k(e,t,n,r){for(var o=0;o<r&&!(o+n>=t.length||o>=e.length);o++)t[o+n]=e[o];return o}function T(e){try{return decodeURIComponent(e)}catch(e){return String.fromCharCode(65533)}}function M(e,t){F("number"==typeof e,"cannot write a non-number as a number"),F(0<=e,"specified a negative value for writing an unsigned value"),F(e<=t,"value is larger than maximum value for type"),F(Math.floor(e)===e,"value has a fractional component")}function N(e,t,n){F("number"==typeof e,"cannot write a non-number as a number"),F(e<=t,"value larger than maximum allowed value"),F(n<=e,"value smaller than minimum allowed value"),F(Math.floor(e)===e,"value has a fractional component")}function Y(e,t,n){F("number"==typeof e,"cannot write a non-number as a number"),F(e<=t,"value larger than maximum allowed value"),F(n<=e,"value smaller than minimum allowed value")}function F(e,t){if(!e)throw new Error(t||"Failed assertion")}f._augment=function(e){return e._isBuffer=!0,e._get=e.get,e._set=e.set,e.get=B.get,e.set=B.set,e.write=B.write,e.toString=B.toString,e.toLocaleString=B.toString,e.toJSON=B.toJSON,e.copy=B.copy,e.slice=B.slice,e.readUInt8=B.readUInt8,e.readUInt16LE=B.readUInt16LE,e.readUInt16BE=B.readUInt16BE,e.readUInt32LE=B.readUInt32LE,e.readUInt32BE=B.readUInt32BE,e.readInt8=B.readInt8,e.readInt16LE=B.readInt16LE,e.readInt16BE=B.readInt16BE,e.readInt32LE=B.readInt32LE,e.readInt32BE=B.readInt32BE,e.readFloatLE=B.readFloatLE,e.readFloatBE=B.readFloatBE,e.readDoubleLE=B.readDoubleLE,e.readDoubleBE=B.readDoubleBE,e.writeUInt8=B.writeUInt8,e.writeUInt16LE=B.writeUInt16LE,e.writeUInt16BE=B.writeUInt16BE,e.writeUInt32LE=B.writeUInt32LE,e.writeUInt32BE=B.writeUInt32BE,e.writeInt8=B.writeInt8,e.writeInt16LE=B.writeInt16LE,e.writeInt16BE=B.writeInt16BE,e.writeInt32LE=B.writeInt32LE,e.writeInt32BE=B.writeInt32BE,e.writeFloatLE=B.writeFloatLE,e.writeFloatBE=B.writeFloatBE,e.writeDoubleLE=B.writeDoubleLE,e.writeDoubleBE=B.writeDoubleBE,e.fill=B.fill,e.inspect=B.inspect,e.toArrayBuffer=B.toArrayBuffer,e}}).call(this,D("lYpoI2"),"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},D("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/node_modules/gulp-browserify/node_modules/buffer/index.js","/node_modules/gulp-browserify/node_modules/buffer")},{"base64-js":2,buffer:3,ieee754:11,lYpoI2:10}],4:[function(l,d,e){(function(e,t,u,n,r,o,i,a,f){u=l("buffer").Buffer;var s=4,c=new u(s);c.fill(0);d.exports={hash:function(e,t,n,r){return u.isBuffer(e)||(e=new u(e)),function(e,t,n){for(var r=new u(t),o=n?r.writeInt32BE:r.writeInt32LE,i=0;i<e.length;i++)o.call(r,e[i],4*i,!0);return r}(t(function(e,t){if(e.length%s!=0){var n=e.length+(s-e.length%s);e=u.concat([e,c],n)}for(var r=[],o=t?e.readInt32BE:e.readInt32LE,i=0;i<e.length;i+=s)r.push(o.call(e,i));return r}(e,r),8*e.length),n,r)}}}).call(this,l("lYpoI2"),"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},l("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/node_modules/gulp-browserify/node_modules/crypto-browserify/helpers.js","/node_modules/gulp-browserify/node_modules/crypto-browserify")},{buffer:3,lYpoI2:10}],5:[function(w,e,b){(function(e,t,a,n,r,o,i,u,f){a=w("buffer").Buffer;var s=w("./sha"),c=w("./sha256"),l=w("./rng"),d={sha1:s,sha256:c,md5:w("./md5")},h=64,p=new a(h);function g(e,r){var o=d[e=e||"sha1"],i=[];return o||y("algorithm:",e,"is not yet supported"),{update:function(e){return a.isBuffer(e)||(e=new a(e)),i.push(e),e.length,this},digest:function(e){var t=a.concat(i),n=r?function(e,t,n){a.isBuffer(t)||(t=new a(t)),a.isBuffer(n)||(n=new a(n)),t.length>h?t=e(t):t.length<h&&(t=a.concat([t,p],h));for(var r=new a(h),o=new a(h),i=0;i<h;i++)r[i]=54^t[i],o[i]=92^t[i];var u=e(a.concat([r,n]));return e(a.concat([o,u]))}(o,r,t):o(t);return i=null,e?n.toString(e):n}}}function y(){var e=[].slice.call(arguments).join(" ");throw new Error([e,"we accept pull requests","http://github.com/dominictarr/crypto-browserify"].join("\n"))}p.fill(0),b.createHash=function(e){return g(e)},b.createHmac=function(e,t){return g(e,t)},b.randomBytes=function(e,t){if(!t||!t.call)return new a(l(e));try{t.call(this,void 0,new a(l(e)))}catch(e){t(e)}},function(e,t){for(var n in e)t(e[n],n)}(["createCredentials","createCipher","createCipheriv","createDecipher","createDecipheriv","createSign","createVerify","createDiffieHellman","pbkdf2"],function(e){b[e]=function(){y("sorry,",e,"is not implemented yet")}})}).call(this,w("lYpoI2"),"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},w("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/node_modules/gulp-browserify/node_modules/crypto-browserify/index.js","/node_modules/gulp-browserify/node_modules/crypto-browserify")},{"./md5":6,"./rng":7,"./sha":8,"./sha256":9,buffer:3,lYpoI2:10}],6:[function(w,b,e){(function(e,t,n,r,o,i,u,a,f){var s=w("./helpers");function c(e,t){e[t>>5]|=128<<t%32,e[14+(t+64>>>9<<4)]=t;for(var n=1732584193,r=-271733879,o=-1732584194,i=271733878,u=0;u<e.length;u+=16){var a=n,f=r,s=o,c=i;r=g(r=g(r=g(r=g(r=p(r=p(r=p(r=p(r=h(r=h(r=h(r=h(r=d(r=d(r=d(r=d(r,o=d(o,i=d(i,n=d(n,r,o,i,e[u+0],7,-680876936),r,o,e[u+1],12,-389564586),n,r,e[u+2],17,606105819),i,n,e[u+3],22,-1044525330),o=d(o,i=d(i,n=d(n,r,o,i,e[u+4],7,-176418897),r,o,e[u+5],12,1200080426),n,r,e[u+6],17,-1473231341),i,n,e[u+7],22,-45705983),o=d(o,i=d(i,n=d(n,r,o,i,e[u+8],7,1770035416),r,o,e[u+9],12,-1958414417),n,r,e[u+10],17,-42063),i,n,e[u+11],22,-1990404162),o=d(o,i=d(i,n=d(n,r,o,i,e[u+12],7,1804603682),r,o,e[u+13],12,-40341101),n,r,e[u+14],17,-1502002290),i,n,e[u+15],22,1236535329),o=h(o,i=h(i,n=h(n,r,o,i,e[u+1],5,-165796510),r,o,e[u+6],9,-1069501632),n,r,e[u+11],14,643717713),i,n,e[u+0],20,-373897302),o=h(o,i=h(i,n=h(n,r,o,i,e[u+5],5,-701558691),r,o,e[u+10],9,38016083),n,r,e[u+15],14,-660478335),i,n,e[u+4],20,-405537848),o=h(o,i=h(i,n=h(n,r,o,i,e[u+9],5,568446438),r,o,e[u+14],9,-1019803690),n,r,e[u+3],14,-187363961),i,n,e[u+8],20,1163531501),o=h(o,i=h(i,n=h(n,r,o,i,e[u+13],5,-1444681467),r,o,e[u+2],9,-51403784),n,r,e[u+7],14,1735328473),i,n,e[u+12],20,-1926607734),o=p(o,i=p(i,n=p(n,r,o,i,e[u+5],4,-378558),r,o,e[u+8],11,-2022574463),n,r,e[u+11],16,1839030562),i,n,e[u+14],23,-35309556),o=p(o,i=p(i,n=p(n,r,o,i,e[u+1],4,-1530992060),r,o,e[u+4],11,1272893353),n,r,e[u+7],16,-155497632),i,n,e[u+10],23,-1094730640),o=p(o,i=p(i,n=p(n,r,o,i,e[u+13],4,681279174),r,o,e[u+0],11,-358537222),n,r,e[u+3],16,-722521979),i,n,e[u+6],23,76029189),o=p(o,i=p(i,n=p(n,r,o,i,e[u+9],4,-640364487),r,o,e[u+12],11,-421815835),n,r,e[u+15],16,530742520),i,n,e[u+2],23,-995338651),o=g(o,i=g(i,n=g(n,r,o,i,e[u+0],6,-198630844),r,o,e[u+7],10,1126891415),n,r,e[u+14],15,-1416354905),i,n,e[u+5],21,-57434055),o=g(o,i=g(i,n=g(n,r,o,i,e[u+12],6,1700485571),r,o,e[u+3],10,-1894986606),n,r,e[u+10],15,-1051523),i,n,e[u+1],21,-2054922799),o=g(o,i=g(i,n=g(n,r,o,i,e[u+8],6,1873313359),r,o,e[u+15],10,-30611744),n,r,e[u+6],15,-1560198380),i,n,e[u+13],21,1309151649),o=g(o,i=g(i,n=g(n,r,o,i,e[u+4],6,-145523070),r,o,e[u+11],10,-1120210379),n,r,e[u+2],15,718787259),i,n,e[u+9],21,-343485551),n=y(n,a),r=y(r,f),o=y(o,s),i=y(i,c)}return Array(n,r,o,i)}function l(e,t,n,r,o,i){return y(function(e,t){return e<<t|e>>>32-t}(y(y(t,e),y(r,i)),o),n)}function d(e,t,n,r,o,i,u){return l(t&n|~t&r,e,t,o,i,u)}function h(e,t,n,r,o,i,u){return l(t&r|n&~r,e,t,o,i,u)}function p(e,t,n,r,o,i,u){return l(t^n^r,e,t,o,i,u)}function g(e,t,n,r,o,i,u){return l(n^(t|~r),e,t,o,i,u)}function y(e,t){var n=(65535&e)+(65535&t);return(e>>16)+(t>>16)+(n>>16)<<16|65535&n}b.exports=function(e){return s.hash(e,c,16)}}).call(this,w("lYpoI2"),"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},w("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/node_modules/gulp-browserify/node_modules/crypto-browserify/md5.js","/node_modules/gulp-browserify/node_modules/crypto-browserify")},{"./helpers":4,buffer:3,lYpoI2:10}],7:[function(e,l,t){(function(e,t,n,r,o,i,u,a,f){var s,c;s=function(e){for(var t,n=new Array(e),r=0;r<e;r++)0==(3&r)&&(t=4294967296*Math.random()),n[r]=t>>>((3&r)<<3)&255;return n},l.exports=c||s}).call(this,e("lYpoI2"),"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},e("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/node_modules/gulp-browserify/node_modules/crypto-browserify/rng.js","/node_modules/gulp-browserify/node_modules/crypto-browserify")},{buffer:3,lYpoI2:10}],8:[function(l,d,e){(function(e,t,n,r,o,i,u,a,f){var s=l("./helpers");function c(e,t){e[t>>5]|=128<<24-t%32,e[15+(t+64>>9<<4)]=t;for(var n,r=Array(80),o=1732584193,i=-271733879,u=-1732584194,a=271733878,f=-1009589776,s=0;s<e.length;s+=16){for(var c=o,l=i,d=u,h=a,p=f,g=0;g<80;g++){r[g]=g<16?e[s+g]:m(r[g-3]^r[g-8]^r[g-14]^r[g-16],1);var y=b(b(m(o,5),w(g,i,u,a)),b(b(f,r[g]),(n=g)<20?1518500249:n<40?1859775393:n<60?-1894007588:-899497514));f=a,a=u,u=m(i,30),i=o,o=y}o=b(o,c),i=b(i,l),u=b(u,d),a=b(a,h),f=b(f,p)}return Array(o,i,u,a,f)}function w(e,t,n,r){return e<20?t&n|~t&r:e<40?t^n^r:e<60?t&n|t&r|n&r:t^n^r}function b(e,t){var n=(65535&e)+(65535&t);return(e>>16)+(t>>16)+(n>>16)<<16|65535&n}function m(e,t){return e<<t|e>>>32-t}d.exports=function(e){return s.hash(e,c,20,!0)}}).call(this,l("lYpoI2"),"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},l("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/node_modules/gulp-browserify/node_modules/crypto-browserify/sha.js","/node_modules/gulp-browserify/node_modules/crypto-browserify")},{"./helpers":4,buffer:3,lYpoI2:10}],9:[function(l,d,e){(function(e,t,n,r,o,i,u,a,f){function B(e,t){var n=(65535&e)+(65535&t);return(e>>16)+(t>>16)+(n>>16)<<16|65535&n}function L(e,t){return e>>>t|e<<32-t}function U(e,t){return e>>>t}function s(e,t){var n,r,o,i,u,a,f,s,c,l,d,h,p,g,y,w,b,m,v=new Array(1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298),_=new Array(1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225),E=new Array(64);e[t>>5]|=128<<24-t%32,e[15+(t+64>>9<<4)]=t;for(var I=0;I<e.length;I+=16){n=_[0],r=_[1],o=_[2],i=_[3],u=_[4],a=_[5],f=_[6],s=_[7];for(var A=0;A<64;A++)E[A]=A<16?e[A+I]:B(B(B((m=E[A-2],L(m,17)^L(m,19)^U(m,10)),E[A-7]),(b=E[A-15],L(b,7)^L(b,18)^U(b,3))),E[A-16]),c=B(B(B(B(s,L(w=u,6)^L(w,11)^L(w,25)),(y=u)&a^~y&f),v[A]),E[A]),l=B(L(g=n,2)^L(g,13)^L(g,22),(d=n)&(h=r)^d&(p=o)^h&p),s=f,f=a,a=u,u=B(i,c),i=o,o=r,r=n,n=B(c,l);_[0]=B(n,_[0]),_[1]=B(r,_[1]),_[2]=B(o,_[2]),_[3]=B(i,_[3]),_[4]=B(u,_[4]),_[5]=B(a,_[5]),_[6]=B(f,_[6]),_[7]=B(s,_[7])}return _}var c=l("./helpers");d.exports=function(e){return c.hash(e,s,32,!0)}}).call(this,l("lYpoI2"),"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},l("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/node_modules/gulp-browserify/node_modules/crypto-browserify/sha256.js","/node_modules/gulp-browserify/node_modules/crypto-browserify")},{"./helpers":4,buffer:3,lYpoI2:10}],10:[function(e,c,t){(function(e,t,n,r,o,i,u,a,f){function s(){}(e=c.exports={}).nextTick=function(){var e="undefined"!=typeof window&&window.setImmediate,t="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(e)return function(e){return window.setImmediate(e)};if(t){var n=[];return window.addEventListener("message",function(e){var t=e.source;t!==window&&null!==t||"process-tick"!==e.data||(e.stopPropagation(),0<n.length&&n.shift()())},!0),function(e){n.push(e),window.postMessage("process-tick","*")}}return function(e){setTimeout(e,0)}}(),e.title="browser",e.browser=!0,e.env={},e.argv=[],e.on=s,e.addListener=s,e.once=s,e.off=s,e.removeListener=s,e.removeAllListeners=s,e.emit=s,e.binding=function(e){throw new Error("process.binding is not supported")},e.cwd=function(){return"/"},e.chdir=function(e){throw new Error("process.chdir is not supported")}}).call(this,e("lYpoI2"),"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},e("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/node_modules/gulp-browserify/node_modules/process/browser.js","/node_modules/gulp-browserify/node_modules/process")},{buffer:3,lYpoI2:10}],11:[function(e,t,s){(function(e,t,n,r,o,i,u,a,f){s.read=function(e,t,n,r,o){var i,u,a=8*o-r-1,f=(1<<a)-1,s=f>>1,c=-7,l=n?o-1:0,d=n?-1:1,h=e[t+l];for(l+=d,i=h&(1<<-c)-1,h>>=-c,c+=a;0<c;i=256*i+e[t+l],l+=d,c-=8);for(u=i&(1<<-c)-1,i>>=-c,c+=r;0<c;u=256*u+e[t+l],l+=d,c-=8);if(0===i)i=1-s;else{if(i===f)return u?NaN:1/0*(h?-1:1);u+=Math.pow(2,r),i-=s}return(h?-1:1)*u*Math.pow(2,i-r)},s.write=function(e,t,n,r,o,i){var u,a,f,s=8*i-o-1,c=(1<<s)-1,l=c>>1,d=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,h=r?0:i-1,p=r?1:-1,g=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,u=c):(u=Math.floor(Math.log(t)/Math.LN2),t*(f=Math.pow(2,-u))<1&&(u--,f*=2),2<=(t+=1<=u+l?d/f:d*Math.pow(2,1-l))*f&&(u++,f/=2),c<=u+l?(a=0,u=c):1<=u+l?(a=(t*f-1)*Math.pow(2,o),u+=l):(a=t*Math.pow(2,l-1)*Math.pow(2,o),u=0));8<=o;e[n+h]=255&a,h+=p,a/=256,o-=8);for(u=u<<o|a,s+=o;0<s;e[n+h]=255&u,h+=p,u/=256,s-=8);e[n+h-p]|=128*g}}).call(this,e("lYpoI2"),"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},e("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/node_modules/ieee754/index.js","/node_modules/ieee754")},{buffer:3,lYpoI2:10}]},{},[1])(1)});
4}).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
5},{}],2:[function(require,module,exports){
6// http://wiki.commonjs.org/wiki/Unit_Testing/1.0
7//
8// THIS IS NOT TESTED NOR LIKELY TO WORK OUTSIDE V8!
9//
10// Originally from narwhal.js (http://narwhaljs.org)
11// Copyright (c) 2009 Thomas Robinson <280north.com>
12//
13// Permission is hereby granted, free of charge, to any person obtaining a copy
14// of this software and associated documentation files (the 'Software'), to
15// deal in the Software without restriction, including without limitation the
16// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
17// sell copies of the Software, and to permit persons to whom the Software is
18// furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included in
21// all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26// AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
27// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30// when used in node, this will actually load the util module we depend on
31// versus loading the builtin util module as happens otherwise
32// this is a bug in node module loading as far as I am concerned
33var util = require('util/');
34
35var pSlice = Array.prototype.slice;
36var hasOwn = Object.prototype.hasOwnProperty;
37
38// 1. The assert module provides functions that throw
39// AssertionError's when particular conditions are not met. The
40// assert module must conform to the following interface.
41
42var assert = module.exports = ok;
43
44// 2. The AssertionError is defined in assert.
45// new assert.AssertionError({ message: message,
46// actual: actual,
47// expected: expected })
48
49assert.AssertionError = function AssertionError(options) {
50 this.name = 'AssertionError';
51 this.actual = options.actual;
52 this.expected = options.expected;
53 this.operator = options.operator;
54 if (options.message) {
55 this.message = options.message;
56 this.generatedMessage = false;
57 } else {
58 this.message = getMessage(this);
59 this.generatedMessage = true;
60 }
61 var stackStartFunction = options.stackStartFunction || fail;
62
63 if (Error.captureStackTrace) {
64 Error.captureStackTrace(this, stackStartFunction);
65 }
66 else {
67 // non v8 browsers so we can have a stacktrace
68 var err = new Error();
69 if (err.stack) {
70 var out = err.stack;
71
72 // try to strip useless frames
73 var fn_name = stackStartFunction.name;
74 var idx = out.indexOf('\n' + fn_name);
75 if (idx >= 0) {
76 // once we have located the function frame
77 // we need to strip out everything before it (and its line)
78 var next_line = out.indexOf('\n', idx + 1);
79 out = out.substring(next_line + 1);
80 }
81
82 this.stack = out;
83 }
84 }
85};
86
87// assert.AssertionError instanceof Error
88util.inherits(assert.AssertionError, Error);
89
90function replacer(key, value) {
91 if (util.isUndefined(value)) {
92 return '' + value;
93 }
94 if (util.isNumber(value) && (isNaN(value) || !isFinite(value))) {
95 return value.toString();
96 }
97 if (util.isFunction(value) || util.isRegExp(value)) {
98 return value.toString();
99 }
100 return value;
101}
102
103function truncate(s, n) {
104 if (util.isString(s)) {
105 return s.length < n ? s : s.slice(0, n);
106 } else {
107 return s;
108 }
109}
110
111function getMessage(self) {
112 return truncate(JSON.stringify(self.actual, replacer), 128) + ' ' +
113 self.operator + ' ' +
114 truncate(JSON.stringify(self.expected, replacer), 128);
115}
116
117// At present only the three keys mentioned above are used and
118// understood by the spec. Implementations or sub modules can pass
119// other keys to the AssertionError's constructor - they will be
120// ignored.
121
122// 3. All of the following functions must throw an AssertionError
123// when a corresponding condition is not met, with a message that
124// may be undefined if not provided. All assertion methods provide
125// both the actual and expected values to the assertion error for
126// display purposes.
127
128function fail(actual, expected, message, operator, stackStartFunction) {
129 throw new assert.AssertionError({
130 message: message,
131 actual: actual,
132 expected: expected,
133 operator: operator,
134 stackStartFunction: stackStartFunction
135 });
136}
137
138// EXTENSION! allows for well behaved errors defined elsewhere.
139assert.fail = fail;
140
141// 4. Pure assertion tests whether a value is truthy, as determined
142// by !!guard.
143// assert.ok(guard, message_opt);
144// This statement is equivalent to assert.equal(true, !!guard,
145// message_opt);. To test strictly for the value true, use
146// assert.strictEqual(true, guard, message_opt);.
147
148function ok(value, message) {
149 if (!value) fail(value, true, message, '==', assert.ok);
150}
151assert.ok = ok;
152
153// 5. The equality assertion tests shallow, coercive equality with
154// ==.
155// assert.equal(actual, expected, message_opt);
156
157assert.equal = function equal(actual, expected, message) {
158 if (actual != expected) fail(actual, expected, message, '==', assert.equal);
159};
160
161// 6. The non-equality assertion tests for whether two objects are not equal
162// with != assert.notEqual(actual, expected, message_opt);
163
164assert.notEqual = function notEqual(actual, expected, message) {
165 if (actual == expected) {
166 fail(actual, expected, message, '!=', assert.notEqual);
167 }
168};
169
170// 7. The equivalence assertion tests a deep equality relation.
171// assert.deepEqual(actual, expected, message_opt);
172
173assert.deepEqual = function deepEqual(actual, expected, message) {
174 if (!_deepEqual(actual, expected)) {
175 fail(actual, expected, message, 'deepEqual', assert.deepEqual);
176 }
177};
178
179function _deepEqual(actual, expected) {
180 // 7.1. All identical values are equivalent, as determined by ===.
181 if (actual === expected) {
182 return true;
183
184 } else if (util.isBuffer(actual) && util.isBuffer(expected)) {
185 if (actual.length != expected.length) return false;
186
187 for (var i = 0; i < actual.length; i++) {
188 if (actual[i] !== expected[i]) return false;
189 }
190
191 return true;
192
193 // 7.2. If the expected value is a Date object, the actual value is
194 // equivalent if it is also a Date object that refers to the same time.
195 } else if (util.isDate(actual) && util.isDate(expected)) {
196 return actual.getTime() === expected.getTime();
197
198 // 7.3 If the expected value is a RegExp object, the actual value is
199 // equivalent if it is also a RegExp object with the same source and
200 // properties (`global`, `multiline`, `lastIndex`, `ignoreCase`).
201 } else if (util.isRegExp(actual) && util.isRegExp(expected)) {
202 return actual.source === expected.source &&
203 actual.global === expected.global &&
204 actual.multiline === expected.multiline &&
205 actual.lastIndex === expected.lastIndex &&
206 actual.ignoreCase === expected.ignoreCase;
207
208 // 7.4. Other pairs that do not both pass typeof value == 'object',
209 // equivalence is determined by ==.
210 } else if (!util.isObject(actual) && !util.isObject(expected)) {
211 return actual == expected;
212
213 // 7.5 For all other Object pairs, including Array objects, equivalence is
214 // determined by having the same number of owned properties (as verified
215 // with Object.prototype.hasOwnProperty.call), the same set of keys
216 // (although not necessarily the same order), equivalent values for every
217 // corresponding key, and an identical 'prototype' property. Note: this
218 // accounts for both named and indexed properties on Arrays.
219 } else {
220 return objEquiv(actual, expected);
221 }
222}
223
224function isArguments(object) {
225 return Object.prototype.toString.call(object) == '[object Arguments]';
226}
227
228function objEquiv(a, b) {
229 if (util.isNullOrUndefined(a) || util.isNullOrUndefined(b))
230 return false;
231 // an identical 'prototype' property.
232 if (a.prototype !== b.prototype) return false;
233 //~~~I've managed to break Object.keys through screwy arguments passing.
234 // Converting to array solves the problem.
235 if (isArguments(a)) {
236 if (!isArguments(b)) {
237 return false;
238 }
239 a = pSlice.call(a);
240 b = pSlice.call(b);
241 return _deepEqual(a, b);
242 }
243 try {
244 var ka = objectKeys(a),
245 kb = objectKeys(b),
246 key, i;
247 } catch (e) {//happens when one is a string literal and the other isn't
248 return false;
249 }
250 // having the same number of owned properties (keys incorporates
251 // hasOwnProperty)
252 if (ka.length != kb.length)
253 return false;
254 //the same set of keys (although not necessarily the same order),
255 ka.sort();
256 kb.sort();
257 //~~~cheap key test
258 for (i = ka.length - 1; i >= 0; i--) {
259 if (ka[i] != kb[i])
260 return false;
261 }
262 //equivalent values for every corresponding key, and
263 //~~~possibly expensive deep test
264 for (i = ka.length - 1; i >= 0; i--) {
265 key = ka[i];
266 if (!_deepEqual(a[key], b[key])) return false;
267 }
268 return true;
269}
270
271// 8. The non-equivalence assertion tests for any deep inequality.
272// assert.notDeepEqual(actual, expected, message_opt);
273
274assert.notDeepEqual = function notDeepEqual(actual, expected, message) {
275 if (_deepEqual(actual, expected)) {
276 fail(actual, expected, message, 'notDeepEqual', assert.notDeepEqual);
277 }
278};
279
280// 9. The strict equality assertion tests strict equality, as determined by ===.
281// assert.strictEqual(actual, expected, message_opt);
282
283assert.strictEqual = function strictEqual(actual, expected, message) {
284 if (actual !== expected) {
285 fail(actual, expected, message, '===', assert.strictEqual);
286 }
287};
288
289// 10. The strict non-equality assertion tests for strict inequality, as
290// determined by !==. assert.notStrictEqual(actual, expected, message_opt);
291
292assert.notStrictEqual = function notStrictEqual(actual, expected, message) {
293 if (actual === expected) {
294 fail(actual, expected, message, '!==', assert.notStrictEqual);
295 }
296};
297
298function expectedException(actual, expected) {
299 if (!actual || !expected) {
300 return false;
301 }
302
303 if (Object.prototype.toString.call(expected) == '[object RegExp]') {
304 return expected.test(actual);
305 } else if (actual instanceof expected) {
306 return true;
307 } else if (expected.call({}, actual) === true) {
308 return true;
309 }
310
311 return false;
312}
313
314function _throws(shouldThrow, block, expected, message) {
315 var actual;
316
317 if (util.isString(expected)) {
318 message = expected;
319 expected = null;
320 }
321
322 try {
323 block();
324 } catch (e) {
325 actual = e;
326 }
327
328 message = (expected && expected.name ? ' (' + expected.name + ').' : '.') +
329 (message ? ' ' + message : '.');
330
331 if (shouldThrow && !actual) {
332 fail(actual, expected, 'Missing expected exception' + message);
333 }
334
335 if (!shouldThrow && expectedException(actual, expected)) {
336 fail(actual, expected, 'Got unwanted exception' + message);
337 }
338
339 if ((shouldThrow && actual && expected &&
340 !expectedException(actual, expected)) || (!shouldThrow && actual)) {
341 throw actual;
342 }
343}
344
345// 11. Expected to throw an error:
346// assert.throws(block, Error_opt, message_opt);
347
348assert.throws = function(block, /*optional*/error, /*optional*/message) {
349 _throws.apply(this, [true].concat(pSlice.call(arguments)));
350};
351
352// EXTENSION! This is annoying to write outside this module.
353assert.doesNotThrow = function(block, /*optional*/message) {
354 _throws.apply(this, [false].concat(pSlice.call(arguments)));
355};
356
357assert.ifError = function(err) { if (err) {throw err;}};
358
359var objectKeys = Object.keys || function (obj) {
360 var keys = [];
361 for (var key in obj) {
362 if (hasOwn.call(obj, key)) keys.push(key);
363 }
364 return keys;
365};
366
367},{"util/":5}],3:[function(require,module,exports){
368if (typeof Object.create === 'function') {
369 // implementation from standard node.js 'util' module
370 module.exports = function inherits(ctor, superCtor) {
371 ctor.super_ = superCtor
372 ctor.prototype = Object.create(superCtor.prototype, {
373 constructor: {
374 value: ctor,
375 enumerable: false,
376 writable: true,
377 configurable: true
378 }
379 });
380 };
381} else {
382 // old school shim for old browsers
383 module.exports = function inherits(ctor, superCtor) {
384 ctor.super_ = superCtor
385 var TempCtor = function () {}
386 TempCtor.prototype = superCtor.prototype
387 ctor.prototype = new TempCtor()
388 ctor.prototype.constructor = ctor
389 }
390}
391
392},{}],4:[function(require,module,exports){
393module.exports = function isBuffer(arg) {
394 return arg && typeof arg === 'object'
395 && typeof arg.copy === 'function'
396 && typeof arg.fill === 'function'
397 && typeof arg.readUInt8 === 'function';
398}
399},{}],5:[function(require,module,exports){
400(function (process,global){
401// Copyright Joyent, Inc. and other Node contributors.
402//
403// Permission is hereby granted, free of charge, to any person obtaining a
404// copy of this software and associated documentation files (the
405// "Software"), to deal in the Software without restriction, including
406// without limitation the rights to use, copy, modify, merge, publish,
407// distribute, sublicense, and/or sell copies of the Software, and to permit
408// persons to whom the Software is furnished to do so, subject to the
409// following conditions:
410//
411// The above copyright notice and this permission notice shall be included
412// in all copies or substantial portions of the Software.
413//
414// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
415// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
416// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
417// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
418// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
419// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
420// USE OR OTHER DEALINGS IN THE SOFTWARE.
421
422var formatRegExp = /%[sdj%]/g;
423exports.format = function(f) {
424 if (!isString(f)) {
425 var objects = [];
426 for (var i = 0; i < arguments.length; i++) {
427 objects.push(inspect(arguments[i]));
428 }
429 return objects.join(' ');
430 }
431
432 var i = 1;
433 var args = arguments;
434 var len = args.length;
435 var str = String(f).replace(formatRegExp, function(x) {
436 if (x === '%%') return '%';
437 if (i >= len) return x;
438 switch (x) {
439 case '%s': return String(args[i++]);
440 case '%d': return Number(args[i++]);
441 case '%j':
442 try {
443 return JSON.stringify(args[i++]);
444 } catch (_) {
445 return '[Circular]';
446 }
447 default:
448 return x;
449 }
450 });
451 for (var x = args[i]; i < len; x = args[++i]) {
452 if (isNull(x) || !isObject(x)) {
453 str += ' ' + x;
454 } else {
455 str += ' ' + inspect(x);
456 }
457 }
458 return str;
459};
460
461
462// Mark that a method should not be used.
463// Returns a modified function which warns once by default.
464// If --no-deprecation is set, then it is a no-op.
465exports.deprecate = function(fn, msg) {
466 // Allow for deprecating things in the process of starting up.
467 if (isUndefined(global.process)) {
468 return function() {
469 return exports.deprecate(fn, msg).apply(this, arguments);
470 };
471 }
472
473 if (process.noDeprecation === true) {
474 return fn;
475 }
476
477 var warned = false;
478 function deprecated() {
479 if (!warned) {
480 if (process.throwDeprecation) {
481 throw new Error(msg);
482 } else if (process.traceDeprecation) {
483 console.trace(msg);
484 } else {
485 console.error(msg);
486 }
487 warned = true;
488 }
489 return fn.apply(this, arguments);
490 }
491
492 return deprecated;
493};
494
495
496var debugs = {};
497var debugEnviron;
498exports.debuglog = function(set) {
499 if (isUndefined(debugEnviron))
500 debugEnviron = process.env.NODE_DEBUG || '';
501 set = set.toUpperCase();
502 if (!debugs[set]) {
503 if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
504 var pid = process.pid;
505 debugs[set] = function() {
506 var msg = exports.format.apply(exports, arguments);
507 console.error('%s %d: %s', set, pid, msg);
508 };
509 } else {
510 debugs[set] = function() {};
511 }
512 }
513 return debugs[set];
514};
515
516
517/**
518 * Echos the value of a value. Trys to print the value out
519 * in the best way possible given the different types.
520 *
521 * @param {Object} obj The object to print out.
522 * @param {Object} opts Optional options object that alters the output.
523 */
524/* legacy: obj, showHidden, depth, colors*/
525function inspect(obj, opts) {
526 // default options
527 var ctx = {
528 seen: [],
529 stylize: stylizeNoColor
530 };
531 // legacy...
532 if (arguments.length >= 3) ctx.depth = arguments[2];
533 if (arguments.length >= 4) ctx.colors = arguments[3];
534 if (isBoolean(opts)) {
535 // legacy...
536 ctx.showHidden = opts;
537 } else if (opts) {
538 // got an "options" object
539 exports._extend(ctx, opts);
540 }
541 // set default options
542 if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
543 if (isUndefined(ctx.depth)) ctx.depth = 2;
544 if (isUndefined(ctx.colors)) ctx.colors = false;
545 if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
546 if (ctx.colors) ctx.stylize = stylizeWithColor;
547 return formatValue(ctx, obj, ctx.depth);
548}
549exports.inspect = inspect;
550
551
552// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
553inspect.colors = {
554 'bold' : [1, 22],
555 'italic' : [3, 23],
556 'underline' : [4, 24],
557 'inverse' : [7, 27],
558 'white' : [37, 39],
559 'grey' : [90, 39],
560 'black' : [30, 39],
561 'blue' : [34, 39],
562 'cyan' : [36, 39],
563 'green' : [32, 39],
564 'magenta' : [35, 39],
565 'red' : [31, 39],
566 'yellow' : [33, 39]
567};
568
569// Don't use 'blue' not visible on cmd.exe
570inspect.styles = {
571 'special': 'cyan',
572 'number': 'yellow',
573 'boolean': 'yellow',
574 'undefined': 'grey',
575 'null': 'bold',
576 'string': 'green',
577 'date': 'magenta',
578 // "name": intentionally not styling
579 'regexp': 'red'
580};
581
582
583function stylizeWithColor(str, styleType) {
584 var style = inspect.styles[styleType];
585
586 if (style) {
587 return '\u001b[' + inspect.colors[style][0] + 'm' + str +
588 '\u001b[' + inspect.colors[style][1] + 'm';
589 } else {
590 return str;
591 }
592}
593
594
595function stylizeNoColor(str, styleType) {
596 return str;
597}
598
599
600function arrayToHash(array) {
601 var hash = {};
602
603 array.forEach(function(val, idx) {
604 hash[val] = true;
605 });
606
607 return hash;
608}
609
610
611function formatValue(ctx, value, recurseTimes) {
612 // Provide a hook for user-specified inspect functions.
613 // Check that value is an object with an inspect function on it
614 if (ctx.customInspect &&
615 value &&
616 isFunction(value.inspect) &&
617 // Filter out the util module, it's inspect function is special
618 value.inspect !== exports.inspect &&
619 // Also filter out any prototype objects using the circular check.
620 !(value.constructor && value.constructor.prototype === value)) {
621 var ret = value.inspect(recurseTimes, ctx);
622 if (!isString(ret)) {
623 ret = formatValue(ctx, ret, recurseTimes);
624 }
625 return ret;
626 }
627
628 // Primitive types cannot have properties
629 var primitive = formatPrimitive(ctx, value);
630 if (primitive) {
631 return primitive;
632 }
633
634 // Look up the keys of the object.
635 var keys = Object.keys(value);
636 var visibleKeys = arrayToHash(keys);
637
638 if (ctx.showHidden) {
639 keys = Object.getOwnPropertyNames(value);
640 }
641
642 // IE doesn't make error fields non-enumerable
643 // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx
644 if (isError(value)
645 && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
646 return formatError(value);
647 }
648
649 // Some type of object without properties can be shortcutted.
650 if (keys.length === 0) {
651 if (isFunction(value)) {
652 var name = value.name ? ': ' + value.name : '';
653 return ctx.stylize('[Function' + name + ']', 'special');
654 }
655 if (isRegExp(value)) {
656 return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
657 }
658 if (isDate(value)) {
659 return ctx.stylize(Date.prototype.toString.call(value), 'date');
660 }
661 if (isError(value)) {
662 return formatError(value);
663 }
664 }
665
666 var base = '', array = false, braces = ['{', '}'];
667
668 // Make Array say that they are Array
669 if (isArray(value)) {
670 array = true;
671 braces = ['[', ']'];
672 }
673
674 // Make functions say that they are functions
675 if (isFunction(value)) {
676 var n = value.name ? ': ' + value.name : '';
677 base = ' [Function' + n + ']';
678 }
679
680 // Make RegExps say that they are RegExps
681 if (isRegExp(value)) {
682 base = ' ' + RegExp.prototype.toString.call(value);
683 }
684
685 // Make dates with properties first say the date
686 if (isDate(value)) {
687 base = ' ' + Date.prototype.toUTCString.call(value);
688 }
689
690 // Make error with message first say the error
691 if (isError(value)) {
692 base = ' ' + formatError(value);
693 }
694
695 if (keys.length === 0 && (!array || value.length == 0)) {
696 return braces[0] + base + braces[1];
697 }
698
699 if (recurseTimes < 0) {
700 if (isRegExp(value)) {
701 return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
702 } else {
703 return ctx.stylize('[Object]', 'special');
704 }
705 }
706
707 ctx.seen.push(value);
708
709 var output;
710 if (array) {
711 output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
712 } else {
713 output = keys.map(function(key) {
714 return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
715 });
716 }
717
718 ctx.seen.pop();
719
720 return reduceToSingleString(output, base, braces);
721}
722
723
724function formatPrimitive(ctx, value) {
725 if (isUndefined(value))
726 return ctx.stylize('undefined', 'undefined');
727 if (isString(value)) {
728 var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
729 .replace(/'/g, "\\'")
730 .replace(/\\"/g, '"') + '\'';
731 return ctx.stylize(simple, 'string');
732 }
733 if (isNumber(value))
734 return ctx.stylize('' + value, 'number');
735 if (isBoolean(value))
736 return ctx.stylize('' + value, 'boolean');
737 // For some reason typeof null is "object", so special case here.
738 if (isNull(value))
739 return ctx.stylize('null', 'null');
740}
741
742
743function formatError(value) {
744 return '[' + Error.prototype.toString.call(value) + ']';
745}
746
747
748function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
749 var output = [];
750 for (var i = 0, l = value.length; i < l; ++i) {
751 if (hasOwnProperty(value, String(i))) {
752 output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
753 String(i), true));
754 } else {
755 output.push('');
756 }
757 }
758 keys.forEach(function(key) {
759 if (!key.match(/^\d+$/)) {
760 output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
761 key, true));
762 }
763 });
764 return output;
765}
766
767
768function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
769 var name, str, desc;
770 desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
771 if (desc.get) {
772 if (desc.set) {
773 str = ctx.stylize('[Getter/Setter]', 'special');
774 } else {
775 str = ctx.stylize('[Getter]', 'special');
776 }
777 } else {
778 if (desc.set) {
779 str = ctx.stylize('[Setter]', 'special');
780 }
781 }
782 if (!hasOwnProperty(visibleKeys, key)) {
783 name = '[' + key + ']';
784 }
785 if (!str) {
786 if (ctx.seen.indexOf(desc.value) < 0) {
787 if (isNull(recurseTimes)) {
788 str = formatValue(ctx, desc.value, null);
789 } else {
790 str = formatValue(ctx, desc.value, recurseTimes - 1);
791 }
792 if (str.indexOf('\n') > -1) {
793 if (array) {
794 str = str.split('\n').map(function(line) {
795 return ' ' + line;
796 }).join('\n').substr(2);
797 } else {
798 str = '\n' + str.split('\n').map(function(line) {
799 return ' ' + line;
800 }).join('\n');
801 }
802 }
803 } else {
804 str = ctx.stylize('[Circular]', 'special');
805 }
806 }
807 if (isUndefined(name)) {
808 if (array && key.match(/^\d+$/)) {
809 return str;
810 }
811 name = JSON.stringify('' + key);
812 if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
813 name = name.substr(1, name.length - 2);
814 name = ctx.stylize(name, 'name');
815 } else {
816 name = name.replace(/'/g, "\\'")
817 .replace(/\\"/g, '"')
818 .replace(/(^"|"$)/g, "'");
819 name = ctx.stylize(name, 'string');
820 }
821 }
822
823 return name + ': ' + str;
824}
825
826
827function reduceToSingleString(output, base, braces) {
828 var numLinesEst = 0;
829 var length = output.reduce(function(prev, cur) {
830 numLinesEst++;
831 if (cur.indexOf('\n') >= 0) numLinesEst++;
832 return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
833 }, 0);
834
835 if (length > 60) {
836 return braces[0] +
837 (base === '' ? '' : base + '\n ') +
838 ' ' +
839 output.join(',\n ') +
840 ' ' +
841 braces[1];
842 }
843
844 return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
845}
846
847
848// NOTE: These type checking functions intentionally don't use `instanceof`
849// because it is fragile and can be easily faked with `Object.create()`.
850function isArray(ar) {
851 return Array.isArray(ar);
852}
853exports.isArray = isArray;
854
855function isBoolean(arg) {
856 return typeof arg === 'boolean';
857}
858exports.isBoolean = isBoolean;
859
860function isNull(arg) {
861 return arg === null;
862}
863exports.isNull = isNull;
864
865function isNullOrUndefined(arg) {
866 return arg == null;
867}
868exports.isNullOrUndefined = isNullOrUndefined;
869
870function isNumber(arg) {
871 return typeof arg === 'number';
872}
873exports.isNumber = isNumber;
874
875function isString(arg) {
876 return typeof arg === 'string';
877}
878exports.isString = isString;
879
880function isSymbol(arg) {
881 return typeof arg === 'symbol';
882}
883exports.isSymbol = isSymbol;
884
885function isUndefined(arg) {
886 return arg === void 0;
887}
888exports.isUndefined = isUndefined;
889
890function isRegExp(re) {
891 return isObject(re) && objectToString(re) === '[object RegExp]';
892}
893exports.isRegExp = isRegExp;
894
895function isObject(arg) {
896 return typeof arg === 'object' && arg !== null;
897}
898exports.isObject = isObject;
899
900function isDate(d) {
901 return isObject(d) && objectToString(d) === '[object Date]';
902}
903exports.isDate = isDate;
904
905function isError(e) {
906 return isObject(e) &&
907 (objectToString(e) === '[object Error]' || e instanceof Error);
908}
909exports.isError = isError;
910
911function isFunction(arg) {
912 return typeof arg === 'function';
913}
914exports.isFunction = isFunction;
915
916function isPrimitive(arg) {
917 return arg === null ||
918 typeof arg === 'boolean' ||
919 typeof arg === 'number' ||
920 typeof arg === 'string' ||
921 typeof arg === 'symbol' || // ES6 symbol
922 typeof arg === 'undefined';
923}
924exports.isPrimitive = isPrimitive;
925
926exports.isBuffer = require('./support/isBuffer');
927
928function objectToString(o) {
929 return Object.prototype.toString.call(o);
930}
931
932
933function pad(n) {
934 return n < 10 ? '0' + n.toString(10) : n.toString(10);
935}
936
937
938var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
939 'Oct', 'Nov', 'Dec'];
940
941// 26 Feb 16:19:34
942function timestamp() {
943 var d = new Date();
944 var time = [pad(d.getHours()),
945 pad(d.getMinutes()),
946 pad(d.getSeconds())].join(':');
947 return [d.getDate(), months[d.getMonth()], time].join(' ');
948}
949
950
951// log is just a thin wrapper to console.log that prepends a timestamp
952exports.log = function() {
953 console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments));
954};
955
956
957/**
958 * Inherit the prototype methods from one constructor into another.
959 *
960 * The Function.prototype.inherits from lang.js rewritten as a standalone
961 * function (not on Function.prototype). NOTE: If this file is to be loaded
962 * during bootstrapping this function needs to be rewritten using some native
963 * functions as prototype setup using normal JavaScript does not work as
964 * expected during bootstrapping (see mirror.js in r114903).
965 *
966 * @param {function} ctor Constructor function which needs to inherit the
967 * prototype.
968 * @param {function} superCtor Constructor function to inherit prototype from.
969 */
970exports.inherits = require('inherits');
971
972exports._extend = function(origin, add) {
973 // Don't do anything if add isn't an object
974 if (!add || !isObject(add)) return origin;
975
976 var keys = Object.keys(add);
977 var i = keys.length;
978 while (i--) {
979 origin[keys[i]] = add[keys[i]];
980 }
981 return origin;
982};
983
984function hasOwnProperty(obj, prop) {
985 return Object.prototype.hasOwnProperty.call(obj, prop);
986}
987
988}).call(this,require("7YKIPe"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
989},{"./support/isBuffer":4,"7YKIPe":9,"inherits":3}],6:[function(require,module,exports){
990var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
991
992;(function (exports) {
993 'use strict';
994
995 var Arr = (typeof Uint8Array !== 'undefined')
996 ? Uint8Array
997 : Array
998
999 var PLUS = '+'.charCodeAt(0)
1000 var SLASH = '/'.charCodeAt(0)
1001 var NUMBER = '0'.charCodeAt(0)
1002 var LOWER = 'a'.charCodeAt(0)
1003 var UPPER = 'A'.charCodeAt(0)
1004 var PLUS_URL_SAFE = '-'.charCodeAt(0)
1005 var SLASH_URL_SAFE = '_'.charCodeAt(0)
1006
1007 function decode (elt) {
1008 var code = elt.charCodeAt(0)
1009 if (code === PLUS ||
1010 code === PLUS_URL_SAFE)
1011 return 62 // '+'
1012 if (code === SLASH ||
1013 code === SLASH_URL_SAFE)
1014 return 63 // '/'
1015 if (code < NUMBER)
1016 return -1 //no match
1017 if (code < NUMBER + 10)
1018 return code - NUMBER + 26 + 26
1019 if (code < UPPER + 26)
1020 return code - UPPER
1021 if (code < LOWER + 26)
1022 return code - LOWER + 26
1023 }
1024
1025 function b64ToByteArray (b64) {
1026 var i, j, l, tmp, placeHolders, arr
1027
1028 if (b64.length % 4 > 0) {
1029 throw new Error('Invalid string. Length must be a multiple of 4')
1030 }
1031
1032 // the number of equal signs (place holders)
1033 // if there are two placeholders, than the two characters before it
1034 // represent one byte
1035 // if there is only one, then the three characters before it represent 2 bytes
1036 // this is just a cheap hack to not do indexOf twice
1037 var len = b64.length
1038 placeHolders = '=' === b64.charAt(len - 2) ? 2 : '=' === b64.charAt(len - 1) ? 1 : 0
1039
1040 // base64 is 4/3 + up to two characters of the original data
1041 arr = new Arr(b64.length * 3 / 4 - placeHolders)
1042
1043 // if there are placeholders, only get up to the last complete 4 chars
1044 l = placeHolders > 0 ? b64.length - 4 : b64.length
1045
1046 var L = 0
1047
1048 function push (v) {
1049 arr[L++] = v
1050 }
1051
1052 for (i = 0, j = 0; i < l; i += 4, j += 3) {
1053 tmp = (decode(b64.charAt(i)) << 18) | (decode(b64.charAt(i + 1)) << 12) | (decode(b64.charAt(i + 2)) << 6) | decode(b64.charAt(i + 3))
1054 push((tmp & 0xFF0000) >> 16)
1055 push((tmp & 0xFF00) >> 8)
1056 push(tmp & 0xFF)
1057 }
1058
1059 if (placeHolders === 2) {
1060 tmp = (decode(b64.charAt(i)) << 2) | (decode(b64.charAt(i + 1)) >> 4)
1061 push(tmp & 0xFF)
1062 } else if (placeHolders === 1) {
1063 tmp = (decode(b64.charAt(i)) << 10) | (decode(b64.charAt(i + 1)) << 4) | (decode(b64.charAt(i + 2)) >> 2)
1064 push((tmp >> 8) & 0xFF)
1065 push(tmp & 0xFF)
1066 }
1067
1068 return arr
1069 }
1070
1071 function uint8ToBase64 (uint8) {
1072 var i,
1073 extraBytes = uint8.length % 3, // if we have 1 byte left, pad 2 bytes
1074 output = "",
1075 temp, length
1076
1077 function encode (num) {
1078 return lookup.charAt(num)
1079 }
1080
1081 function tripletToBase64 (num) {
1082 return encode(num >> 18 & 0x3F) + encode(num >> 12 & 0x3F) + encode(num >> 6 & 0x3F) + encode(num & 0x3F)
1083 }
1084
1085 // go through the array every three bytes, we'll deal with trailing stuff later
1086 for (i = 0, length = uint8.length - extraBytes; i < length; i += 3) {
1087 temp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2])
1088 output += tripletToBase64(temp)
1089 }
1090
1091 // pad the end with zeros, but make sure to not forget the extra bytes
1092 switch (extraBytes) {
1093 case 1:
1094 temp = uint8[uint8.length - 1]
1095 output += encode(temp >> 2)
1096 output += encode((temp << 4) & 0x3F)
1097 output += '=='
1098 break
1099 case 2:
1100 temp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1])
1101 output += encode(temp >> 10)
1102 output += encode((temp >> 4) & 0x3F)
1103 output += encode((temp << 2) & 0x3F)
1104 output += '='
1105 break
1106 }
1107
1108 return output
1109 }
1110
1111 exports.toByteArray = b64ToByteArray
1112 exports.fromByteArray = uint8ToBase64
1113}(typeof exports === 'undefined' ? (this.base64js = {}) : exports))
1114
1115},{}],7:[function(require,module,exports){
1116/*!
1117 * The buffer module from node.js, for the browser.
1118 *
1119 * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
1120 * @license MIT
1121 */
1122
1123var base64 = require('base64-js')
1124var ieee754 = require('ieee754')
1125
1126exports.Buffer = Buffer
1127exports.SlowBuffer = Buffer
1128exports.INSPECT_MAX_BYTES = 50
1129Buffer.poolSize = 8192
1130
1131/**
1132 * If `Buffer._useTypedArrays`:
1133 * === true Use Uint8Array implementation (fastest)
1134 * === false Use Object implementation (compatible down to IE6)
1135 */
1136Buffer._useTypedArrays = (function () {
1137 // Detect if browser supports Typed Arrays. Supported browsers are IE 10+, Firefox 4+,
1138 // Chrome 7+, Safari 5.1+, Opera 11.6+, iOS 4.2+. If the browser does not support adding
1139 // properties to `Uint8Array` instances, then that's the same as no `Uint8Array` support
1140 // because we need to be able to add all the node Buffer API methods. This is an issue
1141 // in Firefox 4-29. Now fixed: https://bugzilla.mozilla.org/show_bug.cgi?id=695438
1142 try {
1143 var buf = new ArrayBuffer(0)
1144 var arr = new Uint8Array(buf)
1145 arr.foo = function () { return 42 }
1146 return 42 === arr.foo() &&
1147 typeof arr.subarray === 'function' // Chrome 9-10 lack `subarray`
1148 } catch (e) {
1149 return false
1150 }
1151})()
1152
1153/**
1154 * Class: Buffer
1155 * =============
1156 *
1157 * The Buffer constructor returns instances of `Uint8Array` that are augmented
1158 * with function properties for all the node `Buffer` API functions. We use
1159 * `Uint8Array` so that square bracket notation works as expected -- it returns
1160 * a single octet.
1161 *
1162 * By augmenting the instances, we can avoid modifying the `Uint8Array`
1163 * prototype.
1164 */
1165function Buffer (subject, encoding, noZero) {
1166 if (!(this instanceof Buffer))
1167 return new Buffer(subject, encoding, noZero)
1168
1169 var type = typeof subject
1170
1171 // Workaround: node's base64 implementation allows for non-padded strings
1172 // while base64-js does not.
1173 if (encoding === 'base64' && type === 'string') {
1174 subject = stringtrim(subject)
1175 while (subject.length % 4 !== 0) {
1176 subject = subject + '='
1177 }
1178 }
1179
1180 // Find the length
1181 var length
1182 if (type === 'number')
1183 length = coerce(subject)
1184 else if (type === 'string')
1185 length = Buffer.byteLength(subject, encoding)
1186 else if (type === 'object')
1187 length = coerce(subject.length) // assume that object is array-like
1188 else
1189 throw new Error('First argument needs to be a number, array or string.')
1190
1191 var buf
1192 if (Buffer._useTypedArrays) {
1193 // Preferred: Return an augmented `Uint8Array` instance for best performance
1194 buf = Buffer._augment(new Uint8Array(length))
1195 } else {
1196 // Fallback: Return THIS instance of Buffer (created by `new`)
1197 buf = this
1198 buf.length = length
1199 buf._isBuffer = true
1200 }
1201
1202 var i
1203 if (Buffer._useTypedArrays && typeof subject.byteLength === 'number') {
1204 // Speed optimization -- use set if we're copying from a typed array
1205 buf._set(subject)
1206 } else if (isArrayish(subject)) {
1207 // Treat array-ish objects as a byte array
1208 for (i = 0; i < length; i++) {
1209 if (Buffer.isBuffer(subject))
1210 buf[i] = subject.readUInt8(i)
1211 else
1212 buf[i] = subject[i]
1213 }
1214 } else if (type === 'string') {
1215 buf.write(subject, 0, encoding)
1216 } else if (type === 'number' && !Buffer._useTypedArrays && !noZero) {
1217 for (i = 0; i < length; i++) {
1218 buf[i] = 0
1219 }
1220 }
1221
1222 return buf
1223}
1224
1225// STATIC METHODS
1226// ==============
1227
1228Buffer.isEncoding = function (encoding) {
1229 switch (String(encoding).toLowerCase()) {
1230 case 'hex':
1231 case 'utf8':
1232 case 'utf-8':
1233 case 'ascii':
1234 case 'binary':
1235 case 'base64':
1236 case 'raw':
1237 case 'ucs2':
1238 case 'ucs-2':
1239 case 'utf16le':
1240 case 'utf-16le':
1241 return true
1242 default:
1243 return false
1244 }
1245}
1246
1247Buffer.isBuffer = function (b) {
1248 return !!(b !== null && b !== undefined && b._isBuffer)
1249}
1250
1251Buffer.byteLength = function (str, encoding) {
1252 var ret
1253 str = str + ''
1254 switch (encoding || 'utf8') {
1255 case 'hex':
1256 ret = str.length / 2
1257 break
1258 case 'utf8':
1259 case 'utf-8':
1260 ret = utf8ToBytes(str).length
1261 break
1262 case 'ascii':
1263 case 'binary':
1264 case 'raw':
1265 ret = str.length
1266 break
1267 case 'base64':
1268 ret = base64ToBytes(str).length
1269 break
1270 case 'ucs2':
1271 case 'ucs-2':
1272 case 'utf16le':
1273 case 'utf-16le':
1274 ret = str.length * 2
1275 break
1276 default:
1277 throw new Error('Unknown encoding')
1278 }
1279 return ret
1280}
1281
1282Buffer.concat = function (list, totalLength) {
1283 assert(isArray(list), 'Usage: Buffer.concat(list, [totalLength])\n' +
1284 'list should be an Array.')
1285
1286 if (list.length === 0) {
1287 return new Buffer(0)
1288 } else if (list.length === 1) {
1289 return list[0]
1290 }
1291
1292 var i
1293 if (typeof totalLength !== 'number') {
1294 totalLength = 0
1295 for (i = 0; i < list.length; i++) {
1296 totalLength += list[i].length
1297 }
1298 }
1299
1300 var buf = new Buffer(totalLength)
1301 var pos = 0
1302 for (i = 0; i < list.length; i++) {
1303 var item = list[i]
1304 item.copy(buf, pos)
1305 pos += item.length
1306 }
1307 return buf
1308}
1309
1310// BUFFER INSTANCE METHODS
1311// =======================
1312
1313function _hexWrite (buf, string, offset, length) {
1314 offset = Number(offset) || 0
1315 var remaining = buf.length - offset
1316 if (!length) {
1317 length = remaining
1318 } else {
1319 length = Number(length)
1320 if (length > remaining) {
1321 length = remaining
1322 }
1323 }
1324
1325 // must be an even number of digits
1326 var strLen = string.length
1327 assert(strLen % 2 === 0, 'Invalid hex string')
1328
1329 if (length > strLen / 2) {
1330 length = strLen / 2
1331 }
1332 for (var i = 0; i < length; i++) {
1333 var byte = parseInt(string.substr(i * 2, 2), 16)
1334 assert(!isNaN(byte), 'Invalid hex string')
1335 buf[offset + i] = byte
1336 }
1337 Buffer._charsWritten = i * 2
1338 return i
1339}
1340
1341function _utf8Write (buf, string, offset, length) {
1342 var charsWritten = Buffer._charsWritten =
1343 blitBuffer(utf8ToBytes(string), buf, offset, length)
1344 return charsWritten
1345}
1346
1347function _asciiWrite (buf, string, offset, length) {
1348 var charsWritten = Buffer._charsWritten =
1349 blitBuffer(asciiToBytes(string), buf, offset, length)
1350 return charsWritten
1351}
1352
1353function _binaryWrite (buf, string, offset, length) {
1354 return _asciiWrite(buf, string, offset, length)
1355}
1356
1357function _base64Write (buf, string, offset, length) {
1358 var charsWritten = Buffer._charsWritten =
1359 blitBuffer(base64ToBytes(string), buf, offset, length)
1360 return charsWritten
1361}
1362
1363function _utf16leWrite (buf, string, offset, length) {
1364 var charsWritten = Buffer._charsWritten =
1365 blitBuffer(utf16leToBytes(string), buf, offset, length)
1366 return charsWritten
1367}
1368
1369Buffer.prototype.write = function (string, offset, length, encoding) {
1370 // Support both (string, offset, length, encoding)
1371 // and the legacy (string, encoding, offset, length)
1372 if (isFinite(offset)) {
1373 if (!isFinite(length)) {
1374 encoding = length
1375 length = undefined
1376 }
1377 } else { // legacy
1378 var swap = encoding
1379 encoding = offset
1380 offset = length
1381 length = swap
1382 }
1383
1384 offset = Number(offset) || 0
1385 var remaining = this.length - offset
1386 if (!length) {
1387 length = remaining
1388 } else {
1389 length = Number(length)
1390 if (length > remaining) {
1391 length = remaining
1392 }
1393 }
1394 encoding = String(encoding || 'utf8').toLowerCase()
1395
1396 var ret
1397 switch (encoding) {
1398 case 'hex':
1399 ret = _hexWrite(this, string, offset, length)
1400 break
1401 case 'utf8':
1402 case 'utf-8':
1403 ret = _utf8Write(this, string, offset, length)
1404 break
1405 case 'ascii':
1406 ret = _asciiWrite(this, string, offset, length)
1407 break
1408 case 'binary':
1409 ret = _binaryWrite(this, string, offset, length)
1410 break
1411 case 'base64':
1412 ret = _base64Write(this, string, offset, length)
1413 break
1414 case 'ucs2':
1415 case 'ucs-2':
1416 case 'utf16le':
1417 case 'utf-16le':
1418 ret = _utf16leWrite(this, string, offset, length)
1419 break
1420 default:
1421 throw new Error('Unknown encoding')
1422 }
1423 return ret
1424}
1425
1426Buffer.prototype.toString = function (encoding, start, end) {
1427 var self = this
1428
1429 encoding = String(encoding || 'utf8').toLowerCase()
1430 start = Number(start) || 0
1431 end = (end !== undefined)
1432 ? Number(end)
1433 : end = self.length
1434
1435 // Fastpath empty strings
1436 if (end === start)
1437 return ''
1438
1439 var ret
1440 switch (encoding) {
1441 case 'hex':
1442 ret = _hexSlice(self, start, end)
1443 break
1444 case 'utf8':
1445 case 'utf-8':
1446 ret = _utf8Slice(self, start, end)
1447 break
1448 case 'ascii':
1449 ret = _asciiSlice(self, start, end)
1450 break
1451 case 'binary':
1452 ret = _binarySlice(self, start, end)
1453 break
1454 case 'base64':
1455 ret = _base64Slice(self, start, end)
1456 break
1457 case 'ucs2':
1458 case 'ucs-2':
1459 case 'utf16le':
1460 case 'utf-16le':
1461 ret = _utf16leSlice(self, start, end)
1462 break
1463 default:
1464 throw new Error('Unknown encoding')
1465 }
1466 return ret
1467}
1468
1469Buffer.prototype.toJSON = function () {
1470 return {
1471 type: 'Buffer',
1472 data: Array.prototype.slice.call(this._arr || this, 0)
1473 }
1474}
1475
1476// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
1477Buffer.prototype.copy = function (target, target_start, start, end) {
1478 var source = this
1479
1480 if (!start) start = 0
1481 if (!end && end !== 0) end = this.length
1482 if (!target_start) target_start = 0
1483
1484 // Copy 0 bytes; we're done
1485 if (end === start) return
1486 if (target.length === 0 || source.length === 0) return
1487
1488 // Fatal error conditions
1489 assert(end >= start, 'sourceEnd < sourceStart')
1490 assert(target_start >= 0 && target_start < target.length,
1491 'targetStart out of bounds')
1492 assert(start >= 0 && start < source.length, 'sourceStart out of bounds')
1493 assert(end >= 0 && end <= source.length, 'sourceEnd out of bounds')
1494
1495 // Are we oob?
1496 if (end > this.length)
1497 end = this.length
1498 if (target.length - target_start < end - start)
1499 end = target.length - target_start + start
1500
1501 var len = end - start
1502
1503 if (len < 100 || !Buffer._useTypedArrays) {
1504 for (var i = 0; i < len; i++)
1505 target[i + target_start] = this[i + start]
1506 } else {
1507 target._set(this.subarray(start, start + len), target_start)
1508 }
1509}
1510
1511function _base64Slice (buf, start, end) {
1512 if (start === 0 && end === buf.length) {
1513 return base64.fromByteArray(buf)
1514 } else {
1515 return base64.fromByteArray(buf.slice(start, end))
1516 }
1517}
1518
1519function _utf8Slice (buf, start, end) {
1520 var res = ''
1521 var tmp = ''
1522 end = Math.min(buf.length, end)
1523
1524 for (var i = start; i < end; i++) {
1525 if (buf[i] <= 0x7F) {
1526 res += decodeUtf8Char(tmp) + String.fromCharCode(buf[i])
1527 tmp = ''
1528 } else {
1529 tmp += '%' + buf[i].toString(16)
1530 }
1531 }
1532
1533 return res + decodeUtf8Char(tmp)
1534}
1535
1536function _asciiSlice (buf, start, end) {
1537 var ret = ''
1538 end = Math.min(buf.length, end)
1539
1540 for (var i = start; i < end; i++)
1541 ret += String.fromCharCode(buf[i])
1542 return ret
1543}
1544
1545function _binarySlice (buf, start, end) {
1546 return _asciiSlice(buf, start, end)
1547}
1548
1549function _hexSlice (buf, start, end) {
1550 var len = buf.length
1551
1552 if (!start || start < 0) start = 0
1553 if (!end || end < 0 || end > len) end = len
1554
1555 var out = ''
1556 for (var i = start; i < end; i++) {
1557 out += toHex(buf[i])
1558 }
1559 return out
1560}
1561
1562function _utf16leSlice (buf, start, end) {
1563 var bytes = buf.slice(start, end)
1564 var res = ''
1565 for (var i = 0; i < bytes.length; i += 2) {
1566 res += String.fromCharCode(bytes[i] + bytes[i+1] * 256)
1567 }
1568 return res
1569}
1570
1571Buffer.prototype.slice = function (start, end) {
1572 var len = this.length
1573 start = clamp(start, len, 0)
1574 end = clamp(end, len, len)
1575
1576 if (Buffer._useTypedArrays) {
1577 return Buffer._augment(this.subarray(start, end))
1578 } else {
1579 var sliceLen = end - start
1580 var newBuf = new Buffer(sliceLen, undefined, true)
1581 for (var i = 0; i < sliceLen; i++) {
1582 newBuf[i] = this[i + start]
1583 }
1584 return newBuf
1585 }
1586}
1587
1588// `get` will be removed in Node 0.13+
1589Buffer.prototype.get = function (offset) {
1590 console.log('.get() is deprecated. Access using array indexes instead.')
1591 return this.readUInt8(offset)
1592}
1593
1594// `set` will be removed in Node 0.13+
1595Buffer.prototype.set = function (v, offset) {
1596 console.log('.set() is deprecated. Access using array indexes instead.')
1597 return this.writeUInt8(v, offset)
1598}
1599
1600Buffer.prototype.readUInt8 = function (offset, noAssert) {
1601 if (!noAssert) {
1602 assert(offset !== undefined && offset !== null, 'missing offset')
1603 assert(offset < this.length, 'Trying to read beyond buffer length')
1604 }
1605
1606 if (offset >= this.length)
1607 return
1608
1609 return this[offset]
1610}
1611
1612function _readUInt16 (buf, offset, littleEndian, noAssert) {
1613 if (!noAssert) {
1614 assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
1615 assert(offset !== undefined && offset !== null, 'missing offset')
1616 assert(offset + 1 < buf.length, 'Trying to read beyond buffer length')
1617 }
1618
1619 var len = buf.length
1620 if (offset >= len)
1621 return
1622
1623 var val
1624 if (littleEndian) {
1625 val = buf[offset]
1626 if (offset + 1 < len)
1627 val |= buf[offset + 1] << 8
1628 } else {
1629 val = buf[offset] << 8
1630 if (offset + 1 < len)
1631 val |= buf[offset + 1]
1632 }
1633 return val
1634}
1635
1636Buffer.prototype.readUInt16LE = function (offset, noAssert) {
1637 return _readUInt16(this, offset, true, noAssert)
1638}
1639
1640Buffer.prototype.readUInt16BE = function (offset, noAssert) {
1641 return _readUInt16(this, offset, false, noAssert)
1642}
1643
1644function _readUInt32 (buf, offset, littleEndian, noAssert) {
1645 if (!noAssert) {
1646 assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
1647 assert(offset !== undefined && offset !== null, 'missing offset')
1648 assert(offset + 3 < buf.length, 'Trying to read beyond buffer length')
1649 }
1650
1651 var len = buf.length
1652 if (offset >= len)
1653 return
1654
1655 var val
1656 if (littleEndian) {
1657 if (offset + 2 < len)
1658 val = buf[offset + 2] << 16
1659 if (offset + 1 < len)
1660 val |= buf[offset + 1] << 8
1661 val |= buf[offset]
1662 if (offset + 3 < len)
1663 val = val + (buf[offset + 3] << 24 >>> 0)
1664 } else {
1665 if (offset + 1 < len)
1666 val = buf[offset + 1] << 16
1667 if (offset + 2 < len)
1668 val |= buf[offset + 2] << 8
1669 if (offset + 3 < len)
1670 val |= buf[offset + 3]
1671 val = val + (buf[offset] << 24 >>> 0)
1672 }
1673 return val
1674}
1675
1676Buffer.prototype.readUInt32LE = function (offset, noAssert) {
1677 return _readUInt32(this, offset, true, noAssert)
1678}
1679
1680Buffer.prototype.readUInt32BE = function (offset, noAssert) {
1681 return _readUInt32(this, offset, false, noAssert)
1682}
1683
1684Buffer.prototype.readInt8 = function (offset, noAssert) {
1685 if (!noAssert) {
1686 assert(offset !== undefined && offset !== null,
1687 'missing offset')
1688 assert(offset < this.length, 'Trying to read beyond buffer length')
1689 }
1690
1691 if (offset >= this.length)
1692 return
1693
1694 var neg = this[offset] & 0x80
1695 if (neg)
1696 return (0xff - this[offset] + 1) * -1
1697 else
1698 return this[offset]
1699}
1700
1701function _readInt16 (buf, offset, littleEndian, noAssert) {
1702 if (!noAssert) {
1703 assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
1704 assert(offset !== undefined && offset !== null, 'missing offset')
1705 assert(offset + 1 < buf.length, 'Trying to read beyond buffer length')
1706 }
1707
1708 var len = buf.length
1709 if (offset >= len)
1710 return
1711
1712 var val = _readUInt16(buf, offset, littleEndian, true)
1713 var neg = val & 0x8000
1714 if (neg)
1715 return (0xffff - val + 1) * -1
1716 else
1717 return val
1718}
1719
1720Buffer.prototype.readInt16LE = function (offset, noAssert) {
1721 return _readInt16(this, offset, true, noAssert)
1722}
1723
1724Buffer.prototype.readInt16BE = function (offset, noAssert) {
1725 return _readInt16(this, offset, false, noAssert)
1726}
1727
1728function _readInt32 (buf, offset, littleEndian, noAssert) {
1729 if (!noAssert) {
1730 assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
1731 assert(offset !== undefined && offset !== null, 'missing offset')
1732 assert(offset + 3 < buf.length, 'Trying to read beyond buffer length')
1733 }
1734
1735 var len = buf.length
1736 if (offset >= len)
1737 return
1738
1739 var val = _readUInt32(buf, offset, littleEndian, true)
1740 var neg = val & 0x80000000
1741 if (neg)
1742 return (0xffffffff - val + 1) * -1
1743 else
1744 return val
1745}
1746
1747Buffer.prototype.readInt32LE = function (offset, noAssert) {
1748 return _readInt32(this, offset, true, noAssert)
1749}
1750
1751Buffer.prototype.readInt32BE = function (offset, noAssert) {
1752 return _readInt32(this, offset, false, noAssert)
1753}
1754
1755function _readFloat (buf, offset, littleEndian, noAssert) {
1756 if (!noAssert) {
1757 assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
1758 assert(offset + 3 < buf.length, 'Trying to read beyond buffer length')
1759 }
1760
1761 return ieee754.read(buf, offset, littleEndian, 23, 4)
1762}
1763
1764Buffer.prototype.readFloatLE = function (offset, noAssert) {
1765 return _readFloat(this, offset, true, noAssert)
1766}
1767
1768Buffer.prototype.readFloatBE = function (offset, noAssert) {
1769 return _readFloat(this, offset, false, noAssert)
1770}
1771
1772function _readDouble (buf, offset, littleEndian, noAssert) {
1773 if (!noAssert) {
1774 assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
1775 assert(offset + 7 < buf.length, 'Trying to read beyond buffer length')
1776 }
1777
1778 return ieee754.read(buf, offset, littleEndian, 52, 8)
1779}
1780
1781Buffer.prototype.readDoubleLE = function (offset, noAssert) {
1782 return _readDouble(this, offset, true, noAssert)
1783}
1784
1785Buffer.prototype.readDoubleBE = function (offset, noAssert) {
1786 return _readDouble(this, offset, false, noAssert)
1787}
1788
1789Buffer.prototype.writeUInt8 = function (value, offset, noAssert) {
1790 if (!noAssert) {
1791 assert(value !== undefined && value !== null, 'missing value')
1792 assert(offset !== undefined && offset !== null, 'missing offset')
1793 assert(offset < this.length, 'trying to write beyond buffer length')
1794 verifuint(value, 0xff)
1795 }
1796
1797 if (offset >= this.length) return
1798
1799 this[offset] = value
1800}
1801
1802function _writeUInt16 (buf, value, offset, littleEndian, noAssert) {
1803 if (!noAssert) {
1804 assert(value !== undefined && value !== null, 'missing value')
1805 assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
1806 assert(offset !== undefined && offset !== null, 'missing offset')
1807 assert(offset + 1 < buf.length, 'trying to write beyond buffer length')
1808 verifuint(value, 0xffff)
1809 }
1810
1811 var len = buf.length
1812 if (offset >= len)
1813 return
1814
1815 for (var i = 0, j = Math.min(len - offset, 2); i < j; i++) {
1816 buf[offset + i] =
1817 (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
1818 (littleEndian ? i : 1 - i) * 8
1819 }
1820}
1821
1822Buffer.prototype.writeUInt16LE = function (value, offset, noAssert) {
1823 _writeUInt16(this, value, offset, true, noAssert)
1824}
1825
1826Buffer.prototype.writeUInt16BE = function (value, offset, noAssert) {
1827 _writeUInt16(this, value, offset, false, noAssert)
1828}
1829
1830function _writeUInt32 (buf, value, offset, littleEndian, noAssert) {
1831 if (!noAssert) {
1832 assert(value !== undefined && value !== null, 'missing value')
1833 assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
1834 assert(offset !== undefined && offset !== null, 'missing offset')
1835 assert(offset + 3 < buf.length, 'trying to write beyond buffer length')
1836 verifuint(value, 0xffffffff)
1837 }
1838
1839 var len = buf.length
1840 if (offset >= len)
1841 return
1842
1843 for (var i = 0, j = Math.min(len - offset, 4); i < j; i++) {
1844 buf[offset + i] =
1845 (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff
1846 }
1847}
1848
1849Buffer.prototype.writeUInt32LE = function (value, offset, noAssert) {
1850 _writeUInt32(this, value, offset, true, noAssert)
1851}
1852
1853Buffer.prototype.writeUInt32BE = function (value, offset, noAssert) {
1854 _writeUInt32(this, value, offset, false, noAssert)
1855}
1856
1857Buffer.prototype.writeInt8 = function (value, offset, noAssert) {
1858 if (!noAssert) {
1859 assert(value !== undefined && value !== null, 'missing value')
1860 assert(offset !== undefined && offset !== null, 'missing offset')
1861 assert(offset < this.length, 'Trying to write beyond buffer length')
1862 verifsint(value, 0x7f, -0x80)
1863 }
1864
1865 if (offset >= this.length)
1866 return
1867
1868 if (value >= 0)
1869 this.writeUInt8(value, offset, noAssert)
1870 else
1871 this.writeUInt8(0xff + value + 1, offset, noAssert)
1872}
1873
1874function _writeInt16 (buf, value, offset, littleEndian, noAssert) {
1875 if (!noAssert) {
1876 assert(value !== undefined && value !== null, 'missing value')
1877 assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
1878 assert(offset !== undefined && offset !== null, 'missing offset')
1879 assert(offset + 1 < buf.length, 'Trying to write beyond buffer length')
1880 verifsint(value, 0x7fff, -0x8000)
1881 }
1882
1883 var len = buf.length
1884 if (offset >= len)
1885 return
1886
1887 if (value >= 0)
1888 _writeUInt16(buf, value, offset, littleEndian, noAssert)
1889 else
1890 _writeUInt16(buf, 0xffff + value + 1, offset, littleEndian, noAssert)
1891}
1892
1893Buffer.prototype.writeInt16LE = function (value, offset, noAssert) {
1894 _writeInt16(this, value, offset, true, noAssert)
1895}
1896
1897Buffer.prototype.writeInt16BE = function (value, offset, noAssert) {
1898 _writeInt16(this, value, offset, false, noAssert)
1899}
1900
1901function _writeInt32 (buf, value, offset, littleEndian, noAssert) {
1902 if (!noAssert) {
1903 assert(value !== undefined && value !== null, 'missing value')
1904 assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
1905 assert(offset !== undefined && offset !== null, 'missing offset')
1906 assert(offset + 3 < buf.length, 'Trying to write beyond buffer length')
1907 verifsint(value, 0x7fffffff, -0x80000000)
1908 }
1909
1910 var len = buf.length
1911 if (offset >= len)
1912 return
1913
1914 if (value >= 0)
1915 _writeUInt32(buf, value, offset, littleEndian, noAssert)
1916 else
1917 _writeUInt32(buf, 0xffffffff + value + 1, offset, littleEndian, noAssert)
1918}
1919
1920Buffer.prototype.writeInt32LE = function (value, offset, noAssert) {
1921 _writeInt32(this, value, offset, true, noAssert)
1922}
1923
1924Buffer.prototype.writeInt32BE = function (value, offset, noAssert) {
1925 _writeInt32(this, value, offset, false, noAssert)
1926}
1927
1928function _writeFloat (buf, value, offset, littleEndian, noAssert) {
1929 if (!noAssert) {
1930 assert(value !== undefined && value !== null, 'missing value')
1931 assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
1932 assert(offset !== undefined && offset !== null, 'missing offset')
1933 assert(offset + 3 < buf.length, 'Trying to write beyond buffer length')
1934 verifIEEE754(value, 3.4028234663852886e+38, -3.4028234663852886e+38)
1935 }
1936
1937 var len = buf.length
1938 if (offset >= len)
1939 return
1940
1941 ieee754.write(buf, value, offset, littleEndian, 23, 4)
1942}
1943
1944Buffer.prototype.writeFloatLE = function (value, offset, noAssert) {
1945 _writeFloat(this, value, offset, true, noAssert)
1946}
1947
1948Buffer.prototype.writeFloatBE = function (value, offset, noAssert) {
1949 _writeFloat(this, value, offset, false, noAssert)
1950}
1951
1952function _writeDouble (buf, value, offset, littleEndian, noAssert) {
1953 if (!noAssert) {
1954 assert(value !== undefined && value !== null, 'missing value')
1955 assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
1956 assert(offset !== undefined && offset !== null, 'missing offset')
1957 assert(offset + 7 < buf.length,
1958 'Trying to write beyond buffer length')
1959 verifIEEE754(value, 1.7976931348623157E+308, -1.7976931348623157E+308)
1960 }
1961
1962 var len = buf.length
1963 if (offset >= len)
1964 return
1965
1966 ieee754.write(buf, value, offset, littleEndian, 52, 8)
1967}
1968
1969Buffer.prototype.writeDoubleLE = function (value, offset, noAssert) {
1970 _writeDouble(this, value, offset, true, noAssert)
1971}
1972
1973Buffer.prototype.writeDoubleBE = function (value, offset, noAssert) {
1974 _writeDouble(this, value, offset, false, noAssert)
1975}
1976
1977// fill(value, start=0, end=buffer.length)
1978Buffer.prototype.fill = function (value, start, end) {
1979 if (!value) value = 0
1980 if (!start) start = 0
1981 if (!end) end = this.length
1982
1983 if (typeof value === 'string') {
1984 value = value.charCodeAt(0)
1985 }
1986
1987 assert(typeof value === 'number' && !isNaN(value), 'value is not a number')
1988 assert(end >= start, 'end < start')
1989
1990 // Fill 0 bytes; we're done
1991 if (end === start) return
1992 if (this.length === 0) return
1993
1994 assert(start >= 0 && start < this.length, 'start out of bounds')
1995 assert(end >= 0 && end <= this.length, 'end out of bounds')
1996
1997 for (var i = start; i < end; i++) {
1998 this[i] = value
1999 }
2000}
2001
2002Buffer.prototype.inspect = function () {
2003 var out = []
2004 var len = this.length
2005 for (var i = 0; i < len; i++) {
2006 out[i] = toHex(this[i])
2007 if (i === exports.INSPECT_MAX_BYTES) {
2008 out[i + 1] = '...'
2009 break
2010 }
2011 }
2012 return '<Buffer ' + out.join(' ') + '>'
2013}
2014
2015/**
2016 * Creates a new `ArrayBuffer` with the *copied* memory of the buffer instance.
2017 * Added in Node 0.12. Only available in browsers that support ArrayBuffer.
2018 */
2019Buffer.prototype.toArrayBuffer = function () {
2020 if (typeof Uint8Array !== 'undefined') {
2021 if (Buffer._useTypedArrays) {
2022 return (new Buffer(this)).buffer
2023 } else {
2024 var buf = new Uint8Array(this.length)
2025 for (var i = 0, len = buf.length; i < len; i += 1)
2026 buf[i] = this[i]
2027 return buf.buffer
2028 }
2029 } else {
2030 throw new Error('Buffer.toArrayBuffer not supported in this browser')
2031 }
2032}
2033
2034// HELPER FUNCTIONS
2035// ================
2036
2037function stringtrim (str) {
2038 if (str.trim) return str.trim()
2039 return str.replace(/^\s+|\s+$/g, '')
2040}
2041
2042var BP = Buffer.prototype
2043
2044/**
2045 * Augment a Uint8Array *instance* (not the Uint8Array class!) with Buffer methods
2046 */
2047Buffer._augment = function (arr) {
2048 arr._isBuffer = true
2049
2050 // save reference to original Uint8Array get/set methods before overwriting
2051 arr._get = arr.get
2052 arr._set = arr.set
2053
2054 // deprecated, will be removed in node 0.13+
2055 arr.get = BP.get
2056 arr.set = BP.set
2057
2058 arr.write = BP.write
2059 arr.toString = BP.toString
2060 arr.toLocaleString = BP.toString
2061 arr.toJSON = BP.toJSON
2062 arr.copy = BP.copy
2063 arr.slice = BP.slice
2064 arr.readUInt8 = BP.readUInt8
2065 arr.readUInt16LE = BP.readUInt16LE
2066 arr.readUInt16BE = BP.readUInt16BE
2067 arr.readUInt32LE = BP.readUInt32LE
2068 arr.readUInt32BE = BP.readUInt32BE
2069 arr.readInt8 = BP.readInt8
2070 arr.readInt16LE = BP.readInt16LE
2071 arr.readInt16BE = BP.readInt16BE
2072 arr.readInt32LE = BP.readInt32LE
2073 arr.readInt32BE = BP.readInt32BE
2074 arr.readFloatLE = BP.readFloatLE
2075 arr.readFloatBE = BP.readFloatBE
2076 arr.readDoubleLE = BP.readDoubleLE
2077 arr.readDoubleBE = BP.readDoubleBE
2078 arr.writeUInt8 = BP.writeUInt8
2079 arr.writeUInt16LE = BP.writeUInt16LE
2080 arr.writeUInt16BE = BP.writeUInt16BE
2081 arr.writeUInt32LE = BP.writeUInt32LE
2082 arr.writeUInt32BE = BP.writeUInt32BE
2083 arr.writeInt8 = BP.writeInt8
2084 arr.writeInt16LE = BP.writeInt16LE
2085 arr.writeInt16BE = BP.writeInt16BE
2086 arr.writeInt32LE = BP.writeInt32LE
2087 arr.writeInt32BE = BP.writeInt32BE
2088 arr.writeFloatLE = BP.writeFloatLE
2089 arr.writeFloatBE = BP.writeFloatBE
2090 arr.writeDoubleLE = BP.writeDoubleLE
2091 arr.writeDoubleBE = BP.writeDoubleBE
2092 arr.fill = BP.fill
2093 arr.inspect = BP.inspect
2094 arr.toArrayBuffer = BP.toArrayBuffer
2095
2096 return arr
2097}
2098
2099// slice(start, end)
2100function clamp (index, len, defaultValue) {
2101 if (typeof index !== 'number') return defaultValue
2102 index = ~~index; // Coerce to integer.
2103 if (index >= len) return len
2104 if (index >= 0) return index
2105 index += len
2106 if (index >= 0) return index
2107 return 0
2108}
2109
2110function coerce (length) {
2111 // Coerce length to a number (possibly NaN), round up
2112 // in case it's fractional (e.g. 123.456) then do a
2113 // double negate to coerce a NaN to 0. Easy, right?
2114 length = ~~Math.ceil(+length)
2115 return length < 0 ? 0 : length
2116}
2117
2118function isArray (subject) {
2119 return (Array.isArray || function (subject) {
2120 return Object.prototype.toString.call(subject) === '[object Array]'
2121 })(subject)
2122}
2123
2124function isArrayish (subject) {
2125 return isArray(subject) || Buffer.isBuffer(subject) ||
2126 subject && typeof subject === 'object' &&
2127 typeof subject.length === 'number'
2128}
2129
2130function toHex (n) {
2131 if (n < 16) return '0' + n.toString(16)
2132 return n.toString(16)
2133}
2134
2135function utf8ToBytes (str) {
2136 var byteArray = []
2137 for (var i = 0; i < str.length; i++) {
2138 var b = str.charCodeAt(i)
2139 if (b <= 0x7F)
2140 byteArray.push(str.charCodeAt(i))
2141 else {
2142 var start = i
2143 if (b >= 0xD800 && b <= 0xDFFF) i++
2144 var h = encodeURIComponent(str.slice(start, i+1)).substr(1).split('%')
2145 for (var j = 0; j < h.length; j++)
2146 byteArray.push(parseInt(h[j], 16))
2147 }
2148 }
2149 return byteArray
2150}
2151
2152function asciiToBytes (str) {
2153 var byteArray = []
2154 for (var i = 0; i < str.length; i++) {
2155 // Node's code seems to be doing this and not & 0x7F..
2156 byteArray.push(str.charCodeAt(i) & 0xFF)
2157 }
2158 return byteArray
2159}
2160
2161function utf16leToBytes (str) {
2162 var c, hi, lo
2163 var byteArray = []
2164 for (var i = 0; i < str.length; i++) {
2165 c = str.charCodeAt(i)
2166 hi = c >> 8
2167 lo = c % 256
2168 byteArray.push(lo)
2169 byteArray.push(hi)
2170 }
2171
2172 return byteArray
2173}
2174
2175function base64ToBytes (str) {
2176 return base64.toByteArray(str)
2177}
2178
2179function blitBuffer (src, dst, offset, length) {
2180 var pos
2181 for (var i = 0; i < length; i++) {
2182 if ((i + offset >= dst.length) || (i >= src.length))
2183 break
2184 dst[i + offset] = src[i]
2185 }
2186 return i
2187}
2188
2189function decodeUtf8Char (str) {
2190 try {
2191 return decodeURIComponent(str)
2192 } catch (err) {
2193 return String.fromCharCode(0xFFFD) // UTF 8 invalid char
2194 }
2195}
2196
2197/*
2198 * We have to make sure that the value is a valid integer. This means that it
2199 * is non-negative. It has no fractional component and that it does not
2200 * exceed the maximum allowed value.
2201 */
2202function verifuint (value, max) {
2203 assert(typeof value === 'number', 'cannot write a non-number as a number')
2204 assert(value >= 0, 'specified a negative value for writing an unsigned value')
2205 assert(value <= max, 'value is larger than maximum value for type')
2206 assert(Math.floor(value) === value, 'value has a fractional component')
2207}
2208
2209function verifsint (value, max, min) {
2210 assert(typeof value === 'number', 'cannot write a non-number as a number')
2211 assert(value <= max, 'value larger than maximum allowed value')
2212 assert(value >= min, 'value smaller than minimum allowed value')
2213 assert(Math.floor(value) === value, 'value has a fractional component')
2214}
2215
2216function verifIEEE754 (value, max, min) {
2217 assert(typeof value === 'number', 'cannot write a non-number as a number')
2218 assert(value <= max, 'value larger than maximum allowed value')
2219 assert(value >= min, 'value smaller than minimum allowed value')
2220}
2221
2222function assert (test, message) {
2223 if (!test) throw new Error(message || 'Failed assertion')
2224}
2225
2226},{"base64-js":6,"ieee754":18}],8:[function(require,module,exports){
2227// Copyright Joyent, Inc. and other Node contributors.
2228//
2229// Permission is hereby granted, free of charge, to any person obtaining a
2230// copy of this software and associated documentation files (the
2231// "Software"), to deal in the Software without restriction, including
2232// without limitation the rights to use, copy, modify, merge, publish,
2233// distribute, sublicense, and/or sell copies of the Software, and to permit
2234// persons to whom the Software is furnished to do so, subject to the
2235// following conditions:
2236//
2237// The above copyright notice and this permission notice shall be included
2238// in all copies or substantial portions of the Software.
2239//
2240// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
2241// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2242// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
2243// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
2244// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
2245// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
2246// USE OR OTHER DEALINGS IN THE SOFTWARE.
2247
2248function EventEmitter() {
2249 this._events = this._events || {};
2250 this._maxListeners = this._maxListeners || undefined;
2251}
2252module.exports = EventEmitter;
2253
2254// Backwards-compat with node 0.10.x
2255EventEmitter.EventEmitter = EventEmitter;
2256
2257EventEmitter.prototype._events = undefined;
2258EventEmitter.prototype._maxListeners = undefined;
2259
2260// By default EventEmitters will print a warning if more than 10 listeners are
2261// added to it. This is a useful default which helps finding memory leaks.
2262EventEmitter.defaultMaxListeners = 10;
2263
2264// Obviously not all Emitters should be limited to 10. This function allows
2265// that to be increased. Set to zero for unlimited.
2266EventEmitter.prototype.setMaxListeners = function(n) {
2267 if (!isNumber(n) || n < 0 || isNaN(n))
2268 throw TypeError('n must be a positive number');
2269 this._maxListeners = n;
2270 return this;
2271};
2272
2273EventEmitter.prototype.emit = function(type) {
2274 var er, handler, len, args, i, listeners;
2275
2276 if (!this._events)
2277 this._events = {};
2278
2279 // If there is no 'error' event listener then throw.
2280 if (type === 'error') {
2281 if (!this._events.error ||
2282 (isObject(this._events.error) && !this._events.error.length)) {
2283 er = arguments[1];
2284 if (er instanceof Error) {
2285 throw er; // Unhandled 'error' event
2286 }
2287 throw TypeError('Uncaught, unspecified "error" event.');
2288 }
2289 }
2290
2291 handler = this._events[type];
2292
2293 if (isUndefined(handler))
2294 return false;
2295
2296 if (isFunction(handler)) {
2297 switch (arguments.length) {
2298 // fast cases
2299 case 1:
2300 handler.call(this);
2301 break;
2302 case 2:
2303 handler.call(this, arguments[1]);
2304 break;
2305 case 3:
2306 handler.call(this, arguments[1], arguments[2]);
2307 break;
2308 // slower
2309 default:
2310 len = arguments.length;
2311 args = new Array(len - 1);
2312 for (i = 1; i < len; i++)
2313 args[i - 1] = arguments[i];
2314 handler.apply(this, args);
2315 }
2316 } else if (isObject(handler)) {
2317 len = arguments.length;
2318 args = new Array(len - 1);
2319 for (i = 1; i < len; i++)
2320 args[i - 1] = arguments[i];
2321
2322 listeners = handler.slice();
2323 len = listeners.length;
2324 for (i = 0; i < len; i++)
2325 listeners[i].apply(this, args);
2326 }
2327
2328 return true;
2329};
2330
2331EventEmitter.prototype.addListener = function(type, listener) {
2332 var m;
2333
2334 if (!isFunction(listener))
2335 throw TypeError('listener must be a function');
2336
2337 if (!this._events)
2338 this._events = {};
2339
2340 // To avoid recursion in the case that type === "newListener"! Before
2341 // adding it to the listeners, first emit "newListener".
2342 if (this._events.newListener)
2343 this.emit('newListener', type,
2344 isFunction(listener.listener) ?
2345 listener.listener : listener);
2346
2347 if (!this._events[type])
2348 // Optimize the case of one listener. Don't need the extra array object.
2349 this._events[type] = listener;
2350 else if (isObject(this._events[type]))
2351 // If we've already got an array, just append.
2352 this._events[type].push(listener);
2353 else
2354 // Adding the second element, need to change to array.
2355 this._events[type] = [this._events[type], listener];
2356
2357 // Check for listener leak
2358 if (isObject(this._events[type]) && !this._events[type].warned) {
2359 var m;
2360 if (!isUndefined(this._maxListeners)) {
2361 m = this._maxListeners;
2362 } else {
2363 m = EventEmitter.defaultMaxListeners;
2364 }
2365
2366 if (m && m > 0 && this._events[type].length > m) {
2367 this._events[type].warned = true;
2368 console.error('(node) warning: possible EventEmitter memory ' +
2369 'leak detected. %d listeners added. ' +
2370 'Use emitter.setMaxListeners() to increase limit.',
2371 this._events[type].length);
2372 if (typeof console.trace === 'function') {
2373 // not supported in IE 10
2374 console.trace();
2375 }
2376 }
2377 }
2378
2379 return this;
2380};
2381
2382EventEmitter.prototype.on = EventEmitter.prototype.addListener;
2383
2384EventEmitter.prototype.once = function(type, listener) {
2385 if (!isFunction(listener))
2386 throw TypeError('listener must be a function');
2387
2388 var fired = false;
2389
2390 function g() {
2391 this.removeListener(type, g);
2392
2393 if (!fired) {
2394 fired = true;
2395 listener.apply(this, arguments);
2396 }
2397 }
2398
2399 g.listener = listener;
2400 this.on(type, g);
2401
2402 return this;
2403};
2404
2405// emits a 'removeListener' event iff the listener was removed
2406EventEmitter.prototype.removeListener = function(type, listener) {
2407 var list, position, length, i;
2408
2409 if (!isFunction(listener))
2410 throw TypeError('listener must be a function');
2411
2412 if (!this._events || !this._events[type])
2413 return this;
2414
2415 list = this._events[type];
2416 length = list.length;
2417 position = -1;
2418
2419 if (list === listener ||
2420 (isFunction(list.listener) && list.listener === listener)) {
2421 delete this._events[type];
2422 if (this._events.removeListener)
2423 this.emit('removeListener', type, listener);
2424
2425 } else if (isObject(list)) {
2426 for (i = length; i-- > 0;) {
2427 if (list[i] === listener ||
2428 (list[i].listener && list[i].listener === listener)) {
2429 position = i;
2430 break;
2431 }
2432 }
2433
2434 if (position < 0)
2435 return this;
2436
2437 if (list.length === 1) {
2438 list.length = 0;
2439 delete this._events[type];
2440 } else {
2441 list.splice(position, 1);
2442 }
2443
2444 if (this._events.removeListener)
2445 this.emit('removeListener', type, listener);
2446 }
2447
2448 return this;
2449};
2450
2451EventEmitter.prototype.removeAllListeners = function(type) {
2452 var key, listeners;
2453
2454 if (!this._events)
2455 return this;
2456
2457 // not listening for removeListener, no need to emit
2458 if (!this._events.removeListener) {
2459 if (arguments.length === 0)
2460 this._events = {};
2461 else if (this._events[type])
2462 delete this._events[type];
2463 return this;
2464 }
2465
2466 // emit removeListener for all listeners on all events
2467 if (arguments.length === 0) {
2468 for (key in this._events) {
2469 if (key === 'removeListener') continue;
2470 this.removeAllListeners(key);
2471 }
2472 this.removeAllListeners('removeListener');
2473 this._events = {};
2474 return this;
2475 }
2476
2477 listeners = this._events[type];
2478
2479 if (isFunction(listeners)) {
2480 this.removeListener(type, listeners);
2481 } else {
2482 // LIFO order
2483 while (listeners.length)
2484 this.removeListener(type, listeners[listeners.length - 1]);
2485 }
2486 delete this._events[type];
2487
2488 return this;
2489};
2490
2491EventEmitter.prototype.listeners = function(type) {
2492 var ret;
2493 if (!this._events || !this._events[type])
2494 ret = [];
2495 else if (isFunction(this._events[type]))
2496 ret = [this._events[type]];
2497 else
2498 ret = this._events[type].slice();
2499 return ret;
2500};
2501
2502EventEmitter.listenerCount = function(emitter, type) {
2503 var ret;
2504 if (!emitter._events || !emitter._events[type])
2505 ret = 0;
2506 else if (isFunction(emitter._events[type]))
2507 ret = 1;
2508 else
2509 ret = emitter._events[type].length;
2510 return ret;
2511};
2512
2513function isFunction(arg) {
2514 return typeof arg === 'function';
2515}
2516
2517function isNumber(arg) {
2518 return typeof arg === 'number';
2519}
2520
2521function isObject(arg) {
2522 return typeof arg === 'object' && arg !== null;
2523}
2524
2525function isUndefined(arg) {
2526 return arg === void 0;
2527}
2528
2529},{}],9:[function(require,module,exports){
2530// shim for using process in browser
2531
2532var process = module.exports = {};
2533
2534process.nextTick = (function () {
2535 var canSetImmediate = typeof window !== 'undefined'
2536 && window.setImmediate;
2537 var canPost = typeof window !== 'undefined'
2538 && window.postMessage && window.addEventListener
2539 ;
2540
2541 if (canSetImmediate) {
2542 return function (f) { return window.setImmediate(f) };
2543 }
2544
2545 if (canPost) {
2546 var queue = [];
2547 window.addEventListener('message', function (ev) {
2548 var source = ev.source;
2549 if ((source === window || source === null) && ev.data === 'process-tick') {
2550 ev.stopPropagation();
2551 if (queue.length > 0) {
2552 var fn = queue.shift();
2553 fn();
2554 }
2555 }
2556 }, true);
2557
2558 return function nextTick(fn) {
2559 queue.push(fn);
2560 window.postMessage('process-tick', '*');
2561 };
2562 }
2563
2564 return function nextTick(fn) {
2565 setTimeout(fn, 0);
2566 };
2567})();
2568
2569process.title = 'browser';
2570process.browser = true;
2571process.env = {};
2572process.argv = [];
2573
2574function noop() {}
2575
2576process.on = noop;
2577process.addListener = noop;
2578process.once = noop;
2579process.off = noop;
2580process.removeListener = noop;
2581process.removeAllListeners = noop;
2582process.emit = noop;
2583
2584process.binding = function (name) {
2585 throw new Error('process.binding is not supported');
2586}
2587
2588// TODO(shtylman)
2589process.cwd = function () { return '/' };
2590process.chdir = function (dir) {
2591 throw new Error('process.chdir is not supported');
2592};
2593
2594},{}],10:[function(require,module,exports){
2595// Copyright Joyent, Inc. and other Node contributors.
2596//
2597// Permission is hereby granted, free of charge, to any person obtaining a
2598// copy of this software and associated documentation files (the
2599// "Software"), to deal in the Software without restriction, including
2600// without limitation the rights to use, copy, modify, merge, publish,
2601// distribute, sublicense, and/or sell copies of the Software, and to permit
2602// persons to whom the Software is furnished to do so, subject to the
2603// following conditions:
2604//
2605// The above copyright notice and this permission notice shall be included
2606// in all copies or substantial portions of the Software.
2607//
2608// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
2609// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2610// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
2611// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
2612// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
2613// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
2614// USE OR OTHER DEALINGS IN THE SOFTWARE.
2615
2616// a duplex stream is just a stream that is both readable and writable.
2617// Since JS doesn't have multiple prototypal inheritance, this class
2618// prototypally inherits from Readable, and then parasitically from
2619// Writable.
2620
2621module.exports = Duplex;
2622var inherits = require('inherits');
2623var setImmediate = require('process/browser.js').nextTick;
2624var Readable = require('./readable.js');
2625var Writable = require('./writable.js');
2626
2627inherits(Duplex, Readable);
2628
2629Duplex.prototype.write = Writable.prototype.write;
2630Duplex.prototype.end = Writable.prototype.end;
2631Duplex.prototype._write = Writable.prototype._write;
2632
2633function Duplex(options) {
2634 if (!(this instanceof Duplex))
2635 return new Duplex(options);
2636
2637 Readable.call(this, options);
2638 Writable.call(this, options);
2639
2640 if (options && options.readable === false)
2641 this.readable = false;
2642
2643 if (options && options.writable === false)
2644 this.writable = false;
2645
2646 this.allowHalfOpen = true;
2647 if (options && options.allowHalfOpen === false)
2648 this.allowHalfOpen = false;
2649
2650 this.once('end', onend);
2651}
2652
2653// the no-half-open enforcer
2654function onend() {
2655 // if we allow half-open state, or if the writable side ended,
2656 // then we're ok.
2657 if (this.allowHalfOpen || this._writableState.ended)
2658 return;
2659
2660 // no more data can be written.
2661 // But allow more writes to happen in this tick.
2662 var self = this;
2663 setImmediate(function () {
2664 self.end();
2665 });
2666}
2667
2668},{"./readable.js":14,"./writable.js":16,"inherits":19,"process/browser.js":12}],11:[function(require,module,exports){
2669// Copyright Joyent, Inc. and other Node contributors.
2670//
2671// Permission is hereby granted, free of charge, to any person obtaining a
2672// copy of this software and associated documentation files (the
2673// "Software"), to deal in the Software without restriction, including
2674// without limitation the rights to use, copy, modify, merge, publish,
2675// distribute, sublicense, and/or sell copies of the Software, and to permit
2676// persons to whom the Software is furnished to do so, subject to the
2677// following conditions:
2678//
2679// The above copyright notice and this permission notice shall be included
2680// in all copies or substantial portions of the Software.
2681//
2682// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
2683// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2684// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
2685// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
2686// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
2687// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
2688// USE OR OTHER DEALINGS IN THE SOFTWARE.
2689
2690module.exports = Stream;
2691
2692var EE = require('events').EventEmitter;
2693var inherits = require('inherits');
2694
2695inherits(Stream, EE);
2696Stream.Readable = require('./readable.js');
2697Stream.Writable = require('./writable.js');
2698Stream.Duplex = require('./duplex.js');
2699Stream.Transform = require('./transform.js');
2700Stream.PassThrough = require('./passthrough.js');
2701
2702// Backwards-compat with node 0.4.x
2703Stream.Stream = Stream;
2704
2705
2706
2707// old-style streams. Note that the pipe method (the only relevant
2708// part of this class) is overridden in the Readable class.
2709
2710function Stream() {
2711 EE.call(this);
2712}
2713
2714Stream.prototype.pipe = function(dest, options) {
2715 var source = this;
2716
2717 function ondata(chunk) {
2718 if (dest.writable) {
2719 if (false === dest.write(chunk) && source.pause) {
2720 source.pause();
2721 }
2722 }
2723 }
2724
2725 source.on('data', ondata);
2726
2727 function ondrain() {
2728 if (source.readable && source.resume) {
2729 source.resume();
2730 }
2731 }
2732
2733 dest.on('drain', ondrain);
2734
2735 // If the 'end' option is not supplied, dest.end() will be called when
2736 // source gets the 'end' or 'close' events. Only dest.end() once.
2737 if (!dest._isStdio && (!options || options.end !== false)) {
2738 source.on('end', onend);
2739 source.on('close', onclose);
2740 }
2741
2742 var didOnEnd = false;
2743 function onend() {
2744 if (didOnEnd) return;
2745 didOnEnd = true;
2746
2747 dest.end();
2748 }
2749
2750
2751 function onclose() {
2752 if (didOnEnd) return;
2753 didOnEnd = true;
2754
2755 if (typeof dest.destroy === 'function') dest.destroy();
2756 }
2757
2758 // don't leave dangling pipes when there are errors.
2759 function onerror(er) {
2760 cleanup();
2761 if (EE.listenerCount(this, 'error') === 0) {
2762 throw er; // Unhandled stream error in pipe.
2763 }
2764 }
2765
2766 source.on('error', onerror);
2767 dest.on('error', onerror);
2768
2769 // remove all the event listeners that were added.
2770 function cleanup() {
2771 source.removeListener('data', ondata);
2772 dest.removeListener('drain', ondrain);
2773
2774 source.removeListener('end', onend);
2775 source.removeListener('close', onclose);
2776
2777 source.removeListener('error', onerror);
2778 dest.removeListener('error', onerror);
2779
2780 source.removeListener('end', cleanup);
2781 source.removeListener('close', cleanup);
2782
2783 dest.removeListener('close', cleanup);
2784 }
2785
2786 source.on('end', cleanup);
2787 source.on('close', cleanup);
2788
2789 dest.on('close', cleanup);
2790
2791 dest.emit('pipe', source);
2792
2793 // Allow for unix-like usage: A.pipe(B).pipe(C)
2794 return dest;
2795};
2796
2797},{"./duplex.js":10,"./passthrough.js":13,"./readable.js":14,"./transform.js":15,"./writable.js":16,"events":8,"inherits":19}],12:[function(require,module,exports){
2798// shim for using process in browser
2799
2800var process = module.exports = {};
2801
2802process.nextTick = (function () {
2803 var canSetImmediate = typeof window !== 'undefined'
2804 && window.setImmediate;
2805 var canPost = typeof window !== 'undefined'
2806 && window.postMessage && window.addEventListener
2807 ;
2808
2809 if (canSetImmediate) {
2810 return function (f) { return window.setImmediate(f) };
2811 }
2812
2813 if (canPost) {
2814 var queue = [];
2815 window.addEventListener('message', function (ev) {
2816 var source = ev.source;
2817 if ((source === window || source === null) && ev.data === 'process-tick') {
2818 ev.stopPropagation();
2819 if (queue.length > 0) {
2820 var fn = queue.shift();
2821 fn();
2822 }
2823 }
2824 }, true);
2825
2826 return function nextTick(fn) {
2827 queue.push(fn);
2828 window.postMessage('process-tick', '*');
2829 };
2830 }
2831
2832 return function nextTick(fn) {
2833 setTimeout(fn, 0);
2834 };
2835})();
2836
2837process.title = 'browser';
2838process.browser = true;
2839process.env = {};
2840process.argv = [];
2841
2842process.binding = function (name) {
2843 throw new Error('process.binding is not supported');
2844}
2845
2846// TODO(shtylman)
2847process.cwd = function () { return '/' };
2848process.chdir = function (dir) {
2849 throw new Error('process.chdir is not supported');
2850};
2851
2852},{}],13:[function(require,module,exports){
2853// Copyright Joyent, Inc. and other Node contributors.
2854//
2855// Permission is hereby granted, free of charge, to any person obtaining a
2856// copy of this software and associated documentation files (the
2857// "Software"), to deal in the Software without restriction, including
2858// without limitation the rights to use, copy, modify, merge, publish,
2859// distribute, sublicense, and/or sell copies of the Software, and to permit
2860// persons to whom the Software is furnished to do so, subject to the
2861// following conditions:
2862//
2863// The above copyright notice and this permission notice shall be included
2864// in all copies or substantial portions of the Software.
2865//
2866// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
2867// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2868// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
2869// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
2870// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
2871// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
2872// USE OR OTHER DEALINGS IN THE SOFTWARE.
2873
2874// a passthrough stream.
2875// basically just the most minimal sort of Transform stream.
2876// Every written chunk gets output as-is.
2877
2878module.exports = PassThrough;
2879
2880var Transform = require('./transform.js');
2881var inherits = require('inherits');
2882inherits(PassThrough, Transform);
2883
2884function PassThrough(options) {
2885 if (!(this instanceof PassThrough))
2886 return new PassThrough(options);
2887
2888 Transform.call(this, options);
2889}
2890
2891PassThrough.prototype._transform = function(chunk, encoding, cb) {
2892 cb(null, chunk);
2893};
2894
2895},{"./transform.js":15,"inherits":19}],14:[function(require,module,exports){
2896(function (process){
2897// Copyright Joyent, Inc. and other Node contributors.
2898//
2899// Permission is hereby granted, free of charge, to any person obtaining a
2900// copy of this software and associated documentation files (the
2901// "Software"), to deal in the Software without restriction, including
2902// without limitation the rights to use, copy, modify, merge, publish,
2903// distribute, sublicense, and/or sell copies of the Software, and to permit
2904// persons to whom the Software is furnished to do so, subject to the
2905// following conditions:
2906//
2907// The above copyright notice and this permission notice shall be included
2908// in all copies or substantial portions of the Software.
2909//
2910// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
2911// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2912// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
2913// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
2914// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
2915// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
2916// USE OR OTHER DEALINGS IN THE SOFTWARE.
2917
2918module.exports = Readable;
2919Readable.ReadableState = ReadableState;
2920
2921var EE = require('events').EventEmitter;
2922var Stream = require('./index.js');
2923var Buffer = require('buffer').Buffer;
2924var setImmediate = require('process/browser.js').nextTick;
2925var StringDecoder;
2926
2927var inherits = require('inherits');
2928inherits(Readable, Stream);
2929
2930function ReadableState(options, stream) {
2931 options = options || {};
2932
2933 // the point at which it stops calling _read() to fill the buffer
2934 // Note: 0 is a valid value, means "don't call _read preemptively ever"
2935 var hwm = options.highWaterMark;
2936 this.highWaterMark = (hwm || hwm === 0) ? hwm : 16 * 1024;
2937
2938 // cast to ints.
2939 this.highWaterMark = ~~this.highWaterMark;
2940
2941 this.buffer = [];
2942 this.length = 0;
2943 this.pipes = null;
2944 this.pipesCount = 0;
2945 this.flowing = false;
2946 this.ended = false;
2947 this.endEmitted = false;
2948 this.reading = false;
2949
2950 // In streams that never have any data, and do push(null) right away,
2951 // the consumer can miss the 'end' event if they do some I/O before
2952 // consuming the stream. So, we don't emit('end') until some reading
2953 // happens.
2954 this.calledRead = false;
2955
2956 // a flag to be able to tell if the onwrite cb is called immediately,
2957 // or on a later tick. We set this to true at first, becuase any
2958 // actions that shouldn't happen until "later" should generally also
2959 // not happen before the first write call.
2960 this.sync = true;
2961
2962 // whenever we return null, then we set a flag to say
2963 // that we're awaiting a 'readable' event emission.
2964 this.needReadable = false;
2965 this.emittedReadable = false;
2966 this.readableListening = false;
2967
2968
2969 // object stream flag. Used to make read(n) ignore n and to
2970 // make all the buffer merging and length checks go away
2971 this.objectMode = !!options.objectMode;
2972
2973 // Crypto is kind of old and crusty. Historically, its default string
2974 // encoding is 'binary' so we have to make this configurable.
2975 // Everything else in the universe uses 'utf8', though.
2976 this.defaultEncoding = options.defaultEncoding || 'utf8';
2977
2978 // when piping, we only care about 'readable' events that happen
2979 // after read()ing all the bytes and not getting any pushback.
2980 this.ranOut = false;
2981
2982 // the number of writers that are awaiting a drain event in .pipe()s
2983 this.awaitDrain = 0;
2984
2985 // if true, a maybeReadMore has been scheduled
2986 this.readingMore = false;
2987
2988 this.decoder = null;
2989 this.encoding = null;
2990 if (options.encoding) {
2991 if (!StringDecoder)
2992 StringDecoder = require('string_decoder').StringDecoder;
2993 this.decoder = new StringDecoder(options.encoding);
2994 this.encoding = options.encoding;
2995 }
2996}
2997
2998function Readable(options) {
2999 if (!(this instanceof Readable))
3000 return new Readable(options);
3001
3002 this._readableState = new ReadableState(options, this);
3003
3004 // legacy
3005 this.readable = true;
3006
3007 Stream.call(this);
3008}
3009
3010// Manually shove something into the read() buffer.
3011// This returns true if the highWaterMark has not been hit yet,
3012// similar to how Writable.write() returns true if you should
3013// write() some more.
3014Readable.prototype.push = function(chunk, encoding) {
3015 var state = this._readableState;
3016
3017 if (typeof chunk === 'string' && !state.objectMode) {
3018 encoding = encoding || state.defaultEncoding;
3019 if (encoding !== state.encoding) {
3020 chunk = new Buffer(chunk, encoding);
3021 encoding = '';
3022 }
3023 }
3024
3025 return readableAddChunk(this, state, chunk, encoding, false);
3026};
3027
3028// Unshift should *always* be something directly out of read()
3029Readable.prototype.unshift = function(chunk) {
3030 var state = this._readableState;
3031 return readableAddChunk(this, state, chunk, '', true);
3032};
3033
3034function readableAddChunk(stream, state, chunk, encoding, addToFront) {
3035 var er = chunkInvalid(state, chunk);
3036 if (er) {
3037 stream.emit('error', er);
3038 } else if (chunk === null || chunk === undefined) {
3039 state.reading = false;
3040 if (!state.ended)
3041 onEofChunk(stream, state);
3042 } else if (state.objectMode || chunk && chunk.length > 0) {
3043 if (state.ended && !addToFront) {
3044 var e = new Error('stream.push() after EOF');
3045 stream.emit('error', e);
3046 } else if (state.endEmitted && addToFront) {
3047 var e = new Error('stream.unshift() after end event');
3048 stream.emit('error', e);
3049 } else {
3050 if (state.decoder && !addToFront && !encoding)
3051 chunk = state.decoder.write(chunk);
3052
3053 // update the buffer info.
3054 state.length += state.objectMode ? 1 : chunk.length;
3055 if (addToFront) {
3056 state.buffer.unshift(chunk);
3057 } else {
3058 state.reading = false;
3059 state.buffer.push(chunk);
3060 }
3061
3062 if (state.needReadable)
3063 emitReadable(stream);
3064
3065 maybeReadMore(stream, state);
3066 }
3067 } else if (!addToFront) {
3068 state.reading = false;
3069 }
3070
3071 return needMoreData(state);
3072}
3073
3074
3075
3076// if it's past the high water mark, we can push in some more.
3077// Also, if we have no data yet, we can stand some
3078// more bytes. This is to work around cases where hwm=0,
3079// such as the repl. Also, if the push() triggered a
3080// readable event, and the user called read(largeNumber) such that
3081// needReadable was set, then we ought to push more, so that another
3082// 'readable' event will be triggered.
3083function needMoreData(state) {
3084 return !state.ended &&
3085 (state.needReadable ||
3086 state.length < state.highWaterMark ||
3087 state.length === 0);
3088}
3089
3090// backwards compatibility.
3091Readable.prototype.setEncoding = function(enc) {
3092 if (!StringDecoder)
3093 StringDecoder = require('string_decoder').StringDecoder;
3094 this._readableState.decoder = new StringDecoder(enc);
3095 this._readableState.encoding = enc;
3096};
3097
3098// Don't raise the hwm > 128MB
3099var MAX_HWM = 0x800000;
3100function roundUpToNextPowerOf2(n) {
3101 if (n >= MAX_HWM) {
3102 n = MAX_HWM;
3103 } else {
3104 // Get the next highest power of 2
3105 n--;
3106 for (var p = 1; p < 32; p <<= 1) n |= n >> p;
3107 n++;
3108 }
3109 return n;
3110}
3111
3112function howMuchToRead(n, state) {
3113 if (state.length === 0 && state.ended)
3114 return 0;
3115
3116 if (state.objectMode)
3117 return n === 0 ? 0 : 1;
3118
3119 if (isNaN(n) || n === null) {
3120 // only flow one buffer at a time
3121 if (state.flowing && state.buffer.length)
3122 return state.buffer[0].length;
3123 else
3124 return state.length;
3125 }
3126
3127 if (n <= 0)
3128 return 0;
3129
3130 // If we're asking for more than the target buffer level,
3131 // then raise the water mark. Bump up to the next highest
3132 // power of 2, to prevent increasing it excessively in tiny
3133 // amounts.
3134 if (n > state.highWaterMark)
3135 state.highWaterMark = roundUpToNextPowerOf2(n);
3136
3137 // don't have that much. return null, unless we've ended.
3138 if (n > state.length) {
3139 if (!state.ended) {
3140 state.needReadable = true;
3141 return 0;
3142 } else
3143 return state.length;
3144 }
3145
3146 return n;
3147}
3148
3149// you can override either this method, or the async _read(n) below.
3150Readable.prototype.read = function(n) {
3151 var state = this._readableState;
3152 state.calledRead = true;
3153 var nOrig = n;
3154
3155 if (typeof n !== 'number' || n > 0)
3156 state.emittedReadable = false;
3157
3158 // if we're doing read(0) to trigger a readable event, but we
3159 // already have a bunch of data in the buffer, then just trigger
3160 // the 'readable' event and move on.
3161 if (n === 0 &&
3162 state.needReadable &&
3163 (state.length >= state.highWaterMark || state.ended)) {
3164 emitReadable(this);
3165 return null;
3166 }
3167
3168 n = howMuchToRead(n, state);
3169
3170 // if we've ended, and we're now clear, then finish it up.
3171 if (n === 0 && state.ended) {
3172 if (state.length === 0)
3173 endReadable(this);
3174 return null;
3175 }
3176
3177 // All the actual chunk generation logic needs to be
3178 // *below* the call to _read. The reason is that in certain
3179 // synthetic stream cases, such as passthrough streams, _read
3180 // may be a completely synchronous operation which may change
3181 // the state of the read buffer, providing enough data when
3182 // before there was *not* enough.
3183 //
3184 // So, the steps are:
3185 // 1. Figure out what the state of things will be after we do
3186 // a read from the buffer.
3187 //
3188 // 2. If that resulting state will trigger a _read, then call _read.
3189 // Note that this may be asynchronous, or synchronous. Yes, it is
3190 // deeply ugly to write APIs this way, but that still doesn't mean
3191 // that the Readable class should behave improperly, as streams are
3192 // designed to be sync/async agnostic.
3193 // Take note if the _read call is sync or async (ie, if the read call
3194 // has returned yet), so that we know whether or not it's safe to emit
3195 // 'readable' etc.
3196 //
3197 // 3. Actually pull the requested chunks out of the buffer and return.
3198
3199 // if we need a readable event, then we need to do some reading.
3200 var doRead = state.needReadable;
3201
3202 // if we currently have less than the highWaterMark, then also read some
3203 if (state.length - n <= state.highWaterMark)
3204 doRead = true;
3205
3206 // however, if we've ended, then there's no point, and if we're already
3207 // reading, then it's unnecessary.
3208 if (state.ended || state.reading)
3209 doRead = false;
3210
3211 if (doRead) {
3212 state.reading = true;
3213 state.sync = true;
3214 // if the length is currently zero, then we *need* a readable event.
3215 if (state.length === 0)
3216 state.needReadable = true;
3217 // call internal read method
3218 this._read(state.highWaterMark);
3219 state.sync = false;
3220 }
3221
3222 // If _read called its callback synchronously, then `reading`
3223 // will be false, and we need to re-evaluate how much data we
3224 // can return to the user.
3225 if (doRead && !state.reading)
3226 n = howMuchToRead(nOrig, state);
3227
3228 var ret;
3229 if (n > 0)
3230 ret = fromList(n, state);
3231 else
3232 ret = null;
3233
3234 if (ret === null) {
3235 state.needReadable = true;
3236 n = 0;
3237 }
3238
3239 state.length -= n;
3240
3241 // If we have nothing in the buffer, then we want to know
3242 // as soon as we *do* get something into the buffer.
3243 if (state.length === 0 && !state.ended)
3244 state.needReadable = true;
3245
3246 // If we happened to read() exactly the remaining amount in the
3247 // buffer, and the EOF has been seen at this point, then make sure
3248 // that we emit 'end' on the very next tick.
3249 if (state.ended && !state.endEmitted && state.length === 0)
3250 endReadable(this);
3251
3252 return ret;
3253};
3254
3255function chunkInvalid(state, chunk) {
3256 var er = null;
3257 if (!Buffer.isBuffer(chunk) &&
3258 'string' !== typeof chunk &&
3259 chunk !== null &&
3260 chunk !== undefined &&
3261 !state.objectMode &&
3262 !er) {
3263 er = new TypeError('Invalid non-string/buffer chunk');
3264 }
3265 return er;
3266}
3267
3268
3269function onEofChunk(stream, state) {
3270 if (state.decoder && !state.ended) {
3271 var chunk = state.decoder.end();
3272 if (chunk && chunk.length) {
3273 state.buffer.push(chunk);
3274 state.length += state.objectMode ? 1 : chunk.length;
3275 }
3276 }
3277 state.ended = true;
3278
3279 // if we've ended and we have some data left, then emit
3280 // 'readable' now to make sure it gets picked up.
3281 if (state.length > 0)
3282 emitReadable(stream);
3283 else
3284 endReadable(stream);
3285}
3286
3287// Don't emit readable right away in sync mode, because this can trigger
3288// another read() call => stack overflow. This way, it might trigger
3289// a nextTick recursion warning, but that's not so bad.
3290function emitReadable(stream) {
3291 var state = stream._readableState;
3292 state.needReadable = false;
3293 if (state.emittedReadable)
3294 return;
3295
3296 state.emittedReadable = true;
3297 if (state.sync)
3298 setImmediate(function() {
3299 emitReadable_(stream);
3300 });
3301 else
3302 emitReadable_(stream);
3303}
3304
3305function emitReadable_(stream) {
3306 stream.emit('readable');
3307}
3308
3309
3310// at this point, the user has presumably seen the 'readable' event,
3311// and called read() to consume some data. that may have triggered
3312// in turn another _read(n) call, in which case reading = true if
3313// it's in progress.
3314// However, if we're not ended, or reading, and the length < hwm,
3315// then go ahead and try to read some more preemptively.
3316function maybeReadMore(stream, state) {
3317 if (!state.readingMore) {
3318 state.readingMore = true;
3319 setImmediate(function() {
3320 maybeReadMore_(stream, state);
3321 });
3322 }
3323}
3324
3325function maybeReadMore_(stream, state) {
3326 var len = state.length;
3327 while (!state.reading && !state.flowing && !state.ended &&
3328 state.length < state.highWaterMark) {
3329 stream.read(0);
3330 if (len === state.length)
3331 // didn't get any data, stop spinning.
3332 break;
3333 else
3334 len = state.length;
3335 }
3336 state.readingMore = false;
3337}
3338
3339// abstract method. to be overridden in specific implementation classes.
3340// call cb(er, data) where data is <= n in length.
3341// for virtual (non-string, non-buffer) streams, "length" is somewhat
3342// arbitrary, and perhaps not very meaningful.
3343Readable.prototype._read = function(n) {
3344 this.emit('error', new Error('not implemented'));
3345};
3346
3347Readable.prototype.pipe = function(dest, pipeOpts) {
3348 var src = this;
3349 var state = this._readableState;
3350
3351 switch (state.pipesCount) {
3352 case 0:
3353 state.pipes = dest;
3354 break;
3355 case 1:
3356 state.pipes = [state.pipes, dest];
3357 break;
3358 default:
3359 state.pipes.push(dest);
3360 break;
3361 }
3362 state.pipesCount += 1;
3363
3364 var doEnd = (!pipeOpts || pipeOpts.end !== false) &&
3365 dest !== process.stdout &&
3366 dest !== process.stderr;
3367
3368 var endFn = doEnd ? onend : cleanup;
3369 if (state.endEmitted)
3370 setImmediate(endFn);
3371 else
3372 src.once('end', endFn);
3373
3374 dest.on('unpipe', onunpipe);
3375 function onunpipe(readable) {
3376 if (readable !== src) return;
3377 cleanup();
3378 }
3379
3380 function onend() {
3381 dest.end();
3382 }
3383
3384 // when the dest drains, it reduces the awaitDrain counter
3385 // on the source. This would be more elegant with a .once()
3386 // handler in flow(), but adding and removing repeatedly is
3387 // too slow.
3388 var ondrain = pipeOnDrain(src);
3389 dest.on('drain', ondrain);
3390
3391 function cleanup() {
3392 // cleanup event handlers once the pipe is broken
3393 dest.removeListener('close', onclose);
3394 dest.removeListener('finish', onfinish);
3395 dest.removeListener('drain', ondrain);
3396 dest.removeListener('error', onerror);
3397 dest.removeListener('unpipe', onunpipe);
3398 src.removeListener('end', onend);
3399 src.removeListener('end', cleanup);
3400
3401 // if the reader is waiting for a drain event from this
3402 // specific writer, then it would cause it to never start
3403 // flowing again.
3404 // So, if this is awaiting a drain, then we just call it now.
3405 // If we don't know, then assume that we are waiting for one.
3406 if (!dest._writableState || dest._writableState.needDrain)
3407 ondrain();
3408 }
3409
3410 // if the dest has an error, then stop piping into it.
3411 // however, don't suppress the throwing behavior for this.
3412 // check for listeners before emit removes one-time listeners.
3413 var errListeners = EE.listenerCount(dest, 'error');
3414 function onerror(er) {
3415 unpipe();
3416 if (errListeners === 0 && EE.listenerCount(dest, 'error') === 0)
3417 dest.emit('error', er);
3418 }
3419 dest.once('error', onerror);
3420
3421 // Both close and finish should trigger unpipe, but only once.
3422 function onclose() {
3423 dest.removeListener('finish', onfinish);
3424 unpipe();
3425 }
3426 dest.once('close', onclose);
3427 function onfinish() {
3428 dest.removeListener('close', onclose);
3429 unpipe();
3430 }
3431 dest.once('finish', onfinish);
3432
3433 function unpipe() {
3434 src.unpipe(dest);
3435 }
3436
3437 // tell the dest that it's being piped to
3438 dest.emit('pipe', src);
3439
3440 // start the flow if it hasn't been started already.
3441 if (!state.flowing) {
3442 // the handler that waits for readable events after all
3443 // the data gets sucked out in flow.
3444 // This would be easier to follow with a .once() handler
3445 // in flow(), but that is too slow.
3446 this.on('readable', pipeOnReadable);
3447
3448 state.flowing = true;
3449 setImmediate(function() {
3450 flow(src);
3451 });
3452 }
3453
3454 return dest;
3455};
3456
3457function pipeOnDrain(src) {
3458 return function() {
3459 var dest = this;
3460 var state = src._readableState;
3461 state.awaitDrain--;
3462 if (state.awaitDrain === 0)
3463 flow(src);
3464 };
3465}
3466
3467function flow(src) {
3468 var state = src._readableState;
3469 var chunk;
3470 state.awaitDrain = 0;
3471
3472 function write(dest, i, list) {
3473 var written = dest.write(chunk);
3474 if (false === written) {
3475 state.awaitDrain++;
3476 }
3477 }
3478
3479 while (state.pipesCount && null !== (chunk = src.read())) {
3480
3481 if (state.pipesCount === 1)
3482 write(state.pipes, 0, null);
3483 else
3484 forEach(state.pipes, write);
3485
3486 src.emit('data', chunk);
3487
3488 // if anyone needs a drain, then we have to wait for that.
3489 if (state.awaitDrain > 0)
3490 return;
3491 }
3492
3493 // if every destination was unpiped, either before entering this
3494 // function, or in the while loop, then stop flowing.
3495 //
3496 // NB: This is a pretty rare edge case.
3497 if (state.pipesCount === 0) {
3498 state.flowing = false;
3499
3500 // if there were data event listeners added, then switch to old mode.
3501 if (EE.listenerCount(src, 'data') > 0)
3502 emitDataEvents(src);
3503 return;
3504 }
3505
3506 // at this point, no one needed a drain, so we just ran out of data
3507 // on the next readable event, start it over again.
3508 state.ranOut = true;
3509}
3510
3511function pipeOnReadable() {
3512 if (this._readableState.ranOut) {
3513 this._readableState.ranOut = false;
3514 flow(this);
3515 }
3516}
3517
3518
3519Readable.prototype.unpipe = function(dest) {
3520 var state = this._readableState;
3521
3522 // if we're not piping anywhere, then do nothing.
3523 if (state.pipesCount === 0)
3524 return this;
3525
3526 // just one destination. most common case.
3527 if (state.pipesCount === 1) {
3528 // passed in one, but it's not the right one.
3529 if (dest && dest !== state.pipes)
3530 return this;
3531
3532 if (!dest)
3533 dest = state.pipes;
3534
3535 // got a match.
3536 state.pipes = null;
3537 state.pipesCount = 0;
3538 this.removeListener('readable', pipeOnReadable);
3539 state.flowing = false;
3540 if (dest)
3541 dest.emit('unpipe', this);
3542 return this;
3543 }
3544
3545 // slow case. multiple pipe destinations.
3546
3547 if (!dest) {
3548 // remove all.
3549 var dests = state.pipes;
3550 var len = state.pipesCount;
3551 state.pipes = null;
3552 state.pipesCount = 0;
3553 this.removeListener('readable', pipeOnReadable);
3554 state.flowing = false;
3555
3556 for (var i = 0; i < len; i++)
3557 dests[i].emit('unpipe', this);
3558 return this;
3559 }
3560
3561 // try to find the right one.
3562 var i = indexOf(state.pipes, dest);
3563 if (i === -1)
3564 return this;
3565
3566 state.pipes.splice(i, 1);
3567 state.pipesCount -= 1;
3568 if (state.pipesCount === 1)
3569 state.pipes = state.pipes[0];
3570
3571 dest.emit('unpipe', this);
3572
3573 return this;
3574};
3575
3576// set up data events if they are asked for
3577// Ensure readable listeners eventually get something
3578Readable.prototype.on = function(ev, fn) {
3579 var res = Stream.prototype.on.call(this, ev, fn);
3580
3581 if (ev === 'data' && !this._readableState.flowing)
3582 emitDataEvents(this);
3583
3584 if (ev === 'readable' && this.readable) {
3585 var state = this._readableState;
3586 if (!state.readableListening) {
3587 state.readableListening = true;
3588 state.emittedReadable = false;
3589 state.needReadable = true;
3590 if (!state.reading) {
3591 this.read(0);
3592 } else if (state.length) {
3593 emitReadable(this, state);
3594 }
3595 }
3596 }
3597
3598 return res;
3599};
3600Readable.prototype.addListener = Readable.prototype.on;
3601
3602// pause() and resume() are remnants of the legacy readable stream API
3603// If the user uses them, then switch into old mode.
3604Readable.prototype.resume = function() {
3605 emitDataEvents(this);
3606 this.read(0);
3607 this.emit('resume');
3608};
3609
3610Readable.prototype.pause = function() {
3611 emitDataEvents(this, true);
3612 this.emit('pause');
3613};
3614
3615function emitDataEvents(stream, startPaused) {
3616 var state = stream._readableState;
3617
3618 if (state.flowing) {
3619 // https://github.com/isaacs/readable-stream/issues/16
3620 throw new Error('Cannot switch to old mode now.');
3621 }
3622
3623 var paused = startPaused || false;
3624 var readable = false;
3625
3626 // convert to an old-style stream.
3627 stream.readable = true;
3628 stream.pipe = Stream.prototype.pipe;
3629 stream.on = stream.addListener = Stream.prototype.on;
3630
3631 stream.on('readable', function() {
3632 readable = true;
3633
3634 var c;
3635 while (!paused && (null !== (c = stream.read())))
3636 stream.emit('data', c);
3637
3638 if (c === null) {
3639 readable = false;
3640 stream._readableState.needReadable = true;
3641 }
3642 });
3643
3644 stream.pause = function() {
3645 paused = true;
3646 this.emit('pause');
3647 };
3648
3649 stream.resume = function() {
3650 paused = false;
3651 if (readable)
3652 setImmediate(function() {
3653 stream.emit('readable');
3654 });
3655 else
3656 this.read(0);
3657 this.emit('resume');
3658 };
3659
3660 // now make it start, just in case it hadn't already.
3661 stream.emit('readable');
3662}
3663
3664// wrap an old-style stream as the async data source.
3665// This is *not* part of the readable stream interface.
3666// It is an ugly unfortunate mess of history.
3667Readable.prototype.wrap = function(stream) {
3668 var state = this._readableState;
3669 var paused = false;
3670
3671 var self = this;
3672 stream.on('end', function() {
3673 if (state.decoder && !state.ended) {
3674 var chunk = state.decoder.end();
3675 if (chunk && chunk.length)
3676 self.push(chunk);
3677 }
3678
3679 self.push(null);
3680 });
3681
3682 stream.on('data', function(chunk) {
3683 if (state.decoder)
3684 chunk = state.decoder.write(chunk);
3685 if (!chunk || !state.objectMode && !chunk.length)
3686 return;
3687
3688 var ret = self.push(chunk);
3689 if (!ret) {
3690 paused = true;
3691 stream.pause();
3692 }
3693 });
3694
3695 // proxy all the other methods.
3696 // important when wrapping filters and duplexes.
3697 for (var i in stream) {
3698 if (typeof stream[i] === 'function' &&
3699 typeof this[i] === 'undefined') {
3700 this[i] = function(method) { return function() {
3701 return stream[method].apply(stream, arguments);
3702 }}(i);
3703 }
3704 }
3705
3706 // proxy certain important events.
3707 var events = ['error', 'close', 'destroy', 'pause', 'resume'];
3708 forEach(events, function(ev) {
3709 stream.on(ev, function (x) {
3710 return self.emit.apply(self, ev, x);
3711 });
3712 });
3713
3714 // when we try to consume some more bytes, simply unpause the
3715 // underlying stream.
3716 self._read = function(n) {
3717 if (paused) {
3718 paused = false;
3719 stream.resume();
3720 }
3721 };
3722
3723 return self;
3724};
3725
3726
3727
3728// exposed for testing purposes only.
3729Readable._fromList = fromList;
3730
3731// Pluck off n bytes from an array of buffers.
3732// Length is the combined lengths of all the buffers in the list.
3733function fromList(n, state) {
3734 var list = state.buffer;
3735 var length = state.length;
3736 var stringMode = !!state.decoder;
3737 var objectMode = !!state.objectMode;
3738 var ret;
3739
3740 // nothing in the list, definitely empty.
3741 if (list.length === 0)
3742 return null;
3743
3744 if (length === 0)
3745 ret = null;
3746 else if (objectMode)
3747 ret = list.shift();
3748 else if (!n || n >= length) {
3749 // read it all, truncate the array.
3750 if (stringMode)
3751 ret = list.join('');
3752 else
3753 ret = Buffer.concat(list, length);
3754 list.length = 0;
3755 } else {
3756 // read just some of it.
3757 if (n < list[0].length) {
3758 // just take a part of the first list item.
3759 // slice is the same for buffers and strings.
3760 var buf = list[0];
3761 ret = buf.slice(0, n);
3762 list[0] = buf.slice(n);
3763 } else if (n === list[0].length) {
3764 // first list is a perfect match
3765 ret = list.shift();
3766 } else {
3767 // complex case.
3768 // we have enough to cover it, but it spans past the first buffer.
3769 if (stringMode)
3770 ret = '';
3771 else
3772 ret = new Buffer(n);
3773
3774 var c = 0;
3775 for (var i = 0, l = list.length; i < l && c < n; i++) {
3776 var buf = list[0];
3777 var cpy = Math.min(n - c, buf.length);
3778
3779 if (stringMode)
3780 ret += buf.slice(0, cpy);
3781 else
3782 buf.copy(ret, c, 0, cpy);
3783
3784 if (cpy < buf.length)
3785 list[0] = buf.slice(cpy);
3786 else
3787 list.shift();
3788
3789 c += cpy;
3790 }
3791 }
3792 }
3793
3794 return ret;
3795}
3796
3797function endReadable(stream) {
3798 var state = stream._readableState;
3799
3800 // If we get here before consuming all the bytes, then that is a
3801 // bug in node. Should never happen.
3802 if (state.length > 0)
3803 throw new Error('endReadable called on non-empty stream');
3804
3805 if (!state.endEmitted && state.calledRead) {
3806 state.ended = true;
3807 setImmediate(function() {
3808 // Check that we didn't get one last unshift.
3809 if (!state.endEmitted && state.length === 0) {
3810 state.endEmitted = true;
3811 stream.readable = false;
3812 stream.emit('end');
3813 }
3814 });
3815 }
3816}
3817
3818function forEach (xs, f) {
3819 for (var i = 0, l = xs.length; i < l; i++) {
3820 f(xs[i], i);
3821 }
3822}
3823
3824function indexOf (xs, x) {
3825 for (var i = 0, l = xs.length; i < l; i++) {
3826 if (xs[i] === x) return i;
3827 }
3828 return -1;
3829}
3830
3831}).call(this,require("7YKIPe"))
3832},{"./index.js":11,"7YKIPe":9,"buffer":7,"events":8,"inherits":19,"process/browser.js":12,"string_decoder":17}],15:[function(require,module,exports){
3833// Copyright Joyent, Inc. and other Node contributors.
3834//
3835// Permission is hereby granted, free of charge, to any person obtaining a
3836// copy of this software and associated documentation files (the
3837// "Software"), to deal in the Software without restriction, including
3838// without limitation the rights to use, copy, modify, merge, publish,
3839// distribute, sublicense, and/or sell copies of the Software, and to permit
3840// persons to whom the Software is furnished to do so, subject to the
3841// following conditions:
3842//
3843// The above copyright notice and this permission notice shall be included
3844// in all copies or substantial portions of the Software.
3845//
3846// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
3847// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
3848// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
3849// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
3850// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
3851// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
3852// USE OR OTHER DEALINGS IN THE SOFTWARE.
3853
3854// a transform stream is a readable/writable stream where you do
3855// something with the data. Sometimes it's called a "filter",
3856// but that's not a great name for it, since that implies a thing where
3857// some bits pass through, and others are simply ignored. (That would
3858// be a valid example of a transform, of course.)
3859//
3860// While the output is causally related to the input, it's not a
3861// necessarily symmetric or synchronous transformation. For example,
3862// a zlib stream might take multiple plain-text writes(), and then
3863// emit a single compressed chunk some time in the future.
3864//
3865// Here's how this works:
3866//
3867// The Transform stream has all the aspects of the readable and writable
3868// stream classes. When you write(chunk), that calls _write(chunk,cb)
3869// internally, and returns false if there's a lot of pending writes
3870// buffered up. When you call read(), that calls _read(n) until
3871// there's enough pending readable data buffered up.
3872//
3873// In a transform stream, the written data is placed in a buffer. When
3874// _read(n) is called, it transforms the queued up data, calling the
3875// buffered _write cb's as it consumes chunks. If consuming a single
3876// written chunk would result in multiple output chunks, then the first
3877// outputted bit calls the readcb, and subsequent chunks just go into
3878// the read buffer, and will cause it to emit 'readable' if necessary.
3879//
3880// This way, back-pressure is actually determined by the reading side,
3881// since _read has to be called to start processing a new chunk. However,
3882// a pathological inflate type of transform can cause excessive buffering
3883// here. For example, imagine a stream where every byte of input is
3884// interpreted as an integer from 0-255, and then results in that many
3885// bytes of output. Writing the 4 bytes {ff,ff,ff,ff} would result in
3886// 1kb of data being output. In this case, you could write a very small
3887// amount of input, and end up with a very large amount of output. In
3888// such a pathological inflating mechanism, there'd be no way to tell
3889// the system to stop doing the transform. A single 4MB write could
3890// cause the system to run out of memory.
3891//
3892// However, even in such a pathological case, only a single written chunk
3893// would be consumed, and then the rest would wait (un-transformed) until
3894// the results of the previous transformed chunk were consumed.
3895
3896module.exports = Transform;
3897
3898var Duplex = require('./duplex.js');
3899var inherits = require('inherits');
3900inherits(Transform, Duplex);
3901
3902
3903function TransformState(options, stream) {
3904 this.afterTransform = function(er, data) {
3905 return afterTransform(stream, er, data);
3906 };
3907
3908 this.needTransform = false;
3909 this.transforming = false;
3910 this.writecb = null;
3911 this.writechunk = null;
3912}
3913
3914function afterTransform(stream, er, data) {
3915 var ts = stream._transformState;
3916 ts.transforming = false;
3917
3918 var cb = ts.writecb;
3919
3920 if (!cb)
3921 return stream.emit('error', new Error('no writecb in Transform class'));
3922
3923 ts.writechunk = null;
3924 ts.writecb = null;
3925
3926 if (data !== null && data !== undefined)
3927 stream.push(data);
3928
3929 if (cb)
3930 cb(er);
3931
3932 var rs = stream._readableState;
3933 rs.reading = false;
3934 if (rs.needReadable || rs.length < rs.highWaterMark) {
3935 stream._read(rs.highWaterMark);
3936 }
3937}
3938
3939
3940function Transform(options) {
3941 if (!(this instanceof Transform))
3942 return new Transform(options);
3943
3944 Duplex.call(this, options);
3945
3946 var ts = this._transformState = new TransformState(options, this);
3947
3948 // when the writable side finishes, then flush out anything remaining.
3949 var stream = this;
3950
3951 // start out asking for a readable event once data is transformed.
3952 this._readableState.needReadable = true;
3953
3954 // we have implemented the _read method, and done the other things
3955 // that Readable wants before the first _read call, so unset the
3956 // sync guard flag.
3957 this._readableState.sync = false;
3958
3959 this.once('finish', function() {
3960 if ('function' === typeof this._flush)
3961 this._flush(function(er) {
3962 done(stream, er);
3963 });
3964 else
3965 done(stream);
3966 });
3967}
3968
3969Transform.prototype.push = function(chunk, encoding) {
3970 this._transformState.needTransform = false;
3971 return Duplex.prototype.push.call(this, chunk, encoding);
3972};
3973
3974// This is the part where you do stuff!
3975// override this function in implementation classes.
3976// 'chunk' is an input chunk.
3977//
3978// Call `push(newChunk)` to pass along transformed output
3979// to the readable side. You may call 'push' zero or more times.
3980//
3981// Call `cb(err)` when you are done with this chunk. If you pass
3982// an error, then that'll put the hurt on the whole operation. If you
3983// never call cb(), then you'll never get another chunk.
3984Transform.prototype._transform = function(chunk, encoding, cb) {
3985 throw new Error('not implemented');
3986};
3987
3988Transform.prototype._write = function(chunk, encoding, cb) {
3989 var ts = this._transformState;
3990 ts.writecb = cb;
3991 ts.writechunk = chunk;
3992 ts.writeencoding = encoding;
3993 if (!ts.transforming) {
3994 var rs = this._readableState;
3995 if (ts.needTransform ||
3996 rs.needReadable ||
3997 rs.length < rs.highWaterMark)
3998 this._read(rs.highWaterMark);
3999 }
4000};
4001
4002// Doesn't matter what the args are here.
4003// _transform does all the work.
4004// That we got here means that the readable side wants more data.
4005Transform.prototype._read = function(n) {
4006 var ts = this._transformState;
4007
4008 if (ts.writechunk && ts.writecb && !ts.transforming) {
4009 ts.transforming = true;
4010 this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
4011 } else {
4012 // mark that we need a transform, so that any data that comes in
4013 // will get processed, now that we've asked for it.
4014 ts.needTransform = true;
4015 }
4016};
4017
4018
4019function done(stream, er) {
4020 if (er)
4021 return stream.emit('error', er);
4022
4023 // if there's nothing in the write buffer, then that means
4024 // that nothing more will ever be provided
4025 var ws = stream._writableState;
4026 var rs = stream._readableState;
4027 var ts = stream._transformState;
4028
4029 if (ws.length)
4030 throw new Error('calling transform done when ws.length != 0');
4031
4032 if (ts.transforming)
4033 throw new Error('calling transform done when still transforming');
4034
4035 return stream.push(null);
4036}
4037
4038},{"./duplex.js":10,"inherits":19}],16:[function(require,module,exports){
4039// Copyright Joyent, Inc. and other Node contributors.
4040//
4041// Permission is hereby granted, free of charge, to any person obtaining a
4042// copy of this software and associated documentation files (the
4043// "Software"), to deal in the Software without restriction, including
4044// without limitation the rights to use, copy, modify, merge, publish,
4045// distribute, sublicense, and/or sell copies of the Software, and to permit
4046// persons to whom the Software is furnished to do so, subject to the
4047// following conditions:
4048//
4049// The above copyright notice and this permission notice shall be included
4050// in all copies or substantial portions of the Software.
4051//
4052// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
4053// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
4054// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
4055// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
4056// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
4057// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
4058// USE OR OTHER DEALINGS IN THE SOFTWARE.
4059
4060// A bit simpler than readable streams.
4061// Implement an async ._write(chunk, cb), and it'll handle all
4062// the drain event emission and buffering.
4063
4064module.exports = Writable;
4065Writable.WritableState = WritableState;
4066
4067var isUint8Array = typeof Uint8Array !== 'undefined'
4068 ? function (x) { return x instanceof Uint8Array }
4069 : function (x) {
4070 return x && x.constructor && x.constructor.name === 'Uint8Array'
4071 }
4072;
4073var isArrayBuffer = typeof ArrayBuffer !== 'undefined'
4074 ? function (x) { return x instanceof ArrayBuffer }
4075 : function (x) {
4076 return x && x.constructor && x.constructor.name === 'ArrayBuffer'
4077 }
4078;
4079
4080var inherits = require('inherits');
4081var Stream = require('./index.js');
4082var setImmediate = require('process/browser.js').nextTick;
4083var Buffer = require('buffer').Buffer;
4084
4085inherits(Writable, Stream);
4086
4087function WriteReq(chunk, encoding, cb) {
4088 this.chunk = chunk;
4089 this.encoding = encoding;
4090 this.callback = cb;
4091}
4092
4093function WritableState(options, stream) {
4094 options = options || {};
4095
4096 // the point at which write() starts returning false
4097 // Note: 0 is a valid value, means that we always return false if
4098 // the entire buffer is not flushed immediately on write()
4099 var hwm = options.highWaterMark;
4100 this.highWaterMark = (hwm || hwm === 0) ? hwm : 16 * 1024;
4101
4102 // object stream flag to indicate whether or not this stream
4103 // contains buffers or objects.
4104 this.objectMode = !!options.objectMode;
4105
4106 // cast to ints.
4107 this.highWaterMark = ~~this.highWaterMark;
4108
4109 this.needDrain = false;
4110 // at the start of calling end()
4111 this.ending = false;
4112 // when end() has been called, and returned
4113 this.ended = false;
4114 // when 'finish' is emitted
4115 this.finished = false;
4116
4117 // should we decode strings into buffers before passing to _write?
4118 // this is here so that some node-core streams can optimize string
4119 // handling at a lower level.
4120 var noDecode = options.decodeStrings === false;
4121 this.decodeStrings = !noDecode;
4122
4123 // Crypto is kind of old and crusty. Historically, its default string
4124 // encoding is 'binary' so we have to make this configurable.
4125 // Everything else in the universe uses 'utf8', though.
4126 this.defaultEncoding = options.defaultEncoding || 'utf8';
4127
4128 // not an actual buffer we keep track of, but a measurement
4129 // of how much we're waiting to get pushed to some underlying
4130 // socket or file.
4131 this.length = 0;
4132
4133 // a flag to see when we're in the middle of a write.
4134 this.writing = false;
4135
4136 // a flag to be able to tell if the onwrite cb is called immediately,
4137 // or on a later tick. We set this to true at first, becuase any
4138 // actions that shouldn't happen until "later" should generally also
4139 // not happen before the first write call.
4140 this.sync = true;
4141
4142 // a flag to know if we're processing previously buffered items, which
4143 // may call the _write() callback in the same tick, so that we don't
4144 // end up in an overlapped onwrite situation.
4145 this.bufferProcessing = false;
4146
4147 // the callback that's passed to _write(chunk,cb)
4148 this.onwrite = function(er) {
4149 onwrite(stream, er);
4150 };
4151
4152 // the callback that the user supplies to write(chunk,encoding,cb)
4153 this.writecb = null;
4154
4155 // the amount that is being written when _write is called.
4156 this.writelen = 0;
4157
4158 this.buffer = [];
4159}
4160
4161function Writable(options) {
4162 // Writable ctor is applied to Duplexes, though they're not
4163 // instanceof Writable, they're instanceof Readable.
4164 if (!(this instanceof Writable) && !(this instanceof Stream.Duplex))
4165 return new Writable(options);
4166
4167 this._writableState = new WritableState(options, this);
4168
4169 // legacy.
4170 this.writable = true;
4171
4172 Stream.call(this);
4173}
4174
4175// Otherwise people can pipe Writable streams, which is just wrong.
4176Writable.prototype.pipe = function() {
4177 this.emit('error', new Error('Cannot pipe. Not readable.'));
4178};
4179
4180
4181function writeAfterEnd(stream, state, cb) {
4182 var er = new Error('write after end');
4183 // TODO: defer error events consistently everywhere, not just the cb
4184 stream.emit('error', er);
4185 setImmediate(function() {
4186 cb(er);
4187 });
4188}
4189
4190// If we get something that is not a buffer, string, null, or undefined,
4191// and we're not in objectMode, then that's an error.
4192// Otherwise stream chunks are all considered to be of length=1, and the
4193// watermarks determine how many objects to keep in the buffer, rather than
4194// how many bytes or characters.
4195function validChunk(stream, state, chunk, cb) {
4196 var valid = true;
4197 if (!Buffer.isBuffer(chunk) &&
4198 'string' !== typeof chunk &&
4199 chunk !== null &&
4200 chunk !== undefined &&
4201 !state.objectMode) {
4202 var er = new TypeError('Invalid non-string/buffer chunk');
4203 stream.emit('error', er);
4204 setImmediate(function() {
4205 cb(er);
4206 });
4207 valid = false;
4208 }
4209 return valid;
4210}
4211
4212Writable.prototype.write = function(chunk, encoding, cb) {
4213 var state = this._writableState;
4214 var ret = false;
4215
4216 if (typeof encoding === 'function') {
4217 cb = encoding;
4218 encoding = null;
4219 }
4220
4221 if (!Buffer.isBuffer(chunk) && isUint8Array(chunk))
4222 chunk = new Buffer(chunk);
4223 if (isArrayBuffer(chunk) && typeof Uint8Array !== 'undefined')
4224 chunk = new Buffer(new Uint8Array(chunk));
4225
4226 if (Buffer.isBuffer(chunk))
4227 encoding = 'buffer';
4228 else if (!encoding)
4229 encoding = state.defaultEncoding;
4230
4231 if (typeof cb !== 'function')
4232 cb = function() {};
4233
4234 if (state.ended)
4235 writeAfterEnd(this, state, cb);
4236 else if (validChunk(this, state, chunk, cb))
4237 ret = writeOrBuffer(this, state, chunk, encoding, cb);
4238
4239 return ret;
4240};
4241
4242function decodeChunk(state, chunk, encoding) {
4243 if (!state.objectMode &&
4244 state.decodeStrings !== false &&
4245 typeof chunk === 'string') {
4246 chunk = new Buffer(chunk, encoding);
4247 }
4248 return chunk;
4249}
4250
4251// if we're already writing something, then just put this
4252// in the queue, and wait our turn. Otherwise, call _write
4253// If we return false, then we need a drain event, so set that flag.
4254function writeOrBuffer(stream, state, chunk, encoding, cb) {
4255 chunk = decodeChunk(state, chunk, encoding);
4256 var len = state.objectMode ? 1 : chunk.length;
4257
4258 state.length += len;
4259
4260 var ret = state.length < state.highWaterMark;
4261 state.needDrain = !ret;
4262
4263 if (state.writing)
4264 state.buffer.push(new WriteReq(chunk, encoding, cb));
4265 else
4266 doWrite(stream, state, len, chunk, encoding, cb);
4267
4268 return ret;
4269}
4270
4271function doWrite(stream, state, len, chunk, encoding, cb) {
4272 state.writelen = len;
4273 state.writecb = cb;
4274 state.writing = true;
4275 state.sync = true;
4276 stream._write(chunk, encoding, state.onwrite);
4277 state.sync = false;
4278}
4279
4280function onwriteError(stream, state, sync, er, cb) {
4281 if (sync)
4282 setImmediate(function() {
4283 cb(er);
4284 });
4285 else
4286 cb(er);
4287
4288 stream.emit('error', er);
4289}
4290
4291function onwriteStateUpdate(state) {
4292 state.writing = false;
4293 state.writecb = null;
4294 state.length -= state.writelen;
4295 state.writelen = 0;
4296}
4297
4298function onwrite(stream, er) {
4299 var state = stream._writableState;
4300 var sync = state.sync;
4301 var cb = state.writecb;
4302
4303 onwriteStateUpdate(state);
4304
4305 if (er)
4306 onwriteError(stream, state, sync, er, cb);
4307 else {
4308 // Check if we're actually ready to finish, but don't emit yet
4309 var finished = needFinish(stream, state);
4310
4311 if (!finished && !state.bufferProcessing && state.buffer.length)
4312 clearBuffer(stream, state);
4313
4314 if (sync) {
4315 setImmediate(function() {
4316 afterWrite(stream, state, finished, cb);
4317 });
4318 } else {
4319 afterWrite(stream, state, finished, cb);
4320 }
4321 }
4322}
4323
4324function afterWrite(stream, state, finished, cb) {
4325 if (!finished)
4326 onwriteDrain(stream, state);
4327 cb();
4328 if (finished)
4329 finishMaybe(stream, state);
4330}
4331
4332// Must force callback to be called on nextTick, so that we don't
4333// emit 'drain' before the write() consumer gets the 'false' return
4334// value, and has a chance to attach a 'drain' listener.
4335function onwriteDrain(stream, state) {
4336 if (state.length === 0 && state.needDrain) {
4337 state.needDrain = false;
4338 stream.emit('drain');
4339 }
4340}
4341
4342
4343// if there's something in the buffer waiting, then process it
4344function clearBuffer(stream, state) {
4345 state.bufferProcessing = true;
4346
4347 for (var c = 0; c < state.buffer.length; c++) {
4348 var entry = state.buffer[c];
4349 var chunk = entry.chunk;
4350 var encoding = entry.encoding;
4351 var cb = entry.callback;
4352 var len = state.objectMode ? 1 : chunk.length;
4353
4354 doWrite(stream, state, len, chunk, encoding, cb);
4355
4356 // if we didn't call the onwrite immediately, then
4357 // it means that we need to wait until it does.
4358 // also, that means that the chunk and cb are currently
4359 // being processed, so move the buffer counter past them.
4360 if (state.writing) {
4361 c++;
4362 break;
4363 }
4364 }
4365
4366 state.bufferProcessing = false;
4367 if (c < state.buffer.length)
4368 state.buffer = state.buffer.slice(c);
4369 else
4370 state.buffer.length = 0;
4371}
4372
4373Writable.prototype._write = function(chunk, encoding, cb) {
4374 cb(new Error('not implemented'));
4375};
4376
4377Writable.prototype.end = function(chunk, encoding, cb) {
4378 var state = this._writableState;
4379
4380 if (typeof chunk === 'function') {
4381 cb = chunk;
4382 chunk = null;
4383 encoding = null;
4384 } else if (typeof encoding === 'function') {
4385 cb = encoding;
4386 encoding = null;
4387 }
4388
4389 if (typeof chunk !== 'undefined' && chunk !== null)
4390 this.write(chunk, encoding);
4391
4392 // ignore unnecessary end() calls.
4393 if (!state.ending && !state.finished)
4394 endWritable(this, state, cb);
4395};
4396
4397
4398function needFinish(stream, state) {
4399 return (state.ending &&
4400 state.length === 0 &&
4401 !state.finished &&
4402 !state.writing);
4403}
4404
4405function finishMaybe(stream, state) {
4406 var need = needFinish(stream, state);
4407 if (need) {
4408 state.finished = true;
4409 stream.emit('finish');
4410 }
4411 return need;
4412}
4413
4414function endWritable(stream, state, cb) {
4415 state.ending = true;
4416 finishMaybe(stream, state);
4417 if (cb) {
4418 if (state.finished)
4419 setImmediate(cb);
4420 else
4421 stream.once('finish', cb);
4422 }
4423 state.ended = true;
4424}
4425
4426},{"./index.js":11,"buffer":7,"inherits":19,"process/browser.js":12}],17:[function(require,module,exports){
4427// Copyright Joyent, Inc. and other Node contributors.
4428//
4429// Permission is hereby granted, free of charge, to any person obtaining a
4430// copy of this software and associated documentation files (the
4431// "Software"), to deal in the Software without restriction, including
4432// without limitation the rights to use, copy, modify, merge, publish,
4433// distribute, sublicense, and/or sell copies of the Software, and to permit
4434// persons to whom the Software is furnished to do so, subject to the
4435// following conditions:
4436//
4437// The above copyright notice and this permission notice shall be included
4438// in all copies or substantial portions of the Software.
4439//
4440// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
4441// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
4442// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
4443// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
4444// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
4445// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
4446// USE OR OTHER DEALINGS IN THE SOFTWARE.
4447
4448var Buffer = require('buffer').Buffer;
4449
4450function assertEncoding(encoding) {
4451 if (encoding && !Buffer.isEncoding(encoding)) {
4452 throw new Error('Unknown encoding: ' + encoding);
4453 }
4454}
4455
4456var StringDecoder = exports.StringDecoder = function(encoding) {
4457 this.encoding = (encoding || 'utf8').toLowerCase().replace(/[-_]/, '');
4458 assertEncoding(encoding);
4459 switch (this.encoding) {
4460 case 'utf8':
4461 // CESU-8 represents each of Surrogate Pair by 3-bytes
4462 this.surrogateSize = 3;
4463 break;
4464 case 'ucs2':
4465 case 'utf16le':
4466 // UTF-16 represents each of Surrogate Pair by 2-bytes
4467 this.surrogateSize = 2;
4468 this.detectIncompleteChar = utf16DetectIncompleteChar;
4469 break;
4470 case 'base64':
4471 // Base-64 stores 3 bytes in 4 chars, and pads the remainder.
4472 this.surrogateSize = 3;
4473 this.detectIncompleteChar = base64DetectIncompleteChar;
4474 break;
4475 default:
4476 this.write = passThroughWrite;
4477 return;
4478 }
4479
4480 this.charBuffer = new Buffer(6);
4481 this.charReceived = 0;
4482 this.charLength = 0;
4483};
4484
4485
4486StringDecoder.prototype.write = function(buffer) {
4487 var charStr = '';
4488 var offset = 0;
4489
4490 // if our last write ended with an incomplete multibyte character
4491 while (this.charLength) {
4492 // determine how many remaining bytes this buffer has to offer for this char
4493 var i = (buffer.length >= this.charLength - this.charReceived) ?
4494 this.charLength - this.charReceived :
4495 buffer.length;
4496
4497 // add the new bytes to the char buffer
4498 buffer.copy(this.charBuffer, this.charReceived, offset, i);
4499 this.charReceived += (i - offset);
4500 offset = i;
4501
4502 if (this.charReceived < this.charLength) {
4503 // still not enough chars in this buffer? wait for more ...
4504 return '';
4505 }
4506
4507 // get the character that was split
4508 charStr = this.charBuffer.slice(0, this.charLength).toString(this.encoding);
4509
4510 // lead surrogate (D800-DBFF) is also the incomplete character
4511 var charCode = charStr.charCodeAt(charStr.length - 1);
4512 if (charCode >= 0xD800 && charCode <= 0xDBFF) {
4513 this.charLength += this.surrogateSize;
4514 charStr = '';
4515 continue;
4516 }
4517 this.charReceived = this.charLength = 0;
4518
4519 // if there are no more bytes in this buffer, just emit our char
4520 if (i == buffer.length) return charStr;
4521
4522 // otherwise cut off the characters end from the beginning of this buffer
4523 buffer = buffer.slice(i, buffer.length);
4524 break;
4525 }
4526
4527 var lenIncomplete = this.detectIncompleteChar(buffer);
4528
4529 var end = buffer.length;
4530 if (this.charLength) {
4531 // buffer the incomplete character bytes we got
4532 buffer.copy(this.charBuffer, 0, buffer.length - lenIncomplete, end);
4533 this.charReceived = lenIncomplete;
4534 end -= lenIncomplete;
4535 }
4536
4537 charStr += buffer.toString(this.encoding, 0, end);
4538
4539 var end = charStr.length - 1;
4540 var charCode = charStr.charCodeAt(end);
4541 // lead surrogate (D800-DBFF) is also the incomplete character
4542 if (charCode >= 0xD800 && charCode <= 0xDBFF) {
4543 var size = this.surrogateSize;
4544 this.charLength += size;
4545 this.charReceived += size;
4546 this.charBuffer.copy(this.charBuffer, size, 0, size);
4547 this.charBuffer.write(charStr.charAt(charStr.length - 1), this.encoding);
4548 return charStr.substring(0, end);
4549 }
4550
4551 // or just emit the charStr
4552 return charStr;
4553};
4554
4555StringDecoder.prototype.detectIncompleteChar = function(buffer) {
4556 // determine how many bytes we have to check at the end of this buffer
4557 var i = (buffer.length >= 3) ? 3 : buffer.length;
4558
4559 // Figure out if one of the last i bytes of our buffer announces an
4560 // incomplete char.
4561 for (; i > 0; i--) {
4562 var c = buffer[buffer.length - i];
4563
4564 // See http://en.wikipedia.org/wiki/UTF-8#Description
4565
4566 // 110XXXXX
4567 if (i == 1 && c >> 5 == 0x06) {
4568 this.charLength = 2;
4569 break;
4570 }
4571
4572 // 1110XXXX
4573 if (i <= 2 && c >> 4 == 0x0E) {
4574 this.charLength = 3;
4575 break;
4576 }
4577
4578 // 11110XXX
4579 if (i <= 3 && c >> 3 == 0x1E) {
4580 this.charLength = 4;
4581 break;
4582 }
4583 }
4584
4585 return i;
4586};
4587
4588StringDecoder.prototype.end = function(buffer) {
4589 var res = '';
4590 if (buffer && buffer.length)
4591 res = this.write(buffer);
4592
4593 if (this.charReceived) {
4594 var cr = this.charReceived;
4595 var buf = this.charBuffer;
4596 var enc = this.encoding;
4597 res += buf.slice(0, cr).toString(enc);
4598 }
4599
4600 return res;
4601};
4602
4603function passThroughWrite(buffer) {
4604 return buffer.toString(this.encoding);
4605}
4606
4607function utf16DetectIncompleteChar(buffer) {
4608 var incomplete = this.charReceived = buffer.length % 2;
4609 this.charLength = incomplete ? 2 : 0;
4610 return incomplete;
4611}
4612
4613function base64DetectIncompleteChar(buffer) {
4614 var incomplete = this.charReceived = buffer.length % 3;
4615 this.charLength = incomplete ? 3 : 0;
4616 return incomplete;
4617}
4618
4619},{"buffer":7}],18:[function(require,module,exports){
4620exports.read = function (buffer, offset, isLE, mLen, nBytes) {
4621 var e, m
4622 var eLen = (nBytes * 8) - mLen - 1
4623 var eMax = (1 << eLen) - 1
4624 var eBias = eMax >> 1
4625 var nBits = -7
4626 var i = isLE ? (nBytes - 1) : 0
4627 var d = isLE ? -1 : 1
4628 var s = buffer[offset + i]
4629
4630 i += d
4631
4632 e = s & ((1 << (-nBits)) - 1)
4633 s >>= (-nBits)
4634 nBits += eLen
4635 for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {}
4636
4637 m = e & ((1 << (-nBits)) - 1)
4638 e >>= (-nBits)
4639 nBits += mLen
4640 for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {}
4641
4642 if (e === 0) {
4643 e = 1 - eBias
4644 } else if (e === eMax) {
4645 return m ? NaN : ((s ? -1 : 1) * Infinity)
4646 } else {
4647 m = m + Math.pow(2, mLen)
4648 e = e - eBias
4649 }
4650 return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
4651}
4652
4653exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
4654 var e, m, c
4655 var eLen = (nBytes * 8) - mLen - 1
4656 var eMax = (1 << eLen) - 1
4657 var eBias = eMax >> 1
4658 var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
4659 var i = isLE ? 0 : (nBytes - 1)
4660 var d = isLE ? 1 : -1
4661 var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
4662
4663 value = Math.abs(value)
4664
4665 if (isNaN(value) || value === Infinity) {
4666 m = isNaN(value) ? 1 : 0
4667 e = eMax
4668 } else {
4669 e = Math.floor(Math.log(value) / Math.LN2)
4670 if (value * (c = Math.pow(2, -e)) < 1) {
4671 e--
4672 c *= 2
4673 }
4674 if (e + eBias >= 1) {
4675 value += rt / c
4676 } else {
4677 value += rt * Math.pow(2, 1 - eBias)
4678 }
4679 if (value * c >= 2) {
4680 e++
4681 c /= 2
4682 }
4683
4684 if (e + eBias >= eMax) {
4685 m = 0
4686 e = eMax
4687 } else if (e + eBias >= 1) {
4688 m = ((value * c) - 1) * Math.pow(2, mLen)
4689 e = e + eBias
4690 } else {
4691 m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
4692 e = 0
4693 }
4694 }
4695
4696 for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
4697
4698 e = (e << mLen) | m
4699 eLen += mLen
4700 for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
4701
4702 buffer[offset + i - d] |= s * 128
4703}
4704
4705},{}],19:[function(require,module,exports){
4706module.exports=require(3)
4707},{}],20:[function(require,module,exports){
4708'use strict';
4709
4710var assert = require('assert');
4711var stream = require('stream');
4712var hash = require('../index');
4713
4714describe('writeToStream', function() {
4715 it('should emit information about an object to a stream', function() {
4716 var strm = new stream.PassThrough();
4717
4718 hash.writeToStream({foo: 'bar'}, strm);
4719 var result = strm.read().toString();
4720 assert.strictEqual(typeof result, 'string');
4721 assert.notStrictEqual(result.indexOf('foo'), -1);
4722 assert.notStrictEqual(result.indexOf('bar'), -1);
4723 });
4724
4725 it('should leave out keys when excludeValues = true', function() {
4726 var strm = new stream.PassThrough();
4727
4728 hash.writeToStream({foo: 'bar'}, {excludeValues: true}, strm);
4729 var result = strm.read().toString();
4730 assert.strictEqual(typeof result, 'string');
4731 assert.notStrictEqual(result.indexOf('foo'), -1);
4732 assert. strictEqual(result.indexOf('bar'), -1);
4733 });
4734});
4735
4736},{"../index":1,"assert":2,"stream":11}]},{},[20])
\No newline at end of file