C ++ Decompressing a gzip array from bytes

Here's the full situation: I'm working on a card reader for .tmx files, from a tiled one. In most cases, tiles are stored in the base64 string, which contains an array of bytes compressed by gzip . Right now I can read an array of compressed bytes, but I have no idea how to unpack it. I read several docs about zlib and boost , but both were related to file streams and very complex ...

I am very new to data compression, so if someone knows a peculiar solution or some useful documentation, I would really welcome.

+4
source share
1 answer
 #include <fstream> #include <iostream> #include <boost/iostreams/filtering_streambuf.hpp> #include <boost/iostreams/copy.hpp> #include <boost/iostreams/filter/gzip.hpp> int main() { using namespace std; ifstream file("hello.gz", ios_base::in | ios_base::binary); filtering_streambuf<input> in; in.push(gzip_decompressor()); in.push(file); boost::iostreams::copy(in, cout); } 

I am not sure what is difficult or difficult when looking at the above example, taken from http://www.boost.org/doc/libs/1_36_0/libs/iostreams/doc/classes/gzip.html . Decompression is very simple. Before unpacking, make sure you decode base64. ( How can I encode base64 (decode) in C? Should help you)

+6
source

All Articles