I have a string that I would like to compress using GZip before inserting into a database as a BLOB. However, it seems that the built in GZip Perl modules are all designed to compress files, not inline strings.
In PHP I would accomplish this with $compressed = gzcompress($string)
What is a Perl equivalent of PHP's gzcompress()?
There is a gzip
function in IO::Compress::Gzip that should do what you need. Something like this:
gzip \$input => \$output
would be more or less equivalent to your PHP. Note the use of references to scalars if you want to do everything in memory buffers, if you use plain scalars then gzip
will think they're filenames.
Perhaps http://perldoc.perl.org/IO/Compress/Gzip.html ?
use Compress::Zlib;
#then $out = compress($in) or $out = uncompress($in)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With