pub struct Pack {
pub number: usize,
pub signature: SHA1,
pub objects: Vec<Box<dyn ObjectTrait>>,
pub pool: Arc<ThreadPool>,
pub waitlist: Arc<Waitlist>,
pub caches: Arc<Caches>,
pub mem_limit: Option<usize>,
pub cache_objs_mem: Arc<AtomicUsize>,
pub clean_tmp: bool,
}Fields§
§number: usize§signature: SHA1§objects: Vec<Box<dyn ObjectTrait>>§pool: Arc<ThreadPool>§waitlist: Arc<Waitlist>§caches: Arc<Caches>§mem_limit: Option<usize>§cache_objs_mem: Arc<AtomicUsize>§clean_tmp: boolImplementations§
Source§impl Pack
impl Pack
Sourcepub fn new(
thread_num: Option<usize>,
mem_limit: Option<usize>,
temp_path: Option<PathBuf>,
clean_tmp: bool,
) -> Self
pub fn new( thread_num: Option<usize>, mem_limit: Option<usize>, temp_path: Option<PathBuf>, clean_tmp: bool, ) -> Self
§Parameters
thread_num: The number of threads to use for decoding and cache,Nonemean use the number of logical CPUs. It can’t be zero, or panicmem_limit: The maximum size of the memory cache in bytes, or None for unlimited. The 80% of it will be used for Caches
Not very accurate, because of memory alignment and other reasons, overuse about 15%temp_path: The path to a directory for temporary files, default is “./.cache_temp”
For example, thread_num = 4 will use up to 8 threads (4 for decoding and 4 for cache)clean_tmp: whether to remove temp directory when Pack is dropped
Sourcepub fn check_header(pack: &mut impl BufRead) -> Result<(u32, Vec<u8>), GitError>
pub fn check_header(pack: &mut impl BufRead) -> Result<(u32, Vec<u8>), GitError>
Checks and reads the header of a Git pack file.
This function reads the first 12 bytes of a pack file, which include the b“PACK“ magic identifier, the version number, and the number of objects in the pack. It verifies that the magic identifier is correct and that the version number is 2 (which is the version currently supported by Git). It also collects these header bytes for later use, such as for hashing the entire pack file.
§Parameters
pack- A mutable reference to an object implementing theReadtrait, representing the source of the pack file data (e.g., file, memory stream).
§Returns
A Result which is:
Ok((u32, Vec<u8>)): On successful reading and validation of the header, returns a tuple where:- The first element is the number of objects in the pack file (
u32). - The second element is a vector containing the bytes of the pack file header (
Vec<u8>).
- The first element is the number of objects in the pack file (
Err(GitError): On failure, returns aGitErrorwith a description of the issue.
§Errors
This function can return an error in the following situations:
- If the pack file does not start with the “PACK” magic identifier.
- If the pack file’s version number is not 2.
- If there are any issues reading from the provided
packsource.
Sourcepub fn decompress_data(
pack: &mut (impl BufRead + Send),
expected_size: usize,
) -> Result<(Vec<u8>, usize), GitError>
pub fn decompress_data( pack: &mut (impl BufRead + Send), expected_size: usize, ) -> Result<(Vec<u8>, usize), GitError>
Decompresses data from a given Read and BufRead source using Zlib decompression.
§Parameters
pack: A source that implements both Read and BufRead traits (e.g., file, network stream).expected_size: The expected decompressed size of the data.
§Returns
Returns a Result containing either:
- A tuple with a
Vec<u8>of the decompressed data and the total number of input bytes processed, - Or a
GitErrorin case of a mismatch in expected size or any other reading error.
Sourcepub fn decode_pack_object(
pack: &mut (impl BufRead + Send),
offset: &mut usize,
) -> Result<CacheObject, GitError>
pub fn decode_pack_object( pack: &mut (impl BufRead + Send), offset: &mut usize, ) -> Result<CacheObject, GitError>
Decodes a pack object from a given Read and BufRead source and returns the object as a CacheObject.
§Parameters
pack: A source that implements both Read and BufRead traits.offset: A mutable reference to the current offset within the pack.
§Returns
Returns a Result containing either:
- A tuple of the next offset in the pack and the original compressed data as
Vec<u8>, - Or a
GitErrorin case of any reading or decompression error.
Sourcepub fn decode<F>(
&mut self,
pack: &mut (impl BufRead + Send),
callback: F,
) -> Result<(), GitError>
pub fn decode<F>( &mut self, pack: &mut (impl BufRead + Send), callback: F, ) -> Result<(), GitError>
Decodes a pack file from a given Read and BufRead source, for each object in the pack, it decodes the object and processes it using the provided callback function.
Sourcepub fn decode_async(
self,
pack: impl BufRead + Send + 'static,
sender: UnboundedSender<Entry>,
) -> JoinHandle<Pack>
pub fn decode_async( self, pack: impl BufRead + Send + 'static, sender: UnboundedSender<Entry>, ) -> JoinHandle<Pack>
Decode a Pack in a new thread and send the CacheObjects while decoding.
Attention: It will consume the pack and return in a JoinHandle.
Sourcepub async fn decode_stream(
self,
stream: impl Stream<Item = Result<Bytes, Error>> + Unpin + Send + 'static,
sender: UnboundedSender<Entry>,
) -> Self
pub async fn decode_stream( self, stream: impl Stream<Item = Result<Bytes, Error>> + Unpin + Send + 'static, sender: UnboundedSender<Entry>, ) -> Self
Decodes a Pack from a Stream of Bytes, and sends the Entry while decoding.
Sourcepub fn rebuild_delta(
delta_obj: CacheObject,
base_obj: Arc<CacheObject>,
) -> CacheObject
pub fn rebuild_delta( delta_obj: CacheObject, base_obj: Arc<CacheObject>, ) -> CacheObject
Reconstruct the Delta Object based on the “base object” and return the new object.
pub fn rebuild_zstdelta( delta_obj: CacheObject, base_obj: Arc<CacheObject>, ) -> CacheObject
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Pack
impl !RefUnwindSafe for Pack
impl Send for Pack
impl Sync for Pack
impl Unpin for Pack
impl !UnwindSafe for Pack
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more