Module: ActiveSupport::Gzip

Defined in:
activesupport/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.



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

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.



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

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