Skip to content

Commit

Permalink
add error handling example
Browse files Browse the repository at this point in the history
  • Loading branch information
max-mapper committed Nov 27, 2014
1 parent 9c14e0e commit fa2211a
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions readme.md
Expand Up @@ -67,6 +67,30 @@ By default `concat-stream` will give you back the same data type as the type of

If you don't specify an encoding, and the types can't be inferred (e.g. you write things that aren't int he list above), it will try to convert concat them into a `Buffer`.

# error handling

`concat-stream` does not handle errors for you, so you must handle errors on whatever streams you pipe into `concat-stream`. This is a general rule when programming with node.js streams: always handle errors on each and every stream. Since `concat-stream` is not itself a stream it does not emit errors. Here is a common example of handling errors in a stream:

```
var fs = require('fs')
var concat = require('concat-stream')
var readStream = fs.createReadStream('cat.png')
var concatStream = concat(gotPicture)
readStream.on('error', handleError)
function gotPicture(imageBuffer) {
// process image
}
function handleError(err) {
// handle your error appropriately here
console.error(err) // print the error to STDERR
process.exit(1) // exit program with non-zero exit code
}
```

# license

MIT LICENSE

0 comments on commit fa2211a

Please sign in to comment.