Class: ScbiZcatFile

Inherits:
Object
  • Object
show all
Defined in:
lib/scbi_zcat/scbi_zcat_file.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_name) ⇒ ScbiZcatFile

Returns a new instance of ScbiZcatFile.



10
11
12
13
# File 'lib/scbi_zcat/scbi_zcat_file.rb', line 10

def initialize(file_name)
  @file_name=file_name
  open_file
end

Class Method Details

.gz_file?(file_name) ⇒ Boolean

Returns:

  • (Boolean)


4
5
6
7
8
# File 'lib/scbi_zcat/scbi_zcat_file.rb', line 4

def self.gz_file?(file_name)
  res=`file -L "#{File.expand_path(file_name)}"`

  return !res.index('gzip').nil?
end

Instance Method Details

#closeObject



41
42
43
44
# File 'lib/scbi_zcat/scbi_zcat_file.rb', line 41

def close
  #@io.finish
  @file.close if !@file.closed?
end

#eofObject



37
38
39
# File 'lib/scbi_zcat/scbi_zcat_file.rb', line 37

def eof
  eof?
end

#eof?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/scbi_zcat/scbi_zcat_file.rb', line 33

def eof?
  @file.eof?
end

#open_fileObject



15
16
17
18
19
20
21
# File 'lib/scbi_zcat/scbi_zcat_file.rb', line 15

def open_file
  cmd="zcat \"#{File.expand_path(@file_name)}\""
  #puts "OPEN: #{cmd}"
  @file = IO.popen(cmd)
  #@file.close_write
  @eof=false
end

#readlineObject



23
24
25
26
27
28
29
30
31
# File 'lib/scbi_zcat/scbi_zcat_file.rb', line 23

def readline
  begin
  res = @file.readline
  rescue IOError
    close
  end

  return res
end

#rewindObject



46
47
48
49
# File 'lib/scbi_zcat/scbi_zcat_file.rb', line 46

def rewind
  close
  open_file
end