Class: Zlib::GzipReader
- Inherits:
-
GzipFile
show all
- Includes:
- Enumerable
- Defined in:
- lib/pr/zlib/gzipreader.rb
Constant Summary
Constants inherited
from GzipFile
Zlib::GzipFile::GZFILE_FLAG_FOOTER_FINISHED, Zlib::GzipFile::GZFILE_FLAG_HEADER_FINISHED, Zlib::GzipFile::GZFILE_FLAG_SYNC, Zlib::GzipFile::GZFILE_READ_SIZE, Zlib::GzipFile::GZ_EXTRAFLAG_FAST, Zlib::GzipFile::GZ_EXTRAFLAG_SLOW, Zlib::GzipFile::GZ_FLAG_COMMENT, Zlib::GzipFile::GZ_FLAG_ENCRYPT, Zlib::GzipFile::GZ_FLAG_EXTRA, Zlib::GzipFile::GZ_FLAG_MULTIPART, Zlib::GzipFile::GZ_FLAG_ORIG_NAME, Zlib::GzipFile::GZ_FLAG_UNKNOWN_MASK, Zlib::GzipFile::GZ_MAGIC1, Zlib::GzipFile::GZ_MAGIC2, Zlib::GzipFile::GZ_METHOD_DEFLATE, Zlib::GzipFile::OS_CODE
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from GzipFile
#GZFILE_IS_FINISHED, #close, #closed?, #comment, #crc, #finish, #gzfile_close, #gzfile_ensure_close, gzfile_s_open, #level, #mtime, #orig_name, #os_code, #sync, #sync=, #to_io, wrap
Constructor Details
#initialize(io, level = Z_DEFAULT_COMPRESSION, _strategy = Z_DEFAULT_STRATEGY) ⇒ GzipReader
Returns a new instance of GzipReader.
Class Method Details
.open(filename, level = Z_DEFAULT_COMPRESSION, strategy = Z_DEFAULT_STRATEGY, &blk) ⇒ Object
Instance Method Details
#each(rs = $/) ⇒ Object
Also known as:
each_line
105
106
107
108
109
110
|
# File 'lib/pr/zlib/gzipreader.rb', line 105
def each(rs = $/)
while (str = gzreader_gets(rs))
yield(str)
end
self
end
|
#each_byte ⇒ Object
85
86
87
88
89
90
|
# File 'lib/pr/zlib/gzipreader.rb', line 85
def each_byte
while (c = getc)
yield(c)
end
nil
end
|
#eof ⇒ Object
Also known as:
eof?
19
20
21
22
|
# File 'lib/pr/zlib/gzipreader.rb', line 19
def eof
raise GzipFile::Error, 'closed gzip stream' unless @gz.z.ZSTREAM_IS_READY()
GZFILE_IS_FINISHED(@gz)
end
|
#getc ⇒ Object
72
73
74
75
|
# File 'lib/pr/zlib/gzipreader.rb', line 72
def getc
dst = gzfile_read(1)
dst ? dst[0] : dst
end
|
#gets(rs = $/) ⇒ Object
97
98
99
|
# File 'lib/pr/zlib/gzipreader.rb', line 97
def gets(rs = $/)
gzreader_gets(rs)
end
|
#lineno ⇒ Object
9
10
11
12
|
# File 'lib/pr/zlib/gzipreader.rb', line 9
def lineno
raise GzipFile::Error, 'closed gzip stream' unless @gz.z.ZSTREAM_IS_READY()
@gz.lineno
end
|
#lineno=(lineno) ⇒ Object
14
15
16
17
|
# File 'lib/pr/zlib/gzipreader.rb', line 14
def lineno=(lineno)
raise GzipFile::Error, 'closed gzip stream' unless @gz.z.ZSTREAM_IS_READY()
@gz.lineno = lineno
end
|
#pos ⇒ Object
Also known as:
tell
25
26
27
28
29
30
31
|
# File 'lib/pr/zlib/gzipreader.rb', line 25
def pos
if @gz.z.buf.nil?
@gz.z.stream.total_out
else
@gz.z.stream.total_out - @gz.z.buf.offset
end
end
|
#read(len = nil) ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/pr/zlib/gzipreader.rb', line 60
def read(len = nil)
if len.nil?
return gzfile_read_all()
end
if len < 0
raise ArgumentError, "negative length #{len} given"
end
gzfile_read(len)
end
|
#readchar ⇒ Object
77
78
79
80
81
82
83
|
# File 'lib/pr/zlib/gzipreader.rb', line 77
def readchar
dst = getc()
if dst.nil?
raise EOFError, 'end of file reached'
end
dst
end
|
#readline(rs = $/) ⇒ Object
101
102
103
|
# File 'lib/pr/zlib/gzipreader.rb', line 101
def readline(rs = $/)
gets(rs)
end
|
#readlines(rs = $/) ⇒ Object
113
114
115
116
117
118
119
|
# File 'lib/pr/zlib/gzipreader.rb', line 113
def readlines(rs = $/)
dst = []
while str = gzreader_gets(rs)
dst.push(str)
end
dst
end
|
#rewind ⇒ Object
51
52
53
54
|
# File 'lib/pr/zlib/gzipreader.rb', line 51
def rewind
gzfile_reader_rewind()
0
end
|
#ungetc(ch) ⇒ Object
92
93
94
95
|
# File 'lib/pr/zlib/gzipreader.rb', line 92
def ungetc(ch)
gzfile_ungetc(ch)
nil
end
|
#unused ⇒ Object
56
57
58
|
# File 'lib/pr/zlib/gzipreader.rb', line 56
def unused
gzfile_reader_get_unused()
end
|