Skip to content

Instantly share code, notes, and snippets.

@mikeal
Created October 11, 2010 05:23
Show Gist options
  • Save mikeal/620021 to your computer and use it in GitHub Desktop.
Save mikeal/620021 to your computer and use it in GitHub Desktop.
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