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
2 changes: 1 addition & 1 deletion ext/zlib/zlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
28 changes: 28 additions & 0 deletions test/zlib/test_zlib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down