The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

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>)
    {
        ...

Alternatively, 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.

  1. 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.

  2. 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.

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 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.

SEE ALSO

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.

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-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.