1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
package Compress::Snappy;
use strict;
use warnings;
use Exporter qw(import);
use XSLoader;
our $VERSION = '0.25';
our $XS_VERSION = $VERSION;
$VERSION = eval $VERSION;
XSLoader::load(__PACKAGE__, $XS_VERSION);
our @EXPORT = qw(compress decompress uncompress);
1;
__END__
=head1 NAME
Compress::Snappy - Perl interface to Google's Snappy (de)compressor
=head1 SYNOPSIS
use Compress::Snappy;
my $dest = compress($source);
my $dest = decompress($source);
=head1 DESCRIPTION
The C<Compress::Snappy> module provides an interface to Google's Snappy
(de)compressor.
Snappy does not aim for maximum compression, or compatibility with any other
compression library; instead, it aims for very high speeds and reasonable
compression. For instance, compared to the fastest mode of zlib, Snappy is
an order of magnitude faster for most inputs, but the resulting compressed
files are anywhere from 20% to 100% bigger.
=head1 FUNCTIONS
=head2 compress
$string = compress($buffer)
Compresses the given buffer and returns the resulting string. The input
buffer can be either a scalar or a scalar reference.
=head2 decompress
=head2 uncompress
$string = decompress($buffer)
Decompresses the given buffer and returns the resulting string. The input
buffer can be either a scalar or a scalar reference.
On error (in case of corrupted data) undef is returned.
=head1 PERFORMANCE
This distribution contains a benchmarking script which compares several
compression modules available on CPAN. These are the results on a MacBook
2GHz Core 2 Duo (64-bit) with Perl 5.14.2:
Compressible data (10 KiB) - compression
----------------------------------------
Compress::LZ4::compress 183794/s 1795 MiB/s 1.152%
Compress::Snappy::compress 122496/s 1196 MiB/s 5.332%
Compress::LZF::compress 44383/s 433 MiB/s 1.865%
Compress::Zlib::compress 2765/s 27 MiB/s 1.201%
Compress::Bzip2::compress 110/s 1 MiB/s 2.070%
Compressible data (10 KiB) - decompression
------------------------------------------
Compress::LZ4::decompress 546133/s 5333 MiB/s
Compress::Snappy::decompress 175363/s 1713 MiB/s
Compress::LZF::decompress 135244/s 1321 MiB/s
Compress::Bzip2::decompress 6352/s 62 MiB/s
Compress::Zlib::uncompress 5440/s 53 MiB/s
Uncompressible data (10 KiB) - compression
------------------------------------------
Compress::LZ4::compress 763738/s 7458 MiB/s 107.463%
Compress::Snappy::compress 552269/s 5393 MiB/s 100.000%
Compress::LZF::compress 532919/s 5204 MiB/s 101.493%
Compress::Bzip2::compress 15424/s 151 MiB/s 185.075%
Compress::Zlib::compress 4325/s 42 MiB/s 105.970%
Uncompressible data (10 KiB) - decompression
--------------------------------------------
Compress::LZF::decompress 2583577/s 25230 MiB/s
Compress::LZ4::decompress 2383127/s 23273 MiB/s
Compress::Snappy::decompress 2068002/s 20195 MiB/s
Compress::Bzip2::decompress 48650/s 475 MiB/s
Compress::Zlib::uncompress 6342/s 62 MiB/s
=head1 SEE ALSO
L<http://google.github.io/snappy/>
L<https://github.com/zeevt/csnappy>
=head1 COPYRIGHT AND LICENSE
Copyright (c) 2011 gray <gray at cpan.org>, all rights reserved.
This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
=head1 AUTHOR
gray, <gray at cpan.org>
=cut
|