NAME

Gzip::Faster - gzip and gunzip, without the fuss

SYNOPSIS

    use Gzip::Faster;
    my $gzipped = gzip ($input);
    my $roundtrip = gunzip ($gzipped);
    if ($roundtrip ne $input) { die; }
    gzip_to_file ($input, 'file.gz');
    $roundtrip = gunzip_file ('file.gz');
    if ($roundtrip ne $input) { die; }

DESCRIPTION

This module compresses to and decompresses from the gzip format.

FUNCTIONS

gzip

    my $zipped = gzip ($stuff);

This compresses $stuff into the gzip format. The return value is the compressed version of $stuff.

gunzip

    my $stuff = gunzip ($zipped);

This uncompresses $zipped and returns the result of the uncompression. It returns the undefined value if $zipped is the undefined value or an empty string. Otherwise, it throws a fatal error if $zipped is not in the gzip format.

gzip_file

    my $zipped = gzip_file ('file');

This reads the contents of file into memory and then runs "gzip" on the file's contents. The return value and the possible errors are the same as "gzip", plus this may also throw an error if open fails.

gunzip_file

    my $stuff = gunzip_file ('file.gz');

This reads the contents of file.gz into memory and then runs "gunzip" on the file's contents. The return value and the possible errors are the same as "gunzip", plus this may also throw an error if open fails.

gzip_to_file

    gzip_to_file ($plain, 'file.gz');

This compresses $plain in memory using "gzip" and writes the compressed content to 'file.gz'. There is no return value. The errors are the same as "gzip", plus this may also throw an error if open fails. As of this version, it does not write any gzip header information to file.gz.

PERFORMANCE

This section compares the performance of Gzip::Faster with IO::Compress::Gzip and IO::Uncompress::Gunzip. According to my results, Gzip::Faster is about five times faster to load, seven times faster to compress, and twenty-five times faster to uncompress. Round trips are about ten times faster with Gzip::Faster.

The versions used in this test are as follows:

    $IO::Compress::Gzip::VERSION = 2.060
    $IO::Uncompress::Gunzip::VERSION = 2.060
    $Gzip::Faster::VERSION = 0.07

Here is a comparison of load times:

                Rate Load IOUG Load IOCG   Load GF
    Load IOUG 25.1/s        --       -4%      -81%
    Load IOCG 26.2/s        4%        --      -80%
    Load GF    132/s      425%      403%        --

Here is a comparison of a round-trip:

                          Rate IO::Compress::Gzip       Gzip::Faster
    IO::Compress::Gzip  1268/s                 --               -90%
    Gzip::Faster       12623/s               896%                 --

Here is a comparison of gzip (compression) only:

                          Rate IO::Compress::Gzip       Gzip::Faster
    IO::Compress::Gzip  2490/s                 --               -86%
    Gzip::Faster       17680/s               610%                 --

Here is a comparison of gunzip (decompression) only:

                              Rate IO::Uncompress::Gunzip           Gzip::Faster
    IO::Uncompress::Gunzip  2722/s                     --                   -96%
    Gzip::Faster           67368/s                  2375%                     --

The test file is in "examples/benchmark.pl" in the distribution.

There is also a module called Compress::Raw::Zlib which offers access to zlib itself. It may offer improved performance, however I have not figured out what it does yet. Its documented way of making a gzip compressed object returns something I cannot understand so I was unable to include it in the benchmark.

BUGS

The module source code includes disabled functionality to round-trip Perl flags. I applied this to preserving Perl's "utf8" flag. However, the mechanism I used trips a browser bug in the Firefox web browser where it produces a content encoding error message. Thus this functionality is disabled. Please refer to the file gzip-faster-perl.c in the distribution, the relevant parts are commented out with a macro COPY_PERL.

AUTHOR, COPYRIGHT AND LICENCE

Ben Bullock <bkb@cpan.org>. Copyright (C) 2014 Ben Bullock. This software may be used, modified, distributed under the same licence as Perl itself.