module Ritm::Encodings
Constants
- ENCODINGS
Public Class Methods
decode(encoding, data)
click to toggle source
# File lib/ritm/helpers/encodings.rb, line 20 def self.decode(encoding, data) case encoding when :gzip decode_gzip(data) when :deflate decode_deflate(data) when :identity identity(data) else raise "Unsupported encoding #{encoding}" end end
encode(encoding, data)
click to toggle source
# File lib/ritm/helpers/encodings.rb, line 7 def self.encode(encoding, data) case encoding when :gzip encode_gzip(data) when :deflate encode_deflate(data) when :identity identity(data) else raise "Unsupported encoding #{encoding}" end end
Private Class Methods
decode_deflate(data)
click to toggle source
# File lib/ritm/helpers/encodings.rb, line 58 def decode_deflate(data) Zlib::Inflate.inflate(data) end
decode_gzip(data)
click to toggle source
# File lib/ritm/helpers/encodings.rb, line 48 def decode_gzip(data) io = StringIO.new(data, 'rb') gz = Zlib::GzipReader.new(io) gz.read end
encode_deflate(data)
click to toggle source
# File lib/ritm/helpers/encodings.rb, line 54 def encode_deflate(data) Zlib::Deflate.deflate(data) end
encode_gzip(data)
click to toggle source
# File lib/ritm/helpers/encodings.rb, line 40 def encode_gzip(data) wio = StringIO.new('wb') w_gz = Zlib::GzipWriter.new(wio) w_gz.write(data) w_gz.close wio.string end
identity(data)
click to toggle source
# File lib/ritm/helpers/encodings.rb, line 36 def identity(data) data end