14#if !defined(ZLIB_CONST)
29#define G_LOG_DOMAIN "libgvm util"
42gvm_compress (
const void *src,
unsigned long srclen,
unsigned long *dstlen)
44 unsigned long buflen = srclen * 2;
46 if (src == NULL || dstlen == NULL)
62 strm.avail_in = srclen;
67 strm.next_in = (
void *) src;
69 if (deflateInit (&strm, Z_DEFAULT_COMPRESSION) != Z_OK)
72 buffer = g_malloc0 (buflen);
73 strm.avail_out = buflen;
74 strm.next_out = buffer;
76 err = deflate (&strm, Z_SYNC_FLUSH);
82 if (strm.avail_out != 0)
84 *dstlen = strm.total_out;
113 unsigned long buflen;
115 if (src == NULL || dstlen == NULL || srclen == 0)
118 if (srclen >= SSIZE_MAX)
121 if (srclen > SSIZE_MAX / 2)
133 strm.zalloc = Z_NULL;
135 strm.opaque = Z_NULL;
136 strm.avail_in = srclen;
141 strm.next_in = (
void *) src;
148 if (inflateInit2 (&strm, 15 + 32) != Z_OK)
151 buffer = g_malloc0 (buflen);
152 strm.avail_out = buflen;
153 strm.next_out = buffer;
155 err = inflate (&strm, Z_SYNC_FLUSH);
161 if (strm.avail_out != 0)
163 *dstlen = strm.total_out;
169 if (buflen >= SSIZE_MAX)
171 else if (srclen > SSIZE_MAX / 2)
196 unsigned long *dstlen)
198 unsigned long buflen = srclen * 2;
199 int windowsBits = 15;
200 int GZIP_ENCODING = 16;
202 if (src == NULL || dstlen == NULL)
215 strm.zalloc = Z_NULL;
217 strm.opaque = Z_NULL;
218 strm.avail_in = srclen;
223 strm.next_in = (
void *) src;
226 if (deflateInit2 (&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED,
227 windowsBits | GZIP_ENCODING, 8, Z_DEFAULT_STRATEGY)
231 buffer = g_malloc0 (buflen);
232 strm.avail_out = buflen;
233 strm.next_out = buffer;
235 err = deflate (&strm, Z_FINISH);
241 if (strm.avail_out != 0)
243 *dstlen = strm.total_out;
271 gzFile gz_file = cookie;
273 return gzread (gz_file, buffer, buffer_size);
286 gzFile gz_file = cookie;
288 return gzclose (gz_file);
302 static cookie_io_functions_t io_functions = {
314 gzFile gz_file = gzopen (path,
"r");
320 FILE *file = fopencookie (gz_file,
"r", io_functions);
334 static cookie_io_functions_t io_functions = {
346 gzFile gz_file = gzdopen (fd,
"r");
352 FILE *file = fopencookie (gz_file,
"r", io_functions);
FILE * gvm_gzip_open_file_reader_fd(int fd)
Opens a gzip file as a FILE* stream for reading and decompression.
Definition compressutils.c:332
void * gvm_uncompress(const void *src, unsigned long srclen, unsigned long *dstlen)
Uncompresses data in src buffer.
Definition compressutils.c:111
void * gvm_compress(const void *src, unsigned long srclen, unsigned long *dstlen)
Compresses data in src buffer.
Definition compressutils.c:42
FILE * gvm_gzip_open_file_reader(const char *path)
Opens a gzip file as a FILE* stream for reading and decompression.
Definition compressutils.c:300
static int gz_file_close(void *cookie)
Close a gzip file.
Definition compressutils.c:284
static ssize_t gz_file_read(void *cookie, char *buffer, size_t buffer_size)
Read decompressed data from a gzip file.
Definition compressutils.c:269
void * gvm_compress_gzipheader(const void *src, unsigned long srclen, unsigned long *dstlen)
Compresses data in src buffer, gzip format compatible.
Definition compressutils.c:195
API related to data compression (gzip format.).