aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/gzip.rb
blob: c65944dacdcdeae0a50a64f3764deeaed3d52af4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
require 'zlib'
require 'stringio'

module ActiveSupport
  module Gzip
    class Stream < StringIO
      def close; rewind; end
    end

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

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