Created
November 4, 2015 01:57
-
-
Save spasiu/d967333b9c4778d80326 to your computer and use it in GitHub Desktop.
readable streams
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
const Readable = require('stream').Readable; | |
const util = require('util'); | |
function Reader() { | |
Readable.call(this); | |
this.arr = [0,1,2,3,4,5,6,7,8,9,10,11]; | |
} | |
util.inherits(Reader, Readable); | |
Reader.prototype._read = function() { | |
let element = this.arr.pop() | |
return this.push(element? element.toString(): null); | |
}; | |
let reader = new Reader(); | |
reader.setEncoding('utf8'); | |
reader.on('data', chunk => console.log(chunk)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment