mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 08:48:11 +00:00
LibCompress: Let BrotliDecompressionStream
take a MaybeOwned
This commit is contained in:
parent
8a853278d0
commit
dbc25f18ec
6 changed files with 8 additions and 8 deletions
|
@ -12,7 +12,7 @@ extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size)
|
||||||
{
|
{
|
||||||
FixedMemoryStream bufstream { { data, size } };
|
FixedMemoryStream bufstream { { data, size } };
|
||||||
|
|
||||||
auto brotli_stream = Compress::BrotliDecompressionStream { bufstream };
|
auto brotli_stream = Compress::BrotliDecompressionStream { MaybeOwned<Stream> { bufstream } };
|
||||||
|
|
||||||
(void)brotli_stream.read_until_eof();
|
(void)brotli_stream.read_until_eof();
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -24,7 +24,7 @@ static void run_test(StringView const file_name)
|
||||||
DeprecatedString path_compressed = DeprecatedString::formatted("{}.br", path);
|
DeprecatedString path_compressed = DeprecatedString::formatted("{}.br", path);
|
||||||
|
|
||||||
auto file = MUST(Core::File::open(path_compressed, Core::File::OpenMode::Read));
|
auto file = MUST(Core::File::open(path_compressed, Core::File::OpenMode::Read));
|
||||||
auto brotli_stream = Compress::BrotliDecompressionStream { *file };
|
auto brotli_stream = Compress::BrotliDecompressionStream { MaybeOwned<Stream> { *file } };
|
||||||
auto data = MUST(brotli_stream.read_until_eof());
|
auto data = MUST(brotli_stream.read_until_eof());
|
||||||
|
|
||||||
EXPECT_EQ(data, cmp_data);
|
EXPECT_EQ(data, cmp_data);
|
||||||
|
@ -97,7 +97,7 @@ TEST_CASE(brotli_decompress_zero_one_bin)
|
||||||
DeprecatedString path_compressed = DeprecatedString::formatted("{}.br", path);
|
DeprecatedString path_compressed = DeprecatedString::formatted("{}.br", path);
|
||||||
|
|
||||||
auto file = MUST(Core::File::open(path_compressed, Core::File::OpenMode::Read));
|
auto file = MUST(Core::File::open(path_compressed, Core::File::OpenMode::Read));
|
||||||
auto brotli_stream = Compress::BrotliDecompressionStream { *file };
|
auto brotli_stream = Compress::BrotliDecompressionStream { MaybeOwned<Stream> { *file } };
|
||||||
|
|
||||||
u8 buffer_raw[4096];
|
u8 buffer_raw[4096];
|
||||||
Bytes buffer { buffer_raw, 4096 };
|
Bytes buffer { buffer_raw, 4096 };
|
||||||
|
|
|
@ -28,8 +28,8 @@ ErrorOr<size_t> Brotli::CanonicalCode::read_symbol(LittleEndianInputBitStream& i
|
||||||
return Error::from_string_literal("no matching code found");
|
return Error::from_string_literal("no matching code found");
|
||||||
}
|
}
|
||||||
|
|
||||||
BrotliDecompressionStream::BrotliDecompressionStream(Stream& stream)
|
BrotliDecompressionStream::BrotliDecompressionStream(MaybeOwned<Stream> stream)
|
||||||
: m_input_stream(MaybeOwned(stream))
|
: m_input_stream(move(stream))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -111,7 +111,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BrotliDecompressionStream(Stream&);
|
BrotliDecompressionStream(MaybeOwned<Stream>);
|
||||||
|
|
||||||
ErrorOr<Bytes> read_some(Bytes output_buffer) override;
|
ErrorOr<Bytes> read_some(Bytes output_buffer) override;
|
||||||
ErrorOr<size_t> write_some(ReadonlyBytes bytes) override { return m_input_stream.write_some(bytes); }
|
ErrorOr<size_t> write_some(ReadonlyBytes bytes) override { return m_input_stream.write_some(bytes); }
|
||||||
|
|
|
@ -1000,7 +1000,7 @@ ErrorOr<NonnullRefPtr<Font>> Font::try_load_from_externally_owned_memory(Seekabl
|
||||||
return Error::from_string_literal("Not enough data to read in the reported size of the compressed data");
|
return Error::from_string_literal("Not enough data to read in the reported size of the compressed data");
|
||||||
|
|
||||||
auto compressed_stream = FixedMemoryStream(compressed_bytes);
|
auto compressed_stream = FixedMemoryStream(compressed_bytes);
|
||||||
auto brotli_stream = Compress::BrotliDecompressionStream { compressed_stream };
|
auto brotli_stream = Compress::BrotliDecompressionStream { MaybeOwned<Stream>(compressed_stream) };
|
||||||
auto decompressed_table_data = TRY(brotli_stream.read_until_eof());
|
auto decompressed_table_data = TRY(brotli_stream.read_until_eof());
|
||||||
if (decompressed_table_data.size() != total_length_of_all_tables)
|
if (decompressed_table_data.size() != total_length_of_all_tables)
|
||||||
return Error::from_string_literal("Size of the decompressed data is not equal to the total of the reported lengths of each table");
|
return Error::from_string_literal("Size of the decompressed data is not equal to the total of the reported lengths of each table");
|
||||||
|
|
|
@ -75,7 +75,7 @@ static ErrorOr<ByteBuffer> handle_content_encoding(ByteBuffer const& buf, Deprec
|
||||||
dbgln_if(JOB_DEBUG, "Job::handle_content_encoding: buf is brotli compressed!");
|
dbgln_if(JOB_DEBUG, "Job::handle_content_encoding: buf is brotli compressed!");
|
||||||
|
|
||||||
FixedMemoryStream bufstream { buf };
|
FixedMemoryStream bufstream { buf };
|
||||||
auto brotli_stream = Compress::BrotliDecompressionStream { bufstream };
|
auto brotli_stream = Compress::BrotliDecompressionStream { MaybeOwned<Stream>(bufstream) };
|
||||||
|
|
||||||
auto uncompressed = TRY(brotli_stream.read_until_eof());
|
auto uncompressed = TRY(brotli_stream.read_until_eof());
|
||||||
if constexpr (JOB_DEBUG) {
|
if constexpr (JOB_DEBUG) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue