Class: Zlib::GzipReader

Inherits:
GzipFile show all
Includes:
Enumerable
Defined in:
lib/pr/zlib.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.



1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
# File 'lib/pr/zlib.rb', line 1218

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()
  gzfile_read_header()
  self
end

Class Method Details

.open(filename, level = Z_DEFAULT_COMPRESSION, strategy = Z_DEFAULT_STRATEGY, &blk) ⇒ Object



1214
1215
1216
# File 'lib/pr/zlib.rb', line 1214

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



1287
1288
1289
1290
1291
1292
# File 'lib/pr/zlib.rb', line 1287

def each(rs=$/)
  while (str = gzreader_gets(rs))
    yield(str)
  end
  self
end

#each_byteObject



1265
1266
1267
1268
1269
1270
# File 'lib/pr/zlib.rb', line 1265

def each_byte()
  while (c = getc)
    yield(c)
  end
  nil
end

#eofObject Also known as: eof?

Raises:



1199
1200
1201
1202
# File 'lib/pr/zlib.rb', line 1199

def eof
  raise GzipFile::Error,"closed gzip stream" unless @gz.z.ZSTREAM_IS_READY()
  GZFILE_IS_FINISHED(@gz)
end

#getcObject



1252
1253
1254
1255
# File 'lib/pr/zlib.rb', line 1252

def getc()
  dst = gzfile_read(1)
  dst ? dst[0] : dst
end

#gets(rs = $/) ⇒ Object



1277
1278
1279
1280
1281
# File 'lib/pr/zlib.rb', line 1277

def gets(rs=$/)
  dst = gzreader_gets(rs)
  $_ = dst if dst
  dst
end

#linenoObject

Raises:



1189
1190
1191
1192
# File 'lib/pr/zlib.rb', line 1189

def lineno
  raise GzipFile::Error, "closed gzip stream" unless @gz.z.ZSTREAM_IS_READY()
  @gz.lineno
end

#lineno=(lineno) ⇒ Object

Raises:



1194
1195
1196
1197
# File 'lib/pr/zlib.rb', line 1194

def lineno=(lineno)
  raise GzipFile::Error, "closed gzip stream" unless @gz.z.ZSTREAM_IS_READY()
  @gz.lineno = lineno
end

#posObject Also known as: tell



1205
1206
1207
1208
1209
1210
1211
# File 'lib/pr/zlib.rb', line 1205

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



1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
# File 'lib/pr/zlib.rb', line 1240

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

#readcharObject



1257
1258
1259
1260
1261
1262
1263
# File 'lib/pr/zlib.rb', line 1257

def readchar()
  dst = getc()
  if dst.nil?
    raise EOFError, "end of file reached"
  end
  dst
end

#readline(rs = $/) ⇒ Object



1283
1284
1285
# File 'lib/pr/zlib.rb', line 1283

def readline(rs=$/)
  dst = gets(rs)
end

#readlines(rs = $/) ⇒ Object



1295
1296
1297
1298
1299
1300
1301
# File 'lib/pr/zlib.rb', line 1295

def readlines(rs=$/)
  dst = []
  while str = gzreader_gets(rs)
    dst.push(str)
  end
  dst
end

#rewindObject



1231
1232
1233
1234
# File 'lib/pr/zlib.rb', line 1231

def rewind()
  gzfile_reader_rewind()
  return 0
end

#ungetc(ch) ⇒ Object



1272
1273
1274
1275
# File 'lib/pr/zlib.rb', line 1272

def ungetc(ch)
  gzfile_ungetc(ch)
  nil
end

#unusedObject



1236
1237
1238
# File 'lib/pr/zlib.rb', line 1236

def unused()
  gzfile_reader_get_unused()
end