4 #include <libdeflate.h> 13 std::unique_ptr<struct libdeflate_compressor, void (*)(struct libdeflate_compressor*)> c = {libdeflate_alloc_compressor(compression_level),
14 &libdeflate_free_compressor};
19 out.resize(body.size());
21 const auto actual_compressed_size = [&]() {
24 return libdeflate_deflate_compress(c.get(), body.data(), body.size(), out.data(),
25 libdeflate_deflate_compress_bound(c.get(), body.size()));
27 return libdeflate_zlib_compress(c.get(), body.data(), body.size(), out.data(), libdeflate_zlib_compress_bound(c.get(), body.size()));
29 return libdeflate_gzip_compress(c.get(), body.data(), body.size(), out.data(), libdeflate_gzip_compress_bound(c.get(), body.size()));
33 if (actual_compressed_size == 0)
36 out.resize(actual_compressed_size);
37 body = std::move(out);
#define UNREACHABLE
Definition: utility.hpp:19
constexpr auto compression_level
Definition: libdeflate.hpp:8
Mode
Definition: libdeflate.hpp:10
Definition: libdeflate.hpp:6
bool compress(std::string &body, Mode mode) noexcept
Definition: libdeflate.hpp:12