NAME
Compress::Zlib::FAQ -- Frequently Asked Questions about Compress::Zlib
DESCRIPTION
Common questions answered.
Compatibility with Unix compress/uncompress.
Although Compress::Zlib
has a pair of functions called compress
and uncompress
, they are not the same as the Unix programs of the same name. The Compress::Zlib
library is not compatible with Unix compress
.
If you have the uncompress
program available, you can use this to read compressed files
open F, "uncompress -c $filename |";
while (<F>)
{
...
If you have the gunzip
program available, you can use this to read compressed files
open F, "gunzip -c $filename |";
while (<F>)
{
...
and this to write compress files if you have the compress
program available
open F, "| compress -c $filename ";
print F "data";
...
close F ;
Accessing .tar.Z files
The Archive::Tar
module can optionally use Compress::Zlib
(via the IO::Zlib
module) to access tar files that have been compressed with gzip
. Unfortunately tar files compressed with the Unix compress
utility cannot be read by Compress::Zlib
and so cannot be directly accesses by Archive::Tar
.
If the uncompress
or gunzip
programs are available, you can use one of these workarounds to read .tar.Z
files from Archive::Tar
Firstly with uncompress
use strict;
use warnings;
use Archive::Tar;
open F, "uncompress -c $filename |";
my $tar = Archive::Tar->new(*F);
...
and this with gunzip
use strict;
use warnings;
use Archive::Tar;
open F, "gunzip -c $filename |";
my $tar = Archive::Tar->new(*F);
...
Similarly, if the compress
program is available, you can use this to write a .tar.Z
file
use strict;
use warnings;
use Archive::Tar;
use IO::File;
my $fh = new IO::File "| compress -c >$filename";
my $tar = Archive::Tar->new();
...
$tar->write($fh);
$fh->close ;
Accessing Zip Files
Although it is possible (with some effort on your part) to use this module to access .zip files, there is a module on CPAN that will do all the hard work for you. Check out the Archive::Zip
module on CPAN at
http://www.cpan.org/modules/by-module/Archive/Archive-Zip-*.tar.gz
Assuming you don't want to use this module to access zip files there are a number of undocumented features in the zlib library you need to be aware of.
When calling inflateInit or deflateInit the WindowBits parameter must be set to
-MAX_WBITS
. This disables the creation of the zlib header.The zlib function inflate, and so the inflate method supplied in this module, assume that there is at least one trailing byte after the compressed data stream. Normally this isn't a problem because both the gzip and zip file formats will guarantee that there is data directly after the compressed data stream.
Zlib Library Version Support
By default Compress::Zlib
will build with a private copy of version 1.2.3 of the zlib library. (See the README file for details of how to override this behavior)
If you decide to use a different version of the zlib library, you need to be aware of the following issues
First off, you must have zlib 1.0.5 or better.
You need to have zlib 1.2.1 or better if you want to use the
-Merge
option withIO::Gzip
,IO::Deflate
andIO::RawDeflate
.
SEE ALSO
Compress::Zlib, IO::Gzip, IO::Gunzip, IO::Deflate, IO::Inflate, IO::RawDeflate, IO::RawInflate, IO::AnyInflate
File::GlobMapper, Archive::Tar, IO::Zlib
For RFC 1950, 1951 and 1952 see http://www.faqs.org/rfcs/rfc1950.html, http://www.faqs.org/rfcs/rfc1951.html and http://www.faqs.org/rfcs/rfc1952.html
The primary site for the gzip program is http://www.gzip.org.
AUTHOR
The module was written by Paul Marquess, pmqs@cpan.org. The latest copy of the module can be found on CPAN in modules/by-module/Compress/Compress-Zlib-x.x.tar.gz.
The zlib compression library was written by Jean-loup Gailly gzip@prep.ai.mit.edu and Mark Adler madler@alumni.caltech.edu.
The primary site for the zlib compression library is http://www.zlib.org.
MODIFICATION HISTORY
See the Changes file.
COPYRIGHT AND LICENSE
Copyright (c) 2005 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.