Skip to content

Instantly share code, notes, and snippets.

@veader
Created September 15, 2010 18:12
Show Gist options
  • Save veader/581171 to your computer and use it in GitHub Desktop.
Save veader/581171 to your computer and use it in GitHub Desktop.
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