snappy 0.0.11 → 0.0.12

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
2
  SHA1:
3
- metadata.gz: b4a1e7596c5afb723e2ce4a83f2fb7cb93209437
4
- data.tar.gz: 04e9a2a418c1c689171973cd0c6dcac7eac8ce14
3
+ metadata.gz: e51acd5443feeb8d6c9e84d345729b4da5d97df1
4
+ data.tar.gz: b827cae9f58d92b2968e8b4223e22c3e0609c8e7
5
5
  SHA512:
6
- metadata.gz: 223724133a803ebebfc86d956885fdd9294910e86dbc3759714ee42e8332407254b6c0d6bb8325827f2acfa3c1c1edf1b337e537144c4d2721cafcfbf6e6e25d
7
- data.tar.gz: 09de13c3bcbd183976ca76208b28c903811a3b96b7d327ac7762fe127208b536500a58fbbf9af3f8d8fd83dad6def9115fa40c0334cc95b27bd003480c2c8e6b
6
+ metadata.gz: f323a70f3c7d6646ab67361d169b5755c68dcbaeef0a60ec6e7a1600eb89c59040a0c9ae6594bcda045e6ab4a867a9d3ae07ce2144606764c1d7df0a42ebcb6c
7
+ data.tar.gz: de0e150baa26396b6ac7a96ef4bb63e1de4dddd8a12aee64d78e5ffd52d9874db4615b1c5f3925e51a026f9df333e444c21e530385aa5052209324da9f27ace3
data/.gitmodules CHANGED
@@ -1,3 +1,3 @@
1
1
  [submodule "vendor/snappy"]
2
2
  path = vendor/snappy
3
- url = git@github.com:google/snappy.git
3
+ url = git://github.com/google/snappy.git
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ - jruby-19mode
data/README.md CHANGED
@@ -1,6 +1,16 @@
1
- # Snappy
1
+ # Snappy ![](https://travis-ci.org/miyucy/snappy.svg?branch=master)
2
2
 
3
- see http://code.google.com/p/snappy
3
+ see https://github.com/google/snappy
4
+
5
+ ## Preparation
6
+
7
+ Use libsnappy
8
+
9
+ $ brew install snappy
10
+
11
+ Or
12
+
13
+ $ brew install autoconf automake libtool
4
14
 
5
15
  ## Installation
6
16
 
data/ext/api.c CHANGED
@@ -21,7 +21,7 @@ static VALUE
21
21
  snappy_deflate(int argc, VALUE *argv, VALUE self)
22
22
  {
23
23
  VALUE src, dst;
24
- size_t output_length;
24
+ size_t output_length;
25
25
  snappy_status result;
26
26
 
27
27
  rb_scan_args(argc, argv, "11", &src, &dst);
@@ -37,12 +37,12 @@ snappy_deflate(int argc, VALUE *argv, VALUE self)
37
37
  }
38
38
 
39
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 {
40
+ if (result != SNAPPY_OK) {
44
41
  return snappy_raise(result);
45
42
  }
43
+
44
+ rb_str_resize(dst, output_length);
45
+ return dst;
46
46
  }
47
47
 
48
48
  static VALUE
@@ -72,24 +72,39 @@ snappy_inflate(int argc, VALUE *argv, VALUE self)
72
72
  return snappy_raise(result);
73
73
  }
74
74
 
75
- StringValue(dst);
76
75
  rb_str_resize(dst, output_length);
77
-
78
76
  return dst;
79
77
  }
80
78
 
79
+ static VALUE
80
+ snappy_valid_p(VALUE self, VALUE str)
81
+ {
82
+ snappy_status result;
83
+
84
+ StringValue(str);
85
+ result = snappy_validate_compressed_buffer(RSTRING_PTR(str), RSTRING_LEN(str));
86
+ if (result == SNAPPY_OK) {
87
+ return Qtrue;
88
+ } else {
89
+ return Qfalse;
90
+ }
91
+ }
92
+
81
93
  void Init_snappy_ext()
82
94
  {
95
+ VALUE rb_mSnappy_singleton;
96
+
83
97
  rb_mSnappy = rb_define_module("Snappy");
84
98
  rb_eSnappy = rb_define_class_under(rb_mSnappy, "Error", rb_eStandardError);
85
99
  rb_define_singleton_method(rb_mSnappy, "deflate", snappy_deflate, -1);
86
100
  rb_define_singleton_method(rb_mSnappy, "inflate", snappy_inflate, -1);
101
+ rb_define_singleton_method(rb_mSnappy, "valid?", snappy_valid_p, 1);
87
102
 
88
- VALUE rb_mSnappy_singleton = rb_singleton_class(rb_mSnappy);
103
+ rb_mSnappy_singleton = rb_singleton_class(rb_mSnappy);
89
104
 
90
105
  rb_define_alias(rb_mSnappy_singleton, "compress", "deflate");
91
106
  rb_define_alias(rb_mSnappy_singleton, "dump", "deflate");
92
107
 
93
108
  rb_define_alias(rb_mSnappy_singleton, "uncompress", "inflate");
94
109
  rb_define_alias(rb_mSnappy_singleton, "load", "inflate");
95
- }
110
+ }
data/ext/extconf.rb CHANGED
@@ -1,14 +1,22 @@
1
1
  require 'mkmf'
2
2
  require 'fileutils'
3
3
 
4
+ def patch_autogen
5
+ # s/libtoolize/glibtoolize/
6
+ File.write('autogen.sh', File.read('autogen.sh').gsub(/libtoolize/, 'glibtoolize'))
7
+ end
8
+
4
9
  unless have_library 'snappy'
5
10
  # build vendor/snappy
6
11
  pwd = File.dirname File.expand_path __FILE__
7
12
  dir = File.join pwd, '..', 'vendor', 'snappy'
8
13
 
9
14
  Dir.chdir dir do
10
- system './autogen.sh'
11
- system './configure --disable-option-checking --disable-dependency-tracking --disable-gtest --without-gflags'
15
+ unless system './autogen.sh'
16
+ patch_autogen
17
+ raise '`autogen.sh` failed' unless system './autogen.sh'
18
+ end
19
+ raise '`configure` failed' unless system './configure --disable-option-checking --disable-dependency-tracking --disable-gtest --without-gflags'
12
20
  end
13
21
 
14
22
  src = %w(
@@ -1,3 +1,3 @@
1
1
  module Snappy
2
- VERSION = "0.0.11"
2
+ VERSION = "0.0.12"
3
3
  end
data/test/test-snappy.rb CHANGED
@@ -1,16 +1,16 @@
1
- require "minitest/autorun"
2
- require "minitest/spec"
3
- require "snappy"
1
+ require 'minitest/autorun'
2
+ require 'minitest/spec'
3
+ require 'snappy'
4
4
 
5
5
  describe Snappy do
6
- T = [*"a".."z", *"A".."Z", *"0".."9"]
6
+ T = [*'a'..'z', *'A'..'Z', *'0'..'9']
7
7
 
8
- it "well done" do
8
+ it 'well done' do
9
9
  s = Array.new(1024){T.sample}.join
10
10
  Snappy.inflate(Snappy.deflate s).must_equal(s)
11
11
  end
12
12
 
13
- it "well done (pair)" do
13
+ it 'well done (pair)' do
14
14
  s = Array.new(1024){T.sample}.join
15
15
  [
16
16
  [:deflate, :inflate],
@@ -21,4 +21,38 @@ describe Snappy do
21
21
  eval %{Snappy.#{o}(Snappy.#{i} s).must_equal(s)}
22
22
  end
23
23
  end
24
+
25
+ describe '#deflate' do
26
+ it 'can pass buffer' do
27
+ skip 'cannot pass buffer in jruby' if defined? JRUBY_VERSION
28
+ s = 'a' * 1024
29
+ d = ' ' * 1024
30
+ r = Snappy.deflate(s, d)
31
+ d.must_be_same_as r
32
+ end
33
+ end
34
+
35
+ describe '#inflate' do
36
+ it 'can pass buffer' do
37
+ skip 'cannot pass buffer in jruby' if defined? JRUBY_VERSION
38
+ s = Snappy.deflate('a' * 1024)
39
+ d = ' ' * 1024
40
+ r = Snappy.inflate(s, d)
41
+ d.must_be_same_as r
42
+ end
43
+ end
44
+
45
+ describe '#valid?' do
46
+ it 'return true when passed deflated data' do
47
+ skip 'snappy-jars does not have valid?' if defined? JRUBY_VERSION
48
+ d = Snappy.deflate(Array.new(1024){T.sample}.join)
49
+ Snappy.valid?(d).must_equal true
50
+ end
51
+
52
+ it 'return false when passed invalid data' do
53
+ skip 'snappy-jars does not have valid?' if defined? JRUBY_VERSION
54
+ d = Snappy.deflate(Array.new(1024){T.sample}.join).reverse
55
+ Snappy.valid?(d).must_equal false
56
+ end
57
+ end
24
58
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snappy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - miyucy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-24 00:00:00.000000000 Z
11
+ date: 2015-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -62,6 +62,7 @@ extra_rdoc_files: []
62
62
  files:
63
63
  - ".gitignore"
64
64
  - ".gitmodules"
65
+ - ".travis.yml"
65
66
  - Gemfile
66
67
  - LICENSE.txt
67
68
  - README.md
@@ -136,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
137
  version: '0'
137
138
  requirements: []
138
139
  rubyforge_project:
139
- rubygems_version: 2.4.1
140
+ rubygems_version: 2.4.7
140
141
  signing_key:
141
142
  specification_version: 4
142
143
  summary: libsnappy binding for Ruby