0

I tried to unzip a zip file with boost zlib, but it doesn't work ,my boost version is 1.75 which is binary which is have been built,I tried the code below with 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);
   }
}

the exception was zlib error: iostream stream error,any idea what wrong I have done? thank you so much

Ken
  • 47
  • 6
  • 1
    The [zip](https://en.wikipedia.org/wiki/ZIP_(file_format)) file format is not supported by boost. You could use it to unzip the files in the `.zip` file, but I found it was just as simple to use the zlib library directly. If your question was *how to unzip one file from a zip*, I could answer that. [Here](https://github.com/lakeweb/dmarc_client) is an example of what I did. – lakeweb Mar 30 '21 at 15:30
  • @lakeweb thanks for your time, I got it – Ken Mar 30 '21 at 23:55

1 Answers1

0

zlib does not process zip files. zlib can process zlib, gzip, and raw deflate streams.

Mark Adler
  • 101,978
  • 13
  • 118
  • 158