use crate::{GitOid, HashAlgorithm, ObjectType, Result};
use std::io::{BufReader, Read};
use tokio::io::AsyncReadExt;
pub struct GitOidBuilder {
hash_algorithm: HashAlgorithm,
object_type: ObjectType,
}
impl GitOidBuilder {
pub fn new(hash_algorithm: HashAlgorithm, object_type: ObjectType) -> GitOidBuilder {
GitOidBuilder {
hash_algorithm,
object_type,
}
}
pub fn build_from_bytes(&self, content: &[u8]) -> GitOid {
GitOid::new_from_bytes(self.hash_algorithm, self.object_type, content)
}
pub fn build_from_str(&self, s: &str) -> GitOid {
GitOid::new_from_str(self.hash_algorithm, self.object_type, s)
}
pub fn build_from_reader<R>(
&self,
reader: BufReader<R>,
expected_length: usize,
) -> Result<GitOid>
where
R: Read,
{
GitOid::new_from_reader(
self.hash_algorithm,
self.object_type,
reader,
expected_length,
)
}
pub async fn build_from_async_reader<R>(
&self,
reader: R,
expected_length: usize,
) -> Result<GitOid>
where
R: AsyncReadExt + Unpin,
{
GitOid::new_from_async_reader(
self.hash_algorithm,
self.object_type,
reader,
expected_length,
)
.await
}
}