pub struct Header { /* private fields */ }
Expand description
Representation of an archive entry header.
Implementations§
Source§impl Header
impl Header
Sourcepub fn new(identifier: Vec<u8>, size: u64) -> Header
pub fn new(identifier: Vec<u8>, size: u64) -> Header
Creates a header with the given file identifier and size, and all other fields set to zero.
Sourcepub fn from_metadata(identifier: Vec<u8>, meta: &Metadata) -> Header
pub fn from_metadata(identifier: Vec<u8>, meta: &Metadata) -> Header
Creates a header with the given file identifier and all other fields set from the given filesystem metadata.
Sourcepub fn identifier(&self) -> &[u8] ⓘ
pub fn identifier(&self) -> &[u8] ⓘ
Returns the file identifier.
Examples found in repository?
examples/extract.rs (line 39)
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
fn main() {
let num_args = env::args().count();
if num_args != 2 {
println!("Usage: extract <path/to/archive.a>");
return;
}
let input_path = env::args().nth(1).unwrap();
let input_path = Path::new(&input_path);
let input_file =
File::open(input_path).expect("failed to open input file");
let mut archive = ar::Archive::new(input_file);
while let Some(entry) = archive.next_entry() {
let mut entry = entry.expect("failed to parse archive entry");
let output_path = Path::new(
str::from_utf8(entry.header().identifier())
.expect("Non UTF-8 filename"),
)
.to_path_buf();
let mut output_file = File::create(&output_path)
.expect(&format!("unable to create file {:?}", output_path));
io::copy(&mut entry, &mut output_file)
.expect(&format!("failed to extract file {:?}", output_path));
}
}
Sourcepub fn set_identifier(&mut self, identifier: Vec<u8>)
pub fn set_identifier(&mut self, identifier: Vec<u8>)
Sets the file identifier.
Trait Implementations§
impl Eq for Header
impl StructuralPartialEq for Header
Auto Trait Implementations§
impl Freeze for Header
impl RefUnwindSafe for Header
impl Send for Header
impl Sync for Header
impl Unpin for Header
impl UnwindSafe for Header
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more