| inline bool gzipInflate(const std::string& compressedBytes, |
| std::string& uncompressedBytes) |
| if (compressedBytes.empty()) |
| uncompressedBytes = compressedBytes; |
| uncompressedBytes.clear(); |
| unsigned half_length = compressedBytes.size() / 2; |
| // The following line is nolint because we're declaring away constness. |
| // It's not clear why the input buffers on zlib aren't const, so this is a |
| // bit of a cheat for the moment |
| strm.next_in = (Bytef*)compressedBytes.data(); // NOLINT |
| strm.avail_in = compressedBytes.size(); |
| if (inflateInit2(&strm, (16 + MAX_WBITS)) != Z_OK) |
| // If our output buffer is too small |
| if (strm.total_out >= uncompressedBytes.size()) |
| uncompressedBytes.resize(uncompressedBytes.size() + half_length); |
| (Bytef*)(uncompressedBytes.data() + strm.total_out); // NOLINT |
| ((uLong)uncompressedBytes.size() - strm.total_out); // NOLINT |
| // Inflate another chunk. |
| int err = inflate(&strm, Z_SYNC_FLUSH); |
| return inflateEnd(&strm) == Z_OK; |