VC下minizip+ZLib 解压文件
来源:互联网 发布:飞控编程用什么语言 编辑:程序博客网 时间:2024/06/06 01:18
一、zlib开源库
zlib是应用最广泛的压缩与解压缩zip文件的免费开源库,提供了数据压缩与解压缩的函式库。
zlib中最关键的函数有以下两个:
(1)int compress(Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen);
(2)int uncompress(Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen);
其中,函数compress()用于将源缓冲区数据压缩到目的缓冲区,函数uncompress()用于将源缓冲区数据解压到目的缓冲区。
从这里可以看出zlib不能单独完成解压文件的操作,所以要结合minizip的API函数来解压。二、minizip
minizip是zlib的上层库,它封装了与zip文件相关的操作。
其中解压的API函数说明:
(1)unzFile unzOpen(const char *path); //打开zip文件
(2)int unzClose(unzFile file);//关闭zip文件
(3)int unzGetGlobalInfo(unzFile file, unz_global_info *pglobal_info);//获取zip压缩文件的信息
(4)int unzGoToNextFile(unzFile file);//获取下一个文件
(5)int unzGetCurrentFileInfo(unzFile file, unz_file_info *pfile_info, char *szFileName, uLong fileNameBufferSize, void *extraField, uLong extraFieldBufferSize, char *szComment, uLong commentBufferSize); //获取文件的信息
(6)int unzOpenCurrentFile(unzFile file); //打开当前文件
(7)int unzCloseCurrentFile(unzFile file); //关闭当前文件
(8)int unzReadCurrentFile(unzFile file, voidp buf, unsigned len);//读当前文件
三、环境配置
在VC下要加入如下文件:
zlib.h
zlib.lib
unzip.h
unzip.cpp
上述文件均可在网上很容易找到,这里不提供链接了。
四、示例代码
#include <iostream>
#include <string>
#include <windows.h>
#include "unzip.h"
using namespace std;
int main()
{
TCHAR * mUnPackPath = L"Google_usb_driver";
TCHAR * mZipFileFullPath = L"Google_usb_driver.zip";
HZIP hz = OpenZip(mZipFileFullPath,0);
if (hz == 0)
{
//打开Zip文件失败
cout << "打开文件失败" << endl;
return -1;
}
ZRESULT zr = SetUnzipBaseDir(hz,mUnPackPath);
if (zr != ZR_OK)
{
//打开ZIP文件失败
cout << "打开ZIP文件失败" << endl;
CloseZip(hz);
return -1;
}
ZIPENTRY ze;
zr = GetZipItem(hz,-1,&ze);
if (zr != ZR_OK)
{
//获取Zip文件内容失败
cout << "获取文件内容失败" << endl;
CloseZip(hz);
return -1;
}
int numitems = ze.index;
for (int i = 0;i < numitems;i ++)
{
zr = GetZipItem(hz,i,&ze);
zr = UnzipItem(hz,i,ze.name);
if (zr != ZR_OK)
{
cout << "获取Zip文件内容失败" << endl;
CloseZip(hz);
return -1;
}
}
CloseZip(hz);
cout << "解压成功" << endl;
return 0;
}
- VC下minizip+ZLib 解压文件
- zlib minizip 实现解压zip
- zlib, minizip加密,多文件压缩
- 采用ZLIB及MINIZIP进行文件解压缩及加解密
- 采用ZLIB及MINIZIP进行文件解压缩及加解密
- zlib 解压zip文件
- zlib minizip 压缩与解压缩
- Zlib文件压缩和解压
- Zlib文件压缩和解压
- MTK zlib uncompress 解压文件
- C++ zlib 压缩解压文件
- Zlib文件压缩和解压
- Zlib文件压缩和解压
- 使用zlib压缩/解压文件
- Zlib文件压缩和解压
- [VC++]_[初级]_[使用zlib标准库解压zip文件]
- c++使用zlib和minizip压缩文件
- [Zlib]_[初级]_[使用zlib库解压提取文件]
- Android_View,ViewGroup,Window之间的关系
- Andriod通过代码添加图片和音频的方法
- U盘做启动盘后怎样恢复初始容量
- pebble baymax color watchface!
- HTML5 history API,创造更好的浏览体验
- VC下minizip+ZLib 解压文件
- 轻量级的Picture
- spring装配集合
- DWZ(二):常用组件了解
- 兔子--ps中各种工具的作用
- leetcode刷题,总结,记录,备忘 108
- 英文论文中“such as, for example, e.g., i.e., etc., et al. ”的用法分析
- springmvc+velocity+ Rest Services(xml,json)实例
- Android自定义控件---继承Linearlayout