Safely pipe node.js streams while capturing all errors to a single promise.
promisePipe(<readable stream>, [transform streams...], <writeable stream>)
It returns a native promise. On success the resolved value will be an array of the streams passed in. When rejected an error object is created with following keys:
source: The stream that caused the error
originalError: Original error from the stream
message: The error message from original error
Notice that the
promisePipe function installs handlers for some events and cancels
them upon return, and this may include any event handler you installed before calling
var promisePipe = ;;
npm install promisepipe
Stream piping in node.js is cool, but error handling is not because streams do not bubble errors to the target streams.
For example if the previous example is written like this:
It might crash your program at any time. You must handle the errors from each stream manually like this:
Which is imo repeative and cumbersome (at least when you want to use promises).