module ActiveSupport::Gzip

def self.compress(source, level = Zlib::DEFAULT_COMPRESSION, strategy = Zlib::DEFAULT_STRATEGY)

Compresses a string using gzip.
def self.compress(source, level = Zlib::DEFAULT_COMPRESSION, strategy = Zlib::DEFAULT_STRATEGY)
  output = Stream.new
  gz = Zlib::GzipWriter.new(output, level, strategy)
  gz.write(source)
  gz.close
  output.string
end

def self.decompress(source)

Decompresses a gzipped string.
def self.decompress(source)
  Zlib::GzipReader.wrap(StringIO.new(source), &:read)
end