Class: Zlib::GzipFile
- Inherits:
-
Object
- Object
- Zlib::GzipFile
- Defined in:
- ext/zlib/zlib.c,
ext/zlib/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.
Method Catalogue
-
::wrap
-
::open (Zlib::GzipReader::open and Zlib::GzipWriter::open)
-
#close
-
#closed?
-
#comment
-
comment= (Zlib::GzipWriter#comment=)
-
#crc
-
eof? (Zlib::GzipReader#eof?)
-
#finish
-
#level
-
lineno (Zlib::GzipReader#lineno)
-
lineno= (Zlib::GzipReader#lineno=)
-
#mtime
-
mtime= (Zlib::GzipWriter#mtime=)
-
#orig_name
-
orig_name (Zlib::GzipWriter#orig_name=)
-
#os_code
-
path (when the underlying IO supports #path)
-
#sync
-
#sync=
-
#to_io
(due to internal structure, documentation may appear under Zlib::GzipReader or Zlib::GzipWriter)
Direct Known Subclasses
Defined Under Namespace
Classes: CRCError, Error, LengthError, NoFooter
Class Method Summary collapse
-
.wrap(*args) ⇒ Object
call-seq: Zlib::GzipReader.wrap(io, …) { |gz| … } Zlib::GzipWriter.wrap(io, …) { |gz| … }.
Instance Method Summary collapse
-
#close ⇒ Object
Closes the GzipFile object.
-
#closed? ⇒ Boolean
Same as IO#closed?.
-
#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
nilif original filename is not present. -
#os_code ⇒ Object
Returns OS code number recorded in the gzip file header.
-
#sync ⇒ Object
Same as IO#sync.
-
#sync=(mode) ⇒ Object
call-seq: sync = flag.
-
#to_io ⇒ Object
Same as IO.
Class Method Details
.wrap(*args) ⇒ Object
call-seq:
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 Zlib::GzipFile#finish method in the block.
3294 3295 3296 3297 3298 |
# File 'ext/zlib/zlib.c', line 3294 static VALUE rb_gzfile_s_wrap(int argc, VALUE *argv, VALUE klass) { return gzfile_wrap(argc, argv, klass, 0); } |
Instance Method Details
#close ⇒ Object
Closes the GzipFile object. This method calls close method of the associated IO object. Returns the associated IO object.
3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 |
# File 'ext/zlib/zlib.c', line 3518 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; } |
#closed? ⇒ Boolean
Same as IO#closed?
3557 3558 3559 3560 3561 3562 3563 |
# File 'ext/zlib/zlib.c', line 3557 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; } |
#comment ⇒ Object
Returns comments recorded in the gzip file header, or nil if the comments is not present.
3394 3395 3396 3397 3398 3399 3400 3401 3402 |
# File 'ext/zlib/zlib.c', line 3394 static VALUE rb_gzfile_comment(VALUE obj) { VALUE str = get_gzfile(obj)->comment; if (!NIL_P(str)) { str = rb_str_dup(str); } return str; } |
#crc ⇒ Object
Returns CRC value of the uncompressed data.
3333 3334 3335 3336 3337 |
# File 'ext/zlib/zlib.c', line 3333 static VALUE rb_gzfile_crc(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.
3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 |
# File 'ext/zlib/zlib.c', line 3540 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 ⇒ Object
Returns compression level.
3355 3356 3357 3358 3359 |
# File 'ext/zlib/zlib.c', line 3355 static VALUE rb_gzfile_level(VALUE obj) { return INT2FIX(get_gzfile(obj)->level); } |
#mtime ⇒ Object
Returns last modification time recorded in the gzip file header.
3344 3345 3346 3347 3348 |
# File 'ext/zlib/zlib.c', line 3344 static VALUE rb_gzfile_mtime(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.
3378 3379 3380 3381 3382 3383 3384 3385 3386 |
# File 'ext/zlib/zlib.c', line 3378 static VALUE rb_gzfile_orig_name(VALUE obj) { VALUE str = get_gzfile(obj)->orig_name; if (!NIL_P(str)) { str = rb_str_dup(str); } return str; } |
#os_code ⇒ Object
Returns OS code number recorded in the gzip file header.
3366 3367 3368 3369 3370 |
# File 'ext/zlib/zlib.c', line 3366 static VALUE rb_gzfile_os_code(VALUE obj) { return INT2FIX(get_gzfile(obj)->os_code); } |
#sync ⇒ Object
Same as IO#sync
3586 3587 3588 3589 3590 |
# File 'ext/zlib/zlib.c', line 3586 static VALUE rb_gzfile_sync(VALUE obj) { return (get_gzfile(obj)->z.flags & GZFILE_FLAG_SYNC) ? Qtrue : Qfalse; } |
#sync=(mode) ⇒ Object
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.
3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 |
# File 'ext/zlib/zlib.c', line 3601 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; } |
#to_io ⇒ Object
Same as IO.
3322 3323 3324 3325 3326 |
# File 'ext/zlib/zlib.c', line 3322 static VALUE rb_gzfile_to_io(VALUE obj) { return get_gzfile(obj)->io; } |