Class: Cassandra::Compression::Compressors::Lz4
- Inherits:
-
Cassandra::Compression::Compressor
- Object
- Cassandra::Compression::Compressor
- Cassandra::Compression::Compressors::Lz4
- Defined in:
- lib/cassandra/compression/compressors/lz4.rb
Overview
Note:
This compressor requires the lz4-ruby gem (v0.3.2 or later required).
Note:
No need to instantiate this class manually, use compression:
:lz4
option when calling Cassandra.cluster and one will be created
automatically for you.
A compressor that uses the LZ4 compression library.
Instance Attribute Summary collapse
-
#algorithm ⇒ String
readonly
'lz4'
.
Instance Method Summary collapse
- #compress(str) ⇒ Object
-
#compress?(str) ⇒ true, false
Will return false for frames smaller than the
min_size
given to the constructor. - #decompress(str) ⇒ Object
-
#initialize(min_size = 64) ⇒ Lz4
constructor
A new instance of Lz4.
Constructor Details
#initialize(min_size = 64) ⇒ Lz4
Returns a new instance of Lz4.
42 43 44 45 |
# File 'lib/cassandra/compression/compressors/lz4.rb', line 42 def initialize(min_size=64) @algorithm = 'lz4'.freeze @min_size = min_size end |
Instance Attribute Details
#algorithm ⇒ String (readonly)
Returns 'lz4'
.
38 39 40 |
# File 'lib/cassandra/compression/compressors/lz4.rb', line 38 def algorithm @algorithm end |
Instance Method Details
#compress(str) ⇒ Object
55 56 57 |
# File 'lib/cassandra/compression/compressors/lz4.rb', line 55 def compress(str) [str.bytesize, ::LZ4::Raw.compress(str.to_s).first].pack(BUFFER_FORMAT) end |
#compress?(str) ⇒ true, false
Returns will return false for frames smaller than the
min_size
given to the constructor.
50 51 52 |
# File 'lib/cassandra/compression/compressors/lz4.rb', line 50 def compress?(str) str.bytesize > @min_size end |
#decompress(str) ⇒ Object
60 61 62 63 |
# File 'lib/cassandra/compression/compressors/lz4.rb', line 60 def decompress(str) decompressed_size, compressed_data = str.to_s.unpack(BUFFER_FORMAT) ::LZ4::Raw.decompress(compressed_data, decompressed_size).first end |