use crate::zip::error::HeaderParseError;
pub trait PackageStreamReader: tokio::io::AsyncBufRead + Unpin + Send + Sync {}
impl<T: tokio::io::AsyncBufRead + Unpin + Send + Sync> PackageStreamReader for T {}
pub trait IntoAsyncRead {
fn into_async_reader(self) -> impl PackageStreamReader;
}
pub enum Either<A, B> {
Either(A),
Or(B),
}
impl<B> From<HeaderParseError> for Either<HeaderParseError, B> {
fn from(value: HeaderParseError) -> Self {
Self::Either(value)
}
}
pub trait PackageStream {
type Error;
type FileStream: IntoAsyncRead;
fn open_central_directory_stream(
&self,
) -> impl std::future::Future<Output = Result<(impl std::io::Read + std::io::Seek, u64), Self::Error>>;
fn open_file_header_stream(
&self,
offset: u64,
total_size: u64,
) -> impl std::future::Future<Output = Result<Self::FileStream, Either<HeaderParseError, Self::Error>>>;
fn open_raw(&self) -> impl std::future::Future<Output = Result<Self::FileStream, Self::Error>>;
fn size(&self) -> impl std::future::Future<Output = Result<u64, Self::Error>>;
fn local_header_size<R: tokio::io::AsyncBufRead + Unpin>(
reader: &mut R,
) -> impl std::future::Future<Output = Result<u64, HeaderParseError>> {
crate::zip::reader::local_header_size(reader)
}
fn name(&self) -> String;
}
impl IntoAsyncRead for tokio::io::Take<tokio::io::BufReader<tokio::fs::File>> {
fn into_async_reader(self) -> impl PackageStreamReader {
self
}
}