简单测试librsync几个接口,流程如下:
- rs_sig_file()创建签名文件
- rs_loadsig_file()加载签名文件至内存
- rs_build_hash_table()建立哈希表
- rs_delta_file()同步增量文件
progress_timer t;
cout << "testconsole.................." << endl;
cout << "version: " << rs_librsync_version << endl;
FILE* file = NULL;
file = fopen("/home/lianyi/work_file/old.txt", "r");
if (file == NULL)
cout << "open file error" << endl;
else
cout << "open file success" << endl;
FILE* fps;
fps = fopen("/home/lianyi/work_file/sig.sig", "w+");
rs_stats stat;
rs_result res = rs_sig_file(file, fps, 0, 0, RS_RK_BLAKE2_SIG_MAGIC, &stat);
fclose(file);
fclose(fps);
printf("Result code: %d\n", res);
cout << "op: " << stat.op << endl;
cout << "sig_blocks: " << stat.sig_blocks << endl;
cout << "in_bytes: " << stat.in_bytes << endl;
cout << "out_bytes: " << stat.out_bytes << endl;
FILE* fpb;
fpb = fopen("/home/lianyi/work_file/new.txt", "r");
FILE* fpd;
fpd = fopen("/home/lianyi/work_file/delta.delt", "w+");
FILE* sigFile;
sigFile = fopen("/home/lianyi/work_file/sig.sig", "r");
rs_signature_t* signature;
rs_loadsig_file(sigFile, &signature, &stat);
cout << "op: " << stat.op << endl;
cout << "sig_blocks: " << stat.sig_blocks << endl;
cout << "in_bytes: " << stat.in_bytes << endl;
cout << "out_bytes: " << stat.out_bytes << endl;
rs_build_hash_table(signature);
res = rs_delta_file(signature, fpb, fpd, &stat);
rs_free_sumset(signature);
printf("Result: %d\n", res);
cout << "op: " << stat.op << endl;
cout << "sig_blocks: " << stat.sig_blocks << endl;
cout << "in_bytes: " << stat.in_bytes << endl;
cout << "out_bytes: " << stat.out_bytes << endl;
fclose(fpb); fclose(fpd); fclose(sigFile);
/* FILE* fpd;*/
fpd = fopen("/home/lianyi/work_file/delta.delt", "r");
FILE* fpa;
fpa = fopen("/home/lianyi/work_file/old.txt", "w+");
FILE* fpn;
fpn = fopen("/home/lianyi/work_file/new2.txt", "w+");
res = rs_patch_file(fpa, fpd, fpa, &stat);
printf("Result: %d\n", res);
cout << "op: " << stat.op << endl;
cout << "sig_blocks: " << stat.sig_blocks << endl;
cout << "in_bytes: " << stat.in_bytes << endl;
cout << "out_bytes: " << stat.out_bytes << endl;
fclose(fpd); fclose(fpa); fclose(fpn);
cout << "runtime: " << t.elapsed() << endl;
cin.get();
return 0;