nitlog: oops, didn't deal properly with posts in months that haven't
[wvapps.git] / wvsync / tests / cbdelta.cc
blobbada0e95ea0ae38ff8401c813b68fca77efd085b
1 /*
2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2004 Net Integration Technologies, Inc.
5 * Generates a librsync delta that can turn one file into another.
6 * Uses a callback to handle a large delta so it doesn't need to be all in
7 * memory at once.
9 */
11 #include <strutils.h>
13 #include "wvsyncfile.h"
15 static off_t totalsize = 0;
17 void deltacb(WvSyncObj &, WvBuf &out)
19 totalsize += out.used();
20 off_t size = out.used();
21 wvcon->print("--> deltacb() called (%s)\n", size);
22 wvcon->print(hexdump_buffer(out.get(size), size));
26 int main(int argc, char *argv[])
28 if (argc < 3)
30 wvcon->print("Usage: %s srcfile newfile\n", argv[0]);
31 return -1;
34 // grab the signature
35 WvSyncFile srcfile(argv[1], "");
37 WvDynBuf sigbuf;
38 srcfile.getsig(sigbuf);
40 if (!srcfile.isok())
41 return -1;
43 size_t size = sigbuf.used();
44 wvcon->print("Signature is %s bytes.\n", size);
45 wvcon->print(hexdump_buffer(sigbuf.peek(0, size), size));
47 // make the delta
48 WvSyncFile newfile(argv[2], "");
50 WvDynBuf deltabuf;
51 newfile.makedelta(sigbuf, deltabuf, deltacb);
53 if (!newfile.isok())
54 return -1;
56 size = deltabuf.used();
57 totalsize += size;
58 wvcon->print("Here's the last bit.\n");
59 wvcon->print(hexdump_buffer(deltabuf.get(size), size));
60 wvcon->print("Delta was %s bytes.\n", totalsize);
62 return 0;