bindata 2.4.10 → 2.5.0

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.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog.rdoc +39 -0
  3. data/LICENSE +25 -0
  4. data/NEWS.rdoc +5 -0
  5. data/README.md +6 -9
  6. data/bindata.gemspec +9 -4
  7. data/examples/NBT.txt +1 -1
  8. data/examples/list.rb +1 -1
  9. data/lib/bindata/alignment.rb +15 -7
  10. data/lib/bindata/array.rb +54 -54
  11. data/lib/bindata/base.rb +14 -25
  12. data/lib/bindata/base_primitive.rb +24 -20
  13. data/lib/bindata/bits.rb +15 -15
  14. data/lib/bindata/buffer.rb +89 -11
  15. data/lib/bindata/choice.rb +9 -6
  16. data/lib/bindata/count_bytes_remaining.rb +1 -1
  17. data/lib/bindata/delayed_io.rb +18 -10
  18. data/lib/bindata/dsl.rb +37 -35
  19. data/lib/bindata/float.rb +3 -3
  20. data/lib/bindata/framework.rb +8 -10
  21. data/lib/bindata/int.rb +14 -16
  22. data/lib/bindata/io.rb +276 -253
  23. data/lib/bindata/name.rb +1 -1
  24. data/lib/bindata/params.rb +9 -7
  25. data/lib/bindata/primitive.rb +3 -3
  26. data/lib/bindata/registry.rb +18 -18
  27. data/lib/bindata/rest.rb +1 -1
  28. data/lib/bindata/sanitize.rb +9 -16
  29. data/lib/bindata/section.rb +97 -0
  30. data/lib/bindata/skip.rb +140 -51
  31. data/lib/bindata/string.rb +9 -9
  32. data/lib/bindata/stringz.rb +12 -10
  33. data/lib/bindata/struct.rb +92 -68
  34. data/lib/bindata/trace.rb +35 -42
  35. data/lib/bindata/transform/brotli.rb +35 -0
  36. data/lib/bindata/transform/lz4.rb +35 -0
  37. data/lib/bindata/transform/lzma.rb +35 -0
  38. data/lib/bindata/transform/xor.rb +19 -0
  39. data/lib/bindata/transform/xz.rb +35 -0
  40. data/lib/bindata/transform/zlib.rb +33 -0
  41. data/lib/bindata/transform/zstd.rb +35 -0
  42. data/lib/bindata/uint8_array.rb +2 -2
  43. data/lib/bindata/version.rb +1 -1
  44. data/lib/bindata/virtual.rb +4 -7
  45. data/lib/bindata/warnings.rb +1 -1
  46. data/lib/bindata.rb +1 -0
  47. data/test/alignment_test.rb +8 -8
  48. data/test/array_test.rb +98 -96
  49. data/test/base_primitive_test.rb +47 -47
  50. data/test/base_test.rb +24 -24
  51. data/test/bits_test.rb +15 -15
  52. data/test/buffer_test.rb +31 -22
  53. data/test/choice_test.rb +32 -32
  54. data/test/count_bytes_remaining_test.rb +8 -8
  55. data/test/delayed_io_test.rb +91 -30
  56. data/test/float_test.rb +8 -8
  57. data/test/int_test.rb +14 -14
  58. data/test/io_test.rb +110 -302
  59. data/test/lazy_test.rb +38 -38
  60. data/test/params_test.rb +19 -19
  61. data/test/primitive_test.rb +26 -26
  62. data/test/record_test.rb +99 -99
  63. data/test/registry_test.rb +43 -43
  64. data/test/rest_test.rb +5 -5
  65. data/test/section_test.rb +111 -0
  66. data/test/skip_test.rb +71 -26
  67. data/test/string_test.rb +60 -60
  68. data/test/stringz_test.rb +34 -26
  69. data/test/struct_test.rb +167 -92
  70. data/test/system_test.rb +159 -41
  71. data/test/test_helper.rb +24 -13
  72. data/test/uint8_array_test.rb +6 -6
  73. data/test/virtual_test.rb +7 -7
  74. data/test/warnings_test.rb +14 -2
  75. metadata +19 -22
  76. data/.gitignore +0 -2
  77. data/.travis.yml +0 -15
  78. data/BSDL +0 -22
  79. data/COPYING +0 -52
  80. data/INSTALL +0 -12
  81. data/lib/bindata/offset.rb +0 -94
  82. data/test/offset_test.rb +0 -100
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bindata
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.10
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dion Mendel
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-18 00:00:00.000000000 Z
11
+ date: 1980-01-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -31,9 +31,6 @@ dependencies:
31
31
  - - ">"
32
32
  - !ruby/object:Gem::Version
33
33
  version: 5.0.0
34
- - - "<"
35
- - !ruby/object:Gem::Version
36
- version: 5.12.0
37
34
  type: :development
38
35
  prerelease: false
39
36
  version_requirements: !ruby/object:Gem::Requirement
@@ -41,11 +38,8 @@ dependencies:
41
38
  - - ">"
42
39
  - !ruby/object:Gem::Version
43
40
  version: 5.0.0
44
- - - "<"
45
- - !ruby/object:Gem::Version
46
- version: 5.12.0
47
41
  - !ruby/object:Gem::Dependency
48
- name: coveralls
42
+ name: simplecov
49
43
  requirement: !ruby/object:Gem::Requirement
50
44
  requirements:
51
45
  - - ">="
@@ -71,13 +65,9 @@ extensions: []
71
65
  extra_rdoc_files:
72
66
  - NEWS.rdoc
73
67
  files:
74
- - ".gitignore"
75
- - ".travis.yml"
76
- - BSDL
77
- - COPYING
78
68
  - ChangeLog.rdoc
79
69
  - Gemfile
80
- - INSTALL
70
+ - LICENSE
81
71
  - NEWS.rdoc
82
72
  - README.md
83
73
  - Rakefile
@@ -105,18 +95,25 @@ files:
105
95
  - lib/bindata/io.rb
106
96
  - lib/bindata/lazy.rb
107
97
  - lib/bindata/name.rb
108
- - lib/bindata/offset.rb
109
98
  - lib/bindata/params.rb
110
99
  - lib/bindata/primitive.rb
111
100
  - lib/bindata/record.rb
112
101
  - lib/bindata/registry.rb
113
102
  - lib/bindata/rest.rb
114
103
  - lib/bindata/sanitize.rb
104
+ - lib/bindata/section.rb
115
105
  - lib/bindata/skip.rb
116
106
  - lib/bindata/string.rb
117
107
  - lib/bindata/stringz.rb
118
108
  - lib/bindata/struct.rb
119
109
  - lib/bindata/trace.rb
110
+ - lib/bindata/transform/brotli.rb
111
+ - lib/bindata/transform/lz4.rb
112
+ - lib/bindata/transform/lzma.rb
113
+ - lib/bindata/transform/xor.rb
114
+ - lib/bindata/transform/xz.rb
115
+ - lib/bindata/transform/zlib.rb
116
+ - lib/bindata/transform/zstd.rb
120
117
  - lib/bindata/uint8_array.rb
121
118
  - lib/bindata/version.rb
122
119
  - lib/bindata/virtual.rb
@@ -134,12 +131,12 @@ files:
134
131
  - test/int_test.rb
135
132
  - test/io_test.rb
136
133
  - test/lazy_test.rb
137
- - test/offset_test.rb
138
134
  - test/params_test.rb
139
135
  - test/primitive_test.rb
140
136
  - test/record_test.rb
141
137
  - test/registry_test.rb
142
138
  - test/rest_test.rb
139
+ - test/section_test.rb
143
140
  - test/skip_test.rb
144
141
  - test/string_test.rb
145
142
  - test/stringz_test.rb
@@ -151,9 +148,9 @@ files:
151
148
  - test/warnings_test.rb
152
149
  homepage: https://github.com/dmendel/bindata
153
150
  licenses:
154
- - Ruby
151
+ - BSD-2-Clause
155
152
  metadata: {}
156
- post_install_message:
153
+ post_install_message:
157
154
  rdoc_options:
158
155
  - "--main"
159
156
  - NEWS.rdoc
@@ -163,15 +160,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
163
160
  requirements:
164
161
  - - ">="
165
162
  - !ruby/object:Gem::Version
166
- version: '0'
163
+ version: 2.5.0
167
164
  required_rubygems_version: !ruby/object:Gem::Requirement
168
165
  requirements:
169
166
  - - ">="
170
167
  - !ruby/object:Gem::Version
171
168
  version: '0'
172
169
  requirements: []
173
- rubygems_version: 3.1.4
174
- signing_key:
170
+ rubygems_version: 3.4.22
171
+ signing_key:
175
172
  specification_version: 4
176
173
  summary: A declarative way to read and write binary file formats
177
174
  test_files: []
data/.gitignore DELETED
@@ -1,2 +0,0 @@
1
- Gemfile.lock
2
- wiki
data/.travis.yml DELETED
@@ -1,15 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.2
4
- - 2.3
5
- - 2.4
6
- - 2.5
7
- - 2.6
8
- - 2.7
9
- - jruby
10
- - ruby-head
11
-
12
- matrix:
13
- allow_failures:
14
- - rvm: jruby
15
- - rvm: ruby-head
data/BSDL DELETED
@@ -1,22 +0,0 @@
1
- Copyright (C) 2007-2012 Dion Mendel. All rights reserved.
2
-
3
- Redistribution and use in source and binary forms, with or without
4
- modification, are permitted provided that the following conditions
5
- are met:
6
- 1. Redistributions of source code must retain the above copyright
7
- notice, this list of conditions and the following disclaimer.
8
- 2. Redistributions in binary form must reproduce the above copyright
9
- notice, this list of conditions and the following disclaimer in the
10
- documentation and/or other materials provided with the distribution.
11
-
12
- THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
13
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15
- ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
16
- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
18
- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19
- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20
- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
21
- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
22
- SUCH DAMAGE.
data/COPYING DELETED
@@ -1,52 +0,0 @@
1
- BinData is copyrighted free software by Dion Mendel <bindata@dm9.info>.
2
- You can redistribute it and/or modify it under either the terms of the
3
- 2-clause BSDL (see the file BSDL), or the conditions below:
4
-
5
- 1. You may make and give away verbatim copies of the source form of the
6
- software without restriction, provided that you duplicate all of the
7
- original copyright notices and associated disclaimers.
8
-
9
- 2. You may modify your copy of the software in any way, provided that
10
- you do at least ONE of the following:
11
-
12
- a) place your modifications in the Public Domain or otherwise
13
- make them Freely Available, such as by posting said
14
- modifications to Usenet or an equivalent medium, or by allowing
15
- the author to include your modifications in the software.
16
-
17
- b) use the modified software only within your corporation or
18
- organization.
19
-
20
- c) give non-standard binaries non-standard names, with
21
- instructions on where to get the original software distribution.
22
-
23
- d) make other distribution arrangements with the author.
24
-
25
- 3. You may distribute the software in object code or binary form,
26
- provided that you do at least ONE of the following:
27
-
28
- a) distribute the binaries and library files of the software,
29
- together with instructions (in the manual page or equivalent)
30
- on where to get the original distribution.
31
-
32
- b) accompany the distribution with the machine-readable source of
33
- the software.
34
-
35
- c) give non-standard binaries non-standard names, with
36
- instructions on where to get the original software distribution.
37
-
38
- d) make other distribution arrangements with the author.
39
-
40
- 4. You may modify and include the part of the software into any other
41
- software (possibly commercial).
42
-
43
- 5. The scripts and library files supplied as input to or produced as
44
- output from the software do not automatically fall under the
45
- copyright of the software, but belong to whomever generated them,
46
- and may be sold commercially, and may be aggregated with this
47
- software.
48
-
49
- 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
50
- IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
51
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
52
- PURPOSE.
data/INSTALL DELETED
@@ -1,12 +0,0 @@
1
- This package is designed to be installed with rubygems.
2
-
3
- $ gem install bindata
4
-
5
- If you are using ruby 1.8
6
-
7
- $ gem install bindata -v '~> 1.8.0'
8
-
9
- If you are not using rubygems, you may like to install BinData with
10
- Minero Aoki's setup.rb found at:
11
-
12
- https://github.com/rubyworks/setup
@@ -1,94 +0,0 @@
1
- module BinData
2
- # WARNING: THIS IS UNSUPPORTED!!
3
- #
4
- # This was a (failed) experimental feature that allowed seeking within the
5
- # input stream. It remains here for backwards compatability for the few
6
- # people that used it.
7
- #
8
- # The official way to skip around the stream is to use BinData::Skip with
9
- # the `:to_abs_offset` parameter.
10
- #
11
- # == Parameters
12
- #
13
- # Parameters may be provided at initialisation to control the behaviour of
14
- # an object. These parameters are:
15
- #
16
- # [<tt>:check_offset</tt>] Raise an error if the current IO offset doesn't
17
- # meet this criteria. A boolean return indicates
18
- # success or failure. Any other return is compared
19
- # to the current offset. The variable +offset+
20
- # is made available to any lambda assigned to
21
- # this parameter. This parameter is only checked
22
- # before reading.
23
- # [<tt>:adjust_offset</tt>] Ensures that the current IO offset is at this
24
- # position before reading. This is like
25
- # <tt>:check_offset</tt>, except that it will
26
- # adjust the IO offset instead of raising an error.
27
- module CheckOrAdjustOffsetPlugin
28
-
29
- def self.included(base) #:nodoc:
30
- base.optional_parameters :check_offset, :adjust_offset
31
- base.mutually_exclusive_parameters :check_offset, :adjust_offset
32
- end
33
-
34
- def initialize_shared_instance
35
- extend CheckOffsetMixin if has_parameter?(:check_offset)
36
- extend AdjustOffsetMixin if has_parameter?(:adjust_offset)
37
- super
38
- end
39
-
40
- module CheckOffsetMixin
41
- def do_read(io) #:nodoc:
42
- check_offset(io)
43
- super(io)
44
- end
45
-
46
- #---------------
47
- private
48
-
49
- def check_offset(io)
50
- actual_offset = io.offset
51
- expected = eval_parameter(:check_offset, offset: actual_offset)
52
-
53
- if !expected
54
- raise ValidityError, "offset not as expected for #{debug_name}"
55
- elsif actual_offset != expected && expected != true
56
- raise ValidityError,
57
- "offset is '#{actual_offset}' but " +
58
- "expected '#{expected}' for #{debug_name}"
59
- end
60
- end
61
- end
62
-
63
- module AdjustOffsetMixin
64
- def do_read(io) #:nodoc:
65
- adjust_offset(io)
66
- super(io)
67
- end
68
-
69
- #---------------
70
- private
71
-
72
- def adjust_offset(io)
73
- actual_offset = io.offset
74
- expected = eval_parameter(:adjust_offset)
75
- if actual_offset != expected
76
- begin
77
- seek = expected - actual_offset
78
- io.seekbytes(seek)
79
- warn "adjusting stream position by #{seek} bytes" if $VERBOSE
80
- rescue
81
- raise ValidityError,
82
- "offset is '#{actual_offset}' but couldn't seek to " +
83
- "expected '#{expected}' for #{debug_name}"
84
- end
85
- end
86
- end
87
- end
88
- end
89
-
90
- # Add these offset options to Base
91
- class Base
92
- include CheckOrAdjustOffsetPlugin
93
- end
94
- end
data/test/offset_test.rb DELETED
@@ -1,100 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require File.expand_path(File.join(File.dirname(__FILE__), "test_helper"))
4
- require 'bindata/offset'
5
-
6
- describe BinData::Base, "offsets" do
7
- class ThreeByteReader < BinData::Base
8
- def do_read(io)
9
- @val = io.readbytes(3)
10
- end
11
-
12
- def snapshot
13
- @val
14
- end
15
- end
16
-
17
- class TenByteOffsetBase < BinData::Base
18
- def self.create(params)
19
- obj = self.new
20
- obj.initialize_child(params)
21
- obj
22
- end
23
-
24
- def initialize_child(params)
25
- @child = ThreeByteReader.new(params, self)
26
- end
27
-
28
- def snapshot
29
- @child.snapshot
30
- end
31
-
32
- def do_read(io)
33
- io.seekbytes(10)
34
- @child.do_read(io)
35
- end
36
-
37
- def clear
38
- end
39
- end
40
-
41
- let(:data) { "0123456789abcdefghijk" }
42
- let(:io) { StringIO.new(data) }
43
-
44
- describe "with :check_offset" do
45
- it "fails when offset is incorrect" do
46
- io.seek(2)
47
- obj = TenByteOffsetBase.create(check_offset: 10 - 4)
48
- lambda { obj.read(io) }.must_raise BinData::ValidityError
49
- end
50
-
51
- it "succeeds when offset is correct" do
52
- io.seek(3)
53
- obj = TenByteOffsetBase.create(check_offset: 10)
54
- obj.read(io).snapshot.must_equal data[3 + 10, 3]
55
- end
56
-
57
- it "fails when :check_offset fails" do
58
- io.seek(4)
59
- obj = TenByteOffsetBase.create(check_offset: -> { offset == 10 + 1 } )
60
- lambda { obj.read(io) }.must_raise BinData::ValidityError
61
- end
62
-
63
- it "succeeds when :check_offset succeeds" do
64
- io.seek(5)
65
- obj = TenByteOffsetBase.create(check_offset: -> { offset == 10 } )
66
- obj.read(io).snapshot.must_equal data[5 + 10, 3]
67
- end
68
- end
69
-
70
- describe "with :adjust_offset" do
71
- it "is mutually exclusive with :check_offset" do
72
- params = { check_offset: 8, adjust_offset: 8 }
73
- lambda { TenByteOffsetBase.create(params) }.must_raise ArgumentError
74
- end
75
-
76
- it "adjust offset when incorrect" do
77
- w, $-w = $-w, false
78
-
79
- begin
80
- io.seek(2)
81
- obj = TenByteOffsetBase.create(adjust_offset: 13)
82
- obj.read(io).snapshot.must_equal data[2 + 13, 3]
83
- ensure
84
- $-w = w
85
- end
86
- end
87
-
88
- it "succeeds when offset is correct" do
89
- io.seek(3)
90
- obj = TenByteOffsetBase.create(adjust_offset: 10)
91
- obj.read(io).snapshot.must_equal data[3 + 10, 3]
92
- end
93
-
94
- it "fails if cannot adjust offset" do
95
- io.seek(4)
96
- obj = TenByteOffsetBase.create(adjust_offset: -5)
97
- lambda { obj.read(io) }.must_raise BinData::ValidityError
98
- end
99
- end
100
- end