I have a personal project where I have to use zlib to decompress some data. I store the binary data into a std::vector where byte_t isn't anything else than unsigned char.
So I modified the zlib decompress function from their site to look like: http://pastebin.com/spXcRyxa
Everything went fine for about 90% of test, but then it crash the application(some bug in addToVector - couldn't find it).
Then I remember that boost have a nice wrapper for zlib. I compiled boost with zlib and searched how to do it with a std::vector (almost all examples were for std::string). But I found an example for bzip(Uncompress data in memory using Boost gzip_decompressor), then I changed some things to make it run;
std::vector<byte_t> unzip(const std::vector<byte_t> compressed)
{
std::vector<byte_t> decompressed = std::vector<byte_t>();
boost::iostreams::filtering_ostream os;
os.push(boost::iostreams::zlib_decompressor());
os.push(std::back_inserter(decompressed));
boost::iostreams::write(os, reinterpret_cast<const char*>(&compressed[0]), compressed.size());
return decompressed;
}
My changes fails to all tests. The decompress data from boost zlib is about 10 000 characters shorter than normal zlib library.
What am I doing wrong in this boost zlib implementation ? Thanks you !