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
495 def initialize(filename, filesize = nil)
496   @filename = filename
497   @filesize = filesize
498   @io = nil
499 end
new_from_string(str) click to toggle source
    # File lib/bio/io/flatfile/index.rb
489 def self.new_from_string(str)
490   a = str.split("\t", 2)
491   a[1] = a[1].to_i if a[1]
492   self.new(a[0], a[1])
493 end

Public Instance Methods

check() click to toggle source
    # File lib/bio/io/flatfile/index.rb
502 def check
503   begin
504     fsize = File.size(@filename)
505     r = ( fsize == @filesize)
506   rescue Errno::ENOENT
507     fsize = -1
508     r = nil
509   end
510   DEBUG.print "FileID: File.size(#{@filename.inspect}) = ",
511     fsize, (r ? ' == ' : ' != ') , @filesize,
512     (r ? '' : ' bad!'), "\n"
513   r
514 end
close() click to toggle source
    # File lib/bio/io/flatfile/index.rb
540 def close
541   if @io then
542     DEBUG.print "FileID: close #{@filename}\n"
543     @io.close
544     @io = nil
545     nil
546   else
547     true
548   end
549 end
get(pos, length) click to toggle source
    # File lib/bio/io/flatfile/index.rb
559 def get(pos, length)
560   open
561   seek(pos, IO::SEEK_SET)
562   data = read(length)
563   close
564   data
565 end
open() click to toggle source
    # File lib/bio/io/flatfile/index.rb
530 def open
531   unless @io then
532     DEBUG.print "FileID: open #{@filename}\n"
533     @io = File.open(@filename, 'rb')
534     true
535   else
536     nil
537   end
538 end
read(size) click to toggle source
    # File lib/bio/io/flatfile/index.rb
555 def read(size)
556   @io.read(size)
557 end
recalc() click to toggle source
    # File lib/bio/io/flatfile/index.rb
516 def recalc
517   @filesize = File.size(@filename)
518 end
seek(*arg) click to toggle source
    # File lib/bio/io/flatfile/index.rb
551 def seek(*arg)
552   @io.seek(*arg)
553 end
to_s(i = nil) click to toggle source
    # File lib/bio/io/flatfile/index.rb
520 def to_s(i = nil)
521   if i then
522     str = "fileid_#{i}\t"
523   else
524     str = ''
525   end
526   str << "#{@filename}\t#{@filesize}"
527   str
528 end