Method: Zlib::GzipReader#initialize
- Defined in:
-
ext/zstdlib/ruby/zlib-2.2/zlib.c,
ext/zstdlib/ruby/zlib-2.3/zlib.c,
ext/zstdlib/ruby/zlib-2.4/zlib.c,
ext/zstdlib/ruby/zlib-2.5/zlib.c,
ext/zstdlib/ruby/zlib-2.6/zlib.c
call-seq:
Zlib::GzipReader.new(io, = {})
Creates a GzipReader object associated with io
. The GzipReader object reads gzipped data from io
, and parses/decompresses it. The io
must have a read
method that behaves same as the IO#read.
The options
hash may be used to set the encoding of the data. :external_encoding
, :internal_encoding
and :encoding
may be set as in IO::new.
If the gzip file header is incorrect, raises an Zlib::GzipFile::Error exception.
3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 |
# File 'ext/zstdlib/ruby/zlib-2.2/zlib.c', line 3715
static VALUE
rb_gzreader_initialize(int argc, VALUE *argv, VALUE obj)
{
VALUE io, opt = Qnil;
struct gzfile *gz;
int err;
TypedData_Get_Struct(obj, struct gzfile, &gzfile_data_type, gz);
rb_scan_args(argc, argv, "1:", &io, &opt);
/* this is undocumented feature of zlib */
err = inflateInit2(&gz->z.stream, -MAX_WBITS);
if (err != Z_OK) {
raise_zlib_error(err, gz->z.stream.msg);
}
gz->io = io;
ZSTREAM_READY(&gz->z);
gzfile_read_header(gz);
rb_gzfile_ecopts(gz, opt);
if (rb_respond_to(io, id_path)) {
gz->path = rb_funcall(gz->io, id_path, 0);
rb_define_singleton_method(obj, "path", rb_gzfile_path, 0);
}
return obj;
}
|