问题
After successfully compress/decompress using Poco::Zip, I found that I cannot decompress the .zip file which I zip it with my Compress method and vice-versa. But I can decompress my zip file with other tools like 7z or WinRAR and of course, if I compress the zip file using WinRAR or 7z, I can decompress the zip file using my decompress method. I don't know what's wrong here?
Here is my compress method:
void ZipFile(string source, string target){
Poco::File aFile(source);
if (aFile.exists())
{
if (aFile.isDirectory())
{
Poco::Path sourceDir(source);
sourceDir.makeDirectory();
c.addRecursive(sourceDir, Poco::Zip::ZipCommon::CompressionMethod::CM_DEFLATE,
Poco::Zip::ZipCommon::CL_NORMAL, false);
}
else if (aFile.isFile())
{
Poco::Path p(aFile.path());
c.addFile(p, p.getFileName(), Poco::Zip::ZipCommon::CompressionMethod::CM_AUTO,
Poco::Zip::ZipCommon::CL_NORMAL);
}
}
}
And my decompress method :
void UnZipFile(string source, string target)
{
_log.StartMethod("UnZipFile");
std::ifstream inp("C:/Users/Emotive/Desktop/a.zip", std::ios::binary);
Poco::Path targetDir(target);
Poco::Zip::Decompress dec(inp, targetDir, true, true);
// if an error happens invoke the ZipTest::onDecompressError method
//dec.EError += Poco::Delegate<ZipTest, std::pair<const Poco::Zip::ZipLocalFileHeader, const std::string> >(this, &ZipTest::onDecompressError);
dec.decompressAllFiles();
//dec.EError -= Poco::Delegate<ZipTest, std::pair<const Poco::Zip::ZipLocalFileHeader, const std::string> >(this, &ZipTest::onDecompressError)
inp.close();
}
来源:https://stackoverflow.com/questions/59560438/pocozip-compress-decompress