From 871a60cd12f6d032ae36fdbd75dbc96be7e1b7bc Mon Sep 17 00:00:00 2001 From: Vse Mozhet Byt Date: Sun, 7 Jul 2019 20:56:12 +0300 Subject: [PATCH] doc: fix nits in stream.md * Unify periods and upper case in comments. * Add missing parentheses for methods. * Add missing backticks. * Fix sorting position of `writable.writableFinished` section. * Replace a one-letter variable with a more readable one. * `catch(console.log)` -> `catch(console.error)`. * Document missing `emitClose` option in `new stream.Readable()` section mentioned in https://nodejs.org/api/stream.html#stream_event_close_1 and https://nodejs.org/api/stream.html#stream_readable_destroy_error copying from the `new stream.Writable()` section. Refs: https://github.com/nodejs/node/blob/36fdf1aa6c87ccfaebabb8f9c8004baab0549b0b/lib/_stream_readable.js#L121 PR-URL: https://github.com/nodejs/node/pull/28591 Reviewed-By: Luigi Pinca Reviewed-By: Ruben Bridgewater Reviewed-By: Rich Trott Reviewed-By: Matteo Collina Reviewed-By: Trivikram Kamat --- doc/api/stream.md | 112 +++++++++++++++++++++++----------------------- 1 file changed, 57 insertions(+), 55 deletions(-) diff --git a/doc/api/stream.md b/doc/api/stream.md index 6f43d83fc31..4a041e63ecc 100644 --- a/doc/api/stream.md +++ b/doc/api/stream.md @@ -115,20 +115,20 @@ that implements an HTTP server: const http = require('http'); const server = http.createServer((req, res) => { - // `req` is an http.IncomingMessage, which is a Readable Stream - // `res` is an http.ServerResponse, which is a Writable Stream + // `req` is an http.IncomingMessage, which is a Readable Stream. + // `res` is an http.ServerResponse, which is a Writable Stream. let body = ''; // Get the data as utf8 strings. // If an encoding is not set, Buffer objects will be received. req.setEncoding('utf8'); - // Readable streams emit 'data' events once a listener is added + // Readable streams emit 'data' events once a listener is added. req.on('data', (chunk) => { body += chunk; }); - // The 'end' event indicates that the entire body has been received + // The 'end' event indicates that the entire body has been received. req.on('end', () => { try { const data = JSON.parse(body); @@ -250,7 +250,7 @@ function writeOneMillionTimes(writer, data, encoding, callback) { do { i--; if (i === 0) { - // last time! + // Last time! writer.write(data, encoding, callback); } else { // See if we should continue, or wait. @@ -259,8 +259,8 @@ function writeOneMillionTimes(writer, data, encoding, callback) { } } while (i > 0 && ok); if (i > 0) { - // had to stop early! - // write some more once it drains + // Had to stop early! + // Write some more once it drains. writer.once('drain', write); } } @@ -410,7 +410,7 @@ Calling the [`stream.write()`][stream-write] method after calling [`stream.end()`][stream-end] will raise an error. ```js -// Write 'hello, ' and then end with 'world!' +// Write 'hello, ' and then end with 'world!'. const fs = require('fs'); const file = fs.createWriteStream('example.txt'); file.write('hello, '); @@ -480,6 +480,15 @@ added: v11.4.0 Is `true` if it is safe to call [`writable.write()`][stream-write]. +##### writable.writableFinished + + +* {boolean} + +Is `true` if after the [`'finish'`][] event has been emitted. + ##### writable.writableHighWaterMark - -* {boolean} - -Is `true` if all data has been flushed to the underlying system. After -the [`'finish'`][] event has been emitted. - ##### writable.writableObjectMode