MCPcopy Create free account
hub / github.com/apache/cloudberry / tar_write_compressed_data

Function tar_write_compressed_data

src/bin/pg_basebackup/walmethods.c:508–556  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

506
507#ifdef HAVE_LIBZ
508static bool
509tar_write_compressed_data(void *buf, size_t count, bool flush)
510{
511 tar_data->zp->next_in = buf;
512 tar_data->zp->avail_in = count;
513
514 while (tar_data->zp->avail_in || flush)
515 {
516 int r;
517
518 r = deflate(tar_data->zp, flush ? Z_FINISH : Z_NO_FLUSH);
519 if (r == Z_STREAM_ERROR)
520 {
521 tar_set_error("could not compress data");
522 return false;
523 }
524
525 if (tar_data->zp->avail_out < ZLIB_OUT_SIZE)
526 {
527 size_t len = ZLIB_OUT_SIZE - tar_data->zp->avail_out;
528
529 errno = 0;
530 if (write(tar_data->fd, tar_data->zlibOut, len) != len)
531 {
532 /* If write didn't set errno, assume problem is no disk space */
533 tar_data->lasterrno = errno ? errno : ENOSPC;
534 return false;
535 }
536
537 tar_data->zp->next_out = tar_data->zlibOut;
538 tar_data->zp->avail_out = ZLIB_OUT_SIZE;
539 }
540
541 if (r == Z_STREAM_END)
542 break;
543 }
544
545 if (flush)
546 {
547 /* Reset the stream for writing */
548 if (deflateReset(tar_data->zp) != Z_OK)
549 {
550 tar_set_error("could not reset compression stream");
551 return false;
552 }
553 }
554
555 return true;
556}
557#endif
558
559static ssize_t

Callers 4

tar_writeFunction · 0.85
tar_open_for_writeFunction · 0.85
tar_closeFunction · 0.85
tar_finishFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected