Struct DecoderReader

struct DecoderReader<'e, E: Engine, R: io::Read> { ... }

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: io::Read> DecoderReader<'e, E, R>

fn new(reader: R, engine: &'e E) -> Self

Create a new decoder that will read from the provided reader r.

fn into_inner(self: Self) -> R

Unwraps this DecoderReader, returning the base reader which it reads base64 encoded input from.

Because DecoderReader performs 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 the Read implementation which may still be useful.

impl<'e, E, R> Freeze for DecoderReader<'e, E, R>

impl<'e, E, R> RefUnwindSafe for DecoderReader<'e, E, R>

impl<'e, E, R> Send for DecoderReader<'e, E, R>

impl<'e, E, R> Sync for DecoderReader<'e, E, R>

impl<'e, E, R> Unpin for DecoderReader<'e, E, R>

impl<'e, E, R> UnsafeUnpin for DecoderReader<'e, E, R>

impl<'e, E, R> UnwindSafe for DecoderReader<'e, E, R>

impl<'e, E: Engine, R: io::Read> Debug for DecoderReader<'e, E, R>

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

impl<'e, E: Engine, R: io::Read> Read for DecoderReader<'e, E, R>

fn read(self: &mut Self, buf: &mut [u8]) -> Result<usize>

Decode input from the wrapped reader.

Under non-error circumstances, this returns Ok with the value being the number of bytes written in buf.

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.

impl<T> Any for DecoderReader<'e, E, R>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for DecoderReader<'e, E, R>

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for DecoderReader<'e, E, R>

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> From for DecoderReader<'e, E, R>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T, U> Into for DecoderReader<'e, E, R>

fn into(self: Self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom for DecoderReader<'e, E, R>

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for DecoderReader<'e, E, R>

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>