snappy 0.0.9-java

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 841d5e25d67e11a3d8fc876284e5a451578b4ced
4
+ data.tar.gz: 0ccbcf88ab4cfcc97cddc8215766172687e3e1c3
5
+ SHA512:
6
+ metadata.gz: 9389ce9c57f29a7d56a83679256e7e8b1a88ca07029e7e08a7f8fa3e4b5a3f875bfee7551dab4ab2561919bd8183bd5c1778e62750408637bbe96235c33aeb56
7
+ data.tar.gz: 91447b0e2b8e814576ac4569ce146f1da049cef16112ff828755980cc5883899052b9977e19fc4459dbe4db00934408a35ed3627a8f50e048a5c754659b0e336
data/.gitignore ADDED
@@ -0,0 +1,24 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ lib/snappy_ext.*
19
+ ext/Makefile
20
+ ext/config.h
21
+ ext/*.o
22
+ ext/*.log
23
+ ext/snappy*
24
+ ext/java/build
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in snappy.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2011-2013 miyucy
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # Snappy
2
+
3
+ see http://code.google.com/p/snappy
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'snappy'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install snappy
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ require 'snappy'
23
+
24
+ Snappy.deflate(source)
25
+ # => Compressed data
26
+
27
+ Snappy.inflate(source)
28
+ # => Decompressed data
29
+ ```
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,68 @@
1
+ require "bundler/setup"
2
+ require "bundler/gem_tasks"
3
+ require "rake/testtask"
4
+ require "rbconfig"
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.warning = true
8
+ t.verbose = true
9
+ end
10
+
11
+ if defined?(JRUBY_VERSION)
12
+ require 'ant'
13
+
14
+ directory 'ext/java/build'
15
+
16
+ task :setup => 'ext/java/build' do
17
+ ant.property name: 'src.dir', value: 'ext/java/src'
18
+ ant.property name: 'build.dir', value: 'ext/java/build'
19
+
20
+ ant.path id: 'compile.class.path' do
21
+ pathelement location: File.join(RbConfig::CONFIG['prefix'], 'lib', 'jruby.jar')
22
+ $LOAD_PATH.flat_map { |path| Dir[File.join(path, '**', '*.jar')] }.each do |jar|
23
+ pathelement location: jar
24
+ end
25
+ end
26
+ end
27
+
28
+ desc 'Compile the extension'
29
+ task :compile => :setup do
30
+ ant.javac destdir: '${build.dir}', includeantruntime: 'no', target: '1.6', source: '1.6', debug: 'on' do
31
+ classpath refid: 'compile.class.path'
32
+ src { pathelement location: '${src.dir}' }
33
+ end
34
+ end
35
+
36
+ desc 'Clean up build artifacts'
37
+ task :clean do
38
+ rm_rf 'ext/java/build'
39
+ rm_rf 'lib/snappy_ext.jar'
40
+ end
41
+
42
+ desc 'Package the jar'
43
+ file 'lib/snappy_ext.jar' => :compile do |t|
44
+ ant.jar destfile: 'lib/snappy_ext.jar', basedir: '${build.dir}' do
45
+ ant.fileset dir: '${build.dir}', includes: 'snappy/*.class'
46
+ ant.fileset dir: '${build.dir}', includes: 'SnappyExtLibraryService.class'
47
+ end
48
+ end
49
+
50
+ task :test => 'lib/snappy_ext.jar'
51
+ task :build => [:clean, 'lib/snappy_ext.jar']
52
+ else
53
+ DLEXT = RbConfig::CONFIG["DLEXT"]
54
+
55
+ file "ext/snappy_ext.#{DLEXT}" => Dir.glob("ext/*{.rb,.c}") do
56
+ Dir.chdir("ext") do
57
+ ruby "extconf.rb"
58
+ sh "make"
59
+ end
60
+ cp "ext/snappy_ext.#{DLEXT}", "lib/snappy_ext.#{DLEXT}"
61
+ end
62
+
63
+ task :clean do
64
+ rm_rf(["ext/snappy_ext.#{DLEXT}", "lib/snappy_ext.#{DLEXT}", "ext/mkmf.log", "ext/config.h", "ext/api.o", "ext/Makefile", "ext/snappy.cc", "ext/snappy.h", "ext/snappy.o"] + Dir["ext/snappy-*"])
65
+ end
66
+
67
+ task :test => "ext/snappy_ext.#{DLEXT}"
68
+ end
data/ext/api.c ADDED
@@ -0,0 +1,95 @@
1
+ #include "ruby.h"
2
+ #include "snappy-c.h"
3
+
4
+ static VALUE rb_mSnappy;
5
+ static VALUE rb_eSnappy;
6
+
7
+ static VALUE
8
+ snappy_raise(snappy_status result)
9
+ {
10
+ if (result == SNAPPY_INVALID_INPUT) {
11
+ rb_raise(rb_eSnappy, "INVALID INPUT");
12
+ } else if (result == SNAPPY_BUFFER_TOO_SMALL) {
13
+ rb_raise(rb_eSnappy, "BUFFER TOO SMALL");
14
+ } else {
15
+ rb_raise(rb_eSnappy, "ERROR");
16
+ }
17
+ return Qnil;
18
+ }
19
+
20
+ static VALUE
21
+ snappy_deflate(int argc, VALUE *argv, VALUE self)
22
+ {
23
+ VALUE src, dst;
24
+ size_t output_length;
25
+ snappy_status result;
26
+
27
+ rb_scan_args(argc, argv, "11", &src, &dst);
28
+ StringValue(src);
29
+
30
+ output_length = snappy_max_compressed_length(RSTRING_LEN(src));
31
+
32
+ if (NIL_P(dst)) {
33
+ dst = rb_str_new(NULL, output_length);
34
+ } else {
35
+ StringValue(dst);
36
+ rb_str_resize(dst, output_length);
37
+ }
38
+
39
+ result = snappy_compress(RSTRING_PTR(src), RSTRING_LEN(src), RSTRING_PTR(dst), &output_length);
40
+ if (result == SNAPPY_OK) {
41
+ rb_str_resize(dst, output_length);
42
+ return dst;
43
+ } else {
44
+ return snappy_raise(result);
45
+ }
46
+ }
47
+
48
+ static VALUE
49
+ snappy_inflate(int argc, VALUE *argv, VALUE self)
50
+ {
51
+ VALUE src, dst;
52
+ size_t output_length;
53
+ snappy_status result;
54
+
55
+ rb_scan_args(argc, argv, "11", &src, &dst);
56
+ StringValue(src);
57
+
58
+ result = snappy_uncompressed_length(RSTRING_PTR(src), RSTRING_LEN(src), &output_length);
59
+ if (result != SNAPPY_OK) {
60
+ return snappy_raise(result);
61
+ }
62
+
63
+ if (NIL_P(dst)) {
64
+ dst = rb_str_new(NULL, output_length);
65
+ } else {
66
+ StringValue(dst);
67
+ rb_str_resize(dst, output_length);
68
+ }
69
+
70
+ result = snappy_uncompress(RSTRING_PTR(src), RSTRING_LEN(src), RSTRING_PTR(dst), &output_length);
71
+ if (result != SNAPPY_OK) {
72
+ return snappy_raise(result);
73
+ }
74
+
75
+ StringValue(dst);
76
+ rb_str_resize(dst, output_length);
77
+
78
+ return dst;
79
+ }
80
+
81
+ void Init_snappy_ext()
82
+ {
83
+ rb_mSnappy = rb_define_module("Snappy");
84
+ rb_eSnappy = rb_define_class_under(rb_mSnappy, "Error", rb_eStandardError);
85
+ rb_define_singleton_method(rb_mSnappy, "deflate", snappy_deflate, -1);
86
+ rb_define_singleton_method(rb_mSnappy, "inflate", snappy_inflate, -1);
87
+
88
+ VALUE rb_mSnappy_singleton = rb_singleton_class(rb_mSnappy);
89
+
90
+ rb_define_alias(rb_mSnappy_singleton, "compress", "deflate");
91
+ rb_define_alias(rb_mSnappy_singleton, "dump", "deflate");
92
+
93
+ rb_define_alias(rb_mSnappy_singleton, "uncompress", "inflate");
94
+ rb_define_alias(rb_mSnappy_singleton, "load", "inflate");
95
+ }
data/ext/extconf.rb ADDED
@@ -0,0 +1,39 @@
1
+ require 'mkmf'
2
+ require 'fileutils'
3
+
4
+ unless have_library 'snappy_ext'
5
+ dst = File.dirname File.expand_path __FILE__
6
+
7
+ tar = 'tar'
8
+ tar = 'gnutar' if find_executable 'gnutar'
9
+
10
+ ver = "1.1.0"
11
+ src = "snappy-#{ver}"
12
+
13
+ FileUtils.rm_rf File.join dst, src
14
+ system "curl -s http://snappy.googlecode.com/files/#{src}.tar.gz | #{tar} xz"
15
+
16
+ src = File.join dst, src
17
+
18
+ Dir.chdir src do
19
+ system "./configure --disable-option-checking --disable-dependency-tracking --disable-gtest --without-gflags"
20
+ end
21
+
22
+ %w(
23
+ config.h
24
+ snappy-c.cc
25
+ snappy-c.h
26
+ snappy-internal.h
27
+ snappy-sinksource.cc
28
+ snappy-sinksource.h
29
+ snappy-stubs-internal.cc
30
+ snappy-stubs-internal.h
31
+ snappy-stubs-public.h
32
+ snappy.cc
33
+ snappy.h
34
+ ).each do |file|
35
+ FileUtils.copy File.join(src, file), File.join(dst, file) if FileTest.exist? File.join(src, file)
36
+ end
37
+ end
38
+
39
+ create_makefile 'snappy_ext'
@@ -0,0 +1,18 @@
1
+ import org.jruby.Ruby;
2
+ import org.jruby.RubyModule;
3
+ import org.jruby.anno.JRubyMethod;
4
+ import org.jruby.runtime.ThreadContext;
5
+ import org.jruby.runtime.builtin.IRubyObject;
6
+ import org.jruby.runtime.load.Library;
7
+ import org.jruby.runtime.load.BasicLibraryService;
8
+
9
+ import snappy.SnappyModule;
10
+
11
+
12
+ public class SnappyExtService implements BasicLibraryService {
13
+ public boolean basicLoad(final Ruby runtime) {
14
+ RubyModule snappyModule = runtime.defineModule("Snappy");
15
+ snappyModule.defineAnnotatedMethods(SnappyModule.class);
16
+ return true;
17
+ }
18
+ }
@@ -0,0 +1,32 @@
1
+ package snappy;
2
+
3
+ import java.io.IOException;
4
+
5
+ import org.jruby.RubyString;
6
+ import org.jruby.anno.JRubyModule;
7
+ import org.jruby.anno.JRubyMethod;
8
+ import org.jruby.runtime.ThreadContext;
9
+ import org.jruby.runtime.builtin.IRubyObject;
10
+ import org.jruby.util.ByteList;
11
+
12
+ import org.xerial.snappy.Snappy;
13
+
14
+
15
+ @JRubyModule(name = "Snappy")
16
+ public class SnappyModule {
17
+ @JRubyMethod(module = true, name = {"deflate", "compress", "dump"})
18
+ public static IRubyObject deflate(ThreadContext context, IRubyObject self, IRubyObject str) throws IOException {
19
+ ByteList input = str.convertToString().getByteList();
20
+ byte[] compressed = new byte[Snappy.maxCompressedLength(input.length())];
21
+ int compressedLength = Snappy.compress(input.unsafeBytes(), input.begin(), input.length(), compressed, 0);
22
+ return RubyString.newStringNoCopy(context.runtime, compressed, 0, compressedLength);
23
+ }
24
+
25
+ @JRubyMethod(module = true, name = {"inflate", "uncompress", "load"})
26
+ public static IRubyObject inflate(ThreadContext context, IRubyObject self, IRubyObject str) throws IOException {
27
+ ByteList input = str.convertToString().getByteList();
28
+ byte[] uncompressed = new byte[Snappy.uncompressedLength(input.unsafeBytes(), input.begin(), input.length())];
29
+ int uncompressedLength = Snappy.uncompress(input.unsafeBytes(), input.begin(), input.length(), uncompressed, 0);
30
+ return RubyString.newStringNoCopy(context.runtime, uncompressed, 0, uncompressedLength);
31
+ }
32
+ }
data/lib/snappy.rb ADDED
@@ -0,0 +1,6 @@
1
+ # encoding: utf-8
2
+
3
+ require 'snappy-jars' if defined?(JRUBY_VERSION)
4
+ require 'snappy_ext'
5
+ require 'snappy/reader'
6
+ require 'snappy/writer'
@@ -0,0 +1,54 @@
1
+ module Snappy
2
+ class Reader
3
+ attr_reader :io, :magic, :default_version, :minimum_compatible_version
4
+
5
+ def initialize(io)
6
+ @io = io
7
+ @io.set_encoding Encoding::ASCII_8BIT unless RUBY_VERSION =~ /^1\.8/
8
+ read_header!
9
+ yield self if block_given?
10
+ end
11
+
12
+ def each
13
+ until @io.eof?
14
+ size = @chunked ? @io.read(4).unpack("N").first : @io.length
15
+ yield Snappy.inflate(@io.read(size)) if block_given?
16
+ end
17
+ end
18
+
19
+ def read
20
+ @buff = StringIO.new
21
+ each do |chunk|
22
+ @buff << chunk
23
+ end
24
+ @buff.string
25
+ end
26
+
27
+ def each_line(sep_string=$/)
28
+ last = ""
29
+ each do |chunk|
30
+ chunk = last + chunk
31
+ lines = chunk.split(sep_string)
32
+ last = lines.pop
33
+ lines.each do |line|
34
+ yield line if block_given?
35
+ end
36
+ end
37
+ yield last
38
+ end
39
+
40
+ private
41
+
42
+ def read_header!
43
+ magic_byte = @io.readchar
44
+ @io.ungetc(magic_byte)
45
+
46
+ if @io.length >= 16 && magic_byte == Snappy::Writer::MAGIC[0]
47
+ @magic, @default_version, @minimum_compatible_version = @io.read(16).unpack("a8NN")
48
+ @chunked = true
49
+ else
50
+ @chunked = false
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,3 @@
1
+ module Snappy
2
+ VERSION = "0.0.9"
3
+ end
@@ -0,0 +1,46 @@
1
+ module Snappy
2
+ class Writer
3
+ if RUBY_VERSION[0..2] == '1.8'
4
+ MAGIC = "\x82SNAPPY\x0"
5
+ else
6
+ MAGIC = "\x82SNAPPY\x0".force_encoding Encoding::ASCII_8BIT
7
+ end
8
+ DEFAULT_VERSION = 1
9
+ MINIMUM_COMPATIBLE_VERSION = 1
10
+ DEFAULT_BLOCK_SIZE = 32 * 1024
11
+
12
+ attr_reader :io, :block_size
13
+
14
+ def initialize(io, block_size = DEFAULT_BLOCK_SIZE)
15
+ @block_size = block_size
16
+ @buffer = ""
17
+ @io = io
18
+ @io.set_encoding Encoding::ASCII_8BIT unless RUBY_VERSION =~ /^1\.8/
19
+ write_header!
20
+ if block_given?
21
+ yield self
22
+ dump!
23
+ end
24
+ end
25
+
26
+ def <<(msg)
27
+ @buffer << msg.to_s
28
+ dump! if @buffer.size > @block_size
29
+ end
30
+
31
+ def dump!
32
+ compressed = Snappy.deflate(@buffer)
33
+ @io << [compressed.size, compressed].pack("Na#{compressed.size}")
34
+ @io.flush
35
+ @buffer = ""
36
+ end
37
+
38
+ alias_method :flush, :dump!
39
+
40
+ private
41
+
42
+ def write_header!
43
+ @io << [MAGIC, DEFAULT_VERSION, MINIMUM_COMPATIBLE_VERSION].pack("a8NN")
44
+ end
45
+ end
46
+ end
data/snappy.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'snappy/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "snappy"
8
+ spec.version = Snappy::VERSION
9
+ spec.authors = ["miyucy"]
10
+ spec.email = ["fistfvck@gmail.com"]
11
+ spec.description = %q{libsnappy binding for Ruby}
12
+ spec.summary = %q{libsnappy binding for Ruby}
13
+ spec.homepage = "http://github.com/miyucy/snappy"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ if defined?(JRUBY_VERSION)
22
+ spec.files += %w[lib/snappy_ext.jar]
23
+ spec.platform = 'java'
24
+ spec.add_dependency 'snappy-jars', '~> 1.1.0'
25
+ else
26
+ spec.extensions = ["ext/extconf.rb"]
27
+ end
28
+
29
+ spec.add_development_dependency "bundler", "~> 1.3"
30
+ spec.add_development_dependency "rake"
31
+ spec.add_development_dependency "minitest"
32
+ end
@@ -0,0 +1,113 @@
1
+ require "minitest/spec"
2
+ require "minitest/autorun"
3
+ require "snappy"
4
+ require "stringio"
5
+
6
+ describe Snappy::Reader do
7
+ before do
8
+ @buffer = StringIO.new
9
+ Snappy::Writer.new @buffer do |w|
10
+ w << "foo"
11
+ w << "bar"
12
+ w << "baz"
13
+ w << "quux"
14
+ end
15
+ @buffer.rewind
16
+ end
17
+
18
+ subject do
19
+ Snappy::Reader.new @buffer
20
+ end
21
+
22
+ describe :initialize do
23
+ it "should yield itself to the block" do
24
+ yielded = nil
25
+ returned = Snappy::Reader.new @buffer do |r|
26
+ yielded = r
27
+ end
28
+ returned.must_equal yielded
29
+ end
30
+
31
+ it "should read the header" do
32
+ subject.magic.must_equal Snappy::Writer::MAGIC
33
+ subject.default_version.must_equal Snappy::Writer::DEFAULT_VERSION
34
+ subject.minimum_compatible_version.must_equal Snappy::Writer::MINIMUM_COMPATIBLE_VERSION
35
+ end
36
+ end
37
+
38
+ describe :initialize_without_headers do
39
+ before do
40
+ @buffer = StringIO.new
41
+ @buffer << Snappy.deflate("HelloWorld" * 10)
42
+ @buffer.rewind
43
+ end
44
+
45
+ it "should inflate with a magic header" do
46
+ subject.read.must_equal "HelloWorld" * 10
47
+ end
48
+ end
49
+
50
+ describe :io do
51
+ it "should be a constructor argument" do
52
+ subject.io.must_equal @buffer
53
+ end
54
+ end
55
+
56
+ describe :each do
57
+ before do
58
+ Snappy::Writer.new @buffer do |w|
59
+ w << "foo"
60
+ w << "bar"
61
+ w.dump!
62
+ w << "baz"
63
+ w << "quux"
64
+ end
65
+ @buffer.rewind
66
+ end
67
+
68
+ it "should yield each chunk" do
69
+ chunks = []
70
+ Snappy::Reader.new(@buffer).each do |chunk|
71
+ chunks << chunk
72
+ end
73
+ chunks.must_equal ["foobar", "bazquux"]
74
+ end
75
+ end
76
+
77
+ describe :read do
78
+ before do
79
+ Snappy::Writer.new @buffer do |w|
80
+ w << "foo"
81
+ w << "bar"
82
+ w << "baz"
83
+ w << "quux"
84
+ end
85
+ @buffer.rewind
86
+ end
87
+
88
+ it "should return the bytes" do
89
+ Snappy::Reader.new(@buffer).read.must_equal "foobarbazquux"
90
+ end
91
+ end
92
+
93
+ describe :each_line do
94
+ before do
95
+ Snappy::Writer.new @buffer do |w|
96
+ w << "foo\n"
97
+ w << "bar"
98
+ w.dump!
99
+ w << "baz\n"
100
+ w << "quux\n"
101
+ end
102
+ @buffer.rewind
103
+ end
104
+
105
+ it "should yield each line" do
106
+ lines = []
107
+ Snappy::Reader.new(@buffer).each_line do |line|
108
+ lines << line
109
+ end
110
+ lines.must_equal ["foo", "barbaz", "quux"]
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,55 @@
1
+ require "minitest/spec"
2
+ require "minitest/autorun"
3
+ require "snappy"
4
+ require "stringio"
5
+
6
+ describe Snappy::Writer do
7
+ before do
8
+ @buffer = StringIO.new
9
+ end
10
+
11
+ subject do
12
+ Snappy::Writer.new @buffer
13
+ end
14
+
15
+ describe :initialize do
16
+ it "should yield itself to the block" do
17
+ yielded = nil
18
+ returned = Snappy::Writer.new @buffer do |w|
19
+ yielded = w
20
+ end
21
+ returned.must_equal yielded
22
+ end
23
+
24
+ it "should write the header" do
25
+ subject.io.string.must_equal [Snappy::Writer::MAGIC,
26
+ Snappy::Writer::DEFAULT_VERSION,
27
+ Snappy::Writer::MINIMUM_COMPATIBLE_VERSION].pack("a8NN")
28
+ end
29
+
30
+ it "should dump on the end of yield" do
31
+ Snappy::Writer.new @buffer do |w|
32
+ w << "foo"
33
+ end
34
+ foo = Snappy.deflate "foo"
35
+ @buffer.string[16, @buffer.size - 16].must_equal [foo.size, foo].pack("Na#{foo.size}")
36
+ end
37
+ end
38
+
39
+ describe :io do
40
+ it "should be a constructor argument" do
41
+ io = StringIO.new
42
+ Snappy::Writer.new(io).io.must_equal io
43
+ end
44
+ end
45
+
46
+ describe :block_size do
47
+ it "should default to DEFAULT_BLOCK_SIZE" do
48
+ Snappy::Writer.new(StringIO.new).block_size.must_equal Snappy::Writer::DEFAULT_BLOCK_SIZE
49
+ end
50
+
51
+ it "should be settable via the constructor" do
52
+ Snappy::Writer.new(StringIO.new, 42).block_size.must_equal 42
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,24 @@
1
+ require "minitest/spec"
2
+ require "minitest/autorun"
3
+ require "snappy"
4
+
5
+ describe Snappy do
6
+ T = [*"a".."z", *"A".."Z", *"0".."9"]
7
+
8
+ it "well done" do
9
+ s = Array.new(1024){T.sample}.join
10
+ Snappy.inflate(Snappy.deflate s).must_equal(s)
11
+ end
12
+
13
+ it "well done (pair)" do
14
+ s = Array.new(1024){T.sample}.join
15
+ [
16
+ [:deflate, :inflate],
17
+ [:compress, :uncompress],
18
+ [:dump, :load],
19
+ ].each do |(i, o)|
20
+ Snappy.__send__(o, (Snappy.__send__ i, s)).must_equal(s)
21
+ eval %{Snappy.#{o}(Snappy.#{i} s).must_equal(s)}
22
+ end
23
+ end
24
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: snappy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.9
5
+ platform: java
6
+ authors:
7
+ - miyucy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: snappy-jars
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 1.1.0
20
+ requirement: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ~>
23
+ - !ruby/object:Gem::Version
24
+ version: 1.1.0
25
+ prerelease: false
26
+ type: :runtime
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ~>
37
+ - !ruby/object:Gem::Version
38
+ version: '1.3'
39
+ prerelease: false
40
+ type: :development
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ prerelease: false
54
+ type: :development
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ prerelease: false
68
+ type: :development
69
+ description: libsnappy binding for Ruby
70
+ email:
71
+ - fistfvck@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - ext/api.c
82
+ - ext/extconf.rb
83
+ - ext/java/src/SnappyExtService.java
84
+ - ext/java/src/snappy/SnappyModule.java
85
+ - lib/snappy.rb
86
+ - lib/snappy/reader.rb
87
+ - lib/snappy/version.rb
88
+ - lib/snappy/writer.rb
89
+ - snappy.gemspec
90
+ - test/test-snappy-reader.rb
91
+ - test/test-snappy-writer.rb
92
+ - test/test-snappy.rb
93
+ - lib/snappy_ext.jar
94
+ homepage: http://github.com/miyucy/snappy
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.1.11
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: libsnappy binding for Ruby
118
+ test_files:
119
+ - test/test-snappy-reader.rb
120
+ - test/test-snappy-writer.rb
121
+ - test/test-snappy.rb