Class: Zlib::GzipFile (Ruby 2.2.4)
Description: Class : Zlib::GzipFile - Ruby 2.2.4

- Home
- Core 2.2.4
- Std-lib 2.2.4
- Downloads

Support for the Ruby 2.2 series has ended. See here for reference.

### Home Classes Methods

### In Files

- zlib/zlib.c

### Parent

Object

### Namespace

- CLASS Zlib::GzipFile::CRCError
- CLASS Zlib::GzipFile::Error
- CLASS Zlib::GzipFile::LengthError
- CLASS Zlib::GzipFile::NoFooter

### Methods

- ::wrap
- #close
- #closed?
- #comment
- #crc
- #finish
- #level
- #mtime
- #orig_name
- #os_code
- #sync
- #sync=
- #to_io

### Class/Module Index

Quicksearch

- Zlib
- Zlib::BufError
- Zlib::DataError
- Zlib::Deflate
- Zlib::Error
- Zlib::GzipFile
- Zlib::GzipFile::CRCError
- Zlib::GzipFile::Error
- Zlib::GzipFile::LengthError
- Zlib::GzipFile::NoFooter
- Zlib::GzipReader
- Zlib::GzipWriter
- Zlib::Inflate
- Zlib::MemError
- Zlib::NeedDict
- Zlib::StreamEnd
- Zlib::StreamError
- Zlib::VersionError
- Zlib::ZStream
- unknown

No matching classes.

# 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, 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)

### Public Class Methods

Zlib::GzipReader.wrap(io, ...) { |gz| ... } click to toggle source
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.

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

### Public Instance Methods

close() click to toggle source

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

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

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

closed?() click to toggle source

Same as IO#closed?

                   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() click to toggle source

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

                   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() click to toggle source

Returns CRC value of the uncompressed data.

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

finish() click to toggle source

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

                   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() click to toggle source

Returns compression level.

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

mtime() click to toggle source

Returns last modification time recorded in the gzip file header.

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

orig_name() click to toggle source

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

                   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() click to toggle source

Returns OS code number recorded in the gzip file header.

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

sync() click to toggle source

Same as IO#sync

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

sync = flag click to toggle source

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(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() click to toggle source

Same as IO.

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