MCPcopy Create free account
hub / github.com/apache/arrow / Compress

Method Compress

cpp/src/arrow/util/compression_zlib.cc:218–243  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

216 }
217
218 Result<CompressResult> Compress(int64_t input_len, const uint8_t* input,
219 int64_t output_len, uint8_t* output) override {
220 DCHECK(initialized_) << "Called on non-initialized stream";
221
222 static constexpr auto input_limit =
223 static_cast<int64_t>(std::numeric_limits<uInt>::max());
224
225 stream_.next_in = const_cast<Bytef*>(reinterpret_cast<const Bytef*>(input));
226 stream_.avail_in = static_cast<uInt>(std::min(input_len, input_limit));
227 stream_.next_out = reinterpret_cast<Bytef*>(output);
228 stream_.avail_out = static_cast<uInt>(std::min(output_len, input_limit));
229
230 int64_t ret = 0;
231 ret = deflate(&stream_, Z_NO_FLUSH);
232 if (ret == Z_STREAM_ERROR) {
233 return ZlibError("zlib compress failed: ");
234 }
235 if (ret == Z_OK) {
236 // Some progress has been made
237 return CompressResult{input_len - stream_.avail_in, output_len - stream_.avail_out};
238 } else {
239 // No progress was possible
240 ARROW_CHECK_EQ(ret, Z_BUF_ERROR);
241 return CompressResult{0, 0};
242 }
243 }
244
245 Result<FlushResult> Flush(int64_t output_len, uint8_t* output) override {
246 DCHECK(initialized_) << "Called on non-initialized stream";

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected