Algorithm-GDiffDelta
view release on metacpan or search on metacpan
GDiffDelta.xs view on Meta::CPAN
else {
switch (c) {
case 247: /* ushort, <n> bytes - append <n> data bytes */
s = read_ushort(delta);
copy_data(delta, output, s, buf, "delta", "output");
break;
case 248: /* int, <n> bytes - append <n> data bytes */
s = read_int(delta);
copy_data(delta, output, s, buf, "delta", "output");
break;
case 249: /* ushort, ubyte - copy <position>, <length> */
r = read_ushort(delta);
s = read_ubyte(delta);
careful_fseek(orig, r, "original");
copy_data(orig, output, s, buf, "original", "output");
break;
case 250: /* ushort, ushort - copy <position>, <length> */
r = read_ushort(delta);
s = read_ushort(delta);
careful_fseek(orig, r, "original");
copy_data(orig, output, s, buf, "original", "output");
break;
case 251: /* ushort, int - copy <position>, <length> */
r = read_ushort(delta);
s = read_int(delta);
careful_fseek(orig, r, "original");
copy_data(orig, output, s, buf, "original", "output");
break;
case 252: /* int, ubyte - copy <position>, <length> */
r = read_int(delta);
s = read_ubyte(delta);
careful_fseek(orig, r, "original");
copy_data(orig, output, s, buf, "original", "output");
break;
case 253: /* int, ushort - copy <position>, <length> */
r = read_int(delta);
s = read_ushort(delta);
careful_fseek(orig, r, "original");
copy_data(orig, output, s, buf, "original", "output");
break;
case 254: /* int, int - copy <position>, <length> */
r = read_int(delta);
s = read_int(delta);
careful_fseek(orig, r, "original");
copy_data(orig, output, s, buf, "original", "output");
break;
case 255: /* long, int - copy <position>, <length> */
/* TODO - 64 seeking */
assert(0);
break;
default: assert(0);
}
}
}
# vi:ts=4 sw=4 expandtab:
compile_gdiff view on Meta::CPAN
next unless /\S/;
next if /^\s*#/;
my ($opcode, @arg) = split ' ';
@arg = map { parse_arg($_) } @arg;
if ($opcode =~ /^data_(\d+)$/i) {
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"};
write_num($offset_type, $arg[0]);
t/30delta.t view on Meta::CPAN
my $delta = "\xD1\xFF\xD1\xFF\x04" .
"\xF9\0\0\x02\x02XY\xF9\0\x02\x02\xF9\0\x01\x04\0";
my $ios_orig_file = IO::Scalar->new(\$orig);
my $ios_new_file = IO::Scalar->new(\$new);
my $ios_delta_file = IO::Scalar->new;
gdiff_delta($ios_orig_file, $ios_new_file, $ios_delta_file);
is("$ios_orig_file", $orig_bak,
'make sure original data in IO::Scalar still OK');
is("$ios_new_file", $new_bak,
'make sure new data in IO::Scalar still OK');
is(length "$ios_delta_file", 17,
'check delta produced with IO::Scalar is right length');
like("$ios_delta_file", qr/^\xD1\xFF\xD1\xFF\x04/, 'GDIFF header is right');
like("$ios_delta_file", qr/\x00\z/, 'GDIFF delta ends in EOF opcode');
$ios_orig_file = IO::Scalar->new(\$orig);
$ios_delta_file = IO::Scalar->new(\"$ios_delta_file");
$ios_new_file = IO::Scalar->new;
gdiff_apply($ios_orig_file, $ios_delta_file, $ios_new_file);
is("$ios_new_file", $new_bak, 'delta applies correctly');
# Maximum and minimum lengths we expect the deltas to be for the tests below.
my %DELTA_MAX_LEN = (
predefined_1 => [ 17, 17 ],
predefined_2 => [ 433, 435 ],
);
# Now test with real files, using sample data in 't/data'.
for (1 .. 2) {
my $orig_filename = catfile($data_dir, "$_.orig");
my $delta_filename = catfile($data_dir, "$_.gdiff");
my $new_filename = catfile($data_dir, "$_.new");
t/data/2.gdiff.txt view on Meta::CPAN
data_9 "[------]\n"
data_10 "[-------]\n"
data_11 "[--------]\n"
data_12 "[---------]\n"
data_13 "[----------]\n"
data_14 "[-----------]\n"
data_15 "[------------]\n"
data_16 "[-------------]\n"
data_246 "<***********************************************************************************************************************************************************************************************************************************************...
# Data commands that have an operand for the length.
data_ushort 9 "peekaboo\n"
data_int 10 "peekafoo\n\n"
# Copy commands.
copy_ushort_ubyte 18 59
copy_ushort_ushort 78 3
data_1 "\n"
copy_ushort_int 81 3
data_1 "\n"
copy_int_ubyte 84 3
( run in 0.501 second using v1.01-cache-2.11-cpan-65fba6d93b7 )