2 * Helper routines to use Zlib
5 * Christopher Lahey (clahey@ximian.co)
7 * (C) 2004 Novell, Inc.
13 create_z_stream(int compress
, unsigned char gzip
)
18 #if !defined(ZLIB_VERNUM) || (ZLIB_VERNUM < 0x1204)
19 /* Older versions of zlib do not support raw deflate or gzip */
23 z
= malloc (sizeof (z_stream
));
32 retval
= deflateInit2 (z
, Z_DEFAULT_COMPRESSION
, Z_DEFLATED
, gzip
? 31 : -15, 8, Z_DEFAULT_STRATEGY
);
34 retval
= inflateInit2 (z
, gzip
? 31 : -15);
45 free_z_stream(z_stream
*z
, int compress
)
56 z_stream_set_next_in(z_stream
*z
, unsigned char *next_in
)
62 z_stream_set_avail_in(z_stream
*z
, int avail_in
)
64 z
->avail_in
= avail_in
;
68 z_stream_get_avail_in(z_stream
*z
)
74 z_stream_set_next_out(z_stream
*z
, unsigned char *next_out
)
76 z
->next_out
= next_out
;
80 z_stream_set_avail_out(z_stream
*z
, int avail_out
)
82 z
->avail_out
= avail_out
;
86 z_stream_deflate (z_stream
*z
, int flush
, unsigned char *next_out
, int *avail_out
)
90 z
->next_out
= next_out
;
91 z
->avail_out
= *avail_out
;
93 ret_val
= deflate (z
, flush
);
95 *avail_out
= z
->avail_out
;
101 z_stream_inflate (z_stream
*z
, int *avail_out
)
105 z
->avail_out
= *avail_out
;
107 ret_val
= inflate (z
, Z_NO_FLUSH
);
109 *avail_out
= z
->avail_out
;