14 #ifndef OR_TOOLS_BASE_GZIPSTRING_H_ 15 #define OR_TOOLS_BASE_GZIPSTRING_H_ 30 if (inflateInit2(&zs, 15 + 32) != Z_OK) {
34 zs.next_in = (Bytef*)str.data();
35 zs.avail_in = str.size();
42 zs.next_out = reinterpret_cast<Bytef*>(buffer);
43 zs.avail_out =
sizeof(buffer);
45 status = inflate(&zs, 0);
47 if (out->size() < zs.total_out) {
48 out->append(buffer, zs.total_out - out->size());
50 }
while (status == Z_OK);
54 if (status != Z_STREAM_END) {
55 VLOG(1) <<
"Exception during zlib decompression: (" << status <<
") " 72 if (deflateInit(&zs, Z_BEST_COMPRESSION) != Z_OK) {
73 VLOG(1) <<
"Cannot initialize zlib compression.";
77 zs.next_in = (Bytef*)uncompressed.data();
78 zs.avail_in = uncompressed.size();
85 zs.next_out = reinterpret_cast<Bytef*>(buffer);
86 zs.avail_out =
sizeof(buffer);
88 status = deflate(&zs, Z_FINISH);
93 }
while (status == Z_OK);
97 if (status != Z_STREAM_END) {
98 VLOG(1) <<
"Exception during zlib compression: (" << status <<
") " 103 #endif // OR_TOOLS_BASE_GZIPSTRING_H_ #define VLOG(verboselevel)
bool GunzipString(const std::string &str, std::string *out)
void GzipString(absl::string_view uncompressed, std::string *compressed)