CINXE.COM
Compress::Zlib - Interface to zlib compression library - Perldoc Browser
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Compress::Zlib - Interface to zlib compression library - Perldoc Browser</title> <link rel="search" href="/opensearch.xml" type="application/opensearchdescription+xml" title="Perldoc Browser"> <link rel="canonical" href="https://perldoc.perl.org/Compress::Zlib"> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/styles/stackoverflow-light.min.css" integrity="sha512-cG1IdFxqipi3gqLmksLtuk13C+hBa57a6zpWxMeoY3Q9O6ooFxq50DayCdm0QrDgZjMUn23z/0PMZlgft7Yp5Q==" crossorigin="anonymous" /> <style> body { background: #f4f4f5; color: #020202; } .navbar-dark { background-image: -webkit-linear-gradient(top, #005f85 0, #002e49 100%); background-image: -o-linear-gradient(top, #005f85 0, #002e49 100%); background-image: linear-gradient(to bottom, #005f85 0, #002e49 100%); filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff005f85', endColorstr='#ff002e49', GradientType=0); background-repeat: repeat-x; } .navbar-dark .navbar-nav .nav-link, .navbar-dark .navbar-nav .nav-link:focus { color: #fff } .navbar-dark .navbar-nav .nav-link:hover { color: #ffef68 } #wrapperlicious { margin: 0 auto; font: 0.9em 'Helvetica Neue', Helvetica, sans-serif; font-weight: normal; line-height: 1.5em; margin: 0; padding: 0; } #wrapperlicious h1 { font-size: 1.5em } #wrapperlicious h2 { font-size: 1.3em } #wrapperlicious h3 { font-size: 1.1em } #wrapperlicious h4 { font-size: 0.9em } #wrapperlicious h1, #wrapperlicious h2, #wrapperlicious h3, #wrapperlicious h4, #wrapperlicious dt { color: #020202; margin-top: 1em; margin-bottom: 1em; position: relative; font-weight: bold; } #wrapperlicious a { color: inherit; text-decoration: underline } #wrapperlicious #toc { text-decoration: none } #wrapperlicious a:hover { color: #2a2a2a } #wrapperlicious a img { border: 0 } #wrapperlicious :not(pre) > code { color: inherit; background-color: rgba(0, 0, 0, 0.04); border-radius: 3px; font: 0.9em Consolas, Menlo, Monaco, monospace; padding: 0.3em; } #wrapperlicious dd { margin: 0; margin-left: 2em; } #wrapperlicious dt { color: #2a2a2a; font-weight: bold; margin-left: 0.9em; } #wrapperlicious p { margin-bottom: 1em; margin-top: 1em; } #wrapperlicious li > p { margin-bottom: 0; margin-top: 0; } #wrapperlicious pre { border: 1px solid #c1c1c1; border-radius: 3px; font: 100% Consolas, Menlo, Monaco, monospace; margin-bottom: 1em; margin-top: 1em; } #wrapperlicious pre > code { display: block; background-color: #f6f6f6; font: 0.9em Consolas, Menlo, Monaco, monospace; line-height: 1.5em; text-align: left; white-space: pre; padding: 1em; } #wrapperlicious dl, #wrapperlicious ol, #wrapperlicious ul { margin-bottom: 1em; margin-top: 1em; } #wrapperlicious ul { list-style-type: square; } #wrapperlicious ul ul { margin-bottom: 0px; margin-top: 0px; } #footer { font-size: 0.8em; padding-top: 0.5em; text-align: center; } #more { display: inline; font-size: 0.8em; } #perldocdiv { background-color: #fff; border: 1px solid #c1c1c1; border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; margin-left: auto; margin-right: auto; padding: 3em; padding-top: 1em; max-width: 960px; } #moduleversion { float: right } #wrapperlicious .leading-notice { font-style: italic; padding-left: 1em; margin-top: 1em; margin-bottom: 1em; } #wrapperlicious .permalink { display: none; left: -0.75em; position: absolute; padding-right: 0.25em; text-decoration: none; } #wrapperlicious h1:hover .permalink, #wrapperlicious h2:hover .permalink, #wrapperlicious h3:hover .permalink, #wrapperlicious h4:hover .permalink, #wrapperlicious dt:hover .permalink { display: block; } </style> <!-- Global site tag (gtag.js) - Google Analytics --> <script async src="https://www.googletagmanager.com/gtag/js?id=G-KVNWBNT5FB"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'G-KVNWBNT5FB'); gtag('config', 'UA-50555-3'); </script> </head> <body> <nav class="navbar navbar-expand-md navbar-dark bg-dark justify-content-between"> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <a class="navbar-brand" href="/"><img src="/images/perl_camel_30.png" width="30" height="30" class="d-inline-block align-top" alt="Perl Camel Logo"> Perldoc Browser</a> <div class="collapse navbar-collapse" id="navbarNav"> <ul class="navbar-nav mr-auto"> <li class="nav-item dropdown text-nowrap"> <a class="nav-link dropdown-toggle" href="#" id="dropdownlink-stable" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">5.28.3</a> <div class="dropdown-menu" aria-labelledby="dropdownlink-stable"> <a class="dropdown-item" href="/Compress::Zlib">Latest</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.40.1/Compress::Zlib">5.40.1</a> <a class="dropdown-item" href="/5.40.0/Compress::Zlib">5.40.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.38.3/Compress::Zlib">5.38.3</a> <a class="dropdown-item" href="/5.38.2/Compress::Zlib">5.38.2</a> <a class="dropdown-item" href="/5.38.1/Compress::Zlib">5.38.1</a> <a class="dropdown-item" href="/5.38.0/Compress::Zlib">5.38.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.36.3/Compress::Zlib">5.36.3</a> <a class="dropdown-item" href="/5.36.2/Compress::Zlib">5.36.2</a> <a class="dropdown-item" href="/5.36.1/Compress::Zlib">5.36.1</a> <a class="dropdown-item" href="/5.36.0/Compress::Zlib">5.36.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.34.3/Compress::Zlib">5.34.3</a> <a class="dropdown-item" href="/5.34.2/Compress::Zlib">5.34.2</a> <a class="dropdown-item" href="/5.34.1/Compress::Zlib">5.34.1</a> <a class="dropdown-item" href="/5.34.0/Compress::Zlib">5.34.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.32.1/Compress::Zlib">5.32.1</a> <a class="dropdown-item" href="/5.32.0/Compress::Zlib">5.32.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.30.3/Compress::Zlib">5.30.3</a> <a class="dropdown-item" href="/5.30.2/Compress::Zlib">5.30.2</a> <a class="dropdown-item" href="/5.30.1/Compress::Zlib">5.30.1</a> <a class="dropdown-item" href="/5.30.0/Compress::Zlib">5.30.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item active" href="/5.28.3/Compress::Zlib">5.28.3</a> <a class="dropdown-item" href="/5.28.2/Compress::Zlib">5.28.2</a> <a class="dropdown-item" href="/5.28.1/Compress::Zlib">5.28.1</a> <a class="dropdown-item" href="/5.28.0/Compress::Zlib">5.28.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.26.3/Compress::Zlib">5.26.3</a> <a class="dropdown-item" href="/5.26.2/Compress::Zlib">5.26.2</a> <a class="dropdown-item" href="/5.26.1/Compress::Zlib">5.26.1</a> <a class="dropdown-item" href="/5.26.0/Compress::Zlib">5.26.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.24.4/Compress::Zlib">5.24.4</a> <a class="dropdown-item" href="/5.24.3/Compress::Zlib">5.24.3</a> <a class="dropdown-item" href="/5.24.2/Compress::Zlib">5.24.2</a> <a class="dropdown-item" href="/5.24.1/Compress::Zlib">5.24.1</a> <a class="dropdown-item" href="/5.24.0/Compress::Zlib">5.24.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.22.4/Compress::Zlib">5.22.4</a> <a class="dropdown-item" href="/5.22.3/Compress::Zlib">5.22.3</a> <a class="dropdown-item" href="/5.22.2/Compress::Zlib">5.22.2</a> <a class="dropdown-item" href="/5.22.1/Compress::Zlib">5.22.1</a> <a class="dropdown-item" href="/5.22.0/Compress::Zlib">5.22.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.20.3/Compress::Zlib">5.20.3</a> <a class="dropdown-item" href="/5.20.2/Compress::Zlib">5.20.2</a> <a class="dropdown-item" href="/5.20.1/Compress::Zlib">5.20.1</a> <a class="dropdown-item" href="/5.20.0/Compress::Zlib">5.20.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.18.4/Compress::Zlib">5.18.4</a> <a class="dropdown-item" href="/5.18.3/Compress::Zlib">5.18.3</a> <a class="dropdown-item" href="/5.18.2/Compress::Zlib">5.18.2</a> <a class="dropdown-item" href="/5.18.1/Compress::Zlib">5.18.1</a> <a class="dropdown-item" href="/5.18.0/Compress::Zlib">5.18.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.16.3/Compress::Zlib">5.16.3</a> <a class="dropdown-item" href="/5.16.2/Compress::Zlib">5.16.2</a> <a class="dropdown-item" href="/5.16.1/Compress::Zlib">5.16.1</a> <a class="dropdown-item" href="/5.16.0/Compress::Zlib">5.16.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.14.4/Compress::Zlib">5.14.4</a> <a class="dropdown-item" href="/5.14.3/Compress::Zlib">5.14.3</a> <a class="dropdown-item" href="/5.14.2/Compress::Zlib">5.14.2</a> <a class="dropdown-item" href="/5.14.1/Compress::Zlib">5.14.1</a> <a class="dropdown-item" href="/5.14.0/Compress::Zlib">5.14.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.12.5/Compress::Zlib">5.12.5</a> <a class="dropdown-item" href="/5.12.4/Compress::Zlib">5.12.4</a> <a class="dropdown-item" href="/5.12.3/Compress::Zlib">5.12.3</a> <a class="dropdown-item" href="/5.12.2/Compress::Zlib">5.12.2</a> <a class="dropdown-item" href="/5.12.1/Compress::Zlib">5.12.1</a> <a class="dropdown-item" href="/5.12.0/Compress::Zlib">5.12.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.10.1/Compress::Zlib">5.10.1</a> <a class="dropdown-item" href="/5.10.0/Compress::Zlib">5.10.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.8.9/Compress::Zlib">5.8.9</a> <a class="dropdown-item" href="/5.8.8/Compress::Zlib">5.8.8</a> <a class="dropdown-item" href="/5.8.7/Compress::Zlib">5.8.7</a> <a class="dropdown-item" href="/5.8.6/Compress::Zlib">5.8.6</a> <a class="dropdown-item" href="/5.8.5/Compress::Zlib">5.8.5</a> <a class="dropdown-item" href="/5.8.4/Compress::Zlib">5.8.4</a> <a class="dropdown-item" href="/5.8.3/Compress::Zlib">5.8.3</a> <a class="dropdown-item" href="/5.8.2/Compress::Zlib">5.8.2</a> <a class="dropdown-item" href="/5.8.1/Compress::Zlib">5.8.1</a> <a class="dropdown-item" href="/5.8.0/Compress::Zlib">5.8.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.6.2/Compress::Zlib">5.6.2</a> <a class="dropdown-item" href="/5.6.1/Compress::Zlib">5.6.1</a> <a class="dropdown-item" href="/5.6.0/Compress::Zlib">5.6.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.005_04/Compress::Zlib">5.005_04</a> <a class="dropdown-item" href="/5.005_03/Compress::Zlib">5.005_03</a> <a class="dropdown-item" href="/5.005_02/Compress::Zlib">5.005_02</a> <a class="dropdown-item" href="/5.005_01/Compress::Zlib">5.005_01</a> <a class="dropdown-item" href="/5.005/Compress::Zlib">5.005</a> </div> </li> <li class="nav-item dropdown text-nowrap"> <a class="nav-link dropdown-toggle" href="#" id="dropdownlink-dev" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dev</a> <div class="dropdown-menu" aria-labelledby="dropdownlink-dev"> <a class="dropdown-item" href="/blead/Compress::Zlib">blead</a> <a class="dropdown-item" href="/5.41.10/Compress::Zlib">5.41.10</a> <a class="dropdown-item" href="/5.41.9/Compress::Zlib">5.41.9</a> <a class="dropdown-item" href="/5.41.8/Compress::Zlib">5.41.8</a> <a class="dropdown-item" href="/5.41.7/Compress::Zlib">5.41.7</a> <a class="dropdown-item" href="/5.41.6/Compress::Zlib">5.41.6</a> <a class="dropdown-item" href="/5.41.5/Compress::Zlib">5.41.5</a> <a class="dropdown-item" href="/5.41.4/Compress::Zlib">5.41.4</a> <a class="dropdown-item" href="/5.41.3/Compress::Zlib">5.41.3</a> <a class="dropdown-item" href="/5.41.2/Compress::Zlib">5.41.2</a> <a class="dropdown-item" href="/5.41.1/Compress::Zlib">5.41.1</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.40.1-RC1/Compress::Zlib">5.40.1-RC1</a> <a class="dropdown-item" href="/5.40.0-RC2/Compress::Zlib">5.40.0-RC2</a> <a class="dropdown-item" href="/5.40.0-RC1/Compress::Zlib">5.40.0-RC1</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.39.10/Compress::Zlib">5.39.10</a> <a class="dropdown-item" href="/5.39.9/Compress::Zlib">5.39.9</a> <a class="dropdown-item" href="/5.39.8/Compress::Zlib">5.39.8</a> <a class="dropdown-item" href="/5.39.7/Compress::Zlib">5.39.7</a> <a class="dropdown-item" href="/5.39.6/Compress::Zlib">5.39.6</a> <a class="dropdown-item" href="/5.39.5/Compress::Zlib">5.39.5</a> <a class="dropdown-item" href="/5.39.4/Compress::Zlib">5.39.4</a> <a class="dropdown-item" href="/5.39.3/Compress::Zlib">5.39.3</a> <a class="dropdown-item" href="/5.39.2/Compress::Zlib">5.39.2</a> <a class="dropdown-item" href="/5.39.1/Compress::Zlib">5.39.1</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.38.3-RC1/Compress::Zlib">5.38.3-RC1</a> </div> </li> <li class="nav-item dropdown text-nowrap"> <a class="nav-link dropdown-toggle" href="#" id="dropdownlink-nav" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Documentation</a> <div class="dropdown-menu" aria-labelledby="dropdownlink-nav"> <a class="dropdown-item" href="/5.28.3/perl">Perl</a> <a class="dropdown-item" href="/5.28.3/perlintro">Intro</a> <a class="dropdown-item" href="/5.28.3/perl#Tutorials">Tutorials</a> <a class="dropdown-item" href="/5.28.3/perlfaq">FAQs</a> <a class="dropdown-item" href="/5.28.3/perl#Reference-Manual">Reference</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.28.3/perlop">Operators</a> <a class="dropdown-item" href="/5.28.3/functions">Functions</a> <a class="dropdown-item" href="/5.28.3/variables">Variables</a> <a class="dropdown-item" href="/5.28.3/modules">Modules</a> <a class="dropdown-item" href="/5.28.3/perlutil">Utilities</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.28.3/perldelta">Release Notes</a> <a class="dropdown-item" href="/5.28.3/perlcommunity">Community</a> <a class="dropdown-item" href="/5.28.3/perlhist">History</a> </div> </li> </ul> <ul class="navbar-nav"> <script> function set_expand (expand) { var perldocdiv = document.getElementById('perldocdiv'); var width = window.getComputedStyle(perldocdiv).getPropertyValue('max-width'); var expanded = (width == '' || width == 'none') ? true : false; if (expand === null) { expand = !expanded; } if ((expand && !expanded) || (!expand && expanded)) { perldocdiv.style.setProperty('max-width', expand ? 'none' : '960px'); var button_classlist = document.getElementById('content-expand-button').classList; if (expand) { button_classlist.add('btn-light'); button_classlist.remove('btn-outline-light'); } else { button_classlist.add('btn-outline-light'); button_classlist.remove('btn-light'); } } return expand; } function toggle_expand () { var expand = set_expand(null); document.cookie = 'perldoc_expand=' + (expand ? 1 : 0) + '; path=/; expires=Tue, 19 Jan 2038 03:14:07 UTC'; } function read_expand () { return document.cookie.split(';').some(function (item) { return item.indexOf('perldoc_expand=1') >= 0 }); } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', function () { if (read_expand()) { set_expand(true); } }); } else if (read_expand()) { set_expand(true); } </script> <button id="content-expand-button" type="button" class="btn btn-outline-light d-none d-lg-inline-block mr-4" onclick="toggle_expand()">Expand</button> </ul> <form class="form-inline" method="get" action="/5.28.3/search"> <input class="form-control mr-3" type="search" name="q" placeholder="Search" aria-label="Search" value=""> </form> </div> </nav> <div id="wrapperlicious" class="container-fluid"> <div id="perldocdiv"> <div id="links"> <a href="/5.28.3/Compress::Zlib">Compress::Zlib</a> <div id="more"> (<a href="/5.28.3/Compress::Zlib.txt">source</a>, <a href="https://metacpan.org/pod/Compress::Zlib">CPAN</a>) </div> <div id="moduleversion">version 2.074</div> </div> <div class="leading-notice"> You are viewing the version of this documentation from Perl 5.28.3. <a href="/Compress::Zlib">View the latest version</a> </div> <h1><a id="toc">CONTENTS</a></h1> <ul> <li> <a class="text-decoration-none" href="#NAME">NAME</a> </li> <li> <a class="text-decoration-none" href="#SYNOPSIS">SYNOPSIS</a> </li> <li> <a class="text-decoration-none" href="#DESCRIPTION">DESCRIPTION</a> <ul> <li> <a class="text-decoration-none" href="#Notes-for-users-of-Compress::Zlib-version-1">Notes for users of Compress::Zlib version 1</a> </li> </ul> </li> <li> <a class="text-decoration-none" href="#GZIP-INTERFACE">GZIP INTERFACE</a> <ul> <li> <a class="text-decoration-none" href="#Examples">Examples</a> </li> <li> <a class="text-decoration-none" href="#Compress::Zlib::memGzip">Compress::Zlib::memGzip</a> </li> <li> <a class="text-decoration-none" href="#Compress::Zlib::memGunzip">Compress::Zlib::memGunzip</a> </li> </ul> </li> <li> <a class="text-decoration-none" href="#COMPRESS/UNCOMPRESS">COMPRESS/UNCOMPRESS</a> </li> <li> <a class="text-decoration-none" href="#Deflate-Interface">Deflate Interface</a> <ul> <li> <a class="text-decoration-none" href="#($d,-$status)-=-deflateInit(-%5BOPT%5D-)">($d, $status) = deflateInit( [OPT] )</a> </li> <li> <a class="text-decoration-none" href="#($out,-$status)-=-$d-%3Edeflate($buffer)">($out, $status) = $d->deflate($buffer)</a> </li> <li> <a class="text-decoration-none" href="#($out,-$status)-=-$d-%3Eflush()-=head2-($out,-$status)-=-$d-%3Eflush($flush_type)">($out, $status) = $d->flush() =head2 ($out, $status) = $d->flush($flush_type)</a> </li> <li> <a class="text-decoration-none" href="#$status-=-$d-%3EdeflateParams(%5BOPT%5D)">$status = $d->deflateParams([OPT])</a> </li> <li> <a class="text-decoration-none" href="#$d-%3Edict_adler()">$d->dict_adler()</a> </li> <li> <a class="text-decoration-none" href="#$d-%3Emsg()">$d->msg()</a> </li> <li> <a class="text-decoration-none" href="#$d-%3Etotal_in()">$d->total_in()</a> </li> <li> <a class="text-decoration-none" href="#$d-%3Etotal_out()">$d->total_out()</a> </li> <li> <a class="text-decoration-none" href="#Example">Example</a> </li> </ul> </li> <li> <a class="text-decoration-none" href="#Inflate-Interface">Inflate Interface</a> <ul> <li> <a class="text-decoration-none" href="#($i,-$status)-=-inflateInit()">($i, $status) = inflateInit()</a> </li> <li> <a class="text-decoration-none" href="#($out,-$status)-=-$i-%3Einflate($buffer)">($out, $status) = $i->inflate($buffer)</a> </li> <li> <a class="text-decoration-none" href="#$status-=-$i-%3EinflateSync($buffer)">$status = $i->inflateSync($buffer)</a> </li> <li> <a class="text-decoration-none" href="#$i-%3Edict_adler()">$i->dict_adler()</a> </li> <li> <a class="text-decoration-none" href="#$i-%3Emsg()">$i->msg()</a> </li> <li> <a class="text-decoration-none" href="#$i-%3Etotal_in()">$i->total_in()</a> </li> <li> <a class="text-decoration-none" href="#$i-%3Etotal_out()">$i->total_out()</a> </li> <li> <a class="text-decoration-none" href="#Example1">Example</a> </li> </ul> </li> <li> <a class="text-decoration-none" href="#CHECKSUM-FUNCTIONS">CHECKSUM FUNCTIONS</a> </li> <li> <a class="text-decoration-none" href="#Misc">Misc</a> <ul> <li> <a class="text-decoration-none" href="#my-$version-=-Compress::Zlib::zlib_version();">my $version = Compress::Zlib::zlib_version();</a> </li> </ul> </li> <li> <a class="text-decoration-none" href="#CONSTANTS">CONSTANTS</a> </li> <li> <a class="text-decoration-none" href="#SEE-ALSO">SEE ALSO</a> </li> <li> <a class="text-decoration-none" href="#AUTHOR">AUTHOR</a> </li> <li> <a class="text-decoration-none" href="#MODIFICATION-HISTORY">MODIFICATION HISTORY</a> </li> <li> <a class="text-decoration-none" href="#COPYRIGHT-AND-LICENSE">COPYRIGHT AND LICENSE</a> </li> </ul> <h1 id="NAME"><a class="permalink" href="#NAME">#</a>NAME</h1> <p>Compress::Zlib - Interface to zlib compression library</p> <h1 id="SYNOPSIS"><a class="permalink" href="#SYNOPSIS">#</a>SYNOPSIS</h1> <pre><code>use Compress::Zlib ; ($d, $status) = deflateInit( [OPT] ) ; $status = $d->deflate($input, $output) ; $status = $d->flush([$flush_type]) ; $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) = inflateInit( [OPT] ) ; $status = $i->inflate($input, $output [, $eof]) ; $status = $i->inflateSync($input) ; $i->dict_adler() ; $d->crc32() ; $d->adler32() ; $i->total_in() ; $i->total_out() ; $i->msg() ; $d->get_BufSize(); $dest = compress($source) ; $dest = uncompress($source) ; $gz = gzopen($filename or filehandle, $mode) ; $bytesread = $gz->gzread($buffer [,$size]) ; $bytesread = $gz->gzreadline($line) ; $byteswritten = $gz->gzwrite($buffer) ; $status = $gz->gzflush($flush) ; $offset = $gz->gztell() ; $status = $gz->gzseek($offset, $whence) ; $status = $gz->gzclose() ; $status = $gz->gzeof() ; $status = $gz->gzsetparams($level, $strategy) ; $errstring = $gz->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();</code></pre> <h1 id="DESCRIPTION"><a class="permalink" href="#DESCRIPTION">#</a>DESCRIPTION</h1> <p>The <i>Compress::Zlib</i> module provides a Perl interface to the <i>zlib</i> compression library (see <a href="#AUTHOR">"AUTHOR"</a> for details about where to get <i>zlib</i>).</p> <p>The <code>Compress::Zlib</code> module can be split into two general areas of functionality, namely a simple read/write interface to <i>gzip</i> files and a low-level in-memory compression/decompression interface.</p> <p>Each of these areas will be discussed in the following sections.</p> <h2 id="Notes-for-users-of-Compress::Zlib-version-1"><a class="permalink" href="#Notes-for-users-of-Compress::Zlib-version-1">#</a><a id="Notes"></a>Notes for users of Compress::Zlib version 1</h2> <p>The main change in <code>Compress::Zlib</code> version 2.x is that it does not now interface directly to the zlib library. Instead it uses the <code>IO::Compress::Gzip</code> and <code>IO::Uncompress::Gunzip</code> modules for reading/writing gzip files, and the <code>Compress::Raw::Zlib</code> module for some low-level zlib access.</p> <p>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 <a href="#AUTHOR">"AUTHOR"</a>). See <a href="#GZIP-INTERFACE">"GZIP INTERFACE"</a></p> <p>With the creation of the <code>IO::Compress</code> and <code>IO::Uncompress</code> modules no new features are planned for <code>Compress::Zlib</code> - the new modules do everything that <code>Compress::Zlib</code> does and then some. Development on <code>Compress::Zlib</code> will be limited to bug fixes only.</p> <p>If you are writing new code, your first port of call should be one of the new <code>IO::Compress</code> or <code>IO::Uncompress</code> modules.</p> <h1 id="GZIP-INTERFACE"><a class="permalink" href="#GZIP-INTERFACE">#</a><a id="GZIP"></a>GZIP INTERFACE</h1> <p>A number of functions are supplied in <i>zlib</i> for reading and writing <i>gzip</i> files that conform to RFC 1952. This module provides an interface to most of them.</p> <p>If you have previously used <code>Compress::Zlib</code> 1.x, the following enhancements/changes have been made to the <code>gzopen</code> interface:</p> <ol> <li><p>If you want to open either STDIN or STDOUT with <code>gzopen</code>, you can now optionally use the special filename "<code>-</code>" as a synonym for <code>\*STDIN</code> and <code>\*STDOUT</code>.</p> </li> <li><p>In <code>Compress::Zlib</code> version 1.x, <code>gzopen</code> used the zlib library to open the underlying file. This made things especially tricky when a Perl filehandle was passed to <code>gzopen</code>. Behind the scenes the numeric C file descriptor had to be extracted from the Perl filehandle and this passed to the zlib library.</p> <p>Apart from being non-portable to some operating systems, this made it difficult to use <code>gzopen</code> 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.</p> <p>It also made it impossible to pass a perl filehandle that wasn't associated with a real filesystem file, like, say, an <code>IO::String</code>.</p> <p>In <code>Compress::Zlib</code> version 2.x, the <code>gzopen</code> interface has been completely rewritten to use the <a href="/5.28.3/IO::Compress::Gzip">IO::Compress::Gzip</a> for writing gzip files and <a href="/5.28.3/IO::Uncompress::Gunzip">IO::Uncompress::Gunzip</a> for reading gzip files. None of the limitations mentioned above apply.</p> </li> <li><p>Addition of <code>gzseek</code> to provide a restricted <code>seek</code> interface.</p> </li> <li><p>Added <code>gztell</code>.</p> </li> </ol> <p>A more complete and flexible interface for reading/writing gzip files/buffers is included with the module <code>IO-Compress-Zlib</code>. See <a href="/5.28.3/IO::Compress::Gzip">IO::Compress::Gzip</a> and <a href="/5.28.3/IO::Uncompress::Gunzip">IO::Uncompress::Gunzip</a> for more details.</p> <dl> <dt id="$gz-=-gzopen($filename,-$mode)"><a class="permalink" href="#$gz-=-gzopen($filename,-$mode)">#</a><a id="gz-gzopen-filename-mode"></a><b>$gz = gzopen($filename, $mode)</b></dt> <dd> </dd> <dt id="$gz-=-gzopen($filehandle,-$mode)"><a class="permalink" href="#$gz-=-gzopen($filehandle,-$mode)">#</a><a id="gz-gzopen-filehandle-mode"></a><b>$gz = gzopen($filehandle, $mode)</b></dt> <dd> <p>This function opens either the <i>gzip</i> file <code>$filename</code> for reading or writing or attaches to the opened filehandle, <code>$filehandle</code>. It returns an object on success and <code>undef</code> on failure.</p> <p>When writing a gzip file this interface will <i>always</i> 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 <a href="/5.28.3/IO::Compress::Gzip">IO::Compress::Gzip</a> instead. Similarly if you want to read the contents of the gzip header use <a href="/5.28.3/IO::Uncompress::Gunzip">IO::Uncompress::Gunzip</a>.</p> <p>The second parameter, <code>$mode</code>, 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 <code>$mode</code> parameter is similar to the mode parameter to the 'C' function <code>fopen</code>, so "rb" is used to open for reading, "wb" for writing and "ab" for appending (writing at the end of the file).</p> <p>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.</p> <p>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.</p> <p>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.</p> <p>Refer to the <i>zlib</i> documentation for the exact format of the <code>$mode</code> parameter.</p> </dd> <dt id="$bytesread-=-$gz->gzread($buffer-[,-$size])-;"><a class="permalink" href="#$bytesread-=-$gz-%3Egzread($buffer-%5B,-$size%5D)-;">#</a><a id="bytesread-gz-gzread-buffer-size"></a><b>$bytesread = $gz->gzread($buffer [, $size]) ;</b></dt> <dd> <p>Reads <code>$size</code> bytes from the compressed file into <code>$buffer</code>. If <code>$size</code> is not specified, it will default to 4096. If the scalar <code>$buffer</code> is not large enough, it will be extended automatically.</p> <p>Returns the number of bytes actually read. On EOF it returns 0 and in the case of an error, -1.</p> </dd> <dt id="$bytesread-=-$gz->gzreadline($line)-;"><a class="permalink" href="#$bytesread-=-$gz-%3Egzreadline($line)-;">#</a><a id="bytesread-gz-gzreadline-line"></a><b>$bytesread = $gz->gzreadline($line) ;</b></dt> <dd> <p>Reads the next line from the compressed file into <code>$line</code>.</p> <p>Returns the number of bytes actually read. On EOF it returns 0 and in the case of an error, -1.</p> <p>It is legal to intermix calls to <code>gzread</code> and <code>gzreadline</code>.</p> <p>To maintain backward compatibility with version 1.x of this module <code>gzreadline</code> ignores the <code>$/</code> variable - it <i>always</i> uses the string <code>"\n"</code> as the line delimiter.</p> <p>If you want to read a gzip file a line at a time and have it respect the <code>$/</code> variable (or <code>$INPUT_RECORD_SEPARATOR</code>, or <code>$RS</code> when <code>English</code> is in use) see <a href="/5.28.3/IO::Uncompress::Gunzip">IO::Uncompress::Gunzip</a>.</p> </dd> <dt id="$byteswritten-=-$gz->gzwrite($buffer)-;"><a class="permalink" href="#$byteswritten-=-$gz-%3Egzwrite($buffer)-;">#</a><a id="byteswritten-gz-gzwrite-buffer"></a><b>$byteswritten = $gz->gzwrite($buffer) ;</b></dt> <dd> <p>Writes the contents of <code>$buffer</code> to the compressed file. Returns the number of bytes actually written, or 0 on error.</p> </dd> <dt id="$status-=-$gz->gzflush($flush_type)-;"><a class="permalink" href="#$status-=-$gz-%3Egzflush($flush_type)-;">#</a><a id="status-gz-gzflush-flush_type"></a><b>$status = $gz->gzflush($flush_type) ;</b></dt> <dd> <p>Flushes all pending output into the compressed file.</p> <p>This method takes an optional parameter, <code>$flush_type</code>, that controls how the flushing will be carried out. By default the <code>$flush_type</code> used is <code>Z_FINISH</code>. Other valid values for <code>$flush_type</code> are <code>Z_NO_FLUSH</code>, <code>Z_SYNC_FLUSH</code>, <code>Z_FULL_FLUSH</code> and <code>Z_BLOCK</code>. It is strongly recommended that you only set the <code>flush_type</code> parameter if you fully understand the implications of what it does - overuse of <code>flush</code> can seriously degrade the level of compression achieved. See the <code>zlib</code> documentation for details.</p> <p>Returns 0 on success.</p> </dd> <dt id="$offset-=-$gz->gztell()-;"><a class="permalink" href="#$offset-=-$gz-%3Egztell()-;">#</a><a id="offset-gz-gztell"></a><b>$offset = $gz->gztell() ;</b></dt> <dd> <p>Returns the uncompressed file offset.</p> </dd> <dt id="$status-=-$gz->gzseek($offset,-$whence)-;"><a class="permalink" href="#$status-=-$gz-%3Egzseek($offset,-$whence)-;">#</a><a id="status-gz-gzseek-offset-whence"></a><b>$status = $gz->gzseek($offset, $whence) ;</b></dt> <dd> <p>Provides a sub-set of the <code>seek</code> 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.</p> <p>When opened for writing, empty parts of the file will have NULL (0x00) bytes written to them.</p> <p>The <code>$whence</code> parameter should be one of SEEK_SET, SEEK_CUR or SEEK_END.</p> <p>Returns 1 on success, 0 on failure.</p> </dd> <dt id="$gz->gzclose"><a class="permalink" href="#$gz-%3Egzclose">#</a><a id="gzclose"></a><a id="gz-gzclose"></a><b>$gz->gzclose</b></dt> <dd> <p>Closes the compressed file. Any pending data is flushed to the file before it is closed.</p> <p>Returns 0 on success.</p> </dd> <dt id="$gz->gzsetparams($level,-$strategy"><a class="permalink" href="#$gz-%3Egzsetparams($level,-$strategy">#</a><a id="gzsetparams"></a><a id="gz-gzsetparams-level-strategy"></a><b>$gz->gzsetparams($level, $strategy</b></dt> <dd> <p>Change settings for the deflate stream <code>$gz</code>.</p> <p>The list of the valid options is shown below. Options not specified will remain unchanged.</p> <p>Note: This method is only available if you are running zlib 1.0.6 or better.</p> <dl> <dt id="$level"><a class="permalink" href="#$level">#</a><a id="level"></a><b>$level</b></dt> <dd> <p>Defines the compression level. Valid values are 0 through 9, <code>Z_NO_COMPRESSION</code>, <code>Z_BEST_SPEED</code>, <code>Z_BEST_COMPRESSION</code>, and <code>Z_DEFAULT_COMPRESSION</code>.</p> </dd> <dt id="$strategy"><a class="permalink" href="#$strategy">#</a><a id="strategy"></a><b>$strategy</b></dt> <dd> <p>Defines the strategy used to tune the compression. The valid values are <code>Z_DEFAULT_STRATEGY</code>, <code>Z_FILTERED</code> and <code>Z_HUFFMAN_ONLY</code>.</p> </dd> </dl> </dd> <dt id="$gz->gzerror"><a class="permalink" href="#$gz-%3Egzerror">#</a><a id="gzerror"></a><a id="gz-gzerror"></a><b>$gz->gzerror</b></dt> <dd> <p>Returns the <i>zlib</i> error message or number for the last operation associated with <code>$gz</code>. The return value will be the <i>zlib</i> error number when used in a numeric context and the <i>zlib</i> error message when used in a string context. The <i>zlib</i> error number constants, shown below, are available for use.</p> <pre><code class="plaintext">Z_OK Z_STREAM_END Z_ERRNO Z_STREAM_ERROR Z_DATA_ERROR Z_MEM_ERROR Z_BUF_ERROR</code></pre> </dd> <dt id="$gzerrno"><a class="permalink" href="#$gzerrno">#</a><a id="gzerrno"></a><b>$gzerrno</b></dt> <dd> <p>The <code>$gzerrno</code> scalar holds the error code associated with the most recent <i>gzip</i> routine. Note that unlike <code>gzerror()</code>, the error is <i>not</i> associated with a particular file.</p> <p>As with <code>gzerror()</code> it returns an error number in numeric context and an error message in string context. Unlike <code>gzerror()</code> though, the error message will correspond to the <i>zlib</i> message when the error is associated with <i>zlib</i> itself, or the UNIX error message when it is not (i.e. <i>zlib</i> returned <code>Z_ERRORNO</code>).</p> <p>As there is an overlap between the error numbers used by <i>zlib</i> and UNIX, <code>$gzerrno</code> should only be used to check for the presence of <i>an</i> error in numeric context. Use <code>gzerror()</code> to check for specific <i>zlib</i> errors. The <i>gzcat</i> example below shows how the variable can be used safely.</p> </dd> </dl> <h2 id="Examples"><a class="permalink" href="#Examples">#</a>Examples</h2> <p>Here is an example script which uses the interface. It implements a <i>gzcat</i> function.</p> <pre><code>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->gzread($buffer) > 0 ; die "Error reading from $file: $gzerrno" . ($gzerrno+0) . "\n" if $gzerrno != Z_STREAM_END ; $gz->gzclose() ; }</code></pre> <p>Below is a script which makes use of <code>gzreadline</code>. It implements a very simple <i>grep</i> like script.</p> <pre><code>use strict ; use warnings ; use Compress::Zlib ; die "Usage: gzgrep pattern [file...]\n" unless @ARGV >= 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->gzreadline($_) > 0) { print if /$pattern/ ; } die "Error reading from $file: $gzerrno\n" if $gzerrno != Z_STREAM_END ; $gz->gzclose() ; }</code></pre> <p>This script, <i>gzstream</i>, does the opposite of the <i>gzcat</i> script above. It reads from standard input and writes a gzip data stream to standard output.</p> <pre><code>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 (<>) { $gz->gzwrite($_) or die "error writing: $gzerrno\n" ; } $gz->gzclose ;</code></pre> <h2 id="Compress::Zlib::memGzip"><a class="permalink" href="#Compress::Zlib::memGzip">#</a><a id="Compress"></a>Compress::Zlib::memGzip</h2> <p>This function is used to create an in-memory gzip file with the minimum possible gzip header (exactly 10 bytes).</p> <pre><code>$dest = Compress::Zlib::memGzip($buffer) or die "Cannot compress: $gzerrno\n";</code></pre> <p>If successful, it returns the in-memory gzip file. Otherwise it returns <code>undef</code> and the <code>$gzerrno</code> variable will store the zlib error code.</p> <p>The <code>$buffer</code> parameter can either be a scalar or a scalar reference.</p> <p>See <a href="/5.28.3/IO::Compress::Gzip">IO::Compress::Gzip</a> for an alternative way to carry out in-memory gzip compression.</p> <h2 id="Compress::Zlib::memGunzip"><a class="permalink" href="#Compress::Zlib::memGunzip">#</a><a id="Compress1"></a>Compress::Zlib::memGunzip</h2> <p>This function is used to uncompress an in-memory gzip file.</p> <pre><code>$dest = Compress::Zlib::memGunzip($buffer) or die "Cannot uncompress: $gzerrno\n";</code></pre> <p>If successful, it returns the uncompressed gzip file. Otherwise it returns <code>undef</code> and the <code>$gzerrno</code> variable will store the zlib error code.</p> <p>The <code>$buffer</code> parameter can either be a scalar or a scalar reference. The contents of the <code>$buffer</code> parameter are destroyed after calling this function.</p> <p>If <code>$buffer</code> consists of multiple concatenated gzip data streams only the first will be uncompressed. Use <code>gunzip</code> with the <code>MultiStream</code> option in the <code>IO::Uncompress::Gunzip</code> module if you need to deal with concatenated data streams.</p> <p>See <a href="/5.28.3/IO::Uncompress::Gunzip">IO::Uncompress::Gunzip</a> for an alternative way to carry out in-memory gzip uncompression.</p> <h1 id="COMPRESS/UNCOMPRESS"><a class="permalink" href="#COMPRESS/UNCOMPRESS">#</a><a id="COMPRESS"></a><a id="COMPRESS-UNCOMPRESS"></a>COMPRESS/UNCOMPRESS</h1> <p>Two functions are provided to perform in-memory compression/uncompression of RFC 1950 data streams. They are called <code>compress</code> and <code>uncompress</code>.</p> <dl> <dt id="$dest-=-compress($source-[,-$level]-)-;"><a class="permalink" href="#$dest-=-compress($source-%5B,-$level%5D-)-;">#</a><a id="dest-compress-source-level"></a><b>$dest = compress($source [, $level] ) ;</b></dt> <dd> <p>Compresses <code>$source</code>. If successful it returns the compressed data. Otherwise it returns <i>undef</i>.</p> <p>The source buffer, <code>$source</code>, can either be a scalar or a scalar reference.</p> <p>The <code>$level</code> parameter defines the compression level. Valid values are 0 through 9, <code>Z_NO_COMPRESSION</code>, <code>Z_BEST_SPEED</code>, <code>Z_BEST_COMPRESSION</code>, and <code>Z_DEFAULT_COMPRESSION</code>. If <code>$level</code> is not specified <code>Z_DEFAULT_COMPRESSION</code> will be used.</p> </dd> <dt id="$dest-=-uncompress($source)-;"><a class="permalink" href="#$dest-=-uncompress($source)-;">#</a><a id="dest-uncompress-source"></a><b>$dest = uncompress($source) ;</b></dt> <dd> <p>Uncompresses <code>$source</code>. If successful it returns the uncompressed data. Otherwise it returns <i>undef</i>.</p> <p>The source buffer can either be a scalar or a scalar reference.</p> </dd> </dl> <p>Please note: the two functions defined above are <i>not</i> compatible with the Unix commands of the same name.</p> <p>See <a href="/5.28.3/IO::Deflate">IO::Deflate</a> and <a href="/5.28.3/IO::Inflate">IO::Inflate</a> included with this distribution for an alternative interface for reading/writing RFC 1950 files/buffers.</p> <h1 id="Deflate-Interface"><a class="permalink" href="#Deflate-Interface">#</a><a id="Deflate"></a>Deflate Interface</h1> <p>This section defines an interface that allows in-memory compression using the <i>deflate</i> interface provided by zlib.</p> <p>Here is a definition of the interface available:</p> <h2 id="($d,-$status)-=-deflateInit(-[OPT]-)"><a class="permalink" href="#($d,-$status)-=-deflateInit(-%5BOPT%5D-)">#</a><a id="d-status-deflateInit-OPT"></a><b>($d, $status) = deflateInit( [OPT] )</b></h2> <p>Initialises a deflation stream.</p> <p>It combines the features of the <i>zlib</i> functions <code>deflateInit</code>, <code>deflateInit2</code> and <code>deflateSetDictionary</code>.</p> <p>If successful, it will return the initialised deflation stream, <code>$d</code> and <code>$status</code> of <code>Z_OK</code> in a list context. In scalar context it returns the deflation stream, <code>$d</code>, only.</p> <p>If not successful, the returned deflation stream (<code>$d</code>) will be <i>undef</i> and <code>$status</code> will hold the exact <i>zlib</i> error code.</p> <p>The function optionally takes a number of named options specified as <code>-Name=>value</code> pairs. This allows individual options to be tailored without having to specify them all in the parameter list.</p> <p>For backward compatibility, it is also possible to pass the parameters as a reference to a hash containing the name=>value pairs.</p> <p>The function takes one optional parameter, a reference to a hash. The contents of the hash allow the deflation interface to be tailored.</p> <p>Here is a list of the valid options:</p> <dl> <dt id="-Level"><a class="permalink" href="#-Level">#</a><a id="Level"></a><b>-Level</b></dt> <dd> <p>Defines the compression level. Valid values are 0 through 9, <code>Z_NO_COMPRESSION</code>, <code>Z_BEST_SPEED</code>, <code>Z_BEST_COMPRESSION</code>, and <code>Z_DEFAULT_COMPRESSION</code>.</p> <p>The default is Z_DEFAULT_COMPRESSION.</p> </dd> <dt id="-Method"><a class="permalink" href="#-Method">#</a><a id="Method"></a><b>-Method</b></dt> <dd> <p>Defines the compression method. The only valid value at present (and the default) is Z_DEFLATED.</p> </dd> <dt id="-WindowBits"><a class="permalink" href="#-WindowBits">#</a><a id="WindowBits"></a><b>-WindowBits</b></dt> <dd> <p>To create an RFC 1950 data stream, set <code>WindowBits</code> to a positive number.</p> <p>To create an RFC 1951 data stream, set <code>WindowBits</code> to <code>-MAX_WBITS</code>.</p> <p>For a full definition of the meaning and valid values for <code>WindowBits</code> refer to the <i>zlib</i> documentation for <i>deflateInit2</i>.</p> <p>Defaults to MAX_WBITS.</p> </dd> <dt id="-MemLevel"><a class="permalink" href="#-MemLevel">#</a><a id="MemLevel"></a><b>-MemLevel</b></dt> <dd> <p>For a definition of the meaning and valid values for <code>MemLevel</code> refer to the <i>zlib</i> documentation for <i>deflateInit2</i>.</p> <p>Defaults to MAX_MEM_LEVEL.</p> </dd> <dt id="-Strategy"><a class="permalink" href="#-Strategy">#</a><a id="Strategy"></a><b>-Strategy</b></dt> <dd> <p>Defines the strategy used to tune the compression. The valid values are <code>Z_DEFAULT_STRATEGY</code>, <code>Z_FILTERED</code> and <code>Z_HUFFMAN_ONLY</code>.</p> <p>The default is Z_DEFAULT_STRATEGY.</p> </dd> <dt id="-Dictionary"><a class="permalink" href="#-Dictionary">#</a><a id="Dictionary"></a><b>-Dictionary</b></dt> <dd> <p>When a dictionary is specified <i>Compress::Zlib</i> will automatically call <code>deflateSetDictionary</code> directly after calling <code>deflateInit</code>. The Adler32 value for the dictionary can be obtained by calling the method <code>$d-</code>dict_adler()>.</p> <p>The default is no dictionary.</p> </dd> <dt id="-Bufsize"><a class="permalink" href="#-Bufsize">#</a><a id="Bufsize"></a><b>-Bufsize</b></dt> <dd> <p>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 <code>Bufsize</code>.</p> <p>The default is 4096.</p> </dd> </dl> <p>Here is an example of using the <code>deflateInit</code> optional parameter list to override the default buffer size and compression level. All other options will take their default values.</p> <pre><code>deflateInit( -Bufsize => 300, -Level => Z_BEST_SPEED ) ;</code></pre> <h2 id="($out,-$status)-=-$d->deflate($buffer)"><a class="permalink" href="#($out,-$status)-=-$d-%3Edeflate($buffer)">#</a><a id="out-status-d-deflate-buffer"></a><b>($out, $status) = $d->deflate($buffer)</b></h2> <p>Deflates the contents of <code>$buffer</code>. The buffer can either be a scalar or a scalar reference. When finished, <code>$buffer</code> will be completely processed (assuming there were no errors). If the deflation was successful it returns the deflated output, <code>$out</code>, and a status value, <code>$status</code>, of <code>Z_OK</code>.</p> <p>On error, <code>$out</code> will be <i>undef</i> and <code>$status</code> will contain the <i>zlib</i> error code.</p> <p>In a scalar context <code>deflate</code> will return <code>$out</code> only.</p> <p>As with the <i>deflate</i> function in <i>zlib</i>, it is not necessarily the case that any output will be produced by this method. So don't rely on the fact that <code>$out</code> is empty for an error test.</p> <h2 id="($out,-$status)-=-$d->flush()-=head2-($out,-$status)-=-$d->flush($flush_type)"><a class="permalink" href="#($out,-$status)-=-$d-%3Eflush()-=head2-($out,-$status)-=-$d-%3Eflush($flush_type)">#</a><a id="out-status-d-flush-head2-out-status-d-flush-flush_type"></a><b>($out, $status) = $d->flush()</b> =head2 <b>($out, $status) = $d->flush($flush_type)</b></h2> <p>Typically used to finish the deflation. Any pending output will be returned via <code>$out</code>. <code>$status</code> will have a value <code>Z_OK</code> if successful.</p> <p>In a scalar context <code>flush</code> will return <code>$out</code> only.</p> <p>Note that flushing can seriously degrade the compression ratio, so it should only be used to terminate a decompression (using <code>Z_FINISH</code>) or when you want to create a <i>full flush point</i> (using <code>Z_FULL_FLUSH</code>).</p> <p>By default the <code>flush_type</code> used is <code>Z_FINISH</code>. Other valid values for <code>flush_type</code> are <code>Z_NO_FLUSH</code>, <code>Z_PARTIAL_FLUSH</code>, <code>Z_SYNC_FLUSH</code> and <code>Z_FULL_FLUSH</code>. It is strongly recommended that you only set the <code>flush_type</code> parameter if you fully understand the implications of what it does. See the <code>zlib</code> documentation for details.</p> <h2 id="$status-=-$d->deflateParams([OPT])"><a class="permalink" href="#$status-=-$d-%3EdeflateParams(%5BOPT%5D)">#</a><a id="status-d-deflateParams-OPT"></a><b>$status = $d->deflateParams([OPT])</b></h2> <p>Change settings for the deflate stream <code>$d</code>.</p> <p>The list of the valid options is shown below. Options not specified will remain unchanged.</p> <dl> <dt id="-Level1"><a class="permalink" href="#-Level1">#</a><a id="Level1"></a><b>-Level</b></dt> <dd> <p>Defines the compression level. Valid values are 0 through 9, <code>Z_NO_COMPRESSION</code>, <code>Z_BEST_SPEED</code>, <code>Z_BEST_COMPRESSION</code>, and <code>Z_DEFAULT_COMPRESSION</code>.</p> </dd> <dt id="-Strategy1"><a class="permalink" href="#-Strategy1">#</a><a id="Strategy1"></a><b>-Strategy</b></dt> <dd> <p>Defines the strategy used to tune the compression. The valid values are <code>Z_DEFAULT_STRATEGY</code>, <code>Z_FILTERED</code> and <code>Z_HUFFMAN_ONLY</code>.</p> </dd> </dl> <h2 id="$d->dict_adler()"><a class="permalink" href="#$d-%3Edict_adler()">#</a><a id="dict_adler"></a><a id="d-dict_adler"></a><b>$d->dict_adler()</b></h2> <p>Returns the adler32 value for the dictionary.</p> <h2 id="$d->msg()"><a class="permalink" href="#$d-%3Emsg()">#</a><a id="msg"></a><a id="d-msg"></a><b>$d->msg()</b></h2> <p>Returns the last error message generated by zlib.</p> <h2 id="$d->total_in()"><a class="permalink" href="#$d-%3Etotal_in()">#</a><a id="total_in"></a><a id="d-total_in"></a><b>$d->total_in()</b></h2> <p>Returns the total number of bytes uncompressed bytes input to deflate.</p> <h2 id="$d->total_out()"><a class="permalink" href="#$d-%3Etotal_out()">#</a><a id="total_out"></a><a id="d-total_out"></a><b>$d->total_out()</b></h2> <p>Returns the total number of compressed bytes output from deflate.</p> <h2 id="Example"><a class="permalink" href="#Example">#</a>Example</h2> <p>Here is a trivial example of using <code>deflate</code>. It simply reads standard input, deflates it and writes it to standard output.</p> <pre><code>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 (<>) { ($output, $status) = $x->deflate($_) ; $status == Z_OK or die "deflation failed\n" ; print $output ; } ($output, $status) = $x->flush() ; $status == Z_OK or die "deflation failed\n" ; print $output ;</code></pre> <h1 id="Inflate-Interface"><a class="permalink" href="#Inflate-Interface">#</a><a id="Inflate"></a>Inflate Interface</h1> <p>This section defines the interface available that allows in-memory uncompression using the <i>deflate</i> interface provided by zlib.</p> <p>Here is a definition of the interface:</p> <h2 id="($i,-$status)-=-inflateInit()"><a class="permalink" href="#($i,-$status)-=-inflateInit()">#</a><a id="i-status-inflateInit"></a><b>($i, $status) = inflateInit()</b></h2> <p>Initialises an inflation stream.</p> <p>In a list context it returns the inflation stream, <code>$i</code>, and the <i>zlib</i> status code in <code>$status</code>. In a scalar context it returns the inflation stream only.</p> <p>If successful, <code>$i</code> will hold the inflation stream and <code>$status</code> will be <code>Z_OK</code>.</p> <p>If not successful, <code>$i</code> will be <i>undef</i> and <code>$status</code> will hold the <i>zlib</i> error code.</p> <p>The function optionally takes a number of named options specified as <code>-Name=>value</code> pairs. This allows individual options to be tailored without having to specify them all in the parameter list.</p> <p>For backward compatibility, it is also possible to pass the parameters as a reference to a hash containing the name=>value pairs.</p> <p>The function takes one optional parameter, a reference to a hash. The contents of the hash allow the deflation interface to be tailored.</p> <p>Here is a list of the valid options:</p> <dl> <dt id="-WindowBits1"><a class="permalink" href="#-WindowBits1">#</a><a id="WindowBits1"></a><b>-WindowBits</b></dt> <dd> <p>To uncompress an RFC 1950 data stream, set <code>WindowBits</code> to a positive number.</p> <p>To uncompress an RFC 1951 data stream, set <code>WindowBits</code> to <code>-MAX_WBITS</code>.</p> <p>For a full definition of the meaning and valid values for <code>WindowBits</code> refer to the <i>zlib</i> documentation for <i>inflateInit2</i>.</p> <p>Defaults to MAX_WBITS.</p> </dd> <dt id="-Bufsize1"><a class="permalink" href="#-Bufsize1">#</a><a id="Bufsize1"></a><b>-Bufsize</b></dt> <dd> <p>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 <code>Bufsize</code>.</p> <p>Default is 4096.</p> </dd> <dt id="-Dictionary1"><a class="permalink" href="#-Dictionary1">#</a><a id="Dictionary1"></a><b>-Dictionary</b></dt> <dd> <p>The default is no dictionary.</p> </dd> </dl> <p>Here is an example of using the <code>inflateInit</code> optional parameter to override the default buffer size.</p> <pre><code>inflateInit( -Bufsize => 300 ) ;</code></pre> <h2 id="($out,-$status)-=-$i->inflate($buffer)"><a class="permalink" href="#($out,-$status)-=-$i-%3Einflate($buffer)">#</a><a id="out-status-i-inflate-buffer"></a><b>($out, $status) = $i->inflate($buffer)</b></h2> <p>Inflates the complete contents of <code>$buffer</code>. The buffer can either be a scalar or a scalar reference.</p> <p>Returns <code>Z_OK</code> if successful and <code>Z_STREAM_END</code> if the end of the compressed data has been successfully reached. If not successful, <code>$out</code> will be <i>undef</i> and <code>$status</code> will hold the <i>zlib</i> error code.</p> <p>The <code>$buffer</code> parameter is modified by <code>inflate</code>. On completion it will contain what remains of the input buffer after inflation. This means that <code>$buffer</code> will be an empty string when the return status is <code>Z_OK</code>. When the return status is <code>Z_STREAM_END</code> the <code>$buffer</code> parameter will contains what (if anything) was stored in the input buffer after the deflated data stream.</p> <p>This feature is useful when processing a file format that encapsulates a compressed data stream (e.g. gzip, zip).</p> <h2 id="$status-=-$i->inflateSync($buffer)"><a class="permalink" href="#$status-=-$i-%3EinflateSync($buffer)">#</a><a id="status-i-inflateSync-buffer"></a><b>$status = $i->inflateSync($buffer)</b></h2> <p>Scans <code>$buffer</code> until it reaches either a <i>full flush point</i> or the end of the buffer.</p> <p>If a <i>full flush point</i> is found, <code>Z_OK</code> is returned and <code>$buffer</code> will be have all data up to the flush point removed. This can then be passed to the <code>deflate</code> method.</p> <p>Any other return code means that a flush point was not found. If more data is available, <code>inflateSync</code> can be called repeatedly with more compressed data until the flush point is found.</p> <h2 id="$i->dict_adler()"><a class="permalink" href="#$i-%3Edict_adler()">#</a><a id="dict_adler1"></a><a id="i-dict_adler"></a><b>$i->dict_adler()</b></h2> <p>Returns the adler32 value for the dictionary.</p> <h2 id="$i->msg()"><a class="permalink" href="#$i-%3Emsg()">#</a><a id="msg1"></a><a id="i-msg"></a><b>$i->msg()</b></h2> <p>Returns the last error message generated by zlib.</p> <h2 id="$i->total_in()"><a class="permalink" href="#$i-%3Etotal_in()">#</a><a id="total_in1"></a><a id="i-total_in"></a><b>$i->total_in()</b></h2> <p>Returns the total number of bytes compressed bytes input to inflate.</p> <h2 id="$i->total_out()"><a class="permalink" href="#$i-%3Etotal_out()">#</a><a id="total_out1"></a><a id="i-total_out"></a><b>$i->total_out()</b></h2> <p>Returns the total number of uncompressed bytes output from inflate.</p> <h2 id="Example1"><a class="permalink" href="#Example1">#</a>Example</h2> <p>Here is an example of using <code>inflate</code>.</p> <pre><code>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->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 ;</code></pre> <h1 id="CHECKSUM-FUNCTIONS"><a class="permalink" href="#CHECKSUM-FUNCTIONS">#</a><a id="CHECKSUM"></a>CHECKSUM FUNCTIONS</h1> <p>Two functions are provided by <i>zlib</i> 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.</p> <pre><code>$crc = adler32($buffer [,$crc]) ; $crc = crc32($buffer [,$crc]) ;</code></pre> <p>The buffer parameters can either be a scalar or a scalar reference.</p> <p>If the $crc parameters is <code>undef</code>, the crc value will be reset.</p> <p>If you have built this module with zlib 1.2.3 or better, two more CRC-related functions are available.</p> <pre><code>$crc = crc32_combine($crc1, $crc2, $len2); $adler = adler32_combine($adler1, $adler2, $len2);</code></pre> <p>These functions allow checksums to be merged. Refer to the <i>zlib</i> documentation for more details.</p> <h1 id="Misc"><a class="permalink" href="#Misc">#</a>Misc</h1> <h2 id="my-$version-=-Compress::Zlib::zlib_version();"><a class="permalink" href="#my-$version-=-Compress::Zlib::zlib_version();">#</a><a id="my"></a><a id="my-version-Compress::Zlib::zlib_version"></a>my $version = Compress::Zlib::zlib_version();</h2> <p>Returns the version of the zlib library.</p> <h1 id="CONSTANTS"><a class="permalink" href="#CONSTANTS">#</a>CONSTANTS</h1> <p>All the <i>zlib</i> constants are automatically imported when you make use of <i>Compress::Zlib</i>.</p> <h1 id="SEE-ALSO"><a class="permalink" href="#SEE-ALSO">#</a><a id="SEE"></a>SEE ALSO</h1> <p><a href="/5.28.3/IO::Compress::Gzip">IO::Compress::Gzip</a>, <a href="/5.28.3/IO::Uncompress::Gunzip">IO::Uncompress::Gunzip</a>, <a href="/5.28.3/IO::Compress::Deflate">IO::Compress::Deflate</a>, <a href="/5.28.3/IO::Uncompress::Inflate">IO::Uncompress::Inflate</a>, <a href="/5.28.3/IO::Compress::RawDeflate">IO::Compress::RawDeflate</a>, <a href="/5.28.3/IO::Uncompress::RawInflate">IO::Uncompress::RawInflate</a>, <a href="/5.28.3/IO::Compress::Bzip2">IO::Compress::Bzip2</a>, <a href="/5.28.3/IO::Uncompress::Bunzip2">IO::Uncompress::Bunzip2</a>, <a href="/5.28.3/IO::Compress::Lzma">IO::Compress::Lzma</a>, <a href="/5.28.3/IO::Uncompress::UnLzma">IO::Uncompress::UnLzma</a>, <a href="/5.28.3/IO::Compress::Xz">IO::Compress::Xz</a>, <a href="/5.28.3/IO::Uncompress::UnXz">IO::Uncompress::UnXz</a>, <a href="/5.28.3/IO::Compress::Lzop">IO::Compress::Lzop</a>, <a href="/5.28.3/IO::Uncompress::UnLzop">IO::Uncompress::UnLzop</a>, <a href="/5.28.3/IO::Compress::Lzf">IO::Compress::Lzf</a>, <a href="/5.28.3/IO::Uncompress::UnLzf">IO::Uncompress::UnLzf</a>, <a href="/5.28.3/IO::Uncompress::AnyInflate">IO::Uncompress::AnyInflate</a>, <a href="/5.28.3/IO::Uncompress::AnyUncompress">IO::Uncompress::AnyUncompress</a></p> <p><a href="/5.28.3/IO::Compress::FAQ">IO::Compress::FAQ</a></p> <p><a href="/5.28.3/File::GlobMapper">File::GlobMapper</a>, <a href="/5.28.3/Archive::Zip">Archive::Zip</a>, <a href="/5.28.3/Archive::Tar">Archive::Tar</a>, <a href="/5.28.3/IO::Zlib">IO::Zlib</a></p> <p>For RFC 1950, 1951 and 1952 see <a href="http://www.faqs.org/rfcs/rfc1950.html">http://www.faqs.org/rfcs/rfc1950.html</a>, <a href="http://www.faqs.org/rfcs/rfc1951.html">http://www.faqs.org/rfcs/rfc1951.html</a> and <a href="http://www.faqs.org/rfcs/rfc1952.html">http://www.faqs.org/rfcs/rfc1952.html</a></p> <p>The <i>zlib</i> compression library was written by Jean-loup Gailly <code>gzip@prep.ai.mit.edu</code> and Mark Adler <code>madler@alumni.caltech.edu</code>.</p> <p>The primary site for the <i>zlib</i> compression library is <a href="http://www.zlib.org">http://www.zlib.org</a>.</p> <p>The primary site for gzip is <a href="http://www.gzip.org">http://www.gzip.org</a>.</p> <h1 id="AUTHOR"><a class="permalink" href="#AUTHOR">#</a>AUTHOR</h1> <p>This module was written by Paul Marquess, <code>pmqs@cpan.org</code>.</p> <h1 id="MODIFICATION-HISTORY"><a class="permalink" href="#MODIFICATION-HISTORY">#</a><a id="MODIFICATION"></a>MODIFICATION HISTORY</h1> <p>See the Changes file.</p> <h1 id="COPYRIGHT-AND-LICENSE"><a class="permalink" href="#COPYRIGHT-AND-LICENSE">#</a><a id="COPYRIGHT"></a>COPYRIGHT AND LICENSE</h1> <p>Copyright (c) 1995-2017 Paul Marquess. All rights reserved.</p> <p>This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.</p> </div> <div id="footer"> <p>Perldoc Browser is maintained by Dan Book (<a href="https://metacpan.org/author/DBOOK">DBOOK</a>). Please contact him via the <a href="https://github.com/Grinnz/perldoc-browser/issues">GitHub issue tracker</a> or <a href="mailto:dbook@cpan.org">email</a> regarding any issues with the site itself, search, or rendering of documentation.</p> <p>The Perl documentation is maintained by the Perl 5 Porters in the development of Perl. Please contact them via the <a href="https://github.com/Perl/perl5/issues">Perl issue tracker</a>, the <a href="https://lists.perl.org/list/perl5-porters.html">mailing list</a>, or <a href="https://kiwiirc.com/client/irc.perl.org/p5p">IRC</a> to report any issues with the contents or format of the documentation.</p> </div> </div> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.slim.min.js" integrity="sha512-/DXTXr6nQodMUiq+IUJYCt2PPOUjrHJ9wFrqpJ3XkgPNOZVfMok7cRw6CSxyCQxXn6ozlESsSh1/sMCTF1rL/g==" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.1/umd/popper.min.js" integrity="sha512-ubuT8Z88WxezgSqf3RLuNi5lmjstiJcyezx34yIU2gAHonIi27Na7atqzUZCOoY4CExaoFumzOsFQ2Ch+I/HCw==" crossorigin="anonymous"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script> <script src="/js/highlight.pack.js"></script> <script>hljs.highlightAll();</script> </body> </html>