Class: MultiGzReader
- Inherits:
-
Object
- Object
- MultiGzReader
- Defined in:
- lib/scbi_multi_gz_reader/multi_gz_reader.rb
Instance Method Summary collapse
- #close ⇒ Object
- #eof? ⇒ Boolean
-
#initialize(file_name) ⇒ MultiGzReader
constructor
A new instance of MultiGzReader.
- #readline ⇒ Object
Constructor Details
#initialize(file_name) ⇒ MultiGzReader
Returns a new instance of MultiGzReader.
5 6 7 8 |
# File 'lib/scbi_multi_gz_reader/multi_gz_reader.rb', line 5 def initialize(file_name) @file = File.open(file_name) @io = Zlib::GzipReader.new @file end |
Instance Method Details
#close ⇒ Object
46 47 48 49 |
# File 'lib/scbi_multi_gz_reader/multi_gz_reader.rb', line 46 def close #@io.finish @file.close end |
#eof? ⇒ Boolean
41 42 43 44 |
# File 'lib/scbi_multi_gz_reader/multi_gz_reader.rb', line 41 def eof? #nothing more to read @io.unused.nil? && (@io.closed? || @io.eof?) && (@file.closed? || @file.eof?) end |
#readline ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/scbi_multi_gz_reader/multi_gz_reader.rb', line 10 def readline res=nil begin res=@io.readline rescue EOFError => e #reached END, check if there is more data to read unused = @io.unused @io.finish # there is something left to read, open another stream if !unused.nil? #puts "FIN1, fpos: #{@file.pos}, unused: #{unused.length}, io_eof: #{@io.eof}, eof: #{@file.eof}" @file.pos -= unused.length @io = Zlib::GzipReader.new @file #repeat the read so there is no eof error res=readline else #no more data to read, return nil res=nil end end return res end |