mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
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:
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user