Skip to main content

OoxmlContainer

Struct OoxmlContainer 

Source
pub struct OoxmlContainer { /* private fields */ }
Expand description

OOXML container abstraction over a ZIP archive.

Provides methods to read XML files, binary data, and relationships from an Office Open XML document.

Implementations§

Source§

impl OoxmlContainer

Source

pub fn open(path: impl AsRef<Path>) -> Result<Self>

Open an OOXML container from a file path.

§Example
use undoc::container::OoxmlContainer;

let container = OoxmlContainer::open("document.docx")?;
Source

pub fn from_bytes(data: Vec<u8>) -> Result<Self>

Create an OOXML container from a byte vector.

Source

pub fn from_reader<R: Read + Seek>(reader: R) -> Result<Self>

Create an OOXML container from a reader.

Source

pub fn read_xml(&self, path: &str) -> Result<String>

Read an XML file from the archive as a string.

Handles different encodings:

  • UTF-8 (with or without BOM)
  • UTF-16 LE (with BOM: FF FE)
  • UTF-16 BE (with BOM: FE FF)
Source

pub fn read_xml_optional(&self, path: &str) -> Result<Option<String>>

Read an optional XML part.

Returns Ok(None) when the part is absent (Error::MissingComponent), but surfaces any other error — including Error::Encoding for malformed byte content — so that corrupted optional parts are never silently degraded into a valid-empty result.

Source

pub fn read_binary(&self, path: &str) -> Result<Vec<u8>>

Read a binary file from the archive.

Source

pub fn exists(&self, path: &str) -> bool

Check if a file exists in the archive.

Source

pub fn list_files(&self) -> Vec<String>

List all files in the archive.

Source

pub fn list_files_with_prefix(&self, prefix: &str) -> Vec<String>

List files matching a prefix.

Source

pub fn read_relationships(&self, part_path: &str) -> Result<Relationships>

Read and parse relationships from a .rels file.

Legacy helper: treats missing relationship parts as optional.

Source

pub fn read_required_relationships_for_part( &self, part_path: &str, ) -> Result<Relationships>

Read relationships for a required OOXML part.

Source

pub fn read_optional_relationships_for_part( &self, part_path: &str, ) -> Result<Relationships>

Read relationships for an optional OOXML part.

Source

pub fn read_package_relationships(&self) -> Result<Relationships>

Read package-level relationships (_rels/.rels).

Source

pub fn parse_core_metadata(&self) -> Result<Metadata>

Parse core metadata from docProps/core.xml.

This is common to all OOXML formats (DOCX, XLSX, PPTX).

Source

pub fn resolve_path(base: &str, relative: &str) -> String

Resolve a relative path from a base path.

Trait Implementations§

Source§

impl Debug for OoxmlContainer

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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, 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.