Skip to content

Commit 8f91338

Browse files
addaleaxcodebytere
authored andcommitted
doc: fix stream example
- Un-break the code for multibyte characters - Get `fs.createReadStream` from the right module PR-URL: #33426 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 8ada953 commit 8f91338

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

doc/api/stream.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -1666,14 +1666,15 @@ The `pipeline` API also supports async generators:
16661666

16671667
```js
16681668
const pipeline = util.promisify(stream.pipeline);
1669-
const fs = require('fs').promises;
1669+
const fs = require('fs');
16701670

16711671
async function run() {
16721672
await pipeline(
16731673
fs.createReadStream('lowercase.txt'),
16741674
async function* (source) {
1675+
source.setEncoding('utf8'); // Work with strings rather than `Buffer`s.
16751676
for await (const chunk of source) {
1676-
yield String(chunk).toUpperCase();
1677+
yield chunk.toUpperCase();
16771678
}
16781679
},
16791680
fs.createWriteStream('uppercase.txt')

0 commit comments

Comments
 (0)