mirror of
https://github.com/YGGverse/aquatic-crawler.git
synced 2026-04-01 01:25:36 +00:00
implement info-hash enum
This commit is contained in:
parent
b3bf89b6f7
commit
dcbb4108fd
3 changed files with 23 additions and 8 deletions
14
src/api.rs
14
src/api.rs
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue