I was going to post my own SoPW on my troubles at getting Compress::Zlib to work, and Super Search pointed me here. Based on the code samples here, I was able to get my test case (a line-oriented zip/unzip) to work correctly.
Specifically, my problem was that I was creating a $gz handle using deflateInit(). So here's my code for future readers in the same predicament:
#! /usr/bin/perl -w use strict; use Compress::Zlib; my $file = shift || 'testdata.gz'; my $gz = gzopen( $file, 'wb' ) or die "Cannot open $file for gzwrite +: $gzerrno\n"; my $line; while( defined($line = <DATA>) ) { $gz->gzwrite( $line ) or die "Could not write gzipped data to $file: $gzerrno\n"; } $gz->gzclose(); $gz = gzopen( $file, 'rb' ) or die "Cannot open $file for gzread: $gze +rrno\n"; while( $gz->gzreadline($line) > 0 ) { print $line; } die "Error reading from $file: [$gzerrno]\n" unless Z_STREAM_END == $g +zerrno; $gz->gzclose(); __DATA__ foo bar Judge my vow, sphinx of black quartz __END__
I think it's pretty self-explanatory...
This does leave me with one question, however, and that is, how can I specify the that the writer uses different compression strategies, à la Z_BEST_SPEED and Z_BEST_COMPRESSION?
update: in reply to idnopheq's suggestion, despite have 512Mb RAM, I'd rather not have this hanging around in RAM, I actually want to dump it straight out onto tape. I initially used a deflateInit approach and wrote the output to a file myself, but I was unable to successfully read it back using gzopen on the resulting file.
--In reply to Re: examples using Compress::Zlib ?
by grinder
in thread examples using Compress::Zlib ?
by ybiC
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |