| 301 | } |
| 302 | |
| 303 | uint64_t ZlibCompressionStream::doStreamingCompression() { |
| 304 | if (deflateReset(&strm_) != Z_OK) { |
| 305 | throw CompressionError("Failed to reset inflate."); |
| 306 | } |
| 307 | |
| 308 | // iterate through all blocks |
| 309 | uint64_t blockId = 0; |
| 310 | bool finish = false; |
| 311 | |
| 312 | do { |
| 313 | if (blockId == rawInputBuffer.getBlockNumber()) { |
| 314 | finish = true; |
| 315 | strm_.avail_in = 0; |
| 316 | strm_.next_in = nullptr; |
| 317 | } else { |
| 318 | auto block = rawInputBuffer.getBlock(blockId++); |
| 319 | strm_.avail_in = static_cast<unsigned int>(block.size); |
| 320 | strm_.next_in = reinterpret_cast<unsigned char*>(block.data); |
| 321 | } |
| 322 | |
| 323 | do { |
| 324 | if (outputPosition >= outputSize) { |
| 325 | if (!BufferedOutputStream::Next(reinterpret_cast<void**>(&outputBuffer), &outputSize)) { |
| 326 | throw CompressionError("Failed to get next output buffer from output stream."); |
| 327 | } |
| 328 | outputPosition = 0; |
| 329 | } |
| 330 | strm_.next_out = reinterpret_cast<unsigned char*>(outputBuffer + outputPosition); |
| 331 | strm_.avail_out = static_cast<unsigned int>(outputSize - outputPosition); |
| 332 | |
| 333 | int ret = deflate(&strm_, finish ? Z_FINISH : Z_NO_FLUSH); |
| 334 | outputPosition = outputSize - static_cast<int>(strm_.avail_out); |
| 335 | |
| 336 | if (ret == Z_STREAM_END) { |
| 337 | break; |
| 338 | } else if (ret == Z_OK) { |
| 339 | // needs more buffer so will continue the loop |
| 340 | } else { |
| 341 | throw CompressionError("Failed to deflate input data."); |
| 342 | } |
| 343 | } while (strm_.avail_out == 0); |
| 344 | } while (!finish); |
| 345 | return strm_.total_out; |
| 346 | } |
| 347 | |
| 348 | std::string ZlibCompressionStream::getName() const { |
| 349 | return "ZlibCompressionStream"; |
nothing calls this directly
no test coverage detected