libsnappy 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/.rspec ADDED
File without changes
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,33 @@
1
+ # Snappy
2
+
3
+ Ruby wrapper for Google's fast compressor/decompressor: http://code.google.com/p/snappy/
4
+
5
+ Snappy is a compression/decompression library. It does not aim for maximum compression, or compatibility with any other compression library; instead, it aims for very high speeds and reasonable compression. For instance, compared to the fastest mode of zlib, Snappy is an order of magnitude faster for most inputs, but the resulting compressed files are anywhere from 20% to 100% bigger. On a single core of a Core i7 processor in 64-bit mode, Snappy compresses at about 250 MB/sec or more and decompresses at about 500 MB/sec or more.
6
+
7
+ Snappy is widely used inside Google, in everything from BigTable and MapReduce to our internal RPC systems. (Snappy has previously been referred to as “Zippy” in some presentations and the likes.)
8
+
9
+ ## Installation
10
+
11
+ - Grab the latest Snappy build and install it on your system:
12
+ - [http://code.google.com/p/snappy/](http://code.google.com/p/snappy/)
13
+ - You may need 'Google Test' and 'Google Flags' to build Snappy:
14
+ - [http://code.google.com/p/googletest/](http://code.google.com/p/googletest/])
15
+ - [http://code.google.com/p/google-gflags/](http://code.google.com/p/google-gflags/)
16
+
17
+ Once you have Snappy installed on your system, you can install the gem:
18
+
19
+ gem install libsnappy
20
+
21
+ ## Example
22
+
23
+ compressed = Snappy.compress('string to compress')
24
+ uncompressed = Snappy.uncompress(compressed)
25
+
26
+ For benchmarks and motivation behind Snappy see:
27
+
28
+ - [http://blog.sesse.net/blog/tech/2011-03-22-19-24_snappy](http://blog.sesse.net/blog/tech/2011-03-22-19-24_snappy)
29
+ - [http://pastebin.com/SFaNzRuf](http://pastebin.com/SFaNzRuf)
30
+
31
+ ### License
32
+
33
+ (MIT License) - Copyright (c) 2011 Ilya Grigorik
@@ -0,0 +1,18 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ require 'rake/extensiontask'
6
+
7
+ Rake::ExtensionTask.new do |ext|
8
+ ext.name = 'libsnappy'
9
+ ext.ext_dir = 'ext'
10
+ ext.lib_dir = 'lib'
11
+ ext.config_script = 'extconf.rb'
12
+ end
13
+
14
+ desc "Run all RSpec tests"
15
+ RSpec::Core::RakeTask.new(:spec)
16
+
17
+ desc "Build libsnappy, then run tests."
18
+ task :default => [:compile, :spec]
@@ -0,0 +1,6 @@
1
+ require 'mkmf'
2
+
3
+ extension_name = 'libsnappy'
4
+ $LIBS << " -lstdc++ -lsnappy"
5
+
6
+ create_makefile(extension_name)
@@ -0,0 +1,40 @@
1
+ #include <ruby.h>
2
+ #include <snappy.h>
3
+
4
+ using namespace snappy;
5
+
6
+ typedef VALUE (ruby_method)(...);
7
+
8
+ extern "C" VALUE compress(VALUE self, VALUE input) {
9
+ string *out = new string();
10
+
11
+ size_t sz = snappy::Compress(RSTRING_PTR(input), RSTRING_LEN(input), out);
12
+ VALUE ret = rb_str_new(out->c_str(), sz);
13
+ delete out;
14
+
15
+ return ret;
16
+ }
17
+
18
+ extern "C" VALUE uncompress(VALUE self, VALUE input) {
19
+ VALUE ret;
20
+ string *out = new string();
21
+
22
+ bool pass = snappy::Uncompress(RSTRING_PTR(input), RSTRING_LEN(input), out);
23
+
24
+ if (pass)
25
+ ret = rb_str_new(out->c_str(), out->length());
26
+ else
27
+ ret = Qnil;
28
+
29
+ delete out;
30
+ return ret;
31
+ }
32
+
33
+ static VALUE RSnappy;
34
+
35
+ extern "C" void Init_libsnappy()
36
+ {
37
+ RSnappy = rb_define_class("Snappy", rb_cObject);
38
+ rb_define_singleton_method(RSnappy, "compress", (ruby_method*) &compress, 1);
39
+ rb_define_singleton_method(RSnappy, "uncompress", (ruby_method*) &uncompress, 1);
40
+ }
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "libsnappy"
6
+ s.version = "0.1.0"
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["Ilya Grigorik", "Michael Bernstein"]
9
+ s.email = ["ilya@igvita.com", "michael@spaceshipknows.com"]
10
+ s.homepage = "http://code.google.com/p/snappy/"
11
+ s.summary = "Snappy, a fast compressor/decompressor (courtesy of Google)"
12
+ s.description = s.summary
13
+
14
+ s.rubyforge_project = "libsnappy"
15
+ s.extensions = ["ext/extconf.rb"]
16
+
17
+ s.add_development_dependency "rake-compiler", "0.7.6"
18
+ s.add_development_dependency "rspec"
19
+
20
+ s.files = `git ls-files`.split("\n")
21
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
23
+ s.require_paths = ["lib"]
24
+ end
@@ -0,0 +1,26 @@
1
+ require 'rspec'
2
+ require 'libsnappy'
3
+
4
+ describe Snappy do
5
+ it 'should compress data' do
6
+ lambda do
7
+ Snappy.compress('abcdefg')
8
+ end.should_not raise_error
9
+ end
10
+
11
+ it 'should uncompress data' do
12
+ lambda do
13
+ Snappy.uncompress(Snappy.compress('abcdefg'))
14
+ end.should_not raise_error
15
+ end
16
+
17
+ it 'should roundtrip the data' do
18
+ original = 'abcdefg' * 100
19
+
20
+ compressed = Snappy.compress(original)
21
+ uncompressed = Snappy.uncompress(compressed)
22
+
23
+ original.should == uncompressed
24
+ compressed.size.should < original.size
25
+ end
26
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: libsnappy
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - Ilya Grigorik
9
+ - Michael Bernstein
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+
14
+ date: 2011-03-27 00:00:00 -04:00
15
+ default_executable:
16
+ dependencies:
17
+ - !ruby/object:Gem::Dependency
18
+ name: rake-compiler
19
+ prerelease: false
20
+ requirement: &id001 !ruby/object:Gem::Requirement
21
+ none: false
22
+ requirements:
23
+ - - "="
24
+ - !ruby/object:Gem::Version
25
+ version: 0.7.6
26
+ type: :development
27
+ version_requirements: *id001
28
+ - !ruby/object:Gem::Dependency
29
+ name: rspec
30
+ prerelease: false
31
+ requirement: &id002 !ruby/object:Gem::Requirement
32
+ none: false
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: "0"
37
+ type: :development
38
+ version_requirements: *id002
39
+ description: Snappy, a fast compressor/decompressor (courtesy of Google)
40
+ email:
41
+ - ilya@igvita.com
42
+ - michael@spaceshipknows.com
43
+ executables: []
44
+
45
+ extensions:
46
+ - ext/extconf.rb
47
+ extra_rdoc_files: []
48
+
49
+ files:
50
+ - .gitignore
51
+ - .rspec
52
+ - Gemfile
53
+ - README.md
54
+ - Rakefile
55
+ - ext/extconf.rb
56
+ - ext/libsnappy.cc
57
+ - libsnappy.gemspec
58
+ - spec/snappy_spec.rb
59
+ has_rdoc: true
60
+ homepage: http://code.google.com/p/snappy/
61
+ licenses: []
62
+
63
+ post_install_message:
64
+ rdoc_options: []
65
+
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: "0"
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: "0"
80
+ requirements: []
81
+
82
+ rubyforge_project: libsnappy
83
+ rubygems_version: 1.6.2
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: Snappy, a fast compressor/decompressor (courtesy of Google)
87
+ test_files:
88
+ - spec/snappy_spec.rb