Struct msi::Package

source ·
pub struct Package<F> { /* private fields */ }
Expand description

An MSI package file, backed by an underlying reader/writer (such as a File or Cursor).

Examples

use msi::{Column, Expr, Insert, Package, PackageType, Select, Value};
use std::io::Cursor;

// Create an in-memory package using a Cursor:
let cursor = Cursor::new(Vec::new());
let mut package = Package::create(PackageType::Installer, cursor).unwrap();
// Set some summary information:
package.summary_info_mut().set_author("Jane Doe".to_string());
// Add a table to the package:
let columns = vec![
    Column::build("Property").primary_key().id_string(72),
    Column::build("Value").nullable().formatted_string(64),
];
package.create_table("CheckBox", columns).unwrap();
// Add a row to the new table:
let query = Insert::into("CheckBox").row(vec![
    Value::from("MoreMagic"),
    Value::from("Whether magic should be maximized"),
]);
package.insert_rows(query).unwrap();
// Close the package and get the cursor back out.
let cursor = package.into_inner().unwrap();

// Now, re-open the package and make sure our data is still there.
let mut package = Package::open(cursor).unwrap();
assert_eq!(package.summary_info().author(), Some("Jane Doe"));
let query = Select::table("CheckBox")
    .with(Expr::col("Property").eq(Expr::string("MoreMagic")));
let mut rows = package.select_rows(query).unwrap();
assert_eq!(rows.len(), 1);
let row = rows.next().unwrap();
assert_eq!(row["Property"], Value::Str("MoreMagic".to_string()));
assert_eq!(row["Value"],
           Value::Str("Whether magic should be maximized".to_string()));

Implementations§

source§

impl<F> Package<F>

source

pub fn package_type(&self) -> PackageType

Returns what type of package this is.

source

pub fn summary_info(&self) -> &SummaryInfo

Returns summary information for this package.

source

pub fn database_codepage(&self) -> CodePage

Returns the code page used for serializing strings in the database.

source

pub fn has_table(&self, table_name: &str) -> bool

Returns true if the database has a table with the given name.

source

pub fn get_table(&self, table_name: &str) -> Option<&Table>

Returns the database table with the given name (if any).

source

pub fn tables(&self) -> Tables<'_>

Returns an iterator over the database tables in this package.

source

pub fn has_stream(&self, stream_name: &str) -> bool

Returns true if the package has an embedded binary stream with the given name.

source

pub fn streams(&self) -> Streams<'_, F>

Returns an iterator over the embedded binary streams in this package.

source

pub fn has_digital_signature(&self) -> bool

Returns true if the package has been digitally signed. Note that this method only checks whether a signature is present; it does not verify that the signature is actually valid.

source

pub fn into_inner(self) -> Result<F>

Consumes the Package object, returning the underlying reader/writer.

source§

impl<F: Read + Seek> Package<F>

source

pub fn open(inner: F) -> Result<Package<F>>

Opens an existing MSI file, using the underlying reader. If the underlying reader also supports the Write trait, then the Package object will be writable as well.

source

pub fn select_rows(&mut self, query: Select) -> Result<Rows<'_>>

Attempts to execute a select query. Returns an error if the query fails (e.g. due to the column names being incorrect or the table(s) not existing).

source

pub fn read_stream(&mut self, stream_name: &str) -> Result<StreamReader<F>>

Opens an existing binary stream in the package for reading.

source§

impl<F: Read + Write + Seek> Package<F>

source

pub fn create(package_type: PackageType, inner: F) -> Result<Package<F>>

Creates a new, empty package of the given type, using the underlying reader/writer. The reader/writer should be initially empty.

source

pub fn summary_info_mut(&mut self) -> &mut SummaryInfo

Returns a mutable reference to the summary information for this package. Call flush() or drop the Package object to persist any changes made to the underlying writer.

source

pub fn set_database_codepage(&mut self, codepage: CodePage)

Sets the code page used for serializing strings in the database.

source

pub fn create_table<S: Into<String>>( &mut self, table_name: S, columns: Vec<Column> ) -> Result<()>

Creates a new database table. Returns an error without modifying the database if the table name or columns are invalid, or if a table with that name already exists.

source

pub fn drop_table(&mut self, table_name: &str) -> Result<()>

Removes an existing database table. Returns an error without modifying the database if the table name is invalid, or if no such table exists.

source

pub fn delete_rows(&mut self, query: Delete) -> Result<()>

Attempts to execute a delete query. Returns an error without modifying the database if the query fails (e.g. due to the table not existing).

source

pub fn insert_rows(&mut self, query: Insert) -> Result<()>

Attempts to execute an insert query. Returns an error without modifying the database if the query fails (e.g. due to values being invalid, or keys not being unique, or the table not existing).

source

pub fn update_rows(&mut self, query: Update) -> Result<()>

Attempts to execute an update query. Returns an error without modifying the database if the query fails (e.g. due to values being invalid, or column names being incorrect, or the table not existing).

source

pub fn write_stream(&mut self, stream_name: &str) -> Result<StreamWriter<F>>

Creates (or overwrites) a binary stream in the package.

source

pub fn remove_stream(&mut self, stream_name: &str) -> Result<()>

Removes an existing binary stream from the package.

source

pub fn remove_digital_signature(&mut self) -> Result<()>

Removes any existing digital signature from the package. This can be useful if you need to modify a signed package (which will invalidate the signature).

source

pub fn flush(&mut self) -> Result<()>

Flushes any buffered changes to the underlying writer.

Trait Implementations§

source§

impl<F> Drop for Package<F>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<F> !RefUnwindSafe for Package<F>

§

impl<F> !Send for Package<F>

§

impl<F> !Sync for Package<F>

§

impl<F> Unpin for Package<F>

§

impl<F> !UnwindSafe for Package<F>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.