diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c index 2f4fa11..8825241 100644 --- a/ext/zlib/zlib.c +++ b/ext/zlib/zlib.c @@ -4072,7 +4072,7 @@ rb_gzreader_s_zcat(int argc, VALUE *argv, VALUE klass) io = argv[0]; do { - obj = rb_funcallv(klass, rb_intern("new"), argc, argv); + obj = rb_funcallv_kw(klass, rb_intern("new"), argc, argv, RB_PASS_CALLED_KEYWORDS); if (rb_block_given_p()) { rb_gzreader_each(0, 0, obj); } diff --git a/test/zlib/test_zlib.rb b/test/zlib/test_zlib.rb index afe9529..969a970 100644 --- a/test/zlib/test_zlib.rb +++ b/test/zlib/test_zlib.rb @@ -832,6 +832,34 @@ def test_gzip_reader_zcat } end + def test_gzip_reader_zcat_with_options + Tempfile.create("test_zlib_gzip_file_to_io") {|t| + t.binmode + gz = Zlib::GzipWriter.new(t) + gz.print("foo") + gz.close + File.open(t.path, 'ab') do |f| + gz = Zlib::GzipWriter.new(f) + gz.print("bar") + gz.close + end + + results = [] + File.open(t.path, 'rb') do |f| + Zlib::GzipReader.zcat(f, external_encoding: Encoding::UTF_8) do |str| + results << str + end + end + assert_equal(["foo", "bar"], results) + assert_equal([Encoding::UTF_8, Encoding::UTF_8], results.map(&:encoding)) + + results = File.open(t.path, 'rb') do |f| + Zlib::GzipReader.zcat(f, external_encoding: Encoding::UTF_8) + end + assert_equal("foobar", results) + } + end + def test_to_io Tempfile.create("test_zlib_gzip_file_to_io") {|t| t.close