Class: Zlib::GzipReader

Inherits:
GzipFile show all
Includes:
Enumerable
Defined in:
ext/rubysl/zlib/zlib.c,
ext/rubysl/zlib/zlib.c

Overview

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.

  • #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#close method is called after the object reaches the end of file.

  • When Zlib::GzipReader#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 collapse

Instance Method Summary collapse

Methods inherited from GzipFile

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

Constructor Details

#Zlib::GzipReader.new(io) ⇒ Object

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.



2929
2930
2931
# File 'ext/rubysl/zlib/zlib.c', line 2929

static VALUE
rb_gzreader_initialize(obj, io)
VALUE obj, io;

Class Method Details

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

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.

Yields:

  • (gz)


2910
2911
2912
# File 'ext/rubysl/zlib/zlib.c', line 2910

static VALUE
rb_gzreader_s_open(argc, argv, klass)
int argc;

Instance Method Details

#eachObject

See Zlib::GzipReader documentation for a description.



3220
3221
3222
# File 'ext/rubysl/zlib/zlib.c', line 3220

static VALUE
rb_gzreader_each(argc, argv, obj)
int argc;

#each_byteObject

See Zlib::GzipReader documentation for a description.



3036
3037
3038
# File 'ext/rubysl/zlib/zlib.c', line 3036

static VALUE
rb_gzreader_each_byte(obj)
VALUE obj;

#each_lineObject

See Zlib::GzipReader documentation for a description.



3220
3221
3222
# File 'ext/rubysl/zlib/zlib.c', line 3220

static VALUE
rb_gzreader_each(argc, argv, obj)
int argc;

#eofObject

???



2606
2607
2608
# File 'ext/rubysl/zlib/zlib.c', line 2606

static VALUE
rb_gzfile_eof_p(obj)
VALUE obj;

#eof?Boolean

???

Returns:

  • (Boolean)


2606
2607
2608
# File 'ext/rubysl/zlib/zlib.c', line 2606

static VALUE
rb_gzfile_eof_p(obj)
VALUE obj;

#getcObject

See Zlib::GzipReader documentation for a description.



3004
3005
3006
# File 'ext/rubysl/zlib/zlib.c', line 3004

static VALUE
rb_gzreader_getc(obj)
VALUE obj;

#getsObject

See Zlib::GzipReader documentation for a description.



3186
3187
3188
# File 'ext/rubysl/zlib/zlib.c', line 3186

static VALUE
rb_gzreader_gets(argc, argv, obj)
int argc;

#linenoObject

???



2469
2470
2471
# File 'ext/rubysl/zlib/zlib.c', line 2469

static VALUE
rb_gzfile_lineno(obj)
VALUE obj;

#lineno=Object

???



2479
2480
2481
# File 'ext/rubysl/zlib/zlib.c', line 2479

static VALUE
rb_gzfile_set_lineno(obj, lineno)
VALUE obj, lineno;

#posObject

???



2659
2660
2661
# File 'ext/rubysl/zlib/zlib.c', line 2659

static VALUE
rb_gzfile_total_out(obj)
VALUE obj;

#readObject

See Zlib::GzipReader documentation for a description.



2979
2980
2981
# File 'ext/rubysl/zlib/zlib.c', line 2979

static VALUE
rb_gzreader_read(argc, argv, obj)
int argc;

#readcharObject

See Zlib::GzipReader documentation for a description.



3021
3022
3023
# File 'ext/rubysl/zlib/zlib.c', line 3021

static VALUE
rb_gzreader_readchar(obj)
VALUE obj;

#readlineObject

See Zlib::GzipReader documentation for a description.



3203
3204
3205
# File 'ext/rubysl/zlib/zlib.c', line 3203

static VALUE
rb_gzreader_readline(argc, argv, obj)
int argc;

#readlinesObject

See Zlib::GzipReader documentation for a description.



3236
3237
3238
# File 'ext/rubysl/zlib/zlib.c', line 3236

static VALUE
rb_gzreader_readlines(argc, argv, obj)
int argc;

#rewindObject

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.



2954
2955
2956
# File 'ext/rubysl/zlib/zlib.c', line 2954

static VALUE
rb_gzreader_rewind(obj)
VALUE obj;

#tellObject

???



2659
2660
2661
# File 'ext/rubysl/zlib/zlib.c', line 2659

static VALUE
rb_gzfile_total_out(obj)
VALUE obj;

#ungetcObject

See Zlib::GzipReader documentation for a description.



3050
3051
3052
# File 'ext/rubysl/zlib/zlib.c', line 3050

static VALUE
rb_gzreader_ungetc(obj, ch)
VALUE obj, ch;

#unusedObject

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



2967
2968
2969
# File 'ext/rubysl/zlib/zlib.c', line 2967

static VALUE
rb_gzreader_unused(obj)
VALUE obj;