
Product
Socket Now Protects the Chrome Extension Ecosystem
Socket is launching experimental protection for Chrome extensions, scanning for malware and risky permissions to prevent silent supply chain attacks.
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 32 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.
Product
Socket is launching experimental protection for Chrome extensions, scanning for malware and risky permissions to prevent silent supply chain attacks.
Product
Add secure dependency scanning to Claude Desktop with Socket MCP, a one-click extension that keeps your coding conversations safe from malicious packages.
Product
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.