romanbsd-vcdiff 0.1.1

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.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.o
2
+ *.bundle
3
+ ext/Makefile
4
+ pkg
data/README.markdown ADDED
@@ -0,0 +1,29 @@
1
+ # VCDiff
2
+ This is a wrapper around Google's open-vcdiff library, which provides
3
+ an encoder and decoder for the format described in RFC 3284:
4
+ "The VCDIFF Generic Differencing and Compression Data Format."
5
+ The encoding strategy is largely based on Bentley-McIlroy 99:
6
+ "Data Compression Using Long Common Strings.
7
+
8
+ For more details visit: http://code.google.com/p/open-vcdiff
9
+
10
+ ## Installing
11
+ # Install the gem:
12
+ sudo gem install romanbsd-vcdiff
13
+
14
+ ## Usage
15
+ require 'VCDiff'
16
+
17
+ # Encoding
18
+ dictionary = IO.read('dictionary_file')
19
+ modified = IO.read('modified_file')
20
+ # Optional
21
+ encoder.format_flags = VCDiff::VCD_FORMAT_INTERLEAVED | VCDiff::VCD_FORMAT_CHECKSUM
22
+ encoder = VCDiff::Encoder.new(dictionary)
23
+ res = encoder.encode(modified)
24
+
25
+ # Decoding
26
+ decoder = VCDiff::Decoder.new
27
+ orig = decoder.decode(dictionary, res)
28
+
29
+ orig == modified # -> true
data/Rakefile ADDED
@@ -0,0 +1,20 @@
1
+ begin
2
+ require 'jeweler'
3
+ Jeweler::Tasks.new do |gemspec|
4
+ gemspec.name = "vcdiff"
5
+ gemspec.summary = "Wrapper aroung open-vcdiff library"
6
+ gemspec.description = %q{An encoder and decoder for the format described in
7
+ RFC 3284: "The VCDIFF Generic Differencing and Compression Data Format."
8
+ The encoding strategy is largely based on Bentley-McIlroy 99:
9
+ "Data Compression Using Long Common Strings.
10
+ This is a wrapper aroung Google's open-vcdiff library.
11
+ For more details visit: http://code.google.com/p/open-vcdiff}
12
+ gemspec.email = 'romanbsd@yahoo.com'
13
+ gemspec.homepage = 'http://github.com/romanbsd/vcdiff'
14
+ gemspec.authors = ["Roman Shterenzon"]
15
+ gemspec.extensions = ['ext/extconf.rb']
16
+ end
17
+ rescue LoadError
18
+ puts "Jeweler not available. Install it with: sudo gem install jeweler"
19
+ end
20
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
data/ext/extconf.rb ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby19
2
+ require 'mkmf'
3
+
4
+ $CFLAGS << ' -Wall'
5
+ $LDFLAGS << ' -lvcdcom -lvcdenc -lvcddec'
6
+
7
+ create_makefile('VCDiff')
@@ -0,0 +1,218 @@
1
+ // Copyright 2009 Roman Shterenzon
2
+ // Author: Roman Shterenzon
3
+ //
4
+ // Licensed under the Apache License, Version 2.0 (the "License");
5
+ // you may not use this file except in compliance with the License.
6
+ // You may obtain a copy of the License at
7
+ //
8
+ // http://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
15
+
16
+ #include <ruby.h>
17
+ #include <google/vcdecoder.h>
18
+ #include <google/vcencoder.h>
19
+ #include <string>
20
+
21
+ #ifdef __cplusplus
22
+ # ifndef RUBY_METHOD_FUNC /* These definitions should work for Ruby 1.4.6 */
23
+ # define PROTECTFUNC(f) ((VALUE (*)()) f)
24
+ # define VALUEFUNC(f) ((VALUE (*)()) f)
25
+ # define VOIDFUNC(f) ((void (*)()) f)
26
+ # else
27
+ # ifndef ANYARGS /* These definitions should work for Ruby 1.6 */
28
+ # define PROTECTFUNC(f) ((VALUE (*)()) f)
29
+ # define VALUEFUNC(f) ((VALUE (*)()) f)
30
+ # define VOIDFUNC(f) ((RUBY_DATA_FUNC) f)
31
+ # else /* These definitions should work for Ruby 1.7+ */
32
+ # define PROTECTFUNC(f) ((VALUE (*)(VALUE)) f)
33
+ # define VALUEFUNC(f) ((VALUE (*)(ANYARGS)) f)
34
+ # define VOIDFUNC(f) ((RUBY_DATA_FUNC) f)
35
+ # endif
36
+ # endif
37
+ #else
38
+ # define VALUEFUNC(f) (f)
39
+ # define VOIDFUNC(f) (f)
40
+ #endif
41
+
42
+ using namespace std;
43
+
44
+ // Destroys the class instance
45
+ static void VCDiffEncoder_destroy(open_vcdiff::VCDiffEncoder *encoder) {
46
+ delete encoder;
47
+ }
48
+
49
+ // No allocation is performed, but a destroy function assigned.
50
+ static VALUE _wrap_VCDiffEncoder_allocate(VALUE klass) {
51
+ VALUE obj;
52
+ obj = Data_Wrap_Struct(klass, 0, VCDiffEncoder_destroy, 0);
53
+ return obj;
54
+ }
55
+
56
+ static VALUE _wrap_new_VCDiffEncoder(VALUE self, VALUE arg) {
57
+ open_vcdiff::VCDiffEncoder *result = 0 ;
58
+ VALUE str;
59
+
60
+ str = StringValue(arg);
61
+ result = new open_vcdiff::VCDiffEncoder((char const *)RSTRING_PTR(str),RSTRING_LEN(str));
62
+ DATA_PTR(self) = result;
63
+ return self;
64
+ }
65
+
66
+ /* call-seq:
67
+ * encoder.format_flags=(Fixnum) => nil
68
+ *
69
+ * By default, VCDiffEncoder uses standard VCDIFF format. This function
70
+ * can be used before calling encode(), to specify that interleaved format
71
+ * and/or checksum format should be used.
72
+ */
73
+ static VALUE _wrap_VCDiffEncoder_SetFormatFlags(VALUE self, VALUE arg) {
74
+ open_vcdiff::VCDiffEncoder *encoder = NULL;
75
+ Data_Get_Struct(self, open_vcdiff::VCDiffEncoder, encoder);
76
+
77
+ encoder->SetFormatFlags(FIX2INT(arg));
78
+ return Qnil;
79
+ }
80
+
81
+ /*
82
+ * call-seq:
83
+ * encoder.target_matching=(bool) => nil
84
+ *
85
+ * By default, VCDiffEncoder looks for matches in the dictionary and also in
86
+ * the previously encoded target data. This function can be used before
87
+ * calling encode(), to specify whether or not target matching should be
88
+ * enabled.
89
+ */
90
+ static VALUE _wrap_VCDiffEncoder_SetTargetMatching(VALUE self, VALUE arg) {
91
+ open_vcdiff::VCDiffEncoder *encoder = NULL;
92
+ Data_Get_Struct(self, open_vcdiff::VCDiffEncoder, encoder);
93
+
94
+ if ( arg == Qtrue ) {
95
+ encoder->SetTargetMatching(true);
96
+ }
97
+ else if ( arg == Qfalse || arg == Qnil ) {
98
+ encoder->SetTargetMatching(false);
99
+ }
100
+ else {
101
+ rb_raise(rb_eArgError, "boolean expected");
102
+ }
103
+ return Qnil;
104
+ }
105
+
106
+ /*
107
+ * call-seq:
108
+ * encoder.encode(data) => str or nil
109
+ *
110
+ * Performs encoding of the data, returning <i>str</i>,
111
+ * or <code>nil</code> if the encoder fails.
112
+ */
113
+ static VALUE _wrap_VCDiffEncoder_Encode(VALUE self, VALUE arg) {
114
+ open_vcdiff::VCDiffEncoder *encoder = NULL;
115
+ bool result;
116
+ VALUE str;
117
+ string output;
118
+
119
+ Data_Get_Struct(self, open_vcdiff::VCDiffEncoder, encoder);
120
+ str = StringValue(arg);
121
+
122
+ result = encoder->Encode((char const *)RSTRING_PTR(str),RSTRING_LEN(str), &output);
123
+
124
+ if (result) {
125
+ str = rb_str_new(output.data(), output.length());
126
+ output.clear();
127
+ return str;
128
+ } else {
129
+ return Qnil;
130
+ }
131
+ }
132
+
133
+ // Destroys the class instance
134
+ static void VCDiffDecoder_destroy(open_vcdiff::VCDiffDecoder *decoder) {
135
+ delete decoder;
136
+ }
137
+
138
+ // Allocation is performed, a destroy function is assigned.
139
+ static VALUE _wrap_VCDiffDecoder_allocate(VALUE klass) {
140
+ VALUE obj;
141
+ obj = Data_Wrap_Struct(klass, 0, VCDiffDecoder_destroy, new open_vcdiff::VCDiffDecoder());
142
+ return obj;
143
+ }
144
+
145
+ /*
146
+ * call-seq:
147
+ * decoder.decode(dictionary, delta) => str or nil
148
+ *
149
+ * Performs decoding of the delta using the provided dictionary,
150
+ * returning <i>str</i>, or <code>nil</code> if the decoder fails.
151
+ */
152
+ static VALUE _wrap_VCDiffDecoder_Decode(VALUE self, VALUE dict, VALUE delta) {
153
+ open_vcdiff::VCDiffDecoder *decoder = NULL;
154
+ bool result;
155
+ VALUE str;
156
+ VALUE d;
157
+ string output;
158
+ string *c_delta;
159
+
160
+ Data_Get_Struct(self, open_vcdiff::VCDiffDecoder, decoder);
161
+ str = StringValue(dict);
162
+
163
+ d = StringValue(delta);
164
+ c_delta = new string(RSTRING_PTR(d), RSTRING_LEN(d));
165
+
166
+ result = decoder->Decode((char const *)RSTRING_PTR(str), RSTRING_LEN(str), *c_delta , &output);
167
+ delete c_delta;
168
+
169
+ if (result) {
170
+ str = rb_str_new(output.data(), output.length());
171
+ output.clear();
172
+ return str;
173
+ } else {
174
+ return Qnil;
175
+ }
176
+ }
177
+
178
+
179
+ /* Wrapper around http://code.google.com/p/open-vcdiff library */
180
+
181
+ static VALUE mVCDiff;
182
+
183
+ #ifdef __cplusplus
184
+ extern "C"
185
+ #endif
186
+ void Init_VCDiff(void) {
187
+ VALUE VCDiffEncoder;
188
+ VALUE VCDiffDecoder;
189
+
190
+ mVCDiff = rb_define_module("VCDiff");
191
+
192
+ VCDiffEncoder = rb_define_class_under(mVCDiff, "Encoder", rb_cObject);
193
+ rb_define_alloc_func(VCDiffEncoder, _wrap_VCDiffEncoder_allocate);
194
+
195
+ rb_define_method(VCDiffEncoder, "initialize", VALUEFUNC(_wrap_new_VCDiffEncoder), 1);
196
+ rb_define_method(VCDiffEncoder, "format_flags=", VALUEFUNC(_wrap_VCDiffEncoder_SetFormatFlags), 1);
197
+ rb_define_method(VCDiffEncoder, "target_matching=", VALUEFUNC(_wrap_VCDiffEncoder_SetTargetMatching), 1);
198
+ rb_define_method(VCDiffEncoder, "encode", VALUEFUNC(_wrap_VCDiffEncoder_Encode), 1);
199
+
200
+ // No extensions: the encoded format will conform to the RFC
201
+ // draft standard for VCDIFF.
202
+ rb_define_const(mVCDiff, "VCD_STANDARD_FORMAT", INT2FIX(0x00));
203
+ // If this flag is specified, then the encoder writes each delta file
204
+ // window by interleaving instructions and sizes with their corresponding
205
+ // addresses and data, rather than placing these elements
206
+ // into three separate sections. This facilitates providing partially
207
+ // decoded results when only a portion of a delta file window is received
208
+ // (e.g. when HTTP over TCP is used as the transmission protocol.)
209
+ rb_define_const(mVCDiff, "VCD_FORMAT_INTERLEAVED", INT2FIX(0x01));
210
+ // If this flag is specified, then an Adler32 checksum
211
+ // of the target window data is included in the delta window.
212
+ rb_define_const(mVCDiff, "VCD_FORMAT_CHECKSUM", INT2FIX(0x02));
213
+
214
+ VCDiffDecoder = rb_define_class_under(mVCDiff, "Decoder", rb_cObject);
215
+ rb_define_alloc_func(VCDiffDecoder, _wrap_VCDiffDecoder_allocate);
216
+
217
+ rb_define_method(VCDiffDecoder, "decode", VALUEFUNC(_wrap_VCDiffDecoder_Decode), 2);
218
+ }
data/vcdiff.gemspec ADDED
@@ -0,0 +1,48 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
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 = %q{vcdiff}
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Roman Shterenzon"]
12
+ s.date = %q{2009-08-24}
13
+ s.description = %q{An encoder and decoder for the format described in
14
+ RFC 3284: "The VCDIFF Generic Differencing and Compression Data Format."
15
+ The encoding strategy is largely based on Bentley-McIlroy 99:
16
+ "Data Compression Using Long Common Strings.
17
+ This is a wrapper aroung Google's open-vcdiff library.
18
+ For more details visit: http://code.google.com/p/open-vcdiff}
19
+ s.email = %q{romanbsd@yahoo.com}
20
+ s.extensions = ["ext/extconf.rb"]
21
+ s.extra_rdoc_files = [
22
+ "README.markdown"
23
+ ]
24
+ s.files = [
25
+ ".gitignore",
26
+ "README.markdown",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "ext/extconf.rb",
30
+ "ext/vcdiff_wrap.cxx",
31
+ "vcdiff.gemspec"
32
+ ]
33
+ s.homepage = %q{http://github.com/romanbsd/vcdiff}
34
+ s.rdoc_options = ["--charset=UTF-8"]
35
+ s.require_paths = ["lib"]
36
+ s.rubygems_version = %q{1.3.4}
37
+ s.summary = %q{Wrapper aroung open-vcdiff library}
38
+
39
+ if s.respond_to? :specification_version then
40
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
41
+ s.specification_version = 3
42
+
43
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
44
+ else
45
+ end
46
+ else
47
+ end
48
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: romanbsd-vcdiff
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Roman Shterenzon
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-08-24 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: "An encoder and decoder for the format described in RFC 3284: \"The VCDIFF Generic Differencing and Compression Data Format.\" The encoding strategy is largely based on Bentley-McIlroy 99: \"Data Compression Using Long Common Strings. This is a wrapper aroung Google's open-vcdiff library. For more details visit: http://code.google.com/p/open-vcdiff"
17
+ email: romanbsd@yahoo.com
18
+ executables: []
19
+
20
+ extensions:
21
+ - ext/extconf.rb
22
+ extra_rdoc_files:
23
+ - README.markdown
24
+ files:
25
+ - .gitignore
26
+ - README.markdown
27
+ - Rakefile
28
+ - VERSION
29
+ - ext/extconf.rb
30
+ - ext/vcdiff_wrap.cxx
31
+ - vcdiff.gemspec
32
+ has_rdoc: false
33
+ homepage: http://github.com/romanbsd/vcdiff
34
+ licenses:
35
+ post_install_message:
36
+ rdoc_options:
37
+ - --charset=UTF-8
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: "0"
45
+ version:
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: "0"
51
+ version:
52
+ requirements: []
53
+
54
+ rubyforge_project:
55
+ rubygems_version: 1.3.5
56
+ signing_key:
57
+ specification_version: 3
58
+ summary: Wrapper aroung open-vcdiff library
59
+ test_files: []
60
+