ms-binary-resources 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 86da19e6dd64a8090ae6f58af1ee9389c064c2a4
4
- data.tar.gz: 146e58a02d2cdb175ee62fbd09852646f7d4afab
3
+ metadata.gz: 100dddc9ccf90578d09c5388d236c990f0a1b511
4
+ data.tar.gz: 30361b6b3908cc88588281fc3ca1421d2b560d1f
5
5
  SHA512:
6
- metadata.gz: d7a57c1f7c631d0169cedbee504e4fc4dbee44c66988fb94ef53c9bca9cf0a1ff659967bbde449a520b0ff2f69afd326ecc0af1156ff23431011b0684be9b2aa
7
- data.tar.gz: 0995fe940c55880302f93f636a57785492c0bc238dce4d81e0699d4c705c095aadf43cea5af9fbb773640109394672d3c565f434898761e506664abd0d7f4bf3
6
+ metadata.gz: 71b1138e6df25a1cb079e44b1db14f1a3c7b0552bfd509636f9a2ba45fb34a817ebd8d54dc5a0bd52d409c004da7678e903b5cb3f40b990e6b3293a1b9f5a136
7
+ data.tar.gz: fcf741fe2dcee9ee98100256af6ecee0c0a148bb1e9321b236a212e8af39ae5e574f914e84e7f389c783b9390d96bf027a8dec2cfe31494370489435c49ccf3e
@@ -23,7 +23,7 @@ module Ms
23
23
  timespan: 16,
24
24
  bytearray: 32,
25
25
  stream: 33,
26
- fistcustom: 64,
26
+ fistcustom: 64
27
27
  }
28
28
 
29
29
  end
@@ -8,15 +8,13 @@ module Ms
8
8
 
9
9
  include Enumerable
10
10
 
11
- attr_reader :manager_magic, :manager_version, :manager_length, :resource_version,
12
- :resource_count, :type_count
11
+ attr_reader :manager_magic, :manager_version, :manager_length, :resource_version, :resource_count, :type_count
13
12
 
14
13
  def initialize(uri)
15
14
  @file = open(uri, 'rb')
16
15
  read_headers
17
16
  rescue => e
18
- raise ArgumentError, "file does not appear to be a resources @file (#{e})"
19
- @file.close
17
+ fail ArgumentError, "file does not appear to be a resources file (#{e})"
20
18
  end
21
19
 
22
20
  def each(&block)
@@ -34,7 +32,7 @@ module Ms
34
32
  def type_of(name)
35
33
  info = info_for_name(name)
36
34
  if info
37
- type = RESOURCE_TYPES.find { |_,v| info.type_index == v }
35
+ type = RESOURCE_TYPES.find { |_, v| info.type_index == v }
38
36
  type && type.first
39
37
  end
40
38
  end
@@ -57,7 +55,7 @@ module Ms
57
55
 
58
56
  def read_headers
59
57
  @manager_magic = read_uint32
60
- raise 'magic (%08X)' % manager_magic unless MAGIC_NUMBER == manager_magic
58
+ fail 'magic (%08X)' % manager_magic unless MAGIC_NUMBER == manager_magic
61
59
 
62
60
  @manager_version = read_uint32
63
61
  @manager_length = read_uint32
@@ -65,12 +63,12 @@ module Ms
65
63
  if 1 == manager_version
66
64
  @reader_class = @file.read(@manager_length)
67
65
  else
68
- raise 'Unsupported manager version (%d)' % manager_version
66
+ fail 'Unsupported manager version (%d)' % manager_version
69
67
  end
70
68
 
71
69
  @resource_version = read_uint32
72
70
  unless [1, 2].include?(resource_version)
73
- raise 'Unsupported resource version (%d)' % resource_version
71
+ fail 'Unsupported resource version (%d)' % resource_version
74
72
  end
75
73
 
76
74
  @resource_count = read_uint32
@@ -89,9 +87,8 @@ module Ms
89
87
  @data_section_offset = read_uint32
90
88
  @name_section_offset = @file.pos
91
89
 
90
+ # cache the file location and type of all resources
92
91
  @resource_infos = @positions.map { |pos| read_resource_info(pos) }
93
-
94
- @file.seek(@name_section_offset)
95
92
  end
96
93
 
97
94
  def read_resource_info(name_position)
@@ -102,7 +99,7 @@ module Ms
102
99
  seek_to_data(read_uint32)
103
100
  type_index = read_7bit_encoded_int
104
101
 
105
- OpenStruct.new name: name, value_position: @file.pos, type_index: type_index
102
+ OpenStruct.new(name: name, value_position: @file.pos, type_index: type_index)
106
103
  end
107
104
 
108
105
  def read(bytes)
@@ -140,7 +137,6 @@ module Ms
140
137
  def read_7bit_encoded_int
141
138
  ret = 0
142
139
  shift = 0
143
- b = 0
144
140
 
145
141
  begin
146
142
  b = read_byte
@@ -167,7 +163,7 @@ module Ms
167
163
  when RESOURCE_TYPES[:int64]; read_int64
168
164
  when RESOURCE_TYPES[:uint64]; read_uint64
169
165
  else
170
- raise 'Unsupported type index: %d' % resource_info.type_index
166
+ fail 'Unsupported type index: %d' % resource_info.type_index
171
167
  end
172
168
  end
173
169
 
@@ -1,5 +1,5 @@
1
1
  module Ms
2
2
  module BinaryResources
3
- VERSION = '0.1.0'
3
+ VERSION = '0.1.1'
4
4
  end
5
5
  end
data/spec/spec_helper.rb CHANGED
@@ -8,6 +8,10 @@ require 'awesome_print'
8
8
  require 'pathname'
9
9
  require 'ms/binary/resources'
10
10
 
11
+ # Requires supporting ruby files with custom matchers and macros, etc,
12
+ # in spec/support/ and its subdirectories.
13
+ Dir[Pathname.new(File.dirname(__FILE__)).join('support/**/*.rb')].each { |f| require f }
14
+
11
15
  RSpec.configure do |config|
12
16
  config.treat_symbols_as_metadata_keys_with_true_values = true
13
17
  config.run_all_when_everything_filtered = true
@@ -19,14 +23,3 @@ RSpec.configure do |config|
19
23
  # --seed 1234
20
24
  config.order = 'random'
21
25
  end
22
-
23
- def data_file(name)
24
- File.expand_path("#{File.dirname(__FILE__)}/../support/data/#{name}")
25
- end
26
-
27
- def invalid_data_files
28
- dir = "#{File.dirname(__FILE__)}/../support/data/invalid"
29
- invalid = Dir.glob("#{dir}/**/*").select { |e| File.file? e }
30
- invalid << __FILE__
31
- invalid << 'not-really-a-file.resources'
32
- end
@@ -0,0 +1,10 @@
1
+ def data_file(name)
2
+ File.expand_path("#{File.dirname(__FILE__)}/../../support/data/#{name}")
3
+ end
4
+
5
+ def invalid_data_files
6
+ dir = "#{File.dirname(__FILE__)}/../../support/data/invalid"
7
+ invalid = Dir.glob("#{dir}/**/*").select { |e| File.file? e }
8
+ invalid << __FILE__
9
+ invalid << 'not-really-a-file.resources'
10
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ms-binary-resources
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Veys
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-08 00:00:00.000000000 Z
11
+ date: 2014-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print
@@ -201,6 +201,7 @@ files:
201
201
  - ms-binary-resources.gemspec
202
202
  - spec/reader_spec.rb
203
203
  - spec/spec_helper.rb
204
+ - spec/support/data_files.rb
204
205
  - support/data/Example.resources
205
206
  - support/data/Example.txt
206
207
  - support/data/Example2.resources
@@ -234,4 +235,5 @@ summary: Read binary resource files
234
235
  test_files:
235
236
  - spec/reader_spec.rb
236
237
  - spec/spec_helper.rb
238
+ - spec/support/data_files.rb
237
239
  has_rdoc: