Skip to main content

Package

Struct Package 

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

An OpenDocument package: a zip archive whose first entry declares the media type of everything else in it.

Entries are kept in the order they were read, and every entry is kept whether or not anything here understands it — a digital signature, a thumbnail, an embedded object, a part from a future version of the format.

Implementations§

Source§

impl Package

Source

pub fn read(bytes: &[u8]) -> Result<Self, Error>

Read a package from its bytes.

§Errors

The bytes are not a zip archive, or an entry cannot be decompressed.

Source

pub fn media_type(&self) -> Option<&str>

The media type the package declares.

None for a package that declares none, which is legal: the specification makes the mimetype entry optional, and a package written without one is identified by its file extension alone.

Source

pub fn part(&self, name: &str) -> Option<&Part>

An entry by name.

Source

pub fn parts(&self) -> impl Iterator<Item = &Part>

Every entry, in the order they are stored.

Source

pub fn xml(&self, name: &'static str) -> Result<Element, Error>

Parse an entry as XML.

§Errors

The entry is absent, or is not well-formed XML.

Source

pub fn optional_xml(&self, name: &'static str) -> Result<Option<Element>, Error>

Parse an entry as XML, or give back an empty document if it is absent.

styles.xml, meta.xml and settings.xml are each optional in a package that has nothing to put in them, and a document with no metadata is not a document that should fail to open.

§Errors

The entry is present and is not well-formed XML.

Source

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

Replace an entry’s bytes, adding it at the end if it was not there.

Source

pub fn set_xml(&mut self, name: &str, root: &Element)

Replace an entry with a serialized XML tree.

Source

pub fn write(&self) -> Result<Vec<u8>, Error>

Write the package back out.

The mimetype entry goes first and uncompressed whatever order it was read in, because that is the one ordering rule the format has and a package that breaks it is identified by its extension alone.

§Errors

The underlying writer failed, which for a buffer in memory means the allocation did.

Source

pub fn expect_media_type( &self, wanted: &'static [&'static str], ) -> Result<(), Error>

Check the package declares one of the media types this reader opens.

A format may have more than one: a Writer/Web document is a text document and declares a media type of its own.

§Errors

The package declares a media type that is none of them. A package that declares none is accepted: the caller asked for a format, and the file extension is the only other thing that ever said.

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.