To unzip a zip file in JavaScript using the fs
module, you can use the unzip
and zlib
modules. Here is an example:
441 chars17 lines
In this example, we use fs.createReadStream
to read the zip file, then pipe it to zlib.createGunzip
to unzip it, and finally pipe it to unzip.Extract
to extract the files to the specified output directory. The unzip.Extract
method takes an options object with a path
property specifying the output directory. We also handle errors and log a success message when the extraction is complete.
gistlibby LogSnag