use std;
use ole;
pub struct ThumbsDb<'ole> {
pub(crate) ole: ole::Reader<'ole>,
pub(crate) content: std::vec::Vec<u8>,
pub(crate) thumbnails: std::vec::Vec<super::thumbnail::Thumbnail>
}
impl<'ole> ThumbsDb<'ole> {
pub fn new<T: 'ole>(readable: T)
-> Result<ThumbsDb<'ole>, super::error::Error>
where T: std::io::Read {
let mut thumbsdb = ThumbsDb {
ole: ole::Reader::new(readable).map_err(super::error::Error::OLEError)?,
content: std::vec::Vec::new(),
thumbnails: std::vec::Vec::new()
};
thumbsdb.read_catalog()?;
thumbsdb.extract_thumbnails()?;
Ok(thumbsdb)
}
pub fn from_path(path: &str) -> Result<ThumbsDb, Box<std::error::Error>> {
match std::fs::File::open(path) {
Ok(f) => match ThumbsDb::new(f) {
Ok(t) => Ok(t),
Err(e) => Err(Box::new(e))
},
Err(e) => Err(Box::new(e))
}
}
pub fn iterate(&self) -> super::iterator::ThumbnailIterator {
super::iterator::ThumbnailIterator::new(self)
}
}