stream-events

WebJar for stream-events

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

stream-events
Last Version

Last Version

1.0.5
Release Date

Release Date

Type

Type

jar
Description

Description

stream-events
WebJar for stream-events
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/stephenplusplus/stream-events

Download stream-events

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/stream-events/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>stream-events</artifactId>
    <version>1.0.5</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/stream-events/
implementation 'org.webjars.npm:stream-events:1.0.5'
// https://jarcasting.com/artifacts/org.webjars.npm/stream-events/
implementation ("org.webjars.npm:stream-events:1.0.5")
'org.webjars.npm:stream-events:jar:1.0.5'
<dependency org="org.webjars.npm" name="stream-events" rev="1.0.5">
  <artifact name="stream-events" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='stream-events', version='1.0.5')
)
libraryDependencies += "org.webjars.npm" % "stream-events" % "1.0.5"
[org.webjars.npm/stream-events "1.0.5"]

Dependencies

compile (1)

Group / Artifact Type Version
org.webjars.npm : stubs jar [3.0.0,4)

Project Modules

There are no modules declared in this project.

stream-events

Get an event when you're being sent data or asked for it.

About

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.

Use

$ npm install --save stream-events
var 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.push(null)
}

MyStream.prototype._write = function() {
  console.log('_write called as usual')
}

var stream = new MyStream

stream.on('reading', function() {
  console.log('stream is being asked for data')
})

stream.on('writing', function() {
  console.log('stream is being sent data')
})

stream.pipe(stream)

Using with Duplexify

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)

Versions

Version
1.0.5
1.0.1