Skip to main content

decode_reader

Function decode_reader 

Source
pub fn decode_reader<'a, R: Read + 'a>(
    codec: &dyn Codec,
    r: R,
    o: &DecodeOpts,
) -> Result<Box<dyn Source + 'a>>
Expand description

Decodes r with codec, borrowing r for as long as the decoder lives.

The one-call route for a caller holding a codec and a reader — notably an archive member’s reader, which is neither 'static nor Send. Needs no registry. A codec that cannot decode is refused with the same Error::CapabilityUnavailable Registry::require_decoder raises (exit 3).

Errors come back already classified, as on every other decode path: an io::Error from the decoder’s construction is folded through Error::from_decode_io, and the returned source is a DecodeSideSource, so a malformed member read through it and converted with a bare ? is the same Error::Corrupt (exit 5) as anywhere else, while a failure of r itself (a disk, a permission) stays Error::Io.

What the decode approximated is not in the returned source. A codec records it in o.fidelity (crate::DecodeOpts::fidelity) — today crate::Fidelity::TrailingDataIgnored, from gzip or bzip2, for bytes after the last verified member that were ignored — and only once it has reached the end of its stream. So keep a clone of the sink (or the DecodeOpts itself) and read it after the source has returned Ok(0): crate::FidelitySink::warnings, or crate::FidelitySink::drain_into a crate::FidelityReport. A caller that never looks loses the warning.