use std::{convert::TryInto, path::Path};
use filebuffer::FileBuffer;
use git_hash::SIZE_OF_SHA1_DIGEST as SHA1_SIZE;
#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
pub struct Entry {
pub header: entry::Header,
pub decompressed_size: u64,
pub data_offset: u64,
}
#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
pub struct Object<'a> {
pub kind: git_object::Kind,
pub data: &'a [u8],
pub pack_location: Option<crate::bundle::Location>,
}
mod file;
pub use file::{decode_entry, verify, ResolvedBase};
pub mod header;
pub mod entry;
pub mod object;
pub mod input;
pub mod output;
pub type EntryRange = std::ops::Range<u64>;
#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)]
#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
#[allow(missing_docs)]
pub enum Version {
V2,
V3,
}
impl Default for Version {
fn default() -> Self {
Version::V2
}
}
pub struct File {
data: FileBuffer,
path: std::path::PathBuf,
pub id: u32,
version: Version,
num_objects: u32,
}
impl File {
pub fn version(&self) -> Version {
self.version
}
pub fn num_objects(&self) -> u32 {
self.num_objects
}
pub fn data_len(&self) -> usize {
self.data.len()
}
pub fn pack_end(&self) -> usize {
self.data.len() - SHA1_SIZE
}
pub fn path(&self) -> &Path {
&self.path
}
pub fn entry_slice(&self, slice: EntryRange) -> Option<&[u8]> {
let entry_end: usize = slice.end.try_into().expect("end of pack fits into usize");
let entry_start = slice.start as usize;
self.data.get(entry_start..entry_end)
}
pub fn entry_crc32(&self, pack_offset: u64, size: usize) -> u32 {
let pack_offset: usize = pack_offset.try_into().expect("pack_size fits into usize");
git_features::hash::crc32(&self.data[pack_offset..pack_offset + size])
}
}
pub(crate) mod delta;