Implementing Transform Streams

Learn about the implementation of Transform streams and the use of simplified construction for transform streams.

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.

Get hands-on with 1400+ tech skills courses.