PDA

View Full Version : compress function




BadWolf
Mar 2, 2009, 10:36 PM
Hi,

The compress function on the mac os, uses an adaptive Lempel-Ziv algorithm. I searched online and I couldn't really find a good summary concerning the function's operation. Does anyone know whether the algorithm compresses files while reading them (like the adaptive huffman coding algorithm) or whether it reads the files once to construct a frequency table and then reads the file once more to compress it (like regular huffman coding)? Also, does anyone know where on the system the c and h files for compress are stored?

Thank you for your help,

BadWolf



Gruffalo
Mar 3, 2009, 12:43 AM
Hi,

The compress function on the mac os, uses an adaptive Lempel-Ziv algorithm. I searched online and I couldn't really find a good summary concerning the function's operation. Does anyone know whether the algorithm compresses files while reading them (like the adaptive huffman coding algorithm) or whether it reads the files once to construct a frequency table and then reads the file once more to compress it (like regular huffman coding)? Also, does anyone know where on the system the c and h files for compress are stored?

Thank you for your help,

BadWolf

Wikipedia's explanation (http://en.wikipedia.org/wiki/LZW) of the standard LZW algorithm seems pretty clear to me, but to directly answer your question, it produces a compressed stream in a single pass.

Apple no longer make the system source available, however, I'd guess that the compress in OS X is identical to that used on other *BSD derivatives. You could have a look at the FreeBSD source (http://www.dk.freebsd.org/cgi/cvsweb.cgi/src/usr.bin/compress/) code directly for the gory details. Zopen.c contains the guts of the algorithm.

neonblue2
Mar 3, 2009, 02:09 AM
Apple no longer make the system source available

http://www.opensource.apple.com/darwinsource/

BadWolf
Mar 4, 2009, 03:29 AM
Thanks for the confirmation on the function operation, for some reason, the wiki just wasn't clear enough for me. I had actually found the BSD code, but I experience problems when it called upon include files "sys/param.h" and so forth. I guess I'll keep playing with it, and I'll check out the darwinsource as well. thanks again!:)