Skip to content

Instantly share code, notes, and snippets.

@wtfil
Last active August 29, 2015 14:01
Show Gist options
  • Save wtfil/f9121c3b3171132bf960 to your computer and use it in GitHub Desktop.
Save wtfil/f9121c3b3171132bf960 to your computer and use it in GitHub Desktop.
DelayStream
var Transform = require('stream').Transform,
http = require('http');
function DelayStream () {
Transform.apply(this, arguments);
}
DelayStream.prototype = Object.create(Transform.prototype);
DelayStream.prototype._transform = Transform.prototype.push;
function get(options) {
var stream = new DelayStream();
http.get(options, function (res) {
res.pipe(stream);
});
return stream;
}
get('http://google.com')
.on('data', function (chunk) {
console.log(chunk);
})
.on('end', function () {
console.log('done');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment