Last active
September 13, 2016 12:34
-
-
Save dignifiedquire/238459beb666158ecb4238bb83d24ae0 to your computer and use it in GitHub Desktop.
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 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