apio
140910763e
All checks were successful
Build and test / build (push) Successful in 1m56s
Why are command-line utilities stored in "apps"? And why are apps like "editor" or "terminal" top-level directories? Command-line utilities now go in "utils". GUI stuff now goes in "gui". This includes: libui -> gui/libui, wind -> gui/wind, GUI apps -> gui/apps, editor&terminal -> gui/apps... System services go in "system".
40 lines
1.1 KiB
C++
40 lines
1.1 KiB
C++
#include <luna/Base64.h>
|
|
#include <os/ArgumentParser.h>
|
|
#include <os/File.h>
|
|
|
|
Result<int> luna_main(int argc, char** argv)
|
|
{
|
|
StringView path;
|
|
bool decode { false };
|
|
bool allow_garbage { false };
|
|
|
|
os::ArgumentParser parser;
|
|
parser.add_description("Encode or decode Base64 data. If not given a file, reads from standard input.");
|
|
parser.add_system_program_info("base64"_sv);
|
|
parser.add_positional_argument(path, "file", "-"_sv);
|
|
parser.add_switch_argument(decode, 'd', "decode", "decode data");
|
|
parser.add_switch_argument(allow_garbage, 'i', "ignore-garbage", "when decoding, ignore non-base64 characters");
|
|
parser.parse(argc, argv);
|
|
|
|
auto file = TRY(os::File::open_input_file(path));
|
|
|
|
if (!decode)
|
|
{
|
|
auto data = TRY(file->read_all());
|
|
|
|
auto encoded = TRY(Base64::encode(data));
|
|
|
|
os::println("%s", encoded.chars());
|
|
}
|
|
else
|
|
{
|
|
auto data = TRY(file->read_all_as_string());
|
|
|
|
auto decoded = TRY(Base64::decode(data.view(), allow_garbage));
|
|
|
|
os::File::standard_output()->write(decoded);
|
|
}
|
|
|
|
return 0;
|
|
}
|