snappy 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OWYxZjliN2JhMzUxOGU5ZDI4ZWEwY2Q4ZDFlNTQ1OGY3NjdmNDliOQ==
4
+ YTdmZWM4Y2U4OTJkYTgxY2E3MDUyYzE2MDZjMGVhMWMyYmJmNWE4Yg==
5
5
  data.tar.gz: !binary |-
6
- NWNlYzI4NmVkODgzZTgzNWM1ZThmNjBiZDJhYmEwOTY5MGUxMTg4MA==
6
+ NjFlNmUzMjYwYjFhZjhlZGQ4YTBmODNjZGYyNzU5NDI0ZmVlMzA0Yg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NGRiMGI5ZjIwZDJhNzMwMGIyN2E5ODQxZDVjZDczNWI1MjA0Y2UyZDk3OGIw
10
- MDcwN2Y2ZmFlYWNmNzMxYzJjMmIyODMxM2NlNTg3MWVmYzNiYTY4YzEzMjUz
11
- MTQ3ZTg4NDMzZjljMWNiNzM5MzFiYWIxYzQ2MzI1OWE0MGY1Yzc=
9
+ MTU4ZDY5YzM5M2Q2ZmE5YTU2ZTgwYWUxOTQxZTFkYzk4Y2Q1YmZiMGUxZDBl
10
+ Njc5YWVjNzU2YzU3M2MxNDYwYzBiODJkNWI4MWVjZTlmY2E3MDc4YjJlZGNj
11
+ YTgwMThhNWExOWQyMTY2Yjc3NzAzNTAwM2ZlMTk2YmZmZWIzMDU=
12
12
  data.tar.gz: !binary |-
13
- ZWIyMGEwMzgxMjRhYjA2MDE1NDZmZTIxYzUzOGVhYjI2ODY1MTQ4ODI2OGI3
14
- NDcwNjc4YWUxYjBjMmIwZGRiYmUyMDczYjBiM2RhNDhjMzcwOWJjZDdkOGZj
15
- NDM2YzE0OWYzNzhhNDc5ZTliMzUyN2ZhMGI4MTM0MTdiYmRlNzI=
13
+ OWE4YTI2NWUxODJhN2E2MjBjNWM0OWYzNDJhMzdjMzA4YTFiNjA4YmEwNzUy
14
+ MWUxNDdjZmQxMWJmNWNkYmQ5MTE4ODNiMTYwY2I2MDJiMDQ5ZjdmNzM1OGRh
15
+ NmYxMzY2YzAwNzI0NjlhYWU2NjRkMGRmZWFjYzBhZTlkMGI2NmE=
data/ext/api.c ADDED
@@ -0,0 +1,98 @@
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()
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, "load", "deflate");
92
+
93
+ rb_define_alias(rb_mSnappy_singleton, "uncompress", "inflate");
94
+ rb_define_alias(rb_mSnappy_singleton, "dump", "inflate");
95
+
96
+ rb_require("snappy/writer");
97
+ rb_require("snappy/reader");
98
+ }
data/ext/extconf.rb CHANGED
@@ -36,5 +36,4 @@ snappy.h
36
36
  end
37
37
  end
38
38
 
39
- have_library 'stdc++'
40
39
  create_makefile 'snappy'
@@ -1,3 +1,3 @@
1
1
  module Snappy
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
data/test/test-snappy.rb CHANGED
@@ -9,4 +9,16 @@ describe Snappy do
9
9
  s = Array.new(1024){T.sample}.join
10
10
  Snappy.inflate(Snappy.deflate s).must_equal(s)
11
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
+ [:load, :dump],
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
12
24
  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.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - miyucy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-22 00:00:00.000000000 Z
11
+ date: 2013-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -65,7 +65,7 @@ files:
65
65
  - LICENSE.txt
66
66
  - README.md
67
67
  - Rakefile
68
- - ext/api.cc
68
+ - ext/api.c
69
69
  - ext/extconf.rb
70
70
  - lib/snappy/reader.rb
71
71
  - lib/snappy/version.rb
data/ext/api.cc DELETED
@@ -1,72 +0,0 @@
1
- #include "ruby.h"
2
- #include "snappy.h"
3
-
4
- static VALUE rb_mSnappy;
5
- static VALUE rb_eSnappy;
6
-
7
- static VALUE
8
- snappy_deflate(int argc, VALUE *argv, VALUE self)
9
- {
10
- VALUE src, dst;
11
- size_t output_length;
12
-
13
- rb_scan_args(argc, argv, "11", &src, &dst);
14
- StringValue(src);
15
-
16
- output_length = snappy::MaxCompressedLength(RSTRING_LEN(src));
17
-
18
- if (NIL_P(dst)) {
19
- dst = rb_str_new(NULL, output_length);
20
- } else {
21
- StringValue(dst);
22
- rb_str_resize(dst, output_length);
23
- }
24
-
25
- snappy::RawCompress(RSTRING_PTR(src), RSTRING_LEN(src), RSTRING_PTR(dst), &output_length);
26
- rb_str_resize(dst, output_length);
27
-
28
- return dst;
29
- }
30
-
31
- static VALUE
32
- snappy_inflate(int argc, VALUE *argv, VALUE self)
33
- {
34
- VALUE src, dst;
35
- size_t output_length;
36
-
37
- rb_scan_args(argc, argv, "11", &src, &dst);
38
- StringValue(src);
39
-
40
- if (!snappy::GetUncompressedLength(RSTRING_PTR(src), RSTRING_LEN(src), &output_length)) {
41
- rb_raise(rb_eSnappy, "snappy::GetUncompressedLength");
42
- }
43
-
44
- if (NIL_P(dst)) {
45
- dst = rb_str_new(NULL, output_length);
46
- } else {
47
- StringValue(dst);
48
- rb_str_resize(dst, output_length);
49
- }
50
-
51
- if (!snappy::RawUncompress(RSTRING_PTR(src), RSTRING_LEN(src), RSTRING_PTR(dst))) {
52
- rb_raise(rb_eSnappy, "snappy::RawUncompress");
53
- }
54
-
55
- return dst;
56
- }
57
-
58
- extern "C" {
59
- void Init_snappy()
60
- {
61
- rb_mSnappy = rb_define_module("Snappy");
62
- rb_eSnappy = rb_define_class_under(rb_mSnappy, "Error", rb_eStandardError);
63
- rb_define_singleton_method(rb_mSnappy, "deflate", (VALUE (*)(...))snappy_deflate, -1);
64
- rb_define_singleton_method(rb_mSnappy, "inflate", (VALUE (*)(...))snappy_inflate, -1);
65
-
66
- rb_define_singleton_method(rb_mSnappy, "compress", (VALUE (*)(...))snappy_deflate, -1);
67
- rb_define_singleton_method(rb_mSnappy, "uncompress", (VALUE (*)(...))snappy_inflate, -1);
68
-
69
- rb_require("snappy/writer");
70
- rb_require("snappy/reader");
71
- }
72
- }