Merge pull request #1 from roadrunner2/master

Improve handling of error conditions
Implement flow-control on the output pipe.

Otherwise a slow reader on the output will cause internal stream buffers
to grow unbounded.

Note that the input pipe already has implicit flow-control via the
callback.