Skip to main content

OpcPackage

Struct OpcPackage 

Source
pub struct OpcPackage {
    pub content_types: ContentTypes,
    pub package_rels: Relationships,
    pub part_rels: HashMap<String, Relationships>,
    pub parts: HashMap<String, Vec<u8>>,
}
Expand description

An in-memory representation of an OPC package (ZIP archive).

Fields§

§content_types: ContentTypes

Content types from [Content_Types].xml

§package_rels: Relationships

Package-level relationships from _rels/.rels

§part_rels: HashMap<String, Relationships>

Part-level relationships keyed by the part they belong to. Key is the part name (e.g. “/word/document.xml”), value is the parsed relationships.

§parts: HashMap<String, Vec<u8>>

All parts keyed by their URI (e.g. “/word/document.xml”).

Implementations§

Source§

impl OpcPackage

Source

pub fn open<P>(path: P) -> Result<OpcPackage, OpcError>
where P: AsRef<Path>,

Open an OPC package from a file path.

Source

pub fn from_reader<R>(reader: R) -> Result<OpcPackage, OpcError>
where R: Read + Seek,

Open an OPC package from any reader that implements Read + Seek.

Source

pub fn save<P>(&self, path: P) -> Result<(), OpcError>
where P: AsRef<Path>,

Save the OPC package to a file path.

Source

pub fn write_to<W>(&self, writer: W) -> Result<(), OpcError>
where W: Write + Seek,

Write the OPC package to any writer.

Source

pub fn get_part(&self, part_name: &str) -> Option<&[u8]>

Get raw bytes of a part by its URI.

Source

pub fn set_part(&mut self, part_name: &str, data: Vec<u8>)

Set (or replace) a part’s raw bytes.

Source

pub fn get_part_rels(&self, part_name: &str) -> Option<&Relationships>

Get the relationships for a specific part.

Source

pub fn get_or_create_part_rels(&mut self, part_name: &str) -> &mut Relationships

Get or create the relationships for a specific part.

Source

pub fn resolve_rel_target(source_part: &str, rel_target: &str) -> String

Resolve the target URI of a relationship relative to its source part.

. and .. segments are collapsed, so a target such as ../media/image1.png on /word/charts/chart1.xml resolves to /media/image1.png and matches the key it is stored under. Without this, parts referenced through a parent directory could never be found.

Source

pub fn main_document_part(&self) -> Option<String>

Find the main document part URI by looking at package relationships.

Source

pub fn new() -> OpcPackage

Create an empty package with the universal OPC content types.

Source

pub fn with_main_part(part_name: &str, content_type: &str) -> OpcPackage

Create a package whose office document relationship targets a main part.

Trait Implementations§

Source§

impl Clone for OpcPackage

Source§

fn clone(&self) -> OpcPackage

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for OpcPackage

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for OpcPackage

Source§

fn default() -> OpcPackage

Returns the “default value” for a type. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.