#![allow(clippy::expect_used)]
use copia::Sync;
use std::io::Cursor;
fn main() {
println!("=== Copia Delta-Sync Demo ===\n");
let basis = b"The quick brown fox jumps over the lazy dog. \
This is the original content that both sides share. \
Only a small portion of this file will change.";
let source = b"The quick brown fox leaps over the lazy cat. \
This is the original content that both sides share. \
A new paragraph has been appended at the end!";
println!("Basis size: {} bytes", basis.len());
println!("Source size: {} bytes", source.len());
let sync = copia::SyncBuilder::new().block_size(512).build();
let signature = sync
.signature(Cursor::new(basis.as_slice()))
.expect("signature generation failed");
println!(
"\nSignature: {} blocks (block_size={})",
signature.blocks.len(),
signature.block_size
);
let delta = sync
.delta(Cursor::new(source.as_slice()), &signature)
.expect("delta computation failed");
println!(
"Delta: {} operations, source_size={}",
delta.ops.len(),
delta.source_size
);
println!(
" Matched: {} bytes | Literal: {} bytes",
delta.bytes_matched(),
delta.bytes_literal()
);
let mut output = Vec::new();
sync.patch(Cursor::new(basis.as_slice()), &delta, &mut output)
.expect("patch application failed");
assert_eq!(output, source, "Reconstructed output must equal source");
println!("\nPatch applied successfully — output matches source.");
println!("Reconstructed: {} bytes", output.len());
println!(
"\nReconstructed content:\n \"{}\"",
String::from_utf8_lossy(&output)
);
println!("\nDone.");
}