Class: Cabriolet::LIT::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/cabriolet/lit/parser.rb

Overview

Parser for Microsoft Reader LIT files

Handles parsing of the complex LIT file structure including:

  • Primary and secondary headers with piece table

  • IFCM/AOLL/AOLI directory chunks with encoded integers

  • DataSpace sections with transform layers

  • Manifest file with filename mappings

Based on the openclit/SharpLit reference implementation.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io_system = nil) ⇒ Parser

Returns a new instance of Parser.



21
22
23
# File 'lib/cabriolet/lit/parser.rb', line 21

def initialize(io_system = nil)
  @io_system = io_system || System::IOSystem.new
end

Instance Attribute Details

#io_systemObject (readonly)

Returns the value of attribute io_system.



19
20
21
# File 'lib/cabriolet/lit/parser.rb', line 19

def io_system
  @io_system
end

Instance Method Details

#parse(filename) ⇒ Models::LITFile

Parse a LIT file and return the model

Parameters:

  • filename (String)

    Path to LIT file

Returns:

Raises:

  • (Errors::ParseError)

    if file is invalid or unsupported



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/cabriolet/lit/parser.rb', line 30

def parse(filename)
  handle = @io_system.open(filename, Constants::MODE_READ)

  begin
    lit_file = Models::LITFile.new

    # Parse primary header
    parse_primary_header(handle, lit_file)

    # Parse pieces
    pieces = parse_pieces(handle, lit_file)

    # Parse secondary header
    parse_secondary_header(handle, lit_file, pieces)

    # Parse directory from piece 1
    parse_directory(handle, lit_file, pieces[1])

    # Parse sections
    parse_sections(handle, lit_file)

    # Parse manifest
    parse_manifest(handle, lit_file)

    lit_file
  ensure
    @io_system.close(handle) if handle
  end
end