Coder Social home page Coder Social logo

node-shaper's Introduction

shaper

Limit stream speed to bytes per second/chunk per second

Inspired by node-throttle module, but acts as a through stream and splits input chunks if required to maintain target speed as close as possible.

Installation

$ npm install shaper

Examples

'Slow cat' example:

    var shape = require('shaper');
    process.stdin.pipe(shape(10)).pipe(process.stdout, {end: false} );
    process.stdin.resume();

output:

    $ time echo "this is 58-chars long string (including trailing newline)" | node examples/slowcat.js 
    this is 58-chars long string (including trailing newline)

    real	0m5.912s
    user	0m0.056s
    sys	        0m0.012s

API

    var shaper = require('shaper');
    var shapeStream = shaper(byteRate, chunkRate, lowWatermark, highWatermark)

byteRate - targeted speed in bytes per second

chunkRate - (default is 10) - output chunk rate. If target speed is 20000 bytes per second and chunk rate is 100, you'll have 100 chunks per second stream, each 200 bytes in size (on average). Note that if input stream is slower then target, chunks are sent immideately at input rate, wich could be higher than target chunk rate. If input is 1000 chunks per second, each 10 bytes shape(20000, 500) should give same 1000 chunk per second x 10 bytes stream.

lowWatermark - emit drain event if buffer size is less than this paremeter. Default to 0.

highWatermark - size when buffer is considered full. Default to 0.

node-shaper's People

Contributors

sidorares avatar

Watchers

James Cloos avatar Antti Korpi avatar  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.