class Ole::Storage::Header

A class which wraps the ole header

::new can be both used to load from a string, or to create from defaults. Serialization is accomplished with the to_s method.

Constants

DEFAULT
EOC

what you get if creating new header from scratch. AllocationTable::EOC isn't available yet. meh.

MAGIC

i have seen it pointed out that the first 4 bytes of hex, 0xd0cf11e0, is supposed to spell out docfile. hmmm :)

PACK
SIZE

Public Class Methods

new(values=DEFAULT) click to toggle source
Calls superclass method
# File lib/ole/storage/base.rb, line 365
def initialize values=DEFAULT
  values = values.unpack(PACK) if String === values
  super(*values)
  validate!
end

Public Instance Methods

to_s() click to toggle source
# File lib/ole/storage/base.rb, line 371
def to_s
  to_a.pack PACK
end
validate!() click to toggle source
# File lib/ole/storage/base.rb, line 375
def validate!
  raise FormatError, "OLE2 signature is invalid" unless magic == MAGIC
  if num_bat == 0 or # is that valid for a completely empty file?
     # not sure about this one. basically to do max possible bat given size of mbat
     num_bat > 109 && num_bat > 109 + num_mbat * (1 << b_shift - 2) or
     # shouldn't need to use the mbat as there is enough space in the header block
     num_bat < 109 && num_mbat != 0 or
     # given the size of the header is 76, if b_shift <= 6, blocks address the header.
     s_shift > b_shift or b_shift <= 6 or b_shift >= 31 or
     # we only handle little endian
     byte_order != "\xfe\xff"
    raise FormatError, "not valid OLE2 structured storage file"
  end
  # relaxed this, due to test-msg/qwerty_[1-3]*.msg they all had
  # 3 for this value. 
  # transacting_signature != "\x00" * 4 or
  if threshold != 4096 or
     num_mbat == 0 && mbat_start != AllocationTable::EOC or
     reserved != "\x00" * 6
    Log.warn "may not be a valid OLE2 structured storage file"
  end
  true
end