Class: Ole::Storage::RangesIOResizeable

### Home Classes Methods

### In Files

- lib/ole/storage/base.rb

### Parent

RangesIO

### Methods

- ::new
- #truncate

### Files

- ChangeLog
- README

### Class/Module Index

Quicksearch

- Ole
- Ole::IOMode
- Ole::IOMode::Constants
- Ole::Storage
- Ole::Storage::AllocationTable
- Ole::Storage::AllocationTable::Big
- Ole::Storage::AllocationTable::Small
- Ole::Storage::DirClass
- Ole::Storage::DirClass::Dir
- Ole::Storage::Dirent
- Ole::Storage::FileClass
- Ole::Storage::FileClass::Stat
- Ole::Storage::Header
- Ole::Storage::MetaData
- Ole::Storage::RangesIOMigrateable
- Ole::Storage::RangesIOResizeable
- Ole::Types
- Ole::Types::Clsid
- Ole::Types::Data
- Ole::Types::FileTime
- Ole::Types::Lpstr
- Ole::Types::Lpwstr
- Ole::Types::PropertySet
- Ole::Types::PropertySet::Constants
- Ole::Types::PropertySet::Section
- Ole::Types::Variant
- Ole::Types::Variant::Constants
- RangesIO

No matching classes.

# 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:

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.

### Attributes

bat[R]
first_block[RW]

### Public Class Methods

new(bat, mode='r', params={}) click to toggle source

    # File lib/ole/storage/base.rb, line 603
    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 614
    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

[Validate]

Generated with the Darkfish Rdoc Generator 2.