pub struct StreamingDecoder { /* private fields */ }Expand description
Incremental decoder for a Content-Encoding value: one coding, or a list
of them applied in order (see StreamingDecoder::from_codings).
Implementations§
Source§impl StreamingDecoder
impl StreamingDecoder
Sourcepub fn new(encoding: &str, limit: usize) -> Result<Self>
pub fn new(encoding: &str, limit: usize) -> Result<Self>
A decoder for one Content-Encoding header value, which may be a list
("gzip, br"). The same as from_codings with
that one value.
Sourcepub fn from_codings<I>(values: I, limit: usize) -> Result<Self>
pub fn from_codings<I>(values: I, limit: usize) -> Result<Self>
A decoder for a Content-Encoding field: pass every header line’s
value, in order. Repeated lines are merged as for any list-valued field
(RFC 9110 section 5.3), and each value may itself be a comma-separated
list.
Codings are listed in the order they were applied, so they are decoded
in reverse: in gzip, br the last-listed br is outermost and decoded
first. Names are case-insensitive, x-gzip is gzip, and identity
and empty list elements are skipped; no coding at all decodes as
identity. An unknown coding, or more than MAX_CODINGS, fails with
UND_ERR_NOT_SUPPORTED.
One coding decodes straight into the caller’s output as before. Each
further coding stages its output in a fixed 16 KiB buffer allocated
here and kept across reset; limit bounds every
coding’s output, not only the last, so an outer coding cannot expand
without bound into an inner one that produces nothing.
Sourcepub fn reset(&mut self, limit: usize) -> Result<()>
pub fn reset(&mut self, limit: usize) -> Result<()>
Reuse algorithm and scratch storage for another body of the same encoding. Warm up with the largest expected body shape before measuring allocations.
Sourcepub fn process(
&mut self,
input: &[u8],
output: &mut [u8],
end: bool,
) -> Result<DecodeStep>
pub fn process( &mut self, input: &[u8], output: &mut [u8], end: bool, ) -> Result<DecodeStep>
Decode as far as input and output allow: the call returns only when
the body is finished, the decoder needs more input, or output is full,
and DecodeStep says which. One call per transport read and one per
full output buffer is enough; there is no need to loop until a step
makes no progress.
end means no more encoded bytes will arrive, not that output is unbounded.