UnZip.h/Zip.h C++压缩解压类
2016-12-09 12:36
926 查看
最近刚好用到,个人觉得还是比较好用的:
以下来自网络示例:
Example 1 - create a Zip file from existing files
Example 2 - unzip a Zip file using the names it has inside it
Example 3- unzip from resource directly into memory
This technique is useful for small games, where you want to keep all resources bundled up inside the executable, but restricting the size.
Suppose we used a .rc with 1 RCDATA “file.zip” to embed the Zip file as a resource.
Example 4 - unzip chunk by chunk to a membuffer
Normally when you call UnzipItem(…), it gives the return-code ZR_OK. But if you gave it too small a buffer so that it couldn’t fit it all in, then it returns ZR_MORE.
下载地址:Zip Utils
以下来自网络示例:
Example 1 - create a Zip file from existing files
// We place the file "simple.bmp" inside, but inside // the zipfile it will actually be called "znsimple.bmp". // Similarly the textfile. HZIP hz = CreateZip("simple1.zip",0); ZipAdd(hz,"znsimple.bmp", "simple.bmp"); ZipAdd(hz,"znsimple.txt", "simple.txt"); CloseZip(hz);
Example 2 - unzip a Zip file using the names it has inside it
HZIP hz = OpenZip("\\simple1.zip",0); ZIPENTRY ze; GetZipItem(hz,-1,&ze); int numitems=ze.index; // -1 gives overall information about the zipfile for (int zi=0; zi<numitems; zi++) { ZIPENTRY ze; GetZipItem(hz,zi,&ze); // fetch individual details UnzipItem(hz, zi, ze.name); // e.g. the item's name. } CloseZip(hz);
Example 3- unzip from resource directly into memory
This technique is useful for small games, where you want to keep all resources bundled up inside the executable, but restricting the size.
Suppose we used a .rc with 1 RCDATA “file.zip” to embed the Zip file as a resource.
HRSRC hrsrc = FindResource(hInstance,MAKEINTRESOURCE(1),RT_RCDATA); HANDLE hglob = LoadResource(hInstance,hrsrc); void *zipbuf = LockResource(hglob); unsigned int ziplen = SizeofResource(hInstance,hrsrc); hz = OpenZip(zipbuf, ziplen, 0); ZIPENTRY ze; int i; FindZipItem(hz,"sample.jpg",true,&i,&ze); // that lets us search for an item by filename. // Now we unzip it to a membuffer. char *ibuf = new char[ze.unc_size]; UnzipItem(hz,i, ibuf, ze.unc_size); ... delete[] ibuf; CloseZip(hz); // note: no need to free resources obtained through Find/Load/LockResource
Example 4 - unzip chunk by chunk to a membuffer
Normally when you call UnzipItem(…), it gives the return-code ZR_OK. But if you gave it too small a buffer so that it couldn’t fit it all in, then it returns ZR_MORE.
char buf[1024]; ZRESULT zr=ZR_MORE; unsigned long totsize=0; while (zr==ZR_MORE) { zr = UnzipItem(hz,i, buf,1024); unsigned long bufsize=1024; if (zr==ZR_OK) bufsize=ze.unc_size-totsize; ... maybe write the buffer to a disk file here totsize+=bufsize; }
下载地址:Zip Utils
相关文章推荐
- linux zip/unzip err encoding压缩解压中文文件 乱码
- linux zip/unzip err encoding压缩解压中文文件 乱码
- LinuxStudyNote(29)-Linux常用命令(6)-压缩解压命令汇总gzip、gunzip、tar、zip、unzip、bzip2、bunzip2
- Linux下的压缩(zip)解压(unzip)缩命令
- linux下压缩与解压(zip、unzip、tar)详解
- CentOS安装zip和unzip进行压缩和解压
- linux zip 压缩命令 解压命令 unzip
- gzip,bzip2, xz , zip ,unzip ,解压,压缩;tar打包,解压。
- 在VC开发中使用简单灵巧的压缩/解压工具包LiteZip/LiteUnzip
- linux笔记:压缩解压命令gzip,gunzip,tar,zip,unzip,bzip2,bunzip2
- CentOS7下zip解压和unzip压缩文件
- Linux ZIP/UNZIP打包压缩/解压命令详解
- Linux命令-压缩解压命令:zip、unzip
- linux下压缩与解压(zip、unzip、tar)详解
- centos7使用zip、unzip压缩、解压文件
- linux下压缩与解压(zip、unzip、tar)详解
- zip和unzip压缩解压指令 --排除目录
- linux下压缩与解压(zip、unzip、tar)详解
- Centos中压缩(zip)和解压(unzip)命令
- Centos中压缩(zip)和解压(unzip)命令