Socket
Socket
Sign inDemoInstall

clock-stream

Package Overview
Dependencies
1
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    clock-stream

Push stream chunks only when a clock pulse function is called


Version published
Weekly downloads
2
Maintainers
1
Install size
11.0 kB
Created
Weekly downloads
 

Readme

Source

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

FAQs

Last updated on 24 Oct 2013

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc