iostruct 0.0.2 → 0.0.4

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.
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Rakefile CHANGED
@@ -1 +1,7 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ desc "run specs"
5
+ RSpec::Core::RakeTask.new
6
+
7
+ task :default => :spec
@@ -3,7 +3,7 @@ module IOStruct
3
3
  size = fmt.scan(/([a-z])(\d*)/i).map do |f,len|
4
4
  [len.to_i, 1].max *
5
5
  case f
6
- when /[AC]/i then 1
6
+ when /[AaCcx]/ then 1
7
7
  when 'v' then 2
8
8
  when 'V','l','L' then 4
9
9
  when 'Q' then 8
@@ -48,5 +48,21 @@ module IOStruct
48
48
  def empty?
49
49
  to_a.all?{ |t| t == 0 || t.nil? || t.to_s.tr("\x00","").empty? }
50
50
  end
51
+
52
+ # allow initializing individual struct members by name, like:
53
+ # PEdump::IMAGE_SECTION_HEADER.new(
54
+ # :VirtualSize => 0x100,
55
+ # :VirtualAddress => 0x100000
56
+ # )
57
+ def initialize *args
58
+ if args.size == 1 && args.first.is_a?(Hash)
59
+ super()
60
+ args.first.each do |k,v|
61
+ send "#{k}=", v
62
+ end
63
+ else
64
+ super
65
+ end
66
+ end
51
67
  end # InstanceMethods
52
68
  end # IOStruct
@@ -1,3 +1,3 @@
1
1
  module IOStruct
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+ require 'stringio'
3
+
4
+ describe IOStruct do
5
+ describe "#read" do
6
+ it "reads from IO" do
7
+ a = [12345,56789]
8
+ data = a.pack('L2')
9
+ x = IOStruct.new('LL', :x, :y).read(StringIO.new(data))
10
+ x.x.should == a[0]
11
+ x.y.should == a[1]
12
+ end
13
+
14
+ it "reads from String" do
15
+ a = [12345,56789]
16
+ data = a.pack('L2')
17
+ x = IOStruct.new('LL', :x, :y).read(data)
18
+ x.x.should == a[0]
19
+ x.y.should == a[1]
20
+ end
21
+ end
22
+
23
+ it "skips on 'x'" do
24
+ a = [12345,56789]
25
+ data = a.pack('L2')
26
+ x = IOStruct.new('x4L', :y).read(data)
27
+ x.y.should == a[1]
28
+ end
29
+ end
@@ -0,0 +1,7 @@
1
+ require File.join(File.dirname(__FILE__), '../lib/iostruct.rb')
2
+
3
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
4
+ RSpec.configure do |config|
5
+ config.treat_symbols_as_metadata_keys_with_true_values = true
6
+ config.run_all_when_everything_filtered = true
7
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iostruct
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -50,6 +50,7 @@ extensions: []
50
50
  extra_rdoc_files: []
51
51
  files:
52
52
  - .gitignore
53
+ - .rspec
53
54
  - Gemfile
54
55
  - Gemfile.lock
55
56
  - LICENSE.txt
@@ -58,6 +59,8 @@ files:
58
59
  - iostruct.gemspec
59
60
  - lib/iostruct.rb
60
61
  - lib/iostruct/version.rb
62
+ - spec/iostruct_spec.rb
63
+ - spec/spec_helper.rb
61
64
  homepage: http://github.com/zed-0xff/iostruct
62
65
  licenses:
63
66
  - MIT