Sha256: 7ade203ebdd745193efb8145f2cd2360eeba98d4a3685f1a8abf86bc53ef9ae6

Contents?: true

Size: 746 Bytes

Versions: 11

Compression:

Stored size: 746 Bytes

Contents

require 'zlib'
require 'stringio'
require 'active_support/core_ext/string/encoding'

module ActiveSupport
  # A convenient wrapper for the zlib standard library that allows compression/decompression of strings with gzip.
  module Gzip
    class Stream < StringIO
      def initialize(*)
         super
         set_encoding "BINARY" if "".encoding_aware?
       end
      def close; rewind; end
    end

    # Decompresses a gzipped string.
    def self.decompress(source)
      Zlib::GzipReader.new(StringIO.new(source)).read
    end

    # Compresses a string using gzip.
    def self.compress(source)
      output = Stream.new
      gz = Zlib::GzipWriter.new(output)
      gz.write(source)
      gz.close
      output.string
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
activesupport-3.0.19 lib/active_support/gzip.rb
activesupport-3.0.18 lib/active_support/gzip.rb
activesupport-3.0.17 lib/active_support/gzip.rb
activesupport-3.0.16 lib/active_support/gzip.rb
activesupport-3.0.15 lib/active_support/gzip.rb
activesupport-3.0.14 lib/active_support/gzip.rb
activesupport-3.0.13 lib/active_support/gzip.rb
activesupport-3.0.13.rc1 lib/active_support/gzip.rb
activesupport-3.0.12 lib/active_support/gzip.rb
activesupport-3.0.12.rc1 lib/active_support/gzip.rb
activesupport-3.0.11 lib/active_support/gzip.rb