-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
66 lines (51 loc) · 1.96 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
#include <iostream>
#include <fstream>
#include "filedataprovider.h"
#include "signaturecalculator.h"
#include "deltacalculator.h"
/*!
* This application demonstrates an implementation of rsync algorithm for rolling hash based diff tool.
* This algorithm make use of 2 checksums (aka signatures) to be as fast, efficient and accurate as possible.
* The operation of generating a diff is described in the following papers:
* https://rsync.samba.org/tech_report
* https://www.samba.org/~tridge/phd_thesis.pdf
*/
int main(int argc, char** argv)
{
std::cout << "yardiff - yet another rdiff implementation\n";
if(argc != 4)
{
std::cout << "Usage:\n"
<< " yardiff BASE_FILE UPDATED_FILE BLOCK_SIZE\n";
return -1;
}
const std::string base_file_name = argv[1];
const std::string updated_file_name = argv[2];
const unsigned int BLOCK_SIZE = std::stoi(argv[3]);
if(BLOCK_SIZE <= 0)
{
std::cerr << "Incorrect block size used! Must be greater than 0!\n";
return -1;
}
std::ifstream base_file_handle(base_file_name, std::ios::binary);
std::ifstream updated_file_handle(updated_file_name, std::ios::binary);
if(!base_file_handle)
{
std::cerr << "Cannot open the file : "<< base_file_name << '\n';
return -1;
}
if(!updated_file_handle)
{
std::cerr << "Cannot open the file : "<< updated_file_name << '\n';
return -1;
}
FileDataProvider base_data_provider(base_file_handle, BLOCK_SIZE);
SignatureCalculator signature_calculator{base_data_provider};
const auto& signature = signature_calculator.calculate();
std::cout << "Signature: " << signature.size() << " blocks\n";
FileDataProvider updated_data_provider(updated_file_handle, BLOCK_SIZE);
DeltaCalculator delta_calculator{updated_data_provider, signature};
Delta delta = delta_calculator.calculate();
std::cout << "Delta: " << delta << '\n';
return 0;
}