1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 09:14:58 +00:00

base64: Port to Core::Stream

This commit is contained in:
Sam Atkins 2022-09-13 14:46:49 +01:00 committed by Linus Groh
parent 5a0c298074
commit d071a93047

View file

@ -6,7 +6,7 @@
#include <AK/Base64.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/File.h>
#include <LibCore/Stream.h>
#include <LibCore/System.h>
#include <LibMain/Main.h>
@ -22,19 +22,14 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
args_parser.add_positional_argument(filepath, "", "file", Core::ArgsParser::Required::No);
args_parser.parse(arguments);
ByteBuffer buffer;
if (filepath == nullptr || filepath == "-") {
buffer = Core::File::standard_input()->read_all();
} else {
auto file = TRY(Core::File::open(filepath, Core::OpenMode::ReadOnly));
buffer = file->read_all();
}
auto file = TRY(Core::Stream::File::open_file_or_standard_stream(filepath, Core::Stream::OpenMode::Read));
ByteBuffer buffer = TRY(file->read_all());
TRY(Core::System::pledge("stdio"));
if (decode) {
auto decoded = TRY(decode_base64(StringView(buffer)));
Core::File::standard_output()->write(decoded.data(), decoded.size());
auto decoded = TRY(decode_base64(buffer));
out("{}", StringView(decoded.bytes()));
return 0;
}