4
votes

There are lots of implementations of the Deflate decompression algorithm in different languages. The decompression algorithm itself is described in RFC1951. However, the compression algorithm seems more elusive and I've only ever seen it implemented in long C/C++ files.

I'd like to find an implementation of the compression algorithm in a higher level language, e.g. Python/Ruby/Lua/etc., for study purposes. Can someone point me to one?

1

1 Answers

1
votes

Pyflate is a pure python implementation of gzip (which uses DEFLATE). http://www.paul.sladen.org/projects/pyflate/

Edit: Here is a python implementation of LZ77 compression, which is the first step in DEFLATE.

https://github.com/olle/lz77-kit/blob/master/src/main/python/lz77.py

The next step, Huffman encoding of the symbols, is a simple greedy algorithm which shouldn't be too hard to implement.