Created
September 1, 2011 17:36
-
-
Save ymnk/1186724 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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