Skip to main content

decoded_stream

Function decoded_stream 

Source
pub fn decoded_stream(
    stream: &Stream,
    r: &impl Resolve,
    limits: &Limits,
    diags: &mut Diagnostics,
) -> Vec<u8> 
Expand description

A stream’s data with its filters applied.

Never fails: a stream whose filter chain is unusable yields its raw bytes and a diagnostic, which is what makes a damaged file’s content still render. A chain ending in an image codec yields the codec’s input; the image path takes it from there.

use pdfrum_common::{Diagnostics, Limits};
use pdfrum_object::{ByteSpan, Dict, Name, NoResolve, Object, Stream, names};
use pdfrum_parser::decoded_stream;

let dict = Dict::from_pairs([(
    names::FILTER.clone(),
    Object::Name(Name::from("ASCIIHexDecode")),
)]);
let stream = Stream::new(dict, ByteSpan::from(b"48656c6c6f>".to_vec()));
let mut diags = Diagnostics::default();
let bytes = decoded_stream(&stream, &NoResolve, &Limits::default(), &mut diags);
assert_eq!(bytes, b"Hello");