Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the POSIX System Library for the LZW Algorithm Used by the Compress Utility

This has been an incredibly difficult question to Google. I am not looking for gzip or Zip or deflate. The algorithm I want to use is called "compress" but that does not mean I am trying to implement compression in general. I am looking for a specific algorithm.

I am looking for the adaptive Lempel-Ziv algorithm used by the compress command line tool in Unix-like systems. I am looking for the algorithm HTTP says you should use when you receive a Content-Encoding: compress header. It's the algorithm you see described when you type man compress in a POSIX shell, and in this Wikipedia article.

I understand this compression algorithm is very old and has been replaced by gzip, Zip, deflate, etc. for almost all practical purposes. But I am writing a server in C++ as a pet project and IANA specifies this Unix "compress" algorithm as one of the encodings every server should support.

The compress utility has been part of the Unix shell for a long time - since before POSIX - and I have trouble believing there's no standard C language implementation. I could use calls to system or exec to do the compression in the shell (creating another process...ugh) but that would be so much less efficient than just compiling the algorithm into my executable.

Is there a standard C implementation/library for this algorithm?

like image 444
William Rosenbloom Avatar asked Nov 25 '25 14:11

William Rosenbloom


1 Answers

I think I've found some good references:

First here is the Free BSD implementation of compress based on Lempel-Ziv: https://www.freebsd.org/security/advisories/FreeBSD-SA-11:04.compress.asc

Here and here a modified version of the Lempel-Ziv algorithm (among the authors you will find Spencer W. Thomas).

Newer implementation

DOS porting

Apple version based on FREE BSD.

hint: search "compress.c" quoted.

like image 57
terence hill Avatar answered Nov 27 '25 03:11

terence hill



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!