Created
January 10, 2019 15:24
-
-
Save w7089/930b6385e0f61666f958e7b3914b3085 to your computer and use it in GitHub Desktop.
readable.js
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
const {Readable} = require('stream') | |
const inStream = new Readable( { | |
read(size) { | |
this.push(String.fromCharCode(this.currentCharCode++)) | |
if (this.currentCharCode > 90) { | |
this.push(null) | |
} | |
} | |
}); | |
inStream.currentCharCode = 65; | |
// not efficient as we push to stream and only then pipe | |
// inStream.push('hi') | |
// inStream.push(null) | |
// let's push on demand | |
inStream.pipe(process.stdout) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment