pub struct ComponentPackageReader { /* private fields */ }Expand description
Read-only interface for a single component package.
Implementations§
source§impl ComponentPackageReader
impl ComponentPackageReader
sourcepub fn from_file_data(
bom: Option<Vec<u8>>,
package_info: Option<Vec<u8>>,
payload: Option<Vec<u8>>,
scripts: Option<Vec<u8>>
) -> PkgResult<Self>
pub fn from_file_data(
bom: Option<Vec<u8>>,
package_info: Option<Vec<u8>>,
payload: Option<Vec<u8>>,
scripts: Option<Vec<u8>>
) -> PkgResult<Self>
Construct an instance with raw file data backing different files.
Examples found in repository?
src/reader.rs (lines 133-138)
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
fn resolve_component(
&mut self,
path_prefix: &str,
) -> PkgResult<Option<ComponentPackageReader>> {
let prefix = if path_prefix.is_empty() {
"".to_string()
} else {
format!("{path_prefix}/")
};
let mut bom_data = None;
let mut package_info_data = None;
let mut payload_data = None;
let mut scripts_data = None;
for (filename, file) in self
.xar
.files()?
.into_iter()
.filter(|(filename, _)| filename.starts_with(&prefix))
{
let mut data = Vec::<u8>::with_capacity(file.size.unwrap_or(0) as _);
self.xar
.write_file_data_decoded_from_file(&file, &mut data)?;
let filename = filename.strip_prefix(&prefix).expect("prefix should match");
match filename {
"Bom" => {
bom_data = Some(data);
}
"PackageInfo" => {
package_info_data = Some(data);
}
"Payload" => {
payload_data = Some(data);
}
"Scripts" => {
scripts_data = Some(data);
}
_ => {}
}
}
if bom_data.is_some()
|| package_info_data.is_some()
|| payload_data.is_some()
|| scripts_data.is_some()
{
Ok(Some(ComponentPackageReader::from_file_data(
bom_data,
package_info_data,
payload_data,
scripts_data,
)?))
} else {
Ok(None)
}
}sourcepub fn package_info(&self) -> Option<&PackageInfo>
pub fn package_info(&self) -> Option<&PackageInfo>
Obtain the parsed PackageInfo XML file.
sourcepub fn payload_reader(&self) -> PkgResult<Option<CpioReader>>
pub fn payload_reader(&self) -> PkgResult<Option<CpioReader>>
Obtain a reader for the Payload cpio archive.
sourcepub fn scripts_reader(&self) -> PkgResult<Option<CpioReader>>
pub fn scripts_reader(&self) -> PkgResult<Option<CpioReader>>
Obtain a reader for the Scripts cpio archive.