Implementing Transform Streams
Learn about the implementation of Transform streams and the use of simplified construction for transform streams.
We'll cover the following...
Transform streams
Transform streams are a special kind of Duplex stream that are specifically designed to handle data transformations. For example, the functions zlib.createGzip() and crypto.createCipheriv() create Transform streams for compression and encryption, respectively.
In a simple Duplex stream, there’s no immediate relationship between the data read from the stream and the data written into it (at least, the stream is agnostic to such a relationship). Think about a TCP socket, which just sends and receives data to and from the remote peer; the socket is not aware of any relationship between the input and output. The illustration given below shows the data flow in a Duplex stream.
On the other hand, Transform streams apply some kind of transformation to each chunk of data that they receive from their Writable side, and then make the transformed data available on their Readable side. The illustration given below shows how the data flows in a Transform stream.
From the outside, the interface of a Transform ...