package
Get an event when you're being sent data or asked for it.
npm install stream-eventsGitHub-flavored package documentation.
Across all versions, last 30 days.
131,680,203 in 30 days
Runtime metadata.
Tagged topics.
Get an event when you're being sent data or asked for it.
This is just a simple thing that tells you when _read and _write have been called, saving you the trouble of writing this yourself. You receive two events reading and writing-- no magic is performed.
This works well with duplexify or lazy streams, so you can wait until you know you're being used as a stream to do something asynchronous, such as fetching an API token.
$ npm install --save stream-eventsvar stream = require('stream')
var streamEvents = require('stream-events')
var util = require('util')
function MyStream() {
stream.Duplex.call(this)
streamEvents.call(this)
}
util.inherits(MyStream, stream.Duplex)
MyStream.prototype._read = function(chunk) {
console.log('_read called as usual')
this.push(new Buffer(chunk))
this
var duplexify = require('duplexify')
var streamEvents = require('stream-events')
var fs = require('fs')
var dup = streamEvents(duplexify())
dup.on('writing', function() {
// do something async
dup.setWritable(/*writable stream*/)
})
fs.createReadStream('file').pipe(dup)Estimated unpacked size across 2 packages.
3.0 kB
Includes dependencies.