Tuesday, August 11, 2009

Hack Of The Day: Creating a Windows Self-Extracting Zip File On Linux

One of our customers wanted to make it especially easy to handle a zip file download we were generating on the fly for him. On a hunch, I went looking for ways to generate self extracting ZIP files. The big catch being that I needed to be able to create them on the fly on a Linux box.

After a whole lot of poking I found two really useful articles:

In the first case, the very basic info-zip package is used (which you probably already have installed on your Linux box). The second option uses the 7-zip package.

Both systems use the same approach: take a small windows executable and append to it the actual zip file, and have Windows folks use that. The Windows executable at the start of the file will run first, no doubt seek to it's end, and then unpack the embedded zip file.

If you ask me, it's pure genius.

The 7-zip approach even gets slightly fancier, and embeds a configuration file between the binary and archive, which says what program to run.

A fancier solution is to take an installer like NSIS, and build it for Linux. Then, build up an installer package on the fly.

But for my purposes, the self extracting zip file should do the trick.

If nothing else, thinking through the whole appending-your-data-to-the-end-of-the-binary trick has been worth pondering. Come to think of it, perl actually made extensive use of this trick with their __END__ and __DATA__ keywords.

No comments:

Post a Comment