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.

--
g r i n d e r

In reply to Re: examples using Compress::Zlib ? by grinder
in thread examples using Compress::Zlib ? by ybiC

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.