await-stream-ready

A promise waiting stream ready

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
await-stream-ready
3401.0.16 years ago6 years agoMinified + gzip package size for await-stream-ready in KB

Readme

await-stream-ready
A promise waiting stream ready
!NPM versionnpm-imagenpm-url !build statustravis-imagetravis-url !Test coveragecodecov-imagecodecov-url !David depsdavid-imagedavid-url !Known Vulnerabilitiessnyk-imagesnyk-url !NPM downloaddownload-imagedownload-url

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.

License

MIT