pub struct Signature { /* private fields */ }
Expand description
A identifier of a file, much smaller than the file itself.
See crate-level documentation for more details.
Implementations§
source§impl Signature
impl Signature
sourcepub fn parallel_diff(&self, data: &[u8], wp: &WorkerPool) -> Difference
pub fn parallel_diff(&self, data: &[u8], wp: &WorkerPool) -> Difference
Calculate the Self::diff
in parallel using multiple OS threads.
sourcepub fn parallel_diff_with_options(
&self,
data: &[u8],
wp: &WorkerPool,
data_size_threshold: usize,
parallel_block_size: usize
) -> Difference
pub fn parallel_diff_with_options( &self, data: &[u8], wp: &WorkerPool, data_size_threshold: usize, parallel_block_size: usize ) -> Difference
Calculate the Self::diff
in parallel using multiple OS threads.
data_size_threshold
is the threshold for how long data
has to be before using the
parallel implementation. If data
is shorter than data_size_threshold
, Self::diff
is
used instead.
parallel_block_size
is the size of the blocks data
is split into before being sent to
other threads.
Panics
Panics if parallel_block_size == 0
.
source§impl Signature
impl Signature
sourcepub fn new(block_size: usize) -> SignatureBuilder
pub fn new(block_size: usize) -> SignatureBuilder
Creates a new SignatureBuilder
in which data can be added to create a list of hashes
for blocks the size of block_size
.
I recommend block size 4096
for remote transfers.
If small documents are what’s mostly being transmitted, consider 512
.
Consider running Difference::minify
if getting the smallest diff is your concern.
This creates a signature of a resource. The signature takes up much less space than the resource.
Larger block_size
s will take more less to compute but signatures become larger, as if a
block’s contents isn’t found, it has to send block_size
bytes of data.
Smaller block_size
s takes more time to compute, but send data in the Signature
.
Diffs with smaller block_size
s also have the advantage of interfering less with changes
if applied to data other than what’s written to the signature.
The HashAlgorithm
is chosen using experience with hasher’s performance and heuristics.
You can query the algorithm using Self::algorithm
.
Panics
Panics if block_size
is 0
.
sourcepub fn with_algorithm(
algorithm: HashAlgorithm,
block_size: usize
) -> SignatureBuilder
pub fn with_algorithm( algorithm: HashAlgorithm, block_size: usize ) -> SignatureBuilder
This will create a new SignatureBuilder
with the algorithm
. Consider using Self::new
if you don’t know exactly what you are doing, as it sets the algorithm for you.
You can query the algorithm using Self::algorithm
.
See Self::new
for more details and insights into how to choose block_size
.
Panics
Will panic if HashAlgorithm
is of type None*
and block_size
is larger than the
HashAlgorithm
.
Also panics if block_size
is 0
.
sourcepub const fn algorithm(&self) -> HashAlgorithm
pub const fn algorithm(&self) -> HashAlgorithm
Get the algorithm used by this signature.
sourcepub const fn block_size(&self) -> usize
pub const fn block_size(&self) -> usize
Returns the block size of this signature.
sourcepub fn diff(&self, data: &[u8]) -> Difference
pub fn diff(&self, data: &[u8]) -> Difference
Get the Difference
between the data the Signature
represents and the local data
.
This will return a struct which when serialized (using e.g. bincode
) is much smaller than
data
.