node-timed-stream
Yet another timed stream package. Mostly an exercise.
This module offers features similar to node-throttle
and node-brake
: throttle a stream with time constraints (rate and period at which it emits data)
There is one more feature that this package provide: ability to pause the stream.
The rate can be adjusted on the fly.
Internally it uses backpressure to ensure the rate and period are constant. It also uses a passthrough stream in paused mode and reads to it at the given rate & period.
Examples
const fs = const TimedStream = console const t = rate: 10 /* 1 byte per second */ period: 1000 /* try to emit data every 1000 ms */ let c = 0 // counting data lengthtt fs
For more insight please take a look at tests
Installing
Install via npm:
npm install --save timed-stream
JSDoc
TimedStream
A TimedStream allow data to passthrough at a given rate and pause/resume at any time
Kind: global class
- TimedStream
- new TimedStream([options])
- .rate :
number
- .period :
number
- .streamPaused :
boolean
- .totalTime :
number
- .pauseStream()
- .resumeStream()
- .destroy()
new TimedStream([options])
Creates an instance of TimedStream.
Param | Type | Default | Description |
---|---|---|---|
[options] | object |
Options forwarder to Stream.Transform ctor | |
[options.rate] | number |
0 |
Bytes per seconds (0: unlimited) |
[options.period] | number |
100 |
Time between data event in ms |
number
timedStream.rate : The rate in bytes per second
Kind: instance property of TimedStream
number
timedStream.period : The period between data events in ms
Kind: instance property of TimedStream
boolean
timedStream.streamPaused : True if the stream is paused
Kind: instance property of TimedStream
number
timedStream.totalTime : The total time that the data flowed
Kind: instance property of TimedStream
Read only: true
timedStream.pauseStream()
Pause the stream
Kind: instance method of TimedStream
timedStream.resumeStream()
Resume the stream
Kind: instance method of TimedStream
timedStream.destroy()
Destroy the stream. A destroyed stream will not emit 'end' or any other event
Kind: instance method of TimedStream