Created
September 15, 2010 18:12
-
-
Save veader/581171 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'zlib' | |
class String | |
def gzip | |
io = StringIO.new | |
gz = Zlib::GzipWriter.new(io) | |
gz.write(self) | |
gz.close | |
io.string | |
end | |
def gzip! | |
replace gzip | |
end | |
def gunzip | |
Zlib::GzipReader.new(StringIO.new(self)).read | |
rescue Zlib::GzipFile::Error | |
self | |
end | |
def gunzip! | |
replace gunzip | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment