Skip to content

Instantly share code, notes, and snippets.

@isaacs
Created July 26, 2012 02:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isaacs/3179964 to your computer and use it in GitHub Desktop.
Save isaacs/3179964 to your computer and use it in GitHub Desktop.
Readable.prototype.pipe = function(dest) {
this.on('end', dest.end.bind(dest));
flow.call(this);
function flow() {
var chunk;
while (chunk = this.read()) {
var written = dest.write(chunk);
if (!written) {
dest.once('drain', flow.bind(this));
return;
}
}
this.once('readable', flow);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment