module Zlib

A convenient wrapper for the zlib standard library that allows compression/decompression of strings with gzip.

Public Class Methods

compress(source) click to toggle source

Compresses a string using gzip.

# File lib/facets/zlib.rb, line 16
def self.compress(source)
  output = StringIO.new
  class << output
    def close; rewind; end
  end
  gz = GzipWriter.new(output)
  gz.write(source)
  gz.close
  output.string
end
decompress(source) click to toggle source

Decompresses a gzipped string.

# File lib/facets/zlib.rb, line 11
def self.decompress(source)
  GzipReader.new(StringIO.new(source)).read
end
deflate(string, level=DEFAULT_COMPRESSION) click to toggle source

Deflate a string.

# File lib/facets/zlib.rb, line 33
def self.deflate(string, level=DEFAULT_COMPRESSION)
  Deflate.deflate(string, level)
end
inflate(string) click to toggle source

Inflate a deflated sting.

# File lib/facets/zlib.rb, line 28
def self.inflate(string)
  Inflate.inflate(string)
end