Algorithm-GDiffDelta

 view release on metacpan or  search on metacpan

GDiffDelta.pm  view on Meta::CPAN

rather than the custom format used by xdiff (which was funtionally
equivalent but a little simpler than GDIFF).

Notes about how the algorithm works should be added here once I
figure it out myself.

A GDIFF file consists of a five byte header, followed by a sequence
of commands.  Each command has a one byte 'opcode' followed by some
arguments.  The delta file is terminated by opcode zero.

There are two types of commands.  DATA commands have a chunk of literal
data as one of their arguments, which is inserted into the output.
COPY commands cause a chunk of data from the input file to be
inserted into the output.

A GDIFF delta is one-way: if it generates I<$file2> from I<$file1>
then it cannot be used to generate I<$file1> from I<$file2>.

=head1 SEE ALSO

The xdiff library, upon which this module was based:

GDiffDelta.xs  view on Meta::CPAN

                break;
            offset -= QEF_BLK_SIZE;
        }
        assert(offset == 0);
    }

    bdf->fphbits = fphbits;
    bdf->fphash = fphash;
}

/* Output a GDIFF DATA operation.  */
static void
data_op (SV *changed, SV *delta, Off_t offset, Off_t size, unsigned char *buf)
{
    size_t headsz = 0;

    assert(size > 0);
    assert(size <= QEF_INT_MAX);
    assert(buf);

    if (size <= 246)

compile_gdiff  view on Meta::CPAN

#!/usr/bin/perl -w
use strict;
use Carp;

# This little program generates GDIFF files from textual version of the
# format.  It's only intended purpose is for generating test files for
# this module.  See t/data/*.gdiff.txt for example input files.

my %DATA_OPCODE = (
    ushort => "\xF7",
    int => "\xF8",
);
my %COPY_OPCODE = (
    ushort_ubyte => "\xF9",
    ushort_ushort => "\xFA",
    ushort_int => "\xFB",
    int_ubyte => "\xFC",
    int_ushort => "\xFD",
    int_int => "\xFE",

compile_gdiff  view on Meta::CPAN

          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"};
        write_num($offset_type, $arg[0]);
        write_num($len_type, $arg[1]);



( run in 2.500 seconds using v1.01-cache-2.11-cpan-140bd7fdf52 )