controlstream

0.0.6 • Public • Published

ReadStream

Install

npm install controlstream

create a ReadStream

var controlStream = require('controlstream').controlStream
var cs = new controlStream()

fs.createReadStream('file').pipe(cs)

cs.read(50, function(err, data){
	//first 50 bytes are available in data
	
})

move to a certain location

cs.curser = 100
cs.read(50, function(err, data){
	//read bytes 100 to 150	

})	

pipe to a destination

var controlStream = require('controlstream').controlStream
var cs = new controlStream()

fs.createReadStream('file').pipe(cs).pipe(dest)

pipe to multiple destinations

var controlStream = require('controlstream').controlStream
var cs = new controlStream()

fs.createReadStream('file').pipe(cs)

cs.pipe(dest1)
cs.pipe(dest2)

Advanced

var controlStream = require('controlstream').controlStream
var cs = new controlStream({slice:true})

if you pass options {slice:true}, every time you read, that data is no longer in the buffer

cs.read(10, function(err, data){
	//read a header and decide what to do with it
	cs.pipe(dest)
	//pipe the remaining bytes to a destination
	cs.pipe(dest2)
	//pipe remaining bytes to another destination
})

only piping to one destination? or is this the last destination you are piping to?

cs.pipe(dest, {slice:true})
//when cs is done piping, there will be nothing left in the buffer

describe pace and cadence of the pipe (bytes per second)

var controlStream = require('controlstream').controlStream
var cs = new controlStream()

fs.createReadStream('file').pipe(cs)

cs.pipe(dest1, {pace:50,cadence:1000})
//pipe at 50 bytes per second

Readme

Keywords

none

Package Sidebar

Install

npm i controlstream

Weekly Downloads

1

Version

0.0.6

License

none

Last publish

Collaborators

  • timthetoolman