Reputation:
Are there any open-source compression/decomp libraries available for Ruby? Has anyone implemented LZW?
Or, are there any open-source libraries that use a compression component which could conceivably be extracted for independent use?
EDIT -- thanks for the answers! I should have mentioned that what I have to compress are long strings that will only reside in a database (I won't be compressing files). Also, it would be ideal if whatever library could do this had an equivalent implementation in JavaScript for client-side comp/decomp, as this would be for a web app.
Upvotes: 5
Views: 4244
Reputation: 3662
You can try ruby-lzws, bindings for lzws library. It is compatible with UNIX compress.
gem install ruby-lzws
require "lzws"
data = LZWS::String.compress "TOBEORNOTTOBEORTOBEORNOT"
puts LZWS::String.decompress(data)
TOBEORNOTTOBEORTOBEORNOT
Upvotes: 0
Reputation: 20398
zlib is fine if you care more about size than speed or you want to be sure there's bindings in other languages for compatibility. For on the wire transfers, speed and CPU utilization is often more important.
A few ruby libs integrating much faster compression libs are: Google's Snappy, QuickLZ, and LZO
Upvotes: 2
Reputation: 16752
You find a nice list of all shipped libs of ruby under ruby stdlib.
I'd use the zlib library, it's open, it's used everywhere and you'll find libraries for virtually every language!
Upvotes: 5