Class Ole::Storage::RangesIOResizeable
In: lib/ole/storage/base.rb
Parent: RangesIO
String Data Lpstr Clsid Lpwstr Section Enumerable DateTime FileTime Constants Variant::Constants Storage\n[lib/ole/storage/base.rb\nlib/ole/storage/file_system.rb\nlib/ole/storage/meta_data.rb] PropertySet lib/ole/storage/file_system.rb lib/ole/types/property_set.rb lib/ole/types/base.rb Constants Constants Variant Types Ole dot/m_9_0.png

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:

  1. serialized dirent data
  2. sbat table data
  3. 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.

Methods

new   truncate  

Attributes

bat  [R] 
first_block  [RW] 

Public Class methods

[Source]

     # 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

Public Instance methods

[Source]

     # 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

[Validate]