Archiving and Compression with CGI
By Randal L. Schwartz
Tens of thousands of compressed tar archives probably exist out there on the Web to download. I can't imagine how much time, even on a high speed connection, it would take to download them all. A major problem with compressed archives, whether tar, zip, or otherwise, is that even if the publisher of the information has carefully bundled only the most important files, sometimes I really want only part of the data. However, I'm forced to download the entire thing (perhaps over a slow connection in a hotel room, as I often am), to discard only the parts I don't want.
The Data publisher should provide a way to build a custom-compressed archive, with only the files or directories that I choose. That's what we have this month: A CGI program that lets a user choose individual distribution files, on an item-by-item basis. Once a user has made his or her choice, a specific tarred and gzipped file (.tar.gz) appears on the server for the user to download. The code for the script that does this is in
Listing 1.
As a side note, this month's column idea was suggested by fellow Stonehenge Perl trainer and Usenet poster extraordinaire, the one and only Tom Phoenix (rootbeer@redcat.com). It's based on similar code he wrote for me to handle the downloads of exercise data and answers for our on-site training classes. I wrote the code in Listing 1 from scratch, though, so if it isn't exactly what he was suggesting, that's my fault.<>