Remove unnecessary indentation by rearranging ifs.
Move up readAsciiData(). Generalize to std::istream.
Move up decodeBinaryData(). Generalize to std::istream.
Check input stream state while decoding from base64.
Make readDataArray() return optional<> in case of error.

This allows an early exit in case of incomplete data.