Skip to content

Instantly share code, notes, and snippets.

@mafintosh
Created August 21, 2018 19:05
Show Gist options
  • Save mafintosh/9c3b1ea99186a6590f61e205d7816026 to your computer and use it in GitHub Desktop.
Save mafintosh/9c3b1ea99186a6590f61e205d7816026 to your computer and use it in GitHub Desktop.
const stream = require('stream')
const r = new stream.Readable({
read () {
this.push('hello')
this.push('world')
this.push(null)
}
})
r.on('data', data => console.log('r data', data))
r.on('end', () => console.log('r end'))
r.on('close', () => console.log('r close'))
const t = new stream.Transform({
transform (data, enc, cb) {
cb(null, data)
}
})
t.write('hello')
t.write('world')
t.end()
t.on('data', data => console.log('t data', data))
t.on('end', () => console.log('t end'))
t.on('finish', () => console.log('t finish'))
t.on('close', () => console.log('t close'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment