<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">
package Compress::Zlib;

require 5.006 ;
require Exporter;
use Carp ;
use IO::Handle ;
use Scalar::Util qw(dualvar);

use IO::Compress::Base::Common 2.074 ;
use Compress::Raw::Zlib 2.074 ;
use IO::Compress::Gzip 2.074 ;
use IO::Uncompress::Gunzip 2.074 ;

use strict ;
use warnings ;
use bytes ;
our ($VERSION, $XS_VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);

$VERSION = '2.074';
$XS_VERSION = $VERSION; 
$VERSION = eval $VERSION;

@ISA = qw(Exporter);
# Items to export into callers namespace by default. Note: do not export
# names by default without a very good reason. Use EXPORT_OK instead.
# Do not simply export all your public functions/methods/constants.
@EXPORT = qw(
        deflateInit inflateInit

        compress uncompress

        gzopen $gzerrno
    );

push @EXPORT, @Compress::Raw::Zlib::EXPORT ;

@EXPORT_OK = qw(memGunzip memGzip zlib_version);
%EXPORT_TAGS = (
    ALL         =&gt; \@EXPORT
);

BEGIN
{
    *zlib_version = \&amp;Compress::Raw::Zlib::zlib_version;
}

use constant FLAG_APPEND             =&gt; 1 ;
use constant FLAG_CRC                =&gt; 2 ;
use constant FLAG_ADLER              =&gt; 4 ;
use constant FLAG_CONSUME_INPUT      =&gt; 8 ;

our (@my_z_errmsg);

@my_z_errmsg = (
    "need dictionary",     # Z_NEED_DICT     2
    "stream end",          # Z_STREAM_END    1
    "",                    # Z_OK            0
    "file error",          # Z_ERRNO        (-1)
    "stream error",        # Z_STREAM_ERROR (-2)
    "data error",          # Z_DATA_ERROR   (-3)
    "insufficient memory", # Z_MEM_ERROR    (-4)
    "buffer error",        # Z_BUF_ERROR    (-5)
    "incompatible version",# Z_VERSION_ERROR(-6)
    );


sub _set_gzerr
{
    my $value = shift ;

    if ($value == 0) {
        $Compress::Zlib::gzerrno = 0 ;
    }
    elsif ($value == Z_ERRNO() || $value &gt; 2) {
        $Compress::Zlib::gzerrno = $! ;
    }
    else {
        $Compress::Zlib::gzerrno = dualvar($value+0, $my_z_errmsg[2 - $value]);
    }

    return $value ;
}

sub _set_gzerr_undef
{
    _set_gzerr(@_);
    return undef;
}

sub _save_gzerr
{
    my $gz = shift ;
    my $test_eof = shift ;

    my $value = $gz-&gt;errorNo() || 0 ;
    my $eof = $gz-&gt;eof() ;

    if ($test_eof) {
        # gzread uses Z_STREAM_END to denote a successful end
        $value = Z_STREAM_END() if $gz-&gt;eof() &amp;&amp; $value == 0 ;
    }

    _set_gzerr($value) ;
}

sub gzopen($$)
{
    my ($file, $mode) = @_ ;

    my $gz ;
    my %defOpts = (Level    =&gt; Z_DEFAULT_COMPRESSION(),
                   Strategy =&gt; Z_DEFAULT_STRATEGY(),
                  );

    my $writing ;
    $writing = ! ($mode =~ /r/i) ;
    $writing = ($mode =~ /[wa]/i) ;

    $defOpts{Level}    = $1               if $mode =~ /(\d)/;
    $defOpts{Strategy} = Z_FILTERED()     if $mode =~ /f/i;
    $defOpts{Strategy} = Z_HUFFMAN_ONLY() if $mode =~ /h/i;
    $defOpts{Append}   = 1                if $mode =~ /a/i;

    my $infDef = $writing ? 'deflate' : 'inflate';
    my @params = () ;

    croak "gzopen: file parameter is not a filehandle or filename"
        unless isaFilehandle $file || isaFilename $file  || 
               (ref $file &amp;&amp; ref $file eq 'SCALAR');

    return undef unless $mode =~ /[rwa]/i ;

    _set_gzerr(0) ;

    if ($writing) {
        $gz = new IO::Compress::Gzip($file, Minimal =&gt; 1, AutoClose =&gt; 1, 
                                     %defOpts) 
            or $Compress::Zlib::gzerrno = $IO::Compress::Gzip::GzipError;
    }
    else {
        $gz = new IO::Uncompress::Gunzip($file, 
                                         Transparent =&gt; 1,
                                         Append =&gt; 0, 
                                         AutoClose =&gt; 1, 
                                         MultiStream =&gt; 1,
                                         Strict =&gt; 0) 
            or $Compress::Zlib::gzerrno = $IO::Uncompress::Gunzip::GunzipError;
    }

    return undef
        if ! defined $gz ;

    bless [$gz, $infDef], 'Compress::Zlib::gzFile';
}

sub Compress::Zlib::gzFile::gzread
{
    my $self = shift ;

    return _set_gzerr(Z_STREAM_ERROR())
        if $self-&gt;[1] ne 'inflate';

    my $len = defined $_[1] ? $_[1] : 4096 ; 

    my $gz = $self-&gt;[0] ;
    if ($self-&gt;gzeof() || $len == 0) {
        # Zap the output buffer to match ver 1 behaviour.
        $_[0] = "" ;
        _save_gzerr($gz, 1);
        return 0 ;
    }

    my $status = $gz-&gt;read($_[0], $len) ; 
    _save_gzerr($gz, 1);
    return $status ;
}

sub Compress::Zlib::gzFile::gzreadline
{
    my $self = shift ;

    my $gz = $self-&gt;[0] ;
    {
        # Maintain backward compatibility with 1.x behaviour
        # It didn't support $/, so this can't either.
        local $/ = "\n" ;
        $_[0] = $gz-&gt;getline() ; 
    }
    _save_gzerr($gz, 1);
    return defined $_[0] ? length $_[0] : 0 ;
}

sub Compress::Zlib::gzFile::gzwrite
{
    my $self = shift ;
    my $gz = $self-&gt;[0] ;

    return _set_gzerr(Z_STREAM_ERROR())
        if $self-&gt;[1] ne 'deflate';

    $] &gt;= 5.008 and (utf8::downgrade($_[0], 1) 
        or croak "Wide character in gzwrite");

    my $status = $gz-&gt;write($_[0]) ;
    _save_gzerr($gz);
    return $status ;
}

sub Compress::Zlib::gzFile::gztell
{
    my $self = shift ;
    my $gz = $self-&gt;[0] ;
    my $status = $gz-&gt;tell() ;
    _save_gzerr($gz);
    return $status ;
}

sub Compress::Zlib::gzFile::gzseek
{
    my $self   = shift ;
    my $offset = shift ;
    my $whence = shift ;

    my $gz = $self-&gt;[0] ;
    my $status ;
    eval { $status = $gz-&gt;seek($offset, $whence) ; };
    if ($@)
    {
        my $error = $@;
        $error =~ s/^.*: /gzseek: /;
        $error =~ s/ at .* line \d+\s*$//;
        croak $error;
    }
    _save_gzerr($gz);
    return $status ;
}

sub Compress::Zlib::gzFile::gzflush
{
    my $self = shift ;
    my $f    = shift ;

    my $gz = $self-&gt;[0] ;
    my $status = $gz-&gt;flush($f) ;
    my $err = _save_gzerr($gz);
    return $status ? 0 : $err;
}

sub Compress::Zlib::gzFile::gzclose
{
    my $self = shift ;
    my $gz = $self-&gt;[0] ;

    my $status = $gz-&gt;close() ;
    my $err = _save_gzerr($gz);
    return $status ? 0 : $err;
}

sub Compress::Zlib::gzFile::gzeof
{
    my $self = shift ;
    my $gz = $self-&gt;[0] ;

    return 0
        if $self-&gt;[1] ne 'inflate';

    my $status = $gz-&gt;eof() ;
    _save_gzerr($gz);
    return $status ;
}

sub Compress::Zlib::gzFile::gzsetparams
{
    my $self = shift ;
    croak "Usage: Compress::Zlib::gzFile::gzsetparams(file, level, strategy)"
        unless @_ eq 2 ;

    my $gz = $self-&gt;[0] ;
    my $level = shift ;
    my $strategy = shift;

    return _set_gzerr(Z_STREAM_ERROR())
        if $self-&gt;[1] ne 'deflate';
 
    my $status = *$gz-&gt;{Compress}-&gt;deflateParams(-Level   =&gt; $level, 
                                                -Strategy =&gt; $strategy);
    _save_gzerr($gz);
    return $status ;
}

sub Compress::Zlib::gzFile::gzerror
{
    my $self = shift ;
    my $gz = $self-&gt;[0] ;
    
    return $Compress::Zlib::gzerrno ;
}


sub compress($;$)
{
    my ($x, $output, $err, $in) =('', '', '', '') ;

    if (ref $_[0] ) {
        $in = $_[0] ;
        croak "not a scalar reference" unless ref $in eq 'SCALAR' ;
    }
    else {
        $in = \$_[0] ;
    }

    $] &gt;= 5.008 and (utf8::downgrade($$in, 1) 
        or croak "Wide character in compress");

    my $level = (@_ == 2 ? $_[1] : Z_DEFAULT_COMPRESSION() );

    $x = Compress::Raw::Zlib::_deflateInit(FLAG_APPEND,
                                           $level,
                                           Z_DEFLATED,
                                           MAX_WBITS,
                                           MAX_MEM_LEVEL,
                                           Z_DEFAULT_STRATEGY,
                                           4096,
                                           '') 
            or return undef ;

    $err = $x-&gt;deflate($in, $output) ;
    return undef unless $err == Z_OK() ;

    $err = $x-&gt;flush($output) ;
    return undef unless $err == Z_OK() ;
    
    return $output ;
}

sub uncompress($)
{
    my ($output, $in) =('', '') ;

    if (ref $_[0] ) {
        $in = $_[0] ;
        croak "not a scalar reference" unless ref $in eq 'SCALAR' ;
    }
    else {
        $in = \$_[0] ;
    }

    $] &gt;= 5.008 and (utf8::downgrade($$in, 1) 
        or croak "Wide character in uncompress");    
        
    my ($obj, $status) = Compress::Raw::Zlib::_inflateInit(0,
                                MAX_WBITS, 4096, "") ;   
                                
    $status == Z_OK 
        or return undef;
    
    $obj-&gt;inflate($in, $output) == Z_STREAM_END 
        or return undef;
    
    return $output;
}
 
sub deflateInit(@)
{
    my ($got) = ParseParameters(0,
                {
                'bufsize'       =&gt; [IO::Compress::Base::Common::Parse_unsigned, 4096],
                'level'         =&gt; [IO::Compress::Base::Common::Parse_signed,   Z_DEFAULT_COMPRESSION()],
                'method'        =&gt; [IO::Compress::Base::Common::Parse_unsigned, Z_DEFLATED()],
                'windowbits'    =&gt; [IO::Compress::Base::Common::Parse_signed,   MAX_WBITS()],
                'memlevel'      =&gt; [IO::Compress::Base::Common::Parse_unsigned, MAX_MEM_LEVEL()],
                'strategy'      =&gt; [IO::Compress::Base::Common::Parse_unsigned, Z_DEFAULT_STRATEGY()],
                'dictionary'    =&gt; [IO::Compress::Base::Common::Parse_any,      ""],
                }, @_ ) ;

    croak "Compress::Zlib::deflateInit: Bufsize must be &gt;= 1, you specified " . 
            $got-&gt;getValue('bufsize')
        unless $got-&gt;getValue('bufsize') &gt;= 1;

    my $obj ;
 
    my $status = 0 ;
    ($obj, $status) = 
      Compress::Raw::Zlib::_deflateInit(0,
                $got-&gt;getValue('level'), 
                $got-&gt;getValue('method'), 
                $got-&gt;getValue('windowbits'), 
                $got-&gt;getValue('memlevel'), 
                $got-&gt;getValue('strategy'), 
                $got-&gt;getValue('bufsize'),
                $got-&gt;getValue('dictionary')) ;

    my $x = ($status == Z_OK() ? bless $obj, "Zlib::OldDeflate"  : undef) ;
    return wantarray ? ($x, $status) : $x ;
}
 
sub inflateInit(@)
{
    my ($got) = ParseParameters(0,
                {
                'bufsize'       =&gt; [IO::Compress::Base::Common::Parse_unsigned, 4096],
                'windowbits'    =&gt; [IO::Compress::Base::Common::Parse_signed,   MAX_WBITS()],
                'dictionary'    =&gt; [IO::Compress::Base::Common::Parse_any,      ""],
                }, @_) ;


    croak "Compress::Zlib::inflateInit: Bufsize must be &gt;= 1, you specified " . 
            $got-&gt;getValue('bufsize')
        unless $got-&gt;getValue('bufsize') &gt;= 1;

    my $status = 0 ;
    my $obj ;
    ($obj, $status) = Compress::Raw::Zlib::_inflateInit(FLAG_CONSUME_INPUT,
                                $got-&gt;getValue('windowbits'), 
                                $got-&gt;getValue('bufsize'), 
                                $got-&gt;getValue('dictionary')) ;

    my $x = ($status == Z_OK() ? bless $obj, "Zlib::OldInflate"  : undef) ;

    wantarray ? ($x, $status) : $x ;
}

package Zlib::OldDeflate ;

our (@ISA);
@ISA = qw(Compress::Raw::Zlib::deflateStream);


sub deflate
{
    my $self = shift ;
    my $output ;

    my $status = $self-&gt;SUPER::deflate($_[0], $output) ;
    wantarray ? ($output, $status) : $output ;
}

sub flush
{
    my $self = shift ;
    my $output ;
    my $flag = shift || Compress::Zlib::Z_FINISH();
    my $status = $self-&gt;SUPER::flush($output, $flag) ;
    
    wantarray ? ($output, $status) : $output ;
}

package Zlib::OldInflate ;

our (@ISA);
@ISA = qw(Compress::Raw::Zlib::inflateStream);

sub inflate
{
    my $self = shift ;
    my $output ;
    my $status = $self-&gt;SUPER::inflate($_[0], $output) ;
    wantarray ? ($output, $status) : $output ;
}

package Compress::Zlib ;

use IO::Compress::Gzip::Constants 2.074 ;

sub memGzip($)
{
    _set_gzerr(0);
    my $x = Compress::Raw::Zlib::_deflateInit(FLAG_APPEND|FLAG_CRC,
                                           Z_BEST_COMPRESSION,
                                           Z_DEFLATED,
                                           -MAX_WBITS(),
                                           MAX_MEM_LEVEL,
                                           Z_DEFAULT_STRATEGY,
                                           4096,
                                           '') 
            or return undef ;
 
    # if the deflation buffer isn't a reference, make it one
    my $string = (ref $_[0] ? $_[0] : \$_[0]) ;

    $] &gt;= 5.008 and (utf8::downgrade($$string, 1) 
        or croak "Wide character in memGzip");

    my $out;
    my $status ;

    $x-&gt;deflate($string, $out) == Z_OK
        or return undef ;
 
    $x-&gt;flush($out) == Z_OK
        or return undef ;
 
    return IO::Compress::Gzip::Constants::GZIP_MINIMUM_HEADER . 
           $out . 
           pack("V V", $x-&gt;crc32(), $x-&gt;total_in());
}


sub _removeGzipHeader($)
{
    my $string = shift ;

    return Z_DATA_ERROR() 
        if length($$string) &lt; GZIP_MIN_HEADER_SIZE ;

    my ($magic1, $magic2, $method, $flags, $time, $xflags, $oscode) = 
        unpack ('CCCCVCC', $$string);

    return Z_DATA_ERROR()
        unless $magic1 == GZIP_ID1 and $magic2 == GZIP_ID2 and
           $method == Z_DEFLATED() and !($flags &amp; GZIP_FLG_RESERVED) ;
    substr($$string, 0, GZIP_MIN_HEADER_SIZE) = '' ;

    # skip extra field
    if ($flags &amp; GZIP_FLG_FEXTRA)
    {
        return Z_DATA_ERROR()
            if length($$string) &lt; GZIP_FEXTRA_HEADER_SIZE ;

        my ($extra_len) = unpack ('v', $$string);
        $extra_len += GZIP_FEXTRA_HEADER_SIZE;
        return Z_DATA_ERROR()
            if length($$string) &lt; $extra_len ;

        substr($$string, 0, $extra_len) = '';
    }

    # skip orig name
    if ($flags &amp; GZIP_FLG_FNAME)
    {
        my $name_end = index ($$string, GZIP_NULL_BYTE);
        return Z_DATA_ERROR()
           if $name_end == -1 ;
        substr($$string, 0, $name_end + 1) =  '';
    }

    # skip comment
    if ($flags &amp; GZIP_FLG_FCOMMENT)
    {
        my $comment_end = index ($$string, GZIP_NULL_BYTE);
        return Z_DATA_ERROR()
            if $comment_end == -1 ;
        substr($$string, 0, $comment_end + 1) = '';
    }

    # skip header crc
    if ($flags &amp; GZIP_FLG_FHCRC)
    {
        return Z_DATA_ERROR()
            if length ($$string) &lt; GZIP_FHCRC_SIZE ;
        substr($$string, 0, GZIP_FHCRC_SIZE) = '';
    }
    
    return Z_OK();
}

sub _ret_gun_error
{
    $Compress::Zlib::gzerrno = $IO::Uncompress::Gunzip::GunzipError;
    return undef;
}


sub memGunzip($)
{
    # if the buffer isn't a reference, make it one
    my $string = (ref $_[0] ? $_[0] : \$_[0]);
 
    $] &gt;= 5.008 and (utf8::downgrade($$string, 1) 
        or croak "Wide character in memGunzip");

    _set_gzerr(0);

    my $status = _removeGzipHeader($string) ;
    $status == Z_OK() 
        or return _set_gzerr_undef($status);
     
    my $bufsize = length $$string &gt; 4096 ? length $$string : 4096 ;
    my $x = Compress::Raw::Zlib::_inflateInit(FLAG_CRC | FLAG_CONSUME_INPUT,
                                -MAX_WBITS(), $bufsize, '') 
              or return _ret_gun_error();

    my $output = '' ;
    $status = $x-&gt;inflate($string, $output);
    
    if ( $status == Z_OK() )
    {
        _set_gzerr(Z_DATA_ERROR());
        return undef;
    }

    return _ret_gun_error()
        if ($status != Z_STREAM_END());

    if (length $$string &gt;= 8)
    {
        my ($crc, $len) = unpack ("VV", substr($$string, 0, 8));
        substr($$string, 0, 8) = '';
        return _set_gzerr_undef(Z_DATA_ERROR())
            unless $len == length($output) and
                   $crc == Compress::Raw::Zlib::crc32($output);
    }
    else
    {
        $$string = '';
    }

    return $output;   
}

# Autoload methods go after __END__, and are processed by the autosplit program.

1;
__END__


=head1 NAME

Compress::Zlib - Interface to zlib compression library

=head1 SYNOPSIS

    use Compress::Zlib ;

    ($d, $status) = deflateInit( [OPT] ) ;
    $status = $d-&gt;deflate($input, $output) ;
    $status = $d-&gt;flush([$flush_type]) ;
    $d-&gt;deflateParams(OPTS) ;
    $d-&gt;deflateTune(OPTS) ;
    $d-&gt;dict_adler() ;
    $d-&gt;crc32() ;
    $d-&gt;adler32() ;
    $d-&gt;total_in() ;
    $d-&gt;total_out() ;
    $d-&gt;msg() ;
    $d-&gt;get_Strategy();
    $d-&gt;get_Level();
    $d-&gt;get_BufSize();

    ($i, $status) = inflateInit( [OPT] ) ;
    $status = $i-&gt;inflate($input, $output [, $eof]) ;
    $status = $i-&gt;inflateSync($input) ;
    $i-&gt;dict_adler() ;
    $d-&gt;crc32() ;
    $d-&gt;adler32() ;
    $i-&gt;total_in() ;
    $i-&gt;total_out() ;
    $i-&gt;msg() ;
    $d-&gt;get_BufSize();

    $dest = compress($source) ;
    $dest = uncompress($source) ;

    $gz = gzopen($filename or filehandle, $mode) ;
    $bytesread = $gz-&gt;gzread($buffer [,$size]) ;
    $bytesread = $gz-&gt;gzreadline($line) ;
    $byteswritten = $gz-&gt;gzwrite($buffer) ;
    $status = $gz-&gt;gzflush($flush) ;
    $offset = $gz-&gt;gztell() ;
    $status = $gz-&gt;gzseek($offset, $whence) ;
    $status = $gz-&gt;gzclose() ;
    $status = $gz-&gt;gzeof() ;
    $status = $gz-&gt;gzsetparams($level, $strategy) ;
    $errstring = $gz-&gt;gzerror() ; 
    $gzerrno

    $dest = Compress::Zlib::memGzip($buffer) ;
    $dest = Compress::Zlib::memGunzip($buffer) ;

    $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();

=head1 DESCRIPTION

The I&lt;Compress::Zlib&gt; module provides a Perl interface to the I&lt;zlib&gt;
compression library (see L&lt;/AUTHOR&gt; for details about where to get
I&lt;zlib&gt;). 

The C&lt;Compress::Zlib&gt; module can be split into two general areas of
functionality, namely a simple read/write interface to I&lt;gzip&gt; files
and a low-level in-memory compression/decompression interface.

Each of these areas will be discussed in the following sections.

=head2 Notes for users of Compress::Zlib version 1

The main change in C&lt;Compress::Zlib&gt; version 2.x is that it does not now
interface directly to the zlib library. Instead it uses the
C&lt;IO::Compress::Gzip&gt; and C&lt;IO::Uncompress::Gunzip&gt; modules for
reading/writing gzip files, and the C&lt;Compress::Raw::Zlib&gt; module for some
low-level zlib access. 

The interface provided by version 2 of this module should be 100% backward
compatible with version 1. If you find a difference in the expected
behaviour please contact the author (See L&lt;/AUTHOR&gt;). See L&lt;GZIP INTERFACE&gt; 

With the creation of the C&lt;IO::Compress&gt; and C&lt;IO::Uncompress&gt; modules no
new features are planned for C&lt;Compress::Zlib&gt; - the new modules do
everything that C&lt;Compress::Zlib&gt; does and then some. Development on
C&lt;Compress::Zlib&gt; will be limited to bug fixes only.

If you are writing new code, your first port of call should be one of the
new C&lt;IO::Compress&gt; or C&lt;IO::Uncompress&gt; modules.

=head1 GZIP INTERFACE

A number of functions are supplied in I&lt;zlib&gt; for reading and writing
I&lt;gzip&gt; files that conform to RFC 1952. This module provides an interface
to most of them. 

If you have previously used C&lt;Compress::Zlib&gt; 1.x, the following
enhancements/changes have been made to the C&lt;gzopen&gt; interface:

=over 5

=item 1

If you want to open either STDIN or STDOUT with C&lt;gzopen&gt;, you can now
optionally use the special filename "C&lt;-&gt;" as a synonym for C&lt;\*STDIN&gt; and
C&lt;\*STDOUT&gt;.

=item 2 

In C&lt;Compress::Zlib&gt; version 1.x, C&lt;gzopen&gt; used the zlib library to open
the underlying file. This made things especially tricky when a Perl
filehandle was passed to C&lt;gzopen&gt;. Behind the scenes the numeric C file
descriptor had to be extracted from the Perl filehandle and this passed to
the zlib library.

Apart from being non-portable to some operating systems, this made it
difficult to use C&lt;gzopen&gt; in situations where you wanted to extract/create
a gzip data stream that is embedded in a larger file, without having to
resort to opening and closing the file multiple times. 

It also made it impossible to pass a perl filehandle that wasn't associated
with a real filesystem file, like, say, an C&lt;IO::String&gt;.

In C&lt;Compress::Zlib&gt; version 2.x, the C&lt;gzopen&gt; interface has been
completely rewritten to use the L&lt;IO::Compress::Gzip|IO::Compress::Gzip&gt;
for writing gzip files and L&lt;IO::Uncompress::Gunzip|IO::Uncompress::Gunzip&gt;
for reading gzip files. None of the limitations mentioned above apply.

=item 3

Addition of C&lt;gzseek&gt; to provide a restricted C&lt;seek&gt; interface.

=item 4.

Added C&lt;gztell&gt;.

=back

A more complete and flexible interface for reading/writing gzip
files/buffers is included with the module C&lt;IO-Compress-Zlib&gt;. See
L&lt;IO::Compress::Gzip|IO::Compress::Gzip&gt; and
L&lt;IO::Uncompress::Gunzip|IO::Uncompress::Gunzip&gt; for more details.

=over 5

=item B&lt;$gz = gzopen($filename, $mode)&gt;

=item B&lt;$gz = gzopen($filehandle, $mode)&gt;

This function opens either the I&lt;gzip&gt; file C&lt;$filename&gt; for reading or
writing or attaches to the opened filehandle, C&lt;$filehandle&gt;. 
It returns an object on success and C&lt;undef&gt; on failure.

When writing a gzip file this interface will I&lt;always&gt; create the smallest
possible gzip header (exactly 10 bytes). If you want greater control over
what gets stored in the gzip header (like the original filename or a
comment) use L&lt;IO::Compress::Gzip|IO::Compress::Gzip&gt; instead. Similarly if
you want to read the contents of the gzip header use
L&lt;IO::Uncompress::Gunzip|IO::Uncompress::Gunzip&gt;.

The second parameter, C&lt;$mode&gt;, is used to specify whether the file is
opened for reading or writing and to optionally specify a compression
level and compression strategy when writing. The format of the C&lt;$mode&gt;
parameter is similar to the mode parameter to the 'C' function C&lt;fopen&gt;,
so "rb" is used to open for reading, "wb" for writing and "ab" for
appending (writing at the end of the file).

To specify a compression level when writing, append a digit between 0
and 9 to the mode string -- 0 means no compression and 9 means maximum
compression.
If no compression level is specified Z_DEFAULT_COMPRESSION is used.

To specify the compression strategy when writing, append 'f' for filtered
data, 'h' for Huffman only compression, or 'R' for run-length encoding.
If no strategy is specified Z_DEFAULT_STRATEGY is used.

So, for example, "wb9" means open for writing with the maximum compression
using the default strategy and "wb4R" means open for writing with compression
level 4 and run-length encoding.

Refer to the I&lt;zlib&gt; documentation for the exact format of the C&lt;$mode&gt;
parameter.

=item B&lt;$bytesread = $gz-E&lt;gt&gt;gzread($buffer [, $size]) ;&gt;

Reads C&lt;$size&gt; bytes from the compressed file into C&lt;$buffer&gt;. If
C&lt;$size&gt; is not specified, it will default to 4096. If the scalar
C&lt;$buffer&gt; is not large enough, it will be extended automatically.

Returns the number of bytes actually read. On EOF it returns 0 and in
the case of an error, -1.

=item B&lt;$bytesread = $gz-E&lt;gt&gt;gzreadline($line) ;&gt;

Reads the next line from the compressed file into C&lt;$line&gt;. 

Returns the number of bytes actually read. On EOF it returns 0 and in
the case of an error, -1.

It is legal to intermix calls to C&lt;gzread&gt; and C&lt;gzreadline&gt;.

To maintain backward compatibility with version 1.x of this module
C&lt;gzreadline&gt; ignores the C&lt;$/&gt; variable - it I&lt;always&gt; uses the string
C&lt;"\n"&gt; as the line delimiter.  

If you want to read a gzip file a line at a time and have it respect the
C&lt;$/&gt; variable (or C&lt;$INPUT_RECORD_SEPARATOR&gt;, or C&lt;$RS&gt; when C&lt;English&gt; is
in use) see L&lt;IO::Uncompress::Gunzip|IO::Uncompress::Gunzip&gt;.

=item B&lt;$byteswritten = $gz-E&lt;gt&gt;gzwrite($buffer) ;&gt;

Writes the contents of C&lt;$buffer&gt; to the compressed file. Returns the
number of bytes actually written, or 0 on error.

=item B&lt;$status = $gz-E&lt;gt&gt;gzflush($flush_type) ;&gt;

Flushes all pending output into the compressed file.

This method takes an optional parameter, C&lt;$flush_type&gt;, that controls
how the flushing will be carried out. By default the C&lt;$flush_type&gt;
used is C&lt;Z_FINISH&gt;. Other valid values for C&lt;$flush_type&gt; are
C&lt;Z_NO_FLUSH&gt;, C&lt;Z_SYNC_FLUSH&gt;, C&lt;Z_FULL_FLUSH&gt; and C&lt;Z_BLOCK&gt;. It is
strongly recommended that you only set the C&lt;flush_type&gt; parameter if
you fully understand the implications of what it does - overuse of C&lt;flush&gt;
can seriously degrade the level of compression achieved. See the C&lt;zlib&gt;
documentation for details.

Returns 0 on success.

=item B&lt;$offset = $gz-E&lt;gt&gt;gztell() ;&gt;

Returns the uncompressed file offset.

=item B&lt;$status = $gz-E&lt;gt&gt;gzseek($offset, $whence) ;&gt;

Provides a sub-set of the C&lt;seek&gt; functionality, with the restriction
that it is only legal to seek forward in the compressed file.
It is a fatal error to attempt to seek backward.

When opened for writing, empty parts of the file will have NULL (0x00)
bytes written to them.

The C&lt;$whence&gt; parameter should be one of SEEK_SET, SEEK_CUR or SEEK_END.

Returns 1 on success, 0 on failure.

=item B&lt;$gz-E&lt;gt&gt;gzclose&gt;

Closes the compressed file. Any pending data is flushed to the file
before it is closed.

Returns 0 on success.

=item B&lt;$gz-E&lt;gt&gt;gzsetparams($level, $strategy&gt;

Change settings for the deflate stream C&lt;$gz&gt;.

The list of the valid options is shown below. Options not specified
will remain unchanged.

Note: This method is only available if you are running zlib 1.0.6 or better.

=over 5

=item B&lt;$level&gt;

Defines the compression level. Valid values are 0 through 9,
C&lt;Z_NO_COMPRESSION&gt;, C&lt;Z_BEST_SPEED&gt;, C&lt;Z_BEST_COMPRESSION&gt;, and
C&lt;Z_DEFAULT_COMPRESSION&gt;.

=item B&lt;$strategy&gt;

Defines the strategy used to tune the compression. The valid values are
C&lt;Z_DEFAULT_STRATEGY&gt;, C&lt;Z_FILTERED&gt; and C&lt;Z_HUFFMAN_ONLY&gt;. 

=back

=item B&lt;$gz-E&lt;gt&gt;gzerror&gt;

Returns the I&lt;zlib&gt; error message or number for the last operation
associated with C&lt;$gz&gt;. The return value will be the I&lt;zlib&gt; error
number when used in a numeric context and the I&lt;zlib&gt; error message
when used in a string context. The I&lt;zlib&gt; error number constants,
shown below, are available for use.

    Z_OK
    Z_STREAM_END
    Z_ERRNO
    Z_STREAM_ERROR
    Z_DATA_ERROR
    Z_MEM_ERROR
    Z_BUF_ERROR

=item B&lt;$gzerrno&gt;

The C&lt;$gzerrno&gt; scalar holds the error code associated with the most
recent I&lt;gzip&gt; routine. Note that unlike C&lt;gzerror()&gt;, the error is
I&lt;not&gt; associated with a particular file.

As with C&lt;gzerror()&gt; it returns an error number in numeric context and
an error message in string context. Unlike C&lt;gzerror()&gt; though, the
error message will correspond to the I&lt;zlib&gt; message when the error is
associated with I&lt;zlib&gt; itself, or the UNIX error message when it is
not (i.e. I&lt;zlib&gt; returned C&lt;Z_ERRORNO&gt;).

As there is an overlap between the error numbers used by I&lt;zlib&gt; and
UNIX, C&lt;$gzerrno&gt; should only be used to check for the presence of
I&lt;an&gt; error in numeric context. Use C&lt;gzerror()&gt; to check for specific
I&lt;zlib&gt; errors. The I&lt;gzcat&gt; example below shows how the variable can
be used safely.

=back

=head2 Examples

Here is an example script which uses the interface. It implements a
I&lt;gzcat&gt; function.

    use strict ;
    use warnings ;
    
    use Compress::Zlib ;
    
    # use stdin if no files supplied
    @ARGV = '-' unless @ARGV ;
    
    foreach my $file (@ARGV) {
        my $buffer ;
    
        my $gz = gzopen($file, "rb") 
             or die "Cannot open $file: $gzerrno\n" ;
    
        print $buffer while $gz-&gt;gzread($buffer) &gt; 0 ;
    
        die "Error reading from $file: $gzerrno" . ($gzerrno+0) . "\n" 
            if $gzerrno != Z_STREAM_END ;
        
        $gz-&gt;gzclose() ;
    }

Below is a script which makes use of C&lt;gzreadline&gt;. It implements a
very simple I&lt;grep&gt; like script.

    use strict ;
    use warnings ;
    
    use Compress::Zlib ;
    
    die "Usage: gzgrep pattern [file...]\n"
        unless @ARGV &gt;= 1;
    
    my $pattern = shift ;
    
    # use stdin if no files supplied
    @ARGV = '-' unless @ARGV ;
    
    foreach my $file (@ARGV) {
        my $gz = gzopen($file, "rb") 
             or die "Cannot open $file: $gzerrno\n" ;
    
        while ($gz-&gt;gzreadline($_) &gt; 0) {
            print if /$pattern/ ;
        }
    
        die "Error reading from $file: $gzerrno\n" 
            if $gzerrno != Z_STREAM_END ;
        
        $gz-&gt;gzclose() ;
    }

This script, I&lt;gzstream&gt;, does the opposite of the I&lt;gzcat&gt; script
above. It reads from standard input and writes a gzip data stream to
standard output.

    use strict ;
    use warnings ;
    
    use Compress::Zlib ;
    
    binmode STDOUT;  # gzopen only sets it on the fd
    
    my $gz = gzopen(\*STDOUT, "wb")
          or die "Cannot open stdout: $gzerrno\n" ;
    
    while (&lt;&gt;) {
        $gz-&gt;gzwrite($_) 
          or die "error writing: $gzerrno\n" ;
    }

    $gz-&gt;gzclose ;

=head2 Compress::Zlib::memGzip

This function is used to create an in-memory gzip file with the minimum
possible gzip header (exactly 10 bytes).

    $dest = Compress::Zlib::memGzip($buffer) 
        or die "Cannot compress: $gzerrno\n";

If successful, it returns the in-memory gzip file. Otherwise it returns
C&lt;undef&gt; and the C&lt;$gzerrno&gt; variable will store the zlib error code.

The C&lt;$buffer&gt; parameter can either be a scalar or a scalar reference.

See L&lt;IO::Compress::Gzip|IO::Compress::Gzip&gt; for an alternative way to
carry out in-memory gzip compression.

=head2 Compress::Zlib::memGunzip

This function is used to uncompress an in-memory gzip file.

    $dest = Compress::Zlib::memGunzip($buffer) 
        or die "Cannot uncompress: $gzerrno\n";

If successful, it returns the uncompressed gzip file. Otherwise it
returns C&lt;undef&gt; and the C&lt;$gzerrno&gt; variable will store the zlib error
code.

The C&lt;$buffer&gt; parameter can either be a scalar or a scalar reference. The
contents of the C&lt;$buffer&gt; parameter are destroyed after calling this function.

If C&lt;$buffer&gt; consists of multiple concatenated gzip data streams only the
first will be uncompressed. Use C&lt;gunzip&gt; with the C&lt;MultiStream&gt; option in
the C&lt;IO::Uncompress::Gunzip&gt; module if you need to deal with concatenated
data streams.

See L&lt;IO::Uncompress::Gunzip|IO::Uncompress::Gunzip&gt; for an alternative way
to carry out in-memory gzip uncompression.

=head1 COMPRESS/UNCOMPRESS

Two functions are provided to perform in-memory compression/uncompression of
RFC 1950 data streams. They are called C&lt;compress&gt; and C&lt;uncompress&gt;.

=over 5

=item B&lt;$dest = compress($source [, $level] ) ;&gt;

Compresses C&lt;$source&gt;. If successful it returns the compressed
data. Otherwise it returns I&lt;undef&gt;.

The source buffer, C&lt;$source&gt;, can either be a scalar or a scalar
reference.

The C&lt;$level&gt; parameter defines the compression level. Valid values are
0 through 9, C&lt;Z_NO_COMPRESSION&gt;, C&lt;Z_BEST_SPEED&gt;,
C&lt;Z_BEST_COMPRESSION&gt;, and C&lt;Z_DEFAULT_COMPRESSION&gt;.
If C&lt;$level&gt; is not specified C&lt;Z_DEFAULT_COMPRESSION&gt; will be used.

=item B&lt;$dest = uncompress($source) ;&gt;

Uncompresses C&lt;$source&gt;. If successful it returns the uncompressed
data. Otherwise it returns I&lt;undef&gt;.

The source buffer can either be a scalar or a scalar reference.

=back

Please note: the two functions defined above are I&lt;not&gt; compatible with
the Unix commands of the same name.

See L&lt;IO::Deflate|IO::Deflate&gt; and L&lt;IO::Inflate|IO::Inflate&gt; included with
this distribution for an alternative interface for reading/writing RFC 1950
files/buffers.

=head1 Deflate Interface

This section defines an interface that allows in-memory compression using
the I&lt;deflate&gt; interface provided by zlib.

Here is a definition of the interface available:

=head2 B&lt;($d, $status) = deflateInit( [OPT] )&gt;

Initialises a deflation stream. 

It combines the features of the I&lt;zlib&gt; functions C&lt;deflateInit&gt;,
C&lt;deflateInit2&gt; and C&lt;deflateSetDictionary&gt;.

If successful, it will return the initialised deflation stream, C&lt;$d&gt;
and C&lt;$status&gt; of C&lt;Z_OK&gt; in a list context. In scalar context it
returns the deflation stream, C&lt;$d&gt;, only.

If not successful, the returned deflation stream (C&lt;$d&gt;) will be
I&lt;undef&gt; and C&lt;$status&gt; will hold the exact I&lt;zlib&gt; error code.

The function optionally takes a number of named options specified as
C&lt;&lt; -Name=&gt;value &gt;&gt; pairs. This allows individual options to be
tailored without having to specify them all in the parameter list.

For backward compatibility, it is also possible to pass the parameters
as a reference to a hash containing the name=&gt;value pairs.

The function takes one optional parameter, a reference to a hash.  The
contents of the hash allow the deflation interface to be tailored.

Here is a list of the valid options:

=over 5

=item B&lt;-Level&gt;

Defines the compression level. Valid values are 0 through 9,
C&lt;Z_NO_COMPRESSION&gt;, C&lt;Z_BEST_SPEED&gt;, C&lt;Z_BEST_COMPRESSION&gt;, and
C&lt;Z_DEFAULT_COMPRESSION&gt;.

The default is Z_DEFAULT_COMPRESSION.

=item B&lt;-Method&gt;

Defines the compression method. The only valid value at present (and
the default) is Z_DEFLATED.

=item B&lt;-WindowBits&gt;

To create an RFC 1950 data stream, set C&lt;WindowBits&gt; to a positive number.

To create an RFC 1951 data stream, set C&lt;WindowBits&gt; to C&lt;-MAX_WBITS&gt;.

For a full definition of the meaning and valid values for C&lt;WindowBits&gt; refer
to the I&lt;zlib&gt; documentation for I&lt;deflateInit2&gt;.

Defaults to MAX_WBITS.

=item B&lt;-MemLevel&gt;

For a definition of the meaning and valid values for C&lt;MemLevel&gt;
refer to the I&lt;zlib&gt; documentation for I&lt;deflateInit2&gt;.

Defaults to MAX_MEM_LEVEL.

=item B&lt;-Strategy&gt;

Defines the strategy used to tune the compression. The valid values are
C&lt;Z_DEFAULT_STRATEGY&gt;, C&lt;Z_FILTERED&gt; and C&lt;Z_HUFFMAN_ONLY&gt;. 

The default is Z_DEFAULT_STRATEGY.

=item B&lt;-Dictionary&gt;

When a dictionary is specified I&lt;Compress::Zlib&gt; will automatically
call C&lt;deflateSetDictionary&gt; directly after calling C&lt;deflateInit&gt;. The
Adler32 value for the dictionary can be obtained by calling the method 
C&lt;$d-&gt;dict_adler()&gt;.

The default is no dictionary.

=item B&lt;-Bufsize&gt;

Sets the initial size for the deflation buffer. If the buffer has to be
reallocated to increase the size, it will grow in increments of
C&lt;Bufsize&gt;.

The default is 4096.

=back

Here is an example of using the C&lt;deflateInit&gt; optional parameter list
to override the default buffer size and compression level. All other
options will take their default values.

    deflateInit( -Bufsize =&gt; 300, 
                 -Level =&gt; Z_BEST_SPEED  ) ;

=head2 B&lt;($out, $status) = $d-E&lt;gt&gt;deflate($buffer)&gt;

Deflates the contents of C&lt;$buffer&gt;. The buffer can either be a scalar
or a scalar reference.  When finished, C&lt;$buffer&gt; will be
completely processed (assuming there were no errors). If the deflation
was successful it returns the deflated output, C&lt;$out&gt;, and a status
value, C&lt;$status&gt;, of C&lt;Z_OK&gt;.

On error, C&lt;$out&gt; will be I&lt;undef&gt; and C&lt;$status&gt; will contain the
I&lt;zlib&gt; error code.

In a scalar context C&lt;deflate&gt; will return C&lt;$out&gt; only.

As with the I&lt;deflate&gt; function in I&lt;zlib&gt;, it is not necessarily the
case that any output will be produced by this method. So don't rely on
the fact that C&lt;$out&gt; is empty for an error test.

=head2 B&lt;($out, $status) = $d-E&lt;gt&gt;flush()&gt;
=head2 B&lt;($out, $status) = $d-E&lt;gt&gt;flush($flush_type)&gt;

Typically used to finish the deflation. Any pending output will be
returned via C&lt;$out&gt;.
C&lt;$status&gt; will have a value C&lt;Z_OK&gt; if successful.

In a scalar context C&lt;flush&gt; will return C&lt;$out&gt; only.

Note that flushing can seriously degrade the compression ratio, so it
should only be used to terminate a decompression (using C&lt;Z_FINISH&gt;) or
when you want to create a I&lt;full flush point&gt; (using C&lt;Z_FULL_FLUSH&gt;).

By default the C&lt;flush_type&gt; used is C&lt;Z_FINISH&gt;. Other valid values
for C&lt;flush_type&gt; are C&lt;Z_NO_FLUSH&gt;, C&lt;Z_PARTIAL_FLUSH&gt;, C&lt;Z_SYNC_FLUSH&gt;
and C&lt;Z_FULL_FLUSH&gt;. It is strongly recommended that you only set the
C&lt;flush_type&gt; parameter if you fully understand the implications of
what it does. See the C&lt;zlib&gt; documentation for details.

=head2 B&lt;$status = $d-E&lt;gt&gt;deflateParams([OPT])&gt;

Change settings for the deflate stream C&lt;$d&gt;.

The list of the valid options is shown below. Options not specified
will remain unchanged.

=over 5

=item B&lt;-Level&gt;

Defines the compression level. Valid values are 0 through 9,
C&lt;Z_NO_COMPRESSION&gt;, C&lt;Z_BEST_SPEED&gt;, C&lt;Z_BEST_COMPRESSION&gt;, and
C&lt;Z_DEFAULT_COMPRESSION&gt;.

=item B&lt;-Strategy&gt;

Defines the strategy used to tune the compression. The valid values are
C&lt;Z_DEFAULT_STRATEGY&gt;, C&lt;Z_FILTERED&gt; and C&lt;Z_HUFFMAN_ONLY&gt;. 

=back

=head2 B&lt;$d-E&lt;gt&gt;dict_adler()&gt;

Returns the adler32 value for the dictionary.

=head2 B&lt;$d-E&lt;gt&gt;msg()&gt;

Returns the last error message generated by zlib.

=head2 B&lt;$d-E&lt;gt&gt;total_in()&gt;

Returns the total number of bytes uncompressed bytes input to deflate.

=head2 B&lt;$d-E&lt;gt&gt;total_out()&gt;

Returns the total number of compressed bytes output from deflate.

=head2 Example

Here is a trivial example of using C&lt;deflate&gt;. It simply reads standard
input, deflates it and writes it to standard output.

    use strict ;
    use warnings ;

    use Compress::Zlib ;

    binmode STDIN;
    binmode STDOUT;
    my $x = deflateInit()
       or die "Cannot create a deflation stream\n" ;

    my ($output, $status) ;
    while (&lt;&gt;)
    {
        ($output, $status) = $x-&gt;deflate($_) ;
    
        $status == Z_OK
            or die "deflation failed\n" ;
    
        print $output ;
    }
    
    ($output, $status) = $x-&gt;flush() ;
    
    $status == Z_OK
        or die "deflation failed\n" ;
    
    print $output ;

=head1 Inflate Interface

This section defines the interface available that allows in-memory
uncompression using the I&lt;deflate&gt; interface provided by zlib.

Here is a definition of the interface:

=head2 B&lt;($i, $status) = inflateInit()&gt;

Initialises an inflation stream. 

In a list context it returns the inflation stream, C&lt;$i&gt;, and the
I&lt;zlib&gt; status code in C&lt;$status&gt;. In a scalar context it returns the
inflation stream only.

If successful, C&lt;$i&gt; will hold the inflation stream and C&lt;$status&gt; will
be C&lt;Z_OK&gt;.

If not successful, C&lt;$i&gt; will be I&lt;undef&gt; and C&lt;$status&gt; will hold the
I&lt;zlib&gt; error code.

The function optionally takes a number of named options specified as
C&lt;&lt; -Name=&gt;value &gt;&gt; pairs. This allows individual options to be
tailored without having to specify them all in the parameter list.
 
For backward compatibility, it is also possible to pass the parameters
as a reference to a hash containing the name=&gt;value pairs.
 
The function takes one optional parameter, a reference to a hash.  The
contents of the hash allow the deflation interface to be tailored.
 
Here is a list of the valid options:

=over 5

=item B&lt;-WindowBits&gt;

To uncompress an RFC 1950 data stream, set C&lt;WindowBits&gt; to a positive number.

To uncompress an RFC 1951 data stream, set C&lt;WindowBits&gt; to C&lt;-MAX_WBITS&gt;.

For a full definition of the meaning and valid values for C&lt;WindowBits&gt; refer
to the I&lt;zlib&gt; documentation for I&lt;inflateInit2&gt;.

Defaults to MAX_WBITS.

=item B&lt;-Bufsize&gt;

Sets the initial size for the inflation buffer. If the buffer has to be
reallocated to increase the size, it will grow in increments of
C&lt;Bufsize&gt;. 

Default is 4096.

=item B&lt;-Dictionary&gt;

The default is no dictionary.

=back

Here is an example of using the C&lt;inflateInit&gt; optional parameter to
override the default buffer size.

    inflateInit( -Bufsize =&gt; 300 ) ;

=head2 B&lt;($out, $status) = $i-E&lt;gt&gt;inflate($buffer)&gt;

Inflates the complete contents of C&lt;$buffer&gt;. The buffer can either be
a scalar or a scalar reference.

Returns C&lt;Z_OK&gt; if successful and C&lt;Z_STREAM_END&gt; if the end of the
compressed data has been successfully reached. 
If not successful, C&lt;$out&gt; will be I&lt;undef&gt; and C&lt;$status&gt; will hold
the I&lt;zlib&gt; error code.

The C&lt;$buffer&gt; parameter is modified by C&lt;inflate&gt;. On completion it
will contain what remains of the input buffer after inflation. This
means that C&lt;$buffer&gt; will be an empty string when the return status is
C&lt;Z_OK&gt;. When the return status is C&lt;Z_STREAM_END&gt; the C&lt;$buffer&gt;
parameter will contains what (if anything) was stored in the input
buffer after the deflated data stream.

This feature is useful when processing a file format that encapsulates
a  compressed data stream (e.g. gzip, zip).

=head2 B&lt;$status = $i-E&lt;gt&gt;inflateSync($buffer)&gt;

Scans C&lt;$buffer&gt; until it reaches either a I&lt;full flush point&gt; or the
end of the buffer.

If a I&lt;full flush point&gt; is found, C&lt;Z_OK&gt; is returned and C&lt;$buffer&gt;
will be have all data up to the flush point removed. This can then be
passed to the C&lt;deflate&gt; method.

Any other return code means that a flush point was not found. If more
data is available, C&lt;inflateSync&gt; can be called repeatedly with more
compressed data until the flush point is found.

=head2 B&lt;$i-E&lt;gt&gt;dict_adler()&gt;

Returns the adler32 value for the dictionary.

=head2 B&lt;$i-E&lt;gt&gt;msg()&gt;

Returns the last error message generated by zlib.

=head2 B&lt;$i-E&lt;gt&gt;total_in()&gt;

Returns the total number of bytes compressed bytes input to inflate.

=head2 B&lt;$i-E&lt;gt&gt;total_out()&gt;

Returns the total number of uncompressed bytes output from inflate.

=head2 Example

Here is an example of using C&lt;inflate&gt;.

    use strict ;
    use warnings ;
    
    use Compress::Zlib ;
    
    my $x = inflateInit()
       or die "Cannot create a inflation stream\n" ;
    
    my $input = '' ;
    binmode STDIN;
    binmode STDOUT;
    
    my ($output, $status) ;
    while (read(STDIN, $input, 4096))
    {
        ($output, $status) = $x-&gt;inflate(\$input) ;
    
        print $output 
            if $status == Z_OK or $status == Z_STREAM_END ;
    
        last if $status != Z_OK ;
    }
    
    die "inflation failed\n"
        unless $status == Z_STREAM_END ;

=head1 CHECKSUM FUNCTIONS

Two functions are provided by I&lt;zlib&gt; to calculate checksums. For the
Perl interface, the order of the two parameters in both functions has
been reversed. This allows both running checksums and one off
calculations to be done.

    $crc = adler32($buffer [,$crc]) ;
    $crc = crc32($buffer [,$crc]) ;

The buffer parameters can either be a scalar or a scalar reference.

If the $crc parameters is C&lt;undef&gt;, the crc value will be reset.

If you have built this module with zlib 1.2.3 or better, two more
CRC-related functions are available.

    $crc = crc32_combine($crc1, $crc2, $len2);
    $adler = adler32_combine($adler1, $adler2, $len2);

These functions allow checksums to be merged.
Refer to the I&lt;zlib&gt; documentation for more details.

=head1 Misc

=head2 my $version = Compress::Zlib::zlib_version();

Returns the version of the zlib library.

=head1 CONSTANTS

All the I&lt;zlib&gt; constants are automatically imported when you make use
of I&lt;Compress::Zlib&gt;.

=head1 SEE ALSO

L&lt;IO::Compress::Gzip&gt;, L&lt;IO::Uncompress::Gunzip&gt;, L&lt;IO::Compress::Deflate&gt;, L&lt;IO::Uncompress::Inflate&gt;, L&lt;IO::Compress::RawDeflate&gt;, L&lt;IO::Uncompress::RawInflate&gt;, L&lt;IO::Compress::Bzip2&gt;, L&lt;IO::Uncompress::Bunzip2&gt;, L&lt;IO::Compress::Lzma&gt;, L&lt;IO::Uncompress::UnLzma&gt;, L&lt;IO::Compress::Xz&gt;, L&lt;IO::Uncompress::UnXz&gt;, L&lt;IO::Compress::Lzop&gt;, L&lt;IO::Uncompress::UnLzop&gt;, L&lt;IO::Compress::Lzf&gt;, L&lt;IO::Uncompress::UnLzf&gt;, L&lt;IO::Uncompress::AnyInflate&gt;, L&lt;IO::Uncompress::AnyUncompress&gt;

L&lt;IO::Compress::FAQ|IO::Compress::FAQ&gt;

L&lt;File::GlobMapper|File::GlobMapper&gt;, L&lt;Archive::Zip|Archive::Zip&gt;,
L&lt;Archive::Tar|Archive::Tar&gt;,
L&lt;IO::Zlib|IO::Zlib&gt;

For RFC 1950, 1951 and 1952 see 
L&lt;http://www.faqs.org/rfcs/rfc1950.html&gt;,
L&lt;http://www.faqs.org/rfcs/rfc1951.html&gt; and
L&lt;http://www.faqs.org/rfcs/rfc1952.html&gt;

The I&lt;zlib&gt; compression library was written by Jean-loup Gailly
C&lt;gzip@prep.ai.mit.edu&gt; and Mark Adler C&lt;madler@alumni.caltech.edu&gt;.

The primary site for the I&lt;zlib&gt; compression library is
L&lt;http://www.zlib.org&gt;.

The primary site for gzip is L&lt;http://www.gzip.org&gt;.

=head1 AUTHOR

This module was written by Paul Marquess, C&lt;pmqs@cpan.org&gt;. 

=head1 MODIFICATION HISTORY

See the Changes file.

=head1 COPYRIGHT AND LICENSE

Copyright (c) 1995-2017 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.

</pre></body></html>