Extracting files using Zzip and Minizip

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 comm Ent (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 (length > 0) {if (pzipdirent->d_name[length-1]! = '//' && Pzipdirent->d_name[leng TH-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 Zipfileinfo; ZipFile 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, N ULL, 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;};

Extracting files using Zzip and Minizip

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: info-contact@alibabacloud.com 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.