| Class | Ole::Storage::RangesIOResizeable |
| In: |
lib/ole/storage/base.rb
|
| Parent: | RangesIO |
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:
Note that all internal access to first_block is through accessors, as it is sometimes useful to redirect it.
| bat | [R] | |
| first_block | [RW] |
# File lib/ole/storage/base.rb, line 594
594: def initialize bat, mode='r', params={}
595: mode, params = 'r', mode if Hash === mode
596: first_block, size = params.values_at :first_block, :size
597: raise ArgumentError, 'must specify first_block' unless first_block
598: @bat = bat
599: self.first_block = first_block
600: # we now cache the blocks chain, for faster resizing.
601: @blocks = @bat.chain first_block
602: super @bat.io, mode, :ranges => @bat.ranges(@blocks, size)
603: end
# File lib/ole/storage/base.rb, line 605
605: def truncate size
606: # note that old_blocks is != @ranges.length necessarily. i'm planning to write a
607: # merge_ranges function that merges sequential ranges into one as an optimization.
608: @bat.resize_chain @blocks, size
609: @pos = size if @pos > size
610: self.ranges = @bat.ranges(@blocks, size)
611: self.first_block = @blocks.empty? ? AllocationTable::EOC : @blocks.first
612:
613: # don't know if this is required, but we explicitly request our @io to grow if necessary
614: # we never shrink it though. maybe this belongs in allocationtable, where smarter decisions
615: # can be made.
616: # maybe its ok to just seek out there later??
617: max = @ranges.map { |pos, len| pos + len }.max || 0
618: @io.truncate max if max > @io.size
619: end