JSPM

cancelable-pipeline

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 19
  • Score
    100M100P100Q67827F
  • License ISC

Cancelable `stream.pipeline()`

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-pipeline

npm version Build Status codecov

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);

Installation

Use npm.

npm install cancelable-pipeline

API

const cancelablePipeline = require('cancelable-pipeline');

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

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

cancelablePipeline(streams [, callback])

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 Streams without passing any errors to the callback.

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

cancel();

License

ISC License © 2017 - 2019 Shinnosuke Watanabe