1 |
#!/usr/bin/perl |
2 |
|
3 |
use File::Rdiff qw(:trace :nonblocking); |
4 |
|
5 |
trace_level(LOG_INFO); |
6 |
|
7 |
if ($ARGV[0] eq "signature") { |
8 |
open $basis, "<", $ARGV[1] |
9 |
or die "$ARGV[1]: $!"; |
10 |
open $sig, ">", $ARGV[2] |
11 |
or die "$ARGV[2]: $!"; |
12 |
|
13 |
my $job = new_sig File::Rdiff::Job 128; |
14 |
my $buf = new File::Rdiff::Buffers 4096; |
15 |
|
16 |
while ($job->iter($buf) == BLOCKED) { |
17 |
# fetch more input data |
18 |
$buf->avail_in or do { |
19 |
my $in; |
20 |
65536 == sysread $basis, $in, 65536 or $buf->eof; |
21 |
$buf->in($in); |
22 |
}; |
23 |
print $sig $buf->out; |
24 |
} |
25 |
print $sig $buf->out; |
26 |
|
27 |
} elsif ($ARGV[0] eq "delta") { |
28 |
open $sig, "<$ARGV[1]" or die "$ARGV[1]: $!"; |
29 |
open $new, "<$ARGV[2]" or die "$ARGV[2]: $!"; |
30 |
open $delta, ">$ARGV[3]" or die "$ARGV[3]: $!"; |
31 |
|
32 |
# first load the signature into memory |
33 |
my $job = new_loadsig File::Rdiff::Job; |
34 |
my $buf = new File::Rdiff::Buffers 0; |
35 |
|
36 |
do { |
37 |
$buf->avail_in or do { |
38 |
my $in; |
39 |
65536 == sysread $sig, $in, 65536 or $buf->eof; |
40 |
$buf->in($in); |
41 |
}; |
42 |
} while $job->iter($buf) == BLOCKED; |
43 |
|
44 |
$sig = $job->signature; |
45 |
|
46 |
$sig->build_hash_table; |
47 |
|
48 |
# now create the delta file |
49 |
my $job = new_delta File::Rdiff::Job $sig; |
50 |
my $buf = new File::Rdiff::Buffers 65536; |
51 |
|
52 |
do { |
53 |
$buf->avail_in or do { |
54 |
my $in; |
55 |
65536 == sysread $new, $in, 65536 or $buf->eof; |
56 |
$buf->in($in); |
57 |
}; |
58 |
print $delta $buf->out; |
59 |
} while $job->iter($buf) == BLOCKED; |
60 |
print $delta $buf->out; |
61 |
|
62 |
} elsif ($ARGV[0] eq "patch") { |
63 |
open $base, "<$ARGV[1]" or die "$ARGV[1]: $!"; |
64 |
open $delta, "<$ARGV[2]" or die "$ARGV[2]: $!"; |
65 |
open $new, ">$ARGV[3]" or die "$ARGV[3]: $!"; |
66 |
|
67 |
# NYI |
68 |
File::Rdiff::patch_file $base, $delta, $new; |
69 |
} else { |
70 |
print <<EOF; |
71 |
$0 signature BASIS SIGNATURE |
72 |
$0 delta SIGNATURE NEW DELTA |
73 |
$0 patch BASE DELTA NEW |
74 |
EOF |
75 |
exit (1); |
76 |
} |
77 |
|