new(p1)
public
Creates a GzipReader object associated with io. The GzipReader
object reads gzipped data from io, and parses/decompresses them.
At least, io must have a read method that behaves same as
the read method in IO class.
If the gzip file header is incorrect, raises an Zlib::GzipFile::Error exception.
Show source
static VALUE
rb_gzreader_initialize(int argc, VALUE *argv, VALUE obj)
{
VALUE io, opt = Qnil;
struct gzfile *gz;
int err;
Data_Get_Struct(obj, struct gzfile, gz);
if (argc > 1) {
opt = rb_check_convert_type(argv[argc-1], T_HASH, "Hash", "to_hash");
if (!NIL_P(opt)) argc--;
}
rb_scan_args(argc, argv, "1", &io);
/* 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);
return obj;
}