
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
async-stream-reader
Advanced tools
An async way to read stream
Sometime you may want to read something from a stream, typically a file stream, in an async-await style. This tool may help you by providing an async read method for streams.
The async-stream-reader
holds events and returns them one by one every time async StreamReader#next
get called. If async-stream-reader
has got some events in the holder, it will try to pause the input stream, and resume it if the holder get empty.
So as long as the input stream supports pause
and resume
, you can just do your work at each frame of data at ease, without worring missing something, or memory consumed in large quantities
const fs = require('fs');
const readline = require('readline');
const StreamReader = require('async-stream-reader');
const rl = readline.createInterface({
input: fs.createReadStream("./foo.txt");
});
const reader = new StreamReader(rl, {
events: { data: 'line', end: 'close' },
});
async main() {
let line;
while (line = await reader.next()) {
console.log(line);
}
}
main().catch(error => console.log(error));
undefined
or options.end
will be returned.reader.next()
get called and consumes the error on the head of the queue.Thanks @Divvito for rewriting this in typescript version.
FAQs
A stream reader with async functions
The npm package async-stream-reader receives a total of 40 weekly downloads. As such, async-stream-reader popularity was classified as not popular.
We found that async-stream-reader demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.