gix_pack/data/input/types.rs
1/// Iteration Mode
2#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)]
3#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
4pub enum Mode {
5 /// Provide the trailer as read from the pack
6 AsIs,
7 /// Generate an own hash and trigger an error on the last iterated object
8 /// if it does not match the hash provided with the pack.
9 ///
10 /// This way the one iterating the data cannot miss corruption as long as
11 /// the iteration is continued through to the end.
12 Verify,
13 /// Generate an own hash and if there was an error or the objects are depleted early
14 /// due to partial packs, return the last valid entry and with our own hash thus far.
15 /// Note that the existing pack hash, if present, will be ignored.
16 /// As we won't know which objects fails, every object will have the hash obtained thus far.
17 /// This also means that algorithms must know about this possibility, or else might wrongfully
18 /// assume the pack is finished.
19 Restore,
20}
21
22/// Define what to do with the compressed bytes portion of a pack [`Entry`][super::Entry]
23#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)]
24#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
25pub enum EntryDataMode {
26 /// Do nothing with the compressed bytes we read
27 Ignore,
28 /// Only create a CRC32 of the entry, otherwise similar to `Ignore`
29 Crc32,
30 /// Keep them and pass them along in a newly allocated buffer
31 Keep,
32 /// As above, but also compute a CRC32
33 KeepAndCrc32,
34}
35
36impl EntryDataMode {
37 /// Returns true if a crc32 should be computed
38 pub fn crc32(&self) -> bool {
39 match self {
40 EntryDataMode::KeepAndCrc32 | EntryDataMode::Crc32 => true,
41 EntryDataMode::Keep | EntryDataMode::Ignore => false,
42 }
43 }
44 /// Returns true if compressed bytes should be kept
45 pub fn keep(&self) -> bool {
46 match self {
47 EntryDataMode::Keep | EntryDataMode::KeepAndCrc32 => true,
48 EntryDataMode::Ignore | EntryDataMode::Crc32 => false,
49 }
50 }
51}