Class: Ole::Storage::RangesIOResizeable
- Defined in:
- lib/ole/storage.rb
Overview
like normal RangesIO, but Ole::Storage specific. the ranges are backed by an AllocationTable, and can be resized. used for read/write to 2 streams:
-
serialized dirent data
-
sbat table data
-
all dirents but through RangesIOMigrateable below
Note that all internal access to first_block is through accessors, as it is sometimes useful to redirect it.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#bat ⇒ Object
readonly
Returns the value of attribute bat.
-
#first_block ⇒ Object
Returns the value of attribute first_block.
Attributes inherited from RangesIO
#io, #mode, #pos, #ranges, #size
Instance Method Summary collapse
-
#initialize(bat, mode = 'r', params = {}) ⇒ RangesIOResizeable
constructor
A new instance of RangesIOResizeable.
- #truncate(size) ⇒ Object
Methods inherited from RangesIO
#close, #eof?, #gets, #inspect, #offset_and_size, open, #read, #write
Constructor Details
#initialize(bat, mode = 'r', params = {}) ⇒ RangesIOResizeable
Returns a new instance of RangesIOResizeable.
623 624 625 626 627 628 629 630 631 632 |
# File 'lib/ole/storage.rb', line 623 def initialize bat, mode='r', params={} mode, params = 'r', mode if Hash === mode first_block, size = params.values_at :first_block, :size raise ArgumentError, 'must specify first_block' unless first_block @bat = bat self.first_block = first_block # we now cache the blocks chain, for faster resizing. @blocks = @bat.chain first_block super @bat.io, mode, :ranges => @bat.ranges(@blocks, size) end |
Instance Attribute Details
#bat ⇒ Object (readonly)
Returns the value of attribute bat.
621 622 623 |
# File 'lib/ole/storage.rb', line 621 def bat @bat end |
#first_block ⇒ Object
Returns the value of attribute first_block.
622 623 624 |
# File 'lib/ole/storage.rb', line 622 def first_block @first_block end |
Instance Method Details
#truncate(size) ⇒ Object
634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 |
# File 'lib/ole/storage.rb', line 634 def truncate size # note that old_blocks is != @ranges.length necessarily. i'm planning to write a # merge_ranges function that merges sequential ranges into one as an optimization. @bat.resize_chain @blocks, size @ranges = @bat.ranges @blocks, size @pos = @size if @pos > size self.first_block = @blocks.empty? ? AllocationTable::EOC : @blocks.first # don't know if this is required, but we explicitly request our @io to grow if necessary # we never shrink it though. maybe this belongs in allocationtable, where smarter decisions # can be made. # maybe its ok to just seek out there later?? max = @ranges.map { |pos, len| pos + len }.max || 0 @io.truncate max if max > @io.size @size = size end |