snappy 0.0.17 → 0.3.0

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.
Files changed (87) hide show
  1. checksums.yaml +5 -5
  2. data/.dockerignore +2 -0
  3. data/.github/workflows/main.yml +34 -0
  4. data/.github/workflows/publish.yml +34 -0
  5. data/.gitignore +2 -1
  6. data/.gitmodules +1 -1
  7. data/Dockerfile +13 -0
  8. data/Gemfile +4 -0
  9. data/README.md +29 -5
  10. data/Rakefile +32 -29
  11. data/ext/api.c +6 -1
  12. data/ext/extconf.rb +23 -16
  13. data/lib/snappy/hadoop/reader.rb +62 -0
  14. data/lib/snappy/hadoop/writer.rb +51 -0
  15. data/lib/snappy/hadoop.rb +22 -0
  16. data/lib/snappy/reader.rb +14 -10
  17. data/lib/snappy/shim.rb +1 -1
  18. data/lib/snappy/version.rb +1 -1
  19. data/lib/snappy.rb +5 -4
  20. data/snappy.gemspec +13 -13
  21. data/test/hadoop/snappy_hadoop_reader_test.rb +115 -0
  22. data/test/hadoop/snappy_hadoop_writer_test.rb +48 -0
  23. data/test/snappy_hadoop_test.rb +26 -0
  24. data/test/snappy_reader_test.rb +148 -0
  25. data/test/snappy_test.rb +95 -0
  26. data/test/snappy_writer_test.rb +55 -0
  27. data/test/test_helper.rb +7 -0
  28. data/test.sh +3 -0
  29. data/vendor/snappy/CMakeLists.txt +297 -0
  30. data/vendor/snappy/CONTRIBUTING.md +26 -0
  31. data/vendor/snappy/NEWS +40 -0
  32. data/vendor/snappy/{README → README.md} +27 -18
  33. data/vendor/snappy/cmake/SnappyConfig.cmake.in +33 -0
  34. data/vendor/snappy/cmake/config.h.in +62 -0
  35. data/vendor/snappy/docs/README.md +72 -0
  36. data/vendor/snappy/snappy-internal.h +22 -18
  37. data/vendor/snappy/snappy-stubs-internal.cc +1 -1
  38. data/vendor/snappy/snappy-stubs-internal.h +116 -38
  39. data/vendor/snappy/snappy-stubs-public.h.in +20 -46
  40. data/vendor/snappy/snappy-test.cc +26 -22
  41. data/vendor/snappy/snappy-test.h +24 -98
  42. data/vendor/snappy/snappy.cc +380 -183
  43. data/vendor/snappy/snappy.h +14 -10
  44. data/vendor/snappy/snappy_compress_fuzzer.cc +59 -0
  45. data/vendor/snappy/snappy_uncompress_fuzzer.cc +57 -0
  46. data/vendor/snappy/snappy_unittest.cc +236 -261
  47. metadata +37 -92
  48. data/.travis.yml +0 -26
  49. data/smoke.sh +0 -8
  50. data/test/test-snappy-reader.rb +0 -129
  51. data/test/test-snappy-writer.rb +0 -55
  52. data/test/test-snappy.rb +0 -58
  53. data/vendor/snappy/ChangeLog +0 -2468
  54. data/vendor/snappy/INSTALL +0 -370
  55. data/vendor/snappy/Makefile +0 -982
  56. data/vendor/snappy/Makefile.am +0 -26
  57. data/vendor/snappy/Makefile.in +0 -982
  58. data/vendor/snappy/aclocal.m4 +0 -9738
  59. data/vendor/snappy/autogen.sh +0 -12
  60. data/vendor/snappy/autom4te.cache/output.0 +0 -18856
  61. data/vendor/snappy/autom4te.cache/output.1 +0 -18852
  62. data/vendor/snappy/autom4te.cache/requests +0 -297
  63. data/vendor/snappy/autom4te.cache/traces.0 +0 -2689
  64. data/vendor/snappy/autom4te.cache/traces.1 +0 -714
  65. data/vendor/snappy/config.guess +0 -1530
  66. data/vendor/snappy/config.h +0 -135
  67. data/vendor/snappy/config.h.in +0 -134
  68. data/vendor/snappy/config.log +0 -1640
  69. data/vendor/snappy/config.status +0 -2318
  70. data/vendor/snappy/config.sub +0 -1773
  71. data/vendor/snappy/configure +0 -18852
  72. data/vendor/snappy/configure.ac +0 -134
  73. data/vendor/snappy/depcomp +0 -688
  74. data/vendor/snappy/install-sh +0 -527
  75. data/vendor/snappy/libtool +0 -10246
  76. data/vendor/snappy/ltmain.sh +0 -9661
  77. data/vendor/snappy/m4/gtest.m4 +0 -74
  78. data/vendor/snappy/m4/libtool.m4 +0 -8001
  79. data/vendor/snappy/m4/ltoptions.m4 +0 -384
  80. data/vendor/snappy/m4/ltsugar.m4 +0 -123
  81. data/vendor/snappy/m4/ltversion.m4 +0 -23
  82. data/vendor/snappy/m4/lt~obsolete.m4 +0 -98
  83. data/vendor/snappy/missing +0 -331
  84. data/vendor/snappy/snappy-stubs-public.h +0 -100
  85. data/vendor/snappy/snappy.pc +0 -10
  86. data/vendor/snappy/snappy.pc.in +0 -10
  87. data/vendor/snappy/stamp-h1 +0 -1
@@ -0,0 +1,115 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+ require "stringio"
5
+
6
+ class SnappyHadoopReaderTest < Test::Unit::TestCase
7
+ def setup
8
+ @buffer = StringIO.new
9
+ Snappy::Hadoop::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
+ def subject
19
+ @subject ||= Snappy::Hadoop::Reader.new @buffer
20
+ end
21
+
22
+ sub_test_case "#initialize" do
23
+ test "should yield itself to the block" do
24
+ yielded = nil
25
+ returned = Snappy::Hadoop::Reader.new @buffer do |r|
26
+ yielded = r
27
+ end
28
+ assert_equal returned, yielded
29
+ end
30
+ end
31
+
32
+ sub_test_case "#io" do
33
+ test "should be a constructor argument" do
34
+ assert_equal @buffer, subject.io
35
+ end
36
+
37
+ test "should not receive `length' in initializing" do
38
+ dont_allow(@buffer).length
39
+ Snappy::Hadoop::Reader.new @buffer
40
+ end
41
+ end
42
+
43
+ sub_test_case "#each" do
44
+ def setup
45
+ @buffer = StringIO.new
46
+ Snappy::Hadoop::Writer.new @buffer do |w|
47
+ w << "foo"
48
+ w << "bar"
49
+ w.dump!
50
+ w << "baz"
51
+ w << "quux"
52
+ end
53
+ @buffer.rewind
54
+ end
55
+
56
+ test "should yield each chunk" do
57
+ chunks = []
58
+ subject.each do |chunk|
59
+ chunks << chunk
60
+ end
61
+ assert_equal %w[foobar bazquux], chunks
62
+ end
63
+ end
64
+
65
+ sub_test_case "#read" do
66
+ test "should return the bytes" do
67
+ assert_equal "foobarbazquux", subject.read
68
+ end
69
+ end
70
+
71
+ sub_test_case "#each_line" do
72
+ def setup
73
+ @buffer = StringIO.new
74
+ Snappy::Hadoop::Writer.new @buffer do |w|
75
+ w << "foo\n"
76
+ w << "bar"
77
+ w.dump!
78
+ w << "baz\n"
79
+ w << "quux\n"
80
+ end
81
+ @buffer.rewind
82
+ end
83
+
84
+ test "should yield each line" do
85
+ lines = []
86
+ subject.each_line do |line|
87
+ lines << line
88
+ end
89
+ assert_equal %w[foo barbaz quux], lines
90
+ end
91
+
92
+ test "should return enumerator w/o block" do
93
+ eacher = subject.each_line
94
+ assert_instance_of Enumerator, eacher
95
+ lines = []
96
+ loop { lines << eacher.next }
97
+ assert_equal %w[foo barbaz quux], lines
98
+ end
99
+
100
+ test "each_line split by sep_string" do
101
+ buffer = StringIO.new
102
+ Snappy::Hadoop::Writer.new buffer do |w|
103
+ w << %w[a b c].join(",")
104
+ w.dump!
105
+ w << %w[d e f].join(",")
106
+ end
107
+ buffer.rewind
108
+ reader = Snappy::Hadoop::Reader.new buffer
109
+ eacher = reader.each_line(",")
110
+ lines = []
111
+ loop { lines << eacher.next }
112
+ assert_equal %w[a b cd e f], lines
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+ require "stringio"
5
+
6
+ class SnappyHadoopWriterTest < Test::Unit::TestCase
7
+ def setup
8
+ @buffer = StringIO.new
9
+ end
10
+
11
+ def subject
12
+ @subject ||= Snappy::Hadoop::Writer.new @buffer
13
+ end
14
+
15
+ sub_test_case "#initialize" do
16
+ test "should yield itself to the block" do
17
+ yielded = nil
18
+ returned = Snappy::Hadoop::Writer.new @buffer do |w|
19
+ yielded = w
20
+ end
21
+ assert_equal returned, yielded
22
+ end
23
+
24
+ test "should write the header" do
25
+ Snappy::Hadoop::Writer.new @buffer do |w|
26
+ w << "foo"
27
+ end
28
+ assert_equal "\u0000\u0000\u0000\u0003\u0000\u0000\u0000\u0005\u0003\bfoo", @buffer.string
29
+ end
30
+ end
31
+
32
+ sub_test_case "#io" do
33
+ test "should be a constructor argument" do
34
+ io = StringIO.new
35
+ assert_equal io, Snappy::Hadoop::Writer.new(io).io
36
+ end
37
+ end
38
+
39
+ sub_test_case "#block_size" do
40
+ test "should default to DEFAULT_BLOCK_SIZE" do
41
+ assert_equal Snappy::Hadoop::Writer::DEFAULT_BLOCK_SIZE, subject.block_size
42
+ end
43
+
44
+ test "should be settable via the constructor" do
45
+ assert_equal 42, Snappy::Hadoop::Writer.new(StringIO.new, 42).block_size
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+ require "stringio"
5
+
6
+ class SnappyHadoopTest < Test::Unit::TestCase
7
+ T = [*"a".."z", *"A".."Z", *"0".."9"].freeze
8
+
9
+ def random_data(length = 1024)
10
+ Array.new(length) { T.sample }.join
11
+ end
12
+
13
+ test "well done" do
14
+ s = random_data
15
+ assert_equal s, Snappy::Hadoop.inflate(Snappy::Hadoop.deflate(s))
16
+ end
17
+
18
+ test "well done(pair)" do
19
+ s = random_data
20
+ [
21
+ %i[deflate inflate]
22
+ ].each do |(i, o)|
23
+ assert_equal s, Snappy::Hadoop.__send__(o, Snappy::Hadoop.__send__(i, s))
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,148 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+ require "stringio"
5
+
6
+ class SnappyReaderTest < Test::Unit::TestCase
7
+ def setup
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
+ def subject
19
+ @subject ||= Snappy::Reader.new @buffer
20
+ end
21
+
22
+ sub_test_case "#initialize" do
23
+ test "should yield itself to the block" do
24
+ yielded = nil
25
+ returned = Snappy::Reader.new @buffer do |r|
26
+ yielded = r
27
+ end
28
+ assert_equal returned, yielded
29
+ end
30
+
31
+ test "should read the header" do
32
+ assert_equal Snappy::Writer::MAGIC, subject.magic
33
+ assert_equal Snappy::Writer::DEFAULT_VERSION, subject.default_version
34
+ assert_equal Snappy::Writer::MINIMUM_COMPATIBLE_VERSION, subject.minimum_compatible_version
35
+ end
36
+ end
37
+
38
+ sub_test_case :initialize_without_headers do
39
+ def setup
40
+ @buffer = StringIO.new
41
+ @buffer << Snappy.deflate("HelloWorld" * 10)
42
+ @buffer.rewind
43
+ end
44
+
45
+ test "should inflate with a magic header" do
46
+ assert_equal "HelloWorld" * 10, subject.read
47
+ end
48
+
49
+ test "should not receive `length' in eaching" do
50
+ dont_allow(@buffer).length
51
+ subject.read
52
+ end
53
+ end
54
+
55
+ sub_test_case "#io" do
56
+ test "should be a constructor argument" do
57
+ assert_equal @buffer, subject.io
58
+ end
59
+
60
+ test "should not receive `length' in initializing" do
61
+ dont_allow(@buffer).length
62
+ Snappy::Reader.new @buffer
63
+ end
64
+ end
65
+
66
+ sub_test_case "#each" do
67
+ def setup
68
+ @buffer = StringIO.new
69
+ Snappy::Writer.new @buffer do |w|
70
+ w << "foo"
71
+ w << "bar"
72
+ w.dump!
73
+ w << "baz"
74
+ w << "quux"
75
+ end
76
+ @buffer.rewind
77
+ end
78
+
79
+ test "should yield each chunk" do
80
+ chunks = []
81
+ subject.each do |chunk|
82
+ chunks << chunk
83
+ end
84
+ assert_equal %w[foobar bazquux], chunks
85
+ end
86
+
87
+ test "should return enumerator w/o block" do
88
+ eacher = subject.each
89
+ assert_instance_of Enumerator, eacher
90
+ chunks = []
91
+ chunks << eacher.next
92
+ chunks << eacher.next
93
+ assert_raise(StopIteration) { eacher.next }
94
+ assert_equal %w[foobar bazquux], chunks
95
+ end
96
+ end
97
+
98
+ sub_test_case "#read" do
99
+ test "should return the bytes" do
100
+ assert_equal "foobarbazquux", subject.read
101
+ end
102
+ end
103
+
104
+ sub_test_case "#each_line" do
105
+ def setup
106
+ @buffer = StringIO.new
107
+ Snappy::Writer.new @buffer do |w|
108
+ w << "foo\n"
109
+ w << "bar"
110
+ w.dump!
111
+ w << "baz\n"
112
+ w << "quux\n"
113
+ end
114
+ @buffer.rewind
115
+ end
116
+
117
+ test "should yield each line" do
118
+ lines = []
119
+ subject.each_line do |line|
120
+ lines << line
121
+ end
122
+ assert_equal %w[foo barbaz quux], lines
123
+ end
124
+
125
+ test "should return enumerator w/o block" do
126
+ eacher = subject.each_line
127
+ assert_instance_of Enumerator, eacher
128
+ lines = []
129
+ loop { lines << eacher.next }
130
+ assert_equal %w[foo barbaz quux], lines
131
+ end
132
+
133
+ test "each_line split by sep_string" do
134
+ buffer = StringIO.new
135
+ Snappy::Writer.new buffer do |w|
136
+ w << %w[a b c].join(",")
137
+ w.dump!
138
+ w << %w[d e f].join(",")
139
+ end
140
+ buffer.rewind
141
+ reader = Snappy::Reader.new buffer
142
+ eacher = reader.each_line(",")
143
+ lines = []
144
+ loop { lines << eacher.next }
145
+ assert_equal %w[a b cd e f], lines
146
+ end
147
+ end
148
+ end
@@ -0,0 +1,95 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ class SnappyTest < Test::Unit::TestCase
6
+ T = [*"a".."z", *"A".."Z", *"0".."9"].freeze
7
+
8
+ def random_data(length = 1024)
9
+ Array.new(length) { T.sample }.join
10
+ end
11
+
12
+ test "VERSION" do
13
+ assert do
14
+ ::Snappy.const_defined?(:VERSION)
15
+ end
16
+ end
17
+
18
+ test "well done" do
19
+ s = random_data
20
+ assert_equal s, Snappy.inflate(Snappy.deflate(s))
21
+ end
22
+
23
+ test "well done (pair)" do
24
+ s = random_data
25
+ [
26
+ %i[deflate inflate],
27
+ %i[compress uncompress],
28
+ %i[dump load]
29
+ ].each do |(i, o)|
30
+ assert_equal s, Snappy.__send__(o, Snappy.__send__(i, s))
31
+ end
32
+ end
33
+
34
+ sub_test_case ".deflate" do
35
+ test "can pass buffer" do
36
+ if defined? JRUBY_VERSION
37
+ notify "cannot pass buffer in jruby"
38
+ omit
39
+ end
40
+ s = random_data
41
+ d = " " * 1024
42
+ r = Snappy.deflate(s, d)
43
+ assert_equal r.object_id, d.object_id
44
+ end
45
+ end
46
+
47
+ sub_test_case ".inflate" do
48
+ test "can pass buffer" do
49
+ if defined? JRUBY_VERSION
50
+ notify "cannot pass buffer in jruby"
51
+ omit
52
+ end
53
+ s = Snappy.deflate(random_data)
54
+ d = " " * 1024
55
+ r = Snappy.inflate(s, d)
56
+ assert_equal r.object_id, d.object_id
57
+ end
58
+ end
59
+
60
+ sub_test_case ".valid?" do
61
+ test "return true when passed deflated data" do
62
+ if defined? JRUBY_VERSION
63
+ notify "snappy-jars does not have valid?"
64
+ omit
65
+ end
66
+ d = Snappy.deflate(random_data)
67
+ assert_true Snappy.valid?(d)
68
+ end
69
+
70
+ test "return false when passed invalid data" do
71
+ if defined? JRUBY_VERSION
72
+ notify "snappy-jars does not have valid?"
73
+ omit
74
+ end
75
+ d = Snappy.deflate(random_data).reverse
76
+ assert_false Snappy.valid?(d)
77
+ end
78
+ end
79
+
80
+ sub_test_case "Ractor safe" do
81
+ test "able to invoke non-main ractor" do
82
+ unless defined? ::Ractor
83
+ notify "Ractor not defined"
84
+ omit
85
+ end
86
+ s = random_data
87
+ a = Array.new(2) do
88
+ Ractor.new(s) do |s|
89
+ Snappy.inflate(Snappy.deflate(s)) == s
90
+ end
91
+ end
92
+ assert_equal [true, true], a.map(&:take)
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+ require "stringio"
5
+
6
+ class SnappyWriterTest < Test::Unit::TestCase
7
+ def setup
8
+ @buffer = StringIO.new
9
+ end
10
+
11
+ def subject
12
+ @subject ||= Snappy::Writer.new @buffer
13
+ end
14
+
15
+ sub_test_case "#initialize" do
16
+ test "should yield itself to the block" do
17
+ yielded = nil
18
+ returned = Snappy::Writer.new @buffer do |w|
19
+ yielded = w
20
+ end
21
+ assert_equal returned, yielded
22
+ end
23
+
24
+ test "should write the header" do
25
+ assert_equal [Snappy::Writer::MAGIC,
26
+ Snappy::Writer::DEFAULT_VERSION,
27
+ Snappy::Writer::MINIMUM_COMPATIBLE_VERSION].pack("a8NN"), subject.io.string
28
+ end
29
+
30
+ test "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
+ assert_equal [foo.size, foo].pack("Na#{foo.size}"), @buffer.string[16, @buffer.size - 16]
36
+ end
37
+ end
38
+
39
+ sub_test_case "#io" do
40
+ test "should be a constructor argument" do
41
+ io = StringIO.new
42
+ assert_equal io, Snappy::Writer.new(io).io
43
+ end
44
+ end
45
+
46
+ sub_test_case "#block_size" do
47
+ test "should default to DEFAULT_BLOCK_SIZE" do
48
+ assert_equal Snappy::Writer::DEFAULT_BLOCK_SIZE, subject.block_size
49
+ end
50
+
51
+ test "should be settable via the constructor" do
52
+ assert_equal 42, Snappy::Writer.new(StringIO.new, 42).block_size
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
4
+ require "snappy"
5
+
6
+ require "test-unit"
7
+ require "test/unit/rr"
data/test.sh ADDED
@@ -0,0 +1,3 @@
1
+ #!/bin/bash
2
+ docker build -t miyucy/snappy .
3
+ docker run --rm -v "$(pwd):/app" miyucy/snappy bash -c 'bundle install && bundle exec rake'