class Zlib::GzipReader
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. * each * each_line * each_byte * gets * getc * lineno * lineno= * read * readchar * readline * readlines * ungetc
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.
-
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
Zlib::GzipFile#closemethod is called after the object reaches the end of file. -
When
Zlib::GzipReader#unusedmethod is called after the object reaches the end of file.
The rest of the methods are adequately described in their own documentation.
Public Class Methods
(_Reader io, **untyped opts) → void
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/zlib/0/gzip_reader.rbs, line 291
def initialize: (_Reader io, **untyped opts) -> void
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.
(path filename) → instance
(path filename) { (instance gz) → void } → void
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/zlib/0/gzip_reader.rbs, line 65
def self.open: (path filename) -> instance
| (path filename) { (instance gz) -> void } -> void
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.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/zlib/0/gzip_reader.rbs, line 54
def self.wrap: (IO io) -> instance
| (IO io) { (instance gz) -> void } -> void
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/zlib/0/gzip_reader.rbs, line 81
def self.zcat: (IO io, **untyped) -> String
| (IO io, **untyped) { (String chunk) -> void } -> nil
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.
Public Instance Methods
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/zlib/0/gzip_reader.rbs, line 90
def each: (*untyped) { (String) -> void } -> void
See Zlib::GzipReader documentation for a description.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/zlib/0/gzip_reader.rbs, line 98
def each_byte: () { (String) -> void } -> void
See Zlib::GzipReader documentation for a description.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/zlib/0/gzip_reader.rbs, line 106
def each_char: () { (String) -> void } -> void
See Zlib::GzipReader documentation for a description.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/zlib/0/gzip_reader.rbs, line 111
def each_line: (*untyped) { (String) -> void } -> void
See Zlib::GzipReader documentation for a description.
() → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/zlib/0/gzip_reader.rbs, line 119
def eof: () -> bool
Returns true or false whether the stream has reached the end.
() → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/zlib/0/gzip_reader.rbs, line 124
def eof?: () -> bool
Returns true or false whether the stream has reached the end.
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/zlib/0/gzip_reader.rbs, line 132
def external_encoding: () -> Encoding
See Zlib::GzipReader documentation for a description.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/zlib/0/gzip_reader.rbs, line 140
def getbyte: () -> Integer?
See Zlib::GzipReader documentation for a description.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/zlib/0/gzip_reader.rbs, line 148
def getc: () -> String?
See Zlib::GzipReader documentation for a description.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/zlib/0/gzip_reader.rbs, line 158
def gets: (?String sep, ?Integer limit) -> String?
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.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/zlib/0/gzip_reader.rbs, line 166
def lineno: () -> Integer
The line number of the last row read from this file.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/zlib/0/gzip_reader.rbs, line 174
def lineno=: (Integer arg0) -> Integer
Specify line number of the last row read from this file.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/zlib/0/gzip_reader.rbs, line 182
def pos: () -> Integer
Total number of output bytes output so far.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/zlib/0/gzip_reader.rbs, line 190
def read: (?int? length, ?string outbuf) -> String?
See Zlib::GzipReader documentation for a description.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/zlib/0/gzip_reader.rbs, line 198
def readbyte: () -> Integer
See Zlib::GzipReader documentation for a description.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/zlib/0/gzip_reader.rbs, line 206
def readchar: () -> String
See Zlib::GzipReader documentation for a description.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/zlib/0/gzip_reader.rbs, line 214
def readline: (?String sep, ?Integer limit) -> String
See Zlib::GzipReader documentation for a description.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/zlib/0/gzip_reader.rbs, line 222
def readlines: (?String sep, ?Integer limit) -> ::Array[String]
See Zlib::GzipReader documentation for a description.
(int maxlen, ?string outbuf) → String
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/zlib/0/gzip_reader.rbs, line 233
def readpartial: (int maxlen, ?string outbuf) -> String
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/zlib/0/gzip_reader.rbs, line 242
def rewind: () -> Integer
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.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/zlib/0/gzip_reader.rbs, line 247
def tell: () -> Integer
Total number of output bytes output so far.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/zlib/0/gzip_reader.rbs, line 255
def ungetbyte: (String | Integer arg0) -> NilClass
See Zlib::GzipReader documentation for a description.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/zlib/0/gzip_reader.rbs, line 263
def ungetc: (String arg0) -> NilClass
See Zlib::GzipReader documentation for a description.