mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 21:18:14 +00:00
Utilities: Add an lzcat
utility
This commit is contained in:
parent
b3a9729e23
commit
858c44ae1b
2 changed files with 37 additions and 1 deletions
35
Userland/Utilities/lzcat.cpp
Normal file
35
Userland/Utilities/lzcat.cpp
Normal file
|
@ -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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue