lz4-ruby 0.3.0-x86-mingw32 → 0.3.1-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.
- checksums.yaml +5 -5
- data/README.rdoc +1 -1
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/1.8/lz4ruby.so +0 -0
- data/lib/1.9/lz4ruby.so +0 -0
- data/src/main/java/com/headius/jruby/lz4/LZ4Internal.java +252 -36
- metadata +17 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: c4a6dc0313da950fdc6b9ac8efdbd234834aa2dc
|
4
|
-
data.tar.gz: d480a328c933234263e461674e376d869cb5b1b9
|
5
2
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b7c8c4031ace9a7f264e898dc540b46b5edbbd4cc8a9a9b5a94fa9c6315f66ab9a2f9e0a36625926f3cce0cf1a30cc930584a6ec38977f3f5b4e254db3a7360b
|
4
|
+
data.tar.gz: 29b2866d4403c1063aac1df854a61df93017d8d401df4172b6658e4c1d4e6ba1a77c328c9f6b9e85e2f5bbd7af6a042bd5ad1afc8d8b156a1a592c552b527bb8
|
5
|
+
SHA1:
|
6
|
+
metadata.gz: 66d782a5410a36a003d0dcecd58cde8a266aa839
|
7
|
+
data.tar.gz: 6cae50481f8df11d006d051b5ee46082db5ee6c6
|
data/README.rdoc
CHANGED
@@ -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
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.1
|
data/lib/1.8/lz4ruby.so
CHANGED
Binary file
|
data/lib/1.9/lz4ruby.so
CHANGED
Binary file
|
@@ -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
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
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,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lz4-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
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: 2014-
|
12
|
+
date: 2014-04-30 00:00:00 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
|
17
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
18
17
|
requirements:
|
19
18
|
- &id003
|
20
19
|
- ">="
|
21
20
|
- !ruby/object:Gem::Version
|
22
21
|
version: "0"
|
22
|
+
prerelease: false
|
23
|
+
requirement: *id001
|
23
24
|
type: :development
|
24
|
-
version_requirements: *id001
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rdoc
|
27
|
-
|
28
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
27
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
29
28
|
requirements:
|
30
29
|
- - ~>
|
31
30
|
- !ruby/object:Gem::Version
|
32
31
|
version: "3.12"
|
32
|
+
prerelease: false
|
33
|
+
requirement: *id002
|
33
34
|
type: :development
|
34
|
-
version_requirements: *id002
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: bundler
|
37
|
-
|
38
|
-
requirement: &id004 !ruby/object:Gem::Requirement
|
37
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
39
38
|
requirements:
|
40
39
|
- *id003
|
40
|
+
prerelease: false
|
41
|
+
requirement: *id004
|
41
42
|
type: :development
|
42
|
-
version_requirements: *id004
|
43
43
|
- !ruby/object:Gem::Dependency
|
44
44
|
name: jeweler
|
45
|
-
|
46
|
-
requirement: &id005 !ruby/object:Gem::Requirement
|
45
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
47
46
|
requirements:
|
48
47
|
- - ~>
|
49
48
|
- !ruby/object:Gem::Version
|
50
49
|
version: 1.8.3
|
50
|
+
prerelease: false
|
51
|
+
requirement: *id005
|
51
52
|
type: :development
|
52
|
-
version_requirements: *id005
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
54
|
name: rake-compiler
|
55
|
-
|
56
|
-
requirement: &id006 !ruby/object:Gem::Requirement
|
55
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
57
56
|
requirements:
|
58
57
|
- *id003
|
58
|
+
prerelease: false
|
59
|
+
requirement: *id006
|
59
60
|
type: :development
|
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: []
|