Poco::Zip compress/decompress

我与影子孤独终老i 提交于 2020-01-25 08:00:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!