Q:

How do you zip a file in node.js?

belongs to collection: Node.js programming Exercises

0

How do you zip a file in node.js

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Solution

Node.js provides Zlib module to zip a file. The given example demonstrates this -

var zlib = require('zlib');
var fs = require('fs');

var gzip = zlib.createGzip();
var r = fs.createReadStream('./demofile.txt');
var w = fs.createWriteStream('./demogzipfile.txt.gz');
r.pipe(gzip).pipe(w);

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

How do you use try catch blocks in node.js?... >>
<< How does node JS connect to MongoDB database?...