summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2022-09-13 14:46:49 +0100
committerLinus Groh <mail@linusgroh.de>2022-11-19 17:00:10 +0000
commitd071a930476784a517852caa4e1e84c8523767c9 (patch)
tree87096c44eed4f059e3892091b3fca2f2c3e4ea3a
parent5a0c2980745c56caf0a5ed247edce7b756396964 (diff)
downloadserenity-d071a930476784a517852caa4e1e84c8523767c9.zip
base64: Port to Core::Stream
-rw-r--r--Userland/Utilities/base64.cpp15
1 files changed, 5 insertions, 10 deletions
diff --git a/Userland/Utilities/base64.cpp b/Userland/Utilities/base64.cpp
index 4d21b88199..dbcd0a1221 100644
--- a/Userland/Utilities/base64.cpp
+++ b/Userland/Utilities/base64.cpp
@@ -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;
}