Class

Zlib::GzipReader

Inheritance
< Zlib::GzipFile < Object
Included Modules
Enumerable

Zlib::GzipReader is the class for reading a gzipped file. GzipReader should be used an IO, or -IO-lie, 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

  # TODO: test these.  Are they equivalent?  Can GzipReader.new take a
  # block?

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.

Methods

Class

Visibility Signature
public new (p1)
public open (...)

Instance

Visibility Signature
public each (...)
public each_byte ()
public each_line (...)
public eof ()
public eof? ()
public getc ()
public gets (...)
public lineno ()
public lineno= (p1)
public pos ()
public read (...)
public readchar ()
public readline (...)
public readlines (...)
public rewind ()
public tell ()
public ungetc (p1)
public unused ()

Class Method Detail

Zlib::GzipReader.new(io)

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

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

Zlib::GzipReader.open(filename) {|gz| ... }

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::GzipReader.wrap.

Instance Method Detail

each(...)

See Zlib::GzipReader documentation for a description.

each_byte()

See Zlib::GzipReader documentation for a description.

each_line(...)

See Zlib::GzipReader documentation for a description.

eof()

???

eof?()

???

getc()

See Zlib::GzipReader documentation for a description.

gets(...)

See Zlib::GzipReader documentation for a description.

lineno()

???

lineno=(p1)

???

pos()

???

read(...)

See Zlib::GzipReader documentation for a description.

readchar()

See Zlib::GzipReader documentation for a description.

readline(...)

See Zlib::GzipReader documentation for a description.

readlines(...)

See Zlib::GzipReader documentation for a description.

rewind()

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.

tell()

???

ungetc(p1)

See Zlib::GzipReader documentation for a description.

unused()

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