robertDurst / huffman_compression

Huffman Compression in 🐍

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Huffman's Compression Algorithm

Implemented via this video. Read more here. Fixed byte decoding/encoding issue with help from this post. Actual motivating factor along with avoiding an international relations essay. What I like to think motivated me.

Example Usage

example.py

from huffman import compress, decompress

# obviously you can compress much larger things...
data = "Avocados are super tasty!"

# compress
compressed = compress(data)

# decompress
decompressed = decompress(compressed)

print(decoded)

terminal

> python example.py
"Avocados are super tasty!"

For a more interesting and complete example, see example.py.

Stats

Compressed the entire Illiad and compared against ASCII encoding.

Compressed size: 54.4% of original                                                                                      
Size of huffman compressed file: 446.6kb                                                                                
Size of ascii compressed file: 807.45kb                                                                                 
Size of  uncompressed file: 820.89kb                                                                                    
Time to encode Huffman: 1.55 sec                                                                           
Time to encode ASCII: 5.10 sec                                                                           
Time to decode Huffman: 2.75 sec

About

Huffman Compression in 🐍


Languages

Language:Python 100.0%