Node.js Course
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?

Flash Cards

Question

Transform vs Duplex?

Click to reveal answer
Answer

In a Duplex stream, reading and writing are completely independent. In a Transform stream, the data you Read is the modified result of the data you Wrote.

Question

Which module uses it for encryption?

Click to reveal answer
Answer

The `crypto` module. `crypto.createCipheriv()` returns a Transform stream that scrambles data as it passes through.