我正尝试从网络中解压缩zip文件,如图here所示。
它失败并显示以下错误:
Decompress error CRC mismatch. Corrupt file: ...
但是,如果我将服务器响应写到一个临时zip文件并将其解压缩,则效果很好。我在做什么错了?
工作代码:
Poco::URI uri(host_);
HTTPClientSession session(uri.getHost(), uri.getPort());
HTTPRequest req(HTTPRequest::HTTP_GET, "/" + path_, HTTPMessage::HTTP_1_1);
req.setChunkedTransferEncoding(true);
session.sendRequest(req);
HTTPResponse res;
std::istream& rs = session.receiveResponse(res);
{
std::ofstream tmpOs("./tmp.zip");
std::copy(std::istreambuf_iterator<char>(rs), std::istreambuf_iterator<char>(),
std::ostream_iterator<char>(tmpOs));
}
std::ifstream tmp("./tmp.zip");
Decompress dec(tmp, Poco::Path());
dec.EError += Poco::Delegate<SharingServiceDownloader, std::pair<const Poco::Zip::ZipLocalFileHeader, const std::string> >(this, &SharingServiceDownloader::onDecompressError);
dec.decompressAllFiles();
dec.EError -= Poco::Delegate<SharingServiceDownloader, std::pair<const Poco::Zip::ZipLocalFileHeader, const std::string> >(this, &SharingServiceDownloader::onDecompressError);
失败,并显示错误:
Poco::URI uri(host_);
HTTPClientSession session(uri.getHost(), uri.getPort());
HTTPRequest req(HTTPRequest::HTTP_GET, "/" + path_, HTTPMessage::HTTP_1_1);
req.setChunkedTransferEncoding(true);
session.sendRequest(req);
HTTPResponse res;
std::istream& rs = session.receiveResponse(res);
Decompress dec(rs, Poco::Path());
dec.EError += Poco::Delegate<SharingServiceDownloader, std::pair<const Poco::Zip::ZipLocalFileHeader, const std::string> >(this, &SharingServiceDownloader::onDecompressError);
dec.decompressAllFiles();
dec.EError -= Poco::Delegate<SharingServiceDownloader, std::pair<const Poco::Zip::ZipLocalFileHeader, const std::string> >(this, &SharingServiceDownloader::onDecompressError);
我应该注意,我在服务器端使用了分块编码。