Class: Cassandra::Compression::Compressors::Snappy

Inherits:
Cassandra::Compression::Compressor show all
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

Instance Method Summary collapse

Constructor Details

#initialize(min_size = 64) ⇒ Snappy

Returns a new instance of Snappy.

Parameters:

  • min_size (Integer) (defaults to: 64)

    (64) Don't compress frames smaller than this size (see #compress?).



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

#algorithmString (readonly)

Returns 'snappy'.

Returns:

  • (String)

    '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.

Returns:

  • (true, false)

    will return false for frames smaller than the min_size given to the constructor.

See Also:



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