pub struct SinkExtractRequest<'a> { /* private fields */ }Expand description
Extracts an archive read from a reader into an EntrySink.
Every entry passes the validation pipeline of ExtractRequest and is then
delivered to the sink instead of being written under a directory. See the
sink module for what the sink may rely on and what it must
do. The optional ProgressCallback sees the events of a directory
extraction.
A 7z source is read in two phases: everything the file table can refuse (admission, ratios, quotas, link policy, paths, name lengths) is refused before the sink sees an entry, then the entries are decoded and delivered in archive order.
§Errors
extract returns the errors of ExtractRequest, plus
any error the sink returns: ArchiveError::Io if
no entry was delivered yet,
ArchiveError::PartialExtraction
wrapping it afterwards. A sink that reports SinkFull
ends the extraction with a
QuotaResource::SinkCapacity quota
error.
§Examples
use std::io;
use exarch_core::ArchiveReader;
use exarch_core::MemorySink;
use exarch_core::SecurityConfig;
use exarch_core::SinkExtractRequest;
let mut builder = tar::Builder::new(Vec::new());
let mut header = tar::Header::new_gnu();
header.set_size(2);
header.set_mode(0o644);
builder.append_data(&mut header, "a.txt", &b"hi"[..])?;
let bytes = builder.into_inner()?;
let mut sink = MemorySink::default();
let config = SecurityConfig::default();
let report = SinkExtractRequest::new(&config)
.extract(ArchiveReader::tar(io::Cursor::new(bytes), None), &mut sink)?;
assert_eq!(report.files_extracted, 1);Implementations§
Source§impl<'a> SinkExtractRequest<'a>
impl<'a> SinkExtractRequest<'a>
Sourcepub fn new(config: &'a SecurityConfig) -> Self
pub fn new(config: &'a SecurityConfig) -> Self
An extraction into a sink under config with default options and no
progress callback.
Sourcepub const fn with_options(self, options: SinkOptions) -> Self
pub const fn with_options(self, options: SinkOptions) -> Self
Sets the sink extraction options.
Sourcepub fn with_progress(self, progress: &'a mut dyn ProgressCallback) -> Self
pub fn with_progress(self, progress: &'a mut dyn ProgressCallback) -> Self
Reports progress to progress.