| 127 | } |
| 128 | |
| 129 | Status GzipCompressor::ProcessBlock(bool output_preallocated, |
| 130 | int64_t input_length, const uint8_t* input, int64_t* output_length, |
| 131 | uint8_t** output) { |
| 132 | DCHECK_GE(input_length, 0); |
| 133 | DCHECK(!output_preallocated || (output_preallocated && *output_length > 0)); |
| 134 | int64_t max_compressed_len = MaxOutputLen(input_length); |
| 135 | if (!output_preallocated) { |
| 136 | if (!reuse_buffer_ || buffer_length_ < max_compressed_len || out_buffer_ == nullptr) { |
| 137 | DCHECK(memory_pool_ != nullptr) << "Can't allocate without passing in a mem pool"; |
| 138 | buffer_length_ = max_compressed_len; |
| 139 | out_buffer_ = memory_pool_->Allocate(buffer_length_); |
| 140 | } |
| 141 | *output = out_buffer_; |
| 142 | *output_length = buffer_length_; |
| 143 | } else if (*output_length < max_compressed_len) { |
| 144 | return Status("GzipCompressor::ProcessBlock: output length too small"); |
| 145 | } |
| 146 | |
| 147 | RETURN_IF_ERROR(Compress(input_length, input, output_length, *output)); |
| 148 | return Status::OK(); |
| 149 | } |
| 150 | |
| 151 | Status GzipCompressor::ValidateCompressionLevel(int compression_level) { |
| 152 | if (compression_level >= Z_BEST_SPEED && compression_level <= Z_BEST_COMPRESSION) { |