Module: ActiveSupport::Gzip

Defined in:
lib/active_support/gzip.rb

Overview

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

Defined Under Namespace

Classes: Stream

Class Method Summary collapse

Class Method Details

.compress(source) ⇒ Object

Compresses a string using gzip.



21
22
23
24
25
26
27
# File 'lib/active_support/gzip.rb', line 21

def self.compress(source)
  output = Stream.new
  gz = Zlib::GzipWriter.new(output)
  gz.write(source)
  gz.close
  output.string
end

.decompress(source) ⇒ Object

Decompresses a gzipped string.



16
17
18
# File 'lib/active_support/gzip.rb', line 16

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