# ruby-ole-1.2.11.7 Documentation

The ruby-ole library provides a variety of functions primarily for working with OLE2 structured storage files, such as those produced by Microsoft Office - eg *.doc, *.msg etc.

# Example Usage

Here are some examples of how to use the library functionality, categorised roughly by purpose.

1. Reading and writing files within an OLE container

   The recommended way to manipulate the contents is via the "file_system" API, whereby you use Ole::Storage instance methods similar to the regular File and Dir class methods.

       ole = Ole::Storage.open('oleWithDirs.ole', 'rb+')
       p ole.dir.entries('.') # => [".", "..", "dir1", "dir2", "file1"]
       p ole.file.read('file1')[0, 25] # => "this is the entry 'file1'"
       ole.dir.mkdir('newdir')

2. Accessing OLE meta data

   Some convenience functions are provided for (currently read only) access to OLE property sets and other sources of meta data.

       ole = Ole::Storage.open('test_word_95.doc')
       p ole.meta_data.file_format # => "MSWordDoc"
       p ole.meta_data.mime_type # => "application/msword"
       p ole.meta_data.doc_author.split.first # => "Charles"

3. Raw access to underlying OLE internals

   This is probably of little interest to most developers using the library, but for some use cases you may need to drop down to the lower level API on which the "file_system" API is constructed, which exposes more of the format details.

   `Ole::Storage` files can have multiple files with the same name, or with a slash in the name, and other things that are probably strictly invalid. This API is the only way to access those files.

   You can access the header object directly:

       p ole.header.num_sbat # => 1
       p ole.header.magic.unpack('H*') # => ["d0cf11e0a1b11ae1"]

   You can directly access the array of all Dirent objects, including the root:

       p ole.dirents.length # => 5
       puts ole.root.to_tree
       # =>
       - #<Dirent:"Root Entry">
         |- #<Dirent:"\001Ole" size=20 data="\001\000\000\002\000...">
         |- #<Dirent:"\001CompObj" size=98 data="\001\000\376\377\003...">
         |- #<Dirent:"WordDocument" size=2574 data="\334\245e\000-...">
         \- #<Dirent:"\005SummaryInformation" size=54788 data="\376\377\000\000\001...">

   You can access (through RangesIO methods, or by using the relevant Dirent and AllocationTable methods) information like where within the container a stream is located (these are offset/length pairs):

       p ole.root["\001CompObj"].open { |io| io.ranges } # => [[0, 64], [64, 34]]

See the documentation for each class for more details.

# Thanks

- The code contained in this project was initially based on chicago's libole (source available at prdownloads.sf.net/chicago/ole.tgz).

- It was later augmented with some corrections by inspecting pole, and (purely for header definitions) gsf.

- The property set parsing code came from the apache java project POIFS.

- The excellent idea for using a pseudo file system style interface by providing file and dir methods which mimic File and Dir, was borrowed (along with almost unchanged tests!) from Thomas Sondergaard's rubyzip.

# TODO

## 1.2.12

- internal api cleanup

- add buffering to rangesio so that performance for small reads and writes isn't so awful. maybe try and remove the bottlenecks of unbuffered first with more profiling, then implement the buffering on top of that.

- fix mode strings - like truncate when using 'w+', supporting append 'a+' modes etc. done?

- make ranges io obey readable vs writeable modes.

- more RangesIO completion. ie, doesn't support #<< at the moment.

- maybe some oletool doc.

- make sure `rake test' runs tests both with $KCODE='UTF8', and without, and maybe ensure i don't regress on 1.9 and jruby either now that they're fixed.

## 1.3.1

- case insensitive open mode would be nice

- fix property sets a bit more. see TODO in Ole::Storage::MetaData

- ability to zero out padding and unused blocks

- better tests for mbat support.

- further doc cleanup

- add in place testing for jruby and ruby1.9

## Longer term

- more benchmarking, profiling, and speed fixes. was thinking vs other ruby filesystems (eg, vs File/Dir itself, and vs rubyzip), and vs other ole implementations (maybe perl's, and poifs) just to check its in the ballpark, with no remaining silly bottlenecks.

- supposedly vba does something weird to ole files. test that.

## Files

- ChangeLog
- README

## Classes/Modules

- 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

## Methods

- ::copy — Ole::Storage::Dirent
- ::dump — Ole::Types::FileTime
- ::dump — Ole::Types::Variant
- ::dump — Ole::Types::Clsid
- ::dump — Ole::Types::Data
- ::dump — Ole::Types::Lpwstr
- ::dump — Ole::Types::Lpstr
- ::flatten_helper — Ole::Storage::Dirent
- ::from_time — Ole::Types::FileTime
- ::load — Ole::Types::FileTime
- ::load — Ole::Types::Lpwstr
- ::load — Ole::Types::Variant
- ::load — Ole::Types::Lpstr
- ::load — Ole::Types::Clsid
- ::load — Ole::Types::Data
- ::load_guid — Ole::Types
- ::load_time — Ole::Types
- ::new — RangesIO
- ::new — Ole::Storage::Dirent
- ::new — Ole::Storage::RangesIOMigrateable
- ::new — Ole::Storage::RangesIOResizeable
- ::new — Ole::Storage::AllocationTable::Small
- ::new — Ole::Storage::AllocationTable::Big
- ::new — Ole::Storage::MetaData
- ::new — Ole::IOMode
- ::new — Ole::Types::PropertySet
- ::new — Ole::Storage::AllocationTable
- ::new — Ole::Storage::DirClass
- ::new — Ole::Types::PropertySet::Section
- ::new — Ole::Storage::FileClass::Stat
- ::new — Ole::Storage
- ::new — Ole::Types::FileTime
- ::new — Ole::Storage::FileClass
- ::new — Ole::Storage::DirClass::Dir
- ::new — Ole::Storage::Header
- ::now — Ole::Types::FileTime
- ::open — Ole::Storage
- ::open — RangesIO
- ::parse — Ole::Types::Clsid
- ::parse_mode — Ole::IOMode
- #/ — Ole::Storage::Dirent
- #<< — Ole::Storage::Dirent
- #<< — RangesIO
- #[] — Ole::Types::PropertySet::Section
- #[] — Ole::Storage::Dirent
- #[] — Ole::Types::PropertySet
- #[] — Ole::Storage::MetaData
- #[]= — Ole::Storage::MetaData
- #[]= — Ole::Types::PropertySet::Section
- #[]= — Ole::Storage::AllocationTable
- #[]= — Ole::Types::PropertySet
- #append? — Ole::IOMode
- #bat_for_size — Ole::Storage
- #binary? — Ole::IOMode
- #blocks_to_ranges — Ole::Storage::AllocationTable
- #blocks_to_ranges — Ole::Storage::AllocationTable::Big
- #chain — Ole::Storage::AllocationTable
- #chdir — Ole::Storage::DirClass
- #clear — Ole::Storage
- #close — Ole::Storage::DirClass::Dir
- #close — RangesIO
- #close — Ole::Storage
- #create? — Ole::IOMode
- #delete — Ole::Storage::DirClass
- #delete — Ole::Storage::Dirent
- #delete — Ole::Storage::FileClass
- #dir — Ole::Storage
- #dir? — Ole::Storage::Dirent
- #directory? — Ole::Storage::FileClass::Stat
- #directory? — Ole::Storage::FileClass
- #dirent_from_path — Ole::Storage
- #each — Ole::Types::PropertySet
- #each — Ole::Storage::MetaData
- #each — Ole::Types::PropertySet::Section
- #each — Ole::Storage::DirClass::Dir
- #each_child — Ole::Storage::Dirent
- #entries — Ole::Storage::DirClass
- #eof? — RangesIO
- #exist? — Ole::Storage::FileClass
- #exists? — Ole::Storage::FileClass
- #expand_path — Ole::Storage::FileClass
- #file — Ole::Storage
- #file? — Ole::Storage::Dirent
- #file? — Ole::Storage::FileClass::Stat
- #file? — Ole::Storage::FileClass
- #file_format — Ole::Storage::MetaData
- #first_block — Ole::Storage::RangesIOMigrateable
- #first_block= — Ole::Storage::RangesIOMigrateable
- #flatten — Ole::Storage::Dirent
- #flush — Ole::Storage
- #foreach — Ole::Storage::DirClass
- #format — Ole::Types::Clsid
- #free_block — Ole::Storage::AllocationTable
- #gets — RangesIO
- #getwd — Ole::Storage::DirClass
- #inspect — Ole::Storage::FileClass::Stat
- #inspect — Ole::Storage::Dirent
- #inspect — Ole::IOMode
- #inspect — RangesIO
- #inspect — Ole::Types::FileTime
- #inspect — Ole::Storage
- #inspect — Ole::Types::Clsid
- #io — Ole::Types::PropertySet::Section
- #load — Ole::Storage
- #load — Ole::Storage::AllocationTable
- #load_header — Ole::Types::PropertySet
- #load_header — Ole::Types::PropertySet::Section
- #load_section_list — Ole::Types::PropertySet
- #meta_data — Ole::Storage
- #method_missing — Ole::Storage::MetaData
- #method_missing — Ole::Types::PropertySet
- #mime_type — Ole::Storage::MetaData
- #mkdir — Ole::Storage::DirClass
- #name= — Ole::Storage::Dirent
- #new — Ole::Storage::DirClass
- #new — Ole::Storage::FileClass
- #open — Ole::Storage::Dirent
- #open — Ole::Storage::AllocationTable
- #open — Ole::Storage::FileClass
- #open — Ole::Storage::DirClass
- #pos — Ole::Storage::DirClass::Dir
- #pos= — RangesIO
- #pos= — Ole::Storage::DirClass::Dir
- #pwd — Ole::Storage::DirClass
- #ranges — Ole::Storage::AllocationTable
- #ranges= — RangesIO
- #read — Ole::Storage::DirClass::Dir
- #read — Ole::Storage::Dirent
- #read — RangesIO
- #read — Ole::Storage::AllocationTable
- #read — Ole::Storage::FileClass
- #readable? — Ole::IOMode
- #readline — RangesIO
- #rename — Ole::Storage::FileClass
- #repack — Ole::Storage
- #repack_using_io — Ole::Storage
- #resize_chain — Ole::Storage::AllocationTable
- #rewind — RangesIO
- #rewind — Ole::Storage::DirClass::Dir
- #rmdir — Ole::Storage::DirClass
- #seek — RangesIO
- #seek — Ole::Storage::DirClass::Dir
- #size — Ole::Storage::FileClass
- #size= — RangesIO
- #size? — Ole::Storage::FileClass::Stat
- #size? — Ole::Storage::FileClass
- #stat — Ole::Storage::FileClass
- #tell — Ole::Storage::DirClass::Dir
- #time — Ole::Storage::Dirent
- #to_h — Ole::Storage::MetaData
- #to_h — Ole::Types::PropertySet
- #to_s — Ole::Storage::Header
- #to_s — Ole::Storage::Dirent
- #to_s — Ole::Storage::AllocationTable
- #truncate — Ole::Storage::AllocationTable
- #truncate — RangesIO
- #truncate — Ole::Storage::RangesIOMigrateable
- #truncate — Ole::Storage::RangesIOResizeable
- #truncate! — Ole::Storage::AllocationTable
- #truncate? — Ole::IOMode
- #unlink — Ole::Storage::FileClass
- #unlink — Ole::Storage::DirClass
- #validate! — Ole::Storage::Header
- #write — RangesIO
- #writeable? — Ole::IOMode

[Validate]

Generated with the Darkfish Rdoc Generator 2.