'Ending node pipe on Transform or PassThrough

I have a stream pipe that reads, unzips, transforms, then I'd like to choose whether it moves onto a callback or writes and moves onto a callback. I hit on PassThrough and thought I could use that to create the option, setting the variable of the last pipe to either the PassThrough or writestream. I guess that's a stretch goal at this point. I just do not always want to write the large data file after working with it.

response.pipe(unzip).pipe(transformstream).pipe(writeorpass).on("finish", () => {

It works (callback triggers) when it ends with the write stream. It does not with either transform or passthrough. I suspect from my learning that neither of those emit a "finish" or similar.

What are some solutions to end the stream on a transform or passthrough, particularly to go on asynchronously after the stream finishes.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source