lz4-ruby 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 KOMIYA Atsushi
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,65 @@
1
+ = lz4-ruby
2
+
3
+ Ruby bindings for {LZ4}[http://code.google.com/p/lz4/].
4
+
5
+ == Install
6
+
7
+ gem install lz4-ruby
8
+
9
+ == Usage
10
+
11
+ require 'rubygems'
12
+ require 'lz4-ruby'
13
+
14
+ compressed = LZ4::compress("hello, world")
15
+ # compressed = LZ4::compressHC("hello, world")
16
+ uncompressed = LZ4::uncompress(compressed)
17
+
18
+ == TODO
19
+
20
+ * Support compressCtx/compress64kCtx methods.
21
+ * Write API documents.
22
+ * Write test codes.
23
+ * Benchmark other compression libraries (lzo, snappy...).
24
+ * Optimize memory allocation.
25
+ * Support mswin32 platform.
26
+
27
+ == Copyright
28
+
29
+ Copyright (c) 2012 KOMIYA Atsushi.
30
+ See LICENSE.txt for further details.
31
+
32
+ == About LZ4
33
+
34
+ This Rubygem includes LZ4 codes written by Yann Collet.
35
+
36
+ LZ4 - Fast LZ compression algorithm
37
+ Copyright (C) 2011-2012, Yann Collet.
38
+ BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
39
+
40
+ Redistribution and use in source and binary forms, with or without
41
+ modification, are permitted provided that the following conditions are
42
+ met:
43
+
44
+ * Redistributions of source code must retain the above copyright
45
+ notice, this list of conditions and the following disclaimer.
46
+ * Redistributions in binary form must reproduce the above
47
+ copyright notice, this list of conditions and the following disclaimer
48
+ in the documentation and/or other materials provided with the
49
+ distribution.
50
+
51
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
52
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
53
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
54
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
55
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
56
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
57
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
58
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
59
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
60
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
61
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62
+
63
+ You can contact the author at :
64
+ - LZ4 homepage : http://fastcompression.blogspot.com/p/lz4.html
65
+ - LZ4 source repository : http://code.google.com/p/lz4/
@@ -0,0 +1,55 @@
1
+ # -*- mode: ruby -*-
2
+ # encoding: utf-8
3
+
4
+ require 'rubygems'
5
+ require 'bundler'
6
+ begin
7
+ Bundler.setup(:default, :development)
8
+ rescue Bundler::BundlerError => e
9
+ $stderr.puts e.message
10
+ $stderr.puts "Run `bundle install` to install missing gems"
11
+ exit e.status_code
12
+ end
13
+ require 'rake'
14
+
15
+ require 'jeweler'
16
+ Jeweler::Tasks.new do |gem|
17
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
18
+ gem.name = "lz4-ruby"
19
+ gem.homepage = "http://github.com/komiya-atsushi/lz4-ruby"
20
+ gem.license = "MIT"
21
+ gem.summary = %Q{Ruby bindings for LZ4.}
22
+ gem.description = %Q{Ruby bindings for LZ4.}
23
+ gem.email = "komiya.atsushi@gmail.com"
24
+ gem.authors = ["KOMIYA Atsushi"]
25
+ gem.extensions = "ext/extconf.rb"
26
+ # dependencies defined in Gemfile
27
+ end
28
+ Jeweler::RubygemsDotOrgTasks.new
29
+
30
+ require 'rake/testtask'
31
+ Rake::TestTask.new(:test) do |test|
32
+ test.libs << 'lib' << 'test'
33
+ test.pattern = 'test/**/test_*.rb'
34
+ test.verbose = true
35
+ end
36
+
37
+ #require 'rcov/rcovtask'
38
+ #Rcov::RcovTask.new do |test|
39
+ # test.libs << 'test'
40
+ # test.pattern = 'test/**/test_*.rb'
41
+ # test.verbose = true
42
+ # test.rcov_opts << '--exclude "gems/*"'
43
+ #end
44
+
45
+ task :default => :test
46
+
47
+ require 'rdoc/task'
48
+ Rake::RDocTask.new do |rdoc|
49
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
50
+
51
+ rdoc.rdoc_dir = 'rdoc'
52
+ rdoc.title = "lz4-ruby #{version}"
53
+ rdoc.rdoc_files.include('README*')
54
+ rdoc.rdoc_files.include('lib/**/*.rb')
55
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,25 @@
1
+ require 'mkmf'
2
+
3
+ LZ4_REV_NO = 66
4
+
5
+ URL = "http://lz4.googlecode.com/svn-history/r#{LZ4_REV_NO}/trunk/"
6
+
7
+ def download_from_web(url)
8
+ `wget #{url}`
9
+
10
+ if $?.exitstatus != 0
11
+ return false
12
+ end
13
+
14
+ return true
15
+ end
16
+
17
+ return if !download_from_web("#{URL}/lz4.c")
18
+ return if !download_from_web("#{URL}/lz4.h")
19
+ return if !download_from_web("#{URL}/lz4hc.c")
20
+ return if !download_from_web("#{URL}/lz4hc.h")
21
+
22
+ $CFLAGS += " -Wall "
23
+
24
+ create_makefile('lz4ruby')
25
+
@@ -0,0 +1,78 @@
1
+ #include <ruby.h>
2
+ #include "lz4.h"
3
+ #include "lz4hc.h"
4
+
5
+ typedef int (*CompressFunc)(const char *source, char *dest, int isize);
6
+
7
+ static VALUE lz4;
8
+
9
+ static VALUE compress(CompressFunc compressor, VALUE self, VALUE source) {
10
+ const char *src_p = NULL;
11
+ char *buf = NULL;
12
+ VALUE result;
13
+ int src_size;
14
+ int buf_size;
15
+ int comp_size;
16
+
17
+ Check_Type(source, T_STRING);
18
+ src_p = RSTRING_PTR(source);
19
+ src_size = RSTRING_LEN(source);
20
+ buf_size = LZ4_compressBound(src_size);
21
+
22
+ buf = xmalloc(buf_size + 4);
23
+ buf[0] = (char)((src_size >> 24) & 0xff);
24
+ buf[1] = (char)((src_size >> 16) & 0xff);
25
+ buf[2] = (char)((src_size >> 8) & 0xff);
26
+ buf[3] = (char)(src_size & 0xff);
27
+
28
+ comp_size = compressor(src_p, buf + 4, src_size);
29
+ result = rb_str_new(buf, comp_size + 4);
30
+
31
+ xfree(buf);
32
+
33
+ return result;
34
+ }
35
+
36
+ static VALUE lz4_ruby_compress(VALUE self, VALUE source) {
37
+ return compress(LZ4_compress, self, source);
38
+ }
39
+
40
+ static VALUE lz4_ruby_compressHC(VALUE self, VALUE source) {
41
+ return compress(LZ4_compressHC, self, source);
42
+ }
43
+
44
+ static VALUE lz4_ruby_uncompress(VALUE self, VALUE source) {
45
+ const char *src_p = NULL;
46
+ char *buf = NULL;
47
+ VALUE result;
48
+ int src_size;
49
+ int buf_size;
50
+ int read_bytes;
51
+
52
+ Check_Type(source, T_STRING);
53
+ src_p = RSTRING_PTR(source);
54
+ src_size = RSTRING_LEN(source);
55
+
56
+ buf_size = ((src_p[0] & 0xffU) << 24)
57
+ | ((src_p[1] & 0xffU) << 16)
58
+ | ((src_p[2] & 0xffU) << 8)
59
+ | (src_p[3] & 0xffU);
60
+
61
+ buf = xmalloc(buf_size);
62
+
63
+ read_bytes = LZ4_uncompress(src_p + 4, buf, buf_size);
64
+ // TODO read_bytes が負だったら、データが壊れていることを表す
65
+ result = rb_str_new(buf, buf_size);
66
+
67
+ xfree(buf);
68
+
69
+ return result;
70
+ }
71
+
72
+ void Init_lz4ruby(void) {
73
+ lz4 = rb_define_module("LZ4Native");
74
+
75
+ rb_define_module_function(lz4, "compress", lz4_ruby_compress, 1);
76
+ rb_define_module_function(lz4, "compressHC", lz4_ruby_compressHC, 1);
77
+ rb_define_module_function(lz4, "uncompress", lz4_ruby_uncompress, 1);
78
+ }
@@ -0,0 +1,15 @@
1
+ require 'lz4ruby'
2
+
3
+ class LZ4
4
+ def self.compress(source)
5
+ return LZ4Native::compress(source)
6
+ end
7
+
8
+ def self.compressHC(source)
9
+ return LZ4Native::compressHC(source)
10
+ end
11
+
12
+ def self.uncompress(source)
13
+ return LZ4Native::uncompress(source)
14
+ end
15
+ end
@@ -0,0 +1,60 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "lz4-ruby"
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["KOMIYA Atsushi"]
12
+ s.date = "2012-06-03"
13
+ s.description = "Ruby bindings for LZ4."
14
+ s.email = "komiya.atsushi@gmail.com"
15
+ s.extensions = ["ext/extconf.rb"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE.txt",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ "LICENSE.txt",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "ext/extconf.rb",
27
+ "ext/lz4ruby.c",
28
+ "lib/lz4-ruby.rb",
29
+ "lz4-ruby.gemspec",
30
+ "test/helper.rb",
31
+ "test/test_lz4-ruby.rb"
32
+ ]
33
+ s.homepage = "http://github.com/komiya-atsushi/lz4-ruby"
34
+ s.licenses = ["MIT"]
35
+ s.require_paths = ["lib"]
36
+ s.rubygems_version = "1.8.23"
37
+ s.summary = "Ruby bindings for LZ4."
38
+
39
+ if s.respond_to? :specification_version then
40
+ s.specification_version = 3
41
+
42
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
43
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
44
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
45
+ s.add_development_dependency(%q<bundler>, ["~> 1.1.4"])
46
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
47
+ else
48
+ s.add_dependency(%q<shoulda>, [">= 0"])
49
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
50
+ s.add_dependency(%q<bundler>, ["~> 1.1.4"])
51
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
52
+ end
53
+ else
54
+ s.add_dependency(%q<shoulda>, [">= 0"])
55
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
56
+ s.add_dependency(%q<bundler>, ["~> 1.1.4"])
57
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
58
+ end
59
+ end
60
+
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'lz4-ruby'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestLz4Ruby < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lz4-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - KOMIYA Atsushi
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: shoulda
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rdoc
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '3.12'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '3.12'
46
+ - !ruby/object:Gem::Dependency
47
+ name: bundler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 1.1.4
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.1.4
62
+ - !ruby/object:Gem::Dependency
63
+ name: jeweler
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 1.8.3
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 1.8.3
78
+ description: Ruby bindings for LZ4.
79
+ email: komiya.atsushi@gmail.com
80
+ executables: []
81
+ extensions:
82
+ - ext/extconf.rb
83
+ extra_rdoc_files:
84
+ - LICENSE.txt
85
+ - README.rdoc
86
+ files:
87
+ - .document
88
+ - LICENSE.txt
89
+ - README.rdoc
90
+ - Rakefile
91
+ - VERSION
92
+ - ext/extconf.rb
93
+ - ext/lz4ruby.c
94
+ - lib/lz4-ruby.rb
95
+ - lz4-ruby.gemspec
96
+ - test/helper.rb
97
+ - test/test_lz4-ruby.rb
98
+ homepage: http://github.com/komiya-atsushi/lz4-ruby
99
+ licenses:
100
+ - MIT
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ segments:
112
+ - 0
113
+ hash: 412764659
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ! '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 1.8.23
123
+ signing_key:
124
+ specification_version: 3
125
+ summary: Ruby bindings for LZ4.
126
+ test_files: []