簡體   English   中英

嘗試使用 boost 將 zip 文件解壓縮為 memory,但它不起作用

[英]Tried to decompress a zip file into memory with boost,but it doesn't work

我嘗試使用 boost zlib 解壓縮 zip 文件,但它不起作用,我的 boost 版本是 1.75,這是已構建的二進制文件,我使用 VS 2013 CE 嘗試了以下代碼

 #include<iostream>
 #include<fstream>
 #include<algorithm> 
 #include<iterator>
 #include<sstream>
 #include <boost/iostreams/filtering_streambuf.hpp>
 #include <boost/iostreams/copy.hpp>
 #include <boost/iostreams/filter/zlib.hpp>

 using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
    ifstream src;
    ofstream dst;
    stringstream  ss;

 try
 {
      src.open("d:\\202012303333629003180526491.txt.zip", ios::in | ios::binary);
      dst.open("to.zip", ios::out | ios::binary);

      copy(istreambuf_iterator<char>(src),
        istreambuf_iterator<char>(),
        ostreambuf_iterator<char>(ss));

      cout << ss.str() << endl;


      std::stringstream decompressed;

      boost::iostreams::filtering_streambuf<boost::iostreams::input> in;
      in.push(boost::iostreams::zlib_decompressor());
      in.push(ss);
      boost::iostreams::copy(in, decompressed);
      string decompressestr = decompressed.str();

      src.close();
      dst.close();
      return 0;
  }
  catch (const std::exception& error)
  {
      std::cerr << error.what() << std::endl;
      return (EXIT_FAILURE);
   }
}

例外是 zlib 錯誤:iostream stream 錯誤,知道我做錯了什么嗎? 太感謝了

zlib 不處理 zip 文件。 zlib 可以處理 zlib、gzip 和原始 deflate 流。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM