Compression libraries for Ruby?

回眸只為那壹抹淺笑 提交于 2019-12-23 10:57:53

问题


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.


回答1:


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!




回答2:


http://rubyzip.sourceforge.net/




回答3:


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




回答4:


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



来源:https://stackoverflow.com/questions/845348/compression-libraries-for-ruby

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!