mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 23:48:11 +00:00
gunzip+LibCompress: Move utility to decompress files to GzipDecompressor
This is to allow re-using this method (and any optimization it receives) by other utilities, like gzip.
This commit is contained in:
parent
df577b457a
commit
857f559a06
3 changed files with 20 additions and 18 deletions
|
@ -11,6 +11,7 @@
|
|||
#include <AK/DeprecatedString.h>
|
||||
#include <AK/MemoryStream.h>
|
||||
#include <LibCore/DateTime.h>
|
||||
#include <LibCore/File.h>
|
||||
|
||||
namespace Compress {
|
||||
|
||||
|
@ -179,6 +180,22 @@ ErrorOr<ByteBuffer> GzipDecompressor::decompress_all(ReadonlyBytes bytes)
|
|||
return output_buffer;
|
||||
}
|
||||
|
||||
ErrorOr<void> GzipDecompressor::decompress_file(StringView input_filename, NonnullOwnPtr<Stream> output_stream)
|
||||
{
|
||||
auto input_file = TRY(Core::File::open(input_filename, Core::File::OpenMode::Read));
|
||||
auto input_stream = TRY(Core::BufferedFile::create(move(input_file), 256 * KiB));
|
||||
|
||||
auto gzip_stream = GzipDecompressor { move(input_stream) };
|
||||
auto buffer = TRY(ByteBuffer::create_uninitialized(256 * KiB));
|
||||
|
||||
while (!gzip_stream.is_eof()) {
|
||||
auto span = TRY(gzip_stream.read_some(buffer));
|
||||
TRY(output_stream->write_until_depleted(span));
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
bool GzipDecompressor::is_eof() const { return m_input_stream->is_eof(); }
|
||||
|
||||
ErrorOr<size_t> GzipDecompressor::write_some(ReadonlyBytes)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue