2 * Helper routines to use Zlib
5 * Christopher Lahey (clahey@ximian.co)
7 * (C) 2004 Novell, Inc.
10 #if defined (HAVE_ZLIB)
19 create_z_stream(int compress
, unsigned char gzip
)
24 #if !defined(ZLIB_VERNUM) || (ZLIB_VERNUM < 0x1204)
25 /* Older versions of zlib do not support raw deflate or gzip */
29 z
= malloc (sizeof (z_stream
));
38 retval
= deflateInit2 (z
, Z_DEFAULT_COMPRESSION
, Z_DEFLATED
, gzip
? 31 : -15, 8, Z_DEFAULT_STRATEGY
);
40 retval
= inflateInit2 (z
, gzip
? 31 : -15);
51 free_z_stream(z_stream
*z
, int compress
)
62 z_stream_set_next_in(z_stream
*z
, unsigned char *next_in
)
68 z_stream_set_avail_in(z_stream
*z
, int avail_in
)
70 z
->avail_in
= avail_in
;
74 z_stream_get_avail_in(z_stream
*z
)
80 z_stream_set_next_out(z_stream
*z
, unsigned char *next_out
)
82 z
->next_out
= next_out
;
86 z_stream_set_avail_out(z_stream
*z
, int avail_out
)
88 z
->avail_out
= avail_out
;
92 z_stream_deflate (z_stream
*z
, int flush
, unsigned char *next_out
, int *avail_out
)
96 z
->next_out
= next_out
;
97 z
->avail_out
= *avail_out
;
99 ret_val
= deflate (z
, flush
);
101 *avail_out
= z
->avail_out
;
107 z_stream_inflate (z_stream
*z
, int *avail_out
)
111 z
->avail_out
= *avail_out
;
113 ret_val
= inflate (z
, Z_NO_FLUSH
);
115 *avail_out
= z
->avail_out
;