Skip to content

Commit

Permalink
Fix uncompressing concatenated gzip files
Browse files Browse the repository at this point in the history
  • Loading branch information
mhekkel committed Aug 4, 2023
1 parent db1dff1 commit 15a49f1
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion include/cif++/gzio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,13 @@ class basic_igzip_streambuf : public basic_streambuf<CharT, Traits>
zstream.avail_in = static_cast<uInt>(this->m_upstream->sgetn(m_in_buffer.data(), m_in_buffer.size()));
}

if (zstream.avail_in == 0)
break;

int err = ::inflate(&zstream, Z_SYNC_FLUSH);
std::streamsize n = kBufferByteSize - zstream.avail_out;

if (err == Z_STREAM_END or (err == Z_OK and n > 0))
if (n > 0)
{
this->setg(
m_out_buffer.data(),
Expand All @@ -258,6 +261,9 @@ class basic_igzip_streambuf : public basic_streambuf<CharT, Traits>
break;
}

if (err == Z_STREAM_END and zstream.avail_in > 0)
err = ::inflateReset2(&zstream, 47);

if (err < Z_OK)
break;
}
Expand Down

0 comments on commit 15a49f1

Please sign in to comment.