| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 8ada953 commit 8f91338
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1666,14 +1666,15 @@ The `pipeline` API also supports async generators: | |||
| 1666 | 1666 | ||
| 1667 | 1667 | ```js | |
| 1668 | 1668 | const pipeline = util.promisify(stream.pipeline); | |
| 1669 | - const fs = require('fs').promises; | ||
| 1669 | + const fs = require('fs'); | ||
| 1670 | 1670 | ||
| 1671 | 1671 | async function run() { | |
| 1672 | 1672 | await pipeline( | |
| 1673 | 1673 | fs.createReadStream('lowercase.txt'), | |
| 1674 | 1674 | async function* (source) { | |
| 1675 | + source.setEncoding('utf8'); // Work with strings rather than `Buffer`s. | ||
| 1675 | 1676 | for await (const chunk of source) { | |
| 1676 | - yield String(chunk).toUpperCase(); | ||
| 1677 | + yield chunk.toUpperCase(); | ||
| 1677 | 1678 | } | |
| 1678 | 1679 | }, | |
| 1679 | 1680 | fs.createWriteStream('uppercase.txt') | |
| Back | FazBrowse Home | New Git URL |
0 commit comments