implement info-hash enum

This commit is contained in:
yggverse 2025-07-08 15:47:52 +03:00
parent b3bf89b6f7
commit dcbb4108fd
3 changed files with 23 additions and 8 deletions

View file

@ -1,8 +1,11 @@
mod info_hash;
use info_hash::InfoHash;
/// Parse infohash from the source filepath,
/// decode hash bytes to String array on success.
/// decode hash bytes to `InfoHash` array on success.
///
/// * return `None` if the `path` is not reachable
pub fn get(path: &str) -> Option<Vec<String>> {
pub fn get(path: &str) -> Option<Vec<InfoHash>> {
use std::io::Read;
if path.contains("://") {
todo!("URL sources yet not supported")
@ -16,12 +19,7 @@ pub fn get(path: &str) -> Option<Vec<String>> {
if l != L {
break;
}
r.push(
b[..l]
.iter()
.map(|i| format!("{i:02x}"))
.collect::<String>(),
)
r.push(InfoHash::V1(b[..l].to_vec()))
}
Some(r)
}