Compress::Zlib::FAQ -- Frequently Asked Questions about Compress::Zlib
Common questions answered.
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.
Compress::Zlib
compress
uncompress
If you have the uncompress program available, you can use this to read compressed files
open F, "uncompress -c $filename |"; while (<F>) { ...
Alternatively, if you have the gunzip program available, you can use this to read compressed files
gunzip
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 ;
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.
Archive::Tar
IO::Zlib
gzip
If the uncompress or gunzip programs are available, you can use one of these workarounds to read .tar.Z files from Archive::Tar
.tar.Z
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 ;
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
Archive::Zip
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 Compress::Zlib::Inflate::new or Compress::Zlib::Deflate::new the WindowBits parameter must be set to -MAX_WBITS. This enables the creation of an RFC1951 compressed data stream.
-MAX_WBITS
If you are using zlib older than 1.2.0, 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.
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 behaviour)
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 with IO::Compress::Gzip, IO::Compress::Deflate and IO::Compress::RawDeflate.
-Merge
IO::Compress::Gzip
IO::Compress::Deflate
IO::Compress::RawDeflate
Compress::Zlib, IO::Compress::Gzip, IO::Uncompress::Gunzip, IO::Compress::Deflate, IO::Uncompress::Inflate, IO::Compress::RawDeflate, IO::Uncompress::RawInflate, IO::Uncompress::AnyInflate
Compress::Zlib::FAQ
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.
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.
See the Changes file.
Copyright (c) 2005-2006 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.
To install Env, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Env
CPAN shell
perl -MCPAN -e shell install Env
For more information on module installation, please visit the detailed CPAN module installation guide.