December 2018
Intermediate to advanced
642 pages
15h 5m
English
We use the fs module to produce two streams: a readable one, with which we will be reading a given file (here, a fixed one, but it would be trivial to read any other one) and a writable one, where the gzipped output will go. We will pipe the input stream through the gzip module, which will compress the input before passing it on to the output.
We could as easily have produced a server that would have sent the zipped file to the client, to download. The following is the required code; the key difference is that the zipped stream now goes to the response stream. We must also provide some headers, so the client will know that a zipped file is being sent:
// Source file: src/zip_send.jsconst zlib = require("zlib");const fs = require("fs"); ...Read now
Unlock full access