pub struct Decoder<'i, E: Encoding> { /* private fields */ }
Expand description
Stateful Base64 decoder with support for buffered, incremental decoding.
The E
type parameter can be any type which impls Encoding
such as
Base64
or Base64Unpadded
.
Implementations
sourceimpl<'i, E: Encoding> Decoder<'i, E>
impl<'i, E: Encoding> Decoder<'i, E>
sourcepub fn new(input: &'i [u8]) -> Result<Self, Error>
pub fn new(input: &'i [u8]) -> Result<Self, Error>
Create a new decoder for a byte slice containing contiguous (non-newline-delimited) Base64-encoded data.
Returns
Ok(decoder)
on success.Err(Error::InvalidLength)
if the input buffer is empty.
sourcepub fn new_wrapped(input: &'i [u8], line_width: usize) -> Result<Self, Error>
pub fn new_wrapped(input: &'i [u8], line_width: usize) -> Result<Self, Error>
Create a new decoder for a byte slice containing Base64 which line wraps at the given line length.
Trailing newlines are not supported and must be removed in advance.
Newlines are handled according to what are roughly RFC7468 conventions:
[parsers] MUST handle different newline conventions
RFC7468 allows any of the following as newlines, and allows a mixture of different types of newlines:
eol = CRLF / CR / LF
Returns
Ok(decoder)
on success.Err(Error::InvalidLength)
if the input buffer is empty or the line width is zero.
sourcepub fn decode<'o>(&mut self, out: &'o mut [u8]) -> Result<&'o [u8], Error>
pub fn decode<'o>(&mut self, out: &'o mut [u8]) -> Result<&'o [u8], Error>
Fill the provided buffer with data decoded from Base64.
Enough Base64 input data must remain to fill the entire buffer.
Returns
Ok(bytes)
if the expected amount of data was readErr(Error::InvalidLength)
if the exact amount of data couldn’t be read
sourcepub fn decode_to_end<'o>(
&mut self,
buf: &'o mut Vec<u8>
) -> Result<&'o [u8], Error>
Available on crate feature alloc
only.
pub fn decode_to_end<'o>(
&mut self,
buf: &'o mut Vec<u8>
) -> Result<&'o [u8], Error>
alloc
only.Decode all remaining Base64 data, placing the result into buf
.
If successful, this function will return the total number of bytes
decoded into buf
.
sourcepub fn remaining_len(&self) -> usize
pub fn remaining_len(&self) -> usize
Get the length of the remaining data after Base64 decoding.
Decreases every time data is decoded.
sourcepub fn is_finished(&self) -> bool
pub fn is_finished(&self) -> bool
Has all of the input data been decoded?
Trait Implementations
sourceimpl<'i, E: Encoding> Read for Decoder<'i, E>
Available on crate feature std
only.
impl<'i, E: Encoding> Read for Decoder<'i, E>
std
only.sourcefn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
sourcefn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize>
buf
. Read moresourcefn read_exact(&mut self, buf: &mut [u8]) -> Result<()>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<()>
buf
. Read more1.36.0 · sourcefn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read
, except that it reads into a slice of buffers. Read moresourcefn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector
)1.0.0 · sourcefn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf
. Read moresourcefn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)sourcefn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)cursor
. Read more1.0.0 · sourcefn by_ref(&mut self) -> &mut Self
fn by_ref(&mut self) -> &mut Self
Read
. Read more