From 4e7d34571dddc4549c73fa668f55c1b38034514b Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Fri, 4 Jan 2019 19:21:27 +0100 Subject: [PATCH] doc: fix process.stdin example Fixes: https://github.com/nodejs/node/issues/20503 PR-URL: https://github.com/nodejs/node/pull/25344 Reviewed-By: Colin Ihrig Reviewed-By: Matteo Collina Reviewed-By: Rich Trott Reviewed-By: Luigi Pinca Reviewed-By: Anto Aravinth Reviewed-By: Franziska Hinkelmann Reviewed-By: James M Snell --- doc/api/process.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/api/process.md b/doc/api/process.md index 818bb6ed4ab73c..28ed9734f55144 100644 --- a/doc/api/process.md +++ b/doc/api/process.md @@ -1856,8 +1856,9 @@ a [Readable][] stream. process.stdin.setEncoding('utf8'); process.stdin.on('readable', () => { - const chunk = process.stdin.read(); - if (chunk !== null) { + let chunk; + // Use a loop to make sure we read all available data. + while ((chunk = process.stdin.read()) !== null) { process.stdout.write(`data: ${chunk}`); } });