zlib.c: multiple arguments to write

* ext/zlib/zlib.c (rb_gzwriter_write): accepts multiple arguments.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60379 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2017-10-23 07:06:12 +00:00
Родитель cf4351f82a
Коммит 585cbf6535
3 изменённых файлов: 26 добавлений и 10 удалений

3
NEWS
Просмотреть файл

@ -211,6 +211,9 @@ with all sufficient information, see the ChangeLog file or Redmine
* Add Server Name Indication (SNI) support [Feature #13729]
* Zlilb
* Zlib::GzipWriter#write accepts multiple arguments
=== Compatibility issues (excluding feature bug fixes)
* BasicSocket#read_nonblock and BasicSocket#write_nonblock no

Просмотреть файл

@ -197,7 +197,7 @@ static VALUE rb_gzwriter_s_allocate(VALUE);
static VALUE rb_gzwriter_s_open(int, VALUE*, VALUE);
static VALUE rb_gzwriter_initialize(int, VALUE*, VALUE);
static VALUE rb_gzwriter_flush(int, VALUE*, VALUE);
static VALUE rb_gzwriter_write(VALUE, VALUE);
static VALUE rb_gzwriter_write(int, VALUE*, VALUE);
static VALUE rb_gzwriter_putc(VALUE, VALUE);
static VALUE rb_gzreader_s_allocate(VALUE);
@ -3566,18 +3566,23 @@ rb_gzwriter_flush(int argc, VALUE *argv, VALUE obj)
* Same as IO.
*/
static VALUE
rb_gzwriter_write(VALUE obj, VALUE str)
rb_gzwriter_write(int argc, VALUE *argv, VALUE obj)
{
struct gzfile *gz = get_gzfile(obj);
size_t total = 0;
if (!RB_TYPE_P(str, T_STRING))
str = rb_obj_as_string(str);
if (gz->enc2 && gz->enc2 != rb_ascii8bit_encoding()) {
str = rb_str_conv_enc(str, rb_enc_get(str), gz->enc2);
while (argc-- > 0) {
VALUE str = *argv++;
if (!RB_TYPE_P(str, T_STRING))
str = rb_obj_as_string(str);
if (gz->enc2 && gz->enc2 != rb_ascii8bit_encoding()) {
str = rb_str_conv_enc(str, rb_enc_get(str), gz->enc2);
}
gzfile_write(gz, (Bytef*)RSTRING_PTR(str), RSTRING_LEN(str));
total += RSTRING_LEN(str);
RB_GC_GUARD(str);
}
gzfile_write(gz, (Bytef*)RSTRING_PTR(str), RSTRING_LEN(str));
RB_GC_GUARD(str);
return INT2FIX(RSTRING_LEN(str));
return SIZET2NUM(total);
}
/*
@ -4650,7 +4655,7 @@ Init_zlib(void)
rb_define_alloc_func(cGzipWriter, rb_gzwriter_s_allocate);
rb_define_method(cGzipWriter, "initialize", rb_gzwriter_initialize,-1);
rb_define_method(cGzipWriter, "flush", rb_gzwriter_flush, -1);
rb_define_method(cGzipWriter, "write", rb_gzwriter_write, 1);
rb_define_method(cGzipWriter, "write", rb_gzwriter_write, -1);
rb_define_method(cGzipWriter, "putc", rb_gzwriter_putc, 1);
rb_define_method(cGzipWriter, "<<", rb_gzwriter_addstr, 1);
rb_define_method(cGzipWriter, "printf", rb_gzwriter_printf, -1);

Просмотреть файл

@ -1057,6 +1057,14 @@ if defined? Zlib
}
end
def test_puts
Tempfile.create("test_zlib_gzip_writer_puts") {|t|
t.close
Zlib::GzipWriter.open(t.path) {|gz| gz.puts("foo") }
assert_equal("foo\n", Zlib::GzipReader.open(t.path) {|gz| gz.read })
}
end
def test_writer_wrap
Tempfile.create("test_zlib_gzip_writer_wrap") {|t|
t.binmode