Q21: Why should pipeline() from stream/promises be preferred over readable.pipe()?

While readable.pipe() routes data between streams, it fails to handle error forwarding across all stream stages automatically, often leaving streams open and causing memory or file descriptor leaks. The stream.pipeline() helper properly forwards errors, cleans up unclosed underlying file descriptors, and supports Promise syntax via stream/promises.

Key Takeaways
  • pipe() can leak file descriptors and stream handles when errors occur mid-stream.
  • pipeline() cleans up destroyed streams safely and provides built-in Promise support.
Knowledge Check

What is the primary advantage of stream.pipeline() over the traditional stream.pipe() method?