Skip to content

A duplex stream that holds onto data until it receives a clock pulse

License

Notifications You must be signed in to change notification settings

emac-utd/clock-stream

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

clock-stream

Build Status

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()) //<Buffer 01 02 03 04>, when it gets called
})

//Some other stuff

stream.pulse() //Will fire readable

var threeAtATime = new CS(3)
threeAtATime.write(new Buffer([1,2,3,4]))
threeAtATime.on('readable', function() {
  console.log(stream.read())
})

threeAtATime.pulse() //<Buffer 01 02 03>
threeAtATime.pulse() //<Buffer 04>

//Pulse is meant to be used in conjunction with EventEmitter#on
//midi-clock, for instance, can be used for metronome-esque functionality
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

About

A duplex stream that holds onto data until it receives a clock pulse

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published