From df30fd623207101123e850221086232fb3c2c000 Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Thu, 9 Mar 2023 00:50:58 +0100 Subject: tar: Add partial support for LZMA-compressed archives --- Userland/Utilities/tar.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'Userland/Utilities/tar.cpp') diff --git a/Userland/Utilities/tar.cpp b/Userland/Utilities/tar.cpp index ae8b9352fc..9b891d338f 100644 --- a/Userland/Utilities/tar.cpp +++ b/Userland/Utilities/tar.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -30,6 +31,7 @@ ErrorOr serenity_main(Main::Arguments arguments) bool list = false; bool verbose = false; bool gzip = false; + bool lzma = false; bool no_auto_compress = false; StringView archive_file; bool dereference; @@ -42,6 +44,7 @@ ErrorOr serenity_main(Main::Arguments arguments) args_parser.add_option(list, "List contents", "list", 't'); args_parser.add_option(verbose, "Print paths", "verbose", 'v'); args_parser.add_option(gzip, "Compress or decompress file using gzip", "gzip", 'z'); + args_parser.add_option(lzma, "Compress or decompress file using lzma", "lzma", 0); args_parser.add_option(no_auto_compress, "Do not use the archive suffix to select the compression algorithm", "no-auto-compress", 0); args_parser.add_option(directory, "Directory to extract to/create from", "directory", 'C', "DIRECTORY"); args_parser.add_option(archive_file, "Archive file", "file", 'f', "FILE"); @@ -57,6 +60,8 @@ ErrorOr serenity_main(Main::Arguments arguments) if (!no_auto_compress && !archive_file.is_empty()) { if (archive_file.ends_with(".gz"sv) || archive_file.ends_with(".tgz"sv)) gzip = true; + if (archive_file.ends_with(".lzma"sv)) + lzma = true; } if (list || extract) { @@ -68,6 +73,9 @@ ErrorOr serenity_main(Main::Arguments arguments) if (gzip) input_stream = make(move(input_stream)); + if (lzma) + input_stream = TRY(Compress::LzmaDecompressor::create_from_container(move(input_stream))); + auto tar_stream = TRY(Archive::TarInputStream::construct(move(input_stream))); HashMap global_overrides; @@ -216,6 +224,9 @@ ErrorOr serenity_main(Main::Arguments arguments) if (gzip) output_stream = TRY(try_make(move(output_stream))); + if (lzma) + TODO(); + Archive::TarOutputStream tar_stream(move(output_stream)); auto add_file = [&](DeprecatedString path) -> ErrorOr { -- cgit v1.2.3