NeoMutt  2024-11-14-34-g5aaf0d
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
compress()

Compress header cache data. More...

+ Collaboration diagram for compress():

Functions

static void * compr_lz4_compress (ComprHandle *handle, const char *data, size_t dlen, size_t *clen)
 Compress header cache data - Implements ComprOps::compress() -.
 
static void * compr_zlib_compress (ComprHandle *handle, const char *data, size_t dlen, size_t *clen)
 Compress header cache data - Implements ComprOps::compress() -.
 
static void * compr_zstd_compress (ComprHandle *handle, const char *data, size_t dlen, size_t *clen)
 Compress header cache data - Implements ComprOps::compress() -.
 

Detailed Description

Compress header cache data.

Parameters
[in]handleCompression handle
[in]dataData to be compressed
[in]dlenLength of the uncompressed data
[out]clenLength of returned compressed data
Return values
ptrSuccess, pointer to compressed data
NULLOtherwise
Note
This function returns a pointer to data, which will be freed by the close() function.

Function Documentation

◆ compr_lz4_compress()

static void * compr_lz4_compress ( ComprHandle handle,
const char *  data,
size_t  dlen,
size_t *  clen 
)
static

Compress header cache data - Implements ComprOps::compress() -.

Definition at line 101 of file lz4.c.

103{
104 if (!handle || (dlen > INT_MAX))
105 return NULL;
106
107 // Decloak an opaque pointer
108 struct Lz4ComprData *cdata = handle;
109
110 int datalen = dlen;
111 int len = LZ4_compressBound(dlen);
112 if (len > (INT_MAX - 4))
113 return NULL; // LCOV_EXCL_LINE
114 mutt_mem_realloc(&cdata->buf, len + 4);
115 char *cbuf = cdata->buf;
116
117 len = LZ4_compress_fast(data, cbuf + 4, datalen, len, cdata->level);
118 if (len == 0)
119 return NULL; // LCOV_EXCL_LINE
120 *clen = len + 4;
121
122 /* save ulen to first 4 bytes */
123 unsigned char *cs = cdata->buf;
124 cs[0] = dlen & 0xff;
125 dlen >>= 8;
126 cs[1] = dlen & 0xff;
127 dlen >>= 8;
128 cs[2] = dlen & 0xff;
129 dlen >>= 8;
130 cs[3] = dlen & 0xff;
131
132 return cdata->buf;
133}
void mutt_mem_realloc(void *pptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:147
Private Lz4 Compression Data.
Definition: lz4.c:47
void * buf
Temporary buffer.
Definition: lz4.c:48
short level
Compression Level to be used.
Definition: lz4.c:49
+ Here is the call graph for this function:

◆ compr_zlib_compress()

static void * compr_zlib_compress ( ComprHandle handle,
const char *  data,
size_t  dlen,
size_t *  clen 
)
static

Compress header cache data - Implements ComprOps::compress() -.

Definition at line 101 of file zlib.c.

103{
104 if (!handle)
105 return NULL;
106
107 // Decloak an opaque pointer
108 struct ZlibComprData *cdata = handle;
109
110 uLong len = compressBound(dlen);
111 mutt_mem_realloc(&cdata->buf, len + 4);
112 Bytef *cbuf = (unsigned char *) cdata->buf + 4;
113 const void *ubuf = data;
114 int rc = compress2(cbuf, &len, ubuf, dlen, cdata->level);
115 if (rc != Z_OK)
116 return NULL; // LCOV_EXCL_LINE
117 *clen = len + 4;
118
119 /* save ulen to first 4 bytes */
120 unsigned char *cs = cdata->buf;
121 cs[0] = dlen & 0xff;
122 dlen >>= 8;
123 cs[1] = dlen & 0xff;
124 dlen >>= 8;
125 cs[2] = dlen & 0xff;
126 dlen >>= 8;
127 cs[3] = dlen & 0xff;
128
129 return cdata->buf;
130}
Private Zlib Compression Data.
Definition: zlib.c:47
short level
Compression Level to be used.
Definition: zlib.c:49
void * buf
Temporary buffer.
Definition: zlib.c:48
+ Here is the call graph for this function:

◆ compr_zstd_compress()

static void * compr_zstd_compress ( ComprHandle handle,
const char *  data,
size_t  dlen,
size_t *  clen 
)
static

Compress header cache data - Implements ComprOps::compress() -.

Definition at line 115 of file zstd.c.

117{
118 if (!handle)
119 return NULL;
120
121 // Decloak an opaque pointer
122 struct ZstdComprData *cdata = handle;
123
124 size_t len = ZSTD_compressBound(dlen);
125 mutt_mem_realloc(&cdata->buf, len);
126
127 size_t rc = ZSTD_compressCCtx(cdata->cctx, cdata->buf, len, data, dlen, cdata->level);
128 if (ZSTD_isError(rc))
129 return NULL; // LCOV_EXCL_LINE
130
131 *clen = rc;
132
133 return cdata->buf;
134}
Private Zstandard Compression Data.
Definition: zstd.c:46
short level
Compression Level to be used.
Definition: zstd.c:48
ZSTD_CCtx * cctx
Compression context.
Definition: zstd.c:50
void * buf
Temporary buffer.
Definition: zstd.c:47
+ Here is the call graph for this function: