Skip to content

Instantly share code, notes, and snippets.

@mando
Created January 27, 2012 04:29
Show Gist options
  • Save mando/1686990 to your computer and use it in GitHub Desktop.
Save mando/1686990 to your computer and use it in GitHub Desktop.
zlib's being a little bitch
require 'zlib'
d = Zlib::Deflate.new
d.set_dictionary("foo")
s = d.deflate("foo" * 100, Zlib::FINISH)
i = Zlib::Inflate.new
begin
puts "Trying to set dictionary pre-emptively"
i.set_dictionary("foo")
puts i.inflate(s)
rescue Zlib::StreamError
puts "CRAP - got a StreamError"
end
begin
i.inflate(s)
rescue Zlib::NeedDict
puts "Trying to set the dictionary after handling the NeedDict"
i.set_dictionary("foo")
puts i.inflate(s)
puts "BOOM"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment