Class Ole::Storage::AllocationTable
In: lib/ole/storage/base.rb
Parent: Array

AllocationTable‘s hold the chains corresponding to files. Given an initial index, AllocationTable#chain follows the chain, returning the blocks that make up that file.

There are 2 allocation tables, the bbat, and sbat, for big and small blocks respectively. The block chain should be loaded using either Storage#read_big_blocks or Storage#read_small_blocks as appropriate.

Whether or not big or small blocks are used for a file depends on whether its size is over the Header#threshold level.

An Ole::Storage document is serialized as a series of directory objects, which are stored in blocks throughout the file. The blocks are either big or small, and are accessed using the AllocationTable.

The bbat allocation table‘s data is stored in the spare room in the header block, and in extra blocks throughout the file as referenced by the meta bat. That chain is linear, as there is no higher level table.

AllocationTable.new is used to create an empty table. It can parse a string with the load method. Serialization is accomplished with the to_s method.

Methods

[]=   blocks_to_ranges   chain   free_block   load   new   open   ranges   read   resize_chain   to_s   truncate   truncate!  

Classes and Modules

Class Ole::Storage::AllocationTable::Big
Class Ole::Storage::AllocationTable::Small

Constants

AVAIL = 0xffffffff   a free block (I don‘t currently leave any blocks free), although I do pad out the allocation table with AVAIL to the block size.
EOC = 0xfffffffe
BAT = 0xfffffffd   these blocks are used for storing the allocation table chains
META_BAT = 0xfffffffc

Attributes

block_size  [R] 
io  [R] 
ole  [R] 

Public Class methods

Public Instance methods

Turn a chain (an array given by chain) of blocks (optionally truncated to size) into an array of arrays describing the stretches of bytes in the file that it belongs to.

The blocks are Big or Small blocks depending on the table type.

rewrote this to be non-recursive as it broke on a large attachment chain with a stack error

quick shortcut. chain can be either a head (in which case the table is used to turn it into a chain), or a chain. it is converted to ranges, then to rangesio.

must return first_block. modifies blocks in place

[Validate]