1Compress::Zlib(3)     User Contributed Perl Documentation    Compress::Zlib(3)
2
3
4

NAME

6       Compress::Zlib - Interface to zlib compression library
7

SYNOPSIS

9           use Compress::Zlib ;
10
11           ($d, $status) = deflateInit( [OPT] ) ;
12           $status = $d->deflate($input, $output) ;
13           $status = $d->flush([$flush_type]) ;
14           $d->deflateParams(OPTS) ;
15           $d->deflateTune(OPTS) ;
16           $d->dict_adler() ;
17           $d->crc32() ;
18           $d->adler32() ;
19           $d->total_in() ;
20           $d->total_out() ;
21           $d->msg() ;
22           $d->get_Strategy();
23           $d->get_Level();
24           $d->get_BufSize();
25
26           ($i, $status) = inflateInit( [OPT] ) ;
27           $status = $i->inflate($input, $output [, $eof]) ;
28           $status = $i->inflateSync($input) ;
29           $i->dict_adler() ;
30           $d->crc32() ;
31           $d->adler32() ;
32           $i->total_in() ;
33           $i->total_out() ;
34           $i->msg() ;
35           $d->get_BufSize();
36
37           $dest = compress($source) ;
38           $dest = uncompress($source) ;
39
40           $gz = gzopen($filename or filehandle, $mode) ;
41           $bytesread = $gz->gzread($buffer [,$size]) ;
42           $bytesread = $gz->gzreadline($line) ;
43           $byteswritten = $gz->gzwrite($buffer) ;
44           $status = $gz->gzflush($flush) ;
45           $offset = $gz->gztell() ;
46           $status = $gz->gzseek($offset, $whence) ;
47           $status = $gz->gzclose() ;
48           $status = $gz->gzeof() ;
49           $status = $gz->gzsetparams($level, $strategy) ;
50           $errstring = $gz->gzerror() ;
51           $gzerrno
52
53           $dest = Compress::Zlib::memGzip($buffer) ;
54           $dest = Compress::Zlib::memGunzip($buffer) ;
55
56           $crc = adler32($buffer [,$crc]) ;
57           $crc = crc32($buffer [,$crc]) ;
58
59           $crc = crc32_combine($crc1, $crc2, $len2);
60           $adler = adler32_combine($adler1, $adler2, $len2);
61
62           my $version = Compress::Raw::Zlib::zlib_version();
63

DESCRIPTION

65       The Compress::Zlib module provides a Perl interface to the zlib
66       compression library (see "AUTHOR" for details about where to get zlib).
67
68       The "Compress::Zlib" module can be split into two general areas of
69       functionality, namely a simple read/write interface to gzip files and a
70       low-level in-memory compression/decompression interface.
71
72       Each of these areas will be discussed in the following sections.
73
74   Notes for users of Compress::Zlib version 1
75       The main change in "Compress::Zlib" version 2.x is that it does not now
76       interface directly to the zlib library. Instead it uses the
77       "IO::Compress::Gzip" and "IO::Uncompress::Gunzip" modules for
78       reading/writing gzip files, and the "Compress::Raw::Zlib" module for
79       some low-level zlib access.
80
81       The interface provided by version 2 of this module should be 100%
82       backward compatible with version 1. If you find a difference in the
83       expected behaviour please contact the author (See "AUTHOR"). See "GZIP
84       INTERFACE"
85
86       With the creation of the "IO::Compress" and "IO::Uncompress" modules no
87       new features are planned for "Compress::Zlib" - the new modules do
88       everything that "Compress::Zlib" does and then some. Development on
89       "Compress::Zlib" will be limited to bug fixes only.
90
91       If you are writing new code, your first port of call should be one of
92       the new "IO::Compress" or "IO::Uncompress" modules.
93

GZIP INTERFACE

95       A number of functions are supplied in zlib for reading and writing gzip
96       files that conform to RFC 1952. This module provides an interface to
97       most of them.
98
99       If you have previously used "Compress::Zlib" 1.x, the following
100       enhancements/changes have been made to the "gzopen" interface:
101
102       1.   If you want to open either STDIN or STDOUT with "gzopen", you can
103            now optionally use the special filename ""-"" as a synonym for
104            "\*STDIN" and "\*STDOUT".
105
106       2.   In "Compress::Zlib" version 1.x, "gzopen" used the zlib library to
107            open the underlying file. This made things especially tricky when
108            a Perl filehandle was passed to "gzopen". Behind the scenes the
109            numeric C file descriptor had to be extracted from the Perl
110            filehandle and this passed to the zlib library.
111
112            Apart from being non-portable to some operating systems, this made
113            it difficult to use "gzopen" in situations where you wanted to
114            extract/create a gzip data stream that is embedded in a larger
115            file, without having to resort to opening and closing the file
116            multiple times.
117
118            It also made it impossible to pass a perl filehandle that wasn't
119            associated with a real filesystem file, like, say, an
120            "IO::String".
121
122            In "Compress::Zlib" version 2.x, the "gzopen" interface has been
123            completely rewritten to use the IO::Compress::Gzip for writing
124            gzip files and IO::Uncompress::Gunzip for reading gzip files. None
125            of the limitations mentioned above apply.
126
127       3.   Addition of "gzseek" to provide a restricted "seek" interface.
128
129       4.   Added "gztell".
130
131       A more complete and flexible interface for reading/writing gzip
132       files/buffers is included with the module "IO-Compress-Zlib". See
133       IO::Compress::Gzip and IO::Uncompress::Gunzip for more details.
134
135       $gz = gzopen($filename, $mode)
136       $gz = gzopen($filehandle, $mode)
137            This function opens either the gzip file $filename for reading or
138            writing or attaches to the opened filehandle, $filehandle.  It
139            returns an object on success and "undef" on failure.
140
141            When writing a gzip file this interface will always create the
142            smallest possible gzip header (exactly 10 bytes). If you want
143            greater control over what gets stored in the gzip header (like the
144            original filename or a comment) use IO::Compress::Gzip instead.
145            Similarly if you want to read the contents of the gzip header use
146            IO::Uncompress::Gunzip.
147
148            The second parameter, $mode, is used to specify whether the file
149            is opened for reading or writing and to optionally specify a
150            compression level and compression strategy when writing. The
151            format of the $mode parameter is similar to the mode parameter to
152            the 'C' function "fopen", so "rb" is used to open for reading,
153            "wb" for writing and "ab" for appending (writing at the end of the
154            file).
155
156            To specify a compression level when writing, append a digit
157            between 0 and 9 to the mode string -- 0 means no compression and 9
158            means maximum compression.  If no compression level is specified
159            Z_DEFAULT_COMPRESSION is used.
160
161            To specify the compression strategy when writing, append 'f' for
162            filtered data, 'h' for Huffman only compression, or 'R' for run-
163            length encoding.  If no strategy is specified Z_DEFAULT_STRATEGY
164            is used.
165
166            So, for example, "wb9" means open for writing with the maximum
167            compression using the default strategy and "wb4R" means open for
168            writing with compression level 4 and run-length encoding.
169
170            Refer to the zlib documentation for the exact format of the $mode
171            parameter.
172
173       $bytesread = $gz->gzread($buffer [, $size]) ;
174            Reads $size bytes from the compressed file into $buffer. If $size
175            is not specified, it will default to 4096. If the scalar $buffer
176            is not large enough, it will be extended automatically.
177
178            Returns the number of bytes actually read. On EOF it returns 0 and
179            in the case of an error, -1.
180
181       $bytesread = $gz->gzreadline($line) ;
182            Reads the next line from the compressed file into $line.
183
184            Returns the number of bytes actually read. On EOF it returns 0 and
185            in the case of an error, -1.
186
187            It is legal to intermix calls to "gzread" and "gzreadline".
188
189            To maintain backward compatibility with version 1.x of this module
190            "gzreadline" ignores the $/ variable - it always uses the string
191            "\n" as the line delimiter.
192
193            If you want to read a gzip file a line at a time and have it
194            respect the $/ variable (or $INPUT_RECORD_SEPARATOR, or $RS when
195            "English" is in use) see IO::Uncompress::Gunzip.
196
197       $byteswritten = $gz->gzwrite($buffer) ;
198            Writes the contents of $buffer to the compressed file. Returns the
199            number of bytes actually written, or 0 on error.
200
201       $status = $gz->gzflush($flush_type) ;
202            Flushes all pending output into the compressed file.
203
204            This method takes an optional parameter, $flush_type, that
205            controls how the flushing will be carried out. By default the
206            $flush_type used is "Z_FINISH". Other valid values for $flush_type
207            are "Z_NO_FLUSH", "Z_SYNC_FLUSH", "Z_FULL_FLUSH" and "Z_BLOCK". It
208            is strongly recommended that you only set the "flush_type"
209            parameter if you fully understand the implications of what it does
210            - overuse of "flush" can seriously degrade the level of
211            compression achieved. See the "zlib" documentation for details.
212
213            Returns 0 on success.
214
215       $offset = $gz->gztell() ;
216            Returns the uncompressed file offset.
217
218       $status = $gz->gzseek($offset, $whence) ;
219            Provides a sub-set of the "seek" functionality, with the
220            restriction that it is only legal to seek forward in the
221            compressed file.  It is a fatal error to attempt to seek backward.
222
223            When opened for writing, empty parts of the file will have NULL
224            (0x00) bytes written to them.
225
226            The $whence parameter should be one of SEEK_SET, SEEK_CUR or
227            SEEK_END.
228
229            Returns 1 on success, 0 on failure.
230
231       $gz->gzclose
232            Closes the compressed file. Any pending data is flushed to the
233            file before it is closed.
234
235            Returns 0 on success.
236
237       $gz->gzsetparams($level, $strategy
238            Change settings for the deflate stream $gz.
239
240            The list of the valid options is shown below. Options not
241            specified will remain unchanged.
242
243            Note: This method is only available if you are running zlib 1.0.6
244            or better.
245
246            $level
247                 Defines the compression level. Valid values are 0 through 9,
248                 "Z_NO_COMPRESSION", "Z_BEST_SPEED", "Z_BEST_COMPRESSION", and
249                 "Z_DEFAULT_COMPRESSION".
250
251            $strategy
252                 Defines the strategy used to tune the compression. The valid
253                 values are "Z_DEFAULT_STRATEGY", "Z_FILTERED" and
254                 "Z_HUFFMAN_ONLY".
255
256       $gz->gzerror
257            Returns the zlib error message or number for the last operation
258            associated with $gz. The return value will be the zlib error
259            number when used in a numeric context and the zlib error message
260            when used in a string context. The zlib error number constants,
261            shown below, are available for use.
262
263                Z_OK
264                Z_STREAM_END
265                Z_ERRNO
266                Z_STREAM_ERROR
267                Z_DATA_ERROR
268                Z_MEM_ERROR
269                Z_BUF_ERROR
270
271       $gzerrno
272            The $gzerrno scalar holds the error code associated with the most
273            recent gzip routine. Note that unlike gzerror(), the error is not
274            associated with a particular file.
275
276            As with gzerror() it returns an error number in numeric context
277            and an error message in string context. Unlike gzerror() though,
278            the error message will correspond to the zlib message when the
279            error is associated with zlib itself, or the UNIX error message
280            when it is not (i.e. zlib returned "Z_ERRORNO").
281
282            As there is an overlap between the error numbers used by zlib and
283            UNIX, $gzerrno should only be used to check for the presence of an
284            error in numeric context. Use gzerror() to check for specific zlib
285            errors. The gzcat example below shows how the variable can be used
286            safely.
287
288   Examples
289       Here is an example script which uses the interface. It implements a
290       gzcat function.
291
292           use strict ;
293           use warnings ;
294
295           use Compress::Zlib ;
296
297           # use stdin if no files supplied
298           @ARGV = '-' unless @ARGV ;
299
300           foreach my $file (@ARGV) {
301               my $buffer ;
302
303               my $gz = gzopen($file, "rb")
304                    or die "Cannot open $file: $gzerrno\n" ;
305
306               print $buffer while $gz->gzread($buffer) > 0 ;
307
308               die "Error reading from $file: $gzerrno" . ($gzerrno+0) . "\n"
309                   if $gzerrno != Z_STREAM_END ;
310
311               $gz->gzclose() ;
312           }
313
314       Below is a script which makes use of "gzreadline". It implements a very
315       simple grep like script.
316
317           use strict ;
318           use warnings ;
319
320           use Compress::Zlib ;
321
322           die "Usage: gzgrep pattern [file...]\n"
323               unless @ARGV >= 1;
324
325           my $pattern = shift ;
326
327           # use stdin if no files supplied
328           @ARGV = '-' unless @ARGV ;
329
330           foreach my $file (@ARGV) {
331               my $gz = gzopen($file, "rb")
332                    or die "Cannot open $file: $gzerrno\n" ;
333
334               while ($gz->gzreadline($_) > 0) {
335                   print if /$pattern/ ;
336               }
337
338               die "Error reading from $file: $gzerrno\n"
339                   if $gzerrno != Z_STREAM_END ;
340
341               $gz->gzclose() ;
342           }
343
344       This script, gzstream, does the opposite of the gzcat script above. It
345       reads from standard input and writes a gzip data stream to standard
346       output.
347
348           use strict ;
349           use warnings ;
350
351           use Compress::Zlib ;
352
353           binmode STDOUT;  # gzopen only sets it on the fd
354
355           my $gz = gzopen(\*STDOUT, "wb")
356                 or die "Cannot open stdout: $gzerrno\n" ;
357
358           while (<>) {
359               $gz->gzwrite($_)
360                 or die "error writing: $gzerrno\n" ;
361           }
362
363           $gz->gzclose ;
364
365   Compress::Zlib::memGzip
366       This function is used to create an in-memory gzip file with the minimum
367       possible gzip header (exactly 10 bytes).
368
369           $dest = Compress::Zlib::memGzip($buffer)
370               or die "Cannot compress: $gzerrno\n";
371
372       If successful, it returns the in-memory gzip file. Otherwise it returns
373       "undef" and the $gzerrno variable will store the zlib error code.
374
375       The $buffer parameter can either be a scalar or a scalar reference.
376
377       See IO::Compress::Gzip for an alternative way to carry out in-memory
378       gzip compression.
379
380   Compress::Zlib::memGunzip
381       This function is used to uncompress an in-memory gzip file.
382
383           $dest = Compress::Zlib::memGunzip($buffer)
384               or die "Cannot uncompress: $gzerrno\n";
385
386       If successful, it returns the uncompressed gzip file. Otherwise it
387       returns "undef" and the $gzerrno variable will store the zlib error
388       code.
389
390       The $buffer parameter can either be a scalar or a scalar reference. The
391       contents of the $buffer parameter are destroyed after calling this
392       function.
393
394       If $buffer consists of multiple concatenated gzip data streams only the
395       first will be uncompressed. Use "gunzip" with the "MultiStream" option
396       in the "IO::Uncompress::Gunzip" module if you need to deal with
397       concatenated data streams.
398
399       See IO::Uncompress::Gunzip for an alternative way to carry out in-
400       memory gzip uncompression.
401

COMPRESS/UNCOMPRESS

403       Two functions are provided to perform in-memory
404       compression/uncompression of RFC 1950 data streams. They are called
405       "compress" and "uncompress".
406
407       $dest = compress($source [, $level] ) ;
408            Compresses $source. If successful it returns the compressed data.
409            Otherwise it returns undef.
410
411            The source buffer, $source, can either be a scalar or a scalar
412            reference.
413
414            The $level parameter defines the compression level. Valid values
415            are 0 through 9, "Z_NO_COMPRESSION", "Z_BEST_SPEED",
416            "Z_BEST_COMPRESSION", and "Z_DEFAULT_COMPRESSION".  If $level is
417            not specified "Z_DEFAULT_COMPRESSION" will be used.
418
419       $dest = uncompress($source) ;
420            Uncompresses $source. If successful it returns the uncompressed
421            data. Otherwise it returns undef.
422
423            The source buffer can either be a scalar or a scalar reference.
424
425       Please note: the two functions defined above are not compatible with
426       the Unix commands of the same name.
427
428       See IO::Deflate and IO::Inflate included with this distribution for an
429       alternative interface for reading/writing RFC 1950 files/buffers.
430

Deflate Interface

432       This section defines an interface that allows in-memory compression
433       using the deflate interface provided by zlib.
434
435       Here is a definition of the interface available:
436
437   ($d, $status) = deflateInit( [OPT] )
438       Initialises a deflation stream.
439
440       It combines the features of the zlib functions "deflateInit",
441       "deflateInit2" and "deflateSetDictionary".
442
443       If successful, it will return the initialised deflation stream, $d and
444       $status of "Z_OK" in a list context. In scalar context it returns the
445       deflation stream, $d, only.
446
447       If not successful, the returned deflation stream ($d) will be undef and
448       $status will hold the exact zlib error code.
449
450       The function optionally takes a number of named options specified as
451       "-Name=>value" pairs. This allows individual options to be tailored
452       without having to specify them all in the parameter list.
453
454       For backward compatibility, it is also possible to pass the parameters
455       as a reference to a hash containing the name=>value pairs.
456
457       The function takes one optional parameter, a reference to a hash.  The
458       contents of the hash allow the deflation interface to be tailored.
459
460       Here is a list of the valid options:
461
462       -Level
463            Defines the compression level. Valid values are 0 through 9,
464            "Z_NO_COMPRESSION", "Z_BEST_SPEED", "Z_BEST_COMPRESSION", and
465            "Z_DEFAULT_COMPRESSION".
466
467            The default is Z_DEFAULT_COMPRESSION.
468
469       -Method
470            Defines the compression method. The only valid value at present
471            (and the default) is Z_DEFLATED.
472
473       -WindowBits
474            To create an RFC 1950 data stream, set "WindowBits" to a positive
475            number.
476
477            To create an RFC 1951 data stream, set "WindowBits" to
478            "-MAX_WBITS".
479
480            For a full definition of the meaning and valid values for
481            "WindowBits" refer to the zlib documentation for deflateInit2.
482
483            Defaults to MAX_WBITS.
484
485       -MemLevel
486            For a definition of the meaning and valid values for "MemLevel"
487            refer to the zlib documentation for deflateInit2.
488
489            Defaults to MAX_MEM_LEVEL.
490
491       -Strategy
492            Defines the strategy used to tune the compression. The valid
493            values are "Z_DEFAULT_STRATEGY", "Z_FILTERED" and
494            "Z_HUFFMAN_ONLY".
495
496            The default is Z_DEFAULT_STRATEGY.
497
498       -Dictionary
499            When a dictionary is specified Compress::Zlib will automatically
500            call "deflateSetDictionary" directly after calling "deflateInit".
501            The Adler32 value for the dictionary can be obtained by calling
502            the method "$d->dict_adler()".
503
504            The default is no dictionary.
505
506       -Bufsize
507            Sets the initial size for the deflation buffer. If the buffer has
508            to be reallocated to increase the size, it will grow in increments
509            of "Bufsize".
510
511            The default is 4096.
512
513       Here is an example of using the "deflateInit" optional parameter list
514       to override the default buffer size and compression level. All other
515       options will take their default values.
516
517           deflateInit( -Bufsize => 300,
518                        -Level => Z_BEST_SPEED  ) ;
519
520   ($out, $status) = $d->deflate($buffer)
521       Deflates the contents of $buffer. The buffer can either be a scalar or
522       a scalar reference.  When finished, $buffer will be completely
523       processed (assuming there were no errors). If the deflation was
524       successful it returns the deflated output, $out, and a status value,
525       $status, of "Z_OK".
526
527       On error, $out will be undef and $status will contain the zlib error
528       code.
529
530       In a scalar context "deflate" will return $out only.
531
532       As with the deflate function in zlib, it is not necessarily the case
533       that any output will be produced by this method. So don't rely on the
534       fact that $out is empty for an error test.
535
536   ($out, $status) = $d->flush() =head2 ($out, $status) =
537       $d->flush($flush_type)
538       Typically used to finish the deflation. Any pending output will be
539       returned via $out.  $status will have a value "Z_OK" if successful.
540
541       In a scalar context "flush" will return $out only.
542
543       Note that flushing can seriously degrade the compression ratio, so it
544       should only be used to terminate a decompression (using "Z_FINISH") or
545       when you want to create a full flush point (using "Z_FULL_FLUSH").
546
547       By default the "flush_type" used is "Z_FINISH". Other valid values for
548       "flush_type" are "Z_NO_FLUSH", "Z_PARTIAL_FLUSH", "Z_SYNC_FLUSH" and
549       "Z_FULL_FLUSH". It is strongly recommended that you only set the
550       "flush_type" parameter if you fully understand the implications of what
551       it does. See the "zlib" documentation for details.
552
553   $status = $d->deflateParams([OPT])
554       Change settings for the deflate stream $d.
555
556       The list of the valid options is shown below. Options not specified
557       will remain unchanged.
558
559       -Level
560            Defines the compression level. Valid values are 0 through 9,
561            "Z_NO_COMPRESSION", "Z_BEST_SPEED", "Z_BEST_COMPRESSION", and
562            "Z_DEFAULT_COMPRESSION".
563
564       -Strategy
565            Defines the strategy used to tune the compression. The valid
566            values are "Z_DEFAULT_STRATEGY", "Z_FILTERED" and
567            "Z_HUFFMAN_ONLY".
568
569   $d->dict_adler()
570       Returns the adler32 value for the dictionary.
571
572   $d->msg()
573       Returns the last error message generated by zlib.
574
575   $d->total_in()
576       Returns the total number of bytes uncompressed bytes input to deflate.
577
578   $d->total_out()
579       Returns the total number of compressed bytes output from deflate.
580
581   Example
582       Here is a trivial example of using "deflate". It simply reads standard
583       input, deflates it and writes it to standard output.
584
585           use strict ;
586           use warnings ;
587
588           use Compress::Zlib ;
589
590           binmode STDIN;
591           binmode STDOUT;
592           my $x = deflateInit()
593              or die "Cannot create a deflation stream\n" ;
594
595           my ($output, $status) ;
596           while (<>)
597           {
598               ($output, $status) = $x->deflate($_) ;
599
600               $status == Z_OK
601                   or die "deflation failed\n" ;
602
603               print $output ;
604           }
605
606           ($output, $status) = $x->flush() ;
607
608           $status == Z_OK
609               or die "deflation failed\n" ;
610
611           print $output ;
612

Inflate Interface

614       This section defines the interface available that allows in-memory
615       uncompression using the deflate interface provided by zlib.
616
617       Here is a definition of the interface:
618
619   ($i, $status) = inflateInit()
620       Initialises an inflation stream.
621
622       In a list context it returns the inflation stream, $i, and the zlib
623       status code in $status. In a scalar context it returns the inflation
624       stream only.
625
626       If successful, $i will hold the inflation stream and $status will be
627       "Z_OK".
628
629       If not successful, $i will be undef and $status will hold the zlib
630       error code.
631
632       The function optionally takes a number of named options specified as
633       "-Name=>value" pairs. This allows individual options to be tailored
634       without having to specify them all in the parameter list.
635
636       For backward compatibility, it is also possible to pass the parameters
637       as a reference to a hash containing the name=>value pairs.
638
639       The function takes one optional parameter, a reference to a hash.  The
640       contents of the hash allow the deflation interface to be tailored.
641
642       Here is a list of the valid options:
643
644       -WindowBits
645            To uncompress an RFC 1950 data stream, set "WindowBits" to a
646            positive number.
647
648            To uncompress an RFC 1951 data stream, set "WindowBits" to
649            "-MAX_WBITS".
650
651            For a full definition of the meaning and valid values for
652            "WindowBits" refer to the zlib documentation for inflateInit2.
653
654            Defaults to MAX_WBITS.
655
656       -Bufsize
657            Sets the initial size for the inflation buffer. If the buffer has
658            to be reallocated to increase the size, it will grow in increments
659            of "Bufsize".
660
661            Default is 4096.
662
663       -Dictionary
664            The default is no dictionary.
665
666       Here is an example of using the "inflateInit" optional parameter to
667       override the default buffer size.
668
669           inflateInit( -Bufsize => 300 ) ;
670
671   ($out, $status) = $i->inflate($buffer)
672       Inflates the complete contents of $buffer. The buffer can either be a
673       scalar or a scalar reference.
674
675       Returns "Z_OK" if successful and "Z_STREAM_END" if the end of the
676       compressed data has been successfully reached.  If not successful, $out
677       will be undef and $status will hold the zlib error code.
678
679       The $buffer parameter is modified by "inflate". On completion it will
680       contain what remains of the input buffer after inflation. This means
681       that $buffer will be an empty string when the return status is "Z_OK".
682       When the return status is "Z_STREAM_END" the $buffer parameter will
683       contains what (if anything) was stored in the input buffer after the
684       deflated data stream.
685
686       This feature is useful when processing a file format that encapsulates
687       a  compressed data stream (e.g. gzip, zip).
688
689   $status = $i->inflateSync($buffer)
690       Scans $buffer until it reaches either a full flush point or the end of
691       the buffer.
692
693       If a full flush point is found, "Z_OK" is returned and $buffer will be
694       have all data up to the flush point removed. This can then be passed to
695       the "deflate" method.
696
697       Any other return code means that a flush point was not found. If more
698       data is available, "inflateSync" can be called repeatedly with more
699       compressed data until the flush point is found.
700
701   $i->dict_adler()
702       Returns the adler32 value for the dictionary.
703
704   $i->msg()
705       Returns the last error message generated by zlib.
706
707   $i->total_in()
708       Returns the total number of bytes compressed bytes input to inflate.
709
710   $i->total_out()
711       Returns the total number of uncompressed bytes output from inflate.
712
713   Example
714       Here is an example of using "inflate".
715
716           use strict ;
717           use warnings ;
718
719           use Compress::Zlib ;
720
721           my $x = inflateInit()
722              or die "Cannot create a inflation stream\n" ;
723
724           my $input = '' ;
725           binmode STDIN;
726           binmode STDOUT;
727
728           my ($output, $status) ;
729           while (read(STDIN, $input, 4096))
730           {
731               ($output, $status) = $x->inflate(\$input) ;
732
733               print $output
734                   if $status == Z_OK or $status == Z_STREAM_END ;
735
736               last if $status != Z_OK ;
737           }
738
739           die "inflation failed\n"
740               unless $status == Z_STREAM_END ;
741

CHECKSUM FUNCTIONS

743       Two functions are provided by zlib to calculate checksums. For the Perl
744       interface, the order of the two parameters in both functions has been
745       reversed. This allows both running checksums and one off calculations
746       to be done.
747
748           $crc = adler32($buffer [,$crc]) ;
749           $crc = crc32($buffer [,$crc]) ;
750
751       The buffer parameters can either be a scalar or a scalar reference.
752
753       If the $crc parameters is "undef", the crc value will be reset.
754
755       If you have built this module with zlib 1.2.3 or better, two more CRC-
756       related functions are available.
757
758           $crc = crc32_combine($crc1, $crc2, $len2);
759           $adler = adler32_combine($adler1, $adler2, $len2);
760
761       These functions allow checksums to be merged.  Refer to the zlib
762       documentation for more details.
763

Misc

765   my $version = Compress::Zlib::zlib_version();
766       Returns the version of the zlib library.
767

CONSTANTS

769       All the zlib constants are automatically imported when you make use of
770       Compress::Zlib.
771

SUPPORT

773       General feedback/questions/bug reports should be sent to
774       <https://github.com/pmqs/IO-Compress/issues> (preferred) or
775       <https://rt.cpan.org/Public/Dist/Display.html?Name=IO-Compress>.
776

SEE ALSO

778       IO::Compress::Gzip, IO::Uncompress::Gunzip, IO::Compress::Deflate,
779       IO::Uncompress::Inflate, IO::Compress::RawDeflate,
780       IO::Uncompress::RawInflate, IO::Compress::Bzip2,
781       IO::Uncompress::Bunzip2, IO::Compress::Lzma, IO::Uncompress::UnLzma,
782       IO::Compress::Xz, IO::Uncompress::UnXz, IO::Compress::Lzip,
783       IO::Uncompress::UnLzip, IO::Compress::Lzop, IO::Uncompress::UnLzop,
784       IO::Compress::Lzf, IO::Uncompress::UnLzf, IO::Compress::Zstd,
785       IO::Uncompress::UnZstd, IO::Uncompress::AnyInflate,
786       IO::Uncompress::AnyUncompress
787
788       IO::Compress::FAQ
789
790       File::GlobMapper, Archive::Zip, Archive::Tar, IO::Zlib
791
792       For RFC 1950, 1951 and 1952 see
793       <https://datatracker.ietf.org/doc/html/rfc1950>,
794       <https://datatracker.ietf.org/doc/html/rfc1951> and
795       <https://datatracker.ietf.org/doc/html/rfc1952>
796
797       The zlib compression library was written by Jean-loup Gailly
798       "gzip@prep.ai.mit.edu" and Mark Adler "madler@alumni.caltech.edu".
799
800       The primary site for the zlib compression library is
801       <http://www.zlib.org>.
802
803       The primary site for the zlib-ng compression library is
804       <https://github.com/zlib-ng/zlib-ng>.
805
806       The primary site for gzip is <http://www.gzip.org>.
807

AUTHOR

809       This module was written by Paul Marquess, "pmqs@cpan.org".
810

MODIFICATION HISTORY

812       See the Changes file.
813
815       Copyright (c) 1995-2023 Paul Marquess. All rights reserved.
816
817       This program is free software; you can redistribute it and/or modify it
818       under the same terms as Perl itself.
819
820
821
822perl v5.38.0                      2023-07-26                 Compress::Zlib(3)
Impressum