Skip to main content

PackageReader

Struct PackageReader 

Source
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>

Source

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 mimetype file exists with an accepted value
Source

pub fn read_header_xml(&mut self) -> HwpxResult<String>

Returns the raw XML content of Contents/header.xml.

Source

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.

Source

pub fn section_count(&self) -> usize

Returns the number of section files found in the archive.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for PackageReader<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for PackageReader<'a>

§

impl<'a> RefUnwindSafe for PackageReader<'a>

§

impl<'a> Send for PackageReader<'a>

§

impl<'a> Sync for PackageReader<'a>

§

impl<'a> Unpin for PackageReader<'a>

§

impl<'a> UnsafeUnpin for PackageReader<'a>

§

impl<'a> UnwindSafe for PackageReader<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.