stream2asynciter
v1.0.3
Published
Create async iterator from regular stream
Downloads
69,825
Maintainers
Readme
stream2asyncIter
Example code which convert nodejs's stream to async iterator:
const stream2asynciter = require('stream2asynciter');
const asyncIterator = stream2asynciter(
// any readable stream!
process.stdin
);
(async () => {
for await (const line of asyncIterator) {
console.log('readed', line.length / 1024, 'Kb');
}
})().then(() => {
console.log('ok!');
process.exit();
}, err => {
console.log('err', err);
process.exit();
});
exec
cat somefile.txt | node test.js
and get:
readed 64 Kb
readed 64 Kb
readed 64 Kb
readed 64 Kb
readed 64 Kb
readed 64 Kb
readed 64 Kb
readed 64 Kb
readed 64 Kb
readed 64 Kb
readed 64 Kb
readed 3.4736328125 Kb
ok!