电商设备网站怎么做,公司邮箱一般用哪个,北京公司电话大全黄页,天津站内关键词优化zlib库可在git上自己clone下来然后使用cmake工具生成解决方案#xff0c;编译、生成zlib二进制文件。然后将zlib库引入项目#xff1a;
//zlib库支持
#include ../zlib/include/zlib.h
#ifdef _DEBUG
#pragma comment(lib, ../zlib/lib/zlibd.lib)
…zlib库可在git上自己clone下来然后使用cmake工具生成解决方案编译、生成zlib二进制文件。然后将zlib库引入项目
//zlib库支持
#include ../zlib/include/zlib.h
#ifdef _DEBUG
#pragma comment(lib, ../zlib/lib/zlibd.lib)
#else
#pragma comment(lib, ../zlib/lib/zlib.lib)
#endif定义一个文件结构
typedef struct tagZipperFileInfo
{char m_szLocalPath[MAX_PATH];char m_szRootPath[MAX_PATH];char m_szFileName[MAX_PATH];size_t m_FileSize;
}ZipperFileInfo;压缩文件相关
/*
* strFolder 需要被压缩的文件夹
* strOut 保存的文件
*/
void CompressFolder(std::string strFolder, std::string strOut)
{//创建压缩的目标文件std::ofstream dest(strOut, std::ios::binary | std::ios::trunc);if (!dest.is_open()) {//errorreturn;}dest.close();std::vectorZipperFileInfo vecZipperFiles;//遍历文件夹下的所有文件OperateFolder(strFolder, strFolder, vecZipperFiles);//压缩文件gzFile gzOut gzopen(strOut.c_str(), wb);CompressFiles(vecZipperFiles, gzOut);gzclose(gzOut);
}void OperateFolder(std::string strFolder, std::string strRoot, std::vectorZipperFileInfo vecZipperFiles)
{std::string searchPath strFolder \\*;WIN32_FIND_DATAA findData;HANDLE hFind FindFirstFileA(searchPath.c_str(), findData);if (hFind INVALID_HANDLE_VALUE) {//errorreturn;}do {if (findData.dwFileAttributes FILE_ATTRIBUTE_DIRECTORY) {if (strcmp(findData.cFileName, .) ! 0 strcmp(findData.cFileName, ..) ! 0) {std::string subFolderPath strFolder \\ findData.cFileName;OperateFolder(subFolderPath, strRoot, vecZipperFiles);}}else {std::string strLocalPath strFolder \\ findData.cFileName;std::string strFileRootPath strFolder;std::string strFileName findData.cFileName;//需要根据strRoot分割出来需要压缩文件的相对路径名std::string strTempPath;size_t start strFileRootPath.find(strRoot);if (start std::string::npos)strTempPath strFileRootPath; // 如果找不到根路径则返回完整路径else{if (strFileRootPath strRoot)strTempPath strFileRootPath.substr(start strRoot.length());elsestrTempPath strFileRootPath.substr(start strRoot.length() 1);}ZipperFileInfo zipperFile;memcpy(zipperFile.m_szRootPath, strTempPath.c_str(), MAX_PATH);memcpy(zipperFile.m_szLocalPath, strLocalPath.c_str(), MAX_PATH);memcpy(zipperFile.m_szFileName, strFileName.c_str(), MAX_PATH);//计算文件大小std::ifstream in(strLocalPath, std::ios::binary | std::ios::ate);size_t fileSize in.tellg();in.seekg(0);in.close();zipperFile.m_FileSize fileSize;vecZipperFiles.push_back(zipperFile);}} while (FindNextFileA(hFind, findData) ! 0);FindClose(hFind);
}压缩文件
void CompressFiles(std::vectorZipperFileInfo vecZipperFiles, gzFile gzOut)
{int nFileCount vecZipperFiles.size();gzwrite(gzOut, reinterpret_castconst void*(nFileCount), 4);gzwrite(gzOut, reinterpret_castconst void*(vecZipperFiles.data()), vecZipperFiles.size() * sizeof(ZipperFileInfo));//再往压缩文件中写入需要压缩为文件内容for (int i 0; i vecZipperFiles.size(); i){std::string strLocalPath vecZipperFiles[i].m_szLocalPath;std::ifstream infile(strLocalPath, std::ios::binary);char buffer[4096];while (infile){infile.read(buffer, sizeof(buffer));auto bytes infile.gcount();if (bytes 0){//写入目标压缩文件gzwrite(gzOut, buffer, bytes);}}infile.close();}
}文件解压相关
//strFilePath 压缩文件路径
void DecompressFiles(std::string strFilePath)
{gzFile gzin gzopen(strFilePath.c_str(), rb);if (!gzin) return; //open errorint nFileCount 0;gzread(gzin, nFileCount, 4); //读取压缩的文件数量// 读取文件列表信息std::vectorZipperFileInfo vecZipperFiles;ZipperFileInfo zipperFile;for (int i 0; i nFileCount; i){if (gzread(gzin, zipperFile, sizeof(ZipperFileInfo)) sizeof(ZipperFileInfo))vecZipperFiles.push_back(zipperFile);}SStringW sstrAppPath CGlobalUnits::GetInstance()-m_sstrAppPath;std::string strAppPath S_CW2A(sstrAppPath);//先创建个输出目录size_t szPos strFilePath.find_last_of(\\);if (szPos ! std::string::npos){std::string strTmp strFilePath.substr(szPos 1);//分解出namesize_t szName strTmp.find_last_of(.);if (szName ! std::string::npos){std::string strName strTmp.substr(0, szName);strAppPath strName;}}CreateDirectoryA(strAppPath.c_str(), NULL);//解压文件for (int i 0; i vecZipperFiles.size(); i){ZipperFileInfo info vecZipperFiles[i];std::string strRoot info.m_szRootPath;std::string strPath;if (strRoot ) //根目录下strPath strAppPath \\ info.m_szFileName;else{CreateFolder(strAppPath, strRoot);strPath strAppPath \\ strRoot \\ info.m_szFileName;}std::ofstream outFile(strPath, std::ios::binary);if (!outFile) continue; //error char buffer[4096];size_t fileSize info.m_FileSize;while (fileSize 0){size_t bytesToRead std::min(static_castsize_t(4096), fileSize);int bytesRead gzread(gzin, buffer, bytesToRead);if (bytesRead 0) break; //read erroroutFile.write(buffer, bytesRead);fileSize - bytesRead;}outFile.close();}gzclose(gzin);
}递归生成压缩文件中的目录结构
/*
* strRoot 解压缩的目标目录
* strDir 压缩文件的相对路径
*/
void CreateFolder(std::string strRoot, std::string strDir)
{size_t szPos strDir.find_first_of(\\);if (szPos ! std::string::npos){std::string strName strDir.substr(0, szPos);std::string strPath strRoot \\ strName;CreateDirectoryA(strPath.c_str(), NULL);std::string strSubName strDir.substr(szPos 1);std::string strTempRoot strRoot \\ strName;CreateFolder(strTempRoot, strSubName);}else{std::string strPath strRoot \\ strDir;CreateDirectoryA(strPath.c_str(), NULL);}
}
文章转载自: http://www.morning.wmcng.cn.gov.cn.wmcng.cn http://www.morning.kyytt.cn.gov.cn.kyytt.cn http://www.morning.jnvivi.com.gov.cn.jnvivi.com http://www.morning.mxhgy.cn.gov.cn.mxhgy.cn http://www.morning.mbnhr.cn.gov.cn.mbnhr.cn http://www.morning.mqbzk.cn.gov.cn.mqbzk.cn http://www.morning.xqbgm.cn.gov.cn.xqbgm.cn http://www.morning.zmlbq.cn.gov.cn.zmlbq.cn http://www.morning.mcbqq.cn.gov.cn.mcbqq.cn http://www.morning.pzcqz.cn.gov.cn.pzcqz.cn http://www.morning.tlfyb.cn.gov.cn.tlfyb.cn http://www.morning.jphxt.cn.gov.cn.jphxt.cn http://www.morning.dgfpp.cn.gov.cn.dgfpp.cn http://www.morning.jyknk.cn.gov.cn.jyknk.cn http://www.morning.lpzqd.cn.gov.cn.lpzqd.cn http://www.morning.rythy.cn.gov.cn.rythy.cn http://www.morning.litao4.cn.gov.cn.litao4.cn http://www.morning.pwbps.cn.gov.cn.pwbps.cn http://www.morning.lwrks.cn.gov.cn.lwrks.cn http://www.morning.yfffg.cn.gov.cn.yfffg.cn http://www.morning.ptmsk.cn.gov.cn.ptmsk.cn http://www.morning.ptysj.cn.gov.cn.ptysj.cn http://www.morning.hrqfl.cn.gov.cn.hrqfl.cn http://www.morning.weiwt.com.gov.cn.weiwt.com http://www.morning.ggrzk.cn.gov.cn.ggrzk.cn http://www.morning.xcyzy.cn.gov.cn.xcyzy.cn http://www.morning.rpljf.cn.gov.cn.rpljf.cn http://www.morning.qphcq.cn.gov.cn.qphcq.cn http://www.morning.thnpj.cn.gov.cn.thnpj.cn http://www.morning.sjjq.cn.gov.cn.sjjq.cn http://www.morning.txjrc.cn.gov.cn.txjrc.cn http://www.morning.nzdks.cn.gov.cn.nzdks.cn http://www.morning.xxknq.cn.gov.cn.xxknq.cn http://www.morning.bynf.cn.gov.cn.bynf.cn http://www.morning.qpzjh.cn.gov.cn.qpzjh.cn http://www.morning.dkfrd.cn.gov.cn.dkfrd.cn http://www.morning.fnpmf.cn.gov.cn.fnpmf.cn http://www.morning.yesidu.com.gov.cn.yesidu.com http://www.morning.zcfmb.cn.gov.cn.zcfmb.cn http://www.morning.crtgd.cn.gov.cn.crtgd.cn http://www.morning.iknty.cn.gov.cn.iknty.cn http://www.morning.jzlfq.cn.gov.cn.jzlfq.cn http://www.morning.mbmtn.cn.gov.cn.mbmtn.cn http://www.morning.hqllx.cn.gov.cn.hqllx.cn http://www.morning.bmgdl.cn.gov.cn.bmgdl.cn http://www.morning.rbkgp.cn.gov.cn.rbkgp.cn http://www.morning.fkgqn.cn.gov.cn.fkgqn.cn http://www.morning.bmgdl.cn.gov.cn.bmgdl.cn http://www.morning.ykwbx.cn.gov.cn.ykwbx.cn http://www.morning.qqnjr.cn.gov.cn.qqnjr.cn http://www.morning.yslfn.cn.gov.cn.yslfn.cn http://www.morning.pswqx.cn.gov.cn.pswqx.cn http://www.morning.kxsnp.cn.gov.cn.kxsnp.cn http://www.morning.paoers.com.gov.cn.paoers.com http://www.morning.sxlrg.cn.gov.cn.sxlrg.cn http://www.morning.ruyuaixuexi.com.gov.cn.ruyuaixuexi.com http://www.morning.hybmz.cn.gov.cn.hybmz.cn http://www.morning.frsbf.cn.gov.cn.frsbf.cn http://www.morning.yhjrc.cn.gov.cn.yhjrc.cn http://www.morning.hpnhl.cn.gov.cn.hpnhl.cn http://www.morning.ydrfl.cn.gov.cn.ydrfl.cn http://www.morning.msbpb.cn.gov.cn.msbpb.cn http://www.morning.pbtdr.cn.gov.cn.pbtdr.cn http://www.morning.wpjst.cn.gov.cn.wpjst.cn http://www.morning.nhdw.cn.gov.cn.nhdw.cn http://www.morning.ypzsk.cn.gov.cn.ypzsk.cn http://www.morning.cszbj.cn.gov.cn.cszbj.cn http://www.morning.jgnjl.cn.gov.cn.jgnjl.cn http://www.morning.rpstb.cn.gov.cn.rpstb.cn http://www.morning.cwyrp.cn.gov.cn.cwyrp.cn http://www.morning.spqbp.cn.gov.cn.spqbp.cn http://www.morning.xpmhs.cn.gov.cn.xpmhs.cn http://www.morning.lgcqj.cn.gov.cn.lgcqj.cn http://www.morning.gqmhq.cn.gov.cn.gqmhq.cn http://www.morning.mlmwl.cn.gov.cn.mlmwl.cn http://www.morning.gchqy.cn.gov.cn.gchqy.cn http://www.morning.21r000.cn.gov.cn.21r000.cn http://www.morning.ndmbd.cn.gov.cn.ndmbd.cn http://www.morning.gwqcr.cn.gov.cn.gwqcr.cn http://www.morning.kfyjh.cn.gov.cn.kfyjh.cn