Class: IOBlockReader::DataBlock
- Inherits:
-
Object
- Object
- IOBlockReader::DataBlock
- Defined in:
- lib/ioblockreader/datablock.rb
Overview
Class defining a data block
Constant Summary collapse
- @@access_time_sequence =
Use a Fixnum sequence instead of real Time values for last_access_time for performance reasons
0
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Data contained in this block String.
-
#last_access_time ⇒ Object
readonly
Timestamp indicating when this block has been touched (created or done with touch method) Fixnum.
-
#offset ⇒ Object
readonly
Offset of this block, in bytes Fixnum.
Instance Method Summary collapse
-
#fill(io, offset, size) ⇒ Object
Fill the data block for a given IO.
-
#initialize ⇒ DataBlock
constructor
Constructor.
-
#last_block? ⇒ Boolean
Is this block the last of its IO stream?.
-
#touch ⇒ Object
Update the last access time.
Constructor Details
#initialize ⇒ DataBlock
Constructor
22 23 24 25 26 |
# File 'lib/ioblockreader/datablock.rb', line 22 def initialize @offset = nil @last_access_time = nil @data = '' end |
Instance Attribute Details
#data ⇒ Object (readonly)
Data contained in this block
_String_
19 20 21 |
# File 'lib/ioblockreader/datablock.rb', line 19 def data @data end |
#last_access_time ⇒ Object (readonly)
Timestamp indicating when this block has been touched (created or done with touch method)
_Fixnum_
15 16 17 |
# File 'lib/ioblockreader/datablock.rb', line 15 def last_access_time @last_access_time end |
#offset ⇒ Object (readonly)
Offset of this block, in bytes
_Fixnum_
11 12 13 |
# File 'lib/ioblockreader/datablock.rb', line 11 def offset @offset end |
Instance Method Details
#fill(io, offset, size) ⇒ Object
Fill the data block for a given IO
- Parameters
-
io (IO): IO to read from
-
offset (Fixnum): Offset of this block in the IO
-
size (Fixnum): Size of the block to be read
34 35 36 37 38 39 40 41 42 |
# File 'lib/ioblockreader/datablock.rb', line 34 def fill(io, offset, size) @offset = offset @last_access_time = @@access_time_sequence @@access_time_sequence += 1 #puts "[IOBlockReader] - Read #{size} @#{@offset}" io.seek(@offset) io.read(size, @data) @last_block = io.eof? end |
#last_block? ⇒ Boolean
Is this block the last of its IO stream?
Result:
-
Boolean: Is this block the last of its IO stream?
48 49 50 |
# File 'lib/ioblockreader/datablock.rb', line 48 def last_block? return @last_block end |
#touch ⇒ Object
Update the last access time
53 54 55 56 |
# File 'lib/ioblockreader/datablock.rb', line 53 def touch @last_access_time = @@access_time_sequence @@access_time_sequence += 1 end |