Created
May 23, 2015 22:23
-
-
Save gyaresu/8ec65881ef162bf879ec to your computer and use it in GitHub Desktop.
How to catch a stream error (using through2)
This file contains 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
var tr = require('through2') | |
function write(buffer, encoding, next) { | |
try { | |
this.push(buffer.toUpperCase()) //buffer needs .toString() | |
} catch (e) { | |
this.emit('error', e) | |
} | |
next() | |
} | |
function end(done) { | |
done() | |
} | |
var stream = tr(write, end) | |
stream.on('error', function (e) { | |
console.log('Broked it.', e) | |
}) | |
process.stdin.pipe(stream).pipe(process.stdout) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment