2023-07-04 01:19:07 -04:00
|
|
|
use {
|
|
|
|
crate::{Error, Node},
|
|
|
|
std::{
|
|
|
|
io::{ErrorKind, Read},
|
|
|
|
iter::Iterator,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2023-07-04 20:13:38 -04:00
|
|
|
/// An iterator over a series of archive `Node`'s. This struct is generic over any
|
|
|
|
/// type which implements `Read`, such as a file or a network stream.
|
2023-07-04 01:19:07 -04:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Stream<T: Read> {
|
|
|
|
reader: T,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: Read> From<T> for Stream<T> {
|
|
|
|
fn from(value: T) -> Self {
|
|
|
|
Self { reader: value }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: Read> Iterator for Stream<T> {
|
|
|
|
type Item = Result<Node, Error>;
|
|
|
|
|
|
|
|
fn next(&mut self) -> Option<Self::Item> {
|
|
|
|
match Node::read(&mut self.reader) {
|
|
|
|
Err(Error::Io(e)) if e.kind() == ErrorKind::UnexpectedEof => None,
|
2023-07-05 00:25:31 -04:00
|
|
|
Ok(f) => match f.filetype {
|
|
|
|
crate::FileType::Eof => None,
|
|
|
|
_ => Some(Ok(f)),
|
|
|
|
},
|
2023-07-04 01:19:07 -04:00
|
|
|
x => Some(x),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-07-05 23:21:30 -04:00
|
|
|
|
|
|
|
impl<T: Read> Stream<T> {
|
|
|
|
pub fn extract(&mut self, prefix: Option<&str>) -> Result<(), Error> {
|
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(feature = "parallel")]
|
|
|
|
pub fn par_extract(&mut self, prefix: Option<&str>) -> Result<(), Error> {
|
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
}
|