lz4-ruby 0.3.0-x86-mingw32 → 0.3.1-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
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: 890642c4d06de124d0a709a6a6db65777e2558e1b89112f574948394dd74e9eec76bb61f801ae19560846c690b5573331199df279c6f0f7b5cbec276cd80104b
7
- data.tar.gz: e28522bcd5286436bc6a6ba17de758f12de1ea13be588e8d3d2711425fb463ae3245b0747d700096a45e9a18ec0fcf3b93eeca976f38baf569c637391450b566
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
@@ -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
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
- 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,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.0
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-03-10 00:00:00 Z
12
+ date: 2014-04-30 00:00:00 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- prerelease: false
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
- prerelease: false
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
- prerelease: false
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
- prerelease: false
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
- prerelease: false
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: []