Module: LibRubyDiff
- Defined in:
- lib/lib_ruby_diff/version.rb,
ext/lib_ruby_diff/lib_ruby_diff.c
Constant Summary collapse
- VERSION =
"0.1.1"
Class Method Summary collapse
- .delta(new_file_path, signature_file_path, delta_file_path) ⇒ Object
- .patch(base_file_path, delta_file_path, patched_file_path) ⇒ Object
- .signature(base_file_path, signature_file_path) ⇒ Object
Class Method Details
.delta(new_file_path, signature_file_path, delta_file_path) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'ext/lib_ruby_diff/lib_ruby_diff.c', line 33
static VALUE lib_ruby_diff_delta(VALUE self, VALUE new_file_path, VALUE signature_file_path, VALUE delta_file_path) {
FILE *new_file, *signature_file, *delta_file;
rs_result result;
rs_stats_t stats;
rs_signature_t *signature;
new_file = fopen(StringValuePtr(new_file_path), "rb");
signature_file = fopen(StringValuePtr(signature_file_path), "rb");
delta_file = fopen(StringValuePtr(delta_file_path), "wb");
if (!new_file || !signature_file || !delta_file) {
rb_raise(rb_eIOError, "Failed to open required files. Check they exist and you have the correct permissions.");
return Qnil;
}
result = rs_loadsig_file(signature_file, &signature, &stats);
if (result != RS_DONE) {
rb_raise(rb_eStandardError, "Failed to load signature file.");
return Qnil;
}
result = rs_build_hash_table(signature);
if (result != RS_DONE) {
rb_raise(rb_eStandardError, "Failed to build hash table.");
return Qnil;
}
result = rs_delta_file(signature, new_file, delta_file, &stats);
if (result != RS_DONE) {
rb_raise(rb_eStandardError, "Failed to create delta file.");
return Qnil;
}
rs_free_sumset(signature);
fclose(new_file);
fclose(signature_file);
fclose(delta_file);
return Qnil;
}
|
.patch(base_file_path, delta_file_path, patched_file_path) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'ext/lib_ruby_diff/lib_ruby_diff.c', line 75
static VALUE lib_ruby_diff_patch(VALUE self, VALUE base_file_path, VALUE delta_file_path, VALUE patched_file_path) {
FILE *base_file, *delta_file, *patched_file;
rs_stats_t stats;
rs_result result;
base_file = fopen(StringValuePtr(base_file_path), "rb");
delta_file = fopen(StringValuePtr(delta_file_path), "rb");
patched_file = fopen(StringValuePtr(patched_file_path), "wb");
if (!base_file || !delta_file || !patched_file) {
rb_raise(rb_eIOError, "Failed to open required files. Check they exist and you have the correct permissions.");
return Qnil;
}
result = rs_patch_file(base_file, delta_file, patched_file, &stats);
if (result != RS_DONE) {
rb_raise(rb_eStandardError, "Failed to create patched file.");
return Qnil;
}
fclose(base_file);
fclose(delta_file);
fclose(patched_file);
return Qnil;
}
|
.signature(base_file_path, signature_file_path) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'ext/lib_ruby_diff/lib_ruby_diff.c', line 8
static VALUE lib_ruby_diff_signature(VALUE self, VALUE base_file_path, VALUE signature_file_path) {
FILE *base_file, *signature_file;
rs_result result;
rs_stats_t stats;
base_file = fopen(StringValuePtr(base_file_path), "rb");
signature_file = fopen(StringValuePtr(signature_file_path), "wb");
if (!base_file || !signature_file) {
rb_raise(rb_eIOError, "Failed to open required files. Check they exist and you have the correct permissions.");
return Qnil;
}
result = rs_sig_file(base_file, signature_file, RS_DEFAULT_BLOCK_LEN, 0, RS_BLAKE2_SIG_MAGIC, &stats);
if (result != RS_DONE) {
rb_raise(rb_eStandardError, "Failed to create signature file.");
return Qnil;
}
fclose(base_file);
fclose(signature_file);
return Qnil;
}
|