Node.js
/Advanced
Transform Streams
Definition
A special type of Duplex stream where the output (Readable) is mathematically computed from the input (Writable).
Explain Like I'm New
It's an assembly line machine. You feed raw potatoes into one side (Writable), the machine slices them, and out the other side comes potato chips (Readable). The output is a direct transformation of the input.
Real World Example
Zipping a file. You pipe a massive 50GB file into `zlib.createGzip()`. As chunks enter the Gzip Transform stream, it compresses the bytes, and spits out compressed chunks to be saved to the hard drive.
Common Use Cases
- •File compression (zlib)
- •Data encryption (crypto ciphers)
- •Parsing massive CSV files into JSON on-the-fly
Interactive Example
Loading...
Console output will appear here...
Interview Questions
basic
- How is a Transform stream different from a Duplex stream?
intermediate
- What core Node module heavily utilizes Transform streams for encryption?