Categories
JavaScript Answers

How to download and unzip files in Node.js cross-platform?

Spread the love

To download and unzip files in Node.js cross-platform, we use the zlib library.

For instance, we write

const zlib = require("zlib");

zlib.gunzip(gzipBuffer, (err, result) => {
  if (err) {
    return console.error(err);
  }

  console.log(result);
});

to call gunzip to unzip the gzipBuffer file.

We get the unzipped file from the result parameter in the callback.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *