File-Rdiff
view release on metacpan or search on metacpan
library.
$msg = strerror $rcode
Returns a string representation of the given error code. You usually
just "exit(1)" or something when a function/method fails, as all
(most?) librsync functions log the error properly, so there is
rarely a need to call this function.
$md4 = md4_file $fh
sig_file $old_fh, $sig_fh[, $block_len[, $strong_len]]
$sig = loadsig_file $fh
delta_file $signature, $new_fh, $delta_fh
patch_file $base_fh, $delta_fh, $new_fh
The File::Rdiff::Job class
The File::Rdiff::Buffers class
This class contains the input and output buffers for the non-blocking
interface. It is slightly unusual in that it allows direct manipulation
of (some) of it's internal variables.
new File::Rdiff::Buffers [$outsize]
The File::Rdiff::Job class
It is possible to have multiple jobs running at the same time. The idea
is to create job objects and then drive them incrementally with input or
output data until all date has been processed.
new_sig File::Rdiff::Job [$new_block_len[, $strong_sum_len]]
Create a job that converts a base stream into a signature stream
(i.e. creates signatures).
new_loadsig File::Rdiff::Job
Create a job that converts the input stream into a in-memory
File::Rdiff::Signature object. The signature object can be fetched
anytime with the "signature"-method.
new_delta File::Rdiff::Job $signature
Creates a job that creates (outputs) a delta between the input
stream (the newer file) and the file represented by the given
signature.
new_patch File::Rdiff::Job $callback_or_filehandle
$job->iter($buffers)
Do as much work as possible given the input and/or output data in
the File::Rdiff::Buffers structure and return either "DONE" when the
job is finished, "BLOCKED" if there aren't enough bytes available in
the input or output buffers (in which case you should deplete the
output buffer and/or fill the input buffer and loop), or some error
code indicating that the operation failed.
$job->signature
Only valid for "new_loadsig", so look there.
EXAMPLE PROGRAM ONE
Very simple program that mimics librsync's rdiff, using the simple file
utility functions. see example below for the same program, written using
the nonblocking API.
#!/usr/bin/perl
use File::Rdiff qw(:trace :file);
if ($ARGV[0] eq "signature") {
open $base, "<$ARGV[1]" or die "$ARGV[1]: $!";
open $sig, ">$ARGV[2]" or die "$ARGV[2]: $!";
File::Rdiff::sig_file $base, $sig;
} elsif ($ARGV[0] eq "delta") {
open $sig, "<$ARGV[1]" or die "$ARGV[1]: $!";
open $new, "<$ARGV[2]" or die "$ARGV[2]: $!";
open $delta, ">$ARGV[3]" or die "$ARGV[3]: $!";
$sig = loadsig_file $sig;
ref $sig or exit 1;
$sig->build_hash_table;
File::Rdiff::delta_file $sig, $new, $delta;
} elsif ($ARGV[0] eq "patch") {
open $base, "<$ARGV[1]" or die "$ARGV[1]: $!";
open $delta, "<$ARGV[2]" or die "$ARGV[2]: $!";
open $new, ">$ARGV[3]" or die "$ARGV[3]: $!";
print $sig $buf->out;
}
print $sig $buf->out;
} elsif ($ARGV[0] eq "delta") {
open $sig, "<$ARGV[1]" or die "$ARGV[1]: $!";
open $new, "<$ARGV[2]" or die "$ARGV[2]: $!";
open $delta, ">$ARGV[3]" or die "$ARGV[3]: $!";
# first load the signature into memory
my $job = new_loadsig File::Rdiff::Job;
my $buf = new File::Rdiff::Buffers 0;
do {
$buf->avail_in or do {
my $in;
65536 == sysread $sig, $in, 65536 or $buf->eof;
$buf->in($in);
};
} while $job->iter($buf) == BLOCKED;
{
my @loglevels = qw(LOG_EMERG LOG_ALERT LOG_CRIT LOG_ERR LOG_WARNING LOG_NOTICE LOG_INFO LOG_DEBUG);
my @result = qw(DONE BLOCKED RUNNING TEST_SKIPPED IO_ERROR SYNTAX_ERROR MEM_ERROR INPUT_ENDED BAD_MAGIC UNIMPLEMENTED CORRUPT INTERNAL_ERROR PARAM_ERROR);
%EXPORT_TAGS = (
loglevels => [@loglevels],
trace => [@loglevels, qw(trace_level trace_to)],
result => [@result],
error => [@result, qw(strerror)],
file => [@result, qw(md4_file sig_file loadsig_file delta_file patch_file)],
nonblocking => [@result],
);
my %export_ok;
@export_ok{map @$_, values %EXPORT_TAGS} = ();
@EXPORT_OK = keys %export_ok;
}
=item LIBRSYNC_VERSION
Returns a string representation of the given error code. You usually
just "exit(1)" or something when a function/method fails, as all (most?)
librsync functions log the error properly, so there is rarely a need to
call this function.
=item $md4 = md4_file $fh
=item sig_file $old_fh, $sig_fh[, $block_len[, $strong_len]]
=item $sig = loadsig_file $fh
=item delta_file $signature, $new_fh, $delta_fh
=item patch_file $base_fh, $delta_fh, $new_fh
=back
=head2 The File::Rdiff::Job class
=head2 The File::Rdiff::Buffers class
It is possible to have multiple jobs running at the same time. The idea
is to create job objects and then drive them incrementally with input or
output data until all date has been processed.
=over 4
=item new_sig File::Rdiff::Job [$new_block_len[, $strong_sum_len]]
Create a job that converts a base stream into a signature stream (i.e. creates signatures).
=item new_loadsig File::Rdiff::Job
Create a job that converts the input stream into a in-memory
File::Rdiff::Signature object. The signature object can be fetched anytime
with the C<signature>-method.
=item new_delta File::Rdiff::Job $signature
Creates a job that creates (outputs) a delta between the input stream (the
newer file) and the file represented by the given signature.
Do as much work as possible given the input and/or output data in the
File::Rdiff::Buffers structure and return either C<DONE> when the job is
finished, C<BLOCKED> if there aren't enough bytes available in the input
or output buffers (in which case you should deplete the output buffer
and/or fill the input buffer and loop), or some error code indicating that
the operation failed.
=item $job->signature
Only valid for C<new_loadsig>, so look there.
=back
=head1 EXAMPLE PROGRAM ONE
Very simple program that mimics librsync's rdiff, using the simple file
utility functions. see example below for the same program, written using
the nonblocking API.
#!/usr/bin/perl
if ($ARGV[0] eq "signature") {
open $base, "<$ARGV[1]" or die "$ARGV[1]: $!";
open $sig, ">$ARGV[2]" or die "$ARGV[2]: $!";
File::Rdiff::sig_file $base, $sig;
} elsif ($ARGV[0] eq "delta") {
open $sig, "<$ARGV[1]" or die "$ARGV[1]: $!";
open $new, "<$ARGV[2]" or die "$ARGV[2]: $!";
open $delta, ">$ARGV[3]" or die "$ARGV[3]: $!";
$sig = loadsig_file $sig;
ref $sig or exit 1;
$sig->build_hash_table;
File::Rdiff::delta_file $sig, $new, $delta;
} elsif ($ARGV[0] eq "patch") {
open $base, "<$ARGV[1]" or die "$ARGV[1]: $!";
open $delta, "<$ARGV[2]" or die "$ARGV[2]: $!";
open $new, ">$ARGV[3]" or die "$ARGV[3]: $!";
print $sig $buf->out;
}
print $sig $buf->out;
} elsif ($ARGV[0] eq "delta") {
open $sig, "<$ARGV[1]" or die "$ARGV[1]: $!";
open $new, "<$ARGV[2]" or die "$ARGV[2]: $!";
open $delta, ">$ARGV[3]" or die "$ARGV[3]: $!";
# first load the signature into memory
my $job = new_loadsig File::Rdiff::Job;
my $buf = new File::Rdiff::Buffers 0;
do {
$buf->avail_in or do {
my $in;
65536 == sysread $sig, $in, 65536 or $buf->eof;
$buf->in($in);
};
} while $job->iter($buf) == BLOCKED;
size_t new_block_len
size_t strong_sum_len
PROTOTYPE: $;$$
CODE:
Newz (0, RETVAL, 1, struct File__Rdiff__Job);
RETVAL->rs = rs_sig_begin (new_block_len, strong_sum_len);
OUTPUT:
RETVAL
File::Rdiff::Job
new_loadsig(class)
SV * class
CODE:
rs_signature_t *sig;
Newz (0, RETVAL, 1, struct File__Rdiff__Job);
RETVAL->rs = rs_loadsig_begin (&sig);
RETVAL->sig = new_sig (sig);
OUTPUT:
RETVAL
File::Rdiff::Job
new_delta(class, signature)
SV * class
SV * signature
CODE:
Newz (0, RETVAL, 1, struct File__Rdiff__Job);
FILE * sig_file
size_t block_len
size_t strong_len
PROTOTYPE: $$;$$
CODE:
RETVAL = rs_sig_file(old_file, sig_file, block_len, strong_len, 0);
OUTPUT:
RETVAL
File::Rdiff::Signature
loadsig_file(file)
FILE * file
CODE:
rs_result r = rs_loadsig_file(file, &RETVAL, 0);
if (r != RS_DONE)
XSRETURN_IV (r);
OUTPUT:
RETVAL
int
delta_file(signature, new_file, delta_file)
File::Rdiff::Signature signature
FILE * new_file
FILE * delta_file
if ($ARGV[0] eq "signature") {
open $base, "<$ARGV[1]" or die "$ARGV[1]: $!";
open $sig, ">$ARGV[2]" or die "$ARGV[2]: $!";
File::Rdiff::sig_file $base, $sig;
} elsif ($ARGV[0] eq "delta") {
open $sig, "<$ARGV[1]" or die "$ARGV[1]: $!";
open $new, "<$ARGV[2]" or die "$ARGV[2]: $!";
open $delta, ">$ARGV[3]" or die "$ARGV[3]: $!";
$sig = loadsig_file $sig;
ref $sig or exit 1;
$sig->build_hash_table;
File::Rdiff::delta_file $sig, $new, $delta;
} elsif ($ARGV[0] eq "patch") {
open $base, "<$ARGV[1]" or die "$ARGV[1]: $!";
open $delta, "<$ARGV[2]" or die "$ARGV[2]: $!";
open $new, ">$ARGV[3]" or die "$ARGV[3]: $!";
print $sig $buf->out;
}
print $sig $buf->out;
} elsif ($ARGV[0] eq "delta") {
open $sig, "<$ARGV[1]" or die "$ARGV[1]: $!";
open $new, "<$ARGV[2]" or die "$ARGV[2]: $!";
open $delta, ">$ARGV[3]" or die "$ARGV[3]: $!";
# first load the signature into memory
my $job = new_loadsig File::Rdiff::Job;
my $buf = new File::Rdiff::Buffers 0;
do {
$buf->avail_in or do {
my $in;
65536 == sysread $sig, $in, 65536 or $buf->eof;
$buf->in($in);
};
} while $job->iter($buf) == BLOCKED;
( run in 0.539 second using v1.01-cache-2.11-cpan-71847e10f99 )