From a685b1cf29446af5d73be37cb1a2263d8caca9d0 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Tue, 6 Sep 2016 11:32:37 -0400 Subject: [PATCH] first stab at 6.5.0 --- README.md | 2 +- doc/stream.md | 39 ++++++++++----------- lib/_stream_readable.js | 2 ++ test/parallel/test-stream-events-prepend.js | 31 ++++++++++++++++ 4 files changed, 53 insertions(+), 21 deletions(-) create mode 100644 test/parallel/test-stream-events-prepend.js diff --git a/README.md b/README.md index 4ca9861c6b..a7bf9472b5 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # readable-stream -***Node-core v6.4.0 streams for userland*** [![Build Status](https://travis-ci.org/nodejs/readable-stream.svg?branch=master)](https://travis-ci.org/nodejs/readable-stream) +***Node-core v6.5.0 streams for userland*** [![Build Status](https://travis-ci.org/nodejs/readable-stream.svg?branch=master)](https://travis-ci.org/nodejs/readable-stream) [![NPM](https://nodei.co/npm/readable-stream.png?downloads=true&downloadRank=true)](https://nodei.co/npm/readable-stream/) diff --git a/doc/stream.md b/doc/stream.md index 4a88ac8fe4..4607d2578d 100644 --- a/doc/stream.md +++ b/doc/stream.md @@ -130,15 +130,14 @@ const server = http.createServer( (req, res) => { req.on('end', () => { try { const data = JSON.parse(body); + // write back something interesting to the user: + res.write(typeof data); + res.end(); } catch (er) { // uh oh! bad json! res.statusCode = 400; return res.end(`error: ${er.message}`); } - - // write back something interesting to the user: - res.write(typeof data); - res.end(); }); }); @@ -1968,10 +1967,10 @@ readable buffer so there is nothing for a user to consume. [`'end'`]: #stream_event_end [`'finish'`]: #stream_event_finish [`'readable'`]: #stream_event_readable -[`EventEmitter`]: https://nodejs.org/docs/v6.4.0/api/events.html#events_class_eventemitter -[`process.stderr`]: https://nodejs.org/docs/v6.4.0/api/process.html#process_process_stderr -[`process.stdin`]: https://nodejs.org/docs/v6.4.0/api/process.html#process_process_stdin -[`process.stdout`]: https://nodejs.org/docs/v6.4.0/api/process.html#process_process_stdout +[`EventEmitter`]: https://nodejs.org/docs/v6.5.0/api/events.html#events_class_eventemitter +[`process.stderr`]: https://nodejs.org/docs/v6.5.0/api/process.html#process_process_stderr +[`process.stdin`]: https://nodejs.org/docs/v6.5.0/api/process.html#process_process_stdin +[`process.stdout`]: https://nodejs.org/docs/v6.5.0/api/process.html#process_process_stdout [`stream.cork()`]: #stream_writable_cork [`stream.pipe()`]: #stream_readable_pipe_destination_options [`stream.uncork()`]: #stream_writable_uncork @@ -1979,20 +1978,20 @@ readable buffer so there is nothing for a user to consume. [`stream.wrap()`]: #stream_readable_wrap_stream [API for Stream Consumers]: #stream_api_for_stream_consumers [API for Stream Implementers]: #stream_api_for_stream_implementers -[child process stdin]: https://nodejs.org/docs/v6.4.0/api/child_process.html#child_process_child_stdin -[child process stdout and stderr]: https://nodejs.org/docs/v6.4.0/api/child_process.html#child_process_child_stdout +[child process stdin]: https://nodejs.org/docs/v6.5.0/api/child_process.html#child_process_child_stdin +[child process stdout and stderr]: https://nodejs.org/docs/v6.5.0/api/child_process.html#child_process_child_stdout [Compatibility]: #stream_compatibility_with_older_node_js_versions [crypto]: crypto.html [Duplex]: #stream_class_stream_duplex -[fs read streams]: https://nodejs.org/docs/v6.4.0/api/fs.html#fs_class_fs_readstream -[fs write streams]: https://nodejs.org/docs/v6.4.0/api/fs.html#fs_class_fs_writestream -[`fs.createReadStream()`]: https://nodejs.org/docs/v6.4.0/api/fs.html#fs_fs_createreadstream_path_options -[`fs.createWriteStream()`]: https://nodejs.org/docs/v6.4.0/api/fs.html#fs_fs_createwritestream_path_options -[`net.Socket`]: https://nodejs.org/docs/v6.4.0/api/net.html#net_class_net_socket -[`zlib.createDeflate()`]: https://nodejs.org/docs/v6.4.0/api/zlib.html#zlib_zlib_createdeflate_options -[HTTP requests, on the client]: https://nodejs.org/docs/v6.4.0/api/http.html#http_class_http_clientrequest -[HTTP responses, on the server]: https://nodejs.org/docs/v6.4.0/api/http.html#http_class_http_serverresponse -[http-incoming-message]: https://nodejs.org/docs/v6.4.0/api/http.html#http_class_http_incomingmessage +[fs read streams]: https://nodejs.org/docs/v6.5.0/api/fs.html#fs_class_fs_readstream +[fs write streams]: https://nodejs.org/docs/v6.5.0/api/fs.html#fs_class_fs_writestream +[`fs.createReadStream()`]: https://nodejs.org/docs/v6.5.0/api/fs.html#fs_fs_createreadstream_path_options +[`fs.createWriteStream()`]: https://nodejs.org/docs/v6.5.0/api/fs.html#fs_fs_createwritestream_path_options +[`net.Socket`]: https://nodejs.org/docs/v6.5.0/api/net.html#net_class_net_socket +[`zlib.createDeflate()`]: https://nodejs.org/docs/v6.5.0/api/zlib.html#zlib_zlib_createdeflate_options +[HTTP requests, on the client]: https://nodejs.org/docs/v6.5.0/api/http.html#http_class_http_clientrequest +[HTTP responses, on the server]: https://nodejs.org/docs/v6.5.0/api/http.html#http_class_http_serverresponse +[http-incoming-message]: https://nodejs.org/docs/v6.5.0/api/http.html#http_class_http_incomingmessage [Readable]: #stream_class_stream_readable [stream-_flush]: #stream_transform_flush_callback [stream-_read]: #stream_readable_read_size_1 @@ -2005,7 +2004,7 @@ readable buffer so there is nothing for a user to consume. [stream-read]: #stream_readable_read_size [stream-resume]: #stream_readable_resume [stream-write]: #stream_writable_write_chunk_encoding_callback -[TCP sockets]: https://nodejs.org/docs/v6.4.0/api/net.html#net_class_net_socket +[TCP sockets]: https://nodejs.org/docs/v6.5.0/api/net.html#net_class_net_socket [Transform]: #stream_class_stream_transform [Writable]: #stream_class_stream_writable [zlib]: zlib.html diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js index 208cc65f1c..eed7827e37 100644 --- a/lib/_stream_readable.js +++ b/lib/_stream_readable.js @@ -57,6 +57,8 @@ var StringDecoder; util.inherits(Readable, Stream); 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 { diff --git a/test/parallel/test-stream-events-prepend.js b/test/parallel/test-stream-events-prepend.js new file mode 100644 index 0000000000..d808a7cdc9 --- /dev/null +++ b/test/parallel/test-stream-events-prepend.js @@ -0,0 +1,31 @@ +/**/ +var bufferShim = require('buffer-shims'); +/**/ +var common = require('../common'); +var stream = require('../../'); +var util = require('util'); + +function Writable() { + this.writable = true; + stream.Writable.call(this); + this.prependListener = undefined; +} +util.inherits(Writable, stream.Writable); +Writable.prototype._write = function (chunk, end, cb) { + cb(); +}; + +function Readable() { + this.readable = true; + stream.Readable.call(this); +} +util.inherits(Readable, stream.Readable); +Readable.prototype._read = function () { + this.push(null); +}; + +var w = new Writable(); +w.on('pipe', common.mustCall(function () {})); + +var r = new Readable(); +r.pipe(w); \ No newline at end of file