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§
Source§impl<'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>
pub fn decode_to_end<'o>( &mut self, buf: &'o mut Vec<u8>, ) -> Result<&'o [u8], Error>
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§
Source§impl<'i, E: Encoding> Read for Decoder<'i, E>
impl<'i, E: Encoding> Read for Decoder<'i, E>
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
Source§fn 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 moreSource§fn read_exact(&mut self, buf: &mut [u8]) -> Result<()>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<()>
buf
. Read more1.36.0 · Source§fn 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 moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector
)1.0.0 · Source§fn 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 moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)Source§fn 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 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read
. Read more