summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Schumacher <timschumi@gmx.de>2023-03-11 14:30:17 +0100
committerAndreas Kling <kling@serenityos.org>2023-03-21 10:25:13 +0100
commita61c120b3fc0259627f22d5415402200f1eaf6e0 (patch)
tree0694b9db73be91a30ebae317046d4038833eac88
parent9e990f7329294151a2dc232f35311cd5a044c856 (diff)
downloadserenity-a61c120b3fc0259627f22d5415402200f1eaf6e0.zip
Utilities: Add an `xzcat` utility
-rw-r--r--Userland/Utilities/CMakeLists.txt3
-rw-r--r--Userland/Utilities/xzcat.cpp35
2 files changed, 37 insertions, 1 deletions
diff --git a/Userland/Utilities/CMakeLists.txt b/Userland/Utilities/CMakeLists.txt
index 0cb5171c88..001dcfc31c 100644
--- a/Userland/Utilities/CMakeLists.txt
+++ b/Userland/Utilities/CMakeLists.txt
@@ -8,7 +8,7 @@ list(APPEND REQUIRED_TARGETS
)
list(APPEND RECOMMENDED_TARGETS
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
+ nc netstat notify ntpquery open passwd pls printf pro shot strings tar tt unzip wallpaper xzcat zip
)
# FIXME: Support specifying component dependencies for utilities (e.g. WebSocket for telws)
@@ -138,6 +138,7 @@ target_link_libraries(wallpaper PRIVATE LibGfx LibGUI)
target_link_libraries(wasm PRIVATE LibWasm LibLine LibJS)
target_link_libraries(wsctl PRIVATE LibGUI LibIPC)
target_link_libraries(xml PRIVATE LibXML)
+target_link_libraries(xzcat PRIVATE LibCompress)
target_link_libraries(zip PRIVATE LibArchive LibCompress LibCrypto)
# FIXME: Link this file into headless-browser without compiling it again.
diff --git a/Userland/Utilities/xzcat.cpp b/Userland/Utilities/xzcat.cpp
new file mode 100644
index 0000000000..81ffe61a45
--- /dev/null
+++ b/Userland/Utilities/xzcat.cpp
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2023, Tim Schumacher <timschumi@gmx.de>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <LibCompress/Xz.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 XZ 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::XzDecompressor::create(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;
+}