rustsync 0.2.0

A pure Rust implementation of rsync
Documentation

An implementation of an rsync-like protocol (not compatible with rsync), in pure Rust.

extern crate rand;
extern crate rsync;
use rsync::*;
use rand::Rng;
fn main() {
  let mut chunks = Vec::new();
  let chunk_size = 10;
  for _ in 0..100 {
      chunks.push(rand::thread_rng()
                  .gen_ascii_chars()
                  .take(chunk_size)
                  .collect::<String>())
  }

  let mut source = String::new();
  for c in chunks.iter() {
      source.push_str(c)
  }

  let mut modified = String::new();
  for i in 0..chunks.len() {
      if i == 20 {
          modified.push_str(
              &rand::thread_rng()
               .gen_ascii_chars()
               .take(chunk_size/2)
               .collect::<String>()
          )
      } else {
          modified.push_str(&chunks[i])
      }
  }

  let block = [0; 32];
  let source_sig = signature(source.as_bytes(), block).unwrap();
  let comp = compare(&source_sig, modified.as_bytes(), block).unwrap();

  let mut restored = Vec::new();
  restore_seek(&mut restored, std::io::Cursor::new(source.as_bytes()), vec![0; 1000], &comp).unwrap();
  assert_eq!(&restored[..], modified.as_bytes())
}