1 #ifdef CROW_ENABLE_COMPRESSION
22 inline std::string compress_string(std::string
const& str, algorithm algo)
24 std::string compressed_str;
27 if (::deflateInit2(&stream, Z_DEFAULT_COMPRESSION, Z_DEFLATED, algo, 8, Z_DEFAULT_STRATEGY) == Z_OK)
31 stream.avail_in = str.size();
33 stream.next_in =
const_cast<Bytef*
>(
reinterpret_cast<const Bytef*
>(str.c_str()));
38 stream.avail_out =
sizeof(buffer);
39 stream.next_out =
reinterpret_cast<Bytef*
>(&buffer[0]);
41 code = ::deflate(&stream, Z_FINISH);
43 if (code == Z_OK || code == Z_STREAM_END)
45 std::copy(&buffer[0], &buffer[
sizeof(buffer) - stream.avail_out], std::back_inserter(compressed_str));
48 }
while (code == Z_OK);
50 if (code != Z_STREAM_END)
51 compressed_str.clear();
53 ::deflateEnd(&stream);
56 return compressed_str;
59 inline std::string decompress_string(std::string
const& deflated_string)
61 std::string inflated_string;
65 zstream.avail_in = deflated_string.size();
67 zstream.next_in =
const_cast<Bytef*
>(
reinterpret_cast<Bytef const*
>(deflated_string.c_str()));
69 if (::inflateInit2(&zstream, MAX_WBITS | 32) == Z_OK)
73 zstream.avail_out =
sizeof(tmp);
74 zstream.next_out = &tmp[0];
76 auto ret = ::inflate(&zstream, Z_NO_FLUSH);
77 if (ret == Z_OK || ret == Z_STREAM_END)
79 std::copy(&tmp[0], &tmp[
sizeof(tmp) - zstream.avail_out], std::back_inserter(inflated_string));
84 inflated_string.clear();
88 }
while (zstream.avail_out == 0);
91 ::inflateEnd(&zstream);
94 return inflated_string;
The main namespace of the library. In this namespace is defined the most important classes and functi...