def deflate(string, level)
z = Zlib::Deflate.new(level)
dst = z.deflate(string, Zlib::NO_FLUSH)
z.close
return dst
end
def inflate(string)
zstream = Zlib::Inflate.new
buf = zstream.inflate(string)
zstream.finish
zstream.close
return buf
end
a = deflate("asasasas",6)
p a
p inflate(a)
Gives me a buffer error on line
zstream.finish
Why is that? Ruby 1.8.7 I believe.
The documentation on deflate says:
By using Zlib::NO_FLUSH the returned value is not the entire deflated stream. Use Zlib::FINISH instead.
The functions you’ve written are the ones provided in the Zlib::Deflate / Zlib::Inflate documentation. You could replace all the code you’ve written with: