Every readable stream is asynchronously iterable, which means that we can use a for await...of
loop to read the stream's contents:
import * as fs from "fs";
async function logChunks(readable) {
for await (const chunk of readable) {
consoel.log(chunk);
}
}
const readable = fs.createReadStream("tmp/test.txt", { encoding: "utf8" });
logChunks(readable);
// 'This is a test!\n'
Shout out to Marshall for the pointer on this one ❤️