summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikeal Rogers <mikeal.rogers@gmail.com>2011-02-09 23:02:51 -0800
committerRyan Dahl <ry@tinyclouds.org>2011-02-09 23:04:35 -0800
commit634e7236f7456432107d05fe8ec5f8da19a6abe4 (patch)
tree8dae64d78c4ce1affd3d553922f8d96cd15b89ed
parent583f2e599962f2664dbaafa0ae98a8d6c1242441 (diff)
downloadandroid-node-v8-634e7236f7456432107d05fe8ec5f8da19a6abe4.tar.gz
android-node-v8-634e7236f7456432107d05fe8ec5f8da19a6abe4.tar.bz2
android-node-v8-634e7236f7456432107d05fe8ec5f8da19a6abe4.zip
Add 'pipe' event
-rw-r--r--doc/api/streams.markdown6
-rw-r--r--lib/stream.js2
-rw-r--r--test/simple/test-stream-pipe-event.js27
3 files changed, 35 insertions, 0 deletions
diff --git a/doc/api/streams.markdown b/doc/api/streams.markdown
index 98cee1efff..0fc4aadf3b 100644
--- a/doc/api/streams.markdown
+++ b/doc/api/streams.markdown
@@ -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'`
diff --git a/lib/stream.js b/lib/stream.js
index 98f0c37fcb..c5fcd2a4c2 100644
--- a/lib/stream.js
+++ b/lib/stream.js
@@ -67,4 +67,6 @@ Stream.prototype.pipe = function(dest, options) {
dest.on('resume', function() {
if (source.readable) source.resume();
});
+
+ dest.emit('pipe', source);
};
diff --git a/test/simple/test-stream-pipe-event.js b/test/simple/test-stream-pipe-event.js
new file mode 100644
index 0000000000..a480d60f90
--- /dev/null
+++ b/test/simple/test-stream-pipe-event.js
@@ -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)