Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

root/trunk/activesupport/lib/active_support/gzip.rb

Revision 9093, 0.6 kB (checked in by pratik, 7 months ago)

Improve documentation.

Line 
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
Note: See TracBrowser for help on using the browser.