pub struct PackageReader<'a> { /* private fields */ }Expand description
Reader for HWPX ZIP archives.
Validates structure and provides access to individual XML files within the archive. Enforces safety limits on decompressed data to prevent ZIP bomb attacks.
Implementations§
Source§impl<'a> PackageReader<'a>
impl<'a> PackageReader<'a>
Sourcepub fn new(bytes: &'a [u8]) -> HwpxResult<Self>
pub fn new(bytes: &'a [u8]) -> HwpxResult<Self>
Opens an HWPX archive from raw bytes.
Validates:
- The bytes form a valid ZIP archive
- The entry count is within safety limits
- A
mimetypefile exists with an accepted value
Sourcepub fn read_header_xml(&mut self) -> HwpxResult<String>
pub fn read_header_xml(&mut self) -> HwpxResult<String>
Returns the raw XML content of Contents/header.xml.
Sourcepub fn read_section_xml(&mut self, index: usize) -> HwpxResult<String>
pub fn read_section_xml(&mut self, index: usize) -> HwpxResult<String>
Returns the raw XML content of Contents/section{index}.xml.
Sections are zero-indexed: section 0, section 1, etc.
Sourcepub fn section_count(&self) -> usize
pub fn section_count(&self) -> usize
Returns the number of section files found in the archive.
Sourcepub fn list_entries(&mut self) -> HwpxResult<Vec<PackageEntryInfo>>
pub fn list_entries(&mut self) -> HwpxResult<Vec<PackageEntryInfo>>
Returns metadata for every entry in the archive.
Entries are returned in ZIP order so callers can compare package structure directly against a fixture.
Sourcepub fn read_text_entry(&mut self, path: &str) -> HwpxResult<String>
pub fn read_text_entry(&mut self, path: &str) -> HwpxResult<String>
Reads an arbitrary archive entry as UTF-8 text.
This is primarily useful for package-census tooling that needs raw
access to files such as Contents/content.hpf.
Sourcepub fn read_masterpage_xmls(&mut self) -> HwpxResult<HashMap<usize, String>>
pub fn read_masterpage_xmls(&mut self) -> HwpxResult<HashMap<usize, String>>
Reads all Contents/masterpage*.xml entries from the archive.
Returns a map from masterpage index to XML content.
E.g., {0: "<masterPage>...</masterPage>"} for Contents/masterpage0.xml.
Sourcepub fn read_chart_xmls(&mut self) -> HwpxResult<HashMap<String, String>>
pub fn read_chart_xmls(&mut self) -> HwpxResult<HashMap<String, String>>
Reads all Chart/*.xml entries from the archive into a map.
Each entry’s full path (e.g. "Chart/chart1.xml") becomes the key,
and the XML string becomes the value.
Sourcepub fn read_all_bindata(&mut self) -> HwpxResult<ImageStore>
pub fn read_all_bindata(&mut self) -> HwpxResult<ImageStore>
Reads all BinData/* entries from the archive into an
hwpforge_core::image::ImageStore.
Each entry’s filename (without the BinData/ prefix) becomes the
key in the store, and the raw bytes become the value.
Keys are sanitized to prevent path traversal (CWE-22): .. components
and leading slashes are stripped before insertion.