Module: Pheme::Compression

Included in:
QueuePoller, TopicPublisher
Defined in:
lib/pheme/compression.rb

Instance Method Summary collapse

Instance Method Details

#compress(body) ⇒ Object



6
7
8
9
10
# File 'lib/pheme/compression.rb', line 6

def compress(body)
  gz = Zlib::GzipWriter.new(StringIO.new)
  gz << body
  Base64.encode64(gz.close.string)
end

#decompress(body) ⇒ Object



12
13
14
15
16
# File 'lib/pheme/compression.rb', line 12

def decompress(body)
  return Zlib::GzipReader.new(StringIO.new(Base64.decode64(body))).read if gzip?(body)

  body
end