Module: LZW
Overview
Scaling LZW, like Unix compress(1)
The LZW gem offers:
- LZW
-
Simple functional interface
- Compressor
-
LZW compressor with more fine-grained controls
- Decompressor
-
LZW decompressor in the same vein
- BitBuf
-
A String-backed buffer allowing bit-level operations
compress-lzw
About
This gem is a Ruby implementation of the Lempel-Ziv-Welch compression algorithm created in 1984. As of 2004, all patents on it had expired.
This implementation is compatible with the classic unix compress tool, and not compatible with the LZW compression used within GIF streams.
LZW is notable in two ways: it is dictionary-based compression but does not need to pass that dictionary within its files, instead decompression relies on progressively building a dictionary in the same way as the compressor. It also works outside the boundaries of bytes, writing its dictionary codes 9 bits at a time and scaling up as the codes increase to 16 bits.
To get right to work, check out the LZW module.
TODO
-
Convert from circleci to github actions
-
Code isn't the most efficient, but get impl right first. Buffering with a queue of 8 codes makes the packed code always fit an octet boundary.
-
Add a set of tests that tries to find compress binaries installed to use for compatibility tests.
Defined Under Namespace
Modules: Constants Classes: BitBuf, Compressor, Decompressor
Constant Summary collapse
- InputStreamError =
Exception class raised when compressed input is corrupt
Class.new(RuntimeError)
- VERSION =
"0.0.2"
Instance Method Summary collapse
-
#compress(data) ⇒ String
Compress input with defaults.
-
#decompress(data) ⇒ String
Decompress input with defaults.
Instance Method Details
#compress(data) ⇒ String
Compress input with defaults
27 28 29 |
# File 'lib/lzw.rb', line 27 def compress(data) LZW::Compressor.new.compress(data) end |
#decompress(data) ⇒ String
Decompress input with defaults
36 37 38 |
# File 'lib/lzw.rb', line 36 def decompress(data) LZW::Decompressor.new.decompress(data) end |