| 461 | } |
| 462 | |
| 463 | Result<int64_t> Compress(int64_t input_length, const uint8_t* input, |
| 464 | int64_t output_buffer_len, uint8_t* output) override { |
| 465 | if (!compressor_initialized_) { |
| 466 | RETURN_NOT_OK(InitCompressor()); |
| 467 | } |
| 468 | stream_.next_in = const_cast<Bytef*>(reinterpret_cast<const Bytef*>(input)); |
| 469 | stream_.avail_in = static_cast<uInt>(input_length); |
| 470 | stream_.next_out = reinterpret_cast<Bytef*>(output); |
| 471 | stream_.avail_out = static_cast<uInt>(output_buffer_len); |
| 472 | |
| 473 | int64_t ret = 0; |
| 474 | if ((ret = deflate(&stream_, Z_FINISH)) != Z_STREAM_END) { |
| 475 | if (ret == Z_OK) { |
| 476 | // Will return Z_OK (and stream.msg NOT set) if stream.avail_out is too |
| 477 | // small |
| 478 | return Status::IOError("zlib deflate failed, output buffer too small"); |
| 479 | } |
| 480 | |
| 481 | return ZlibErrorPrefix("zlib deflate failed: ", stream_.msg); |
| 482 | } |
| 483 | |
| 484 | if (deflateReset(&stream_) != Z_OK) { |
| 485 | return ZlibErrorPrefix("zlib deflateReset failed: ", stream_.msg); |
| 486 | } |
| 487 | |
| 488 | // Actual output length |
| 489 | return output_buffer_len - stream_.avail_out; |
| 490 | } |
| 491 | |
| 492 | Status Init() override { |
| 493 | if (window_bits_ < kGZipMinWindowBits || window_bits_ > kGZipMaxWindowBits) { |
nothing calls this directly
no test coverage detected