await-stream-ready
v1.0.1
Published
A promise waiting stream ready
Downloads
4,773
Readme
await-stream-ready
A promise waiting stream ready
Usage
npm i await-stream-ready --save
Wait a read stream
const fs = require('fs');
const awaitReadStream = require('await-stream-ready').read;
async function read(file) {
const stream = fs.createReadStream(file);
stream.on('data', buf => {
// consume buf
});
await awaitReadStream(stream);
}
Or wait a write stream
const fs = require('fs');
const awaitWriteStream = require('await-stream-ready').write;
async function write(srcStream, file) {
const stream = srcStream.pipe(fs.createWriteStream(file));
await awaitWriteStream(stream);
}
It will switch the readable stream to flowing mode automatically.