class Ole::Storage::RangesIOResizeable
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.
Attributes
bat[R]
first_block[RW]
Public Class Methods
new(bat, mode='r', params={})
click to toggle source
Calls superclass method
RangesIO::new
# File lib/ole/storage/base.rb, line 604 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
Public Instance Methods
truncate(size)
click to toggle source
# File lib/ole/storage/base.rb, line 615 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 @pos = size if @pos > size self.ranges = @bat.ranges(@blocks, 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 end