Skip to content

Instantly share code, notes, and snippets.

@tbuchok
Last active August 29, 2015 13:59
Show Gist options
  • Save tbuchok/10482143 to your computer and use it in GitHub Desktop.
Save tbuchok/10482143 to your computer and use it in GitHub Desktop.
readable streams are fun.
var Readable = require('stream').Readable
, util = require('util')
;
util.inherits(FakeReadable, Readable);
function FakeReadable(options) {
var self = this;
Readable.call(self);
self.push(new Buffer('data'));
setTimeout(function() {
self.push(new Buffer('moar data!'));
self.push(null);
}, 2000);
}
FakeReadable.prototype._read = function(size) {
process.stdout.write('\nreadable!\n');
};
new FakeReadable()
.pipe(process.stdout)
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment