summaryrefslogtreecommitdiff
path: root/ext/zlib
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-23 07:06:12 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-23 07:06:12 +0000
commit585cbf65351ca10ebe673fefac22fdb9864779eb (patch)
tree3d2afa50d4599f14242a6492b8e6bfaaccb75412 /ext/zlib
parentcf4351f82a8e7ea18b351c9d06b0ea76fb6d0d85 (diff)
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
Diffstat (limited to 'ext/zlib')
-rw-r--r--ext/zlib/zlib.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c
index fde85be..4cae484 100644
--- a/ext/zlib/zlib.c
+++ b/ext/zlib/zlib.c
@@ -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);
-
- 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);
+ size_t total = 0;
+
+ 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);