Sha256: 737ad38392dca4a9972e58e58a2b88aaf2ab3d8bad7fe56571e9fabdc4c4ad69

Contents?: true

Size: 693 Bytes

Versions: 6

Compression:

Stored size: 693 Bytes

Contents

require 'zlib'
require 'stringio'

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

6 entries across 6 versions & 1 rubygems

Version Path
activesupport-3.1.0.rc5 lib/active_support/gzip.rb
activesupport-3.1.0.rc4 lib/active_support/gzip.rb
activesupport-3.1.0.rc3 lib/active_support/gzip.rb
activesupport-3.1.0.rc2 lib/active_support/gzip.rb
activesupport-3.1.0.rc1 lib/active_support/gzip.rb
activesupport-3.1.0.beta1 lib/active_support/gzip.rb