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>
impl<F> Package<F>
sourcepub fn package_type(&self) -> PackageType
pub fn package_type(&self) -> PackageType
Returns what type of package this is.
sourcepub fn summary_info(&self) -> &SummaryInfo
pub fn summary_info(&self) -> &SummaryInfo
Returns summary information for this package.
sourcepub fn database_codepage(&self) -> CodePage
pub fn database_codepage(&self) -> CodePage
Returns the code page used for serializing strings in the database.
sourcepub fn has_table(&self, table_name: &str) -> bool
pub fn has_table(&self, table_name: &str) -> bool
Returns true if the database has a table with the given name.
sourcepub fn get_table(&self, table_name: &str) -> Option<&Table>
pub fn get_table(&self, table_name: &str) -> Option<&Table>
Returns the database table with the given name (if any).
sourcepub fn tables(&self) -> Tables<'_> ⓘ
pub fn tables(&self) -> Tables<'_> ⓘ
Returns an iterator over the database tables in this package.
sourcepub fn has_stream(&self, stream_name: &str) -> bool
pub fn has_stream(&self, stream_name: &str) -> bool
Returns true if the package has an embedded binary stream with the given name.
sourcepub fn streams(&self) -> Streams<'_, F> ⓘ
pub fn streams(&self) -> Streams<'_, F> ⓘ
Returns an iterator over the embedded binary streams in this package.
sourcepub fn has_digital_signature(&self) -> bool
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.
sourcepub fn into_inner(self) -> Result<F>
pub fn into_inner(self) -> Result<F>
Consumes the Package
object, returning the underlying reader/writer.
source§impl<F: Read + Seek> Package<F>
impl<F: Read + Seek> Package<F>
sourcepub fn open(inner: F) -> Result<Package<F>>
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.
sourcepub fn select_rows(&mut self, query: Select) -> Result<Rows<'_>>
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).
sourcepub fn read_stream(&mut self, stream_name: &str) -> Result<StreamReader<F>>
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>
impl<F: Read + Write + Seek> Package<F>
sourcepub fn create(package_type: PackageType, inner: F) -> Result<Package<F>>
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.
sourcepub fn summary_info_mut(&mut self) -> &mut SummaryInfo
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.
sourcepub fn set_database_codepage(&mut self, codepage: CodePage)
pub fn set_database_codepage(&mut self, codepage: CodePage)
Sets the code page used for serializing strings in the database.
sourcepub fn create_table<S: Into<String>>(
&mut self,
table_name: S,
columns: Vec<Column>
) -> Result<()>
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.
sourcepub fn drop_table(&mut self, table_name: &str) -> Result<()>
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.
sourcepub fn delete_rows(&mut self, query: Delete) -> Result<()>
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).
sourcepub fn insert_rows(&mut self, query: Insert) -> Result<()>
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).
sourcepub fn update_rows(&mut self, query: Update) -> Result<()>
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).
sourcepub fn write_stream(&mut self, stream_name: &str) -> Result<StreamWriter<F>>
pub fn write_stream(&mut self, stream_name: &str) -> Result<StreamWriter<F>>
Creates (or overwrites) a binary stream in the package.
sourcepub fn remove_stream(&mut self, stream_name: &str) -> Result<()>
pub fn remove_stream(&mut self, stream_name: &str) -> Result<()>
Removes an existing binary stream from the package.
sourcepub fn remove_digital_signature(&mut self) -> Result<()>
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).