snappy 0.0.14-java → 0.2.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/main.yml +34 -0
  3. data/.github/workflows/publish.yml +34 -0
  4. data/Gemfile +4 -0
  5. data/README.md +28 -4
  6. data/Rakefile +32 -29
  7. data/ext/api.c +6 -1
  8. data/ext/extconf.rb +21 -24
  9. data/lib/snappy.rb +6 -4
  10. data/lib/snappy/hadoop.rb +22 -0
  11. data/lib/snappy/hadoop/reader.rb +62 -0
  12. data/lib/snappy/hadoop/writer.rb +51 -0
  13. data/lib/snappy/reader.rb +19 -11
  14. data/lib/snappy/shim.rb +30 -0
  15. data/lib/snappy/version.rb +3 -1
  16. data/lib/snappy/writer.rb +8 -9
  17. data/snappy.gemspec +17 -37
  18. data/test/hadoop/snappy_hadoop_reader_test.rb +115 -0
  19. data/test/hadoop/snappy_hadoop_writer_test.rb +48 -0
  20. data/test/snappy_hadoop_test.rb +26 -0
  21. data/test/snappy_reader_test.rb +148 -0
  22. data/test/snappy_test.rb +95 -0
  23. data/test/snappy_writer_test.rb +55 -0
  24. data/test/test_helper.rb +7 -0
  25. data/vendor/snappy/CMakeLists.txt +297 -0
  26. data/vendor/snappy/CONTRIBUTING.md +26 -0
  27. data/vendor/snappy/COPYING +1 -1
  28. data/vendor/snappy/NEWS +60 -0
  29. data/vendor/snappy/{README → README.md} +29 -16
  30. data/vendor/snappy/cmake/SnappyConfig.cmake.in +33 -0
  31. data/vendor/snappy/cmake/config.h.in +62 -0
  32. data/vendor/snappy/docs/README.md +72 -0
  33. data/vendor/snappy/snappy-c.h +3 -3
  34. data/vendor/snappy/snappy-internal.h +113 -32
  35. data/vendor/snappy/snappy-sinksource.cc +33 -0
  36. data/vendor/snappy/snappy-sinksource.h +51 -6
  37. data/vendor/snappy/snappy-stubs-internal.cc +1 -1
  38. data/vendor/snappy/snappy-stubs-internal.h +160 -45
  39. data/vendor/snappy/snappy-stubs-public.h.in +23 -47
  40. data/vendor/snappy/snappy-test.cc +31 -24
  41. data/vendor/snappy/snappy-test.h +46 -103
  42. data/vendor/snappy/snappy.cc +786 -431
  43. data/vendor/snappy/snappy.h +37 -14
  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 +441 -290
  47. metadata +35 -75
  48. data/.travis.yml +0 -4
  49. data/test/test-snappy-reader.rb +0 -129
  50. data/test/test-snappy-writer.rb +0 -55
  51. data/test/test-snappy.rb +0 -58
  52. data/vendor/snappy/ChangeLog +0 -1916
  53. data/vendor/snappy/Makefile.am +0 -23
  54. data/vendor/snappy/autogen.sh +0 -7
  55. data/vendor/snappy/configure.ac +0 -133
  56. data/vendor/snappy/m4/gtest.m4 +0 -74
  57. data/vendor/snappy/testdata/alice29.txt +0 -3609
  58. data/vendor/snappy/testdata/asyoulik.txt +0 -4122
  59. data/vendor/snappy/testdata/baddata1.snappy +0 -0
  60. data/vendor/snappy/testdata/baddata2.snappy +0 -0
  61. data/vendor/snappy/testdata/baddata3.snappy +0 -0
  62. data/vendor/snappy/testdata/fireworks.jpeg +0 -0
  63. data/vendor/snappy/testdata/geo.protodata +0 -0
  64. data/vendor/snappy/testdata/html +0 -1
  65. data/vendor/snappy/testdata/html_x_4 +0 -1
  66. data/vendor/snappy/testdata/kppkn.gtb +0 -0
  67. data/vendor/snappy/testdata/lcet10.txt +0 -7519
  68. data/vendor/snappy/testdata/paper-100k.pdf +2 -600
  69. data/vendor/snappy/testdata/plrabn12.txt +0 -10699
  70. data/vendor/snappy/testdata/urls.10K +0 -10000
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e0dd553a2b05494e3985d5b71be1c0381468b011
4
- data.tar.gz: 2a146b0103be309d4c9ceb3ae51481fd2e218958
2
+ SHA256:
3
+ metadata.gz: dc1e9d110a0bf1b0a6e04906ed2ed31223b95ed7b009c684b8e499a78b1a17e8
4
+ data.tar.gz: 325f0fa94023b89a4ff06d6bb4cde178fef16f9d692e6f331227af3ee31b41b8
5
5
  SHA512:
6
- metadata.gz: 9a721d16f5f799600374314dd118a465a41e6c5d2ea432095b4bfe7533f37989256b9f9b482d26c036424b847119cb8d203edb839fafc618785da628ac944232
7
- data.tar.gz: 1e70c72896879655be67cd11a32511342d439e3ed98121d4fd37238c2f62a84d032180065f859b5d8f0e53b8559322e886e3daa9c3dabd7ee998f5925340367d
6
+ metadata.gz: 01bcc433736c9f9bf08d0cad2eb5647bc771099490c3a60f67a629a16acd8885179718f16f59f126610658292ba86a1a9058eb1243d81077efebe6d523895a57
7
+ data.tar.gz: 9eaf7fff9956c56c6db98ba4b38370d5ef27c1ad1b97bb4437006092b7c78bd5d7c52f23b42bf1bcfc7f69a06a82fb288d1e42b277805d8d172850cf520537b4
@@ -0,0 +1,34 @@
1
+ name: Ruby
2
+
3
+ on: [pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ strategy:
8
+ fail-fast: false
9
+ matrix:
10
+ ruby: [2.5, 2.6, 2.7, jruby]
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - uses: actions/checkout@v2
14
+ with:
15
+ submodules: true
16
+ - name: Set up Ruby
17
+ uses: ruby/setup-ruby@v1
18
+ with:
19
+ ruby-version: ${{ matrix.ruby }}
20
+ bundler-cache: true
21
+ - name: Run the default task
22
+ run: |
23
+ bundle exec rake clobber clean test build
24
+ gem install --no-document "$(ls pkg/snappy-*.gem)"
25
+ cat <<EOF | ruby
26
+ require "snappy"
27
+ if Snappy.inflate(Snappy.deflate(File.read("README.md"))) == File.read("README.md")
28
+ puts "OK"
29
+ exit 0
30
+ else
31
+ puts "NG"
32
+ exit 0
33
+ end
34
+ EOF
@@ -0,0 +1,34 @@
1
+ name: Publish Gem
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - 'v*'
7
+
8
+ jobs:
9
+ build:
10
+ strategy:
11
+ fail-fast: false
12
+ matrix:
13
+ ruby: [2.7, jruby]
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - uses: actions/checkout@v2
17
+ with:
18
+ submodules: true
19
+ - name: Set up Ruby
20
+ uses: ruby/setup-ruby@v1
21
+ with:
22
+ ruby-version: ${{ matrix.ruby }}
23
+ bundler-cache: true
24
+ - name: Run release task
25
+ run: |
26
+ mkdir -p ~/.gem
27
+ cat << EOF > ~/.gem/credentials
28
+ ---
29
+ :github: Bearer ${{secrets.GITHUB_TOKEN}}
30
+ :rubygems_api_key: ${{secrets.RUBYGEMS_API_KEY}}
31
+ EOF
32
+ chmod 600 ~/.gem/credentials
33
+ bundle exec rake release[remote]
34
+ rm -f ~/.gem/credentials
data/Gemfile CHANGED
@@ -2,3 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in snappy.gemspec
4
4
  gemspec
5
+
6
+ gem "rake", "~> 13.0"
7
+ gem "test-unit", "~> 3.0"
8
+ gem "test-unit-rr"
data/README.md CHANGED
@@ -4,13 +4,27 @@ see https://github.com/google/snappy
4
4
 
5
5
  ## Preparation
6
6
 
7
- Use libsnappy
8
7
 
9
- $ brew install snappy
8
+ ### macOS
10
9
 
11
- Or
10
+ ```bash
11
+ $ brew install snappy
12
+ $ brew install autoconf automake libtool
13
+ ```
14
+
15
+ ### Ubuntu
16
+
17
+ ```bash
18
+ $ apt-get install libsnappy-dev -y
19
+ $ apt-get install libtool automake autoconf -y
20
+ ```
21
+
22
+ ### Alpine
12
23
 
13
- $ brew install autoconf automake libtool
24
+ ```bash
25
+ $ apk install snappy
26
+ $ apk install build-base libexecinfo automake autoconf libtool
27
+ ```
14
28
 
15
29
  ## Installation
16
30
 
@@ -28,6 +42,7 @@ Or install it yourself as:
28
42
 
29
43
  ## Usage
30
44
 
45
+ Snappy-java format
31
46
  ```ruby
32
47
  require 'snappy'
33
48
 
@@ -38,6 +53,15 @@ Snappy.inflate(source)
38
53
  # => Decompressed data
39
54
  ```
40
55
 
56
+ Hadoop-snappy format
57
+ ```ruby
58
+ Snappy::Hadoop.deflate(source)
59
+ # => Compressed data
60
+
61
+ Snappy::Hadoop.inflate(source)
62
+ # => Decompressed data
63
+ ```
64
+
41
65
  ## Contributing
42
66
 
43
67
  1. Fork it
data/Rakefile CHANGED
@@ -2,48 +2,51 @@ require "bundler/setup"
2
2
  require "bundler/gem_tasks"
3
3
  require "rake/testtask"
4
4
  require "rbconfig"
5
- DLEXT = RbConfig::CONFIG['DLEXT']
5
+ DLEXT = RbConfig::CONFIG["DLEXT"]
6
6
 
7
- Rake::TestTask.new do |t|
7
+ Rake::TestTask.new(:test) do |t|
8
+ t.libs << "test"
9
+ t.libs << "lib"
10
+ t.test_files = FileList["test/**/*_test.rb"]
8
11
  t.warning = true
9
12
  t.verbose = true
10
13
  end
11
14
 
12
15
  if defined?(JRUBY_VERSION)
13
- require 'ant'
16
+ require "ant"
14
17
 
15
- directory 'ext/java/build'
18
+ directory "ext/java/build"
16
19
 
17
- task :setup => 'ext/java/build' do
18
- ant.property name: 'src.dir', value: 'ext/java/src'
19
- ant.property name: 'build.dir', value: 'ext/java/build'
20
+ task setup: "ext/java/build" do
21
+ ant.property name: "src.dir", value: "ext/java/src"
22
+ ant.property name: "build.dir", value: "ext/java/build"
20
23
 
21
- ant.path id: 'compile.class.path' do
22
- pathelement location: File.join(RbConfig::CONFIG['prefix'], 'lib', 'jruby.jar')
23
- $LOAD_PATH.flat_map { |path| Dir[File.join(path, '**', '*.jar')] }.each do |jar|
24
+ ant.path id: "compile.class.path" do
25
+ pathelement location: File.join(RbConfig::CONFIG["prefix"], "lib", "jruby.jar")
26
+ $LOAD_PATH.flat_map { |path| Dir[File.join(path, "**", "*.jar")] }.each do |jar|
24
27
  pathelement location: jar
25
28
  end
26
29
  end
27
30
  end
28
31
 
29
- desc 'Compile the extension'
30
- task :compile => :setup do
31
- ant.javac destdir: '${build.dir}', includeantruntime: 'no', target: '1.6', source: '1.6', debug: 'on' do
32
- classpath refid: 'compile.class.path'
33
- src { pathelement location: '${src.dir}' }
32
+ desc "Compile the extension"
33
+ task compile: :setup do
34
+ ant.javac destdir: "${build.dir}", includeantruntime: "no", target: "1.6", source: "1.6", debug: "on" do
35
+ classpath refid: "compile.class.path"
36
+ src { pathelement location: "${src.dir}" }
34
37
  end
35
38
  end
36
39
 
37
- desc 'Package the jar'
38
- file 'lib/snappy_ext.jar' => :compile do |t|
39
- ant.jar destfile: 'lib/snappy_ext.jar', basedir: '${build.dir}' do
40
- ant.fileset dir: '${build.dir}', includes: 'snappy/*.class'
41
- ant.fileset dir: '${build.dir}', includes: 'SnappyExtLibraryService.class'
40
+ desc "Package the jar"
41
+ file "lib/snappy_ext.jar" => :compile do |t|
42
+ ant.jar destfile: "lib/snappy_ext.jar", basedir: "${build.dir}" do
43
+ ant.fileset dir: "${build.dir}", includes: "snappy/*.class"
44
+ ant.fileset dir: "${build.dir}", includes: "SnappyExtLibraryService.class"
42
45
  end
43
46
  end
44
47
 
45
- task :test => 'lib/snappy_ext.jar'
46
- task :build => [:clean, 'lib/snappy_ext.jar']
48
+ task test: "lib/snappy_ext.jar"
49
+ task build: [:clean, "lib/snappy_ext.jar"]
47
50
  else
48
51
  file "ext/snappy_ext.#{DLEXT}" => Dir.glob("ext/*{.rb,.c}") do
49
52
  Dir.chdir("ext") do
@@ -53,15 +56,15 @@ else
53
56
  cp "ext/snappy_ext.#{DLEXT}", "lib/snappy_ext.#{DLEXT}"
54
57
  end
55
58
 
56
-
57
- task :test => "ext/snappy_ext.#{DLEXT}"
59
+ task test: "ext/snappy_ext.#{DLEXT}"
58
60
  end
59
61
 
60
- desc 'Clean up build artifacts'
62
+ desc "Clean up build artifacts"
61
63
  task :clean do
62
- rm_rf 'ext/java/build'
63
- rm_rf 'lib/snappy_ext.jar'
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-*'])
64
+ rm_rf "ext/java/build"
65
+ rm_rf "lib/snappy_ext.jar"
66
+ rm_rf(["ext/snappy_ext.#{DLEXT}", "lib/snappy_ext.#{DLEXT}", "ext/mkmf.log", "ext/config.h", "ext/api.o",
67
+ "ext/Makefile", "ext/snappy.cc", "ext/snappy.h", "ext/snappy.o"] + Dir["ext/snappy-*"])
65
68
  end
66
69
 
67
- task :default => :test
70
+ task default: :test
data/ext/api.c CHANGED
@@ -1,7 +1,6 @@
1
1
  #include "ruby.h"
2
2
  #include "snappy-c.h"
3
3
 
4
- static VALUE rb_mSnappy;
5
4
  static VALUE rb_eSnappy;
6
5
 
7
6
  static VALUE
@@ -92,10 +91,16 @@ snappy_valid_p(VALUE self, VALUE str)
92
91
 
93
92
  void Init_snappy_ext()
94
93
  {
94
+ #if HAVE_RB_EXT_RACTOR_SAFE
95
+ rb_ext_ractor_safe(true);
96
+ #endif
97
+
98
+ VALUE rb_mSnappy;
95
99
  VALUE rb_mSnappy_singleton;
96
100
 
97
101
  rb_mSnappy = rb_define_module("Snappy");
98
102
  rb_eSnappy = rb_define_class_under(rb_mSnappy, "Error", rb_eStandardError);
103
+ rb_global_variable(&rb_eSnappy);
99
104
  rb_define_singleton_method(rb_mSnappy, "deflate", snappy_deflate, -1);
100
105
  rb_define_singleton_method(rb_mSnappy, "inflate", snappy_inflate, -1);
101
106
  rb_define_singleton_method(rb_mSnappy, "valid?", snappy_valid_p, 1);
@@ -1,37 +1,34 @@
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
-
9
- unless have_library 'snappy'
4
+ unless pkg_config('libsnappy') || have_library('snappy')
10
5
  # build vendor/snappy
11
6
  pwd = File.dirname File.expand_path __FILE__
12
7
  dir = File.join pwd, '..', 'vendor', 'snappy'
13
8
 
14
- Dir.chdir dir do
15
- unless system './autogen.sh'
16
- patch_autogen
17
- raise '`autogen.sh` failed' unless system './autogen.sh'
9
+ Dir.chdir(dir) do
10
+ FileUtils.mkdir_p 'build'
11
+ Dir.chdir(File.join(dir, 'build')) do
12
+ `cmake .. -DCMAKE_BUILD_TYPE=Release`
18
13
  end
19
- raise '`configure` failed' unless system './configure --disable-option-checking --disable-dependency-tracking --disable-gtest --without-gflags'
20
14
  end
21
15
 
22
- src = %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
- ).map { |e| File.join dir, e }
16
+ src = %w[
17
+ config.h
18
+ snappy-stubs-public.h
19
+ ].map { |e| File.join dir, 'build', e }
20
+ FileUtils.cp src, pwd, :verbose => true
21
+ src = %w[
22
+ snappy-c.cc
23
+ snappy-c.h
24
+ snappy-internal.h
25
+ snappy-sinksource.cc
26
+ snappy-sinksource.h
27
+ snappy.cc
28
+ snappy.h
29
+ snappy-stubs-internal.cc
30
+ snappy-stubs-internal.h
31
+ ].map { |e| File.join dir, e }
35
32
  FileUtils.cp src, pwd, :verbose => true
36
33
  end
37
34
 
@@ -1,6 +1,8 @@
1
1
  # encoding: utf-8
2
+ # frozen_string_literal: true
2
3
 
3
- require 'snappy-jars' if defined?(JRUBY_VERSION)
4
- require 'snappy_ext'
5
- require 'snappy/reader'
6
- require 'snappy/writer'
4
+ require "snappy-jars" if defined?(JRUBY_VERSION)
5
+ require "snappy_ext"
6
+ require "snappy/reader"
7
+ require "snappy/writer"
8
+ require "snappy/hadoop"
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ require 'stringio'
5
+ require 'snappy/hadoop/reader'
6
+ require 'snappy/hadoop/writer'
7
+
8
+ module Snappy
9
+ module Hadoop
10
+ def self.deflate(source, block_size = Snappy::Hadoop::Writer::DEFAULT_BLOCK_SIZE)
11
+ compressed_io = StringIO.new
12
+ writer = Snappy::Hadoop::Writer.new(compressed_io)
13
+ writer << source
14
+ writer.flush
15
+ compressed_io.string
16
+ end
17
+
18
+ def self.inflate(source)
19
+ Snappy::Hadoop::Reader.new(StringIO.new(source)).read
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'stringio'
4
+ require 'snappy/shim'
5
+
6
+ module Snappy
7
+ module Hadoop
8
+ class Reader
9
+ attr_reader :io
10
+
11
+ def initialize(io)
12
+ @io = Snappy.set_encoding io
13
+ yield self if block_given?
14
+ end
15
+
16
+ def each
17
+ return to_enum unless block_given?
18
+
19
+ until @io.eof?
20
+ # Uncompressed size (32 bit integer, BE).
21
+ uncompressed_size = @io.read(4).unpack('N').first
22
+
23
+ uncompressed_block_io = StringIO.new
24
+ while uncompressed_block_io.size < uncompressed_size
25
+ # Compressed subblock size (32 bit integer, BE).
26
+ compressed_size = @io.read(4).unpack('N').first
27
+ uncompressed_block_io << Snappy.inflate(@io.read(compressed_size))
28
+ end
29
+
30
+ if uncompressed_block_io.size > uncompressed_size
31
+ raise RuntimeError("Invalid data: expected #{uncompressed_size} bytes, got #{Uncompressed.size}")
32
+ end
33
+
34
+ yield uncompressed_block_io.string
35
+ end
36
+ end
37
+
38
+ def read
39
+ buff = StringIO.new
40
+ each do |chunk|
41
+ buff << chunk
42
+ end
43
+ buff.string
44
+ end
45
+
46
+ def each_line(sep_string = $/)
47
+ return to_enum(:each_line, sep_string) unless block_given?
48
+
49
+ last = ""
50
+ each do |chunk|
51
+ chunk = last + chunk
52
+ lines = chunk.split(sep_string)
53
+ last = lines.pop
54
+ lines.each do |line|
55
+ yield line
56
+ end
57
+ end
58
+ yield last
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'snappy/shim'
4
+
5
+ module Snappy
6
+ module Hadoop
7
+ class Writer
8
+ DEFAULT_BLOCK_SIZE = 256 * 1024
9
+
10
+ attr_reader :io, :block_size
11
+
12
+ def initialize(io, block_size = DEFAULT_BLOCK_SIZE)
13
+ @block_size = block_size
14
+ @buffer = String.new
15
+ @io = Snappy.set_encoding io
16
+ if block_given?
17
+ yield self
18
+ dump!
19
+ end
20
+ end
21
+
22
+ def <<(msg)
23
+ @buffer << msg.to_s
24
+ dump! if @buffer.size >= @block_size
25
+ end
26
+
27
+ alias_method :write, :<<
28
+
29
+ def dump!
30
+ offset = 0
31
+ while offset < @buffer.size
32
+ uncompressed = @buffer[offset, @block_size]
33
+ compressed = Snappy.deflate(uncompressed)
34
+
35
+ # Uncompressed size (32 bit integer, BE), compressed size (32 bit integer, BE), data.
36
+ @io << [uncompressed.size, compressed.size, compressed].pack("NNa#{compressed.size}")
37
+ offset += uncompressed.size
38
+ end
39
+
40
+ @io.flush
41
+ @buffer.clear
42
+ end
43
+
44
+ alias_method :flush, :dump!
45
+
46
+ def close
47
+ @io.close
48
+ end
49
+ end
50
+ end
51
+ end