| 1 |
.\" -*- mode: troff; coding: utf-8 -*- |
| 2 |
.\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45) |
| 3 |
.\" |
| 4 |
.\" Standard preamble: |
| 5 |
.\" ======================================================================== |
| 6 |
.de Sp \" Vertical space (when we can't use .PP) |
| 7 |
.if t .sp .5v |
| 8 |
.if n .sp |
| 9 |
.. |
| 10 |
.de Vb \" Begin verbatim text |
| 11 |
.ft CW |
| 12 |
.nf |
| 13 |
.ne \\$1 |
| 14 |
.. |
| 15 |
.de Ve \" End verbatim text |
| 16 |
.ft R |
| 17 |
.fi |
| 18 |
.. |
| 19 |
.\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. |
| 20 |
.ie n \{\ |
| 21 |
. ds C` "" |
| 22 |
. ds C' "" |
| 23 |
'br\} |
| 24 |
.el\{\ |
| 25 |
. ds C` |
| 26 |
. ds C' |
| 27 |
'br\} |
| 28 |
.\" |
| 29 |
.\" Escape single quotes in literal strings from groff's Unicode transform. |
| 30 |
.ie \n(.g .ds Aq \(aq |
| 31 |
.el .ds Aq ' |
| 32 |
.\" |
| 33 |
.\" If the F register is >0, we'll generate index entries on stderr for |
| 34 |
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index |
| 35 |
.\" entries marked with X<> in POD. Of course, you'll have to process the |
| 36 |
.\" output yourself in some meaningful fashion. |
| 37 |
.\" |
| 38 |
.\" Avoid warning from groff about undefined register 'F'. |
| 39 |
.de IX |
| 40 |
.. |
| 41 |
.nr rF 0 |
| 42 |
.if \n(.g .if rF .nr rF 1 |
| 43 |
.if (\n(rF:(\n(.g==0)) \{\ |
| 44 |
. if \nF \{\ |
| 45 |
. de IX |
| 46 |
. tm Index:\\$1\t\\n%\t"\\$2" |
| 47 |
.. |
| 48 |
. if !\nF==2 \{\ |
| 49 |
. nr % 0 |
| 50 |
. nr F 2 |
| 51 |
. \} |
| 52 |
. \} |
| 53 |
.\} |
| 54 |
.rr rF |
| 55 |
.\" ======================================================================== |
| 56 |
.\" |
| 57 |
.IX Title "Compress::Zlib 3perl" |
| 58 |
.TH Compress::Zlib 3perl 2025-11-16 "perl v5.40.1" "Perl Programmers Reference Guide" |
| 59 |
.\" For nroff, turn off justification. Always turn off hyphenation; it makes |
| 60 |
.\" way too many mistakes in technical documents. |
| 61 |
.if n .ad l |
| 62 |
.nh |
| 63 |
.SH NAME |
| 64 |
Compress::Zlib \- Interface to zlib compression library |
| 65 |
.SH SYNOPSIS |
| 66 |
.IX Header "SYNOPSIS" |
| 67 |
.Vb 1 |
| 68 |
\& use Compress::Zlib ; |
| 69 |
\& |
| 70 |
\& ($d, $status) = deflateInit( [OPT] ) ; |
| 71 |
\& $status = $d\->deflate($input, $output) ; |
| 72 |
\& $status = $d\->flush([$flush_type]) ; |
| 73 |
\& $d\->deflateParams(OPTS) ; |
| 74 |
\& $d\->deflateTune(OPTS) ; |
| 75 |
\& $d\->dict_adler() ; |
| 76 |
\& $d\->crc32() ; |
| 77 |
\& $d\->adler32() ; |
| 78 |
\& $d\->total_in() ; |
| 79 |
\& $d\->total_out() ; |
| 80 |
\& $d\->msg() ; |
| 81 |
\& $d\->get_Strategy(); |
| 82 |
\& $d\->get_Level(); |
| 83 |
\& $d\->get_BufSize(); |
| 84 |
\& |
| 85 |
\& ($i, $status) = inflateInit( [OPT] ) ; |
| 86 |
\& $status = $i\->inflate($input, $output [, $eof]) ; |
| 87 |
\& $status = $i\->inflateSync($input) ; |
| 88 |
\& $i\->dict_adler() ; |
| 89 |
\& $d\->crc32() ; |
| 90 |
\& $d\->adler32() ; |
| 91 |
\& $i\->total_in() ; |
| 92 |
\& $i\->total_out() ; |
| 93 |
\& $i\->msg() ; |
| 94 |
\& $d\->get_BufSize(); |
| 95 |
\& |
| 96 |
\& $dest = compress($source) ; |
| 97 |
\& $dest = uncompress($source) ; |
| 98 |
\& |
| 99 |
\& $gz = gzopen($filename or filehandle, $mode) ; |
| 100 |
\& $bytesread = $gz\->gzread($buffer [,$size]) ; |
| 101 |
\& $bytesread = $gz\->gzreadline($line) ; |
| 102 |
\& $byteswritten = $gz\->gzwrite($buffer) ; |
| 103 |
\& $status = $gz\->gzflush($flush) ; |
| 104 |
\& $offset = $gz\->gztell() ; |
| 105 |
\& $status = $gz\->gzseek($offset, $whence) ; |
| 106 |
\& $status = $gz\->gzclose() ; |
| 107 |
\& $status = $gz\->gzeof() ; |
| 108 |
\& $status = $gz\->gzsetparams($level, $strategy) ; |
| 109 |
\& $errstring = $gz\->gzerror() ; |
| 110 |
\& $gzerrno |
| 111 |
\& |
| 112 |
\& $dest = Compress::Zlib::memGzip($buffer) ; |
| 113 |
\& $dest = Compress::Zlib::memGunzip($buffer) ; |
| 114 |
\& |
| 115 |
\& $crc = adler32($buffer [,$crc]) ; |
| 116 |
\& $crc = crc32($buffer [,$crc]) ; |
| 117 |
\& |
| 118 |
\& $crc = crc32_combine($crc1, $crc2, $len2); |
| 119 |
\& $adler = adler32_combine($adler1, $adler2, $len2); |
| 120 |
\& |
| 121 |
\& my $version = Compress::Raw::Zlib::zlib_version(); |
| 122 |
.Ve |
| 123 |
.SH DESCRIPTION |
| 124 |
.IX Header "DESCRIPTION" |
| 125 |
The \fICompress::Zlib\fR module provides a Perl interface to the \fIzlib\fR |
| 126 |
compression library (see "AUTHOR" for details about where to get |
| 127 |
\&\fIzlib\fR). |
| 128 |
.PP |
| 129 |
The \f(CW\*(C`Compress::Zlib\*(C'\fR module can be split into two general areas of |
| 130 |
functionality, namely a simple read/write interface to \fIgzip\fR files |
| 131 |
and a low-level in-memory compression/decompression interface. |
| 132 |
.PP |
| 133 |
Each of these areas will be discussed in the following sections. |
| 134 |
.SS "Notes for users of Compress::Zlib version 1" |
| 135 |
.IX Subsection "Notes for users of Compress::Zlib version 1" |
| 136 |
The main change in \f(CW\*(C`Compress::Zlib\*(C'\fR version 2.x is that it does not now |
| 137 |
interface directly to the zlib library. Instead it uses the |
| 138 |
\&\f(CW\*(C`IO::Compress::Gzip\*(C'\fR and \f(CW\*(C`IO::Uncompress::Gunzip\*(C'\fR modules for |
| 139 |
reading/writing gzip files, and the \f(CW\*(C`Compress::Raw::Zlib\*(C'\fR module for some |
| 140 |
low-level zlib access. |
| 141 |
.PP |
| 142 |
The interface provided by version 2 of this module should be 100% backward |
| 143 |
compatible with version 1. If you find a difference in the expected |
| 144 |
behaviour please contact the author (See "AUTHOR"). See "GZIP INTERFACE" |
| 145 |
.PP |
| 146 |
With the creation of the \f(CW\*(C`IO::Compress\*(C'\fR and \f(CW\*(C`IO::Uncompress\*(C'\fR modules no |
| 147 |
new features are planned for \f(CW\*(C`Compress::Zlib\*(C'\fR \- the new modules do |
| 148 |
everything that \f(CW\*(C`Compress::Zlib\*(C'\fR does and then some. Development on |
| 149 |
\&\f(CW\*(C`Compress::Zlib\*(C'\fR will be limited to bug fixes only. |
| 150 |
.PP |
| 151 |
If you are writing new code, your first port of call should be one of the |
| 152 |
new \f(CW\*(C`IO::Compress\*(C'\fR or \f(CW\*(C`IO::Uncompress\*(C'\fR modules. |
| 153 |
.SH "GZIP INTERFACE" |
| 154 |
.IX Header "GZIP INTERFACE" |
| 155 |
A number of functions are supplied in \fIzlib\fR for reading and writing |
| 156 |
\&\fIgzip\fR files that conform to RFC 1952. This module provides an interface |
| 157 |
to most of them. |
| 158 |
.PP |
| 159 |
If you have previously used \f(CW\*(C`Compress::Zlib\*(C'\fR 1.x, the following |
| 160 |
enhancements/changes have been made to the \f(CW\*(C`gzopen\*(C'\fR interface: |
| 161 |
.IP 1. 5 |
| 162 |
If you want to open either STDIN or STDOUT with \f(CW\*(C`gzopen\*(C'\fR, you can now |
| 163 |
optionally use the special filename "\f(CW\*(C`\-\*(C'\fR" as a synonym for \f(CW\*(C`\e*STDIN\*(C'\fR and |
| 164 |
\&\f(CW\*(C`\e*STDOUT\*(C'\fR. |
| 165 |
.IP 2. 5 |
| 166 |
In \f(CW\*(C`Compress::Zlib\*(C'\fR version 1.x, \f(CW\*(C`gzopen\*(C'\fR used the zlib library to open |
| 167 |
the underlying file. This made things especially tricky when a Perl |
| 168 |
filehandle was passed to \f(CW\*(C`gzopen\*(C'\fR. Behind the scenes the numeric C file |
| 169 |
descriptor had to be extracted from the Perl filehandle and this passed to |
| 170 |
the zlib library. |
| 171 |
.Sp |
| 172 |
Apart from being non-portable to some operating systems, this made it |
| 173 |
difficult to use \f(CW\*(C`gzopen\*(C'\fR in situations where you wanted to extract/create |
| 174 |
a gzip data stream that is embedded in a larger file, without having to |
| 175 |
resort to opening and closing the file multiple times. |
| 176 |
.Sp |
| 177 |
It also made it impossible to pass a perl filehandle that wasn't associated |
| 178 |
with a real filesystem file, like, say, an \f(CW\*(C`IO::String\*(C'\fR. |
| 179 |
.Sp |
| 180 |
In \f(CW\*(C`Compress::Zlib\*(C'\fR version 2.x, the \f(CW\*(C`gzopen\*(C'\fR interface has been |
| 181 |
completely rewritten to use the IO::Compress::Gzip |
| 182 |
for writing gzip files and IO::Uncompress::Gunzip |
| 183 |
for reading gzip files. None of the limitations mentioned above apply. |
| 184 |
.IP 3. 5 |
| 185 |
Addition of \f(CW\*(C`gzseek\*(C'\fR to provide a restricted \f(CW\*(C`seek\*(C'\fR interface. |
| 186 |
.IP 4. 5 |
| 187 |
Added \f(CW\*(C`gztell\*(C'\fR. |
| 188 |
.PP |
| 189 |
A more complete and flexible interface for reading/writing gzip |
| 190 |
files/buffers is included with the module \f(CW\*(C`IO\-Compress\-Zlib\*(C'\fR. See |
| 191 |
IO::Compress::Gzip and |
| 192 |
IO::Uncompress::Gunzip for more details. |
| 193 |
.ie n .IP "\fR\fB$gz\fR\fB = gzopen($filename, \fR\fB$mode\fR\fB)\fR" 5 |
| 194 |
.el .IP "\fR\f(CB$gz\fR\fB = gzopen($filename, \fR\f(CB$mode\fR\fB)\fR" 5 |
| 195 |
.IX Item "$gz = gzopen($filename, $mode)" |
| 196 |
.PD 0 |
| 197 |
.ie n .IP "\fR\fB$gz\fR\fB = gzopen($filehandle, \fR\fB$mode\fR\fB)\fR" 5 |
| 198 |
.el .IP "\fR\f(CB$gz\fR\fB = gzopen($filehandle, \fR\f(CB$mode\fR\fB)\fR" 5 |
| 199 |
.IX Item "$gz = gzopen($filehandle, $mode)" |
| 200 |
.PD |
| 201 |
This function opens either the \fIgzip\fR file \f(CW$filename\fR for reading or |
| 202 |
writing or attaches to the opened filehandle, \f(CW$filehandle\fR. |
| 203 |
It returns an object on success and \f(CW\*(C`undef\*(C'\fR on failure. |
| 204 |
.Sp |
| 205 |
When writing a gzip file this interface will \fIalways\fR create the smallest |
| 206 |
possible gzip header (exactly 10 bytes). If you want greater control over |
| 207 |
what gets stored in the gzip header (like the original filename or a |
| 208 |
comment) use IO::Compress::Gzip instead. Similarly if |
| 209 |
you want to read the contents of the gzip header use |
| 210 |
IO::Uncompress::Gunzip. |
| 211 |
.Sp |
| 212 |
The second parameter, \f(CW$mode\fR, is used to specify whether the file is |
| 213 |
opened for reading or writing and to optionally specify a compression |
| 214 |
level and compression strategy when writing. The format of the \f(CW$mode\fR |
| 215 |
parameter is similar to the mode parameter to the 'C' function \f(CW\*(C`fopen\*(C'\fR, |
| 216 |
so "rb" is used to open for reading, "wb" for writing and "ab" for |
| 217 |
appending (writing at the end of the file). |
| 218 |
.Sp |
| 219 |
To specify a compression level when writing, append a digit between 0 |
| 220 |
and 9 to the mode string \-\- 0 means no compression and 9 means maximum |
| 221 |
compression. |
| 222 |
If no compression level is specified Z_DEFAULT_COMPRESSION is used. |
| 223 |
.Sp |
| 224 |
To specify the compression strategy when writing, append 'f' for filtered |
| 225 |
data, 'h' for Huffman only compression, or 'R' for run-length encoding. |
| 226 |
If no strategy is specified Z_DEFAULT_STRATEGY is used. |
| 227 |
.Sp |
| 228 |
So, for example, "wb9" means open for writing with the maximum compression |
| 229 |
using the default strategy and "wb4R" means open for writing with compression |
| 230 |
level 4 and run-length encoding. |
| 231 |
.Sp |
| 232 |
Refer to the \fIzlib\fR documentation for the exact format of the \f(CW$mode\fR |
| 233 |
parameter. |
| 234 |
.ie n .IP "\fR\fB$bytesread\fR\fB = \fR\fB$gz\fR\fB\->gzread($buffer [, \fR\fB$size\fR\fB]) ;\fR" 5 |
| 235 |
.el .IP "\fR\f(CB$bytesread\fR\fB = \fR\f(CB$gz\fR\fB\->gzread($buffer [, \fR\f(CB$size\fR\fB]) ;\fR" 5 |
| 236 |
.IX Item "$bytesread = $gz->gzread($buffer [, $size]) ;" |
| 237 |
Reads \f(CW$size\fR bytes from the compressed file into \f(CW$buffer\fR. If |
| 238 |
\&\f(CW$size\fR is not specified, it will default to 4096. If the scalar |
| 239 |
\&\f(CW$buffer\fR is not large enough, it will be extended automatically. |
| 240 |
.Sp |
| 241 |
Returns the number of bytes actually read. On EOF it returns 0 and in |
| 242 |
the case of an error, \-1. |
| 243 |
.ie n .IP "\fR\fB$bytesread\fR\fB = \fR\fB$gz\fR\fB\->gzreadline($line) ;\fR" 5 |
| 244 |
.el .IP "\fR\f(CB$bytesread\fR\fB = \fR\f(CB$gz\fR\fB\->gzreadline($line) ;\fR" 5 |
| 245 |
.IX Item "$bytesread = $gz->gzreadline($line) ;" |
| 246 |
Reads the next line from the compressed file into \f(CW$line\fR. |
| 247 |
.Sp |
| 248 |
Returns the number of bytes actually read. On EOF it returns 0 and in |
| 249 |
the case of an error, \-1. |
| 250 |
.Sp |
| 251 |
It is legal to intermix calls to \f(CW\*(C`gzread\*(C'\fR and \f(CW\*(C`gzreadline\*(C'\fR. |
| 252 |
.Sp |
| 253 |
To maintain backward compatibility with version 1.x of this module |
| 254 |
\&\f(CW\*(C`gzreadline\*(C'\fR ignores the \f(CW$/\fR variable \- it \fIalways\fR uses the string |
| 255 |
\&\f(CW"\en"\fR as the line delimiter. |
| 256 |
.Sp |
| 257 |
If you want to read a gzip file a line at a time and have it respect the |
| 258 |
\&\f(CW$/\fR variable (or \f(CW$INPUT_RECORD_SEPARATOR\fR, or \f(CW$RS\fR when \f(CW\*(C`English\*(C'\fR is |
| 259 |
in use) see IO::Uncompress::Gunzip. |
| 260 |
.ie n .IP "\fR\fB$byteswritten\fR\fB = \fR\fB$gz\fR\fB\->gzwrite($buffer) ;\fR" 5 |
| 261 |
.el .IP "\fR\f(CB$byteswritten\fR\fB = \fR\f(CB$gz\fR\fB\->gzwrite($buffer) ;\fR" 5 |
| 262 |
.IX Item "$byteswritten = $gz->gzwrite($buffer) ;" |
| 263 |
Writes the contents of \f(CW$buffer\fR to the compressed file. Returns the |
| 264 |
number of bytes actually written, or 0 on error. |
| 265 |
.ie n .IP "\fR\fB$status\fR\fB = \fR\fB$gz\fR\fB\->gzflush($flush_type) ;\fR" 5 |
| 266 |
.el .IP "\fR\f(CB$status\fR\fB = \fR\f(CB$gz\fR\fB\->gzflush($flush_type) ;\fR" 5 |
| 267 |
.IX Item "$status = $gz->gzflush($flush_type) ;" |
| 268 |
Flushes all pending output into the compressed file. |
| 269 |
.Sp |
| 270 |
This method takes an optional parameter, \f(CW$flush_type\fR, that controls |
| 271 |
how the flushing will be carried out. By default the \f(CW$flush_type\fR |
| 272 |
used is \f(CW\*(C`Z_FINISH\*(C'\fR. Other valid values for \f(CW$flush_type\fR are |
| 273 |
\&\f(CW\*(C`Z_NO_FLUSH\*(C'\fR, \f(CW\*(C`Z_SYNC_FLUSH\*(C'\fR, \f(CW\*(C`Z_FULL_FLUSH\*(C'\fR and \f(CW\*(C`Z_BLOCK\*(C'\fR. It is |
| 274 |
strongly recommended that you only set the \f(CW\*(C`flush_type\*(C'\fR parameter if |
| 275 |
you fully understand the implications of what it does \- overuse of \f(CW\*(C`flush\*(C'\fR |
| 276 |
can seriously degrade the level of compression achieved. See the \f(CW\*(C`zlib\*(C'\fR |
| 277 |
documentation for details. |
| 278 |
.Sp |
| 279 |
Returns 0 on success. |
| 280 |
.ie n .IP "\fR\fB$offset\fR\fB = \fR\fB$gz\fR\fB\->gztell() ;\fR" 5 |
| 281 |
.el .IP "\fR\f(CB$offset\fR\fB = \fR\f(CB$gz\fR\fB\->gztell() ;\fR" 5 |
| 282 |
.IX Item "$offset = $gz->gztell() ;" |
| 283 |
Returns the uncompressed file offset. |
| 284 |
.ie n .IP "\fR\fB$status\fR\fB = \fR\fB$gz\fR\fB\->gzseek($offset, \fR\fB$whence\fR\fB) ;\fR" 5 |
| 285 |
.el .IP "\fR\f(CB$status\fR\fB = \fR\f(CB$gz\fR\fB\->gzseek($offset, \fR\f(CB$whence\fR\fB) ;\fR" 5 |
| 286 |
.IX Item "$status = $gz->gzseek($offset, $whence) ;" |
| 287 |
Provides a sub-set of the \f(CW\*(C`seek\*(C'\fR functionality, with the restriction |
| 288 |
that it is only legal to seek forward in the compressed file. |
| 289 |
It is a fatal error to attempt to seek backward. |
| 290 |
.Sp |
| 291 |
When opened for writing, empty parts of the file will have NULL (0x00) |
| 292 |
bytes written to them. |
| 293 |
.Sp |
| 294 |
The \f(CW$whence\fR parameter should be one of SEEK_SET, SEEK_CUR or SEEK_END. |
| 295 |
.Sp |
| 296 |
Returns 1 on success, 0 on failure. |
| 297 |
.ie n .IP \fR\fB$gz\fR\fB\->gzclose\fR 5 |
| 298 |
.el .IP \fR\f(CB$gz\fR\fB\->gzclose\fR 5 |
| 299 |
.IX Item "$gz->gzclose" |
| 300 |
Closes the compressed file. Any pending data is flushed to the file |
| 301 |
before it is closed. |
| 302 |
.Sp |
| 303 |
Returns 0 on success. |
| 304 |
.ie n .IP "\fR\fB$gz\fR\fB\->gzsetparams($level, \fR\fB$strategy\fR\fB\fR" 5 |
| 305 |
.el .IP "\fR\f(CB$gz\fR\fB\->gzsetparams($level, \fR\f(CB$strategy\fR\fB\fR" 5 |
| 306 |
.IX Item "$gz->gzsetparams($level, $strategy" |
| 307 |
Change settings for the deflate stream \f(CW$gz\fR. |
| 308 |
.Sp |
| 309 |
The list of the valid options is shown below. Options not specified |
| 310 |
will remain unchanged. |
| 311 |
.Sp |
| 312 |
Note: This method is only available if you are running zlib 1.0.6 or better. |
| 313 |
.RS 5 |
| 314 |
.ie n .IP \fR\fB$level\fR\fB\fR 5 |
| 315 |
.el .IP \fR\f(CB$level\fR\fB\fR 5 |
| 316 |
.IX Item "$level" |
| 317 |
Defines the compression level. Valid values are 0 through 9, |
| 318 |
\&\f(CW\*(C`Z_NO_COMPRESSION\*(C'\fR, \f(CW\*(C`Z_BEST_SPEED\*(C'\fR, \f(CW\*(C`Z_BEST_COMPRESSION\*(C'\fR, and |
| 319 |
\&\f(CW\*(C`Z_DEFAULT_COMPRESSION\*(C'\fR. |
| 320 |
.ie n .IP \fR\fB$strategy\fR\fB\fR 5 |
| 321 |
.el .IP \fR\f(CB$strategy\fR\fB\fR 5 |
| 322 |
.IX Item "$strategy" |
| 323 |
Defines the strategy used to tune the compression. The valid values are |
| 324 |
\&\f(CW\*(C`Z_DEFAULT_STRATEGY\*(C'\fR, \f(CW\*(C`Z_FILTERED\*(C'\fR and \f(CW\*(C`Z_HUFFMAN_ONLY\*(C'\fR. |
| 325 |
.RE |
| 326 |
.RS 5 |
| 327 |
.RE |
| 328 |
.ie n .IP \fR\fB$gz\fR\fB\->gzerror\fR 5 |
| 329 |
.el .IP \fR\f(CB$gz\fR\fB\->gzerror\fR 5 |
| 330 |
.IX Item "$gz->gzerror" |
| 331 |
Returns the \fIzlib\fR error message or number for the last operation |
| 332 |
associated with \f(CW$gz\fR. The return value will be the \fIzlib\fR error |
| 333 |
number when used in a numeric context and the \fIzlib\fR error message |
| 334 |
when used in a string context. The \fIzlib\fR error number constants, |
| 335 |
shown below, are available for use. |
| 336 |
.Sp |
| 337 |
.Vb 7 |
| 338 |
\& Z_OK |
| 339 |
\& Z_STREAM_END |
| 340 |
\& Z_ERRNO |
| 341 |
\& Z_STREAM_ERROR |
| 342 |
\& Z_DATA_ERROR |
| 343 |
\& Z_MEM_ERROR |
| 344 |
\& Z_BUF_ERROR |
| 345 |
.Ve |
| 346 |
.ie n .IP \fR\fB$gzerrno\fR\fB\fR 5 |
| 347 |
.el .IP \fR\f(CB$gzerrno\fR\fB\fR 5 |
| 348 |
.IX Item "$gzerrno" |
| 349 |
The \f(CW$gzerrno\fR scalar holds the error code associated with the most |
| 350 |
recent \fIgzip\fR routine. Note that unlike \f(CWgzerror()\fR, the error is |
| 351 |
\&\fInot\fR associated with a particular file. |
| 352 |
.Sp |
| 353 |
As with \f(CWgzerror()\fR it returns an error number in numeric context and |
| 354 |
an error message in string context. Unlike \f(CWgzerror()\fR though, the |
| 355 |
error message will correspond to the \fIzlib\fR message when the error is |
| 356 |
associated with \fIzlib\fR itself, or the UNIX error message when it is |
| 357 |
not (i.e. \fIzlib\fR returned \f(CW\*(C`Z_ERRORNO\*(C'\fR). |
| 358 |
.Sp |
| 359 |
As there is an overlap between the error numbers used by \fIzlib\fR and |
| 360 |
UNIX, \f(CW$gzerrno\fR should only be used to check for the presence of |
| 361 |
\&\fIan\fR error in numeric context. Use \f(CWgzerror()\fR to check for specific |
| 362 |
\&\fIzlib\fR errors. The \fIgzcat\fR example below shows how the variable can |
| 363 |
be used safely. |
| 364 |
.SS Examples |
| 365 |
.IX Subsection "Examples" |
| 366 |
Here is an example script which uses the interface. It implements a |
| 367 |
\&\fIgzcat\fR function. |
| 368 |
.PP |
| 369 |
.Vb 2 |
| 370 |
\& use strict ; |
| 371 |
\& use warnings ; |
| 372 |
\& |
| 373 |
\& use Compress::Zlib ; |
| 374 |
\& |
| 375 |
\& # use stdin if no files supplied |
| 376 |
\& @ARGV = \*(Aq\-\*(Aq unless @ARGV ; |
| 377 |
\& |
| 378 |
\& foreach my $file (@ARGV) { |
| 379 |
\& my $buffer ; |
| 380 |
\& |
| 381 |
\& my $gz = gzopen($file, "rb") |
| 382 |
\& or die "Cannot open $file: $gzerrno\en" ; |
| 383 |
\& |
| 384 |
\& print $buffer while $gz\->gzread($buffer) > 0 ; |
| 385 |
\& |
| 386 |
\& die "Error reading from $file: $gzerrno" . ($gzerrno+0) . "\en" |
| 387 |
\& if $gzerrno != Z_STREAM_END ; |
| 388 |
\& |
| 389 |
\& $gz\->gzclose() ; |
| 390 |
\& } |
| 391 |
.Ve |
| 392 |
.PP |
| 393 |
Below is a script which makes use of \f(CW\*(C`gzreadline\*(C'\fR. It implements a |
| 394 |
very simple \fIgrep\fR like script. |
| 395 |
.PP |
| 396 |
.Vb 2 |
| 397 |
\& use strict ; |
| 398 |
\& use warnings ; |
| 399 |
\& |
| 400 |
\& use Compress::Zlib ; |
| 401 |
\& |
| 402 |
\& die "Usage: gzgrep pattern [file...]\en" |
| 403 |
\& unless @ARGV >= 1; |
| 404 |
\& |
| 405 |
\& my $pattern = shift ; |
| 406 |
\& |
| 407 |
\& # use stdin if no files supplied |
| 408 |
\& @ARGV = \*(Aq\-\*(Aq unless @ARGV ; |
| 409 |
\& |
| 410 |
\& foreach my $file (@ARGV) { |
| 411 |
\& my $gz = gzopen($file, "rb") |
| 412 |
\& or die "Cannot open $file: $gzerrno\en" ; |
| 413 |
\& |
| 414 |
\& while ($gz\->gzreadline($_) > 0) { |
| 415 |
\& print if /$pattern/ ; |
| 416 |
\& } |
| 417 |
\& |
| 418 |
\& die "Error reading from $file: $gzerrno\en" |
| 419 |
\& if $gzerrno != Z_STREAM_END ; |
| 420 |
\& |
| 421 |
\& $gz\->gzclose() ; |
| 422 |
\& } |
| 423 |
.Ve |
| 424 |
.PP |
| 425 |
This script, \fIgzstream\fR, does the opposite of the \fIgzcat\fR script |
| 426 |
above. It reads from standard input and writes a gzip data stream to |
| 427 |
standard output. |
| 428 |
.PP |
| 429 |
.Vb 2 |
| 430 |
\& use strict ; |
| 431 |
\& use warnings ; |
| 432 |
\& |
| 433 |
\& use Compress::Zlib ; |
| 434 |
\& |
| 435 |
\& binmode STDOUT; # gzopen only sets it on the fd |
| 436 |
\& |
| 437 |
\& my $gz = gzopen(\e*STDOUT, "wb") |
| 438 |
\& or die "Cannot open stdout: $gzerrno\en" ; |
| 439 |
\& |
| 440 |
\& while (<>) { |
| 441 |
\& $gz\->gzwrite($_) |
| 442 |
\& or die "error writing: $gzerrno\en" ; |
| 443 |
\& } |
| 444 |
\& |
| 445 |
\& $gz\->gzclose ; |
| 446 |
.Ve |
| 447 |
.SS Compress::Zlib::memGzip |
| 448 |
.IX Subsection "Compress::Zlib::memGzip" |
| 449 |
This function is used to create an in-memory gzip file with the minimum |
| 450 |
possible gzip header (exactly 10 bytes). |
| 451 |
.PP |
| 452 |
.Vb 2 |
| 453 |
\& $dest = Compress::Zlib::memGzip($buffer) |
| 454 |
\& or die "Cannot compress: $gzerrno\en"; |
| 455 |
.Ve |
| 456 |
.PP |
| 457 |
If successful, it returns the in-memory gzip file. Otherwise it returns |
| 458 |
\&\f(CW\*(C`undef\*(C'\fR and the \f(CW$gzerrno\fR variable will store the zlib error code. |
| 459 |
.PP |
| 460 |
The \f(CW$buffer\fR parameter can either be a scalar or a scalar reference. |
| 461 |
.PP |
| 462 |
See IO::Compress::Gzip for an alternative way to |
| 463 |
carry out in-memory gzip compression. |
| 464 |
.SS Compress::Zlib::memGunzip |
| 465 |
.IX Subsection "Compress::Zlib::memGunzip" |
| 466 |
This function is used to uncompress an in-memory gzip file. |
| 467 |
.PP |
| 468 |
.Vb 2 |
| 469 |
\& $dest = Compress::Zlib::memGunzip($buffer) |
| 470 |
\& or die "Cannot uncompress: $gzerrno\en"; |
| 471 |
.Ve |
| 472 |
.PP |
| 473 |
If successful, it returns the uncompressed gzip file. Otherwise it |
| 474 |
returns \f(CW\*(C`undef\*(C'\fR and the \f(CW$gzerrno\fR variable will store the zlib error |
| 475 |
code. |
| 476 |
.PP |
| 477 |
The \f(CW$buffer\fR parameter can either be a scalar or a scalar reference. The |
| 478 |
contents of the \f(CW$buffer\fR parameter are destroyed after calling this function. |
| 479 |
.PP |
| 480 |
If \f(CW$buffer\fR consists of multiple concatenated gzip data streams only the |
| 481 |
first will be uncompressed. Use \f(CW\*(C`gunzip\*(C'\fR with the \f(CW\*(C`MultiStream\*(C'\fR option in |
| 482 |
the \f(CW\*(C`IO::Uncompress::Gunzip\*(C'\fR module if you need to deal with concatenated |
| 483 |
data streams. |
| 484 |
.PP |
| 485 |
See IO::Uncompress::Gunzip for an alternative way |
| 486 |
to carry out in-memory gzip uncompression. |
| 487 |
.SH COMPRESS/UNCOMPRESS |
| 488 |
.IX Header "COMPRESS/UNCOMPRESS" |
| 489 |
Two functions are provided to perform in-memory compression/uncompression of |
| 490 |
RFC 1950 data streams. They are called \f(CW\*(C`compress\*(C'\fR and \f(CW\*(C`uncompress\*(C'\fR. |
| 491 |
.ie n .IP "\fR\fB$dest\fR\fB = compress($source [, \fR\fB$level\fR\fB] ) ;\fR" 5 |
| 492 |
.el .IP "\fR\f(CB$dest\fR\fB = compress($source [, \fR\f(CB$level\fR\fB] ) ;\fR" 5 |
| 493 |
.IX Item "$dest = compress($source [, $level] ) ;" |
| 494 |
Compresses \f(CW$source\fR. If successful it returns the compressed |
| 495 |
data. Otherwise it returns \fIundef\fR. |
| 496 |
.Sp |
| 497 |
The source buffer, \f(CW$source\fR, can either be a scalar or a scalar |
| 498 |
reference. |
| 499 |
.Sp |
| 500 |
The \f(CW$level\fR parameter defines the compression level. Valid values are |
| 501 |
0 through 9, \f(CW\*(C`Z_NO_COMPRESSION\*(C'\fR, \f(CW\*(C`Z_BEST_SPEED\*(C'\fR, |
| 502 |
\&\f(CW\*(C`Z_BEST_COMPRESSION\*(C'\fR, and \f(CW\*(C`Z_DEFAULT_COMPRESSION\*(C'\fR. |
| 503 |
If \f(CW$level\fR is not specified \f(CW\*(C`Z_DEFAULT_COMPRESSION\*(C'\fR will be used. |
| 504 |
.ie n .IP "\fR\fB$dest\fR\fB = uncompress($source) ;\fR" 5 |
| 505 |
.el .IP "\fR\f(CB$dest\fR\fB = uncompress($source) ;\fR" 5 |
| 506 |
.IX Item "$dest = uncompress($source) ;" |
| 507 |
Uncompresses \f(CW$source\fR. If successful it returns the uncompressed |
| 508 |
data. Otherwise it returns \fIundef\fR. |
| 509 |
.Sp |
| 510 |
The source buffer can either be a scalar or a scalar reference. |
| 511 |
.PP |
| 512 |
Please note: the two functions defined above are \fInot\fR compatible with |
| 513 |
the Unix commands of the same name. |
| 514 |
.PP |
| 515 |
See IO::Deflate and IO::Inflate included with |
| 516 |
this distribution for an alternative interface for reading/writing RFC 1950 |
| 517 |
files/buffers. |
| 518 |
.SH "Deflate Interface" |
| 519 |
.IX Header "Deflate Interface" |
| 520 |
This section defines an interface that allows in-memory compression using |
| 521 |
the \fIdeflate\fR interface provided by zlib. |
| 522 |
.PP |
| 523 |
Here is a definition of the interface available: |
| 524 |
.ie n .SS "\fB($d, \fP\fB$status\fP\fB) = deflateInit( [OPT] )\fP" |
| 525 |
.el .SS "\fB($d, \fP\f(CB$status\fP\fB) = deflateInit( [OPT] )\fP" |
| 526 |
.IX Subsection "($d, $status) = deflateInit( [OPT] )" |
| 527 |
Initialises a deflation stream. |
| 528 |
.PP |
| 529 |
It combines the features of the \fIzlib\fR functions \f(CW\*(C`deflateInit\*(C'\fR, |
| 530 |
\&\f(CW\*(C`deflateInit2\*(C'\fR and \f(CW\*(C`deflateSetDictionary\*(C'\fR. |
| 531 |
.PP |
| 532 |
If successful, it will return the initialised deflation stream, \f(CW$d\fR |
| 533 |
and \f(CW$status\fR of \f(CW\*(C`Z_OK\*(C'\fR in a list context. In scalar context it |
| 534 |
returns the deflation stream, \f(CW$d\fR, only. |
| 535 |
.PP |
| 536 |
If not successful, the returned deflation stream (\f(CW$d\fR) will be |
| 537 |
\&\fIundef\fR and \f(CW$status\fR will hold the exact \fIzlib\fR error code. |
| 538 |
.PP |
| 539 |
The function optionally takes a number of named options specified as |
| 540 |
\&\f(CW\*(C`\-Name=>value\*(C'\fR pairs. This allows individual options to be |
| 541 |
tailored without having to specify them all in the parameter list. |
| 542 |
.PP |
| 543 |
For backward compatibility, it is also possible to pass the parameters |
| 544 |
as a reference to a hash containing the name=>value pairs. |
| 545 |
.PP |
| 546 |
The function takes one optional parameter, a reference to a hash. The |
| 547 |
contents of the hash allow the deflation interface to be tailored. |
| 548 |
.PP |
| 549 |
Here is a list of the valid options: |
| 550 |
.IP \fB\-Level\fR 5 |
| 551 |
.IX Item "-Level" |
| 552 |
Defines the compression level. Valid values are 0 through 9, |
| 553 |
\&\f(CW\*(C`Z_NO_COMPRESSION\*(C'\fR, \f(CW\*(C`Z_BEST_SPEED\*(C'\fR, \f(CW\*(C`Z_BEST_COMPRESSION\*(C'\fR, and |
| 554 |
\&\f(CW\*(C`Z_DEFAULT_COMPRESSION\*(C'\fR. |
| 555 |
.Sp |
| 556 |
The default is Z_DEFAULT_COMPRESSION. |
| 557 |
.IP \fB\-Method\fR 5 |
| 558 |
.IX Item "-Method" |
| 559 |
Defines the compression method. The only valid value at present (and |
| 560 |
the default) is Z_DEFLATED. |
| 561 |
.IP \fB\-WindowBits\fR 5 |
| 562 |
.IX Item "-WindowBits" |
| 563 |
To create an RFC 1950 data stream, set \f(CW\*(C`WindowBits\*(C'\fR to a positive number. |
| 564 |
.Sp |
| 565 |
To create an RFC 1951 data stream, set \f(CW\*(C`WindowBits\*(C'\fR to \f(CW\*(C`\-MAX_WBITS\*(C'\fR. |
| 566 |
.Sp |
| 567 |
For a full definition of the meaning and valid values for \f(CW\*(C`WindowBits\*(C'\fR refer |
| 568 |
to the \fIzlib\fR documentation for \fIdeflateInit2\fR. |
| 569 |
.Sp |
| 570 |
Defaults to MAX_WBITS. |
| 571 |
.IP \fB\-MemLevel\fR 5 |
| 572 |
.IX Item "-MemLevel" |
| 573 |
For a definition of the meaning and valid values for \f(CW\*(C`MemLevel\*(C'\fR |
| 574 |
refer to the \fIzlib\fR documentation for \fIdeflateInit2\fR. |
| 575 |
.Sp |
| 576 |
Defaults to MAX_MEM_LEVEL. |
| 577 |
.IP \fB\-Strategy\fR 5 |
| 578 |
.IX Item "-Strategy" |
| 579 |
Defines the strategy used to tune the compression. The valid values are |
| 580 |
\&\f(CW\*(C`Z_DEFAULT_STRATEGY\*(C'\fR, \f(CW\*(C`Z_FILTERED\*(C'\fR and \f(CW\*(C`Z_HUFFMAN_ONLY\*(C'\fR. |
| 581 |
.Sp |
| 582 |
The default is Z_DEFAULT_STRATEGY. |
| 583 |
.IP \fB\-Dictionary\fR 5 |
| 584 |
.IX Item "-Dictionary" |
| 585 |
When a dictionary is specified \fICompress::Zlib\fR will automatically |
| 586 |
call \f(CW\*(C`deflateSetDictionary\*(C'\fR directly after calling \f(CW\*(C`deflateInit\*(C'\fR. The |
| 587 |
Adler32 value for the dictionary can be obtained by calling the method |
| 588 |
\&\f(CW\*(C`$d\->dict_adler()\*(C'\fR. |
| 589 |
.Sp |
| 590 |
The default is no dictionary. |
| 591 |
.IP \fB\-Bufsize\fR 5 |
| 592 |
.IX Item "-Bufsize" |
| 593 |
Sets the initial size for the deflation buffer. If the buffer has to be |
| 594 |
reallocated to increase the size, it will grow in increments of |
| 595 |
\&\f(CW\*(C`Bufsize\*(C'\fR. |
| 596 |
.Sp |
| 597 |
The default is 4096. |
| 598 |
.PP |
| 599 |
Here is an example of using the \f(CW\*(C`deflateInit\*(C'\fR optional parameter list |
| 600 |
to override the default buffer size and compression level. All other |
| 601 |
options will take their default values. |
| 602 |
.PP |
| 603 |
.Vb 2 |
| 604 |
\& deflateInit( \-Bufsize => 300, |
| 605 |
\& \-Level => Z_BEST_SPEED ) ; |
| 606 |
.Ve |
| 607 |
.ie n .SS "\fB($out, \fP\fB$status\fP\fB) = \fP\fB$d\fP\fB\->deflate($buffer)\fP" |
| 608 |
.el .SS "\fB($out, \fP\f(CB$status\fP\fB) = \fP\f(CB$d\fP\fB\->deflate($buffer)\fP" |
| 609 |
.IX Subsection "($out, $status) = $d->deflate($buffer)" |
| 610 |
Deflates the contents of \f(CW$buffer\fR. The buffer can either be a scalar |
| 611 |
or a scalar reference. When finished, \f(CW$buffer\fR will be |
| 612 |
completely processed (assuming there were no errors). If the deflation |
| 613 |
was successful it returns the deflated output, \f(CW$out\fR, and a status |
| 614 |
value, \f(CW$status\fR, of \f(CW\*(C`Z_OK\*(C'\fR. |
| 615 |
.PP |
| 616 |
On error, \f(CW$out\fR will be \fIundef\fR and \f(CW$status\fR will contain the |
| 617 |
\&\fIzlib\fR error code. |
| 618 |
.PP |
| 619 |
In a scalar context \f(CW\*(C`deflate\*(C'\fR will return \f(CW$out\fR only. |
| 620 |
.PP |
| 621 |
As with the \fIdeflate\fR function in \fIzlib\fR, it is not necessarily the |
| 622 |
case that any output will be produced by this method. So don't rely on |
| 623 |
the fact that \f(CW$out\fR is empty for an error test. |
| 624 |
.ie n .SS "\fB($out, \fP\fB$status\fP\fB) = \fP\fB$d\fP\fB\->flush()\fP =head2 \fB($out, \fP\fB$status\fP\fB) = \fP\fB$d\fP\fB\->flush($flush_type)\fP" |
| 625 |
.el .SS "\fB($out, \fP\f(CB$status\fP\fB) = \fP\f(CB$d\fP\fB\->flush()\fP =head2 \fB($out, \fP\f(CB$status\fP\fB) = \fP\f(CB$d\fP\fB\->flush($flush_type)\fP" |
| 626 |
.IX Subsection "($out, $status) = $d->flush() =head2 ($out, $status) = $d->flush($flush_type)" |
| 627 |
Typically used to finish the deflation. Any pending output will be |
| 628 |
returned via \f(CW$out\fR. |
| 629 |
\&\f(CW$status\fR will have a value \f(CW\*(C`Z_OK\*(C'\fR if successful. |
| 630 |
.PP |
| 631 |
In a scalar context \f(CW\*(C`flush\*(C'\fR will return \f(CW$out\fR only. |
| 632 |
.PP |
| 633 |
Note that flushing can seriously degrade the compression ratio, so it |
| 634 |
should only be used to terminate a decompression (using \f(CW\*(C`Z_FINISH\*(C'\fR) or |
| 635 |
when you want to create a \fIfull flush point\fR (using \f(CW\*(C`Z_FULL_FLUSH\*(C'\fR). |
| 636 |
.PP |
| 637 |
By default the \f(CW\*(C`flush_type\*(C'\fR used is \f(CW\*(C`Z_FINISH\*(C'\fR. Other valid values |
| 638 |
for \f(CW\*(C`flush_type\*(C'\fR are \f(CW\*(C`Z_NO_FLUSH\*(C'\fR, \f(CW\*(C`Z_PARTIAL_FLUSH\*(C'\fR, \f(CW\*(C`Z_SYNC_FLUSH\*(C'\fR |
| 639 |
and \f(CW\*(C`Z_FULL_FLUSH\*(C'\fR. It is strongly recommended that you only set the |
| 640 |
\&\f(CW\*(C`flush_type\*(C'\fR parameter if you fully understand the implications of |
| 641 |
what it does. See the \f(CW\*(C`zlib\*(C'\fR documentation for details. |
| 642 |
.ie n .SS "\fB\fP\fB$status\fP\fB = \fP\fB$d\fP\fB\->deflateParams([OPT])\fP" |
| 643 |
.el .SS "\fB\fP\f(CB$status\fP\fB = \fP\f(CB$d\fP\fB\->deflateParams([OPT])\fP" |
| 644 |
.IX Subsection "$status = $d->deflateParams([OPT])" |
| 645 |
Change settings for the deflate stream \f(CW$d\fR. |
| 646 |
.PP |
| 647 |
The list of the valid options is shown below. Options not specified |
| 648 |
will remain unchanged. |
| 649 |
.IP \fB\-Level\fR 5 |
| 650 |
.IX Item "-Level" |
| 651 |
Defines the compression level. Valid values are 0 through 9, |
| 652 |
\&\f(CW\*(C`Z_NO_COMPRESSION\*(C'\fR, \f(CW\*(C`Z_BEST_SPEED\*(C'\fR, \f(CW\*(C`Z_BEST_COMPRESSION\*(C'\fR, and |
| 653 |
\&\f(CW\*(C`Z_DEFAULT_COMPRESSION\*(C'\fR. |
| 654 |
.IP \fB\-Strategy\fR 5 |
| 655 |
.IX Item "-Strategy" |
| 656 |
Defines the strategy used to tune the compression. The valid values are |
| 657 |
\&\f(CW\*(C`Z_DEFAULT_STRATEGY\*(C'\fR, \f(CW\*(C`Z_FILTERED\*(C'\fR and \f(CW\*(C`Z_HUFFMAN_ONLY\*(C'\fR. |
| 658 |
.ie n .SS \fB\fP\fB$d\fP\fB\->dict_adler()\fP |
| 659 |
.el .SS \fB\fP\f(CB$d\fP\fB\->dict_adler()\fP |
| 660 |
.IX Subsection "$d->dict_adler()" |
| 661 |
Returns the adler32 value for the dictionary. |
| 662 |
.ie n .SS \fB\fP\fB$d\fP\fB\->msg()\fP |
| 663 |
.el .SS \fB\fP\f(CB$d\fP\fB\->msg()\fP |
| 664 |
.IX Subsection "$d->msg()" |
| 665 |
Returns the last error message generated by zlib. |
| 666 |
.ie n .SS \fB\fP\fB$d\fP\fB\->total_in()\fP |
| 667 |
.el .SS \fB\fP\f(CB$d\fP\fB\->total_in()\fP |
| 668 |
.IX Subsection "$d->total_in()" |
| 669 |
Returns the total number of bytes uncompressed bytes input to deflate. |
| 670 |
.ie n .SS \fB\fP\fB$d\fP\fB\->total_out()\fP |
| 671 |
.el .SS \fB\fP\f(CB$d\fP\fB\->total_out()\fP |
| 672 |
.IX Subsection "$d->total_out()" |
| 673 |
Returns the total number of compressed bytes output from deflate. |
| 674 |
.SS Example |
| 675 |
.IX Subsection "Example" |
| 676 |
Here is a trivial example of using \f(CW\*(C`deflate\*(C'\fR. It simply reads standard |
| 677 |
input, deflates it and writes it to standard output. |
| 678 |
.PP |
| 679 |
.Vb 2 |
| 680 |
\& use strict ; |
| 681 |
\& use warnings ; |
| 682 |
\& |
| 683 |
\& use Compress::Zlib ; |
| 684 |
\& |
| 685 |
\& binmode STDIN; |
| 686 |
\& binmode STDOUT; |
| 687 |
\& my $x = deflateInit() |
| 688 |
\& or die "Cannot create a deflation stream\en" ; |
| 689 |
\& |
| 690 |
\& my ($output, $status) ; |
| 691 |
\& while (<>) |
| 692 |
\& { |
| 693 |
\& ($output, $status) = $x\->deflate($_) ; |
| 694 |
\& |
| 695 |
\& $status == Z_OK |
| 696 |
\& or die "deflation failed\en" ; |
| 697 |
\& |
| 698 |
\& print $output ; |
| 699 |
\& } |
| 700 |
\& |
| 701 |
\& ($output, $status) = $x\->flush() ; |
| 702 |
\& |
| 703 |
\& $status == Z_OK |
| 704 |
\& or die "deflation failed\en" ; |
| 705 |
\& |
| 706 |
\& print $output ; |
| 707 |
.Ve |
| 708 |
.SH "Inflate Interface" |
| 709 |
.IX Header "Inflate Interface" |
| 710 |
This section defines the interface available that allows in-memory |
| 711 |
uncompression using the \fIdeflate\fR interface provided by zlib. |
| 712 |
.PP |
| 713 |
Here is a definition of the interface: |
| 714 |
.ie n .SS "\fB($i, \fP\fB$status\fP\fB) = inflateInit()\fP" |
| 715 |
.el .SS "\fB($i, \fP\f(CB$status\fP\fB) = inflateInit()\fP" |
| 716 |
.IX Subsection "($i, $status) = inflateInit()" |
| 717 |
Initialises an inflation stream. |
| 718 |
.PP |
| 719 |
In a list context it returns the inflation stream, \f(CW$i\fR, and the |
| 720 |
\&\fIzlib\fR status code in \f(CW$status\fR. In a scalar context it returns the |
| 721 |
inflation stream only. |
| 722 |
.PP |
| 723 |
If successful, \f(CW$i\fR will hold the inflation stream and \f(CW$status\fR will |
| 724 |
be \f(CW\*(C`Z_OK\*(C'\fR. |
| 725 |
.PP |
| 726 |
If not successful, \f(CW$i\fR will be \fIundef\fR and \f(CW$status\fR will hold the |
| 727 |
\&\fIzlib\fR error code. |
| 728 |
.PP |
| 729 |
The function optionally takes a number of named options specified as |
| 730 |
\&\f(CW\*(C`\-Name=>value\*(C'\fR pairs. This allows individual options to be |
| 731 |
tailored without having to specify them all in the parameter list. |
| 732 |
.PP |
| 733 |
For backward compatibility, it is also possible to pass the parameters |
| 734 |
as a reference to a hash containing the name=>value pairs. |
| 735 |
.PP |
| 736 |
The function takes one optional parameter, a reference to a hash. The |
| 737 |
contents of the hash allow the deflation interface to be tailored. |
| 738 |
.PP |
| 739 |
Here is a list of the valid options: |
| 740 |
.IP \fB\-WindowBits\fR 5 |
| 741 |
.IX Item "-WindowBits" |
| 742 |
To uncompress an RFC 1950 data stream, set \f(CW\*(C`WindowBits\*(C'\fR to a positive number. |
| 743 |
.Sp |
| 744 |
To uncompress an RFC 1951 data stream, set \f(CW\*(C`WindowBits\*(C'\fR to \f(CW\*(C`\-MAX_WBITS\*(C'\fR. |
| 745 |
.Sp |
| 746 |
For a full definition of the meaning and valid values for \f(CW\*(C`WindowBits\*(C'\fR refer |
| 747 |
to the \fIzlib\fR documentation for \fIinflateInit2\fR. |
| 748 |
.Sp |
| 749 |
Defaults to MAX_WBITS. |
| 750 |
.IP \fB\-Bufsize\fR 5 |
| 751 |
.IX Item "-Bufsize" |
| 752 |
Sets the initial size for the inflation buffer. If the buffer has to be |
| 753 |
reallocated to increase the size, it will grow in increments of |
| 754 |
\&\f(CW\*(C`Bufsize\*(C'\fR. |
| 755 |
.Sp |
| 756 |
Default is 4096. |
| 757 |
.IP \fB\-Dictionary\fR 5 |
| 758 |
.IX Item "-Dictionary" |
| 759 |
The default is no dictionary. |
| 760 |
.PP |
| 761 |
Here is an example of using the \f(CW\*(C`inflateInit\*(C'\fR optional parameter to |
| 762 |
override the default buffer size. |
| 763 |
.PP |
| 764 |
.Vb 1 |
| 765 |
\& inflateInit( \-Bufsize => 300 ) ; |
| 766 |
.Ve |
| 767 |
.ie n .SS "\fB($out, \fP\fB$status\fP\fB) = \fP\fB$i\fP\fB\->inflate($buffer)\fP" |
| 768 |
.el .SS "\fB($out, \fP\f(CB$status\fP\fB) = \fP\f(CB$i\fP\fB\->inflate($buffer)\fP" |
| 769 |
.IX Subsection "($out, $status) = $i->inflate($buffer)" |
| 770 |
Inflates the complete contents of \f(CW$buffer\fR. The buffer can either be |
| 771 |
a scalar or a scalar reference. |
| 772 |
.PP |
| 773 |
Returns \f(CW\*(C`Z_OK\*(C'\fR if successful and \f(CW\*(C`Z_STREAM_END\*(C'\fR if the end of the |
| 774 |
compressed data has been successfully reached. |
| 775 |
If not successful, \f(CW$out\fR will be \fIundef\fR and \f(CW$status\fR will hold |
| 776 |
the \fIzlib\fR error code. |
| 777 |
.PP |
| 778 |
The \f(CW$buffer\fR parameter is modified by \f(CW\*(C`inflate\*(C'\fR. On completion it |
| 779 |
will contain what remains of the input buffer after inflation. This |
| 780 |
means that \f(CW$buffer\fR will be an empty string when the return status is |
| 781 |
\&\f(CW\*(C`Z_OK\*(C'\fR. When the return status is \f(CW\*(C`Z_STREAM_END\*(C'\fR the \f(CW$buffer\fR |
| 782 |
parameter will contains what (if anything) was stored in the input |
| 783 |
buffer after the deflated data stream. |
| 784 |
.PP |
| 785 |
This feature is useful when processing a file format that encapsulates |
| 786 |
a compressed data stream (e.g. gzip, zip). |
| 787 |
.ie n .SS "\fB\fP\fB$status\fP\fB = \fP\fB$i\fP\fB\->inflateSync($buffer)\fP" |
| 788 |
.el .SS "\fB\fP\f(CB$status\fP\fB = \fP\f(CB$i\fP\fB\->inflateSync($buffer)\fP" |
| 789 |
.IX Subsection "$status = $i->inflateSync($buffer)" |
| 790 |
Scans \f(CW$buffer\fR until it reaches either a \fIfull flush point\fR or the |
| 791 |
end of the buffer. |
| 792 |
.PP |
| 793 |
If a \fIfull flush point\fR is found, \f(CW\*(C`Z_OK\*(C'\fR is returned and \f(CW$buffer\fR |
| 794 |
will be have all data up to the flush point removed. This can then be |
| 795 |
passed to the \f(CW\*(C`deflate\*(C'\fR method. |
| 796 |
.PP |
| 797 |
Any other return code means that a flush point was not found. If more |
| 798 |
data is available, \f(CW\*(C`inflateSync\*(C'\fR can be called repeatedly with more |
| 799 |
compressed data until the flush point is found. |
| 800 |
.ie n .SS \fB\fP\fB$i\fP\fB\->dict_adler()\fP |
| 801 |
.el .SS \fB\fP\f(CB$i\fP\fB\->dict_adler()\fP |
| 802 |
.IX Subsection "$i->dict_adler()" |
| 803 |
Returns the adler32 value for the dictionary. |
| 804 |
.ie n .SS \fB\fP\fB$i\fP\fB\->msg()\fP |
| 805 |
.el .SS \fB\fP\f(CB$i\fP\fB\->msg()\fP |
| 806 |
.IX Subsection "$i->msg()" |
| 807 |
Returns the last error message generated by zlib. |
| 808 |
.ie n .SS \fB\fP\fB$i\fP\fB\->total_in()\fP |
| 809 |
.el .SS \fB\fP\f(CB$i\fP\fB\->total_in()\fP |
| 810 |
.IX Subsection "$i->total_in()" |
| 811 |
Returns the total number of bytes compressed bytes input to inflate. |
| 812 |
.ie n .SS \fB\fP\fB$i\fP\fB\->total_out()\fP |
| 813 |
.el .SS \fB\fP\f(CB$i\fP\fB\->total_out()\fP |
| 814 |
.IX Subsection "$i->total_out()" |
| 815 |
Returns the total number of uncompressed bytes output from inflate. |
| 816 |
.SS Example |
| 817 |
.IX Subsection "Example" |
| 818 |
Here is an example of using \f(CW\*(C`inflate\*(C'\fR. |
| 819 |
.PP |
| 820 |
.Vb 2 |
| 821 |
\& use strict ; |
| 822 |
\& use warnings ; |
| 823 |
\& |
| 824 |
\& use Compress::Zlib ; |
| 825 |
\& |
| 826 |
\& my $x = inflateInit() |
| 827 |
\& or die "Cannot create a inflation stream\en" ; |
| 828 |
\& |
| 829 |
\& my $input = \*(Aq\*(Aq ; |
| 830 |
\& binmode STDIN; |
| 831 |
\& binmode STDOUT; |
| 832 |
\& |
| 833 |
\& my ($output, $status) ; |
| 834 |
\& while (read(STDIN, $input, 4096)) |
| 835 |
\& { |
| 836 |
\& ($output, $status) = $x\->inflate(\e$input) ; |
| 837 |
\& |
| 838 |
\& print $output |
| 839 |
\& if $status == Z_OK or $status == Z_STREAM_END ; |
| 840 |
\& |
| 841 |
\& last if $status != Z_OK ; |
| 842 |
\& } |
| 843 |
\& |
| 844 |
\& die "inflation failed\en" |
| 845 |
\& unless $status == Z_STREAM_END ; |
| 846 |
.Ve |
| 847 |
.SH "CHECKSUM FUNCTIONS" |
| 848 |
.IX Header "CHECKSUM FUNCTIONS" |
| 849 |
Two functions are provided by \fIzlib\fR to calculate checksums. For the |
| 850 |
Perl interface, the order of the two parameters in both functions has |
| 851 |
been reversed. This allows both running checksums and one off |
| 852 |
calculations to be done. |
| 853 |
.PP |
| 854 |
.Vb 2 |
| 855 |
\& $crc = adler32($buffer [,$crc]) ; |
| 856 |
\& $crc = crc32($buffer [,$crc]) ; |
| 857 |
.Ve |
| 858 |
.PP |
| 859 |
The buffer parameters can either be a scalar or a scalar reference. |
| 860 |
.PP |
| 861 |
If the \f(CW$crc\fR parameters is \f(CW\*(C`undef\*(C'\fR, the crc value will be reset. |
| 862 |
.PP |
| 863 |
If you have built this module with zlib 1.2.3 or better, two more |
| 864 |
CRC-related functions are available. |
| 865 |
.PP |
| 866 |
.Vb 2 |
| 867 |
\& $crc = crc32_combine($crc1, $crc2, $len2); |
| 868 |
\& $adler = adler32_combine($adler1, $adler2, $len2); |
| 869 |
.Ve |
| 870 |
.PP |
| 871 |
These functions allow checksums to be merged. |
| 872 |
Refer to the \fIzlib\fR documentation for more details. |
| 873 |
.SH Misc |
| 874 |
.IX Header "Misc" |
| 875 |
.ie n .SS "my $version = \fBCompress::Zlib::zlib_version()\fP;" |
| 876 |
.el .SS "my \f(CW$version\fP = \fBCompress::Zlib::zlib_version()\fP;" |
| 877 |
.IX Subsection "my $version = Compress::Zlib::zlib_version();" |
| 878 |
Returns the version of the zlib library. |
| 879 |
.SH CONSTANTS |
| 880 |
.IX Header "CONSTANTS" |
| 881 |
All the \fIzlib\fR constants are automatically imported when you make use |
| 882 |
of \fICompress::Zlib\fR. |
| 883 |
.SH SUPPORT |
| 884 |
.IX Header "SUPPORT" |
| 885 |
General feedback/questions/bug reports should be sent to |
| 886 |
<https://github.com/pmqs/IO\-Compress/issues> (preferred) or |
| 887 |
<https://rt.cpan.org/Public/Dist/Display.html?Name=IO\-Compress>. |
| 888 |
.SH "SEE ALSO" |
| 889 |
.IX Header "SEE ALSO" |
| 890 |
IO::Compress::Gzip, IO::Uncompress::Gunzip, IO::Compress::Deflate, IO::Uncompress::Inflate, IO::Compress::RawDeflate, IO::Uncompress::RawInflate, IO::Compress::Bzip2, IO::Uncompress::Bunzip2, IO::Compress::Lzma, IO::Uncompress::UnLzma, IO::Compress::Xz, IO::Uncompress::UnXz, IO::Compress::Lzip, IO::Uncompress::UnLzip, IO::Compress::Lzop, IO::Uncompress::UnLzop, IO::Compress::Lzf, IO::Uncompress::UnLzf, IO::Compress::Zstd, IO::Uncompress::UnZstd, IO::Uncompress::AnyInflate, IO::Uncompress::AnyUncompress |
| 891 |
.PP |
| 892 |
IO::Compress::FAQ |
| 893 |
.PP |
| 894 |
File::GlobMapper, Archive::Zip, |
| 895 |
Archive::Tar, |
| 896 |
IO::Zlib |
| 897 |
.PP |
| 898 |
For RFC 1950, 1951 and 1952 see |
| 899 |
<https://datatracker.ietf.org/doc/html/rfc1950>, |
| 900 |
<https://datatracker.ietf.org/doc/html/rfc1951> and |
| 901 |
<https://datatracker.ietf.org/doc/html/rfc1952> |
| 902 |
.PP |
| 903 |
The \fIzlib\fR compression library was written by Jean-loup Gailly |
| 904 |
\&\f(CW\*(C`[email protected]\*(C'\fR and Mark Adler \f(CW\*(C`[email protected]\*(C'\fR. |
| 905 |
.PP |
| 906 |
The primary site for the \fIzlib\fR compression library is |
| 907 |
<http://www.zlib.org>. |
| 908 |
.PP |
| 909 |
The primary site for the \fIzlib-ng\fR compression library is |
| 910 |
<https://github.com/zlib\-ng/zlib\-ng>. |
| 911 |
.PP |
| 912 |
The primary site for gzip is <http://www.gzip.org>. |
| 913 |
.SH AUTHOR |
| 914 |
.IX Header "AUTHOR" |
| 915 |
This module was written by Paul Marquess, \f(CW\*(C`[email protected]\*(C'\fR. |
| 916 |
.SH "MODIFICATION HISTORY" |
| 917 |
.IX Header "MODIFICATION HISTORY" |
| 918 |
See the Changes file. |
| 919 |
.SH "COPYRIGHT AND LICENSE" |
| 920 |
.IX Header "COPYRIGHT AND LICENSE" |
| 921 |
Copyright (c) 1995\-2024 Paul Marquess. All rights reserved. |
| 922 |
.PP |
| 923 |
This program is free software; you can redistribute it and/or |
| 924 |
modify it under the same terms as Perl itself. |