Struct compress_tools::ArchiveIteratorBuilder
source · pub struct ArchiveIteratorBuilder<R>where
R: Read + Seek,{ /* private fields */ }
Implementations§
source§impl<R> ArchiveIteratorBuilder<R>where
R: Read + Seek,
impl<R> ArchiveIteratorBuilder<R>where R: Read + Seek,
A builder to generate an archive iterator over the contents of an
archive, streaming the contents of each entry in small chunks.
The default configuration is identical to ArchiveIterator::from_read
.
Example
use compress_tools::{ArchiveContents, ArchiveIteratorBuilder};
use std::path::Path;
use std::ffi::OsStr;
let source = std::fs::File::open("tests/fixtures/tree.tar").expect("Failed to open file");
let decode_utf8 = |bytes: &[u8]| Ok(std::str::from_utf8(bytes)?.to_owned());
for content in ArchiveIteratorBuilder::new(source)
.decoder(decode_utf8)
.filter(|name, stat| Path::new(name).file_name() == Some(OsStr::new("foo")) || stat.st_size == 42)
.build()
.expect("Failed to initialize archive")
{
if let ArchiveContents::StartOfEntry(name, _stat) = content {
println!("{name}");
}
}
sourcepub fn new(source: R) -> ArchiveIteratorBuilder<R>
pub fn new(source: R) -> ArchiveIteratorBuilder<R>
Create a new builder for an archive iterator. Default configuration is
identical to ArchiveIterator::from_read
.
sourcepub fn decoder(self, decoder: DecodeCallback) -> ArchiveIteratorBuilder<R>
pub fn decoder(self, decoder: DecodeCallback) -> ArchiveIteratorBuilder<R>
Use a custom decoder to decode filenames of archive entries.
By default an UTF-8 decoder (decode_utf8
) is used.
sourcepub fn filter<F>(self, filter: F) -> ArchiveIteratorBuilder<R>where
F: Fn(&str, &stat) -> bool + 'static,
pub fn filter<F>(self, filter: F) -> ArchiveIteratorBuilder<R>where F: Fn(&str, &stat) -> bool + 'static,
Use a filter to skip unwanted entries and their decompression. By default all entries are iterated.
sourcepub fn build(self) -> Result<ArchiveIterator<R>>
pub fn build(self) -> Result<ArchiveIterator<R>>
Finish the builder and generate the configured ArchiveIterator
.
Auto Trait Implementations§
impl<R> !RefUnwindSafe for ArchiveIteratorBuilder<R>
impl<R> !Send for ArchiveIteratorBuilder<R>
impl<R> !Sync for ArchiveIteratorBuilder<R>
impl<R> Unpin for ArchiveIteratorBuilder<R>where R: Unpin,
impl<R> !UnwindSafe for ArchiveIteratorBuilder<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