I am trying to achieve following error handling:
- Say we have a
readable
stream. - We pipe it into a
transform
stream. - Somehow the
transform
stream emits anerror
. - We would like to recover the
readable
stream (and all of its data), and re-pipe it into anothertransform
stream.
Step 4 appears to be difficult: I can listen to unpipe
event on the target stream (transform
stream) and retrieve a reference to the source stream (readable
stream), but at least some chunks of its data have been lost.
Can we do this without creating a custom transform stream?
A real-world example is deflate
content encoding, where in some cases, you need zlib.createInflateRaw()
instead of zlib.createInflate()
, but we can't decide which one would be the correct choice before looking at the response body buffers.