1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// src/api/merge.rs
// ──────────────────────────────────────────────────────────────────────────────
// Merging several .fsdb files into one, content-addressing objects on the way.
//
// The algorithm is deliberately identical to Python's `fusedb.merge()`:
// sources in argument order, keys in sorted order within each source, objects
// deduplicated by exact payload bytes, later keys overwriting earlier ones.
// Same inputs therefore produce the same file in both languages, byte for byte.
use Path;
use crate;
use FuseReader;
use FuseWriter;
/// Merge two or more `.fsdb` files into `output`.
///
/// Objects with identical payloads are stored once, so merging overlapping
/// databases costs disk space only for what is genuinely new.
///
/// # Example
/// ```no_run
/// fusedb::merge(&["geo_v1.fsdb", "geo_v2.fsdb"], "geo_merged.fsdb")?;
/// # Ok::<(), fusedb::FuseError>(())
/// ```
///
/// # Errors
/// Propagates any read error from a source (including CRC failure — every
/// source is verified on open) and any write error on `output`.
/// Fold one `.fsdb` file into an existing [`FuseWriter`].
///
/// Use this to merge databases with freshly-added records in a single pass:
///
/// ```no_run
/// use fusedb::{merge_into, FuseWriter};
///
/// let mut w = FuseWriter::new();
/// merge_into(&mut w, "geo_v1.fsdb")?;
/// w.add("new.example.com", &"fresh record")?;
/// w.build("geo_v2.fsdb")?;
/// # Ok::<(), fusedb::FuseError>(())
/// ```