Node.js · Middle · Question 20 of 75

How do you gzip a file with streams?

import { createReadStream, createWriteStream } from "node:fs";
import { createGzip } from "node:zlib";
import { pipeline } from "node:stream/promises";

Explanation

createGzip() is a Transform stream. The whole file is never in memory, and pipeline handles errors and cleanup.

Further reading

Problem with a question

Node.js · Middle · question 20

Test yourself

Take the Node.js · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz