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

+ (Object) compress(source)

Compresses a string using gzip.



17
18
19
20
21
22
23
# File 'activesupport/lib/active_support/gzip.rb', line 17

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

+ (Object) decompress(source)

Decompresses a gzipped string.



12
13
14
# File 'activesupport/lib/active_support/gzip.rb', line 12

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