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

LibCompress: Move finishing the current XZ block into its own function

This commit is contained in:
Tim Schumacher 2023-04-05 16:34:06 +02:00 committed by Brian Gianforcaro
parent 0e11e7012d
commit 68984abc43
2 changed files with 51 additions and 44 deletions

View file

@ -252,17 +252,8 @@ ErrorOr<bool> XzDecompressor::load_next_stream()
return true;
}
ErrorOr<Bytes> XzDecompressor::read_some(Bytes bytes)
ErrorOr<void> XzDecompressor::finish_current_block()
{
if (!m_stream_flags.has_value()) {
if (!TRY(load_next_stream()))
return bytes.trim(0);
}
if (!m_current_block_stream.has_value() || (*m_current_block_stream)->is_eof()) {
if (m_current_block_stream.has_value()) {
// We have already processed a block, so we weed to clean up trailing data before the next block starts.
auto unpadded_size = m_stream->read_bytes() - m_current_block_start_offset;
// 3.3. Block Padding:
@ -306,6 +297,21 @@ ErrorOr<Bytes> XzDecompressor::read_some(Bytes bytes)
.uncompressed_size = m_current_block_uncompressed_size,
.unpadded_size = unpadded_size,
}));
return {};
}
ErrorOr<Bytes> XzDecompressor::read_some(Bytes bytes)
{
if (!m_stream_flags.has_value()) {
if (!TRY(load_next_stream()))
return bytes.trim(0);
}
if (!m_current_block_stream.has_value() || (*m_current_block_stream)->is_eof()) {
if (m_current_block_stream.has_value()) {
// We have already processed a block, so we weed to clean up trailing data before the next block starts.
TRY(finish_current_block());
}
auto start_of_current_block = m_stream->read_bytes();

View file

@ -112,6 +112,7 @@ private:
XzDecompressor(NonnullOwnPtr<CountingStream>);
ErrorOr<bool> load_next_stream();
ErrorOr<void> finish_current_block();
NonnullOwnPtr<CountingStream> m_stream;
Optional<XzStreamFlags> m_stream_flags;