mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 04:57:45 +00:00
LibCompress: Move loading XZ stream headers into its own function
This commit is contained in:
parent
95e35b7f5e
commit
0e11e7012d
2 changed files with 54 additions and 43 deletions
|
@ -191,12 +191,12 @@ static Optional<size_t> size_for_check_type(XzStreamCheckType check_type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<Bytes> XzDecompressor::read_some(Bytes bytes)
|
ErrorOr<bool> XzDecompressor::load_next_stream()
|
||||||
{
|
{
|
||||||
|
// If we already determined to have found the last stream footer, there is nothing more to do.
|
||||||
if (m_found_last_stream_footer)
|
if (m_found_last_stream_footer)
|
||||||
return bytes.trim(0);
|
return false;
|
||||||
|
|
||||||
if (!m_stream_flags.has_value()) {
|
|
||||||
// This assumes that we can just read the Stream Header into memory as-is. Check that this still holds up for good measure.
|
// This assumes that we can just read the Stream Header into memory as-is. Check that this still holds up for good measure.
|
||||||
static_assert(AK::Traits<XzStreamHeader>::is_trivially_serializable());
|
static_assert(AK::Traits<XzStreamHeader>::is_trivially_serializable());
|
||||||
|
|
||||||
|
@ -239,7 +239,7 @@ ErrorOr<Bytes> XzDecompressor::read_some(Bytes bytes)
|
||||||
|
|
||||||
if (m_stream->is_eof()) {
|
if (m_stream->is_eof()) {
|
||||||
m_found_last_stream_footer = true;
|
m_found_last_stream_footer = true;
|
||||||
return bytes.trim(0);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -248,6 +248,15 @@ ErrorOr<Bytes> XzDecompressor::read_some(Bytes bytes)
|
||||||
|
|
||||||
m_stream_flags = stream_header.flags;
|
m_stream_flags = stream_header.flags;
|
||||||
m_found_first_stream_header = true;
|
m_found_first_stream_header = true;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
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() || (*m_current_block_stream)->is_eof()) {
|
||||||
|
|
|
@ -111,6 +111,8 @@ public:
|
||||||
private:
|
private:
|
||||||
XzDecompressor(NonnullOwnPtr<CountingStream>);
|
XzDecompressor(NonnullOwnPtr<CountingStream>);
|
||||||
|
|
||||||
|
ErrorOr<bool> load_next_stream();
|
||||||
|
|
||||||
NonnullOwnPtr<CountingStream> m_stream;
|
NonnullOwnPtr<CountingStream> m_stream;
|
||||||
Optional<XzStreamFlags> m_stream_flags;
|
Optional<XzStreamFlags> m_stream_flags;
|
||||||
bool m_found_first_stream_header { false };
|
bool m_found_first_stream_header { false };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue