Last active
December 15, 2015 15:18
-
-
Save bodokaiser/5280367 to your computer and use it in GitHub Desktop.
Gist which shows "unexpected" behavior that when I unshift data back on the source I get no call of "_read".
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
var stream = require('stream'); | |
var rOne = new stream.Readable(); | |
var rTwo = new stream.Readable(); | |
rTwo.isBody = false; | |
rTwo.source = rOne; | |
rOne._read = function() {}; | |
rTwo._read = function() { | |
var chunk = this.source.read(); | |
if (chunk === null) | |
return this.push(''); | |
if (!this.isBody) { | |
this.isBody = true; | |
this.source.unshift(chunk); | |
} else { | |
this.push(chunk); | |
} | |
}; | |
rOne.on('readable', function() { | |
rTwo.read(0); | |
}); | |
rTwo.on('readable', function() { | |
console.log(rTwo.read().toString()); | |
}); | |
rOne.push(new Buffer('Hello')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment