lua 解压缩文件zlib
来源:互联网 发布:c007电话软件下载 编辑:程序博客网 时间:2024/06/04 19:13
bool ZipUtils::uncompressDir(char* filename, char* destPath){ if (filename == NULL || destPath == NULL) { CCLOG("source zip is null or dest path is null!"); return false; } // Open the zip file std::string outFileName = filename; unzFile zipfile = unzOpen(outFileName.c_str()); if (!zipfile) { CCLOG("can not open downloaded zip file %s", outFileName.c_str()); return false; } // Get info about the zip file unz_global_info global_info; if (unzGetGlobalInfo(zipfile, &global_info) != UNZ_OK) { CCLOG("can not read file global info of %s", outFileName.c_str()); unzClose(zipfile); return false; } const int BUFFER_SIZE = 8192; const int MAX_FILENAME = 512; // Buffer to hold data read from the zip file char readBuffer[BUFFER_SIZE]; CCLOG("start uncompressing"); // Loop to extract all files. uLong i; for (i = 0; i < global_info.number_entry; ++i) { // Get info about current file. unz_file_info fileInfo; char fileName[MAX_FILENAME]; if (unzGetCurrentFileInfo(zipfile, &fileInfo, fileName, MAX_FILENAME, NULL, 0, NULL, 0) != UNZ_OK) { CCLOG("can not read file info"); unzClose(zipfile); return false; } std::string storagePath = destPath; std::string fullPath = storagePath + fileName; // Check if this entry is a directory or a file. const size_t filenameLength = strlen(fileName); if (fileName[filenameLength - 1] == '/') { // get all dir std::string fileNameStr = std::string(fileName); size_t position = 0; while ((position = fileNameStr.find_first_of("/", position)) != std::string::npos) { std::string dirPath = storagePath + fileNameStr.substr(0, position); // Entry is a direcotry, so create it. // If the directory exists, it will failed scilently. if (!createDirectory(dirPath.c_str())) { CCLOG("can not create directory %s", dirPath.c_str()); //unzClose(zipfile); //return false; } position++; } } else { // Entry is a file, so extract it. // Open current file. if (unzOpenCurrentFile(zipfile) != UNZ_OK) { CCLOG("can not open file %s", fileName); unzClose(zipfile); return false; } // Create a file to store current file. FILE *out = fopen(fullPath.c_str(), "wb"); if (!out) { CCLOG("can not open destination file %s", fullPath.c_str()); unzCloseCurrentFile(zipfile); unzClose(zipfile); return false; } // Write current file content to destinate file. int error = UNZ_OK; do { error = unzReadCurrentFile(zipfile, readBuffer, BUFFER_SIZE); if (error < 0) { CCLOG("can not read zip file %s, error code is %d", fileName, error); unzCloseCurrentFile(zipfile); unzClose(zipfile); return false; } if (error > 0) { fwrite(readBuffer, error, 1, out); } } while (error > 0); fclose(out); } unzCloseCurrentFile(zipfile); // Goto next entry listed in the zip file. if ((i + 1) < global_info.number_entry) { if (unzGoToNextFile(zipfile) != UNZ_OK) { CCLOG("can not read next file"); unzClose(zipfile); return false; } } } unzClose(zipfile); CCLOG("end uncompressing"); return true;}
方法是导出ZipUtils,在ZipUtils里面添加uncompressDir的方法给lua用
0 0
- lua 解压缩文件zlib
- zlib压缩解压缩文件
- 使用zlib压缩解压缩文件
- java压缩,解压缩zlib文件
- 使用ZLib 压缩/解压缩 zip文件
- 心得 ~ 使用 zlib库 解压缩 zip文件
- Qt调用zlib库文件解压缩zip文件
- 使用zlib压缩解压缩文件的详细过程
- 使用zlib压缩解压缩文件的详细过程
- 采用ZLIB及MINIZIP进行文件解压缩及加解密
- 采用ZLIB及MINIZIP进行文件解压缩及加解密
- Zlib库的使用实现对zip文件的解压缩
- 使用PHP自带zlib函数 文件压缩解压缩
- java实现zlib压缩解压缩:文件、byte[]字节数组,数据流
- Zlib解压缩示例
- android ZLib压缩/解压缩
- Android实现zlib解压缩
- ZLib 解压缩工具
- 利用Java生成静态HMTL页面
- Vasya and Chess - CodeForces 493 D 博弈
- 天天ASP开发网完成中国仡佬族文化研究会网站建设
- distribute-list分发列表
- test13
- lua 解压缩文件zlib
- 计算机图形学方向投稿国外期刊
- 在Eclipse中安装和使用TFS插件
- Activity布局
- test14
- 理解Ceph RBD块设备
- SQL函数DATEADD可以在数据库中控制时间的加减
- codeforces training8
- test15