Class: HMap::MapFileReader

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods-hmap/hmap_reader.rb

Overview

hmap file reader

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ MapFileReader

Returns a new instance of MapFileReader.

Raises:

  • (ArgumentError)


22
23
24
25
26
27
28
29
# File 'lib/cocoapods-hmap/hmap_reader.rb', line 22

def initialize(path)
  raise ArgumentError, "#{path}: no such file" unless File.file?(path)

  @filename = path
  @raw_data = File.open(@filename, 'rb', &:read)
  populate_fields
  puts description
end

Instance Attribute Details

#bucktesHash<HMap::HMapBucket => HMap::HMapBucketStr> (readonly)

Note:

bucktes are provided in order of ascending offset.

Returns an array of the file’s bucktes.

Returns:



20
21
22
# File 'lib/cocoapods-hmap/hmap_reader.rb', line 20

def bucktes
  @bucktes
end

#filenameString? (readonly)

Returns the filename loaded from, or nil if loaded from a binary string.

Returns:

  • (String, nil)

    the filename loaded from, or nil if loaded from a binary string



8
9
10
# File 'lib/cocoapods-hmap/hmap_reader.rb', line 8

def filename
  @filename
end

#headerHMap::HMapHeader (readonly)

Returns:



16
17
18
# File 'lib/cocoapods-hmap/hmap_reader.rb', line 16

def header
  @header
end

#swappedObject (readonly)

Returns true/false the swapped of the mapfile.

Returns:

  • true/false the swapped of the mapfile



13
14
15
# File 'lib/cocoapods-hmap/hmap_reader.rb', line 13

def swapped
  @swapped
end

Instance Method Details

#populate_fieldsvoid

Note:

This method is public, but should (almost) never need to be called.

This method returns an undefined value.

Populate the instance’s fields with the raw HMap data.



34
35
36
37
38
39
40
41
42
43
# File 'lib/cocoapods-hmap/hmap_reader.rb', line 34

def populate_fields
  @header = populate_hmap_header
  string_t = @raw_data[header.strings_offset..-1]
  @bucktes = populate_buckets do |bucket|
    bucket_s = bucket.to_a.map do |key|
      string_t[key..-1].match(/[^\0]+/)[0]
    end
    HMapBucketStr.new(*bucket_s)
  end
end