1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 13:17:35 +00:00

LibCompress: Port ZlibDecompressor to AK::Stream

This commit is contained in:
Tim Schumacher 2023-06-08 19:35:44 +02:00 committed by Sam Atkins
parent 90780d9ade
commit 8a853278d0
7 changed files with 96 additions and 68 deletions

View file

@ -51,13 +51,17 @@ static ErrorOr<ByteBuffer> handle_content_encoding(ByteBuffer const& buf, Deprec
// Even though the content encoding is "deflate", it's actually deflate with the zlib wrapper.
// https://tools.ietf.org/html/rfc7230#section-4.2.2
auto uncompressed = Compress::ZlibDecompressor::decompress_all(buf);
if (!uncompressed.has_value()) {
auto memory_stream = make<FixedMemoryStream>(buf);
auto zlib_decompressor = Compress::ZlibDecompressor::create(move(memory_stream));
Optional<ByteBuffer> uncompressed;
if (zlib_decompressor.is_error()) {
// From the RFC:
// "Note: Some non-conformant implementations send the "deflate"
// compressed data without the zlib wrapper."
dbgln_if(JOB_DEBUG, "Job::handle_content_encoding: ZlibDecompressor::decompress_all() failed. Trying DeflateDecompressor::decompress_all()");
uncompressed = TRY(Compress::DeflateDecompressor::decompress_all(buf));
} else {
uncompressed = TRY(zlib_decompressor.value()->read_until_eof());
}
if constexpr (JOB_DEBUG) {