Compressing multiple files using zlib

user3180402 picture user3180402 · Feb 24, 2014 · Viewed 15.3k times · Source

The below code will compress one file. How can I compress multiple files

var gzip = zlib.createGzip();
var fs = require('fs');
var inp = fs.createReadStream('input.txt');
var out = fs.createWriteStream('input.txt.gz');

inp.pipe(gzip).pipe(out);

Answer

B T picture B T · Aug 31, 2014

Gzip is an algorithm that compresses a string of data. It knows nothing about files or folders and so can't do what you want by itself. What you can do is use an archiver tool to build a single archive file, and then use gzip to compress the data that makes up the archive:

Also see this answer for more information: Node.js - Zip/Unzip a folder