libz_rs_sys

Function adler32_combine

Source
#[export_name = "adler32_combine"]
pub extern "C-unwind" fn adler32_combine(
    adler1: c_ulong,
    adler2: c_ulong,
    len2: z_off_t,
) -> c_ulong
Expand description

Combines the checksum of two slices into one.

The combined value is equivalent to calculating the checksum of the whole input.

This function can be used when input arrives in chunks, or when different threads calculate the checksum of different sections of the input.

ยงExample

use libz_rs_sys::{adler32, adler32_combine};

let input = [1, 2, 3, 4, 5, 6, 7, 8];
let lo = &input[..4];
let hi = &input[4..];

unsafe {
    let full = adler32(1, input.as_ptr(), input.len() as _);

    let adler1 = adler32(1, lo.as_ptr(), lo.len() as _);
    let adler2 = adler32(1, hi.as_ptr(), hi.len() as _);

    let combined = adler32_combine(adler1, adler2, hi.len() as _);

    assert_eq!(full, combined);
}