Created
October 11, 2010 05:23
-
-
Save mikeal/620021 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/stream.js b/lib/stream.js | |
index 189708a..37687b0 100644 | |
--- a/lib/stream.js | |
+++ b/lib/stream.js | |
@@ -53,3 +53,22 @@ Stream.prototype.pipe = function (dest, options) { | |
if (source.readable) source.resume(); | |
}); | |
}; | |
+ | |
+exports.createFilter = function (listener) { | |
+ var filter = new Stream(); | |
+ filter.readable = true; | |
+ filter.writeable = true; | |
+ | |
+ var w = function (chunk) { | |
+ filter.emit("data"); | |
+ }; | |
+ | |
+ filter.write = function (chunk) { | |
+ listener(chunk, w); | |
+ }; | |
+ filter.on("end", function () { | |
+ listener(null, w); | |
+ }); | |
+ | |
+ return filter; | |
+} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment