风君子博客
作者:
在
#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_DELETEARRAYp) ifp != 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 = strlenpZipDirent->d_name); if length > 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, sizeofsz) ); 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, 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 mainint argc, char* argv[]) { UnzipAndZip "test.zip", "dst.zip" ); return 0; };
您的邮箱地址不会被公开。 必填项已用 * 标注
评论 *
显示名称 *
邮箱 *
网站
Δ
人工智能 保险 保障 信用卡 信贷 华为 多久 手机 投资理财 支付宝 教程 方法 有哪些 流量 理财知识 电脑 知名企业 股票 苹果 贷款 路由器 银行 银行卡 额度
发表回复