pandaant / huffmanrb

Implements a Huffman encoder/decoder in ruby

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Huffmanrb

Implements a Huffman encoder/decoder in ruby.

Installation

$ git clone https://github.com/pandaant/huffmanrb.git
$ cd huffmanrb
$ rake all

Example usage:

Create input to encode. 50% a's, 33.33% b's, 16.66% c's.

$ ruby -e "puts %w[a a a b b c].map{ |c| [c]*10000 }.flatten.shuffle.join" > testinput

Compress input to file

$ huffrb < testinput > enc.testinput

Decompress encoded file to file

$ huffrb -d < enc.testinput > dec.testinput

Compare file sizes

$ du -h testinput enc.testinput

Possible output:

60K testinput
16K enc.testinput

Compare md5 checksums of original and the decoded file

$ md5sum testinput dec.testinput

Possible output:

7de2762f5bd59a7f95796d3fa43b23d1  testinput
7de2762f5bd59a7f95796d3fa43b23d1  dec.testinput

About

Implements a Huffman encoder/decoder in ruby


Languages

Language:Ruby 100.0%