Skip to content

Instantly share code, notes, and snippets.

@w7089
Created January 10, 2019 15:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save w7089/0b09c22322f51985e8bee357d66b6e3c to your computer and use it in GitHub Desktop.
Save w7089/0b09c22322f51985e8bee357d66b6e3c to your computer and use it in GitHub Desktop.
readable.js
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