Class | Bio::FlatFileIndex::FileID
In: | lib/bio/io/flatfile/index.rb
Parent: | Object

FileID class.

Internal use only.

### Methods

check close get new new_from_string open read recalc seek to_s

### Attributes

filename | [R] |
filesize | [R] |

### Public Class methods

new(filename, filesize = nil)

[Source]

         # File lib/bio/io/flatfile/index.rb, line 495
    495:       def initialize(filename, filesize = nil)
    496:         @filename = filename
    497:         @filesize = filesize
    498:         @io = nil
    499:       end

new_from_string(str)

[Source]

         # File lib/bio/io/flatfile/index.rb, line 489
    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()

[Source]

         # File lib/bio/io/flatfile/index.rb, line 502
    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()

[Source]

         # File lib/bio/io/flatfile/index.rb, line 540
    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)

[Source]

         # File lib/bio/io/flatfile/index.rb, line 559
    559:       def get(pos, length)
    560:         open
    561:         seek(pos, IO::SEEK_SET)
    562:         data = read(length)
    563:         close
    564:         data
    565:       end

open()

[Source]

         # File lib/bio/io/flatfile/index.rb, line 530
    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)

[Source]

         # File lib/bio/io/flatfile/index.rb, line 555
    555:       def read(size)
    556:         @io.read(size)
    557:       end

recalc()

[Source]

         # File lib/bio/io/flatfile/index.rb, line 516
    516:       def recalc
    517:         @filesize = File.size(@filename)
    518:       end

seek(*arg)

[Source]

         # File lib/bio/io/flatfile/index.rb, line 551
    551:       def seek(*arg)
    552:         @io.seek(*arg)
    553:       end

to_s(i = nil)

[Source]

         # File lib/bio/io/flatfile/index.rb, line 520
    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

[Validate]