Project

huffman_tw

0.0
The project is in a healthy, maintained state
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.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

~> 4.0.4
 Project Readme

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

gem install huffman_tw
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.