Skip to main content

StreamDecoder

Struct StreamDecoder 

Source
pub struct StreamDecoder<'a> { /* private fields */ }
Expand description

Decodes one stream a chunk at a time under a ratio budget.

§Examples

use pdfcer_model::filters::{ReadStatus, StreamDecoder};
use pdfcer_model::object::Dict;

let dict = Dict::new(); // no /Filter: the raw bytes are the data
let mut dec = StreamDecoder::new(&dict, b"0 0 m 1 1 l S")?;
let mut out = Vec::new();
while dec.read(&mut out)? == ReadStatus::More {}
assert_eq!(out, b"0 0 m 1 1 l S");

Implementations§

Source§

impl<'a> StreamDecoder<'a>

Source

pub fn new(dict: &Dict, raw: &'a [u8]) -> Result<Self, FilterError>

Prepare to decode raw (the stream’s encoded bytes) per dict’s /Filter and /DecodeParms.

§Errors

FilterError from parsing the filter chain, or from a stage this decodes whole (module docs) — the same errors super::decode_stream would report for it.

Source

pub fn limit(&self) -> usize

The most bytes this decoder will ever produce.

Source

pub fn read(&mut self, out: &mut Vec<u8>) -> Result<ReadStatus, FilterError>

Append the next chunk (about 64 KiB) of decoded bytes to out.

§Errors

FilterError::Corrupt or FilterError::Truncated when the stream is damaged part-way. Bytes decoded before the damage were returned by earlier calls; the decoder is finished after an error.

Trait Implementations§

Source§

impl Debug for StreamDecoder<'_>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

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

§

impl<'a> !Send for StreamDecoder<'a>

§

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

§

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

§

impl<'a> Forget for StreamDecoder<'a>

§

impl<'a> Freeze for StreamDecoder<'a>
where &'a [u8]: Freeze, Vec<u8>: Freeze, *const dyn Pull + 'a is !null: Freeze, PhantomData<dyn Pull + 'a>: Freeze,

§

impl<'a> Move for StreamDecoder<'a>

§

impl<'a> Unpin for StreamDecoder<'a>
where &'a [u8]: Unpin, Vec<u8>: Unpin, Box<dyn Pull + 'a>: Unpin,

§

impl<'a> UnsafeUnpin for StreamDecoder<'a>
where &'a [u8]: UnsafeUnpin, Vec<u8>: UnsafeUnpin, *const dyn Pull + 'a is !null: UnsafeUnpin, PhantomData<dyn Pull + 'a>: UnsafeUnpin,

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.