@@ -364,7 +364,8 @@ pub mod decode {
364
364
}
365
365
}
366
366
367
- /// A standalone function to compute a hash of kind `hash_kind` for an object of `object_kind` and its `data`.
367
+ /// A function to compute a hash of kind `hash_kind` for an object of `object_kind` and its `data`.
368
+ #[ doc( alias = "hash_object" , alias = "git2" ) ]
368
369
pub fn compute_hash ( hash_kind : gix_hash:: Kind , object_kind : Kind , data : & [ u8 ] ) -> gix_hash:: ObjectId {
369
370
let header = encode:: loose_header ( object_kind, data. len ( ) as u64 ) ;
370
371
@@ -374,3 +375,23 @@ pub fn compute_hash(hash_kind: gix_hash::Kind, object_kind: Kind, data: &[u8]) -
374
375
375
376
hasher. digest ( ) . into ( )
376
377
}
378
+
379
+ /// A function to compute a hash of kind `hash_kind` for an object of `object_kind` and its data read from `stream`
380
+ /// which has to yield exactly `stream_len` bytes.
381
+ /// Use `progress` to learn about progress in bytes processed and `should_interrupt` to be able to abort the operation
382
+ /// if set to `true`.
383
+ #[ doc( alias = "hash_file" , alias = "git2" ) ]
384
+ pub fn compute_stream_hash (
385
+ hash_kind : gix_hash:: Kind ,
386
+ object_kind : Kind ,
387
+ stream : & mut dyn std:: io:: Read ,
388
+ stream_len : u64 ,
389
+ progress : & mut dyn gix_features:: progress:: Progress ,
390
+ should_interrupt : & std:: sync:: atomic:: AtomicBool ,
391
+ ) -> std:: io:: Result < gix_hash:: ObjectId > {
392
+ let header = encode:: loose_header ( object_kind, stream_len) ;
393
+ let mut hasher = gix_features:: hash:: hasher ( hash_kind) ;
394
+
395
+ hasher. update ( & header) ;
396
+ gix_features:: hash:: bytes_with_hasher ( stream, stream_len, hasher, progress, should_interrupt)
397
+ }
0 commit comments