boost: Uncompress http response using gzip failed

535 Views Asked by At

I'm trying to uncompress http body response using boost gzip filters. I'm using the standard code example provided everywhere:

std::string source = "c:\\install\\data.gz";
std::string destination = "c:\\install\\data.txt";

using namespace std;
using namespace boost::iostreams;

ifstream file(source, ios_base::in | ios_base::binary);
filtering_streambuf<input> in;
in.push(gzip_decompressor());
in.push(file);
ofstream unzipped(destination, std::ios::out | std::ios::binary);
boost::iostreams::copy(in, unzipped);

In this scenario, I saved content of the page into source file before. The problem is that this code doesn't work with some sites using gzip-encoding (for example, http://mail.ru - the biggest russian portal). Other sites, for example, http://bing.com is uncompressed perfectly.

I wrote small code to test saved data using GZipStream. It work fine even with mail.ru:

String source = @"c:\install\data.gz";
String destination = @"c:\install\data.txt";

using (FileStream inFile = new FileStream(source, FileMode.Open))
{
    using (FileStream outFile = File.Create(destination))
    {
        using (GZipStream Decompress = new GZipStream(inFile, CompressionMode.Decompress))
        {
            Decompress.CopyTo(outFile);
        }
    }
}

Can anybody explain what's wrong with me, mail.ru or gzip?

0

There are 0 best solutions below