Skip to content

Instantly share code, notes, and snippets.

@w7089
Created Jan 10, 2019
Embed
What would you like to do?
readable.js
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