aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/gzip.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support/gzip.rb')
-rw-r--r--activesupport/lib/active_support/gzip.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/gzip.rb b/activesupport/lib/active_support/gzip.rb
new file mode 100644
index 0000000000..c65944dacd
--- /dev/null
+++ b/activesupport/lib/active_support/gzip.rb
@@ -0,0 +1,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 \ No newline at end of file