Skip to main content

zsync_rs/
lib.rs

1//! Efficient partial file transfer over HTTP, compatible with zsync.
2//!
3//! A `.zsync` control file describes a target file as a list of block
4//! checksums. A client that already holds similar data, such as an older
5//! version of the same file, finds the blocks it has locally and downloads
6//! only the rest with HTTP range requests. Nothing beyond a plain web server
7//! that honours `Range` is needed on the serving side.
8//!
9//! [`ZsyncAssembly`] drives a whole transfer and is the place to start. The
10//! modules beneath it are public for callers that need one piece on its own:
11//! [`control`] reads and writes control files, [`matcher`] finds known
12//! blocks in local data, [`http`] fetches ranges, and [`checksum`] and
13//! [`rsum`] are the hashes the format is built on.
14//!
15//! ```no_run
16//! use std::path::Path;
17//! use zsync_rs::ZsyncAssembly;
18//!
19//! # fn main() -> Result<(), zsync_rs::AssemblyError> {
20//! let mut assembly =
21//!     ZsyncAssembly::from_url("https://example.com/file.zsync", Path::new("file.bin"))?;
22//!
23//! assembly.submit_source_file(Path::new("old-file.bin"))?;
24//! while assembly.download_missing_blocks()? > 0 {}
25//!
26//! // Fails if any block is still missing, then verifies the SHA-1.
27//! assembly.complete()?;
28//! # Ok(())
29//! # }
30//! ```
31
32#![deny(missing_docs)]
33
34pub mod assembly;
35pub mod checksum;
36pub mod control;
37pub mod http;
38pub mod matcher;
39pub mod rsum;
40
41pub use assembly::{AssemblyError, ZsyncAssembly};
42pub use control::{ControlFile, GenerateError, WriteError};
43pub use http::{HttpClient, HttpError};
44pub use matcher::BlockMatcher;