diff --git a/src/lib.rs b/src/lib.rs index d053d01..2b48b0e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,6 +4,9 @@ mod file; mod filetype; mod node; mod special; +mod stream; + pub use { checksum::Checksum, error::Error, file::File, filetype::FileType, node::Node, special::Special, + stream::Stream, }; diff --git a/src/stream.rs b/src/stream.rs new file mode 100644 index 0000000..7345ed3 --- /dev/null +++ b/src/stream.rs @@ -0,0 +1,29 @@ +use { + crate::{Error, Node}, + std::{ + io::{ErrorKind, Read}, + iter::Iterator, + }, +}; + +#[derive(Debug)] +pub struct Stream { + reader: T, +} + +impl From for Stream { + fn from(value: T) -> Self { + Self { reader: value } + } +} + +impl Iterator for Stream { + type Item = Result; + + fn next(&mut self) -> Option { + match Node::read(&mut self.reader) { + Err(Error::Io(e)) if e.kind() == ErrorKind::UnexpectedEof => None, + x => Some(x), + } + } +}