From ba508f5ad2596d676fc2a12a70a7d084c76b01b7 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sat, 16 May 2020 01:38:24 +0200 Subject: [PATCH] doc: fix stream example - Un-break the code for multibyte characters - Get `fs.createReadStream` from the right module --- doc/api/stream.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/api/stream.md b/doc/api/stream.md index 6229704eb91bc4..2801d2e7e8d4dd 100644 --- a/doc/api/stream.md +++ b/doc/api/stream.md @@ -1666,14 +1666,15 @@ The `pipeline` API also supports async generators: ```js const pipeline = util.promisify(stream.pipeline); -const fs = require('fs').promises; +const fs = require('fs'); async function run() { await pipeline( fs.createReadStream('lowercase.txt'), async function* (source) { + source.setEncoding('utf8'); // Work with strings rather than `Buffer`s. for await (const chunk of source) { - yield String(chunk).toUpperCase(); + yield chunk.toUpperCase(); } }, fs.createWriteStream('uppercase.txt')