Asgaroth has asked for the wisdom of the Perl Monks concerning the following question:

Hi Guru's

I have been looking into the Compress:Zlib module, and the compression/decompression of the logs works great, however, I need to report on extended statistics of the completed gzip'd file.

What I mean is this, with the gzip utility you can get a "long listing" report on the statistics within the compressed file, eg:

gzip -lv pook.log.gz | tail +2 defla 3ddb5103 Aug 16 15:28 26203165 52428800 50.0% pook.log

Is there any way that I could possibly get the same details from the Compress::Zlib module, rather than spawning a system command for a "gzip -l" after using the module to compress the log file.

I have looked at the documentation for Compress:Zlib, but there does not appear to be any variables that return these details (i may be blind though). If anyone knows of a module that may extract this info from the gzip'd file please could you let me know. Any pointers would be greatky apperciated.

Thanks
Asgaroth

Replies are listed 'Best First'.
Re: Compress::Zlib or equivilent
by graff (Chancellor) on Aug 17, 2004 at 02:45 UTC
    You don't show how you're actually using Compress::Zlib, which might be relevant. If you are reading uncompressed data from some source, passing it to a Zlib method and writing the result to a file, maybe it would be sufficient to keep count of the input data (e.g.  $read_count += length()), and then compare this to the finished size of the output compressed file -- e.g.
    ... close OUTZ; my $comp_count = (-s $outzfile); printf("Input byte count: %d; output byte count: %d; ratio: %3.1f\n", $read_count, comp_count, 100*$comp_count/$read_count ); # (updated: reporting "100*$read_count/$comp_count would not be right)
    Adding a time stamp to that is trivial (see scalar localtime).