LibCompress: Remove Gzip compress_file & decompress_file methods

The gzip utility was the last user of these methods, but now is using
the more comfortable Stream mechanism so we can just remove this code.
This commit is contained in:
Liav A. 2024-05-10 22:29:01 +03:00 committed by Andrew Kaster
parent 5b34b4af14
commit f474d0c316
2 changed files with 0 additions and 36 deletions

View file

@ -182,22 +182,6 @@ 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::InputBufferedFile::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)
@ -262,22 +246,4 @@ ErrorOr<ByteBuffer> GzipCompressor::compress_all(ReadonlyBytes bytes)
return buffer;
}
ErrorOr<void> GzipCompressor::compress_file(StringView input_filename, NonnullOwnPtr<Stream> output_stream)
{
// We map the whole file instead of streaming to reduce size overhead (gzip header) and increase the deflate block size (better compression)
// TODO: automatically fallback to buffered streaming for very large files
OwnPtr<Core::MappedFile> file;
ReadonlyBytes input_bytes;
if (TRY(Core::System::stat(input_filename)).st_size > 0) {
file = TRY(Core::MappedFile::map(input_filename));
input_bytes = file->bytes();
}
auto output_bytes = TRY(Compress::GzipCompressor::compress_all(input_bytes));
TRY(output_stream->write_until_depleted(output_bytes));
return {};
}
}

View file

@ -52,7 +52,6 @@ public:
virtual void close() override {};
static ErrorOr<ByteBuffer> decompress_all(ReadonlyBytes);
static ErrorOr<void> decompress_file(StringView input_file, NonnullOwnPtr<Stream> output_stream);
static ErrorOr<Optional<String>> describe_header(ReadonlyBytes);
static bool is_likely_compressed(ReadonlyBytes bytes);
@ -93,7 +92,6 @@ public:
virtual void close() override;
static ErrorOr<ByteBuffer> compress_all(ReadonlyBytes bytes);
static ErrorOr<void> compress_file(StringView input_file, NonnullOwnPtr<Stream> output_stream);
private:
MaybeOwned<Stream> m_output_stream;