Use zzip and minizip to Extract files

Source: Internet
Author: User

# 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 ("", " "); return 0 ;};

Use zzip and minizip to Extract files

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.