Skip to content

Instantly share code, notes, and snippets.

@bodokaiser
Last active December 15, 2015 15:18
Show Gist options
  • Save bodokaiser/5280367 to your computer and use it in GitHub Desktop.
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".
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