bindata 2.4.14 → 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.
- checksums.yaml +4 -4
- data/ChangeLog.rdoc +20 -0
- data/LICENSE +25 -0
- data/NEWS.rdoc +5 -0
- data/README.md +6 -9
- data/bindata.gemspec +9 -4
- data/examples/NBT.txt +1 -1
- data/examples/list.rb +1 -1
- data/lib/bindata/alignment.rb +15 -7
- data/lib/bindata/array.rb +54 -54
- data/lib/bindata/base.rb +14 -25
- data/lib/bindata/base_primitive.rb +24 -20
- data/lib/bindata/bits.rb +5 -5
- data/lib/bindata/buffer.rb +89 -11
- data/lib/bindata/choice.rb +9 -6
- data/lib/bindata/count_bytes_remaining.rb +1 -1
- data/lib/bindata/delayed_io.rb +12 -11
- data/lib/bindata/dsl.rb +34 -32
- data/lib/bindata/float.rb +3 -3
- data/lib/bindata/framework.rb +8 -10
- data/lib/bindata/int.rb +9 -9
- data/lib/bindata/io.rb +276 -253
- data/lib/bindata/name.rb +1 -1
- data/lib/bindata/params.rb +9 -7
- data/lib/bindata/primitive.rb +3 -3
- data/lib/bindata/registry.rb +18 -18
- data/lib/bindata/rest.rb +1 -1
- data/lib/bindata/sanitize.rb +9 -16
- data/lib/bindata/section.rb +97 -0
- data/lib/bindata/skip.rb +140 -51
- data/lib/bindata/string.rb +9 -9
- data/lib/bindata/stringz.rb +12 -10
- data/lib/bindata/struct.rb +83 -66
- data/lib/bindata/trace.rb +35 -42
- data/lib/bindata/transform/brotli.rb +35 -0
- data/lib/bindata/transform/lz4.rb +35 -0
- data/lib/bindata/transform/lzma.rb +35 -0
- data/lib/bindata/transform/xor.rb +19 -0
- data/lib/bindata/transform/xz.rb +35 -0
- data/lib/bindata/transform/zlib.rb +33 -0
- data/lib/bindata/transform/zstd.rb +35 -0
- data/lib/bindata/uint8_array.rb +2 -2
- data/lib/bindata/version.rb +1 -1
- data/lib/bindata/virtual.rb +4 -7
- data/lib/bindata/warnings.rb +1 -1
- data/lib/bindata.rb +1 -0
- data/test/array_test.rb +10 -8
- data/test/buffer_test.rb +9 -0
- data/test/choice_test.rb +1 -1
- data/test/delayed_io_test.rb +16 -0
- data/test/io_test.rb +54 -246
- data/test/registry_test.rb +1 -1
- data/test/section_test.rb +111 -0
- data/test/skip_test.rb +55 -10
- data/test/string_test.rb +4 -4
- data/test/stringz_test.rb +8 -0
- data/test/struct_test.rb +87 -12
- data/test/system_test.rb +119 -1
- data/test/test_helper.rb +24 -13
- data/test/warnings_test.rb +12 -0
- metadata +19 -22
- data/.gitignore +0 -2
- data/.travis.yml +0 -15
- data/BSDL +0 -22
- data/COPYING +0 -52
- data/INSTALL +0 -12
- data/lib/bindata/offset.rb +0 -94
- data/test/offset_test.rb +0 -100
data/lib/bindata/offset.rb
DELETED
@@ -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
|
-
_ { 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
|
-
_ { 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
|
-
_ { 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
|
-
_ { obj.read(io) }.must_raise BinData::ValidityError
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|