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.
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.
27 28 29 30 31 |
# File 'lib/bio/maf/parser.rb', line 27 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.
20 21 22 |
# File 'lib/bio/maf/parser.rb', line 20 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.
26 27 28 |
# File 'lib/bio/maf/parser.rb', line 26 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.
23 24 25 |
# File 'lib/bio/maf/parser.rb', line 23 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.
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/bio/maf/parser.rb', line 40 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.
53 54 55 56 57 |
# File 'lib/bio/maf/parser.rb', line 53 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.
66 67 68 69 70 71 |
# File 'lib/bio/maf/parser.rb', line 66 def read_chunk_at(offset, size_hint=@chunk_size) f.seek(offset) chunk = f.read(size_hint) @pos = offset + chunk.bytesize return chunk end |