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: ContentTypesContent types from [Content_Types].xml
package_rels: RelationshipsPackage-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
impl OpcPackage
Sourcepub fn open<P: AsRef<Path>>(path: P) -> Result<Self, OpcError>
pub fn open<P: AsRef<Path>>(path: P) -> Result<Self, OpcError>
Open an OPC package from a file path.
Sourcepub fn from_reader<R: Read + Seek>(reader: R) -> Result<Self, OpcError>
pub fn from_reader<R: Read + Seek>(reader: R) -> Result<Self, OpcError>
Open an OPC package from any reader that implements Read + Seek.
Sourcepub fn save<P: AsRef<Path>>(&self, path: P) -> Result<(), OpcError>
pub fn save<P: AsRef<Path>>(&self, path: P) -> Result<(), OpcError>
Save the OPC package to a file path.
Sourcepub fn write_to<W: Write + Seek>(&self, writer: W) -> Result<(), OpcError>
pub fn write_to<W: Write + Seek>(&self, writer: W) -> Result<(), OpcError>
Write the OPC package to any writer.
Sourcepub fn set_part(&mut self, part_name: &str, data: Vec<u8>)
pub fn set_part(&mut self, part_name: &str, data: Vec<u8>)
Set (or replace) a part’s raw bytes.
Sourcepub fn get_part_rels(&self, part_name: &str) -> Option<&Relationships>
pub fn get_part_rels(&self, part_name: &str) -> Option<&Relationships>
Get the relationships for a specific part.
Sourcepub fn get_or_create_part_rels(&mut self, part_name: &str) -> &mut Relationships
pub fn get_or_create_part_rels(&mut self, part_name: &str) -> &mut Relationships
Get or create the relationships for a specific part.
Sourcepub fn resolve_rel_target(source_part: &str, rel_target: &str) -> String
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.
Sourcepub fn main_document_part(&self) -> Option<String>
pub fn main_document_part(&self) -> Option<String>
Find the main document part URI by looking at package relationships.
Sourcepub fn with_main_part(part_name: &str, content_type: &str) -> Self
pub fn with_main_part(part_name: &str, content_type: &str) -> Self
Create a package whose office document relationship targets a main part.
Trait Implementations§
Source§impl Clone for OpcPackage
impl Clone for OpcPackage
Source§fn clone(&self) -> OpcPackage
fn clone(&self) -> OpcPackage
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more