Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Rust bindings to librsync

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
NotificationsYou must be signed in to change notification settings

mbrt/librsync-rs

Repository files navigation

Build StatusCoverage Status

Rust bindings tolibrsync.

API Documentation

Introduction

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.

Installation

Simply add a corresponding entry to yourCargo.toml dependency list:

[dependencies]librsync ="0.2"

And add this to your crate root:

externcrate librsync;

Overview of types and modules

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.

Example: streams

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.

Example: whole file API

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

License

Licensed under either of

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.

Contribution

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

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp