Creating transform streams
Transform streams allow us to consume input data, process that data, and then output the data in its processed form. We can use transform streams to handle data manipulation functionally and asynchronously. It’s possible to pipe many transform streams together, allowing us to break complex processing down into sequential tasks.
In this recipe, we’re going to create a transform stream using the Node.js core stream
module.
Important note
The through2
module (https://www.npmjs.com/package/through2) is very popular and provides a wrapper for creating Node.js transform streams. However, over the past few years, there have been many simplifications and improvements to the Node.js core stream implementation. Today, the Node.js stream API provides simplified construction, as demonstrated in this recipe, which means we can achieve equivalent syntax using Node.js core directly, without the need for through2
.
Getting ready
Follow these steps...