Class: Cql::Compression::SnappyCompressor

Inherits:
Object
  • Object
show all
Defined in:
lib/cql/compression/snappy_compressor.rb

Overview

Note:

This compressor requires the snappy gem (v0.0.10 or later for JRuby support).

A compressor that uses the Snappy compression library.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(min_size = 64) ⇒ SnappyCompressor

Returns a new instance of SnappyCompressor.

Parameters:

  • min_size (Integer) (defaults to: 64)

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


22
23
24
25
# File 'lib/cql/compression/snappy_compressor.rb', line 22

def initialize(min_size=64)
  @algorithm = 'snappy'.freeze
  @min_size = min_size
end

Instance Attribute Details

#algorithmString (readonly)

Returns:

  • (String)

18
19
20
# File 'lib/cql/compression/snappy_compressor.rb', line 18

def algorithm
  @algorithm
end

Instance Method Details

#compress(str) ⇒ Object


33
34
35
# File 'lib/cql/compression/snappy_compressor.rb', line 33

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.


29
30
31
# File 'lib/cql/compression/snappy_compressor.rb', line 29

def compress?(str)
  str.bytesize > @min_size
end

#decompress(str) ⇒ Object


37
38
39
# File 'lib/cql/compression/snappy_compressor.rb', line 37

def decompress(str)
  Snappy.inflate(str)
end