class Zlib::GzipFile
Zlib::GzipFile is an abstract class for handling a gzip formatted compressed file. The operations are defined in the subclasses,Zlib::GzipReader for reading, andZlib::GzipWriter for writing.
GzipReader should be used by associating anIO, or IO-like, object.
Method Catalogue¶↑
::open (
Zlib::GzipReader::openandZlib::GzipWriter::open)comment= (
Zlib::GzipWriter#comment=)eof? (
Zlib::GzipReader#eof?)lineno (
Zlib::GzipReader#lineno)lineno= (
Zlib::GzipReader#lineno=)mtime= (
Zlib::GzipWriter#mtime=)path (when the underlying
IOsupports path)
(due to internal structure, documentation may appear underZlib::GzipReader orZlib::GzipWriter)
Public Class Methods
Source
static VALUErb_gzfile_s_wrap(int argc, VALUE *argv, VALUE klass){ return gzfile_wrap(argc, argv, klass, 0);}Creates aGzipReader orGzipWriter associated withio, passing in any necessary extra options, and executes the block with the newly created object just likeFile.open.
TheGzipFile object will be closed automatically after executing the block. If you want to keep the associatedIO object open, you may callZlib::GzipFile#finish method in the block.
Public Instance Methods
Source
static VALUErb_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;}Closes theGzipFile object. This method calls close method of the associatedIO object. Returns the associatedIO object.
Source
static VALUErb_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;}Same asIO#closed?
Source
static VALUErb_gzfile_comment(VALUE obj){ VALUE str = get_gzfile(obj)->comment; if (!NIL_P(str)) { str = rb_str_dup(str); } return str;}Returns comments recorded in the gzip file header, or nil if the comments is not present.
Source
static VALUErb_gzfile_crc(VALUE obj){ return rb_uint2inum(get_gzfile(obj)->crc);}Returns CRC value of the uncompressed data.
Source
static VALUErb_gzfile_finish(VALUE obj){ struct gzfile *gz = get_gzfile(obj); VALUE io; io = gz->io; gzfile_close(gz, 0); return io;}Closes theGzipFile object. UnlikeZlib::GzipFile#close, this method never calls the close method of the associatedIO object. Returns the associatedIO object.
Source
static VALUErb_gzfile_level(VALUE obj){ return INT2FIX(get_gzfile(obj)->level);}Returns compression level.
Source
static VALUErb_gzfile_mtime(VALUE obj){ return rb_time_new(get_gzfile(obj)->mtime, (time_t)0);}Returns last modification time recorded in the gzip file header.
Source
static VALUErb_gzfile_orig_name(VALUE obj){ VALUE str = get_gzfile(obj)->orig_name; if (!NIL_P(str)) { str = rb_str_dup(str); } return str;}Returns original filename recorded in the gzip file header, ornil if original filename is not present.
Source
static VALUErb_gzfile_os_code(VALUE obj){ return INT2FIX(get_gzfile(obj)->os_code);}Returns OS code number recorded in the gzip file header.
Source
static VALUErb_gzfile_sync(VALUE obj){ return (get_gzfile(obj)->z.flags & GZFILE_FLAG_SYNC) ? Qtrue : Qfalse;}Same asIO#sync
Source
static VALUErb_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;}Same asIO. If flag istrue, the associatedIO object must respond to theflush method. Whilesync mode istrue, the compression ratio decreases sharply.