JSON torrent detail api

This commit is contained in:
Igor Katson 2021-07-08 23:49:25 +01:00
parent 3beac77e5d
commit e7c310a1df
2 changed files with 59 additions and 42 deletions

View file

@ -85,6 +85,26 @@ where
}
impl<'a, ByteBuf> FileIteratorName<'a, ByteBuf> {
pub fn to_string(&self) -> anyhow::Result<String>
where
ByteBuf: AsRef<[u8]>,
{
let mut it = self.iter_components();
let mut buf = it
.next()
.and_then(|v| v)
.map(|v| std::str::from_utf8(v.as_ref()))
.ok_or_else(|| anyhow::anyhow!("empty filename"))??
.to_string();
for bit in it {
buf.push('/');
let bit = bit
.map(|v| std::str::from_utf8(v.as_ref()))
.ok_or_else(|| anyhow::anyhow!("empty filename"))??;
buf.push_str(bit);
}
Ok(buf)
}
pub fn to_pathbuf(&self) -> anyhow::Result<PathBuf>
where
ByteBuf: AsRef<[u8]>,