Last active
August 29, 2015 14:01
-
-
Save wtfil/f9121c3b3171132bf960 to your computer and use it in GitHub Desktop.
DelayStream
This file contains hidden or 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
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