Method: Zlib::GzipReader.zcat
- Defined in:
- zlib.c
.zcat(*args) ⇒ Object
call-seq:
Zlib::GzipReader.zcat(io, = {}, &block) => nil
Zlib::GzipReader.zcat(io, = {}) => string
Decompresses all gzip data in the io, handling multiple gzip streams until the end of the io. There should not be any non-gzip data after the gzip streams.
If a block is given, it is yielded strings of uncompressed data, and the method returns nil. If a block is not given, the method returns the concatenation of all uncompressed data in all gzip streams.
3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 |
# File 'zlib.c', line 3971 static VALUE rb_gzreader_s_zcat(int argc, VALUE *argv, VALUE klass) { VALUE io, unused, obj, buf=0, tmpbuf; long pos; rb_check_arity(argc, 1, 2); io = argv[0]; do { obj = rb_funcallv(klass, rb_intern("new"), argc, argv); if (rb_block_given_p()) { rb_gzreader_each(0, 0, obj); } else { if (!buf) { buf = rb_str_new(0, 0); } tmpbuf = gzfile_read_all(get_gzfile(obj), Qnil); rb_str_cat(buf, RSTRING_PTR(tmpbuf), RSTRING_LEN(tmpbuf)); } rb_gzreader_read(0, 0, obj); pos = NUM2LONG(rb_funcall(io, rb_intern("pos"), 0)); unused = rb_gzreader_unused(obj); rb_gzfile_finish(obj); if (!NIL_P(unused)) { pos -= NUM2LONG(rb_funcall(unused, rb_intern("length"), 0)); rb_funcall(io, rb_intern("pos="), 1, LONG2NUM(pos)); } } while (pos < NUM2LONG(rb_funcall(io, rb_intern("size"), 0))); if (rb_block_given_p()) { return Qnil; } return buf; } |