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

Function zlib_uncompress

src/SBTL/SVDSurfaceSerializer.cpp:441–466  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

439}
440
441std::vector<char> zlib_uncompress(const std::vector<char>& compressed) {
442 // Mirrors TabularBackends.cpp:52-69: start at 5x the compressed
443 // size, double on Z_BUF_ERROR until it fits or we exhaust patience.
444 std::vector<char> out(compressed.size() * 5);
445 auto out_size = static_cast<mz_ulong>(out.size());
446 auto in_size = static_cast<mz_ulong>(compressed.size());
447 int code = 0;
448 int retries = 0;
449 do {
450 // NOLINTBEGIN(cppcoreguidelines-pro-type-reinterpret-cast) — zlib C API takes unsigned char* (pre-existing glue).
451 code =
452 uncompress(reinterpret_cast<unsigned char*>(out.data()), &out_size, reinterpret_cast<const unsigned char*>(compressed.data()), in_size);
453 // NOLINTEND(cppcoreguidelines-pro-type-reinterpret-cast)
454 if (code == Z_BUF_ERROR) {
455 if (++retries > 8) {
456 throw std::runtime_error("SVDSurfaceSerializer: zlib uncompress would not fit after 8 retries");
457 }
458 out.resize(out.size() * 2);
459 out_size = static_cast<mz_ulong>(out.size());
460 } else if (code != Z_OK) {
461 throw std::runtime_error(std::string("SVDSurfaceSerializer: zlib uncompress failed (code ") + std::to_string(code) + ")");
462 }
463 } while (code != Z_OK);
464 out.resize(out_size);
465 return out;
466}
467
468} // namespace
469

Callers 1

loadMethod · 0.85

Calls 4

uncompressFunction · 0.85
stringClass · 0.50
sizeMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected