1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
# Load built-in zlib library
JRuby::Util.load_ext("org.jruby.ext.zlib.ZlibLibrary")
require 'stringio'
module Zlib
def self.gzip(src, opts = nil)
if Hash === opts
level = opts[:level]
strategy = opts[:strategy]
end
io = StringIO.new("".force_encoding("ASCII-8BIT"))
GzipWriter.new(io, level, strategy) do |writer|
writer.write(src)
end
io.string
end
def self.gunzip(src)
io = StringIO.new(src)
reader = GzipReader.new(io)
result = reader.read
reader.close
result
end
end
|