使用zzip和minizip解压缩文件

摘要:
=NULL){delete[](p);(p)=NULL;};voidUnzipAndZip(constchar*pScrFileName,constchar*pDstFileName){structFILE_DESC{unsignedchar*pData;size_tDataSize;};std::map<std::string,FILE_ DESC>mapFileStreams;ZZIP_DIR*pZipDir=ZZIP_opendir(pScrFileName);ZZIP_方向*pZipDirent=空;while(pZipDirent=zzip_readdir(pZipDir)){size_tlength=strlen(pZipDirector->d_name);if(length>0){if(pZipDirect->d_name[length-1]!='\\'&&pZipDirent->d_name[length-1'!='/'){zzip_FILE*pZipFile=zzipfile_open!
#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;
};

免责声明:文章转载自《使用zzip和minizip解压缩文件》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇Amoeba(变形虫)logicaldoc的外部认证——AD集成下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

随便看看

git使用说明

初次使用请参考百度,google,博客园。1修改文件并提交到github[luwenwei@dev01v~/git/helww/labs]$vimREADME[luwenwei@dev01v~/git/helww/labs]$gitdiffdiff--gita/READMEb/READMEindex39d8172..464c83f100644---a/REA...

【01】如何在XMind中排列自由主题

如何在XMind中安排免费主题。在XMind思维导图软件中,用户可以根据需要添加免费主题。然而,由于自由主题的灵活性,它并不整洁,与需要控制界面有序排列的用户相比,这会造成一定的麻烦。首先选择要组织的所有免费主题,单击,然后在下拉框中选择以安排免费主题。有六种排列方式:左对齐、垂直居中、右对齐、顶部对齐、水平居中和底部对齐。...

Innodb_large_prefix

但是,索引列的总长度不能超过3072字节的限制仍然存在...

jquery跨域请求数据

Jquery跨域请求数据Jquery跨请求数据。事实上,这很容易。请遵循以下步骤:首先,编写js,通过get获取远程数据。请注意,回调参数应添加在链接之后,这意味着将回调函数地址传输到远程页面。',{params},函数cb{alert;alert;},'json');第二:编写处理程序。publicvoidProcessRequest{context.Re...

Corn表达式

CronTriggerCronTrigger通常比SimpleTrigger更有用。如果您需要基于日历的概念,而不是SimpleTrigger完全指定的时间间隔,则重复启动工作的时间表。CronTrigger,您可以指定触发器计划,例如“每周五中午”、“每工作日9:30”,甚至“每周一上午、周三和周五9:00和10:00每五分钟”。即使如此,就像Simple...

PB各对象常用事件

1.触发窗口中事件名称的时间01.在激活窗口之前激活触发器02。单击触发器03.Close触发器04.CloseQuery在窗口被清除或关闭时触发。...