Streaming API

36 views
Skip to first unread message

C.J. Wagenius

unread,
Feb 26, 2021, 3:41:20 AM2/26/21
to librsync
Hi.

I'm trying to make use of the streaming API but I get into trouble when generating delta. It works if I use the whole-file API, so I guess I'm doing something wrong. Help is appreciated.

Thanks.

delta.c
---
#include <stdio.h>
#include <stdlib.h>
#include <librsync.h>
 
#define BUFSZ (1024*4)
 
int main(int argc, char **argv) {
 
    int e;
    FILE *f;
    char ibuf[BUFSZ];
    char obuf[BUFSZ];
    rs_job_t *job = NULL;
    rs_signature_t *sig = NULL;
    rs_buffers_t rsb = { 0 };
 
    if (argv[1] == NULL) {
        fputs("USAGE: delta newfile < sigfile > deltafile\n", stderr);
        return EXIT_FAILURE;
    }
    if (!(f = fopen(argv[1], "r"))) {
        perror(NULL);
        return EXIT_FAILURE;
    }
 
    if (rs_loadsig_file(stdin, &sig, NULL) || rs_build_hash_table(sig))
        goto cleanup;
    job = rs_delta_begin(sig);
 
    do {
        rsb.next_in = ibuf, rsb.avail_in = sizeof(ibuf);
        rsb.avail_in = fread(ibuf, 1, rsb.avail_in, f);
        if (rsb.avail_in == 0) {
            if (ferror(f)) {
                perror(NULL);
                goto cleanup;
            }
            rsb.eof_in = 1;
        }
        do {
            rsb.next_out = obuf, rsb.avail_out = sizeof(obuf);
            e = rs_job_iter(job, &rsb);
            if (e != RS_DONE && e != RS_BLOCKED)
                goto cleanup;
            fwrite(obuf, 1, sizeof(obuf) - rsb.avail_out, stdout);
        } while (rsb.avail_in);
    } while (!rsb.eof_in);
 
cleanup:
    fclose(f);
    if (job)
        rs_job_free(job);
    if (sig)
        rs_free_sumset(sig);
 
    return rsb.eof_in ? EXIT_SUCCESS : EXIT_FAILURE;
}
---

C.J. Wagenius

unread,
Feb 26, 2021, 3:52:30 AM2/26/21
to librsync
The delta generated isn't complete. The size of it is smaller than the whole-file generated one. It also generate 'Bad address' when patching. File- and buffer sizes doesn't matter.

C.J. Wagenius

unread,
Feb 26, 2021, 7:51:52 AM2/26/21
to librsync
Never mind. Suddenly it works. I messed up somewhere but I don't know where. Hours wasted...

/cjw

--
You received this message because you are subscribed to a topic in the Google Groups "librsync" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/librsync/UsWWXUhQjnI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to librsync+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/librsync/713e3413-7021-4331-9710-00a3034faed8n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages