#Thisisslightlyhacky,butreturninga.pipe'd stream would make all the response object attributes unavailable to the end user. Therefore, 'branching' the stream into our progress monitoring stream is a much better option. We use .pause() to ensure the stream doesn'tstartflowinguntiltheenduser(orourlibrary)hasactuallypipeditintosomething.
response.pipe(progressStream)
response.pause()
#Thisisavery,verydirtyhack-however,using.pipefollowedby.pausebreaksinNode.jsv0.10.35with"Cannot switch to old mode now".Oursolutionistomonkeypatchthe`on`and`resume`methodstoattachtheprogresseventhandlerassoonassomethingelseisattachedtotheresponsestream(orwhenitisdrained).Thisway,ausercanalsopipetheresponseinalatertick,withoutthestreamdrainingprematurely.