diff options
author | Anna Henningsen <anna@addaleax.net> | 2020-05-16 02:38:24 +0300 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2020-05-16 03:28:38 +0300 |
commit | 0f232ed69263874bae517b65fd79cb91ef1ed85e (patch) | |
tree | 4e20248fc1a5625cd1bac76384bd5daf965bd210 /doc/api/stream.md | |
parent | 21b5c5f9e0e8d80f23fa258031e9da68e2c25d34 (diff) |
doc: fix stream example
- Un-break the code for multibyte characters
- Get `fs.createReadStream` from the right module
PR-URL: https://github.com/nodejs/node/pull/33426
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'doc/api/stream.md')
-rw-r--r-- | doc/api/stream.md | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/doc/api/stream.md b/doc/api/stream.md index 6229704eb91..2801d2e7e8d 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') |