c - How do I use Minizip (on Zlib)? -
i'm trying archive files cross-platform application, , looks minizip (built on zlib) portable archivers come.
when try run following dummy code, however, system error [my executable] has stopped working. windows can check online solution problem.
can me see how use library? — (there's no doc or tutorial anywhere can find)
zip_fileinfo zfi; int main() { zipfile zf = zipopen("myarch.zip",append_status_addinzip); int ret = zipopennewfileinzip(zf, "myfile.txt", &zfi, null, 0, null, 0, "my comment interior file", z_deflated, z_no_compression ); zipclosefileinzip(zf); zipclose(zf, "my comment exterior file"); return 0; }
specs: msys + mingw, windows 7, using zlibwapi.dll zlib125dll.zip/dll32
since found question via google , didn't contain complete, working code, providing here future visitors.
int createzipfile (std::vector<wstring> paths) { zipfile zf = zipopen(std::string(destinationpath.begin(), destinationpath.end()).c_str(), append_status_create); if (zf == null) return 1; bool _return = true; (size_t = 0; < paths.size(); i++) { std::fstream file(paths[i].c_str(), std::ios::binary | std::ios::in); if (file.is_open()) { file.seekg(0, std::ios::end); long size = file.tellg(); file.seekg(0, std::ios::beg); std::vector<char> buffer(size); if (size == 0 || file.read(&buffer[0], size)) { zip_fileinfo zfi = { 0 }; std::wstring filename = paths[i].substr(paths[i].rfind('\\')+1); if (s_ok == zipopennewfileinzip(zf, std::string(filename.begin(), filename.end()).c_str(), &zfi, null, 0, null, 0, null, z_deflated, z_default_compression)) { if (zipwriteinfileinzip(zf, size == 0 ? "" : &buffer[0], size)) _return = false; if (zipclosefileinzip(zf)) _return = false; file.close(); continue; } } file.close(); } _return = false; } if (zipclose(zf, null)) return 3; if (!_return) return 4; return s_ok; }
Comments
Post a Comment