Class: Zlib::GzipFile
- Inherits:
-
Object
- Object
- Zlib::GzipFile
- Defined in:
- zlib.c
Overview
Zlib::GzipFile is an abstract class for handling a gzip formatted compressed file. The operations are defined in the subclasses, Zlib::GzipReader for reading, and Zlib::GzipWriter for writing.
GzipReader should be used by associating an IO, or IO-like, object.
Direct Known Subclasses
Defined Under Namespace
Classes: CRCError, Error, LengthError, NoFooter
Class Method Summary collapse
-
.wrap ⇒ Object
See Zlib::GzipReader#wrap and Zlib::GzipWriter#wrap.
Instance Method Summary collapse
-
#close ⇒ Object
Closes the GzipFile object.
-
#closed? ⇒ Object
Same as IO.
-
#comment ⇒ Object
Returns comments recorded in the gzip file header, or nil if the comments is not present.
-
#crc ⇒ Object
Returns CRC value of the uncompressed data.
-
#finish ⇒ Object
Closes the GzipFile object.
-
#level ⇒ Object
Returns compression level.
-
#mtime ⇒ Object
Returns last modification time recorded in the gzip file header.
-
#orig_name ⇒ Object
Returns original filename recorded in the gzip file header, or
nil
if original filename is not present. -
#os_code ⇒ Object
Returns OS code number recorded in the gzip file header.
-
#sync ⇒ Object
Same as IO.
-
#sync=(flag) ⇒ Object
Same as IO.
-
#to_io ⇒ Object
Same as IO.
Class Method Details
.wrap ⇒ Object
See Zlib::GzipReader#wrap and Zlib::GzipWriter#wrap.
|
# File 'zlib.c'
/*
* See Zlib::GzipReader#wrap and Zlib::GzipWriter#wrap.
*/
static VALUE
rb_gzfile_s_wrap(argc, argv, klass)
int argc;
VALUE *argv;
VALUE klass;
{
VALUE obj = rb_class_new_instance(argc, argv, klass);
if (rb_block_given_p()) {
return rb_ensure(rb_yield, obj, gzfile_ensure_close, obj);
}
else {
return obj;
}
}
|
Instance Method Details
#close ⇒ Object
Closes the GzipFile object. This method calls close method of the associated IO object. Returns the associated IO object.
|
# File 'zlib.c'
/*
* Closes the GzipFile object. This method calls close method of the
* associated IO object. Returns the associated IO object.
*/
static VALUE
rb_gzfile_close(obj)
VALUE obj;
{
struct gzfile *gz = get_gzfile(obj);
VALUE io;
io = gz->io;
gzfile_close(gz, 1);
return io;
}
|
#closed? ⇒ Object
Same as IO.
|
# File 'zlib.c'
/*
* Same as IO.
*/
static VALUE
rb_gzfile_closed_p(obj)
VALUE obj;
{
struct gzfile *gz;
Data_Get_Struct(obj, struct gzfile, gz);
return NIL_P(gz->io) ? Qtrue : Qfalse;
}
|
#comment ⇒ Object
Returns comments recorded in the gzip file header, or nil if the comments is not present.
|
# File 'zlib.c'
/*
* Returns comments recorded in the gzip file header, or nil if the comments
* is not present.
*/
static VALUE
rb_gzfile_comment(obj)
VALUE obj;
{
VALUE str = get_gzfile(obj)->comment;
if (!NIL_P(str)) {
str = rb_str_dup(str);
}
OBJ_TAINT(str); /* for safe */
return str;
}
|
#crc ⇒ Object
Returns CRC value of the uncompressed data.
|
# File 'zlib.c'
/*
* Returns CRC value of the uncompressed data.
*/
static VALUE
rb_gzfile_crc(obj)
VALUE obj;
{
return rb_uint2inum(get_gzfile(obj)->crc);
}
|
#finish ⇒ Object
Closes the GzipFile object. Unlike Zlib::GzipFile#close, this method never calls the close method of the associated IO object. Returns the associated IO object.
|
# File 'zlib.c'
/*
* Closes the GzipFile object. Unlike Zlib::GzipFile#close, this method never
* calls the close method of the associated IO object. Returns the associated IO
* object.
*/
static VALUE
rb_gzfile_finish(obj)
VALUE obj;
{
struct gzfile *gz = get_gzfile(obj);
VALUE io;
io = gz->io;
gzfile_close(gz, 0);
return io;
}
|
#level ⇒ Object
Returns compression level.
|
# File 'zlib.c'
/*
* Returns compression level.
*/
static VALUE
rb_gzfile_level(obj)
VALUE obj;
{
return INT2FIX(get_gzfile(obj)->level);
}
|
#mtime ⇒ Object
Returns last modification time recorded in the gzip file header.
|
# File 'zlib.c'
/*
* Returns last modification time recorded in the gzip file header.
*/
static VALUE
rb_gzfile_mtime(obj)
VALUE obj;
{
return rb_time_new(get_gzfile(obj)->mtime, (time_t)0);
}
|
#orig_name ⇒ Object
Returns original filename recorded in the gzip file header, or nil
if original filename is not present.
|
# File 'zlib.c'
/*
* Returns original filename recorded in the gzip file header, or +nil+ if
* original filename is not present.
*/
static VALUE
rb_gzfile_orig_name(obj)
VALUE obj;
{
VALUE str = get_gzfile(obj)->orig_name;
if (!NIL_P(str)) {
str = rb_str_dup(str);
}
OBJ_TAINT(str); /* for safe */
return str;
}
|
#os_code ⇒ Object
Returns OS code number recorded in the gzip file header.
|
# File 'zlib.c'
/*
* Returns OS code number recorded in the gzip file header.
*/
static VALUE
rb_gzfile_os_code(obj)
VALUE obj;
{
return INT2FIX(get_gzfile(obj)->os_code);
}
|
#sync ⇒ Object
Same as IO.
|
# File 'zlib.c'
/*
* Same as IO.
*/
static VALUE
rb_gzfile_sync(obj)
VALUE obj;
{
return (get_gzfile(obj)->z.flags & GZFILE_FLAG_SYNC) ? Qtrue : Qfalse;
}
|
#sync=(flag) ⇒ Object
Same as IO. If flag is true
, the associated IO object must respond to the flush
method. While sync
mode is true
, the compression ratio decreases sharply.
|
# File 'zlib.c'
/*
* call-seq: sync = flag
*
* Same as IO. If flag is +true+, the associated IO object must respond to the
* +flush+ method. While +sync+ mode is +true+, the compression ratio
* decreases sharply.
*/
static VALUE
rb_gzfile_set_sync(obj, mode)
VALUE obj, mode;
{
struct gzfile *gz = get_gzfile(obj);
if (RTEST(mode)) {
gz->z.flags |= GZFILE_FLAG_SYNC;
}
else {
gz->z.flags &= ~GZFILE_FLAG_SYNC;
}
return mode;
}
|
#to_io ⇒ Object
Same as IO.
|
# File 'zlib.c'
/*
* Same as IO.
*/
static VALUE
rb_gzfile_to_io(obj)
VALUE obj;
{
return get_gzfile(obj)->io;
}
|