Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
stream: Emit readable on ended streams via read(0)
Browse files Browse the repository at this point in the history
cc: @mjijackson
  • Loading branch information
isaacs committed Mar 27, 2013
1 parent e8d179e commit 582c5b1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/_stream_readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ Readable.prototype.read = function(n) {
// the 'readable' event and move on.
if (n === 0 &&
state.needReadable &&
state.length >= state.highWaterMark) {
(state.length >= state.highWaterMark || state.ended)) {
emitReadable(this);
return null;
}
Expand Down
24 changes: 24 additions & 0 deletions test/simple/test-stream-readable-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,27 @@ var Readable = require('stream').Readable;
console.log('ok 2');
});
})();

(function third() {
// Third test, not reading when the stream has not passed
// the highWaterMark but *has* reached EOF.
var r = new Readable({
highWaterMark: 30
});

// This triggers a 'readable' event, which is lost.
r.push(new Buffer('blerg'));
r.push(null);

var caughtReadable = false;
setTimeout(function() {
r.on('readable', function() {
caughtReadable = true;
});
});

process.on('exit', function() {
assert(caughtReadable);
console.log('ok 3');
});
})();

0 comments on commit 582c5b1

Please sign in to comment.