From 403dc5357dddd1cd8af4b73bc658fcbf3b91643c Mon Sep 17 00:00:00 2001 From: drbrain Date: Sat, 11 Feb 2012 00:29:52 +0000 Subject: * ext/zlib/zlib.c (do_inflate): Inflate more data if buffered data exists. Allows Zlib::Inflate#set_dictionary to work. [ruby-trunk - Bug #5929] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34552 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/zlib/zlib.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'ext/zlib') diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c index a235cbb621..6cc6d5571f 100644 --- a/ext/zlib/zlib.c +++ b/ext/zlib/zlib.c @@ -1732,7 +1732,7 @@ do_inflate(struct zstream *z, VALUE src) 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); } } @@ -1749,7 +1749,23 @@ do_inflate(struct zstream *z, VALUE src) * * 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. (???) + * 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 */ -- cgit v1.2.3