gix_pack/data/input/
types.rs

1/// Returned by [`BytesToEntriesIter::new_from_header()`][crate::data::input::BytesToEntriesIter::new_from_header()] and as part
2/// of `Item` of [`BytesToEntriesIter`][crate::data::input::BytesToEntriesIter].
3#[derive(thiserror::Error, Debug)]
4#[allow(missing_docs)]
5pub enum Error {
6    #[error("An IO operation failed while streaming an entry")]
7    Io(#[from] gix_hash::io::Error),
8    #[error(transparent)]
9    PackParse(#[from] crate::data::header::decode::Error),
10    #[error("Failed to verify pack checksum in trailer")]
11    Verify(#[from] gix_hash::verify::Error),
12    #[error("pack is incomplete: it was decompressed into {actual} bytes but {expected} bytes where expected.")]
13    IncompletePack { actual: u64, expected: u64 },
14    #[error("The object {object_id} could not be decoded or wasn't found")]
15    NotFound { object_id: gix_hash::ObjectId },
16}
17
18/// Iteration Mode
19#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)]
20#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
21pub enum Mode {
22    /// Provide the trailer as read from the pack
23    AsIs,
24    /// Generate an own hash and trigger an error on the last iterated object
25    /// if it does not match the hash provided with the pack.
26    ///
27    /// This way the one iterating the data cannot miss corruption as long as
28    /// the iteration is continued through to the end.
29    Verify,
30    /// Generate an own hash and if there was an error or the objects are depleted early
31    /// due to partial packs, return the last valid entry and with our own hash thus far.
32    /// Note that the existing pack hash, if present, will be ignored.
33    /// As we won't know which objects fails, every object will have the hash obtained thus far.
34    /// This also means that algorithms must know about this possibility, or else might wrongfully
35    /// assume the pack is finished.
36    Restore,
37}
38
39/// Define what to do with the compressed bytes portion of a pack [`Entry`][super::Entry]
40#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)]
41#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
42pub enum EntryDataMode {
43    /// Do nothing with the compressed bytes we read
44    Ignore,
45    /// Only create a CRC32 of the entry, otherwise similar to `Ignore`
46    Crc32,
47    /// Keep them and pass them along in a newly allocated buffer
48    Keep,
49    /// As above, but also compute a CRC32
50    KeepAndCrc32,
51}
52
53impl EntryDataMode {
54    /// Returns true if a crc32 should be computed
55    pub fn crc32(&self) -> bool {
56        match self {
57            EntryDataMode::KeepAndCrc32 | EntryDataMode::Crc32 => true,
58            EntryDataMode::Keep | EntryDataMode::Ignore => false,
59        }
60    }
61    /// Returns true if compressed bytes should be kept
62    pub fn keep(&self) -> bool {
63        match self {
64            EntryDataMode::Keep | EntryDataMode::KeepAndCrc32 => true,
65            EntryDataMode::Ignore | EntryDataMode::Crc32 => false,
66        }
67    }
68}