51 #include "config_auto.h" 54 #include "allheaders.h" 63 static const l_int32 ZLIB_COMPRESSION_LEVEL = 6;
97 l_int32 status, success;
100 l_uint8 *bufferin, *bufferout;
104 PROCNAME(
"zlibCompress");
107 return (l_uint8 *)ERROR_PTR(
"datain not defined", procName, NULL);
110 bufferin = (l_uint8 *)LEPT_CALLOC(
L_BUF_SIZE,
sizeof(l_uint8));
111 bufferout = (l_uint8 *)LEPT_CALLOC(
L_BUF_SIZE,
sizeof(l_uint8));
118 if (!bufferin || !bufferout || !bbin || !bbout) {
119 L_ERROR(
"calloc fail for buffer\n", procName);
124 z.zalloc = (alloc_func)0;
125 z.zfree = (free_func)0;
126 z.opaque = (voidpf)0;
128 z.next_in = bufferin;
130 z.next_out = bufferout;
133 status = deflateInit(&z, ZLIB_COMPRESSION_LEVEL);
134 if (status != Z_OK) {
135 L_ERROR(
"deflateInit failed\n", procName);
141 if (z.avail_in == 0) {
142 z.next_in = bufferin;
145 fprintf(stderr,
" wrote %lu bytes to bufferin\n",
146 (
unsigned long)nbytes);
150 flush = (bbin->
n) ? Z_SYNC_FLUSH : Z_FINISH;
151 status = deflate(&z, flush);
153 fprintf(stderr,
" status is %d, bytesleft = %u, totalout = %lu\n",
154 status, z.avail_out, z.total_out);
160 fprintf(stderr,
" read %lu bytes from bufferout\n",
161 (
unsigned long)nbytes);
164 z.next_out = bufferout;
166 }
while (flush != Z_FINISH);
179 LEPT_FREE(bufferout);
203 l_uint8 *bufferin, *bufferout;
204 l_int32 status, success;
209 PROCNAME(
"zlibUncompress");
212 return (l_uint8 *)ERROR_PTR(
"datain not defined", procName, NULL);
215 bufferin = (l_uint8 *)LEPT_CALLOC(
L_BUF_SIZE,
sizeof(l_uint8));
216 bufferout = (l_uint8 *)LEPT_CALLOC(
L_BUF_SIZE,
sizeof(l_uint8));
223 if (!bufferin || !bufferout || !bbin || !bbout) {
224 L_ERROR(
"calloc fail for buffer\n", procName);
229 z.zalloc = (alloc_func)0;
230 z.zfree = (free_func)0;
232 z.next_in = bufferin;
234 z.next_out = bufferout;
241 if (z.avail_in == 0) {
242 z.next_in = bufferin;
245 fprintf(stderr,
" wrote %d bytes to bufferin\n", nbytes);
251 status = inflate(&z, Z_SYNC_FLUSH);
253 fprintf(stderr,
" status is %d, bytesleft = %d, totalout = %d\n",
254 status, z.avail_out, z.total_out);
260 fprintf(stderr,
" read %d bytes from bufferout\n", nbytes);
263 z.next_out = bufferout;
278 LEPT_FREE(bufferout);
l_uint8 * zlibCompress(l_uint8 *datain, size_t nin, size_t *pnout)
zlibCompress()
L_BBUFFER * bbufferCreate(const l_uint8 *indata, l_int32 nalloc)
bbufferCreate()
l_ok bbufferWrite(L_BBUFFER *bb, l_uint8 *dest, size_t nbytes, size_t *pnout)
bbufferWrite()
l_uint8 * bbufferDestroyAndSaveData(L_BBUFFER **pbb, size_t *pnbytes)
bbufferDestroyAndSaveData()
l_uint8 * zlibUncompress(l_uint8 *datain, size_t nin, size_t *pnout)
zlibUncompress()
void bbufferDestroy(L_BBUFFER **pbb)
bbufferDestroy()
l_ok bbufferRead(L_BBUFFER *bb, l_uint8 *src, l_int32 nbytes)
bbufferRead()
static const l_int32 L_BUF_SIZE