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

base64: Use Core::File standard_input() standard_output()

This commit is contained in:
Kenneth Myhra 2022-04-30 21:13:17 +02:00 committed by Linus Groh
parent 8ae492ba4d
commit ec1f5fd20f

View file

@ -4,16 +4,12 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/Assertions.h>
#include <AK/Base64.h>
#include <AK/ByteBuffer.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/File.h>
#include <LibCore/System.h>
#include <LibMain/Main.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
@ -29,13 +25,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
ByteBuffer buffer;
if (filepath == nullptr || strcmp(filepath, "-") == 0) {
auto file = Core::File::construct();
bool success = file->open(
STDIN_FILENO,
Core::OpenMode::ReadOnly,
Core::File::ShouldCloseFileDescriptor::Yes);
VERIFY(success);
buffer = file->read_all();
buffer = Core::File::standard_input()->read_all();
} else {
auto result = Core::File::open(filepath, Core::OpenMode::ReadOnly);
VERIFY(!result.is_error());
@ -47,7 +37,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
if (decode) {
auto decoded = TRY(decode_base64(StringView(buffer)));
fwrite(decoded.data(), sizeof(u8), decoded.size(), stdout);
Core::File::standard_output()->write(decoded.data(), decoded.size());
return 0;
}