Skip to content

Commit

Permalink
doc: fix stream example
Browse files Browse the repository at this point in the history
- Un-break the code for multibyte characters
- Get `fs.createReadStream` from the right module

PR-URL: #33426
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
addaleax authored and codebytere committed May 16, 2020
1 parent 8ada953 commit 8f91338
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions doc/api/stream.md
Expand Up @@ -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')
Expand Down

0 comments on commit 8f91338

Please sign in to comment.