use sha1::{Digest, Sha1};
use tokio::io::{AsyncRead, AsyncReadExt};
use crate::errors::Result;
pub async fn hash_object<R: AsyncRead + Unpin>(mut r: R) -> Result<[u8; 20]> {
let mut hasher = Sha1::new();
let mut buffer = [0; 64];
loop {
let bytes = r.read(&mut buffer).await?;
if bytes == 0 {
break;
}
hasher.input(&buffer[..bytes]);
}
Ok(hasher.result().into())
}