rrdiff 0.9.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README +32 -0
- data/Rakefile +24 -0
- data/ext/rrdiff/extconf.rb +6 -0
- data/ext/rrdiff/rrdiff.c +82 -0
- data/lib/rrdiff/file.rb +33 -0
- data/lib/rrdiff.rb +4 -0
- data/rrdiff.gemspec +23 -0
- data/spec/deltafile.correct +0 -0
- data/spec/newfile +1 -0
- data/spec/oldfile +1 -0
- data/spec/rrdiff_spec.rb +34 -0
- data/spec/sigfile.correct +0 -0
- metadata +86 -18
- data/ext/extconf.rb +0 -5
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.gem
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
(The MIT License)
|
2
|
+
|
3
|
+
Copyright (c) 2005-2010 The RSpec Development Team
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
19
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
20
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
21
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
22
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
rrdiff - Ruby bindings to librsync/rdiff.
|
2
|
+
|
3
|
+
Lets say you have two files oldfile and newfile where newfile
|
4
|
+
is a modified version of oldfile. We want to be able to apply
|
5
|
+
the change to oldfile such that it becomes newfile.
|
6
|
+
|
7
|
+
The first process is to create a signature for the oldfile. The
|
8
|
+
parameters are the original file and where you want to store
|
9
|
+
the signature file.
|
10
|
+
|
11
|
+
RRDiff.signature("oldfile", "sigfile")
|
12
|
+
|
13
|
+
Then from the newfile and the sigfile generate a delta. Deltafile
|
14
|
+
is where the delta is stored.
|
15
|
+
|
16
|
+
RRDiff.delta("newfile", "sigfile", "deltafile")
|
17
|
+
|
18
|
+
Finally, apply the deltafile to the oldfile to create the patchedfile
|
19
|
+
which should be equivalent to newfile.
|
20
|
+
|
21
|
+
RRDiff.patch("oldfile", "deltafile", "patchedfile")
|
22
|
+
|
23
|
+
There is also a File interface, that you can pass File instances.
|
24
|
+
It will return Tempfiles.
|
25
|
+
|
26
|
+
RRDiff::File.signature(oldfile) #=> <File>
|
27
|
+
|
28
|
+
RRDiff::File.delta(sigfile, newfile) #=> <File>
|
29
|
+
|
30
|
+
RRDiff::File.diff(oldfile, newfile) #=> <File>
|
31
|
+
|
32
|
+
RRDiff::File.patch(oldfile, deltafile) #=> <File>
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake/clean'
|
3
|
+
require 'rspec/core/rake_task'
|
4
|
+
|
5
|
+
NAME = 'rrdiff'
|
6
|
+
|
7
|
+
# rule to build the extension: this says
|
8
|
+
# that the extension should be rebuilt
|
9
|
+
# after any change to the files in ext
|
10
|
+
file "lib/#{NAME}/#{NAME}.#{RbConfig::CONFIG['DLEXT']}" => Dir.glob("ext/#{NAME}/*{.rb,.c}") do
|
11
|
+
Dir.chdir("ext/#{NAME}") do
|
12
|
+
# this does essentially the same thing
|
13
|
+
# as what RubyGems does
|
14
|
+
ruby "extconf.rb"
|
15
|
+
sh "make"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
CLEAN.include('ext/**/*{.o,.log,.so,.bundle}')
|
20
|
+
CLEAN.include('ext/**/Makefile')
|
21
|
+
CLOBBER.include('lib/**/*.so')
|
22
|
+
|
23
|
+
RSpec::Core::RakeTask.new(:spec)
|
24
|
+
task :default => ["lib/#{NAME}/#{NAME}.#{RbConfig::CONFIG['DLEXT']}", :spec]
|
data/ext/rrdiff/rrdiff.c
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
#include <stdio.h>
|
3
|
+
#include <stdlib.h>
|
4
|
+
#include <librsync.h>
|
5
|
+
|
6
|
+
VALUE RRDiff = Qnil;
|
7
|
+
|
8
|
+
static VALUE rrdiff_signature(VALUE mod, VALUE old_file, VALUE sig_file)
|
9
|
+
{
|
10
|
+
FILE *basis, *signature;
|
11
|
+
|
12
|
+
rs_result result;
|
13
|
+
rs_stats_t stats;
|
14
|
+
|
15
|
+
basis = fopen(StringValuePtr(old_file), "rb");
|
16
|
+
signature = fopen(StringValuePtr(sig_file), "wb");
|
17
|
+
|
18
|
+
result = rs_sig_file(basis, signature, RS_DEFAULT_BLOCK_LEN, RS_DEFAULT_STRONG_LEN, &stats);
|
19
|
+
|
20
|
+
fclose(basis);
|
21
|
+
fclose(signature);
|
22
|
+
|
23
|
+
return Qnil;
|
24
|
+
}
|
25
|
+
|
26
|
+
static VALUE rrdiff_delta(VALUE mod, VALUE new_file, VALUE sig_file, VALUE delta_file)
|
27
|
+
{
|
28
|
+
FILE *newfile, *sigfile, *deltafile;
|
29
|
+
|
30
|
+
rs_result result;
|
31
|
+
rs_stats_t stats;
|
32
|
+
rs_signature_t *sig;
|
33
|
+
|
34
|
+
newfile = fopen(StringValuePtr(new_file), "rb");
|
35
|
+
sigfile = fopen(StringValuePtr(sig_file), "rb");
|
36
|
+
deltafile = fopen(StringValuePtr(delta_file), "wb");
|
37
|
+
|
38
|
+
if((result = rs_loadsig_file(sigfile, &sig, &stats)) != RS_DONE)
|
39
|
+
return Qnil;
|
40
|
+
|
41
|
+
if ((result = rs_build_hash_table(sig)) != RS_DONE)
|
42
|
+
return Qnil;
|
43
|
+
|
44
|
+
result = rs_delta_file(sig, newfile, deltafile, &stats);
|
45
|
+
|
46
|
+
rs_free_sumset(sig);
|
47
|
+
|
48
|
+
fclose(newfile);
|
49
|
+
fclose(sigfile);
|
50
|
+
fclose(deltafile);
|
51
|
+
|
52
|
+
return Qnil;
|
53
|
+
}
|
54
|
+
|
55
|
+
static VALUE rrdiff_patch(VALUE mod, VALUE old_file, VALUE delta_file, VALUE patched_file)
|
56
|
+
{
|
57
|
+
FILE *basisfile, *deltafile, *newfile;
|
58
|
+
|
59
|
+
rs_stats_t stats;
|
60
|
+
rs_result result;
|
61
|
+
|
62
|
+
basisfile = fopen(StringValuePtr(old_file), "rb");
|
63
|
+
deltafile = fopen(StringValuePtr(delta_file), "rb");
|
64
|
+
newfile = fopen(StringValuePtr(patched_file), "wb");
|
65
|
+
|
66
|
+
result = rs_patch_file(basisfile, deltafile, newfile, &stats);
|
67
|
+
|
68
|
+
fclose(newfile);
|
69
|
+
fclose(deltafile);
|
70
|
+
fclose(basisfile);
|
71
|
+
|
72
|
+
return Qnil;
|
73
|
+
}
|
74
|
+
|
75
|
+
void Init_rrdiff()
|
76
|
+
{
|
77
|
+
RRDiff = rb_define_module("RRDiff");
|
78
|
+
|
79
|
+
rb_define_singleton_method(RRDiff, "signature", rrdiff_signature, 2);
|
80
|
+
rb_define_singleton_method(RRDiff, "delta", rrdiff_delta, 3);
|
81
|
+
rb_define_singleton_method(RRDiff, "patch", rrdiff_patch, 3);
|
82
|
+
}
|
data/lib/rrdiff/file.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require "tempfile"
|
2
|
+
|
3
|
+
module RRDiff
|
4
|
+
module File
|
5
|
+
# File interface to RRDiff
|
6
|
+
|
7
|
+
extend self
|
8
|
+
|
9
|
+
def patch(ofile, dfile)
|
10
|
+
nfile = Tempfile.new("nfile")
|
11
|
+
RRDiff.patch(ofile.path, dfile.path, nfile.path)
|
12
|
+
nfile
|
13
|
+
end
|
14
|
+
|
15
|
+
def signature(file)
|
16
|
+
sfile = Tempfile.new("sigfile")
|
17
|
+
RRDiff.signature(file.path, sfile.path)
|
18
|
+
sfile
|
19
|
+
end
|
20
|
+
|
21
|
+
def delta(sfile, file)
|
22
|
+
dfile = Tempfile.new("delfile")
|
23
|
+
RRDiff.delta(file.path, sfile.path, dfile.path)
|
24
|
+
dfile
|
25
|
+
end
|
26
|
+
|
27
|
+
def diff(ofile, nfile)
|
28
|
+
sfile = signature(ofile)
|
29
|
+
delta(sfile, nfile)
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
data/lib/rrdiff.rb
ADDED
data/rrdiff.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "rrdiff"
|
5
|
+
s.version = "0.10.0"
|
6
|
+
|
7
|
+
s.authors = ["Abhi Yerra"]
|
8
|
+
s.email = %q{ykabhinav@gmail.com}
|
9
|
+
|
10
|
+
s.add_development_dependency('rake')
|
11
|
+
s.add_development_dependency('rspec')
|
12
|
+
s.add_development_dependency('debugger')
|
13
|
+
|
14
|
+
s.description = %q{Ruby bindings to librsync which provides rdiff.}
|
15
|
+
s.summary = %q{Ruby bindings to librsync which provides rdiff.}
|
16
|
+
s.homepage = %q{http://github.com/abhiyerra/rrdiff}
|
17
|
+
|
18
|
+
s.extensions = ["ext/rrdiff/extconf.rb"]
|
19
|
+
|
20
|
+
s.files = `git ls-files`.split($/)
|
21
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
22
|
+
s.require_paths = ["lib"]
|
23
|
+
end
|
Binary file
|
data/spec/newfile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
This is maybe a test.
|
data/spec/oldfile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
This is a test
|
data/spec/rrdiff_spec.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__),'..','ext','rrdiff', 'rrdiff')
|
2
|
+
|
3
|
+
require 'debugger'
|
4
|
+
|
5
|
+
debugger; 1
|
6
|
+
|
7
|
+
describe RRDiff do
|
8
|
+
it "should create a signature from an oldfile" do
|
9
|
+
RRDiff.signature("oldfile", "sigfile")
|
10
|
+
|
11
|
+
correct_sig_file = open("sigfile.correct", "rb")
|
12
|
+
new_sig_file = open("sigfile", "rb")
|
13
|
+
|
14
|
+
correct_sig_file.read.should == new_sig_file.read
|
15
|
+
end
|
16
|
+
|
17
|
+
it "show create a delta" do
|
18
|
+
RRDiff.delta("newfile", "sigfile", "deltafile")
|
19
|
+
|
20
|
+
correct_delta_file = open("deltafile.correct", "rb")
|
21
|
+
new_delta_file = open("deltafile", "rb")
|
22
|
+
|
23
|
+
correct_delta_file.read.should == new_delta_file.read
|
24
|
+
end
|
25
|
+
|
26
|
+
it "show patch the oldfile and create a patched file" do
|
27
|
+
RRDiff.patch("oldfile", "deltafile", "patchedfile")
|
28
|
+
|
29
|
+
correct_patched_file = open("newfile", "rb")
|
30
|
+
new_patched_file = open("patchedfile", "rb")
|
31
|
+
|
32
|
+
correct_patched_file.read.should == new_patched_file.read
|
33
|
+
end
|
34
|
+
end
|
Binary file
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rrdiff
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 55
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 10
|
9
|
+
- 0
|
10
|
+
version: 0.10.0
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Abhi Yerra
|
@@ -9,48 +15,110 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date:
|
13
|
-
|
14
|
-
|
15
|
-
|
18
|
+
date: 2013-06-27 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rake
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
type: :development
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: rspec
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
hash: 3
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
version: "0"
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: debugger
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
hash: 3
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
60
|
+
type: :development
|
61
|
+
version_requirements: *id003
|
16
62
|
description: Ruby bindings to librsync which provides rdiff.
|
17
63
|
email: ykabhinav@gmail.com
|
18
64
|
executables: []
|
19
65
|
|
20
66
|
extensions:
|
21
|
-
- ext/extconf.rb
|
67
|
+
- ext/rrdiff/extconf.rb
|
22
68
|
extra_rdoc_files: []
|
23
69
|
|
24
|
-
files:
|
25
|
-
|
26
|
-
|
70
|
+
files:
|
71
|
+
- .gitignore
|
72
|
+
- Gemfile
|
73
|
+
- LICENSE
|
74
|
+
- README
|
75
|
+
- Rakefile
|
76
|
+
- ext/rrdiff/extconf.rb
|
77
|
+
- ext/rrdiff/rrdiff.c
|
78
|
+
- lib/rrdiff.rb
|
79
|
+
- lib/rrdiff/file.rb
|
80
|
+
- rrdiff.gemspec
|
81
|
+
- spec/deltafile.correct
|
82
|
+
- spec/newfile
|
83
|
+
- spec/oldfile
|
84
|
+
- spec/rrdiff_spec.rb
|
85
|
+
- spec/sigfile.correct
|
27
86
|
homepage: http://github.com/abhiyerra/rrdiff
|
28
87
|
licenses: []
|
29
88
|
|
30
89
|
post_install_message:
|
31
|
-
rdoc_options:
|
32
|
-
|
33
|
-
- --charset=UTF-8
|
90
|
+
rdoc_options: []
|
91
|
+
|
34
92
|
require_paths:
|
35
93
|
- lib
|
36
94
|
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
37
96
|
requirements:
|
38
97
|
- - ">="
|
39
98
|
- !ruby/object:Gem::Version
|
99
|
+
hash: 3
|
100
|
+
segments:
|
101
|
+
- 0
|
40
102
|
version: "0"
|
41
|
-
version:
|
42
103
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
none: false
|
43
105
|
requirements:
|
44
106
|
- - ">="
|
45
107
|
- !ruby/object:Gem::Version
|
108
|
+
hash: 3
|
109
|
+
segments:
|
110
|
+
- 0
|
46
111
|
version: "0"
|
47
|
-
version:
|
48
112
|
requirements: []
|
49
113
|
|
50
114
|
rubyforge_project:
|
51
|
-
rubygems_version: 1.
|
115
|
+
rubygems_version: 1.8.24
|
52
116
|
signing_key:
|
53
|
-
specification_version:
|
117
|
+
specification_version: 3
|
54
118
|
summary: Ruby bindings to librsync which provides rdiff.
|
55
|
-
test_files:
|
56
|
-
|
119
|
+
test_files:
|
120
|
+
- spec/deltafile.correct
|
121
|
+
- spec/newfile
|
122
|
+
- spec/oldfile
|
123
|
+
- spec/rrdiff_spec.rb
|
124
|
+
- spec/sigfile.correct
|