File: active_support/gzip.rb

Overview
Module Structure
Class Hierarchy
Code

Overview

Module Structure

  module: <Toplevel Module>
  module: ActiveSupport#4
  module: Gzip#6
has properties
module method: decompress / 1 #12
module method: compress / 1 #17
  class: Stream#7
inherits from
  StringIO ( Builtin-Module )
has properties
method: close #8

Class Hierarchy

Code

   1  require 'zlib'
   2  require 'stringio'
   3 
   4  module ActiveSupport
   5    # A convenient wrapper for the zlib standard library that allows compression/decompression of strings with gzip.
   6    module Gzip
   7      class Stream < StringIO
   8        def close; rewind; end
   9      end
  10 
  11      # Decompresses a gzipped string.
  12      def self.decompress(source)
  13        Zlib::GzipReader.new(StringIO.new(source)).read
  14      end
  15 
  16      # Compresses a string using gzip.
  17      def self.compress(source)
  18        output = Stream.new
  19        gz = Zlib::GzipWriter.new(output)
  20        gz.write(source)
  21        gz.close
  22        output.string
  23      end
  24    end
  25  en