diff options
author | Brian White <mscdex@mscdex.net> | 2015-03-19 22:04:07 -0400 |
---|---|---|
committer | Brian White <mscdex@mscdex.net> | 2015-12-02 12:56:48 -0500 |
commit | cc0342a517279c9c52543e3a37e11da3fc6cdb36 (patch) | |
tree | 7edd8bf0e5b0e37dad3c910091433cdf0a7a84b7 /lib | |
parent | 49b5445cbc7450ec1cb4e605aa34fef8df502919 (diff) | |
download | node-new-cc0342a517279c9c52543e3a37e11da3fc6cdb36.tar.gz |
streams: update .readable/.writable to false
These properties were initially used to determine stream status
back in node v0.8 and earlier. Since streams2 however, these
properties were *always* true, which can be misleading for
example if you are trying to immediately determine whether
a Writable stream is still writable or not (to avoid a "write after
end" exception).
PR-URL: https://github.com/nodejs/node/pull/4083
Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/_stream_readable.js | 3 | ||||
-rw-r--r-- | lib/_stream_writable.js | 1 |
2 files changed, 3 insertions, 1 deletions
diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js index 0316a05571..ea36e6ed62 100644 --- a/lib/_stream_readable.js +++ b/lib/_stream_readable.js @@ -385,6 +385,7 @@ function onEofChunk(stream, state) { } } state.ended = true; + stream.readable = false; // emit 'readable' now to make sure it gets picked up. emitReadable(stream); @@ -670,7 +671,7 @@ Readable.prototype.on = function(ev, fn) { this.resume(); } - if (ev === 'readable' && this.readable) { + if (ev === 'readable' && !this._readableState.endEmitted) { var state = this._readableState; if (!state.readableListening) { state.readableListening = true; diff --git a/lib/_stream_writable.js b/lib/_stream_writable.js index 73f4d9fb3e..10fcae04f5 100644 --- a/lib/_stream_writable.js +++ b/lib/_stream_writable.js @@ -483,4 +483,5 @@ function endWritable(stream, state, cb) { stream.once('finish', cb); } state.ended = true; + stream.writable = false; } |