npm

Need private packages and team management tools?Check out npm Orgs. »

cancelable-pump

0.4.0 • Public • Published

cancelable-pump

npm version Build Status Coverage Status

Cancelable pump

const {createReadStream, createWriteStream} = require('cancelable-pump');
const cancelablePump = require('cancelable-pump');
 
cancelablePump(createReadStream('1GB-file.txt'), createWriteStream('dest0'), () => {
  statSync('dest0').size; //=> 1000000000;
});
 
const cancel = cancelablePump(createReadStream('1GB-file.txt'), createWriteStream('dest1'), () => {
  statSync('dest1').size; //=> 263192576, or something else smaller than 1000000000
});
 
setTimeout(() => {
  cancel();
}, 1000);

Installation

Use npm.

npm install cancelable-pump

API

const cancelablePump = require('cancelable-pump');

cancelablePump(stream0 [, stream1, stream2, ...] [, callback])

stream0, stream1, stream2, ...: Stream
callback: Function
Return: Function

cancelablePump(streams [, callback])

streams: Array<Stream>
callback: Function
Return: Function

The API is almost the same as pump's. The only difference is cancelable-pump returns a function to destroy all streams without passing any errors to the callback.

const cancel = cancelablePump([src, transform, anotherTransform, dest], err => {
  err; //=> undefined
});
 
cancel();

License

ISC License © 2017 - 2018 Shinnosuke Watanabe

install

npm i cancelable-pump

Downloadsweekly downloads

4,114

version

0.4.0

license

ISC

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability