Class: Ole::Storage::Header

### Home Classes Methods

### In Files

- lib/ole/storage/base.rb

### Parent

Struct.new( :magic, :clsid, :minor_ver, :major_ver, :byte_order, :b_shift, :s_shift, :reserved, :csectdir, :num_bat, :dirent_start, :transacting_signature, :threshold, :sbat_start, :num_sbat, :mbat_start, :num_mbat

### Methods

- ::new
- #to_s
- #validate!

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

A class which wraps the ole header

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

    # File lib/ole/storage/base.rb, line 366
    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 372
    def to_s
      to_a.pack PACK
    end

validate!() click to toggle source

    # File lib/ole/storage/base.rb, line 376
    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 && ![AllocationTable::EOC, AllocationTable::AVAIL].include?(mbat_start) or
         reserved != "\x00" * 6
        Log.warn "may not be a valid OLE2 structured storage file"
      end
      true
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.