【发布时间】:2020-01-16 02:50:54
【问题描述】:
成功压缩文件夹后,我的情况如下:
如果 append = true 和 overWrite = false 我必须检查目标 zip 文件是否存在(如果存在)我将检查现有的 zip 文件它不包含哪些文件并将新文件从源文件夹附加到它.
我的问题是:
- 如何打开 zip 文件并将其放入 compress 对象?或者我应该使用 Poco 中的哪个其他库来打开 zip 流?我正在尝试使用
std::ifstream,但 Poco::zip::Compress 似乎没有收到std::ifstream
我当然必须修改 Poco 源代码本身以符合我的要求。提前致谢。
void ZipFile(string source, string target, List extensions, bool append, bool overWrite)
{
Poco::File tempFile(source);
if (tempFile.exists())
{
if (Poco::File(target).exists() && append && !overWrite) {
fs::path targetPath = fs::path(target);
std::ifstream targetFileStream(targetPath.string(), std::ios::binary);
std::ofstream outStream(target, ios::binary);
CompressEx compress(outStream, false, false);
if (tempFile.isDirectory())
{
Poco::Path sourceDir(source);
sourceDir.makeDirectory();
compress.addRecursive(sourceDir, Poco::Zip::ZipCommon::CompressionMethod::CM_AUTO,
Poco::Zip::ZipCommon::CL_NORMAL, false);
}
else if (tempFile.isFile())
{
Poco::Path path(tempFile.path());
compress.addFile(path, path.getFileName(), Poco::Zip::ZipCommon::CompressionMethod::CM_AUTO,
Poco::Zip::ZipCommon::CL_NORMAL);
}
compress.close(); // MUST be done to finalize the Zip file
outStream.close();
}
}
【问题讨论】:
标签: c++ poco-libraries