fix: handle IWD entry end of stream (#976)

* fix: handle IWD entry end of stream

Return EOF correctly for IWD entries and preserve peeked bytes during bulk reads.

* chore: small code style adaption

* chore: use minizip to write test zip file

---------

Co-authored-by: Jan Laupetin <[email protected]>
This commit is contained in:
mo
2026-09-01 00:01:44 +02:00
committed by GitHub
co-authored by Jan Laupetin
parent 662780a896
commit 7d027e8f89
2 changed files with 71 additions and 4 deletions
+14 -4
View File
@@ -78,7 +78,8 @@ namespace
const auto result = unzReadCurrentFile(m_container, &m_peek_symbol, 1u);
if (result >= 0)
// minizip returns zero at the end of the current archive entry.
if (result > 0)
{
m_peeked = true;
return m_peek_symbol;
@@ -96,21 +97,30 @@ namespace
}
const auto result = unzReadCurrentFile(m_container, &m_peek_symbol, 1u);
return result >= 0 ? m_peek_symbol : EOF;
return result > 0 ? m_peek_symbol : EOF;
}
std::streamsize xsgetn(char* ptr, std::streamsize count) override
{
std::streamsize result{};
if (m_peeked && count >= 1)
{
*ptr = static_cast<char>(m_peek_symbol);
m_peeked = false;
ptr++;
count--;
result++;
}
const auto result = unzReadCurrentFile(m_container, ptr, static_cast<unsigned>(count));
if (count <= 0)
return result;
return result >= 0 ? static_cast<std::streamsize>(result) : 0;
const auto readResult = unzReadCurrentFile(m_container, ptr, static_cast<unsigned>(count));
if (readResult > 0)
result += static_cast<std::streamsize>(readResult);
return result;
}
pos_type seekoff(const off_type off, const std::ios_base::seekdir dir, const std::ios_base::openmode mode) override