Reputation: 21
I would like to unzip a .zip file in node without any external libraries. How would i go about doing this?
I have tried using zlib but it returns incorrect header type
let zipfile = fs.readFileSync(fileinfomation.savelocation)
zlib.gunzipSync(zipfile)
Edit I have also tried using
let zipfile = fs.readFileSync(fileinfomation.savelocation)
zlib.unzipSync(zipfile)
And it returned i caused the following error Uncaught Error Error: incorrect header check
Link to zip https://code.visualstudio.com/sha/download?build=stable&os=win32-x64-archive
Upvotes: 0
Views: 1345
Reputation: 707328
zlib does not appear to support decompressing a whole zip file archive (that contains multiple files) which is what your visual studio zip file is.
You will either have to use a different library that does support decompressing zip archive files (there are many different libraries on NPM that support that) or you can use child_process to run a zip decompressor that is already on your system.
If this is windows, you can run (using child_process) the built in tar.exe
that can decompress zip archive files or you can get your own command-line decompressor (I use 7-zip myself) and run it as a child_process.
Upvotes: 2