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>
This commit is contained in:
Anna Henningsen
2020-05-16 01:38:24 +02:00
parent 21b5c5f9e0
commit 0f232ed692

View File

@@ -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')