Class: MultiGzReader

Inherits:
Object
  • Object
show all
Defined in:
lib/scbi_multi_gz_reader/multi_gz_reader.rb

Instance Method Summary collapse

Constructor Details

#initialize(file_name) ⇒ MultiGzReader

Returns a new instance of MultiGzReader.



5
6
7
8
9
10
# File 'lib/scbi_multi_gz_reader/multi_gz_reader.rb', line 5

def initialize(file_name)
	@file_name=file_name

	@file = File.open(@file_name)
	@io = Zlib::GzipReader.new @file
end

Instance Method Details

#closeObject



52
53
54
55
# File 'lib/scbi_multi_gz_reader/multi_gz_reader.rb', line 52

def close
	#@io.finish
	@file.close
end

#eofObject



48
49
50
# File 'lib/scbi_multi_gz_reader/multi_gz_reader.rb', line 48

def eof
	eof?
end

#eof?Boolean

Returns:

  • (Boolean)


43
44
45
46
# File 'lib/scbi_multi_gz_reader/multi_gz_reader.rb', line 43

def eof?
	#nothing more to read
	@io.unused.nil? && (@io.closed? || @io.eof?) && (@file.closed? || @file.eof?)
end

#readlineObject



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
40
41
# File 'lib/scbi_multi_gz_reader/multi_gz_reader.rb', line 12

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

#rewindObject



57
58
59
60
61
# File 'lib/scbi_multi_gz_reader/multi_gz_reader.rb', line 57

def rewind
	close
	@file = File.open(@file_name)
	@io = Zlib::GzipReader.new @file
end