lz4-ruby 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZDM4YzE2NGYyYzdiNDU4YjA3ODgwNjQxNzNmOTA3ZTA2YjYzZDM5OQ==
5
- data.tar.gz: !binary |-
6
- NWE2YjViZTBlMmJhYTA0MzdhMmNkZDlkZTU3YTM2NDMyMzc4M2Q1Mw==
7
- SHA512:
8
- metadata.gz: !binary |-
9
- ODQ4NDY1M2QyOTMyNmY3ODc3ODRkMjY4ZTZiZTVkZjRjMjliY2I0NjkzZGE4
10
- ZWFlMzFhNDRlNjdhMTA0M2U4MTYwMTVjMzkwNDZjN2Y4ZThmMDQwZDY5ZWE4
11
- Y2E2NTYyNjVkZTQxZGRkMWY0OTlhNDQ2ZWRkODUxMzM2MzZiNWQ=
12
- data.tar.gz: !binary |-
13
- NWFlZTk2YTJkYWVmOGUzMzg4NTk3M2Q3ZTIwZDc0OTk0ZGQ4M2Q0OWQ3Mjc3
14
- MWJkNTAyN2Q1YjRhMzcxYmJjMDZiZWUwMjNjMTRiYzMxNDM3MWI1MzJmNzRh
15
- MGEwZmI2NDZmMGMwZjQ4YzQ5YjM0YTI0NDIyODFhNTc2ZTJkMTM=
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9e448ed6f9089c138a3fdcbeef623017bd7a1a62
4
+ data.tar.gz: bf53570a680e34e0ee1e5ecd870f0aefe07a829d
5
+ SHA512:
6
+ metadata.gz: bb93608ac0552471cf08024250ed9a1e852986354b0f45510331e268c263178bd8645ebcb2b80ea19b161f73ccb1834e2ded78b0a3dc06d33fe10c28428cb9b4
7
+ data.tar.gz: 72c49a6b79c4ed2f2fc7b216df48ac100cde562d53dbf14089c751ff96e1aecad849aef27330e355dd328b6d8b434e031e3dd3ed2eacb7a782db0583bfc491b7
@@ -33,8 +33,8 @@ Tested on VirtualBox VM : 2-core / 4GB RAM (Host : Core i5-2520M / 8GB RAM).
33
33
 
34
34
  == TODO
35
35
 
36
- * Support raw data handling methods for JRuby.
37
36
  * Support streaming methods.
37
+ * Support compression level (LZ4HC)
38
38
  * Write API documents.
39
39
 
40
40
  == Copyright
data/Rakefile CHANGED
@@ -77,7 +77,7 @@ task :gems do
77
77
  sh "rake clean build"
78
78
  end
79
79
 
80
- task "build:cross" => [:modify_gemspec_for_windows, :cross, :build] do
80
+ task "build:cross" => [:modify_gemspec_for_windows, :build] do
81
81
  file = "pkg/lz4-ruby-#{get_version}.gem"
82
82
  end
83
83
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
@@ -1,7 +1,9 @@
1
1
  package com.headius.jruby.lz4;
2
2
 
3
3
  import net.jpountz.lz4.LZ4Compressor;
4
+ import net.jpountz.lz4.LZ4Exception;
4
5
  import net.jpountz.lz4.LZ4Factory;
6
+ import org.jruby.RubyArray;
5
7
  import org.jruby.RubyInteger;
6
8
  import org.jruby.RubyString;
7
9
  import org.jruby.anno.JRubyMethod;
@@ -9,56 +11,270 @@ import org.jruby.runtime.ThreadContext;
9
11
  import org.jruby.runtime.builtin.IRubyObject;
10
12
  import org.jruby.util.ByteList;
11
13
 
14
+ import java.util.Arrays;
15
+
16
+ @SuppressWarnings("UnusedParameters")
12
17
  public class LZ4Internal {
13
18
  private static final LZ4Factory FACTORY = LZ4Factory.fastestInstance();
14
-
15
- public static IRubyObject compress_internal(ThreadContext context, LZ4Compressor compressor, IRubyObject _header, IRubyObject _input, IRubyObject _in_size) {
16
- RubyString input = _input.convertToString();
17
- RubyString header = _header.convertToString();
18
- RubyInteger in_size = _in_size.convertToInteger();
19
-
20
- ByteList inputBL = input.getByteList();
21
- int srcSize = (int)in_size.getLongValue();
22
-
23
- ByteList headerBL = header.getByteList();
24
- int headerSize = headerBL.getRealSize();
25
-
26
- int bufSize = compressor.maxCompressedLength(srcSize);
27
- byte[] buf = new byte[bufSize + headerSize];
28
-
29
- System.arraycopy(headerBL.getUnsafeBytes(), headerBL.getBegin(), buf, 0, headerSize);
30
-
31
- compressor.compress(inputBL.getUnsafeBytes(), inputBL.getBegin(), srcSize, buf, headerSize);
32
-
33
- return RubyString.newStringNoCopy(context.runtime, buf);
19
+
20
+ private static RubyArray compressInternal(
21
+ ThreadContext context,
22
+ LZ4Compressor compressor,
23
+ IRubyObject _header,
24
+ IRubyObject _input,
25
+ IRubyObject _inputSize,
26
+ IRubyObject _outputBuffer,
27
+ IRubyObject _maxOutputSize) {
28
+
29
+ byte[] headerBytes = {};
30
+ int headerSize = 0;
31
+ if (isNotNil(_header)) {
32
+ ByteList header = _header.convertToString().getByteList();
33
+ headerBytes = header.getUnsafeBytes();
34
+ headerSize = header.getRealSize();
35
+ }
36
+
37
+ int inputSize = intFrom(_inputSize);
38
+ ByteOutput output;
39
+ if (isNotNil(_outputBuffer)) {
40
+ output = new ByteOutput(_outputBuffer, _maxOutputSize);
41
+
42
+ } else if (isNotNil(_maxOutputSize)) {
43
+ int maxOutputSize = intFrom(_maxOutputSize) + headerSize;
44
+ output = new ByteOutput(maxOutputSize);
45
+
46
+ } else {
47
+ int maxOutputSize = compressor.maxCompressedLength(inputSize) + headerSize;
48
+ output = new ByteOutput(maxOutputSize);
49
+ }
50
+
51
+ System.arraycopy(
52
+ headerBytes, 0,
53
+ output.unsafeBytes, 0,
54
+ headerSize);
55
+
56
+ ByteInput input = new ByteInput(_input);
57
+ try {
58
+ int compressedSize = compressor.compress(
59
+ input.unsafeBytes, input.offset, inputSize,
60
+ output.unsafeBytes, output.offset + headerSize, output.bufferSize - headerSize);
61
+
62
+ return RubyArray.newArray(context.runtime, Arrays.asList(
63
+ output.toRubyString(context, compressedSize + headerSize),
64
+ RubyInteger.int2fix(context.runtime, compressedSize)));
65
+
66
+ } catch (LZ4Exception ignore) {
67
+ return RubyArray.newArray(context.runtime, Arrays.asList(
68
+ null,
69
+ RubyInteger.int2fix(context.runtime, -1)));
70
+ }
34
71
  }
35
-
72
+
73
+ private static RubyArray decompressInternal(
74
+ ThreadContext context,
75
+ IRubyObject _offset,
76
+ IRubyObject _input,
77
+ IRubyObject _inputSize,
78
+ IRubyObject _outputBuffer,
79
+ IRubyObject _maxOutputSize) {
80
+
81
+ int offset = 0;
82
+ if (isNotNil(_offset)) {
83
+ offset = intFrom(_offset);
84
+ }
85
+
86
+ ByteOutput output;
87
+ if (isNotNil(_outputBuffer)) {
88
+ output = new ByteOutput(_outputBuffer, _maxOutputSize);
89
+
90
+ } else {
91
+ output = new ByteOutput(intFrom(_maxOutputSize));
92
+ }
93
+
94
+ ByteInput input = new ByteInput(_input);
95
+ try {
96
+ int decompressedSize = FACTORY.unknwonSizeDecompressor()
97
+ .decompress(
98
+ input.unsafeBytes, input.offset + offset, intFrom(_inputSize) - offset,
99
+ output.unsafeBytes, output.offset, output.bufferSize);
100
+
101
+ return RubyArray.newArray(context.runtime, Arrays.asList(
102
+ output.toRubyString(context, decompressedSize),
103
+ RubyInteger.int2fix(context.runtime, decompressedSize)));
104
+
105
+ } catch (LZ4Exception ignore) {
106
+ return RubyArray.newArray(context.runtime, Arrays.asList(
107
+ null,
108
+ RubyInteger.int2fix(context.runtime, -1)));
109
+ }
110
+ }
111
+
36
112
  @JRubyMethod(module = true)
37
113
  public static IRubyObject compress(ThreadContext context, IRubyObject self, IRubyObject _header, IRubyObject _input, IRubyObject _in_size) {
38
- return compress_internal(context, FACTORY.fastCompressor(), _header, _input, _in_size);
114
+ RubyArray array = compressInternal(context,
115
+ FACTORY.fastCompressor(),
116
+ _header,
117
+ _input,
118
+ _in_size,
119
+ null,
120
+ null);
121
+ return array.first();
39
122
  }
40
-
123
+
41
124
  @JRubyMethod(module = true)
42
125
  public static IRubyObject compressHC(ThreadContext context, IRubyObject self, IRubyObject _header, IRubyObject _input, IRubyObject _in_size) {
43
- return compress_internal(context, FACTORY.highCompressor(), _header, _input, _in_size);
126
+ RubyArray array = compressInternal(context,
127
+ FACTORY.highCompressor(),
128
+ _header,
129
+ _input,
130
+ _in_size,
131
+ null,
132
+ null);
133
+ return array.first();
44
134
  }
45
-
135
+
46
136
  @JRubyMethod(required = 4, module = true)
47
137
  public static IRubyObject uncompress(ThreadContext context, IRubyObject self, IRubyObject[] args) {
48
138
  RubyString input = args[0].convertToString();
49
139
  RubyInteger in_size = args[1].convertToInteger();
50
140
  RubyInteger header_size = args[2].convertToInteger();
51
141
  RubyInteger buf_size = args[3].convertToInteger();
52
-
53
- ByteList inputBL = input.getByteList();
54
- int inSize = (int)in_size.getLongValue();
55
- int headerSize = (int)header_size.getLongValue();
56
- int bufSize = (int)buf_size.getLongValue();
57
-
58
- byte[] buf = new byte[bufSize];
59
-
60
- FACTORY.decompressor().decompress(inputBL.getUnsafeBytes(), inputBL.getBegin() + headerSize, buf, 0, buf.length);
61
-
62
- return RubyString.newStringNoCopy(context.runtime, buf);
142
+
143
+ RubyArray array = decompressInternal(context,
144
+ header_size,
145
+ input,
146
+ in_size,
147
+ null,
148
+ buf_size);
149
+ return array.first();
150
+ }
151
+
152
+ @JRubyMethod(required = 4, module = true)
153
+ public static IRubyObject compress_raw(
154
+ ThreadContext context,
155
+ IRubyObject self,
156
+ IRubyObject[] args) {
157
+
158
+ IRubyObject _input = args[0];
159
+ IRubyObject _inputSize = args[1];
160
+ IRubyObject _outputBuffer = args[2];
161
+ IRubyObject _maxOutputSize = args[3];
162
+
163
+ return compressInternal(context,
164
+ FACTORY.fastCompressor(),
165
+ null,
166
+ _input,
167
+ _inputSize,
168
+ _outputBuffer,
169
+ _maxOutputSize);
170
+ }
171
+
172
+ @JRubyMethod(required = 4, module = true)
173
+ public static IRubyObject compressHC_raw(
174
+ ThreadContext context,
175
+ IRubyObject self,
176
+ IRubyObject[] args) {
177
+
178
+ IRubyObject _input = args[0];
179
+ IRubyObject _inputSize = args[1];
180
+ IRubyObject _outputBuffer = args[2];
181
+ IRubyObject _maxOutputSize = args[3];
182
+
183
+ return compressInternal(context,
184
+ FACTORY.highCompressor(),
185
+ null,
186
+ _input,
187
+ _inputSize,
188
+ _outputBuffer,
189
+ _maxOutputSize);
190
+ }
191
+
192
+ @JRubyMethod(required = 4, module = true)
193
+ public static IRubyObject decompress_raw(
194
+ ThreadContext context,
195
+ IRubyObject self,
196
+ IRubyObject[] args) {
197
+
198
+ IRubyObject _input = args[0];
199
+ IRubyObject _inputSize = args[1];
200
+ IRubyObject _outputBuffer = args[2];
201
+ IRubyObject _maxOutputSize = args[3];
202
+
203
+ return decompressInternal(
204
+ context,
205
+ null,
206
+ _input,
207
+ _inputSize,
208
+ _outputBuffer,
209
+ _maxOutputSize);
210
+ }
211
+
212
+ static class ByteInput {
213
+ public final RubyString rubyString;
214
+ public final ByteList byteList;
215
+ public final byte[] unsafeBytes;
216
+ public final int offset;
217
+ public final int realSize;
218
+
219
+ public ByteInput(IRubyObject buffer) {
220
+ rubyString = buffer.convertToString();
221
+ byteList = rubyString.getByteList();
222
+ unsafeBytes = byteList.getUnsafeBytes();
223
+ offset = byteList.getBegin();
224
+ realSize = byteList.getRealSize();
225
+ }
226
+ }
227
+
228
+ static class ByteOutput {
229
+ public final RubyString rubyString;
230
+ public final ByteList byteList;
231
+ public final byte[] unsafeBytes;
232
+ public final int offset;
233
+ public final int bufferSize;
234
+
235
+ public ByteOutput(IRubyObject buffer, IRubyObject size) {
236
+ bufferSize = intFrom(size);
237
+ rubyString = buffer.convertToString();
238
+ byteList = rubyString.getByteList();
239
+ unsafeBytes = byteList.getUnsafeBytes();
240
+ offset = byteList.getBegin();
241
+ }
242
+
243
+ public ByteOutput(int size) {
244
+ bufferSize = size;
245
+ rubyString = null;
246
+ byteList = null;
247
+ unsafeBytes = new byte[bufferSize];
248
+ offset = 0;
249
+ }
250
+
251
+ RubyString toRubyString(ThreadContext context, int length) {
252
+ if (rubyString != null) {
253
+ return rubyString;
254
+ }
255
+
256
+ return RubyString.newString(context.runtime, unsafeBytes, 0, length);
257
+ }
258
+ }
259
+
260
+ /**
261
+ * Test if specified IRubyObject is not null / nil.
262
+ *
263
+ * @param obj
264
+ * @return
265
+ */
266
+ private static boolean isNotNil(IRubyObject obj) {
267
+ return obj != null && !obj.isNil();
268
+ }
269
+
270
+ /**
271
+ * Returns a integer value from specified IRubyObject.
272
+ *
273
+ * @param obj
274
+ * @return
275
+ */
276
+ private static int intFrom(IRubyObject obj) {
277
+ RubyInteger rubyInt = obj.convertToInteger();
278
+ return (int) rubyInt.getLongValue();
63
279
  }
64
280
  }
metadata CHANGED
@@ -1,94 +1,73 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: lz4-ruby
3
- version: !ruby/object:Gem::Version
4
- version: 0.3.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.1
5
5
  platform: ruby
6
- authors:
6
+ authors:
7
7
  - KOMIYA Atsushi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-10 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
11
+
12
+ date: 2014-04-30 00:00:00 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
14
15
  name: rspec
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ! '>='
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :development
16
+ version_requirements: &id001 !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - &id003
19
+ - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: "0"
21
22
  prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ! '>='
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
23
+ requirement: *id001
24
+ type: :development
25
+ - !ruby/object:Gem::Dependency
28
26
  name: rdoc
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
27
+ version_requirements: &id002 !ruby/object:Gem::Requirement
28
+ requirements:
31
29
  - - ~>
32
- - !ruby/object:Gem::Version
33
- version: '3.12'
34
- type: :development
30
+ - !ruby/object:Gem::Version
31
+ version: "3.12"
35
32
  prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ~>
39
- - !ruby/object:Gem::Version
40
- version: '3.12'
41
- - !ruby/object:Gem::Dependency
42
- name: bundler
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ! '>='
46
- - !ruby/object:Gem::Version
47
- version: '0'
33
+ requirement: *id002
48
34
  type: :development
35
+ - !ruby/object:Gem::Dependency
36
+ name: bundler
37
+ version_requirements: &id004 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - *id003
49
40
  prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ! '>='
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
41
+ requirement: *id004
42
+ type: :development
43
+ - !ruby/object:Gem::Dependency
56
44
  name: jeweler
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
45
+ version_requirements: &id005 !ruby/object:Gem::Requirement
46
+ requirements:
59
47
  - - ~>
60
- - !ruby/object:Gem::Version
48
+ - !ruby/object:Gem::Version
61
49
  version: 1.8.3
62
- type: :development
63
50
  prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ~>
67
- - !ruby/object:Gem::Version
68
- version: 1.8.3
69
- - !ruby/object:Gem::Dependency
70
- name: rake-compiler
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ! '>='
74
- - !ruby/object:Gem::Version
75
- version: '0'
51
+ requirement: *id005
76
52
  type: :development
53
+ - !ruby/object:Gem::Dependency
54
+ name: rake-compiler
55
+ version_requirements: &id006 !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - *id003
77
58
  prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ! '>='
81
- - !ruby/object:Gem::Version
82
- version: '0'
59
+ requirement: *id006
60
+ type: :development
83
61
  description: Ruby bindings for LZ4. LZ4 is a very fast lossless compression algorithm.
84
62
  email: komiya.atsushi@gmail.com
85
63
  executables: []
86
- extensions:
64
+
65
+ extensions:
87
66
  - ext/lz4ruby/extconf.rb
88
- extra_rdoc_files:
67
+ extra_rdoc_files:
89
68
  - LICENSE.txt
90
69
  - README.rdoc
91
- files:
70
+ files:
92
71
  - .document
93
72
  - CHANGELOG.rdoc
94
73
  - Gemfile
@@ -120,27 +99,27 @@ files:
120
99
  - src/main/java/com/headius/jruby/lz4/LZ4Internal.java
121
100
  - src/main/java/com/headius/jruby/lz4/LZ4Library.java
122
101
  homepage: http://github.com/komiya-atsushi/lz4-ruby
123
- licenses:
102
+ licenses:
124
103
  - MIT
125
104
  metadata: {}
105
+
126
106
  post_install_message:
127
107
  rdoc_options: []
128
- require_paths:
108
+
109
+ require_paths:
129
110
  - lib
130
- required_ruby_version: !ruby/object:Gem::Requirement
131
- requirements:
132
- - - ! '>='
133
- - !ruby/object:Gem::Version
134
- version: '0'
135
- required_rubygems_version: !ruby/object:Gem::Requirement
136
- requirements:
137
- - - ! '>='
138
- - !ruby/object:Gem::Version
139
- version: '0'
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - *id003
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - *id003
140
117
  requirements: []
118
+
141
119
  rubyforge_project:
142
- rubygems_version: 2.2.2
120
+ rubygems_version: 2.0.14
143
121
  signing_key:
144
122
  specification_version: 4
145
123
  summary: Ruby bindings for LZ4 (Extremely Fast Compression algorithm).
146
124
  test_files: []
125
+