#[derive(Clone, Debug, Default)]
pub struct Page {
pub inner_path: String,
pub root_element: crate::schemas::page::Page,
pub page_res: Vec<crate::parts::page_res::PageRes>,
}
impl Page {
pub(crate) fn new_from_archive<R: std::io::Read + std::io::Seek>(
path: &str,
archive: &mut zip::ZipArchive<R>,
) -> Result<Self, crate::common::SdkError> {
let root_element = crate::schemas::page::Page::from_reader(std::io::BufReader::new(
std::io::Cursor::new(crate::common::read_zip_data(archive, path)?),
))?;
let current_dir = crate::common::zip_parent_dir(path);
let mut page_res_paths: Vec<String> = vec![];
for value in &root_element.page_res {
page_res_paths.push(value.clone());
}
let page_res = crate::common::load_zip_parts(
¤t_dir,
page_res_paths,
archive,
|child_path, archive| {
let resolved_path = crate::common::resolve_zip_child_path(¤t_dir, child_path);
crate::parts::page_res::PageRes::new_from_archive(&resolved_path, archive)
},
)?;
Ok(Self {
inner_path: path.to_string(),
root_element,
page_res,
})
}
pub(crate) fn save_zip<W: std::io::Write + std::io::Seek>(
&self,
zip: &mut zip::ZipWriter<W>,
entry_set: &mut std::collections::HashSet<String>,
) -> Result<(), crate::common::SdkError> {
crate::common::save_zip_data(
&self.inner_path,
self.root_element.to_xml()?.as_bytes(),
zip,
entry_set,
)?;
crate::common::save_zip_parts(&self.page_res, zip, entry_set, |child, zip, entry_set| {
child.save_zip(zip, entry_set)
})?;
Ok(())
}
}