1.0.3 • Published 2 years ago

stream2asynciter v1.0.3

Weekly downloads
3,169
License
ISC
Repository
github
Last release
2 years ago

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!