| 131 | static constexpr size_t MYBLOCK = 32786; |
| 132 | |
| 133 | size_t Compression::decompress(const void *data, size_t in, std::vector<char> &uncompressed) { |
| 134 | ai_assert(mImpl != nullptr); |
| 135 | if (data == nullptr || in == 0) { |
| 136 | return 0l; |
| 137 | } |
| 138 | |
| 139 | mImpl->mZSstream.next_in = (Bytef*)(data); |
| 140 | mImpl->mZSstream.avail_in = (uInt)in; |
| 141 | |
| 142 | int ret = 0; |
| 143 | size_t total = 0l; |
| 144 | const int flushMode = getFlushMode(mImpl->mFlushMode); |
| 145 | if (flushMode == Z_FINISH) { |
| 146 | mImpl->mZSstream.avail_out = static_cast<uInt>(uncompressed.size()); |
| 147 | mImpl->mZSstream.next_out = reinterpret_cast<Bytef *>(&*uncompressed.begin()); |
| 148 | ret = inflate(&mImpl->mZSstream, Z_FINISH); |
| 149 | |
| 150 | if (ret != Z_STREAM_END && ret != Z_OK) { |
| 151 | throw DeadlyImportError("Compression", "Failure decompressing this file using gzip."); |
| 152 | } |
| 153 | total = mImpl->mZSstream.avail_out; |
| 154 | } else { |
| 155 | do { |
| 156 | Bytef block[MYBLOCK] = {}; |
| 157 | mImpl->mZSstream.avail_out = MYBLOCK; |
| 158 | mImpl->mZSstream.next_out = block; |
| 159 | |
| 160 | ret = inflate(&mImpl->mZSstream, flushMode); |
| 161 | |
| 162 | if (ret != Z_STREAM_END && ret != Z_OK) { |
| 163 | throw DeadlyImportError("Compression", "Failure decompressing this file using gzip."); |
| 164 | } |
| 165 | const size_t have = MYBLOCK - mImpl->mZSstream.avail_out; |
| 166 | total += have; |
| 167 | uncompressed.resize(total); |
| 168 | ::memcpy(uncompressed.data() + total - have, block, have); |
| 169 | } while (ret != Z_STREAM_END); |
| 170 | } |
| 171 | |
| 172 | return total; |
| 173 | } |
| 174 | |
| 175 | size_t Compression::decompressBlock(const void *data, size_t in, char *out, size_t availableOut) { |
| 176 | ai_assert(mImpl != nullptr); |
no test coverage detected