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

I would love to be able to distribute my code with an automatic unzipper that could be run via cgi. (You will have to trust me about any security issues.) However, to remain cross-platform, I can't rely on the command line "zip/unzip" tools being available.

1. Can I rely on Compress::ZLib being available (I could easily then distribute Archive::Zip)? Does anyone know how common this module is at ISPs etc.?

2. Better still, is there a pure perl unzip implementation out there somewhere?

best wishes

david dave hj~

Replies are listed 'Best First'.
Re: pure perl unzip
by MZSanford (Curate) on Dec 17, 2001 at 15:28 UTC
    Compress::Zlib is reasonably common... it is even used by CPAN when installing new modules, if it is available. If you cannot use (or don't want to use) command line tools, i suggest Compress::Zlib as the best alternative.
    On the pure-perl-command-line front, i would think that the Perl Power Tools people would be the best to check ... tho i don't believe gzip is on their list.
    $ perl -e 'do() || ! do() ;' Undefined subroutine &main::try
Re: pure perl unzip
by clintp (Curate) on Dec 17, 2001 at 20:10 UTC
    A long while ago, I made up a distribution for a Tk program I was writing that had graphic files, modules, configuration files, documentation and all kinds of crap and it worked under a variety of Unix platforms. For the life of me, I can't find this code! Ugh!

    What I do remember is the thought processes behind it, and I'll outline here:

    • It started as a perl script (.pl) with a huge __DATA__ section and it had to be FTP'd as /binary/ or it wouldn't work.
    • The data section was made by having sections marked off with a filename and an extent. "foo.pm234151 bar.pm123124 junk.gif1234" and so on. Following that was the raw data for each file.
    • The data I had packed with simple run-length encoding (lots of gifs with lots of blank areas). A better solution would have been to use something like mjd's Huffman encoding.
    • Unpacking was a matter of reading the correct number of bytes from __DATA__, decoding them, and then writing them.
    If you don't need a lot of compression, this might be something to look into. As I remember I was less worried about compression than I was about bundling and basically re-implemented shar(1) in Perl.
      Did I hear shar in perl ? ;-)

      --
      perl -p -e "s/(?:\w);([st])/'\$1/mg"

        Turns out that Huffman isn't quite meant for production code, but I'm working on it and will post when done.

        --
        perl -p -e "s/(?:\w);([st])/'\$1/mg"

Re: pure perl unzip
by impossiblerobot (Deacon) on Dec 17, 2001 at 20:12 UTC
    I thought I'd seen something on this at the monastery lately, and Super Search turned up this node.

    I think the overall conclusion was that there was not (as yet) a pure-Perl solution to the zipping problem (though it is doable); all of the current solutions require C-based libraries.

    Impossible Robot