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)


38
39
40
41
42
43
44
45
# File 'lib/cocoapods-hmap/hmap_reader.rb', line 38

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:



36
37
38
# File 'lib/cocoapods-hmap/hmap_reader.rb', line 36

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



24
25
26
# File 'lib/cocoapods-hmap/hmap_reader.rb', line 24

def filename
  @filename
end

#headerHMap::HMapHeader (readonly)

Returns:



32
33
34
# File 'lib/cocoapods-hmap/hmap_reader.rb', line 32

def header
  @header
end

#swappedObject (readonly)

Returns true/false the swapped of the mapfile.

Returns:

  • true/false the swapped of the mapfile



29
30
31
# File 'lib/cocoapods-hmap/hmap_reader.rb', line 29

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.



50
51
52
53
54
55
56
57
58
59
# File 'lib/cocoapods-hmap/hmap_reader.rb', line 50

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