Crate rustsync [] [src]

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())
}

Structs

Delta

The result of comparing two files

FutureCompare
FutureRestore
FutureSignature
ReadBlock
Signature

The "signature" of the file, which is essentially a content-indexed description of the blocks in the file.

WriteBlock

Enums

Block

Functions

compare

Compare a signature with an existing file. This is the second step of the protocol, r is the local file when downloading, and the remote file when uploading.

compare_fut

Same as compare, except that this function reads the file asynchronously.

restore

Restore a file, using a "delta" (resulting from compare)

restore_seek

Same as restore, except that this function uses a seekable, readable stream instead of the entire file in a slice.

restore_seek_fut

Same as restore_seek, except that this function writes its output asynchronously.

signature

Create the "signature" of a file, essentially a content-indexed map of blocks. The first step of the protocol is to run this function on the "source" (the remote file when downloading, the local file while uploading).

signature_fut

This is the same as signature, except that this function reads the input source asynchronously.