23#if defined(__unix__) || defined(__MINGW32__)
28#include "aeongames/Pipeline.hpp"
35 void Base64::ProcessArgs (
int argc,
char** argv )
37 if ( argc < 3 || ( strcmp ( argv[1],
"base64" ) != 0 && ! ( strcmp ( argv[2],
"encode" ) == 0 || strcmp ( argv[2],
"decode" ) == 0 ) ) )
39 std::ostringstream stream;
40 stream <<
"Invalid tool name, expected base64 <encode|decode>, got " << ( ( argc < 2 ) ?
"nothing" : argv[1] ) <<
" " << ( ( argc < 3 ) ?
"nothing" : argv[2] ) << std::endl;
41 throw std::runtime_error ( stream.str().c_str() );
43 mDecode = ( strcmp ( argv[2],
"decode" ) == 0 );
44 for (
int i = 3; i < argc; ++i )
46 if ( argv[i][0] ==
'-' )
48 if ( argv[i][1] ==
'-' )
50 if ( strncmp ( &argv[i][2],
"in",
sizeof (
"in" ) ) == 0 )
55 else if ( strncmp ( &argv[i][2],
"out",
sizeof (
"out" ) ) == 0 )
58 mOutputFile = argv[i];
71 mOutputFile = argv[i];
81 if ( mInputFile.empty() )
83 throw std::runtime_error (
"No Input file provided." );
85 if ( mOutputFile.empty() )
89 std::filesystem::path input_path ( mInputFile );
90 mOutputFile = input_path.replace_extension (
".b64" ).string();
94 throw std::runtime_error (
"No Output file provided. Decoding does not yet infer output extensions." );
101 ProcessArgs ( argc, argv );
103 in.exceptions ( std::ifstream::failbit | std::ifstream::badbit );
104 in.open ( mInputFile, std::ifstream::in | std::ifstream::binary );
105 std::string buffer ( ( std::istreambuf_iterator<char> ( in ) ), ( std::istreambuf_iterator<char>() ) );
107 std::string output{};
117 out.exceptions ( std::ofstream::failbit | std::ofstream::badbit );
118 out.open ( mOutputFile, std::ofstream::out | std::ofstream::binary );
119 out.write (
reinterpret_cast<char*
> ( output.data() ), output.size() );
Base64 encoding and decoding utilities.
Base64()
Default constructor.
int operator()(int argc, char **argv) override
Execute the Base64 tool.
<- This is here just for the literals
DLL std::string Base64Encode(const uint8_t *aData, size_t aDataSize, bool aSplit=true)
Encode a binary string.
DLL std::string Base64Decode(const uint8_t *aData, size_t aDataSize)
Decode a base64 string.