| 1 | // LAF Library |
|---|---|
| 2 | // Copyright (c) 2022 Igara Studio S.A. |
| 3 | // |
| 4 | // This file is released under the terms of the MIT license. |
| 5 | // Read LICENSE.txt for more information. |
| 6 | |
| 7 | #include "base/base64.h" |
| 8 | #include "base/buffer.h" |
| 9 | #include "base/file_content.h" |
| 10 | #include "os/os.h" |
| 11 | |
| 12 | #include <cstring> |
| 13 | |
| 14 | int app_main(int argc, char* argv[]) |
| 15 | { |
| 16 | os::SystemRef system = os::make_system(); |
| 17 | system->setAppMode(os::AppMode::CLI); |
| 18 | |
| 19 | std::string fn; |
| 20 | bool decode = false; |
| 21 | |
| 22 | for (int i=1; i<argc; ++i) { |
| 23 | if (std::strcmp(argv[i], "-d") == 0) |
| 24 | decode = true; |
| 25 | else |
| 26 | fn = argv[i]; |
| 27 | } |
| 28 | |
| 29 | base::buffer input; |
| 30 | if (!fn.empty()) |
| 31 | input = base::read_file_content(fn); |
| 32 | else |
| 33 | input = base::read_file_content(stdin); |
| 34 | |
| 35 | base::buffer output; |
| 36 | if (decode) { |
| 37 | output = base::decode_base64(input); |
| 38 | base::set_write_binary_file_content(stdout); |
| 39 | } |
| 40 | else { |
| 41 | std::string tmp = base::encode_base64(input); |
| 42 | output = base::buffer(tmp.begin(), tmp.end()); |
| 43 | } |
| 44 | base::write_file_content(stdout, output); |
| 45 | return 0; |
| 46 | } |
| 47 |