Command line Base64 transcoder utility written in C++
- Clone the repo.
git clone https://github.com/namantam1/base64
- Change directory to src
cd base64/src/
- Compile with cli option to generate executable.
# Using make
make cli
# Without using make
g++ -DCOMPILE_CLI base64.cpp -o bs64
# Now run following command to get help text and play with cli.
./bs64 -h
# You will get output as -
#Usage: base64 [Options]...
#Options:-
# -h, --help Display help
# -f, --file Path to file
# -t, --text Text to encode
# -o, --output Output to given file name
- Get binary object file, compile the base64.cpp with -c Option.
# Using make
make obj
#without using make
g++ -c base64.cpp -o base64.o
- Include base64 as library in your project.
// example.cpp
#include <iostream>
#include "base64.hpp"
using namespace std;
int main(int argc, char **argv) {
// 8-bit array
vector<uint8_t> arr = {'a', 'b', 'c'};
// get bas64 string
string bs64_str = base64::encode(arr);
// to get base64 of a binary file
string file_bs64_str = base64::encode(base64::read_file("path/to/binary_file.png"));
// to get 8-bit array of base64 string
vector<uint8_t> file_bit_array = base64::decode(bs64_str);
// base64 string to binary file
base64::write_file(file_bit_array, "bin_file.png");
return 0;
}
- Compile your project with object file generated above.
g++ base64.o example.cpp -o example
# execute example
./example
- Implement base64 encode algorithm.
- Implement read binary file and return as 8-bit array.
- Implement command line parser.
- Handle error and throw proper error with message
- Implement base64 decode function.
- Implement write_file function to convert 8-bit array to binary.
- Write test & benchmarks to get performance idea.
- Improve encode/decode algorithm.
- Document encode/decode algorithm.
- To make this as a Header-Only C++ library.