Class: Dalli::GzipCompressor

Inherits:
Object
  • Object
show all
Defined in:
lib/dalli/compressor.rb

Overview

Alternate compressor for Dalli, that uses Gzip. Gzip adds a checksum to each compressed entry.

Class Method Summary collapse

Class Method Details

.compress(data) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/dalli/compressor.rb', line 27

def self.compress(data)
  io = StringIO.new(+'', 'w')
  gz = Zlib::GzipWriter.new(io)
  gz.write(data)
  gz.close
  io.string
end

.decompress(data) ⇒ Object



35
36
37
38
# File 'lib/dalli/compressor.rb', line 35

def self.decompress(data)
  io = StringIO.new(data, 'rb')
  Zlib::GzipReader.new(io).read
end