Module: Zlib

Defined in:
lib/standard/facets/zlib.rb

Overview

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

Class Method Summary collapse

Class Method Details

.compress(source) ⇒ Object

Compresses a string using gzip.



16
17
18
19
20
21
22
23
24
25
# File 'lib/standard/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) ⇒ Object

Decompresses a gzipped string.



11
12
13
# File 'lib/standard/facets/zlib.rb', line 11

def self.decompress(source)
  GzipReader.new(StringIO.new(source)).read
end

.deflate(string, level = DEFAULT_COMPRESSION) ⇒ Object

Deflate a string.



33
34
35
# File 'lib/standard/facets/zlib.rb', line 33

def self.deflate(string, level=DEFAULT_COMPRESSION)
  Deflate.deflate(string, level)
end

.inflate(string) ⇒ Object

Inflate a deflated sting.



28
29
30
# File 'lib/standard/facets/zlib.rb', line 28

def self.inflate(string)
  Inflate.inflate(string)
end