我正在使用标题zip.hpp
(可以在这里找到https://markand.bitbucket.io/libzip/index.html或在这里http://hg.markand.fr/libzip/file)来压缩一些文件。
之后要删除原始文件,我使用remove("myfile.txt")
.
显然,zip.hpp
在运行结束时压缩文件,因此它找不到文件并且不创建压缩文件夹。如果我省略remove("myfile.txt")
,一切正常,除了我有几个文件飞来飞去,我只想以压缩形式拥有。
您对如何强制 libzip 编写 zip 文件有任何想法吗?我希望如果我删除archive
-instance,它应该强制创建,但显然libzip::Archive
-class没有析构函数(至少我找不到一个并delete archive
抛出很多错误)
我的基本代码如下所示:
#include <fstream>
#include <zip.h>
#include "lib/zip.hpp"
int main () {
libzip::Archive archive("output.zip", ZIP_CREATE);
std::ofstream outfile ("myfile.txt");
outfile << "Hello World\n";
outfile.close();
archive.add(libzip::source::file("myfile.txt"), "myfile2.txt");
// delete archive; // throws an error...
// remove("myfile.txt");
// if left out, output.zip gets created otherwise nothing is created
return 0;
}