diff options
author | Tim Schumacher <timschumi@gmx.de> | 2023-03-05 14:30:23 +0100 |
---|---|---|
committer | Idan Horowitz <idan.horowitz@gmail.com> | 2023-03-20 12:15:38 +0200 |
commit | 858c44ae1ba7b1144487a0321354ad064d11e582 (patch) | |
tree | cc6ad75d9680e7abdb85b0acce4080ec47d19901 /Userland/Utilities | |
parent | b3a9729e23a00d40d63b63d7a6c5c8075dc5d481 (diff) | |
download | serenity-858c44ae1ba7b1144487a0321354ad064d11e582.zip |
Utilities: Add an `lzcat` utility
Diffstat (limited to 'Userland/Utilities')
-rw-r--r-- | Userland/Utilities/CMakeLists.txt | 3 | ||||
-rw-r--r-- | Userland/Utilities/lzcat.cpp | 35 |
2 files changed, 37 insertions, 1 deletions
diff --git a/Userland/Utilities/CMakeLists.txt b/Userland/Utilities/CMakeLists.txt index b13de2e832..0cb5171c88 100644 --- a/Userland/Utilities/CMakeLists.txt +++ b/Userland/Utilities/CMakeLists.txt @@ -7,7 +7,7 @@ list(APPEND REQUIRED_TARGETS touch tr true umount uname uniq uptime w wc which whoami xargs yes ) list(APPEND RECOMMENDED_TARGETS - adjtime aplay abench asctl bt checksum chres cksum copy fortune gunzip gzip init install keymap lsirq lsof lspci man mknod mktemp + adjtime aplay abench asctl bt checksum chres cksum copy fortune gunzip gzip init install keymap lsirq lsof lspci lzcat man mknod mktemp nc netstat notify ntpquery open passwd pls printf pro shot strings tar tt unzip wallpaper zip ) @@ -105,6 +105,7 @@ target_link_libraries(keymap PRIVATE LibKeyboard) target_link_libraries(less PRIVATE LibLine) target_link_libraries(lspci PRIVATE LibPCIDB) target_link_libraries(lsusb PRIVATE LibUSBDB) +target_link_libraries(lzcat PRIVATE LibCompress) target_link_libraries(man PRIVATE LibMarkdown LibManual) target_link_libraries(markdown-check PRIVATE LibMarkdown) target_link_libraries(matroska PRIVATE LibVideo) diff --git a/Userland/Utilities/lzcat.cpp b/Userland/Utilities/lzcat.cpp new file mode 100644 index 0000000000..5884a9f0d2 --- /dev/null +++ b/Userland/Utilities/lzcat.cpp @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2023, Tim Schumacher <timschumi@gmx.de> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include <LibCompress/Lzma.h> +#include <LibCore/ArgsParser.h> +#include <LibCore/File.h> +#include <LibCore/System.h> +#include <LibMain/Main.h> + +ErrorOr<int> serenity_main(Main::Arguments arguments) +{ + TRY(Core::System::pledge("rpath stdio")); + + StringView filename; + + Core::ArgsParser args_parser; + args_parser.set_general_help("Decompress and print an LZMA archive"); + args_parser.add_positional_argument(filename, "File to decompress", "file"); + args_parser.parse(arguments); + + auto file = TRY(Core::File::open_file_or_standard_stream(filename, Core::File::OpenMode::Read)); + auto stream = TRY(Compress::LzmaDecompressor::create_from_container(move(file))); + + // Arbitrarily chosen buffer size. + Array<u8, 4096> buffer; + while (!stream->is_eof()) { + auto slice = TRY(stream->read_some(buffer)); + out("{:s}", slice); + } + + return 0; +} |