Skip to main content

objects/delta/
delta_utils.rs

1// SPDX-License-Identifier: Apache-2.0
2//! Delta utility helpers.
3
4use super::delta_encoder::DeltaEncoder;
5
6pub fn compute_delta(base: &[u8], target: &[u8]) -> Option<(Vec<u8>, f64)> {
7    if target.is_empty() {
8        return None;
9    }
10
11    let delta = DeltaEncoder::encode(base, target);
12    let ratio = delta.len() as f64 / target.len() as f64;
13
14    if ratio < 0.9 {
15        Some((delta, ratio))
16    } else {
17        None
18    }
19}