Project

General

Profile

Bug #5929 ยป zlib.c.set_dictionary.patch

drbrain (Eric Hodel), 01/26/2012 11:59 AM

View differences:

ext/zlib/zlib.c (working copy)
return;
}
StringValue(src);
if (RSTRING_LEN(src) > 0) { /* prevent Z_BUF_ERROR */
if (RSTRING_LEN(src) > 0 || z->stream.avail_in > 0) { /* prevent Z_BUF_ERROR */
zstream_run(z, (Bytef*)RSTRING_PTR(src), RSTRING_LEN(src), Z_SYNC_FLUSH);
}
}
......
*
* Raises a Zlib::NeedDict exception if a preset dictionary is needed to
* decompress. Set the dictionary by Zlib::Inflate#set_dictionary and then
* call this method again with an empty string. (<i>???</i>)
* call this method again with an empty string to flush the stream:
*
* inflater = Zlib::Inflate.new
*
* begin
* out = inflater.inflate compressed
* rescue Zlib::NeedDict
* # ensure the dictionary matches the stream's required dictionary
* raise unless inflater.adler == Zlib.adler32(dictionary)
*
* inflater.set_dictionary dictionary
* inflater.inflate ''
* end
*
* # ...
*
* inflater.close
*
* See also Zlib::Inflate.new
*/
test/zlib/test_zlib.rb (working copy)
z << "foo" # ???
end
def test_inflate_dictionary
dictionary = "foo"
deflate = Zlib::Deflate.new
deflate.set_dictionary dictionary
compressed = deflate.deflate "foofoofoo", Zlib::FINISH
deflate.close
out = nil
inflate = Zlib::Inflate.new
begin
out = inflate.inflate compressed
flunk "Zlib::NeedDict was not raised"
rescue Zlib::NeedDict
inflate.set_dictionary dictionary
out = inflate.inflate ""
end
assert_equal "foofoofoo", out
end
def test_sync
z = Zlib::Deflate.new
s = z.deflate("foo" * 1000, Zlib::FULL_FLUSH)
    (1-1/1)