I am trying to unpack an HTTP response using powerful gzip filters. I use 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 case, I previously saved the contents of the page in the source file. The problem is that this code does not work with some sites using gzip-encoding (for example, http://mail.ru - the largest Russian portal). Other sites, such as http://bing.com , are perfectly compressed.
I wrote a little code to verify the stored data using GZipStream. It works great 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 someone explain what is wrong with me, mail.ru or gzip?
source
share