Add protection against buffer overruns (for replay captures).

The capture will now break the dispatch loop in the case where the
internal buffer gets close to full (this is guaranteed to not be needed
in the live case, but could previously cause errors in the replay case).

Improve close event to be always triggered after any end and finish
events.

Refactor the live and replay inheritance model slightly (cleaner
now as the replay won't inherit from duplex anymore, and the live
`_read` and `_write` methods are both on the prototype).

Made error handling more consistent (emitting instead of throwing
in all cases where the call might be async).