Git Product home page Git Product logo

cancelable-pipeline's Introduction

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

cancelable-pipeline's People

Contributors

shinnn avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.