lz4-ruby 0.2.0 → 0.3.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.
@@ -17,6 +17,10 @@ describe "LZ4::compress" do
17
17
  compressed = LZ4.compressHC(text)
18
18
  uncompressed = LZ4.uncompress(compressed)
19
19
 
20
+ it "should be compressed length less than original text" do
21
+ expect(compressed.size).to be < text.length
22
+ end
23
+
20
24
  it "should be able to uncompress" do
21
25
  expect(uncompressed).to eql(text)
22
26
  end
@@ -17,6 +17,10 @@ describe "LZ4::compress" do
17
17
  compressed = LZ4.compress(text)
18
18
  uncompressed = LZ4.uncompress(compressed)
19
19
 
20
+ it "should be compressed length less than original text" do
21
+ expect(compressed.size).to be < text.length
22
+ end
23
+
20
24
  it "should be able to uncompress" do
21
25
  expect(uncompressed).to eql(text)
22
26
  end
@@ -0,0 +1,152 @@
1
+ require './spec/helper'
2
+
3
+ describe "LZ4::Raw::compress" do
4
+ context "give empty text" do
5
+ compressed, size = LZ4::Raw.compress("")
6
+
7
+ expected = [0x00]
8
+
9
+ it "should be compressed to length #{expected.size}" do
10
+ expect(size).to eql(expected.size)
11
+ expect(compressed.size).to eql(expected.size)
12
+ end
13
+
14
+ it "should be compressed into '#{expected}'" do
15
+ expect(compressed).to eql(expected.pack("C*"))
16
+ end
17
+ end
18
+
19
+ context "give text #{text = "aaaaaaaaaaaaaaaaaaaa"}" do
20
+ expected = [0x1a, 0x61, 0x01, 0x00, 0x50, 0x61, 0x61, 0x61, 0x61, 0x61]
21
+
22
+ context "without output buffer" do
23
+ compressed, size = LZ4::Raw.compress(text)
24
+
25
+ it "should be compressed to length #{expected.size}" do
26
+ expect(size).to eql(expected.size)
27
+ expect(compressed.size).to eql(expected.size)
28
+ end
29
+
30
+ it "should be compressed into '#{expected}'" do
31
+ expect(compressed).to eql(expected.pack("C*"))
32
+ end
33
+ end
34
+
35
+ context "with input_size" do
36
+ context "(3) which is less than input text length (#{text.length})" do
37
+ input_size = 3
38
+ compressed, size = LZ4::Raw.compress(text, :input_size => input_size)
39
+
40
+ aaa_ex = [0x30, 0x61, 0x61, 0x61]
41
+
42
+ it "should be compressed to length #{aaa_ex.size}" do
43
+ expect(size).to eql(aaa_ex.size)
44
+ expect(compressed.size).to eql(aaa_ex.size)
45
+ end
46
+
47
+ it "should be compressed into #{aaa_ex}" do
48
+ expect(compressed).to eql(aaa_ex.pack("C*"))
49
+ end
50
+ end
51
+
52
+ context "(30) which is greater than input text length (#{text.length})" do
53
+ input_size = 30
54
+ it "should be thrown ArgumentError" do
55
+ expect {
56
+ compressed, size = LZ4::Raw.compress(text, :input_size => input_size)
57
+ }.to raise_error(ArgumentError, "`:input_size` (30) must be less than or equal `source.length` (20)")
58
+ end
59
+ end
60
+ end
61
+
62
+ context "with output buffer" do
63
+ context "enough buffer size: 10" do
64
+ out_buf_size = 10
65
+ out_buf = " " * out_buf_size
66
+
67
+ compressed, size = LZ4::Raw.compress(text, :dest => out_buf)
68
+
69
+ it "should be compressed to length #{expected.size}" do
70
+ expect(size).to eql(expected.size)
71
+ end
72
+
73
+ it "should be unchanged output buffer size" do
74
+ expect(compressed.size).to eql(out_buf_size)
75
+ end
76
+
77
+ it "should be compressed into '#{expected}'" do
78
+ expect(compressed[0, size]).to eql(expected.pack("C*"))
79
+ end
80
+
81
+ it "should be used output buffer" do
82
+ expect(compressed).to eql(out_buf)
83
+ end
84
+ end
85
+
86
+ context "poor buffer size: 3" do
87
+ out_buf_size = 3
88
+ out_buf = " " * out_buf_size
89
+
90
+ it "shoud be thrown LZ4Error" do
91
+ expect {
92
+ compressed, size = LZ4::Raw.compress(text, :dest => out_buf)
93
+ }.to raise_error(LZ4Error, "compression failed")
94
+ end
95
+ end
96
+ end
97
+
98
+ context "with max_output_size" do
99
+ context "enough max_output_size: 10" do
100
+ max_output_size = 10
101
+ compressed, size = LZ4::Raw.compress(text, :max_output_size => max_output_size)
102
+
103
+ it "should be compressed to length #{expected.size}" do
104
+ expect(size).to eql(expected.size)
105
+ end
106
+
107
+ it "should be compressed into '#{expected}'" do
108
+ expect(compressed[0, size]).to eql(expected.pack("C*"))
109
+ end
110
+ end
111
+
112
+ context "poor max_output_size: 3" do
113
+ max_output_size = 3
114
+ it "shoud be thrown LZ4Error" do
115
+ expect {
116
+ compressed, size = LZ4::Raw.compress(text, :max_output_size => max_output_size)
117
+ }.to raise_error(LZ4Error, "compression failed")
118
+ end
119
+ end
120
+ end
121
+
122
+ context "with output buffer and max_output_size" do
123
+ context "when size of output buffer: 30, which is greater than max_output_size: 20" do
124
+ out_buf_size = 30
125
+ max_output_size = 20
126
+ out_buf = " " * out_buf_size
127
+
128
+ compressed, size = LZ4::Raw.compress(text, :dest => out_buf, :max_output_size => max_output_size)
129
+
130
+ it "should be compressed to length #{expected.size}" do
131
+ expect(size).to eql(expected.size)
132
+ end
133
+
134
+ it "should be compressed into '#{expected}'" do
135
+ expect(compressed[0, size]).to eql(expected.pack("C*"))
136
+ end
137
+ end
138
+
139
+ context "when size of output buffer: 10, which is less than max_output_size: 20" do
140
+ out_buf_size = 10
141
+ max_output_size = 20
142
+ out_buf = " " * out_buf_size
143
+
144
+ it "should be thrown ArgumentError" do
145
+ expect {
146
+ compressed, size = LZ4::Raw.compress(text, :dest => out_buf, :max_output_size => max_output_size)
147
+ }.to raise_error(ArgumentError, "`:dest` buffer size (10) must be greater than or equal `:max_output_size` (20)")
148
+ end
149
+ end
150
+ end
151
+ end
152
+ end
@@ -0,0 +1,129 @@
1
+ require './spec/helper'
2
+
3
+ describe "LZ4::Raw.decompress" do
4
+ context "give compressed empty text" do
5
+ decompressed, size = LZ4::Raw.decompress([0x00].pack("C*"), 0)
6
+
7
+ it "should be decompressed to length zero" do
8
+ expect(size).to eql(0)
9
+ expect(decompressed.size).to eql(0)
10
+ expect(decompressed).to eql("")
11
+ end
12
+ end
13
+
14
+ context "give compressed text '#{compressed = [0x1a, 0x61, 0x01, 0x00, 0x50, 0x61, 0x61, 0x61, 0x61, 0x61]}'" do
15
+ expected = "aaaaaaaaaaaaaaaaaaaa"
16
+
17
+ context "with enough max_output_size" do
18
+ decompressed, size = LZ4::Raw.decompress(compressed.pack("C*"), 30)
19
+
20
+ it "should be decompressed to length #{expected.size}" do
21
+ expect(size).to eql(expected.size)
22
+ expect(decompressed.size).to eql(expected.size)
23
+ end
24
+
25
+ it "should be decompressed into '#{expected}'" do
26
+ expect(decompressed).to eql(expected)
27
+ end
28
+ end
29
+
30
+ context "with poor max_output_size" do
31
+ it "should be thrown LZ4Error" do
32
+ expect {
33
+ decompressed, size = LZ4::Raw.decompress(compressed.pack("C*"), 10)
34
+ }.to raise_error LZ4Error, "decompression failed"
35
+ end
36
+ end
37
+
38
+ context "with input_size" do
39
+ context "#{compressed.length}, which is equal to compressed text length" do
40
+ decompressed, size = LZ4::Raw.decompress(compressed.pack("C*") + " ", 30, :input_size => compressed.size)
41
+
42
+ it "should be decompressed to length #{expected.size}" do
43
+ expect(size).to eql(expected.size)
44
+ expect(decompressed.size).to eql(expected.size)
45
+ end
46
+
47
+ it "should be decompressed into '#{expected}'" do
48
+ expect(decompressed).to eql(expected)
49
+ end
50
+ end
51
+
52
+ context "20 which is greater than compressed text length (#{compressed.length})" do
53
+ input_size = 20
54
+
55
+ it "should be thrown ArgumentError" do
56
+ expect {
57
+ decompressed, size = LZ4::Raw.decompress(compressed.pack("C*"), 30, :input_size => input_size)
58
+ }.to raise_error ArgumentError, "`:input_size` (20) must be less than or equal `source.length` (#{compressed.length})"
59
+ end
60
+ end
61
+ end
62
+
63
+ context "with output buffer" do
64
+ context "enough buffer size: 30" do
65
+ out_buf_size = 30
66
+ out_buf = " " * out_buf_size
67
+
68
+ decompressed, size = LZ4::Raw.decompress(compressed.pack("C*"), out_buf_size, :dest => out_buf)
69
+
70
+ it "should be decompressed to length #{expected.size}" do
71
+ expect(size).to eql(expected.size)
72
+ end
73
+
74
+ it "should be unchanged output buffer size" do
75
+ expect(decompressed.size).to eql(out_buf_size)
76
+ end
77
+
78
+ it "should be decompressed into '#{expected}'" do
79
+ expect(decompressed[0, size]).to eql(expected)
80
+ end
81
+
82
+ it "should be used output buffer" do
83
+ expect(decompressed).to eql(out_buf)
84
+ end
85
+ end
86
+
87
+ context "poor buffer size: 19" do
88
+ out_buf_size = 19
89
+ out_buf = " " * out_buf_size
90
+
91
+ it "should be thrown LZ4Error" do
92
+ expect {
93
+ decompressed, size = LZ4::Raw.decompress(compressed.pack("C*"), out_buf_size, :dest => out_buf)
94
+ }.to raise_error LZ4Error, "decompression failed"
95
+ end
96
+ end
97
+ end
98
+
99
+ context "with output buffer and max_output_size" do
100
+ context "when size of output buffer: 30, which is greater than max_output_size: 20" do
101
+ out_buf_size = 30
102
+ max_output_size = 20
103
+ out_buf = " " * out_buf_size
104
+
105
+ decompressed, size = LZ4::Raw.decompress(compressed.pack("C*"), max_output_size, :dest => out_buf)
106
+
107
+ it "should be decompressed to length #{expected.size}" do
108
+ expect(size).to eql(expected.size)
109
+ end
110
+
111
+ it "should be decompressed into '#{expected}'" do
112
+ expect(decompressed[0, size]).to eql(expected)
113
+ end
114
+ end
115
+
116
+ context "when size of output buffer: 10, which is less than max_output_size: 20" do
117
+ out_buf_size = 10
118
+ max_output_size = 20
119
+ out_buf = " " * out_buf_size
120
+
121
+ it "should be thrown ArgumentError" do
122
+ expect {
123
+ decompressed, size = LZ4::Raw.decompress(compressed.pack("C*"), max_output_size, :dest => out_buf)
124
+ }.to raise_error ArgumentError, "`:dest` buffer size (10) must be greater than or equal `max_output_size` (20)"
125
+ end
126
+ end
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,34 @@
1
+ require './spec/helper'
2
+
3
+ describe "LZ4::Raw compressibility" do
4
+ context "give 'lz4-ruby.rb' file" do
5
+ filename = "./lib/lz4-ruby.rb"
6
+ text = IO.readlines(filename).join("\n")
7
+
8
+ compressed, comp_size = LZ4::Raw.compress(text)
9
+ compressedHC, compHC_size = LZ4::Raw.compressHC(text)
10
+
11
+ decompressed, decomp_size = LZ4::Raw.decompress(compressed, text.length)
12
+ decompressedHC, decompHC_size = LZ4::Raw.decompress(compressedHC, text.length)
13
+
14
+ it "should be able to comprese smaller than original text" do
15
+ expect(comp_size).to be < text.length
16
+ end
17
+
18
+ it "should be able to compressHC smaller than original text" do
19
+ expect(compHC_size).to be < text.length
20
+ end
21
+
22
+ it "should be able to compressHC smaller than compress" do
23
+ expect(compHC_size).to be < comp_size
24
+ end
25
+
26
+ it "should be able to decompress from compressed text" do
27
+ expect(decompressed).to eql(text)
28
+ end
29
+
30
+ it "should be able to decompress from compressHCed text" do
31
+ expect(decompressedHC).to eql(text)
32
+ end
33
+ end
34
+ end
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lz4-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: !binary |-
5
- MC4yLjA=
4
+ version: 0.3.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - KOMIYA Atsushi
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-12-01 00:00:00.000000000 Z
11
+ date: 2014-03-10 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rspec
@@ -31,16 +30,14 @@ dependencies:
31
30
  requirements:
32
31
  - - ~>
33
32
  - !ruby/object:Gem::Version
34
- version: !binary |-
35
- My4xMg==
33
+ version: '3.12'
36
34
  type: :development
37
35
  prerelease: false
38
36
  version_requirements: !ruby/object:Gem::Requirement
39
37
  requirements:
40
38
  - - ~>
41
39
  - !ruby/object:Gem::Version
42
- version: !binary |-
43
- My4xMg==
40
+ version: '3.12'
44
41
  - !ruby/object:Gem::Dependency
45
42
  name: bundler
46
43
  requirement: !ruby/object:Gem::Requirement
@@ -61,16 +58,14 @@ dependencies:
61
58
  requirements:
62
59
  - - ~>
63
60
  - !ruby/object:Gem::Version
64
- version: !binary |-
65
- MS44LjM=
61
+ version: 1.8.3
66
62
  type: :development
67
63
  prerelease: false
68
64
  version_requirements: !ruby/object:Gem::Requirement
69
65
  requirements:
70
66
  - - ~>
71
67
  - !ruby/object:Gem::Version
72
- version: !binary |-
73
- MS44LjM=
68
+ version: 1.8.3
74
69
  - !ruby/object:Gem::Dependency
75
70
  name: rake-compiler
76
71
  requirement: !ruby/object:Gem::Requirement
@@ -95,6 +90,7 @@ extra_rdoc_files:
95
90
  - README.rdoc
96
91
  files:
97
92
  - .document
93
+ - CHANGELOG.rdoc
98
94
  - Gemfile
99
95
  - LICENSE.txt
100
96
  - README.rdoc
@@ -118,6 +114,9 @@ files:
118
114
  - spec/helper.rb
119
115
  - spec/lz4_compressHC_spec.rb
120
116
  - spec/lz4_compress_spec.rb
117
+ - spec/lz4_raw_compress_spec.rb
118
+ - spec/lz4_raw_decompress_spec.rb
119
+ - spec/lz4_raw_spec.rb
121
120
  - src/main/java/com/headius/jruby/lz4/LZ4Internal.java
122
121
  - src/main/java/com/headius/jruby/lz4/LZ4Library.java
123
122
  homepage: http://github.com/komiya-atsushi/lz4-ruby
@@ -140,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
139
  version: '0'
141
140
  requirements: []
142
141
  rubyforge_project:
143
- rubygems_version: 2.1.11
142
+ rubygems_version: 2.2.2
144
143
  signing_key:
145
144
  specification_version: 4
146
145
  summary: Ruby bindings for LZ4 (Extremely Fast Compression algorithm).