Zlib::GzipReader is the class for reading a gzipped file. GzipReader should be used as an IO, or -IO-like, object.

Zlib::GzipReader.open('hoge.gz') {|gz|
  print gz.read
}

File.open('hoge.gz') do |f|
  gz = Zlib::GzipReader.new(f)
  print gz.read
  gz.close
end

Method Catalogue

The following methods in Zlib::GzipReader are just like their counterparts in IO, but they raise Zlib::Error or Zlib::GzipFile::Error exception if an error was found in the gzip file.

Be careful of the footer of the gzip file. A gzip file has the checksum of pre-compressed data in its footer. GzipReader checks all uncompressed data against that checksum at the following cases, and if it fails, raises Zlib::GzipFile::NoFooter, Zlib::GzipFile::CRCError, or Zlib::GzipFile::LengthError exception.

The rest of the methods are adequately described in their own documentation.

Class Methods

Creates a GzipReader object associated with io. The GzipReader object reads gzipped data from io, and parses/decompresses it. The io must have a read method that behaves same as the IO#read.

The options hash may be used to set the encoding of the data. :external_encoding, :internal_encoding and :encoding may be set as in IO::new.

If the gzip file header is incorrect, raises an Zlib::GzipFile::Error exception.

Opens a file specified by filename as a gzipped file, and returns a GzipReader object associated with that file. Further details of this method are in Zlib::GzipReader.new and ZLib::GzipFile.wrap.

Decompresses all gzip data in the io, handling multiple gzip streams until the end of the io. There should not be any non-gzip data after the gzip streams.

If a block is given, it is yielded strings of uncompressed data, and the method returns nil. If a block is not given, the method returns the concatenation of all uncompressed data in all gzip streams.

Instance Methods

See Zlib::GzipReader documentation for a description.

See Zlib::GzipReader documentation for a description.

See Zlib::GzipReader documentation for a description.

An alias for each

Returns true or false whether the stream has reached the end.

An alias for eof

See Zlib::GzipReader documentation for a description.

See Zlib::GzipReader documentation for a description.

See Zlib::GzipReader documentation for a description.

See Zlib::GzipReader documentation for a description. However, note that this method can return nil even if eof? returns false, unlike the behavior of File#gets.

The line number of the last row read from this file.

Specify line number of the last row read from this file.

Total number of output bytes output so far.

See Zlib::GzipReader documentation for a description.

See Zlib::GzipReader documentation for a description.

See Zlib::GzipReader documentation for a description.

See Zlib::GzipReader documentation for a description.

See Zlib::GzipReader documentation for a description.

Reads at most maxlen bytes from the gziped stream but it blocks only if gzipreader has no data immediately available. If the optional outbuf argument is present, it must reference a String, which will receive the data. It raises EOFError on end of file.

Resets the position of the file pointer to the point created the GzipReader object. The associated IO object needs to respond to the seek method.

An alias for pos

See Zlib::GzipReader documentation for a description.

See Zlib::GzipReader documentation for a description.

Returns the rest of the data which had read for parsing gzip format, or nil if the whole gzip file is not parsed yet.