Struct DecoderReader
pub struct DecoderReader<'e, E: Engine, R: Read> { /* private fields */ }
A Read implementation that decodes base64 data read from an underlying reader.
Examples
use std::io::Read;
use std::io::Cursor;
use base64::engine::general_purpose;
// use a cursor as the simplest possible `Read` -- in real code this is probably a file, etc.
let mut wrapped_reader = Cursor::new(b"YXNkZg==");
let mut decoder = base64::read::DecoderReader::new(
&mut wrapped_reader,
&general_purpose::STANDARD);
// handle errors as you normally would
let mut result = Vec::new();
decoder.read_to_end(&mut result).unwrap();
assert_eq!(b"asdf", &result[..]);
Implementations
impl<'e, E: Engine, R: Read> DecoderReader<'e, E, R>
fn new(reader: R, engine: &'e E) -> SelfCreate a new decoder that will read from the provided reader
r.fn into_inner(self) -> RUnwraps this
DecoderReader, returning the base reader which it reads base64 encoded input from.Because
DecoderReaderperforms internal buffering, the state of the inner reader is unspecified. This function is mainly provided because the inner reader type may provide additional functionality beyond theReadimplementation which may still be useful.
Trait Implementations
impl<'e, E: Engine, R: Read> Debug for DecoderReader<'e, E, R>
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl<'e, E: Engine, R: Read> Read for DecoderReader<'e, E, R>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>Decode input from the wrapped reader.
Under non-error circumstances, this returns
Okwith the value being the number of bytes written inbuf.Where possible, this function buffers base64 to minimize the number of
read()calls to the delegate reader.Errors
Any errors emitted by the delegate reader are returned. Decoding errors due to invalid base64 are also possible, and will have
io::ErrorKind::InvalidData.