PostgreSQL Source Code  git master
astreamer_lz4.c File Reference
#include "postgres_fe.h"
#include <unistd.h>
#include "common/file_perm.h"
#include "common/logging.h"
#include "common/string.h"
#include "fe_utils/astreamer.h"
Include dependency graph for astreamer_lz4.c:

Go to the source code of this file.

Functions

astreamerastreamer_lz4_compressor_new (astreamer *next, pg_compress_specification *compress)
 
astreamerastreamer_lz4_decompressor_new (astreamer *next)
 

Function Documentation

◆ astreamer_lz4_compressor_new()

astreamer* astreamer_lz4_compressor_new ( astreamer next,
pg_compress_specification compress 
)

Definition at line 74 of file astreamer_lz4.c.

75 {
76 #ifdef USE_LZ4
77  astreamer_lz4_frame *streamer;
78  LZ4F_errorCode_t ctxError;
79  LZ4F_preferences_t *prefs;
80 
81  Assert(next != NULL);
82 
83  streamer = palloc0(sizeof(astreamer_lz4_frame));
84  *((const astreamer_ops **) &streamer->base.bbs_ops) =
85  &astreamer_lz4_compressor_ops;
86 
87  streamer->base.bbs_next = next;
88  initStringInfo(&streamer->base.bbs_buffer);
89  streamer->header_written = false;
90 
91  /* Initialize stream compression preferences */
92  prefs = &streamer->prefs;
93  memset(prefs, 0, sizeof(LZ4F_preferences_t));
94  prefs->frameInfo.blockSizeID = LZ4F_max256KB;
95  prefs->compressionLevel = compress->level;
96 
97  ctxError = LZ4F_createCompressionContext(&streamer->cctx, LZ4F_VERSION);
98  if (LZ4F_isError(ctxError))
99  pg_log_error("could not create lz4 compression context: %s",
100  LZ4F_getErrorName(ctxError));
101 
102  return &streamer->base;
103 #else
104  pg_fatal("this build does not support compression with %s", "LZ4");
105  return NULL; /* keep compiler quiet */
106 #endif
107 }
static int32 next
Definition: blutils.c:222
#define Assert(condition)
Definition: c.h:849
#define pg_log_error(...)
Definition: logging.h:106
void * palloc0(Size size)
Definition: mcxt.c:1347
#define pg_fatal(...)
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59

References Assert, initStringInfo(), pg_compress_specification::level, next, palloc0(), pg_fatal, and pg_log_error.

Referenced by CreateBackupStreamer().

◆ astreamer_lz4_decompressor_new()

astreamer* astreamer_lz4_decompressor_new ( astreamer next)

Definition at line 279 of file astreamer_lz4.c.

280 {
281 #ifdef USE_LZ4
282  astreamer_lz4_frame *streamer;
283  LZ4F_errorCode_t ctxError;
284 
285  Assert(next != NULL);
286 
287  streamer = palloc0(sizeof(astreamer_lz4_frame));
288  *((const astreamer_ops **) &streamer->base.bbs_ops) =
289  &astreamer_lz4_decompressor_ops;
290 
291  streamer->base.bbs_next = next;
292  initStringInfo(&streamer->base.bbs_buffer);
293 
294  /* Initialize internal stream state for decompression */
295  ctxError = LZ4F_createDecompressionContext(&streamer->dctx, LZ4F_VERSION);
296  if (LZ4F_isError(ctxError))
297  pg_fatal("could not initialize compression library: %s",
298  LZ4F_getErrorName(ctxError));
299 
300  return &streamer->base;
301 #else
302  pg_fatal("this build does not support compression with %s", "LZ4");
303  return NULL; /* keep compiler quiet */
304 #endif
305 }

References Assert, initStringInfo(), next, palloc0(), and pg_fatal.

Referenced by create_archive_verifier(), and CreateBackupStreamer().