How to zip a variable with PERL without reading or writing a file?
There is the Archive::Zip I think I can use with Perl 5.10 but I don't know how.
I don't want to read or write any files, just zip something in memory, with best compression, like $text = "this is a test"; $zippedtext = &Zip($text); sub Zip { my $zip = Archive::Zip->new(); # help needed here return ... } I guess it's only a few lines. Thanks in advance. |
Quote:
|
Quote:
The point is I don't need all that extra information which is included in a typical zip file, such as file size and name etc. If I do something like my $zip = Archive::Zip->new(); my $member = $zip->addString($text, $filename); $member->desiredCompressionMethod(COMPRESSION_DEFLATED); how can I access the zipped member and is it possible to get rid of the $filename stuff? |
Found what I was looking for in a different module:
use Compress::Raw::Zlib; sub Zip { my ($d, $status) = new Compress::Raw::Zlib:: Deflate( -Level => Z_BEST_COMPRESSION ); my $result; my $status = $d->deflate(shift, $result); die "deflation failed\n" unless $status == Z_OK; $status = $d->flush($result) ; die "deflation failed\n" unless $status == Z_OK; $result; } |
I know this is a very old thread, but I just had the same question, to compress the contents of a variable in perl.
I tried the method above, and it seems i can compress the data successfully, BUT i can't decompress it. Inflate is not working for me on the variable i just compressed. Googling this doesn't bring up anything else then the normal manual, which is not helpful for me. Doing it that way doesn't work. Code:
#!/usr/bin/perl the output is: Code:
zlib version: 1.2.3 did anyone ever managed to successfully compress and de-compress a variable ? Is there a working example somewhere ? any help would be appreciated... |
All times are GMT -5. The time now is 06:43 AM. |