Compress::Raw::Zlib - Low-Level Interface to zlib compression library
| Use Case | Command | Description |
|---|---|---|
| đĻ Compress data in memory | Compress::Raw::Zlib::Deflate->new(OPT) | Create deflation object with optional compression level, window bits, etc. |
| đ¤ Write compressed data | $d->deflate($input, $output) | Compress $input and write to $output; returns Z_OK on success. |
| đ Finalize compression | $d->flush($output [, $flush_type]) | Finish deflation, write pending output; default Z_FINISH. |
| đĨ Uncompress data in memory | Compress::Raw::Zlib::Inflate->new(OPT) | Create inflation object with optional window bits, buffer size, etc. |
| đ Read uncompressed data | $i->inflate($input, $output [, $eof]) | Uncompress $input, write to $output; returns Z_OK or Z_STREAM_END. |
| đ Reset deflation stream | $d->deflateReset() | Reset deflation object for reuse on a new stream. |
| đ Reset inflation stream | $i->inflateReset() | Reset inflation object for reuse. |
| đ Compute checksum | crc32($buffer [, $crc]) | Calculate CRC32 checksum; can be incremental. |
| đ Compute checksum | adler32($buffer [, $crc]) | Calculate Adler32 checksum; can be incremental. |
| âšī¸ Get zlib version | Compress::Raw::Zlib::zlib_version() | Returns the version of the zlib library. |
use Compress::Raw::Zlib ;
($d, $status) = new Compress::Raw::Zlib::Deflate( [OPT] ) ;
$status = $d->deflate($input, $output) ;
$status = $d->flush($output [, $flush_type]) ;
$d->deflateReset() ;
$d->deflateParams(OPTS) ;
$d->deflateTune(OPTS) ;
$d->dict_adler() ;
$d->crc32() ;
$d->adler32() ;
$d->total_in() ;
$d->total_out() ;
$d->msg() ;
$d->get_Strategy();
$d->get_Level();
$d->get_BufSize();
($i, $status) = new Compress::Raw::Zlib::Inflate( [OPT] ) ;
$status = $i->inflate($input, $output [, $eof]) ;
$status = $i->inflateSync($input) ;
$i->inflateReset() ;
$i->dict_adler() ;
$d->crc32() ;
$d->adler32() ;
$i->total_in() ;
$i->total_out() ;
$i->msg() ;
$d->get_BufSize();
$crc = adler32($buffer [,$crc]) ;
$crc = crc32($buffer [,$crc]) ;
$crc = crc32_combine($crc1, $crc2, $len2);
$adler = adler32_combine($adler1, $adler2, $len2);
my $version = Compress::Raw::Zlib::zlib_version();
my $flags = Compress::Raw::Zlib::zlibCompileFlags();
The Compress::Raw::Zlib module provides a Perl interface to the zlib compression library (see "AUTHOR" for details about where to get zlib).
This section defines an interface that allows in-memory compression using the deflate interface provided by zlib.
Initialises a deflation object. If you are familiar with the zlib library, it combines the features of the zlib functions deflateInit, deflateInit2 and deflateSetDictionary.
If successful, it will return the initialised deflation object, $d and a $status of Z_OK in a list context. In scalar context it returns the deflation object, $d, only.
If not successful, the returned deflation object, $d, will be undef and $status will hold a zlib error code.
The function optionally takes a number of named options specified as "Name => value" pairs. For backward compatibility, it is also possible to pass the parameters as a reference to a hash containing the name=>value pairs.
Z_NO_COMPRESSION, Z_BEST_SPEED, Z_BEST_COMPRESSION, Z_DEFAULT_COMPRESSION. Default: Z_DEFAULT_COMPRESSION.Z_DEFLATED (default).-MAX_WBITS. For gzip (RFC 1952), set to WANT_GZIP. Default: MAX_WBITS.deflateInit2. Default: MAX_MEM_LEVEL.Z_DEFAULT_STRATEGY, Z_FILTERED, Z_RLE, Z_FIXED, Z_HUFFMAN_ONLY. Default: Z_DEFAULT_STRATEGY.deflateSetDictionary. Adler32 value obtained via $d->dict_adler(). Default: no dictionary.$d->crc32(). Default: false.$d->adler32(). Default: false.Example:
my $d = new Compress::Raw::Zlib::Deflate ( -Bufsize => 300,
-Level => Z_BEST_SPEED ) ;
Deflates contents of $input and writes compressed data to $output. $input and $output can be scalars or scalar references. Returns Z_OK on success. Note: Not every call produces output; check return code.
Finishes deflation; writes pending output. Default flush_type is Z_FINISH. Other valid: Z_NO_FLUSH, Z_PARTIAL_FLUSH, Z_SYNC_FLUSH, Z_FULL_FLUSH. Use with care.
Resets deflation object for reuse on multiple data streams after successful flush.
Change settings: -Level, -Strategy, -BufSize. Options not specified remain unchanged.
Tune internal settings (zlib 1.2.2.3+). See zlib.h documentation.
$d->dict_adler() â Returns adler32 of dictionary.$d->crc32() â Returns crc32 of uncompressed data (if CRC32 option enabled).$d->adler32() â Returns adler32 of uncompressed data.$d->msg() â Last error message from zlib.$d->total_in() â Total bytes input to deflate.$d->total_out() â Total bytes output from deflate.$d->get_Strategy() â Current deflation strategy.$d->get_Level() â Current compression level.$d->get_BufSize() â Buffer size used for compression.use strict ;
use warnings ;
use Compress::Raw::Zlib ;
binmode STDIN;
binmode STDOUT;
my $x = new Compress::Raw::Zlib::Deflate
or die "Cannot create a deflation stream\n" ;
my ($output, $status) ;
while (<>)
{
$status = $x->deflate($_, $output) ;
$status == Z_OK
or die "deflation failed\n" ;
print $output ;
}
$status = $x->flush($output) ;
$status == Z_OK
or die "deflation failed\n" ;
print $output ;
This section defines an interface that allows in-memory uncompression using the inflate interface provided by zlib.
Initialises an inflation object. Returns ($i, $status) in list context; $i only in scalar. $status is Z_OK on success.
$i->crc32(). Default: false.$i->adler32(). Default: false.Example:
my ($i, $status) = new Compress::Raw::Zlib::Inflate( -Bufsize => 300 ) ;
Inflates $input and writes uncompressed data to $output. Returns Z_OK or Z_STREAM_END. $eof parameter needed for raw deflate streams (RFC 1951) with no trailing data when using zlib < 1.2.0. Ignored for newer zlib.
Scans for a full flush point in $input. Returns Z_OK if found, removing data up to flush point. Used for recovery from partially corrupt data.
Resets inflation object for reuse on multiple streams.
$i->dict_adler() â Returns adler32 of dictionary.$i->crc32() â Returns crc32 of uncompressed data (if CRC32 option enabled).$i->adler32() â Returns adler32 of uncompressed data (if ADLER32 option enabled).$i->msg() â Last error message from zlib.$i->total_in() â Total bytes compressed input to inflate.$i->total_out() â Total bytes uncompressed output from inflate.$d->get_BufSize() â Buffer size used for decompression.Basic inflate:
use strict ;
use warnings ;
use Compress::Raw::Zlib;
my $x = new Compress::Raw::Zlib::Inflate()
or die "Cannot create a inflation stream\n" ;
my $input = '' ;
binmode STDIN;
binmode STDOUT;
my ($output, $status) ;
while (read(STDIN, $input, 4096))
{
$status = $x->inflate($input, $output) ;
print $output ;
last if $status != Z_OK ;
}
die "inflation failed\n"
unless $status == Z_STREAM_END ;
With LimitOutput:
use strict ;
use warnings ;
use Compress::Raw::Zlib;
my $x = new Compress::Raw::Zlib::Inflate(LimitOutput => 1)
or die "Cannot create a inflation stream\n" ;
my $input = '' ;
binmode STDIN;
binmode STDOUT;
my ($output, $status) ;
OUTER:
while (read(STDIN, $input, 4096))
{
do
{
$status = $x->inflate($input, $output) ;
print $output ;
last OUTER
unless $status == Z_OK || $status == Z_BUF_ERROR ;
}
while ($status == Z_OK && length $input);
}
die "inflation failed\n"
unless $status == Z_STREAM_END ;
Two functions are provided by zlib to calculate checksums. The order of parameters is reversed for Perl interface.
$crc = adler32($buffer [,$crc]) ;
$crc = crc32($buffer [,$crc]) ;
If $crc is undef, the crc value is reset. With zlib 1.2.3+, two combine functions are available:
$crc = crc32_combine($crc1, $crc2, $len2);
$adler = adler32_combine($adler1, $adler2, $len2);
Returns the version of the zlib library.
Returns flags indicating compile-time options. See zlib documentation. For zlib <= 1.2.0, returns 0.
By default $i->inflate($input, $output) will uncompress all data in $input and write all uncompressed data to $output. This can cause unbounded memory growth. The LimitOutput option limits memory usage by returning Z_BUF_ERROR when output buffer is full. See example above for usage.
Use modules like Archive::Zip, Archive::Zip::SimpleZip, IO::Compress::Zip and IO::Uncompress::Unzip for easier .zip handling.
This module is not compatible with Unix compress. Use uncompress or gunzip to read compressed files, or compress to write.
Use uncompress or gunzip with Archive::Tar. Example:
open F, "uncompress -c $filename |";
my $tar = Archive::Tar->new(*F);
...
Requires zlib 1.0.5 or better. Use zlib 1.2.1+ for -Merge option with IO::Compress::Gzip, etc. By default, builds with private copy of zlib 1.2.5.
All zlib constants are automatically imported when using Compress::Raw::Zlib.
Send feedback/questions/bug reports to https://github.com/pmqs/Compress-Raw-Zlib/issues (preferred) or https://rt.cpan.org/Public/Dist/Display.html?Name=Compress-Raw-Zlib.
Compress::Zlib, 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
File::GlobMapper, Archive::Zip, Archive::Tar, IO::Zlib
For RFC 1950, 1951 and 1952 see http://www.faqs.org/rfcs/rfc1950.html, http://www.faqs.org/rfcs/rfc1951.html and http://www.faqs.org/rfcs/rfc1952.html
The zlib compression library was written by Jean-loup Gailly gzip AT prep.edu and Mark Adler madler AT alumni.edu. Primary site: http://www.zlib.org. gzip: http://www.gzip.org.
Paul Marquess, pmqs AT cpan.org.
See the Changes file.
Copyright (c) 2005-2021 Paul Marquess. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Generated by phpman v4.9.26-5-g7740029 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-08-21 00:41 @216.73.216.26
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)