Improve capture stream resource closing.

Also added tests for this. It seems like the `allowHalfOpen` duplex
stream option doesn't work (the readable side doesn't get closed when
the writable is). This is fine for us, we simply listen to the finish
event rather than end, and trigger end from close.