From 7fa4a9697d82fe811b73aea92492b66798420609 Mon Sep 17 00:00:00 2001 From: Jonathan Reem Date: Sat, 28 Jun 2014 11:46:42 -0700 Subject: [PATCH] stream: only end reading on null, not undefined The [Stream documentation for .push](http://nodejs.org/api/stream.html#stream_readable_push_chunk_encoding) explicitly states multiple times that null is a special cased value that indicates the end of a stream. It is confusing and undocumented that undefined *also* ends the stream, even though in object mode there is a distinct and important difference. The docs for Object-Mode also explicitly mention null as the *only* special cased value, making no mention of undefined. Signed-off-by: Fedor Indutny --- lib/_stream_readable.js | 2 +- test/simple/test-stream2-readable-non-empty-end.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js index 317b40bcda..56361e6dd2 100644 --- a/lib/_stream_readable.js +++ b/lib/_stream_readable.js @@ -139,7 +139,7 @@ function readableAddChunk(stream, state, chunk, encoding, addToFront) { var er = chunkInvalid(state, chunk); if (er) { stream.emit('error', er); - } else if (util.isNullOrUndefined(chunk)) { + } else if (chunk === null) { state.reading = false; if (!state.ended) onEofChunk(stream, state); diff --git a/test/simple/test-stream2-readable-non-empty-end.js b/test/simple/test-stream2-readable-non-empty-end.js index 7314ae77b1..65b7afda57 100644 --- a/test/simple/test-stream2-readable-non-empty-end.js +++ b/test/simple/test-stream2-readable-non-empty-end.js @@ -35,7 +35,7 @@ var n = 0; test._read = function(size) { var chunk = chunks[n++]; setTimeout(function() { - test.push(chunk); + test.push(chunk === undefined ? null : chunk); }); };