(pk)zip on-the-fly and gzcompress question

From: John Bokma (postmaster_at_castleamber.com)
Date: 12/26/04


Date: 26 Dec 2004 20:40:35 GMT

The pkzip question is general, hence the crossposting to
comp.compression, follow-up-to set to comp.lang.php.

Is it possible to stream a zip file? Since the local file header must be
set before the file data (see
http://www.pkware.com/company/standards/appnote/ ).

It's not clear to me what the role of the data descriptor is (C). I was
hoping that when it was not possible to fill in the compressed size in
the local file header (A), one could use this data descriptor to define
the compressed size.

I need on-the-fly compression, and grouping of a few files. Is the zip
format usable for this? I don't know the compressed size ahead, unless I
compress to temp files, which I don't want.

PHP question: can gzcompress be called in blocks, ie. can I call
gzcompress every 1 megabyte (for example) and stream every compressed
part instead of doing just one gzcompress for the entire data?

The zip code I have seen so far does the following:

        $zdata = gzcompress($data);
        $zdata = substr(substr($zdata, 0, strlen($zdata) - 4), 2);

                        // fix crc bug

Is this crc bug documented somewhere? I can imagine that when I
gzcompress blocks I have to do this trick for every block? (And
calculate a running crc32 for every uncompressed block).

If anyone can suggest a better way of compressing files on the fly, and
grouping them (or the other way around, tar? ), please let me know. I
haven't had a look at tar yet.

Pointers to PHP solutions are welcome [1]

Many thanks,
John

[1] Note: sadly I can't use PEAR, but I might be able to convert PEAR
    code.

-- 
John                               MexIT: http://johnbokma.com/mexit/
                           personal page:       http://johnbokma.com/
        Experienced programmer available:     http://castleamber.com/
            Happy Customers: http://castleamber.com/testimonials.html