mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
LibCompress: Use OutputMemoryStream in decompress_all methods.
This commit is contained in:
parent
b0ba7a897f
commit
7e02cad476
Notes:
sideshowbarker
2024-07-19 02:46:27 +09:00
Author: https://github.com/asynts Commit: https://github.com/SerenityOS/serenity/commit/7e02cad4763 Pull-request: https://github.com/SerenityOS/serenity/pull/3455
2 changed files with 18 additions and 19 deletions
|
@ -308,18 +308,18 @@ ByteBuffer DeflateDecompressor::decompress_all(ReadonlyBytes bytes)
|
|||
InputMemoryStream memory_stream { bytes };
|
||||
InputBitStream bit_stream { memory_stream };
|
||||
DeflateDecompressor deflate_stream { bit_stream };
|
||||
OutputMemoryStream output_stream;
|
||||
|
||||
auto buffer = ByteBuffer::create_uninitialized(4096);
|
||||
|
||||
size_t nread = 0;
|
||||
while (!deflate_stream.eof()) {
|
||||
nread += deflate_stream.read(buffer.bytes().slice(nread));
|
||||
if (buffer.size() - nread < 4096)
|
||||
buffer.grow(buffer.size() + 4096);
|
||||
u8 buffer[4096];
|
||||
while (!deflate_stream.has_any_error() && !deflate_stream.eof()) {
|
||||
const auto nread = deflate_stream.read({ buffer, sizeof(buffer) });
|
||||
output_stream.write_or_error({ buffer, nread });
|
||||
}
|
||||
|
||||
buffer.trim(nread);
|
||||
return buffer;
|
||||
if (deflate_stream.handle_any_error())
|
||||
return {};
|
||||
|
||||
return output_stream.copy_into_contiguous_buffer();
|
||||
}
|
||||
|
||||
u32 DeflateDecompressor::decode_run_length(u32 symbol)
|
||||
|
|
|
@ -162,19 +162,18 @@ ByteBuffer GzipDecompressor::decompress_all(ReadonlyBytes bytes)
|
|||
{
|
||||
InputMemoryStream memory_stream { bytes };
|
||||
GzipDecompressor gzip_stream { memory_stream };
|
||||
OutputMemoryStream output_stream;
|
||||
|
||||
auto buffer = ByteBuffer::create_uninitialized(4096);
|
||||
|
||||
size_t nread = 0;
|
||||
while (!gzip_stream.eof()) {
|
||||
nread += gzip_stream.read(buffer.bytes().slice(nread));
|
||||
|
||||
if (buffer.size() - nread < 4096)
|
||||
buffer.grow(buffer.size() + 4096);
|
||||
u8 buffer[4096];
|
||||
while (!gzip_stream.has_any_error() && !gzip_stream.eof()) {
|
||||
const auto nread = gzip_stream.read({ buffer, sizeof(buffer) });
|
||||
output_stream.write_or_error({ buffer, nread });
|
||||
}
|
||||
|
||||
buffer.trim(nread);
|
||||
return buffer;
|
||||
if (gzip_stream.handle_any_error())
|
||||
return {};
|
||||
|
||||
return output_stream.copy_into_contiguous_buffer();
|
||||
}
|
||||
|
||||
bool GzipDecompressor::eof() const
|
||||
|
|
Loading…
Reference in a new issue