# Include <zzip/zzip. h> # include <zlib. h> # include <zip. h> # include <unzip. h >#include <string >#include <map> # ifdef _ debug # pragma comment (Lib, "zlib_d.lib") # pragma comment (Lib, "zzip_d.lib ") # pragma comment (Lib, "minizip_d.lib") # else # pragma comment (Lib, "zlib. lib ") # pragma comment (Lib," zzip. lib ") # pragma comment (Lib," minizip. lib ") # endif # define safe_deletearray (p) if (P! = NULL) {Delete [] (p); (p) = NULL ;}; void unzipandzip (const char * pscrfilename, const char * pdstfilename) {struct file_desc {unsigned char * pdata; size_t datasize;}; STD: Map <STD: String, file_desc> mapfilestreams; zzip_dir * pzipdir = zzip_opendir (pscrfilename ); zzip_dirent * pzipdirent = NULL; while (pzipdirent = zzip_readdir (pzipdir) {size_t length = strlen (pzipdirent-> d_name); If (Leng Th> 0) {If (pzipdirent-> d_name [length-1]! = '//' & Pzipdirent-> d_name [length-1]! = '/') {Zzip_file * pzipfile = zzip_file_open (pzipdir, pzipdirent-> d_name, zzip_caseless); If (pzipfile! = NULL) {zzip_stat SZ; memset (& SZ, 0, sizeof (sz); zzip_file_stat (pzipfile, & sz); If (SZ. st_size> 0) {unsigned char * pbuffer = new unsigned char [Sz. st_size]; zzip_file_read (pzipfile, pbuffer, Sz. st_size); file_desc DATA = {pbuffer, Sz. st_size}; mapfilestreams [pzipdirent-> d_name] = data;} zzip_file_close (pzipfile) ;}}}if (pzipdir) zzip_closedir (pzipdir); zip_fileinfo zipfilei Nfo; zipfile = zipopen (pdstfilename, 0); STD: Map <STD: String, file_desc >:: iterator iter = mapfilestreams. Begin (); While (ITER! = Mapfilestreams. end () {int err = zipopennewfileinzip (zipfile, ITER-> first. c_str (), & zipfileinfo, null, 0, null, 0, null, 0, 0); zipwriteinfileinzip (zipfile, ITER-> second. pdata, ITER-> second. datasize); safe_deletearray (ITER-> second. pdata); ++ ITER;} zipclose (zipfile, null);} int main (INT argc, char * argv []) {unzipandzip ("test.zip", "dst.zip "); return 0 ;};
Use zzip and minizip to Extract files