huffman_tw

The teeworlds C++ huffman compression code wrapped as a ruby gem This gem implements the huffman compression algorithm. Using the exact code of the teeworlds codebase. https://github.com/teeworlds/teeworlds/blob/26d24ec061d44e6084b2d77a9b8a0a48e354eba6/src/engine/shared/huffman.cpp So this gem is ideal for developing teeworlds projects in ruby. But this is not a general purpose compression library. Do not expect speed/ease of use/safety/correctness but just being as close to the teeworlds implementation as possible.


License
Unlicense
Install
gem install huffman_tw -v 0.0.4

Documentation

huffman-tw

The teeworlds C++ huffman compression code wrapped as a ruby gem

Build the library

You need make, ruby and a C++ compiler installed.

gem install rice
ruby extconf.rb
make

Methods

Huffman.compress(data)

Takes a String as argument. The String will then be handled as a unsigned char * and compressed. The returned value is an Array of Integers.

Huffman.decompress(data)

Takes a Array or Integers as argument. It will then pack it as a unsigned char * and return an Array of Integers.

Use the library

require "huffman_tw"

huff = Huffman.new
data = huff.compress("hello world")
data = huff.decompress(data)

p data
p data.map(&:chr).join('')
[104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]
"hello world"

Tests

gem install rspec
rspec

DISCLAIMER

This is neither optimized for speed, safety nor ease of use. While this can be used as a compression library it is not recommended to do so. The goal of this project is to have the exact teeworlds compression code accessible via ruby to develop teeworlds related projects in ruby.