Class: Bio::MAF::ChunkReader Private
- Inherits:
-
Object
- Object
- Bio::MAF::ChunkReader
- Defined in:
- lib/bio/maf/parser.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Reads MAF files in chunks.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#chunk_size ⇒ Integer
private
Size, in bytes, of the chunks to read.
-
#f ⇒ File
readonly
private
File from which chunks are read.
-
#pos ⇒ Integer
private
Current position in the file.
Instance Method Summary collapse
- #check_chunk_size(size) ⇒ Object private
-
#initialize(f, chunk_size) ⇒ ChunkReader
constructor
private
A new instance of ChunkReader.
-
#read_chunk ⇒ String
private
Reads the next chunk of the file.
-
#read_chunk_at(offset, size_hint = @chunk_size) ⇒ String
private
Reads a chunk of the file.
Constructor Details
#initialize(f, chunk_size) ⇒ ChunkReader
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of ChunkReader.
24 25 26 27 28 |
# File 'lib/bio/maf/parser.rb', line 24 def initialize(f, chunk_size) @f = f self.chunk_size = chunk_size @pos = 0 end |
Instance Attribute Details
#chunk_size ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Size, in bytes, of the chunks to read. Must be a power of 2.
17 18 19 |
# File 'lib/bio/maf/parser.rb', line 17 def chunk_size @chunk_size end |
#f ⇒ File (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
File from which chunks are read.
23 24 25 |
# File 'lib/bio/maf/parser.rb', line 23 def f @f end |
#pos ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Current position in the file.
20 21 22 |
# File 'lib/bio/maf/parser.rb', line 20 def pos @pos end |
Instance Method Details
#check_chunk_size(size) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/bio/maf/parser.rb', line 37 def check_chunk_size(size) if size < 1 raise "Invalid chunk size: #{size}" end ## test whether it is a power of 2 ## cf. http://bit.ly/JExNc4 if size & (size - 1) != 0 raise "Invalid chunk size (not a power of 2): #{size}}" end end |
#read_chunk ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Reads the next chunk of the file.
50 51 52 53 54 |
# File 'lib/bio/maf/parser.rb', line 50 def read_chunk chunk = f.read(@chunk_size) @pos += chunk.bytesize if chunk return chunk end |
#read_chunk_at(offset, size_hint = @chunk_size) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Reads a chunk of the file.
Currently always reads size_hint bytes but this may change with BGZF support.
64 65 66 67 68 69 |
# File 'lib/bio/maf/parser.rb', line 64 def read_chunk_at(offset, size_hint=@chunk_size) f.seek(offset) chunk = f.read(size_hint) @pos = offset + chunk.bytesize return chunk end |