MCPcopy Create free account
hub / github.com/CoolProp/CoolProp / zlib_compress

Function zlib_compress

src/SBTL/SVDSurfaceSerializer.cpp:424–439  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

422// ---------- compression / decompression -------------------------------
423
424std::vector<char> zlib_compress(const msgpack::sbuffer& sbuf) {
425 // Match TabularBackends.cpp's allocation strategy: start with the
426 // raw size and let zlib write into that buffer. miniz returns
427 // Z_OK when it fits.
428 std::vector<char> out(sbuf.size() + (sbuf.size() / 1000) + 128);
429 auto out_size = static_cast<mz_ulong>(out.size());
430 // NOLINTBEGIN(cppcoreguidelines-pro-type-reinterpret-cast) — zlib's C API takes unsigned char*; our buffers are char (pre-existing glue).
431 const int code = compress(reinterpret_cast<unsigned char*>(out.data()), &out_size, reinterpret_cast<const unsigned char*>(sbuf.data()),
432 static_cast<mz_ulong>(sbuf.size()));
433 // NOLINTEND(cppcoreguidelines-pro-type-reinterpret-cast)
434 if (code != Z_OK) {
435 throw std::runtime_error(std::string("SVDSurfaceSerializer: zlib compress failed (code ") + std::to_string(code) + ")");
436 }
437 out.resize(out_size);
438 return out;
439}
440
441std::vector<char> zlib_uncompress(const std::vector<char>& compressed) {
442 // Mirrors TabularBackends.cpp:52-69: start at 5x the compressed

Callers 1

saveMethod · 0.85

Calls 4

compressFunction · 0.85
stringClass · 0.50
sizeMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected