mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:37:35 +00:00
LibCompress: Move finishing the current XZ block into its own function
This commit is contained in:
parent
0e11e7012d
commit
68984abc43
2 changed files with 51 additions and 44 deletions
|
@ -252,17 +252,8 @@ ErrorOr<bool> XzDecompressor::load_next_stream()
|
||||||
return true;
|
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;
|
auto unpadded_size = m_stream->read_bytes() - m_current_block_start_offset;
|
||||||
|
|
||||||
// 3.3. Block Padding:
|
// 3.3. Block Padding:
|
||||||
|
@ -306,6 +297,21 @@ ErrorOr<Bytes> XzDecompressor::read_some(Bytes bytes)
|
||||||
.uncompressed_size = m_current_block_uncompressed_size,
|
.uncompressed_size = m_current_block_uncompressed_size,
|
||||||
.unpadded_size = unpadded_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();
|
auto start_of_current_block = m_stream->read_bytes();
|
||||||
|
|
|
@ -112,6 +112,7 @@ private:
|
||||||
XzDecompressor(NonnullOwnPtr<CountingStream>);
|
XzDecompressor(NonnullOwnPtr<CountingStream>);
|
||||||
|
|
||||||
ErrorOr<bool> load_next_stream();
|
ErrorOr<bool> load_next_stream();
|
||||||
|
ErrorOr<void> finish_current_block();
|
||||||
|
|
||||||
NonnullOwnPtr<CountingStream> m_stream;
|
NonnullOwnPtr<CountingStream> m_stream;
|
||||||
Optional<XzStreamFlags> m_stream_flags;
|
Optional<XzStreamFlags> m_stream_flags;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue