use std::{io::Read, path::Path};
use crate::hash;
pub fn b3(bin: impl AsRef<[u8]>) -> [u8; 32] {
let bin = bin.as_ref();
let mut hasher = blake3::Hasher::new();
hasher.update(bin);
*hasher.finalize().as_bytes()
}
pub fn b3_len(bin: impl AsRef<[u8]>) -> Box<[u8]> {
let bin = bin.as_ref();
[&b3(bin)[..], &intbin::u64_bin(bin.len() as u64)[..]]
.concat()
.into()
}
pub fn b3_len_fp(path: impl AsRef<Path>) -> Result<Box<[u8]>, std::io::Error> {
let file = std::fs::File::open(path)?;
let (hash, len) = hash!(: blake3::Hasher, file);
Ok(
[hash.finalize().as_bytes(), &intbin::u64_bin(len as u64)[..]]
.concat()
.into(),
)
}