Skip to content

OnikurYH/then-streams

Repository files navigation

then-streams

Convert Node.js Streams to Promise

node npm npm type definitions Build Status

Install

NPM

npm install then-streams -S

Yarn

yarn add then-streams -S

Example

This package is written in TypeScript, also can work on JavaScript!

Writable Stream

import fs from 'fs';
import thenStreams from 'then-streams';

async function readFileToConsole() {
  const stream = fs.createReadStream('some-file.txt')
    .pipe(process.stdout);
  await thenStreams.toPromise(stream);
  console.log('The file has finished reading and pipe to console');
}

Readable Stream

import fs from 'fs';
import thenStreams from 'then-streams';

async function readFileAndCollect() {
  const data = [];
  const stream = fs.createReadStream('some-file.txt')
    .on('data', d => data.push(d));
  await thenStreams.toPromise(stream);
}

Run test

You could run the tests from the test folder

yarn install
yarn test

Copyright and license

Licensed under the MIT license.

Releases

No releases published

Packages

No packages published