| 66 | } |
| 67 | |
| 68 | bool gunzip( |
| 69 | const std::span<const std::byte>& data, |
| 70 | std::vector<std::byte>& out) { |
| 71 | int ret; |
| 72 | unsigned int index = 0; |
| 73 | zng_stream strm; |
| 74 | std::memset(&strm, 0, sizeof(strm)); |
| 75 | |
| 76 | ret = zng_inflateInit2(&strm, 16 + MAX_WBITS); |
| 77 | if (ret != Z_OK) { |
| 78 | return false; |
| 79 | } |
| 80 | |
| 81 | strm.avail_in = static_cast<uInt>(data.size()); |
| 82 | strm.next_in = reinterpret_cast<const Bytef*>(data.data()); |
| 83 | |
| 84 | do { |
| 85 | out.resize(index + ChunkSize); |
| 86 | strm.next_out = reinterpret_cast<Bytef*>(&out[index]); |
| 87 | strm.avail_out = ChunkSize; |
| 88 | ret = zng_inflate(&strm, Z_NO_FLUSH); |
| 89 | CESIUM_ASSERT(ret != Z_STREAM_ERROR); |
| 90 | switch (ret) { |
| 91 | case Z_NEED_DICT: |
| 92 | case Z_DATA_ERROR: |
| 93 | case Z_BUF_ERROR: |
| 94 | case Z_MEM_ERROR: |
| 95 | zng_inflateEnd(&strm); |
| 96 | return false; |
| 97 | } |
| 98 | index += ChunkSize - strm.avail_out; |
| 99 | } while (ret != Z_STREAM_END); |
| 100 | |
| 101 | zng_inflateEnd(&strm); |
| 102 | out.resize(index); |
| 103 | return true; |
| 104 | } |
| 105 | |
| 106 | } // namespace CesiumUtility |
no test coverage detected