Transforming data with transform streams
Transform streams allow us to consume input data, then process that data, and then output the data in 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
through2
(https://www.npmjs.com/package/through2) is a popular module that 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 streams implementation. Today, the Node.js stream API provides simplified construction, as demonstrated in the recipe, which means we can achieve equivalent syntax using Node.js core directly, without the need for through2
.
Getting ready
- Create...