Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

gzip written in perl

by pjc (Novice)
on Nov 04, 2002 at 03:04 UTC ( #210109=perlquestion: print w/ replies, xml ) Need Help??
pjc has asked for the wisdom of the Perl Monks concerning the following question:

Has anyone written a version of gzip in pure perl?
What I mean by "pure perl" is the script doesn't
use backticks (``) or the system() command.

Here's the RFC on GZIP:

I'd like to use it as a drop in replacement for
the binary gzip on different Unix machines.



update (broquaint): removed <code> tags and added appropriate formatting

Comment on gzip written in perl
Download Code
Replies are listed 'Best First'.
Re: gzip written in perl
by graff (Chancellor) on Nov 04, 2002 at 03:29 UTC
    With Perl 5.8, you can also use PerlIO::gzip and read/write gzip data though an IO layer -- e.g. here's a script that reads a gzipped file, numbers the lines, and writes the result to a new gzipped file:
    use PerlIO::gzip; open IN, "<:gzip", "somefile.gz" or die "$!\n"; open OUT, ">:gzip", "numbered.gz" or die "$!\n"; while (<IN>) { print OUT join " ", ++$i, $_; }
    (God, I love it!)

    UPDATE: (2010-10-18) It seems that PerlIO::gzip should be viewed as superseded by PerlIO::via:gzip. (see PerlIO::gzip or PerlIO::via::gzip).

Re: gzip written in perl
by grep (Monsignor) on Nov 04, 2002 at 03:13 UTC
    A quick search of cpan gives me Compress::Zlib which has gzip support.

    Mynd you, mønk bites Kan be pretti nasti...
      A while back I tried to use Compress::Zlib at a customer's site, but it requires the use of an external library. They were OK with installing a pre-built binary (gzip lib), but refused to load a compiler onto their production box (a 5.0 Tru64 machine). The only available pre-built binary was part of a larger suite that was only available on CD...not much use when I was only on-site for a couple of days. A pure-perl gzip would have been very handy indeed.


      ActivePerl includes it for Windoze machines. It works fine for production here.
        hi i am new at perl can you teach me how to compress a file in a directory
Re: gzip written in perl
by strredwolf (Chaplain) on Nov 04, 2002 at 22:20 UTC
    I can tell you, it'll be slow. But that'll be useful to do it, though. There is a C version of gunzip that's nicely small off of the IOCCC.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://210109]
Approved by grep
Front-paged by strredwolf
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (9)
As of 2015-11-25 10:47 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (673 votes), past polls