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

Method DecompressData

cpp/src/arrow/io/compressed.cc:302–343  ·  view source on GitHub ↗

Decompress some data from the compressed_ buffer into decompressor_. Call this function only if the decompressed_ buffer is fully consumed.

Source from the content-addressed store, hash-verified

300 // Decompress some data from the compressed_ buffer into decompressor_.
301 // Call this function only if the decompressed_ buffer is fully consumed.
302 Status DecompressData() {
303 // compressed_buffer_available() could be 0 here because there might
304 // still be some decompressed data left to emit even though the compressed
305 // data was entirely consumed (especially if the expansion factor is large)
306 DCHECK_NE(compressed_->data(), nullptr);
307 DCHECK_EQ(0, decompressed_buffer_available());
308
309 int64_t decompress_size = kDecompressSize;
310
311 while (true) {
312 if (decompressed_ == nullptr) {
313 ARROW_ASSIGN_OR_RAISE(decompressed_,
314 AllocateResizableBuffer(decompress_size, pool_));
315 } else {
316 // Shrinking the buffer if it's already large enough
317 RETURN_NOT_OK(decompressed_->Resize(decompress_size, /*shrink_to_fit=*/true));
318 }
319 decompressed_pos_ = 0;
320
321 int64_t input_len = compressed_->size() - compressed_pos_;
322 const uint8_t* input = compressed_->data() + compressed_pos_;
323 int64_t output_len = decompressed_->size();
324 uint8_t* output = decompressed_->mutable_data();
325
326 ARROW_ASSIGN_OR_RAISE(
327 auto result, decompressor_->Decompress(input_len, input, output_len, output));
328 compressed_pos_ += result.bytes_read;
329 if (result.bytes_read > 0) {
330 fresh_decompressor_ = false;
331 }
332 if (result.bytes_written > 0 || !result.need_more_output || input_len == 0) {
333 // Not calling shrink_to_fit here because we're likely to reusing the buffer.
334 RETURN_NOT_OK(
335 decompressed_->Resize(result.bytes_written, /*shrink_to_fit=*/false));
336 break;
337 }
338 DCHECK_EQ(result.bytes_written, 0);
339 // Need to enlarge output buffer
340 decompress_size *= 2;
341 }
342 return Status::OK();
343 }
344
345 // Copying a given number of bytes from the decompressed_ buffer.
346 int64_t ReadFromDecompressed(int64_t nbytes, uint8_t* out) {

Callers

nothing calls this directly

Calls 7

AllocateResizableBufferFunction · 0.85
ARROW_ASSIGN_OR_RAISEFunction · 0.50
OKFunction · 0.50
dataMethod · 0.45
ResizeMethod · 0.45
sizeMethod · 0.45
mutable_dataMethod · 0.45

Tested by

no test coverage detected