summary refs log tree commit diff
path: root/doc/zlib/deflateInit2.3
blob: 6a581ef8b5562bfa6d9543afe00f4edc438e31d5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
.Dd January 15, 2017
.Dt DEFLATEINIT2 3
.Os
.
.Sh NAME
.Nm deflateInit2
.Nd deflate compression options
.
.Sh LIBRARY
.Lb libz
.
.Sh SYNOPSIS
.In zlib.h
.Ft int
.Fo deflateInit2
.Fa "z_streamp strm"
.Fa "int level"
.Fa "int method"
.Fa "int windowBits"
.Fa "int memLevel"
.Fa "int strategy"
.Fc
.
.Sh DESCRIPTION
This is another version of
.Xr deflateInit 3
with more compression options.
The fields
.Fa next_in ,
.Fa zalloc ,
.Fa zfree
and
.Fa opaque
must be initialized before by the caller.
.
.Pp
The
.Fa method
parameter is the compression method.
It must be
.Dv Z_DEFLATED
in this version of the library.
.
.Pp
The
.Fa windowBits
parameter is the base two logarithm
of the window size
(the size of the history buffer).
It should be in the range 8..15
for this version of the library.
Larger values of this parameter
result in better compression
at the expense of memory usage.
The default value is 15 if
.Xr deflateInit 3
is used instead.
.
.Pp
For the current implementation of
.Xr deflate 3 ,
a
.Fa windowBits
value of 8
(a window size of 256 bytes)
is not supported.
As a result,
a request for 8
will result in 9
(a 512-byte window).
In that case,
providing 8 to
.Xr inflateInit2 3
will result in an error
when the zlib header with 9
is checked against the initialization of
.Xr inflate 3 .
The remedy is to not use 8 with
.Fn deflateInit2
with this initialization,
or at least in that case use 9 with
.Xr inflateInit2 3 .
.
.Pp
.Fa windowBits
can also be -8..-15 for raw deflate.
In this case,
.Fa -windowBits
determines the window size.
.Xr deflate 3
will then generate raw deflate data
with no zlib header or trailer,
and will not compute a check value.
.
.Pp
.Fa windowBits
can also be greater than 15
for optional gzip encoding.
Add 16 to
.Fa windowBits
to write a simple gzip header and trailer
around the compressed data
instead of a zlib wrapper.
The gzip header will have
no file name,
no extra data,
no comment,
no modification time (set to zero),
no header CRC,
and the operating system will be set
to the appropriate value,
if the operating system was determined at compile time.
If a gzip stream is being written,
.Fa strm->adler
is a CRC-32 instead of an Adler-32.
.
.Pp
For raw deflate or gzip encoding,
a request for a 256-byte window
is rejected as invalid,
since only the zlib header provides
a means of transmitting the window size
to the decompressor.
.
.Pp
The
.Fa memLevel
parameter specifies how much memory should be allocated
for the internal compression state.
.Fa memLevel=1
uses minimum memory
but is slow and reduces compression ratio;
.Fa memLevel=9
uses maximum memory for optimal speed.
The default value is 8.
See
.In zconf.h
for total memory usage
as a function of
.Fa windowBits
and
.Fa memLevel .
.
.Pp
The
.Fa strategy
parameter is used to tune the compression algorithm.
Use the value
.Dv Z_DEFAULT_STRATEGY
for normal data,
.Dv Z_FILTERED
for data produced by a filter
(or predictor),
.Dv Z_HUFFMAN_ONLY
to force Huffman encoding only
(no string match),
or
.Dv Z_RLE
to limit match distances to one
(run-length encoding).
Filtered data consists mostly of small values
with a somewhat random distribution.
In this case,
the compression algorithm
is tuned to compress them better.
The effect of
.Dv Z_FILTERED
is to force more Huffman coding
and less string matching;
it is somewhat intermediate between
.Dv Z_DEFAULT_STRATEGY
and
.Dv Z_HUFFMAN_ONLY .
.Dv Z_RLE
is designed to be almost as fast as
.Dv Z_HUFFMAN_ONLY ,
but give better compression for PNG image data.
The
.Fa strategy
parameter only affects the compression ratio
but not the correctness of the compressed output
even if it is not set appropriately.
.Dv Z_FIXED
prevents the use of dynamic Huffman codes,
allowing for a simpler decoder
for special applications.
.
.Pp
.Fn deflateInit2
does not perform any compression:
this will be done by
.Xr deflate 3 .
.
.Sh RETURN VALUES
.Fn deflateInit2
returns
.Dv Z_OK
if success,
.Dv Z_MEM_ERROR
if there was not enough memory,
.Dv Z_STREAM_ERROR
if any parameter is invalid
(such as invalid method),
or
.Dv Z_VERSION_ERROR
if the zlib library version
.Pq Xr zlibVersion 3
is incompatible with the version assumed by the caller
.Pq Dv ZLIB_VERSION .
.Fa msg
is set to null if there is no error message.
.
.Sh SEE ALSO
.Xr deflate 3 ,
.Xr deflateInit 3 ,
.Xr deflateParams 3 ,
.Xr deflateSetHeader 3
.
.Sh HISTORY
This manual page was converted from
.In zlib.h
to mdoc format by
.An C. McEnroe Aq Mt june@causal.agency .
.
.Sh AUTHORS
.An Jean-loup Gailly Aq Mt jloup@gzip.org
.An Mark Adler Aq Mt madler@alumni.caltech.edu