class Bio::FlatFileIndex::FileID

FileID class.

Internal use only.

Attributes

filename[R]
filesize[R]

Public Class Methods

new(filename, filesize = nil) click to toggle source
# File lib/bio/io/flatfile/index.rb, line 495
def initialize(filename, filesize = nil)
  @filename = filename
  @filesize = filesize
  @io = nil
end
new_from_string(str) click to toggle source
# File lib/bio/io/flatfile/index.rb, line 489
def self.new_from_string(str)
  a = str.split("\t", 2)
  a[1] = a[1].to_i if a[1]
  self.new(a[0], a[1])
end

Public Instance Methods

check() click to toggle source
# File lib/bio/io/flatfile/index.rb, line 502
def check
  begin
    fsize = File.size(@filename)
    r = ( fsize == @filesize)
  rescue Errno::ENOENT
    fsize = -1
    r = nil
  end
  DEBUG.print "FileID: File.size(#{@filename.inspect}) = ",
    fsize, (r ? ' == ' : ' != ') , @filesize,
    (r ? '' : ' bad!'), "\n"
  r
end
close() click to toggle source
# File lib/bio/io/flatfile/index.rb, line 540
def close
  if @io then
    DEBUG.print "FileID: close #{@filename}\n"
    @io.close
    @io = nil
    nil
  else
    true
  end
end
get(pos, length) click to toggle source
# File lib/bio/io/flatfile/index.rb, line 559
def get(pos, length)
  open
  seek(pos, IO::SEEK_SET)
  data = read(length)
  close
  data
end
open() click to toggle source
# File lib/bio/io/flatfile/index.rb, line 530
def open
  unless @io then
    DEBUG.print "FileID: open #{@filename}\n"
    @io = File.open(@filename, 'rb')
    true
  else
    nil
  end
end
read(size) click to toggle source
# File lib/bio/io/flatfile/index.rb, line 555
def read(size)
  @io.read(size)
end
recalc() click to toggle source
# File lib/bio/io/flatfile/index.rb, line 516
def recalc
  @filesize = File.size(@filename)
end
seek(*arg) click to toggle source
# File lib/bio/io/flatfile/index.rb, line 551
def seek(*arg)
  @io.seek(*arg)
end
to_s(i = nil) click to toggle source
# File lib/bio/io/flatfile/index.rb, line 520
def to_s(i = nil)
  if i then
    str = "fileid_#{i}\t"
  else
    str = ''
  end
  str << "#{@filename}\t#{@filesize}"
  str
end