Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions ext/zlib/zlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1975,13 +1975,14 @@ rb_deflate_flush(int argc, VALUE *argv, VALUE obj)
}

/*
* Document-method: Zlib::Deflate.params
* Document-method: Zlib::Deflate#params
*
* call-seq: params(level, strategy)
* call-seq: params(level, strategy) -> nil
*
* Changes the parameters of the deflate stream to allow changes between
* different types of data that require different types of compression. Any
* unprocessed data is flushed before changing the params.
* unprocessed data is flushed first. You can also call this method before
* supplying any input.
*
* See Zlib::Deflate.new for a description of +level+ and +strategy+.
*
Expand All @@ -1998,6 +1999,10 @@ 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)) {
zstream_expand_buffer(z);
}

n = z->stream.avail_out;
err = deflateParams(&z->stream, level, strategy);
filled = n - z->stream.avail_out;
Expand Down
9 changes: 9 additions & 0 deletions test/zlib/test_zlib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,15 @@ def test_params_with_buf_error_and_pending_output
assert_equal(data, Zlib::Inflate.inflate(z.finish))
end

def test_params_before_input
z = Zlib::Deflate.new
assert_nil(z.params(Zlib::BEST_SPEED, Zlib::FILTERED))
z << "foo"
assert_equal("foo", Zlib::Inflate.inflate(z.finish))
ensure
z&.close
end

def test_params
z = Zlib::Deflate.new
z << "foo"
Expand Down