Class: Cassandra::Compression::Compressors::Snappy
- Inherits:
-
Cassandra::Compression::Compressor
- Object
- Cassandra::Compression::Compressor
- Cassandra::Compression::Compressors::Snappy
- Defined in:
- lib/cassandra/compression/compressors/snappy.rb
Overview
Note:
This compressor requires the snappy gem (v0.0.10 or later for JRuby support).
Note:
No need to instantiate this class manually, use compression:
:snappy
option when calling Cassandra.cluster and one will be
created automatically for you.
A compressor that uses the Snappy compression library.
Instance Attribute Summary collapse
-
#algorithm ⇒ String
readonly
'snappy'
.
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) ⇒ Snappy
constructor
A new instance of Snappy.
Constructor Details
#initialize(min_size = 64) ⇒ Snappy
Returns a new instance of Snappy.
42 43 44 45 |
# File 'lib/cassandra/compression/compressors/snappy.rb', line 42 def initialize(min_size=64) @algorithm = 'snappy'.freeze @min_size = min_size end |
Instance Attribute Details
#algorithm ⇒ String (readonly)
Returns 'snappy'
.
38 39 40 |
# File 'lib/cassandra/compression/compressors/snappy.rb', line 38 def algorithm @algorithm end |
Instance Method Details
#compress(str) ⇒ Object
55 56 57 |
# File 'lib/cassandra/compression/compressors/snappy.rb', line 55 def compress(str) ::Snappy.deflate(str) 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/snappy.rb', line 50 def compress?(str) str.bytesize > @min_size end |
#decompress(str) ⇒ Object
60 61 62 |
# File 'lib/cassandra/compression/compressors/snappy.rb', line 60 def decompress(str) ::Snappy.inflate(str) end |