Organizational Research By

Surprising Reserch Topic

simplest way to download and unzip files in node js cross platform

simplest way to download and unzip files in node js cross platform  using -'node.js,zip'

Just looking for a simple solution to downloading and unzipping .zip or .tar.gz files in Node.js on any operating system.

Not sure if this is built in or I have to use a separate library.  Any ideas?  Looking for just a couple lines of code so when the next zip file comes that I want to download in node, it's a no brainer.  Feel like this should be easy and/or built in, but I can't find anything. Thanks!

asked Sep 18, 2015 by kotmus2002
0 votes

Related Hot Questions

6 Answers

0 votes

Checkout adm-zip

ADM-ZIP is a pure JavaScript implementation for zip data compression for NodeJS.

The library allows you to:

decompress zip files directly to disk or in memory buffers compress files and store them to disk in .zip format or in compressed buffers update content of/add new/delete files from an existing .zip

answered Sep 18, 2015 by kotmus2002
0 votes

Node has builtin support for gzip and deflate via the zlib module:

var zlib = require('zlib');

zlib.gunzip(gzipBuffer, function(err, result) {
    if(err) return console.error(err);


Edit: You can even pipe the data directly through e.g. Gunzip (using request):

var request = require('request'),
    zlib = require('zlib'),
    fs = require('fs'),
    out = fs.createWriteStream('out');

// Fetch, gunzip it and store the results in 'out'

For tar archives, there is Isaacs' tar module, which is used by npm.

Edit 2: Updated answer as zlib doesn't support the zip format. This will only work for gzip.

answered Sep 18, 2015 by abhi
0 votes

yauzl is a robust library for unzipping. Design principles:

  • Follow the spec. Don't scan for local file headers. Read the central directory for file metadata.
  • Don't block the JavaScript thread. Use and provide async APIs.
  • Keep memory usage under control. Don't attempt to buffer entire files in RAM at once.
  • Never crash (if used properly). Don't let malformed zip files bring down client applications who are trying to catch errors.
  • Catch unsafe filenames entries. A zip file entry throws an error if its file name starts with "/" or /[A-Za-z]:// or if it contains ".." path segments or "\" (per the spec).

Currently has 97% test coverage.

answered Sep 18, 2015 by gauravsinghal83
0 votes

Another working example:

var zlib = require('zlib');
var tar = require('tar');
var ftp = require('ftp');

var files = [];

var conn = new ftp();
conn.on('connect', function(e) 
        if (e)
            throw e;
        conn.get('/tz/tzdata-latest.tar.gz', function(e, stream) 
            stream.on('success', function() 

                console.log("Processing files ...");

                for (var name in files)
                    var file = files[name];

                    console.log("filename: " + name);
            stream.on('error', function(e) 
                console.log('ERROR during get(): ' + e);

            console.log("Reading ...");

            .on("entry", function (e) 
                var filename = e.props["path"];
                console.log("filename:" + filename);
                if( files[filename] == null )
                    files[filename] = "";
                e.on("data", function (c) 
                    files[filename] += c.toString();
.connect(21, "");
answered Sep 18, 2015 by devkumargupta
0 votes
var readPath ="read file location";
var writePath="Write file location ";
fs.createReadStream(reNameReadPath).pipe(unzip.Extract({ path: writePath }));

please see the following link
answered Sep 18, 2015 by sanjaypal1983
0 votes

11/2014: Unfortunately the situation is that there is no good solution to unzipping files in nodejs. There are few libraries each with number of major issues open and contribution stopped long time ago.

answered Sep 18, 2015 by maurya