Add 'pipe' event
This commit is contained in:
parent
583f2e5999
commit
634e7236f7
@ -125,6 +125,12 @@ Emitted on error with the exception `exception`.
|
||||
|
||||
Emitted when the underlying file descriptor has been closed.
|
||||
|
||||
### Event: 'pipe'
|
||||
|
||||
`function (src) { }`
|
||||
|
||||
Emitted when the stream is passed to a readable stream's pipe method.
|
||||
|
||||
### stream.writable
|
||||
|
||||
A boolean that is `true` by default, but turns `false` after an `'error'`
|
||||
|
@ -67,4 +67,6 @@ Stream.prototype.pipe = function(dest, options) {
|
||||
dest.on('resume', function() {
|
||||
if (source.readable) source.resume();
|
||||
});
|
||||
|
||||
dest.emit('pipe', source);
|
||||
};
|
||||
|
27
test/simple/test-stream-pipe-event.js
Normal file
27
test/simple/test-stream-pipe-event.js
Normal file
@ -0,0 +1,27 @@
|
||||
var stream = require('stream');
|
||||
var assert = require('assert');
|
||||
var util = require('util');
|
||||
|
||||
function Writable () {
|
||||
this.writable = true;
|
||||
stream.Stream.call(this);
|
||||
}
|
||||
util.inherits(Writable, stream.Stream);
|
||||
|
||||
function Readable () {
|
||||
this.readable = true;
|
||||
stream.Stream.call(this);
|
||||
}
|
||||
util.inherits(Readable, stream.Stream);
|
||||
|
||||
var passed = false;
|
||||
|
||||
var w = new Writable();
|
||||
w.on('pipe', function (src) {
|
||||
passed = true;
|
||||
});
|
||||
|
||||
var r = new Readable();
|
||||
r.pipe(w);
|
||||
|
||||
assert.ok(passed)
|
Loading…
x
Reference in New Issue
Block a user