- Notifications
You must be signed in to change notification settings - Fork10
Rust bindings to librsync
License
Apache-2.0, MIT licenses found
Licenses found
mbrt/librsync-rs
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Rust bindings tolibrsync.
This library contains bindings to librsync1, to support computation and application ofnetwork deltas, used in rsync and duplicity backup applications. This library encapsulates thealgorithms of the rsync protocol, which computes differences between files efficiently.
The rsync protocol, when computes differences, does not require the presence of both files.It needs instead the new file and a set of checksums of the first file (namely the signature).Computed differences can be stored in a delta file. The rsync protocol is then able toreproduce the new file, by having the old one and the delta.
Simply add a corresponding entry to yourCargo.toml
dependency list:
[dependencies]librsync ="0.2"
And add this to your crate root:
externcrate librsync;
This crate provides the streaming operations to produce signatures, delta and patches in thetop-level module, withSignature
,Delta
andPatch
structs. Those structs take some inputstream (Read
orRead + Seek
traits) and implement another stream (Read
trait) from whichthe output can be read.
Higher level operations are provided within thewhole
submodule. If the application does notneed fine-grained control over IO operations,sig
,delta
andpatch
submodules can beused. Those functions apply the algorithms to an output stream (implementing theWrite
trait)in a single call.
This example shows how to go through the streaming APIs, starting from an input string and amodified string which act as old and new files. The example simulates a real world scenario, inwhich the signature of a base file is computed, used as input to compute differences betweenthe base file and the new one, and finally the new file is reconstructed, by using the patchand the base file.
externcrate librsync;use std::io::prelude::*;use std::io::Cursor;use librsync::{Delta,Patch,Signature};fnmain(){let base ="base file".as_bytes();let new ="modified base file".as_bytes();// create signature starting from base fileletmut sig =Signature::new(base).unwrap();// create delta from new file and the base signaturelet delta =Delta::new(new,&mut sig).unwrap();// create and store the new file from the base one and the deltaletmut patch =Patch::new(Cursor::new(base), delta).unwrap();letmut computed_new =Vec::new(); patch.read_to_end(&mut computed_new).unwrap();// test whether the computed file is exactly the new file, as expectedassert_eq!(computed_new, new);}
Note that intermediate results are not stored in temporary containers. This is possible becausethe operations implement theRead
trait. In this way the results does not need to be fully inmemory, during computation.
This example shows how to go trough the whole file APIs, starting from an input string and amodified string which act as old and new files. Unlike the streaming example, here we call asingle function, to get the computation result of signature, delta and patch operations. Thisis convenient when an output stream (like a network socket or a file) is used as output for anoperation.
externcrate librsync;use std::io::Cursor;use librsync::whole::*;fnmain(){let base ="base file".as_bytes();let new ="modified base file".as_bytes();// signatureletmut sig =Vec::new();signature(&mutCursor::new(base),&mut sig).unwrap();// deltaletmut dlt =Vec::new();delta(&mutCursor::new(new),&mutCursor::new(sig),&mut dlt).unwrap();// patchletmut out =Vec::new();patch(&mutCursor::new(base),&mutCursor::new(dlt),&mut out).unwrap();assert_eq!(out, new);}
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE orhttp://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT orhttp://opensource.org/licenses/MIT)
at your option.
This library useslibrsync, which comes with anLGPL-2.0 license. Please, be sure to fulfill librsynclicensing requirements before to use this library.
Unless you explicitly state otherwise, any contribution intentionallysubmitted for inclusion in the work by you, as defined in the Apache-2.0license, shall be dual licensed as above, without any additional terms orconditions.
About
Rust bindings to librsync