compress function

Discussion in 'Mac Programming' started by BadWolf, Mar 2, 2009.

  1. macrumors newbie

    Feb 11, 2009

    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,

  2. macrumors newbie


    Jan 27, 2006
    Wikipedia's explanation 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 code directly for the gory details. Zopen.c contains the guts of the algorithm.
  3. macrumors 6502a

    Aug 25, 2006
    Port Pirie, South Australia
  4. thread starter macrumors newbie

    Feb 11, 2009
    Thank You

    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!:)

Share This Page