Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I unzip a .zip/.rar file in Node.js into a folder

Tags:

node.js

I am using zlib along with fstream now for zipping and sending to the client, Now I need to unzip an archive(which may contains sub folders) into a folder maintaining the folder structure. How do I do that?

like image 862
Raghavendra Avatar asked Jan 27 '14 13:01

Raghavendra


People also ask

How do I extract a ZIP file from a specific folder?

To unzip a single file or folder, open the zipped folder, then drag the file or folder from the zipped folder to a new location. To unzip all the contents of the zipped folder, press and hold (or right-click) the folder, select Extract All, and then follow the instructions.


1 Answers

There are plenty of node modules that can do this for you. One of them is node-unzip. You can extract a .zip file to a directory as simple as this.

fs.createReadStream('path/to/archive.zip').pipe(unzip.Extract({ path: 'output/path' }));

Further reading: https://github.com/EvanOxfeld/node-unzip

like image 163
gpopoteur Avatar answered Oct 23 '22 11:10

gpopoteur