Class: MppReader::Cfbf::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/mpp_reader/cfbf/directory.rb

Overview

One 128-byte directory entry: a storage (folder), stream (file), or root.

Constant Summary collapse

TYPE_STORAGE =
1
TYPE_STREAM =
2
TYPE_ROOT =
5

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(record) ⇒ Entry

Returns a new instance of Entry.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/mpp_reader/cfbf/directory.rb', line 12

def initialize(record)
  name_len = record.byteslice(64, 2).unpack1("v")
  name_len = 64 if name_len > 64
  @name = if name_len >= 2
            record.byteslice(0, name_len - 2)
                  .force_encoding(Encoding::UTF_16LE)
                  .encode(Encoding::UTF_8, invalid: :replace, undef: :replace)
          else
            ""
          end
  @type = record.getbyte(66)
  @left, @right, @child = record.byteslice(68, 12).unpack("V3")
  @start_sector = record.byteslice(116, 4).unpack1("V")
  @size = record.byteslice(120, 8).unpack1("Q<")
  @children = {}
end

Instance Attribute Details

#childObject (readonly)

Returns the value of attribute child.



9
10
11
# File 'lib/mpp_reader/cfbf/directory.rb', line 9

def child
  @child
end

#childrenObject

Returns the value of attribute children.



10
11
12
# File 'lib/mpp_reader/cfbf/directory.rb', line 10

def children
  @children
end

#leftObject (readonly)

Returns the value of attribute left.



9
10
11
# File 'lib/mpp_reader/cfbf/directory.rb', line 9

def left
  @left
end

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/mpp_reader/cfbf/directory.rb', line 9

def name
  @name
end

#rightObject (readonly)

Returns the value of attribute right.



9
10
11
# File 'lib/mpp_reader/cfbf/directory.rb', line 9

def right
  @right
end

#sizeObject (readonly)

Returns the value of attribute size.



9
10
11
# File 'lib/mpp_reader/cfbf/directory.rb', line 9

def size
  @size
end

#start_sectorObject (readonly)

Returns the value of attribute start_sector.



9
10
11
# File 'lib/mpp_reader/cfbf/directory.rb', line 9

def start_sector
  @start_sector
end

#typeObject (readonly)

Returns the value of attribute type.



9
10
11
# File 'lib/mpp_reader/cfbf/directory.rb', line 9

def type
  @type
end

Instance Method Details

#storage?Boolean

Returns:

  • (Boolean)


29
# File 'lib/mpp_reader/cfbf/directory.rb', line 29

def storage? = @type == TYPE_STORAGE || @type == TYPE_ROOT

#stream?Boolean

Returns:

  • (Boolean)


30
# File 'lib/mpp_reader/cfbf/directory.rb', line 30

def stream? = @type == TYPE_STREAM