Module: Omnizip::Formats::Ole

Defined in:
lib/omnizip/formats/ole.rb,
lib/omnizip/formats/ole/dirent.rb,
lib/omnizip/formats/ole/header.rb,
lib/omnizip/formats/ole/storage.rb,
lib/omnizip/formats/ole/constants.rb,
lib/omnizip/formats/ole/ranges_io.rb,
lib/omnizip/formats/ole/types/variant.rb,
lib/omnizip/formats/ole/allocation_table.rb

Overview

OLE compound document format support

Provides read access to Microsoft OLE compound documents, commonly used for .doc, .xls, .ppt files and MSI installers.

Examples:

Open OLE file and list contents

Omnizip::Formats::Ole.open('document.doc') do |ole|
  ole.list('/').each { |name| puts name }
end

Read a stream from OLE file

Omnizip::Formats::Ole.open('document.doc') do |ole|
  data = ole.read('/WordDocument')
end

Defined Under Namespace

Modules: Constants, Types Classes: AllocationTable, Dirent, Header, RangesIO, RangesIOMigrateable, RangesIOResizeable, Storage

Class Method Summary collapse

Class Method Details

.directory?(ole_path, entry_path) ⇒ Boolean

Check if entry is a directory (storage)

Parameters:

  • ole_path (String)

    Path to OLE file

  • entry_path (String)

    Path to entry within OLE

Returns:

  • (Boolean)


106
107
108
# File 'lib/omnizip/formats/ole.rb', line 106

def directory?(ole_path, entry_path)
  self.open(ole_path) { |ole| ole.directory?(entry_path) }
end

.exist?(ole_path, entry_path) ⇒ Boolean

Check if entry exists in OLE file

Parameters:

  • ole_path (String)

    Path to OLE file

  • entry_path (String)

    Path to entry within OLE

Returns:

  • (Boolean)


88
89
90
# File 'lib/omnizip/formats/ole.rb', line 88

def exist?(ole_path, entry_path)
  self.open(ole_path) { |ole| ole.exist?(entry_path) }
end

.extract(ole_path, output_dir) ⇒ Object

Extract all streams to directory

Parameters:

  • ole_path (String)

    Path to OLE file

  • output_dir (String)

    Output directory



114
115
116
117
118
# File 'lib/omnizip/formats/ole.rb', line 114

def extract(ole_path, output_dir)
  self.open(ole_path) do |ole|
    extract_dirent(ole.root, output_dir, ole)
  end
end

.file?(ole_path, entry_path) ⇒ Boolean

Check if entry is a file (stream)

Parameters:

  • ole_path (String)

    Path to OLE file

  • entry_path (String)

    Path to entry within OLE

Returns:

  • (Boolean)


97
98
99
# File 'lib/omnizip/formats/ole.rb', line 97

def file?(ole_path, entry_path)
  self.open(ole_path) { |ole| ole.file?(entry_path) }
end

.info(ole_path, entry_path = "/") ⇒ Hash?

Get info about entry in OLE file

Parameters:

  • ole_path (String)

    Path to OLE file

  • entry_path (String) (defaults to: "/")

    Path to entry within OLE

Returns:

  • (Hash, nil)

    Entry info



79
80
81
# File 'lib/omnizip/formats/ole.rb', line 79

def info(ole_path, entry_path = "/")
  self.open(ole_path) { |ole| ole.info(entry_path) }
end

.list(path, dir_path = "/") ⇒ Array<String>

List entries in OLE file

Parameters:

  • path (String)

    Path to OLE file

  • dir_path (String) (defaults to: "/")

    Directory path within OLE (default: "/")

Returns:

  • (Array<String>)

    Entry names



61
62
63
# File 'lib/omnizip/formats/ole.rb', line 61

def list(path, dir_path = "/")
  self.open(path) { |ole| ole.list(dir_path) }
end

.open(path) {|Storage| ... } ⇒ Storage

Open OLE file

Parameters:

  • path (String)

    Path to OLE file

Yields:

Returns:



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/omnizip/formats/ole.rb', line 43

def open(path)
  storage = Storage.open(path)
  if block_given?
    begin
      yield storage
    ensure
      storage.close
    end
  else
    storage
  end
end

.read(ole_path, stream_path) ⇒ String

Read stream from OLE file

Parameters:

  • ole_path (String)

    Path to OLE file

  • stream_path (String)

    Path to stream within OLE

Returns:

  • (String)

    Stream content



70
71
72
# File 'lib/omnizip/formats/ole.rb', line 70

def read(ole_path, stream_path)
  self.open(ole_path) { |ole| ole.read(stream_path) }
end

.register!Object

Register OLE format in registry



121
122
123
124
125
126
# File 'lib/omnizip/formats/ole.rb', line 121

def register!
  FormatRegistry.register(".ole", Storage)
  FormatRegistry.register(".doc", Storage)
  FormatRegistry.register(".xls", Storage)
  FormatRegistry.register(".ppt", Storage)
end