Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

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:
http://www.ietf.org/rfc/rfc1952.txt

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

Thanks,

pjc

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

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.

    grep
    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.

      rdfield

      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.

    --
    $Stalag99{"URL"}="http://stalag99.keenspace.com";

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://210109]
Approved by grep
Front-paged by strredwolf
help
Chatterbox?
[Discipulus]: as a greed Agrid I agree.. coffee!

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2018-05-21 08:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?