123456789_123456789_123456789_123456789_123456789_

Class: Zlib::GzipFile

Relationships & Source Files
Namespace Children
Exceptions:
Extension / Inclusion / Inheritance Descendants
Subclasses:
Inherits: Object
Defined in: ext/zlib/zlib.c,
ext/zlib/zlib.c

Overview

GzipFile is an abstract class for handling a gzip formatted compressed file. The operations are defined in the subclasses, GzipReader for reading, and GzipWriter for writing.

GzipReader should be used by associating an IO, or IO-like, object.

Method Catalogue

(due to internal structure, documentation may appear under GzipReader or GzipWriter)

Class Method Summary

Instance Attribute Summary

Instance Method Summary

  • #close

    Closes the GzipFile object.

  • #comment

    Returns comments recorded in the gzip file header, or nil if the comments is not present.

  • #crc

    Returns CRC value of the uncompressed data.

  • #finish

    Closes the GzipFile object.

  • #level

    Returns compression level.

  • #mtime

    Returns last modification time recorded in the gzip file header.

  • #orig_name

    Returns original filename recorded in the gzip file header, or nil if original filename is not present.

  • #os_code

    Returns OS code number recorded in the gzip file header.

  • #to_io

    Same as IO.

Class Method Details

Zlib::GzipReader.wrap(io, ...) {|gz| ... } Zlib::GzipWriter.wrap(io, ...) {|gz| ... }

Creates a GzipReader or GzipWriter associated with io, passing in any necessary extra options, and executes the block with the newly created object just like File.open.

The GzipFile object will be closed automatically after executing the block. If you want to keep the associated IO object open, you may call #finish method in the block.

[ GitHub ]

  
# File 'ext/zlib/zlib.c', line 3057

static VALUE
rb_gzfile_s_wrap(int argc, VALUE *argv, VALUE klass)
{
    return gzfile_wrap(argc, argv, klass, 0);
}

Instance Attribute Details

#closed?Boolean (readonly)

Same as IO#closed?

[ GitHub ]

  
# File 'ext/zlib/zlib.c', line 3321

static VALUE
rb_gzfile_closed_p(VALUE obj)
{
    struct gzfile *gz;
    TypedData_Get_Struct(obj, struct gzfile, &gzfile_data_type, gz);
    return NIL_P(gz->io) ? Qtrue : Qfalse;
}

#sync (rw)

Same as IO#sync

[ GitHub ]

  
# File 'ext/zlib/zlib.c', line 3347

static VALUE
rb_gzfile_sync(VALUE obj)
{
    return (get_gzfile(obj)->z.flags & GZFILE_FLAG_SYNC) ? Qtrue : Qfalse;
}

#sync=(flag) (rw)

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.

[ GitHub ]

  
# File 'ext/zlib/zlib.c', line 3362

static VALUE
rb_gzfile_set_sync(VALUE obj, VALUE 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;
}

Instance Method Details

#close

Closes the GzipFile object. This method calls close method of the associated IO object. Returns the associated IO object.

[ GitHub ]

  
# File 'ext/zlib/zlib.c', line 3282

static VALUE
rb_gzfile_close(VALUE obj)
{
    struct gzfile *gz;
    VALUE io;

    TypedData_Get_Struct(obj, struct gzfile, &gzfile_data_type, gz);
    if (!ZSTREAM_IS_READY(&gz->z)) {
        return Qnil;
    }
    io = gz->io;
    gzfile_close(gz, 1);
    return io;
}

#comment

Returns comments recorded in the gzip file header, or nil if the comments is not present.

[ GitHub ]

  
# File 'ext/zlib/zlib.c', line 3158

static VALUE
rb_gzfile_comment(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

Returns CRC value of the uncompressed data.

[ GitHub ]

  
# File 'ext/zlib/zlib.c', line 3096

static VALUE
rb_gzfile_crc(VALUE obj)
{
    return rb_uint2inum(get_gzfile(obj)->crc);
}

#finish

Closes the GzipFile object. Unlike #close, this method never calls the close method of the associated IO object. Returns the associated IO object.

[ GitHub ]

  
# File 'ext/zlib/zlib.c', line 3304

static VALUE
rb_gzfile_finish(VALUE obj)
{
    struct gzfile *gz = get_gzfile(obj);
    VALUE io;

    io = gz->io;
    gzfile_close(gz, 0);
    return io;
}

#level

Returns compression level.

[ GitHub ]

  
# File 'ext/zlib/zlib.c', line 3118

static VALUE
rb_gzfile_level(VALUE obj)
{
    return INT2FIX(get_gzfile(obj)->level);
}

#mtime

Returns last modification time recorded in the gzip file header.

[ GitHub ]

  
# File 'ext/zlib/zlib.c', line 3107

static VALUE
rb_gzfile_mtime(VALUE obj)
{
    return rb_time_new(get_gzfile(obj)->mtime, (time_t)0);
}

#orig_name

Returns original filename recorded in the gzip file header, or nil if original filename is not present.

[ GitHub ]

  
# File 'ext/zlib/zlib.c', line 3141

static VALUE
rb_gzfile_orig_name(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

Returns OS code number recorded in the gzip file header.

[ GitHub ]

  
# File 'ext/zlib/zlib.c', line 3129

static VALUE
rb_gzfile_os_code(VALUE obj)
{
    return INT2FIX(get_gzfile(obj)->os_code);
}

#to_io

Same as IO.

[ GitHub ]

  
# File 'ext/zlib/zlib.c', line 3085

static VALUE
rb_gzfile_to_io(VALUE obj)
{
    return get_gzfile(obj)->io;
}