Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save KartikShrivastava/0675a81bbb4920bd8ac239b6bbe1f015 to your computer and use it in GitHub Desktop.
Save KartikShrivastava/0675a81bbb4920bd8ac239b6bbe1f015 to your computer and use it in GitHub Desktop.
std::unique_ptr<char[]> Decoder::decompress(size_t &length, size_t off) {
std::unique_ptr<char[]> src = read(length, off);
z_stream zs = {}; // zero-initialize
// using inflateInit2 with windowBits(2nd argument) set to MAX_WBITS | 32, triggers header detection to properly
// decompress both zlib and gzip streams
if (inflateInit2(&zs, MAX_WBITS | 32) != Z_OK) {
errStream << "Failed to initialize zlib inflate" << std::endl;
return nullptr;
}
// code truncated ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment