Impl new fn helpers::download_tar_based_and_visit

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2022-06-11 20:38:11 +10:00
parent 4892d8bf3a
commit f8c8c66f57
No known key found for this signature in database
GPG key ID: 591C0B03040416D6
2 changed files with 60 additions and 1 deletions

View file

@ -282,3 +282,29 @@ where
})
.await
}
pub async fn extract_tar_based_stream_and_visit<V: TarEntriesVisitor + Debug + Send + 'static, E>(
stream: impl Stream<Item = Result<Bytes, E>> + Unpin,
output: &Path,
fmt: TarBasedFmt,
mut visitor: V,
) -> Result<V, BinstallError>
where
BinstallError: From<E>,
{
let path = output.to_owned();
extract_impl(stream, move |mut rx| {
fs::create_dir_all(path.parent().unwrap())?;
extract_compressed_from_readable(
ReadableRx::new(&mut rx),
fmt,
&*path,
Some(&mut visitor),
)?;
Ok(visitor)
})
.await
}