Compress header cache data.
More...
Compress header cache data.
- Parameters
-
[in] | handle | Compression handle |
[in] | data | Data to be compressed |
[in] | dlen | Length of the uncompressed data |
[out] | clen | Length of returned compressed data |
- Return values
-
ptr | Success, pointer to compressed data |
NULL | Otherwise |
- Note
- This function returns a pointer to data, which will be freed by the close() function.
◆ 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
109
110 int datalen = dlen;
111 int len = LZ4_compressBound(dlen);
112 if (len > (INT_MAX - 4))
113 return NULL;
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;
120 *clen = len + 4;
121
122
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
133}
void mutt_mem_realloc(void *pptr, size_t size)
Resize a block of memory on the heap.
Private Lz4 Compression Data.
void * buf
Temporary buffer.
short level
Compression Level to be used.
◆ 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
109
110 uLong len = compressBound(dlen);
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;
117 *clen = len + 4;
118
119
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
130}
Private Zlib Compression Data.
short level
Compression Level to be used.
void * buf
Temporary buffer.
◆ 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
123
124 size_t len = ZSTD_compressBound(dlen);
126
127 size_t rc = ZSTD_compressCCtx(cdata->
cctx, cdata->
buf, len, data, dlen, cdata->
level);
128 if (ZSTD_isError(rc))
129 return NULL;
130
131 *clen = rc;
132
134}
Private Zstandard Compression Data.
short level
Compression Level to be used.
ZSTD_CCtx * cctx
Compression context.
void * buf
Temporary buffer.