我正在一个需要生成zip文件的项目中。我正在使用minizip库,但是正在生成的zip文件为空。 这是我的功能
int compress(std::vector<std::string> paths, std::string &destination, const std::string& password, int level) {
if (level < CS_NO_COMPRESSION || level > CS_BEST_COMPRESSION)
level = MZ_COMPRESS_LEVEL_DEFAULT;
void *writer = NULL;
int err;
mz_zip_writer_create(&writer);
mz_zip_writer_set_password(writer, password.c_str());
mz_zip_writer_set_compress_level(writer, level);
mz_zip_writer_set_compress_method(writer, MZ_COMPRESS_METHOD_DEFLATE);
err = mz_zip_writer_open_file(writer, destination.c_str(), originalSize, 0);
if (err < 0) {
std::cout << err;
mz_zip_writer_delete(&writer);
return err;
}
if(err == MZ_OK){
for (std::string path : paths)
{
std::string fileName = path.substr(path.rfind('\\'));
err = mz_zip_writer_add_path(writer, path.c_str(), NULL, 1, 1);
if (err < 0)
return err;
}
}
err = mz_zip_writer_close(writer);
mz_zip_writer_delete(&writer);
return err;
}
entry point
:
std::vector<std::string> src;
src.push_back("C:\\dev\CompressStudio\\CMakeFiles.txt");
std::string res = "C:\\dev\\CMakeFiles.zip";
int err = compress(src, res); // Password and level have default vaues as NULL and -1 respectively
std::cin.ignore();
return err;
程序以-111
退出
任何帮助将不胜感激