Class: Zlib::GzipReader
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.
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
|
# File 'lib/pr/zlib.rb', line 1225
def initialize(io,level=Z_DEFAULT_COMPRESSION,strategy=Z_DEFAULT_STRATEGY)
gzfile_new(InflateFuncs, :gzfile_reader_end)
@gz.level = level
err = inflateInit2(@gz.z.stream, -MAX_WBITS)
if (err != Z_OK)
raise_zlib_error(err, @gz.stream.msg)
end
@gz.io = io
@gz.z.ZSTREAM_READY()
()
self
end
|
Class Method Details
.open(filename, level = Z_DEFAULT_COMPRESSION, strategy = Z_DEFAULT_STRATEGY, &blk) ⇒ Object
1221
1222
1223
|
# File 'lib/pr/zlib.rb', line 1221
def self.open(filename,level=Z_DEFAULT_COMPRESSION,strategy=Z_DEFAULT_STRATEGY,&blk)
GzipReader.gzfile_s_open(filename,"rb",level=Z_DEFAULT_COMPRESSION,strategy=Z_DEFAULT_STRATEGY,&blk)
end
|
Instance Method Details
#each(rs = $/) ⇒ Object
Also known as:
each_line
1294
1295
1296
1297
1298
1299
|
# File 'lib/pr/zlib.rb', line 1294
def each(rs=$/)
while (str = gzreader_gets(rs))
yield(str)
end
self
end
|
#each_byte ⇒ Object
1272
1273
1274
1275
1276
1277
|
# File 'lib/pr/zlib.rb', line 1272
def each_byte()
while (c = getc)
yield(c)
end
nil
end
|
#eof ⇒ Object
Also known as:
eof?
1206
1207
1208
1209
|
# File 'lib/pr/zlib.rb', line 1206
def eof
raise GzipFile::Error,"closed gzip stream" unless @gz.z.ZSTREAM_IS_READY()
GZFILE_IS_FINISHED(@gz)
end
|
#getc ⇒ Object
1259
1260
1261
1262
|
# File 'lib/pr/zlib.rb', line 1259
def getc()
dst = gzfile_read(1)
dst ? dst[0] : dst
end
|
#gets(rs = $/) ⇒ Object
1284
1285
1286
1287
1288
|
# File 'lib/pr/zlib.rb', line 1284
def gets(rs=$/)
dst = gzreader_gets(rs)
$_ = dst if dst
dst
end
|
#lineno ⇒ Object
1196
1197
1198
1199
|
# File 'lib/pr/zlib.rb', line 1196
def lineno
raise GzipFile::Error, "closed gzip stream" unless @gz.z.ZSTREAM_IS_READY()
@gz.lineno
end
|
#lineno=(lineno) ⇒ Object
1201
1202
1203
1204
|
# File 'lib/pr/zlib.rb', line 1201
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
1212
1213
1214
1215
1216
1217
1218
|
# File 'lib/pr/zlib.rb', line 1212
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
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
|
# File 'lib/pr/zlib.rb', line 1247
def read(len=nil)
if len.nil?
return gzfile_read_all()
end
if len < 0
raise ArgumentError, "negative length #{len} given"
end
return gzfile_read(len)
end
|
#readchar ⇒ Object
1264
1265
1266
1267
1268
1269
1270
|
# File 'lib/pr/zlib.rb', line 1264
def readchar()
dst = getc()
if dst.nil?
raise EOFError, "end of file reached"
end
dst
end
|
#readline(rs = $/) ⇒ Object
1290
1291
1292
|
# File 'lib/pr/zlib.rb', line 1290
def readline(rs=$/)
gets(rs)
end
|
#readlines(rs = $/) ⇒ Object
1302
1303
1304
1305
1306
1307
1308
|
# File 'lib/pr/zlib.rb', line 1302
def readlines(rs=$/)
dst = []
while str = gzreader_gets(rs)
dst.push(str)
end
dst
end
|
#rewind ⇒ Object
1238
1239
1240
1241
|
# File 'lib/pr/zlib.rb', line 1238
def rewind()
gzfile_reader_rewind()
return 0
end
|
#ungetc(ch) ⇒ Object
1279
1280
1281
1282
|
# File 'lib/pr/zlib.rb', line 1279
def ungetc(ch)
gzfile_ungetc(ch)
nil
end
|
#unused ⇒ Object
1243
1244
1245
|
# File 'lib/pr/zlib.rb', line 1243
def unused()
gzfile_reader_get_unused()
end
|