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)


108
109
110
# File 'lib/omnizip/formats/ole.rb', line 108

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)


90
91
92
# File 'lib/omnizip/formats/ole.rb', line 90

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



116
117
118
119
120
# File 'lib/omnizip/formats/ole.rb', line 116

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)


99
100
101
# File 'lib/omnizip/formats/ole.rb', line 99

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



81
82
83
# File 'lib/omnizip/formats/ole.rb', line 81

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



63
64
65
# File 'lib/omnizip/formats/ole.rb', line 63

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:



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

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



72
73
74
# File 'lib/omnizip/formats/ole.rb', line 72

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