lz4-ruby 0.2.0-x86-mingw32 → 0.3.0-x86-mingw32

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,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,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lz4-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: x86-mingw32
6
6
  authors:
7
7
  - KOMIYA Atsushi
@@ -9,55 +9,55 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2013-12-02 00:00:00 Z
12
+ date: 2014-03-10 00:00:00 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- version_requirements: &id001 !ruby/object:Gem::Requirement
15
+ name: rspec
16
+ prerelease: false
17
+ requirement: &id001 !ruby/object:Gem::Requirement
16
18
  requirements:
17
19
  - &id003
18
20
  - ">="
19
21
  - !ruby/object:Gem::Version
20
22
  version: "0"
21
23
  type: :development
22
- name: rspec
23
- prerelease: false
24
- requirement: *id001
24
+ version_requirements: *id001
25
25
  - !ruby/object:Gem::Dependency
26
- version_requirements: &id002 !ruby/object:Gem::Requirement
26
+ name: rdoc
27
+ prerelease: false
28
+ requirement: &id002 !ruby/object:Gem::Requirement
27
29
  requirements:
28
30
  - - ~>
29
31
  - !ruby/object:Gem::Version
30
32
  version: "3.12"
31
33
  type: :development
32
- name: rdoc
33
- prerelease: false
34
- requirement: *id002
34
+ version_requirements: *id002
35
35
  - !ruby/object:Gem::Dependency
36
- version_requirements: &id004 !ruby/object:Gem::Requirement
36
+ name: bundler
37
+ prerelease: false
38
+ requirement: &id004 !ruby/object:Gem::Requirement
37
39
  requirements:
38
40
  - *id003
39
41
  type: :development
40
- name: bundler
41
- prerelease: false
42
- requirement: *id004
42
+ version_requirements: *id004
43
43
  - !ruby/object:Gem::Dependency
44
- version_requirements: &id005 !ruby/object:Gem::Requirement
44
+ name: jeweler
45
+ prerelease: false
46
+ requirement: &id005 !ruby/object:Gem::Requirement
45
47
  requirements:
46
48
  - - ~>
47
49
  - !ruby/object:Gem::Version
48
50
  version: 1.8.3
49
51
  type: :development
50
- name: jeweler
51
- prerelease: false
52
- requirement: *id005
52
+ version_requirements: *id005
53
53
  - !ruby/object:Gem::Dependency
54
- version_requirements: &id006 !ruby/object:Gem::Requirement
54
+ name: rake-compiler
55
+ prerelease: false
56
+ requirement: &id006 !ruby/object:Gem::Requirement
55
57
  requirements:
56
58
  - *id003
57
59
  type: :development
58
- name: rake-compiler
59
- prerelease: false
60
- requirement: *id006
60
+ version_requirements: *id006
61
61
  description: Ruby bindings for LZ4. LZ4 is a very fast lossless compression algorithm.
62
62
  email: komiya.atsushi@gmail.com
63
63
  executables: []
@@ -69,6 +69,7 @@ extra_rdoc_files:
69
69
  - README.rdoc
70
70
  files:
71
71
  - .document
72
+ - CHANGELOG.rdoc
72
73
  - Gemfile
73
74
  - LICENSE.txt
74
75
  - README.rdoc
@@ -94,6 +95,9 @@ files:
94
95
  - spec/helper.rb
95
96
  - spec/lz4_compressHC_spec.rb
96
97
  - spec/lz4_compress_spec.rb
98
+ - spec/lz4_raw_compress_spec.rb
99
+ - spec/lz4_raw_decompress_spec.rb
100
+ - spec/lz4_raw_spec.rb
97
101
  - src/main/java/com/headius/jruby/lz4/LZ4Internal.java
98
102
  - src/main/java/com/headius/jruby/lz4/LZ4Library.java
99
103
  homepage: http://github.com/komiya-atsushi/lz4-ruby