Package Exports
- cancelable-pipeline
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (cancelable-pipeline) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
cancelable-pump
Cancelable pump
const {createReadStream, createWriteStream, promises: {stat}} = require('fs');
const cancelablePump = require('cancelable-pump');
cancelablePump(createReadStream('1GB-file.txt'), createWriteStream('dest0'), async () => {
(await stat('dest0')).size; //=> 1000000000;
});
const cancel = cancelablePump(createReadStream('1GB-file.txt'), createWriteStream('dest1'), async () => {
(await stat('dest1')).size; //=> 263192576, or something else smaller than 1000000000
});
setTimeout(() => {
cancel();
}, 1000);
Installation
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