views:

215

answers:

4

We need a cross platform solution for compressing files. Our server runs on Windows XP/Vista/7 and 3 Unix distros, SunOS, HPUX, and AIX. Our server creates files that needed to be zipped before being set back to the client. Our initial thought was to compress the files with jar, as most of the servers have java installed, but apparently jar isn't included in the jre, just the jdk. Our server is written in C and the application that needs to create a compressed file is Perl.

I'd really like something I don't have install as our install base is LARGE and adding new required applications is generally difficult. Is there anything that is guaranteed to be built into each of those OSes that I could use for zipping? Even if I have to use something different for each, that would probably be okay also.

+1  A: 

You could always consider distributing an open source compression tool or even using a compression SDK as part of your app such as 7 ZIP's

Eric J.
+1  A: 

If you have Java installed (no matter JRE or JDK), you can use the pack200 and unpack200 to create and unpack the archives. Pack200 uses gzip compression which is pretty standard.

You should note that pack200 doesn't allow to compress multiple files in one archive (nature of gzip). If it's required, you can implement your own tool in pure Java that will create zip files and run anywhere with the unified command line interface (Java has built-in zip support, see some samples).

If you go that route, you can also use the native java implementation of bz2 or 7zip formats to get better compression.

CrazyCoder
That looks like a winner on the Windows machine, but I can't seem to find it on any of the Unix boxes. Would it be in a non-standard place or something?
Morinar
pack200 is available in the Sun JDK, in the JDK_HOME/bin folder on the Linux platform. If you have GCJ installed on the servers, you are out of luck and will have to implement your small application in Java to create archives.
CrazyCoder
+4  A: 

I do like 7-zip a lot but for situations like yours I always go to least-common denominataor: ZIP. Simple old ZIP. Most Unices and linuxes have zip and unzip. And for windows there are lots of options, including 7-zip, that can manipulate zip files. And probably the clients will have a zip client installed.

Leonel Martins
+7  A: 

If you don't want to have to install anything you're pretty much SOL. Windows doesn't make this easy.

If you want to write something yourself java.util.zip is in the Java 2 Standard Edition (J2SE) and Perl has Archive::Zip

fiXedd
SOL turned out to be the correct answer. Our install base is so ridiculously varied that there is literally just nothing that all of our customers have. It looks like we'll end up using jar for the newer versions of our software (as we require the jdk) while older versions will have a bundled zip application. Thanks for the feedback all.
Morinar
Just to further it a little, you do realize that JAR files *ARE* ZIP files, right? That would allow you some forward-compatibility.
fiXedd