extlz4 0.2.4.2

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.
@@ -0,0 +1,3 @@
1
+ module LZ4
2
+ VERSION = "0.2.4.2"
3
+ end
@@ -0,0 +1,18 @@
1
+ require "openssl" # for OpenSSL::Random.random_bytes
2
+ require "digest"
3
+
4
+ SMALLSIZE = 400
5
+ BIGSIZE = 12000000
6
+
7
+ SAMPLES = {
8
+ "empty" => "",
9
+ "\\0 (small size)" => "\0".b * SMALLSIZE,
10
+ "\\0 (big size)" => "\0".b * BIGSIZE,
11
+ "\\xaa (small size)" => "\xaa".b * SMALLSIZE,
12
+ "\\xaa (big size)" => "\xaa".b * BIGSIZE,
13
+ "random (small size)" => OpenSSL::Random.random_bytes(SMALLSIZE),
14
+ "random (big size)" => OpenSSL::Random.random_bytes(BIGSIZE),
15
+ }
16
+
17
+ SAMPLES["freebsd ports index"] = File.read("/usr/ports/INDEX-10", mode: "rb") rescue nil # if on FreeBSD
18
+ SAMPLES["freebsd kernel"] = File.read("/boot/kernel/kernel", mode: "rb") rescue nil # if on FreeBSD
@@ -0,0 +1,105 @@
1
+ #!ruby
2
+
3
+ require "test-unit"
4
+ require "extlz4"
5
+
6
+ require_relative "common"
7
+
8
+ class TestBlockAPI < Test::Unit::TestCase
9
+ unless Object.const_defined?(:FrozenError)
10
+ # NOTE: FrozenError は ruby-2.5 で登場
11
+ FrozenError = RuntimeError
12
+ end
13
+
14
+ SAMPLES.each_pair do |name, data|
15
+ [-20, -10, -1, nil, 0, 1, 9].each do |level|
16
+ define_method("test_block_encode_decode_sample:#{name}:level=#{level.inspect}", -> {
17
+ assert(data, LZ4.block_decode(LZ4.block_encode(level, data)))
18
+ })
19
+
20
+ [[], [data]].each do |opt_dict|
21
+ define_method("test_streaming_block_encode_decode:#{name}:level=#{level.inspect}#{opt_dict.empty? ? nil : ":with predict"}", -> {
22
+ lz4 = LZ4.block_stream_encode level, *opt_dict
23
+ input = StringIO.new(data)
24
+ buf = "".b
25
+ blocks = []
26
+ input.size.times do |size|
27
+ break unless input.read((1 << size) + 1, buf)
28
+ blocks << lz4.update(buf)
29
+ end
30
+ lz4.free
31
+
32
+ lz4 = LZ4.block_stream_decode *opt_dict
33
+ data1 = "".b
34
+ blocks.each do |b|
35
+ data1 << lz4.update(b)
36
+ end
37
+ lz4.free
38
+
39
+ assert(data, data1)
40
+ })
41
+ end
42
+ end
43
+ end
44
+
45
+ def test_block_encode
46
+ buf = ""
47
+ assert_kind_of(String, LZ4.block_encode(SAMPLES["\\0 (small size)"]))
48
+ assert_kind_of(String, LZ4.block_encode(SAMPLES["\\0 (small size)"], 1000))
49
+ assert_same(buf, LZ4.block_encode(SAMPLES["\\0 (small size)"], buf))
50
+ assert_same(buf, LZ4.block_encode(SAMPLES["\\0 (small size)"], 1000, buf))
51
+ assert_same(buf, LZ4.block_encode(nil, SAMPLES["\\0 (small size)"], 1000, buf))
52
+
53
+ # high speed
54
+ assert_kind_of(String, LZ4.block_encode(-15, SAMPLES["\\0 (small size)"]))
55
+ assert_kind_of(String, LZ4.block_encode(-15, SAMPLES["\\0 (small size)"], 1000))
56
+ assert_same(buf, LZ4.block_encode(-15, SAMPLES["\\0 (small size)"], buf))
57
+ assert_same(buf, LZ4.block_encode(-15, SAMPLES["\\0 (small size)"], 1000, buf))
58
+
59
+ # high compression
60
+ assert_kind_of(String, LZ4.block_encode(0, SAMPLES["\\0 (small size)"]))
61
+ assert_kind_of(String, LZ4.block_encode(0, SAMPLES["\\0 (small size)"], 1000))
62
+ assert_same(buf, LZ4.block_encode(0, SAMPLES["\\0 (small size)"], buf))
63
+ assert_same(buf, LZ4.block_encode(0, SAMPLES["\\0 (small size)"], 1000, buf))
64
+ end
65
+
66
+ def test_block_encode_invalid_args
67
+ src = SAMPLES["\\0 (small size)"]
68
+ buf = ""
69
+ assert_raise(ArgumentError) { LZ4.block_encode } # no arguments
70
+ assert_raise(TypeError) { LZ4.block_encode(100) } # source is not string
71
+ assert_raise(TypeError) { LZ4.block_encode(nil) } # source is not string
72
+ assert_raise(TypeError) { LZ4.block_encode(:bad_input) } # source is not string
73
+ assert_raise(TypeError) { LZ4.block_encode(/bad-input/) } # source is not string
74
+ assert_raise(FrozenError) { LZ4.block_encode(src, "bad-destbuf".freeze) } # can't modify frozen String
75
+ assert_raise(LZ4::Error) { LZ4.block_encode(src, 1) } # maxdest is too small
76
+ assert_raise(LZ4::Error) { LZ4.block_encode(src, 1, buf) } # maxdest is too small
77
+ assert_raise(TypeError) { LZ4.block_encode(src, "bad-maxsize", "a") } # "bad-maxsize" is not integer
78
+ end
79
+
80
+ def test_block_decode
81
+ src = LZ4.block_encode(SAMPLES["\\0 (small size)"])
82
+ buf = ""
83
+ assert_kind_of(String, LZ4.block_decode(src))
84
+ assert_kind_of(String, LZ4.block_decode(src, 1000))
85
+ assert_same(buf, LZ4.block_decode(src, buf))
86
+ assert_same(buf, LZ4.block_decode(src, 1000, buf))
87
+ end
88
+
89
+ def test_block_decode_invalid_args
90
+ src = LZ4.block_encode(SAMPLES["\\0 (small size)"])
91
+ buf = ""
92
+ assert_raise(ArgumentError) { LZ4.block_decode } # no arguments
93
+ assert_raise(TypeError) { LZ4.block_decode(-1, src) } # do not given level
94
+ assert_raise(TypeError) { LZ4.block_decode(100) } # source is not string
95
+ assert_raise(TypeError) { LZ4.block_decode(nil) } # source is not string
96
+ assert_raise(TypeError) { LZ4.block_decode(:bad_input) } # source is not string
97
+ assert_raise(TypeError) { LZ4.block_decode(/bad-input/) } # source is not string
98
+ assert_raise(FrozenError) { LZ4.block_decode(src, "bad-destbuf".freeze) } # can't modify frozen String
99
+ assert_raise(TypeError) { LZ4.block_decode(src, "bad-maxsize", "a") } # "bad-maxsize" is not integer
100
+
101
+ src2 = SAMPLES["\\xaa (small size)"]
102
+ assert_raise(LZ4::Error) { LZ4.block_decode(src2) } # encounted invalid end of sequence
103
+ assert_raise(LZ4::Error) { LZ4.block_decode(src2, 100000) } # max_dest_size is too small, or data is corrupted
104
+ end
105
+ end
@@ -0,0 +1,59 @@
1
+ #!ruby
2
+
3
+ =begin
4
+ # 必要と思われる試験項目
5
+
6
+ * LZ4.encode
7
+ * LZ4.decode で伸長できるか
8
+ * lz4-cli で伸長できるか
9
+ * 汚染状態の伝搬
10
+ * security level
11
+ * LZ4.encode_file
12
+ * LZ4.decode_file で伸長できるか
13
+ * lz4-cli で伸長できるか
14
+ * LZ4.decode
15
+ * LZ4.decode_file
16
+ * LZ4.test_file
17
+
18
+ * 試験で用いる試料
19
+ * /usr/ports/INDEX-10
20
+ * /boot/kernel/kernel
21
+ * 長さ 0 の空データ
22
+ * 0 で埋められた小さなデータ
23
+ * 0 で埋められたでかいデータ
24
+ * 0xaa で埋められた小さなデータ
25
+ * 0xaa で埋められたでかいデータ
26
+ * /dev/random (4000 bytes)
27
+ * /dev/random (12000000 bytes)
28
+ * 可能であれば数十 GB レベルのファイル
29
+ =end
30
+
31
+ require "test-unit"
32
+ require "extlz4"
33
+
34
+ require_relative "common"
35
+
36
+ class TestFrameAPI < Test::Unit::TestCase
37
+ SAMPLES.each_pair do |name, data|
38
+ define_method("test_encode_decode_sample:#{name}", -> {
39
+ assert_equal(Digest::MD5.hexdigest(data), Digest::MD5.hexdigest(LZ4.decode(LZ4.encode(data))))
40
+ })
41
+ end
42
+
43
+ def test_encode_args
44
+ assert_kind_of(LZ4::Encoder, LZ4.encode)
45
+ assert_kind_of(LZ4::Encoder, LZ4.encode(StringIO.new("")))
46
+ assert_kind_of(String, LZ4.encode {})
47
+ io = StringIO.new("")
48
+ assert_same(io, LZ4.encode(io) {})
49
+ assert_kind_of(LZ4::Encoder, LZ4.encode(io, 16))
50
+ assert_kind_of(LZ4::Encoder, LZ4::Encoder.new)
51
+ end
52
+
53
+ def test_decode_args
54
+ assert_raise(ArgumentError) { LZ4.decode }
55
+ assert_raise(NoMethodError) { LZ4.decode(nil) } # undefined method `read' for nil:NilClass
56
+ assert_raise(LZ4::Error) { LZ4.decode("") } # read error (or already EOF)
57
+ assert_raise(ArgumentError) { LZ4.decode(nil, nil) } # wrong number of arguments (2 for 1)
58
+ end
59
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: extlz4
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.4.2
5
+ platform: ruby
6
+ authors:
7
+ - dearblue
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-01-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: 'ruby bindings for LZ4 <https://github.com/lz4/lz4>.
28
+
29
+ '
30
+ email: dearblue@users.noreply.github.com
31
+ executables:
32
+ - extlz4
33
+ extensions:
34
+ - ext/extconf.rb
35
+ extra_rdoc_files:
36
+ - HISTORY.ja.md
37
+ - LICENSE
38
+ - README.md
39
+ - contrib/lz4/LICENSE
40
+ - contrib/lz4/README.md
41
+ - contrib/lz4/lib/LICENSE
42
+ - contrib/lz4/lib/README.md
43
+ - ext/blockapi.c
44
+ - ext/extlz4.c
45
+ - ext/extlz4.h
46
+ - ext/frameapi.c
47
+ - ext/hashargs.c
48
+ - ext/hashargs.h
49
+ - ext/lz4_amalgam.c
50
+ - lib/extlz4.rb
51
+ - lib/extlz4/compat.rb
52
+ - lib/extlz4/fix-0.1bug.rb
53
+ - lib/extlz4/oldstream.rb
54
+ - lib/extlz4/version.rb
55
+ files:
56
+ - HISTORY.ja.md
57
+ - LICENSE
58
+ - README.md
59
+ - Rakefile
60
+ - bin/extlz4
61
+ - contrib/lz4/INSTALL
62
+ - contrib/lz4/LICENSE
63
+ - contrib/lz4/NEWS
64
+ - contrib/lz4/README.md
65
+ - contrib/lz4/circle.yml
66
+ - contrib/lz4/lib/LICENSE
67
+ - contrib/lz4/lib/README.md
68
+ - contrib/lz4/lib/liblz4.pc.in
69
+ - contrib/lz4/lib/lz4.c
70
+ - contrib/lz4/lib/lz4.h
71
+ - contrib/lz4/lib/lz4frame.c
72
+ - contrib/lz4/lib/lz4frame.h
73
+ - contrib/lz4/lib/lz4frame_static.h
74
+ - contrib/lz4/lib/lz4hc.c
75
+ - contrib/lz4/lib/lz4hc.h
76
+ - contrib/lz4/lib/lz4opt.h
77
+ - contrib/lz4/lib/xxhash.c
78
+ - contrib/lz4/lib/xxhash.h
79
+ - examples/frameapi.rb
80
+ - ext/blockapi.c
81
+ - ext/depend
82
+ - ext/extconf.rb
83
+ - ext/extlz4.c
84
+ - ext/extlz4.h
85
+ - ext/frameapi.c
86
+ - ext/hashargs.c
87
+ - ext/hashargs.h
88
+ - ext/lz4_amalgam.c
89
+ - gemstub.rb
90
+ - lib/extlz4.rb
91
+ - lib/extlz4/compat.rb
92
+ - lib/extlz4/fix-0.1bug.rb
93
+ - lib/extlz4/oldstream.rb
94
+ - lib/extlz4/version.rb
95
+ - test/common.rb
96
+ - test/test_blockapi.rb
97
+ - test/test_frameapi.rb
98
+ homepage: https://github.com/dearblue/ruby-extlz4
99
+ licenses:
100
+ - BSD-2-Clause
101
+ metadata: {}
102
+ post_install_message:
103
+ rdoc_options:
104
+ - "--charset"
105
+ - UTF-8
106
+ - "-m"
107
+ - README.md
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.6.14
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: ruby bindings for LZ4
126
+ test_files: []