31 static const unsigned char gzipMagicBytes[] = { 0x1f, 0x8b, 0x08, 0x00 };
33 static void zobj_free(
void *data) {
34 struct zobj *zdata = data;
50 if (!(ret =
objalloc(
sizeof(*ret), zobj_free))) {
54 ret->
zlen = compressBound(len);
57 if (!(ret->
buff = malloc(ret->
zlen))) {
60 compress2(ret->
buff, (uLongf *)&ret->
zlen, buff, len, level);
78 uncompress(obuff, &olen, buff->
buff, buff->
zlen);
85 extern int is_gzip(uint8_t *buf,
int buf_size) {
89 if (memcmp(buf, gzipMagicBytes, 4)) {
101 extern uint8_t *
gzinflatebuf(uint8_t *buf_in,
int buf_size, uint32_t *len) {
103 uint8_t *buf = NULL, *tmp;
110 zdat.next_in = buf_in;
111 zdat.avail_in = buf_size;
116 if (inflateInit2(&zdat, 31)) {
121 if (!(tmp = realloc(buf,zdat.total_out + (zdat.avail_in * 5) + 1))) {
127 buf[zdat.total_out] =
'\0';
128 zdat.next_out = &buf[zdat.total_out];
129 zdat.avail_out += zdat.avail_in * 5;
130 }
while ((res = inflate(&zdat, Z_NO_FLUSH)) == Z_OK);
132 if (res == Z_STREAM_END) {
133 buf = realloc(buf, zdat.total_out);
134 *len = zdat.total_out;
void zuncompress(struct zobj *buff, uint8_t *obuff)
Uncompress zobj buffer to buffer.
uint16_t zlen
Compressed size of data.
uint8_t * gzinflatebuf(uint8_t *buf_in, int buf_size, uint32_t *len)
Ungzip a buffer.
struct zobj * zcompress(uint8_t *buff, uint16_t len, uint8_t level)
Allocate a buffer and return it with compressed data.
void * objalloc(int size, objdestroy)
Allocate a referenced lockable object.
DTS Application library API Include file.
Zlib buffer used for compression and decompression.
uint8_t * buff
Buffer with compressed/uncompressed data.
uint16_t olen
Original size of data.
int is_gzip(uint8_t *buf, int buf_size)
check a buffer if it contains gzip magic