pub struct ControlFile {
pub version: String,
pub filename: Option<String>,
pub mtime: Option<String>,
pub blocksize: usize,
pub length: u64,
pub hash_lengths: HashLengths,
pub urls: Vec<String>,
pub sha1: Option<String>,
pub block_checksums: Vec<BlockChecksum>,
}Expand description
A parsed control file: what the target is, where to fetch it, and the checksum of every block.
Fields§
§version: StringThe zsync header, naming the version of the tool that wrote the
file, or empty when the header is absent.
filename: Option<String>The suggested name for the target file.
mtime: Option<String>The target’s modification time, verbatim from the MTime header.
blocksize: usizeThe block size in bytes, always a power of two.
length: u64The target’s length in bytes.
hash_lengths: HashLengthsHow much of each block checksum the file stores.
urls: Vec<String>Where the target can be fetched, in the order given. A relative URL resolves against the control file’s own location.
sha1: Option<String>The target’s SHA-1 as 40 hex digits, verbatim from the SHA-1 header.
block_checksums: Vec<BlockChecksum>One entry per block of the target, in order.
Implementations§
Source§impl ControlFile
impl ControlFile
Sourcepub fn parse<R: Read>(reader: R) -> Result<Self, ParseError>
pub fn parse<R: Read>(reader: R) -> Result<Self, ParseError>
Parse a control file.
The header section is read through a byte cap. It arrives from the
network, and both a single unterminated line and an endless run of
URL: lines would otherwise grow without bound, letting the origin
choose how much memory the client spends before any of it is
validated. Unknown headers are skipped.
§Errors
Returns a ParseError naming the first problem found in the header,
or ParseError::Io when reading fails or the block records end
before every block has one.
Sourcepub fn num_blocks(&self) -> usize
pub fn num_blocks(&self) -> usize
The number of blocks in the target.
Sourcepub fn generate<R: Read + Seek>(
reader: &mut R,
filename: &str,
url: &str,
blocksize: Option<usize>,
) -> Result<Self, GenerateError>
pub fn generate<R: Read + Seek>( reader: &mut R, filename: &str, url: &str, blocksize: Option<usize>, ) -> Result<Self, GenerateError>
Generate a control file by scanning an input file.
Every block is checksummed, with the last one padded with zeros to a
full block, and the whole input is hashed with SHA-1. A blocksize of
None picks 2048 bytes for inputs under 100,000,000 bytes and 4096
otherwise. A given size must be a power of two, or the result will not
parse. The hash lengths are derived from the file and block sizes
with the formulas zsyncmake uses, url becomes the only URL, and
the version is written as 0.6.2.
§Errors
Returns GenerateError::EmptyFile for an empty input and
GenerateError::Io when reading or seeking fails.
Sourcepub fn write<W: Write>(&self, writer: &mut W) -> Result<(), WriteError>
pub fn write<W: Write>(&self, writer: &mut W) -> Result<(), WriteError>
Write the control file to a writer.
The block records are written at the lengths Self::hash_lengths
gives, so a file written here parses back to the same checksums.
§Errors
Returns WriteError::Io when the writer fails.