Class: Zlib::GzipReader
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
GzipFile
|
|
Instance Chain:
self,
Enumerable,
GzipFile
|
|
Inherits: |
Zlib::GzipFile
|
Defined in: | ext/zlib/zlib.c, ext/zlib/zlib.c |
Overview
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 GzipReader
are just like their counterparts in IO, but they raise Error or 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 GzipFile::NoFooter, GzipFile::CRCError, or GzipFile::LengthError exception.
-
When an reading request is received beyond the end of file (the end of compressed data). That is, when Zlib::GzipReader#read, Zlib::GzipReader#gets, or some other methods for reading returns nil.
-
When GzipFile#close method is called after the object reaches the end of file.
-
When #unused method is called after the object reaches the end of file.
The rest of the methods are adequately described in their own documentation.
Class Method Summary
-
.new(io, options = {})
constructor
Creates a
GzipReader
object associated withio
. -
.open(filename) {|gz| ... }
Opens a file specified by
filename
as a gzipped file, and returns aGzipReader
object associated with that file.
GzipFile - Inherited
.wrap | Creates a |
Instance Attribute Summary
-
#lineno
rw
The line number of the last row read from this file.
-
#lineno=(lineno)
rw
Specify line number of the last row read from this file.
-
#eof
(also: #eof?)
readonly
Returns
true
orfalse
whether the stream has reached the end. -
#eof?
readonly
Alias for #eof.
GzipFile - Inherited
Instance Method Summary
-
#bytes
This is a deprecated alias for #each_byte.
-
#each(*args)
(also: #each_line)
See
GzipReader
documentation for a description. -
#each_byte
See
GzipReader
documentation for a description. -
#each_char
See
GzipReader
documentation for a description. -
#each_line(*args)
Alias for #each.
-
#external_encoding
See
GzipReader
documentation for a description. -
#getbyte
See
GzipReader
documentation for a description. -
#getc
See
GzipReader
documentation for a description. -
#gets(*args)
See
GzipReader
documentation for a description. -
#lines(*args)
This is a deprecated alias for #each_line.
-
#pos
(also: #tell)
Total number of output bytes output so far.
-
#read(*args)
See
GzipReader
documentation for a description. -
#readbyte
See
GzipReader
documentation for a description. -
#readchar
See
GzipReader
documentation for a description. -
#readline(*args)
See
GzipReader
documentation for a description. -
#readlines(*args)
See
GzipReader
documentation for a description. -
#readpartial(maxlen [, outbuf]) ⇒ String, outbuf
Reads at most maxlen bytes from the gziped stream but it blocks only if gzipreader has no data immediately available.
-
#rewind
Resets the position of the file pointer to the point created the
GzipReader
object. -
#tell
Alias for #pos.
-
#ungetbyte(ch)
See
GzipReader
documentation for a description. -
#ungetc(s)
See
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.
GzipFile - Inherited
#close | Closes the GzipFile object. |
#comment | Returns comments recorded in the gzip file header, or nil if the comments is not present. |
#crc | Returns CRC value of the uncompressed data. |
#finish | Closes the GzipFile object. |
#level | Returns compression level. |
#mtime | Returns last modification time recorded in the gzip file header. |
#orig_name | Returns original filename recorded in the gzip file header, or |
#os_code | Returns OS code number recorded in the gzip file header. |
#to_io | Same as IO. |
Constructor Details
.new(io, options = {})
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 GzipFile::Error exception.
Class Method Details
.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 .new and ZLib::GzipFile.wrap
.
Instance Attribute Details
#eof (readonly) Also known as: #eof?
Returns true
or false
whether the stream has reached the end.
#eof? (readonly)
Alias for #eof.
#lineno (rw)
The line number of the last row read from this file.
#lineno=(lineno) (rw)
Specify line number of the last row read from this file.
Instance Method Details
#bytes
This is a deprecated alias for #each_byte.
#each(*args) Also known as: #each_line
See GzipReader
documentation for a description.
#each_byte
See GzipReader
documentation for a description.
#each_char
See GzipReader
documentation for a description.
#each_line(*args)
Alias for #each.
#external_encoding
See GzipReader
documentation for a description.
#getbyte
See GzipReader
documentation for a description.
#getc
See GzipReader
documentation for a description.
#gets(*args)
See GzipReader
documentation for a description.
#lines(*args)
This is a deprecated alias for #each_line.
#pos Also known as: #tell
Total number of output bytes output so far.
#read(*args)
See GzipReader
documentation for a description.
#readbyte
See GzipReader
documentation for a description.
#readchar
See GzipReader
documentation for a description.
#readline(*args)
See GzipReader
documentation for a description.
#readlines(*args)
See GzipReader
documentation for a description.
#readpartial(maxlen [, outbuf]) ⇒ String
, outbuf
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.
#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
Alias for #pos.
#ungetbyte(ch)
See GzipReader
documentation for a description.
#ungetc(s)
See 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.