librsync增量更新api测试

简单测试librsync几个接口,流程如下:

  1. rs_sig_file()创建签名文件
  2. rs_loadsig_file()加载签名文件至内存
  3. rs_build_hash_table()建立哈希表
  4. 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;

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值