NAME
MySQL::Compress - MySQL COMPRESS() and UNCOMPRESS() compatible Perl functions
DESCRIPTION
This module provides functions compatible with MySQL COMPRESS() and UNCOMPRESS(). One reason you may want to use these functions is because MySQL COMPRESS() does not offer the possibilty to specify the compression level, whereas the mysql_compress() function in this module does.
SYNOPSIS
use MySQL::Compress qw(
mysql_compress
mysql_uncompress
);
Functional interface use:
use MySQL::Compress qw(mysql_compress);
my $password = 'secret';
my $crypted_string = mysql_compress($password);
Functional interface use, using options:
use MySQL::Compress qw(:all);
my $password = 'secret';
my $crypted_string = mysql_compress($password, PASSWORD_DEFAULT, cost => 11);
Class method use, using options:
use MySQL::Compress;
my $password = 'secret';
my $crypted_string = MySQL::Compress->hash($password, cost => 9);
# Note that the 2nd argument of mysql_compress() has been dropped here and may be specified
# as an option as should've been the case in the original mysql_compress() function IMHO.
EXPORTS
The following functions can be imported into the calling namespace by request:
mysql_compress
mysql_uncompress
mysql_uncompressed_length
:all - what it says
FUNCTIONS
- $dest = mysql_compress($source [, $level])
-
MySQL COMPRESS() compatible compression function. $level is the optional compression level (valid values are 0 through 9; default = 6). See Compress::Zlib documentation for details. Returns the compressed data on success, else undef.
From the MySQL COMPRESS() documentation: The compressed string contents are stored the following way: - Empty strings are stored as empty strings. - Nonempty strings are stored as a 4-byte length of the uncompressed string (low byte first), followed by the compressed string. If the string ends with space, an extra "." character is added to avoid problems with endspace trimming should the result be stored in a CHAR or VARCHAR column. (However, use of nonbinary string data types such as CHAR or VARCHAR to store compressed strings is not recommended anyway because character set conversion may occur. Use a VARBINARY or BLOB binary string column instead.)
- $dest = mysql_uncompress($source)
-
MySQL UNCOMPRESS() compatible function. Uncompresses data that has been compressed with MySQL's COMPRESS() function. $source can be either a scalar or a scalar reference. Returns the uncompressed data on success, else undef.
- $length = mysql_uncompressed_length($source)
-
Returns the expected uncompressed length of the given string that has been compressed with MySQL's COMPRESS() function. This is done without actually decompressing since COMPRESS() prepends the length to the compressed string. $source can be either a scalar or a scalar reference. Returns the expected uncompressed length on success, else undef.
SEE ALSO
COPYRIGHT
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
AUTHOR
Craig Manley (craigmanley.com)