#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( 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, 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, 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;
};

最新文章

  1. jersy服务,将图片发送另个服务器,再将异步返回
  2. [后端人员耍前端系列]KnockoutJs篇:快速掌握KnockoutJs
  3. jquery过滤器
  4. iptable
  5. Php最近1个月总结
  6. 安装 SQL Server 2005 的硬件和软件要求(官方全面)
  7. pkgmgmt: Comparison between different Linux Systems..
  8. html input密码显示为“*”
  9. c++ Lambda函数学习
  10. Android隐藏软键盘
  11. 一分钟学会ConstraintLayout(转载)
  12. C#微信扫码支付Demo
  13. Markdown 表格
  14. YII2.0使用ActiveForm表单(转)
  15. JAVAWEB 一一 Sturts2+ibatis(框架,Sturts2,用action代替servlet)
  16. mysql rand
  17. python 信号量,Event, 定时器
  18. lua字符串类型
  19. 再谈应用环境下的TIME_WAIT和CLOSE_WAIT
  20. Linux中断 - GIC代码分析

热门文章

  1. 一起talk C栗子吧(第十二回:C语言实例--单链表一)
  2. SilkTest Q&amp;A 2
  3. 《Head First 设计模式》学习笔记——模板方法模式
  4. 进一步解 apt-get 的几个命令
  5. Inside Qt Series (全集)
  6. cocos2d-x 类大全及其概要
  7. JQuery插件datatables相关api
  8. 首次启动优美新手指引tip
  9. 【HDU】4888 Redraw Beautiful Drawings 网络流【推断解是否唯一】
  10. Android四个多线程分析:MessageQueue实现