diff --git a/example/eventsource-polyfill.js b/example/eventsource-polyfill.js
index 69574c1..a93003c 100644
--- a/example/eventsource-polyfill.js
+++ b/example/eventsource-polyfill.js
@@ -63,7 +63,7 @@
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
-/******/ return __webpack_require__(__webpack_require__.s = 21);
+/******/ return __webpack_require__(__webpack_require__.s = 22);
/******/ })
/************************************************************************/
/******/ ([
@@ -95,6 +95,225 @@ module.exports = g;
/***/ }),
/* 1 */
+/***/ (function(module, exports) {
+
+// shim for using process in browser
+var process = module.exports = {};
+
+// cached from whatever global is present so that test runners that stub it
+// don't break things. But we need to wrap it in a try catch in case it is
+// wrapped in strict mode code which doesn't define any globals. It's inside a
+// function because try/catches deoptimize in certain engines.
+
+var cachedSetTimeout;
+var cachedClearTimeout;
+
+function defaultSetTimout() {
+ throw new Error('setTimeout has not been defined');
+}
+function defaultClearTimeout () {
+ throw new Error('clearTimeout has not been defined');
+}
+(function () {
+ try {
+ if (typeof setTimeout === 'function') {
+ cachedSetTimeout = setTimeout;
+ } else {
+ cachedSetTimeout = defaultSetTimout;
+ }
+ } catch (e) {
+ cachedSetTimeout = defaultSetTimout;
+ }
+ try {
+ if (typeof clearTimeout === 'function') {
+ cachedClearTimeout = clearTimeout;
+ } else {
+ cachedClearTimeout = defaultClearTimeout;
+ }
+ } catch (e) {
+ cachedClearTimeout = defaultClearTimeout;
+ }
+} ())
+function runTimeout(fun) {
+ if (cachedSetTimeout === setTimeout) {
+ //normal enviroments in sane situations
+ return setTimeout(fun, 0);
+ }
+ // if setTimeout wasn't available but was latter defined
+ if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
+ cachedSetTimeout = setTimeout;
+ return setTimeout(fun, 0);
+ }
+ try {
+ // when when somebody has screwed with setTimeout but no I.E. maddness
+ return cachedSetTimeout(fun, 0);
+ } catch(e){
+ try {
+ // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
+ return cachedSetTimeout.call(null, fun, 0);
+ } catch(e){
+ // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
+ return cachedSetTimeout.call(this, fun, 0);
+ }
+ }
+
+
+}
+function runClearTimeout(marker) {
+ if (cachedClearTimeout === clearTimeout) {
+ //normal enviroments in sane situations
+ return clearTimeout(marker);
+ }
+ // if clearTimeout wasn't available but was latter defined
+ if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
+ cachedClearTimeout = clearTimeout;
+ return clearTimeout(marker);
+ }
+ try {
+ // when when somebody has screwed with setTimeout but no I.E. maddness
+ return cachedClearTimeout(marker);
+ } catch (e){
+ try {
+ // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
+ return cachedClearTimeout.call(null, marker);
+ } catch (e){
+ // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
+ // Some versions of I.E. have different rules for clearTimeout vs setTimeout
+ return cachedClearTimeout.call(this, marker);
+ }
+ }
+
+
+
+}
+var queue = [];
+var draining = false;
+var currentQueue;
+var queueIndex = -1;
+
+function cleanUpNextTick() {
+ if (!draining || !currentQueue) {
+ return;
+ }
+ draining = false;
+ if (currentQueue.length) {
+ queue = currentQueue.concat(queue);
+ } else {
+ queueIndex = -1;
+ }
+ if (queue.length) {
+ drainQueue();
+ }
+}
+
+function drainQueue() {
+ if (draining) {
+ return;
+ }
+ var timeout = runTimeout(cleanUpNextTick);
+ draining = true;
+
+ var len = queue.length;
+ while(len) {
+ currentQueue = queue;
+ queue = [];
+ while (++queueIndex < len) {
+ if (currentQueue) {
+ currentQueue[queueIndex].run();
+ }
+ }
+ queueIndex = -1;
+ len = queue.length;
+ }
+ currentQueue = null;
+ draining = false;
+ runClearTimeout(timeout);
+}
+
+process.nextTick = function (fun) {
+ var args = new Array(arguments.length - 1);
+ if (arguments.length > 1) {
+ for (var i = 1; i < arguments.length; i++) {
+ args[i - 1] = arguments[i];
+ }
+ }
+ queue.push(new Item(fun, args));
+ if (queue.length === 1 && !draining) {
+ runTimeout(drainQueue);
+ }
+};
+
+// v8 likes predictible objects
+function Item(fun, array) {
+ this.fun = fun;
+ this.array = array;
+}
+Item.prototype.run = function () {
+ this.fun.apply(null, this.array);
+};
+process.title = 'browser';
+process.browser = true;
+process.env = {};
+process.argv = [];
+process.version = ''; // empty string to avoid regexp issues
+process.versions = {};
+
+function noop() {}
+
+process.on = noop;
+process.addListener = noop;
+process.once = noop;
+process.off = noop;
+process.removeListener = noop;
+process.removeAllListeners = noop;
+process.emit = noop;
+process.prependListener = noop;
+process.prependOnceListener = noop;
+
+process.listeners = function (name) { return [] }
+
+process.binding = function (name) {
+ throw new Error('process.binding is not supported');
+};
+
+process.cwd = function () { return '/' };
+process.chdir = function (dir) {
+ throw new Error('process.chdir is not supported');
+};
+process.umask = function() { return 0; };
+
+
+/***/ }),
+/* 2 */
+/***/ (function(module, exports) {
+
+if (typeof Object.create === 'function') {
+ // implementation from standard node.js 'util' module
+ module.exports = function inherits(ctor, superCtor) {
+ ctor.super_ = superCtor
+ ctor.prototype = Object.create(superCtor.prototype, {
+ constructor: {
+ value: ctor,
+ enumerable: false,
+ writable: true,
+ configurable: true
+ }
+ });
+ };
+} else {
+ // old school shim for old browsers
+ module.exports = function inherits(ctor, superCtor) {
+ ctor.super_ = superCtor
+ var TempCtor = function () {}
+ TempCtor.prototype = superCtor.prototype
+ ctor.prototype = new TempCtor()
+ ctor.prototype.constructor = ctor
+ }
+}
+
+
+/***/ }),
+/* 3 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
@@ -108,8 +327,8 @@ module.exports = g;
-var base64 = __webpack_require__(22)
-var ieee754 = __webpack_require__(25)
+var base64 = __webpack_require__(23)
+var ieee754 = __webpack_require__(26)
var isArray = __webpack_require__(9)
exports.Buffer = Buffer
@@ -1891,234 +2110,44 @@ function isnan (val) {
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(0)))
/***/ }),
-/* 2 */
-/***/ (function(module, exports) {
+/* 4 */
+/***/ (function(module, exports, __webpack_require__) {
-// shim for using process in browser
-var process = module.exports = {};
+"use strict";
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
-// cached from whatever global is present so that test runners that stub it
-// don't break things. But we need to wrap it in a try catch in case it is
-// wrapped in strict mode code which doesn't define any globals. It's inside a
-// function because try/catches deoptimize in certain engines.
+// a duplex stream is just a stream that is both readable and writable.
+// Since JS doesn't have multiple prototypal inheritance, this class
+// prototypally inherits from Readable, and then parasitically from
+// Writable.
-var cachedSetTimeout;
-var cachedClearTimeout;
-function defaultSetTimout() {
- throw new Error('setTimeout has not been defined');
-}
-function defaultClearTimeout () {
- throw new Error('clearTimeout has not been defined');
-}
-(function () {
- try {
- if (typeof setTimeout === 'function') {
- cachedSetTimeout = setTimeout;
- } else {
- cachedSetTimeout = defaultSetTimout;
- }
- } catch (e) {
- cachedSetTimeout = defaultSetTimout;
- }
- try {
- if (typeof clearTimeout === 'function') {
- cachedClearTimeout = clearTimeout;
- } else {
- cachedClearTimeout = defaultClearTimeout;
- }
- } catch (e) {
- cachedClearTimeout = defaultClearTimeout;
- }
-} ())
-function runTimeout(fun) {
- if (cachedSetTimeout === setTimeout) {
- //normal enviroments in sane situations
- return setTimeout(fun, 0);
- }
- // if setTimeout wasn't available but was latter defined
- if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
- cachedSetTimeout = setTimeout;
- return setTimeout(fun, 0);
- }
- try {
- // when when somebody has screwed with setTimeout but no I.E. maddness
- return cachedSetTimeout(fun, 0);
- } catch(e){
- try {
- // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
- return cachedSetTimeout.call(null, fun, 0);
- } catch(e){
- // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
- return cachedSetTimeout.call(this, fun, 0);
- }
- }
-
-
-}
-function runClearTimeout(marker) {
- if (cachedClearTimeout === clearTimeout) {
- //normal enviroments in sane situations
- return clearTimeout(marker);
- }
- // if clearTimeout wasn't available but was latter defined
- if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
- cachedClearTimeout = clearTimeout;
- return clearTimeout(marker);
- }
- try {
- // when when somebody has screwed with setTimeout but no I.E. maddness
- return cachedClearTimeout(marker);
- } catch (e){
- try {
- // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
- return cachedClearTimeout.call(null, marker);
- } catch (e){
- // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
- // Some versions of I.E. have different rules for clearTimeout vs setTimeout
- return cachedClearTimeout.call(this, marker);
- }
- }
-
-
-
-}
-var queue = [];
-var draining = false;
-var currentQueue;
-var queueIndex = -1;
-
-function cleanUpNextTick() {
- if (!draining || !currentQueue) {
- return;
- }
- draining = false;
- if (currentQueue.length) {
- queue = currentQueue.concat(queue);
- } else {
- queueIndex = -1;
- }
- if (queue.length) {
- drainQueue();
- }
-}
-
-function drainQueue() {
- if (draining) {
- return;
- }
- var timeout = runTimeout(cleanUpNextTick);
- draining = true;
-
- var len = queue.length;
- while(len) {
- currentQueue = queue;
- queue = [];
- while (++queueIndex < len) {
- if (currentQueue) {
- currentQueue[queueIndex].run();
- }
- }
- queueIndex = -1;
- len = queue.length;
- }
- currentQueue = null;
- draining = false;
- runClearTimeout(timeout);
-}
-
-process.nextTick = function (fun) {
- var args = new Array(arguments.length - 1);
- if (arguments.length > 1) {
- for (var i = 1; i < arguments.length; i++) {
- args[i - 1] = arguments[i];
- }
- }
- queue.push(new Item(fun, args));
- if (queue.length === 1 && !draining) {
- runTimeout(drainQueue);
- }
-};
-
-// v8 likes predictible objects
-function Item(fun, array) {
- this.fun = fun;
- this.array = array;
-}
-Item.prototype.run = function () {
- this.fun.apply(null, this.array);
-};
-process.title = 'browser';
-process.browser = true;
-process.env = {};
-process.argv = [];
-process.version = ''; // empty string to avoid regexp issues
-process.versions = {};
-
-function noop() {}
-
-process.on = noop;
-process.addListener = noop;
-process.once = noop;
-process.off = noop;
-process.removeListener = noop;
-process.removeAllListeners = noop;
-process.emit = noop;
-
-process.binding = function (name) {
- throw new Error('process.binding is not supported');
-};
-
-process.cwd = function () { return '/' };
-process.chdir = function (dir) {
- throw new Error('process.chdir is not supported');
-};
-process.umask = function() { return 0; };
-
-
-/***/ }),
-/* 3 */
-/***/ (function(module, exports) {
-
-if (typeof Object.create === 'function') {
- // implementation from standard node.js 'util' module
- module.exports = function inherits(ctor, superCtor) {
- ctor.super_ = superCtor
- ctor.prototype = Object.create(superCtor.prototype, {
- constructor: {
- value: ctor,
- enumerable: false,
- writable: true,
- configurable: true
- }
- });
- };
-} else {
- // old school shim for old browsers
- module.exports = function inherits(ctor, superCtor) {
- ctor.super_ = superCtor
- var TempCtor = function () {}
- TempCtor.prototype = superCtor.prototype
- ctor.prototype = new TempCtor()
- ctor.prototype.constructor = ctor
- }
-}
-
-
-/***/ }),
-/* 4 */
-/***/ (function(module, exports, __webpack_require__) {
-
-"use strict";
-// a duplex stream is just a stream that is both readable and writable.
-// Since JS doesn't have multiple prototypal inheritance, this class
-// prototypally inherits from Readable, and then parasitically from
-// Writable.
+/**/
+var processNextTick = __webpack_require__(6);
+/**/
/**/
-
var objectKeys = Object.keys || function (obj) {
var keys = [];
for (var key in obj) {
@@ -2129,17 +2158,13 @@ var objectKeys = Object.keys || function (obj) {
module.exports = Duplex;
-/**/
-var processNextTick = __webpack_require__(8);
-/**/
-
/**/
var util = __webpack_require__(5);
-util.inherits = __webpack_require__(3);
+util.inherits = __webpack_require__(2);
/**/
-var Readable = __webpack_require__(10);
-var Writable = __webpack_require__(12);
+var Readable = __webpack_require__(11);
+var Writable = __webpack_require__(13);
util.inherits(Duplex, Readable);
@@ -2180,6 +2205,34 @@ function onEndNT(self) {
self.end();
}
+Object.defineProperty(Duplex.prototype, 'destroyed', {
+ get: function () {
+ if (this._readableState === undefined || this._writableState === undefined) {
+ return false;
+ }
+ return this._readableState.destroyed && this._writableState.destroyed;
+ },
+ set: function (value) {
+ // we ignore the value if the stream
+ // has not been initialized yet
+ if (this._readableState === undefined || this._writableState === undefined) {
+ return;
+ }
+
+ // backward compatibility, the user is explicitly
+ // managing destroyed
+ this._readableState.destroyed = value;
+ this._writableState.destroyed = value;
+ }
+});
+
+Duplex.prototype._destroy = function (err, cb) {
+ this.push(null);
+ this.end();
+
+ processNextTick(cb, err);
+};
+
function forEach(xs, f) {
for (var i = 0, l = xs.length; i < l; i++) {
f(xs[i], i);
@@ -2298,123 +2351,58 @@ function objectToString(o) {
return Object.prototype.toString.call(o);
}
-/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(1).Buffer))
+/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(3).Buffer))
/***/ }),
/* 6 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
-/* WEBPACK VAR INJECTION */(function(global) {
+/* WEBPACK VAR INJECTION */(function(process) {
-var buffer = __webpack_require__(1);
-var Buffer = buffer.Buffer;
-var SlowBuffer = buffer.SlowBuffer;
-var MAX_LEN = buffer.kMaxLength || 2147483647;
-exports.alloc = function alloc(size, fill, encoding) {
- if (typeof Buffer.alloc === 'function') {
- return Buffer.alloc(size, fill, encoding);
- }
- if (typeof encoding === 'number') {
- throw new TypeError('encoding must not be number');
- }
- if (typeof size !== 'number') {
- throw new TypeError('size must be a number');
- }
- if (size > MAX_LEN) {
- throw new RangeError('size is too large');
- }
- var enc = encoding;
- var _fill = fill;
- if (_fill === undefined) {
- enc = undefined;
- _fill = 0;
- }
- var buf = new Buffer(size);
- if (typeof _fill === 'string') {
- var fillBuf = new Buffer(_fill, enc);
- var flen = fillBuf.length;
- var i = -1;
- while (++i < size) {
- buf[i] = fillBuf[i % flen];
- }
- } else {
- buf.fill(_fill);
- }
- return buf;
-}
-exports.allocUnsafe = function allocUnsafe(size) {
- if (typeof Buffer.allocUnsafe === 'function') {
- return Buffer.allocUnsafe(size);
- }
- if (typeof size !== 'number') {
- throw new TypeError('size must be a number');
- }
- if (size > MAX_LEN) {
- throw new RangeError('size is too large');
- }
- return new Buffer(size);
+if (!process.version ||
+ process.version.indexOf('v0.') === 0 ||
+ process.version.indexOf('v1.') === 0 && process.version.indexOf('v1.8.') !== 0) {
+ module.exports = nextTick;
+} else {
+ module.exports = process.nextTick;
}
-exports.from = function from(value, encodingOrOffset, length) {
- if (typeof Buffer.from === 'function' && (!global.Uint8Array || Uint8Array.from !== Buffer.from)) {
- return Buffer.from(value, encodingOrOffset, length);
- }
- if (typeof value === 'number') {
- throw new TypeError('"value" argument must not be a number');
- }
- if (typeof value === 'string') {
- return new Buffer(value, encodingOrOffset);
+
+function nextTick(fn, arg1, arg2, arg3) {
+ if (typeof fn !== 'function') {
+ throw new TypeError('"callback" argument must be a function');
}
- if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
- var offset = encodingOrOffset;
- if (arguments.length === 1) {
- return new Buffer(value);
- }
- if (typeof offset === 'undefined') {
- offset = 0;
- }
- var len = length;
- if (typeof len === 'undefined') {
- len = value.byteLength - offset;
- }
- if (offset >= value.byteLength) {
- throw new RangeError('\'offset\' is out of bounds');
- }
- if (len > value.byteLength - offset) {
- throw new RangeError('\'length\' is out of bounds');
- }
- return new Buffer(value.slice(offset, offset + len));
- }
- if (Buffer.isBuffer(value)) {
- var out = new Buffer(value.length);
- value.copy(out, 0, 0, value.length);
- return out;
- }
- if (value) {
- if (Array.isArray(value) || (typeof ArrayBuffer !== 'undefined' && value.buffer instanceof ArrayBuffer) || 'length' in value) {
- return new Buffer(value);
- }
- if (value.type === 'Buffer' && Array.isArray(value.data)) {
- return new Buffer(value.data);
+ var len = arguments.length;
+ var args, i;
+ switch (len) {
+ case 0:
+ case 1:
+ return process.nextTick(fn);
+ case 2:
+ return process.nextTick(function afterTickOne() {
+ fn.call(null, arg1);
+ });
+ case 3:
+ return process.nextTick(function afterTickTwo() {
+ fn.call(null, arg1, arg2);
+ });
+ case 4:
+ return process.nextTick(function afterTickThree() {
+ fn.call(null, arg1, arg2, arg3);
+ });
+ default:
+ args = new Array(len - 1);
+ i = 0;
+ while (i < args.length) {
+ args[i++] = arguments[i];
}
+ return process.nextTick(function afterTick() {
+ fn.apply(null, args);
+ });
}
-
- throw new TypeError('First argument must be a string, Buffer, ' + 'ArrayBuffer, Array, or array-like object.');
-}
-exports.allocUnsafeSlow = function allocUnsafeSlow(size) {
- if (typeof Buffer.allocUnsafeSlow === 'function') {
- return Buffer.allocUnsafeSlow(size);
- }
- if (typeof size !== 'number') {
- throw new TypeError('size must be a number');
- }
- if (size >= MAX_LEN) {
- throw new RangeError('size is too large');
- }
- return new SlowBuffer(size);
}
-/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(0)))
+/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(1)))
/***/ }),
/* 7 */
@@ -2728,52 +2716,67 @@ function isUndefined(arg) {
/* 8 */
/***/ (function(module, exports, __webpack_require__) {
-"use strict";
-/* WEBPACK VAR INJECTION */(function(process) {
+/* eslint-disable node/no-deprecated-api */
+var buffer = __webpack_require__(3)
+var Buffer = buffer.Buffer
-if (!process.version ||
- process.version.indexOf('v0.') === 0 ||
- process.version.indexOf('v1.') === 0 && process.version.indexOf('v1.8.') !== 0) {
- module.exports = nextTick;
+if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) {
+ module.exports = buffer
} else {
- module.exports = process.nextTick;
+ // Copy properties from require('buffer')
+ Object.keys(buffer).forEach(function (prop) {
+ exports[prop] = buffer[prop]
+ })
+ exports.Buffer = SafeBuffer
}
-function nextTick(fn, arg1, arg2, arg3) {
- if (typeof fn !== 'function') {
- throw new TypeError('"callback" argument must be a function');
+function SafeBuffer (arg, encodingOrOffset, length) {
+ return Buffer(arg, encodingOrOffset, length)
+}
+
+// Copy static methods from Buffer
+Object.keys(Buffer).forEach(function (prop) {
+ SafeBuffer[prop] = Buffer[prop]
+})
+
+SafeBuffer.from = function (arg, encodingOrOffset, length) {
+ if (typeof arg === 'number') {
+ throw new TypeError('Argument must not be a number')
}
- var len = arguments.length;
- var args, i;
- switch (len) {
- case 0:
- case 1:
- return process.nextTick(fn);
- case 2:
- return process.nextTick(function afterTickOne() {
- fn.call(null, arg1);
- });
- case 3:
- return process.nextTick(function afterTickTwo() {
- fn.call(null, arg1, arg2);
- });
- case 4:
- return process.nextTick(function afterTickThree() {
- fn.call(null, arg1, arg2, arg3);
- });
- default:
- args = new Array(len - 1);
- i = 0;
- while (i < args.length) {
- args[i++] = arguments[i];
+ return Buffer(arg, encodingOrOffset, length)
+}
+
+SafeBuffer.alloc = function (size, fill, encoding) {
+ if (typeof size !== 'number') {
+ throw new TypeError('Argument must be a number')
+ }
+ var buf = Buffer(size)
+ if (fill !== undefined) {
+ if (typeof encoding === 'string') {
+ buf.fill(fill, encoding)
+ } else {
+ buf.fill(fill)
}
- return process.nextTick(function afterTick() {
- fn.apply(null, args);
- });
+ } else {
+ buf.fill(0)
+ }
+ return buf
+}
+
+SafeBuffer.allocUnsafe = function (size) {
+ if (typeof size !== 'number') {
+ throw new TypeError('Argument must be a number')
+ }
+ return Buffer(size)
+}
+
+SafeBuffer.allocUnsafeSlow = function (size) {
+ if (typeof size !== 'number') {
+ throw new TypeError('Argument must be a number')
}
+ return buffer.SlowBuffer(size)
}
-/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(2)))
/***/ }),
/* 9 */
@@ -2790,80 +2793,335 @@ module.exports = Array.isArray || function (arr) {
/* 10 */
/***/ (function(module, exports, __webpack_require__) {
-"use strict";
-/* WEBPACK VAR INJECTION */(function(process) {
-
-module.exports = Readable;
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
-/**/
-var processNextTick = __webpack_require__(8);
-/**/
+var Buffer = __webpack_require__(3).Buffer;
-/**/
-var isArray = __webpack_require__(9);
-/**/
+var isBufferEncoding = Buffer.isEncoding
+ || function(encoding) {
+ switch (encoding && encoding.toLowerCase()) {
+ case 'hex': case 'utf8': case 'utf-8': case 'ascii': case 'binary': case 'base64': case 'ucs2': case 'ucs-2': case 'utf16le': case 'utf-16le': case 'raw': return true;
+ default: return false;
+ }
+ }
-/**/
-var Duplex;
-/**/
-Readable.ReadableState = ReadableState;
+function assertEncoding(encoding) {
+ if (encoding && !isBufferEncoding(encoding)) {
+ throw new Error('Unknown encoding: ' + encoding);
+ }
+}
-/**/
-var EE = __webpack_require__(7).EventEmitter;
+// StringDecoder provides an interface for efficiently splitting a series of
+// buffers into a series of JS strings without breaking apart multi-byte
+// characters. CESU-8 is handled as part of the UTF-8 encoding.
+//
+// @TODO Handling all encodings inside a single object makes it very difficult
+// to reason about this code, so it should be split up in the future.
+// @TODO There should be a utf8-strict encoding that rejects invalid UTF-8 code
+// points as used by CESU-8.
+var StringDecoder = exports.StringDecoder = function(encoding) {
+ this.encoding = (encoding || 'utf8').toLowerCase().replace(/[-_]/, '');
+ assertEncoding(encoding);
+ switch (this.encoding) {
+ case 'utf8':
+ // CESU-8 represents each of Surrogate Pair by 3-bytes
+ this.surrogateSize = 3;
+ break;
+ case 'ucs2':
+ case 'utf16le':
+ // UTF-16 represents each of Surrogate Pair by 2-bytes
+ this.surrogateSize = 2;
+ this.detectIncompleteChar = utf16DetectIncompleteChar;
+ break;
+ case 'base64':
+ // Base-64 stores 3 bytes in 4 chars, and pads the remainder.
+ this.surrogateSize = 3;
+ this.detectIncompleteChar = base64DetectIncompleteChar;
+ break;
+ default:
+ this.write = passThroughWrite;
+ return;
+ }
-var EElistenerCount = function (emitter, type) {
- return emitter.listeners(type).length;
+ // Enough space to store all bytes of a single character. UTF-8 needs 4
+ // bytes, but CESU-8 may require up to 6 (3 bytes per surrogate).
+ this.charBuffer = new Buffer(6);
+ // Number of bytes received for the current incomplete multi-byte character.
+ this.charReceived = 0;
+ // Number of bytes expected for the current incomplete multi-byte character.
+ this.charLength = 0;
};
-/**/
-/**/
-var Stream = __webpack_require__(13);
-/**/
-var Buffer = __webpack_require__(1).Buffer;
-/**/
-var bufferShim = __webpack_require__(6);
-/**/
+// write decodes the given buffer and returns it as JS string that is
+// guaranteed to not contain any partial multi-byte characters. Any partial
+// character found at the end of the buffer is buffered up, and will be
+// returned when calling write again with the remaining bytes.
+//
+// Note: Converting a Buffer containing an orphan surrogate to a String
+// currently works, but converting a String to a Buffer (via `new Buffer`, or
+// Buffer#write) will replace incomplete surrogates with the unicode
+// replacement character. See https://codereview.chromium.org/121173009/ .
+StringDecoder.prototype.write = function(buffer) {
+ var charStr = '';
+ // if our last write ended with an incomplete multibyte character
+ while (this.charLength) {
+ // determine how many remaining bytes this buffer has to offer for this char
+ var available = (buffer.length >= this.charLength - this.charReceived) ?
+ this.charLength - this.charReceived :
+ buffer.length;
-/**/
-var util = __webpack_require__(5);
-util.inherits = __webpack_require__(3);
-/**/
+ // add the new bytes to the char buffer
+ buffer.copy(this.charBuffer, this.charReceived, 0, available);
+ this.charReceived += available;
-/**/
-var debugUtil = __webpack_require__(48);
-var debug = void 0;
-if (debugUtil && debugUtil.debuglog) {
- debug = debugUtil.debuglog('stream');
-} else {
- debug = function () {};
-}
-/**/
+ if (this.charReceived < this.charLength) {
+ // still not enough chars in this buffer? wait for more ...
+ return '';
+ }
-var BufferList = __webpack_require__(33);
-var StringDecoder;
+ // remove bytes belonging to the current character from the buffer
+ buffer = buffer.slice(available, buffer.length);
-util.inherits(Readable, Stream);
+ // get the character that was split
+ charStr = this.charBuffer.slice(0, this.charLength).toString(this.encoding);
-var kProxyEvents = ['error', 'close', 'destroy', 'pause', 'resume'];
+ // CESU-8: lead surrogate (D800-DBFF) is also the incomplete character
+ var charCode = charStr.charCodeAt(charStr.length - 1);
+ if (charCode >= 0xD800 && charCode <= 0xDBFF) {
+ this.charLength += this.surrogateSize;
+ charStr = '';
+ continue;
+ }
+ this.charReceived = this.charLength = 0;
-function prependListener(emitter, event, fn) {
- // Sadly this is not cacheable as some libraries bundle their own
- // event emitter implementation with them.
- if (typeof emitter.prependListener === 'function') {
- return emitter.prependListener(event, fn);
- } else {
- // This is a hack to make sure that our error handler is attached before any
- // userland ones. NEVER DO THIS. This is here only because this code needs
- // to continue to work with older versions of Node.js that do not include
- // the prependListener() method. The goal is to eventually remove this hack.
- if (!emitter._events || !emitter._events[event]) emitter.on(event, fn);else if (isArray(emitter._events[event])) emitter._events[event].unshift(fn);else emitter._events[event] = [fn, emitter._events[event]];
+ // if there are no more bytes in this buffer, just emit our char
+ if (buffer.length === 0) {
+ return charStr;
+ }
+ break;
}
-}
-
-function ReadableState(options, stream) {
- Duplex = Duplex || __webpack_require__(4);
+
+ // determine and set charLength / charReceived
+ this.detectIncompleteChar(buffer);
+
+ var end = buffer.length;
+ if (this.charLength) {
+ // buffer the incomplete character bytes we got
+ buffer.copy(this.charBuffer, 0, buffer.length - this.charReceived, end);
+ end -= this.charReceived;
+ }
+
+ charStr += buffer.toString(this.encoding, 0, end);
+
+ var end = charStr.length - 1;
+ var charCode = charStr.charCodeAt(end);
+ // CESU-8: lead surrogate (D800-DBFF) is also the incomplete character
+ if (charCode >= 0xD800 && charCode <= 0xDBFF) {
+ var size = this.surrogateSize;
+ this.charLength += size;
+ this.charReceived += size;
+ this.charBuffer.copy(this.charBuffer, size, 0, size);
+ buffer.copy(this.charBuffer, 0, 0, size);
+ return charStr.substring(0, end);
+ }
+
+ // or just emit the charStr
+ return charStr;
+};
+
+// detectIncompleteChar determines if there is an incomplete UTF-8 character at
+// the end of the given buffer. If so, it sets this.charLength to the byte
+// length that character, and sets this.charReceived to the number of bytes
+// that are available for this character.
+StringDecoder.prototype.detectIncompleteChar = function(buffer) {
+ // determine how many bytes we have to check at the end of this buffer
+ var i = (buffer.length >= 3) ? 3 : buffer.length;
+
+ // Figure out if one of the last i bytes of our buffer announces an
+ // incomplete char.
+ for (; i > 0; i--) {
+ var c = buffer[buffer.length - i];
+
+ // See http://en.wikipedia.org/wiki/UTF-8#Description
+
+ // 110XXXXX
+ if (i == 1 && c >> 5 == 0x06) {
+ this.charLength = 2;
+ break;
+ }
+
+ // 1110XXXX
+ if (i <= 2 && c >> 4 == 0x0E) {
+ this.charLength = 3;
+ break;
+ }
+
+ // 11110XXX
+ if (i <= 3 && c >> 3 == 0x1E) {
+ this.charLength = 4;
+ break;
+ }
+ }
+ this.charReceived = i;
+};
+
+StringDecoder.prototype.end = function(buffer) {
+ var res = '';
+ if (buffer && buffer.length)
+ res = this.write(buffer);
+
+ if (this.charReceived) {
+ var cr = this.charReceived;
+ var buf = this.charBuffer;
+ var enc = this.encoding;
+ res += buf.slice(0, cr).toString(enc);
+ }
+
+ return res;
+};
+
+function passThroughWrite(buffer) {
+ return buffer.toString(this.encoding);
+}
+
+function utf16DetectIncompleteChar(buffer) {
+ this.charReceived = buffer.length % 2;
+ this.charLength = this.charReceived ? 2 : 0;
+}
+
+function base64DetectIncompleteChar(buffer) {
+ this.charReceived = buffer.length % 3;
+ this.charLength = this.charReceived ? 3 : 0;
+}
+
+
+/***/ }),
+/* 11 */
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+/* WEBPACK VAR INJECTION */(function(process) {// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+
+
+/**/
+
+var processNextTick = __webpack_require__(6);
+/**/
+
+module.exports = Readable;
+
+/**/
+var isArray = __webpack_require__(9);
+/**/
+
+/**/
+var Duplex;
+/**/
+
+Readable.ReadableState = ReadableState;
+
+/**/
+var EE = __webpack_require__(7).EventEmitter;
+
+var EElistenerCount = function (emitter, type) {
+ return emitter.listeners(type).length;
+};
+/**/
+
+/**/
+var Stream = __webpack_require__(15);
+/**/
+
+/**/
+var Buffer = __webpack_require__(8).Buffer;
+function _uint8ArrayToBuffer(chunk) {
+ return Buffer.from(chunk);
+}
+function _isUint8Array(obj) {
+ return Object.prototype.toString.call(obj) === '[object Uint8Array]' || Buffer.isBuffer(obj);
+}
+/**/
+
+/**/
+var util = __webpack_require__(5);
+util.inherits = __webpack_require__(2);
+/**/
+
+/**/
+var debugUtil = __webpack_require__(49);
+var debug = void 0;
+if (debugUtil && debugUtil.debuglog) {
+ debug = debugUtil.debuglog('stream');
+} else {
+ debug = function () {};
+}
+/**/
+
+var BufferList = __webpack_require__(34);
+var destroyImpl = __webpack_require__(14);
+var StringDecoder;
+
+util.inherits(Readable, Stream);
+
+var kProxyEvents = ['error', 'close', 'destroy', 'pause', 'resume'];
+
+function prependListener(emitter, event, fn) {
+ // Sadly this is not cacheable as some libraries bundle their own
+ // event emitter implementation with them.
+ if (typeof emitter.prependListener === 'function') {
+ return emitter.prependListener(event, fn);
+ } else {
+ // This is a hack to make sure that our error handler is attached before any
+ // userland ones. NEVER DO THIS. This is here only because this code needs
+ // to continue to work with older versions of Node.js that do not include
+ // the prependListener() method. The goal is to eventually remove this hack.
+ if (!emitter._events || !emitter._events[event]) emitter.on(event, fn);else if (isArray(emitter._events[event])) emitter._events[event].unshift(fn);else emitter._events[event] = [fn, emitter._events[event]];
+ }
+}
+
+function ReadableState(options, stream) {
+ Duplex = Duplex || __webpack_require__(4);
options = options || {};
@@ -2880,7 +3138,7 @@ function ReadableState(options, stream) {
this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm;
// cast to ints.
- this.highWaterMark = ~~this.highWaterMark;
+ this.highWaterMark = Math.floor(this.highWaterMark);
// A linked list is used to store data chunks instead of an array because the
// linked list can remove elements from the beginning faster than
@@ -2894,10 +3152,10 @@ function ReadableState(options, stream) {
this.endEmitted = false;
this.reading = false;
- // a flag to be able to tell if the onwrite cb is called immediately,
- // or on a later tick. We set this to true at first, because any
- // actions that shouldn't happen until "later" should generally also
- // not happen before the first write call.
+ // a flag to be able to tell if the event 'readable'/'data' is emitted
+ // immediately, or on a later tick. We set this to true at first, because
+ // any actions that shouldn't happen until "later" should generally also
+ // not happen before the first read call.
this.sync = true;
// whenever we return null, then we set a flag to say
@@ -2907,15 +3165,14 @@ function ReadableState(options, stream) {
this.readableListening = false;
this.resumeScheduled = false;
+ // has it been destroyed
+ this.destroyed = false;
+
// Crypto is kind of old and crusty. Historically, its default string
// encoding is 'binary' so we have to make this configurable.
// Everything else in the universe uses 'utf8', though.
this.defaultEncoding = options.defaultEncoding || 'utf8';
- // when piping, we only care about 'readable' events that happen
- // after read()ing all the bytes and not getting any pushback.
- this.ranOut = false;
-
// the number of writers that are awaiting a drain event in .pipe()s
this.awaitDrain = 0;
@@ -2925,7 +3182,7 @@ function ReadableState(options, stream) {
this.decoder = null;
this.encoding = null;
if (options.encoding) {
- if (!StringDecoder) StringDecoder = __webpack_require__(17).StringDecoder;
+ if (!StringDecoder) StringDecoder = __webpack_require__(10).StringDecoder;
this.decoder = new StringDecoder(options.encoding);
this.encoding = options.encoding;
}
@@ -2941,87 +3198,129 @@ function Readable(options) {
// legacy
this.readable = true;
- if (options && typeof options.read === 'function') this._read = options.read;
+ if (options) {
+ if (typeof options.read === 'function') this._read = options.read;
+
+ if (typeof options.destroy === 'function') this._destroy = options.destroy;
+ }
Stream.call(this);
}
+Object.defineProperty(Readable.prototype, 'destroyed', {
+ get: function () {
+ if (this._readableState === undefined) {
+ return false;
+ }
+ return this._readableState.destroyed;
+ },
+ set: function (value) {
+ // we ignore the value if the stream
+ // has not been initialized yet
+ if (!this._readableState) {
+ return;
+ }
+
+ // backward compatibility, the user is explicitly
+ // managing destroyed
+ this._readableState.destroyed = value;
+ }
+});
+
+Readable.prototype.destroy = destroyImpl.destroy;
+Readable.prototype._undestroy = destroyImpl.undestroy;
+Readable.prototype._destroy = function (err, cb) {
+ this.push(null);
+ cb(err);
+};
+
// Manually shove something into the read() buffer.
// This returns true if the highWaterMark has not been hit yet,
// similar to how Writable.write() returns true if you should
// write() some more.
Readable.prototype.push = function (chunk, encoding) {
var state = this._readableState;
-
- if (!state.objectMode && typeof chunk === 'string') {
- encoding = encoding || state.defaultEncoding;
- if (encoding !== state.encoding) {
- chunk = bufferShim.from(chunk, encoding);
- encoding = '';
+ var skipChunkCheck;
+
+ if (!state.objectMode) {
+ if (typeof chunk === 'string') {
+ encoding = encoding || state.defaultEncoding;
+ if (encoding !== state.encoding) {
+ chunk = Buffer.from(chunk, encoding);
+ encoding = '';
+ }
+ skipChunkCheck = true;
}
+ } else {
+ skipChunkCheck = true;
}
- return readableAddChunk(this, state, chunk, encoding, false);
+ return readableAddChunk(this, chunk, encoding, false, skipChunkCheck);
};
// Unshift should *always* be something directly out of read()
Readable.prototype.unshift = function (chunk) {
- var state = this._readableState;
- return readableAddChunk(this, state, chunk, '', true);
-};
-
-Readable.prototype.isPaused = function () {
- return this._readableState.flowing === false;
+ return readableAddChunk(this, chunk, null, true, false);
};
-function readableAddChunk(stream, state, chunk, encoding, addToFront) {
- var er = chunkInvalid(state, chunk);
- if (er) {
- stream.emit('error', er);
- } else if (chunk === null) {
+function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) {
+ var state = stream._readableState;
+ if (chunk === null) {
state.reading = false;
onEofChunk(stream, state);
- } else if (state.objectMode || chunk && chunk.length > 0) {
- if (state.ended && !addToFront) {
- var e = new Error('stream.push() after EOF');
- stream.emit('error', e);
- } else if (state.endEmitted && addToFront) {
- var _e = new Error('stream.unshift() after end event');
- stream.emit('error', _e);
- } else {
- var skipAdd;
- if (state.decoder && !addToFront && !encoding) {
- chunk = state.decoder.write(chunk);
- skipAdd = !state.objectMode && chunk.length === 0;
+ } else {
+ var er;
+ if (!skipChunkCheck) er = chunkInvalid(state, chunk);
+ if (er) {
+ stream.emit('error', er);
+ } else if (state.objectMode || chunk && chunk.length > 0) {
+ if (typeof chunk !== 'string' && Object.getPrototypeOf(chunk) !== Buffer.prototype && !state.objectMode) {
+ chunk = _uint8ArrayToBuffer(chunk);
}
- if (!addToFront) state.reading = false;
-
- // Don't add to the buffer if we've decoded to an empty string chunk and
- // we're not in object mode
- if (!skipAdd) {
- // if we want the data now, just emit it.
- if (state.flowing && state.length === 0 && !state.sync) {
- stream.emit('data', chunk);
- stream.read(0);
+ if (addToFront) {
+ if (state.endEmitted) stream.emit('error', new Error('stream.unshift() after end event'));else addChunk(stream, state, chunk, true);
+ } else if (state.ended) {
+ stream.emit('error', new Error('stream.push() after EOF'));
+ } else {
+ state.reading = false;
+ if (state.decoder && !encoding) {
+ chunk = state.decoder.write(chunk);
+ if (state.objectMode || chunk.length !== 0) addChunk(stream, state, chunk, false);else maybeReadMore(stream, state);
} else {
- // update the buffer info.
- state.length += state.objectMode ? 1 : chunk.length;
- if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk);
-
- if (state.needReadable) emitReadable(stream);
+ addChunk(stream, state, chunk, false);
}
}
-
- maybeReadMore(stream, state);
+ } else if (!addToFront) {
+ state.reading = false;
}
- } else if (!addToFront) {
- state.reading = false;
}
return needMoreData(state);
}
+function addChunk(stream, state, chunk, addToFront) {
+ if (state.flowing && state.length === 0 && !state.sync) {
+ stream.emit('data', chunk);
+ stream.read(0);
+ } else {
+ // update the buffer info.
+ state.length += state.objectMode ? 1 : chunk.length;
+ if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk);
+
+ if (state.needReadable) emitReadable(stream);
+ }
+ maybeReadMore(stream, state);
+}
+
+function chunkInvalid(state, chunk) {
+ var er;
+ if (!_isUint8Array(chunk) && typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
+ er = new TypeError('Invalid non-string/buffer chunk');
+ }
+ return er;
+}
+
// if it's past the high water mark, we can push in some more.
// Also, if we have no data yet, we can stand some
// more bytes. This is to work around cases where hwm=0,
@@ -3033,9 +3332,13 @@ function needMoreData(state) {
return !state.ended && (state.needReadable || state.length < state.highWaterMark || state.length === 0);
}
+Readable.prototype.isPaused = function () {
+ return this._readableState.flowing === false;
+};
+
// backwards compatibility.
Readable.prototype.setEncoding = function (enc) {
- if (!StringDecoder) StringDecoder = __webpack_require__(17).StringDecoder;
+ if (!StringDecoder) StringDecoder = __webpack_require__(10).StringDecoder;
this._readableState.decoder = new StringDecoder(enc);
this._readableState.encoding = enc;
return this;
@@ -3181,14 +3484,6 @@ Readable.prototype.read = function (n) {
return ret;
};
-function chunkInvalid(state, chunk) {
- var er = null;
- if (!Buffer.isBuffer(chunk) && typeof chunk !== 'string' && chunk !== null && chunk !== undefined && !state.objectMode) {
- er = new TypeError('Invalid non-string/buffer chunk');
- }
- return er;
-}
-
function onEofChunk(stream, state) {
if (state.ended) return;
if (state.decoder) {
@@ -3276,14 +3571,17 @@ Readable.prototype.pipe = function (dest, pipeOpts) {
var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr;
- var endFn = doEnd ? onend : cleanup;
+ var endFn = doEnd ? onend : unpipe;
if (state.endEmitted) processNextTick(endFn);else src.once('end', endFn);
dest.on('unpipe', onunpipe);
- function onunpipe(readable) {
+ function onunpipe(readable, unpipeInfo) {
debug('onunpipe');
if (readable === src) {
- cleanup();
+ if (unpipeInfo && unpipeInfo.hasUnpiped === false) {
+ unpipeInfo.hasUnpiped = true;
+ cleanup();
+ }
}
}
@@ -3309,7 +3607,7 @@ Readable.prototype.pipe = function (dest, pipeOpts) {
dest.removeListener('error', onerror);
dest.removeListener('unpipe', onunpipe);
src.removeListener('end', onend);
- src.removeListener('end', cleanup);
+ src.removeListener('end', unpipe);
src.removeListener('data', ondata);
cleanedUp = true;
@@ -3402,6 +3700,7 @@ function pipeOnDrain(src) {
Readable.prototype.unpipe = function (dest) {
var state = this._readableState;
+ var unpipeInfo = { hasUnpiped: false };
// if we're not piping anywhere, then do nothing.
if (state.pipesCount === 0) return this;
@@ -3417,7 +3716,7 @@ Readable.prototype.unpipe = function (dest) {
state.pipes = null;
state.pipesCount = 0;
state.flowing = false;
- if (dest) dest.emit('unpipe', this);
+ if (dest) dest.emit('unpipe', this, unpipeInfo);
return this;
}
@@ -3432,7 +3731,7 @@ Readable.prototype.unpipe = function (dest) {
state.flowing = false;
for (var i = 0; i < len; i++) {
- dests[i].emit('unpipe', this);
+ dests[i].emit('unpipe', this, unpipeInfo);
}return this;
}
@@ -3444,7 +3743,7 @@ Readable.prototype.unpipe = function (dest) {
state.pipesCount -= 1;
if (state.pipesCount === 1) state.pipes = state.pipes[0];
- dest.emit('unpipe', this);
+ dest.emit('unpipe', this, unpipeInfo);
return this;
};
@@ -3465,7 +3764,7 @@ Readable.prototype.on = function (ev, fn) {
if (!state.reading) {
processNextTick(nReadingNextTick, this);
} else if (state.length) {
- emitReadable(this, state);
+ emitReadable(this);
}
}
}
@@ -3666,7 +3965,7 @@ function copyFromBufferString(n, list) {
// This function is designed to be inlinable, so please take care when making
// changes to the function body.
function copyFromBuffer(n, list) {
- var ret = bufferShim.allocUnsafe(n);
+ var ret = Buffer.allocUnsafe(n);
var p = list.head;
var c = 1;
p.data.copy(ret);
@@ -3726,17 +4025,38 @@ function indexOf(xs, x) {
}
return -1;
}
-/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(2)))
+/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(1)))
/***/ }),
-/* 11 */
+/* 12 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
-// a transform stream is a readable/writable stream where you do
-// something with the data. Sometimes it's called a "filter",
-// but that's not a great name for it, since that implies a thing where
-// some bits pass through, and others are simply ignored. (That would
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+// a transform stream is a readable/writable stream where you do
+// something with the data. Sometimes it's called a "filter",
+// but that's not a great name for it, since that implies a thing where
+// some bits pass through, and others are simply ignored. (That would
// be a valid example of a transform, of course.)
//
// While the output is causally related to the input, it's not a
@@ -3783,7 +4103,7 @@ var Duplex = __webpack_require__(4);
/**/
var util = __webpack_require__(5);
-util.inherits = __webpack_require__(3);
+util.inherits = __webpack_require__(2);
/**/
util.inherits(Transform, Duplex);
@@ -3806,7 +4126,9 @@ function afterTransform(stream, er, data) {
var cb = ts.writecb;
- if (!cb) return stream.emit('error', new Error('no writecb in Transform class'));
+ if (!cb) {
+ return stream.emit('error', new Error('write callback called multiple times'));
+ }
ts.writechunk = null;
ts.writecb = null;
@@ -3899,6 +4221,15 @@ Transform.prototype._read = function (n) {
}
};
+Transform.prototype._destroy = function (err, cb) {
+ var _this = this;
+
+ Duplex.prototype._destroy.call(this, err, function (err2) {
+ cb(err2);
+ _this.emit('close');
+ });
+};
+
function done(stream, er, data) {
if (er) return stream.emit('error', er);
@@ -3917,22 +4248,61 @@ function done(stream, er, data) {
}
/***/ }),
-/* 12 */
+/* 13 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
-/* WEBPACK VAR INJECTION */(function(process, setImmediate) {// A bit simpler than readable streams.
+/* WEBPACK VAR INJECTION */(function(process, setImmediate) {// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+// A bit simpler than readable streams.
// Implement an async ._write(chunk, encoding, cb), and it'll handle all
// the drain event emission and buffering.
-module.exports = Writable;
-
/**/
-var processNextTick = __webpack_require__(8);
+
+var processNextTick = __webpack_require__(6);
/**/
+module.exports = Writable;
+
+/* */
+function WriteReq(chunk, encoding, cb) {
+ this.chunk = chunk;
+ this.encoding = encoding;
+ this.callback = cb;
+ this.next = null;
+}
+
+// It seems a linked list but it is not
+// there will be only 2 of these for each stream
+function CorkedRequest(state) {
+ this.next = null;
+ this.entry = null;
+ this.finish = onCorkedFinish.bind(undefined, this, state);
+}
+/* */
+
/**/
var asyncWrite = !process.browser && ['v0.10', 'v0.9.'].indexOf(process.version.slice(0, 5)) > -1 ? setImmediate : processNextTick;
/**/
@@ -3945,35 +4315,35 @@ Writable.WritableState = WritableState;
/**/
var util = __webpack_require__(5);
-util.inherits = __webpack_require__(3);
+util.inherits = __webpack_require__(2);
/**/
/**/
var internalUtil = {
- deprecate: __webpack_require__(42)
+ deprecate: __webpack_require__(43)
};
/**/
/**/
-var Stream = __webpack_require__(13);
+var Stream = __webpack_require__(15);
/**/
-var Buffer = __webpack_require__(1).Buffer;
/**/
-var bufferShim = __webpack_require__(6);
+var Buffer = __webpack_require__(8).Buffer;
+function _uint8ArrayToBuffer(chunk) {
+ return Buffer.from(chunk);
+}
+function _isUint8Array(obj) {
+ return Object.prototype.toString.call(obj) === '[object Uint8Array]' || Buffer.isBuffer(obj);
+}
/**/
+var destroyImpl = __webpack_require__(14);
+
util.inherits(Writable, Stream);
function nop() {}
-function WriteReq(chunk, encoding, cb) {
- this.chunk = chunk;
- this.encoding = encoding;
- this.callback = cb;
- this.next = null;
-}
-
function WritableState(options, stream) {
Duplex = Duplex || __webpack_require__(4);
@@ -3993,7 +4363,10 @@ function WritableState(options, stream) {
this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm;
// cast to ints.
- this.highWaterMark = ~~this.highWaterMark;
+ this.highWaterMark = Math.floor(this.highWaterMark);
+
+ // if _final has been called
+ this.finalCalled = false;
// drain event flag.
this.needDrain = false;
@@ -4004,6 +4377,9 @@ function WritableState(options, stream) {
// when 'finish' is emitted
this.finished = false;
+ // has it been destroyed
+ this.destroyed = false;
+
// should we decode strings into buffers before passing to _write?
// this is here so that some node-core streams can optimize string
// handling at a lower level.
@@ -4085,7 +4461,7 @@ WritableState.prototype.getBuffer = function getBuffer() {
Object.defineProperty(WritableState.prototype, 'buffer', {
get: internalUtil.deprecate(function () {
return this.getBuffer();
- }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.')
+ }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.', 'DEP0003')
});
} catch (_) {}
})();
@@ -4131,6 +4507,10 @@ function Writable(options) {
if (typeof options.write === 'function') this._write = options.write;
if (typeof options.writev === 'function') this._writev = options.writev;
+
+ if (typeof options.destroy === 'function') this._destroy = options.destroy;
+
+ if (typeof options.final === 'function') this._final = options.final;
}
Stream.call(this);
@@ -4171,7 +4551,11 @@ function validChunk(stream, state, chunk, cb) {
Writable.prototype.write = function (chunk, encoding, cb) {
var state = this._writableState;
var ret = false;
- var isBuf = Buffer.isBuffer(chunk);
+ var isBuf = _isUint8Array(chunk) && !state.objectMode;
+
+ if (isBuf && !Buffer.isBuffer(chunk)) {
+ chunk = _uint8ArrayToBuffer(chunk);
+ }
if (typeof encoding === 'function') {
cb = encoding;
@@ -4216,7 +4600,7 @@ Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
function decodeChunk(state, chunk, encoding) {
if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') {
- chunk = bufferShim.from(chunk, encoding);
+ chunk = Buffer.from(chunk, encoding);
}
return chunk;
}
@@ -4226,8 +4610,12 @@ function decodeChunk(state, chunk, encoding) {
// If we return false, then we need a drain event, so set that flag.
function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) {
if (!isBuf) {
- chunk = decodeChunk(state, chunk, encoding);
- if (Buffer.isBuffer(chunk)) encoding = 'buffer';
+ var newChunk = decodeChunk(state, chunk, encoding);
+ if (chunk !== newChunk) {
+ isBuf = true;
+ encoding = 'buffer';
+ chunk = newChunk;
+ }
}
var len = state.objectMode ? 1 : chunk.length;
@@ -4239,7 +4627,13 @@ function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) {
if (state.writing || state.corked) {
var last = state.lastBufferedRequest;
- state.lastBufferedRequest = new WriteReq(chunk, encoding, cb);
+ state.lastBufferedRequest = {
+ chunk: chunk,
+ encoding: encoding,
+ isBuf: isBuf,
+ callback: cb,
+ next: null
+ };
if (last) {
last.next = state.lastBufferedRequest;
} else {
@@ -4264,12 +4658,17 @@ function doWrite(stream, state, writev, len, chunk, encoding, cb) {
function onwriteError(stream, state, sync, er, cb) {
--state.pendingcb;
- if (sync) processNextTick(cb, er);else cb(er);
+ if (sync) processNextTick(afterError, stream, state, cb, er);else afterError(stream, state, cb, er);
stream._writableState.errorEmitted = true;
stream.emit('error', er);
}
+function afterError(stream, state, cb, err) {
+ cb(err);
+ finishMaybe(stream, state);
+}
+
function onwriteStateUpdate(state) {
state.writing = false;
state.writecb = null;
@@ -4332,11 +4731,14 @@ function clearBuffer(stream, state) {
holder.entry = entry;
var count = 0;
+ var allBuffers = true;
while (entry) {
buffer[count] = entry;
+ if (!entry.isBuf) allBuffers = false;
entry = entry.next;
count += 1;
}
+ buffer.allBuffers = allBuffers;
doWrite(stream, state, true, state.length, buffer, '', holder.finish);
@@ -4410,23 +4812,37 @@ Writable.prototype.end = function (chunk, encoding, cb) {
function needFinish(state) {
return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing;
}
-
-function prefinish(stream, state) {
- if (!state.prefinished) {
+function callFinal(stream, state) {
+ stream._final(function (err) {
+ state.pendingcb--;
+ if (err) {
+ stream.emit('error', err);
+ }
state.prefinished = true;
stream.emit('prefinish');
+ finishMaybe(stream, state);
+ });
+}
+function prefinish(stream, state) {
+ if (!state.prefinished && !state.finalCalled) {
+ if (typeof stream._final === 'function') {
+ state.pendingcb++;
+ state.finalCalled = true;
+ processNextTick(callFinal, stream, state);
+ } else {
+ state.prefinished = true;
+ stream.emit('prefinish');
+ }
}
}
function finishMaybe(stream, state) {
var need = needFinish(state);
if (need) {
+ prefinish(stream, state);
if (state.pendingcb === 0) {
- prefinish(stream, state);
state.finished = true;
stream.emit('finish');
- } else {
- prefinish(stream, state);
}
}
return need;
@@ -4442,59 +4858,156 @@ function endWritable(stream, state, cb) {
stream.writable = false;
}
-// It seems a linked list but it is not
-// there will be only 2 of these for each stream
-function CorkedRequest(state) {
+function onCorkedFinish(corkReq, state, err) {
+ var entry = corkReq.entry;
+ corkReq.entry = null;
+ while (entry) {
+ var cb = entry.callback;
+ state.pendingcb--;
+ cb(err);
+ entry = entry.next;
+ }
+ if (state.corkedRequestsFree) {
+ state.corkedRequestsFree.next = corkReq;
+ } else {
+ state.corkedRequestsFree = corkReq;
+ }
+}
+
+Object.defineProperty(Writable.prototype, 'destroyed', {
+ get: function () {
+ if (this._writableState === undefined) {
+ return false;
+ }
+ return this._writableState.destroyed;
+ },
+ set: function (value) {
+ // we ignore the value if the stream
+ // has not been initialized yet
+ if (!this._writableState) {
+ return;
+ }
+
+ // backward compatibility, the user is explicitly
+ // managing destroyed
+ this._writableState.destroyed = value;
+ }
+});
+
+Writable.prototype.destroy = destroyImpl.destroy;
+Writable.prototype._undestroy = destroyImpl.undestroy;
+Writable.prototype._destroy = function (err, cb) {
+ this.end();
+ cb(err);
+};
+/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(1), __webpack_require__(39).setImmediate))
+
+/***/ }),
+/* 14 */
+/***/ (function(module, exports, __webpack_require__) {
+
+"use strict";
+
+
+/**/
+
+var processNextTick = __webpack_require__(6);
+/**/
+
+// undocumented cb() API, needed for core, not for public API
+function destroy(err, cb) {
var _this = this;
- this.next = null;
- this.entry = null;
- this.finish = function (err) {
- var entry = _this.entry;
- _this.entry = null;
- while (entry) {
- var cb = entry.callback;
- state.pendingcb--;
+ var readableDestroyed = this._readableState && this._readableState.destroyed;
+ var writableDestroyed = this._writableState && this._writableState.destroyed;
+
+ if (readableDestroyed || writableDestroyed) {
+ if (cb) {
cb(err);
- entry = entry.next;
+ } else if (err && (!this._writableState || !this._writableState.errorEmitted)) {
+ processNextTick(emitErrorNT, this, err);
}
- if (state.corkedRequestsFree) {
- state.corkedRequestsFree.next = _this;
- } else {
- state.corkedRequestsFree = _this;
+ return;
+ }
+
+ // we set destroyed to true before firing error callbacks in order
+ // to make it re-entrance safe in case destroy() is called within callbacks
+
+ if (this._readableState) {
+ this._readableState.destroyed = true;
+ }
+
+ // if this is a duplex stream mark the writable part as destroyed as well
+ if (this._writableState) {
+ this._writableState.destroyed = true;
+ }
+
+ this._destroy(err || null, function (err) {
+ if (!cb && err) {
+ processNextTick(emitErrorNT, _this, err);
+ if (_this._writableState) {
+ _this._writableState.errorEmitted = true;
+ }
+ } else if (cb) {
+ cb(err);
}
- };
+ });
+}
+
+function undestroy() {
+ if (this._readableState) {
+ this._readableState.destroyed = false;
+ this._readableState.reading = false;
+ this._readableState.ended = false;
+ this._readableState.endEmitted = false;
+ }
+
+ if (this._writableState) {
+ this._writableState.destroyed = false;
+ this._writableState.ended = false;
+ this._writableState.ending = false;
+ this._writableState.finished = false;
+ this._writableState.errorEmitted = false;
+ }
+}
+
+function emitErrorNT(self, err) {
+ self.emit('error', err);
}
-/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(2), __webpack_require__(38).setImmediate))
+
+module.exports = {
+ destroy: destroy,
+ undestroy: undestroy
+};
/***/ }),
-/* 13 */
+/* 15 */
/***/ (function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(7).EventEmitter;
/***/ }),
-/* 14 */
+/* 16 */
/***/ (function(module, exports, __webpack_require__) {
-exports = module.exports = __webpack_require__(10);
+exports = module.exports = __webpack_require__(11);
exports.Stream = exports;
exports.Readable = exports;
-exports.Writable = __webpack_require__(12);
+exports.Writable = __webpack_require__(13);
exports.Duplex = __webpack_require__(4);
-exports.Transform = __webpack_require__(11);
-exports.PassThrough = __webpack_require__(32);
+exports.Transform = __webpack_require__(12);
+exports.PassThrough = __webpack_require__(33);
/***/ }),
-/* 15 */
+/* 17 */
/***/ (function(module, exports, __webpack_require__) {
-/* WEBPACK VAR INJECTION */(function(global) {var ClientRequest = __webpack_require__(36)
-var extend = __webpack_require__(47)
-var statusCodes = __webpack_require__(23)
-var url = __webpack_require__(19)
+/* WEBPACK VAR INJECTION */(function(global) {var ClientRequest = __webpack_require__(37)
+var extend = __webpack_require__(48)
+var statusCodes = __webpack_require__(24)
+var url = __webpack_require__(20)
var http = exports
@@ -4573,318 +5086,91 @@ http.METHODS = [
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(0)))
/***/ }),
-/* 16 */
-/***/ (function(module, exports, __webpack_require__) {
-
-/* WEBPACK VAR INJECTION */(function(global) {exports.fetch = isFunction(global.fetch) && isFunction(global.ReadableStream)
-
-exports.blobConstructor = false
-try {
- new Blob([new ArrayBuffer(1)])
- exports.blobConstructor = true
-} catch (e) {}
-
-// The xhr request to example.com may violate some restrictive CSP configurations,
-// so if we're running in a browser that supports `fetch`, avoid calling getXHR()
-// and assume support for certain features below.
-var xhr
-function getXHR () {
- // Cache the xhr value
- if (xhr !== undefined) return xhr
-
- if (global.XMLHttpRequest) {
- xhr = new global.XMLHttpRequest()
- // If XDomainRequest is available (ie only, where xhr might not work
- // cross domain), use the page location. Otherwise use example.com
- // Note: this doesn't actually make an http request.
- try {
- xhr.open('GET', global.XDomainRequest ? '/' : 'https://example.com')
- } catch(e) {
- xhr = null
- }
- } else {
- // Service workers don't have XHR
- xhr = null
- }
- return xhr
-}
-
-function checkTypeSupport (type) {
- var xhr = getXHR()
- if (!xhr) return false
- try {
- xhr.responseType = type
- return xhr.responseType === type
- } catch (e) {}
- return false
-}
-
-// For some strange reason, Safari 7.0 reports typeof global.ArrayBuffer === 'object'.
-// Safari 7.1 appears to have fixed this bug.
-var haveArrayBuffer = typeof global.ArrayBuffer !== 'undefined'
-var haveSlice = haveArrayBuffer && isFunction(global.ArrayBuffer.prototype.slice)
-
-// If fetch is supported, then arraybuffer will be supported too. Skip calling
-// checkTypeSupport(), since that calls getXHR().
-exports.arraybuffer = exports.fetch || (haveArrayBuffer && checkTypeSupport('arraybuffer'))
-
-// These next two tests unavoidably show warnings in Chrome. Since fetch will always
-// be used if it's available, just return false for these to avoid the warnings.
-exports.msstream = !exports.fetch && haveSlice && checkTypeSupport('ms-stream')
-exports.mozchunkedarraybuffer = !exports.fetch && haveArrayBuffer &&
- checkTypeSupport('moz-chunked-arraybuffer')
-
-// If fetch is supported, then overrideMimeType will be supported too. Skip calling
-// getXHR().
-exports.overrideMimeType = exports.fetch || (getXHR() ? isFunction(getXHR().overrideMimeType) : false)
-
-exports.vbArray = isFunction(global.VBArray)
-
-function isFunction (value) {
- return typeof value === 'function'
-}
-
-xhr = null // Help gc
-
-/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(0)))
-
-/***/ }),
-/* 17 */
+/* 18 */
/***/ (function(module, exports, __webpack_require__) {
-// Copyright Joyent, Inc. and other Node contributors.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a
-// copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to permit
-// persons to whom the Software is furnished to do so, subject to the
-// following conditions:
-//
-// The above copyright notice and this permission notice shall be included
-// in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
-// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
-// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
-// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
-// USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-var Buffer = __webpack_require__(1).Buffer;
-
-var isBufferEncoding = Buffer.isEncoding
- || function(encoding) {
- switch (encoding && encoding.toLowerCase()) {
- case 'hex': case 'utf8': case 'utf-8': case 'ascii': case 'binary': case 'base64': case 'ucs2': case 'ucs-2': case 'utf16le': case 'utf-16le': case 'raw': return true;
- default: return false;
- }
- }
-
-
-function assertEncoding(encoding) {
- if (encoding && !isBufferEncoding(encoding)) {
- throw new Error('Unknown encoding: ' + encoding);
- }
-}
-
-// StringDecoder provides an interface for efficiently splitting a series of
-// buffers into a series of JS strings without breaking apart multi-byte
-// characters. CESU-8 is handled as part of the UTF-8 encoding.
-//
-// @TODO Handling all encodings inside a single object makes it very difficult
-// to reason about this code, so it should be split up in the future.
-// @TODO There should be a utf8-strict encoding that rejects invalid UTF-8 code
-// points as used by CESU-8.
-var StringDecoder = exports.StringDecoder = function(encoding) {
- this.encoding = (encoding || 'utf8').toLowerCase().replace(/[-_]/, '');
- assertEncoding(encoding);
- switch (this.encoding) {
- case 'utf8':
- // CESU-8 represents each of Surrogate Pair by 3-bytes
- this.surrogateSize = 3;
- break;
- case 'ucs2':
- case 'utf16le':
- // UTF-16 represents each of Surrogate Pair by 2-bytes
- this.surrogateSize = 2;
- this.detectIncompleteChar = utf16DetectIncompleteChar;
- break;
- case 'base64':
- // Base-64 stores 3 bytes in 4 chars, and pads the remainder.
- this.surrogateSize = 3;
- this.detectIncompleteChar = base64DetectIncompleteChar;
- break;
- default:
- this.write = passThroughWrite;
- return;
- }
-
- // Enough space to store all bytes of a single character. UTF-8 needs 4
- // bytes, but CESU-8 may require up to 6 (3 bytes per surrogate).
- this.charBuffer = new Buffer(6);
- // Number of bytes received for the current incomplete multi-byte character.
- this.charReceived = 0;
- // Number of bytes expected for the current incomplete multi-byte character.
- this.charLength = 0;
-};
-
-
-// write decodes the given buffer and returns it as JS string that is
-// guaranteed to not contain any partial multi-byte characters. Any partial
-// character found at the end of the buffer is buffered up, and will be
-// returned when calling write again with the remaining bytes.
-//
-// Note: Converting a Buffer containing an orphan surrogate to a String
-// currently works, but converting a String to a Buffer (via `new Buffer`, or
-// Buffer#write) will replace incomplete surrogates with the unicode
-// replacement character. See https://codereview.chromium.org/121173009/ .
-StringDecoder.prototype.write = function(buffer) {
- var charStr = '';
- // if our last write ended with an incomplete multibyte character
- while (this.charLength) {
- // determine how many remaining bytes this buffer has to offer for this char
- var available = (buffer.length >= this.charLength - this.charReceived) ?
- this.charLength - this.charReceived :
- buffer.length;
-
- // add the new bytes to the char buffer
- buffer.copy(this.charBuffer, this.charReceived, 0, available);
- this.charReceived += available;
-
- if (this.charReceived < this.charLength) {
- // still not enough chars in this buffer? wait for more ...
- return '';
- }
-
- // remove bytes belonging to the current character from the buffer
- buffer = buffer.slice(available, buffer.length);
-
- // get the character that was split
- charStr = this.charBuffer.slice(0, this.charLength).toString(this.encoding);
-
- // CESU-8: lead surrogate (D800-DBFF) is also the incomplete character
- var charCode = charStr.charCodeAt(charStr.length - 1);
- if (charCode >= 0xD800 && charCode <= 0xDBFF) {
- this.charLength += this.surrogateSize;
- charStr = '';
- continue;
- }
- this.charReceived = this.charLength = 0;
-
- // if there are no more bytes in this buffer, just emit our char
- if (buffer.length === 0) {
- return charStr;
- }
- break;
- }
-
- // determine and set charLength / charReceived
- this.detectIncompleteChar(buffer);
-
- var end = buffer.length;
- if (this.charLength) {
- // buffer the incomplete character bytes we got
- buffer.copy(this.charBuffer, 0, buffer.length - this.charReceived, end);
- end -= this.charReceived;
- }
-
- charStr += buffer.toString(this.encoding, 0, end);
-
- var end = charStr.length - 1;
- var charCode = charStr.charCodeAt(end);
- // CESU-8: lead surrogate (D800-DBFF) is also the incomplete character
- if (charCode >= 0xD800 && charCode <= 0xDBFF) {
- var size = this.surrogateSize;
- this.charLength += size;
- this.charReceived += size;
- this.charBuffer.copy(this.charBuffer, size, 0, size);
- buffer.copy(this.charBuffer, 0, 0, size);
- return charStr.substring(0, end);
- }
-
- // or just emit the charStr
- return charStr;
-};
-
-// detectIncompleteChar determines if there is an incomplete UTF-8 character at
-// the end of the given buffer. If so, it sets this.charLength to the byte
-// length that character, and sets this.charReceived to the number of bytes
-// that are available for this character.
-StringDecoder.prototype.detectIncompleteChar = function(buffer) {
- // determine how many bytes we have to check at the end of this buffer
- var i = (buffer.length >= 3) ? 3 : buffer.length;
-
- // Figure out if one of the last i bytes of our buffer announces an
- // incomplete char.
- for (; i > 0; i--) {
- var c = buffer[buffer.length - i];
+/* WEBPACK VAR INJECTION */(function(global) {exports.fetch = isFunction(global.fetch) && isFunction(global.ReadableStream)
- // See http://en.wikipedia.org/wiki/UTF-8#Description
+exports.blobConstructor = false
+try {
+ new Blob([new ArrayBuffer(1)])
+ exports.blobConstructor = true
+} catch (e) {}
- // 110XXXXX
- if (i == 1 && c >> 5 == 0x06) {
- this.charLength = 2;
- break;
- }
+// The xhr request to example.com may violate some restrictive CSP configurations,
+// so if we're running in a browser that supports `fetch`, avoid calling getXHR()
+// and assume support for certain features below.
+var xhr
+function getXHR () {
+ // Cache the xhr value
+ if (xhr !== undefined) return xhr
- // 1110XXXX
- if (i <= 2 && c >> 4 == 0x0E) {
- this.charLength = 3;
- break;
- }
+ if (global.XMLHttpRequest) {
+ xhr = new global.XMLHttpRequest()
+ // If XDomainRequest is available (ie only, where xhr might not work
+ // cross domain), use the page location. Otherwise use example.com
+ // Note: this doesn't actually make an http request.
+ try {
+ xhr.open('GET', global.XDomainRequest ? '/' : 'https://example.com')
+ } catch(e) {
+ xhr = null
+ }
+ } else {
+ // Service workers don't have XHR
+ xhr = null
+ }
+ return xhr
+}
- // 11110XXX
- if (i <= 3 && c >> 3 == 0x1E) {
- this.charLength = 4;
- break;
- }
- }
- this.charReceived = i;
-};
+function checkTypeSupport (type) {
+ var xhr = getXHR()
+ if (!xhr) return false
+ try {
+ xhr.responseType = type
+ return xhr.responseType === type
+ } catch (e) {}
+ return false
+}
-StringDecoder.prototype.end = function(buffer) {
- var res = '';
- if (buffer && buffer.length)
- res = this.write(buffer);
+// For some strange reason, Safari 7.0 reports typeof global.ArrayBuffer === 'object'.
+// Safari 7.1 appears to have fixed this bug.
+var haveArrayBuffer = typeof global.ArrayBuffer !== 'undefined'
+var haveSlice = haveArrayBuffer && isFunction(global.ArrayBuffer.prototype.slice)
- if (this.charReceived) {
- var cr = this.charReceived;
- var buf = this.charBuffer;
- var enc = this.encoding;
- res += buf.slice(0, cr).toString(enc);
- }
+// If fetch is supported, then arraybuffer will be supported too. Skip calling
+// checkTypeSupport(), since that calls getXHR().
+exports.arraybuffer = exports.fetch || (haveArrayBuffer && checkTypeSupport('arraybuffer'))
- return res;
-};
+// These next two tests unavoidably show warnings in Chrome. Since fetch will always
+// be used if it's available, just return false for these to avoid the warnings.
+exports.msstream = !exports.fetch && haveSlice && checkTypeSupport('ms-stream')
+exports.mozchunkedarraybuffer = !exports.fetch && haveArrayBuffer &&
+ checkTypeSupport('moz-chunked-arraybuffer')
-function passThroughWrite(buffer) {
- return buffer.toString(this.encoding);
-}
+// If fetch is supported, then overrideMimeType will be supported too. Skip calling
+// getXHR().
+exports.overrideMimeType = exports.fetch || (getXHR() ? isFunction(getXHR().overrideMimeType) : false)
-function utf16DetectIncompleteChar(buffer) {
- this.charReceived = buffer.length % 2;
- this.charLength = this.charReceived ? 2 : 0;
-}
+exports.vbArray = isFunction(global.VBArray)
-function base64DetectIncompleteChar(buffer) {
- this.charReceived = buffer.length % 3;
- this.charLength = this.charReceived ? 3 : 0;
+function isFunction (value) {
+ return typeof value === 'function'
}
+xhr = null // Help gc
+
+/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(0)))
/***/ }),
-/* 18 */
+/* 19 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
-var required = __webpack_require__(34)
- , lolcation = __webpack_require__(40)
- , qs = __webpack_require__(31)
+var required = __webpack_require__(35)
+ , lolcation = __webpack_require__(41)
+ , qs = __webpack_require__(32)
, relativere = /^\/(?!\/)/;
/**
@@ -5111,7 +5397,7 @@ module.exports = URL;
/***/ }),
-/* 19 */
+/* 20 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
@@ -5138,8 +5424,8 @@ module.exports = URL;
-var punycode = __webpack_require__(27);
-var util = __webpack_require__(41);
+var punycode = __webpack_require__(28);
+var util = __webpack_require__(42);
exports.parse = urlParse;
exports.resolve = urlResolve;
@@ -5214,7 +5500,7 @@ var protocolPattern = /^([a-z0-9.+-]+:)/i,
'gopher:': true,
'file:': true
},
- querystring = __webpack_require__(30);
+ querystring = __webpack_require__(31);
function urlParse(url, parseQueryString, slashesDenoteHost) {
if (url && util.isObject(url) && url instanceof Url) return url;
@@ -5850,15 +6136,20 @@ Url.prototype.parseHost = function() {
/***/ }),
-/* 20 */
+/* 21 */
/***/ (function(module, exports, __webpack_require__) {
-/* WEBPACK VAR INJECTION */(function(process) {var original = __webpack_require__(26)
- , parse = __webpack_require__(19).parse
- , events = __webpack_require__(7)
- , https = __webpack_require__(24)
- , http = __webpack_require__(15)
- , util = __webpack_require__(45);
+/* WEBPACK VAR INJECTION */(function(process) {var original = __webpack_require__(27)
+var parse = __webpack_require__(20).parse
+var events = __webpack_require__(7)
+var https = __webpack_require__(25)
+var http = __webpack_require__(17)
+var util = __webpack_require__(46)
+
+var httpsOptions = [
+ 'pfx', 'key', 'passphrase', 'cert', 'ca', 'ciphers',
+ 'rejectUnauthorized', 'secureProtocol', 'servername'
+]
/**
* Creates a new EventSource object
@@ -5867,235 +6158,267 @@ Url.prototype.parseHost = function() {
* @param {Object} [eventSourceInitDict] extra init params. See README for details.
* @api public
**/
-function EventSource(url, eventSourceInitDict) {
- var readyState = EventSource.CONNECTING;
+function EventSource (url, eventSourceInitDict) {
+ var readyState = EventSource.CONNECTING
Object.defineProperty(this, 'readyState', {
get: function () {
- return readyState;
+ return readyState
}
- });
+ })
Object.defineProperty(this, 'url', {
get: function () {
- return url;
+ return url
}
- });
+ })
- var self = this;
- self.reconnectInterval = 1000;
+ var self = this
+ self.reconnectInterval = 1000
- function onConnectionClosed() {
- if (readyState === EventSource.CLOSED) return;
- readyState = EventSource.CONNECTING;
- _emit('error', new Event('error'));
+ function onConnectionClosed () {
+ if (readyState === EventSource.CLOSED) return
+ readyState = EventSource.CONNECTING
+ _emit('error', new Event('error'))
// The url may have been changed by a temporary
// redirect. If that's the case, revert it now.
if (reconnectUrl) {
- url = reconnectUrl;
- reconnectUrl = null;
+ url = reconnectUrl
+ reconnectUrl = null
}
setTimeout(function () {
if (readyState !== EventSource.CONNECTING) {
- return;
+ return
}
- connect();
- }, self.reconnectInterval);
+ connect()
+ }, self.reconnectInterval)
}
- var req;
- var lastEventId = '';
+ var req
+ var lastEventId = ''
if (eventSourceInitDict && eventSourceInitDict.headers && eventSourceInitDict.headers['Last-Event-ID']) {
- lastEventId = eventSourceInitDict.headers['Last-Event-ID'];
- delete eventSourceInitDict.headers['Last-Event-ID'];
+ lastEventId = eventSourceInitDict.headers['Last-Event-ID']
+ delete eventSourceInitDict.headers['Last-Event-ID']
}
var discardTrailingNewline = false
- , data = ''
- , eventName = '';
-
- var reconnectUrl = null;
+ var data = ''
+ var eventName = ''
- function connect() {
+ var reconnectUrl = null
- var options = parse(url);
- var isSecure = options.protocol == 'https:';
- options.headers = { 'Cache-Control': 'no-cache', 'Accept': 'text/event-stream' };
- if (lastEventId) options.headers['Last-Event-ID'] = lastEventId;
+ function connect () {
+ var options = parse(url)
+ var isSecure = options.protocol === 'https:'
+ options.headers = { 'Cache-Control': 'no-cache', 'Accept': 'text/event-stream' }
+ if (lastEventId) options.headers['Last-Event-ID'] = lastEventId
if (eventSourceInitDict && eventSourceInitDict.headers) {
for (var i in eventSourceInitDict.headers) {
- var header = eventSourceInitDict.headers[i];
+ var header = eventSourceInitDict.headers[i]
if (header) {
- options.headers[i] = header;
+ options.headers[i] = header
}
}
}
- options.rejectUnauthorized = !(eventSourceInitDict && eventSourceInitDict.rejectUnauthorized == false);
+ // Legacy: this should be specified as `eventSourceInitDict.https.rejectUnauthorized`,
+ // but for now exists as a backwards-compatibility layer
+ options.rejectUnauthorized = !(eventSourceInitDict && !eventSourceInitDict.rejectUnauthorized)
// If specify http proxy, make the request to sent to the proxy server,
// and include the original url in path and Host headers
- if (eventSourceInitDict && eventSourceInitDict.proxy) {
- var proxy = parse(eventSourceInitDict.proxy);
- options.path = url;
- options.headers.Host = options.host;
- options.hostname = proxy.hostname;
- options.host = proxy.host;
- options.port = proxy.port;
+ var useProxy = eventSourceInitDict && eventSourceInitDict.proxy
+ if (useProxy) {
+ var proxy = parse(eventSourceInitDict.proxy)
+ isSecure = proxy.protocol === 'https:'
+
+ options.protocol = isSecure ? 'https:' : 'http:'
+ options.path = url
+ options.headers.Host = options.host
+ options.hostname = proxy.hostname
+ options.host = proxy.host
+ options.port = proxy.port
+ }
+
+ // If https options are specified, merge them into the request options
+ if (eventSourceInitDict && eventSourceInitDict.https) {
+ for (var optName in eventSourceInitDict.https) {
+ if (httpsOptions.indexOf(optName) === -1) {
+ continue
+ }
+
+ var option = eventSourceInitDict.https[optName]
+ if (option !== undefined) {
+ options[optName] = option
+ }
+ }
+ }
+
+ // Pass this on to the XHR
+ if (eventSourceInitDict && eventSourceInitDict.withCredentials !== undefined) {
+ options.withCredentials = eventSourceInitDict.withCredentials
}
req = (isSecure ? https : http).request(options, function (res) {
+ // Handle HTTP errors
+ if (res.statusCode === 500 || res.statusCode === 502 || res.statusCode === 503 || res.statusCode === 504) {
+ _emit('error', new Event('error', {status: res.statusCode}))
+ onConnectionClosed()
+ return
+ }
+
// Handle HTTP redirects
- if (res.statusCode == 301 || res.statusCode == 307) {
+ if (res.statusCode === 301 || res.statusCode === 307) {
if (!res.headers.location) {
// Server sent redirect response without Location header.
- _emit('error', new Event('error', {status: res.statusCode}));
- return;
+ _emit('error', new Event('error', {status: res.statusCode}))
+ return
}
- if (res.statusCode == 307) reconnectUrl = url;
- url = res.headers.location;
- process.nextTick(connect);
- return;
+ if (res.statusCode === 307) reconnectUrl = url
+ url = res.headers.location
+ process.nextTick(connect)
+ return
}
if (res.statusCode !== 200) {
- _emit('error', new Event('error', {status: res.statusCode}));
- if (res.statusCode == 204) return self.close();
- return
+ _emit('error', new Event('error', {status: res.statusCode}))
+ return self.close()
}
- readyState = EventSource.OPEN;
- res.on('close', function() {
- res.removeAllListeners('close');
- res.removeAllListeners('end');
- onConnectionClosed();
- });
+ readyState = EventSource.OPEN
+ res.on('close', function () {
+ res.removeAllListeners('close')
+ res.removeAllListeners('end')
+ onConnectionClosed()
+ })
- res.on('end', function() {
- res.removeAllListeners('close');
- res.removeAllListeners('end');
- onConnectionClosed();
- });
- _emit('open', new Event('open'));
+ res.on('end', function () {
+ res.removeAllListeners('close')
+ res.removeAllListeners('end')
+ onConnectionClosed()
+ })
+ _emit('open', new Event('open'))
// text/event-stream parser adapted from webkit's
// Source/WebCore/page/EventSource.cpp
- var buf = '';
+ var buf = ''
res.on('data', function (chunk) {
- buf += chunk;
+ buf += chunk
var pos = 0
- , length = buf.length;
+ var length = buf.length
+
while (pos < length) {
if (discardTrailingNewline) {
if (buf[pos] === '\n') {
- ++pos;
+ ++pos
}
- discardTrailingNewline = false;
+ discardTrailingNewline = false
}
var lineLength = -1
- , fieldLength = -1
- , c;
+ var fieldLength = -1
+ var c
for (var i = pos; lineLength < 0 && i < length; ++i) {
- c = buf[i];
+ c = buf[i]
if (c === ':') {
if (fieldLength < 0) {
- fieldLength = i - pos;
+ fieldLength = i - pos
}
} else if (c === '\r') {
- discardTrailingNewline = true;
- lineLength = i - pos;
+ discardTrailingNewline = true
+ lineLength = i - pos
} else if (c === '\n') {
- lineLength = i - pos;
+ lineLength = i - pos
}
}
if (lineLength < 0) {
- break;
+ break
}
- parseEventStreamLine(buf, pos, fieldLength, lineLength);
+ parseEventStreamLine(buf, pos, fieldLength, lineLength)
- pos += lineLength + 1;
+ pos += lineLength + 1
}
if (pos === length) {
- buf = '';
+ buf = ''
} else if (pos > 0) {
- buf = buf.slice(pos);
+ buf = buf.slice(pos)
}
- });
- });
+ })
+ })
- req.on('error', onConnectionClosed);
- if (req.setNoDelay) req.setNoDelay(true);
- req.end();
+ req.on('error', onConnectionClosed)
+ if (req.setNoDelay) req.setNoDelay(true)
+ req.end()
}
- connect();
+ connect()
- function _emit() {
+ function _emit () {
if (self.listeners(arguments[0]).length > 0) {
- self.emit.apply(self, arguments);
+ self.emit.apply(self, arguments)
}
}
- this.close = function () {
- if (readyState == EventSource.CLOSED) return;
- readyState = EventSource.CLOSED;
- if (req.abort) req.abort();
- if (req.xhr && req.xhr.abort) req.xhr.abort();
- };
+ this._close = function () {
+ if (readyState === EventSource.CLOSED) return
+ readyState = EventSource.CLOSED
+ if (req.abort) req.abort()
+ if (req.xhr && req.xhr.abort) req.xhr.abort()
+ }
- function parseEventStreamLine(buf, pos, fieldLength, lineLength) {
+ function parseEventStreamLine (buf, pos, fieldLength, lineLength) {
if (lineLength === 0) {
if (data.length > 0) {
- var type = eventName || 'message';
+ var type = eventName || 'message'
_emit(type, new MessageEvent(type, {
data: data.slice(0, -1), // remove trailing newline
lastEventId: lastEventId,
origin: original(url)
- }));
- data = '';
+ }))
+ data = ''
}
- eventName = void 0;
+ eventName = void 0
} else if (fieldLength > 0) {
var noValue = fieldLength < 0
- , step = 0
- , field = buf.slice(pos, pos + (noValue ? lineLength : fieldLength));
+ var step = 0
+ var field = buf.slice(pos, pos + (noValue ? lineLength : fieldLength))
if (noValue) {
- step = lineLength;
+ step = lineLength
} else if (buf[pos + fieldLength + 1] !== ' ') {
- step = fieldLength + 1;
+ step = fieldLength + 1
} else {
- step = fieldLength + 2;
+ step = fieldLength + 2
}
- pos += step;
+ pos += step
+
var valueLength = lineLength - step
- , value = buf.slice(pos, pos + valueLength);
+ var value = buf.slice(pos, pos + valueLength)
if (field === 'data') {
- data += value + '\n';
+ data += value + '\n'
} else if (field === 'event') {
- eventName = value;
+ eventName = value
} else if (field === 'id') {
- lastEventId = value;
+ lastEventId = value
} else if (field === 'retry') {
- var retry = parseInt(value, 10);
+ var retry = parseInt(value, 10)
if (!Number.isNaN(retry)) {
- self.reconnectInterval = retry;
+ self.reconnectInterval = retry
}
}
}
}
}
-module.exports = EventSource;
+module.exports = EventSource
-util.inherits(EventSource, events.EventEmitter);
+util.inherits(EventSource, events.EventEmitter)
EventSource.prototype.constructor = EventSource; // make stacktraces readable
['open', 'error', 'message'].forEach(function (method) {
@@ -6106,9 +6429,9 @@ EventSource.prototype.constructor = EventSource; // make stacktraces readable
* @return {Mixed} the set function or undefined
* @api private
*/
- get: function get() {
- var listener = this.listeners(method)[0];
- return listener ? (listener._listener ? listener._listener : listener) : undefined;
+ get: function get () {
+ var listener = this.listeners(method)[0]
+ return listener ? (listener._listener ? listener._listener : listener) : undefined
},
/**
@@ -6118,36 +6441,66 @@ EventSource.prototype.constructor = EventSource; // make stacktraces readable
* @return {Mixed} the set function or undefined
* @api private
*/
- set: function set(listener) {
- this.removeAllListeners(method);
- this.addEventListener(method, listener);
+ set: function set (listener) {
+ this.removeAllListeners(method)
+ this.addEventListener(method, listener)
}
- });
-});
+ })
+})
/**
* Ready states
*/
-Object.defineProperty(EventSource, 'CONNECTING', { enumerable: true, value: 0});
-Object.defineProperty(EventSource, 'OPEN', { enumerable: true, value: 1});
-Object.defineProperty(EventSource, 'CLOSED', { enumerable: true, value: 2});
+Object.defineProperty(EventSource, 'CONNECTING', {enumerable: true, value: 0})
+Object.defineProperty(EventSource, 'OPEN', {enumerable: true, value: 1})
+Object.defineProperty(EventSource, 'CLOSED', {enumerable: true, value: 2})
+
+EventSource.prototype.CONNECTING = 0
+EventSource.prototype.OPEN = 1
+EventSource.prototype.CLOSED = 2
+
+/**
+ * Closes the connection, if one is made, and sets the readyState attribute to 2 (closed)
+ *
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/EventSource/close
+ * @api public
+ */
+EventSource.prototype.close = function () {
+ this._close()
+}
/**
* Emulates the W3C Browser based WebSocket interface using addEventListener.
*
- * @param {String} method Listen for an event
+ * @param {String} type A string representing the event type to listen out for
* @param {Function} listener callback
* @see https://developer.mozilla.org/en/DOM/element.addEventListener
* @see http://dev.w3.org/html5/websockets/#the-websocket-interface
* @api public
*/
-EventSource.prototype.addEventListener = function addEventListener(method, listener) {
+EventSource.prototype.addEventListener = function addEventListener (type, listener) {
if (typeof listener === 'function') {
// store a reference so we can return the original function again
- listener._listener = listener;
- this.on(method, listener);
+ listener._listener = listener
+ this.on(type, listener)
}
-};
+}
+
+/**
+ * Emulates the W3C Browser based WebSocket interface using removeEventListener.
+ *
+ * @param {String} type A string representing the event type to remove
+ * @param {Function} listener callback
+ * @see https://developer.mozilla.org/en/DOM/element.removeEventListener
+ * @see http://dev.w3.org/html5/websockets/#the-websocket-interface
+ * @api public
+ */
+EventSource.prototype.removeEventListener = function removeEventListener (type, listener) {
+ if (typeof listener === 'function') {
+ listener._listener = undefined
+ this.removeListener(type, listener)
+ }
+}
/**
* W3C Event
@@ -6155,12 +6508,12 @@ EventSource.prototype.addEventListener = function addEventListener(method, liste
* @see http://www.w3.org/TR/DOM-Level-3-Events/#interface-Event
* @api private
*/
-function Event(type, optionalProperties) {
- Object.defineProperty(this, 'type', { writable: false, value: type, enumerable: true });
+function Event (type, optionalProperties) {
+ Object.defineProperty(this, 'type', { writable: false, value: type, enumerable: true })
if (optionalProperties) {
for (var f in optionalProperties) {
if (optionalProperties.hasOwnProperty(f)) {
- Object.defineProperty(this, f, { writable: false, value: optionalProperties[f], enumerable: true });
+ Object.defineProperty(this, f, { writable: false, value: optionalProperties[f], enumerable: true })
}
}
}
@@ -6172,27 +6525,27 @@ function Event(type, optionalProperties) {
* @see http://www.w3.org/TR/webmessaging/#event-definitions
* @api private
*/
-function MessageEvent(type, eventInitDict) {
- Object.defineProperty(this, 'type', { writable: false, value: type, enumerable: true });
+function MessageEvent (type, eventInitDict) {
+ Object.defineProperty(this, 'type', { writable: false, value: type, enumerable: true })
for (var f in eventInitDict) {
if (eventInitDict.hasOwnProperty(f)) {
- Object.defineProperty(this, f, { writable: false, value: eventInitDict[f], enumerable: true });
+ Object.defineProperty(this, f, { writable: false, value: eventInitDict[f], enumerable: true })
}
}
}
-/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(2)))
+/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(1)))
/***/ }),
-/* 21 */
+/* 22 */
/***/ (function(module, exports, __webpack_require__) {
-window.EventSourcePolyfill = __webpack_require__(20);
+window.EventSourcePolyfill = __webpack_require__(21)
window.EventSource = window.EventSource || window.EventSourcePolyfill
/***/ }),
-/* 22 */
+/* 23 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
@@ -6313,7 +6666,7 @@ function fromByteArray (uint8) {
/***/ }),
-/* 23 */
+/* 24 */
/***/ (function(module, exports) {
module.exports = {
@@ -6383,10 +6736,10 @@ module.exports = {
/***/ }),
-/* 24 */
+/* 25 */
/***/ (function(module, exports, __webpack_require__) {
-var http = __webpack_require__(15);
+var http = __webpack_require__(17);
var https = module.exports;
@@ -6403,7 +6756,7 @@ https.request = function (params, cb) {
/***/ }),
-/* 25 */
+/* 26 */
/***/ (function(module, exports) {
exports.read = function (buffer, offset, isLE, mLen, nBytes) {
@@ -6493,13 +6846,13 @@ exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
/***/ }),
-/* 26 */
+/* 27 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
-var parse = __webpack_require__(18);
+var parse = __webpack_require__(19);
/**
* Transform an URL to a valid origin value.
@@ -6546,7 +6899,7 @@ module.exports = origin;
/***/ }),
-/* 27 */
+/* 28 */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(module, global) {var __WEBPACK_AMD_DEFINE_RESULT__;/*! https://mths.be/punycode v1.4.1 by @mathias */
@@ -7082,10 +7435,10 @@ module.exports = origin;
}(this));
-/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(46)(module), __webpack_require__(0)))
+/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(47)(module), __webpack_require__(0)))
/***/ }),
-/* 28 */
+/* 29 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
@@ -7176,7 +7529,7 @@ var isArray = Array.isArray || function (xs) {
/***/ }),
-/* 29 */
+/* 30 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
@@ -7268,18 +7621,18 @@ var objectKeys = Object.keys || function (obj) {
/***/ }),
-/* 30 */
+/* 31 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
-exports.decode = exports.parse = __webpack_require__(28);
-exports.encode = exports.stringify = __webpack_require__(29);
+exports.decode = exports.parse = __webpack_require__(29);
+exports.encode = exports.stringify = __webpack_require__(30);
/***/ }),
-/* 31 */
+/* 32 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
@@ -7347,10 +7700,31 @@ exports.parse = querystring;
/***/ }),
-/* 32 */
+/* 33 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
// a passthrough stream.
// basically just the most minimal sort of Transform stream.
// Every written chunk gets output as-is.
@@ -7359,11 +7733,11 @@ exports.parse = querystring;
module.exports = PassThrough;
-var Transform = __webpack_require__(11);
+var Transform = __webpack_require__(12);
/**/
var util = __webpack_require__(5);
-util.inherits = __webpack_require__(3);
+util.inherits = __webpack_require__(2);
/**/
util.inherits(PassThrough, Transform);
@@ -7379,77 +7753,97 @@ PassThrough.prototype._transform = function (chunk, encoding, cb) {
};
/***/ }),
-/* 33 */
+/* 34 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
-var Buffer = __webpack_require__(1).Buffer;
/**/
-var bufferShim = __webpack_require__(6);
-/**/
-
-module.exports = BufferList;
-function BufferList() {
- this.head = null;
- this.tail = null;
- this.length = 0;
-}
-
-BufferList.prototype.push = function (v) {
- var entry = { data: v, next: null };
- if (this.length > 0) this.tail.next = entry;else this.head = entry;
- this.tail = entry;
- ++this.length;
-};
+var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
-BufferList.prototype.unshift = function (v) {
- var entry = { data: v, next: this.head };
- if (this.length === 0) this.tail = entry;
- this.head = entry;
- ++this.length;
-};
-
-BufferList.prototype.shift = function () {
- if (this.length === 0) return;
- var ret = this.head.data;
- if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next;
- --this.length;
- return ret;
-};
+function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
-BufferList.prototype.clear = function () {
- this.head = this.tail = null;
- this.length = 0;
-};
+var Buffer = __webpack_require__(8).Buffer;
+/**/
-BufferList.prototype.join = function (s) {
- if (this.length === 0) return '';
- var p = this.head;
- var ret = '' + p.data;
- while (p = p.next) {
- ret += s + p.data;
- }return ret;
-};
+function copyBuffer(src, target, offset) {
+ src.copy(target, offset);
+}
+
+module.exports = function () {
+ function BufferList() {
+ _classCallCheck(this, BufferList);
+
+ this.head = null;
+ this.tail = null;
+ this.length = 0;
+ }
+
+ _createClass(BufferList, [{
+ key: 'push',
+ value: function push(v) {
+ var entry = { data: v, next: null };
+ if (this.length > 0) this.tail.next = entry;else this.head = entry;
+ this.tail = entry;
+ ++this.length;
+ }
+ }, {
+ key: 'unshift',
+ value: function unshift(v) {
+ var entry = { data: v, next: this.head };
+ if (this.length === 0) this.tail = entry;
+ this.head = entry;
+ ++this.length;
+ }
+ }, {
+ key: 'shift',
+ value: function shift() {
+ if (this.length === 0) return;
+ var ret = this.head.data;
+ if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next;
+ --this.length;
+ return ret;
+ }
+ }, {
+ key: 'clear',
+ value: function clear() {
+ this.head = this.tail = null;
+ this.length = 0;
+ }
+ }, {
+ key: 'join',
+ value: function join(s) {
+ if (this.length === 0) return '';
+ var p = this.head;
+ var ret = '' + p.data;
+ while (p = p.next) {
+ ret += s + p.data;
+ }return ret;
+ }
+ }, {
+ key: 'concat',
+ value: function concat(n) {
+ if (this.length === 0) return Buffer.alloc(0);
+ if (this.length === 1) return this.head.data;
+ var ret = Buffer.allocUnsafe(n >>> 0);
+ var p = this.head;
+ var i = 0;
+ while (p) {
+ copyBuffer(p.data, ret, i);
+ i += p.data.length;
+ p = p.next;
+ }
+ return ret;
+ }
+ }]);
-BufferList.prototype.concat = function (n) {
- if (this.length === 0) return bufferShim.alloc(0);
- if (this.length === 1) return this.head.data;
- var ret = bufferShim.allocUnsafe(n >>> 0);
- var p = this.head;
- var i = 0;
- while (p) {
- p.data.copy(ret, i);
- i += p.data.length;
- p = p.next;
- }
- return ret;
-};
+ return BufferList;
+}();
/***/ }),
-/* 34 */
+/* 35 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
@@ -7494,7 +7888,7 @@ module.exports = function required(port, protocol) {
/***/ }),
-/* 35 */
+/* 36 */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(global, process) {(function (global, undefined) {
@@ -7684,17 +8078,17 @@ module.exports = function required(port, protocol) {
attachTo.clearImmediate = clearImmediate;
}(typeof self === "undefined" ? typeof global === "undefined" ? this : global : self));
-/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(0), __webpack_require__(2)))
+/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(0), __webpack_require__(1)))
/***/ }),
-/* 36 */
+/* 37 */
/***/ (function(module, exports, __webpack_require__) {
-/* WEBPACK VAR INJECTION */(function(Buffer, global, process) {var capability = __webpack_require__(16)
-var inherits = __webpack_require__(3)
-var response = __webpack_require__(37)
-var stream = __webpack_require__(14)
-var toArrayBuffer = __webpack_require__(39)
+/* WEBPACK VAR INJECTION */(function(Buffer, global, process) {var capability = __webpack_require__(18)
+var inherits = __webpack_require__(2)
+var response = __webpack_require__(38)
+var stream = __webpack_require__(16)
+var toArrayBuffer = __webpack_require__(40)
var IncomingMessage = response.IncomingMessage
var rStates = response.readyStates
@@ -7773,8 +8167,10 @@ ClientRequest.prototype.setHeader = function (name, value) {
}
ClientRequest.prototype.getHeader = function (name) {
- var self = this
- return self._headers[name.toLowerCase()].value
+ var header = this._headers[name.toLowerCase()]
+ if (header)
+ return header.value
+ return null
}
ClientRequest.prototype.removeHeader = function (name) {
@@ -7995,15 +8391,15 @@ var unsafeHeaders = [
'via'
]
-/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(1).Buffer, __webpack_require__(0), __webpack_require__(2)))
+/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(3).Buffer, __webpack_require__(0), __webpack_require__(1)))
/***/ }),
-/* 37 */
+/* 38 */
/***/ (function(module, exports, __webpack_require__) {
-/* WEBPACK VAR INJECTION */(function(process, Buffer, global) {var capability = __webpack_require__(16)
-var inherits = __webpack_require__(3)
-var stream = __webpack_require__(14)
+/* WEBPACK VAR INJECTION */(function(process, Buffer, global) {var capability = __webpack_require__(18)
+var inherits = __webpack_require__(2)
+var stream = __webpack_require__(16)
var rStates = exports.readyStates = {
UNSENT: 0,
@@ -8184,10 +8580,10 @@ IncomingMessage.prototype._onXHRProgress = function () {
}
}
-/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(2), __webpack_require__(1).Buffer, __webpack_require__(0)))
+/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(1), __webpack_require__(3).Buffer, __webpack_require__(0)))
/***/ }),
-/* 38 */
+/* 39 */
/***/ (function(module, exports, __webpack_require__) {
var apply = Function.prototype.apply;
@@ -8240,16 +8636,16 @@ exports._unrefActive = exports.active = function(item) {
};
// setimmediate attaches itself to the global object
-__webpack_require__(35);
+__webpack_require__(36);
exports.setImmediate = setImmediate;
exports.clearImmediate = clearImmediate;
/***/ }),
-/* 39 */
+/* 40 */
/***/ (function(module, exports, __webpack_require__) {
-var Buffer = __webpack_require__(1).Buffer
+var Buffer = __webpack_require__(3).Buffer
module.exports = function (buf) {
// If the buffer is backed by a Uint8Array, a faster version will work
@@ -8279,7 +8675,7 @@ module.exports = function (buf) {
/***/ }),
-/* 40 */
+/* 41 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
@@ -8310,7 +8706,7 @@ var ignore = { hash: 1, query: 1 }
*/
module.exports = function lolcation(loc) {
loc = loc || global.location || {};
- URL = URL || __webpack_require__(18);
+ URL = URL || __webpack_require__(19);
var finaldestination = {}
, type = typeof loc
@@ -8332,7 +8728,7 @@ module.exports = function lolcation(loc) {
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(0)))
/***/ }),
-/* 41 */
+/* 42 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
@@ -8355,7 +8751,7 @@ module.exports = {
/***/ }),
-/* 42 */
+/* 43 */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(global) {
@@ -8429,7 +8825,7 @@ function config (name) {
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(0)))
/***/ }),
-/* 43 */
+/* 44 */
/***/ (function(module, exports) {
if (typeof Object.create === 'function') {
@@ -8458,7 +8854,7 @@ if (typeof Object.create === 'function') {
/***/ }),
-/* 44 */
+/* 45 */
/***/ (function(module, exports) {
module.exports = function isBuffer(arg) {
@@ -8469,7 +8865,7 @@ module.exports = function isBuffer(arg) {
}
/***/ }),
-/* 45 */
+/* 46 */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(global, process) {// Copyright Joyent, Inc. and other Node contributors.
@@ -8997,7 +9393,7 @@ function isPrimitive(arg) {
}
exports.isPrimitive = isPrimitive;
-exports.isBuffer = __webpack_require__(44);
+exports.isBuffer = __webpack_require__(45);
function objectToString(o) {
return Object.prototype.toString.call(o);
@@ -9041,7 +9437,7 @@ exports.log = function() {
* prototype.
* @param {function} superCtor Constructor function to inherit prototype from.
*/
-exports.inherits = __webpack_require__(43);
+exports.inherits = __webpack_require__(44);
exports._extend = function(origin, add) {
// Don't do anything if add isn't an object
@@ -9059,10 +9455,10 @@ function hasOwnProperty(obj, prop) {
return Object.prototype.hasOwnProperty.call(obj, prop);
}
-/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(0), __webpack_require__(2)))
+/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(0), __webpack_require__(1)))
/***/ }),
-/* 46 */
+/* 47 */
/***/ (function(module, exports) {
module.exports = function(module) {
@@ -9090,7 +9486,7 @@ module.exports = function(module) {
/***/ }),
-/* 47 */
+/* 48 */
/***/ (function(module, exports) {
module.exports = extend
@@ -9115,7 +9511,7 @@ function extend() {
/***/ }),
-/* 48 */
+/* 49 */
/***/ (function(module, exports) {
/* (ignored) */
diff --git a/lib/eventsource.js b/lib/eventsource.js
index de12cb6..68d3584 100644
--- a/lib/eventsource.js
+++ b/lib/eventsource.js
@@ -113,6 +113,11 @@ function EventSource (url, eventSourceInitDict) {
}
}
+ // Pass this on to the XHR
+ if (eventSourceInitDict && eventSourceInitDict.withCredentials !== undefined) {
+ options.withCredentials = eventSourceInitDict.withCredentials
+ }
+
req = (isSecure ? https : http).request(options, function (res) {
// Handle HTTP errors
if (res.statusCode === 500 || res.statusCode === 502 || res.statusCode === 503 || res.statusCode === 504) {