Created
January 10, 2019 15:29
-
-
Save w7089/0b09c22322f51985e8bee357d66b6e3c 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) { | |
setTimeout(() => { | |
this.push(String.fromCharCode(this.currentCharCode++)) | |
if (this.currentCharCode > 90) { | |
this.push(null) | |
} | |
}, 100) | |
} | |
}); | |
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