Skip to content

node-modules/await-stream-ready

Repository files navigation

await-stream-ready

A promise waiting stream ready

NPM version build status Test coverage David deps Known Vulnerabilities NPM download


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

About

a promise waiting stream ready

Resources

License

Stars

Watchers

Forks

Packages

No packages published