1Compress::Zlib(3pm) Perl Programmers Reference Guide Compress::Zlib(3pm)
2
3
4
6 Compress::Zlib - Interface to zlib compression library
7
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 = adler32_combine($crc1, $crc2, $len2)l
60 $crc = crc32_combine($adler1, $adler2, $len2)
61
62 my $version = Compress::Raw::Zlib::zlib_version();
63
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
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 to open either STDIN or STDOUT with "gzopen", you
103 can 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
274 not 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
285 zlib errors. The gzcat example below shows how the variable can be
286 used 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
371 If successful, it returns the in-memory gzip file, otherwise it returns
372 undef.
373
374 The $buffer parameter can either be a scalar or a scalar reference.
375
376 See IO::Compress::Gzip for an alternative way to carry out in-memory
377 gzip compression.
378
379 Compress::Zlib::memGunzip
380 This function is used to uncompress an in-memory gzip file.
381
382 $dest = Compress::Zlib::memGunzip($buffer) ;
383
384 If successful, it returns the uncompressed gzip file, otherwise it
385 returns undef.
386
387 The $buffer parameter can either be a scalar or a scalar reference. The
388 contents of the $buffer parameter are destroyed after calling this
389 function.
390
391 If $buffer consists of multiple concatenated gzip data streams only the
392 first will be uncompressed. Use "gunzip" with the "MultiStream" option
393 in the "IO::Uncompress::Gunzip" module if you need to deal with
394 concatenated data streams.
395
396 See IO::Uncompress::Gunzip for an alternative way to carry out in-
397 memory gzip uncompression.
398
400 Two functions are provided to perform in-memory
401 compression/uncompression of RFC 1950 data streams. They are called
402 "compress" and "uncompress".
403
404 $dest = compress($source [, $level] ) ;
405 Compresses $source. If successful it returns the compressed data.
406 Otherwise it returns undef.
407
408 The source buffer, $source, can either be a scalar or a scalar
409 reference.
410
411 The $level parameter defines the compression level. Valid values
412 are 0 through 9, "Z_NO_COMPRESSION", "Z_BEST_SPEED",
413 "Z_BEST_COMPRESSION", and "Z_DEFAULT_COMPRESSION". If $level is
414 not specified "Z_DEFAULT_COMPRESSION" will be used.
415
416 $dest = uncompress($source) ;
417 Uncompresses $source. If successful it returns the uncompressed
418 data. Otherwise it returns undef.
419
420 The source buffer can either be a scalar or a scalar reference.
421
422 Please note: the two functions defined above are not compatible with
423 the Unix commands of the same name.
424
425 See IO::Deflate and IO::Inflate included with this distribution for an
426 alternative interface for reading/writing RFC 1950 files/buffers.
427
429 This section defines an interface that allows in-memory compression
430 using the deflate interface provided by zlib.
431
432 Here is a definition of the interface available:
433
434 ($d, $status) = deflateInit( [OPT] )
435 Initialises a deflation stream.
436
437 It combines the features of the zlib functions "deflateInit",
438 "deflateInit2" and "deflateSetDictionary".
439
440 If successful, it will return the initialised deflation stream, $d and
441 $status of "Z_OK" in a list context. In scalar context it returns the
442 deflation stream, $d, only.
443
444 If not successful, the returned deflation stream ($d) will be undef and
445 $status will hold the exact zlib error code.
446
447 The function optionally takes a number of named options specified as
448 "-Name=>value" pairs. This allows individual options to be tailored
449 without having to specify them all in the parameter list.
450
451 For backward compatibility, it is also possible to pass the parameters
452 as a reference to a hash containing the name=>value pairs.
453
454 The function takes one optional parameter, a reference to a hash. The
455 contents of the hash allow the deflation interface to be tailored.
456
457 Here is a list of the valid options:
458
459 -Level
460 Defines the compression level. Valid values are 0 through 9,
461 "Z_NO_COMPRESSION", "Z_BEST_SPEED", "Z_BEST_COMPRESSION", and
462 "Z_DEFAULT_COMPRESSION".
463
464 The default is Z_DEFAULT_COMPRESSION.
465
466 -Method
467 Defines the compression method. The only valid value at present
468 (and the default) is Z_DEFLATED.
469
470 -WindowBits
471 To create an RFC 1950 data stream, set "WindowBits" to a positive
472 number.
473
474 To create an RFC 1951 data stream, set "WindowBits" to
475 "-MAX_WBITS".
476
477 For a full definition of the meaning and valid values for
478 "WindowBits" refer to the zlib documentation for deflateInit2.
479
480 Defaults to MAX_WBITS.
481
482 -MemLevel
483 For a definition of the meaning and valid values for "MemLevel"
484 refer to the zlib documentation for deflateInit2.
485
486 Defaults to MAX_MEM_LEVEL.
487
488 -Strategy
489 Defines the strategy used to tune the compression. The valid
490 values are "Z_DEFAULT_STRATEGY", "Z_FILTERED" and
491 "Z_HUFFMAN_ONLY".
492
493 The default is Z_DEFAULT_STRATEGY.
494
495 -Dictionary
496 When a dictionary is specified Compress::Zlib will automatically
497 call "deflateSetDictionary" directly after calling "deflateInit".
498 The Adler32 value for the dictionary can be obtained by calling
499 the method "$d-"dict_adler()>.
500
501 The default is no dictionary.
502
503 -Bufsize
504 Sets the initial size for the deflation buffer. If the buffer has
505 to be reallocated to increase the size, it will grow in increments
506 of "Bufsize".
507
508 The default is 4096.
509
510 Here is an example of using the "deflateInit" optional parameter list
511 to override the default buffer size and compression level. All other
512 options will take their default values.
513
514 deflateInit( -Bufsize => 300,
515 -Level => Z_BEST_SPEED ) ;
516
517 ($out, $status) = $d->deflate($buffer)
518 Deflates the contents of $buffer. The buffer can either be a scalar or
519 a scalar reference. When finished, $buffer will be completely
520 processed (assuming there were no errors). If the deflation was
521 successful it returns the deflated output, $out, and a status value,
522 $status, of "Z_OK".
523
524 On error, $out will be undef and $status will contain the zlib error
525 code.
526
527 In a scalar context "deflate" will return $out only.
528
529 As with the deflate function in zlib, it is not necessarily the case
530 that any output will be produced by this method. So don't rely on the
531 fact that $out is empty for an error test.
532
533 ($out, $status) = $d->flush() =head2 ($out, $status) =
534 $d->flush($flush_type)
535 Typically used to finish the deflation. Any pending output will be
536 returned via $out. $status will have a value "Z_OK" if successful.
537
538 In a scalar context "flush" will return $out only.
539
540 Note that flushing can seriously degrade the compression ratio, so it
541 should only be used to terminate a decompression (using "Z_FINISH") or
542 when you want to create a full flush point (using "Z_FULL_FLUSH").
543
544 By default the "flush_type" used is "Z_FINISH". Other valid values for
545 "flush_type" are "Z_NO_FLUSH", "Z_PARTIAL_FLUSH", "Z_SYNC_FLUSH" and
546 "Z_FULL_FLUSH". It is strongly recommended that you only set the
547 "flush_type" parameter if you fully understand the implications of what
548 it does. See the "zlib" documentation for details.
549
550 $status = $d->deflateParams([OPT])
551 Change settings for the deflate stream $d.
552
553 The list of the valid options is shown below. Options not specified
554 will remain unchanged.
555
556 -Level
557 Defines the compression level. Valid values are 0 through 9,
558 "Z_NO_COMPRESSION", "Z_BEST_SPEED", "Z_BEST_COMPRESSION", and
559 "Z_DEFAULT_COMPRESSION".
560
561 -Strategy
562 Defines the strategy used to tune the compression. The valid
563 values are "Z_DEFAULT_STRATEGY", "Z_FILTERED" and
564 "Z_HUFFMAN_ONLY".
565
566 $d->dict_adler()
567 Returns the adler32 value for the dictionary.
568
569 $d->msg()
570 Returns the last error message generated by zlib.
571
572 $d->total_in()
573 Returns the total number of bytes uncompressed bytes input to deflate.
574
575 $d->total_out()
576 Returns the total number of compressed bytes output from deflate.
577
578 Example
579 Here is a trivial example of using "deflate". It simply reads standard
580 input, deflates it and writes it to standard output.
581
582 use strict ;
583 use warnings ;
584
585 use Compress::Zlib ;
586
587 binmode STDIN;
588 binmode STDOUT;
589 my $x = deflateInit()
590 or die "Cannot create a deflation stream\n" ;
591
592 my ($output, $status) ;
593 while (<>)
594 {
595 ($output, $status) = $x->deflate($_) ;
596
597 $status == Z_OK
598 or die "deflation failed\n" ;
599
600 print $output ;
601 }
602
603 ($output, $status) = $x->flush() ;
604
605 $status == Z_OK
606 or die "deflation failed\n" ;
607
608 print $output ;
609
611 This section defines the interface available that allows in-memory
612 uncompression using the deflate interface provided by zlib.
613
614 Here is a definition of the interface:
615
616 ($i, $status) = inflateInit()
617 Initialises an inflation stream.
618
619 In a list context it returns the inflation stream, $i, and the zlib
620 status code in $status. In a scalar context it returns the inflation
621 stream only.
622
623 If successful, $i will hold the inflation stream and $status will be
624 "Z_OK".
625
626 If not successful, $i will be undef and $status will hold the zlib
627 error code.
628
629 The function optionally takes a number of named options specified as
630 "-Name=>value" pairs. This allows individual options to be tailored
631 without having to specify them all in the parameter list.
632
633 For backward compatibility, it is also possible to pass the parameters
634 as a reference to a hash containing the name=>value pairs.
635
636 The function takes one optional parameter, a reference to a hash. The
637 contents of the hash allow the deflation interface to be tailored.
638
639 Here is a list of the valid options:
640
641 -WindowBits
642 To uncompress an RFC 1950 data stream, set "WindowBits" to a
643 positive number.
644
645 To uncompress an RFC 1951 data stream, set "WindowBits" to
646 "-MAX_WBITS".
647
648 For a full definition of the meaning and valid values for
649 "WindowBits" refer to the zlib documentation for inflateInit2.
650
651 Defaults to MAX_WBITS.
652
653 -Bufsize
654 Sets the initial size for the inflation buffer. If the buffer has
655 to be reallocated to increase the size, it will grow in increments
656 of "Bufsize".
657
658 Default is 4096.
659
660 -Dictionary
661 The default is no dictionary.
662
663 Here is an example of using the "inflateInit" optional parameter to
664 override the default buffer size.
665
666 inflateInit( -Bufsize => 300 ) ;
667
668 ($out, $status) = $i->inflate($buffer)
669 Inflates the complete contents of $buffer. The buffer can either be a
670 scalar or a scalar reference.
671
672 Returns "Z_OK" if successful and "Z_STREAM_END" if the end of the
673 compressed data has been successfully reached. If not successful, $out
674 will be undef and $status will hold the zlib error code.
675
676 The $buffer parameter is modified by "inflate". On completion it will
677 contain what remains of the input buffer after inflation. This means
678 that $buffer will be an empty string when the return status is "Z_OK".
679 When the return status is "Z_STREAM_END" the $buffer parameter will
680 contains what (if anything) was stored in the input buffer after the
681 deflated data stream.
682
683 This feature is useful when processing a file format that encapsulates
684 a compressed data stream (e.g. gzip, zip).
685
686 $status = $i->inflateSync($buffer)
687 Scans $buffer until it reaches either a full flush point or the end of
688 the buffer.
689
690 If a full flush point is found, "Z_OK" is returned and $buffer will be
691 have all data up to the flush point removed. This can then be passed to
692 the "deflate" method.
693
694 Any other return code means that a flush point was not found. If more
695 data is available, "inflateSync" can be called repeatedly with more
696 compressed data until the flush point is found.
697
698 $i->dict_adler()
699 Returns the adler32 value for the dictionary.
700
701 $i->msg()
702 Returns the last error message generated by zlib.
703
704 $i->total_in()
705 Returns the total number of bytes compressed bytes input to inflate.
706
707 $i->total_out()
708 Returns the total number of uncompressed bytes output from inflate.
709
710 Example
711 Here is an example of using "inflate".
712
713 use strict ;
714 use warnings ;
715
716 use Compress::Zlib ;
717
718 my $x = inflateInit()
719 or die "Cannot create a inflation stream\n" ;
720
721 my $input = '' ;
722 binmode STDIN;
723 binmode STDOUT;
724
725 my ($output, $status) ;
726 while (read(STDIN, $input, 4096))
727 {
728 ($output, $status) = $x->inflate(\$input) ;
729
730 print $output
731 if $status == Z_OK or $status == Z_STREAM_END ;
732
733 last if $status != Z_OK ;
734 }
735
736 die "inflation failed\n"
737 unless $status == Z_STREAM_END ;
738
740 Two functions are provided by zlib to calculate checksums. For the Perl
741 interface, the order of the two parameters in both functions has been
742 reversed. This allows both running checksums and one off calculations
743 to be done.
744
745 $crc = adler32($buffer [,$crc]) ;
746 $crc = crc32($buffer [,$crc]) ;
747
748 The buffer parameters can either be a scalar or a scalar reference.
749
750 If the $crc parameters is "undef", the crc value will be reset.
751
752 If you have built this module with zlib 1.2.3 or better, two more CRC-
753 related functions are available.
754
755 $crc = adler32_combine($crc1, $crc2, $len2)l
756 $crc = crc32_combine($adler1, $adler2, $len2)
757
758 These functions allow checksums to be merged.
759
761 my $version = Compress::Zlib::zlib_version();
762 Returns the version of the zlib library.
763
765 All the zlib constants are automatically imported when you make use of
766 Compress::Zlib.
767
769 IO::Compress::Gzip, IO::Uncompress::Gunzip, IO::Compress::Deflate,
770 IO::Uncompress::Inflate, IO::Compress::RawDeflate,
771 IO::Uncompress::RawInflate, IO::Compress::Bzip2,
772 IO::Uncompress::Bunzip2, IO::Compress::Lzop, IO::Uncompress::UnLzop,
773 IO::Compress::Lzf, IO::Uncompress::UnLzf, IO::Uncompress::AnyInflate,
774 IO::Uncompress::AnyUncompress
775
776 Compress::Zlib::FAQ
777
778 File::GlobMapper, Archive::Zip, Archive::Tar, IO::Zlib
779
780 For RFC 1950, 1951 and 1952 see http://www.faqs.org/rfcs/rfc1950.html,
781 http://www.faqs.org/rfcs/rfc1951.html and
782 http://www.faqs.org/rfcs/rfc1952.html
783
784 The zlib compression library was written by Jean-loup Gailly
785 gzip@prep.ai.mit.edu and Mark Adler madler@alumni.caltech.edu.
786
787 The primary site for the zlib compression library is
788 http://www.zlib.org.
789
790 The primary site for gzip is http://www.gzip.org.
791
793 This module was written by Paul Marquess, pmqs@cpan.org.
794
796 See the Changes file.
797
799 Copyright (c) 1995-2009 Paul Marquess. All rights reserved.
800
801 This program is free software; you can redistribute it and/or modify it
802 under the same terms as Perl itself.
803
804
805
806perl v5.10.1 2017-03-22 Compress::Zlib(3pm)