clock-stream

A duplex stream that holds onto data until it receives a "pulse." Perfect for rationing pipes on a schedule.
Example
var CS = require('clock-stream')
var stream = new CS()
stream.write(new Buffer([1,2,3,4]))
stream.on('readable', function() {
console.log(stream.read())
})
stream.pulse()
var threeAtATime = new CS(3)
threeAtATime.write(new Buffer([1,2,3,4]))
threeAtATime.on('readable', function() {
console.log(stream.read())
})
threeAtATime.pulse()
threeAtATime.pulse()
var MidiClock = require('midi-clock')
var clock = MidiClock()
clock.on('position', threeAtATime.pulse)
API
In addition to the normal duplex stream methods, clock-stream offers:
###var CS = require('clock-stream')
Main class for clock-stream
var stream = new CS([pulsesize])
Create a new stream, optionally specifying how many bytes to feed on each pulse
stream.pulse()
Feed the previously specified number of bytes through the stream, or all currently queued data if no size was specified.
See also
Substack's Stream Handbook
Official Stream API docs
Official Buffer API docs
License
MIT