diff options
Diffstat (limited to 'lib/_stream_readable.js')
-rw-r--r-- | lib/_stream_readable.js | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js index c6f31bc1f9..0b5af41f1c 100644 --- a/lib/_stream_readable.js +++ b/lib/_stream_readable.js @@ -117,7 +117,7 @@ function Readable(options) { Readable.prototype.push = function(chunk, encoding) { var state = this._readableState; - if (typeof chunk === 'string' && !state.objectMode) { + if (IS_STRING(chunk) && !state.objectMode) { encoding = encoding || state.defaultEncoding; if (encoding !== state.encoding) { chunk = new Buffer(chunk, encoding); @@ -138,7 +138,7 @@ function readableAddChunk(stream, state, chunk, encoding, addToFront) { var er = chunkInvalid(state, chunk); if (er) { stream.emit('error', er); - } else if (chunk === null || chunk === undefined) { + } else if (IS_NULL_OR_UNDEFINED(chunk)) { state.reading = false; if (!state.ended) onEofChunk(stream, state); @@ -219,7 +219,7 @@ function howMuchToRead(n, state) { if (state.objectMode) return n === 0 ? 0 : 1; - if (isNaN(n) || n === null) { + if (isNaN(n) || IS_NULL(n)) { // only flow one buffer at a time if (state.flowing && state.buffer.length) return state.buffer[0].length; @@ -256,7 +256,7 @@ Readable.prototype.read = function(n) { state.calledRead = true; var nOrig = n; - if (typeof n !== 'number' || n > 0) + if (!IS_NUMBER(n) || n > 0) state.emittedReadable = false; // if we're doing read(0) to trigger a readable event, but we @@ -345,7 +345,7 @@ Readable.prototype.read = function(n) { else ret = null; - if (ret === null) { + if (IS_NULL(ret)) { state.needReadable = true; n = 0; } @@ -363,17 +363,16 @@ Readable.prototype.read = function(n) { if (state.ended && !state.endEmitted && state.length === 0) endReadable(this); - if (ret !== null) + if (!IS_NULL(ret)) this.emit('data', ret); return ret; }; function chunkInvalid(state, chunk) { var er = null; - if (!Buffer.isBuffer(chunk) && - 'string' !== typeof chunk && - chunk !== null && - chunk !== undefined && + if (!IS_BUFFER(chunk) && + !IS_STRING(chunk) && + !IS_NULL_OR_UNDEFINED(chunk) && !state.objectMode && !er) { er = new TypeError('Invalid non-string/buffer chunk'); @@ -775,8 +774,7 @@ Readable.prototype.wrap = function(stream) { // proxy all the other methods. // important when wrapping filters and duplexes. for (var i in stream) { - if (typeof stream[i] === 'function' && - typeof this[i] === 'undefined') { + if (IS_FUNCTION(stream[i]) && IS_UNDEFINED(this[i])) { this[i] = function(method) { return function() { return stream[method].apply(stream, arguments); }}(i); |