Simple Way to Unzip a .Zip File Using Zlib

Simple way to unzip a .zip file using zlib

zlib handles the deflate compression/decompression algorithm, but there is more than that in a ZIP file.

You can try libzip. It is free, portable and easy to use.

UPDATE: Here I attach quick'n'dirty example of libzip, with all the error controls ommited:

#include <zip.h>

int main()
{
//Open the ZIP archive
int err = 0;
zip *z = zip_open("foo.zip", 0, &err);

//Search for the file of given name
const char *name = "file.txt";
struct zip_stat st;
zip_stat_init(&st);
zip_stat(z, name, 0, &st);

//Alloc memory for its uncompressed contents
char *contents = new char[st.size];

//Read the compressed file
zip_file *f = zip_fopen(z, name, 0);
zip_fread(f, contents, st.size);
zip_fclose(f);

//And close the archive
zip_close(z);

//Do something with the contents
//delete allocated memory
delete[] contents;
}

unzipping a zip file with zlib/minizip: C/C++ Application

Resolved the error by running make first in zlib-1.2.3 and then make in minizip

zlib uncompress a .zip file

From faq

Can zlib handle .zip archives?

Not by itself, no. See the directory contrib/minizip in the zlib distribution.

see: http://www.zlib.net/zlib_faq.html#faq11

How to make a .zip file using zlib

As @Jongware mentioned, you can find an example in the contrib/minizip folder of the source code library.

OR !

You can simply use libzip.

Possible duplicate: Simple way to unzip a .zip file using zlib

Cannot unzip the zip file created using zlib in Java

Make sure to close the ZipOutputStream after you've written the last entry. This gives the stream a chance to finish creating the ZIP archive.

How to unzip an archive using zlib in Node.js?

zlib by itself does not process .zip files. You need something like libarchive or libzip for that. (Both of those use zlib for the core compression, decompression, and CRC-32 calculation.)

I looks like they are both part of the Amazon Linux AMI.

ZLib unzip a zip containing multiple files

If you're having problems with zlib, maybe you might want to consider TurboPower's Abbrevia (available on SourceForge). With Abbrevia, here's our multiple-file extract code:

zip.ArchiveType := atZip ;
zip.ForceType := true ;
zip.OpenArchive({...your .zip archive name});

zip.BaseDirectory := {...your extract path...} ;
zip.OnConfirmOverwrite := Overwrite
zip.ExtractFiles('*');

There's options to handle extraction failure, confirmation of overwrites, etc. It's a pretty nice library to work with, and it's free.

How would I unzip a zip file in node

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.



Related Topics



Leave a reply



Submit