~michaelforrest/use-case-mapper/trunk

« back to all changes in this revision

Viewing changes to vendor/rails/activesupport/lib/active_support/gzip.rb

  • Committer: Michael Forrest
  • Date: 2010-10-15 16:28:50 UTC
  • Revision ID: michael.forrest@canonical.com-20101015162850-tj2vchanv0kr0dun
refrozeĀ gems

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
end
 
 
b'\\ No newline at end of file'