diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c index bcdd32a..d90f29e 100644 --- a/ext/zlib/zlib.c +++ b/ext/zlib/zlib.c @@ -1947,6 +1947,9 @@ rb_deflate_params(VALUE obj, VALUE v_level, VALUE v_strategy) level = ARG_LEVEL(v_level); strategy = ARG_STRATEGY(v_strategy); + if (NIL_P(z->buf) || z->stream.avail_out == 0) { + zstream_expand_buffer(z); + } n = z->stream.avail_out; err = deflateParams(&z->stream, level, strategy); filled = n - z->stream.avail_out; diff --git a/test/zlib/test_zlib.rb b/test/zlib/test_zlib.rb index e1ecbf8..970fbba 100644 --- a/test/zlib/test_zlib.rb +++ b/test/zlib/test_zlib.rb @@ -216,6 +216,20 @@ def test_params z.close # without this, outputs `zlib(finalizer): the stream was freed prematurely.' end + def test_params_without_output_buffer + z = Zlib::Deflate.new + z.params(Zlib::BEST_SPEED, Zlib::DEFAULT_STRATEGY) + z << "foo" + assert_equal("foo", Zlib::Inflate.inflate(z.finish)) + + z = Zlib::Deflate.new + z << "foo" + s = z.flush_next_out + z.params(Zlib::BEST_COMPRESSION, Zlib::FILTERED) + z << "bar" + assert_equal("foobar", Zlib::Inflate.inflate(s + z.finish)) + end + def test_set_dictionary z = Zlib::Deflate.new z.set_dictionary("foo")