pub struct Entry<'a, R: 'a + Read> { /* private fields */ }Expand description
Representation of an archive entry.
Entry objects implement the Read trait, and can be used to extract the
data from this archive entry. If the underlying reader supports the Seek
trait, then the Entry object supports Seek as well.
Implementations§
Source§impl<'a, R: 'a + Read> Entry<'a, R>
impl<'a, R: 'a + Read> Entry<'a, R>
Sourcepub fn header(&self) -> &Header
pub fn header(&self) -> &Header
Returns the header for this archive entry.
Examples found in repository?
examples/extract.rs (line 39)
23fn main() {
24 let num_args = env::args().count();
25 if num_args != 2 {
26 println!("Usage: extract <path/to/archive.a>");
27 return;
28 }
29
30 let input_path = env::args().nth(1).unwrap();
31 let input_path = Path::new(&input_path);
32 let input_file =
33 File::open(input_path).expect("failed to open input file");
34 let mut archive = ar::Archive::new(input_file);
35
36 while let Some(entry) = archive.next_entry() {
37 let mut entry = entry.expect("failed to parse archive entry");
38 let output_path = Path::new(
39 str::from_utf8(entry.header().identifier())
40 .expect("Non UTF-8 filename"),
41 )
42 .to_path_buf();
43 let mut output_file = File::create(&output_path)
44 .expect(&format!("unable to create file {:?}", output_path));
45 io::copy(&mut entry, &mut output_file)
46 .expect(&format!("failed to extract file {:?}", output_path));
47 }
48}Trait Implementations§
Source§impl<'a, R: 'a + Read> Read for Entry<'a, R>
impl<'a, R: 'a + Read> Read for Entry<'a, R>
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
Pull some bytes from this source into the specified buffer, returning
how many bytes were read. Read more
1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
Like
read, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
🔬This is a nightly-only experimental API. (
can_vector)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
Reads all bytes until EOF in this source, placing them into
buf. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
Reads all bytes until EOF in this source, appending them to
buf. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
Reads the exact number of bytes required to fill
buf. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
🔬This is a nightly-only experimental API. (
read_buf)Pull some bytes from this source into the specified buffer. Read more
Source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
🔬This is a nightly-only experimental API. (
read_buf)Reads the exact number of bytes required to fill
cursor. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Creates a “by reference” adaptor for this instance of
Read. Read moreSource§impl<'a, R: 'a + Read + Seek> Seek for Entry<'a, R>
impl<'a, R: 'a + Read + Seek> Seek for Entry<'a, R>
Source§fn seek(&mut self, pos: SeekFrom) -> Result<u64>
fn seek(&mut self, pos: SeekFrom) -> Result<u64>
Seek to an offset, in bytes, in a stream. Read more
1.55.0 · Source§fn rewind(&mut self) -> Result<(), Error>
fn rewind(&mut self) -> Result<(), Error>
Rewind to the beginning of a stream. Read more
Source§fn stream_len(&mut self) -> Result<u64, Error>
fn stream_len(&mut self) -> Result<u64, Error>
🔬This is a nightly-only experimental API. (
seek_stream_len)Returns the length of this stream (in bytes). Read more
Auto Trait Implementations§
impl<'a, R> Freeze for Entry<'a, R>
impl<'a, R> RefUnwindSafe for Entry<'a, R>where
R: RefUnwindSafe,
impl<'a, R> Send for Entry<'a, R>where
R: Send,
impl<'a, R> Sync for Entry<'a, R>where
R: Sync,
impl<'a, R> Unpin for Entry<'a, R>
impl<'a, R> !UnwindSafe for Entry<'a, R>
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