public
Fork of tobi/cacheable
Description: Page caching extension of Shopify
Homepage: http://www.shopify.com
Clone URL: git://github.com/Shopify/cacheable.git
Tobias Luetke (home) (author)
Sun Feb 24 08:51:37 -0800 2008
cacheable / lib / gzip.rb
100644 21 lines (17 sloc) 0.371 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
require 'zlib'
require 'stringio'
 
 
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