Skip to content

Truly independent web browser

LibCompress: Remove the unused Brotli, Gzip and LZW code

Shannon Booth406acbe4a8c2
diff --git a/Libraries/LibCompress/Brotli.cpp b/Libraries/LibCompress/Brotli.cpp
deleted file mode 100644
index 3ecfdad6d2e..00000000000
--- a/Libraries/LibCompress/Brotli.cpp
+++ /dev/null
@@ -1,228 +0,0 @@
-/*
- * Copyright (c) 2026-present, the Ladybird developers.
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#include <LibCompress/Brotli.h>
-#include <LibCompress/GenericZlib.h>
-
-#include <brotli/decode.h>
-#include <brotli/encode.h>
-#include <string.h>
-
-namespace Compress {
-
-static Error brotli_decoder_error(BrotliDecoderState* state)
-{
- auto const* message = BrotliDecoderErrorString(BrotliDecoderGetErrorCode(state));
- return Error::from_string_view({ message, strlen(message) });
-}
-
-static u32 quality_from_compression_level(BrotliCompressionLevel compression_level)
-{
- switch (compression_level) {
- case BrotliCompressionLevel::Fastest:
- return BROTLI_MIN_QUALITY;
- case BrotliCompressionLevel::Default:
- return BROTLI_DEFAULT_QUALITY;
- case BrotliCompressionLevel::Best:
- return BROTLI_MAX_QUALITY;
- }
-
- VERIFY_NOT_REACHED();
-}
-
-BrotliDecompressor::BrotliDecompressor(AK::FixedArray<u8> buffer, MaybeOwned<Stream> stream, BrotliDecoderState* decoder)
- : m_buffer(move(buffer))
- , m_stream(move(stream))
- , m_decoder(decoder)
-{
-}
-
-ErrorOr<NonnullOwnPtr<BrotliDecompressor>> BrotliDecompressor::create(MaybeOwned<Stream> stream)
-{
- auto buffer = TRY(AK::FixedArray<u8>::create(16 * KiB));
- auto* decoder = BrotliDecoderCreateInstance(nullptr, nullptr, nullptr);
- if (!decoder)
- return Error::from_errno(ENOMEM);
-
- return adopt_nonnull_own_or_enomem(new (nothrow) BrotliDecompressor(move(buffer), move(stream), decoder));
-}
-
-ErrorOr<ByteBuffer> BrotliDecompressor::decompress_all(ReadonlyBytes bytes)
-{
- return ::Compress::decompress_all<BrotliDecompressor>(bytes);
-}
-
-BrotliDecompressor::~BrotliDecompressor()
-{
- BrotliDecoderDestroyInstance(m_decoder);
-}
-
-ErrorOr<Bytes> BrotliDecompressor::read_some(Bytes bytes)
-{
- if (bytes.is_empty())
- return bytes.trim(0);
-
- if (m_eof) {
- if (!m_stream->is_eof())
- return Error::from_string_literal("Brotli stream has trailing data");
- return bytes.trim(0);
- }
-
- if (m_available_in == 0) {
- auto input = TRY(m_stream->read_some(m_buffer.span()));
- m_available_in = input.size();
- m_next_in = input.data();
- }
-
- auto* next_out = bytes.data();
- auto available_out = bytes.size();
- auto had_input = m_available_in > 0;
-
- auto result = BrotliDecoderDecompressStream(m_decoder, &m_available_in, &m_next_in, &available_out, &next_out, nullptr);
- auto produced = bytes.size() - available_out;
-
- switch (result) {
- case BROTLI_DECODER_RESULT_ERROR:
- return brotli_decoder_error(m_decoder);
- case BROTLI_DECODER_RESULT_SUCCESS:
- if (m_available_in > 0 || !m_stream->is_eof())
- return Error::from_string_literal("Brotli stream has trailing data");
-
- m_eof = true;
- return bytes.trim(produced);
- case BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT:
- return bytes.trim(produced);
- case BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT:
- if (produced > 0 || had_input)
- return bytes.trim(produced);
- return Error::from_string_literal("Brotli stream ended before the end marker");
- }
-
- VERIFY_NOT_REACHED();
-}
-
-ErrorOr<size_t> BrotliDecompressor::write_some(ReadonlyBytes)
-{
- return Error::from_errno(EBADF);
-}
-
-bool BrotliDecompressor::is_eof() const
-{
- return m_eof;
-}
-
-bool BrotliDecompressor::is_open() const
-{
- return m_stream->is_open();
-}
-
-void BrotliDecompressor::close()
-{
-}
-
-BrotliCompressor::BrotliCompressor(AK::FixedArray<u8> buffer, MaybeOwned<Stream> stream, BrotliEncoderState* encoder)
- : m_buffer(move(buffer))
- , m_stream(move(stream))
- , m_encoder(encoder)
-{
-}
-
-ErrorOr<NonnullOwnPtr<BrotliCompressor>> BrotliCompressor::create(MaybeOwned<Stream> stream, BrotliCompressionLevel compression_level)
-{
- auto buffer = TRY(AK::FixedArray<u8>::create(16 * KiB));
- auto* encoder = BrotliEncoderCreateInstance(nullptr, nullptr, nullptr);
- if (!encoder)
- return Error::from_errno(ENOMEM);
-
- if (!BrotliEncoderSetParameter(encoder, BROTLI_PARAM_QUALITY, quality_from_compression_level(compression_level))) {
- BrotliEncoderDestroyInstance(encoder);
- return Error::from_string_literal("Failed to set Brotli compression quality");
- }
-
- return adopt_nonnull_own_or_enomem(new (nothrow) BrotliCompressor(move(buffer), move(stream), encoder));
-}
-
-ErrorOr<ByteBuffer> BrotliCompressor::compress_all(ReadonlyBytes bytes, BrotliCompressionLevel compression_level)
-{
- return ::Compress::compress_all<BrotliCompressor>(bytes, compression_level);
-}
-
-BrotliCompressor::~BrotliCompressor()
-{
- BrotliEncoderDestroyInstance(m_encoder);
-}
-
-ErrorOr<Bytes> BrotliCompressor::read_some(Bytes)
-{
- return Error::from_errno(EBADF);
-}
-
-ErrorOr<size_t> BrotliCompressor::write_some(ReadonlyBytes bytes)
-{
- if (m_finished)
- return Error::from_string_literal("Brotli stream is already finished");
-
- auto available_in = bytes.size();
- auto const* next_in = bytes.data();
-
- while (true) {
- auto* next_out = m_buffer.data();
- auto available_out = m_buffer.size();
-
- if (!BrotliEncoderCompressStream(m_encoder, BROTLI_OPERATION_PROCESS, &available_in, &next_in, &available_out, &next_out, nullptr))
- return Error::from_string_literal("Brotli compression failed");
-
- auto have = m_buffer.size() - available_out;
- TRY(m_stream->write_until_depleted(m_buffer.span().slice(0, have)));
-
- if (available_in == 0 && !BrotliEncoderHasMoreOutput(m_encoder))
- break;
- }
-
- return bytes.size();
-}
-
-bool BrotliCompressor::is_eof() const
-{
- return false;
-}
-
-bool BrotliCompressor::is_open() const
-{
- return m_stream->is_open();
-}
-
-void BrotliCompressor::close()
-{
-}
-
-ErrorOr<void> BrotliCompressor::finish()
-{
- if (m_finished)
- return {};
-
- size_t available_in = 0;
- u8 const* next_in = nullptr;
-
- while (!BrotliEncoderIsFinished(m_encoder)) {
- auto* next_out = m_buffer.data();
- auto available_out = m_buffer.size();
-
- if (!BrotliEncoderCompressStream(m_encoder, BROTLI_OPERATION_FINISH, &available_in, &next_in, &available_out, &next_out, nullptr))
- return Error::from_string_literal("Brotli compression failed");
-
- auto have = m_buffer.size() - available_out;
- TRY(m_stream->write_until_depleted(m_buffer.span().slice(0, have)));
-
- if (have == 0 && !BrotliEncoderIsFinished(m_encoder))
- return Error::from_string_literal("No Brotli compression progress");
- }
-
- m_finished = true;
- return {};
-}
-
-}
diff --git a/Libraries/LibCompress/Brotli.h b/Libraries/LibCompress/Brotli.h
deleted file mode 100644
index 15e91a6f5a7..00000000000
--- a/Libraries/LibCompress/Brotli.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright (c) 2026-present, the Ladybird developers.
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#pragma once
-
-#include <AK/ByteBuffer.h>
-#include <AK/FixedArray.h>
-#include <AK/MaybeOwned.h>
-#include <AK/NonnullOwnPtr.h>
-#include <AK/Stream.h>
-
-extern "C" {
-typedef struct BrotliDecoderStateStruct BrotliDecoderState;
-typedef struct BrotliEncoderStateStruct BrotliEncoderState;
-}
-
-namespace Compress {
-
-enum class BrotliCompressionLevel : u8 {
- Fastest,
- Default,
- Best,
-};
-
-class BrotliDecompressor final : public Stream {
- AK_MAKE_NONCOPYABLE(BrotliDecompressor);
-
-public:
- static ErrorOr<NonnullOwnPtr<BrotliDecompressor>> create(MaybeOwned<Stream>);
- static ErrorOr<ByteBuffer> decompress_all(ReadonlyBytes);
- ~BrotliDecompressor() override;
-
- virtual ErrorOr<Bytes> read_some(Bytes) override;
- virtual ErrorOr<size_t> write_some(ReadonlyBytes) override;
- virtual bool is_eof() const override;
- virtual bool is_open() const override;
- virtual void close() override;
-
-private:
- BrotliDecompressor(AK::FixedArray<u8>, MaybeOwned<Stream>, BrotliDecoderState*);
-
- AK::FixedArray<u8> m_buffer;
- MaybeOwned<Stream> m_stream;
- BrotliDecoderState* m_decoder { nullptr };
- u8 const* m_next_in { nullptr };
- size_t m_available_in { 0 };
- bool m_eof { false };
-};
-
-class BrotliCompressor final : public Stream {
- AK_MAKE_NONCOPYABLE(BrotliCompressor);
-
-public:
- static ErrorOr<NonnullOwnPtr<BrotliCompressor>> create(MaybeOwned<Stream>, BrotliCompressionLevel = BrotliCompressionLevel::Default);
- static ErrorOr<ByteBuffer> compress_all(ReadonlyBytes, BrotliCompressionLevel = BrotliCompressionLevel::Default);
- ~BrotliCompressor() override;
-
- virtual ErrorOr<Bytes> read_some(Bytes) override;
- virtual ErrorOr<size_t> write_some(ReadonlyBytes) override;
- virtual bool is_eof() const override;
- virtual bool is_open() const override;
- virtual void close() override;
- ErrorOr<void> finish();
-
-private:
- BrotliCompressor(AK::FixedArray<u8>, MaybeOwned<Stream>, BrotliEncoderState*);
-
- AK::FixedArray<u8> m_buffer;
- MaybeOwned<Stream> m_stream;
- BrotliEncoderState* m_encoder { nullptr };
- bool m_finished { false };
-};
-
-}
diff --git a/Libraries/LibCompress/CMakeLists.txt b/Libraries/LibCompress/CMakeLists.txt
index 67888c2f776..229faec92c2 100644
--- a/Libraries/LibCompress/CMakeLists.txt
+++ b/Libraries/LibCompress/CMakeLists.txt
@@ -1,8 +1,6 @@
set(SOURCES
- Brotli.cpp
Deflate.cpp
GenericZlib.cpp
- Gzip.cpp
Zlib.cpp
)
@@ -10,4 +8,3 @@ ladybird_lib(LibCompress compress)
target_link_libraries(LibCompress PRIVATE LibCore LibCrypto)
target_link_libraries(LibCompress PRIVATE ZLIB::ZLIB)
-target_link_libraries(LibCompress PRIVATE ${BROTLI_TARGETS})
diff --git a/Libraries/LibCompress/Forward.h b/Libraries/LibCompress/Forward.h
index 23941cf2908..1d586996e32 100644
--- a/Libraries/LibCompress/Forward.h
+++ b/Libraries/LibCompress/Forward.h
@@ -8,12 +8,8 @@
namespace Compress {
-class BrotliCompressor;
-class BrotliDecompressor;
class DeflateCompressor;
class DeflateDecompressor;
-class GzipCompressor;
-class GzipDecompressor;
class ZlibCompressor;
class ZlibDecompressor;
diff --git a/Libraries/LibCompress/Gzip.cpp b/Libraries/LibCompress/Gzip.cpp
deleted file mode 100644
index 1e34af83800..00000000000
--- a/Libraries/LibCompress/Gzip.cpp
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (c) 2020-2022, the SerenityOS developers.
- * Copyright (c) 2021, Idan Horowitz <[email protected]>
- * Copyright (c) 2025, Altomani Gianluca <[email protected]>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#include <LibCompress/Gzip.h>
-
-#include <zlib.h>
-
-namespace Compress {
-
-ErrorOr<NonnullOwnPtr<GzipDecompressor>> GzipDecompressor::create(MaybeOwned<Stream> stream)
-{
- auto buffer = TRY(AK::FixedArray<u8>::create(16 * 1024));
- auto zstream = TRY(GenericZlibDecompressor::new_z_stream(MAX_WBITS | 16));
- return adopt_nonnull_own_or_enomem(new (nothrow) GzipDecompressor(move(buffer), move(stream), zstream));
-}
-
-ErrorOr<ByteBuffer> GzipDecompressor::decompress_all(ReadonlyBytes bytes)
-{
- return ::Compress::decompress_all<GzipDecompressor>(bytes);
-}
-
-ErrorOr<NonnullOwnPtr<GzipCompressor>> GzipCompressor::create(MaybeOwned<Stream> stream, GenericZlibCompressionLevel compression_level)
-{
- auto buffer = TRY(AK::FixedArray<u8>::create(16 * 1024));
- auto zstream = TRY(GenericZlibCompressor::new_z_stream(MAX_WBITS | 16, compression_level));
- return adopt_nonnull_own_or_enomem(new (nothrow) GzipCompressor(move(buffer), move(stream), zstream));
-}
-
-ErrorOr<ByteBuffer> GzipCompressor::compress_all(ReadonlyBytes bytes, GenericZlibCompressionLevel compression_level)
-{
- return ::Compress::compress_all<GzipCompressor>(bytes, compression_level);
-}
-
-}
diff --git a/Libraries/LibCompress/Gzip.h b/Libraries/LibCompress/Gzip.h
deleted file mode 100644
index b8e8c716235..00000000000
--- a/Libraries/LibCompress/Gzip.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (c) 2020-2022, the SerenityOS developers.
- * Copyright (c) 2021, Idan Horowitz <[email protected]>
- * Copyright (c) 2025, Altomani Gianluca <[email protected]>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#pragma once
-
-#include <LibCompress/GenericZlib.h>
-
-namespace Compress {
-
-class GzipDecompressor final : public GenericZlibDecompressor {
-public:
- bool is_likely_compressed(ReadonlyBytes bytes);
-
- static ErrorOr<NonnullOwnPtr<GzipDecompressor>> create(MaybeOwned<Stream>);
- static ErrorOr<ByteBuffer> decompress_all(ReadonlyBytes);
-
-private:
- GzipDecompressor(AK::FixedArray<u8> buffer, MaybeOwned<Stream> stream, z_stream* zstream)
- : GenericZlibDecompressor(move(buffer), move(stream), zstream)
- {
- }
-};
-
-class GzipCompressor final : public GenericZlibCompressor {
-public:
- static ErrorOr<NonnullOwnPtr<GzipCompressor>> create(MaybeOwned<Stream>, GenericZlibCompressionLevel = GenericZlibCompressionLevel::Default);
- static ErrorOr<ByteBuffer> compress_all(ReadonlyBytes, GenericZlibCompressionLevel = GenericZlibCompressionLevel::Default);
-
-private:
- GzipCompressor(AK::FixedArray<u8> buffer, MaybeOwned<Stream> stream, z_stream* zstream)
- : GenericZlibCompressor(move(buffer), move(stream), zstream)
- {
- }
-};
-
-}
diff --git a/Libraries/LibCompress/Lzw.h b/Libraries/LibCompress/Lzw.h
deleted file mode 100644
index 201450baa5d..00000000000
--- a/Libraries/LibCompress/Lzw.h
+++ /dev/null
@@ -1,255 +0,0 @@
-/*
- * Copyright (c) 2018-2021, Andreas Kling <[email protected]>
- * Copyright (c) 2022, the SerenityOS developers.
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#pragma once
-
-#include <AK/BitStream.h>
-#include <AK/ByteBuffer.h>
-#include <AK/Concepts.h>
-#include <AK/Debug.h>
-#include <AK/Format.h>
-#include <AK/IntegralMath.h>
-#include <AK/MemoryStream.h>
-#include <AK/Vector.h>
-
-namespace Compress {
-
-namespace Details {
-
-class LzwState {
-public:
- u16 add_control_code()
- {
- u16 const control_code = m_code_table.size();
- m_code_table.append(Vector<u8> {});
- m_original_code_table.append(Vector<u8> {});
- if (m_code_table.size() >= m_table_capacity && m_code_size < max_code_size) {
- ++m_code_size;
- ++m_original_code_size;
- m_table_capacity *= 2;
- }
- return control_code;
- }
-
- void reset()
- {
- m_code_table.clear();
- m_code_table.extend(m_original_code_table);
- m_code_size = m_original_code_size;
- m_table_capacity = AK::exp2<u32>(m_code_size);
- }
-
-protected:
- static constexpr int max_code_size = 12;
- static constexpr int max_table_size = 1 << max_code_size;
-
- LzwState(u8 min_code_size, i32 offset_for_size_change)
- : m_code_size(min_code_size)
- , m_original_code_size(min_code_size)
- , m_table_capacity(AK::exp2<u32>(min_code_size))
- , m_offset_for_size_change(offset_for_size_change)
- {
- init_code_table();
- }
-
- void init_code_table()
- {
- m_code_table.ensure_capacity(m_table_capacity);
- for (u16 i = 0; i < m_table_capacity; ++i) {
- m_code_table.unchecked_append({ (u8)i });
- }
- m_original_code_table = m_code_table;
- }
-
- void extend_code_table(Vector<u8> const& entry)
- {
- if (entry.size() > 1 && m_code_table.size() < max_table_size) {
- m_code_table.append(entry);
- if (m_code_table.size() >= (m_table_capacity + m_offset_for_size_change) && m_code_size < max_code_size) {
- ++m_code_size;
- m_table_capacity *= 2;
- }
- }
- }
-
- Vector<Vector<u8>> m_code_table {};
- Vector<Vector<u8>> m_original_code_table {};
-
- u8 m_code_size { 0 };
- u8 m_original_code_size { 0 };
-
- u32 m_table_capacity { 0 };
- i32 m_offset_for_size_change {};
-};
-
-}
-
-template<InputBitStream InputStream>
-class LzwDecompressor : private Details::LzwState {
-public:
- LzwDecompressor(MaybeOwned<InputStream> lzw_stream, u8 min_code_size, i32 offset_for_size_change = 0)
- : LzwState(min_code_size, offset_for_size_change)
- , m_bit_stream(move(lzw_stream))
- {
- }
-
- static ErrorOr<ByteBuffer> decompress_all(ReadonlyBytes bytes, u8 initial_code_size, i32 offset_for_size_change = 0)
- {
- auto memory_stream = make<FixedMemoryStream>(bytes);
- auto lzw_stream = make<InputStream>(MaybeOwned<Stream>(move(memory_stream)));
- LzwDecompressor lzw_decompressor { MaybeOwned<InputStream> { move(lzw_stream) }, initial_code_size, offset_for_size_change };
-
- ByteBuffer decompressed;
-
- u16 const clear_code = lzw_decompressor.add_control_code();
- u16 const end_of_data_code = lzw_decompressor.add_control_code();
-
- while (true) {
- // Some encoders omit the End-of-Information code or emit trailing padding that decodes as invalid LZW
- // codes. Treat any LZW error as an implicit end of the compressed stream and use whatever was successfully
- // decoded so far - this matches the behavior of Firefox, Chrome and Safari.
- auto code_or_error = lzw_decompressor.next_code();
- if (code_or_error.is_error()) {
- dbgln_if(LZW_DEBUG, "LZW stream ended unexpectedly: {}", code_or_error.release_error());
- break;
- }
- auto const code = code_or_error.release_value();
-
- if (code == clear_code) {
- lzw_decompressor.reset();
- continue;
- }
-
- if (code == end_of_data_code)
- break;
-
- TRY(decompressed.try_append(lzw_decompressor.get_output()));
- }
-
- return decompressed;
- }
-
- void reset()
- {
- LzwState::reset();
- m_output.clear();
- }
-
- ErrorOr<u16> next_code()
- {
- m_current_code = TRY(m_bit_stream->template read_bits<u16>(m_code_size));
-
- if (m_current_code > m_code_table.size()) {
- dbgln_if(LZW_DEBUG, "Corrupted LZW stream, invalid code: {}, code table size: {}",
- m_current_code,
- m_code_table.size());
- return Error::from_string_literal("Corrupted LZW stream, invalid code");
- } else if (m_current_code == m_code_table.size() && m_output.is_empty()) {
- dbgln_if(LZW_DEBUG, "Corrupted LZW stream, valid new code but output buffer is empty: {}, code table size: {}",
- m_current_code,
- m_code_table.size());
- return Error::from_string_literal("Corrupted LZW stream, valid new code but output buffer is empty");
- }
-
- return m_current_code;
- }
-
- Vector<u8>& get_output()
- {
- VERIFY(m_current_code <= m_code_table.size());
- if (m_current_code < m_code_table.size()) {
- Vector<u8> new_entry = m_output;
- m_output = m_code_table.at(m_current_code);
- new_entry.append(m_output[0]);
- extend_code_table(new_entry);
- } else if (m_current_code == m_code_table.size()) {
- VERIFY(!m_output.is_empty());
- m_output.append(m_output[0]);
- extend_code_table(m_output);
- }
- return m_output;
- }
-
-private:
- MaybeOwned<InputStream> m_bit_stream;
-
- u16 m_current_code { 0 };
- Vector<u8> m_output {};
-};
-
-class LzwCompressor : private Details::LzwState {
-public:
- static ErrorOr<ByteBuffer> compress_all(ReadonlyBytes bytes, u8 initial_code_size)
- {
- LzwCompressor compressor { initial_code_size };
- AllocatingMemoryStream buffer;
- LittleEndianOutputBitStream output_stream { MaybeOwned<Stream>(buffer) };
-
- u16 const clear_code = compressor.add_control_code();
- u16 const end_of_data_code = compressor.add_control_code();
-
- TRY(output_stream.write_bits(clear_code, compressor.m_code_size));
-
- u32 last_offset = 0;
-
- while (last_offset < bytes.size()) {
- ReadonlyBytes current_symbol {};
- u16 current_code {};
-
- if (compressor.m_code_table.size() == max_table_size - 2) {
- TRY(output_stream.write_bits(clear_code, compressor.m_code_size));
- compressor.reset();
- }
-
- bool found_symbol = false;
-
- for (u32 symbol_size = 1; last_offset + symbol_size <= bytes.size(); ++symbol_size) {
- current_symbol = bytes.slice(last_offset, symbol_size);
- auto const new_code = compressor.code_for_symbol(current_symbol);
-
- if (new_code.has_value()) {
- current_code = *new_code;
- } else {
- found_symbol = true;
- break;
- }
- }
-
- TRY(output_stream.write_bits(current_code, compressor.m_code_size));
-
- if (found_symbol) {
- compressor.extend_code_table(Vector(current_symbol));
- current_symbol = current_symbol.trim(current_symbol.size() - 1);
- }
- last_offset += current_symbol.size();
- }
-
- TRY(output_stream.write_bits(end_of_data_code, compressor.m_code_size));
- TRY(output_stream.align_to_byte_boundary());
- TRY(output_stream.flush_buffer_to_stream());
-
- return TRY(buffer.read_until_eof());
- }
-
-private:
- explicit LzwCompressor(u8 initial_code_size)
- : Details::LzwState(initial_code_size, 1)
- {
- }
-
- Optional<u16> code_for_symbol(ReadonlyBytes bytes)
- {
- for (u16 i = 0; i < m_code_table.size(); ++i) {
- if (m_code_table[i].span() == bytes)
- return i;
- }
-
- return OptionalNone {};
- }
-};
-
-}
diff --git a/Libraries/LibCompress/Rust/Cargo.toml b/Libraries/LibCompress/Rust/Cargo.toml
index ca9556fa081..3e2c61114e6 100644
--- a/Libraries/LibCompress/Rust/Cargo.toml
+++ b/Libraries/LibCompress/Rust/Cargo.toml
@@ -9,7 +9,7 @@ crate-type = ["rlib"]
# After changing dependencies, regenerate the Flatpak sources:
# python3 Meta/CMake/flatpak/generate-cargo-sources.py
[dependencies]
-# NB: Without the ffi-api feature, which would export C functions named as libbrotli's, which LibCompress links.
+# NB: Without the ffi-api feature, which would export C functions named as libbrotli's, which curl and woff2 link.
brotli = { version = "9.0.0", default-features = false, features = ["std"] }
flate2 = { version = "1.1.10", default-features = false, features = ["zlib-rs"] }
diff --git a/Meta/CMake/check_for_dependencies.cmake b/Meta/CMake/check_for_dependencies.cmake
index 208c0e734fc..3a1dc8768a0 100644
--- a/Meta/CMake/check_for_dependencies.cmake
+++ b/Meta/CMake/check_for_dependencies.cmake
@@ -75,14 +75,6 @@ find_package(SQLite3 REQUIRED)
find_package(Threads REQUIRED)
find_package(ZLIB REQUIRED)
-find_package(unofficial-brotli CONFIG)
-if(unofficial-brotli_FOUND)
- set(BROTLI_TARGETS unofficial::brotli::brotlienc unofficial::brotli::brotlidec)
-else()
- pkg_check_modules(BROTLI REQUIRED IMPORTED_TARGET libbrotlienc libbrotlidec libbrotlicommon)
- set(BROTLI_TARGETS PkgConfig::BROTLI)
-endif()
-
pkg_check_modules(LIBPSL REQUIRED IMPORTED_TARGET libpsl)
pkg_check_modules(libtommath REQUIRED IMPORTED_TARGET libtommath)
diff --git a/Tests/LibCompress/CMakeLists.txt b/Tests/LibCompress/CMakeLists.txt
index fca567687b2..dca05002af0 100644
--- a/Tests/LibCompress/CMakeLists.txt
+++ b/Tests/LibCompress/CMakeLists.txt
@@ -1,8 +1,5 @@
set(TEST_SOURCES
- TestBrotli.cpp
TestDeflate.cpp
- TestGzip.cpp
- TestLzw.cpp
TestZlib.cpp
)
diff --git a/Tests/LibCompress/TestBrotli.cpp b/Tests/LibCompress/TestBrotli.cpp
deleted file mode 100644
index 9e747be02a8..00000000000
--- a/Tests/LibCompress/TestBrotli.cpp
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Copyright (c) 2026-present, the Ladybird developers.
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#include <AK/MemoryStream.h>
-#include <AK/Random.h>
-#include <LibCompress/Brotli.h>
-#include <LibTest/TestCase.h>
-
-TEST_CASE(brotli_decompress_simple)
-{
- Array<u8, 20> const compressed {
- 0x21, 0x38, 0x00, 0x04, 0x65, 0x78, 0x70, 0x65, 0x63, 0x74,
- 0x65, 0x64, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x03
- };
-
- u8 const uncompressed[] = "expected output";
-
- auto const decompressed = TRY_OR_FAIL(Compress::BrotliDecompressor::decompress_all(compressed));
- EXPECT(decompressed.bytes() == (ReadonlyBytes { uncompressed, sizeof(uncompressed) - 1 }));
-}
-
-TEST_CASE(brotli_decompress_empty)
-{
- Array<u8, 2> const compressed { 0xa1, 0x01 };
-
- auto const decompressed = TRY_OR_FAIL(Compress::BrotliDecompressor::decompress_all(compressed));
- EXPECT(decompressed.is_empty());
-}
-
-TEST_CASE(brotli_round_trip)
-{
- auto original = ByteBuffer::create_uninitialized(1024).release_value();
- fill_with_random(original);
-
- auto compressed = TRY_OR_FAIL(Compress::BrotliCompressor::compress_all(original));
- auto uncompressed = TRY_OR_FAIL(Compress::BrotliDecompressor::decompress_all(compressed));
- EXPECT(uncompressed == original);
-}
-
-TEST_CASE(brotli_compression_levels)
-{
- Array compression_levels {
- Compress::BrotliCompressionLevel::Fastest,
- Compress::BrotliCompressionLevel::Default,
- Compress::BrotliCompressionLevel::Best,
- };
-
- auto original = "Ladybird Brotli compression level test data"sv.bytes();
- for (auto compression_level : compression_levels) {
- auto compressed = TRY_OR_FAIL(Compress::BrotliCompressor::compress_all(original, compression_level));
- auto uncompressed = TRY_OR_FAIL(Compress::BrotliDecompressor::decompress_all(compressed));
- EXPECT(uncompressed == original);
- }
-}
-
-TEST_CASE(brotli_trailing_data)
-{
- Array<u8, 21> const compressed {
- 0x21, 0x38, 0x00, 0x04, 0x65, 0x78, 0x70, 0x65, 0x63, 0x74,
- 0x65, 0x64, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x03,
- 0x00
- };
-
- auto const decompressed = Compress::BrotliDecompressor::decompress_all(compressed);
- EXPECT(decompressed.is_error());
-}
-
-TEST_CASE(brotli_trailing_data_after_end)
-{
- Array<u8, 20> const compressed {
- 0x21, 0x38, 0x00, 0x04, 0x65, 0x78, 0x70, 0x65, 0x63, 0x74,
- 0x65, 0x64, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x03
- };
-
- auto input_stream = make<AllocatingMemoryStream>();
- auto decompressor = TRY_OR_FAIL(Compress::BrotliDecompressor::create(MaybeOwned<Stream> { *input_stream }));
-
- TRY_OR_FAIL(input_stream->write_until_depleted(compressed));
-
- Array<u8, 32> output;
- auto const decompressed = TRY_OR_FAIL(decompressor->read_some(output));
- u8 const uncompressed[] = "expected output";
- EXPECT(decompressed == (ReadonlyBytes { uncompressed, sizeof(uncompressed) - 1 }));
-
- u8 trailing_data = 0;
- TRY_OR_FAIL(input_stream->write_until_depleted({ &trailing_data, 1 }));
- EXPECT(decompressor->read_some(output).is_error());
-}
diff --git a/Tests/LibCompress/TestGzip.cpp b/Tests/LibCompress/TestGzip.cpp
deleted file mode 100644
index 5a76b2cee42..00000000000
--- a/Tests/LibCompress/TestGzip.cpp
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Copyright (c) 2020-2021, the SerenityOS developers.
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#include <LibCompress/Gzip.h>
-#include <LibTest/TestCase.h>
-
-TEST_CASE(gzip_decompress_simple)
-{
- Array<u8, 33> const compressed {
- 0x1f, 0x8b, 0x08, 0x00, 0x77, 0xff, 0x47, 0x5f, 0x02, 0xff, 0x2b, 0xcf,
- 0x2f, 0x4a, 0x31, 0x54, 0x48, 0x4c, 0x4a, 0x56, 0x28, 0x07, 0xb2, 0x8c,
- 0x00, 0xc2, 0x1d, 0x22, 0x15, 0x0f, 0x00, 0x00, 0x00
- };
-
- u8 const uncompressed[] = "word1 abc word2";
-
- auto const decompressed = TRY_OR_FAIL(Compress::GzipDecompressor::decompress_all(compressed));
- EXPECT(decompressed.bytes() == (ReadonlyBytes { uncompressed, sizeof(uncompressed) - 1 }));
-}
-
-TEST_CASE(gzip_decompress_multiple_members)
-{
- Array<u8, 52> const compressed {
- 0x1f, 0x8b, 0x08, 0x00, 0xe0, 0x03, 0x48, 0x5f, 0x02, 0xff, 0x4b, 0x4c,
- 0x4a, 0x4e, 0x4c, 0x4a, 0x06, 0x00, 0x4c, 0x99, 0x6e, 0x72, 0x06, 0x00,
- 0x00, 0x00, 0x1f, 0x8b, 0x08, 0x00, 0xe0, 0x03, 0x48, 0x5f, 0x02, 0xff,
- 0x4b, 0x4c, 0x4a, 0x4e, 0x4c, 0x4a, 0x06, 0x00, 0x4c, 0x99, 0x6e, 0x72,
- 0x06, 0x00, 0x00, 0x00
- };
-
- u8 const uncompressed[] = "abcabcabcabc";
-
- auto const decompressed = TRY_OR_FAIL(Compress::GzipDecompressor::decompress_all(compressed));
- EXPECT(decompressed.bytes() == (ReadonlyBytes { uncompressed, sizeof(uncompressed) - 1 }));
-}
-
-TEST_CASE(gzip_decompress_zeroes)
-{
- Array<u8, 161> const compressed {
- 0x1f, 0x8b, 0x08, 0x00, 0x6e, 0x7a, 0x4b, 0x5f, 0x02, 0xff, 0xed, 0xc1,
- 0x31, 0x01, 0x00, 0x00, 0x00, 0xc2, 0xa0, 0xf5, 0x4f, 0xed, 0x61, 0x0d,
- 0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6e, 0xcd, 0xcd, 0xe8,
- 0x7e, 0x00, 0x00, 0x02, 0x00
- };
-
- Array<u8, 128 * 1024> const uncompressed = { 0 };
-
- auto const decompressed = TRY_OR_FAIL(Compress::GzipDecompressor::decompress_all(compressed));
- EXPECT(uncompressed == decompressed.bytes());
-}
-
-TEST_CASE(gzip_decompress_repeat_around_buffer)
-{
- Array<u8, 70> const compressed {
- 0x1f, 0x8b, 0x08, 0x00, 0xc6, 0x74, 0x53, 0x5f, 0x02, 0xff, 0xed, 0xc1,
- 0x01, 0x0d, 0x00, 0x00, 0x0c, 0x02, 0xa0, 0xdb, 0xbf, 0xf4, 0x37, 0x6b,
- 0x08, 0x24, 0xdb, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xca,
- 0xb8, 0x07, 0xcd, 0xe5, 0x38, 0xfa, 0x00, 0x80, 0x00, 0x00
- };
-
- Array<u8, 0x8000> uncompressed;
- uncompressed.span().slice(0x0000, 0x0100).fill(1);
- uncompressed.span().slice(0x0100, 0x7e00).fill(0);
- uncompressed.span().slice(0x7f00, 0x0100).fill(1);
-
- auto const decompressed = TRY_OR_FAIL(Compress::GzipDecompressor::decompress_all(compressed));
- EXPECT(uncompressed == decompressed.bytes());
-}
-
-TEST_CASE(gzip_round_trip)
-{
- auto original = ByteBuffer::create_uninitialized(1024).release_value();
- fill_with_random(original);
- auto compressed = TRY_OR_FAIL(Compress::GzipCompressor::compress_all(original));
- auto uncompressed = TRY_OR_FAIL(Compress::GzipDecompressor::decompress_all(compressed));
- EXPECT(uncompressed == original);
-}
-
-TEST_CASE(gzip_truncated_uncompressed_block)
-{
- Array<u8, 38> const compressed {
- 0x1F, 0x8B, 0x08, 0x13, 0x5D, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x85, 0x1C,
- 0x1C, 0xFF, 0xDB, 0xFB, 0xFF, 0xDB
- };
-
- auto const decompressed_or_error = Compress::GzipDecompressor::decompress_all(compressed);
- EXPECT(decompressed_or_error.is_error());
-}
diff --git a/Tests/LibCompress/TestLzw.cpp b/Tests/LibCompress/TestLzw.cpp
deleted file mode 100644
index 20c64097a26..00000000000
--- a/Tests/LibCompress/TestLzw.cpp
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (c) 2024, Lucas Chollet <[email protected]>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#include <LibTest/TestCase.h>
-
-#include <AK/Array.h>
-#include <LibCompress/Lzw.h>
-
-namespace {
-
-ErrorOr<bool> test_roundtrip_string(StringView input)
-{
- auto const compressed = TRY(Compress::LzwCompressor::compress_all(input.bytes(), 8));
- auto const roundtrip = TRY(Compress::LzwDecompressor<LittleEndianInputBitStream>::decompress_all(compressed, 8));
- return roundtrip == input.bytes();
-}
-
-}
-
-TEST_CASE(roundtrip_lzw_little_endian_short)
-{
- EXPECT(TRY_OR_FAIL(test_roundtrip_string("WeWellll"sv)));
-}
-
-TEST_CASE(roundtrip_lzw_little_endian_long)
-{
- // LZW changes the code size after ~512 new symbols, this test case is long enough to trigger that.
- constexpr auto input = "WellWellWellWellaqwertyuiop[]sdfghjkl;'zxcvbnm,./uipnaspchu9epqrjepncdp9ruew-r8thvnufsipdonvjcx zvlrz[iu0q-348urfjsd;fjmvxc.nnnmvcxzvmc c,m;l'/,l4532[5i904tmorew;lgkrmopds['kg,l;'s,gWellWellWellWellaqwertyuiop[]sdfghjkl;'zxcvbnm,./uipnaspchu9epqrjepncdp9ruew-r8thvnufsipdonvjcx zvlrz[iu0q-348urfjsd;fjmvxc.nnnmvcxzvmc c,m;l'/,l4532[5i904tmorew;lgkrmopds['kg,l;'s,gWellWellWellWellaqwertyuiop[]sdfghjkl;'zxcvbnm,./uipnaspchu9epqrjepncdp9ruew-r8thvnufsipdonvjcx zvlrz[iu0q-348urfjsd;fjmvxc.nnnmvcxzvmc c,m;l'/,l4532[5i904tmorew;lgkrmopds['kg,l;'s,gWellWellWellWellaqwertyuiop[]sdfghjkl;'zxcvbnm,./uipnaspchu9epqrjepncdp9ruew-r8thvnufsipdonvjcx zvlrz[iu0q-348urfjsd;fjmvxc.nnnmvcxzvmc c,m;l'/,l4532[5i904tmorew;lgkrmopds['kg,l;'s,g"sv;
- EXPECT(TRY_OR_FAIL(test_roundtrip_string(input)));
-}