Skip to content

Instantly share code, notes, and snippets.

@ymnk
Created September 1, 2011 17:36
Show Gist options
  • Save ymnk/1186724 to your computer and use it in GitHub Desktop.
Save ymnk/1186724 to your computer and use it in GitHub Desktop.
require 'zlib'
dict = "hello"
str = "hello, hello!"
d = Zlib::Deflate.new
d.set_dictionary(dict)
comp_str = d.deflate(str)
comp_str << d.finish
i = Zlib::Inflate.new(Zlib::MAX_WBITS + 32)
i.set_dictionary(dict)
i << comp_str
uncomp_comp_str = i.finish
p uncomp_comp_str, str == uncomp_comp_str
require 'zlib'
dict = "hello"
str = "hello, hello!"
d = Zlib::Deflate.new
d.set_dictionary(dict)
comp_str = d.deflate(str)
comp_str << d.finish
i = Zlib::Inflate.new(Zlib::MAX_WBITS + 32)
begin
i.inflate(comp_str)
rescue Zlib::NeedDict
end
i.set_dictionary(dict)
i << ""
uncomp_comp_str = i.finish
p uncomp_comp_str, str == uncomp_comp_str
require 'zlib'
dict = "hello"
str = "hello, hello!"
d = Zlib::Deflate.new
d.set_dictionary(dict)
comp_str = d.deflate(str)
comp_str << d.finish
i = Zlib::Inflate.new(Zlib::MAX_WBITS + 32)
begin
i << comp_str.slice!(0, 9)
rescue Zlib::NeedDict
end
i.set_dictionary(dict)
i << comp_str
uncomp_comp_str = i.finish
p uncomp_comp_str, str == uncomp_comp_str
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment