| 243 | } |
| 244 | |
| 245 | Result<FlushResult> Flush(int64_t output_len, uint8_t* output) override { |
| 246 | DCHECK(initialized_) << "Called on non-initialized stream"; |
| 247 | |
| 248 | static constexpr auto input_limit = |
| 249 | static_cast<int64_t>(std::numeric_limits<uInt>::max()); |
| 250 | |
| 251 | stream_.avail_in = 0; |
| 252 | stream_.next_out = reinterpret_cast<Bytef*>(output); |
| 253 | stream_.avail_out = static_cast<uInt>(std::min(output_len, input_limit)); |
| 254 | |
| 255 | int64_t ret = 0; |
| 256 | ret = deflate(&stream_, Z_SYNC_FLUSH); |
| 257 | if (ret == Z_STREAM_ERROR) { |
| 258 | return ZlibError("zlib flush failed: "); |
| 259 | } |
| 260 | int64_t bytes_written; |
| 261 | if (ret == Z_OK) { |
| 262 | bytes_written = output_len - stream_.avail_out; |
| 263 | } else { |
| 264 | ARROW_CHECK_EQ(ret, Z_BUF_ERROR); |
| 265 | bytes_written = 0; |
| 266 | } |
| 267 | // "If deflate returns with avail_out == 0, this function must be called |
| 268 | // again with the same value of the flush parameter and more output space |
| 269 | // (updated avail_out), until the flush is complete (deflate returns |
| 270 | // with non-zero avail_out)." |
| 271 | // "Note that Z_BUF_ERROR is not fatal, and deflate() can be called again |
| 272 | // with more input and more output space to continue compressing." |
| 273 | return FlushResult{bytes_written, stream_.avail_out == 0}; |
| 274 | } |
| 275 | |
| 276 | Result<EndResult> End(int64_t output_len, uint8_t* output) override { |
| 277 | DCHECK(initialized_) << "Called on non-initialized stream"; |
nothing calls this directly
no outgoing calls
no test coverage detected