Skip to content

Instantly share code, notes, and snippets.

@dignifiedquire
Last active September 13, 2016 12:34
Show Gist options
  • Save dignifiedquire/238459beb666158ecb4238bb83d24ae0 to your computer and use it in GitHub Desktop.
Save dignifiedquire/238459beb666158ecb4238bb83d24ae0 to your computer and use it in GitHub Desktop.
const through = reuquire('through2')
getResponse((response) => {
const mapper = through((chunk, enc, cb) => {
let parsed
try {
parsed = JSON.parse(chunk.toString())
} catch (err) {
return cb(err)
}
// process parsed object
const finished = process(parsed)
cb(null, finished)
})
mapper.cancel = () => {
req.abort()
}
response.pipe(mapper)
cb(null, mapper)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment