Skip to main content

SinkExtractRequest

Struct SinkExtractRequest 

Source
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>

Source

pub fn new(config: &'a SecurityConfig) -> Self

An extraction into a sink under config with default options and no progress callback.

Source

pub const fn with_options(self, options: SinkOptions) -> Self

Sets the sink extraction options.

Source

pub fn with_progress(self, progress: &'a mut dyn ProgressCallback) -> Self

Reports progress to progress.

Source

pub fn extract<S: EntrySink>( self, reader: ArchiveReader<'_>, sink: &mut S, ) -> Result<ExtractionReport>

Extracts reader into sink.

§Errors

See SinkExtractRequest.

Trait Implementations§

Source§

impl<'a> Debug for SinkExtractRequest<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for SinkExtractRequest<'a>

§

impl<'a> !Sync for SinkExtractRequest<'a>

§

impl<'a> !UnwindSafe for SinkExtractRequest<'a>

§

impl<'a> Freeze for SinkExtractRequest<'a>

§

impl<'a> Send for SinkExtractRequest<'a>

§

impl<'a> Unpin for SinkExtractRequest<'a>

§

impl<'a> UnsafeUnpin for SinkExtractRequest<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.