Sha256: fd99ce4a2200f86d2efa6a670894d8b4f3c61c23ab0265df3a8a11c75d1e7f9b

Contents?: true

Size: 1.42 KB

Versions: 25

Compression:

Stored size: 1.42 KB

Contents

package snappy;

import java.io.IOException;

import org.jruby.RubyString;
import org.jruby.anno.JRubyModule;
import org.jruby.anno.JRubyMethod;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.util.ByteList;

import org.xerial.snappy.Snappy;


@JRubyModule(name = "Snappy")
public class SnappyModule {
  @JRubyMethod(module = true, name = {"deflate", "compress", "dump"})
  public static IRubyObject deflate(ThreadContext context, IRubyObject self, IRubyObject str) throws IOException {
    ByteList input = str.convertToString().getByteList();
    byte[] compressed = new byte[Snappy.maxCompressedLength(input.length())];
    int compressedLength = Snappy.compress(input.unsafeBytes(), input.begin(), input.length(), compressed, 0);
    return RubyString.newStringNoCopy(context.runtime, compressed, 0, compressedLength);
  }

  @JRubyMethod(module = true, name = {"inflate", "uncompress", "load"})
  public static IRubyObject inflate(ThreadContext context, IRubyObject self, IRubyObject str) throws IOException {
    ByteList input = str.convertToString().getByteList();
    byte[] uncompressed = new byte[Snappy.uncompressedLength(input.unsafeBytes(), input.begin(), input.length())];
    int uncompressedLength = Snappy.uncompress(input.unsafeBytes(), input.begin(), input.length(), uncompressed, 0);
    return RubyString.newStringNoCopy(context.runtime, uncompressed, 0, uncompressedLength);
  }
}

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
snappy-0.4.0-java ext/java/src/snappy/SnappyModule.java
snappy-0.4.0 ext/java/src/snappy/SnappyModule.java
snappy-0.3.0-java ext/java/src/snappy/SnappyModule.java
snappy-0.3.0 ext/java/src/snappy/SnappyModule.java
snappy-0.2.0-java ext/java/src/snappy/SnappyModule.java
snappy-0.2.0 ext/java/src/snappy/SnappyModule.java
snappy-0.1.0-java ext/java/src/snappy/SnappyModule.java
snappy-0.1.0 ext/java/src/snappy/SnappyModule.java
snappy-0.0.17-java ext/java/src/snappy/SnappyModule.java
snappy-0.0.17 ext/java/src/snappy/SnappyModule.java
snappy-0.0.16-java ext/java/src/snappy/SnappyModule.java
snappy-0.0.16 ext/java/src/snappy/SnappyModule.java
snappy-0.0.15-java ext/java/src/snappy/SnappyModule.java
snappy-0.0.15 ext/java/src/snappy/SnappyModule.java
snappy-0.0.14-java ext/java/src/snappy/SnappyModule.java
snappy-0.0.14 ext/java/src/snappy/SnappyModule.java
snappy-0.0.13 ext/java/src/snappy/SnappyModule.java
snappy-0.0.12-java ext/java/src/snappy/SnappyModule.java
snappy-0.0.12 ext/java/src/snappy/SnappyModule.java
snappy-0.0.11-java ext/java/src/snappy/SnappyModule.java