Algorithm-GDiffDelta
view release on metacpan or search on metacpan
GDiffDelta.pm view on Meta::CPAN
gdiff_apply($orig, $delta, $changed);
# A fast adler32 digest implementation is also available:
my $adler32 = gdiff_adler32(1, 'some data');
$adler32 = gdiff_adler32($adler32, 'some more data');
=head1 DESCRIPTION
This module can be used to generate binary deltas describing the
differences between two files. Given the first file and the
delta the second file can be reconstructed.
A delta is equivalent to the output of the unix C<diff> program,
except that it can efficiently represent the differences between
similar binary files, containing any sequences of bytes. These
deltas can be used for updating files over a network (as C<rsync>
does) or for efficiently storing a revision history of changes to
a file (as Subversion does).
There are several formats used for binary deltas. The one supported
by this module is the GDIFF format, which is fairly simple and is
documented as a W3C note (See the SEE ALSO section below).
This module generates and processes deltas using file handles.
It supports both native Perl file handles (created with the built-in
C<open> format) and objects that support the right methods.
For an object to work it must support at least the C<read>, C<seek>,
and C<tell> methods (if it is an input file) or the C<write> method
(if it is an output file). This allows strings to be used for input
and output, by wrapping them in an L<IO::Scalar|IO::Scalar> object
or similar. A future version of this module might support reading
and writing directly through references to scalars, because that
should be much more efficient.
See the section ALGORITHM AND DELTA FORMAT below for some notes on
the algorithm used by this module and how the GDIFF delta format works.
=head1 FUNCTIONS
No functions are exported by default. Pass the function names to
Exporter in the C<use> line, or use the C<:all> tag to import them all.
=over 4
=item gdiff_adler32(I<$initial_value>, I<$string_data>)
GDiffDelta.pm view on Meta::CPAN
available. It isn't needed for generating or applying binary delta files.
The I<$initial_value> should usually be 1. The result of calling this
function (which is a 32-bit unsigned integer value) can be passed back
in as a new initial value to checksum some more data. This allows a
large file to be checksummed in separate chunks.
Another implementation of Adler-32 is provided in the
L<Digest::Adler32|Digest::Adler32> module.
The Adler-32 checksum algorithm is defined in RFC 1950, section 8.2.
Sample code in C is also provided there.
=item gdiff_apply(I<$file1>, I<$file2>, I<$delta_file>)
Takes three file handles. The first two are read from, and it must
be possible to seek in them. The third is written to.
This generates a binary delta describing the changes from I<$file1>
to I<$file2>. The delta will allow I<$file2> to be reconstructed
from I<$file1> later.
compile_gdiff view on Meta::CPAN
my $n = $1;
die "line $.: bad 'data_N' command\n"
unless $n >= 1 && $n <= 246 && @arg == 1;
die "line $.: wrong amount of data in 'data_N' command\n"
unless length $arg[0] == $n;
print chr($n), $arg[0];
}
elsif ($opcode =~ /^data_(ushort|int)$/i) {
my $len_type = lc $1;
die "line $.: wrong number of args\n" unless @arg == 2;
die "line $.: wrong amount of data in second arg\n"
unless $arg[0] == length $arg[1];
print $DATA_OPCODE{$len_type};
write_num($len_type, $arg[0]);
print $arg[1];
}
elsif ($opcode =~ /^copy_(ushort|int|long)_(ubyte|ushort|int)$/i) {
my $offset_type = lc $1;
my $len_type = lc $2;
die "line $.: wrong number of args\n" unless @arg == 2;
print $COPY_OPCODE{"${offset_type}_$len_type"};
( run in 0.698 second using v1.01-cache-2.11-cpan-39bf76dae61 )