Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

zlib c++ and extracting files

Tags:

c++

c

zlib

I have started to use zlib 1.2.5 and I do not see any routine to extract from a zip file? I read about a minizip application, part of the distribution.

Is that how it is supposed to be done?

like image 802
reza Avatar asked Jan 14 '11 23:01

reza


2 Answers

Yes, it does it well. (But if ever you don't like C code, you should look at 7-zip SDK that have code in C++ and C#.)

  • All the functions to browse and uncompress the files from a zip archive are in unzip.h
  • All the functions to compress and add files to a zip archive are in zip.h

(look at contrib\minizip\unzip.h and contrib\minizip\zip.h)

For example, decompressing: the unzOpen() functions of your zip file returns a unzFile

then use unzGoToFirstFile() and unzGoToNextFile() on this unzFile to browse through all files in the archive.

then you get the file info for each file with unzGetCurrentFileInfo(), namely for its size,

surely you should call unzOpenCurrentFile() at some moment.

and call unzReadCurrentFile() using the size from file info, retrieving the binary content of the archived file.

optionally, there is an opaque structure you can provide so as to use your own i/o function, but obviously, there is a default win32 implementation for file access, so you could even not worry about that.

PS: and dont forget to call unzCloseCurrentFile().

like image 198
Stephane Rolland Avatar answered Sep 22 '22 11:09

Stephane Rolland


From: http://www.zlib.net/zlib_faq.html#faq11 : 11. Can zlib handle .zip archives?

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

There's not a tutorial there but the minizip zip.c source is exactly for IO (so presumably compression and decompression) on zip files using zlib.

And still no tutorial BUT http://www.winimage.com/zLibDll/minizip.html gives more details.

like image 39
Kirt Undercoffer Avatar answered Sep 26 '22 11:09

Kirt Undercoffer