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

Go to the source code of this file.

Functions

bbstreamerbbstreamer_lz4_compressor_new (bbstreamer *next, pg_compress_specification *compress)
 
bbstreamerbbstreamer_lz4_decompressor_new (bbstreamer *next)
 

Function Documentation

◆ bbstreamer_lz4_compressor_new()

bbstreamer* bbstreamer_lz4_compressor_new ( bbstreamer next,
pg_compress_specification compress 
)

Definition at line 70 of file bbstreamer_lz4.c.

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

◆ bbstreamer_lz4_decompressor_new()

bbstreamer* bbstreamer_lz4_decompressor_new ( bbstreamer next)

Definition at line 275 of file bbstreamer_lz4.c.

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

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

Referenced by CreateBackupStreamer().