Cancelable stream.pipeline()
const {createReadStream, createWriteStream, promises: {stat}} = require('fs');
const cancelablePipeline = require('cancelable-pipeline');
cancelablePipeline(createReadStream('1GB-file.txt'), createWriteStream('dest0'), async () => {
(await stat('dest0')).size; //=> 1000000000;
});
const cancel = cancelablePipeline(createReadStream('1GB-file.txt'), createWriteStream('dest1'), async () => {
(await stat('dest1')).size; //=> 263192576, or something else smaller than 1000000000
});
setTimeout(() => cancel(), 1000);
npm install cancelable-pipeline
const cancelablePipeline = require('cancelable-pipeline');
stream0, stream1, stream2, ...: Stream
callback: Function
Return: Function
streams: Stream[]
callback: Function
Return: Function
The API is almost the same as stream.pipeline()
. The only difference is cancelable-pipeline returns a Function
which destroys all the piped Stream
s without passing any errors to the callback.
const cancel = cancelablePipeline([src, transform, anotherTransform, dest], err => {
err; //=> undefined
});
cancel();
ISC License © 2017 - 2019 Shinnosuke Watanabe